changeset 1248:3546dc1e4f1e

properly clip draw requests We always need to set a clipping rectangle when drawing to avoid that text "leaks" out as in the following test case (by corvid): <input type="image" name="name1" src="whatever" WIDTH="80" HEIGHT="14" alt="name1name1name1name1"> <input type="image" name="name2" src="whatever" width="9" height="14" alt="name2name2name2name2">
author Johannes Hofmann <Johannes.Hofmann@gmx.de>
date Tue, 28 Jul 2009 20:28:32 +0200
parents d8ad0a9ad8cb
children c478e5a7bed6
files dw/fltkviewbase.cc dw/fltkviewbase.hh
diffstat 2 files changed, 14 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/dw/fltkviewbase.cc	Tue Jul 28 16:32:27 2009 +0000
+++ b/dw/fltkviewbase.cc	Tue Jul 28 20:28:32 2009 +0200
@@ -75,7 +75,7 @@
       container::typed::Iterator <core::Rectangle> it;
 
       for (it = drawRegion.rectangles (); it.hasNext (); ) {
-         draw (it.getNext (), true);
+         draw (it.getNext (), DRAW_BUFFERED);
       }
 
       drawRegion.clear ();
@@ -94,16 +94,18 @@
          w (),
          h ());
 
-      draw (&rect, false);
-
-      if (! (d & DAMAGE_SCROLL)) {
+      if (d == DAMAGE_SCROLL) {
+         // a clipping rectangle has already been set by fltk::scrollrect ()
+         draw (&rect, DRAW_PLAIN);
+      } else {
+         draw (&rect, DRAW_CLIPPED);
          drawRegion.clear ();
       }
    }
 }
 
 void FltkViewBase::draw (const core::Rectangle *rect,
-                         bool doubleBuffer)
+                         DrawType type)
 {
    int offsetX = 0, offsetY = 0;
 
@@ -127,7 +129,7 @@
          viewRect.w (),
          viewRect.h ());
 
-      if (doubleBuffer && backBuffer && !backBufferInUse) {
+      if (type == DRAW_BUFFERED && backBuffer && !backBufferInUse) {
          backBufferInUse = true;
          {
             GSave gsave;
@@ -145,15 +147,15 @@
             viewRect);
 
          backBufferInUse = false;
-      } else if (doubleBuffer) {
+      } 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
          push_clip (viewRect);
          setcolor (bgColor);
          fillrect (viewRect);
          theLayout->expose (this, &r);
          pop_clip ();
       } else {
-         // if doubleBuffer is false we assume that a clipping
-         // rectangle has been set already
          setcolor (bgColor);
          fillrect (viewRect);
          theLayout->expose (this, &r);
--- a/dw/fltkviewbase.hh	Tue Jul 28 16:32:27 2009 +0000
+++ b/dw/fltkviewbase.hh	Tue Jul 28 20:28:32 2009 +0200
@@ -16,12 +16,14 @@
 class FltkViewBase: public FltkView, public ::fltk::Group
 {
 private:
+   typedef enum { DRAW_PLAIN, DRAW_CLIPPED, DRAW_BUFFERED } DrawType;
+
    int bgColor;
    core::Region drawRegion;
    static ::fltk::Image *backBuffer;
    static bool backBufferInUse;
 
-   void draw (const core::Rectangle *rect, bool doubleBuffer);
+   void draw (const core::Rectangle *rect, DrawType type);
    void drawChildWidgets ();
 
 protected: