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/ButtonManager.rb
CHANGED
@@ -1,106 +1,106 @@
|
|
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
|
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
CHANGED
@@ -1,224 +1,224 @@
|
|
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
|
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
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
module Savio
|
2
|
-
module Colors
|
3
|
-
White = '#FDFDFD'
|
4
|
-
Gray = '#858585'
|
5
|
-
Black = '#1A1A1A'
|
6
|
-
|
7
|
-
Red = '#FF728B'
|
8
|
-
Green = '#28E457'
|
9
|
-
Blue = '#28B2E4'
|
10
|
-
Yellow = '#FFED61'
|
11
|
-
Purple = '#FF90FF'
|
12
|
-
end
|
13
|
-
end
|
1
|
+
module Savio
|
2
|
+
module Colors
|
3
|
+
White = '#FDFDFD'
|
4
|
+
Gray = '#858585'
|
5
|
+
Black = '#1A1A1A'
|
6
|
+
|
7
|
+
Red = '#FF728B'
|
8
|
+
Green = '#28E457'
|
9
|
+
Blue = '#28B2E4'
|
10
|
+
Yellow = '#FFED61'
|
11
|
+
Purple = '#FF90FF'
|
12
|
+
end
|
13
|
+
end
|