Class: Demos::Forum::MusicBlock
- Inherits:
-
Hokusai::Block
- Object
- Hokusai::Block
- Demos::Forum::MusicBlock
- Defined in:
- ui/examples/forum/music.rb
Instance Attribute Summary collapse
-
#duration ⇒ Object
Returns the value of attribute duration.
-
#head ⇒ Object
Returns the value of attribute head.
-
#started ⇒ Object
Returns the value of attribute started.
-
#ticks ⇒ Object
Returns the value of attribute ticks.
Attributes inherited from Hokusai::Block
Instance Method Summary collapse
- #control ⇒ Object
-
#initialize(**args) ⇒ MusicBlock
constructor
A new instance of MusicBlock.
- #render(canvas) ⇒ Object
- #update_player(event) ⇒ Object
Methods inherited from Hokusai::Block
#children, #children?, compile, computed, computed!, #draw, #draw_with, #dump, #emit, inject, inject!, #method_missing, mount, #on_resize, provide, provides, style, styles_get, template, template_from_file, template_get, #update, use, uses
Constructor Details
#initialize(**args) ⇒ MusicBlock
Returns a new instance of MusicBlock.
18 19 20 21 22 23 24 |
# File 'ui/examples/forum/music.rb', line 18 def initialize(**args) super @started = false @duration = 300 @head = 0 @ticks = 0 end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Hokusai::Block
Instance Attribute Details
#duration ⇒ Object
Returns the value of attribute duration.
16 17 18 |
# File 'ui/examples/forum/music.rb', line 16 def duration @duration end |
#head ⇒ Object
Returns the value of attribute head.
16 17 18 |
# File 'ui/examples/forum/music.rb', line 16 def head @head end |
#started ⇒ Object
Returns the value of attribute started.
16 17 18 |
# File 'ui/examples/forum/music.rb', line 16 def started @started end |
#ticks ⇒ Object
Returns the value of attribute ticks.
16 17 18 |
# File 'ui/examples/forum/music.rb', line 16 def ticks @ticks end |
Instance Method Details
#control ⇒ Object
30 31 32 |
# File 'ui/examples/forum/music.rb', line 30 def control started ? "#{__dir__}/../assets/icons/media-playback-pause.png" : "#{__dir__}/../assets/icons/media-playback-start.png" end |
#render(canvas) ⇒ Object
34 35 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 62 63 64 65 66 67 68 69 70 71 72 |
# File 'ui/examples/forum/music.rb', line 34 def render(canvas) if started if self.ticks >= 60 self.head += 1 self.ticks = 0 end if head >= duration self.started = false self.head = 0 self.ticks = 0 end self.ticks += 1 end draw do start = canvas.x + 20 canvas.y += 6.0 padding = 4.0 # draw controls image(control, canvas.x, canvas.y, 15.0, 15.0) # draw line rect(start, canvas.y + 3.0 + padding, canvas.width, 2.0) do |command| command.color = Hokusai::Color.new(244,244,244) end # draw the playhead ix = head * canvas.width / duration rect(start + ix, canvas.y + padding, 2.0, 10.0) do |command| command.color = Hokusai::Color.new(244,244,244) end yield canvas end end |
#update_player(event) ⇒ Object
26 27 28 |
# File 'ui/examples/forum/music.rb', line 26 def update_player(event) self.started = true end |