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, 100 /*std::max (20, w + PADDING) */);
47 req->height = std::max (req->height, std::max (12, h + 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::blink (bool onoff)
72 ArdourGauge::render (Cairo::RefPtr<Cairo::Context> const& ctx, cairo_rectangle_t*)
74 cairo_t* cr = ctx->cobj ();
75 Gtkmm2ext::Color bg = UIConfiguration::instance().color ("gtk_background");
76 Gtkmm2ext::Color base = UIConfiguration::instance ().color ("ruler base");
77 Gtkmm2ext::Color text = UIConfiguration::instance ().color ("ruler text");
79 const int width = get_width ();
80 const int height = get_height ();
82 cairo_rectangle (cr, 0, 0, width, height);
83 cairo_set_source_rgba (cr, 0,0,0,1 );
86 cairo_rectangle (cr, 1, 1, width-2, height-2);
87 Gtkmm2ext::set_source_rgba (cr, bg);
90 if (alert () && _blink) {
91 Gtkmm2ext::rounded_rectangle (cr, 1, 1, width - 2, height - 2, 1);
92 cairo_set_source_rgba (cr, 0.5, 0, 0, 1.0);
96 cairo_rectangle (cr, PADDING, PADDING, width - PADDING - PADDING, height - PADDING - PADDING);
99 const float lvl = level ();
101 int bw = (width - PADDING - PADDING) * lvl;
102 cairo_rectangle (cr, PADDING, PADDING, bw, height-PADDING);
104 switch (indicator ()) {
106 cairo_set_source_rgba (cr, 0, .5, 0, 1.0);
109 cairo_set_source_rgba (cr, .7, .6, 0, 1.0);
112 cairo_set_source_rgba (cr, .9, 0, 0, 1.0);
118 _layout->get_pixel_size (w, h);
122 cairo_translate (cr, width * .5, height * .5);
124 cairo_move_to (cr, w * -.5, h * -.5);
125 pango_cairo_update_layout (cr, _layout->gobj());
126 Gtkmm2ext::set_source_rgb_a (cr, base, 0.5);
127 pango_cairo_layout_path (cr, _layout->gobj());
128 cairo_set_line_width (cr, 1.5);
131 cairo_move_to (cr, w * -.5, h * -.5);
132 pango_cairo_update_layout (cr, _layout->gobj());
133 Gtkmm2ext::set_source_rgba (cr, text);
134 pango_cairo_show_layout (cr, _layout->gobj());