DRC | 2ff39b8 | 2011-07-28 08:38:59 +0000 | [diff] [blame] | 1 | // |
| 2 | // "$Id: Fl_Cairo_Window.H 8198 2011-01-06 10:24:58Z manolo $" |
| 3 | // |
| 4 | // Main header file 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. |
| 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
| 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 | /* \file |
| 29 | Fl_Cairo_Window Handling transparently a fltk window incorporte a cairo draw callback. |
| 30 | */ |
| 31 | |
| 32 | #ifndef FL_CAIRO_WINDOW_H |
| 33 | # define FL_CAIRO_WINDOW_H |
| 34 | # ifdef FLTK_HAVE_CAIRO |
| 35 | |
| 36 | // Cairo is currently supported for the following platforms: |
| 37 | // Win32, Apple Quartz, X11 |
| 38 | # include <FL/Fl.H> |
| 39 | # include <FL/Fl_Double_Window.H> |
| 40 | |
| 41 | /** |
| 42 | \addtogroup group_cairo |
| 43 | @{ |
| 44 | */ |
| 45 | |
| 46 | /** |
| 47 | This defines a pre-configured cairo fltk window. |
| 48 | This class overloads the virtual draw() method for you, |
| 49 | so that the only thing you have to do is to provide your cairo code. |
| 50 | All cairo context handling is achieved transparently. |
| 51 | \note You can alternatively define your custom cairo fltk window, |
| 52 | and thus at least override the draw() method to provide custom cairo |
| 53 | support. In this case you will probably use Fl::cairo_make_current(Fl_Window*) |
| 54 | to attach a context to your window. You should do it only when your window is |
| 55 | the current window. \see Fl_Window::current() |
| 56 | */ |
| 57 | class FL_EXPORT Fl_Cairo_Window : public Fl_Double_Window { |
| 58 | |
| 59 | public: |
| 60 | Fl_Cairo_Window(int w, int h) : Fl_Double_Window(w,h),draw_cb_(0) {} |
| 61 | |
| 62 | protected: |
| 63 | /** Overloaded to provide cairo callback support */ |
| 64 | void draw() { |
| 65 | Fl_Double_Window::draw(); |
| 66 | // manual method ? if yes explicitly get a cairo_context here |
| 67 | if (!Fl::cairo_autolink_context()) |
| 68 | Fl::cairo_make_current(this); |
| 69 | if (draw_cb_) draw_cb_(this, Fl::cairo_cc()); |
| 70 | } |
| 71 | |
| 72 | public: |
| 73 | /** This defines the cairo draw callback prototype that you must further */ |
| 74 | typedef void (*cairo_draw_cb) (Fl_Cairo_Window* self, cairo_t* def); |
| 75 | /** |
| 76 | You must provide a draw callback which will implement your cairo rendering. |
| 77 | This method will permit you to set your cairo callback to \p cb. |
| 78 | */ |
| 79 | void set_draw_cb(cairo_draw_cb cb){draw_cb_=cb;} |
| 80 | private: |
| 81 | cairo_draw_cb draw_cb_; |
| 82 | }; |
| 83 | |
| 84 | |
| 85 | /** @} */ |
| 86 | |
| 87 | # endif // FLTK_HAVE_CAIRO |
| 88 | #endif // FL_CAIRO_WINDOW_H |
| 89 | |
| 90 | // |
| 91 | // End of "$Id: Fl_Cairo_Window.H 8198 2011-01-06 10:24:58Z manolo $" . |
| 92 | // |