Class: Hokusai::Blocks::Titlebar::OSX

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

Constant Summary collapse

GREEN =
[38, 200, 75]
YELLOW =
[253, 189, 61]
RED =
[255, 92, 87]
DEFAULT =
[133, 133, 133]
DRAG =
[46,49,63]

Instance Attribute Summary collapse

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, #render, style, styles_get, template, template_from_file, template_get, #update, use, uses

Constructor Details

#initialize(**args) ⇒ OSX

Returns a new instance of OSX.



134
135
136
137
138
139
140
141
142
143
# File 'ui/src/hokusai/blocks/titlebar/osx.rb', line 134

def initialize(**args)
  super(**args)
  @hovered_red = false
  @hovered_yellow = false
  @hovered_green = false
  @moving = false
  @hovering = false
  @last_event = nil
  @maximized = false
end

Dynamic Method Handling

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

Instance Attribute Details

#hoveringObject

Returns the value of attribute hovering.



50
51
52
# File 'ui/src/hokusai/blocks/titlebar/osx.rb', line 50

def hovering
  @hovering
end

#last_eventObject

Returns the value of attribute last_event.



50
51
52
# File 'ui/src/hokusai/blocks/titlebar/osx.rb', line 50

def last_event
  @last_event
end

#maximizedObject

Returns the value of attribute maximized.



50
51
52
# File 'ui/src/hokusai/blocks/titlebar/osx.rb', line 50

def maximized
  @maximized
end

#movingObject

Returns the value of attribute moving.



50
51
52
# File 'ui/src/hokusai/blocks/titlebar/osx.rb', line 50

def moving
  @moving
end

Instance Method Details

#blur_green(_) ⇒ Object



106
107
108
# File 'ui/src/hokusai/blocks/titlebar/osx.rb', line 106

def blur_green(_)
  @hovered_green = false
end

#blur_red(_) ⇒ Object



98
99
100
# File 'ui/src/hokusai/blocks/titlebar/osx.rb', line 98

def blur_red(_)
  @hovered_red = false
end

#blur_yellow(_) ⇒ Object



102
103
104
# File 'ui/src/hokusai/blocks/titlebar/osx.rb', line 102

def blur_yellow(_)
  @hovered_yellow = false
end

#clear_hover(_) ⇒ Object



76
77
78
# File 'ui/src/hokusai/blocks/titlebar/osx.rb', line 76

def clear_hover(_)
  self.hovering = false
end

#close(_) ⇒ Object



80
81
82
# File 'ui/src/hokusai/blocks/titlebar/osx.rb', line 80

def close(_)
  Hokusai.close_window
end

#get_backgroundObject



52
53
54
# File 'ui/src/hokusai/blocks/titlebar/osx.rb', line 52

def get_background
  moving ? background_drag : background
end

#greenObject



130
131
132
# File 'ui/src/hokusai/blocks/titlebar/osx.rb', line 130

def green
  @hovered_green ? GREEN : unhovered_color
end

#handle_move(event) ⇒ Object



61
62
63
64
65
66
67
68
69
70
# File 'ui/src/hokusai/blocks/titlebar/osx.rb', line 61

def handle_move(event)
  if moving && event.left.down
    x = event.pos.x - last_event[0]
    y = event.pos.y - last_event[1]
    # pp ["set window", Time.now.strftime("%H:%M:%S %L")]
    Hokusai.set_window_position([x, y])
  else
    self.moving = false
  end
end

#handle_move_start(event) ⇒ Object



56
57
58
59
# File 'ui/src/hokusai/blocks/titlebar/osx.rb', line 56

def handle_move_start(event)
  self.last_event = [event.pos.x, event.pos.y] unless moving
  self.moving = true
end

#hover_green(_) ⇒ Object



118
119
120
# File 'ui/src/hokusai/blocks/titlebar/osx.rb', line 118

def hover_green(_)
  @hovered_green = true
end

#hover_red(_) ⇒ Object



110
111
112
# File 'ui/src/hokusai/blocks/titlebar/osx.rb', line 110

def hover_red(_)
  @hovered_red = true
end

#hover_yellow(_) ⇒ Object



114
115
116
# File 'ui/src/hokusai/blocks/titlebar/osx.rb', line 114

def hover_yellow(_)
  @hovered_yellow = true
end

#maximize(_) ⇒ Object



88
89
90
91
92
93
94
95
96
# File 'ui/src/hokusai/blocks/titlebar/osx.rb', line 88

def maximize(_)
  if maximized
    Hokusai.restore_window
    self.maximized = false
  else
    Hokusai.maximize_window
    self.maximized = true
  end
end

#minimize(_) ⇒ Object



84
85
86
# File 'ui/src/hokusai/blocks/titlebar/osx.rb', line 84

def minimize(_)
  Hokusai.minimize_window
end

#redObject



122
123
124
# File 'ui/src/hokusai/blocks/titlebar/osx.rb', line 122

def red
  @hovered_red ? RED : unhovered_color
end

#set_hover(_) ⇒ Object



72
73
74
# File 'ui/src/hokusai/blocks/titlebar/osx.rb', line 72

def set_hover(_)
  self.hovering = true
end

#yellowObject



126
127
128
# File 'ui/src/hokusai/blocks/titlebar/osx.rb', line 126

def yellow
  @hovered_yellow ? YELLOW : unhovered_color
end