savio 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- metadata +7 -30
- data/.DS_Store +0 -0
- data/.gitignore +0 -8
- data/Gemfile +0 -6
- data/LICENSE.txt +0 -21
- data/README.md +0 -261
- data/Rakefile +0 -2
- data/bin/console +0 -14
- data/bin/setup +0 -8
- data/lib/.DS_Store +0 -0
- data/lib/savio/Button.rb +0 -253
- data/lib/savio/ButtonManager.rb +0 -106
- data/lib/savio/ColorSlider.rb +0 -224
- data/lib/savio/Colors.rb +0 -13
- data/lib/savio/IORenderable.rb +0 -127
- data/lib/savio/InputBox.rb +0 -163
- data/lib/savio/Scene.rb +0 -55
- data/lib/savio/Slider.rb +0 -195
- data/lib/savio/hsv2rgb.rb +0 -78
- data/lib/savio/io.rb +0 -250
- data/lib/savio/version.rb +0 -3
- data/lib/savio.rb +0 -82
- data/savio.gemspec +0 -26
- data/test.rb +0 -9
data/lib/savio/ButtonManager.rb
DELETED
@@ -1,106 +0,0 @@
|
|
1
|
-
module Savio
|
2
|
-
class ButtonManager
|
3
|
-
attr_reader :selected, :buttons
|
4
|
-
|
5
|
-
@@buttonManagers = []
|
6
|
-
def self.buttonManagers
|
7
|
-
@@buttonManagers
|
8
|
-
end
|
9
|
-
|
10
|
-
def initialize(args = {})
|
11
|
-
@@buttonManagers.push(self)
|
12
|
-
|
13
|
-
@buttons = []
|
14
|
-
@selected = []
|
15
|
-
|
16
|
-
@type = args[:type] || 'radio'
|
17
|
-
|
18
|
-
if @type != 'checkbox' && @type != 'radio'
|
19
|
-
raise ArgumentError, 'ButtonManager type ' + @type.to_s + ' is invalid. Must be radio or checkbox'
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
def type=(type)
|
25
|
-
if type == 'radio' || type == "checkbox"
|
26
|
-
@type = type
|
27
|
-
else
|
28
|
-
raise ArgumentError, 'ButtonManager type ' + type.to_s + ' is invalid. Must be radio or checkbox'
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def addButton(button)
|
33
|
-
if button.class.name != 'Savio::Button'
|
34
|
-
raise ArgumentError, 'Given object ' + button.to_s + ' is not a Button. Must be of type Button'
|
35
|
-
end
|
36
|
-
button.deselect(false)
|
37
|
-
@buttons.push(button)
|
38
|
-
if button.buttonManager != self
|
39
|
-
button.buttonManager = self
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def removeButton(button, overwrite = true)
|
44
|
-
if @buttons.include?(button)
|
45
|
-
@buttons.delete(button)
|
46
|
-
if @selected.include?(button)
|
47
|
-
@selected.delete(button)
|
48
|
-
end
|
49
|
-
if overwrite == true
|
50
|
-
button.buttonManager = nil
|
51
|
-
end
|
52
|
-
else
|
53
|
-
raise ArgumentError, ('Could not find button ' + button.to_s + ' in buttonManager')
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def toggle(button)
|
58
|
-
if @buttons.include?(button)
|
59
|
-
if @type == 'checkbox'
|
60
|
-
if button.selected
|
61
|
-
deselect(button)
|
62
|
-
else
|
63
|
-
select(button)
|
64
|
-
end
|
65
|
-
elsif @type == 'radio'
|
66
|
-
select(button)
|
67
|
-
end
|
68
|
-
else
|
69
|
-
raise ArgumentError, ('Could not find button ' + button.to_s + ' in buttonManager')
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def select(button)
|
74
|
-
if @buttons.include?(button)
|
75
|
-
if @type == 'checkbox'
|
76
|
-
@selected.push(button)
|
77
|
-
button.select(false)
|
78
|
-
elsif @type == 'radio'
|
79
|
-
@buttons.each do |i|
|
80
|
-
i.deselect(false)
|
81
|
-
end
|
82
|
-
@selected.clear
|
83
|
-
@selected.push(button)
|
84
|
-
button.select(false)
|
85
|
-
end
|
86
|
-
else
|
87
|
-
raise ArgumentError, ('Could not find button ' + button.to_s + ' in buttonManager')
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
def deselect(button)
|
92
|
-
if @buttons.include?(button)
|
93
|
-
if @type == 'checkbox'
|
94
|
-
@selected.delete(button)
|
95
|
-
button.deselect(false)
|
96
|
-
elsif @type == 'radio'
|
97
|
-
@selected.delete(button)
|
98
|
-
button.deselect(false)
|
99
|
-
end
|
100
|
-
else
|
101
|
-
raise ArgumentError, ('Could not find button ' + button.to_s + ' in buttonManager')
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
end
|
106
|
-
end
|
data/lib/savio/ColorSlider.rb
DELETED
@@ -1,224 +0,0 @@
|
|
1
|
-
module Savio
|
2
|
-
class ColorSlider
|
3
|
-
include IORenderable
|
4
|
-
|
5
|
-
attr_reader :baseColor, :knobColor, :textColor, :sectors, :optionsShown, :animating
|
6
|
-
|
7
|
-
@@colorSliders = []
|
8
|
-
def self.colorSliders
|
9
|
-
@@colorSliders
|
10
|
-
end
|
11
|
-
|
12
|
-
def initialize(args = {})
|
13
|
-
args[:size] = args[:size] || 80
|
14
|
-
super(args)
|
15
|
-
@@colorSliders.push(self)
|
16
|
-
|
17
|
-
@color = args[:color] || HsvColor.new(rand(0..360), rand(0.0..1.0),rand(0.0..1.0))
|
18
|
-
@hue = @color[0]
|
19
|
-
|
20
|
-
@baseColor = args[:baseColor] || Savio::Colors::White
|
21
|
-
@knobColor = args[:baseColor] || Savio::Colors::Gray
|
22
|
-
@textColor = args[:textColor] || Savio::Colors::Black
|
23
|
-
@sectors = args[:sectors] || 64
|
24
|
-
|
25
|
-
@optionsShown = false
|
26
|
-
@steps = 0
|
27
|
-
@animating = false
|
28
|
-
|
29
|
-
@radiusStep = 0
|
30
|
-
@yStep = 0
|
31
|
-
|
32
|
-
build()
|
33
|
-
end
|
34
|
-
|
35
|
-
def baseColor=(c)
|
36
|
-
@baseColor = c
|
37
|
-
rebuild()
|
38
|
-
end
|
39
|
-
def knobColor=(c)
|
40
|
-
@knob.color = c
|
41
|
-
end
|
42
|
-
def textColor=(c)
|
43
|
-
@textColor = c
|
44
|
-
rebuild()
|
45
|
-
end
|
46
|
-
|
47
|
-
def remove()
|
48
|
-
super()
|
49
|
-
@innerCircle.remove
|
50
|
-
@outerCircle.remove
|
51
|
-
@knob.remove
|
52
|
-
@saturationSlider.remove
|
53
|
-
@valueSlider.remove
|
54
|
-
end
|
55
|
-
|
56
|
-
def add()
|
57
|
-
super()
|
58
|
-
@innerCircle.add
|
59
|
-
@outerCircle.add
|
60
|
-
@knob.add
|
61
|
-
@saturationSlider.add
|
62
|
-
@valueSlider.add
|
63
|
-
end
|
64
|
-
|
65
|
-
def animate()
|
66
|
-
animatorThread = Thread.new do
|
67
|
-
12.times do
|
68
|
-
sleep(1 / 60)
|
69
|
-
@steps += 1
|
70
|
-
@innerCircle.radius += @radiusStep
|
71
|
-
@innerCircle.y += @yStep
|
72
|
-
if @steps >= 12
|
73
|
-
@steps = 0
|
74
|
-
@radiusStep = 0
|
75
|
-
@yStep = 0
|
76
|
-
@animating = false
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
def calculateStep(desire, start, steps)
|
83
|
-
delta = desire.to_f - start.to_f
|
84
|
-
step = delta/steps
|
85
|
-
return step
|
86
|
-
end
|
87
|
-
|
88
|
-
def showOptions()
|
89
|
-
if @optionsShown == false
|
90
|
-
@optionsShown = true
|
91
|
-
|
92
|
-
@steps = 0
|
93
|
-
@radiusStep = 0
|
94
|
-
@yStep = 0
|
95
|
-
@animating = false
|
96
|
-
|
97
|
-
@radiusStep = calculateStep(0.25 * @size, @innerCircle.radius, 12)
|
98
|
-
@yStep = calculateStep(@y - @size + 0.35 * @size, @innerCircle.y, 12)
|
99
|
-
@animating = true
|
100
|
-
animate()
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
def hideOptions()
|
105
|
-
if @optionsShown == true
|
106
|
-
@optionsShown = false
|
107
|
-
|
108
|
-
@steps = 0
|
109
|
-
@radiusStep = 0
|
110
|
-
@yStep = 0
|
111
|
-
@animating = false
|
112
|
-
|
113
|
-
@radiusStep = calculateStep(@size * 0.95, @innerCircle.radius, 12)
|
114
|
-
@yStep = calculateStep(@y, @innerCircle.y, 12)
|
115
|
-
@animating = true
|
116
|
-
animate()
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
def setValue(angle)
|
121
|
-
@knob.x = (@size).to_f * Math.cos((angle.to_f % 360.0) * Math::PI/180.0) + @x.to_f
|
122
|
-
@knob.y = (@size).to_f * Math.sin((angle.to_f % 360.0) * Math::PI/180.0) + @y.to_f
|
123
|
-
|
124
|
-
@color = HsvColor.new(angle % 360, @saturationSlider.value, @valueSlider.value)
|
125
|
-
@hue = @color[0]
|
126
|
-
|
127
|
-
rgb = RgbColor.newFromHSV(@color)
|
128
|
-
@innerCircle.color.r = rgb[0]
|
129
|
-
@innerCircle.color.g = rgb[1]
|
130
|
-
@innerCircle.color.b = rgb[2]
|
131
|
-
end
|
132
|
-
|
133
|
-
def rgb()
|
134
|
-
return RgbColor.newFromHSV(@color)
|
135
|
-
end
|
136
|
-
|
137
|
-
def hsv()
|
138
|
-
return HsvColor.new(@color[0],@color[1],@color[2])
|
139
|
-
end
|
140
|
-
|
141
|
-
def hex()
|
142
|
-
rgb = RgbColor.newFromHSV(@color)
|
143
|
-
return ("#%02x%02x%02x" % [rgb[0]*255,rgb[1]*255,rgb[2]*255])
|
144
|
-
end
|
145
|
-
|
146
|
-
def chord(placement)
|
147
|
-
margin = 20
|
148
|
-
height = @size * placement
|
149
|
-
angle = 2 * Math.acos( 1.0 - height / @size.to_f)
|
150
|
-
angle = angle * 180/Math::PI
|
151
|
-
chord = 2 * Math.sqrt(2 * @size * height - height**2)
|
152
|
-
adjust = (@size * 2 - chord) / 2
|
153
|
-
return Struct.new(:margin, :height, :angle, :chord, :adjust).new(margin,height,angle,chord,adjust)
|
154
|
-
end
|
155
|
-
|
156
|
-
def build()
|
157
|
-
@shown = true
|
158
|
-
|
159
|
-
@innerCircle = Circle.new(
|
160
|
-
x: @x, y: @y,
|
161
|
-
radius: @size * 0.95,
|
162
|
-
color: 'black',
|
163
|
-
z: @z + 4,
|
164
|
-
sectors: @sectors
|
165
|
-
)
|
166
|
-
|
167
|
-
@outerCircle = Circle.new(
|
168
|
-
x: @x, y: @y,
|
169
|
-
radius: @size,
|
170
|
-
color: @baseColor,
|
171
|
-
z: @z,
|
172
|
-
sectors: @sectors
|
173
|
-
)
|
174
|
-
|
175
|
-
@knob = Circle.new(
|
176
|
-
x: @x + @size, y: @y,
|
177
|
-
radius: @size * 0.15,
|
178
|
-
color: @knobColor,
|
179
|
-
z: @z + 5,
|
180
|
-
sectors: @sectors
|
181
|
-
)
|
182
|
-
|
183
|
-
placement = chord(1.0)
|
184
|
-
@saturationSlider = Slider.new(
|
185
|
-
displayName: "Saturation",
|
186
|
-
labelColor: @textColor,
|
187
|
-
x:@x - @size + placement.adjust + placement.margin,
|
188
|
-
y:@y - @size + placement.height,
|
189
|
-
z:@z + 1,
|
190
|
-
min:0.0,
|
191
|
-
max:1.0,
|
192
|
-
length:(placement.chord - placement.margin * 2),
|
193
|
-
size: @size * 0.06,
|
194
|
-
showValue: false
|
195
|
-
)
|
196
|
-
|
197
|
-
placement = chord(1.3)
|
198
|
-
@valueSlider = Slider.new(
|
199
|
-
displayName: "Value",
|
200
|
-
labelColor: @textColor,
|
201
|
-
x:@x - @size + placement.adjust + placement.margin,
|
202
|
-
y:@y - @size + placement.height,
|
203
|
-
z: @z + 1,
|
204
|
-
min:0.0,
|
205
|
-
max:1.0,
|
206
|
-
length:(placement.chord - placement.margin * 2),
|
207
|
-
size: @size * 0.06,
|
208
|
-
showValue: false
|
209
|
-
)
|
210
|
-
@valueSlider.showValue=false
|
211
|
-
@saturationSlider.showValue=false
|
212
|
-
|
213
|
-
@valueSlider.onChange do
|
214
|
-
setValue(@hue)
|
215
|
-
end
|
216
|
-
|
217
|
-
@saturationSlider.onChange do
|
218
|
-
setValue(@hue)
|
219
|
-
end
|
220
|
-
|
221
|
-
setValue(@hue)
|
222
|
-
end
|
223
|
-
end
|
224
|
-
end
|
data/lib/savio/Colors.rb
DELETED
data/lib/savio/IORenderable.rb
DELETED
@@ -1,127 +0,0 @@
|
|
1
|
-
module Savio
|
2
|
-
module IORenderable
|
3
|
-
attr_accessor :enabled, :allowDrag, :draggingEnabled, :duplicate
|
4
|
-
attr_reader :x, :y, :z, :size, :shown, :displayName
|
5
|
-
|
6
|
-
def initialize(args = {})
|
7
|
-
Savio.addElement(self)
|
8
|
-
|
9
|
-
@x = args[:x] || 0
|
10
|
-
@y = args[:y] || 0
|
11
|
-
@z = args[:z] || 1
|
12
|
-
@size = args[:size] || 10
|
13
|
-
@enabled = args[:enabled] || true
|
14
|
-
|
15
|
-
@displayName = args[:displayName] || ""
|
16
|
-
|
17
|
-
@draggingEnabled = args[:draggingEnabled] || false
|
18
|
-
@dragType = args[:dragType] || "move"
|
19
|
-
@isDragging = false
|
20
|
-
@allowDrag = false
|
21
|
-
end
|
22
|
-
|
23
|
-
def remove()
|
24
|
-
if @shown == false
|
25
|
-
return
|
26
|
-
end
|
27
|
-
@shown = false
|
28
|
-
end
|
29
|
-
|
30
|
-
def add()
|
31
|
-
if @shown == true
|
32
|
-
return
|
33
|
-
end
|
34
|
-
@shown = true
|
35
|
-
end
|
36
|
-
|
37
|
-
def kill()
|
38
|
-
remove()
|
39
|
-
end
|
40
|
-
|
41
|
-
def rebuild()
|
42
|
-
remove()
|
43
|
-
build()
|
44
|
-
end
|
45
|
-
|
46
|
-
def x=(x)
|
47
|
-
@x = x
|
48
|
-
rebuild()
|
49
|
-
end
|
50
|
-
def y=(y)
|
51
|
-
@y = y
|
52
|
-
rebuild()
|
53
|
-
end
|
54
|
-
def z=(z)
|
55
|
-
@z = z
|
56
|
-
rebuild()
|
57
|
-
end
|
58
|
-
def size=(size)
|
59
|
-
@size = size.abs
|
60
|
-
rebuild()
|
61
|
-
end
|
62
|
-
def displayName=(displayName)
|
63
|
-
@displayName = displayName
|
64
|
-
rebuild()
|
65
|
-
end
|
66
|
-
def dragType=(type)
|
67
|
-
if type == "move" || type == "duplicate"
|
68
|
-
@dragType = type
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def drag(x, y)
|
73
|
-
case @dragType
|
74
|
-
when "move"
|
75
|
-
if @isDragging == false
|
76
|
-
@grabFixX = (x - @x).abs
|
77
|
-
@grabFixY = (y - @y).abs
|
78
|
-
@isDragging = true
|
79
|
-
end
|
80
|
-
if @isDragging == true
|
81
|
-
@x = x - @grabFixX
|
82
|
-
@y = y - @grabFixY
|
83
|
-
rebuild()
|
84
|
-
end
|
85
|
-
when "duplicate"
|
86
|
-
if @isDragging == false
|
87
|
-
@grabFixX = (x - @x).abs
|
88
|
-
@grabFixY = (y - @y).abs
|
89
|
-
|
90
|
-
classType = Object.const_get(self.class.name)
|
91
|
-
|
92
|
-
@duplicate = classType.new(self.context)
|
93
|
-
@duplicate.enabled = false
|
94
|
-
@duplicate.draggingEnabled = false
|
95
|
-
@duplicate.dragType = "move"
|
96
|
-
@isDragging = true
|
97
|
-
end
|
98
|
-
if @isDragging == true
|
99
|
-
@duplicate.enabled = false
|
100
|
-
@duplicate.draggingEnabled = false
|
101
|
-
@duplicate.x = x - @grabFixX
|
102
|
-
@duplicate.y = y - @grabFixY
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
def context()
|
108
|
-
self.instance_variables.map do |attribute|
|
109
|
-
key = attribute.to_s.gsub('@','').intern
|
110
|
-
[key, self.instance_variable_get(attribute)]
|
111
|
-
end.to_h
|
112
|
-
end
|
113
|
-
|
114
|
-
def endDrag()
|
115
|
-
if @isDragging
|
116
|
-
if @dragType == "duplicate"
|
117
|
-
@duplicate.draggingEnabled = true
|
118
|
-
@duplicate.enabled = true
|
119
|
-
@duplicate.allowDrag = false
|
120
|
-
@duplicate = nil
|
121
|
-
end
|
122
|
-
@isDragging = false
|
123
|
-
@allowDrag = false
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
data/lib/savio/InputBox.rb
DELETED
@@ -1,163 +0,0 @@
|
|
1
|
-
module Savio
|
2
|
-
class InputBox
|
3
|
-
include IORenderable
|
4
|
-
|
5
|
-
attr_accessor :shift
|
6
|
-
attr_reader :selected, :value, :length, :height
|
7
|
-
|
8
|
-
@@inputBoxs = []
|
9
|
-
def self.inputBoxs
|
10
|
-
@@inputBoxs
|
11
|
-
end
|
12
|
-
|
13
|
-
def initialize(args = {})
|
14
|
-
@@inputBoxs.push(self)
|
15
|
-
super(args)
|
16
|
-
|
17
|
-
@selected = args[:selected] || false
|
18
|
-
|
19
|
-
@size = args[:size] || 20
|
20
|
-
|
21
|
-
@shift = false
|
22
|
-
|
23
|
-
@value = args[:value] || @displayName
|
24
|
-
@displayName = @value
|
25
|
-
|
26
|
-
@length = args[:length] || @size * 10
|
27
|
-
@height = args[:height] || @size * 1.2
|
28
|
-
|
29
|
-
@color = args[:color] || Savio::Colors::White
|
30
|
-
@activeColor = args[:activeColor] || Savio::Colors::Green
|
31
|
-
|
32
|
-
@activeTextColor = args[:activeTextColor] || Savio::Colors::White
|
33
|
-
@inactiveTextColor = args[:inactiveTextColor] || Savio::Colors::Gray
|
34
|
-
|
35
|
-
build()
|
36
|
-
end
|
37
|
-
|
38
|
-
def remove()
|
39
|
-
super()
|
40
|
-
@display.remove
|
41
|
-
@container.remove
|
42
|
-
end
|
43
|
-
|
44
|
-
def add()
|
45
|
-
super()
|
46
|
-
@display.add
|
47
|
-
@container.add
|
48
|
-
end
|
49
|
-
|
50
|
-
def color=(color)
|
51
|
-
@color = color
|
52
|
-
rebuild()
|
53
|
-
end
|
54
|
-
def activeColor=(color)
|
55
|
-
@activeColor = color
|
56
|
-
rebuild()
|
57
|
-
end
|
58
|
-
def activeTextcolor=(color)
|
59
|
-
@activeTextcolor = color
|
60
|
-
rebuild()
|
61
|
-
end
|
62
|
-
def inactiveTextColor=(color)
|
63
|
-
@inactiveTextColor = color
|
64
|
-
rebuild()
|
65
|
-
end
|
66
|
-
def length=(length)
|
67
|
-
@length = length
|
68
|
-
rebuild()
|
69
|
-
end
|
70
|
-
def height=(height)
|
71
|
-
@height = height
|
72
|
-
rebuild()
|
73
|
-
end
|
74
|
-
|
75
|
-
def value=(value)
|
76
|
-
@value = value
|
77
|
-
@displayName = @value
|
78
|
-
@display.text = @value
|
79
|
-
end
|
80
|
-
|
81
|
-
def size=(size)
|
82
|
-
@length = size * 10
|
83
|
-
@height = size * 1.2
|
84
|
-
super(size)
|
85
|
-
end
|
86
|
-
|
87
|
-
def addKey(key)
|
88
|
-
if key == "space"
|
89
|
-
@value += + " "
|
90
|
-
updateDisplay()
|
91
|
-
elsif key == "return"
|
92
|
-
deselect()
|
93
|
-
elsif key == "backspace"
|
94
|
-
@value = @value[0...-1]
|
95
|
-
updateDisplay()
|
96
|
-
elsif key.chars.count == 1
|
97
|
-
if @shift == true
|
98
|
-
key = key.upcase
|
99
|
-
end
|
100
|
-
@value += key
|
101
|
-
updateDisplay()
|
102
|
-
else
|
103
|
-
puts "SAVIO : I am a work in progress, and the key you pressed couldnt be handled"
|
104
|
-
puts "SAVIO : Unknown key : " + key.to_s
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
def updateDisplay()
|
109
|
-
@display.text = @value + "|"
|
110
|
-
end
|
111
|
-
|
112
|
-
def selected=(bool)
|
113
|
-
if bool == true
|
114
|
-
select()
|
115
|
-
elsif bool == false
|
116
|
-
deselect()
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
def select()
|
121
|
-
@selected = true
|
122
|
-
|
123
|
-
if @value == @displayName
|
124
|
-
@value = ""
|
125
|
-
end
|
126
|
-
|
127
|
-
@display.text = @value + "|"
|
128
|
-
@display.color = @activeTextColor
|
129
|
-
@container.color = @activeColor
|
130
|
-
end
|
131
|
-
|
132
|
-
def deselect()
|
133
|
-
@selected = false
|
134
|
-
|
135
|
-
if @value == ""
|
136
|
-
@value = @displayName
|
137
|
-
end
|
138
|
-
|
139
|
-
@display.text = @value
|
140
|
-
@display.color = @inactiveTextColor
|
141
|
-
@container.color = @color
|
142
|
-
end
|
143
|
-
|
144
|
-
def toggle()
|
145
|
-
if @selected
|
146
|
-
deselect()
|
147
|
-
else
|
148
|
-
select()
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
def build()
|
153
|
-
@shown = true
|
154
|
-
|
155
|
-
@display = Text.new(@value,x: @x + 0.02 * @length,y: @y,z: @z + 1, size: @size, color: @inactiveTextColor)
|
156
|
-
@height = @display.height * 1.1
|
157
|
-
|
158
|
-
@container = Rectangle.new(x: @x, y: @y, z: @z, height: @height, width: @length, color: @color)
|
159
|
-
|
160
|
-
@display.y = @container.y + @container.height / 2 - @display.height / 2
|
161
|
-
end
|
162
|
-
end
|
163
|
-
end
|
data/lib/savio/Scene.rb
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
module Savio
|
2
|
-
class Scene
|
3
|
-
attr_accessor :elements
|
4
|
-
def initialize(file, color = 'black')
|
5
|
-
@file = file
|
6
|
-
@color = color
|
7
|
-
show()
|
8
|
-
end
|
9
|
-
|
10
|
-
def show()
|
11
|
-
@bg = Square.new(x: 0, y: 0, z: 999, size: Window.width+1, color: @color)
|
12
|
-
@elements = []
|
13
|
-
content = File.read(@file)
|
14
|
-
content = content.gsub('[', "").gsub(']', "").gsub('"',"").chomp.split(",")
|
15
|
-
|
16
|
-
(content.count-1).times do |i|
|
17
|
-
if (i % 2) == 0
|
18
|
-
classType = Object.const_get(content[i].gsub(" ",""))
|
19
|
-
hash = content[i+1].gsub(';', ',').gsub('"',"").chomp
|
20
|
-
pairs = hash.split(",").to_s.gsub('"',"").chomp
|
21
|
-
keypair = pairs.split("=>").to_s.gsub('"',"").chomp
|
22
|
-
new = keypair.gsub('{', "").gsub('}', "").gsub('[', "").gsub(']', "").gsub('"',"").gsub(" ","").chomp.split(",")
|
23
|
-
build = {}
|
24
|
-
(new.count-1).times do |j|
|
25
|
-
if (j % 2) == 0
|
26
|
-
case Savio.guessType(new[j+1].chomp)
|
27
|
-
when "int"
|
28
|
-
value = new[j+1].chomp.to_i
|
29
|
-
when "float"
|
30
|
-
value = new[j+1].chomp.to_f
|
31
|
-
when "str"
|
32
|
-
value = new[j+1].chomp.to_s
|
33
|
-
when "bool"
|
34
|
-
value = Savio.makeBool(new[j+1].chomp)
|
35
|
-
end
|
36
|
-
build[new[j].intern] = value
|
37
|
-
end
|
38
|
-
end
|
39
|
-
puts "SCENE: " + @file.to_s + build.to_s
|
40
|
-
@elements.push(classType.new(build))
|
41
|
-
end
|
42
|
-
end
|
43
|
-
@elements.each do |e|
|
44
|
-
e.z = 1000
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def remove()
|
49
|
-
@bg.remove
|
50
|
-
@elements.each do |e|
|
51
|
-
e.kill()
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|