Class: Hokusai::Blocks::Cursor

Inherits:
Hokusai::Block show all
Defined in:
ui/src/hokusai/blocks/cursor.rb

Constant Summary collapse

DEFAULT_COLOR =
[255,0,0,244]

Instance Attribute Summary

Attributes inherited from Hokusai::Block

#node, #provides, #publisher

Instance Method Summary collapse

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) ⇒ Cursor

Returns a new instance of Cursor.



17
18
19
20
21
22
# File 'ui/src/hokusai/blocks/cursor.rb', line 17

def initialize(**args)
  @active = false
  @iteration = 0

  super(**args)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Hokusai::Block

Instance Method Details

#before_updatedObject



24
25
26
27
28
29
30
31
32
33
34
# File 'ui/src/hokusai/blocks/cursor.rb', line 24

def before_updated
  frames = speed * 30

  @active = @iteration < frames

  if @iteration >= 30
    @iteration = 0
  else
    @iteration += 1
  end
end

#render(canvas) {|canvas| ... } ⇒ Object

Yields:

  • (canvas)


36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'ui/src/hokusai/blocks/cursor.rb', line 36

def render(canvas)
  if show
    draw do
      if @active
        rect(x, y, cursor_width, cursor_height) do |command|
          command.color = color
        end
      end
    end
  end

  yield canvas
end