2 * Copyright (C) 2017 Robin Gareus <robin@gareus.org>
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #include "gtkmm2ext/utils.h"
20 #include "widgets/tooltips.h"
22 #include "ardour_gauge.h"
23 #include "ui_config.h"
27 ArdourGauge::ArdourGauge (std::string const& max_text)
29 _layout = Pango::Layout::create (get_pango_context ());
30 _layout->set_text (max_text);
33 ArdourGauge::~ArdourGauge ()
38 ArdourGauge::on_size_request (Gtk::Requisition* req)
40 req->width = req->height = 0;
41 CairoWidget::on_size_request (req);
44 _layout->get_pixel_size (w, h);
46 req->width = std::max (req->width, std::max (12, h + PADDING));
47 req->height = std::max (req->height, 20 /*std::max (20, w + PADDING) */);
51 ArdourGauge::update ()
54 ArdourWidgets::set_tooltip (*this, tooltip_text ());
58 ArdourGauge::update (std::string const& txt)
60 _layout->set_text (txt);
65 ArdourGauge::render (Cairo::RefPtr<Cairo::Context> const& ctx, cairo_rectangle_t*)
67 cairo_t* cr = ctx->cobj ();
68 Gtkmm2ext::Color base = UIConfiguration::instance ().color ("ruler base");
69 Gtkmm2ext::Color text = UIConfiguration::instance ().color ("ruler text");
71 const int width = get_width ();
72 const int height = get_height ();
74 Gtkmm2ext::rounded_rectangle (cr, 0, 0, width, height, PADDING + 1);
75 Gtkmm2ext::set_source_rgba (cr, base);
79 Gtkmm2ext::rounded_rectangle (cr, 1, 1, width - 2, height - 2, PADDING + 1);
80 cairo_set_source_rgba (cr, 0.5, 0, 0, 1.0);
84 Gtkmm2ext::rounded_rectangle (cr, PADDING, PADDING, width - PADDING - PADDING, height - PADDING - PADDING, PADDING + 1);
87 const float lvl = level ();
89 int bh = (height - PADDING - PADDING) * lvl;
90 cairo_rectangle (cr, PADDING, height - PADDING - bh, width - PADDING, bh);
92 switch (indicator ()) {
94 cairo_set_source_rgba (cr, 0, .5, 0, 1.0);
97 cairo_set_source_rgba (cr, .7, .6, 0, 1.0);
100 cairo_set_source_rgba (cr, .9, 0, 0, 1.0);
106 _layout->get_pixel_size (w, h);
110 cairo_translate (cr, width * .5, height * .5);
111 cairo_rotate (cr, M_PI * -.5);
113 cairo_move_to (cr, w * -.5, h * -.5);
114 pango_cairo_update_layout (cr, _layout->gobj());
115 Gtkmm2ext::set_source_rgb_a (cr, base, 0.5);
116 pango_cairo_layout_path (cr, _layout->gobj());
117 cairo_set_line_width (cr, 1.5);
120 cairo_move_to (cr, w * -.5, h * -.5);
121 pango_cairo_update_layout (cr, _layout->gobj());
122 Gtkmm2ext::set_source_rgba (cr, text);
123 pango_cairo_show_layout (cr, _layout->gobj());