GRASS GIS 8 Programmer's Manual  8.2.2dev(2023)-3d2c704037
gsd_label.c
Go to the documentation of this file.
1 /*!
2  \file lib/ogsf/gsd_label.c
3 
4  \brief OGSF library - label management (lower level functions)
5 
6  GRASS OpenGL gsurf OGSF Library
7 
8  (C) 1999-2008 by the GRASS Development Team
9 
10  This program is free software under the
11  GNU General Public License (>=v2).
12  Read the file COPYING that comes with GRASS
13  for details.
14 
15  \author Bill Brown USACERL (1991-1992)
16  \author Doxygenized by Martin Landa <landa.martin gmail.com> (May 2008)
17  */
18 
19 #include <grass/gis.h>
20 #include <grass/glocale.h>
21 #include <grass/ogsf.h>
22 
23 #include "rgbpack.h"
24 
25 #define MAX_LIST 20
26 
27 static int first = 0;
28 GLuint label_base;
29 GLuint label_id;
30 
31 /*!
32  \brief Put label
33 
34  \todo Allocate label dynamically
35 
36  \param fontbase fontbase settings
37  \param size font size
38  \param color font color
39  \param pt
40  */
41 void gs_put_label(const char *text, GLuint fontbase, int size,
42  unsigned long color, int *pt)
43 {
44  int txt_width;
45  GLint tmp[4];
46  float labpt[2];
47  int t, l, b, r;
48 
49  if (!first) {
50  /* initialize display list */
51  label_base = glGenLists(MAX_LIST);
52  glListBase(label_base);
54  first = 1;
55  }
56 
57  if (label_id > (label_base + MAX_LIST)) {
58  G_warning(_("Max. number of labels reached!"));
59  return;
60  }
61 
62  glNewList(label_id, GL_COMPILE_AND_EXECUTE);
63  txt_width = gsd_get_txtwidth(text, size);
64 
65  /* adjust to center text string */
66  labpt[X] = (float)(pt[X] - txt_width / 2.);
67  labpt[Y] = (float)pt[Y];
68 
69  glGetIntegerv(GL_VIEWPORT, tmp);
70  l = tmp[0];
71  r = tmp[0] + tmp[2];
72  b = tmp[1];
73  t = tmp[1] + tmp[3];
74 
75  gsd_bgn_legend_viewport(l, b, r, t);
76 
77 
78  /* Set text color */
79  gsd_color_func(color);
80 
81  do_label_display(fontbase, labpt, text);
82 
83 
85 
86  glEndList();
87 
88  label_id++;
89 
90  return;
91 }
92 
93 
94 /*!
95  \brief Remove current label
96  */
97 void gsd_remove_curr(void)
98 {
99  if (label_id) {
100  glDeleteLists(label_id - 1, 1);
101  label_id--;
102  }
103 
104  return;
105 }
106 
107 
108 /*!
109  \brief Remove all labels from display list
110  */
111 void gsd_remove_all(void)
112 {
113  glDeleteLists(label_base, MAX_LIST);
115 
116  return;
117 }
118 
119 /*!
120  \brief Call display list and draw defined labels -- called from gsd_prim (gsd_call_lists)
121  */
122 void gsd_call_label(void)
123 {
124  int i;
125 
126  for (i = 0; i < MAX_LIST; i++) {
127  glCallList(i + label_base);
128  glFlush();
129  }
130  return;
131 }
void do_label_display(GLuint, float *, const char *)
Display label.
Definition: gsd_fonts.c:98
GLuint label_base
Definition: gsd_label.c:28
void gsd_end_legend_viewport(void)
ADD.
Definition: gsd_legend.c:91
void gsd_remove_all(void)
Remove all labels from display list.
Definition: gsd_label.c:111
void gsd_call_label(void)
Call display list and draw defined labels – called from gsd_prim (gsd_call_lists) ...
Definition: gsd_label.c:122
double l
Definition: r_raster.c:39
double t
Definition: r_raster.c:39
double b
Definition: r_raster.c:39
void gsd_color_func(unsigned int)
Set current color.
Definition: gsd_prim.c:701
void gsd_bgn_legend_viewport(GLint, GLint, GLint, GLint)
ADD.
Definition: gsd_legend.c:61
#define MAX_LIST
Definition: gsd_label.c:25
void gs_put_label(const char *text, GLuint fontbase, int size, unsigned long color, int *pt)
Put label.
Definition: gsd_label.c:41
#define Y
Definition: ogsf.h:138
GLuint label_id
Definition: gsd_label.c:29
void G_warning(const char *,...) __attribute__((format(printf
#define _(str)
Definition: glocale.h:10
#define X
Definition: ogsf.h:137
void gsd_remove_curr(void)
Remove current label.
Definition: gsd_label.c:97
int gsd_get_txtwidth(const char *, int)
Get text width.
Definition: gsd_fonts.c:36
double r
Definition: r_raster.c:39