2008-06-02 17:41:35 -04:00
|
|
|
/*
|
2011-08-31 12:59:21 -04:00
|
|
|
Copyright (C) 2003 Paul Davis
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
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
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __gtkmm2ext_fastmeter_h__
|
|
|
|
#define __gtkmm2ext_fastmeter_h__
|
|
|
|
|
2011-07-25 14:05:54 -04:00
|
|
|
#include <map>
|
2011-08-31 12:59:21 -04:00
|
|
|
#include <boost/tuple/tuple.hpp>
|
|
|
|
#include <boost/tuple/tuple_comparison.hpp>
|
2011-07-25 14:05:54 -04:00
|
|
|
#include <cairomm/pattern.h>
|
2014-03-20 18:50:40 -04:00
|
|
|
#include "gtkmm2ext/cairo_widget.h"
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2013-10-17 11:26:01 -04:00
|
|
|
#include "gtkmm2ext/visibility.h"
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
namespace Gtkmm2ext {
|
|
|
|
|
2014-03-20 18:50:40 -04:00
|
|
|
class LIBGTKMM2EXT_API FastMeter : public CairoWidget {
|
2008-06-02 17:41:35 -04:00
|
|
|
public:
|
2011-08-31 12:59:21 -04:00
|
|
|
enum Orientation {
|
2008-06-02 17:41:35 -04:00
|
|
|
Horizontal,
|
|
|
|
Vertical
|
|
|
|
};
|
2011-08-31 12:59:21 -04:00
|
|
|
|
2013-07-01 20:15:04 -04:00
|
|
|
FastMeter (long hold_cnt, unsigned long width, Orientation, int len=0,
|
2013-07-03 17:39:47 -04:00
|
|
|
int clr0=0x008800ff, int clr1=0x008800ff,
|
|
|
|
int clr2=0x00ff00ff, int clr3=0x00ff00ff,
|
2013-07-03 19:29:59 -04:00
|
|
|
int clr4=0xffaa00ff, int clr5=0xffaa00ff,
|
|
|
|
int clr6=0xffff00ff, int clr7=0xffff00ff,
|
2013-07-03 17:39:47 -04:00
|
|
|
int clr8=0xff0000ff, int clr9=0xff0000ff,
|
2013-07-03 19:29:59 -04:00
|
|
|
int bgc0=0x333333ff, int bgc1=0x444444ff,
|
2013-07-06 10:30:30 -04:00
|
|
|
int bgh0=0x991122ff, int bgh1=0x551111ff,
|
2013-07-03 19:29:59 -04:00
|
|
|
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);
|
2013-07-23 20:47:37 -04:00
|
|
|
float stp3 = 100.0,
|
|
|
|
int styleflags = 3
|
2013-07-01 20:15:04 -04:00
|
|
|
);
|
2008-06-02 17:41:35 -04:00
|
|
|
virtual ~FastMeter ();
|
2014-09-10 20:40:18 -04:00
|
|
|
static void flush_pattern_cache();
|
2011-08-31 12:59:21 -04:00
|
|
|
|
2013-07-07 13:31:09 -04:00
|
|
|
void set (float level, float peak = -1);
|
2008-06-02 17:41:35 -04:00
|
|
|
void clear ();
|
|
|
|
|
|
|
|
float get_level() { return current_level; }
|
|
|
|
float get_user_level() { return current_user_level; }
|
|
|
|
float get_peak() { return current_peak; }
|
|
|
|
|
|
|
|
long hold_count() { return hold_cnt; }
|
|
|
|
void set_hold_count (long);
|
2013-07-06 10:30:30 -04:00
|
|
|
void set_highlight (bool);
|
|
|
|
bool get_highlight () { return highlight; }
|
2011-08-31 12:59:21 -04:00
|
|
|
|
|
|
|
protected:
|
2014-03-20 18:50:40 -04:00
|
|
|
void render (cairo_t *, cairo_rectangle_t*);
|
2008-06-02 17:41:35 -04:00
|
|
|
void on_size_request (GtkRequisition*);
|
|
|
|
void on_size_allocate (Gtk::Allocation&);
|
2011-08-31 12:59:21 -04:00
|
|
|
private:
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2013-07-01 18:08:11 -04:00
|
|
|
Cairo::RefPtr<Cairo::Pattern> fgpattern;
|
|
|
|
Cairo::RefPtr<Cairo::Pattern> bgpattern;
|
2008-06-02 17:41:35 -04:00
|
|
|
gint pixheight;
|
|
|
|
gint pixwidth;
|
2013-07-03 17:39:47 -04:00
|
|
|
|
2013-07-03 19:29:59 -04:00
|
|
|
float _stp[4];
|
2013-07-03 17:39:47 -04:00
|
|
|
int _clr[10];
|
|
|
|
int _bgc[2];
|
2013-07-06 10:30:30 -04:00
|
|
|
int _bgh[2];
|
2013-07-23 20:47:37 -04:00
|
|
|
int _styleflags;
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
Orientation orientation;
|
|
|
|
GdkRectangle pixrect;
|
|
|
|
GdkRectangle last_peak_rect;
|
|
|
|
gint request_width;
|
|
|
|
gint request_height;
|
|
|
|
unsigned long hold_cnt;
|
|
|
|
unsigned long hold_state;
|
2013-07-07 19:06:02 -04:00
|
|
|
bool bright_hold;
|
2008-06-02 17:41:35 -04:00
|
|
|
float current_level;
|
|
|
|
float current_peak;
|
|
|
|
float current_user_level;
|
2013-07-06 10:30:30 -04:00
|
|
|
bool highlight;
|
2011-08-31 12:59:21 -04:00
|
|
|
|
2014-03-20 18:50:40 -04:00
|
|
|
void vertical_expose (cairo_t*, cairo_rectangle_t*);
|
2013-07-25 13:04:52 -04:00
|
|
|
void vertical_size_request (GtkRequisition*);
|
|
|
|
void vertical_size_allocate (Gtk::Allocation&);
|
2008-06-02 17:41:35 -04:00
|
|
|
void queue_vertical_redraw (const Glib::RefPtr<Gdk::Window>&, float);
|
|
|
|
|
2014-03-20 18:50:40 -04:00
|
|
|
void horizontal_expose (cairo_t*, cairo_rectangle_t*);
|
2013-07-25 13:04:52 -04:00
|
|
|
void horizontal_size_request (GtkRequisition*);
|
|
|
|
void horizontal_size_allocate (Gtk::Allocation&);
|
|
|
|
void queue_horizontal_redraw (const Glib::RefPtr<Gdk::Window>&, float);
|
|
|
|
|
2013-07-15 18:56:36 -04:00
|
|
|
static bool no_rgba_overlay;
|
|
|
|
|
2011-08-31 12:59:21 -04:00
|
|
|
static Cairo::RefPtr<Cairo::Pattern> generate_meter_pattern (
|
2013-07-25 13:04:52 -04:00
|
|
|
int, int, int *, float *, int, bool);
|
2011-08-31 12:59:21 -04:00
|
|
|
static Cairo::RefPtr<Cairo::Pattern> request_vertical_meter (
|
2013-07-23 20:47:37 -04:00
|
|
|
int, int, int *, float *, int);
|
2013-07-25 13:04:52 -04:00
|
|
|
static Cairo::RefPtr<Cairo::Pattern> request_horizontal_meter (
|
|
|
|
int, int, int *, float *, int);
|
2013-07-03 17:39:47 -04:00
|
|
|
|
|
|
|
static Cairo::RefPtr<Cairo::Pattern> generate_meter_background (
|
2013-07-25 13:04:52 -04:00
|
|
|
int, int, int *, bool, bool);
|
2013-07-03 17:39:47 -04:00
|
|
|
static Cairo::RefPtr<Cairo::Pattern> request_vertical_background (
|
2013-07-23 20:47:37 -04:00
|
|
|
int, int, int *, bool);
|
2013-07-25 13:04:52 -04:00
|
|
|
static Cairo::RefPtr<Cairo::Pattern> request_horizontal_background (
|
|
|
|
int, int, int *, bool);
|
2013-07-03 17:39:47 -04:00
|
|
|
|
|
|
|
struct Pattern10MapKey {
|
|
|
|
Pattern10MapKey (
|
|
|
|
int w, int h,
|
2013-07-03 19:29:59 -04:00
|
|
|
float stp0, float stp1, float stp2, float stp3,
|
2013-07-03 17:39:47 -04:00
|
|
|
int c0, int c1, int c2, int c3,
|
|
|
|
int c4, int c5, int c6, int c7,
|
2013-07-23 20:47:37 -04:00
|
|
|
int c8, int c9, int st
|
2013-07-03 17:39:47 -04:00
|
|
|
)
|
|
|
|
: dim(w, h)
|
2013-07-03 19:29:59 -04:00
|
|
|
, stp(stp0, stp1, stp2, stp3)
|
2013-07-03 17:39:47 -04:00
|
|
|
, cols(c0, c1, c2, c3, c4, c5, c6, c7, c8, c9)
|
2013-07-23 20:47:37 -04:00
|
|
|
, style(st)
|
2013-07-03 17:39:47 -04:00
|
|
|
{}
|
|
|
|
inline bool operator<(const Pattern10MapKey& rhs) const {
|
|
|
|
return (dim < rhs.dim)
|
|
|
|
|| (dim == rhs.dim && stp < rhs.stp)
|
2013-07-23 20:47:37 -04:00
|
|
|
|| (dim == rhs.dim && stp == rhs.stp && cols < rhs.cols)
|
|
|
|
|| (dim == rhs.dim && stp == rhs.stp && cols == rhs.cols && style < rhs.style);
|
2013-07-03 17:39:47 -04:00
|
|
|
}
|
|
|
|
boost::tuple<int, int> dim;
|
2013-07-03 19:29:59 -04:00
|
|
|
boost::tuple<float, float, float, float> stp;
|
2013-07-03 17:39:47 -04:00
|
|
|
boost::tuple<int, int, int, int, int, int, int, int, int, int> cols;
|
2013-07-23 20:47:37 -04:00
|
|
|
int style;
|
2013-07-03 17:39:47 -04:00
|
|
|
};
|
|
|
|
typedef std::map<Pattern10MapKey, Cairo::RefPtr<Cairo::Pattern> > Pattern10Map;
|
2011-08-31 12:59:21 -04:00
|
|
|
|
2013-07-03 17:39:47 -04:00
|
|
|
struct PatternBgMapKey {
|
2013-07-26 11:17:05 -04:00
|
|
|
PatternBgMapKey (int w, int h, int c0, int c1, bool shade)
|
2011-08-31 12:59:21 -04:00
|
|
|
: dim(w, h)
|
2013-07-03 17:39:47 -04:00
|
|
|
, cols(c0, c1)
|
2013-07-26 11:17:05 -04:00
|
|
|
, sh(shade)
|
2011-08-31 12:59:21 -04:00
|
|
|
{}
|
2013-07-03 17:39:47 -04:00
|
|
|
inline bool operator<(const PatternBgMapKey& rhs) const {
|
2013-07-26 11:17:05 -04:00
|
|
|
return (dim < rhs.dim) || (dim == rhs.dim && cols < rhs.cols) || (dim == rhs.dim && cols == rhs.cols && (sh && !rhs.sh));
|
2011-08-31 12:59:21 -04:00
|
|
|
}
|
2013-07-03 17:39:47 -04:00
|
|
|
boost::tuple<int, int> dim;
|
|
|
|
boost::tuple<int, int> cols;
|
2013-07-26 11:17:05 -04:00
|
|
|
bool sh;
|
2011-08-31 12:59:21 -04:00
|
|
|
};
|
2013-07-03 17:39:47 -04:00
|
|
|
typedef std::map<PatternBgMapKey, Cairo::RefPtr<Cairo::Pattern> > PatternBgMap;
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2013-07-03 17:39:47 -04:00
|
|
|
static Pattern10Map vm_pattern_cache;
|
|
|
|
static PatternBgMap vb_pattern_cache;
|
2013-07-25 13:04:52 -04:00
|
|
|
static Pattern10Map hm_pattern_cache;
|
|
|
|
static PatternBgMap hb_pattern_cache;
|
2011-08-31 12:59:21 -04:00
|
|
|
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
|
2008-06-02 17:41:35 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} /* namespace */
|
|
|
|
|
|
|
|
#endif /* __gtkmm2ext_fastmeter_h__ */
|