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>
31 using namespace Gtkmm2ext;
34 RefPtr<Pixmap> FastMeter::v_pixmap;
35 RefPtr<Bitmap> FastMeter::v_mask;
36 gint FastMeter::v_pixheight = 0;
37 gint FastMeter::v_pixwidth = 0;
39 RefPtr<Pixmap> FastMeter::h_pixmap;
40 RefPtr<Bitmap> FastMeter::h_mask;
41 gint FastMeter::h_pixheight = 0;
42 gint FastMeter::h_pixwidth = 0;
44 FastMeter::FastMeter (long hold, unsigned long dimen, Orientation o)
51 current_user_level = -100.0f;
53 set_events (BUTTON_PRESS_MASK|BUTTON_RELEASE_MASK);
58 if (orientation == Vertical) {
59 pixrect.set_width(min (v_pixwidth, (gint) dimen));
60 pixrect.set_height(v_pixheight);
62 pixrect.set_width(h_pixwidth);
63 pixrect.set_height(min (h_pixheight, (gint) dimen));
66 request_width = pixrect.get_width();
67 request_height= pixrect.get_height();
70 FastMeter::~FastMeter ()
75 FastMeter::on_realize ()
77 DrawingArea::on_realize();
79 RefPtr<Style> style = get_style();
80 Color black = style->get_black();
82 style->set_bg (STATE_NORMAL, black);
83 style->set_bg (STATE_ACTIVE, black);
84 style->set_bg (STATE_SELECTED, black);
85 style->set_bg (STATE_INSENSITIVE, black);
89 FastMeter::set_vertical_xpm (const char **xpm)
94 v_pixmap = Pixmap::create_from_xpm(Colormap::get_system(), v_mask, xpm);
95 v_pixmap->get_size(w, h);
103 FastMeter::set_horizontal_xpm (const char **xpm)
108 h_pixmap = Pixmap::create_from_xpm(Colormap::get_system(), h_mask, xpm);
109 h_pixmap->get_size(w, h);
117 FastMeter::set_hold_count (long val)
131 FastMeter::on_size_request (GtkRequisition* req)
133 req->width = request_width;
134 req->height = request_height;
138 FastMeter::on_expose_event (GdkEventExpose* ev)
140 if (orientation == Vertical) {
141 return vertical_expose (ev);
143 return horizontal_expose (ev);
148 FastMeter::vertical_expose (GdkEventExpose* ev)
153 bool intersecting = false;
155 top_of_meter = (gint) floor (v_pixheight * current_level);
156 pixrect.set_height(top_of_meter);
158 intersect = pixrect.intersect(wrap(&ev->area), intersecting);
160 /* draw the part of the meter image that we need. the area we draw is bounded "in reverse" (top->bottom)
163 RefPtr<Gdk::Window> win(get_window());
164 win->draw_drawable(get_style()->get_fg_gc(get_state()), v_pixmap,
165 intersect.get_x(), v_pixheight - top_of_meter,
166 intersect.get_x(), v_pixheight - top_of_meter,
167 intersect.get_width(), intersect.get_height());
175 RefPtr<Gdk::Window> win(get_window());
176 win->draw_drawable(get_style()->get_fg_gc(get_state()), v_pixmap,
177 intersect.get_x(), v_pixheight - (gint) floor (v_pixheight * current_peak),
178 intersect.get_x(), v_pixheight - (gint) floor (v_pixheight * current_peak),
179 intersect.get_width(), 3);
186 FastMeter::horizontal_expose (GdkEventExpose* ev)
189 bool intersecting = false;
192 right_of_meter = (gint) floor (h_pixwidth * current_level);
193 pixrect.set_width(right_of_meter);
195 intersect = pixrect.intersect(wrap(&ev->area), intersecting);
197 /* draw the part of the meter image that we need.
200 RefPtr<Gdk::Window> win(get_window());
201 win->draw_drawable(get_style()->get_fg_gc(get_state()), h_pixmap,
202 intersect.get_x(), intersect.get_y(),
203 intersect.get_x(), intersect.get_y(),
204 intersect.get_width(), intersect.get_height());
210 RefPtr<Gdk::Window> win(get_window());
211 win->draw_drawable(get_style()->get_fg_gc(get_state()), h_pixmap,
212 right_of_meter, intersect.get_y(),
213 right_of_meter, intersect.get_y(),
214 3, intersect.get_height());
221 FastMeter::set (float lvl, float usrlvl)
224 current_user_level = usrlvl;
226 if (lvl > current_peak) {
228 hold_state = hold_cnt;
231 if (hold_state > 0) {
232 if (--hold_state == 0) {