GRASS GIS 8 Programmer's Manual  8.5.0dev(2024)-d6dec75dd4
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 
76 
77  /* Set text color */
78  gsd_color_func(color);
79 
80  do_label_display(fontbase, labpt, text);
81 
83 
84  glEndList();
85 
86  label_id++;
87 
88  return;
89 }
90 
91 /*!
92  \brief Remove current label
93  */
94 void gsd_remove_curr(void)
95 {
96  if (label_id) {
97  glDeleteLists(label_id - 1, 1);
98  label_id--;
99  }
100 
101  return;
102 }
103 
104 /*!
105  \brief Remove all labels from display list
106  */
107 void gsd_remove_all(void)
108 {
109  glDeleteLists(label_base, MAX_LIST);
111 
112  return;
113 }
114 
115 /*!
116  \brief Call display list and draw defined labels -- called from gsd_prim
117  (gsd_call_lists)
118  */
119 void gsd_call_label(void)
120 {
121  int i;
122 
123  for (i = 0; i < MAX_LIST; i++) {
124  glCallList(i + label_base);
125  glFlush();
126  }
127  return;
128 }
void G_warning(const char *,...) __attribute__((format(printf
void do_label_display(GLuint, float *, const char *)
Display label.
Definition: gsd_fonts.c:97
int gsd_get_txtwidth(const char *, int)
Get text width.
Definition: gsd_fonts.c:36
void gsd_color_func(unsigned int)
Set current color.
Definition: gsd_prim.c:698
void gsd_bgn_legend_viewport(GLint, GLint, GLint, GLint)
ADD.
Definition: gsd_legend.c:61
void gsd_end_legend_viewport(void)
ADD.
Definition: gsd_legend.c:91
#define _(str)
Definition: glocale.h:10
void gsd_remove_curr(void)
Remove current label.
Definition: gsd_label.c:94
GLuint label_base
Definition: gsd_label.c:28
#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
void gsd_remove_all(void)
Remove all labels from display list.
Definition: gsd_label.c:107
GLuint label_id
Definition: gsd_label.c:29
void gsd_call_label(void)
Call display list and draw defined labels – called from gsd_prim (gsd_call_lists)
Definition: gsd_label.c:119
#define X
Definition: ogsf.h:140
#define Y
Definition: ogsf.h:141
double b
Definition: r_raster.c:39
double l
Definition: r_raster.c:39
double t
Definition: r_raster.c:39
double r
Definition: r_raster.c:39