Quellcode durchsuchen

d.northarrow: enable transparent fill color, see https://trac.osgeo.org/grass/ticket/3044

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@68950 15284696-431f-4ddb-bdfa-cd5b030d7da7
Anna Petrášová vor 8 Jahren
Ursprung
Commit
bbd1a9517f
3 geänderte Dateien mit 31 neuen und 19 gelöschten Zeilen
  1. 8 10
      display/d.northarrow/draw_n_arrow.c
  2. 22 8
      display/d.northarrow/main.c
  3. 1 1
      display/d.northarrow/options.h

+ 8 - 10
display/d.northarrow/draw_n_arrow.c

@@ -46,7 +46,7 @@ int draw_n_arrow(double east, double north, double rotation, char *lbl,
         if (rot_with_text)
             D_text_rotation(rotation * 180.0 / M_PI);
         D_get_text_box(lbl, &tt, &tb, &tl, &tr);
-        D_use_color(fg_color);
+        D_use_color(text_color);
 
         /* positions manually tuned */
         switch (n_arrow_num[0]) {
@@ -114,23 +114,21 @@ int draw_n_arrow(double east, double north, double rotation, char *lbl,
     fill_color = G_malloc(sizeof(RGBA_Color));
 
     if (D_color_number_to_RGB(fg_color, &R, &G, &B) == 0)
-        /* fall back to black on failure */
-        G_str_to_color(DEFAULT_FG_COLOR, &R, &G, &B);
+        line_color->a = RGBA_COLOR_TRANSPARENT;
+    else
+        line_color->a = RGBA_COLOR_OPAQUE;
     line_color->r = (unsigned char)R;
     line_color->g = (unsigned char)G;
     line_color->b = (unsigned char)B;
-    line_color->a = RGBA_COLOR_OPAQUE;
+
 
     if (D_color_number_to_RGB(bg_color, &R, &G, &B) == 0)
-        /* fall back to black on failure */
-        G_str_to_color(DEFAULT_FG_COLOR, &R, &G, &B);
+        fill_color->a = RGBA_COLOR_TRANSPARENT;
+    else
+        fill_color->a = RGBA_COLOR_OPAQUE;
     fill_color->r = (unsigned char)R;
     fill_color->g = (unsigned char)G;
     fill_color->b = (unsigned char)B;
-    fill_color->a = RGBA_COLOR_OPAQUE;
-
-    if (n_arrow_num[0] == '2' || n_arrow_num[0] == '9')
-        fill_color->a = RGBA_COLOR_TRANSPARENT;
 
     /* sizes manually tuned */
     switch (n_arrow_num[0]) {

+ 22 - 8
display/d.northarrow/main.c

@@ -25,14 +25,14 @@
 #include <grass/glocale.h>
 #include "options.h"
 
-int fg_color, bg_color;
-int do_background = TRUE;
+int fg_color, bg_color, text_color;
+//int do_background = TRUE;
 
 int main(int argc, char **argv)
 {
     struct GModule *module;
     struct Option *bg_color_opt, *fg_color_opt, *coords, *n_arrow, *fsize,
-        *width_opt, *rotation_opt, *lbl_opt;
+        *width_opt, *rotation_opt, *lbl_opt, *text_color_opt;
     struct Flag *no_text, *rotate_text, *rads;
     double east, north;
     double rotation;
@@ -99,16 +99,21 @@ int main(int argc, char **argv)
         _("Displayed letter on the top of arrow");
     lbl_opt->guisection = _("Text");
 
-    fg_color_opt = G_define_standard_option(G_OPT_C);
+    fg_color_opt = G_define_standard_option(G_OPT_CN);
     fg_color_opt->label = _("Line color");
     fg_color_opt->guisection = _("Colors");
 
     bg_color_opt = G_define_standard_option(G_OPT_CN);
     bg_color_opt->key = "fill_color";
     bg_color_opt->label = _("Fill color");
-    bg_color_opt->answer = _("black");
     bg_color_opt->guisection = _("Colors");
 
+    text_color_opt = G_define_standard_option(G_OPT_C);
+    text_color_opt->key = "text_color";
+    text_color_opt->label = _("Text color");
+    text_color_opt->answer = NULL;
+    text_color_opt->guisection = _("Colors");
+
     width_opt = G_define_option();
     width_opt->key = "width";
     width_opt->type = TYPE_DOUBLE;
@@ -168,12 +173,21 @@ int main(int argc, char **argv)
         rotation += 2.0 * M_PI;
 
     /* Parse and select foreground color */
-    fg_color = D_parse_color(fg_color_opt->answer, 0);
+    fg_color = D_parse_color(fg_color_opt->answer, 1);
 
     /* Parse and select background color */
     bg_color = D_parse_color(bg_color_opt->answer, 1);
-    if (bg_color == 0)
-        do_background = FALSE;
+
+    /* Parse and select text color */
+    if (text_color_opt->answer)
+        text_color = D_parse_color(text_color_opt->answer, 0);
+    else if (strcmp(fg_color_opt->answer, "none") != 0)
+        text_color = D_parse_color(fg_color_opt->answer, 1);
+    else if (strcmp(bg_color_opt->answer, "none") != 0)
+        text_color = D_parse_color(bg_color_opt->answer, 1);
+    else
+        text_color = 0;
+
 
     line_width = atof(width_opt->answer);
     if (line_width < 0)

+ 1 - 1
display/d.northarrow/options.h

@@ -2,7 +2,7 @@
 /* globals */
 extern int fg_color;
 extern int bg_color;
-extern int do_background;
+extern int text_color;
 
 /* draw_n_arrow.c */
 int draw_n_arrow(double, double, double, char *, int, double, char *, double);