mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-07 15:25:01 +01:00
MetaButton: handle boxy theme, separate active state from menu index
This commit is contained in:
parent
7bb4ae2cb8
commit
0516c12694
1 changed files with 24 additions and 25 deletions
|
|
@ -78,11 +78,9 @@ MetaButton::on_button_press_event (GdkEventButton* ev)
|
|||
|
||||
if (ev->type == GDK_BUTTON_PRESS && ev->button == 3) {
|
||||
Gtkmm2ext::anchored_menu_popup (&_menu, this, current_active ? current_active->menutext () : "", ev->button, ev->time);
|
||||
}
|
||||
else if (ev->type == GDK_BUTTON_PRESS && ev->button == 1 && ev->x > (get_width () - _diameter - 7)) {
|
||||
} else if (ev->type == GDK_BUTTON_PRESS && ev->button == 1 && ev->x > (get_width () - _diameter - 7)) {
|
||||
Gtkmm2ext::anchored_menu_popup (&_menu, this, current_active ? current_active->menutext () : "", ev->button, ev->time);
|
||||
}
|
||||
else if (ev->type == GDK_BUTTON_PRESS && ev->button == 1) {
|
||||
} else if (ev->type == GDK_BUTTON_PRESS && ev->button == 1) {
|
||||
if (current_active) {
|
||||
current_active->activate ();
|
||||
}
|
||||
|
|
@ -107,6 +105,14 @@ MetaButton::activate_item (MetaMenuItem const* e)
|
|||
{
|
||||
update_button (e);
|
||||
e->activate ();
|
||||
|
||||
_active = 0;
|
||||
for (auto& i : _menu.items ()) {
|
||||
if (e == dynamic_cast<MetaMenuItem*> (&i)) {
|
||||
break;
|
||||
}
|
||||
++_active;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -118,26 +124,16 @@ MetaButton::update_button (MetaMenuItem const* e)
|
|||
void
|
||||
MetaButton::set_active (std::string const& menulabel)
|
||||
{
|
||||
guint c = 0;
|
||||
bool found = false;
|
||||
|
||||
for (auto& i : _menu.items ()) {
|
||||
if (i.get_label () == menulabel) {
|
||||
if (_menu.get_active () != &i) {
|
||||
_menu.set_active (c);
|
||||
}
|
||||
update_button (dynamic_cast<MetaMenuItem*> (&i));
|
||||
set_active_state (Gtkmm2ext::ExplicitActive);
|
||||
_active = c;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
++c;
|
||||
MetaMenuItem const* current_active = dynamic_cast<MetaMenuItem*> (_menu.get_active ());
|
||||
if (!current_active) {
|
||||
set_active_state (Gtkmm2ext::Off);
|
||||
return;
|
||||
}
|
||||
if (!found) {
|
||||
if (current_active->menutext () == menulabel) {
|
||||
set_active_state (Gtkmm2ext::ExplicitActive);
|
||||
} else {
|
||||
set_active_state (Gtkmm2ext::Off);
|
||||
}
|
||||
StateChanged (); /* EMIT SIGNAL */
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -147,6 +143,7 @@ MetaButton::set_index (guint index)
|
|||
for (auto& i : _menu.items ()) {
|
||||
if (c == index) {
|
||||
_menu.set_active (c);
|
||||
_active = c;
|
||||
update_button (dynamic_cast<MetaMenuItem*> (&i));
|
||||
break;
|
||||
}
|
||||
|
|
@ -161,12 +158,14 @@ MetaButton::render (Cairo::RefPtr<Cairo::Context> const& ctx, cairo_rectangle_t*
|
|||
PBD::Unwinder uw (_hovering, false);
|
||||
ArdourButton::render (ctx, rect);
|
||||
}
|
||||
if (_hovering && UIConfigurationBase::instance().get_widget_prelight()) {
|
||||
cairo_t* cr = ctx->cobj();
|
||||
if (_hovering && UIConfigurationBase::instance ().get_widget_prelight ()) {
|
||||
const bool boxy = (_tweaks & ForceBoxy) | boxy_buttons ();
|
||||
const float corner_radius = boxy ? 0 : std::max (2.f, _corner_radius * UIConfigurationBase::instance ().get_ui_scale ());
|
||||
cairo_t* cr = ctx->cobj ();
|
||||
if (_hover_dropdown) {
|
||||
Gtkmm2ext::rounded_right_half_rectangle (cr, get_width () - _diameter - 6, 1, _diameter + 5, get_height() - 2, _corner_radius);
|
||||
Gtkmm2ext::rounded_right_half_rectangle (cr, get_width () - _diameter - 6, 1, _diameter + 5, get_height () - 2, corner_radius);
|
||||
} else {
|
||||
Gtkmm2ext::rounded_left_half_rectangle (cr, 1, 1, get_width() -_diameter - 7 , get_height() - 2, _corner_radius);
|
||||
Gtkmm2ext::rounded_left_half_rectangle (cr, 1, 1, get_width () - _diameter - 7, get_height () - 2, corner_radius);
|
||||
}
|
||||
cairo_set_source_rgba (cr, 0.905, 0.917, 0.925, 0.2);
|
||||
cairo_fill (cr);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue