Tweak output formatting of save_all_bindings_as_html
[ardour.git] / libs / gtkmm2ext / pixfader.cc
index d46f1226b07a9cc3c9e2729af0cdc76e743d6f44..64ee449646e5f310d824258bccd61a29d6150933 100644 (file)
@@ -53,7 +53,6 @@ PixFader::PixFader (Gtk::Adjustment& adj, int orientation, int fader_length, int
        , _orien (orientation)
        , _pattern (0)
        , _hovering (false)
-       , _last_drawn (-1)
        , _dragging (false)
        , _centered_text (true)
        , _current_parent (0)
@@ -72,7 +71,7 @@ PixFader::PixFader (Gtk::Adjustment& adj, int orientation, int fader_length, int
 
        _adjustment.signal_value_changed().connect (mem_fun (*this, &PixFader::adjustment_changed));
        _adjustment.signal_changed().connect (mem_fun (*this, &PixFader::adjustment_changed));
-
+       signal_grab_broken_event ().connect (mem_fun (*this, &PixFader::on_grab_broken_event));
        if (_orien == VERT) {
                CairoWidget::set_size_request(_girth, _span);
        } else {
@@ -86,6 +85,15 @@ PixFader::~PixFader ()
        if (_layout) _layout.clear (); // drop reference to existing layout
 }
 
+void
+PixFader::flush_pattern_cache () {
+       for (list<FaderImage*>::iterator f = _patterns.begin(); f != _patterns.end(); ++f) {
+               cairo_pattern_destroy ((*f)->pattern);
+       }
+       _patterns.clear();
+}
+
+
 cairo_pattern_t*
 PixFader::find_pattern (double afr, double afg, double afb,
                        double abr, double abg, double abb,
@@ -326,13 +334,11 @@ PixFader::render (cairo_t *cr, cairo_rectangle_t* area)
                Gtkmm2ext::rounded_rectangle (cr, CORNER_OFFSET, CORNER_OFFSET, w-CORNER_SIZE, h-CORNER_SIZE, CORNER_RADIUS);
                cairo_set_source_rgba (cr, 0.505, 0.517, 0.525, 0.4);
                cairo_fill (cr);
-       } else if (_hovering) {
+       } else if (_hovering && CairoWidget::widget_prelight()) {
                Gtkmm2ext::rounded_rectangle (cr, CORNER_OFFSET, CORNER_OFFSET, w-CORNER_SIZE, h-CORNER_SIZE, CORNER_RADIUS);
                cairo_set_source_rgba (cr, 0.905, 0.917, 0.925, 0.1);
                cairo_fill (cr);
        }
-
-       _last_drawn = ds;
 }
 
 void
@@ -350,6 +356,9 @@ PixFader::on_size_request (GtkRequisition* req)
 void
 PixFader::on_size_allocate (Gtk::Allocation& alloc)
 {
+       int old_girth = _girth;
+       int old_span = _span;
+
        CairoWidget::on_size_allocate(alloc);
 
        if (_orien == VERT) {
@@ -360,7 +369,7 @@ PixFader::on_size_allocate (Gtk::Allocation& alloc)
                _span = alloc.get_width ();
        }
 
-       if (is_realized()) {
+       if (is_realized() && ((old_girth != _girth) || (old_span != _span))) {
                /* recreate patterns in case we've changed size */
                create_patterns ();
        }
@@ -368,6 +377,18 @@ PixFader::on_size_allocate (Gtk::Allocation& alloc)
        update_unity_position ();
 }
 
+bool
+PixFader::on_grab_broken_event (GdkEventGrabBroken* ev)
+{
+       if (_dragging) {
+               remove_modal_grab();
+               _dragging = false;
+               gdk_pointer_ungrab (GDK_CURRENT_TIME);
+               StopGesture ();
+       }
+       return (_tweaks & NoButtonForward) ? true : false;
+}
+
 bool
 PixFader::on_button_press_event (GdkEventButton* ev)
 {
@@ -424,7 +445,6 @@ PixFader::on_button_release_event (GdkEventButton* ev)
 
                        if (ev_pos == _grab_start) {
                                /* no motion - just a click */
-                               const double slider_pos =  display_span();
                                ev_pos = rint(ev_pos);
 
                                if (ev->state & Keyboard::TertiaryModifier) {
@@ -562,9 +582,7 @@ PixFader::on_motion_notify_event (GdkEventMotion* ev)
 void
 PixFader::adjustment_changed ()
 {
-       if (display_span() != _last_drawn) {
-               queue_draw ();
-       }
+       queue_draw ();
 }
 
 /** @return pixel offset of the current value from the right or bottom of the fader */
@@ -694,7 +712,7 @@ PixFader::on_style_changed (const Glib::RefPtr<Gtk::Style>&)
                _text = "";
                set_text (txt, _centered_text, false);
        }
-       /* patterns are cached and re-created as needed 
+       /* patterns are cached and re-created as needed
         * during 'expose' in the GUI thread */
        _pattern = 0;
        queue_draw ();