Class: Iconify::CommandStatusIcon

Inherits:
Gtk::StatusIcon
  • Object
show all
Includes:
Gtk
Defined in:
lib/iconify.rb

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ CommandStatusIcon



80
81
82
83
84
# File 'lib/iconify.rb', line 80

def initialize(name)
  super()

  @name = name
end

Instance Method Details

#redrawObject



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/iconify.rb', line 100

def redraw
  # pixmap = Gdk::Pixmap.new(nil, 64, 64, 24)

  image_surface = Cairo::ImageSurface.new(Cairo::FORMAT_ARGB32, 64, 64)

  cr = Cairo::Context.new(image_surface)

  cr.set_source_rgb(0.8, 0.8, 0.8)
  cr.set_operator(Cairo::OPERATOR_SOURCE)
  cr.paint

  cr.set_source_rgb(*@background_color)
  cr.rounded_rectangle(1, 1, 62, 62, 15)
  cr.fill

  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)

  cr.destroy

  buf = image_surface.to_pixbuf(0, 0, 64, 64)
  self.pixbuf = buf

  image_surface.destroy
end

#set_state(state) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/iconify.rb', line 86

def set_state(state)
  case state
  when :running
    @background_color = [0.67, 1.0, 0.0]
    @foreground_color = [0.1, 0.1, 0.1]
  when :stopped
    @background_color = [192/255.0, 0.0, 0.0]
    @foreground_color = [0.9, 0.9, 0.9]
  else
    raise "unknown sate #{state}"
  end
  redraw
end