You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
2.9KB

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