allow addition of images to ArdourButtons (always centered)
authorPaul Davis <paul@linuxaudiosystems.com>
Wed, 2 Nov 2011 18:47:14 +0000 (18:47 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Wed, 2 Nov 2011 18:47:14 +0000 (18:47 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@10399 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/ardour_button.cc
gtk2_ardour/ardour_button.h

index 2bc73398aee9b9b9b82e8c84c47bb549c773999d..24f678e5c5b92c0a22fa77e130cbb62db7f8c220 100644 (file)
@@ -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<Gdk::Pixbuf>& img)
+{
+       _pixbuf = img;
+       queue_draw ();
+}
index 4732eec5099fb054fb2c68a478ad24086e59c382..72614b2b8e98845ada97a83dbeee1a71dbc0b93f 100644 (file)
@@ -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<Gdk::Pixbuf>&);
+
   protected:
        void render (cairo_t *);
        void on_size_request (Gtk::Requisition* req);
@@ -81,6 +82,7 @@ class ArdourButton : public CairoWidget
 
   private:
        Glib::RefPtr<Pango::Layout> _layout;
+       Glib::RefPtr<Gdk::Pixbuf>   _pixbuf;
        std::string                 _text;
        Element                     _elements;
        BindingProxy binding_proxy;