[GRASS-SVN] r68542 - grass/trunk/display/d.grid
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon May 30 14:09:41 PDT 2016
Author: annakrat
Date: 2016-05-30 14:09:41 -0700 (Mon, 30 May 2016)
New Revision: 68542
Modified:
grass/trunk/display/d.grid/d.grid.html
grass/trunk/display/d.grid/local_proto.h
grass/trunk/display/d.grid/main.c
grass/trunk/display/d.grid/plot.c
Log:
d.grid: add bgcolor, see #3017, author Adam Laza
Modified: grass/trunk/display/d.grid/d.grid.html
===================================================================
--- grass/trunk/display/d.grid/d.grid.html 2016-05-30 20:32:24 UTC (rev 68541)
+++ grass/trunk/display/d.grid/d.grid.html 2016-05-30 21:09:41 UTC (rev 68542)
@@ -3,49 +3,26 @@
<em>d.grid</em> overlays a grid of user-defined size and
color in the active display frame on the graphics monitor.
The grid can be created as a standard rectangular grid or
-a geographic grid. The grid will overlay, not overwrite,
-the contents of the active display frame.
+a geographic grid.
<p>
-<em>d.grid</em> can be run non-interactively or
-interactively. If the user specifies the grid
-<em>size</em> and (optionally) the grid <em>color</em> on
-the command line the program will run non-interactively; if
-no grid <em>color</em> is given the default will be used.
-Alternately, the user may simply type <b>d.grid</b> on the
-command line; in this case, the program will prompt the
-user for parameter values using the standard GRASS graphical
-user interface.
-
-
-<h2>NOTES</h2>
-
-<em>d.grid</em> will not erase grids already displayed in
-the active graphics display frame by previous invocations
-of <em>d.grid</em>; multiple invocations of <em>d.grid</em>
-will therefore result in the drawing of multiple grids
-inside the active graphics frame. (A command like
-<em><a href="d.erase.html">d.erase</a></em>, which erases the
-entire contents of the active display frame, must be run to
-erase previously drawn grids from the display frame.)
-
-<p>
-If the user provides a <em>-g</em> flag a geographic (projected) grid
-will be drawn. With the <em>-g</em> flag the <em>size</em>
+If the user provides a <b>-g</b> flag a geographic (projected) grid
+will be drawn. With the <b>-g</b> flag the <b>size</b>
argument accepts both decimal degrees and colon separated
ddd:mm:ss coordinates (eg. <tt>00:30:00</tt> for half of a degree).
-
-<p>
A geographic grid cannot be drawn for a <em>latitude/longitude</em>
or <em>XY</em> projection.
+
<p>
Colors may be standard named GRASS colors (red, green, aqua, etc.) or
-a numerical R:G:B triplet, where component values range from 0-255.<br>
+a numerical R:G:B triplet, where component values range from 0-255.
+Grid color can be set with option <b>color</b>. Options <b>text_color</b> and
+<b>bgcolor</b> set the color of the text and its background.
<p>
-The grid drawing may be turned off by using the <em>-n</em> flag.<br>
-The border drawing may be turned off by using the <em>-b</em> flag.<br>
-The coordinate text may be turned off by using the <em>-t</em> flag.<br>
+The grid drawing may be turned off by using the <b>-n</b> flag.<br>
+The border drawing may be turned off by using the <b>-b</b> flag.<br>
+The coordinate text may be turned off by using the <b>-t</b> flag.<br>
<p>
To draw grid lines at different intervals, e.g. at high latitudes, you
@@ -94,6 +71,7 @@
Geogrid support: Bob Covill<br>
Border support: Markus Neteler<br>
Text and RGB support: Hamish Bowman<br>
+Background color implemented as part of GSoC 2016 by Adam Laza, CTU in Prague
<p>
<i>Last changed: $Date$</i>
Modified: grass/trunk/display/d.grid/local_proto.h
===================================================================
--- grass/trunk/display/d.grid/local_proto.h 2016-05-30 20:32:24 UTC (rev 68541)
+++ grass/trunk/display/d.grid/local_proto.h 2016-05-30 21:09:41 UTC (rev 68542)
@@ -5,9 +5,10 @@
#define DIRN_LON 2
/* plot.c */
-int plot_grid(double, double, double, int, int, int, int, int, double, int);
+int plot_grid(double, double, double, int, int, int, int, int, int, double,
+ int);
int plot_geogrid(double, struct pj_info, struct pj_info, int, int, int, int,
- int, double, int);
+ int, int, double, int);
void init_proj(struct pj_info *, struct pj_info *, int);
void get_ll_bounds(double *, double *, double *, double *, struct Cell_head,
struct pj_info, struct pj_info);
Modified: grass/trunk/display/d.grid/main.c
===================================================================
--- grass/trunk/display/d.grid/main.c 2016-05-30 20:32:24 UTC (rev 68541)
+++ grass/trunk/display/d.grid/main.c 2016-05-30 21:09:41 UTC (rev 68542)
@@ -33,12 +33,13 @@
int colorg = 0;
int colorb = 0;
int colort = 0;
+ int colorbg = 0;
double size = 0., gsize = 0.; /* initialize to zero */
double east, north;
int do_text, fontsize, mark_type, line_width, dirn;
struct GModule *module;
struct Option *opt1, *opt2, *opt3, *opt4, *fsize, *tcolor, *lwidth,
- *direction;
+ *direction, *bgcolor;
struct Flag *noborder, *notext, *geogrid, *nogrid, *wgs84, *cross,
*fiducial, *dot, *align;
struct pj_info info_in; /* Proj structures */
@@ -105,6 +106,12 @@
tcolor->label = _("Text color");
tcolor->guisection = _("Color");
+ bgcolor = G_define_standard_option(G_OPT_CN);
+ bgcolor->key = "bgcolor";
+ bgcolor->answer = "none";
+ bgcolor->label = _("Background color");
+ bgcolor->guisection = _("Color");
+
fsize = G_define_option();
fsize->key = "fontsize";
fsize->type = TYPE_INTEGER;
@@ -269,6 +276,8 @@
colorb = D_parse_color(opt4->answer, FALSE);
/* Parse and select text color */
colort = D_parse_color(tcolor->answer, FALSE);
+ /* Parse and select background color */
+ colorbg = D_parse_color(bgcolor->answer, TRUE);
D_setup(0);
@@ -279,12 +288,12 @@
/* initialzie proj stuff */
init_proj(&info_in, &info_out, wgs84->answer);
plot_geogrid(gsize, info_in, info_out, do_text, colorg, colort,
- fontsize, mark_type, line_width, dirn);
+ colorbg, fontsize, mark_type, line_width, dirn);
}
else {
/* Do the grid plotting */
- plot_grid(size, east, north, do_text, colorg, colort, fontsize,
- mark_type, line_width, dirn);
+ plot_grid(size, east, north, do_text, colorg, colort, colorbg,
+ fontsize, mark_type, line_width, dirn);
}
}
Modified: grass/trunk/display/d.grid/plot.c
===================================================================
--- grass/trunk/display/d.grid/plot.c 2016-05-30 20:32:24 UTC (rev 68541)
+++ grass/trunk/display/d.grid/plot.c 2016-05-30 21:09:41 UTC (rev 68542)
@@ -10,14 +10,15 @@
int plot_grid(double grid_size, double east, double north, int do_text,
- int gcolor, int tcolor, int fontsize, int mark_type,
- double line_width, int direction)
+ int gcolor, int tcolor, int bgcolor, int fontsize,
+ int mark_type, double line_width, int direction)
{
double x, y, y0;
double e1, e2;
struct Cell_head window;
double row_dist, colm_dist;
char text[128];
+ double tx, ty, bt, bb, bl, br, w, h;
G_get_set_window(&window);
@@ -56,10 +57,27 @@
fontsize*.81 = actual text width FOR DEFAULT FONT (NOT FreeType)
*/
D_pos_abs(x + 4.5 * D_get_d_to_u_xconv(), D_get_u_south()
- -
- D_get_d_to_u_yconv() * (strlen(text) * fontsize *
- 0.81 + 7.5));
+ - D_get_d_to_u_yconv() * (strlen(text)
+ * fontsize * 0.81 + 7.5));
+ tx = x + 4.5 * D_get_d_to_u_xconv();
+ ty = D_get_u_south() -
+ D_get_d_to_u_yconv() * (strlen(text) * fontsize * 0.81 + 7.5);
+
+ if (bgcolor != 0) {
+ D_get_text_box(text, &bt, &bb, &bl, &br);
+ w = br - bl;
+ h = bt - bb;
+ bl = tx - w/2;
+ bt = ty + h/10;
+ br = tx + w + w/2;
+ bb = ty - h - h/10;
+ D_use_color(bgcolor);
+ D_box_abs(bl, bt, br, bb);
+ }
+
+ D_use_color(tcolor);
+ D_pos_abs(tx, ty);
D_text(text);
}
x += grid_size;
@@ -110,6 +128,37 @@
0.81 + 7.5),
y - D_get_d_to_u_yconv() * 4.5);
+ tx = D_get_u_east() -
+ D_get_d_to_u_xconv() * (strlen(text) * fontsize * 0.81 +
+ 7.5);
+ ty = y - D_get_d_to_u_yconv() * 4.5;
+
+ if (bgcolor != 0) {
+ D_get_text_box(text, &bt, &bb, &bl, &br);
+ w = br - bl;
+ h = bt - bb;
+
+ if (w > 0)
+ w += 0.2 * fontsize;
+ else
+ /* D_text() does not draw " ". */
+ w = 0.8 * fontsize;
+ if (h > 0)
+ h += 0.2 * fontsize;
+ else
+ /* D_text() does not draw " ". */
+ h = 0.8 * fontsize;
+
+ bl = tx - w/10;
+ bt = ty + h + h/2;
+ br = tx + w + w/10;
+ bb = ty - h/2;
+ D_use_color(bgcolor);
+ D_box_abs(bl, bt, br, bb);
+ }
+
+ D_use_color(tcolor);
+ D_pos_abs(tx, ty);
D_text(text);
}
y += grid_size;
@@ -150,7 +199,7 @@
int plot_geogrid(double size, struct pj_info info_in, struct pj_info info_out,
- int do_text, int gcolor, int tcolor, int fontsize,
+ int do_text, int gcolor, int tcolor, int bgcolor, int fontsize,
int mark_type, double line_width, int direction)
{
double g;
@@ -167,6 +216,7 @@
double row_dist, colm_dist;
float font_angle;
struct Cell_head window;
+ double tx, ty, bt, bb, bl, br, w, h;
/* geo current region */
G_get_set_window(&window);
@@ -232,10 +282,26 @@
G_format_northing(g, text, PROJECTION_LL);
D_text_rotation(font_angle);
D_text_size(fontsize, fontsize);
- D_pos_abs(D_get_u_west() + D_get_d_to_u_xconv() * border_off,
- start_coord - D_get_d_to_u_yconv() * grid_off);
+ tx = D_get_u_west() + D_get_d_to_u_xconv() * border_off;
+ ty = start_coord - D_get_d_to_u_yconv() * grid_off;
+
+ if (bgcolor != 0) {
+ D_get_text_box(text, &bt, &bb, &bl, &br);
+ w = br - bl;
+ h = bt - bb;
+ bl = tx - w/10;
+ bt = ty + h + h/2;
+ br = tx + w + w/10;
+ bb = ty - h/2;
+ D_use_color(bgcolor);
+ D_box_abs(bl, bt, br, bb);
+ }
+
+ D_use_color(tcolor);
+ D_pos_abs(tx, ty);
D_text(text);
}
+
}
/* Lines of Longitude */
@@ -300,9 +366,24 @@
G_format_easting(g, text, PROJECTION_LL);
D_text_rotation(font_angle);
D_text_size(fontsize, fontsize);
- D_pos_abs(start_coord + D_get_d_to_u_xconv() * (grid_off + 1.5),
- D_get_u_north() + D_get_d_to_u_yconv() *
- (border_off + extra_y_off));
+ tx = start_coord + D_get_d_to_u_xconv() * (grid_off + 1.5);
+ ty = D_get_u_north() + D_get_d_to_u_yconv() * (border_off +
+ extra_y_off);
+
+ if (bgcolor != 0) {
+ D_get_text_box(text, &bt, &bb, &bl, &br);
+ w = br - bl;
+ h = bt - bb;
+ bl = tx - w/2;
+ bt = ty + h/10;
+ br = tx + w + w/2;
+ bb = ty - h - h/10;
+ D_use_color(bgcolor);
+ D_box_abs(bl, bt, br, bb);
+ }
+
+ D_use_color(tcolor);
+ D_pos_abs(tx, ty);
D_text(text);
}
}
More information about the grass-commit
mailing list