simplify Canvas::Rectangle rendering to avoid unnecessary nonsense, and remove TimeRe...
authorPaul Davis <paul@linuxaudiosystems.com>
Thu, 12 Feb 2015 02:56:29 +0000 (21:56 -0500)
committerPaul Davis <paul@linuxaudiosystems.com>
Thu, 12 Feb 2015 02:59:38 +0000 (21:59 -0500)
libs/canvas/canvas/rectangle.h
libs/canvas/rectangle.cc

index 8a8353bc329386fafd4fe0eec7756f53b956c2e5..5df10fbc606c1772b3ce5294a025c4ebc3798fec 100644 (file)
@@ -88,18 +88,6 @@ public:
        What _outline_what;
 };
 
-class TimeRectangle : public Rectangle 
-{
-    public:
-       TimeRectangle (Canvas* c) : Rectangle (c) {}
-       TimeRectangle (Canvas* c, Rect const & r) : Rectangle (c, r) {}
-       TimeRectangle (Item* i) : Rectangle (i) {}
-       TimeRectangle (Item* i, Rect const & r) : Rectangle (i, r) {}
-       
-       void render (Rect const &, Cairo::RefPtr<Cairo::Context>) const;
-       void compute_bounding_box () const;
-};
-
 }
 
 #endif
index 7a4129d30a6d1647257e91fc6cc6bf72e081d689..557e8763c7e42e39ee9b0eca2e51a0ec838173e4 100644 (file)
@@ -99,36 +99,43 @@ Rectangle::render_self (Rect const & area, Cairo::RefPtr<Cairo::Context> context
                 * coordinates of the rectangle. So if the rectangle
                 * has a left edge at 0 and a right edge at 10, then
                 * the left edge must span 0..1, the right edge
-                * must span 9..10 because the first and final pixels
-                * to be colored are actually "at" 0.5 and 9.5 (midway
-                * between the integer coordinates.
+                * must span 10..11 because the first and final pixels
+                * to be colored are actually "at" 0.5 and 10.5 (midway
+                * between the integer coordinates).
+                *
+                * See the Cairo FAQ on single pixel lines for more 
+                * detail.
                 */
 
+               if (fmod (_outline_width, 2.0)  != 0.0) {
+                       const double shift = _outline_width * 0.5;
+                       self = self.translate (Duple (shift, shift));
+               }
+               
                if (_outline_what == What (LEFT|RIGHT|BOTTOM|TOP)) {
                        
-                       self = self.shrink (0.5);
                        context->rectangle (self.x0, self.y0, self.width(), self.height());
 
                } else {
 
                        if (_outline_what & LEFT) {
-                               context->move_to (self.x0+0.5, self.y0);
-                               context->line_to (self.x0+0.5, self.y1);
+                               context->move_to (self.x0, self.y0);
+                               context->line_to (self.x0, self.y1);
                        }
                        
                        if (_outline_what & TOP) {
-                               context->move_to (self.x0, self.y0+0.5);
-                               context->line_to (self.x1, self.y0+0.5);
+                               context->move_to (self.x0, self.y0);
+                               context->line_to (self.x1, self.y0);
                        }
 
                        if (_outline_what & BOTTOM) {
-                               context->move_to (self.x0, self.y1-0.5);
-                               context->line_to (self.x1, self.y1-0.5);
+                               context->move_to (self.x0, self.y1);
+                               context->line_to (self.x1, self.y1);
                        }
                        
                        if (_outline_what & RIGHT) {
-                               context->move_to (self.x1-0.5, self.y0);
-                               context->line_to (self.x1-0.5, self.y1);
+                               context->move_to (self.x1, self.y0);
+                               context->line_to (self.x1, self.y1);
                        }
                }
                
@@ -259,37 +266,3 @@ Rectangle::set_outline_what (What what)
                end_visual_change ();
        }
 }
-
-
-/*-------------------*/
-
-void
-TimeRectangle::compute_bounding_box () const
-{
-       Rectangle::compute_bounding_box ();
-
-       if (_bounding_box) {
-               Rect r = _bounding_box.get ();
-               
-               /* This is a TimeRectangle, so its right edge is drawn 1 pixel beyond
-                * (larger x-axis coordinates) than a normal Rectangle.
-                */
-               
-               r.x1 += 1.0; /* this should be using safe_add() */
-               
-               _bounding_box = r;
-       }
-}
-
-void 
-TimeRectangle::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) const
-{
-       Rect self = get_self_for_render ();
-       
-       /* This is a TimeRectangle, so its right edge is drawn 1 pixel beyond
-        * (larger x-axis coordinates) than a normal Rectangle.
-        */
-
-       self.x1 += 1.0; /* this should be using safe_add() */
-       render_self (area, context, self);
-}