update waves' fader implementation, clean up whitespace, indentation, variable initia...
authorPaul Davis <paul@linuxaudiosystems.com>
Thu, 18 Jun 2015 12:16:43 +0000 (08:16 -0400)
committerPaul Davis <paul@linuxaudiosystems.com>
Mon, 29 Jun 2015 18:18:15 +0000 (14:18 -0400)
libs/gtkmm2ext/fader.cc
libs/gtkmm2ext/gtkmm2ext/fader.h

index 7e1384b24047429337519537531269b8bdb10a4d..456856e5f8086e5d982780ba7972833e91b1c573 100755 (executable)
@@ -155,6 +155,28 @@ Fader::~Fader ()
        }
 }
 
+void
+Fader::get_image_scales (double &x_scale, double &y_scale)
+{
+       int pbwidth = _face_pixbuf->get_width ();
+       int pbheight = _face_pixbuf->get_height ();
+       int width = get_width ();
+       int height = get_height ();
+       
+       if ((width != pbwidth) || (height != pbheight)) {
+               x_scale = double (width) / double (pbwidth);
+               if (x_scale == 0.0) {
+                       x_scale = 1.0;
+               }
+               y_scale = double (height) / double (pbheight);
+               if (y_scale == 0.0) {
+                       y_scale = 1.0;
+               }
+       } else {
+               x_scale = y_scale = 1.0;
+       }
+}
+
 void
 Fader::set_touch_cursor (const Glib::RefPtr<Gdk::Pixbuf>& touch_cursor)
 {
@@ -164,39 +186,41 @@ Fader::set_touch_cursor (const Glib::RefPtr<Gdk::Pixbuf>& touch_cursor)
 void
 Fader::render (cairo_t* cr, cairo_rectangle_t*)
 {
+       
+       double xscale = 1.0;
+       double yscale = 1.0;
+       
+       get_image_scales (xscale, yscale);
+       
+       cairo_matrix_t matrix;
+       cairo_get_matrix (cr, &matrix);
+       cairo_matrix_scale (&matrix, xscale, yscale);
+       cairo_set_matrix (cr, &matrix);
+       
        get_handle_position (_last_drawn_x, _last_drawn_y);
 
        if (_underlay_pixbuf != 0) {
-               cairo_rectangle (cr, 0, 0, get_width(), get_height());
                gdk_cairo_set_source_pixbuf (cr,
                                             _underlay_pixbuf->gobj(),
-                                            _last_drawn_x - (int)(_underlay_pixbuf->get_width()/2.0 + 0.5),
-                                            _last_drawn_y - (int)(_underlay_pixbuf->get_height()/2.0 + 0.5));
-               cairo_fill (cr);
+                                            (_last_drawn_x - (int)((_underlay_pixbuf->get_width() * xscale) / 2.0 + 0.5)) / xscale,
+                                            (_last_drawn_y - (int)((_underlay_pixbuf->get_height() * yscale) / 2.0 + 0.5)) / yscale);
+               cairo_paint (cr);
        }
 
-       cairo_rectangle (cr, 0, 0, get_width(), get_height());
-       gdk_cairo_set_source_pixbuf (cr, 
+       gdk_cairo_set_source_pixbuf (cr,
                                     ((get_state () == Gtk::STATE_ACTIVE) && (_active_face_pixbuf != 0)) ? 
                                     _active_face_pixbuf->gobj() : 
                                     _face_pixbuf->gobj(),
                                     0,
                                     0);
-       cairo_fill (cr);
-
-       cairo_rectangle (cr, 0, 0, get_width(), get_height());
-       if (_dragging) {
-               gdk_cairo_set_source_pixbuf (cr,
-                                            _active_handle_pixbuf->gobj(),
-                                            _last_drawn_x - (int)(_active_handle_pixbuf->get_width()/2.0 + 0.5),
-                                            _last_drawn_y - (int)(_active_handle_pixbuf->get_height()/2.0 + 0.5));
-       } else {
-               gdk_cairo_set_source_pixbuf (cr,
-                                            _handle_pixbuf->gobj(),
-                                            _last_drawn_x - (int)(_handle_pixbuf->get_width()/2.0 + 0.5),
-                                            _last_drawn_y - (int)(_handle_pixbuf->get_height()/2.0 + 0.5));
-       }
-       cairo_fill (cr);
+       cairo_paint (cr);
+
+       const Glib::RefPtr<Gdk::Pixbuf> handle_pixbuf (_dragging ? _active_handle_pixbuf : _handle_pixbuf);
+       gdk_cairo_set_source_pixbuf (cr,
+                                    handle_pixbuf->gobj(),
+                                    (_last_drawn_x - (int)((handle_pixbuf->get_width() * xscale) / 2.0 + 0.5)) / xscale,
+                                    (_last_drawn_y - (int)((handle_pixbuf->get_height() * yscale) / 2.0 + 0.5)) / yscale);
+       cairo_paint (cr);
 }
 
 void
@@ -238,8 +262,13 @@ Fader::on_button_press_event (GdkEventButton* ev)
        _grab_start_mouse_y = ev->y;
        get_handle_position (_grab_start_handle_x, _grab_start_handle_y);
 
-       double hw = _handle_pixbuf->get_width();
-       double hh = _handle_pixbuf->get_height();
+       double xscale = 1.0;
+       double yscale = 1.0;
+       
+       get_image_scales (xscale, yscale);
+       
+       double hw = _handle_pixbuf->get_width() * xscale;
+       double hh = _handle_pixbuf->get_height() * yscale;
 
        if ((ev->x < (_grab_start_handle_x - hw/2)) || (ev->x > (_grab_start_handle_x + hw/2)) || (ev->y < (_grab_start_handle_y - hh/2)) || (ev->y > (_grab_start_handle_y + hh/2))) {
                return false;
index 4af3a3b8bdd380630592050dbb1bb9877eb82a41..84175d59421165085834c08f7c6b8bfaba470a89 100755 (executable)
@@ -54,6 +54,7 @@ class LIBGTKMM2EXT_API Fader : public CairoWidget
        void set_controllable (boost::shared_ptr<PBD::Controllable> c) { binding_proxy.set_controllable (c); }
        void set_default_value (float);
        void set_touch_cursor (const Glib::RefPtr<Gdk::Pixbuf>& touch_cursor);
+       void get_image_scales (double &x_scale, double &y_scale);
 
   protected:
        void get_handle_position (double& x, double& y);
@@ -74,6 +75,7 @@ class LIBGTKMM2EXT_API Fader : public CairoWidget
        BindingProxy binding_proxy;
 
   private:
+
        const Glib::RefPtr<Gdk::Pixbuf> _face_pixbuf;
        const Glib::RefPtr<Gdk::Pixbuf> _active_face_pixbuf;
        const Glib::RefPtr<Gdk::Pixbuf> _underlay_pixbuf;
@@ -83,9 +85,12 @@ class LIBGTKMM2EXT_API Fader : public CairoWidget
        int _min_pos_y;
        int _max_pos_x;
        int _max_pos_y;
+
        bool _hovering;
+
        GdkWindow* _grab_window;
        Gdk::Cursor *_touch_cursor;
+
        double _grab_start_mouse_x;
        double _grab_start_mouse_y;
        double _grab_start_handle_x;