2 * Copyright (C) 2016 Paul Davis
3 * Copyright (C) 2016 Robin Gareus <robin@gareus.org>
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, or (at your option)
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 Foundation,
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 #include <cairomm/region.h>
23 #include <cairomm/surface.h>
24 #include <cairomm/context.h>
26 #include "pbd/compose.h"
27 #include "pbd/error.h"
33 #include "maschine2.h"
37 #define Rect ArdourCanvas::Rect
40 using namespace ArdourCanvas;
41 using namespace ArdourSurface;
44 Maschine2Canvas::Maschine2Canvas (Maschine2&m, M2Device* hw)
47 context = Cairo::Context::create (hw->surface ());
48 expose_region = Cairo::Region::create ();
49 _width = hw->surface ()->get_width ();
50 _height = hw->surface ()->get_height ();
52 hw->vblank.connect_same_thread (vblank_connections, boost::bind (&Maschine2Canvas::expose, this));
55 Maschine2Canvas::~Maschine2Canvas ()
60 Maschine2Canvas::request_redraw ()
62 request_redraw (Rect (0, 0, _width, _height));
66 Maschine2Canvas::request_redraw (Rect const & r)
68 Cairo::RectangleInt cr;
73 cr.height = r.height();
75 expose_region->do_union (cr);
77 /* next vblank will redraw */
81 Maschine2Canvas::expose ()
83 if (expose_region->empty()) {
84 return false; /* nothing drawn */
89 const int nrects = expose_region->get_num_rectangles ();
91 for (int n = 0; n < nrects; ++n) {
92 Cairo::RectangleInt r = expose_region->get_rectangle (n);
93 context->rectangle (r.x, r.y, r.width, r.height);
98 Maschine2Layout* layout = m2.current_layout();
101 /* all layouts cover (at least) the full size of the video
102 display, so we do not need to check if the layout intersects
103 the bounding box of the full expose region.
105 Cairo::RectangleInt r = expose_region->get_extents();
106 Rect rr (r.x, r.y, r.x + r.width, r.y + r.height);
107 layout->render (Rect (r.x, r.y, r.x + r.width, r.y + r.height), context);
110 context->reset_clip ();
112 /* why is there no "reset()" method for Cairo::Region? */
113 expose_region = Cairo::Region::create ();
118 Maschine2Canvas::request_size (Duple)
120 /* fixed size canvas */
124 Maschine2Canvas::visible_area () const
126 /* may need to get more sophisticated once we do scrolling */
127 return Rect (0, 0, _width, _height);
130 Glib::RefPtr<Pango::Context>
131 Maschine2Canvas::get_pango_context ()
133 if (!pango_context) {
134 PangoFontMap* map = pango_cairo_font_map_get_default ();
136 error << _("Default Cairo font map is null!") << endmsg;
137 return Glib::RefPtr<Pango::Context> ();
140 PangoContext* context = pango_font_map_create_context (map);
143 error << _("cannot create new PangoContext from cairo font map") << endmsg;
144 return Glib::RefPtr<Pango::Context> ();
147 pango_context = Glib::wrap (context);
150 return pango_context;