GRASS 8 Programmer's Manual 8.6.0dev(2026)-1d1e47ad9d
Loading...
Searching...
No Matches
symbol.c
Go to the documentation of this file.
1/****************************************************************************
2 *
3 * MODULE: display
4 * AUTHOR(S): Hamish Bowman <hamish_b yahoo.com> (original contributor)
5 * (adapted from Radim Blazek's d.vect code)
6 * Glynn Clements <glynn gclements.plus.com>
7 * PURPOSE: draw a symbol at pixel coordinates
8 * COPYRIGHT: (C) 2005-2007 by M. Hamish Bowman, and
9 * the GRASS Development Team
10 *
11 * This program is free software under the GNU General Public
12 * License (>=v2). Read the file COPYING that comes with GRASS
13 * for details.
14 *
15 *****************************************************************************/
16
17#include <grass/gis.h>
18#include <grass/display.h>
19#include <grass/symbol.h>
20#include <grass/glocale.h>
21
22static void symbol(const SYMBOL *Symb, double x0, double y0,
25{
26 int i, j, k;
27 const SYMBPART *part;
28 const SYMBCHAIN *chain;
29 double xp, yp;
30 double *x, *y;
31 double sx = D_get_d_to_u_xconv();
32 double sy = D_get_d_to_u_yconv();
33
34 G_debug(2, "D_symbol(): %d parts", Symb->count);
35
36 for (i = 0; i < Symb->count; i++) {
37 part = Symb->part[i];
38
39 switch (part->type) {
40
41 case S_POLYGON:
42 /* draw background fills */
43 if ((part->fcolor.color == S_COL_DEFAULT &&
45 part->fcolor.color == S_COL_DEFINED) {
46 if (part->fcolor.color == S_COL_DEFAULT)
48 else
49 D_RGB_color(part->fcolor.r, part->fcolor.g, part->fcolor.b);
50
51 for (j = 0; j < part->count;
52 j++) { /* for each component polygon */
53 chain = part->chain[j];
54
55 x = G_malloc(sizeof(double) * chain->scount);
56 y = G_malloc(sizeof(double) * chain->scount);
57
58 for (k = 0; k < chain->scount; k++) {
59 x[k] = x0 + sx * chain->sx[k];
60 y[k] = y0 - sy * chain->sy[k];
61 }
62 D_polygon_abs(x, y, chain->scount);
63
64 G_free(x);
65 G_free(y);
66 }
67 }
68 /* again, to draw the lines */
69 if ((part->color.color == S_COL_DEFAULT &&
71 part->color.color == S_COL_DEFINED) {
72 if (part->color.color == S_COL_DEFAULT)
74 else
75 D_RGB_color(part->color.r, part->color.g, part->color.b);
76
77 for (j = 0; j < part->count; j++) {
78 chain = part->chain[j];
79
80 D_begin();
81 for (k = 0; k < chain->scount; k++) {
82 xp = x0 + sx * chain->sx[k];
83 yp = y0 - sy * chain->sy[k];
84 if (k == 0)
86 else
88 }
89 D_end();
90 D_stroke();
91 }
92 }
93 break;
94
95 case S_STRING:
96 if (part->color.color == S_COL_NONE)
97 break;
98 else if (part->color.color == S_COL_DEFAULT &&
101 else
102 D_RGB_color(part->color.r, part->color.g, part->color.b);
103
104 chain = part->chain[0];
105
106 D_begin();
107 for (j = 0; j < chain->scount; j++) {
108 xp = x0 + sx * chain->sx[j];
109 yp = y0 - sy * chain->sy[j];
110 if (j == 0)
111 D_move_abs(xp, yp);
112 else
113 D_cont_abs(xp, yp);
114 }
115 D_end();
116 D_stroke();
117 break;
118
119 } /* switch */
120 } /* for loop */
121}
122
123/*!
124 * \brief draw a symbol at pixel coordinates
125 *
126 * Draws a symbol (one of $GISBASE/etc/symbols/) to the active display.
127 * The starting x0,y0 coordinate corresponds to the center of the icon.
128 * The symbol must be pre-processed with S_stroke() before being sent
129 * to this function.
130 *
131 * \par Example
132 * \code
133 * #include <grass/display.h>
134 * #include <grass/symbol.h>
135 * ...
136 * SYMBOL *Symb;
137 * Symb = S_read( symbol_name );
138 * S_stroke( Symb, size, rotation, tolerance );
139 * D_symbol( Symb, x0, y0, line_color, fill_color );
140 * \endcode
141 *
142 * \param Symb The symbol name (e.g. basic/circle)
143 * \param x0 The starting x display coordinate (pixel)
144 * \param y0 The starting y display coordinate (pixel)
145 * \param line_color Outline color
146 * \param fill_color Fill color
147 * \return void
148 */
149void D_symbol(const SYMBOL *Symb, double x0, double y0,
151{
152 symbol(Symb, x0, y0, fill_color, line_color, line_color);
153}
154
155/*!
156 * \brief draw a symbol at pixel coordinates (alternate)
157 *
158 * Draws a symbol (one of $GISBASE/etc/symbols/) to the active display.
159 * The same as D_symbol(), but it uses a primary and secondary color
160 * instead of line and fill color. The primary color is used to draw
161 * stroke lines (STRINGs) and as the fill color for polygons. The secondary
162 * color is used for polygon outlines.
163 *
164 * \param Symb The symbol name (e.g. basic/circle)
165 * \param x0 The starting x display coordinate (pixel)
166 * \param y0 The starting y display coordinate (pixel)
167 * \param primary_color Primary draw color
168 * \param secondary_color Secondary draw color
169 * \return void
170 */
171void D_symbol2(const SYMBOL *Symb, double x0, double y0,
174{
176}
double D_get_d_to_u_yconv(void)
Definition cnversions.c:172
void D_stroke(void)
Definition draw2.c:324
void D_cont_abs(double, double)
Definition draw2.c:311
void D_end(void)
Definition draw2.c:297
void D_polygon_abs(const double *, const double *, int)
Definition draw2.c:387
void D_RGB_color(int, int, int)
Definition tran_colr.c:213
void D_move_abs(double, double)
Definition draw2.c:303
void D_begin(void)
Definition draw2.c:292
double D_get_d_to_u_xconv(void)
Definition cnversions.c:168
void G_free(void *)
Free allocated memory.
Definition gis/alloc.c:147
#define G_malloc(n)
Definition defs/gis.h:139
int G_debug(int, const char *,...) __attribute__((format(printf
#define RGBA_COLOR_NONE
Definition display.h:17
double * sy
Definition symbol.h:48
int scount
Definition symbol.h:47
double * sx
Definition symbol.h:48
int b
Definition symbol.h:24
int r
Definition symbol.h:24
int color
Definition symbol.h:23
int g
Definition symbol.h:24
SYMBCHAIN ** chain
Definition symbol.h:57
SYMBCOLOR fcolor
Definition symbol.h:55
SYMBCOLOR color
Definition symbol.h:54
int type
Definition symbol.h:53
int count
Definition symbol.h:56
void D_symbol2(const SYMBOL *Symb, double x0, double y0, const RGBA_Color *primary_color, const RGBA_Color *secondary_color)
draw a symbol at pixel coordinates (alternate)
Definition symbol.c:171
void D_symbol(const SYMBOL *Symb, double x0, double y0, const RGBA_Color *line_color, const RGBA_Color *fill_color)
draw a symbol at pixel coordinates
Definition symbol.c:149
#define S_STRING
Definition symbol.h:15
#define S_COL_DEFAULT
Definition symbol.h:18
#define S_COL_NONE
Definition symbol.h:19
#define S_POLYGON
Definition symbol.h:16
#define S_COL_DEFINED
Definition symbol.h:20
#define x