26 #if defined(OPENGL_X11) || defined(OPENGL_WINDOWS)
29 #elif defined(OPENGL_AQUA)
30 #include <OpenGL/gl.h>
31 #include <OpenGL/glu.h>
41 static float *Listcats;
42 static int Listnum = 0;
51 #define MAX_LEGEND 256
66 glPushAttrib(GL_VIEWPORT);
68 glMatrixMode(GL_PROJECTION);
78 glViewport(wl, wb, (wr - wl), (wt - wb));
80 gluOrtho2D(-0.5, (wr - wl) + 0.5, -0.5, (wt - wb) + 0.5);
81 glMatrixMode(GL_MODELVIEW);
96 glMatrixMode(GL_PROJECTION);
100 glMatrixMode(GL_MODELVIEW);
125 float curnum, step, start;
130 step = (highnum - lownum) / (
float)numvals;
134 start = step * (int)(1 + lownum / step);
135 if (start - lownum < .65 * step)
138 for (curnum = start; curnum < (highnum - .65 * step); curnum += step) {
139 vals[num++] = curnum;
155 float newnum, nextnum;
162 while (.5 * newnum > *num) {
163 nextnum = newnum / 10.;
165 if (.5 * newnum > *num)
167 if (.5 * newnum > *num)
173 while (2 * newnum <= *num) {
174 nextnum = newnum * 10.;
176 if (2 * newnum <= *num)
178 if (2 * newnum <= *num)
202 float *rangef,
int *pt)
204 GLint sl, sr, sb,
st;
206 int cat_labs = 0, cat_vals = 0, do_invert = 0, discrete = 0;
207 int is_fp, fprec, iprec;
237 if (mapset ==
NULL) {
245 G_warning(
_(
"Unable to read color file of raster map <%s>"),
name);
251 G_warning(
_(
"Unable to read category file of raster map <%s>"),
256 if (flags[4] && rangef[0] != -9999. && rangef[1] != -9999.) {
267 G_warning(
_(
"Unable to read fp range of raster map <%s>"),
272 if (flags[4] && rangef[0] != -9999.)
274 if (flags[4] && rangef[1] != -9999.)
283 if (flags[4] && rangef[0] != -9999.)
285 if (flags[4] && rangef[1] != -9999.)
293 G_warning(
_(
"Range request error for legend"));
316 for (tmp = 1; tmp <
max; tmp *= 10, p1++)
319 for (tmp = -1; tmp >
min; tmp *= 10, p2++)
322 iprec = (p1 > p2 ? p1 : p2);
357 int i, k, lleg, horiz;
358 int red, green, blue;
360 DCELL tdcell, pdcell;
361 float vert1[2], vert2[2], vert3[2], vert4[2];
367 int labw, maxlabw, numlabs;
368 float labpos, labpt[3];
371 GLint wt, wb, wl, wr;
375 horiz = (sr - sl >
st - sb);
379 numlabs = Listnum ? Listnum :
max -
min + 1;
381 if (is_fp && !Listnum) {
383 G_warning(
_(
"Unable to show discrete FP range (use list)"));
387 dividers = (
float *)
G_malloc(numlabs *
sizeof(
float));
392 labvals[numlabs + 1] = fmax;
399 if (cat_labs || cat_vals) {
400 for (k = 0; k < numlabs; k++) {
402 tdcell = discrete ? Listcats[k] : labvals[k];
406 if (cat_labs && !cat_vals) {
407 sprintf(buff,
"%s", cstr);
410 if (cat_labs && cat_vals) {
412 sprintf(buff,
"%.*lf) %s", fprec, tdcell, cstr);
414 sprintf(buff,
"%.*lf", fprec, tdcell);
417 sprintf(buff,
"%.*lf", fprec, tdcell);
422 discrete ? Listnum ? Listcats[k] :
min + k : labvals[k];
423 if (cat_labs && !cat_vals)
426 if (cat_labs && cat_vals) {
429 sprintf(buff,
"%*d) %s", iprec, tcell, cstr);
431 sprintf(buff,
"%d", tcell);
434 sprintf(buff,
"%d", tcell);
438 if (labw > maxlabw) {
470 vert1[
X] = vert2[
X] = xoff;
471 vert1[
Y] = vert2[
Y] = yoff;
478 stab2 = vert2[
Y] =
st - sb + yoff;
479 stab1 = vert1[
Y] = yoff;
481 vert1[
X] = vert2[
X] = sr - sl + xoff;
489 stab2 = vert2[
X] = sr - sl + xoff;
490 stab1 = vert1[
X] = xoff;
492 vert1[
Y] = vert2[
Y] =
st - sb + yoff;
496 if (numlabs > lleg / 5)
497 G_warning(
_(
"Too many categories to show as discrete!"));
502 incr = do_invert ? -1 : 1;
503 for (k = 0, i = 0; k < lleg; k++) {
504 if (discrete && Listnum)
505 tdcell = Listcats[(int)((
float)k * numlabs / lleg)];
507 tcell =
min + k * (
max -
min + 1) / lleg;
508 tdcell = fmin + k * (fmax - fmin) / lleg;
512 if (k == 0 || tdcell != pdcell) {
533 dividers[i++] = *dv1;
563 vert1[
X] = vert2[
X] = 1. + xoff;
564 vert1[
Y] = vert4[
Y] = 1. + yoff;
565 vert3[
X] = vert4[
X] = sr - sl - 1. + xoff;
566 vert3[
Y] = vert2[
Y] =
st - sb - 1. + yoff;
578 vert1[
X] = vert2[
X] = xoff;
579 vert1[
Y] = vert4[
Y] = yoff;
580 vert3[
X] = vert4[
X] = sr - sl + xoff;
581 vert3[
Y] = vert2[
Y] =
st - sb + yoff;
597 for (k = 0; k < i; k++) {
598 *dv1 = *dv2 = dividers[k];
606 if (cat_labs || cat_vals) {
608 for (k = 0; k < numlabs; k++) {
610 if (discrete && Listnum) {
611 tdcell = Listcats[k];
612 labpos = (k + .5) / numlabs;
617 labpos = (tdcell - fmin) / (fmax - fmin);
621 if (discrete && Listnum) {
623 labpos = (k + .5) / numlabs;
626 tcell = discrete ?
min + k : labvals[k];
627 labpos = (tcell -
min + .5) / (
max -
min + 1);
631 labpos = 1. - labpos;
638 if (cat_labs && !cat_vals)
639 sprintf(buff,
"%s", cstr);
641 if (cat_labs && cat_vals) {
644 sprintf(buff,
"%.*lf) %s", fprec, tdcell, cstr);
646 sprintf(buff,
"%*d) %s", iprec, tcell, cstr);
648 sprintf(buff,
"%.*lf", fprec, tdcell);
650 sprintf(buff,
"%d", tcell);
654 sprintf(buff,
"%.*lf", fprec, tdcell);
656 sprintf(buff,
"%d", tcell);
660 labpt[
X] = labpos * (sr - sl) + xoff -
699 return (legend_list);
void G_free(void *)
Free allocated memory.
void G_warning(const char *,...) __attribute__((format(printf
const char * G_find_raster2(const char *, const char *)
Find a raster map (look but don't touch)
void gsd_endlist(void)
End list.
void gsd_pushmatrix(void)
Push the current matrix stack.
void GS_set_draw(int)
Sets which buffer to draw to.
void do_label_display(GLuint, float *, const char *)
Display label.
void gsd_bgnlist(int, int)
ADD.
int gsd_makelist(void)
ADD.
int gsd_get_txtwidth(const char *, int)
Get text width.
int gsd_get_txtheight(int size)
Get text height.
void gsd_color_func(unsigned int)
Set current color.
void gsd_popmatrix(void)
Pop the current matrix stack.
int get_txtxoffset(void)
Get text offset.
void gsd_linewidth(short)
Set width of rasterized lines.
void gsd_endline(void)
End line.
void gsd_colormode(int)
Set color mode.
void gsd_bgnline(void)
Begin line.
void GS_done_draw(void)
Draw done, swap buffers.
void Rast_free_cats(struct Categories *)
Free category structure memory.
int Rast_get_c_color(const CELL *, int *, int *, int *, struct Colors *)
Gets color from raster map (CELL)
int Rast_read_colors(const char *, const char *, struct Colors *)
Read color table of raster map.
int Rast_read_cats(const char *, const char *, struct Categories *)
Read raster category file.
int Rast_read_fp_range(const char *, const char *, struct FPRange *)
Read floating-point range.
void Rast_free_colors(struct Colors *)
Free color structure memory.
void Rast_get_fp_range_min_max(const struct FPRange *, DCELL *, DCELL *)
Get minimum and maximum value from fp range.
void Rast_get_range_min_max(const struct Range *, CELL *, CELL *)
Get range min and max.
int Rast_read_range(const char *, const char *, struct Range *)
Read raster range (CELL)
char * Rast_get_c_cat(CELL *, struct Categories *)
Get a raster category label (CELL)
char * Rast_get_d_cat(DCELL *, struct Categories *)
Get a raster category label (DCELL)
int Rast_map_is_fp(const char *, const char *)
Check if raster map is floating-point.
int Rast_get_d_color(const DCELL *, int *, int *, int *, struct Colors *)
Gets color from raster map (DCELL)
int gsd_make_nice_number(float *num)
ADD.
GLuint gsd_put_legend(const char *name, GLuint fontbase, int size, int *flags, float *rangef, int *pt)
Put legend.
int gsd_get_nice_range(float lownum, float highnum, int numvals, float *vals)
ADD.
void gsd_end_legend_viewport(void)
ADD.
void gsd_bgn_legend_viewport(GLint wl, GLint wb, GLint wr, GLint wt)
ADD.
#define RGB_TO_INT(r, g, b, i)