Class: Reight::Navigator

Inherits:
Object
  • Object
show all
Defined in:
lib/reight/app/navigator.rb

Defined Under Namespace

Classes: Message

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Navigator

Returns a new instance of Navigator.



6
7
8
# File 'lib/reight/app/navigator.rb', line 6

def initialize(app)
  @app, @visible = app, true
end

Instance Method Details

#drawObject



25
26
27
28
29
30
31
# File 'lib/reight/app/navigator.rb', line 25

def draw()
  return unless visible?
  fill 220
  no_stroke
  rect 0, 0, width, Reight::App::NAVIGATOR_HEIGHT
  sprite(*sprites)
end

#flashObject



10
# File 'lib/reight/app/navigator.rb', line 10

def flash(...) = message.flash(...)

#key_pressedObject



33
34
35
36
# File 'lib/reight/app/navigator.rb', line 33

def key_pressed()
  index = [F1, F2, F3, F4, F5].index(key_code)
  app_buttons[index]&.click if index
end

#spritesObject



20
21
22
23
# File 'lib/reight/app/navigator.rb', line 20

def sprites()
  [*app_buttons, *history_buttons, *edit_buttons, message]
    .map &:sprite
end

#visible=(visible) ⇒ Object



12
13
14
15
16
# File 'lib/reight/app/navigator.rb', line 12

def visible=(visible)
  return if visible == @visible
  @visible = visible
  sprites.each {|sp| visible ? sp.show : sp.hide}
end

#visible?Boolean

Returns:

  • (Boolean)


18
# File 'lib/reight/app/navigator.rb', line 18

def visible? = @visible

#window_resizedObject



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
73
74
75
# File 'lib/reight/app/navigator.rb', line 38

def window_resized()
  [app_buttons, history_buttons, edit_buttons]
    .flatten.map(&:sprite).each do |sp|
      sp.w = sp.h = Reight::App::NAVIGATOR_HEIGHT
      sp.y = 0
    end

  space = Reight::App::SPACE
  x     = space

  app_buttons.map {_1.sprite}.each do |sp|
    sp.x = x + 1
    x    = sp.right
  end.tap do
    x += space unless _1.empty?
  end

  history_buttons.map {_1.sprite}.each do |sp|
    sp.x = x + 1
    x    = sp.right
  end.tap do
    x += space unless _1.empty?
  end

  edit_buttons.map {_1.sprite}.each do |sp|
    sp.x = x + 1
    x    = sp.right
  end.tap do
    x += space unless _1.empty?
  end

  message.sprite.tap do |sp|
    sp.x     = x + space
    sp.y     = 0
    sp.h     = Reight::App::NAVIGATOR_HEIGHT
    sp.right = width - space
  end
end