[GRASS-SVN] r68950 - grass/trunk/display/d.northarrow

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Jul 12 12:28:12 PDT 2016


Author: annakrat
Date: 2016-07-12 12:28:12 -0700 (Tue, 12 Jul 2016)
New Revision: 68950

Modified:
   grass/trunk/display/d.northarrow/draw_n_arrow.c
   grass/trunk/display/d.northarrow/main.c
   grass/trunk/display/d.northarrow/options.h
Log:
d.northarrow: enable transparent fill color, see #3044

Modified: grass/trunk/display/d.northarrow/draw_n_arrow.c
===================================================================
--- grass/trunk/display/d.northarrow/draw_n_arrow.c	2016-07-12 19:06:28 UTC (rev 68949)
+++ grass/trunk/display/d.northarrow/draw_n_arrow.c	2016-07-12 19:28:12 UTC (rev 68950)
@@ -46,7 +46,7 @@
         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,24 +114,22 @@
     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]) {
     case '1':

Modified: grass/trunk/display/d.northarrow/main.c
===================================================================
--- grass/trunk/display/d.northarrow/main.c	2016-07-12 19:06:28 UTC (rev 68949)
+++ grass/trunk/display/d.northarrow/main.c	2016-07-12 19:28:12 UTC (rev 68950)
@@ -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 @@
         _("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,13 +173,22 @@
         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)
         line_width = 0;

Modified: grass/trunk/display/d.northarrow/options.h
===================================================================
--- grass/trunk/display/d.northarrow/options.h	2016-07-12 19:06:28 UTC (rev 68949)
+++ grass/trunk/display/d.northarrow/options.h	2016-07-12 19:28:12 UTC (rev 68950)
@@ -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);



More information about the grass-commit mailing list