~ubuntu-branches/ubuntu/utopic/ardour3/utopic

« back to all changes in this revision

Viewing changes to libs/gtkmm2ext/gtkmm2ext/fastmeter.h

  • Committer: Package Import Robot
  • Author(s): Felipe Sateler
  • Date: 2013-09-21 19:05:02 UTC
  • Revision ID: package-import@ubuntu.com-20130921190502-8gsftrku6jnzhd7v
Tags: upstream-3.4~dfsg
ImportĀ upstreamĀ versionĀ 3.4~dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright (C) 2003 Paul Davis
 
3
 
 
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.
 
8
 
 
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.
 
13
 
 
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.
 
17
 
 
18
*/
 
19
 
 
20
#ifndef __gtkmm2ext_fastmeter_h__
 
21
#define __gtkmm2ext_fastmeter_h__
 
22
 
 
23
#include <map>
 
24
#include <boost/tuple/tuple.hpp>
 
25
#include <boost/tuple/tuple_comparison.hpp>
 
26
#include <cairomm/pattern.h>
 
27
#include <gtkmm/drawingarea.h>
 
28
#include <gdkmm/pixbuf.h>
 
29
 
 
30
namespace Gtkmm2ext {
 
31
 
 
32
class FastMeter : public Gtk::DrawingArea {
 
33
  public:
 
34
        enum Orientation {
 
35
                Horizontal,
 
36
                Vertical
 
37
        };
 
38
 
 
39
        FastMeter (long hold_cnt, unsigned long width, Orientation, int len=0,
 
40
                        int clr0=0x008800ff, int clr1=0x008800ff,
 
41
                        int clr2=0x00ff00ff, int clr3=0x00ff00ff,
 
42
                        int clr4=0xffaa00ff, int clr5=0xffaa00ff,
 
43
                        int clr6=0xffff00ff, int clr7=0xffff00ff,
 
44
                        int clr8=0xff0000ff, int clr9=0xff0000ff,
 
45
                        int bgc0=0x333333ff, int bgc1=0x444444ff,
 
46
                        int bgh0=0x991122ff, int bgh1=0x551111ff,
 
47
                        float stp0 = 55.0, // log_meter(-18);
 
48
                        float stp1 = 77.5, // log_meter(-9);
 
49
                        float stp2 = 92.5, // log_meter(-3); // 95.0, // log_meter(-2);
 
50
                        float stp3 = 100.0,
 
51
                        int styleflags = 3
 
52
                        );
 
53
        virtual ~FastMeter ();
 
54
 
 
55
        void set (float level, float peak = -1);
 
56
        void clear ();
 
57
 
 
58
        float get_level() { return current_level; }
 
59
        float get_user_level() { return current_user_level; }
 
60
        float get_peak() { return current_peak; }
 
61
 
 
62
        long hold_count() { return hold_cnt; }
 
63
        void set_hold_count (long);
 
64
        void set_highlight (bool);
 
65
        bool get_highlight () { return highlight; }
 
66
 
 
67
protected:
 
68
        bool on_expose_event (GdkEventExpose*);
 
69
        void on_size_request (GtkRequisition*);
 
70
        void on_size_allocate (Gtk::Allocation&);
 
71
private:
 
72
 
 
73
        Cairo::RefPtr<Cairo::Pattern> fgpattern;
 
74
        Cairo::RefPtr<Cairo::Pattern> bgpattern;
 
75
        gint pixheight;
 
76
        gint pixwidth;
 
77
 
 
78
        float _stp[4];
 
79
        int _clr[10];
 
80
        int _bgc[2];
 
81
        int _bgh[2];
 
82
        int _styleflags;
 
83
 
 
84
        Orientation orientation;
 
85
        GdkRectangle pixrect;
 
86
        GdkRectangle last_peak_rect;
 
87
        gint request_width;
 
88
        gint request_height;
 
89
        unsigned long hold_cnt;
 
90
        unsigned long hold_state;
 
91
        bool bright_hold;
 
92
        float current_level;
 
93
        float current_peak;
 
94
        float current_user_level;
 
95
        bool highlight;
 
96
 
 
97
        bool vertical_expose (GdkEventExpose*);
 
98
        void vertical_size_request (GtkRequisition*);
 
99
        void vertical_size_allocate (Gtk::Allocation&);
 
100
        void queue_vertical_redraw (const Glib::RefPtr<Gdk::Window>&, float);
 
101
 
 
102
        bool horizontal_expose (GdkEventExpose*);
 
103
        void horizontal_size_request (GtkRequisition*);
 
104
        void horizontal_size_allocate (Gtk::Allocation&);
 
105
        void queue_horizontal_redraw (const Glib::RefPtr<Gdk::Window>&, float);
 
106
 
 
107
        static bool no_rgba_overlay;
 
108
 
 
109
        static Cairo::RefPtr<Cairo::Pattern> generate_meter_pattern (
 
110
                int, int, int *, float *, int, bool);
 
111
        static Cairo::RefPtr<Cairo::Pattern> request_vertical_meter (
 
112
                int, int, int *, float *, int);
 
113
        static Cairo::RefPtr<Cairo::Pattern> request_horizontal_meter (
 
114
                int, int, int *, float *, int);
 
115
 
 
116
        static Cairo::RefPtr<Cairo::Pattern> generate_meter_background (
 
117
                int, int, int *, bool, bool);
 
118
        static Cairo::RefPtr<Cairo::Pattern> request_vertical_background (
 
119
                int, int, int *, bool);
 
120
        static Cairo::RefPtr<Cairo::Pattern> request_horizontal_background (
 
121
                int, int, int *, bool);
 
122
 
 
123
        struct Pattern10MapKey {
 
124
                Pattern10MapKey (
 
125
                                int w, int h,
 
126
                                float stp0, float stp1, float stp2, float stp3,
 
127
                                int c0, int c1, int c2, int c3,
 
128
                                int c4, int c5, int c6, int c7,
 
129
                                int c8, int c9, int st
 
130
                                )
 
131
                        : dim(w, h)
 
132
                        , stp(stp0, stp1, stp2, stp3)
 
133
                        , cols(c0, c1, c2, c3, c4, c5, c6, c7, c8, c9)
 
134
                        , style(st)
 
135
                {}
 
136
                inline bool operator<(const Pattern10MapKey& rhs) const {
 
137
                        return (dim < rhs.dim)
 
138
                                || (dim == rhs.dim && stp < rhs.stp)
 
139
                                || (dim == rhs.dim && stp == rhs.stp && cols < rhs.cols)
 
140
                                || (dim == rhs.dim && stp == rhs.stp && cols == rhs.cols && style < rhs.style);
 
141
                }
 
142
                boost::tuple<int, int> dim;
 
143
                boost::tuple<float, float, float, float> stp;
 
144
                boost::tuple<int, int, int, int, int, int, int, int, int, int> cols;
 
145
                int style;
 
146
        };
 
147
        typedef std::map<Pattern10MapKey, Cairo::RefPtr<Cairo::Pattern> > Pattern10Map;
 
148
 
 
149
        struct PatternBgMapKey {
 
150
                PatternBgMapKey (int w, int h, int c0, int c1, bool shade)
 
151
                        : dim(w, h)
 
152
                        , cols(c0, c1)
 
153
                        , sh(shade)
 
154
                {}
 
155
                inline bool operator<(const PatternBgMapKey& rhs) const {
 
156
                        return (dim < rhs.dim) || (dim == rhs.dim && cols < rhs.cols) || (dim == rhs.dim && cols == rhs.cols && (sh && !rhs.sh));
 
157
                }
 
158
                boost::tuple<int, int> dim;
 
159
                boost::tuple<int, int> cols;
 
160
                bool sh;
 
161
        };
 
162
        typedef std::map<PatternBgMapKey, Cairo::RefPtr<Cairo::Pattern> > PatternBgMap;
 
163
 
 
164
        static Pattern10Map vm_pattern_cache;
 
165
        static PatternBgMap vb_pattern_cache;
 
166
        static Pattern10Map hm_pattern_cache;
 
167
        static PatternBgMap hb_pattern_cache;
 
168
        static int min_pattern_metric_size; // min dimension for axis that displays the meter level
 
169
        static int max_pattern_metric_size; // max dimension for axis that displays the meter level
 
170
};
 
171
 
 
172
 
 
173
} /* namespace */
 
174
 
 
175
 #endif /* __gtkmm2ext_fastmeter_h__ */