File: gsd_label.c

package info (click to toggle)
grass 6.4.4-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 104,028 kB
  • ctags: 40,409
  • sloc: ansic: 419,980; python: 63,559; tcl: 46,692; cpp: 29,791; sh: 18,564; makefile: 7,000; xml: 3,505; yacc: 561; perl: 559; lex: 480; sed: 70; objc: 7
file content (131 lines) | stat: -rw-r--r-- 2,358 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*!
   \file gsd_label.c

   \brief OGSF library - label management (lower level functions)

   GRASS OpenGL gsurf OGSF Library 

   (C) 1999-2008 by the GRASS Development Team

   This program is free software under the 
   GNU General Public License (>=v2). 
   Read the file COPYING that comes with GRASS
   for details.

   \author Bill Brown USACERL (1991-1992)
   \author Doxygenized by Martin Landa <landa.martin gmail.com> (May 2008)
 */

#include <grass/gis.h>
#include <grass/glocale.h>
#include <grass/gstypes.h>

#include "rgbpack.h"

#define MAX_LIST 20

static int first = 0;
GLuint label_base;
GLuint label_id;

/*!
   \brief Put label

   \todo Allocate label dynamicaly

   \param fontbase fontbase settings
   \param size font size
   \param color font color
   \param pt 
 */
void gs_put_label(const char *text, GLuint fontbase, int size,
		  unsigned long color, int *pt)
{
    int txt_width;
    GLint tmp[4];
    float labpt[2];
    int t, l, b, r;

    if (!first) {
	/* initialize display list */
	label_base = glGenLists(MAX_LIST);
	glListBase(label_base);
	label_id = label_base;
	first = 1;
    }

    if (label_id > (label_base + MAX_LIST)) {
	G_warning(_("Max. number of labels reached!"));
	return;
    }

    glNewList(label_id, GL_COMPILE_AND_EXECUTE);
    txt_width = gsd_get_txtwidth(text, size);

    /* adjust to center text string */
    labpt[X] = (float)(pt[X] - txt_width / 2.);
    labpt[Y] = (float)pt[Y];

    glGetIntegerv(GL_VIEWPORT, tmp);
    l = tmp[0];
    r = tmp[0] + tmp[2];
    b = tmp[1];
    t = tmp[1] + tmp[3];

    gsd_bgn_legend_viewport(l, b, r, t);


    /* Set text color */
    gsd_color_func(color);

    do_label_display(fontbase, labpt, text);


    gsd_end_legend_viewport();

    glEndList();

    label_id++;

    return;
}


/*!
   \brief Remove current label 
 */
void gsd_remove_curr(void)
{
    if (label_id) {
	glDeleteLists(label_id - 1, 1);
	label_id--;
    }

    return;
}


/*!
   \brief Remove all labels from display list
 */
void gsd_remove_all(void)
{
    glDeleteLists(label_base, MAX_LIST);
    label_id = label_base;

    return;
}

/*!
   \brief Call display list and draw defined labels -- called from gsd_prim (gsd_call_lists)
 */
void gsd_call_label(void)
{
    int i;

    for (i = 0; i < MAX_LIST; i++) {
	glCallList(i + label_base);
	glFlush();
    }
    return;
}