|
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_Cairo.cxx 8198 2011-01-06 10:24:58Z manolo $" 00003 // 00004 // Main header file 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 #include <config.h> 00029 00030 #ifdef FLTK_HAVE_CAIRO 00031 #include <FL/Fl.H> 00032 #include <FL/x.H> 00033 #include <FL/Fl_Window.H> 00034 #ifdef __APPLE__ 00035 #include <Carbon/Carbon.h> 00036 #endif 00037 00038 // static Fl module initialization : 00039 Fl_Cairo_State Fl::cairo_state_; 00040 00041 00042 // Fl cairo features implementation 00043 00044 // Fl_Cairo_State class impl 00045 00046 void Fl_Cairo_State::autolink(bool b) { 00047 #ifdef FLTK_USE_CAIRO 00048 autolink_ = b; 00049 #else 00050 Fl::fatal("In Fl::autolink(bool) : Cairo autolink() feature is only " 00051 "available with the enable-cairoext configure option, now quitting."); 00052 #endif 00053 } 00054 00071 cairo_t * Fl::cairo_make_current(Fl_Window* wi) { 00072 if (!wi) return NULL; // Precondition 00073 00074 if (fl_gc==0) { // means remove current cc 00075 Fl::cairo_cc(0); // destroy any previous cc 00076 cairo_state_.window(0); 00077 return 0; 00078 } 00079 00080 // don't re-create a context if it's the same gc/window couple 00081 if (fl_gc==Fl::cairo_state_.gc() && fl_xid(wi) == (Window) Fl::cairo_state_.window()) 00082 return Fl::cairo_cc(); 00083 00084 cairo_state_.window(wi); 00085 00086 #if defined(USE_X11) 00087 return Fl::cairo_make_current(0, wi->w(), wi->h()); 00088 #else 00089 return Fl::cairo_make_current(fl_gc, wi->w(), wi->h()); 00090 #endif 00091 } 00092 00093 /* 00094 Creates transparently a cairo_surface_t object. 00095 gc is an HDC context in WIN32, a CGContext* in Quartz, a display on X11 00096 */ 00097 static cairo_surface_t * cairo_create_surface(void * gc, int W, int H) { 00098 # if defined(USE_X11) 00099 return cairo_xlib_surface_create(fl_display, fl_window, fl_visual->visual, W, H); 00100 # elif defined(WIN32) 00101 return cairo_win32_surface_create((HDC) gc); 00102 # elif defined(__APPLE_QUARTZ__) 00103 return cairo_quartz_surface_create_for_cg_context((CGContext*) gc, W, H); 00104 # else 00105 # error Cairo is not supported under this platform. 00106 # endif 00107 } 00108 00113 cairo_t * Fl::cairo_make_current(void *gc) { 00114 int W=0,H=0; 00115 #if defined(USE_X11) 00116 //FIXME X11 get W,H 00117 // gc will be the window handle here 00118 # warning FIXME get W,H for cairo_make_current(void*) 00119 #elif defined(__APPLE_QUARTZ__) 00120 if (fl_window) { 00121 Rect portRect; 00122 GetPortBounds(GetWindowPort( Fl_X::i(Fl_Window::current())->window_ref() ), &portRect); 00123 W = portRect.right-portRect.left; 00124 H = portRect.bottom-portRect.top; 00125 } 00126 else { 00127 W = CGBitmapContextGetHeight(fl_gc); 00128 H = CGBitmapContextGetHeight(fl_gc); 00129 } 00130 #elif defined(WIN32) 00131 // we don't need any W,H for WIN32 00132 #else 00133 # error Cairo is not supported under this platform. 00134 #endif 00135 if (!gc) { 00136 Fl::cairo_cc(0); 00137 cairo_state_.gc(0); // keep track for next time 00138 return 0; 00139 } 00140 if (gc==Fl::cairo_state_.gc() && fl_window== (Window) Fl::cairo_state_.window()) 00141 return Fl::cairo_cc(); 00142 cairo_state_.gc(fl_gc); // keep track for next time 00143 cairo_surface_t * s = cairo_create_surface(gc, W, H); 00144 cairo_t * c = cairo_create(s); 00145 cairo_surface_destroy(s); 00146 Fl::cairo_cc(c); 00147 return c; 00148 } 00149 00154 cairo_t * Fl::cairo_make_current(void *gc, int W, int H) { 00155 cairo_surface_t * s = cairo_create_surface(gc, W, H); 00156 cairo_t * c = cairo_create(s); 00157 cairo_surface_destroy(s); 00158 Fl::cairo_cc(c); 00159 return c; 00160 } 00161 #else 00162 // just don't leave the libfltk_cairo lib empty to avoid warnings 00163 #include <FL/Fl_Export.H> 00164 FL_EXPORT int fltk_cairo_dummy() { return 1;} 00165 #endif // FLTK_HAVE_CAIRO 00166 00167 // 00168 // End of "$Id: Fl_Cairo.cxx 8198 2011-01-06 10:24:58Z manolo $" . 00169 //