pending-peaks: checker pattern.
authorRobin Gareus <robin@gareus.org>
Tue, 15 Sep 2015 00:28:24 +0000 (02:28 +0200)
committerRobin Gareus <robin@gareus.org>
Tue, 15 Sep 2015 00:28:24 +0000 (02:28 +0200)
gtk2_ardour/audio_region_view.cc

index 6ff4ff80dcf3fc383afda24bdea9be34b588d842..fef4868dc8c8351a1ba0bb3b00e5b8d6e9ca5f5f 100644 (file)
@@ -76,6 +76,34 @@ static double const handle_size = 10; /* height of fade handles */
 
 Cairo::RefPtr<Cairo::Pattern> AudioRegionView::pending_peak_pattern;
 
+static Cairo::RefPtr<Cairo::Pattern> create_pending_peak_pattern() {
+       cairo_surface_t * is = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 8, 8);
+
+       // create checker pattern
+       unsigned char *img = cairo_image_surface_get_data (is);
+       cairo_surface_flush (is);
+       const int stride = cairo_image_surface_get_stride (is);
+
+       for (int y = 0; y < 8; ++y) {
+               for (int x = 0; x < 8; ++x) {
+                       const int off = (y * stride + x * 4);
+                       uint32_t *pixel = (uint32_t*) &img[off];
+                       if ((x < 4) ^ (y < 4)) {
+                               *pixel = 0xa0000000;
+                       } else {
+                               *pixel = 0x40000000;
+                       }
+               }
+       }
+       cairo_surface_mark_dirty (is);
+
+       cairo_pattern_t* pat = cairo_pattern_create_for_surface (is);
+       cairo_pattern_set_extend (pat, CAIRO_EXTEND_REPEAT);
+       Cairo::RefPtr<Cairo::Pattern> p (new Cairo::Pattern (pat, false));
+       cairo_surface_destroy (is);
+       return p;
+}
+
 AudioRegionView::AudioRegionView (ArdourCanvas::Container *parent, RouteTimeAxisView &tv, boost::shared_ptr<AudioRegion> r, double spu,
                                  uint32_t basic_color)
        : RegionView (parent, tv, r, spu, basic_color)
@@ -149,12 +177,7 @@ AudioRegionView::init (bool wfd)
        // where order is important and where it isn't...
 
        if (!pending_peak_pattern) {
-               cairo_pattern_t* pat = cairo_pattern_create_radial (4.0, 4.0, 1.0, 4.0, 4.0, 4.0);      
-               cairo_pattern_add_color_stop_rgba (pat, 0.0, 0, 0, 0, 1.0);
-               cairo_pattern_add_color_stop_rgba (pat, 0.6, 0, 0, 0, 0.0);
-               cairo_pattern_set_extend (pat, CAIRO_EXTEND_REPEAT);
-               Cairo::RefPtr<Cairo::Pattern> p (new Cairo::Pattern (pat, false));
-               pending_peak_pattern = p;
+               pending_peak_pattern = create_pending_peak_pattern();
        }
 
        // needs to be created first, RegionView::init() calls set_height()