Fix Cairo drawing in test/cairo_test demo for Windows (#694)
On the Windows platform Cairo drawings must be flushed explicitly. This is done in Fl_Cairo_Window after calling the draw callback but it was neither done nor documented in test/cairo_test.cxx when using another type of Window with its overloaded draw() method, i.e. when FLTK was configured with --enable-cairoext or CMake OPTION_CAIROEXT. Note: user code must either explicitly flush the Cairo drawings as done here or destroy the Cairo context which is not done in this demo because the Cairo context should be kept alive.
This commit is contained in:
parent
73a2ca5261
commit
6e407cb169
@ -151,7 +151,7 @@ void draw_image(cairo_t *cr, int w, int h) {
|
||||
|
||||
typedef Fl_Cairo_Window cairo_using_window;
|
||||
|
||||
#else // !USE_FL_CAIRO_WINDOW
|
||||
#else // !USE_FL_CAIRO_WINDOW || defined(FLTK_HAVE_CAIROEXT)
|
||||
|
||||
class cairo_using_window : public Fl_Double_Window {
|
||||
void (*draw_with_cairo_)(cairo_using_window*, cairo_t*);
|
||||
@ -169,7 +169,15 @@ public:
|
||||
Fl::cairo_make_current(this); // announce Cairo will be used in this window
|
||||
#endif
|
||||
cairo_t *cc = Fl::cairo_cc(); // get the adequate Cairo context
|
||||
draw_with_cairo_(this, cc); // draw in this window using Cairo
|
||||
draw_with_cairo_(this, cc); // draw in this window using Cairo
|
||||
|
||||
// flush Cairo drawings: necessary at least for Windows
|
||||
// see also FL/Fl_Cairo_Window.H
|
||||
// FIXME: this should be simplified with an FLTK API, for instance:
|
||||
// Fl::cairo_flush(cc);
|
||||
|
||||
cairo_surface_t *s = cairo_get_target(Fl::cairo_cc());
|
||||
cairo_surface_flush(s);
|
||||
}
|
||||
void set_draw_cb( void (*cb)(cairo_using_window*, cairo_t*)) {
|
||||
draw_with_cairo_ = cb;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user