add the ability to use cairo scaling to warp the rendering of the main clock text
authorPaul Davis <paul@linuxaudiosystems.com>
Wed, 31 Dec 2014 11:52:47 +0000 (06:52 -0500)
committerPaul Davis <paul@linuxaudiosystems.com>
Wed, 31 Dec 2014 12:20:48 +0000 (07:20 -0500)
gtk2_ardour/audio_clock.cc
gtk2_ardour/audio_clock.h

index 4eb8a2e8aa0040a0e2e2a2055b54a3a1cba5f56d..ae170b8548f3cabcbed7d5be08a402873aec460c 100644 (file)
@@ -95,6 +95,8 @@ AudioClock::AudioClock (const string& clock_name, bool transient, const string&
        , last_sdelta (0)
        , dragging (false)
        , drag_field (Field (0))
+       , xscale (1.0)
+       , yscale (1.0)
 {
        set_flags (CAN_FOCUS);
 
@@ -277,6 +279,15 @@ AudioClock::set_colors ()
        queue_draw ();
 }
 
+void
+AudioClock::set_scale (double x, double y)
+{
+       xscale = x;
+       yscale = y;
+
+       queue_draw ();
+}
+
 void
 AudioClock::render (cairo_t* cr, cairo_rectangle_t*)
 {
@@ -296,10 +307,22 @@ AudioClock::render (cairo_t* cr, cairo_rectangle_t*)
                cairo_fill (cr);
        }
 
-       cairo_move_to (cr, (get_width() - layout_width) / 2.0, (upper_height - layout_height) / 2.0);
+       double lw = layout_width * xscale;
+       double lh = layout_height * yscale;
 
+       cairo_move_to (cr, (get_width() - lw) / 2.0, (upper_height - lh) / 2.0);
+
+       if (xscale != 1.0 || yscale != 1.0) {
+               cairo_save (cr);
+               cairo_scale (cr, xscale, yscale);
+       }
+       
        pango_cairo_show_layout (cr, _layout->gobj());
 
+       if (xscale != 1.0 || yscale != 1.0) {
+               cairo_restore (cr);
+       }
+
        if (_left_layout) {
 
                double h = get_height() - upper_height - separator_height;
index 259e3300005993984ee7cb282b3ea56da292285c..83bc3233c227e1cf37e101b9c8715c2b577a91b8 100644 (file)
@@ -77,6 +77,14 @@ class AudioClock : public CairoWidget, public ARDOUR::SessionHandlePtr
        void set_session (ARDOUR::Session *s);
         void set_negative_allowed (bool yn); 
 
+       /** Alter cairo scaling during rendering. 
+        *
+        * Used by clocks that resize themselves
+        * to fit any given space. Can lead
+        * to font distortion.
+        */
+       void set_scale (double x, double y);
+       
        static void print_minsec (framepos_t, char* buf, size_t bufsize, float frame_rate);
 
        sigc::signal<void> ValueChanged;
@@ -232,6 +240,9 @@ class AudioClock : public CairoWidget, public ARDOUR::SessionHandlePtr
 
        double bg_r, bg_g, bg_b, bg_a;
        double cursor_r, cursor_g, cursor_b, cursor_a;
+
+       double xscale;
+       double yscale;
 };
 
 #endif /* __audio_clock_h__ */