From: Paul Davis Date: Wed, 2 Nov 2011 18:47:14 +0000 (+0000) Subject: allow addition of images to ArdourButtons (always centered) X-Git-Tag: 3.0-beta1~185 X-Git-Url: https://git.carlh.net/gitweb/?a=commitdiff_plain;h=0cc9daed289a96a82171335660304a3cdc6f42c6;p=ardour.git allow addition of images to ArdourButtons (always centered) git-svn-id: svn://localhost/ardour2/branches/3.0@10399 d708f5d6-7413-0410-9779-e7cbd77b26cf --- diff --git a/gtk2_ardour/ardour_button.cc b/gtk2_ardour/ardour_button.cc index 2bc73398ae..24f678e5c5 100644 --- a/gtk2_ardour/ardour_button.cc +++ b/gtk2_ardour/ardour_button.cc @@ -133,6 +133,17 @@ ArdourButton::render (cairo_t* cr) 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; @@ -202,10 +213,11 @@ ArdourButton::render (cairo_t* cr) } + /* a partially transparent gray layer to indicate insensitivity */ if ((visual_state() & Gtkmm2ext::Insensitive)) { - cairo_rectangle (cr, 0, 0, _width, _height); + 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); } @@ -541,3 +553,9 @@ ArdourButton::setup_led_rect () } } +void +ArdourButton::set_image (const RefPtr& img) +{ + _pixbuf = img; + queue_draw (); +} diff --git a/gtk2_ardour/ardour_button.h b/gtk2_ardour/ardour_button.h index 4732eec509..72614b2b8e 100644 --- a/gtk2_ardour/ardour_button.h +++ b/gtk2_ardour/ardour_button.h @@ -37,7 +37,6 @@ class ArdourButton : public CairoWidget Body = 0x2, Text = 0x4, Indicator = 0x8, - Image = 0x16 }; static Element default_elements; @@ -70,6 +69,8 @@ class ArdourButton : public CairoWidget bool on_button_press_event (GdkEventButton*); bool on_button_release_event (GdkEventButton*); + void set_image (const Glib::RefPtr&); + protected: void render (cairo_t *); void on_size_request (Gtk::Requisition* req); @@ -81,6 +82,7 @@ class ArdourButton : public CairoWidget private: Glib::RefPtr _layout; + Glib::RefPtr _pixbuf; std::string _text; Element _elements; BindingProxy binding_proxy;