~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to display/d.northarrow/draw_n_arrow.c

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * draw_n_arrow() places a north arrow somewhere in the display frame
 
3
 */
 
4
 
 
5
#include <stdio.h>
 
6
#include <string.h>
 
7
#include <grass/gis.h>
 
8
#include <grass/display.h>
 
9
#include <grass/symbol.h>
 
10
#include <grass/colors.h>
 
11
#include <grass/glocale.h>
 
12
#include "options.h"
 
13
 
 
14
int draw_n_arrow(double east, double north, double fontsize,
 
15
                 char *n_arrow_num, double line_width)
 
16
{
 
17
    double x_pos, y_pos;
 
18
    double t, b, l, r;
 
19
    double tt, tb, tl, tr; /* text box*/
 
20
 
 
21
    SYMBOL *Symb;
 
22
    RGBA_Color *line_color, *fill_color;
 
23
    int R, G, B;
 
24
    double x0, y0;
 
25
    char icon[64];
 
26
    double symbol_size;
 
27
 
 
28
 
 
29
    /* Establish text size */
 
30
    if (fontsize > 0)
 
31
        D_text_size(fontsize, fontsize);
 
32
 
 
33
    D_setup_unity(0);
 
34
    D_get_src(&t, &b, &l, &r);
 
35
 
 
36
    x_pos = east * (r - l) / 100.;
 
37
    y_pos = (100. - north) * (b - t) / 100.;
 
38
 
 
39
    if (line_width > 0)
 
40
        D_line_width(line_width);
 
41
 
 
42
    if (fontsize > 0) {
 
43
        /* draw the "N" */
 
44
        D_get_text_box("N", &tt, &tb, &tl, &tr);
 
45
        D_use_color(fg_color);
 
46
 
 
47
        /* positions manually tuned */
 
48
        switch (n_arrow_num[0]) {
 
49
        case '1':
 
50
            D_pos_abs(x_pos - (tr + tl) / 2, y_pos - 45);
 
51
            D_text("N");
 
52
            break;
 
53
        case '3':
 
54
            D_pos_abs(x_pos - (tr + tl) / 2, y_pos - 60);
 
55
            D_text("N");
 
56
            break;
 
57
        case '4':
 
58
            D_pos_abs(x_pos - (tr + tl) / 2, y_pos - 45);
 
59
            D_text("N");
 
60
            break;
 
61
        case '7':
 
62
            D_pos_abs(x_pos - (tr + tl) / 2, y_pos - 70);
 
63
            D_text("N");
 
64
            break;
 
65
        case '9':
 
66
        case 'f':
 
67
            D_pos_abs(x_pos - (tr + tl) / 2, y_pos - 55);
 
68
            D_text("N");
 
69
            break;
 
70
        case 'b':
 
71
            D_pos_abs(x_pos - (tr + tl) / 2, y_pos - 48.5);
 
72
            D_text("N");
 
73
            break;
 
74
        case '2':
 
75
        case '5':
 
76
        case '6':
 
77
        case '8':
 
78
            break;
 
79
        default:
 
80
            G_fatal_error(_("Could not parse symbol"));
 
81
        }
 
82
    }
 
83
 
 
84
    /* display the north arrow symbol */
 
85
    line_color = G_malloc(sizeof(RGBA_Color));
 
86
    fill_color = G_malloc(sizeof(RGBA_Color));
 
87
 
 
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;
 
95
 
 
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;
 
103
 
 
104
    if (n_arrow_num[0] == '2' || n_arrow_num[0] == '9')
 
105
        fill_color->a = RGBA_COLOR_TRANSPARENT;
 
106
 
 
107
    /* sizes manually tuned */
 
108
    switch (n_arrow_num[0]) {
 
109
    case '1':
 
110
        symbol_size = 35.;
 
111
        break;
 
112
    case '2':
 
113
        symbol_size = 19.;
 
114
        break;
 
115
    case '3':
 
116
        symbol_size = 20.;
 
117
        break;
 
118
    case '4':
 
119
        symbol_size = 15.;
 
120
        break;
 
121
    case '5':
 
122
    case '6':
 
123
        symbol_size = 14.;
 
124
        break;
 
125
    case '7':
 
126
        symbol_size = 23.;
 
127
        break;
 
128
    case '8':
 
129
    case '9':
 
130
        symbol_size = 17.;
 
131
        break;
 
132
    case 'b':
 
133
        symbol_size = 80.;
 
134
        break;
 
135
    case 'f':
 
136
        symbol_size = 100.;
 
137
        break;
 
138
    default:
 
139
        G_fatal_error(_("Could not parse symbol"));
 
140
    }
 
141
 
 
142
    x0 = D_d_to_u_col(x_pos);
 
143
    y0 = D_d_to_u_row(y_pos);
 
144
 
 
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");
 
149
    else {
 
150
        strcpy(icon, "n_arrows/n_arrow");
 
151
        strncat(icon, n_arrow_num, 32);
 
152
    }
 
153
 
 
154
    Symb = S_read(icon);
 
155
 
 
156
    if(!Symb)
 
157
        G_fatal_error(_("Could not read symbol \"%s\""), icon);
 
158
 
 
159
    S_stroke(Symb, symbol_size, 0.0, 0);
 
160
    D_symbol(Symb, x0, y0, line_color, fill_color);
 
161
 
 
162
 
 
163
    if (line_width > 0)
 
164
        D_line_width(0);
 
165
 
 
166
    G_free(Symb);
 
167
    G_free(line_color);
 
168
    G_free(fill_color);
 
169
 
 
170
    return 0;
 
171
}