, _led_rect (0)
{
ColorsChanged.connect (sigc::mem_fun (*this, &ArdourButton::color_handler));
- StateChanged.connect (sigc::mem_fun (*this, &ArdourButton::state_handler));
+}
+
+ArdourButton::ArdourButton (const std::string& str, Element e)
+ : _elements (e)
+ , _act_on_release (true)
+ , _text_width (0)
+ , _text_height (0)
+ , _diameter (11.0)
+ , _corner_radius (9.0)
+ , edge_pattern (0)
+ , fill_pattern (0)
+ , led_inset_pattern (0)
+ , reflection_pattern (0)
+ , _led_left (false)
+ , _fixed_diameter (true)
+ , _distinct_led_click (false)
+ , _led_rect (0)
+{
+ set_text (str);
}
ArdourButton::~ArdourButton()
if (!_layout && !_text.empty()) {
_layout = Pango::Layout::create (get_pango_context());
}
-
- _layout->set_text (str);
+
+ if (_layout) {
+ _layout->set_text (str);
+ }
queue_resize ();
}
cairo_fill (cr);
}
+ if (_pixbuf) {
+
+ double x,y;
+ x = (_width - _pixbuf->get_width())/2.0;
+ y = (_height - _pixbuf->get_height())/2.0;
+
+ cairo_rectangle (cr, x, y, _pixbuf->get_width(), _pixbuf->get_height());
+ gdk_cairo_set_source_pixbuf (cr, _pixbuf->gobj(), x, y);
+ cairo_fill (cr);
+ }
+
/* text, if any */
int text_margin;
}
+
/* a partially transparent gray layer to indicate insensitivity */
- if ((visual_state() & Insensitive)) {
- cairo_rectangle (cr, 0, 0, _width, _height);
+ if ((visual_state() & Gtkmm2ext::Insensitive)) {
+ Gtkmm2ext::rounded_rectangle (cr, 0, 0, _width, _height, _corner_radius);
cairo_set_source_rgba (cr, 0.905, 0.917, 0.925, 0.5);
cairo_fill (cr);
}
}
-void
-ArdourButton::state_handler ()
-{
- set_colors ();
-}
-
void
ArdourButton::set_diameter (float d)
{
if (_elements & Edge) {
edge_pattern = cairo_pattern_create_linear (0.0, 0.0, 0.0, _height);
- if (visual_state() & CairoWidget::Selected) {
+ if (visual_state() & Gtkmm2ext::Selected) {
start_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1 border start selected", get_name()));
end_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1 border end selected", get_name()));
} else {
if (_elements & Body) {
fill_pattern = cairo_pattern_create_linear (0.0, 0.0, 0.0, _height);
- if (active_state() == Mid) {
+ if (active_state() == Gtkmm2ext::Mid) {
start_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1 fill start mid", get_name()));
end_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1 fill end mid", get_name()));
- } else if (active_state() == Active) {
+ } else if (active_state() == Gtkmm2ext::Active) {
start_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1 fill start active", get_name()));
end_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1 fill end active", get_name()));
} else {
/* text and LED colors depend on Active/Normal/Mid */
- if (active_state() == Active) {
+ if (active_state() == Gtkmm2ext::Active) {
text_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1 text active", get_name()));
led_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1 led active", get_name()));
- } else if (active_state() == Mid) {
+ } else if (active_state() == Gtkmm2ext::Mid) {
text_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1 text mid", get_name()));
- led_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1 led active", get_name()));
+ led_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1 led mid", get_name()));
} else {
text_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1 text", get_name()));
led_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1 led", get_name()));
bool
ArdourButton::on_button_press_event (GdkEventButton *ev)
{
- if ((_elements & Indicator) && _led_rect) {
+ if ((_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) {
return true;
bool
ArdourButton::on_button_release_event (GdkEventButton *ev)
{
- if ((_elements & Indicator) && _distinct_led_click) {
-
- /* if within LED, emit signal */
-
- float text_margin;
- int top = lrint (_height/2.0 - _diameter/2.0);
- int bottom = lrint (_height/2.0 + _diameter/2.0);
- int left;
- int right;
-
- if (_width < 75) {
- text_margin = 3;
- } else {
- text_margin = 10;
- }
-
- top = _height/2.0;
-
- if (_elements & Text) {
- if (_led_left) {
- left = text_margin;
- } else {
- left = _width - ((_diameter/2.0) + 4.0);
- }
- } else {
- left = _width/2.0 - _diameter/2.0;
- }
-
- right = left + _diameter;
-
- if (ev->x >= left && ev->x <= right && ev->y <= bottom && ev->y >= top) {
+ if ((_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) {
signal_led_clicked(); /* EMIT SIGNAL */
return true;
}
if (_act_on_release) {
if (_action) {
+ Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (_action);
_action->activate ();
return true;
}
float val = binding_proxy.get_controllable()->get_value();
if (fabs (val) >= 0.5f) {
- set_active_state (CairoWidget::Active);
+ set_active_state (Gtkmm2ext::Active);
} else {
unset_active_state ();
}
Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (_action);
if (tact) {
tact->signal_toggled().connect (sigc::mem_fun (*this, &ArdourButton::action_toggled));
- }
+ }
}
void
if (tact) {
if (tact->get_active()) {
- set_active_state (CairoWidget::Active);
+ set_active_state (Gtkmm2ext::Active);
} else {
unset_active_state ();
}
}
void
-ArdourButton::on_style_changed (const RefPtr<Style>&)
+ArdourButton::on_style_changed (const RefPtr<Gtk::Style>&)
{
set_colors ();
}
void
ArdourButton::setup_led_rect ()
{
+ int text_margin;
+
+ if (_width < 75) {
+ text_margin = 3;
+ } else {
+ text_margin = 10;
+ }
+
if (_elements & Indicator) {
_led_rect = new cairo_rectangle_t;
if (_elements & Text) {
if (_led_left) {
- _led_rect->x = 4;
+ _led_rect->x = text_margin;
} else {
- _led_rect->x = lrint (_width - 4 - _diameter/2.0);
+ _led_rect->x = _width - text_margin - _diameter/2.0;
}
} else {
- _led_rect->x = _width/2.0 - (_diameter/2.0);
+ /* centered */
+ _led_rect->x = _width/2.0 - _diameter/2.0;
}
_led_rect->y = _height/2.0 - _diameter/2.0;
}
}
+void
+ArdourButton::set_image (const RefPtr<Gdk::Pixbuf>& img)
+{
+ _pixbuf = img;
+ queue_draw ();
+}
+
+void
+ArdourButton::set_active_state (Gtkmm2ext::ActiveState s)
+{
+ bool changed = (_active_state != s);
+ CairoWidget::set_active_state (s);
+ if (changed) {
+ set_colors ();
+ }
+}
+
+void
+ArdourButton::set_visual_state (Gtkmm2ext::VisualState s)
+{
+ bool changed = (_visual_state != s);
+ CairoWidget::set_visual_state (s);
+ if (changed) {
+ set_colors ();
+ }
+}
+