diff options
| author | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2022-03-31 10:35:50 +0200 |
|---|---|---|
| committer | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2022-03-31 10:36:01 +0200 |
| commit | d9a6ec88e47b9c3c7993018f4f2be13d55b8fca2 (patch) | |
| tree | f0c68938623020dd949369f944b7469a9101c28e /src/drivers | |
| parent | a638f5a545817365897bc7892999b74d3ef83e34 (diff) | |
Add support of Fl_Region to the Cairo graphics driver
and remove it from the Wayland graphics driver.
Diffstat (limited to 'src/drivers')
| -rw-r--r-- | src/drivers/Cairo/Fl_Cairo_Graphics_Driver.H | 3 | ||||
| -rw-r--r-- | src/drivers/Cairo/Fl_Cairo_Graphics_Driver.cxx | 63 | ||||
| -rw-r--r-- | src/drivers/Wayland/Fl_Wayland_Graphics_Driver.H | 4 | ||||
| -rw-r--r-- | src/drivers/Wayland/Fl_Wayland_Graphics_Driver.cxx | 50 |
4 files changed, 61 insertions, 59 deletions
diff --git a/src/drivers/Cairo/Fl_Cairo_Graphics_Driver.H b/src/drivers/Cairo/Fl_Cairo_Graphics_Driver.H index b291f63b0..8345fbd47 100644 --- a/src/drivers/Cairo/Fl_Cairo_Graphics_Driver.H +++ b/src/drivers/Cairo/Fl_Cairo_Graphics_Driver.H @@ -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 diff --git a/src/drivers/Cairo/Fl_Cairo_Graphics_Driver.cxx b/src/drivers/Cairo/Fl_Cairo_Graphics_Driver.cxx index 036fe5418..a93b128e5 100644 --- a/src/drivers/Cairo/Fl_Cairo_Graphics_Driver.cxx +++ b/src/drivers/Cairo/Fl_Cairo_Graphics_Driver.cxx @@ -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 diff --git a/src/drivers/Wayland/Fl_Wayland_Graphics_Driver.H b/src/drivers/Wayland/Fl_Wayland_Graphics_Driver.H index 379db286f..c2d5f9554 100644 --- a/src/drivers/Wayland/Fl_Wayland_Graphics_Driver.H +++ b/src/drivers/Wayland/Fl_Wayland_Graphics_Driver.H @@ -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); diff --git a/src/drivers/Wayland/Fl_Wayland_Graphics_Driver.cxx b/src/drivers/Wayland/Fl_Wayland_Graphics_Driver.cxx index d0ef19724..c593a207b 100644 --- a/src/drivers/Wayland/Fl_Wayland_Graphics_Driver.cxx +++ b/src/drivers/Wayland/Fl_Wayland_Graphics_Driver.cxx @@ -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; |
