2
* draw_n_arrow() places a north arrow somewhere in the display frame
8
#include <grass/display.h>
9
#include <grass/symbol.h>
10
#include <grass/colors.h>
11
#include <grass/glocale.h>
14
int draw_n_arrow(double east, double north, double fontsize,
15
char *n_arrow_num, double line_width)
19
double tt, tb, tl, tr; /* text box*/
22
RGBA_Color *line_color, *fill_color;
29
/* Establish text size */
31
D_text_size(fontsize, fontsize);
34
D_get_src(&t, &b, &l, &r);
36
x_pos = east * (r - l) / 100.;
37
y_pos = (100. - north) * (b - t) / 100.;
40
D_line_width(line_width);
44
D_get_text_box("N", &tt, &tb, &tl, &tr);
45
D_use_color(fg_color);
47
/* positions manually tuned */
48
switch (n_arrow_num[0]) {
50
D_pos_abs(x_pos - (tr + tl) / 2, y_pos - 45);
54
D_pos_abs(x_pos - (tr + tl) / 2, y_pos - 60);
58
D_pos_abs(x_pos - (tr + tl) / 2, y_pos - 45);
62
D_pos_abs(x_pos - (tr + tl) / 2, y_pos - 70);
67
D_pos_abs(x_pos - (tr + tl) / 2, y_pos - 55);
71
D_pos_abs(x_pos - (tr + tl) / 2, y_pos - 48.5);
80
G_fatal_error(_("Could not parse symbol"));
84
/* display the north arrow symbol */
85
line_color = G_malloc(sizeof(RGBA_Color));
86
fill_color = G_malloc(sizeof(RGBA_Color));
88
if (D_color_number_to_RGB(fg_color, &R, &G, &B) == 0)
89
/* fall back to black on failure */
90
G_str_to_color(DEFAULT_FG_COLOR, &R, &G, &B);
91
line_color->r = (unsigned char)R;
92
line_color->g = (unsigned char)G;
93
line_color->b = (unsigned char)B;
94
line_color->a = RGBA_COLOR_OPAQUE;
96
if (D_color_number_to_RGB(bg_color, &R, &G, &B) == 0)
97
/* fall back to black on failure */
98
G_str_to_color(DEFAULT_FG_COLOR, &R, &G, &B);
99
fill_color->r = (unsigned char)R;
100
fill_color->g = (unsigned char)G;
101
fill_color->b = (unsigned char)B;
102
fill_color->a = RGBA_COLOR_OPAQUE;
104
if (n_arrow_num[0] == '2' || n_arrow_num[0] == '9')
105
fill_color->a = RGBA_COLOR_TRANSPARENT;
107
/* sizes manually tuned */
108
switch (n_arrow_num[0]) {
139
G_fatal_error(_("Could not parse symbol"));
142
x0 = D_d_to_u_col(x_pos);
143
y0 = D_d_to_u_row(y_pos);
145
if (n_arrow_num[0] == 'b')
146
strcpy(icon, "n_arrows/basic_compass");
147
else if (n_arrow_num[0] == 'f')
148
strcpy(icon, "n_arrows/fancy_compass");
150
strcpy(icon, "n_arrows/n_arrow");
151
strncat(icon, n_arrow_num, 32);
157
G_fatal_error(_("Could not read symbol \"%s\""), icon);
159
S_stroke(Symb, symbol_size, 0.0, 0);
160
D_symbol(Symb, x0, y0, line_color, fill_color);