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.
data/bin/setup CHANGED
@@ -1,8 +1,8 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/savio/Button.rb CHANGED
@@ -1,253 +1,253 @@
1
- module Savio
2
- class Button
3
- include IORenderable
4
-
5
- attr_accessor :value, :enforceManager
6
- attr_reader :selected, :buttonManager, :style, :length, :height, :type, :timeLastClicked, :cooldownTime
7
-
8
- @@buttons = []
9
- def self.buttons
10
- @@buttons
11
- end
12
-
13
- def initialize(args = {})
14
- super(args)
15
-
16
- @@buttons.push(self)
17
-
18
- @baseColor = args[:baseColor] || Savio::Colors::White
19
- @selectedColor = args[:selectedColor] || Savio::Colors::Blue
20
- @labelActiveColor = args[:labelActiveColor] || Savio::Colors::White
21
- @labelInactiveColor = args[:labelInactiveColor] || Savio::Colors::White
22
-
23
- @cooldownTime = args[:cooldownTime] || 0.0
24
- @timeLastClicked = 0.0
25
-
26
- @selected = args[:selected] || false
27
-
28
- @buttonManager = args[:buttonManager] || nil
29
- @enforceManager = args[:enforceManager] || true
30
-
31
- @type = args[:type] || 'toggle'
32
- if @type != 'toggle' && @type != 'clicker'
33
- @type = 'toggle'
34
- end
35
-
36
- @style = args[:style] || 'badge'
37
- if @style != 'box' && @style != 'badge'
38
- @style = 'badge'
39
- end
40
-
41
- if @style == 'box'
42
- @size *= 2
43
- @labelActiveColor = args[:labelActiveColor] || Savio::Colors::White
44
- @labelInactiveColor = args[:labelInactiveColor] || Savio::Colors::Gray
45
- end
46
-
47
- @length = args[:length] || @size * 10
48
- @height = args[:height] || @size * 2
49
-
50
- @onClick = Proc.new {}
51
-
52
- build()
53
- end
54
-
55
- def size=(size)
56
- @length = size * 10
57
- @height = size * 2
58
- super(size)
59
- end
60
- def type=(newType)
61
- if newType == 'toggle' || newType == 'clicker'
62
- @type = newType
63
- end
64
- end
65
- def style=(style)
66
- if style == 'box' || style == 'badge'
67
- @style = style
68
- rebuild()
69
- end
70
- end
71
-
72
- def cooldownTime=(cooldown)
73
- @cooldownTime = cooldown.to_f
74
- end
75
-
76
- def baseColor=(c)
77
- @baseColor = c
78
- rebuild()
79
- end
80
- def selectedColor=(c)
81
- @selectedColor = c
82
- rebuild()
83
- end
84
- def labelColor=(c)
85
- @labelColor = c
86
- rebuild()
87
- end
88
-
89
- def selected=(bool)
90
- if bool == true
91
- select()
92
- elsif bool == false
93
- deselect()
94
- end
95
- end
96
-
97
- def onClick(&proc)
98
- @onClick = proc
99
- end
100
-
101
- def buttonManager=(newManager)
102
- if @buttonManager != nil
103
- if newManager.class.name != 'Savio::ButtonManager'
104
- raise ArgumentError, 'Given object ' + newManager.to_s + ' is not a ButtonManager. Must be of type ButtonManager'
105
- end
106
- @buttonManager.removeButton(self, false)
107
- end
108
-
109
- if newManager != nil
110
- @buttonManager = newManager
111
- if @buttonManager.buttons.include?(self) != true
112
- @buttonManager.addButton(self)
113
- end
114
- else
115
- @buttonManager = nil
116
- end
117
- end
118
-
119
- def select(enforce = @enforceManager)
120
- if Time.now.to_f - @timeLastClicked.to_f >= @cooldownTime.to_f
121
- @timeLastClicked = Time.now.to_f
122
- click()
123
- if enforce == true && @buttonManager != nil
124
- @buttonManager.select(self)
125
- else
126
- @selectCircle.add
127
- @nameLabel.color = @labelActiveColor
128
- @selected = true
129
- if @type == 'clicker'
130
- fade = Thread.new {
131
- @selectCircle.add
132
- @nameLabel.color = @labelActiveColor
133
- sleep(0.06)
134
- @selectCircle.remove
135
- @nameLabel.color = @labelInactiveColor
136
- }
137
- deselect(enforce)
138
- end
139
- end
140
- end
141
- end
142
-
143
- def deselect(enforce = @enforceManager)
144
- if enforce == true && @buttonManager != nil
145
- @buttonManager.deselect(self)
146
- else
147
- @selectCircle.remove
148
- @nameLabel.color = @labelInactiveColor
149
- @selected = false
150
- end
151
- end
152
-
153
- def toggle(enforce = @enforceManager)
154
- if @selected
155
- deselect(enforce)
156
- else
157
- select(enforce)
158
- end
159
- end
160
-
161
- def remove()
162
- super()
163
- @nameLabel.remove
164
- @baseCircle.remove
165
- @selectCircle.remove
166
- end
167
-
168
- def add()
169
- super()
170
- @nameLabel.add
171
- @baseCircle.add
172
- @selectCircle.add
173
- if @selected
174
- select()
175
- else
176
- deselect()
177
- end
178
- end
179
-
180
- def click()
181
- @onClick.call()
182
- end
183
-
184
- def build()
185
- @shown = true
186
- case @style
187
- when 'badge'
188
- @baseCircle = Circle.new(
189
- x: @x, y: @y,
190
- radius: @size,
191
- color: @baseColor,
192
- z: @z
193
- )
194
- @selectCircle = Circle.new(
195
- x: @x, y: @y,
196
- radius: @size * 0.8,
197
- color: @selectedColor,
198
- z: @z+1
199
- )
200
- @nameLabel = Text.new(
201
- @displayName.to_s,
202
- x: @x + @size * 2, y: @y - @size * 1.5,
203
- size: @size * 2,
204
- color: @labelInactiveColor,
205
- z: @z
206
- )
207
- @nameLabel.y = @baseCircle.y - @baseCircle.radius / 4 - @nameLabel.height / 2
208
- when 'box'
209
- @baseCircle = Rectangle.new(
210
- x: @x, y: @y,
211
- height: @height, width: @length,
212
- color: @baseColor,
213
- z: @z
214
- )
215
- @selectCircle = Rectangle.new(
216
- x: @x + (@height * 0.1), y: @y + (@height * 0.1),
217
- height: @height - (@height * 0.2), width: @length - (@height * 0.2),
218
- color: @selectedColor,
219
- z: @z+1
220
- )
221
- @nameLabel = Text.new(
222
- @displayName.to_s,
223
- x: @x, y: @y,
224
- size: @size,
225
- color: @labelInactiveColor,
226
- z: @z+2
227
- )
228
- @nameLabel.x = @baseCircle.x + @baseCircle.width / 2 - @nameLabel.width / 2
229
- @nameLabel.y = @baseCircle.y + @baseCircle.height / 2 - @nameLabel.height / 2
230
- end
231
-
232
- if @buttonManager == nil
233
- if @selected
234
- select()
235
- else
236
- deselect()
237
- end
238
- else
239
- if @buttonManager.class.name != 'Savio::ButtonManager'
240
- raise ArgumentError, 'Given object ' + @buttonManager.to_s + ' is not a ButtonManager. Must be of type ButtonManager'
241
- end
242
- @buttonManager.addButton(self)
243
-
244
- if @selected
245
- @buttonManager.select(self)
246
- else
247
- @buttonManager.deselect(self)
248
- end
249
- end
250
-
251
- end
252
- end
253
- end
1
+ module Savio
2
+ class Button
3
+ include IORenderable
4
+
5
+ attr_accessor :value, :enforceManager
6
+ attr_reader :selected, :buttonManager, :style, :length, :height, :type, :timeLastClicked, :cooldownTime
7
+
8
+ @@buttons = []
9
+ def self.buttons
10
+ @@buttons
11
+ end
12
+
13
+ def initialize(args = {})
14
+ super(args)
15
+
16
+ @@buttons.push(self)
17
+
18
+ @baseColor = args[:baseColor] || Savio::Colors::White
19
+ @selectedColor = args[:selectedColor] || Savio::Colors::Blue
20
+ @labelActiveColor = args[:labelActiveColor] || Savio::Colors::White
21
+ @labelInactiveColor = args[:labelInactiveColor] || Savio::Colors::White
22
+
23
+ @cooldownTime = args[:cooldownTime] || 0.0
24
+ @timeLastClicked = 0.0
25
+
26
+ @selected = args[:selected] || false
27
+
28
+ @buttonManager = args[:buttonManager] || nil
29
+ @enforceManager = args[:enforceManager] || true
30
+
31
+ @type = args[:type] || 'toggle'
32
+ if @type != 'toggle' && @type != 'clicker'
33
+ @type = 'toggle'
34
+ end
35
+
36
+ @style = args[:style] || 'badge'
37
+ if @style != 'box' && @style != 'badge'
38
+ @style = 'badge'
39
+ end
40
+
41
+ if @style == 'box'
42
+ @size *= 2
43
+ @labelActiveColor = args[:labelActiveColor] || Savio::Colors::White
44
+ @labelInactiveColor = args[:labelInactiveColor] || Savio::Colors::Gray
45
+ end
46
+
47
+ @length = args[:length] || @size * 10
48
+ @height = args[:height] || @size * 2
49
+
50
+ @onClick = Proc.new {}
51
+
52
+ build()
53
+ end
54
+
55
+ def size=(size)
56
+ @length = size * 10
57
+ @height = size * 2
58
+ super(size)
59
+ end
60
+ def type=(newType)
61
+ if newType == 'toggle' || newType == 'clicker'
62
+ @type = newType
63
+ end
64
+ end
65
+ def style=(style)
66
+ if style == 'box' || style == 'badge'
67
+ @style = style
68
+ rebuild()
69
+ end
70
+ end
71
+
72
+ def cooldownTime=(cooldown)
73
+ @cooldownTime = cooldown.to_f
74
+ end
75
+
76
+ def baseColor=(c)
77
+ @baseColor = c
78
+ rebuild()
79
+ end
80
+ def selectedColor=(c)
81
+ @selectedColor = c
82
+ rebuild()
83
+ end
84
+ def labelColor=(c)
85
+ @labelColor = c
86
+ rebuild()
87
+ end
88
+
89
+ def selected=(bool)
90
+ if bool == true
91
+ select()
92
+ elsif bool == false
93
+ deselect()
94
+ end
95
+ end
96
+
97
+ def onClick(&proc)
98
+ @onClick = proc
99
+ end
100
+
101
+ def buttonManager=(newManager)
102
+ if @buttonManager != nil
103
+ if newManager.class.name != 'Savio::ButtonManager'
104
+ raise ArgumentError, 'Given object ' + newManager.to_s + ' is not a ButtonManager. Must be of type ButtonManager'
105
+ end
106
+ @buttonManager.removeButton(self, false)
107
+ end
108
+
109
+ if newManager != nil
110
+ @buttonManager = newManager
111
+ if @buttonManager.buttons.include?(self) != true
112
+ @buttonManager.addButton(self)
113
+ end
114
+ else
115
+ @buttonManager = nil
116
+ end
117
+ end
118
+
119
+ def select(enforce = @enforceManager)
120
+ if Time.now.to_f - @timeLastClicked.to_f >= @cooldownTime.to_f
121
+ @timeLastClicked = Time.now.to_f
122
+ click()
123
+ if enforce == true && @buttonManager != nil
124
+ @buttonManager.select(self)
125
+ else
126
+ @selectCircle.add
127
+ @nameLabel.color = @labelActiveColor
128
+ @selected = true
129
+ if @type == 'clicker'
130
+ fade = Thread.new {
131
+ @selectCircle.add
132
+ @nameLabel.color = @labelActiveColor
133
+ sleep(0.06)
134
+ @selectCircle.remove
135
+ @nameLabel.color = @labelInactiveColor
136
+ }
137
+ deselect(enforce)
138
+ end
139
+ end
140
+ end
141
+ end
142
+
143
+ def deselect(enforce = @enforceManager)
144
+ if enforce == true && @buttonManager != nil
145
+ @buttonManager.deselect(self)
146
+ else
147
+ @selectCircle.remove
148
+ @nameLabel.color = @labelInactiveColor
149
+ @selected = false
150
+ end
151
+ end
152
+
153
+ def toggle(enforce = @enforceManager)
154
+ if @selected
155
+ deselect(enforce)
156
+ else
157
+ select(enforce)
158
+ end
159
+ end
160
+
161
+ def remove()
162
+ super()
163
+ @nameLabel.remove
164
+ @baseCircle.remove
165
+ @selectCircle.remove
166
+ end
167
+
168
+ def add()
169
+ super()
170
+ @nameLabel.add
171
+ @baseCircle.add
172
+ @selectCircle.add
173
+ if @selected
174
+ select()
175
+ else
176
+ deselect()
177
+ end
178
+ end
179
+
180
+ def click()
181
+ @onClick.call()
182
+ end
183
+
184
+ def build()
185
+ @shown = true
186
+ case @style
187
+ when 'badge'
188
+ @baseCircle = Circle.new(
189
+ x: @x, y: @y,
190
+ radius: @size,
191
+ color: @baseColor,
192
+ z: @z
193
+ )
194
+ @selectCircle = Circle.new(
195
+ x: @x, y: @y,
196
+ radius: @size * 0.8,
197
+ color: @selectedColor,
198
+ z: @z+1
199
+ )
200
+ @nameLabel = Text.new(
201
+ @displayName.to_s,
202
+ x: @x + @size * 2, y: @y - @size * 1.5,
203
+ size: @size * 2,
204
+ color: @labelInactiveColor,
205
+ z: @z
206
+ )
207
+ @nameLabel.y = @baseCircle.y - @baseCircle.radius / 4 - @nameLabel.height / 2
208
+ when 'box'
209
+ @baseCircle = Rectangle.new(
210
+ x: @x, y: @y,
211
+ height: @height, width: @length,
212
+ color: @baseColor,
213
+ z: @z
214
+ )
215
+ @selectCircle = Rectangle.new(
216
+ x: @x + (@height * 0.1), y: @y + (@height * 0.1),
217
+ height: @height - (@height * 0.2), width: @length - (@height * 0.2),
218
+ color: @selectedColor,
219
+ z: @z+1
220
+ )
221
+ @nameLabel = Text.new(
222
+ @displayName.to_s,
223
+ x: @x, y: @y,
224
+ size: @size,
225
+ color: @labelInactiveColor,
226
+ z: @z+2
227
+ )
228
+ @nameLabel.x = @baseCircle.x + @baseCircle.width / 2 - @nameLabel.width / 2
229
+ @nameLabel.y = @baseCircle.y + @baseCircle.height / 2 - @nameLabel.height / 2
230
+ end
231
+
232
+ if @buttonManager == nil
233
+ if @selected
234
+ select()
235
+ else
236
+ deselect()
237
+ end
238
+ else
239
+ if @buttonManager.class.name != 'Savio::ButtonManager'
240
+ raise ArgumentError, 'Given object ' + @buttonManager.to_s + ' is not a ButtonManager. Must be of type ButtonManager'
241
+ end
242
+ @buttonManager.addButton(self)
243
+
244
+ if @selected
245
+ @buttonManager.select(self)
246
+ else
247
+ @buttonManager.deselect(self)
248
+ end
249
+ end
250
+
251
+ end
252
+ end
253
+ end