fix a cast warning (as recommended in GTK+ docs
[ardour.git] / libs / canvas / polygon.cc
index 37046f4d4a6f7ac7a83a24a4b1a9767a76d6c559..3c6d5d51a2d155b83e2931e57ad7dbfdcbc60ecb 100644 (file)
@@ -1,35 +1,40 @@
 /*
-    Copyright (C) 2011-2013 Paul Davis
   Author: Carl Hetherington <cth@carlh.net>
-
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
-
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
+ * Copyright (C) 2012 Carl Hetherington <carl@carlh.net>
* Copyright (C) 2013-2015 Paul Davis <paul@linuxaudiosystems.com>
+ *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
 
 #include "canvas/polygon.h"
 
 using namespace ArdourCanvas;
 
-Polygon::Polygon (Group* parent)
-       : Item (parent)
-       , PolyItem (parent)
-       , Fill (parent)
+Polygon::Polygon (Canvas* c)
+       : PolyItem (c)
        , multiple (0)
        , constant (0)
        , cached_size (0)
 {
+}
 
+Polygon::Polygon (Item* parent)
+       : PolyItem (parent)
+       , multiple (0)
+       , constant (0)
+       , cached_size (0)
+{
 }
 
 Polygon::~Polygon ()
@@ -41,17 +46,24 @@ Polygon::~Polygon ()
 void
 Polygon::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) const
 {
-       if (_outline) {
-               setup_outline_context (context);
+       if (_outline || _fill) {
                render_path (area, context);
-               
+
                if (!_points.empty ()) {
                        /* close path */
                        Duple p = item_to_window (Duple (_points.front().x, _points.front().y));
-                       context->move_to (p.x, p.y);
+                       context->line_to (p.x, p.y);
                }
 
-               context->stroke_preserve ();
+       }
+
+       if (_outline) {
+               setup_outline_context (context);
+               if (_fill) {
+                       context->stroke_preserve ();
+               } else {
+                       context->stroke ();
+               }
        }
 
        if (_fill) {
@@ -60,7 +72,7 @@ Polygon::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) const
        }
 }
 
-void 
+void
 Polygon::cache_shape_computation () const
 {
        Points::size_type npoints = _points.size();
@@ -83,20 +95,20 @@ Polygon::cache_shape_computation () const
        for (i = 0; i < npoints; i++) {
                if (_points[j].y == _points[i].y) {
                        constant[i] = _points[i].x;
-                       multiple[i] = 0; 
+                       multiple[i] = 0;
                } else {
                        constant[i] = _points[i].x-(_points[i].y*_points[j].x)/(_points[j].y-_points[i].y)+(_points[i].y*_points[i].x)/(_points[j].y-_points[i].y);
-                       multiple[i] = (_points[j].x-_points[i].x)/(_points[j].y-_points[i].y); 
+                       multiple[i] = (_points[j].x-_points[i].x)/(_points[j].y-_points[i].y);
                }
 
-               j = i; 
+               j = i;
        }
 }
 
-bool 
+bool
 Polygon::covers (Duple const & point) const
 {
-       Duple p = canvas_to_item (point);
+       Duple p = window_to_item (point);
 
        Points::size_type npoints = _points.size();
 
@@ -107,20 +119,20 @@ Polygon::covers (Duple const & point) const
        Points::size_type i;
        Points::size_type j = npoints -1;
        bool oddNodes = false;
-       
+
        if (_bounding_box_dirty) {
                compute_bounding_box ();
        }
-       
+
        for (i = 0; i < npoints; i++) {
                if (((_points[i].y < p.y && _points[j].y >= p.y) || (_points[j].y < p.y && _points[i].y >= p.y))) {
-                       oddNodes ^= (p.y * multiple[i] + constant[i] < p.x); 
+                       oddNodes ^= (p.y * multiple[i] + constant[i] < p.x);
                }
-               j = i; 
+               j = i;
        }
-       
-       return oddNodes; 
-} 
+
+       return oddNodes;
+}
 
 void
 Polygon::compute_bounding_box () const