2 Copyright (C) 2011-2013 Paul Davis
3 Author: Carl Hetherington <cth@carlh.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 /** @file canvas/canvas.h
21 * @brief Declaration of the main canvas classes.
24 #ifndef __CANVAS_CANVAS_H__
25 #define __CANVAS_CANVAS_H__
27 #include <gdkmm/window.h>
28 #include <gtkmm/eventbox.h>
29 #include <gtkmm/alignment.h>
30 #include <cairomm/surface.h>
31 #include <cairomm/context.h>
32 #include "pbd/signals.h"
33 #include "canvas/root_group.h"
37 namespace ArdourCanvas
43 /** The base class for our different types of canvas.
45 * A canvas is an area which holds a collection of canvas items, which in
46 * turn represent shapes, text, etc.
48 * The canvas has an arbitrarily large area, and is addressed in coordinates
49 * of screen pixels, with an origin of (0, 0) at the top left. x increases
50 * rightwards and y increases downwards.
57 Canvas (XMLTree const *);
60 /** called to request a redraw of an area of the canvas */
61 virtual void request_redraw (Rect const &) = 0;
62 /** called to ask the canvas to request a particular size from its host */
63 virtual void request_size (Duple) = 0;
64 /** called to ask the canvas' host to `grab' an item */
65 virtual void grab (Item *) = 0;
66 /** called to ask the canvas' host to `ungrab' any grabbed item */
67 virtual void ungrab () = 0;
69 void render (Rect const &, Cairo::RefPtr<Cairo::Context> const &) const;
71 /** @return root group */
76 /** Called when an item is being destroyed */
77 virtual void item_going_away (Item *, boost::optional<Rect>) {}
78 void item_shown_or_hidden (Item *);
79 void item_changed (Item *, boost::optional<Rect>);
80 void item_moved (Item *, boost::optional<Rect>);
82 XMLTree* get_state () const;
84 virtual Cairo::RefPtr<Cairo::Context> context () = 0;
86 std::list<Rect> const & renders () const {
90 void set_log_renders (bool log) {
94 void scroll_to (Coord x, Coord y);
96 std::string indent() const;
97 std::string render_indent() const;
98 void dump (std::ostream&) const;
101 void queue_draw_item_area (Item *, Rect);
103 /** our root group */
106 mutable std::list<Rect> _renders;
109 Coord _scroll_offset_x;
110 Coord _scroll_offset_y;
113 /** A canvas which renders onto a GTK EventBox */
114 class GtkCanvas : public Canvas, public Gtk::EventBox
118 GtkCanvas (XMLTree const *);
120 void request_redraw (Rect const &);
121 void request_size (Duple);
125 Cairo::RefPtr<Cairo::Context> context ();
127 Rect canvas_to_window (Rect const&) const;
128 Rect window_to_canvas (Rect const&) const;
130 Duple canvas_to_window (Duple const&) const;
131 Duple window_to_canvas (Duple const&) const;
134 bool on_expose_event (GdkEventExpose *);
135 bool on_button_press_event (GdkEventButton *);
136 bool on_button_release_event (GdkEventButton* event);
137 bool on_motion_notify_event (GdkEventMotion *);
139 bool button_handler (GdkEventButton *);
140 bool motion_notify_handler (GdkEventMotion *);
141 bool deliver_event (Duple, GdkEvent *);
144 void item_going_away (Item *, boost::optional<Rect>);
145 bool send_leave_event (Item const *, double, double) const;
148 /** the item that the mouse is currently over, or 0 */
149 Item const * _current_item;
150 /** the item that is currently grabbed, or 0 */
151 Item const * _grabbed_item;
154 /** A GTK::Alignment with a GtkCanvas inside it plus some Gtk::Adjustments for
157 * This provides a GtkCanvas that can be scrolled. It does NOT implement the
158 * Gtk::Scrollable interface.
160 class GtkCanvasViewport : public Gtk::Alignment
163 GtkCanvasViewport (Gtk::Adjustment &, Gtk::Adjustment &);
165 /** @return our GtkCanvas */
166 GtkCanvas* canvas () {
170 void window_to_canvas (int, int, Coord &, Coord &) const;
171 Rect visible_area () const;
174 void on_size_request (Gtk::Requisition *);
179 Gtk::Adjustment& hadjustment;
180 Gtk::Adjustment& vadjustment;
187 std::ostream& operator<< (std::ostream&, const ArdourCanvas::Canvas&);