diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2014-06-21 11:43:42 -0400 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2014-06-21 11:43:42 -0400 |
commit | a8bd6ecc4fe4016090fad92daf6d9a572941d035 (patch) | |
tree | dbde5ef9b5b280656a95be7dce72b67dafbe46e7 /libs/canvas/canvas | |
parent | 5d6dc388f71dbb4910832ed766af92592b000e52 (diff) |
refactor Canvas so that all Items have children; add Container abstract base class; rename Group as "Layout" and retain only drawing semantics
Diffstat (limited to 'libs/canvas/canvas')
26 files changed, 81 insertions, 135 deletions
diff --git a/libs/canvas/canvas/arc.h b/libs/canvas/canvas/arc.h index 5eaa4a0ab9..c2b32d9e10 100644 --- a/libs/canvas/canvas/arc.h +++ b/libs/canvas/canvas/arc.h @@ -32,7 +32,7 @@ class LIBCANVAS_API Arc : public Item { public: Arc (Canvas*); - Arc (Group*); + Arc (Item*); void render (Rect const & area, Cairo::RefPtr<Cairo::Context>) const; void compute_bounding_box () const; diff --git a/libs/canvas/canvas/arrow.h b/libs/canvas/canvas/arrow.h index 75c21da07c..7db225553e 100644 --- a/libs/canvas/canvas/arrow.h +++ b/libs/canvas/canvas/arrow.h @@ -26,8 +26,7 @@ #define __CANVAS_ARROW_H__ #include "canvas/visibility.h" - -#include "canvas/group.h" +#include "canvas/layout.h" namespace ArdourCanvas { @@ -46,11 +45,11 @@ class Polygon; * to draw lines at any angle. */ -class LIBCANVAS_API Arrow : public Group +class LIBCANVAS_API Arrow : public Layout { public: Arrow (Canvas*); - Arrow (Group*); + Arrow (Item*); void set_show_head (int, bool); void set_head_outward (int, bool); diff --git a/libs/canvas/canvas/canvas.h b/libs/canvas/canvas/canvas.h index fac9367985..94005f4cc7 100644 --- a/libs/canvas/canvas/canvas.h +++ b/libs/canvas/canvas/canvas.h @@ -42,7 +42,7 @@ namespace ArdourCanvas { class Rect; -class Group; +class Item; class ScrollGroup; /** The base class for our different types of canvas. @@ -78,7 +78,7 @@ public: void render (Rect const &, Cairo::RefPtr<Cairo::Context> const &) const; /** @return root group */ - Group* root () { + Item* root () { return &_root; } @@ -122,8 +122,8 @@ public: protected: void queue_draw_item_area (Item *, Rect); - /** our root group */ - RootGroup _root; + /** our root item */ + Root _root; virtual void pick_current_item (int state) = 0; virtual void pick_current_item (Duple const &, int state) = 0; diff --git a/libs/canvas/canvas/circle.h b/libs/canvas/canvas/circle.h index 1ca376a7a2..c84e3aceec 100644 --- a/libs/canvas/canvas/circle.h +++ b/libs/canvas/canvas/circle.h @@ -29,7 +29,7 @@ class LIBCANVAS_API Circle : public Arc { public: Circle (Canvas*); - Circle (Group*); + Circle (Item*); }; } diff --git a/libs/canvas/canvas/curve.h b/libs/canvas/canvas/curve.h index 1bcab58e32..d27291e353 100644 --- a/libs/canvas/canvas/curve.h +++ b/libs/canvas/canvas/curve.h @@ -33,7 +33,7 @@ class LIBCANVAS_API Curve : public PolyItem, public InterpolatedCurve { public: Curve (Canvas*); - Curve (Group*); + Curve (Item*); enum CurveFill { None, diff --git a/libs/canvas/canvas/flag.h b/libs/canvas/canvas/flag.h index 2429e1775e..05c0e2777d 100644 --- a/libs/canvas/canvas/flag.h +++ b/libs/canvas/canvas/flag.h @@ -18,8 +18,8 @@ */ #include "canvas/visibility.h" -#include "canvas/group.h" #include "canvas/types.h" +#include "canvas/layout.h" namespace ArdourCanvas { @@ -27,11 +27,11 @@ class Text; class Line; class Rectangle; -class LIBCANVAS_API Flag : public Group +class LIBCANVAS_API Flag : public Layout { public: Flag (Canvas *, Distance, Color, Color, Duple); - Flag (Group*, Distance, Color, Color, Duple); + Flag (Item*, Distance, Color, Color, Duple); void set_text (std::string const &); void set_height (Distance); diff --git a/libs/canvas/canvas/fwd.h b/libs/canvas/canvas/fwd.h index 728e6988d4..61cab3c9d2 100644 --- a/libs/canvas/canvas/fwd.h +++ b/libs/canvas/canvas/fwd.h @@ -33,6 +33,7 @@ namespace ArdourCanvas { class GtkCanvasViewport; class Text; class Curve; + class ScrollGroup; } #endif /* __canvas_canvas_fwd_h__ */ diff --git a/libs/canvas/canvas/group.h b/libs/canvas/canvas/group.h deleted file mode 100644 index 6bfc40ba28..0000000000 --- a/libs/canvas/canvas/group.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - 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. -*/ - -#ifndef __CANVAS_GROUP_H__ -#define __CANVAS_GROUP_H__ - -#include <list> -#include <vector> - -#include "canvas/visibility.h" -#include "canvas/item.h" -#include "canvas/types.h" -#include "canvas/lookup_table.h" - -namespace ArdourCanvas { - -class LIBCANVAS_API Group : public Item -{ -public: - Group (Canvas*); - Group (Group*); - Group (Group*, Duple const& positon); - virtual ~Group (); - - void render (Rect const &, Cairo::RefPtr<Cairo::Context>) const; - virtual void compute_bounding_box () const; - - void add (Item *); - void remove (Item *); - void clear (bool with_delete = false); - std::list<Item*> const & items () const { - return _items; - } - - void raise_child_to_top (Item *); - void raise_child (Item *, int); - void lower_child_to_bottom (Item *); - void child_changed (); - - void scroll_to (Duple const& d); - - void add_items_at_point (Duple, std::vector<Item const *> &) const; - - void dump (std::ostream&) const; - - static int default_items_per_cell; - -private: - friend class ::OptimizingLookupTableTest; - - void ensure_lut () const; - void invalidate_lut () const; - void clear_items (bool with_delete); - - /* our items, from lowest to highest in the stack */ - std::list<Item*> _items; - - mutable LookupTable* _lut; -}; - -} - -#endif diff --git a/libs/canvas/canvas/image.h b/libs/canvas/canvas/image.h index fd86818c21..64d70a5751 100644 --- a/libs/canvas/canvas/image.h +++ b/libs/canvas/canvas/image.h @@ -35,7 +35,7 @@ class LIBCANVAS_API Image : public Item { public: Image (Canvas *, Cairo::Format, int width, int height); - Image (Group*, Cairo::Format, int width, int height); + Image (Item*, Cairo::Format, int width, int height); struct Data { Data (uint8_t *d, int w, int h, int s, Cairo::Format fmt) diff --git a/libs/canvas/canvas/item.h b/libs/canvas/canvas/item.h index bf752f66db..ced94e1e3b 100644 --- a/libs/canvas/canvas/item.h +++ b/libs/canvas/canvas/item.h @@ -32,12 +32,12 @@ #include "canvas/types.h" #include "canvas/fill.h" #include "canvas/outline.h" +#include "canvas/lookup_table.h" namespace ArdourCanvas { class Canvas; -class Group; class Rect; class ScrollGroup; @@ -56,8 +56,8 @@ class LIBCANVAS_API Item : public Fill, public Outline { public: Item (Canvas *); - Item (Group *); - Item (Group *, Duple const& p); + Item (Item *); + Item (Item *, Duple const& p); virtual ~Item (); void redraw () const; @@ -80,13 +80,11 @@ public: * * Note that Item::add_items_at_window_point() is only intended to be * called on items already looked up in a LookupTable (i.e. by a - * parent group) and thus known to cover @param point already. + * parent) and thus known to cover @param point already. * - * Derived classes may add more items than themselves (e.g. Group). + * Derived classes may add more items than themselves (e.g. containers). */ - virtual void add_items_at_point (Duple /*point*/, std::vector<Item const *>& items) const { - items.push_back (this); - } + virtual void add_items_at_point (Duple /*point*/, std::vector<Item const *>& items) const; virtual bool covers (Duple const &) const; @@ -97,10 +95,10 @@ public: void ungrab (); void unparent (); - void reparent (Group *); + void reparent (Item *); /** @return Parent group, or 0 if this is the root group */ - Group* parent () const { + Item* parent () const { return _parent; } @@ -124,8 +122,6 @@ public: void set_y_position (Coord); void move (Duple); - virtual void scroll_to (Duple const&) {} - /** @return Position of this item in the parent's coordinates */ Duple position () const { return _position; @@ -187,6 +183,21 @@ public: void set_data (std::string const &, void *); void* get_data (std::string const &) const; + + /* nested item ("grouping") API */ + void add (Item *); + void remove (Item *); + void clear (bool with_delete = false); + std::list<Item*> const & items () const { + return _items; + } + void raise_child_to_top (Item *); + void raise_child (Item *, int); + void lower_child_to_bottom (Item *); + void child_changed (); + + static int default_items_per_cell; + /* This is a sigc++ signal because it is solely concerned with GUI stuff and is thus single-threaded @@ -243,7 +254,7 @@ protected: Canvas* _canvas; /** parent group; may be 0 if we are the root group or if we have been unparent()ed */ - Group* _parent; + Item* _parent; /** scroll parent group; may be 0 if we are the root group or if we have been unparent()ed */ ScrollGroup* _scroll_parent; /** position of this item in parent coordinates */ @@ -261,6 +272,18 @@ protected: /* XXX: this is a bit grubby */ std::map<std::string, void *> _data; + /* nesting ("grouping") API */ + + void invalidate_lut () const; + void clear_items (bool with_delete); + + void ensure_lut () const; + mutable LookupTable* _lut; + /* our items, from lowest to highest in the stack */ + std::list<Item*> _items; + + void add_child_bounding_boxes() const; + private: void init (); diff --git a/libs/canvas/canvas/line.h b/libs/canvas/canvas/line.h index e8f57a00ba..b178554c84 100644 --- a/libs/canvas/canvas/line.h +++ b/libs/canvas/canvas/line.h @@ -31,7 +31,7 @@ class LIBCANVAS_API Line : public Item { public: Line (Canvas*); - Line (Group*); + Line (Item*); void render (Rect const & area, Cairo::RefPtr<Cairo::Context>) const; void compute_bounding_box () const; diff --git a/libs/canvas/canvas/line_set.h b/libs/canvas/canvas/line_set.h index 38f97250ce..fad100fdf9 100644 --- a/libs/canvas/canvas/line_set.h +++ b/libs/canvas/canvas/line_set.h @@ -36,7 +36,7 @@ public: }; LineSet (Canvas*, Orientation o = Vertical); - LineSet (Group*, Orientation o = Vertical); + LineSet (Item*, Orientation o = Vertical); void compute_bounding_box () const; void render (Rect const & area, Cairo::RefPtr<Cairo::Context>) const; diff --git a/libs/canvas/canvas/lookup_table.h b/libs/canvas/canvas/lookup_table.h index 5be33c1bca..29452365cd 100644 --- a/libs/canvas/canvas/lookup_table.h +++ b/libs/canvas/canvas/lookup_table.h @@ -31,12 +31,11 @@ class OptimizingLookupTableTest; namespace ArdourCanvas { class Item; -class Group; class LIBCANVAS_API LookupTable { public: - LookupTable (Group const &); + LookupTable (Item const &); virtual ~LookupTable (); virtual std::vector<Item*> get (Rect const &) = 0; @@ -45,13 +44,13 @@ public: protected: - Group const & _group; + Item const & _item; }; class LIBCANVAS_API DumbLookupTable : public LookupTable { public: - DumbLookupTable (Group const &); + DumbLookupTable (Item const &); std::vector<Item*> get (Rect const &); std::vector<Item*> items_at_point (Duple const &) const; @@ -61,7 +60,7 @@ public: class LIBCANVAS_API OptimizingLookupTable : public LookupTable { public: - OptimizingLookupTable (Group const &, int); + OptimizingLookupTable (Item const &, int); ~OptimizingLookupTable (); std::vector<Item*> get (Rect const &); std::vector<Item*> items_at_point (Duple const &) const; diff --git a/libs/canvas/canvas/pixbuf.h b/libs/canvas/canvas/pixbuf.h index eba73e57bf..2749b96668 100644 --- a/libs/canvas/canvas/pixbuf.h +++ b/libs/canvas/canvas/pixbuf.h @@ -35,7 +35,7 @@ class LIBCANVAS_API Pixbuf : public Item { public: Pixbuf (Canvas*); - Pixbuf (Group*); + Pixbuf (Item*); void render (Rect const &, Cairo::RefPtr<Cairo::Context>) const; void compute_bounding_box () const; diff --git a/libs/canvas/canvas/poly_item.h b/libs/canvas/canvas/poly_item.h index ab68204ff0..732adb14b3 100644 --- a/libs/canvas/canvas/poly_item.h +++ b/libs/canvas/canvas/poly_item.h @@ -30,7 +30,7 @@ class LIBCANVAS_API PolyItem : public Item { public: PolyItem (Canvas*); - PolyItem (Group*); + PolyItem (Item*); void compute_bounding_box () const; diff --git a/libs/canvas/canvas/poly_line.h b/libs/canvas/canvas/poly_line.h index 5476711e97..16db9a69e2 100644 --- a/libs/canvas/canvas/poly_line.h +++ b/libs/canvas/canvas/poly_line.h @@ -30,7 +30,7 @@ class LIBCANVAS_API PolyLine : public PolyItem { public: PolyLine (Canvas*); - PolyLine (Group*); + PolyLine (Item*); void render (Rect const & area, Cairo::RefPtr<Cairo::Context>) const; diff --git a/libs/canvas/canvas/polygon.h b/libs/canvas/canvas/polygon.h index a3eed37cdc..9703eb46e9 100644 --- a/libs/canvas/canvas/polygon.h +++ b/libs/canvas/canvas/polygon.h @@ -31,7 +31,7 @@ class LIBCANVAS_API Polygon : public PolyItem { public: Polygon (Canvas*); - Polygon (Group*); + Polygon (Item*); virtual ~Polygon(); void render (Rect const & area, Cairo::RefPtr<Cairo::Context>) const; diff --git a/libs/canvas/canvas/rectangle.h b/libs/canvas/canvas/rectangle.h index ff6eca3cd9..2983d33ed2 100644 --- a/libs/canvas/canvas/rectangle.h +++ b/libs/canvas/canvas/rectangle.h @@ -34,8 +34,8 @@ class LIBCANVAS_API Rectangle : public Item public: Rectangle (Canvas*); Rectangle (Canvas*, Rect const &); - Rectangle (Group*); - Rectangle (Group*, Rect const &); + Rectangle (Item*); + Rectangle (Item*, Rect const &); void render (Rect const &, Cairo::RefPtr<Cairo::Context>) const; void compute_bounding_box () const; diff --git a/libs/canvas/canvas/root_group.h b/libs/canvas/canvas/root_group.h index 70c3e5b90b..5db8024f51 100644 --- a/libs/canvas/canvas/root_group.h +++ b/libs/canvas/canvas/root_group.h @@ -21,19 +21,18 @@ #define __CANVAS_ROOT_GROUP_H__ #include "canvas/visibility.h" -#include "canvas/group.h" +#include "canvas/layout.h" namespace ArdourCanvas { -class LIBCANVAS_API RootGroup : public Group +class LIBCANVAS_API Root : public Layout { private: friend class Canvas; - RootGroup (Canvas *); + Root (Canvas *); void compute_bounding_box () const; - void child_changed (); }; } diff --git a/libs/canvas/canvas/ruler.h b/libs/canvas/canvas/ruler.h index 633a1d569e..25040247c9 100644 --- a/libs/canvas/canvas/ruler.h +++ b/libs/canvas/canvas/ruler.h @@ -57,8 +57,8 @@ public: Ruler (Canvas*, const Metric& m); Ruler (Canvas*, const Metric& m, Rect const&); - Ruler (Group*, const Metric& m); - Ruler (Group*, const Metric& m, Rect const&); + Ruler (Item*, const Metric& m); + Ruler (Item*, const Metric& m, Rect const&); void set_range (double lower, double upper); void set_font_description (Pango::FontDescription); diff --git a/libs/canvas/canvas/scroll_group.h b/libs/canvas/canvas/scroll_group.h index 552538eb21..013d769c2f 100644 --- a/libs/canvas/canvas/scroll_group.h +++ b/libs/canvas/canvas/scroll_group.h @@ -19,11 +19,15 @@ #ifndef __CANVAS_SCROLL_GROUP_H__ #define __CANVAS_SCROLL_GROUP_H__ -#include "canvas/group.h" +#include "canvas/layout.h" namespace ArdourCanvas { -class LIBCANVAS_API ScrollGroup : public Group +/** A ScrollGroup has no contents of its own, but renders + * its children in a way that reflects the most recent + * call to its scroll_to() method. + */ +class LIBCANVAS_API ScrollGroup : public Layout { public: enum ScrollSensitivity { @@ -32,7 +36,7 @@ class LIBCANVAS_API ScrollGroup : public Group }; ScrollGroup (Canvas*, ScrollSensitivity); - ScrollGroup (Group*, ScrollSensitivity); + ScrollGroup (Item*, ScrollSensitivity); void scroll_to (Duple const& d); Duple scroll_offset() const { return _scroll_offset; } diff --git a/libs/canvas/canvas/stateful_image.h b/libs/canvas/canvas/stateful_image.h index 5952752e71..7c00b0c5a4 100644 --- a/libs/canvas/canvas/stateful_image.h +++ b/libs/canvas/canvas/stateful_image.h @@ -50,7 +50,7 @@ class StatefulImage : public Item public: StatefulImage (Canvas*, const XMLNode&); - StatefulImage (Group*, const XMLNode&); + StatefulImage (Item*, const XMLNode&); ~StatefulImage (); bool set_state (States::size_type); diff --git a/libs/canvas/canvas/text.h b/libs/canvas/canvas/text.h index cc6d5c815d..85262ee984 100644 --- a/libs/canvas/canvas/text.h +++ b/libs/canvas/canvas/text.h @@ -32,7 +32,7 @@ class LIBCANVAS_API Text : public Item { public: Text (Canvas*); - Text (Group*); + Text (Item*); ~Text(); void render (Rect const &, Cairo::RefPtr<Cairo::Context>) const; diff --git a/libs/canvas/canvas/wave_view.h b/libs/canvas/canvas/wave_view.h index c98c62c7a3..042414e1e2 100644 --- a/libs/canvas/canvas/wave_view.h +++ b/libs/canvas/canvas/wave_view.h @@ -92,7 +92,7 @@ public: WaveView (Canvas *, boost::shared_ptr<ARDOUR::AudioRegion>); - WaveView (Group*, boost::shared_ptr<ARDOUR::AudioRegion>); + WaveView (Item*, boost::shared_ptr<ARDOUR::AudioRegion>); ~WaveView (); void render (Rect const & area, Cairo::RefPtr<Cairo::Context>) const; diff --git a/libs/canvas/canvas/widget.h b/libs/canvas/canvas/widget.h index 842f336a51..590bb3af7d 100644 --- a/libs/canvas/canvas/widget.h +++ b/libs/canvas/canvas/widget.h @@ -32,7 +32,7 @@ class LIBCANVAS_API Widget : public Item { public: Widget (Canvas*, CairoWidget&); - Widget (Group*, CairoWidget&); + Widget (Item*, CairoWidget&); void render (Rect const &, Cairo::RefPtr<Cairo::Context>) const; void compute_bounding_box () const; diff --git a/libs/canvas/canvas/xfade_curve.h b/libs/canvas/canvas/xfade_curve.h index d6a10d1f86..c63e47c583 100644 --- a/libs/canvas/canvas/xfade_curve.h +++ b/libs/canvas/canvas/xfade_curve.h @@ -36,8 +36,8 @@ public: XFadeCurve (Canvas *); XFadeCurve (Canvas *, XFadePosition); - XFadeCurve (Group*); - XFadeCurve (Group*, XFadePosition); + XFadeCurve (Item*); + XFadeCurve (Item*, XFadePosition); void set_fade_position (XFadePosition xfp) { _xfadeposition = xfp; } |