1 //
2 // "$Id: fl_overlay.cxx 5614 2007-01-18 15:25:09Z matt $"
3 //
4 // Overlay support for the Fast Light Tool Kit (FLTK).
5 //
6 // Copyright 1998-2005 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
21 // USA.
22 //
23 // Please report all bugs and problems on the following page:
24 //
25 //     http://www.fltk.org/str.php
26 //
27 
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.
32 
33 #include <FL/x.H>
34 #include <FL/fl_draw.H>
35 #ifdef __APPLE__
36 #include <config.h>
37 #endif
38 
39 //#define USE_XOR
40 
41 static int px,py,pw,ph;
42 
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
48 
draw_current_rect()49 static void draw_current_rect() {
50 #ifdef USE_XOR
51 # ifdef WIN32
52   int old = SetROP2(fl_gc, R2_NOT);
53   fl_rect(px, py, pw, ph);
54   SetROP2(fl_gc, old);
55 # elif defined(__APPLE_QD__)
56   PenMode( patXor );
57   fl_rect(px, py, pw, ph);
58   PenMode( patCopy );
59 # elif defined(__APPLE_QUARTZ__)
60   // warning: Quartz does not support xor drawing
61   // Use the Fl_Overlay_Window instead.
62   fl_color(FL_WHITE);
63   fl_rect(px, py, pw, ph);
64 # else
65   XSetFunction(fl_display, fl_gc, GXxor);
66   XSetForeground(fl_display, fl_gc, 0xffffffff);
67   XDrawRectangle(fl_display, fl_window, fl_gc, px, py, pw, ph);
68   XSetFunction(fl_display, fl_gc, GXcopy);
69 # endif
70 #else
71   if (bgN) { free(bgN); bgN = 0L; }
72   if (bgS) { free(bgS); bgS = 0L; }
73   if (bgE) { free(bgE); bgE = 0L; }
74   if (bgW) { free(bgW); bgW = 0L; }
75   if (pw>0 && ph>0) {
76     bgE = fl_read_image(0L, px+pw-1, py, 1, ph);
77     bgW = fl_read_image(0L, px, py, 1, ph);
78     bgS = fl_read_image(0L, px, py+ph-1, pw, 1);
79     bgN = fl_read_image(0L, px, py, pw, 1);
80     bgx = px; bgy = py;
81     bgw = pw; bgh = ph;
82   }
83   fl_color(FL_WHITE);
84   fl_line_style(FL_SOLID);
85   fl_rect(px, py, pw, ph);
86   fl_color(FL_BLACK);
87   fl_line_style(FL_DOT);
88   fl_rect(px, py, pw, ph);
89   fl_line_style(FL_SOLID);
90 #endif
91 }
92 
erase_current_rect()93 static void erase_current_rect() {
94 #ifdef USE_XOR
95 # ifdef __APPLE_QUARTZ__
96   fl_rect(px, py, pw, ph);
97 # else
98   draw_current_rect();
99 # endif
100 #else
101   if (bgN) fl_draw_image(bgN, bgx, bgy, bgw, 1);
102   if (bgS) fl_draw_image(bgS, bgx, bgy+bgh-1, bgw, 1);
103   if (bgW) fl_draw_image(bgW, bgx, bgy, 1, bgh);
104   if (bgE) fl_draw_image(bgE, bgx+bgw-1, bgy, 1, bgh);
105 #endif
106 }
107 
fl_overlay_clear()108 void fl_overlay_clear() {
109   if (pw > 0) {erase_current_rect(); pw = 0;}
110 }
111 
fl_overlay_rect(int x,int y,int w,int h)112 void fl_overlay_rect(int x, int y, int w, int h) {
113   if (w < 0) {x += w; w = -w;} else if (!w) w = 1;
114   if (h < 0) {y += h; h = -h;} else if (!h) h = 1;
115   if (pw > 0) {
116     if (x==px && y==py && w==pw && h==ph) return;
117     erase_current_rect();
118   }
119   px = x; py = y; pw = w; ph = h;
120   draw_current_rect();
121 }
122 
123 //
124 // End of "$Id: fl_overlay.cxx 5614 2007-01-18 15:25:09Z matt $".
125 //
126