Skip to content

Commit

Permalink
[GCS] Made the contrast label it's own class.
Browse files Browse the repository at this point in the history
The outlines should now also be less jagged as I am covering all pixel
directions.
  • Loading branch information
esden authored and gautierhattenberger committed Nov 4, 2013
1 parent 74dc09c commit bca3fea
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 34 deletions.
2 changes: 1 addition & 1 deletion sw/lib/ocaml/Makefile
Expand Up @@ -59,7 +59,7 @@ SRC = fig.ml debug.ml base64.ml serial.ml ocaml_tools.ml expr_syntax.ml expr_par
CMO = $(SRC:.ml=.cmo)
CMX = $(SRC:.ml=.cmx)

XSRC = gtk_tools.ml platform.ml wind_sock.ml gtk_papget_editor.ml gtk_papget_text_editor.ml gtk_papget_gauge_editor.ml gtk_papget_led_editor.ml papget_common.ml papget_renderer.ml papget.ml mapCanvas.ml mapWaypoints.ml mapTrack.ml mapGoogle.ml mapIGN.ml ml_gtk_drag.o xmlEdit.ml mapFP.ml
XSRC = gtk_tools.ml platform.ml contrastLabel.ml wind_sock.ml gtk_papget_editor.ml gtk_papget_text_editor.ml gtk_papget_gauge_editor.ml gtk_papget_led_editor.ml papget_common.ml papget_renderer.ml papget.ml mapCanvas.ml mapWaypoints.ml mapTrack.ml mapGoogle.ml mapIGN.ml ml_gtk_drag.o xmlEdit.ml mapFP.ml
XCMO = $(XSRC:.ml=.cmo)
XCMX = $(XSRC:.ml=.cmx)

Expand Down
59 changes: 59 additions & 0 deletions sw/lib/ocaml/contrastLabel.ml
@@ -0,0 +1,59 @@
(*
* A Label with a contrasting outline
*
* Copyright (C) 2013 Piotr Esden-Tempski <piotr@esden.net>
*
* This file is part of paparazzi.
*
* paparazzi is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* paparazzi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with paparazzi; see the file COPYING. If not, write to
* the Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
*)

(*
* This module creates labels with outlines by creating 9
* overlapping labels slightly offset from eachother. Where the 8
* labels in the background have a different color from last center one.
*)

let label_offset_matrix =
[
(* X Y *)
[ 0.; -1.]; (* N *)
[ 0.; 1.]; (* S *)
[ 1.; 0.]; (* E *)
[-1.; 0.]; (* W *)
[ 1.; -1.]; (* NE *)
[ 1.; 1.]; (* SE *)
[-1.; 1.]; (* SW *)
[-1.; -1.]; (* NW *)
[ 0.; 0.]; (* Z *)
]

