changeset 1905:370e97c9f39b

port line clipping on expose rectangle to avoid X11 coordinate overflows
author Johannes Hofmann <Johannes.Hofmann@gmx.de>
date Thu, 17 Feb 2011 21:26:04 +0100
parents a629521ec82a
children 3d4b69d3eee7 22d9dd1fb523
files dw/fltkviewbase.cc dw/fltkviewbase.hh
diffstat 2 files changed, 27 insertions(+), 82 deletions(-) [+]
line wrap: on
line diff
--- a/dw/fltkviewbase.cc	Tue Feb 15 19:02:54 2011 +0000
+++ b/dw/fltkviewbase.cc	Thu Feb 17 21:26:04 2011 +0100
@@ -71,10 +71,7 @@
    canvasHeight = 1;
    bgColor = FL_WHITE;
    mouse_x = mouse_y = 0;
-#if 0
-PORT1.3
    exposeArea = NULL;
-#endif
    if (backBuffer == NULL) {
       backBuffer = new BackBuffer ();
    }
@@ -134,67 +131,6 @@
 void FltkViewBase::draw (const core::Rectangle *rect,
                          DrawType type)
 {
-#if 0
-PORT1.3
-   int offsetX = 0, offsetY = 0;
-
-   /* fltk-clipping does not use widget coordinates */
-   transform (offsetX, offsetY);
-
-   ::fltk::Rectangle viewRect (
-      translateCanvasXToViewX (rect->x) + offsetX,
-      translateCanvasYToViewY (rect->y) + offsetY,
-      rect->width, rect->height);
-
-   ::fltk::intersect_with_clip (viewRect);
-
-   viewRect.x (viewRect.x () - offsetX);
-   viewRect.y (viewRect.y () - offsetY);A
-
-   if (! viewRect.empty ()) {
-      dw::core::Rectangle r (
-         translateViewXToCanvasX (viewRect.x ()),
-         translateViewYToCanvasY (viewRect.y ()),
-         viewRect.w (),
-         viewRect.h ());
-
-      exposeArea = &viewRect;
-
-      if (type == DRAW_BUFFERED && backBuffer && !backBufferInUse) {
-         backBufferInUse = true;
-         {
-            GSave gsave;
-
-            backBuffer->setsize (viewRect.w (), viewRect.h ());
-            backBuffer->make_current ();
-            translate (-viewRect.x (), -viewRect.y ());
-
-            setcolor (bgColor);
-            fillrect (viewRect);
-            theLayout->expose (this, &r);
-         }
-
-         backBuffer->draw (Rectangle (0, 0, viewRect.w (), viewRect.h ()),
-            viewRect);
-
-         backBufferInUse = false;
-      } else if (type == DRAW_BUFFERED || type == DRAW_CLIPPED) {
-         // if type == DRAW_BUFFERED but we do not have backBuffer available
-         // we fall back to clipped drawing
-         fl_push_clip (viewRect);
-         setcolor (bgColor);
-         fillrect (viewRect);
-         theLayout->expose (this, &r);
-         fl_pop_clip ();
-      } else {
-         setcolor (bgColor);
-         fillrect (viewRect);
-         theLayout->expose (this, &r);
-      }
-
-      exposeArea = NULL;
-   }
-#endif
    int X, Y, W, H;
    
    fl_clip_box(translateCanvasXToViewX (rect->x),
@@ -209,6 +145,8 @@
    if (r.isEmpty ())
       return;
 
+   exposeArea = &r;
+
    if (type == DRAW_BUFFERED && backBuffer && !backBufferInUse) {
       backBufferInUse = true;
       backBuffer->setSize (X + W, Y + H); // would be nicer to use (W, H)...
@@ -234,6 +172,8 @@
       fl_rectf (X, Y, W, H);
       theLayout->expose (this, &r);
    }
+
+   exposeArea = NULL;
 }
 
 void FltkViewBase::drawChildWidgets () {
@@ -434,6 +374,11 @@
                              int x1, int y1, int x2, int y2)
 {
    fl_color(((FltkColor*)color)->colors[shading]);
+   // we clip with a large border (5000px), as clipping causes artefacts
+   // with non-solid line styles.
+   // However it's still better than no clipping at all.
+   clipPoint (&x1, &y1, 5000);
+   clipPoint (&x2, &y2, 5000);
    fl_line (translateCanvasXToViewX (x1),
             translateCanvasYToViewY (y1),
             translateCanvasXToViewX (x2),
@@ -488,19 +433,21 @@
       height = -height;
    }
 
-   int x1 = translateCanvasXToViewX (X);
-   int y1 = translateCanvasYToViewY (Y);
-   int x2 = translateCanvasXToViewX (X + width);
-   int y2 = translateCanvasYToViewY (Y + height);
+   int x1 = X;
+   int y1 = Y;
+   int x2 = X + width;
+   int y2 = Y + height;
 
-#if 0
-PORT1.3
    // We only support rectangles with line width 1px, so we clip with
    // a rectangle 1px wider and higher than what we actually expose.
    // This is only really necessary for non-filled rectangles.
    clipPoint (&x1, &y1, 1);
    clipPoint (&x2, &y2, 1);
-#endif
+
+   x1 = translateCanvasXToViewX (x1);
+   y1 = translateCanvasYToViewY (y1);
+   x2 = translateCanvasXToViewX (x2);
+   y2 = translateCanvasYToViewY (y2);
 
    if (filled)
       fl_rectf (x1, y1, x2 - x1, y2 - y1);
--- a/dw/fltkviewbase.hh	Tue Feb 15 19:02:54 2011 +0000
+++ b/dw/fltkviewbase.hh	Thu Feb 17 21:26:04 2011 +0100
@@ -34,26 +34,24 @@
 
    int bgColor;
    core::Region drawRegion;
-   //::fltk::Rectangle *exposeArea;
+   core::Rectangle *exposeArea;
    static BackBuffer *backBuffer;
    static bool backBufferInUse;
 
    void draw (const core::Rectangle *rect, DrawType type);
    void drawChildWidgets ();
-#if 0
    inline void clipPoint (int *x, int *y, int border) {
       if (exposeArea) {
-         if (*x < exposeArea->x () - border)
-            *x = exposeArea->x () - border;
-         if (*x > exposeArea->r () + border)
-            *x = exposeArea->r () + border;
-         if (*y < exposeArea->y () - border)
-            *y = exposeArea->y () - border;
-         if (*y > exposeArea->b () + border)
-            *y = exposeArea->b () + border;
+         if (*x < exposeArea->x - border)
+            *x = exposeArea->x - border;
+         if (*x > exposeArea->x + exposeArea->width + border)
+            *x = exposeArea->x + exposeArea->width + border;
+         if (*y < exposeArea->y - border)
+            *y = exposeArea->y - border;
+         if (*y > exposeArea->y + exposeArea->height + border)
+            *y = exposeArea->y + exposeArea->height + border;
       }
    }
-#endif
 protected:
    core::Layout *theLayout;
    int canvasWidth, canvasHeight;