FLTK
Fl_Cairo_Window.H
1 //
2 // Main header file for the Fast Light Tool Kit (FLTK).
3 //
4 // Copyright 1998-2018 by Bill Spitzak and others.
5 //
6 // This library is free software. Distribution and use rights are outlined in
7 // the file "COPYING" which should have been included with this file. If this
8 // file is missing or damaged, see the license at:
9 //
10 // https://www.fltk.org/COPYING.php
11 //
12 // Please see the following page on how to report bugs and issues:
13 //
14 // https://www.fltk.org/bugs.php
15 //
16 
17 /* \file
18  Fl_Cairo_Window Handling transparently a FLTK window incorporating a cairo draw callback.
19 */
20 
21 #ifndef FL_CAIRO_WINDOW_H
22 # define FL_CAIRO_WINDOW_H
23 # ifdef FLTK_HAVE_CAIRO
24 
25 // Cairo is currently supported for the following platforms:
26 // Win32, Apple Quartz, X11
27 # include <FL/Fl.H>
28 # include <FL/Fl_Double_Window.H>
29 
48 class FL_EXPORT Fl_Cairo_Window : public Fl_Double_Window {
49 
50 public:
51  Fl_Cairo_Window(int W, int H, const char *L = 0)
52  : Fl_Double_Window(W, H, L), draw_cb_(0) {}
53  Fl_Cairo_Window(int X, int Y, int W, int H, const char *L = 0)
54  : Fl_Double_Window(X, Y, W, H, L), draw_cb_(0) {}
55 
56 protected:
58  void draw() {
60  if (draw_cb_) { // call the Cairo draw callback
61  // manual method ? if yes explicitly get a cairo_context here
64  draw_cb_(this, Fl::cairo_cc());
65  // flush cairo drawings: necessary at least for Windows
66  cairo_surface_t *s = cairo_get_target(Fl::cairo_cc());
67  cairo_surface_flush(s);
68  }
69  }
70 
71 public:
73  typedef void (*cairo_draw_cb) (Fl_Cairo_Window* self, cairo_t* def);
78  void set_draw_cb(cairo_draw_cb cb) { draw_cb_ = cb; }
79 private:
80  cairo_draw_cb draw_cb_;
81 };
82 
83 
86 # endif // FLTK_HAVE_CAIRO
87 #endif // FL_CAIRO_WINDOW_H
void draw()
Draws the widget.
Definition: Fl_Window.cxx:482
Fl static class.
The Fl_Double_Window provides a double-buffered window.
Definition: Fl_Double_Window.H:38
static bool cairo_autolink_context()
Gets the current autolink mode for cairo support.
Definition: Fl.H:1382
Fl_Double_Window(int W, int H, const char *l=0)
Creates a new Fl_Double_Window widget using the given position, size, and label (title) string...
Definition: Fl_Double_Window.cxx:31
static cairo_t * cairo_make_current(Fl_Window *w)
Provides a corresponding cairo context for window wi.
Definition: Fl_Cairo.cxx:70
static cairo_t * cairo_cc()
Gets the current cairo context linked with a fltk window.
Definition: Fl.H:1384
void set_draw_cb(cairo_draw_cb cb)
You must provide a draw callback which will implement your cairo rendering.
Definition: Fl_Cairo_Window.H:78
This defines a FLTK window with cairo support.
Definition: Fl_Cairo_Window.H:48
void draw()
Overloaded to provide cairo callback support.
Definition: Fl_Cairo_Window.H:58