From fa332f31fa43d8807b197a1cabfd39784cf3ef8a Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Wed, 24 Jul 2013 02:47:37 +0200 Subject: allow to en/disable shade and LED meter style --- libs/gtkmm2ext/fastmeter.cc | 39 ++++++++++++++++++++---------------- libs/gtkmm2ext/gtkmm2ext/fastmeter.h | 19 +++++++++++------- 2 files changed, 34 insertions(+), 24 deletions(-) (limited to 'libs/gtkmm2ext') diff --git a/libs/gtkmm2ext/fastmeter.cc b/libs/gtkmm2ext/fastmeter.cc index 817b11ff6c..282b9e10b8 100644 --- a/libs/gtkmm2ext/fastmeter.cc +++ b/libs/gtkmm2ext/fastmeter.cc @@ -51,7 +51,8 @@ FastMeter::FastMeter (long hold, unsigned long dimen, Orientation o, int len, int bgc0, int bgc1, int bgh0, int bgh1, float stp0, float stp1, - float stp2, float stp3 + float stp2, float stp3, + int styleflags ) { orientation = o; @@ -88,6 +89,8 @@ FastMeter::FastMeter (long hold, unsigned long dimen, Orientation o, int len, _stp[2] = stp2; _stp[3] = stp3; + _styleflags = styleflags; + set_events (BUTTON_PRESS_MASK|BUTTON_RELEASE_MASK); pixrect.x = 1; @@ -96,7 +99,7 @@ FastMeter::FastMeter (long hold, unsigned long dimen, Orientation o, int len, if (!len) { len = 250; } - fgpattern = request_vertical_meter(dimen, len, _clr, _stp, true); + fgpattern = request_vertical_meter(dimen, len, _clr, _stp, _styleflags); bgpattern = request_vertical_background (dimen, len, _bgc, false); pixheight = len; pixwidth = dimen; @@ -116,7 +119,7 @@ FastMeter::~FastMeter () Cairo::RefPtr FastMeter::generate_meter_pattern ( - int width, int height, int *clr, float *stp, bool shade) + int width, int height, int *clr, float *stp, int styleflags) { guint8 r,g,b,a; double knee; @@ -177,7 +180,7 @@ FastMeter::generate_meter_pattern ( cairo_pattern_add_color_stop_rgb (pat, 1.0, r/255.0, g/255.0, b/255.0); - if (shade && !no_rgba_overlay) { + if ((styleflags & 1) && !no_rgba_overlay) { cairo_pattern_t* shade_pattern = cairo_pattern_create_linear (0.0, 0.0, width, 0.0); cairo_pattern_add_color_stop_rgba (shade_pattern, 0, 1.0, 1.0, 1.0, 0.2); cairo_pattern_add_color_stop_rgba (shade_pattern, 1, 0.0, 0.0, 0.0, 0.3); @@ -190,16 +193,18 @@ FastMeter::generate_meter_pattern ( cairo_rectangle (tc, 0, 0, width, height); cairo_fill (tc); - cairo_save (tc); - cairo_set_line_width(tc, 1.0); - cairo_set_source_rgba(tc, .1, .1, .1, .5); - //cairo_set_operator (tc, CAIRO_OPERATOR_SOURCE); - for (float y=.5; y < height; y+= 2.0) { - cairo_move_to(tc, 0, y); - cairo_line_to(tc, width, y); - cairo_stroke (tc); + if (styleflags & 2) { // LED stripes + cairo_save (tc); + cairo_set_line_width(tc, 1.0); + cairo_set_source_rgba(tc, .1, .1, .1, .5); + //cairo_set_operator (tc, CAIRO_OPERATOR_SOURCE); + for (float y=.5; y < height; y+= 2.0) { + cairo_move_to(tc, 0, y); + cairo_line_to(tc, width, y); + cairo_stroke (tc); + } + cairo_restore (tc); } - cairo_restore (tc); cairo_set_source (tc, shade_pattern); cairo_rectangle (tc, 0, 0, width, height); @@ -270,7 +275,7 @@ FastMeter::generate_meter_background ( Cairo::RefPtr FastMeter::request_vertical_meter( - int width, int height, int *clr, float *stp, bool shade) + int width, int height, int *clr, float *stp, int styleflags) { if (height < min_pattern_metric_size) height = min_pattern_metric_size; @@ -281,7 +286,7 @@ FastMeter::request_vertical_meter( stp[0], stp[1], stp[2], stp[3], clr[0], clr[1], clr[2], clr[3], clr[4], clr[5], clr[6], clr[7], - clr[8], clr[9]); + clr[8], clr[9], styleflags); Pattern10Map::iterator i; if ((i = vm_pattern_cache.find (key)) != vm_pattern_cache.end()) { @@ -290,7 +295,7 @@ FastMeter::request_vertical_meter( // TODO flush pattern cache if it gets too large Cairo::RefPtr p = generate_meter_pattern ( - width, height, clr, stp, shade); + width, height, clr, stp, styleflags); vm_pattern_cache[key] = p; return p; @@ -361,7 +366,7 @@ FastMeter::on_size_allocate (Gtk::Allocation &alloc) } if (pixheight != h) { - fgpattern = request_vertical_meter (request_width, h, _clr, _stp, true); + fgpattern = request_vertical_meter (request_width, h, _clr, _stp, _styleflags); bgpattern = request_vertical_background (request_width, h, highlight ? _bgh : _bgc, highlight); pixheight = h - 2; pixwidth = request_width - 2; diff --git a/libs/gtkmm2ext/gtkmm2ext/fastmeter.h b/libs/gtkmm2ext/gtkmm2ext/fastmeter.h index 15c962deb4..3a806262f1 100644 --- a/libs/gtkmm2ext/gtkmm2ext/fastmeter.h +++ b/libs/gtkmm2ext/gtkmm2ext/fastmeter.h @@ -47,7 +47,8 @@ class FastMeter : public Gtk::DrawingArea { 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 + float stp3 = 100.0, + int styleflags = 3 ); virtual ~FastMeter (); @@ -79,6 +80,7 @@ private: int _clr[10]; int _bgc[2]; int _bgh[2]; + int _styleflags; Orientation orientation; GdkRectangle pixrect; @@ -99,14 +101,14 @@ private: static bool no_rgba_overlay; static Cairo::RefPtr generate_meter_pattern ( - int w, int h, int *clr, float *stp, bool shade); + int, int, int *, float *, int); static Cairo::RefPtr request_vertical_meter ( - int w, int h, int *clr, float *stp, bool shade); + int, int, int *, float *, int); static Cairo::RefPtr generate_meter_background ( - int w, int h, int *bgc, bool shade); + int, int, int *, bool); static Cairo::RefPtr request_vertical_background ( - int w, int h, int *bgc, bool shade); + int, int, int *, bool); struct Pattern10MapKey { Pattern10MapKey ( @@ -114,20 +116,23 @@ private: 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 + int c8, int c9, int st ) : dim(w, h) , stp(stp0, stp1, stp2, stp3) , cols(c0, c1, c2, c3, c4, c5, c6, c7, c8, c9) + , style(st) {} 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); + || (dim == rhs.dim && stp == rhs.stp && cols < rhs.cols) + || (dim == rhs.dim && stp == rhs.stp && cols == rhs.cols && style < rhs.style); } boost::tuple dim; boost::tuple stp; boost::tuple cols; + int style; }; typedef std::map > Pattern10Map; -- cgit v1.2.3