class widget = fun ?(name = "Noname") ?(size = 500) ?(bg_color = "black") ?(color = "red") x y (group:GnoCanvas.group) ->
let new_text offset =
GnoCanvas.text group ~props:[`TEXT name;
`X (x +. (List.nth offset 0)); `Y (y +. (List.nth offset 1));
`ANCHOR `SW;
`FILL_COLOR (if offset = [0.;0.] then color else bg_color)] in
let labels = List.map new_text label_offset_matrix in
object(self)
method set_name s = List.iter (fun label -> label#set [`TEXT s]) labels
method set_x x = List.iter2 (fun label offset -> label#set [`X (x +. (List.nth offset 0))])
labels label_offset_matrix
method set_y y = List.iter2 (fun label offset -> label#set [`Y (y +. (List.nth offset 1))])
labels label_offset_matrix
method affine_absolute a = List.iter (fun label -> label#affine_absolute a) labels
end
38 changes: 38 additions & 0 deletions sw/lib/ocaml/contrastLabel.mli
@@ -0,0 +1,38 @@
(*
* A Label with a contrasting outline
*
* Copyright (C) 2013 Piotr Esden-Tempski <piotr@esden.net>
*
* This file is part of paparazzi.
*
* paparazzi is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* paparazzi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with paparazzi; see the file COPYING. If not, write to
* the Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
*)

class widget :
?name:string ->
?size:int ->
?bg_color:string ->
?color:string ->
float ->
float ->
GnoCanvas.group ->
object
method set_name : string -> unit
method set_x : float -> unit
method set_y : float -> unit
method affine_absolute : float array -> unit
end
27 changes: 9 additions & 18 deletions sw/lib/ocaml/mapTrack.ml
Expand Up @@ -28,6 +28,8 @@ module LL = Latlong

module G = MapCanvas

module CL = ContrastLabel

let affine_pos_and_angle z xw yw angle =
let rad_angle = angle /. 180. *. acos(-1.) in
let cos_a = cos rad_angle in
Expand All @@ -50,7 +52,6 @@ type desired =
| DesiredCircle of LL.geographic*float*GnoCanvas.ellipse
| DesiredSegment of LL.geographic*LL.geographic*GnoCanvas.line


class track = fun ?(name="Noname") ?(size = 500) ?(color="red") (geomap:MapCanvas.widget) ->
let group = GnoCanvas.group geomap#canvas#root in
let empty = ({LL.posn_lat=0.; LL.posn_long=0.}, GnoCanvas.line group) in
Expand All @@ -62,12 +63,8 @@ class track = fun ?(name="Noname") ?(size = 500) ?(color="red") (geomap:MapCanva
ignore (GnoCanvas.line ~fill_color:color ~props:[`WIDTH_PIXELS 4;`CAP_STYLE `ROUND] ~points:[|0.;-6.;0.;14.|] aircraft);
ignore (GnoCanvas.line ~fill_color:color ~props:[`WIDTH_PIXELS 4;`CAP_STYLE `ROUND] ~points:[|-9.;0.;9.;0.|] aircraft);
ignore (GnoCanvas.line ~fill_color:color ~props:[`WIDTH_PIXELS 4;`CAP_STYLE `ROUND] ~points:[|-4.;10.;4.;10.|] aircraft) in
let ac_label_bg =
GnoCanvas.text group ~props:[`TEXT name; `X 26.; `Y 26.; `ANCHOR `SW; `FILL_COLOR "black"] in
let ac_label_bgn =
GnoCanvas.text group ~props:[`TEXT name; `X 24.; `Y 24.; `ANCHOR `SW; `FILL_COLOR "black"] in
let ac_label =
GnoCanvas.text group ~props:[`TEXT name; `X 25.; `Y 25.; `ANCHOR `SW; `FILL_COLOR color] in
let ac_label = new CL.widget ~name:name ~color:color 25. 25. group in

let carrot = GnoCanvas.group group in
let _ac_carrot =
ignore (GnoCanvas.polygon ~points:[|0.;0.;-5.;-10.;5.;-10.|] ~props:[`WIDTH_UNITS 1.;`FILL_COLOR "orange"; `OUTLINE_COLOR "orange"; `FILL_STIPPLE (Gdk.Bitmap.create_from_data ~width:2 ~height:2 "\002\001")] carrot) in
Expand Down Expand Up @@ -123,9 +120,7 @@ object (self)
method v_path = v_path
method aircraft = aircraft
method set_label = fun s ->
ac_label_bg#set [`TEXT s];
ac_label_bgn#set [`TEXT s];
ac_label#set [`TEXT s]
ac_label#set_name s
method clear_one = fun i ->
if segments.(i) != empty then begin
(snd segments.(i))#destroy ();
Expand Down Expand Up @@ -157,9 +152,8 @@ object (self)
method set_params_state = fun b ->
params_on <- b;
if not b then (* Reset to the default simple label *)
ac_label_bg#set [`TEXT name; `Y 25.];
ac_label_bgn#set [`TEXT name; `Y 25.];
ac_label#set [`TEXT name; `Y 25.]
ac_label#set_name name;
ac_label#set_y 25.
method set_v_params_state = fun b -> v_params_on <- b
method set_last = fun x -> last <- x
method last = last
Expand Down Expand Up @@ -202,13 +196,10 @@ object (self)

if params_on then begin
let last_height = self#height () in
ac_label_bg#set [`TEXT (sprintf "%s\n%+.0f m\n%.1f m/s" name last_height last_speed); `Y 71. ];
ac_label_bgn#set [`TEXT (sprintf "%s\n%+.0f m\n%.1f m/s" name last_height last_speed); `Y 69. ];
ac_label#set [`TEXT (sprintf "%s\n%+.0f m\n%.1f m/s" name last_height last_speed); `Y 70. ]
ac_label#set_name (sprintf "%s\n%+.0f m\n%.1f m/s" name last_height last_speed);
ac_label#set_y 70.
end;

ac_label_bg#affine_absolute (affine_pos_and_angle geomap#zoom_adj#value xw yw 0.);
ac_label_bgn#affine_absolute (affine_pos_and_angle geomap#zoom_adj#value xw yw 0.);
ac_label#affine_absolute (affine_pos_and_angle geomap#zoom_adj#value xw yw 0.);
self#add_point wgs84 altitude;

Expand Down
19 changes: 5 additions & 14 deletions sw/lib/ocaml/mapWaypoints.ml
Expand Up @@ -26,15 +26,12 @@ module LL = Latlong
open Printf
open LL

module CL = ContrastLabel

(*
* Waypoint label offsets
*)
let s = 6. (* x offset *)
let s_bg = 7. (* background positive x offset *)
let s_bgn = 5. (* background negative x offset *)
let sv = 0. (* y offset *)
let sv_bg = 1. (* background positive y offset *)
let sv_bgn = -1. (* background negative y offset *)

class group = fun ?(color="red") ?(editable=true) ?(show_moved=false) (geomap:MapCanvas.widget) ->
let g = GnoCanvas.group geomap#canvas#root in
Expand Down Expand Up @@ -74,9 +71,7 @@ object (self)
val mutable x0 = 0.
val mutable y0 = 0.

val label_bg = GnoCanvas.text wpt_group ~props:[`TEXT name; `X s_bg; `Y sv_bg; `ANCHOR `SW; `FILL_COLOR "black"]
val label_bgn = GnoCanvas.text wpt_group ~props:[`TEXT name; `X s_bgn; `Y sv_bgn; `ANCHOR `SW; `FILL_COLOR "black"]
val label = GnoCanvas.text wpt_group ~props:[`TEXT name; `X s; `Y sv; `ANCHOR `SW; `FILL_COLOR "white"]
val label = new CL.widget ~name:name ~color:"white" s 0. wpt_group
val mutable name = name (* FIXME: already in label ! *)
val mutable alt = alt
val mutable moved = None
Expand All @@ -94,9 +89,7 @@ object (self)
method set_name n =
if n <> name then begin
name <- n;
label_bg#set [`TEXT name];
label_bgn#set [`TEXT name];
label#set [`TEXT name]
label#set_name name
end
method alt = alt
method label = label
Expand Down Expand Up @@ -162,9 +155,7 @@ object (self)
let callback = fun _ ->
self#set_name ename#text;
alt <- ea#value;
label_bg#set [`TEXT name];
label_bgn#set [`TEXT name];
label#set [`TEXT name];
label#set_name name;
set_coordinates ();
updated ();
if wpts_group#show_moved then
Expand Down
2 changes: 1 addition & 1 deletion sw/lib/ocaml/mapWaypoints.mli
Expand Up @@ -48,7 +48,7 @@ class waypoint :
method pos : Latlong.geographic
method event : GnoCanvas.item_event -> bool
method item : GnoCanvas.rect
method label : GnoCanvas.text
method label : ContrastLabel.widget
method move : float -> float -> unit
method name : string
method set : ?altitude:float -> ?update:bool -> Latlong.geographic -> unit
Expand Down

0 comments on commit bca3fea

Please sign in to comment.