2 Copyright (C) 2017 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include <gtkmm/container.h>
22 #include "gtkmm2ext/colors.h"
23 #include "gtkmm2ext/gtk_ui.h"
24 #include "gtkmm2ext/gui_thread.h"
25 #include "gtkmm2ext/utils.h"
27 #include "ui_config.h"
29 #include "plugin_display.h"
33 PluginDisplay::PluginDisplay (boost::shared_ptr<ARDOUR::Plugin> p, uint32_t max_height)
36 , _max_height (max_height)
40 add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
41 _plug->DropReferences.connect (_death_connection, invalidator (*this), boost::bind (&PluginDisplay::plugin_going_away, this), gui_context());
42 _plug->QueueDraw.connect (_qdraw_connection, invalidator (*this),
43 boost::bind (&Gtk::Widget::queue_draw, this), gui_context ());
46 PluginDisplay::~PluginDisplay ()
49 cairo_surface_destroy (_surf);
54 PluginDisplay::on_button_press_event (GdkEventButton *ev)
60 PluginDisplay::on_button_release_event (GdkEventButton *ev)
66 PluginDisplay::on_size_request (Gtk::Requisition* req)
69 req->height = _cur_height;
74 PluginDisplay::update_height_alloc (uint32_t height)
76 uint32_t shm = std::min (_max_height, height);
78 if (shm != _cur_height) {
85 PluginDisplay::render_inline (cairo_t* cr, uint32_t width)
87 ARDOUR::Plugin::Display_Image_Surface* dis = _plug->render_inline_display (width, _max_height);
92 /* allocate a local image-surface,
93 * We cannot re-use the data via cairo_image_surface_create_for_data(),
94 * since pixman keeps a reference to it.
95 * we'd need to hand over the data and ha cairo_surface_destroy to free it.
96 * it might be possible to work around via cairo_surface_set_user_data().
99 || dis->width != cairo_image_surface_get_width (_surf)
100 || dis->height != cairo_image_surface_get_height (_surf)
103 cairo_surface_destroy (_surf);
105 _surf = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, dis->width, dis->height);
108 if (cairo_image_surface_get_stride (_surf) == dis->stride) {
109 memcpy (cairo_image_surface_get_data (_surf), dis->data, dis->stride * dis->height);
111 unsigned char *src = dis->data;
112 unsigned char *dst = cairo_image_surface_get_data (_surf);
113 const int dst_stride = cairo_image_surface_get_stride (_surf);
114 for (int y = 0; y < dis->height; ++y) {
115 memcpy (dst, src, dis->width * 4 /*ARGB32*/);
121 cairo_surface_flush(_surf);
122 cairo_surface_mark_dirty(_surf);
123 const double xc = floor ((width - dis->width) * .5);
124 cairo_set_source_surface(cr, _surf, xc, 0);
131 PluginDisplay::on_expose_event (GdkEventExpose* ev)
133 Gtk::Allocation a = get_allocation();
134 double const width = a.get_width();
135 double const height = a.get_height();
137 cairo_t* cr = gdk_cairo_create (get_window()->gobj());
138 cairo_rectangle (cr, ev->area.x, ev->area.y, ev->area.width, ev->area.height);
141 Gdk::Color const bg = get_style()->get_bg (Gtk::STATE_NORMAL);
142 cairo_set_source_rgb (cr, bg.get_red_p (), bg.get_green_p (), bg.get_blue_p ());
143 cairo_rectangle (cr, 0, 0, width, height);
147 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
148 display_sample(cr, width, height);
150 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
152 uint32_t ht = render_inline (cr, width);
157 if (_cur_height != 1) {
164 update_height_alloc (ht);
168 std::string name = get_name();
169 Gtkmm2ext::Color fill_color = UIConfiguration::instance().color (string_compose ("%1: fill active", name), &failed);
171 display_sample(cr, width, height);
172 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
173 cairo_set_line_width(cr, 1.0);
175 cairo_set_source_rgba (cr, .75, .75, .75, 1.0);
177 Gtkmm2ext::set_source_rgb_a (cr, fill_color, 1.0);
186 PluginDisplay::display_sample (cairo_t* cr, double w, double h)
188 cairo_rectangle (cr, 0.0, 0.0, w, h);