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/radio.rb,
lib/cyberarm_engine/ui/elements/stack.rb,
lib/cyberarm_engine/ui/elements/button.rb,
lib/cyberarm_engine/ui/elements/slider.rb,
lib/cyberarm_engine/ui/elements/edit_box.rb,
lib/cyberarm_engine/ui/elements/list_box.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, EditBox, EditLine, Flow, Image, Label, ListBox, Progress, Radio, Slider, 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
42
|
# 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
@tip = @options[:tip] ? @options[:tip] : ""
@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
|
#tip ⇒ Object
Returns the value of attribute tip.
7
8
9
|
# File 'lib/cyberarm_engine/ui/element.rb', line 7
def tip
@tip
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
231
232
233
234
|
# File 'lib/cyberarm_engine/ui/element.rb', line 231
def background=(_background)
@style.background_canvas.background=(_background)
update_background
end
|
152
153
|
# File 'lib/cyberarm_engine/ui/element.rb', line 152
def button_down(id)
end
|
155
156
|
# File 'lib/cyberarm_engine/ui/element.rb', line 155
def button_up(id)
end
|
#content_height ⇒ Object
202
203
204
|
# File 'lib/cyberarm_engine/ui/element.rb', line 202
def content_height
@height
end
|
#content_width ⇒ Object
178
179
180
|
# File 'lib/cyberarm_engine/ui/element.rb', line 178
def content_width
@width
end
|
#default_events ⇒ Object
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
# File 'lib/cyberarm_engine/ui/element.rb', line 98
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)
event(:changed)
end
|
#draggable?(button) ⇒ Boolean
158
159
160
|
# File 'lib/cyberarm_engine/ui/element.rb', line 158
def draggable?(button)
false
end
|
#draw ⇒ Object
141
142
143
144
145
146
147
|
# File 'lib/cyberarm_engine/ui/element.rb', line 141
def draw
return unless @visible
@style.background_canvas.draw
@style.border_canvas.draw
render
end
|
#enabled? ⇒ Boolean
118
119
120
|
# File 'lib/cyberarm_engine/ui/element.rb', line 118
def enabled?
@enabled
end
|
#height ⇒ Object
194
195
196
197
198
199
200
|
# File 'lib/cyberarm_engine/ui/element.rb', line 194
def height
if visible?
inner_height + @height
else
0
end
end
|
#hide ⇒ Object
136
137
138
139
|
# File 'lib/cyberarm_engine/ui/element.rb', line 136
def hide
@visible = false
root.gui_state.request_recalculate
end
|
#hit?(x, y) ⇒ Boolean
165
166
167
168
|
# File 'lib/cyberarm_engine/ui/element.rb', line 165
def hit?(x, y)
x.between?(@x, @x + width) &&
y.between?(@y, @y + height)
end
|
#inner_height ⇒ Object
214
215
216
|
# File 'lib/cyberarm_engine/ui/element.rb', line 214
def inner_height
(@style.border_thickness_top + @style.padding_top) + (@style.padding_bottom + @style.border_thickness_bottom)
end
|
#inner_width ⇒ Object
190
191
192
|
# File 'lib/cyberarm_engine/ui/element.rb', line 190
def inner_width
(@style.border_thickness_left + @style.padding_left) + (@style.padding_right + @style.border_thickness_right)
end
|
#is_root? ⇒ Boolean
266
267
268
|
# File 'lib/cyberarm_engine/ui/element.rb', line 266
def is_root?
@gui_state != nil
end
|
#noncontent_height ⇒ Object
206
207
208
|
# File 'lib/cyberarm_engine/ui/element.rb', line 206
def noncontent_height
(inner_height + outer_height) - height
end
|
#noncontent_width ⇒ Object
182
183
184
|
# File 'lib/cyberarm_engine/ui/element.rb', line 182
def noncontent_width
(inner_width + outer_width) - width
end
|
#outer_height ⇒ Object
210
211
212
|
# File 'lib/cyberarm_engine/ui/element.rb', line 210
def outer_height
@style.margin_top + height + @style.margin_bottom
end
|
#outer_width ⇒ Object
186
187
188
|
# File 'lib/cyberarm_engine/ui/element.rb', line 186
def outer_width
@style.margin_left + width + @style.margin_right
end
|
#recalculate ⇒ Object
270
271
272
|
# File 'lib/cyberarm_engine/ui/element.rb', line 270
def recalculate
raise "#{self.class}#recalculate was not overridden!"
end
|
#render ⇒ Object
162
163
|
# File 'lib/cyberarm_engine/ui/element.rb', line 162
def render
end
|
#reposition ⇒ Object
274
275
|
# File 'lib/cyberarm_engine/ui/element.rb', line 274
def reposition
end
|
#root ⇒ Object
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
|
# File 'lib/cyberarm_engine/ui/element.rb', line 248
def root
return self if is_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
55
56
57
58
|
# File 'lib/cyberarm_engine/ui/element.rb', line 55
def set_background(background)
@style.background = background
@style.background_canvas.background = background
end
|
#set_border_color(color) ⇒ Object
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/cyberarm_engine/ui/element.rb', line 69
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
60
61
62
63
64
65
66
67
|
# File 'lib/cyberarm_engine/ui/element.rb', line 60
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
89
90
91
92
93
94
95
96
|
# File 'lib/cyberarm_engine/ui/element.rb', line 89
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
80
81
82
83
84
85
86
87
|
# File 'lib/cyberarm_engine/ui/element.rb', line 80
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
131
132
133
134
|
# File 'lib/cyberarm_engine/ui/element.rb', line 131
def show
@visible = true
root.gui_state.request_recalculate
end
|
#stylize ⇒ Object
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/cyberarm_engine/ui/element.rb', line 44
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
|
#to_s ⇒ Object
285
286
287
|
# File 'lib/cyberarm_engine/ui/element.rb', line 285
def to_s
"#{self.class} x=#{x} y=#{y} width=#{width} height=#{height} value=#{ value.is_a?(String) ? "\"#{value}\"" : value }"
end
|
#toggle ⇒ Object
126
127
128
129
|
# File 'lib/cyberarm_engine/ui/element.rb', line 126
def toggle
@visible = !@visible
root.gui_state.request_recalculate
end
|
#update ⇒ Object
149
150
|
# File 'lib/cyberarm_engine/ui/element.rb', line 149
def update
end
|
#update_background ⇒ Object
236
237
238
239
240
241
242
243
244
245
246
|
# File 'lib/cyberarm_engine/ui/element.rb', line 236
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
277
278
279
|
# File 'lib/cyberarm_engine/ui/element.rb', line 277
def value
raise "#{self.class}#value was not overridden!"
end
|
#value=(value) ⇒ Object
281
282
283
|
# File 'lib/cyberarm_engine/ui/element.rb', line 281
def value=(value)
raise "#{self.class}#value= was not overridden!"
end
|
#visible? ⇒ Boolean
122
123
124
|
# File 'lib/cyberarm_engine/ui/element.rb', line 122
def visible?
@visible
end
|
#width ⇒ Object
170
171
172
173
174
175
176
|
# File 'lib/cyberarm_engine/ui/element.rb', line 170
def width
if visible?
inner_width + @width
else
0
end
end
|