smoothen rendering of x-fades
[ardour.git] / libs / canvas / canvas / item.h
index b4ea5671c7fe6d499ec0a3d10668bcc304518d35..da061f5bfc7a7e6b975f28beada5df157a701501 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "pbd/signals.h"
 
+#include "canvas/visibility.h"
 #include "canvas/types.h"
 
 namespace ArdourCanvas
@@ -48,7 +49,7 @@ class Rect;
  *  and all except the `root group' have a pointer to their parent group.
  */
        
-class Item
+class LIBCANVAS_API Item
 {
 public:
        Item (Canvas *);
@@ -56,8 +57,18 @@ public:
        Item (Group *, Duple);
        virtual ~Item ();
 
+        void redraw () const;
+
        /** Render this item to a Cairo context.
-        *  @param area Area to draw in this item's coordinates.
+        *  @param area Area to draw, in **window** coordinates
+        *
+        *  Items must convert their own coordinates into window coordinates
+        *  because Cairo is limited to a fixed point coordinate space that
+        *  does not extend as far as the Ardour timeline. All rendering must
+        *  be done using coordinates that do not exceed the (rough) limits
+        *  of the canvas' window, to avoid odd errors within Cairo as it
+        *  converts doubles into its fixed point format and then tesselates
+        *  the results.
         */
        virtual void render (Rect const & area, Cairo::RefPtr<Cairo::Context>) const = 0;
 
@@ -65,6 +76,8 @@ public:
                items.push_back (this);
        }
 
+        virtual bool covers (Duple const &) const;
+
        /** Update _bounding_box and _bounding_box_dirty */
        virtual void compute_bounding_box () const = 0;
 
@@ -78,6 +91,21 @@ public:
        Group* parent () const {
                return _parent;
        }
+    
+        uint32_t depth() const;
+        const Item* closest_ancestor_with (const Item& other) const;
+        bool common_ancestor_within (uint32_t, const Item& other) const;
+
+        /** returns true if this item is an ancestor of @param candidate,
+        * and false otherwise. 
+        */
+        bool is_ancestor_of (const Item& candidate) const {
+               return candidate.is_descendant_of (*this);
+       }
+        /** returns true if this Item is a descendant of @param candidate,
+        * and false otherwise. 
+        */
+        bool is_descendant_of (const Item& candidate) const;
 
        void set_position (Duple);
        void set_x_position (Coord);
@@ -105,8 +133,13 @@ public:
         Duple canvas_to_item (Duple const &) const;
        void item_to_canvas (Coord &, Coord &) const;
        Rect item_to_canvas (Rect const &) const;
+       Rect canvas_to_item (Rect const &) const;
         Duple item_to_canvas (Duple const &) const;
 
+        Duple item_to_window (Duple const&) const;
+        Duple window_to_item (Duple const&) const;
+        Rect item_to_window (Rect const&) const;
+
        void raise_to_top ();
        void raise (int);
        void lower_to_bottom ();
@@ -209,7 +242,7 @@ private:
        bool _ignore_events;
 };
 
-extern std::ostream& operator<< (std::ostream&, const ArdourCanvas::Item&);
+extern LIBCANVAS_API std::ostream& operator<< (std::ostream&, const ArdourCanvas::Item&);
 
 }