GRASS Programmer's Manual  6.4.2(2012)
gsd_label.c
Go to the documentation of this file.
00001 
00019 #include <grass/gis.h>
00020 #include <grass/glocale.h>
00021 #include <grass/gstypes.h>
00022 
00023 #include "rgbpack.h"
00024 
00025 #define MAX_LIST 20
00026 
00027 static int first = 0;
00028 GLuint label_base;
00029 GLuint label_id;
00030 
00041 void gs_put_label(const char *text, GLuint fontbase, int size,
00042                   unsigned long color, int *pt)
00043 {
00044     int txt_width;
00045     GLint tmp[4];
00046     float labpt[2];
00047     int t, l, b, r;
00048 
00049     if (!first) {
00050         /* initialize display list */
00051         label_base = glGenLists(MAX_LIST);
00052         glListBase(label_base);
00053         label_id = label_base;
00054         first = 1;
00055     }
00056 
00057     if (label_id > (label_base + MAX_LIST)) {
00058         G_warning(_("Max. number of labels reached!"));
00059         return;
00060     }
00061 
00062     glNewList(label_id, GL_COMPILE_AND_EXECUTE);
00063     txt_width = gsd_get_txtwidth(text, size);
00064 
00065     /* adjust to center text string */
00066     labpt[X] = (float)(pt[X] - txt_width / 2.);
00067     labpt[Y] = (float)pt[Y];
00068 
00069     glGetIntegerv(GL_VIEWPORT, tmp);
00070     l = tmp[0];
00071     r = tmp[0] + tmp[2];
00072     b = tmp[1];
00073     t = tmp[1] + tmp[3];
00074 
00075     gsd_bgn_legend_viewport(l, b, r, t);
00076 
00077 
00078     /* Set text color */
00079     gsd_color_func(color);
00080 
00081     do_label_display(fontbase, labpt, text);
00082 
00083 
00084     gsd_end_legend_viewport();
00085 
00086     glEndList();
00087 
00088     label_id++;
00089 
00090     return;
00091 }
00092 
00093 
00097 void gsd_remove_curr(void)
00098 {
00099     if (label_id) {
00100         glDeleteLists(label_id - 1, 1);
00101         label_id--;
00102     }
00103 
00104     return;
00105 }
00106 
00107 
00111 void gsd_remove_all(void)
00112 {
00113     glDeleteLists(label_base, MAX_LIST);
00114     label_id = label_base;
00115 
00116     return;
00117 }
00118 
00122 void gsd_call_label(void)
00123 {
00124     int i;
00125 
00126     for (i = 0; i < MAX_LIST; i++) {
00127         glCallList(i + label_base);
00128         glFlush();
00129     }
00130     return;
00131 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines