mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-06 14:54:56 +01:00
add hovering/show click functionality to ArdourButton
git-svn-id: svn://localhost/ardour2/branches/3.0@10478 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
parent
b21819b9ee
commit
cccc71e011
2 changed files with 84 additions and 5 deletions
|
|
@ -50,6 +50,7 @@ ArdourButton::Element ArdourButton::just_led_default_elements = ArdourButton::El
|
||||||
|
|
||||||
ArdourButton::ArdourButton (Element e)
|
ArdourButton::ArdourButton (Element e)
|
||||||
: _elements (e)
|
: _elements (e)
|
||||||
|
, _tweaks (Tweaks (0))
|
||||||
, _act_on_release (true)
|
, _act_on_release (true)
|
||||||
, _text_width (0)
|
, _text_width (0)
|
||||||
, _text_height (0)
|
, _text_height (0)
|
||||||
|
|
@ -63,6 +64,7 @@ ArdourButton::ArdourButton (Element e)
|
||||||
, _fixed_diameter (true)
|
, _fixed_diameter (true)
|
||||||
, _distinct_led_click (false)
|
, _distinct_led_click (false)
|
||||||
, _led_rect (0)
|
, _led_rect (0)
|
||||||
|
, _hovering (false)
|
||||||
{
|
{
|
||||||
ColorsChanged.connect (sigc::mem_fun (*this, &ArdourButton::color_handler));
|
ColorsChanged.connect (sigc::mem_fun (*this, &ArdourButton::color_handler));
|
||||||
}
|
}
|
||||||
|
|
@ -241,6 +243,16 @@ ArdourButton::render (cairo_t* cr)
|
||||||
cairo_set_source_rgba (cr, 0.905, 0.917, 0.925, 0.5);
|
cairo_set_source_rgba (cr, 0.905, 0.917, 0.925, 0.5);
|
||||||
cairo_fill (cr);
|
cairo_fill (cr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* if requested, show hovering */
|
||||||
|
|
||||||
|
if ((_tweaks & ShowHover)) {
|
||||||
|
if (_hovering) {
|
||||||
|
Gtkmm2ext::rounded_rectangle (cr, 0, 0, _width, _height, _corner_radius);
|
||||||
|
cairo_set_source_rgba (cr, 0.905, 0.917, 0.925, 0.2);
|
||||||
|
cairo_fill (cr);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
@ -282,12 +294,26 @@ ArdourButton::on_size_request (Gtk::Requisition* req)
|
||||||
_text_height = 0;
|
_text_height = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_pixbuf) {
|
||||||
|
xpad = 6;
|
||||||
|
}
|
||||||
|
|
||||||
if ((_elements & Indicator) && _fixed_diameter) {
|
if ((_elements & Indicator) && _fixed_diameter) {
|
||||||
req->width = _text_width + lrint (_diameter) + xpad;
|
if (_pixbuf) {
|
||||||
req->height = max (_text_height, (int) lrint (_diameter)) + ypad;
|
req->width = _pixbuf->get_width() + lrint (_diameter) + xpad;
|
||||||
|
req->height = max (_pixbuf->get_height(), (int) lrint (_diameter)) + ypad;
|
||||||
|
} else {
|
||||||
|
req->width = _text_width + lrint (_diameter) + xpad;
|
||||||
|
req->height = max (_text_height, (int) lrint (_diameter)) + ypad;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
req->width = _text_width + xpad;
|
if (_pixbuf) {
|
||||||
req->height = _text_height + ypad;
|
req->width = _pixbuf->get_width() + xpad;
|
||||||
|
req->height = _pixbuf->get_height() + ypad;
|
||||||
|
} else {
|
||||||
|
req->width = _text_width + xpad;
|
||||||
|
req->height = _text_height + ypad;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -412,6 +438,10 @@ ArdourButton::on_button_press_event (GdkEventButton *ev)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_tweaks & ShowClick) {
|
||||||
|
set_active_state (Gtkmm2ext::Active);
|
||||||
|
}
|
||||||
|
|
||||||
if (binding_proxy.button_press_handler (ev)) {
|
if (binding_proxy.button_press_handler (ev)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -437,6 +467,10 @@ ArdourButton::on_button_release_event (GdkEventButton *ev)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_tweaks & ShowClick) {
|
||||||
|
unset_active_state ();
|
||||||
|
}
|
||||||
|
|
||||||
if (_act_on_release) {
|
if (_act_on_release) {
|
||||||
if (_action) {
|
if (_action) {
|
||||||
Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (_action);
|
Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic (_action);
|
||||||
|
|
@ -595,3 +629,35 @@ ArdourButton::set_visual_state (Gtkmm2ext::VisualState s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
ArdourButton::on_enter_notify_event (GdkEventCrossing* ev)
|
||||||
|
{
|
||||||
|
_hovering = true;
|
||||||
|
|
||||||
|
if (_tweaks & ShowHover) {
|
||||||
|
queue_draw ();
|
||||||
|
}
|
||||||
|
|
||||||
|
return CairoWidget::on_enter_notify_event (ev);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
ArdourButton::on_leave_notify_event (GdkEventCrossing* ev)
|
||||||
|
{
|
||||||
|
_hovering = false;
|
||||||
|
|
||||||
|
if (_tweaks & ShowHover) {
|
||||||
|
queue_draw ();
|
||||||
|
}
|
||||||
|
|
||||||
|
return CairoWidget::on_leave_notify_event (ev);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ArdourButton::set_tweaks (Tweaks t)
|
||||||
|
{
|
||||||
|
if (_tweaks != t) {
|
||||||
|
_tweaks = t;
|
||||||
|
queue_draw ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ class ArdourButton : public CairoWidget
|
||||||
Text = 0x4,
|
Text = 0x4,
|
||||||
Indicator = 0x8,
|
Indicator = 0x8,
|
||||||
};
|
};
|
||||||
|
|
||||||
static Element default_elements;
|
static Element default_elements;
|
||||||
static Element led_default_elements;
|
static Element led_default_elements;
|
||||||
static Element just_led_default_elements;
|
static Element just_led_default_elements;
|
||||||
|
|
@ -48,6 +48,15 @@ class ArdourButton : public CairoWidget
|
||||||
ArdourButton (const std::string&, Element e = default_elements);
|
ArdourButton (const std::string&, Element e = default_elements);
|
||||||
virtual ~ArdourButton ();
|
virtual ~ArdourButton ();
|
||||||
|
|
||||||
|
enum Tweaks {
|
||||||
|
ShowClick = 0x1,
|
||||||
|
ShowHover = 0x2,
|
||||||
|
NoModel = 0x4,
|
||||||
|
};
|
||||||
|
|
||||||
|
Tweaks tweaks() const { return _tweaks; }
|
||||||
|
void set_tweaks (Tweaks);
|
||||||
|
|
||||||
void set_active_state (Gtkmm2ext::ActiveState);
|
void set_active_state (Gtkmm2ext::ActiveState);
|
||||||
void set_visual_state (Gtkmm2ext::VisualState);
|
void set_visual_state (Gtkmm2ext::VisualState);
|
||||||
|
|
||||||
|
|
@ -81,6 +90,8 @@ class ArdourButton : public CairoWidget
|
||||||
void on_size_request (Gtk::Requisition* req);
|
void on_size_request (Gtk::Requisition* req);
|
||||||
void on_size_allocate (Gtk::Allocation&);
|
void on_size_allocate (Gtk::Allocation&);
|
||||||
void on_style_changed (const Glib::RefPtr<Gtk::Style>&);
|
void on_style_changed (const Glib::RefPtr<Gtk::Style>&);
|
||||||
|
bool on_enter_notify_event (GdkEventCrossing*);
|
||||||
|
bool on_leave_notify_event (GdkEventCrossing*);
|
||||||
|
|
||||||
void controllable_changed ();
|
void controllable_changed ();
|
||||||
PBD::ScopedConnection watch_connection;
|
PBD::ScopedConnection watch_connection;
|
||||||
|
|
@ -90,6 +101,7 @@ class ArdourButton : public CairoWidget
|
||||||
Glib::RefPtr<Gdk::Pixbuf> _pixbuf;
|
Glib::RefPtr<Gdk::Pixbuf> _pixbuf;
|
||||||
std::string _text;
|
std::string _text;
|
||||||
Element _elements;
|
Element _elements;
|
||||||
|
Tweaks _tweaks;
|
||||||
BindingProxy binding_proxy;
|
BindingProxy binding_proxy;
|
||||||
bool _act_on_release;
|
bool _act_on_release;
|
||||||
|
|
||||||
|
|
@ -117,6 +129,7 @@ class ArdourButton : public CairoWidget
|
||||||
bool _fixed_diameter;
|
bool _fixed_diameter;
|
||||||
bool _distinct_led_click;
|
bool _distinct_led_click;
|
||||||
cairo_rectangle_t* _led_rect;
|
cairo_rectangle_t* _led_rect;
|
||||||
|
bool _hovering;
|
||||||
|
|
||||||
void setup_led_rect ();
|
void setup_led_rect ();
|
||||||
void set_colors ();
|
void set_colors ();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue