Class: Iconify::CommandStatusIcon
- Inherits:
-
Gtk::StatusIcon
- Object
- Gtk::StatusIcon
- Iconify::CommandStatusIcon
- Includes:
- Cairo, Gtk
- Defined in:
- lib/iconify.rb
Overview
プログラム名を表示するステータスアイコン
Constant Summary collapse
- COLOR_SCHEME =
{ running: [[0.67, 1.0, 0.0], [0.1, 0.1, 0.1]], stopped: [[0.75, 0.0, 0.0], [0.9, 0.9, 0.9]] }.freeze
Instance Method Summary collapse
- #draw_name(cr) ⇒ Object
- #fill_rounded_rectangle(cr) ⇒ Object
-
#initialize(name) ⇒ CommandStatusIcon
constructor
A new instance of CommandStatusIcon.
- #paint_background(cr) ⇒ Object
- #redraw ⇒ Object
- #update(state) ⇒ Object
- #using(destroyable) {|destroyable| ... } ⇒ Object
Constructor Details
#initialize(name) ⇒ CommandStatusIcon
Returns a new instance of CommandStatusIcon.
181 182 183 184 185 |
# File 'lib/iconify.rb', line 181 def initialize(name) super() @name = name end |
Instance Method Details
#draw_name(cr) ⇒ Object
220 221 222 223 224 225 226 227 |
# File 'lib/iconify.rb', line 220 def draw_name(cr) cr.save do cr.set_font_size(24) cr.move_to(3, 64 / 2 + cr.font_extents.ascent / 2) cr.set_source_rgba(*@foreground_color, 1) cr.show_text(@name) end end |
#fill_rounded_rectangle(cr) ⇒ Object
212 213 214 215 216 217 218 |
# File 'lib/iconify.rb', line 212 def fill_rounded_rectangle(cr) cr.save do cr.set_source_rgb(*@background_color) cr.rounded_rectangle(1, 1, 62, 62, 15) cr.fill end end |
#paint_background(cr) ⇒ Object
204 205 206 207 208 209 210 |
# File 'lib/iconify.rb', line 204 def paint_background(cr) cr.save do cr.set_source_rgb(0.8, 0.8, 0.8) cr.set_operator(OPERATOR_SOURCE) cr.paint end end |
#redraw ⇒ Object
229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/iconify.rb', line 229 def redraw using ImageSurface.new(FORMAT_ARGB32, 64, 64) do |surface| using Context.new(surface) do |cr| paint_background(cr) fill_rounded_rectangle(cr) draw_name(cr) end self.pixbuf = surface.to_pixbuf(0, 0, 64, 64) end end |
#update(state) ⇒ Object
192 193 194 195 196 197 |
# File 'lib/iconify.rb', line 192 def update(state) raise "unknown sate #{state}" unless COLOR_SCHEME.key?(state) @background_color, @foreground_color = COLOR_SCHEME[state] redraw end |
#using(destroyable) {|destroyable| ... } ⇒ Object
199 200 201 202 |
# File 'lib/iconify.rb', line 199 def using(destroyable) yield destroyable destroyable.destroy end |