From 78d3a6b6ef840cf1e6d6373c98578c4f51e4dc16 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Wed, 10 May 2023 14:26:42 -0400 Subject: [PATCH] GC & Drawing: Further work on clipping. Still disabled as it does not work correctly. --- xlib/Drawing.cpp | 6 ++++++ xlib/GC.cpp | 20 ++++++++++++++------ xlib/GC.h | 1 + 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/xlib/Drawing.cpp b/xlib/Drawing.cpp index 3e5c4ad..a0cf878 100644 --- a/xlib/Drawing.cpp +++ b/xlib/Drawing.cpp @@ -25,11 +25,13 @@ extern "C" { class DrawStateManager { XDrawable* _drawable; + GC _gc; public: DrawStateManager(Drawable w, GC gc) { _drawable = Drawables::get(w); + _gc = gc; if (!_drawable) return; @@ -41,6 +43,10 @@ class DrawStateManager if (!_drawable) return; + if (_x_gc_has_clipping(_gc)) { + _drawable->view()->ConstrainClippingRegion(NULL); + _gc->dirty |= GCClipMask; + } _drawable->view()->UnlockLooper(); } diff --git a/xlib/GC.cpp b/xlib/GC.cpp index 0c8e2fd..0248ff9 100644 --- a/xlib/GC.cpp +++ b/xlib/GC.cpp @@ -412,6 +412,16 @@ XSetClipMask(Display* display, GC gc, Pixmap pixmap) return Success; } +bool +_x_gc_has_clipping(GC gc) +{ + ClipMask* mask = gc_clip_mask(gc, false); + if (!mask) + return false; + + return mask->region.CountRects() > 0; +} + extern "C" Status XSetDashes(Display *display, GC gc, int dash_offset, const char *dash_list, int n) { @@ -561,17 +571,15 @@ _x_check_gc(XDrawable* drawable, GC gc) } if (gc->dirty & (GCClipMask | GCClipXOrigin | GCClipYOrigin)) { - //view->ConstrainClippingRegion(NULL); - ClipMask* mask = gc_clip_mask(gc, false); - if (mask && mask->region.CountRects()) { - // TODO: Breaks getting Expose messages! - UNIMPLEMENTED(); #if 0 + view->ConstrainClippingRegion(NULL); + ClipMask* mask = gc_clip_mask(gc, false); + if (mask && mask->region.CountRects() > 0) { BRegion region = mask->region; region.OffsetBy(gc->values.clip_x_origin, gc->values.clip_y_origin); view->ConstrainClippingRegion(®ion); -#endif } +#endif } gc->dirty = 0; diff --git a/xlib/GC.h b/xlib/GC.h index 20bbf0a..f16d022 100644 --- a/xlib/GC.h +++ b/xlib/GC.h @@ -8,3 +8,4 @@ namespace BeXlib { class XDrawable; } void _x_check_gc(BeXlib::XDrawable* drawable, GC gc); +bool _x_gc_has_clipping(GC gc);