themes: Workaround for bug where a background color of RGB 0,0,0 in Black color schem...
[ntk.git] / src / fl_overlay.cxx
blobadcd8712e05960e87bee9f335da8467b9e995b06
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.
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.
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.
23 // Please report all bugs and problems on the following page:
25 // http://www.fltk.org/str.php
28 // Extremely limited "overlay" support. You can use this to drag out
29 // a rectangle in response to mouse events. It is your responsibility
30 // to erase the overlay before drawing anything that might intersect
31 // it.
33 #include <FL/x.H>
34 #include <FL/fl_draw.H>
35 #ifdef __APPLE__
36 #include <config.h>
37 #endif
39 //#define USE_XOR
41 static int px,py,pw,ph;
43 #ifndef USE_XOR
44 #include <stdlib.h>
45 static uchar *bgN = 0L, *bgS = 0L, *bgE = 0L, *bgW = 0L;
46 static int bgx, bgy, bgw, bgh;
47 #endif
49 static void draw_current_rect() {
50 #ifdef USE_XOR
51 # if defined(USE_X11)
52 XSetFunction(fl_display, fl_gc, GXxor);
53 XSetForeground(fl_display, fl_gc, 0xffffffff);
54 XDrawRectangle(fl_display, fl_window, fl_gc, px, py, pw, ph);
55 XSetFunction(fl_display, fl_gc, GXcopy);
56 # elif defined(WIN32)
57 int old = SetROP2(fl_gc, R2_NOT);
58 fl_rect(px, py, pw, ph);
59 SetROP2(fl_gc, old);
60 # elif defined(__APPLE_QUARTZ__)
61 // warning: Quartz does not support xor drawing
62 // Use the Fl_Overlay_Window instead.
63 fl_color(FL_WHITE);
64 fl_rect(px, py, pw, ph);
65 # else
66 # error unsupported platform
67 # endif
68 #else
69 if (bgN) { free(bgN); bgN = 0L; }
70 if (bgS) { free(bgS); bgS = 0L; }
71 if (bgE) { free(bgE); bgE = 0L; }
72 if (bgW) { free(bgW); bgW = 0L; }
73 if (pw>0 && ph>0) {
74 bgE = fl_read_image(0L, px+pw-1, py, 1, ph);
75 bgW = fl_read_image(0L, px, py, 1, ph);
76 bgS = fl_read_image(0L, px, py+ph-1, pw, 1);
77 bgN = fl_read_image(0L, px, py, pw, 1);
78 bgx = px; bgy = py;
79 bgw = pw; bgh = ph;
81 fl_color(FL_WHITE);
82 fl_line_style(FL_SOLID);
83 fl_rect(px, py, pw, ph);
84 fl_color(FL_BLACK);
85 fl_line_style(FL_DOT);
86 fl_rect(px, py, pw, ph);
87 fl_line_style(FL_SOLID);
88 #endif
91 static void erase_current_rect() {
92 #ifdef USE_XOR
93 # ifdef __APPLE_QUARTZ__
94 fl_rect(px, py, pw, ph);
95 # else
96 draw_current_rect();
97 # endif
98 #else
99 if (bgN) fl_draw_image(bgN, bgx, bgy, bgw, 1);
100 if (bgS) fl_draw_image(bgS, bgx, bgy+bgh-1, bgw, 1);
101 if (bgW) fl_draw_image(bgW, bgx, bgy, 1, bgh);
102 if (bgE) fl_draw_image(bgE, bgx+bgw-1, bgy, 1, bgh);
103 #endif
107 Erase a selection rectangle without drawing a new one
109 void fl_overlay_clear() {
110 if (pw > 0) {erase_current_rect(); pw = 0;}
114 Draws a selection rectangle, erasing a previous one by XOR'ing it first.
116 void fl_overlay_rect(int x, int y, int w, int h) {
117 if (w < 0) {x += w; w = -w;} else if (!w) w = 1;
118 if (h < 0) {y += h; h = -h;} else if (!h) h = 1;
119 if (pw > 0) {
120 if (x==px && y==py && w==pw && h==ph) return;
121 erase_current_rect();
123 px = x; py = y; pw = w; ph = h;
124 draw_current_rect();
128 // End of "$Id: fl_overlay.cxx 7903 2010-11-28 21:06:39Z matt $".