2 Copyright (C) 2003 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #ifndef __gtkmm2ext_fastmeter_h__
21 #define __gtkmm2ext_fastmeter_h__
24 #include <boost/tuple/tuple.hpp>
25 #include <boost/tuple/tuple_comparison.hpp>
26 #include <cairomm/pattern.h>
27 #include "gtkmm2ext/cairo_widget.h"
29 #include "gtkmm2ext/visibility.h"
33 class LIBGTKMM2EXT_API FastMeter : public CairoWidget {
40 FastMeter (long hold_cnt, unsigned long width, Orientation, int len=0,
41 int clr0=0x008800ff, int clr1=0x008800ff,
42 int clr2=0x00ff00ff, int clr3=0x00ff00ff,
43 int clr4=0xffaa00ff, int clr5=0xffaa00ff,
44 int clr6=0xffff00ff, int clr7=0xffff00ff,
45 int clr8=0xff0000ff, int clr9=0xff0000ff,
46 int bgc0=0x333333ff, int bgc1=0x444444ff,
47 int bgh0=0x991122ff, int bgh1=0x551111ff,
48 float stp0 = 55.0, // log_meter(-18);
49 float stp1 = 77.5, // log_meter(-9);
50 float stp2 = 92.5, // log_meter(-3); // 95.0, // log_meter(-2);
54 virtual ~FastMeter ();
55 static void flush_pattern_cache();
57 void set (float level, float peak = -1);
60 float get_level() { return current_level; }
61 float get_user_level() { return current_user_level; }
62 float get_peak() { return current_peak; }
64 long hold_count() { return hold_cnt; }
65 void set_hold_count (long);
66 void set_highlight (bool);
67 bool get_highlight () { return highlight; }
68 void render (Cairo::RefPtr<Cairo::Context> const&, cairo_rectangle_t*);
71 void on_size_request (GtkRequisition*);
72 void on_size_allocate (Gtk::Allocation&);
75 Cairo::RefPtr<Cairo::Pattern> fgpattern;
76 Cairo::RefPtr<Cairo::Pattern> bgpattern;
86 Orientation orientation;
88 GdkRectangle last_peak_rect;
91 unsigned long hold_cnt;
92 unsigned long hold_state;
96 float current_user_level;
99 void vertical_expose (cairo_t*, cairo_rectangle_t*);
100 void vertical_size_request (GtkRequisition*);
101 void vertical_size_allocate (Gtk::Allocation&);
102 void queue_vertical_redraw (const Glib::RefPtr<Gdk::Window>&, float);
104 void horizontal_expose (cairo_t*, cairo_rectangle_t*);
105 void horizontal_size_request (GtkRequisition*);
106 void horizontal_size_allocate (Gtk::Allocation&);
107 void queue_horizontal_redraw (const Glib::RefPtr<Gdk::Window>&, float);
109 static bool no_rgba_overlay;
111 static Cairo::RefPtr<Cairo::Pattern> generate_meter_pattern (
112 int, int, int *, float *, int, bool);
113 static Cairo::RefPtr<Cairo::Pattern> request_vertical_meter (
114 int, int, int *, float *, int);
115 static Cairo::RefPtr<Cairo::Pattern> request_horizontal_meter (
116 int, int, int *, float *, int);
118 static Cairo::RefPtr<Cairo::Pattern> generate_meter_background (
119 int, int, int *, bool, bool);
120 static Cairo::RefPtr<Cairo::Pattern> request_vertical_background (
121 int, int, int *, bool);
122 static Cairo::RefPtr<Cairo::Pattern> request_horizontal_background (
123 int, int, int *, bool);
125 struct Pattern10MapKey {
128 float stp0, float stp1, float stp2, float stp3,
129 int c0, int c1, int c2, int c3,
130 int c4, int c5, int c6, int c7,
131 int c8, int c9, int st
134 , stp(stp0, stp1, stp2, stp3)
135 , cols(c0, c1, c2, c3, c4, c5, c6, c7, c8, c9)
138 inline bool operator<(const Pattern10MapKey& rhs) const {
139 return (dim < rhs.dim)
140 || (dim == rhs.dim && stp < rhs.stp)
141 || (dim == rhs.dim && stp == rhs.stp && cols < rhs.cols)
142 || (dim == rhs.dim && stp == rhs.stp && cols == rhs.cols && style < rhs.style);
144 boost::tuple<int, int> dim;
145 boost::tuple<float, float, float, float> stp;
146 boost::tuple<int, int, int, int, int, int, int, int, int, int> cols;
149 typedef std::map<Pattern10MapKey, Cairo::RefPtr<Cairo::Pattern> > Pattern10Map;
151 struct PatternBgMapKey {
152 PatternBgMapKey (int w, int h, int c0, int c1, bool shade)
157 inline bool operator<(const PatternBgMapKey& rhs) const {
158 return (dim < rhs.dim) || (dim == rhs.dim && cols < rhs.cols) || (dim == rhs.dim && cols == rhs.cols && (sh && !rhs.sh));
160 boost::tuple<int, int> dim;
161 boost::tuple<int, int> cols;
164 typedef std::map<PatternBgMapKey, Cairo::RefPtr<Cairo::Pattern> > PatternBgMap;
166 static Pattern10Map vm_pattern_cache;
167 static PatternBgMap vb_pattern_cache;
168 static Pattern10Map hm_pattern_cache;
169 static PatternBgMap hb_pattern_cache;
170 static int min_pattern_metric_size; // min dimension for axis that displays the meter level
171 static int max_pattern_metric_size; // max dimension for axis that displays the meter level
177 #endif /* __gtkmm2ext_fastmeter_h__ */