Fl_Cairo_Window.H 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //
  2. // "$Id: Fl_Cairo_Window.H 8864 2011-07-19 04:49:30Z greg.ercolano $"
  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. Distribution and use rights are outlined in
  9. // the file "COPYING" which should have been included with this file. If this
  10. // file is missing or damaged, see the license at:
  11. //
  12. // http://www.fltk.org/COPYING.php
  13. //
  14. // Please report all bugs and problems on the following page:
  15. //
  16. // http://www.fltk.org/str.php
  17. //
  18. /* \file
  19. Fl_Cairo_Window Handling transparently a fltk window incorporte a cairo draw callback.
  20. */
  21. #ifndef FL_CAIRO_WINDOW_H
  22. # define FL_CAIRO_WINDOW_H
  23. # ifdef FLTK_HAVE_CAIRO
  24. // Cairo is currently supported for the following platforms:
  25. // Win32, Apple Quartz, X11
  26. # include <FL/Fl.H>
  27. # include <FL/Fl_Double_Window.H>
  28. /**
  29. \addtogroup group_cairo
  30. @{
  31. */
  32. /**
  33. This defines a pre-configured cairo fltk window.
  34. This class overloads the virtual draw() method for you,
  35. so that the only thing you have to do is to provide your cairo code.
  36. All cairo context handling is achieved transparently.
  37. \note You can alternatively define your custom cairo fltk window,
  38. and thus at least override the draw() method to provide custom cairo
  39. support. In this case you will probably use Fl::cairo_make_current(Fl_Window*)
  40. to attach a context to your window. You should do it only when your window is
  41. the current window. \see Fl_Window::current()
  42. */
  43. class FL_EXPORT Fl_Cairo_Window : public Fl_Double_Window {
  44. public:
  45. Fl_Cairo_Window(int w, int h) : Fl_Double_Window(w,h),draw_cb_(0) {}
  46. protected:
  47. /** Overloaded to provide cairo callback support */
  48. void draw() {
  49. Fl_Double_Window::draw();
  50. // manual method ? if yes explicitly get a cairo_context here
  51. if (!Fl::cairo_autolink_context())
  52. Fl::cairo_make_current(this);
  53. if (draw_cb_) draw_cb_(this, Fl::cairo_cc());
  54. }
  55. public:
  56. /** This defines the cairo draw callback prototype that you must further */
  57. typedef void (*cairo_draw_cb) (Fl_Cairo_Window* self, cairo_t* def);
  58. /**
  59. You must provide a draw callback which will implement your cairo rendering.
  60. This method will permit you to set your cairo callback to \p cb.
  61. */
  62. void set_draw_cb(cairo_draw_cb cb){draw_cb_=cb;}
  63. private:
  64. cairo_draw_cb draw_cb_;
  65. DECLARE_CLASS_CHEAP_RTTI_2(Fl_Cairo_Window, public Fl_Double_Window)
  66. };
  67. /** @} */
  68. # endif // FLTK_HAVE_CAIRO
  69. #endif // FL_CAIRO_WINDOW_H
  70. //
  71. // End of "$Id: Fl_Cairo_Window.H 8864 2011-07-19 04:49:30Z greg.ercolano $" .
  72. //