|
fltk 1.3.0rc3
About: FLTK (Fast Light Tool Kit) is a cross-platform C++ GUI toolkit for UNIX/Linux (X11), Microsoft Windows, and MacOS X. Release candidate.
SfR Fresh Dox: fltk-1.3.0rc3-source.tar.gz ("inofficial" and yet experimental doxygen-generated source code documentation) ![]() |
00001 // 00002 // "$Id: fl_overlay.cxx 7903 2010-11-28 21:06:39Z matt $" 00003 // 00004 // Overlay support for the Fast Light Tool Kit (FLTK). 00005 // 00006 // Copyright 1998-2010 by Bill Spitzak and others. 00007 // 00008 // This library is free software; you can redistribute it and/or 00009 // modify it under the terms of the GNU Library General Public 00010 // License as published by the Free Software Foundation; either 00011 // version 2 of the License, or (at your option) any later version. 00012 // 00013 // This library is distributed in the hope that it will be useful, 00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 // Library General Public License for more details. 00017 // 00018 // You should have received a copy of the GNU Library General Public 00019 // License along with this library; if not, write to the Free Software 00020 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00021 // USA. 00022 // 00023 // Please report all bugs and problems on the following page: 00024 // 00025 // http://www.fltk.org/str.php 00026 // 00027 00028 // Extremely limited "overlay" support. You can use this to drag out 00029 // a rectangle in response to mouse events. It is your responsibility 00030 // to erase the overlay before drawing anything that might intersect 00031 // it. 00032 00033 #include <FL/x.H> 00034 #include <FL/fl_draw.H> 00035 #ifdef __APPLE__ 00036 #include <config.h> 00037 #endif 00038 00039 //#define USE_XOR 00040 00041 static int px,py,pw,ph; 00042 00043 #ifndef USE_XOR 00044 #include <stdlib.h> 00045 static uchar *bgN = 0L, *bgS = 0L, *bgE = 0L, *bgW = 0L; 00046 static int bgx, bgy, bgw, bgh; 00047 #endif 00048 00049 static void draw_current_rect() { 00050 #ifdef USE_XOR 00051 # if defined(USE_X11) 00052 XSetFunction(fl_display, fl_gc, GXxor); 00053 XSetForeground(fl_display, fl_gc, 0xffffffff); 00054 XDrawRectangle(fl_display, fl_window, fl_gc, px, py, pw, ph); 00055 XSetFunction(fl_display, fl_gc, GXcopy); 00056 # elif defined(WIN32) 00057 int old = SetROP2(fl_gc, R2_NOT); 00058 fl_rect(px, py, pw, ph); 00059 SetROP2(fl_gc, old); 00060 # elif defined(__APPLE_QUARTZ__) 00061 // warning: Quartz does not support xor drawing 00062 // Use the Fl_Overlay_Window instead. 00063 fl_color(FL_WHITE); 00064 fl_rect(px, py, pw, ph); 00065 # else 00066 # error unsupported platform 00067 # endif 00068 #else 00069 if (bgN) { free(bgN); bgN = 0L; } 00070 if (bgS) { free(bgS); bgS = 0L; } 00071 if (bgE) { free(bgE); bgE = 0L; } 00072 if (bgW) { free(bgW); bgW = 0L; } 00073 if (pw>0 && ph>0) { 00074 bgE = fl_read_image(0L, px+pw-1, py, 1, ph); 00075 bgW = fl_read_image(0L, px, py, 1, ph); 00076 bgS = fl_read_image(0L, px, py+ph-1, pw, 1); 00077 bgN = fl_read_image(0L, px, py, pw, 1); 00078 bgx = px; bgy = py; 00079 bgw = pw; bgh = ph; 00080 } 00081 fl_color(FL_WHITE); 00082 fl_line_style(FL_SOLID); 00083 fl_rect(px, py, pw, ph); 00084 fl_color(FL_BLACK); 00085 fl_line_style(FL_DOT); 00086 fl_rect(px, py, pw, ph); 00087 fl_line_style(FL_SOLID); 00088 #endif 00089 } 00090 00091 static void erase_current_rect() { 00092 #ifdef USE_XOR 00093 # ifdef __APPLE_QUARTZ__ 00094 fl_rect(px, py, pw, ph); 00095 # else 00096 draw_current_rect(); 00097 # endif 00098 #else 00099 if (bgN) fl_draw_image(bgN, bgx, bgy, bgw, 1); 00100 if (bgS) fl_draw_image(bgS, bgx, bgy+bgh-1, bgw, 1); 00101 if (bgW) fl_draw_image(bgW, bgx, bgy, 1, bgh); 00102 if (bgE) fl_draw_image(bgE, bgx+bgw-1, bgy, 1, bgh); 00103 #endif 00104 } 00105 00109 void fl_overlay_clear() { 00110 if (pw > 0) {erase_current_rect(); pw = 0;} 00111 } 00112 00116 void fl_overlay_rect(int x, int y, int w, int h) { 00117 if (w < 0) {x += w; w = -w;} else if (!w) w = 1; 00118 if (h < 0) {y += h; h = -h;} else if (!h) h = 1; 00119 if (pw > 0) { 00120 if (x==px && y==py && w==pw && h==ph) return; 00121 erase_current_rect(); 00122 } 00123 px = x; py = y; pw = w; ph = h; 00124 draw_current_rect(); 00125 } 00126 00127 // 00128 // End of "$Id: fl_overlay.cxx 7903 2010-11-28 21:06:39Z matt $". 00129 //