GRASS 8 Programmer's Manual 8.6.0dev(2026)-d2adb3a889
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 * SPDX-FileCopyrightText: 2005-2007 M. Hamish Bowman
9 * SPDX-FileCopyrightText: GRASS Development Team
10 * SPDX-License-Identifier: GPL-2.0-or-later
11 *
12 *****************************************************************************/
13
14#include <grass/gis.h>
15#include <grass/display.h>
16#include <grass/symbol.h>
17#include <grass/glocale.h>
18
19static void symbol(const SYMBOL *Symb, double x0, double y0,
22{
23 int i, j, k;
24 const SYMBPART *part;
25 const SYMBCHAIN *chain;
26 double xp, yp;
27 double *x, *y;
28 double sx = D_get_d_to_u_xconv();
29 double sy = D_get_d_to_u_yconv();
30
31 G_debug(2, "D_symbol(): %d parts", Symb->count);
32
33 for (i = 0; i < Symb->count; i++) {
34 part = Symb->part[i];
35
36 switch (part->type) {
37
38 case S_POLYGON:
39 /* draw background fills */
40 if ((part->fcolor.color == S_COL_DEFAULT &&
42 part->fcolor.color == S_COL_DEFINED) {
43 if (part->fcolor.color == S_COL_DEFAULT)
45 else
46 D_RGB_color(part->fcolor.r, part->fcolor.g, part->fcolor.b);
47
48 for (j = 0; j < part->count;
49 j++) { /* for each component polygon */
50 chain = part->chain[j];
51
52 x = G_malloc(sizeof(double) * chain->scount);
53 y = G_malloc(sizeof(double) * chain->scount);
54
55 for (k = 0; k < chain->scount; k++) {
56 x[k] = x0 + sx * chain->sx[k];
57 y[k] = y0 - sy * chain->sy[k];
58 }
59 D_polygon_abs(x, y, chain->scount);
60
61 G_free(x);
62 G_free(y);
63 }
64 }
65 /* again, to draw the lines */
66 if ((part->color.color == S_COL_DEFAULT &&
68 part->color.color == S_COL_DEFINED) {
69 if (part->color.color == S_COL_DEFAULT)
71 else
72 D_RGB_color(part->color.r, part->color.g, part->color.b);
73
74 for (j = 0; j < part->count; j++) {
75 chain = part->chain[j];
76
77 D_begin();
78 for (k = 0; k < chain->scount; k++) {
79 xp = x0 + sx * chain->sx[k];
80 yp = y0 - sy * chain->sy[k];
81 if (k == 0)
83 else
85 }
86 D_end();
87 D_stroke();
88 }
89 }
90 break;
91
92 case S_STRING:
93 if (part->color.color == S_COL_NONE)
94 break;
95 else if (part->color.color == S_COL_DEFAULT &&
98 else
99 D_RGB_color(part->color.r, part->color.g, part->color.b);
100
101 chain = part->chain[0];
102
103 D_begin();
104 for (j = 0; j < chain->scount; j++) {
105 xp = x0 + sx * chain->sx[j];
106 yp = y0 - sy * chain->sy[j];
107 if (j == 0)
108 D_move_abs(xp, yp);
109 else
110 D_cont_abs(xp, yp);
111 }
112 D_end();
113 D_stroke();
114 break;
115
116 } /* switch */
117 } /* for loop */
118}
119
120/*!
121 * \brief draw a symbol at pixel coordinates
122 *
123 * Draws a symbol (one of $GISBASE/etc/symbols/) to the active display.
124 * The starting x0,y0 coordinate corresponds to the center of the icon.
125 * The symbol must be pre-processed with S_stroke() before being sent
126 * to this function.
127 *
128 * \par Example
129 * \code
130 * #include <grass/display.h>
131 * #include <grass/symbol.h>
132 * ...
133 * SYMBOL *Symb;
134 * Symb = S_read( symbol_name );
135 * S_stroke( Symb, size, rotation, tolerance );
136 * D_symbol( Symb, x0, y0, line_color, fill_color );
137 * \endcode
138 *
139 * \param Symb The symbol name (e.g. basic/circle)
140 * \param x0 The starting x display coordinate (pixel)
141 * \param y0 The starting y display coordinate (pixel)
142 * \param line_color Outline color
143 * \param fill_color Fill color
144 * \return void
145 */
146void D_symbol(const SYMBOL *Symb, double x0, double y0,
148{
149 symbol(Symb, x0, y0, fill_color, line_color, line_color);
150}
151
152/*!
153 * \brief draw a symbol at pixel coordinates (alternate)
154 *
155 * Draws a symbol (one of $GISBASE/etc/symbols/) to the active display.
156 * The same as D_symbol(), but it uses a primary and secondary color
157 * instead of line and fill color. The primary color is used to draw
158 * stroke lines (STRINGs) and as the fill color for polygons. The secondary
159 * color is used for polygon outlines.
160 *
161 * \param Symb The symbol name (e.g. basic/circle)
162 * \param x0 The starting x display coordinate (pixel)
163 * \param y0 The starting y display coordinate (pixel)
164 * \param primary_color Primary draw color
165 * \param secondary_color Secondary draw color
166 * \return void
167 */
168void D_symbol2(const SYMBOL *Symb, double x0, double y0,
171{
173}
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:145
#define G_malloc(n)
Definition defs/gis.h:136
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:168
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:146
#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