GRASS 8 Programmer's Manual 8.6.0dev(2026)-55de52a352
Loading...
Searching...
No Matches
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 SPDX-FileCopyrightText: 1999-2008 GRASS Development Team
9 SPDX-License-Identifier: GPL-2.0-or-later
10
11 \author Bill Brown USACERL (1991-1992)
12 \author Doxygenized by Martin Landa <landa.martin gmail.com> (May 2008)
13 */
14
15#include <grass/gis.h>
16#include <grass/glocale.h>
17#include <grass/ogsf.h>
18
19#include "rgbpack.h"
20
21#define MAX_LIST 20
22
23static int first = 0;
26
27/*!
28 \brief Put label
29
30 \todo Allocate label dynamically
31
32 \param fontbase fontbase settings
33 \param size font size
34 \param color font color
35 \param pt
36 */
37void gs_put_label(const char *text, GLuint fontbase, int size,
38 unsigned long color, int *pt)
39{
40 int txt_width;
41 GLint tmp[4];
42 float labpt[2];
43 int t, l, b, r;
44
45 if (!first) {
46 /* initialize display list */
50 first = 1;
51 }
52
53 if (label_id > (label_base + MAX_LIST)) {
54 G_warning(_("Max. number of labels reached!"));
55 return;
56 }
57
59 txt_width = gsd_get_txtwidth(text, size);
60
61 /* adjust to center text string */
62 labpt[X] = (float)(pt[X] - txt_width / 2.);
63 labpt[Y] = (float)pt[Y];
64
66 l = tmp[0];
67 r = tmp[0] + tmp[2];
68 b = tmp[1];
69 t = tmp[1] + tmp[3];
70
72
73 /* Set text color */
74 gsd_color_func(color);
75
77
79
80 glEndList();
81
82 label_id++;
83
84 return;
85}
86
87/*!
88 \brief Remove current label
89 */
91{
92 if (label_id) {
93 glDeleteLists(label_id - 1, 1);
94 label_id--;
95 }
96
97 return;
98}
99
100/*!
101 \brief Remove all labels from display list
102 */
104{
107
108 return;
109}
110
111/*!
112 \brief Call display list and draw defined labels -- called from gsd_prim
113 (gsd_call_lists)
114 */
116{
117 int i;
118
119 for (i = 0; i < MAX_LIST; i++) {
121 glFlush();
122 }
123 return;
124}
void G_warning(const char *,...) __attribute__((format(printf
void do_label_display(GLuint, float *, const char *)
Display label.
Definition gsd_fonts.c:93
int gsd_get_txtwidth(const char *, int)
Get text width.
Definition gsd_fonts.c:32
void gsd_color_func(unsigned int)
Set current color.
Definition gsd_prim.c:694
void gsd_bgn_legend_viewport(GLint, GLint, GLint, GLint)
ADD.
Definition gsd_legend.c:57
void gsd_end_legend_viewport(void)
ADD.
Definition gsd_legend.c:87
#define _(str)
Definition glocale.h:10
void gsd_remove_curr(void)
Remove current label.
Definition gsd_label.c:90
GLuint label_base
Definition gsd_label.c:24
#define MAX_LIST
Definition gsd_label.c:21
void gs_put_label(const char *text, GLuint fontbase, int size, unsigned long color, int *pt)
Put label.
Definition gsd_label.c:37
void gsd_remove_all(void)
Remove all labels from display list.
Definition gsd_label.c:103
GLuint label_id
Definition gsd_label.c:25
void gsd_call_label(void)
Call display list and draw defined labels – called from gsd_prim (gsd_call_lists)
Definition gsd_label.c:115
OGSF header file (structures)
#define X
Definition ogsf.h:141
#define Y
Definition ogsf.h:142
double b
Definition r_raster.c:37
double l
Definition r_raster.c:37
double t
Definition r_raster.c:37
double r
Definition r_raster.c:37