savio 0.1.4 → 0.1.7
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
- data/.gitignore +8 -8
- data/Gemfile +6 -6
- data/LICENSE.txt +21 -21
- data/README.md +261 -261
- data/Rakefile +2 -2
- data/bin/console +14 -14
- data/bin/setup +8 -8
- data/lib/savio/Button.rb +253 -253
- data/lib/savio/ButtonManager.rb +106 -106
- data/lib/savio/ColorSlider.rb +224 -224
- data/lib/savio/Colors.rb +13 -13
- data/lib/savio/IORenderable.rb +126 -127
- data/lib/savio/InputBox.rb +196 -163
- data/lib/savio/Scene.rb +55 -55
- data/lib/savio/Slider.rb +195 -195
- data/lib/savio/hsv2rgb.rb +78 -78
- data/lib/savio/io.rb +250 -250
- data/lib/savio/version.rb +3 -3
- data/lib/savio.rb +82 -82
- data/savio.gemspec +26 -26
- data/test.rb +9 -9
- metadata +8 -8
data/lib/savio/IORenderable.rb
CHANGED
|
@@ -1,127 +1,126 @@
|
|
|
1
|
-
module Savio
|
|
2
|
-
module IORenderable
|
|
3
|
-
attr_accessor :enabled, :allowDrag, :draggingEnabled, :duplicate
|
|
4
|
-
attr_reader :x, :y, :z, :size, :
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
76
|
-
@
|
|
77
|
-
@
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
@
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
@
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
@duplicate =
|
|
93
|
-
@duplicate.
|
|
94
|
-
@duplicate.
|
|
95
|
-
@
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
@duplicate.
|
|
100
|
-
@duplicate.
|
|
101
|
-
@duplicate.
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
key
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
@duplicate.
|
|
118
|
-
@duplicate.
|
|
119
|
-
@duplicate
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
@
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
end
|
|
1
|
+
module Savio
|
|
2
|
+
module IORenderable
|
|
3
|
+
attr_accessor :enabled, :shown, :allowDrag, :draggingEnabled, :duplicate
|
|
4
|
+
attr_reader :x, :y, :z, :size, :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
|
+
|
|
13
|
+
@size = args[:size] || 10
|
|
14
|
+
|
|
15
|
+
@enabled = args[:enabled] || true
|
|
16
|
+
@shown = args[:shown] || true
|
|
17
|
+
|
|
18
|
+
@displayName = args[:displayName] || ""
|
|
19
|
+
|
|
20
|
+
@draggingEnabled = args[:draggingEnabled] || false
|
|
21
|
+
@dragType = args[:dragType] || "move"
|
|
22
|
+
@isDragging = false
|
|
23
|
+
@allowDrag = false
|
|
24
|
+
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def remove()
|
|
28
|
+
@shown = false
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def add()
|
|
32
|
+
@shown = true
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def kill()
|
|
36
|
+
remove()
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def rebuild()
|
|
40
|
+
remove()
|
|
41
|
+
build()
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def x=(x)
|
|
45
|
+
@x = x
|
|
46
|
+
rebuild()
|
|
47
|
+
end
|
|
48
|
+
def y=(y)
|
|
49
|
+
@y = y
|
|
50
|
+
rebuild()
|
|
51
|
+
end
|
|
52
|
+
def z=(z)
|
|
53
|
+
@z = z
|
|
54
|
+
rebuild()
|
|
55
|
+
end
|
|
56
|
+
def size=(size)
|
|
57
|
+
@size = size.abs
|
|
58
|
+
rebuild()
|
|
59
|
+
end
|
|
60
|
+
def displayName=(displayName)
|
|
61
|
+
@displayName = displayName
|
|
62
|
+
rebuild()
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def dragType=(type)
|
|
66
|
+
if type == "move" || type == "duplicate"
|
|
67
|
+
@dragType = type
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def drag(x, y)
|
|
72
|
+
case @dragType
|
|
73
|
+
when "move"
|
|
74
|
+
if @isDragging == false
|
|
75
|
+
@grabFixX = (x - @x).abs
|
|
76
|
+
@grabFixY = (y - @y).abs
|
|
77
|
+
@isDragging = true
|
|
78
|
+
end
|
|
79
|
+
if @isDragging == true
|
|
80
|
+
@x = x - @grabFixX
|
|
81
|
+
@y = y - @grabFixY
|
|
82
|
+
rebuild()
|
|
83
|
+
end
|
|
84
|
+
when "duplicate"
|
|
85
|
+
if @isDragging == false
|
|
86
|
+
@grabFixX = (x - @x).abs
|
|
87
|
+
@grabFixY = (y - @y).abs
|
|
88
|
+
|
|
89
|
+
classType = Object.const_get(self.class.name)
|
|
90
|
+
|
|
91
|
+
@duplicate = classType.new(self.context)
|
|
92
|
+
@duplicate.enabled = false
|
|
93
|
+
@duplicate.draggingEnabled = false
|
|
94
|
+
@duplicate.dragType = "move"
|
|
95
|
+
@isDragging = true
|
|
96
|
+
end
|
|
97
|
+
if @isDragging == true
|
|
98
|
+
@duplicate.enabled = false
|
|
99
|
+
@duplicate.draggingEnabled = false
|
|
100
|
+
@duplicate.x = x - @grabFixX
|
|
101
|
+
@duplicate.y = y - @grabFixY
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def context()
|
|
107
|
+
self.instance_variables.map do |attribute|
|
|
108
|
+
key = attribute.to_s.gsub('@','').intern
|
|
109
|
+
[key, self.instance_variable_get(attribute)]
|
|
110
|
+
end.to_h
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def endDrag()
|
|
114
|
+
if @isDragging
|
|
115
|
+
if @dragType == "duplicate"
|
|
116
|
+
@duplicate.draggingEnabled = true
|
|
117
|
+
@duplicate.enabled = true
|
|
118
|
+
@duplicate.allowDrag = false
|
|
119
|
+
@duplicate = nil
|
|
120
|
+
end
|
|
121
|
+
@isDragging = false
|
|
122
|
+
@allowDrag = false
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
end
|
data/lib/savio/InputBox.rb
CHANGED
|
@@ -1,163 +1,196 @@
|
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
@
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
@
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
select()
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
@
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
@
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
1
|
+
module Savio
|
|
2
|
+
class InputBox
|
|
3
|
+
include IORenderable
|
|
4
|
+
|
|
5
|
+
attr_accessor :shift
|
|
6
|
+
attr_reader :selected, :value, :length, :height, :displayName
|
|
7
|
+
|
|
8
|
+
@@inputBoxs = []
|
|
9
|
+
def self.inputBoxs
|
|
10
|
+
@@inputBoxs
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
@@tabIndex = 0
|
|
14
|
+
|
|
15
|
+
def initialize(args = {})
|
|
16
|
+
super(args)
|
|
17
|
+
|
|
18
|
+
@@inputBoxs.push(self)
|
|
19
|
+
|
|
20
|
+
@selected = args[:selected] || false
|
|
21
|
+
|
|
22
|
+
@size = args[:size] || 20
|
|
23
|
+
|
|
24
|
+
@shift = false
|
|
25
|
+
|
|
26
|
+
@value = args[:value] || ""
|
|
27
|
+
|
|
28
|
+
@length = args[:length] || @size * 10
|
|
29
|
+
@height = args[:height] || @size * 1.2
|
|
30
|
+
|
|
31
|
+
@color = args[:color] || Savio::Colors::White
|
|
32
|
+
@activeColor = args[:activeColor] || Savio::Colors::Green
|
|
33
|
+
|
|
34
|
+
@activeTextColor = args[:activeTextColor] || Savio::Colors::White
|
|
35
|
+
@inactiveTextColor = args[:inactiveTextColor] || Savio::Colors::Gray
|
|
36
|
+
|
|
37
|
+
build()
|
|
38
|
+
|
|
39
|
+
if @shown == false
|
|
40
|
+
remove()
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def remove()
|
|
46
|
+
super()
|
|
47
|
+
@display.remove
|
|
48
|
+
@container.remove
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def add()
|
|
52
|
+
super()
|
|
53
|
+
@display.add
|
|
54
|
+
@container.add
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def color=(color)
|
|
58
|
+
@color = color
|
|
59
|
+
rebuild()
|
|
60
|
+
end
|
|
61
|
+
def activeColor=(color)
|
|
62
|
+
@activeColor = color
|
|
63
|
+
rebuild()
|
|
64
|
+
end
|
|
65
|
+
def activeTextcolor=(color)
|
|
66
|
+
@activeTextcolor = color
|
|
67
|
+
rebuild()
|
|
68
|
+
end
|
|
69
|
+
def inactiveTextColor=(color)
|
|
70
|
+
@inactiveTextColor = color
|
|
71
|
+
rebuild()
|
|
72
|
+
end
|
|
73
|
+
def length=(length)
|
|
74
|
+
@length = length
|
|
75
|
+
rebuild()
|
|
76
|
+
end
|
|
77
|
+
def height=(height)
|
|
78
|
+
@height = height
|
|
79
|
+
rebuild()
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def value=(value)
|
|
83
|
+
@value = value
|
|
84
|
+
if @value == ""
|
|
85
|
+
@display.text = @displayName
|
|
86
|
+
else
|
|
87
|
+
@display.text = @value
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def clear()
|
|
92
|
+
@value = ""
|
|
93
|
+
@display.text = @displayName
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def size=(size)
|
|
97
|
+
@length = size * 10
|
|
98
|
+
@height = size * 1.2
|
|
99
|
+
super(size)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def tabMover()
|
|
103
|
+
if @@tabIndex >= @@inputBoxs.count
|
|
104
|
+
@@tabIndex = 0
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
for i in @@tabIndex..@@inputBoxs.count-1 do
|
|
108
|
+
if @@inputBoxs[i].enabled && @@inputBoxs[i].shown
|
|
109
|
+
@@tabIndex = i
|
|
110
|
+
deselect()
|
|
111
|
+
@@inputBoxs[i].select()
|
|
112
|
+
end
|
|
113
|
+
if @selected
|
|
114
|
+
@@tabIndex = 0
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def addKey(key)
|
|
120
|
+
if key == "space"
|
|
121
|
+
@value += + " "
|
|
122
|
+
updateDisplay()
|
|
123
|
+
elsif key == "return"
|
|
124
|
+
deselect()
|
|
125
|
+
elsif key == "backspace"
|
|
126
|
+
@value = @value[0...-1]
|
|
127
|
+
updateDisplay()
|
|
128
|
+
elsif key.chars.count == 1
|
|
129
|
+
if @shift == true
|
|
130
|
+
key = key.upcase
|
|
131
|
+
end
|
|
132
|
+
@value += key
|
|
133
|
+
updateDisplay()
|
|
134
|
+
elsif key == "tab"
|
|
135
|
+
tabMover()
|
|
136
|
+
else
|
|
137
|
+
puts "SAVIO : I am a work in progress, and the key you pressed couldnt be handled"
|
|
138
|
+
puts "SAVIO : Unknown key : " + key.to_s
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def updateDisplay()
|
|
143
|
+
@display.text = @value + "|"
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def selected=(bool)
|
|
147
|
+
if bool == true
|
|
148
|
+
select()
|
|
149
|
+
elsif bool == false
|
|
150
|
+
deselect()
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
def select()
|
|
155
|
+
@selected = true
|
|
156
|
+
|
|
157
|
+
@display.text = @value + "|"
|
|
158
|
+
@display.color = @activeTextColor
|
|
159
|
+
@container.color = @activeColor
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
def deselect()
|
|
163
|
+
@selected = false
|
|
164
|
+
|
|
165
|
+
if @value == ""
|
|
166
|
+
@display.text = @displayName
|
|
167
|
+
else
|
|
168
|
+
@display.text = @value
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
@display.color = @inactiveTextColor
|
|
172
|
+
@container.color = @color
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
def toggle()
|
|
176
|
+
if @selected
|
|
177
|
+
deselect()
|
|
178
|
+
else
|
|
179
|
+
select()
|
|
180
|
+
end
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
def build()
|
|
184
|
+
if @value == ""
|
|
185
|
+
@display = Text.new(@displayName,x: @x + 0.02 * @length,y: @y,z: @z + 1, size: @size, color: @inactiveTextColor)
|
|
186
|
+
else
|
|
187
|
+
@display = Text.new(@value,x: @x + 0.02 * @length,y: @y,z: @z + 1, size: @size, color: @inactiveTextColor)
|
|
188
|
+
end
|
|
189
|
+
@height = @display.height * 1.1
|
|
190
|
+
|
|
191
|
+
@container = Rectangle.new(x: @x, y: @y, z: @z, height: @height, width: @length, color: @color)
|
|
192
|
+
|
|
193
|
+
@display.y = @container.y + @container.height / 2 - @display.height / 2
|
|
194
|
+
end
|
|
195
|
+
end
|
|
196
|
+
end
|