Class: CyberarmEngine::Element
- Inherits:
-
Object
- Object
- CyberarmEngine::Element
show all
- Includes:
- Common, Event, Theme
- Defined in:
- lib/cyberarm_engine/ui/element.rb,
lib/cyberarm_engine/ui/elements/flow.rb,
lib/cyberarm_engine/ui/elements/image.rb,
lib/cyberarm_engine/ui/elements/label.rb,
lib/cyberarm_engine/ui/elements/stack.rb,
lib/cyberarm_engine/ui/elements/button.rb,
lib/cyberarm_engine/ui/elements/progress.rb,
lib/cyberarm_engine/ui/elements/check_box.rb,
lib/cyberarm_engine/ui/elements/container.rb,
lib/cyberarm_engine/ui/elements/edit_line.rb,
lib/cyberarm_engine/ui/elements/toggle_button.rb
Defined Under Namespace
Classes: Button, CheckBox, Container, EditLine, Flow, Image, Label, Progress, Stack, ToggleButton
Constant Summary
Constants included
from Theme
Theme::THEME
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Common
#current_state, #darken, #draw_rect, #fill, #get_asset, #get_image, #get_sample, #get_song, #lighten, #opacity, #pop_state, #previous_state, #push_state, #show_cursor, #show_cursor=, #window
Methods included from Event
#event, #publish, #subscribe, #unsubscribe
Methods included from Theme
#deep_merge, #default, #theme_defaults
Constructor Details
#initialize(options = {}, block = nil) ⇒ Element
Returns a new instance of Element.
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/cyberarm_engine/ui/element.rb', line 10
def initialize(options = {}, block = nil)
@parent = options.delete(:parent) options = theme_defaults(options)
@options = options
@block = block
@focus = false
@enabled = true
@visible = true
@style = Style.new(options)
@x = @style.x
@y = @style.y
@z = @style.z
@width = 0
@height = 0
@fixed_x = @x if @x != 0
@fixed_y = @y if @y != 0
@style.width = default(:width) || nil
@style.height = default(:height) || nil
@style.background_canvas = Background.new
@style.border_canvas = BorderCanvas.new(element: self)
stylize
default_events
end
|
Instance Attribute Details
#background_canvas ⇒ Object
Returns the value of attribute background_canvas.
8
9
10
|
# File 'lib/cyberarm_engine/ui/element.rb', line 8
def background_canvas
@background_canvas
end
|
#border_canvas ⇒ Object
Returns the value of attribute border_canvas.
8
9
10
|
# File 'lib/cyberarm_engine/ui/element.rb', line 8
def border_canvas
@border_canvas
end
|
#enabled ⇒ Object
Returns the value of attribute enabled.
7
8
9
|
# File 'lib/cyberarm_engine/ui/element.rb', line 7
def enabled
@enabled
end
|
#event_handler ⇒ Object
Returns the value of attribute event_handler.
8
9
10
|
# File 'lib/cyberarm_engine/ui/element.rb', line 8
def event_handler
@event_handler
end
|
#options ⇒ Object
Returns the value of attribute options.
8
9
10
|
# File 'lib/cyberarm_engine/ui/element.rb', line 8
def options
@options
end
|
#parent ⇒ Object
Returns the value of attribute parent.
8
9
10
|
# File 'lib/cyberarm_engine/ui/element.rb', line 8
def parent
@parent
end
|
#style ⇒ Object
Returns the value of attribute style.
8
9
10
|
# File 'lib/cyberarm_engine/ui/element.rb', line 8
def style
@style
end
|
#x ⇒ Object
Returns the value of attribute x.
7
8
9
|
# File 'lib/cyberarm_engine/ui/element.rb', line 7
def x
@x
end
|
#y ⇒ Object
Returns the value of attribute y.
7
8
9
|
# File 'lib/cyberarm_engine/ui/element.rb', line 7
def y
@y
end
|
#z ⇒ Object
Returns the value of attribute z.
7
8
9
|
# File 'lib/cyberarm_engine/ui/element.rb', line 7
def z
@z
end
|
Instance Method Details
#background=(_background) ⇒ Object
224
225
226
227
|
# File 'lib/cyberarm_engine/ui/element.rb', line 224
def background=(_background)
@style.background_canvas.background=(_background)
update_background
end
|
149
150
|
# File 'lib/cyberarm_engine/ui/element.rb', line 149
def button_down(id)
end
|
152
153
|
# File 'lib/cyberarm_engine/ui/element.rb', line 152
def button_up(id)
end
|
#content_height ⇒ Object
195
196
197
|
# File 'lib/cyberarm_engine/ui/element.rb', line 195
def content_height
@height
end
|
#content_width ⇒ Object
171
172
173
|
# File 'lib/cyberarm_engine/ui/element.rb', line 171
def content_width
@width
end
|
#default_events ⇒ Object
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
# File 'lib/cyberarm_engine/ui/element.rb', line 97
def default_events
[:left, :middle, :right].each do |button|
event(:"#{button}_mouse_button")
event(:"released_#{button}_mouse_button")
event(:"clicked_#{button}_mouse_button")
event(:"holding_#{button}_mouse_button")
end
event(:mouse_wheel_up)
event(:mouse_wheel_down)
event(:enter)
event(:hover)
event(:leave)
event(:blur)
end
|
#draw ⇒ Object
138
139
140
141
142
143
144
|
# File 'lib/cyberarm_engine/ui/element.rb', line 138
def draw
return unless @visible
@style.background_canvas.draw
@style.border_canvas.draw
render
end
|
#enabled? ⇒ Boolean
115
116
117
|
# File 'lib/cyberarm_engine/ui/element.rb', line 115
def enabled?
@enabled
end
|
#height ⇒ Object
187
188
189
190
191
192
193
|
# File 'lib/cyberarm_engine/ui/element.rb', line 187
def height
if visible?
inner_height + @height
else
0
end
end
|
#hide ⇒ Object
133
134
135
136
|
# File 'lib/cyberarm_engine/ui/element.rb', line 133
def hide
@visible = false
root.gui_state.request_recalculate
end
|
#hit?(x, y) ⇒ Boolean
158
159
160
161
|
# File 'lib/cyberarm_engine/ui/element.rb', line 158
def hit?(x, y)
x.between?(@x, @x + width) &&
y.between?(@y, @y + height)
end
|
#inner_height ⇒ Object
207
208
209
|
# File 'lib/cyberarm_engine/ui/element.rb', line 207
def inner_height
(@style.border_thickness_top + @style.padding_top) + (@style.padding_bottom + @style.border_thickness_bottom)
end
|
#inner_width ⇒ Object
183
184
185
|
# File 'lib/cyberarm_engine/ui/element.rb', line 183
def inner_width
(@style.border_thickness_left + @style.padding_left) + (@style.padding_right + @style.border_thickness_right)
end
|
#is_root? ⇒ Boolean
257
258
259
|
# File 'lib/cyberarm_engine/ui/element.rb', line 257
def is_root?
@gui_state != nil
end
|
#noncontent_height ⇒ Object
199
200
201
|
# File 'lib/cyberarm_engine/ui/element.rb', line 199
def noncontent_height
(inner_height + outer_height) - height
end
|
#noncontent_width ⇒ Object
175
176
177
|
# File 'lib/cyberarm_engine/ui/element.rb', line 175
def noncontent_width
(inner_width + outer_width) - width
end
|
#outer_height ⇒ Object
203
204
205
|
# File 'lib/cyberarm_engine/ui/element.rb', line 203
def outer_height
@style.margin_top + height + @style.margin_bottom
end
|
#outer_width ⇒ Object
179
180
181
|
# File 'lib/cyberarm_engine/ui/element.rb', line 179
def outer_width
@style.margin_left + width + @style.margin_right
end
|
#recalculate ⇒ Object
261
262
263
|
# File 'lib/cyberarm_engine/ui/element.rb', line 261
def recalculate
raise "#{self.class}#recalculate was not overridden!"
end
|
#render ⇒ Object
155
156
|
# File 'lib/cyberarm_engine/ui/element.rb', line 155
def render
end
|
#reposition ⇒ Object
265
266
|
# File 'lib/cyberarm_engine/ui/element.rb', line 265
def reposition
end
|
#root ⇒ Object
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
|
# File 'lib/cyberarm_engine/ui/element.rb', line 241
def root
unless @root && @root.parent.nil?
@root = parent
loop do
if @root.parent.nil?
break
else
@root = @root.parent
end
end
end
@root
end
|
#set_background(background) ⇒ Object
54
55
56
57
|
# File 'lib/cyberarm_engine/ui/element.rb', line 54
def set_background(background)
@style.background = background
@style.background_canvas.background = background
end
|
#set_border_color(color) ⇒ Object
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/cyberarm_engine/ui/element.rb', line 68
def set_border_color(color)
@style.border_color = color
@style.border_color_left = default(:border_color_left) || @style.border_color
@style.border_color_right = default(:border_color_right) || @style.border_color
@style.border_color_top = default(:border_color_top) || @style.border_color
@style.border_color_bottom = default(:border_color_bottom) || @style.border_color
@style.border_canvas.color = color
end
|
#set_border_thickness(border_thickness) ⇒ Object
59
60
61
62
63
64
65
66
|
# File 'lib/cyberarm_engine/ui/element.rb', line 59
def set_border_thickness(border_thickness)
@style.border_thickness = border_thickness
@style.border_thickness_left = default(:border_thickness_left) || @style.border_thickness
@style.border_thickness_right = default(:border_thickness_right) || @style.border_thickness
@style.border_thickness_top = default(:border_thickness_top) || @style.border_thickness
@style.border_thickness_bottom = default(:border_thickness_bottom) || @style.border_thickness
end
|
#set_margin(margin) ⇒ Object
88
89
90
91
92
93
94
95
|
# File 'lib/cyberarm_engine/ui/element.rb', line 88
def set_margin(margin)
@style.margin = margin
@style.margin_left = default(:margin_left) || @style.margin
@style.margin_right = default(:margin_right) || @style.margin
@style.margin_top = default(:margin_top) || @style.margin
@style.margin_bottom = default(:margin_bottom) || @style.margin
end
|
#set_padding(padding) ⇒ Object
79
80
81
82
83
84
85
86
|
# File 'lib/cyberarm_engine/ui/element.rb', line 79
def set_padding(padding)
@style.padding = padding
@style.padding_left = default(:padding_left) || @style.padding
@style.padding_right = default(:padding_right) || @style.padding
@style.padding_top = default(:padding_top) || @style.padding
@style.padding_bottom = default(:padding_bottom) || @style.padding
end
|
#show ⇒ Object
128
129
130
131
|
# File 'lib/cyberarm_engine/ui/element.rb', line 128
def show
@visible = true
root.gui_state.request_recalculate
end
|
#stylize ⇒ Object
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/cyberarm_engine/ui/element.rb', line 43
def stylize
set_border_thickness(@style.border_thickness)
set_padding(@style.padding)
set_margin(@style.margin)
set_background(@style.background)
set_border_color(@style.border_color)
end
|
#toggle ⇒ Object
123
124
125
126
|
# File 'lib/cyberarm_engine/ui/element.rb', line 123
def toggle
@visible = !@visible
root.gui_state.request_recalculate
end
|
#update ⇒ Object
146
147
|
# File 'lib/cyberarm_engine/ui/element.rb', line 146
def update
end
|
#update_background ⇒ Object
229
230
231
232
233
234
235
236
237
238
239
|
# File 'lib/cyberarm_engine/ui/element.rb', line 229
def update_background
@style.background_canvas.x = @x
@style.background_canvas.y = @y
@style.background_canvas.z = @z
@style.background_canvas.width = width
@style.background_canvas.height = height
@style.background_canvas.update
@style.border_canvas.update
end
|
#value ⇒ Object
268
269
270
|
# File 'lib/cyberarm_engine/ui/element.rb', line 268
def value
raise "#{self.class}#value was not overridden!"
end
|
#value=(value) ⇒ Object
272
273
274
|
# File 'lib/cyberarm_engine/ui/element.rb', line 272
def value=(value)
raise "#{self.class}#value= was not overridden!"
end
|
#visible? ⇒ Boolean
119
120
121
|
# File 'lib/cyberarm_engine/ui/element.rb', line 119
def visible?
@visible
end
|
#width ⇒ Object
163
164
165
166
167
168
169
|
# File 'lib/cyberarm_engine/ui/element.rb', line 163
def width
if visible?
inner_width + @width
else
0
end
end
|