Add support of Fl_Region to the Cairo graphics driver

and remove it from the Wayland graphics driver.
This commit is contained in:
ManoloFLTK 2022-03-31 10:35:50 +02:00
parent a638f5a545
commit d9a6ec88e4
7 changed files with 70 additions and 61 deletions

View File

@ -115,7 +115,7 @@ typedef struct HGLRC__ *GLContext;
#elif defined(FLTK_USE_WAYLAND)
typedef struct fl_wld_buffer *Fl_Offscreen; /**< an offscreen drawing buffer */
typedef struct flWaylandRegion* Fl_Region;
typedef struct flCairoRegion* Fl_Region;
typedef int FL_SOCKET; /**< socket or file descriptor */
typedef void *EGLContext;
typedef EGLContext GLContext;

View File

@ -20,7 +20,7 @@
typedef struct wld_window *Window;
struct flWaylandRegion {
struct flCairoRegion {
int count;
struct _cairo_rectangle *rects;
}; // a region is the union of a series of rectangles

View File

@ -86,6 +86,13 @@ extern FL_EXPORT Fl_XFont_On_Demand fl_xfont;
extern FL_EXPORT char fl_override_redirect; // hack into Fl_X::make_xid()
#if USE_PANGO
struct flCairoRegion {
int count;
struct _cairo_rectangle *rects;
}; // a region is the union of a series of rectangles
#endif
#endif // FL_LIBRARY || FL_INTERNALS
#endif // FL_DOXYGEN

View File

@ -176,6 +176,9 @@ public:
virtual const char *font_name(int num);
virtual void font_name(int num, const char *name); virtual const char* get_font_name(Fl_Font fnum, int* ap);
virtual int get_font_sizes(Fl_Font fnum, int*& sizep);
virtual Fl_Region XRectangleRegion(int x, int y, int w, int h);
virtual void XDestroyRegion(Fl_Region r);
virtual void add_rectangle_to_region(Fl_Region r, int X, int Y, int W, int H);
};
#endif // FL_CAIRO_GRAPHICS_DRIVER_H

View File

@ -621,11 +621,6 @@ int Fl_Cairo_Graphics_Driver::clip_box(int x, int y, int w, int h, int &X, int &
}
void Fl_Cairo_Graphics_Driver::restore_clip() {
if (cairo_) cairo_reset_clip(cairo_);
}
void Fl_Cairo_Graphics_Driver::point(int x, int y) {
rectf(x, y, 1, 1);
}
@ -1178,5 +1173,63 @@ void Fl_Cairo_Graphics_Driver::text_extents(const char* txt, int n, int& dx, int
h = ink_rect.height;
}
//
// Region-handling member functions.
// They are used ONLY if the cairo graphics driver is the display graphics driver.
// They are not used if the cairo graphics driver is used to draw PostScript.
//
Fl_Region Fl_Cairo_Graphics_Driver::XRectangleRegion(int x, int y, int w, int h) {
struct flCairoRegion *R = (struct flCairoRegion*)malloc(sizeof(*R));
R->count = 1;
R->rects = (cairo_rectangle_t *)malloc(sizeof(cairo_rectangle_t));
R->rects->x=x, R->rects->y=y, R->rects->width=w; R->rects->height=h;
return (Fl_Region)R;
}
// r1 ⊂ r2
static bool CairoRectContainsRect(cairo_rectangle_t *r1, cairo_rectangle_t *r2) {
return r1->x >= r2->x && r1->y >= r2->y && r1->x+r1->width <= r2->x+r2->width &&
r1->y+r1->height <= r2->y+r2->height;
}
void Fl_Cairo_Graphics_Driver::add_rectangle_to_region(Fl_Region r_, int X, int Y, int W, int H) {
struct flCairoRegion *r = (struct flCairoRegion*)r_;
cairo_rectangle_t arg = {double(X), double(Y), double(W), double(H)};
int j; // don't add a rectangle totally inside the Fl_Region
for (j = 0; j < r->count; j++) {
if (CairoRectContainsRect(&arg, &(r->rects[j]))) break;
}
if (j >= r->count) {
r->rects = (cairo_rectangle_t*)realloc(r->rects, (++(r->count)) * sizeof(cairo_rectangle_t));
r->rects[r->count - 1] = arg;
}
}
void Fl_Cairo_Graphics_Driver::XDestroyRegion(Fl_Region r_) {
if (r_) {
struct flCairoRegion *r = (struct flCairoRegion*)r_;
free(r->rects);
free(r);
}
}
void Fl_Cairo_Graphics_Driver::restore_clip() {
if (cairo_) {
cairo_reset_clip(cairo_);
// apply what's in rstack
struct flCairoRegion *r = (struct flCairoRegion*)rstack[rstackptr];
if (r) {
for (int i = 0; i < r->count; i++) {
cairo_rectangle(cairo_, r->rects[i].x, r->rects[i].y, r->rects[i].width, r->rects[i].height);
}
cairo_clip(cairo_);
}
}
}
#endif // USE_PANGO

