gsd_label.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*!
  2. \file lib/ogsf/gsd_label.c
  3. \brief OGSF library - label management (lower level functions)
  4. GRASS OpenGL gsurf OGSF Library
  5. (C) 1999-2008 by the GRASS Development Team
  6. This program is free software under the
  7. GNU General Public License (>=v2).
  8. Read the file COPYING that comes with GRASS
  9. for details.
  10. \author Bill Brown USACERL (1991-1992)
  11. \author Doxygenized by Martin Landa <landa.martin gmail.com> (May 2008)
  12. */
  13. #include <grass/gis.h>
  14. #include <grass/glocale.h>
  15. #include <grass/ogsf.h>
  16. #include "rgbpack.h"
  17. #define MAX_LIST 20
  18. static int first = 0;
  19. GLuint label_base;
  20. GLuint label_id;
  21. /*!
  22. \brief Put label
  23. \todo Allocate label dynamicaly
  24. \param fontbase fontbase settings
  25. \param size font size
  26. \param color font color
  27. \param pt
  28. */
  29. void gs_put_label(const char *text, GLuint fontbase, int size,
  30. unsigned long color, int *pt)
  31. {
  32. int txt_width;
  33. GLint tmp[4];
  34. float labpt[2];
  35. int t, l, b, r;
  36. if (!first) {
  37. /* initialize display list */
  38. label_base = glGenLists(MAX_LIST);
  39. glListBase(label_base);
  40. label_id = label_base;
  41. first = 1;
  42. }
  43. if (label_id > (label_base + MAX_LIST)) {
  44. G_warning(_("Max. number of labels reached!"));
  45. return;
  46. }
  47. glNewList(label_id, GL_COMPILE_AND_EXECUTE);
  48. txt_width = gsd_get_txtwidth(text, size);
  49. /* adjust to center text string */
  50. labpt[X] = (float)(pt[X] - txt_width / 2.);
  51. labpt[Y] = (float)pt[Y];
  52. glGetIntegerv(GL_VIEWPORT, tmp);
  53. l = tmp[0];
  54. r = tmp[0] + tmp[2];
  55. b = tmp[1];
  56. t = tmp[1] + tmp[3];
  57. gsd_bgn_legend_viewport(l, b, r, t);
  58. /* Set text color */
  59. gsd_color_func(color);
  60. do_label_display(fontbase, labpt, text);
  61. gsd_end_legend_viewport();
  62. glEndList();
  63. label_id++;
  64. return;
  65. }
  66. /*!
  67. \brief Remove current label
  68. */
  69. void gsd_remove_curr(void)
  70. {
  71. if (label_id) {
  72. glDeleteLists(label_id - 1, 1);
  73. label_id--;
  74. }
  75. return;
  76. }
  77. /*!
  78. \brief Remove all labels from display list
  79. */
  80. void gsd_remove_all(void)
  81. {
  82. glDeleteLists(label_base, MAX_LIST);
  83. label_id = label_base;
  84. return;
  85. }
  86. /*!
  87. \brief Call display list and draw defined labels -- called from gsd_prim (gsd_call_lists)
  88. */
  89. void gsd_call_label(void)
  90. {
  91. int i;
  92. for (i = 0; i < MAX_LIST; i++) {
  93. glCallList(i + label_base);
  94. glFlush();
  95. }
  96. return;
  97. }