#ifndef __CANVAS_CANVAS_H__
#define __CANVAS_CANVAS_H__
+#include <set>
+
#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;
+#include "canvas/visibility.h"
+
+#include "canvas/root_group.h"
namespace ArdourCanvas
{
+struct Rect;
-class Rect;
-class Group;
+class Item;
+class ScrollGroup;
/** The base class for our different types of canvas.
*
* rightwards and y increases downwards.
*/
-class Canvas
+class LIBCANVAS_API Canvas
{
public:
Canvas ();
- Canvas (XMLTree const *);
virtual ~Canvas () {}
- /** called to request a redraw of an area of the canvas */
+ /** called to request a redraw of an area of the canvas in WINDOW coordinates */
virtual void request_redraw (Rect const &) = 0;
/** called to ask the canvas to request a particular size from its host */
virtual void request_size (Duple) = 0;
/** called to ask the canvas' host to `ungrab' any grabbed item */
virtual void ungrab () = 0;
+ /** called to ask the canvas' host to keyboard focus on an item */
+ virtual void focus (Item *) = 0;
+ /** called to ask the canvas' host to drop keyboard focus on an item */
+ virtual void unfocus (Item*) = 0;
+
void render (Rect const &, Cairo::RefPtr<Cairo::Context> const &) const;
/** @return root group */
- Group* root () {
+ Item* root () {
return &_root;
}
/** 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;
-
- std::list<Rect> const & renders () const {
- return _renders;
- }
-
- void set_log_renders (bool log) {
- _log_renders = log;
- }
-
+ virtual Cairo::RefPtr<Cairo::Context> context () = 0;
+
+ Duple canvas_to_window (Duple const&, bool rounded = true) const;
+ Duple window_to_canvas (Duple const&) const;
+
+ 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 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);
+ void add_scroller (ScrollGroup& i);
+
+ virtual Rect visible_area () const = 0;
+ virtual Coord width () const = 0;
+ virtual Coord height () const = 0;
+
+ /** Store the coordinates of the mouse pointer in window coordinates in
+ @param winpos. Return true if the position was within the window,
+ false otherwise.
+ */
+ virtual bool get_mouse_position (Duple& winpos) const = 0;
+
+ /** Signal to be used by items that need to track the mouse position
+ within the window.
+ */
+ sigc::signal<void,Duple const&> MouseMotion;
+
+ /** Ensures that the position given by @param winpos (in window
+ coordinates) is within the current window area, possibly reduced by
+ @param border.
+ */
+ Duple clamp_to_window (Duple const& winpos, Duple border = Duple());
+
+ void zoomed();
+
std::string indent() const;
std::string render_indent() const;
void dump (std::ostream&) const;
+
+ /** Ask the canvas to pick the current item again, and generate
+ an enter event for it.
+ */
+ virtual void re_enter () = 0;
protected:
void queue_draw_item_area (Item *, Rect);
- /** our root group */
- RootGroup _root;
+ /** our root item */
+ Root _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));
+ virtual void pick_current_item (int state) = 0;
+ virtual void pick_current_item (Duple const &, int state) = 0;
- 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 ();
-
-private:
- /** our Cairo surface */
- Cairo::RefPtr<Cairo::Surface> _surface;
- /** our Cairo context */
- Cairo::RefPtr<Cairo::Context> _context;
+ std::list<ScrollGroup*> scrollers;
};
/** A canvas which renders onto a GTK EventBox */
-class GtkCanvas : public Canvas, public Gtk::EventBox
+class LIBCANVAS_API GtkCanvas : public Canvas, public Gtk::EventBox
{
public:
GtkCanvas ();
- GtkCanvas (XMLTree const *);
void request_redraw (Rect const &);
void request_size (Duple);
void grab (Item *);
void ungrab ();
+ void focus (Item *);
+ void unfocus (Item*);
Cairo::RefPtr<Cairo::Context> context ();
+ Rect visible_area () const;
+ Coord width() const;
+ Coord height() const;
+
+ bool get_mouse_position (Duple& winpos) const;
+
+ void re_enter ();
+
protected:
+ bool on_scroll_event (GdkEventScroll *);
bool on_expose_event (GdkEventExpose *);
bool on_button_press_event (GdkEventButton *);
bool on_button_release_event (GdkEventButton* event);
bool on_motion_notify_event (GdkEventMotion *);
+ bool on_enter_notify_event (GdkEventCrossing*);
+ bool on_leave_notify_event (GdkEventCrossing*);
bool button_handler (GdkEventButton *);
bool motion_notify_handler (GdkEventMotion *);
- bool deliver_event (Duple, GdkEvent *);
+ bool deliver_event (GdkEvent *);
+ void deliver_enter_leave (Duple const & point, int state);
+
+ void pick_current_item (int state);
+ void pick_current_item (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;
+ /** Item currently chosen for event delivery based on pointer position */
+ Item * _current_item;
+ /** Item pending as _current_item */
+ Item * _new_current_item;
/** the item that is currently grabbed, or 0 */
- Item const * _grabbed_item;
+ Item * _grabbed_item;
+ /** the item that currently has key focus or 0 */
+ Item * _focused_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 LIBCANVAS_API 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 ();
};
}