Standardize API to "graphics context" across platforms

Rename fl_wl_cairo() to fl_wl_gc()
Add function cairo_t* fl_cairo_gc() under OPTION_USE_CAIRO
This commit is contained in:
ManoloFLTK 2023-04-13 10:02:40 +02:00
parent e6c9deb4a4
commit caaa11a96f
7 changed files with 14 additions and 16 deletions

View File

@ -35,7 +35,7 @@ extern FL_EXPORT struct wld_window *fl_wl_xid(const Fl_Window *win);
/** Returns the Fl_Window corresponding to a given the platform-specific window reference */
extern FL_EXPORT Fl_Window *fl_wl_find(struct wld_window *);
/** Returns the cairo context associated to the current window or Fl_Image_Surface */
extern FL_EXPORT cairo_t *fl_wl_cairo();
extern FL_EXPORT cairo_t *fl_wl_gc();
/** Returns the wl_compositor of the current Wayland session.
This allows, for example, to create a wl_surface with
\code

View File

@ -32,7 +32,8 @@ extern Window fl_x11_xid(const Fl_Window *win);
extern Fl_Window *fl_x11_find(Window xid);
/** Returns the X11-specific currently active graphics context. */
extern GC fl_x11_gc();
/** Returns the Cairo-specific currently active graphics context (OPTION_USE_CAIRO=On) */
extern cairo_t* fl_cairo_gc();
#else // ! FL_DOXYGEN
#ifndef FL_PLATFORM_H
@ -65,6 +66,10 @@ extern FL_EXPORT Colormap fl_colormap;
// drawing functions:
extern FL_EXPORT GC fl_gc;
#if FLTK_USE_CAIRO
typedef struct _cairo cairo_t;
extern FL_EXPORT cairo_t* fl_cairo_gc();
#endif
extern FL_EXPORT GC fl_x11_gc();
FL_EXPORT ulong fl_xpixel(Fl_Color i);
FL_EXPORT ulong fl_xpixel(uchar r, uchar g, uchar b);

View File

@ -1013,11 +1013,11 @@ struct wl_surface *fl_wl_surface(struct wld_window *wld_win)
Returns a pointer to the struct wl_surface corresponding to a show()'n
top-level window or subwindow.
cairo_t *fl_wl_cairo(void)
cairo_t *fl_wl_gc()
\par
Drawing natively to a Wayland window : Within an overridden Fl_Widget::draw() method,
or after a call to Fl_Window::make_current(), it's possible to draw
<u>using the Cairo library</u>. Function \c fl_wl_cairo() returns the adequate
<u>using the Cairo library</u>. Function \c fl_wl_gc() returns the adequate
\c cairo_t* value. Regular FLTK coordinates, with top-left origin, are to be used.
All FLTK-defined drawing functions (e.g., fl_rect(), fl_draw()) can be used too.

View File

@ -62,3 +62,7 @@ void Fl_X11_Cairo_Graphics_Driver::gc(void *value) {
void *Fl_X11_Cairo_Graphics_Driver::gc() {
return gc_;
}
extern FL_EXPORT cairo_t* fl_cairo_gc() {
return ((Fl_Cairo_Graphics_Driver*)fl_graphics_driver)->cr();
}

View File

@ -80,8 +80,6 @@ public:
static void buffer_release(struct wld_window *window);
static void buffer_commit(struct wld_window *window, struct flCairoRegion *r = NULL);
static void cairo_init(struct fl_wld_buffer *buffer, int width, int height, int stride, cairo_format_t format);
void *gc() FL_OVERRIDE;
void gc(void *gc) FL_OVERRIDE;
};
#endif // FL_WAYLAND_GRAPHICS_DRIVER_H

View File

@ -208,12 +208,3 @@ void Fl_Wayland_Graphics_Driver::copy_offscreen(int x, int y, int w, int h, Fl_O
cairo_surface_destroy(surf);
cairo_restore(cairo_);
}
void Fl_Wayland_Graphics_Driver::gc(void *off) {} // equivalent is done by set_buffer()
void *Fl_Wayland_Graphics_Driver::gc() {
return buffer_;
}

View File

@ -1817,7 +1817,7 @@ FL_EXPORT struct wl_surface *fl_wl_surface(struct wld_window *xid) {
}
cairo_t *fl_wl_cairo() {
cairo_t *fl_wl_gc() {
return ((Fl_Cairo_Graphics_Driver*)fl_graphics_driver)->cr();
}