#include "pbd/error.h"
#include "pbd/stacktrace.h"
-#include "gtkmm2ext/utils.h"
-#include "gtkmm2ext/rgb_macros.h"
+#include "gtkmm2ext/colors.h"
#include "gtkmm2ext/gui_thread.h"
-
-#include "canvas/utils.h"
-#include "canvas/colors.h"
+#include "gtkmm2ext/rgb_macros.h"
+#include "gtkmm2ext/utils.h"
#include "widgets/ardour_button.h"
#include "widgets/tooltips.h"
ArdourButton::Element ArdourButton::led_default_elements = ArdourButton::Element (ArdourButton::default_elements|ArdourButton::Indicator);
ArdourButton::Element ArdourButton::just_led_default_elements = ArdourButton::Element (ArdourButton::Edge|ArdourButton::Body|ArdourButton::Indicator);
-ArdourButton::ArdourButton (Element e)
+ArdourButton::ArdourButton (Element e, bool toggle)
: _sizing_text("")
, _markup (false)
, _elements (e)
, led_inset_pattern (0)
, _led_rect (0)
, _act_on_release (true)
+ , _auto_toggle (toggle)
, _led_left (false)
, _distinct_led_click (false)
, _hovering (false)
signal_grab_broken_event().connect (sigc::mem_fun (*this, &ArdourButton::on_grab_broken_event));
}
-ArdourButton::ArdourButton (const std::string& str, Element e)
+ArdourButton::ArdourButton (const std::string& str, Element e, bool toggle)
: _sizing_text("")
, _markup (false)
, _elements (e)
, led_inset_pattern (0)
, _led_rect (0)
, _act_on_release (true)
+ , _auto_toggle (toggle)
, _led_left (false)
, _distinct_led_click (false)
, _hovering (false)
return;
}
_sizing_text = str;
- if (!is_realized()) {
- return;
- }
- ensure_layout ();
- if (_layout) {
- queue_resize ();
- }
+ queue_resize ();
}
void
if ((_elements & Body)==Body) {
rounded_function (cr, 1, 1, get_width() - 2, get_height() - 2, corner_radius);
if (active_state() == Gtkmm2ext::ImplicitActive && !((_elements & Indicator)==Indicator)) {
- ArdourCanvas::set_source_rgba (cr, fill_inactive_color);
+ Gtkmm2ext::set_source_rgba (cr, fill_inactive_color);
cairo_fill (cr);
} else if ( (active_state() == Gtkmm2ext::ExplicitActive) && !((_elements & Indicator)==Indicator) ) {
//background color
- ArdourCanvas::set_source_rgba (cr, fill_active_color);
+ Gtkmm2ext::set_source_rgba (cr, fill_active_color);
cairo_fill (cr);
} else { //inactive, or it has an indicator
//background color
- ArdourCanvas::set_source_rgba (cr, fill_inactive_color);
+ Gtkmm2ext::set_source_rgba (cr, fill_inactive_color);
}
cairo_fill (cr);
}
if (active_state() == Gtkmm2ext::ImplicitActive && !((_elements & Indicator)==Indicator)) {
cairo_set_line_width (cr, 2.0);
rounded_function (cr, 2, 2, get_width() - 4, get_height() - 4, corner_radius-0.5);
- ArdourCanvas::set_source_rgba (cr, fill_active_color);
+ Gtkmm2ext::set_source_rgba (cr, fill_active_color);
cairo_stroke (cr);
}
}
cairo_clip(cr);
cairo_new_path (cr);
- ArdourCanvas::set_source_rgba (cr, text_color);
+ Gtkmm2ext::set_source_rgba (cr, text_color);
const double text_ypos = (get_height() - _text_height) * .5;
if (_elements & Menu) {
cairo_fill(cr);
//led color
- ArdourCanvas::set_source_rgba (cr, led_color);
+ Gtkmm2ext::set_source_rgba (cr, led_color);
cairo_arc (cr, 0, 0, _diameter * .5 - 3 * UIConfigurationBase::instance().get_ui_scale(), 0, 2 * M_PI);
cairo_fill(cr);
if ((visual_state() & Gtkmm2ext::Insensitive)) {
rounded_function (cr, 0, 0, get_width(), get_height(), corner_radius);
uint32_t ins_color = UIConfigurationBase::instance().color ("gtk_background");
- ArdourCanvas::set_source_rgb_a (cr, ins_color, 0.6);
+ Gtkmm2ext::set_source_rgb_a (cr, ins_color, 0.6);
cairo_fill (cr);
}
* of text.
*/
+ } else if (_layout_ellipsize_width > 0 && _sizing_text.empty()) {
+
+ req->height = std::max(req->height, (int) ceil(char_pixel_height() * BASELINESTRETCH + 1.0));
+ req->width += _layout_ellipsize_width / PANGO_SCALE;
+
} else /*if (!_text.empty() || !_sizing_text.empty()) */ {
req->height = std::max(req->height, (int) ceil(char_pixel_height() * BASELINESTRETCH + 1.0));
}
}
- text_active_color = ArdourCanvas::contrasting_text_color (fill_active_color);
- text_inactive_color = ArdourCanvas::contrasting_text_color (fill_inactive_color);
+ text_active_color = Gtkmm2ext::contrasting_text_color (fill_active_color);
+ text_inactive_color = Gtkmm2ext::contrasting_text_color (fill_inactive_color);
led_active_color = UIConfigurationBase::instance().color (string_compose ("%1: led active", name), &failed);
if (failed) {
* active color.
*/
- ArdourCanvas::HSV inactive (led_active_color);
+ Gtkmm2ext::HSV inactive (led_active_color);
inactive.v = 0.35;
led_inactive_color = inactive.color ();
{
focus_handler (this);
+ if (ev->type == GDK_2BUTTON_PRESS || ev->type == GDK_3BUTTON_PRESS) {
+ return _fallthrough_to_parent ? false : true;
+ }
+
if (ev->button == 1 && (_elements & Indicator) && _led_rect && _distinct_led_click) {
if (ev->x >= _led_rect->x && ev->x < _led_rect->x + _led_rect->width &&
ev->y >= _led_rect->y && ev->y < _led_rect->y + _led_rect->height) {
if (_action) {
_action->activate ();
return true;
+ } else if (_auto_toggle) {
+ set_active (!get_active ());
+ signal_clicked ();
+ return true;
}
}
- if (_fallthrough_to_parent)
- return false;
-
- return true;
+ return _fallthrough_to_parent ? false : true;
}
bool
ArdourButton::on_button_release_event (GdkEventButton *ev)
{
+ if (ev->type == GDK_2BUTTON_PRESS || ev->type == GDK_3BUTTON_PRESS) {
+ return _fallthrough_to_parent ? false : true;
+ }
if (ev->button == 1 && _hovering && (_elements & Indicator) && _led_rect && _distinct_led_click) {
if (ev->x >= _led_rect->x && ev->x < _led_rect->x + _led_rect->width &&
ev->y >= _led_rect->y && ev->y < _led_rect->y + _led_rect->height) {
CairoWidget::set_dirty ();
if (ev->button == 1 && _hovering) {
+ if (_act_on_release && _auto_toggle && !_action) {
+ set_active (!get_active ());
+ }
signal_clicked ();
if (_act_on_release) {
if (_action) {
}
}
- if (_fallthrough_to_parent)
- return false;
-
- return true;
+ return _fallthrough_to_parent ? false : true;
}
void
if (_act_on_release && _focused &&
(ev->keyval == GDK_space || ev->keyval == GDK_Return))
{
+ if (_auto_toggle && !_action) {
+ set_active (!get_active ());
+ }
signal_clicked();
if (_action) {
_action->activate ();
if (!_act_on_release && _focused &&
(ev->keyval == GDK_space || ev->keyval == GDK_Return))
{
+ if (_auto_toggle && !_action) {
+ set_active (!get_active ());
+ }
signal_clicked();
if (_action) {
_action->activate ();