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.
@@ -1,127 +1,126 @@
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
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
@@ -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
- 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
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