diff options
author | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2009-09-01 20:21:55 +0200 |
---|---|---|
committer | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2009-09-01 20:21:55 +0200 |
commit | 6db97f3045f138b96e3ba81a96fb3db3c9930538 (patch) | |
tree | ed29fca2b8c8d06ebde7a1415798549f754bb92f | |
parent | 904eebfd09f49f0a7537b8d6d668e095078204eb (diff) |
improve FltkViewBase::drawRectangle
* allow negative width / height
* clip rectangle to size of the view. This avoids issues with 16 bit X11
coordinates overflowing and seems to improve performance.
-rw-r--r-- | dw/fltkviewbase.cc | 13 | ||||
-rw-r--r-- | dw/fltkviewbase.hh | 10 |
2 files changed, 23 insertions, 0 deletions
diff --git a/dw/fltkviewbase.cc b/dw/fltkviewbase.cc index d12050ce..1d82a661 100644 --- a/dw/fltkviewbase.cc +++ b/dw/fltkviewbase.cc @@ -367,10 +367,23 @@ void FltkViewBase::drawRectangle (core::style::Color *color, int x, int y, int width, int height) { setcolor(((FltkColor*)color)->colors[shading]); + if (width < 0) { + x += width; + width = -width; + } + if (height < 0) { + y += height; + height = -height; + } + int x1 = translateCanvasXToViewX (x); int y1 = translateCanvasYToViewY (y); int x2 = translateCanvasXToViewX (x + width); int y2 = translateCanvasYToViewY (y + height); + + clipPoint (&x1, &y1); + clipPoint (&x2, &y2); + ::fltk::Rectangle rect (x1, y1, x2 - x1, y2 - y1); if (filled) fillrect (rect); diff --git a/dw/fltkviewbase.hh b/dw/fltkviewbase.hh index 4dc0a27f..c502d2f7 100644 --- a/dw/fltkviewbase.hh +++ b/dw/fltkviewbase.hh @@ -25,6 +25,16 @@ private: void draw (const core::Rectangle *rect, DrawType type); void drawChildWidgets (); + inline void clipPoint (int *x, int *y) { + if (*x < 0) + *x = 0; + if (*x > w ()) + *x = w (); + if (*y < 0) + *y = 0; + if (*y > h ()) + *y = h (); + } protected: core::Layout *theLayout; |