fl_overlay.cxx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. //
  2. // "$Id: fl_overlay.cxx 7903 2010-11-28 21:06:39Z matt $"
  3. //
  4. // Overlay support for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 1998-2010 by Bill Spitzak and others.
  7. //
  8. // This library is free software; you can redistribute it and/or
  9. // modify it under the terms of the GNU Library General Public
  10. // License as published by the Free Software Foundation; either
  11. // version 2 of the License, or (at your option) any later version.
  12. //
  13. // This library is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. // Library General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Library General Public
  19. // License along with this library; if not, write to the Free Software
  20. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  21. // USA.
  22. //
  23. // Please report all bugs and problems on the following page:
  24. //
  25. // http://www.fltk.org/str.php
  26. //
  27. // Extremely limited "overlay" support. You can use this to drag out
  28. // a rectangle in response to mouse events. It is your responsibility
  29. // to erase the overlay before drawing anything that might intersect
  30. // it.
  31. #include <FL/x.H>
  32. #include <FL/fl_draw.H>
  33. #ifdef __APPLE__
  34. #include <config.h>
  35. #endif
  36. //#define USE_XOR
  37. static int px,py,pw,ph;
  38. #ifndef USE_XOR
  39. #include <stdlib.h>
  40. static uchar *bgN = 0L, *bgS = 0L, *bgE = 0L, *bgW = 0L;
  41. static int bgx, bgy, bgw, bgh;
  42. #endif
  43. static void draw_current_rect() {
  44. #ifdef USE_XOR
  45. # if defined(USE_X11)
  46. XSetFunction(fl_display, fl_gc, GXxor);
  47. XSetForeground(fl_display, fl_gc, 0xffffffff);
  48. XDrawRectangle(fl_display, fl_window, fl_gc, px, py, pw, ph);
  49. XSetFunction(fl_display, fl_gc, GXcopy);
  50. # elif defined(WIN32)
  51. int old = SetROP2(fl_gc, R2_NOT);
  52. fl_rect(px, py, pw, ph);
  53. SetROP2(fl_gc, old);
  54. # elif defined(__APPLE_QUARTZ__)
  55. // warning: Quartz does not support xor drawing
  56. // Use the Fl_Overlay_Window instead.
  57. fl_color(FL_WHITE);
  58. fl_rect(px, py, pw, ph);
  59. # else
  60. # error unsupported platform
  61. # endif
  62. #else
  63. if (bgN) { free(bgN); bgN = 0L; }
  64. if (bgS) { free(bgS); bgS = 0L; }
  65. if (bgE) { free(bgE); bgE = 0L; }
  66. if (bgW) { free(bgW); bgW = 0L; }
  67. if (pw>0 && ph>0) {
  68. bgE = fl_read_image(0L, px+pw-1, py, 1, ph);
  69. bgW = fl_read_image(0L, px, py, 1, ph);
  70. bgS = fl_read_image(0L, px, py+ph-1, pw, 1);
  71. bgN = fl_read_image(0L, px, py, pw, 1);
  72. bgx = px; bgy = py;
  73. bgw = pw; bgh = ph;
  74. }
  75. fl_color(FL_WHITE);
  76. fl_line_style(FL_SOLID);
  77. fl_rect(px, py, pw, ph);
  78. fl_color(FL_BLACK);
  79. fl_line_style(FL_DOT);
  80. fl_rect(px, py, pw, ph);
  81. fl_line_style(FL_SOLID);
  82. #endif
  83. }
  84. static void erase_current_rect() {
  85. #ifdef USE_XOR
  86. # ifdef __APPLE_QUARTZ__
  87. fl_rect(px, py, pw, ph);
  88. # else
  89. draw_current_rect();
  90. # endif
  91. #else
  92. if (bgN) fl_draw_image(bgN, bgx, bgy, bgw, 1);
  93. if (bgS) fl_draw_image(bgS, bgx, bgy+bgh-1, bgw, 1);
  94. if (bgW) fl_draw_image(bgW, bgx, bgy, 1, bgh);
  95. if (bgE) fl_draw_image(bgE, bgx+bgw-1, bgy, 1, bgh);
  96. #endif
  97. }
  98. /**
  99. Erase a selection rectangle without drawing a new one
  100. */
  101. void fl_overlay_clear() {
  102. if (pw > 0) {erase_current_rect(); pw = 0;}
  103. }
  104. /**
  105. Draws a selection rectangle, erasing a previous one by XOR'ing it first.
  106. */
  107. void fl_overlay_rect(int x, int y, int w, int h) {
  108. if (w < 0) {x += w; w = -w;} else if (!w) w = 1;
  109. if (h < 0) {y += h; h = -h;} else if (!h) h = 1;
  110. if (pw > 0) {
  111. if (x==px && y==py && w==pw && h==ph) return;
  112. erase_current_rect();
  113. }
  114. px = x; py = y; pw = w; ph = h;
  115. draw_current_rect();
  116. }
  117. //
  118. // End of "$Id: fl_overlay.cxx 7903 2010-11-28 21:06:39Z matt $".
  119. //