View File

@ -77,10 +77,6 @@ public:
Fl_Wayland_Graphics_Driver();
static const uint32_t wld_format;
void activate(struct fl_wld_buffer *buffer, float scale);
void clip_region(Fl_Region r);
Fl_Region XRectangleRegion(int x, int y, int w, int h);
void add_rectangle_to_region(Fl_Region r, int X, int Y, int W, int H);
void XDestroyRegion(Fl_Region r);
void set_color(Fl_Color i, unsigned c);
void copy_offscreen(int x, int y, int w, int h, Fl_Offscreen osrc, int srcx, int srcy);
static struct fl_wld_buffer *create_shm_buffer(int width, int height);

View File

@ -177,56 +177,6 @@ void Fl_Wayland_Graphics_Driver::activate(struct fl_wld_buffer *buffer, float sc
}
void Fl_Wayland_Graphics_Driver::clip_region(Fl_Region r) {
if (cairo_) {
cairo_reset_clip(cairo_);
if (r) {
for (int i = 0; i < r->count; i++) {
cairo_rectangle(cairo_, r->rects[i].x-0.5 , r->rects[i].y-0.5 , r->rects[i].width , r->rects[i].height);
}
cairo_clip(cairo_);
}
}
}
Fl_Region Fl_Wayland_Graphics_Driver::XRectangleRegion(int x, int y, int w, int h) {
Fl_Region R = (Fl_Region)malloc(sizeof(*R));
R->count = 1;
R->rects = (cairo_rectangle_t *)malloc(sizeof(cairo_rectangle_t));
R->rects->x=x, R->rects->y=y, R->rects->width=w; R->rects->height=h;
return R;
}
// r1 ⊂ r2
static bool CairoRectContainsRect(cairo_rectangle_t *r1, cairo_rectangle_t *r2) {
return r1->x >= r2->x && r1->y >= r2->y && r1->x+r1->width <= r2->x+r2->width &&
r1->y+r1->height <= r2->y+r2->height;
}
void Fl_Wayland_Graphics_Driver::add_rectangle_to_region(Fl_Region r, int X, int Y, int W, int H) {
cairo_rectangle_t arg = {double(X), double(Y), double(W), double(H)};
int j; // don't add a rectangle totally inside the Fl_Region
for (j = 0; j < r->count; j++) {
if (CairoRectContainsRect(&arg, &(r->rects[j]))) break;
}
if (j >= r->count) {
r->rects = (cairo_rectangle_t*)realloc(r->rects, (++(r->count)) * sizeof(cairo_rectangle_t));
r->rects[r->count - 1] = arg;
}
}
void Fl_Wayland_Graphics_Driver::XDestroyRegion(Fl_Region r) {
if (r) {
free(r->rects);
free(r);
}
}
void Fl_Wayland_Graphics_Driver::set_color(Fl_Color i, unsigned c) {
if (fl_cmap[i] != c) {
fl_cmap[i] = c;