Ardour  9.0-pre0-582-g084a23a80d
canvas/canvas/canvas.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Carl Hetherington <carl@carlh.net>
3  * Copyright (C) 2013-2017 Paul Davis <paul@linuxaudiosystems.com>
4  * Copyright (C) 2014-2015 Ben Loftis <ben@harrisonconsoles.com>
5  * Copyright (C) 2014-2017 Robin Gareus <robin@gareus.org>
6  * Copyright (C) 2017 Tim Mayberry <mojofunk@gmail.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22 
27 #ifndef __CANVAS_CANVAS_H__
28 #define __CANVAS_CANVAS_H__
29 
30 #include <set>
31 
32 #include <gtkmm/alignment.h>
33 #include <gtkmm/eventbox.h>
34 #include <gdkmm/window.h>
35 
36 #include <cairomm/context.h>
37 #include <cairomm/surface.h>
38 
39 #include "pbd/signals.h"
40 
41 #include "gtkmm2ext/cairo_canvas.h"
42 
43 #include "canvas/root_group.h"
44 #include "canvas/visibility.h"
45 
46 namespace Gtk {
47  class Window;
48  class Label;
49 }
50 
51 namespace Pango {
52  class Context;
53 }
54 
55 namespace ArdourCanvas
56 {
57 struct Rect;
58 
59 class Item;
60 class ScrollGroup;
61 
73 {
74 public:
75  Canvas ();
76  virtual ~Canvas () {}
77 
79  virtual void request_redraw (Rect const &) = 0;
81  virtual void request_size (Duple) = 0;
83  virtual void grab (Item *) = 0;
85  virtual void ungrab () = 0;
87  virtual void queue_resize () = 0;
88 
90  virtual void focus (Item *) = 0;
92  virtual void unfocus (Item*) = 0;
93 
94  virtual bool have_grab() const { return false; }
95  virtual bool grab_can_translate () const { return true; }
96 
97  void render (Rect const &, Cairo::RefPtr<Cairo::Context> const &) const;
98 
99  void prepare_for_render (Rect const &) const;
100 
101  gint64 get_last_render_start_timestamp () const { return _last_render_start_timestamp; }
102 
104 
106  Item* root () {
107  return &_root;
108  }
109 
112 
114  Gtkmm2ext::Color background_color() const { return _bg_color; }
115 
117  virtual void item_going_away (Item *, Rect) {}
118  virtual void item_shown_or_hidden (Item *);
120  void item_changed (Item *, Rect);
121  void item_moved (Item *, Rect);
122 
123  Duple canvas_to_window (Duple const&, bool rounded = true) const;
124  Duple window_to_canvas (Duple const&) const;
125 
126  void canvas_to_window (Coord cx, Coord cy, Coord& wx, Coord& wy) {
127  Duple d = canvas_to_window (Duple (cx, cy));
128  wx = d.x;
129  wy = d.y;
130  }
131 
132  void window_to_canvas (Coord wx, Coord wy, Coord& cx, Coord& cy) {
133  Duple d = window_to_canvas (Duple (wx, wy));
134  cx = d.x;
135  cy = d.y;
136  }
137 
138  void scroll_to (Coord x, Coord y);
140 
141  virtual Rect visible_area () const = 0;
142  virtual Coord width () const = 0;
143  virtual Coord height () const = 0;
144 
149  virtual bool get_mouse_position (Duple& winpos) const = 0;
150 
154  sigc::signal<void,Duple const&> MouseMotion;
155 
156  sigc::signal<void> PreRender;
157 
162  Duple clamp_to_window (Duple const& winpos, Duple border = Duple());
163 
164  void zoomed();
165 
166  std::string indent() const;
167  std::string render_indent() const;
168  void dump (std::ostream&) const;
169 
173  virtual void re_enter () = 0;
174 
175  virtual void start_tooltip_timeout (Item*) {}
176  virtual void stop_tooltip_timeout () {}
177 
180  static void set_tooltip_timeout (uint32_t msecs);
181 
182  virtual Glib::RefPtr<Pango::Context> get_pango_context() = 0;
183 
187  void use_intermediate_surface (bool yn = true);
188 
189  void set_debug_render (bool yn) { _debug_render = yn; }
190  bool debug_render() const { return _debug_render; }
191 
193 
194 protected:
200 
202 
203  static uint32_t tooltip_timeout_msecs;
204 
207 
208  virtual void pick_current_item (int state) = 0;
209  virtual void pick_current_item (Duple const &, int state) = 0;
210 
211  std::list<ScrollGroup*> scrollers;
212 
214 };
215 
218 {
219 public:
222 
223  void use_nsglview (bool retina = true);
224 
225  void request_redraw (Rect const &);
227  void grab (Item *);
228  void ungrab ();
229  void focus (Item *);
230  void unfocus (Item*);
231 
232  bool have_grab() const { return _grabbed_item; }
233  bool grab_can_translate () const;
234 
235  Rect visible_area () const;
236  Coord width() const;
237  Coord height() const;
238 
239  bool get_mouse_position (Duple& winpos) const;
240 
241  void set_single_exposure (bool s);
242  bool single_exposure () { return _single_exposure; }
243 
244  void re_enter ();
245 
248 
249  void queue_draw ();
250  void queue_draw_area (int x, int y, int width, int height);
251  void queue_resize ();
252 
253  Glib::RefPtr<Pango::Context> get_pango_context();
254 
255  /* This is the render method called via the Gtkmm2ext::CairoCanvas API,
256  which is distinct from ArdourCanvas.
257  */
258  void render (Cairo::RefPtr<Cairo::Context> const & ctx, cairo_rectangle_t* r);
259  void prepare_for_render () const;
260 
261  uint32_t background_color() { return Canvas::background_color (); }
262 
263 protected:
277  void on_style_changed (const Glib::RefPtr<Gtk::Style>&);
279  void on_map();
280  void on_unmap();
281 
282  void on_realize ();
283 
287  void deliver_enter_leave (Duple const & point, int state);
288 
289  void get_items_enclosing (Duple const& point, std::list<Item const*>& enclosing_items);
290 
291  void pick_current_item (int state);
292  void pick_current_item (Duple const &, int state);
293 
294 private:
297  bool send_leave_event (Item const *, double, double) const;
298 
307 
309  std::map<int, Item*> _touched_item;
310 
313 
314  sigc::connection tooltip_timeout_connection;
318  bool show_tooltip ();
319  void hide_tooltip ();
321  bool resize_handler ();
322 
323  bool _in_dtor;
325 
326  void* _nsglview;
327  Cairo::RefPtr<Cairo::Surface> _canvas_image;
328 };
329 
337 {
338 public:
340 
343  return &_canvas;
344  }
345 
346 protected:
348 
349 private:
354 
355  void scrolled ();
356 };
357 
358 }
359 
360 std::ostream& operator<< (std::ostream&, const ArdourCanvas::Canvas&);
361 
362 #endif
std::ostream & operator<<(std::ostream &, const ArdourCanvas::Canvas &)
#define LIBCANVAS_API
virtual Rect visible_area() const =0
std::string render_indent() const
virtual bool get_mouse_position(Duple &winpos) const =0
virtual Coord height() const =0
void render(Rect const &, Cairo::RefPtr< Cairo::Context > const &) const
virtual void ungrab()=0
virtual void start_tooltip_timeout(Item *)
void canvas_to_window(Coord cx, Coord cy, Coord &wx, Coord &wy)
void item_moved(Item *, Rect)
virtual void focus(Item *)=0
sigc::signal< void, Duple const & > MouseMotion
virtual void pick_current_item(int state)=0
virtual void re_enter()=0
gint64 get_last_render_start_timestamp() const
virtual void unfocus(Item *)=0
virtual Coord width() const =0
virtual void item_shown_or_hidden(Item *)
virtual bool have_grab() const
virtual void stop_tooltip_timeout()
void item_changed(Item *, Rect)
virtual void item_going_away(Item *, Rect)
void use_intermediate_surface(bool yn=true)
virtual void request_redraw(Rect const &)=0
Rect compute_draw_item_area(Item *, Rect)
void scroll_to(Coord x, Coord y)
Duple canvas_to_window(Duple const &, bool rounded=true) const
void item_visual_property_changed(Item *)
Duple window_to_canvas(Duple const &) const
void dump(std::ostream &) const
void add_scroller(ScrollGroup &i)
static void set_tooltip_timeout(uint32_t msecs)
virtual void request_size(Duple)=0
virtual bool grab_can_translate() const
void prepare_for_render(Rect const &) const
void queue_draw_item_area(Item *, Rect)
static uint32_t tooltip_timeout_msecs
void set_background_color(Gtkmm2ext::Color)
gint64 get_microseconds_since_render_start() const
sigc::signal< void > PreRender
virtual void pick_current_item(Duple const &, int state)=0
virtual void grab(Item *)=0
void window_to_canvas(Coord wx, Coord wy, Coord &cx, Coord &cy)
Gtkmm2ext::Color background_color() const
virtual void queue_resize()=0
Duple clamp_to_window(Duple const &winpos, Duple border=Duple())
virtual Glib::RefPtr< Pango::Context > get_pango_context()=0
std::list< ScrollGroup * > scrollers
Gtkmm2ext::Color _bg_color
std::string indent() const
void on_size_request(Gtk::Requisition *)
This is a default handler for the signal signal_size_request().
GtkCanvasViewport(Gtk::Adjustment &, Gtk::Adjustment &)
void set_single_exposure(bool s)
void deliver_enter_leave(Duple const &point, int state)
void on_style_changed(const Glib::RefPtr< Gtk::Style > &)
void get_items_enclosing(Duple const &point, std::list< Item const * > &enclosing_items)
void prepare_for_render() const
bool on_visibility_notify_event(GdkEventVisibility *)
This is a default handler for the signal signal_visibility_notify_event().
bool on_touch_update_event(GdkEventTouch *event)
void queue_draw_area(int x, int y, int width, int height)
bool on_touch_begin_event(GdkEventTouch *)
void request_redraw(Rect const &)
bool deliver_event(GdkEvent *)
void item_shown_or_hidden(Item *)
bool motion_notify_handler(GdkEventMotion *)
Cairo::RefPtr< Cairo::Surface > _canvas_image
bool on_touch_end_event(GdkEventTouch *)
Glib::RefPtr< Pango::Context > get_pango_context()
bool on_enter_notify_event(GdkEventCrossing *)
This is a default handler for the signal signal_enter_notify_event().
bool on_key_press_event(GdkEventKey *)
This is a default handler for the signal signal_key_press_event().
void on_map()
This is a default handler for the signal signal_map().
bool on_scroll_event(GdkEventScroll *)
This is a default handler for the signal signal_scroll_event().
void on_unmap()
This is a default handler for the signal signal_unmap().
void item_going_away(Item *, Rect)
void use_nsglview(bool retina=true)
bool on_motion_notify_event(GdkEventMotion *)
This is a default handler for the signal signal_motion_notify_event().
bool on_expose_event(GdkEventExpose *)
This is a default handler for the signal signal_expose_event().
void on_realize()
This is a default handler for the signal signal_realize().
sigc::connection tooltip_timeout_connection
std::map< int, Item * > _touched_item
void start_tooltip_timeout(Item *)
bool on_button_press_event(GdkEventButton *)
This is a default handler for the signal signal_button_press_event().
bool on_button_release_event(GdkEventButton *event)
This is a default handler for the signal signal_button_release_event().
bool on_key_release_event(GdkEventKey *)
This is a default handler for the signal signal_key_release_event().
bool on_leave_notify_event(GdkEventCrossing *)
This is a default handler for the signal signal_leave_notify_event().
bool get_mouse_position(Duple &winpos) const
void pick_current_item(int state)
bool button_handler(GdkEventButton *)
bool send_leave_event(Item const *, double, double) const
void render(Cairo::RefPtr< Cairo::Context > const &ctx, cairo_rectangle_t *r)
Rect visible_area() const
void pick_current_item(Duple const &, int state)
bool grab_can_translate() const
void on_size_allocate(Gtk::Allocation &)
This is a default handler for the signal signal_size_allocate().
Definition: Window.h:41
Definition: ardour_ui.h:188
uint32_t Color
Definition: colors.h:33
gint height
Definition: xcursors.h:1
gint width
Definition: xcursors.h:1