GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
symbol.c
Go to the documentation of this file.
1 
2 /****************************************************************************
3  *
4  * MODULE: display
5  * AUTHOR(S): Hamish Bowman <hamish_b yahoo.com> (original contributor)
6  * (adapted from Radim Blazek's d.vect code)
7  * Glynn Clements <glynn gclements.plus.com>
8  * PURPOSE: draw a symbol at pixel coordinates
9  * COPYRIGHT: (C) 2005-2007 by M. Hamish Bowman, and
10  * the GRASS Development Team
11  *
12  * This program is free software under the GNU General Public
13  * License (>=v2). Read the file COPYING that comes with GRASS
14  * for details.
15  *
16  *****************************************************************************/
17 
18 #include <grass/gis.h>
19 #include <grass/raster.h>
20 #include <grass/symbol.h>
21 #include <grass/glocale.h>
22 
47 void D_symbol(const SYMBOL * Symb, int x0, int y0,
48  const RGBA_Color * line_color, const RGBA_Color * fill_color)
49 {
50  int i, j, k;
51  const SYMBPART *part;
52  const SYMBCHAIN *chain;
53  int xp, yp;
54  int *x, *y;
55 
56 
57  G_debug(2, "D_symbol(): %d parts", Symb->count);
58 
59  for (i = 0; i < Symb->count; i++) {
60  part = Symb->part[i];
61 
62  switch (part->type) {
63 
64  case S_POLYGON:
65  /* draw background fills */
66  if ((part->fcolor.color == S_COL_DEFAULT &&
67  fill_color->a != RGBA_COLOR_NONE) ||
68  part->fcolor.color == S_COL_DEFINED) {
69  if (part->fcolor.color == S_COL_DEFAULT)
70  R_RGB_color(fill_color->r, fill_color->g, fill_color->b);
71  else
72  R_RGB_color(part->fcolor.r, part->fcolor.g,
73  part->fcolor.b);
74 
75  for (j = 0; j < part->count; j++) { /* for each component polygon */
76  chain = part->chain[j];
77 
78  x = G_malloc(sizeof(int) * chain->scount);
79  y = G_malloc(sizeof(int) * chain->scount);
80 
81  for (k = 0; k < chain->scount; k++) {
82  x[k] = x0 + chain->sx[k];
83  y[k] = y0 - chain->sy[k];
84  }
85  R_polygon_abs(x, y, chain->scount);
86 
87  G_free(x);
88  G_free(y);
89  }
90 
91  }
92  /* again, to draw the lines */
93  if ((part->color.color == S_COL_DEFAULT &&
94  line_color->a != RGBA_COLOR_NONE) ||
95  part->color.color == S_COL_DEFINED) {
96  if (part->color.color == S_COL_DEFAULT) {
97  R_RGB_color(line_color->r, line_color->g, line_color->b);
98  }
99  else
100  R_RGB_color(part->color.r, part->color.g, part->color.b);
101 
102  for (j = 0; j < part->count; j++) {
103  chain = part->chain[j];
104 
105  for (k = 0; k < chain->scount; k++) {
106  xp = x0 + chain->sx[k];
107  yp = y0 - chain->sy[k];
108  if (k == 0)
109  R_move_abs(xp, yp);
110  else
111  R_cont_abs(xp, yp);
112  }
113  }
114  }
115  break;
116 
117  case S_STRING:
118  if (part->color.color == S_COL_NONE)
119  break;
120  else if (part->color.color == S_COL_DEFAULT &&
121  line_color->a != RGBA_COLOR_NONE)
122  R_RGB_color(line_color->r, line_color->g, line_color->b);
123  else
124  R_RGB_color(part->color.r, part->color.g, part->color.b);
125 
126  chain = part->chain[0];
127 
128  for (j = 0; j < chain->scount; j++) {
129  xp = x0 + chain->sx[j];
130  yp = y0 - chain->sy[j];
131  if (j == 0)
132  R_move_abs(xp, yp);
133  else
134  R_cont_abs(xp, yp);
135  }
136  break;
137 
138  } /* switch */
139  } /* for loop */
140 }
141 
142 
159 void D_symbol2(const SYMBOL * Symb, int x0, int y0,
160  const RGBA_Color * primary_color,
161  const RGBA_Color * secondary_color)
162 {
163  /* TODO: merge duplicate D_symbol() code into common lib fns */
164  int i, j, k;
165  const SYMBPART *part;
166  const SYMBCHAIN *chain;
167  int xp, yp;
168  int *x, *y;
169 
170 
171  G_debug(2, "D_symbol(): %d parts", Symb->count);
172 
173  for (i = 0; i < Symb->count; i++) {
174  part = Symb->part[i];
175 
176  switch (part->type) {
177 
178  case S_POLYGON:
179  /* draw background fills */
180  if ((part->fcolor.color == S_COL_DEFAULT &&
181  primary_color->a != RGBA_COLOR_NONE) ||
182  part->fcolor.color == S_COL_DEFINED) {
183  if (part->fcolor.color == S_COL_DEFAULT)
184  R_RGB_color(primary_color->r, primary_color->g,
185  primary_color->b);
186  else
187  R_RGB_color(part->fcolor.r, part->fcolor.g,
188  part->fcolor.b);
189 
190  for (j = 0; j < part->count; j++) { /* for each component polygon */
191  chain = part->chain[j];
192 
193  x = G_malloc(sizeof(int) * chain->scount);
194  y = G_malloc(sizeof(int) * chain->scount);
195 
196  for (k = 0; k < chain->scount; k++) {
197  x[k] = x0 + chain->sx[k];
198  y[k] = y0 - chain->sy[k];
199  }
200  R_polygon_abs(x, y, chain->scount);
201 
202  G_free(x);
203  G_free(y);
204  }
205 
206  }
207  /* again, to draw the lines */
208  if ((part->color.color == S_COL_DEFAULT &&
209  secondary_color->a != RGBA_COLOR_NONE) ||
210  part->color.color == S_COL_DEFINED) {
211  if (part->color.color == S_COL_DEFAULT) {
212  R_RGB_color(secondary_color->r, secondary_color->g,
213  secondary_color->b);
214  }
215  else
216  R_RGB_color(part->color.r, part->color.g, part->color.b);
217 
218  for (j = 0; j < part->count; j++) {
219  chain = part->chain[j];
220 
221  for (k = 0; k < chain->scount; k++) {
222  xp = x0 + chain->sx[k];
223  yp = y0 - chain->sy[k];
224  if (k == 0)
225  R_move_abs(xp, yp);
226  else
227  R_cont_abs(xp, yp);
228  }
229  }
230  }
231  break;
232 
233  case S_STRING:
234  if (part->color.color == S_COL_NONE)
235  break;
236  else if (part->color.color == S_COL_DEFAULT &&
237  primary_color->a != RGBA_COLOR_NONE)
238  R_RGB_color(primary_color->r, primary_color->g,
239  primary_color->b);
240  else
241  R_RGB_color(part->color.r, part->color.g, part->color.b);
242 
243  chain = part->chain[0];
244 
245  for (j = 0; j < chain->scount; j++) {
246  xp = x0 + chain->sx[j];
247  yp = y0 - chain->sy[j];
248  if (j == 0)
249  R_move_abs(xp, yp);
250  else
251  R_cont_abs(xp, yp);
252  }
253  break;
254 
255  } /* switch */
256  } /* for loop */
257 }
void R_polygon_abs(const int *xarray, const int *yarray, int number)
draw a closed polygon
Definition: com_proto.c:311
void G_free(void *buf)
Free allocated memory.
Definition: gis/alloc.c:142
void D_symbol(const SYMBOL *Symb, int x0, int y0, const RGBA_Color *line_color, const RGBA_Color *fill_color)
draw a symbol at pixel coordinates
Definition: symbol.c:47
int y
Definition: plot.c:34
void R_cont_abs(int x, int y)
draw line
Definition: com_proto.c:190
void R_move_abs(int x, int y)
move current location
Definition: com_proto.c:153
void D_symbol2(const SYMBOL *Symb, int x0, int y0, const RGBA_Color *primary_color, const RGBA_Color *secondary_color)
draw a symbol at pixel coordinates (alternate)
Definition: symbol.c:159
int G_debug(int level, const char *msg,...)
Print debugging message.
Definition: gis/debug.c:51
void R_RGB_color(unsigned char red, unsigned char grn, unsigned char blu)
select color
Definition: com_proto.c:109