make all meter-colors configurable,..
[ardour.git] / libs / gtkmm2ext / gtkmm2ext / fastmeter.h
index 87cfd0b836f38cd42350513e08fb6d02da5681dd..ac81f461511c0446fad5fa7f6973c955c53f5535 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2003 Paul Davis 
+    Copyright (C) 2003 Paul Davis
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-    $Id$
 */
 
 #ifndef __gtkmm2ext_fastmeter_h__
 #define __gtkmm2ext_fastmeter_h__
 
+#include <map>
+#include <boost/tuple/tuple.hpp>
+#include <boost/tuple/tuple_comparison.hpp>
+#include <cairomm/pattern.h>
 #include <gtkmm/drawingarea.h>
-#include <gdkmm/pixmap.h>
+#include <gdkmm/pixbuf.h>
 
 namespace Gtkmm2ext {
 
 class FastMeter : public Gtk::DrawingArea {
   public:
-       enum Orientation { 
+       enum Orientation {
                Horizontal,
                Vertical
        };
-       
-       FastMeter (long hold_cnt, unsigned long width, Orientation);
+
+       FastMeter (long hold_cnt, unsigned long width, Orientation, int len=0,
+                       int clr0=0x008800ff, int clr1=0x008800ff,
+                       int clr2=0x00ff00ff, int clr3=0x00ff00ff,
+                       int clr4=0xffaa00ff, int clr5=0xffaa00ff,
+                       int clr6=0xffff00ff, int clr7=0xffff00ff,
+                       int clr8=0xff0000ff, int clr9=0xff0000ff,
+                       int bgc0=0x333333ff, int bgc1=0x444444ff,
+                       float stp0 = 55.0, // log_meter(-18);
+                       float stp1 = 77.5, // log_meter(-9);
+                       float stp2 = 92.5, // log_meter(-3); // 95.0, // log_meter(-2);
+                       float stp3 = 100.0
+                       );
        virtual ~FastMeter ();
-       
-       void set (float level, float user_level=0.0f);
+
+       void set (float level);
        void clear ();
 
        float get_level() { return current_level; }
@@ -45,31 +59,26 @@ class FastMeter : public Gtk::DrawingArea {
 
        long hold_count() { return hold_cnt; }
        void set_hold_count (long);
-       
-       static void set_horizontal_xpm (std::string);
-       static void set_vertical_xpm (std::string);
-       
-  protected:
+
+protected:
        bool on_expose_event (GdkEventExpose*);
        void on_size_request (GtkRequisition*);
-       void on_realize ();
+       void on_size_allocate (Gtk::Allocation&);
+
+private:
 
-  private:  
-       static std::string h_image_path;
-       static std::string v_image_path;
-       static Glib::RefPtr<Gdk::Pixmap> h_pixmap;
-       static Glib::RefPtr<Gdk::Bitmap> h_mask;
-       static gint h_pixheight;
-       static gint h_pixwidth;
+       Cairo::RefPtr<Cairo::Pattern> fgpattern;
+       Cairo::RefPtr<Cairo::Pattern> bgpattern;
+       gint pixheight;
+       gint pixwidth;
 
-       static Glib::RefPtr<Gdk::Pixmap> v_pixmap;
-       static Glib::RefPtr<Gdk::Bitmap> v_mask;
-       static gint v_pixheight;
-       static gint v_pixwidth;
+       float _stp[4];
+       int _clr[10];
+       int _bgc[2];
 
        Orientation orientation;
-       Glib::RefPtr<Gdk::Pixmap> backing;
        GdkRectangle pixrect;
+       GdkRectangle last_peak_rect;
        gint request_width;
        gint request_height;
        unsigned long hold_cnt;
@@ -77,9 +86,61 @@ class FastMeter : public Gtk::DrawingArea {
        float current_level;
        float current_peak;
        float current_user_level;
-       
+       bool resized;
+
        bool vertical_expose (GdkEventExpose*);
-       bool horizontal_expose (GdkEventExpose*);
+       void queue_vertical_redraw (const Glib::RefPtr<Gdk::Window>&, float);
+
+       static Cairo::RefPtr<Cairo::Pattern> generate_meter_pattern (
+               int w, int h, int *clr, float *stp);
+       static Cairo::RefPtr<Cairo::Pattern> request_vertical_meter (
+               int w, int h, int *clr, float *stp);
+
+       static Cairo::RefPtr<Cairo::Pattern> generate_meter_background (
+               int w, int h, int *bgc);
+       static Cairo::RefPtr<Cairo::Pattern> request_vertical_background (
+               int w, int h, int *bgc);
+
+       struct Pattern10MapKey {
+               Pattern10MapKey (
+                               int w, int h,
+                               float stp0, float stp1, float stp2, float stp3,
+                               int c0, int c1, int c2, int c3,
+                               int c4, int c5, int c6, int c7,
+                               int c8, int c9
+                               )
+                       : dim(w, h)
+                       , stp(stp0, stp1, stp2, stp3)
+                       , cols(c0, c1, c2, c3, c4, c5, c6, c7, c8, c9)
+               {}
+               inline bool operator<(const Pattern10MapKey& rhs) const {
+                       return (dim < rhs.dim)
+                               || (dim == rhs.dim && stp < rhs.stp)
+                               || (dim == rhs.dim && stp == rhs.stp && cols < rhs.cols);
+               }
+               boost::tuple<int, int> dim;
+               boost::tuple<float, float, float, float> stp;
+               boost::tuple<int, int, int, int, int, int, int, int, int, int> cols;
+       };
+       typedef std::map<Pattern10MapKey, Cairo::RefPtr<Cairo::Pattern> > Pattern10Map;
+
+       struct PatternBgMapKey {
+               PatternBgMapKey (int w, int h, int c0, int c1)
+                       : dim(w, h)
+                       , cols(c0, c1)
+               {}
+               inline bool operator<(const PatternBgMapKey& rhs) const {
+                       return (dim < rhs.dim) || (dim == rhs.dim && cols < rhs.cols);
+               }
+               boost::tuple<int, int> dim;
+               boost::tuple<int, int> cols;
+       };
+       typedef std::map<PatternBgMapKey, Cairo::RefPtr<Cairo::Pattern> > PatternBgMap;
+
+       static Pattern10Map vm_pattern_cache;
+       static PatternBgMap vb_pattern_cache;
+       static int min_pattern_metric_size; // min dimension for axis that displays the meter level
+       static int max_pattern_metric_size; // max dimension for axis that displays the meter level
 };