/*
- Copyright (C) 2011 Paul Davis
+ Copyright (C) 2011-2013 Paul Davis
Author: Carl Hetherington <cth@carlh.net>
This program is free software; you can redistribute it and/or modify
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.
-
*/
/** @file canvas/canvas.h
#include <gdkmm/window.h>
#include <gtkmm/eventbox.h>
-#include <gtkmm/viewport.h>
+#include <gtkmm/alignment.h>
#include <cairomm/surface.h>
#include <cairomm/context.h>
#include "pbd/signals.h"
#include "canvas/root_group.h"
-class XMLTree;
-
namespace ArdourCanvas
{
{
public:
Canvas ();
- Canvas (XMLTree const *);
virtual ~Canvas () {}
/** called to request a redraw of an area of the canvas */
/** Called when an item is being destroyed */
virtual void item_going_away (Item *, boost::optional<Rect>) {}
void item_shown_or_hidden (Item *);
+ void item_visual_property_changed (Item*);
void item_changed (Item *, boost::optional<Rect>);
void item_moved (Item *, boost::optional<Rect>);
- XMLTree* get_state () const;
+ virtual Cairo::RefPtr<Cairo::Context> context () = 0;
- virtual Cairo::RefPtr<Cairo::Context> context () = 0;
+ Rect canvas_to_window (Rect const&) const;
+ Rect window_to_canvas (Rect const&) const;
+ Duple canvas_to_window (Duple const&) const;
+ Duple window_to_canvas (Duple const&) const;
- std::list<Rect> const & renders () const {
- return _renders;
- }
+ void canvas_to_window (Coord cx, Coord cy, Coord& wx, Coord& wy) {
+ Duple d = canvas_to_window (Duple (cx, cy));
+ wx = d.x;
+ wy = d.y;
+ }
- void set_log_renders (bool log) {
- _log_renders = log;
- }
+ void window_to_canvas (Coord wx, Coord wy, Coord& cx, Coord& cy) {
+ Duple d = window_to_canvas (Duple (wx, wy));
+ cx = d.x;
+ cy = d.y;
+ }
+ void scroll_to (Coord x, Coord y);
+ virtual Rect visible_area () const = 0;
+
+ std::string indent() const;
+ std::string render_indent() const;
+ void dump (std::ostream&) const;
+
protected:
void queue_draw_item_area (Item *, Rect);
/** our root group */
RootGroup _root;
- mutable std::list<Rect> _renders;
- bool _log_renders;
-};
-
-/** A Canvas which renders onto an in-memory pixbuf. In Ardour's context,
- * this is most useful for testing.
- */
-class ImageCanvas : public Canvas
-{
-public:
- ImageCanvas (Duple size = Duple (1024, 1024));
- ImageCanvas (XMLTree const *, Duple size = Duple (1024, 1024));
-
- void request_redraw (Rect const &) {
- /* XXX */
- }
-
- void request_size (Duple) {
- /* XXX */
- }
-
- void grab (Item *) {}
- void ungrab () {}
-
- void render_to_image (Rect const &) const;
- void clear ();
- void write_to_png (std::string const &);
-
- Cairo::RefPtr<Cairo::Context> context ();
+ Coord _scroll_offset_x;
+ Coord _scroll_offset_y;
-private:
- /** our Cairo surface */
- Cairo::RefPtr<Cairo::Surface> _surface;
- /** our Cairo context */
- Cairo::RefPtr<Cairo::Context> _context;
+ virtual void enter_leave_items (int state) = 0;
+ virtual void enter_leave_items (Duple const &, int state) = 0;
};
/** A canvas which renders onto a GTK EventBox */
{
public:
GtkCanvas ();
- GtkCanvas (XMLTree const *);
void request_redraw (Rect const &);
void request_size (Duple);
void ungrab ();
Cairo::RefPtr<Cairo::Context> context ();
-
+
+ Rect visible_area () const;
+
protected:
bool on_expose_event (GdkEventExpose *);
bool on_button_press_event (GdkEventButton *);
bool motion_notify_handler (GdkEventMotion *);
bool deliver_event (Duple, GdkEvent *);
+ void enter_leave_items (int state);
+ void enter_leave_items (Duple const &, int state);
+
private:
void item_going_away (Item *, boost::optional<Rect>);
bool send_leave_event (Item const *, double, double) const;
+
/** the item that the mouse is currently over, or 0 */
Item const * _current_item;
/** the item that is currently grabbed, or 0 */
Item const * _grabbed_item;
};
-/** A GTK::Viewport with a GtkCanvas inside it. This provides a GtkCanvas
- * that can be scrolled.
+/** A GTK::Alignment with a GtkCanvas inside it plus some Gtk::Adjustments for
+ * scrolling.
+ *
+ * This provides a GtkCanvas that can be scrolled. It does NOT implement the
+ * Gtk::Scrollable interface.
*/
-class GtkCanvasViewport : public Gtk::Viewport
+class GtkCanvasViewport : public Gtk::Alignment
{
public:
GtkCanvasViewport (Gtk::Adjustment &, Gtk::Adjustment &);
return &_canvas;
}
- void window_to_canvas (int, int, Coord &, Coord &) const;
- Rect visible_area () const;
-
protected:
void on_size_request (Gtk::Requisition *);
private:
/** our GtkCanvas */
GtkCanvas _canvas;
+ Gtk::Adjustment& hadjustment;
+ Gtk::Adjustment& vadjustment;
+
+ void scrolled ();
};
}
+std::ostream& operator<< (std::ostream&, const ArdourCanvas::Canvas&);
+
#endif