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.
24 #include <gdkmm/rectangle.h>
25 #include <gtkmm2ext/fastmeter.h>
26 #include <gtkmm/style.h>
29 using namespace Gtkmm2ext;
32 Glib::RefPtr<Gdk::Pixmap> FastMeter::v_pixmap;
33 Glib::RefPtr<Gdk::Bitmap> FastMeter::v_mask;
34 gint FastMeter::v_pixheight = 0;
35 gint FastMeter::v_pixwidth = 0;
37 Glib::RefPtr<Gdk::Pixmap> FastMeter::h_pixmap;
38 Glib::RefPtr<Gdk::Bitmap> FastMeter::h_mask;
39 gint FastMeter::h_pixheight = 0;
40 gint FastMeter::h_pixwidth = 0;
42 FastMeter::FastMeter (long hold, unsigned long dimen, Orientation o)
49 current_user_level = -100.0f;
51 set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
56 if (orientation == Vertical) {
57 pixrect.set_width(min (v_pixwidth, (gint) dimen));
58 pixrect.set_height(v_pixheight);
60 pixrect.set_width(h_pixwidth);
61 pixrect.set_height(min (h_pixheight, (gint) dimen));
64 request_width = pixrect.get_width();
65 request_height= pixrect.get_height();
68 FastMeter::~FastMeter ()
73 FastMeter::set_vertical_xpm (const char **xpm)
78 v_pixmap = Gdk::Pixmap::create_from_xpm(Gdk::Colormap::get_system(), v_mask, xpm);
79 v_pixmap->get_size(w, h);
87 FastMeter::set_horizontal_xpm (const char **xpm)
92 h_pixmap = Gdk::Pixmap::create_from_xpm(Gdk::Colormap::get_system(), h_mask, xpm);
93 h_pixmap->get_size(w, h);
101 FastMeter::set_hold_count (long val)
115 FastMeter::on_size_request (GtkRequisition* req)
117 req->width = request_width;
118 req->height = request_height;
122 FastMeter::on_expose_event (GdkEventExpose* ev)
124 if (orientation == Vertical) {
125 return vertical_expose (ev);
127 return horizontal_expose (ev);
132 FastMeter::vertical_expose (GdkEventExpose* ev)
134 Gdk::Rectangle intersect;
137 bool intersecting = false;
139 top_of_meter = (gint) floor (v_pixheight * current_level);
140 pixrect.set_height(top_of_meter);
142 intersect = pixrect.intersect(Glib::wrap(&ev->area), intersecting);
144 /* draw the part of the meter image that we need. the area we draw is bounded "in reverse" (top->bottom)
147 Glib::RefPtr<Gdk::Window> win(get_window());
148 win->draw_drawable(get_style()->get_fg_gc(get_state()), v_pixmap,
149 intersect.get_x(), v_pixheight - top_of_meter,
150 intersect.get_x(), v_pixheight - top_of_meter,
151 intersect.get_width(), intersect.get_height());
159 Glib::RefPtr<Gdk::Window> win(get_window());
160 win->draw_drawable(get_style()->get_fg_gc(get_state()), v_pixmap,
161 intersect.get_x(), v_pixheight - (gint) floor (v_pixheight * current_peak),
162 intersect.get_x(), v_pixheight - (gint) floor (v_pixheight * current_peak),
163 intersect.get_width(), 3);
170 FastMeter::horizontal_expose (GdkEventExpose* ev)
172 Gdk::Rectangle intersect;
173 bool intersecting = false;
176 right_of_meter = (gint) floor (h_pixwidth * current_level);
177 pixrect.set_width(right_of_meter);
179 intersect = pixrect.intersect(Glib::wrap(&ev->area), intersecting);
181 /* draw the part of the meter image that we need.
184 Glib::RefPtr<Gdk::Window> win(get_window());
185 win->draw_drawable(get_style()->get_fg_gc(get_state()), h_pixmap,
186 intersect.get_x(), intersect.get_y(),
187 intersect.get_x(), intersect.get_y(),
188 intersect.get_width(), intersect.get_height());
194 Glib::RefPtr<Gdk::Window> win(get_window());
195 win->draw_drawable(get_style()->get_fg_gc(get_state()), h_pixmap,
196 right_of_meter, intersect.get_y(),
197 right_of_meter, intersect.get_y(),
198 3, intersect.get_height());
205 FastMeter::set (float lvl, float usrlvl)
208 current_user_level = usrlvl;
210 if (lvl > current_peak) {
212 hold_state = hold_cnt;
215 if (hold_state > 0) {
216 if (--hold_state == 0) {