2 // "$Id: fl_overlay.cxx 7903 2010-11-28 21:06:39Z matt $"
4 // Overlay support for the Fast Light Tool Kit (FLTK).
6 // Copyright 1998-2010 by Bill Spitzak and others.
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
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
34 #include <FL/fl_draw.H>
41 static int px
,py
,pw
,ph
;
45 static uchar
*bgN
= 0L, *bgS
= 0L, *bgE
= 0L, *bgW
= 0L;
46 static int bgx
, bgy
, bgw
, bgh
;
49 static void draw_current_rect() {
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
);
57 int old
= SetROP2(fl_gc
, R2_NOT
);
58 fl_rect(px
, py
, pw
, ph
);
60 # elif defined(__APPLE_QUARTZ__)
61 // warning: Quartz does not support xor drawing
62 // Use the Fl_Overlay_Window instead.
64 fl_rect(px
, py
, pw
, ph
);
66 # error unsupported platform
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; }
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);
82 fl_line_style(FL_SOLID
);
83 fl_rect(px
, py
, pw
, ph
);
85 fl_line_style(FL_DOT
);
86 fl_rect(px
, py
, pw
, ph
);
87 fl_line_style(FL_SOLID
);
91 static void erase_current_rect() {
93 # ifdef __APPLE_QUARTZ__
94 fl_rect(px
, py
, pw
, ph
);
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
);
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;
120 if (x
==px
&& y
==py
&& w
==pw
&& h
==ph
) return;
121 erase_current_rect();
123 px
= x
; py
= y
; pw
= w
; ph
= h
;
128 // End of "$Id: fl_overlay.cxx 7903 2010-11-28 21:06:39Z matt $".