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 = 0;
33 Glib::RefPtr<Gdk::Bitmap> *FastMeter::v_mask = 0;
34 gint FastMeter::v_pixheight = 0;
35 gint FastMeter::v_pixwidth = 0;
37 Glib::RefPtr<Gdk::Pixmap> *FastMeter::h_pixmap = 0;
38 Glib::RefPtr<Gdk::Bitmap> *FastMeter::h_mask = 0;
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();
70 FastMeter::~FastMeter ()
73 (*backing)->unreference();
78 FastMeter::set_vertical_xpm (const char **xpm)
83 *v_pixmap = Gdk::Pixmap::create_from_xpm(Gdk::Colormap::get_system(), *v_mask, xpm);
85 (*v_pixmap)->get_size(w, h);
93 FastMeter::set_horizontal_xpm (const char **xpm)
98 *h_pixmap = Gdk::Pixmap::create_from_xpm(Gdk::Colormap::get_system(), *h_mask, xpm);
100 (*h_pixmap)->get_size(w, h);
108 FastMeter::set_hold_count (long val)
122 FastMeter::on_size_request (GtkRequisition* req)
124 req->width = request_width;
125 req->height = request_height;
129 FastMeter::on_expose_event (GdkEventExpose* ev)
131 if (orientation == Vertical) {
132 return vertical_expose (ev);
134 return horizontal_expose (ev);
139 FastMeter::vertical_expose (GdkEventExpose* ev)
141 Gdk::Rectangle intersect;
144 bool intersecting = false;
146 top_of_meter = (gint) floor (v_pixheight * current_level);
147 pixrect.set_height(v_pixheight - top_of_meter); /* bottom of background */
150 *backing = Gdk::Pixmap::create (get_window(), get_width(), get_height());
153 intersect = pixrect.intersect(Glib::wrap(&ev->area), intersecting);
156 /* paint the background (black). */
157 (*backing)->draw_rectangle(get_style()->get_black_gc(), true, intersect.get_x(), intersect.get_y(), intersect.get_width(), intersect.get_height());
161 pixrect.set_height(top_of_meter);
163 intersect = pixrect.intersect(Glib::wrap(&ev->area), intersecting);
165 /* draw the part of the meter image that we need. the area we draw is bounded "in reverse" (top->bottom)
168 (*backing)->draw_drawable(get_style()->get_fg_gc(get_state()), *v_pixmap,
169 intersect.get_x(), v_pixheight - top_of_meter,
170 intersect.get_x(), v_pixheight - top_of_meter,
171 intersect.get_width(), intersect.get_height());
179 (*backing)->draw_drawable(get_style()->get_fg_gc(get_state()), *v_pixmap,
180 intersect.get_x(), v_pixheight - (gint) floor (v_pixheight * current_peak),
181 intersect.get_x(), v_pixheight - (gint) floor (v_pixheight * current_peak),
182 intersect.get_width(), 3);
185 /* bilt to on-screen drawable */
188 Glib::RefPtr<Gdk::Window> win (get_window());
189 win->draw_drawable(get_style()->get_fg_gc(get_state()), *backing,
190 ev->area.x, ev->area.y,
191 ev->area.x, ev->area.y,
192 ev->area.width, ev->area.height);
199 FastMeter::horizontal_expose (GdkEventExpose* ev)
201 Gdk::Rectangle intersect;
202 bool intersecting = false;
206 right_of_meter = (gint) floor (h_pixwidth * current_level);
208 pixrect.set_x(right_of_meter);
210 pixrect.set_width(h_pixwidth - right_of_meter);
213 *backing = Gdk::Pixmap::create(get_window(), get_width(), get_height());
216 intersect = pixrect.intersect(Glib::wrap(&ev->area), intersecting);
218 /* paint the background (black). */
220 (*backing)->draw_rectangle(get_style()->get_black_gc(), true,
221 intersect.get_x(), intersect.get_y(),
222 intersect.get_width(), intersect.get_height());
227 pixrect.set_width(right_of_meter);
229 intersect = pixrect.intersect(Glib::wrap(&ev->area), intersecting);
231 /* draw the part of the meter image that we need.
234 (*backing)->draw_drawable(get_style()->get_fg_gc(get_state()), *h_pixmap,
235 intersect.get_x(), intersect.get_y(),
236 intersect.get_x(), intersect.get_y(),
237 intersect.get_width(), intersect.get_height());
245 (*backing)->draw_drawable(get_style()->get_fg_gc(get_state()), *h_pixmap,
246 right_of_meter, intersect.get_y(),
247 right_of_meter, intersect.get_y(),
248 3, intersect.get_height());
251 /* bilt to on-screen drawable */
254 Glib::RefPtr<Gdk::Window> win(get_window());
255 win->draw_drawable(get_style()->get_fg_gc(get_state()), *backing,
256 ev->area.x, ev->area.y,
257 ev->area.x, ev->area.y,
258 ev->area.width, ev->area.height);
265 FastMeter::set (float lvl, float usrlvl)
268 current_user_level = usrlvl;
270 if (lvl > current_peak) {
272 hold_state = hold_cnt;
275 if (hold_state > 0) {
276 if (--hold_state == 0) {