3 # This file is part of jack_mixer
5 # Copyright (C) 2006 Nedko Arnaudov <nedko@arnaudov.name>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; version 2 of the License
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
22 class meter(gtk
.DrawingArea
):
23 def __init__(self
, scale
):
24 gtk
.DrawingArea
.__init
__(self
)
28 self
.connect("expose-event", self
.on_expose
)
29 self
.connect("size-request", self
.on_size_request
)
30 self
.connect("size_allocate", self
.on_size_allocate
)
32 self
.color_bg
= gtk
.gdk
.Color(0,0,0)
33 self
.color_value
= gtk
.gdk
.Color(int(65535 * 0.8), int(65535 * 0.7), 0)
34 self
.color_mark
= gtk
.gdk
.Color(int(65535 * 0.2), int(65535 * 0.2), int(65535 * 0.2))
38 def on_expose(self
, widget
, event
):
39 cairo_ctx
= widget
.window
.cairo_create()
41 # set a clip region for the expose event
42 cairo_ctx
.rectangle(event
.area
.x
, event
.area
.y
, event
.area
.width
, event
.area
.height
)
49 def on_size_allocate(self
, widget
, allocation
):
50 #print allocation.x, allocation.y, allocation.width, allocation.height
51 self
.width
= float(allocation
.width
)
52 self
.height
= float(allocation
.height
)
55 def on_size_request(self
, widget
, requisition
):
56 #print "size-request, %u x %u" % (requisition.width, requisition.height)
57 requisition
.width
= 20
60 def invalidate_all(self
):
61 self
.queue_draw_area(0, 0, int(self
.width
), int(self
.height
))
63 def draw_background(self
, cairo_ctx
):
64 cairo_ctx
.set_source_color(self
.color_bg
)
65 cairo_ctx
.rectangle(0, 0, self
.width
, self
.height
)
68 cairo_ctx
.set_source_color(self
.color_mark
)
69 cairo_ctx
.select_font_face("Fixed")
70 cairo_ctx
.set_font_size(self
.font_size
)
71 glyph_width
= self
.font_size
* 3 / 5 # avarage glyph ratio
72 for mark
in self
.scale
.get_marks():
73 mark_position
= int(self
.height
* (1 - mark
.scale
))
74 cairo_ctx
.move_to(0, mark_position
)
75 cairo_ctx
.line_to(self
.width
, mark_position
)
77 x_correction
= self
.width
/ 2 - glyph_width
* len(mark
.text
) / 2
78 cairo_ctx
.move_to(x_correction
, mark_position
- 2)
79 cairo_ctx
.show_text(mark
.text
)
81 def draw_value(self
, cairo_ctx
, value
, x
, width
):
83 cairo_ctx
.set_source_color(self
.color_value
)
84 cairo_ctx
.rectangle(x
, self
.height
* (1 - value
), width
, self
.height
* value
)
87 def set_scale(self
, scale
):
92 def __init__(self
, scale
):
93 meter
.__init
__(self
, scale
)
96 def draw(self
, cairo_ctx
):
97 self
.draw_background(cairo_ctx
)
98 self
.draw_value(cairo_ctx
, self
.value
, self
.width
/4.0, self
.width
/2.0)
100 def set_value(self
, value
):
101 if value
!= self
.value
:
102 self
.value
= self
.scale
.db_to_scale(value
)
103 self
.invalidate_all()
106 def __init__(self
, scale
):
107 meter
.__init
__(self
, scale
)
111 def draw(self
, cairo_ctx
):
112 self
.draw_background(cairo_ctx
)
113 self
.draw_value(cairo_ctx
, self
.left
, self
.width
/5.0, self
.width
/5.0)
114 self
.draw_value(cairo_ctx
, self
.right
, self
.width
/5.0 * 3.0, self
.width
/5.0)
116 def set_values(self
, left
, right
):
117 if left
!= self
.left
or right
!= self
.right
:
118 self
.left
= self
.scale
.db_to_scale(left
)
119 self
.right
= self
.scale
.db_to_scale(right
)
120 self
.invalidate_all()