FLTK logo

Re: [fltk.coredev] WIP: new Cairo support features

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.coredev  ]
 
Previous Message ]New Message | Reply ]Next Message ]

Re: WIP: new Cairo support features Albrecht Schlosser Mar 22, 2023  
 
On 3/22/23 14:07 Albrecht Schlosser wrote:
On 3/22/23 08:33 Manolo wrote:
Under Wayland, the adequate API already exists :

[...]

I'll try your code and update my branch accordingly.

Done. The current demo program can draw with Cairo:

- on all supported platforms (in windows and/or widgets)
- on Fl_Image_Surface and Fl_Copy_Surface
- very likely on other FLTK surfaces as well (untested)

See the complete code: https://github.com/Albrecht-S/fltk/blob/Fl_Cairo2a/test/cairo2_image.cxx
(note that this branch will be deleted at some time and thus this link will probably become stale [1]).

@Manolo: Thank you very much for the code on several platforms.

BTW: I added cairo_surface_destroy() where applicable in this demo program.

I can now finish my work on the new Cairo support (Fl_Cairo2*).


[1] Relevant code as of now for reference (slightly edited):

// Create a Cairo context that can be used on an FLTK drawing surface.
// In this demo we assume that the surface is the "current surface" after
// 'Fl_Surface_Device::push_current(surf)'.
cairo_t *cairo_context(Fl_Widget_Surface *surf, int W, int H) {
cairo_surface_t *cairo_surface = NULL;
cairo_t *cairo_context = NULL;
// Windows
#if defined(_WIN32)
cairo_surface = cairo_win32_surface_create(fl_win32_gc());
cairo_context = cairo_create(cairo_surface);
cairo_surface_destroy(cairo_surface);
return cairo_context;
#endif
// Wayland
#ifdef FLTK_USE_WAYLAND
if (fl_wl_display()) { // to avoid when the hybrid library is in x11 mode
cairo_context = fl_wl_cairo();
return cairo_context;
}
#endif
// X11
#if defined(FLTK_USE_X11)
cairo_surface = cairo_xlib_surface_create(fl_display, fl_window, fl_visual->visual, W, H);
cairo_context = cairo_create(cairo_surface);
cairo_surface_destroy(cairo_surface);
return cairo_context;
#endif
// macOS
#if defined(__APPLE__) && !defined(FLTK_USE_X11)
#include <ApplicationServices/ApplicationServices.h>
#include <cairo-quartz.h>
CGContextRef gc = fl_mac_gc();
cairo_surface = cairo_quartz_surface_create_for_cg_context(gc, W, H);
cairo_context = cairo_create(cairo_surface);
cairo_surface_destroy(cairo_surface);
return cairo_context;
#endif
// remaining platforms (shouldn't be any)
return NULL;
} // cairo_context(Fl_Widget_Surface *surf)

  


--
You received this message because you are subscribed to the Google Groups "fltk.coredev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkcoredev+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkcoredev/37898953-e20b-a5de-e301-7626723e35fd%40online.de.
Direct Link to Message ]
 
     
Previous Message ]New Message | Reply ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.