Class: Ektoplayer::Views::PlayingInfo

Inherits:
UI::Window show all
Defined in:
lib/ektoplayer/views/playinginfo.rb

Constant Summary collapse

STOPPED_HEADING =
'- Ektoplayer -'.freeze

Instance Attribute Summary

Attributes inherited from UI::Window

#win

Attributes inherited from UI::Widget

#pos, #size

Instance Method Summary collapse

Methods inherited from UI::Window

#initialize, #layout, #noutrefresh, #refresh

Methods inherited from UI::Widget

#display, #events, #initialize, #invisible!, #invisible?, #key_press, #keys, #layout, #lock, #mouse, #mouse_click, #mouse_event_transform, #mouse_section, #on_key_press, #on_widget_raise, #raise_widget, #refresh, #sub, #unlock, #visible!, #visible=, #visible?, #want_layout, #want_redraw, #want_refresh, #with_lock

Constructor Details

This class inherits a constructor from UI::Window

Instance Method Details

#attach(playlist, player) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/ektoplayer/views/playinginfo.rb', line 36

def attach(playlist, player)
   player.events.on(:pause)  { self.paused!  }
   player.events.on(:stop)   { self.stopped! }
   player.events.on(:play)   { self.playing! }

   player.events.on(:position_change) do
      old_pos, old_length = @position, @length
      @position = player.position.to_i
      @length = player.length.to_i

      if old_pos != @position or old_length != @length
         if visible?
            draw_position_and_length 
            refresh
         end
      end
   end

   playlist.events.on(:current_changed) {
      self.track=(playlist[playlist.current_playing])
   }

   self.mouse.on(ICurses::BUTTON1_CLICKED) do |mevent|
      player.toggle
   end
end

#drawObject



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/ektoplayer/views/playinginfo.rb', line 81

def draw
   @win.erase
   draw_position_and_length

   if ICurses.colors == 256
      top_format = Config[:'playinginfo.format_top_256']
      bottom_format = Config[:'playinginfo.format_bottom_256']
   else
      top_format = Config[:'playinginfo.format_top']
      bottom_format = Config[:'playinginfo.format_bottom']
   end
   
   if @track
      fill(top_format).each_with_index do |fmt,i|
         @win.center(fmt[:sum]) if i == 0
         @win.attrset(UI::Colors.set(nil, *fmt[:curses_attrs]))
         @win << fmt[:filled]
      end

      @win.attrset(Theme[:'playinginfo.state'])
      @win.from_right(@state.to_s.size + 2) << "[#{@state}]"

      @win.next_line

      fill(bottom_format).each_with_index do |fmt,i|
         @win.center(fmt[:sum]) if i == 0
         @win.attrset(UI::Colors.set(nil, *fmt[:curses_attrs]))
         @win << fmt[:filled]
      end
   else
      @win.attrset(0)
      @win.center_string(STOPPED_HEADING)
      @win.attrset(Theme[:'playinginfo.state'])
      @win.from_right(9) << '[stopped]'
   end

   #@win.next_line.addstr('~' * @size.width)
end

#draw_position_and_lengthObject



31
32
33
34
# File 'lib/ektoplayer/views/playinginfo.rb', line 31

def draw_position_and_length
   @win.attrset(Theme[:'playinginfo.position'])
   @win.mvaddstr(0, 0, "[#{Common::to_time(@position)}/#{Common::to_time(@length)}]")
end

#paused!Object



11
12
13
14
# File 'lib/ektoplayer/views/playinginfo.rb', line 11

def paused!
   return if @state == :paused
   with_lock { @state = :paused; want_redraw }
end

#playing!Object



16
17
18
19
# File 'lib/ektoplayer/views/playinginfo.rb', line 16

def playing!
   return if @state == :playing
   with_lock { @state = :playing; want_redraw }
end

#stopped!Object



21
22
23
24
# File 'lib/ektoplayer/views/playinginfo.rb', line 21

def stopped!
   return if @state == :stopped
   with_lock { @state = :stopped; @position = 0; want_redraw }
end

#track=(t) ⇒ Object



26
27
28
29
# File 'lib/ektoplayer/views/playinginfo.rb', line 26

def track=(t)
   return if @track == t
   with_lock { @track = t; want_redraw }
end