savio 0.1.3 → 0.1.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e9c4a4721041e88aef40cb7c21004642868062c0893f9d580b0becc061754e1e
4
- data.tar.gz: 7c297a0dc4c4333610a0073ee3ebeef372cdaed9ca14078d518de5cb17e55507
3
+ metadata.gz: 6f8211e8af8eea0a22081349bc0274e100804f0163f83db1041d896ed7a895ee
4
+ data.tar.gz: 66f8436669bedbf6724c39da5d1563f6eec5580646fc49ad182c2e7480210b7d
5
5
  SHA512:
6
- metadata.gz: 9d58b069df4a6556b7b0c4a931e50eb0e0a730e32b00d39cbeb5453003e9ff2a125387e53a102bc9bc81b92d53ba4b67298992cf2f848bc89fb8141db3cff910
7
- data.tar.gz: 4307f4a3119b6328e4724a4e555a6f767c5e51a16ca1ba89e667157bb594b13b2f2598a183fb4f362aa3961a33645419852e4fb03083256838030ea5ba46b7f9
6
+ metadata.gz: 253013e256d8e2416912d866e69e44fa74b265e3f22cd0727da32735009ed81cd100a1ff77c6b173c832962ac20190c63deb2e3e23e301332388d2016990ac56
7
+ data.tar.gz: 3b985f911a2c5a4de7be93a3895d5c4d57325f7096c66ce78856b975cf37e2f989b7ce138761cc858144fc9dbe7e8f68fb8772c69a2330430f6e84296d0a0271
data/README.md CHANGED
@@ -103,6 +103,7 @@ all SavIO object's parameters are optional, if it is not defined then it will us
103
103
  |.moveKnob(**x**) | Moves the knob to that **x** pixel location on the screen and finds and sets equivalent value for the slider |
104
104
  |.setValue(**value**)|Sets the sliders value to that value and moves the knob there (same as .value=)|
105
105
  | .value = **value** | Sets the sliders value to that **value** and moves the knob there (same as .setValue)|
106
+ |.onChange| Calls the given proc any time the sliders **value** is updated(see basic usage)|
106
107
 
107
108
  ### Basic Usage:
108
109
 
@@ -110,13 +111,18 @@ all SavIO object's parameters are optional, if it is not defined then it will us
110
111
  puts "nice"
111
112
  end
112
113
 
114
+ -----
115
+
116
+ slippyTheSlider.onChange do
117
+ puts "Value Changed! new value is: " + slippyTheSlider.value.to_s
118
+ end
119
+
113
120
  # | Buttons:
114
121
  **On top of** all the basic parameters and methods a **Button** can **also** use these:
115
122
 
116
123
  ### Params:
117
124
  | Variable | Description | Default |
118
125
  |--|--|--|
119
- |value | Anything you want to be tied to the button | 0
120
126
  |selected | Whether the button is selected or not | false
121
127
  |type | Whether the button will act normally('toggle') or instantly deselect itself('clicker') | 'toggle'
122
128
  |style|'box' or 'badge'. Determines the style the button should be rendered with| 'badge'
@@ -12,6 +12,7 @@ module Savio
12
12
  require 'savio/hsv2rgb.rb'
13
13
  require 'savio/ColorSlider.rb'
14
14
  require 'savio/Scene.rb'
15
+ require 'savio/Colors.rb'
15
16
  require 'savio/io.rb'
16
17
 
17
18
  def self.makeBool(value)
@@ -15,11 +15,10 @@ module Savio
15
15
 
16
16
  @@buttons.push(self)
17
17
 
18
- @value = args[:value] || 0
19
-
20
- @baseColor = args[:baseColor] || '#F5F5F5'
21
- @selectedColor = args[:selectedColor] || '#00B3EC'
22
- @labelColor = args[:labelColor] || '#F5F5F5'
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
23
22
 
24
23
  @cooldownTime = args[:cooldownTime] || 0.0
25
24
  @timeLastClicked = 0.0
@@ -41,10 +40,12 @@ module Savio
41
40
 
42
41
  if @style == 'box'
43
42
  @size *= 2
44
- @labelColor = args[:baseColor] || '#757575'
43
+ @labelActiveColor = args[:labelActiveColor] || Savio::Colors::White
44
+ @labelInactiveColor = args[:labelInactiveColor] || Savio::Colors::Gray
45
45
  end
46
+
46
47
  @length = args[:length] || @size * 10
47
- @height = args[:height] || @size * 1.2
48
+ @height = args[:height] || @size * 2
48
49
 
49
50
  @onClick = Proc.new {}
50
51
 
@@ -53,7 +54,7 @@ module Savio
53
54
 
54
55
  def size=(size)
55
56
  @length = size * 10
56
- @height = size * 1.2
57
+ @height = size * 2
57
58
  super(size)
58
59
  end
59
60
  def type=(newType)
@@ -123,12 +124,15 @@ module Savio
123
124
  @buttonManager.select(self)
124
125
  else
125
126
  @selectCircle.add
127
+ @nameLabel.color = @labelActiveColor
126
128
  @selected = true
127
129
  if @type == 'clicker'
128
130
  fade = Thread.new {
129
131
  @selectCircle.add
132
+ @nameLabel.color = @labelActiveColor
130
133
  sleep(0.06)
131
134
  @selectCircle.remove
135
+ @nameLabel.color = @labelInactiveColor
132
136
  }
133
137
  deselect(enforce)
134
138
  end
@@ -141,6 +145,7 @@ module Savio
141
145
  @buttonManager.deselect(self)
142
146
  else
143
147
  @selectCircle.remove
148
+ @nameLabel.color = @labelInactiveColor
144
149
  @selected = false
145
150
  end
146
151
  end
@@ -196,9 +201,10 @@ module Savio
196
201
  @displayName.to_s,
197
202
  x: @x + @size * 2, y: @y - @size * 1.5,
198
203
  size: @size * 2,
199
- color: @labelColor,
204
+ color: @labelInactiveColor,
200
205
  z: @z
201
206
  )
207
+ @nameLabel.y = @baseCircle.y - @baseCircle.radius / 4 - @nameLabel.height / 2
202
208
  when 'box'
203
209
  @baseCircle = Rectangle.new(
204
210
  x: @x, y: @y,
@@ -216,7 +222,7 @@ module Savio
216
222
  @displayName.to_s,
217
223
  x: @x, y: @y,
218
224
  size: @size,
219
- color: @labelColor,
225
+ color: @labelInactiveColor,
220
226
  z: @z+2
221
227
  )
222
228
  @nameLabel.x = @baseCircle.x + @baseCircle.width / 2 - @nameLabel.width / 2
@@ -2,7 +2,7 @@ module Savio
2
2
  class ColorSlider
3
3
  include IORenderable
4
4
 
5
- attr_reader :value, :baseColor, :knobColor, :textColor, :sectors, :optionsShown, :animating
5
+ attr_reader :baseColor, :knobColor, :textColor, :sectors, :optionsShown, :animating
6
6
 
7
7
  @@colorSliders = []
8
8
  def self.colorSliders
@@ -14,10 +14,12 @@ module Savio
14
14
  super(args)
15
15
  @@colorSliders.push(self)
16
16
 
17
- @value = args[:value] || rand(0..360)
18
- @baseColor = args[:baseColor] || 'white'
19
- @knobColor = args[:baseColor] || 'gray'
20
- @textColor = args[:textColor] || 'black'
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
21
23
  @sectors = args[:sectors] || 64
22
24
 
23
25
  @optionsShown = false
@@ -47,8 +49,8 @@ module Savio
47
49
  @innerCircle.remove
48
50
  @outerCircle.remove
49
51
  @knob.remove
50
- @mySaturation.remove
51
- @myValue.remove
52
+ @saturationSlider.remove
53
+ @valueSlider.remove
52
54
  end
53
55
 
54
56
  def add()
@@ -56,8 +58,8 @@ module Savio
56
58
  @innerCircle.add
57
59
  @outerCircle.add
58
60
  @knob.add
59
- @mySaturation.add
60
- @myValue.add
61
+ @saturationSlider.add
62
+ @valueSlider.add
61
63
  end
62
64
 
63
65
  def animate()
@@ -118,24 +120,27 @@ module Savio
118
120
  def setValue(angle)
119
121
  @knob.x = (@size).to_f * Math.cos((angle.to_f % 360.0) * Math::PI/180.0) + @x.to_f
120
122
  @knob.y = (@size).to_f * Math.sin((angle.to_f % 360.0) * Math::PI/180.0) + @y.to_f
121
- @value = angle
122
123
 
123
- hue = Savio.hsv2rgb(@value % 360,@mySaturation.value,@myValue.value)
124
- @innerCircle.color.r = hue[0]
125
- @innerCircle.color.g = hue[1]
126
- @innerCircle.color.b = hue[2]
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]
127
131
  end
128
132
 
129
133
  def rgb()
130
- return Savio.hsv2rgb(@value % 360,@mySaturation.value,@myValue.value)
134
+ return RgbColor.newFromHSV(@color)
131
135
  end
132
136
 
133
137
  def hsv()
134
- return [@value % 360, @mySaturation.value, @myValue.value]
138
+ return HsvColor.new(@color[0],@color[1],@color[2])
135
139
  end
136
140
 
137
141
  def hex()
138
- return ("#%02x%02x%02x" % [rgb()[0]*255,rgb()[1]*255,rgb()[2]*255])
142
+ rgb = RgbColor.newFromHSV(@color)
143
+ return ("#%02x%02x%02x" % [rgb[0]*255,rgb[1]*255,rgb[2]*255])
139
144
  end
140
145
 
141
146
  def chord(placement)
@@ -176,7 +181,7 @@ module Savio
176
181
  )
177
182
 
178
183
  placement = chord(1.0)
179
- @mySaturation = Slider.new(
184
+ @saturationSlider = Slider.new(
180
185
  displayName: "Saturation",
181
186
  labelColor: @textColor,
182
187
  x:@x - @size + placement.adjust + placement.margin,
@@ -190,7 +195,7 @@ module Savio
190
195
  )
191
196
 
192
197
  placement = chord(1.3)
193
- @myValue = Slider.new(
198
+ @valueSlider = Slider.new(
194
199
  displayName: "Value",
195
200
  labelColor: @textColor,
196
201
  x:@x - @size + placement.adjust + placement.margin,
@@ -202,10 +207,18 @@ module Savio
202
207
  size: @size * 0.06,
203
208
  showValue: false
204
209
  )
205
- @myValue.showValue=false
206
- @mySaturation.showValue=false
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
207
220
 
208
- setValue(@value)
221
+ setValue(@hue)
209
222
  end
210
223
  end
211
224
  end
@@ -0,0 +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
@@ -26,11 +26,11 @@ module Savio
26
26
  @length = args[:length] || @size * 10
27
27
  @height = args[:height] || @size * 1.2
28
28
 
29
- @color = args[:color] || '#F5F5F5'
30
- @activeColor = args[:activeColor] || '#5BB36A'
29
+ @color = args[:color] || Savio::Colors::White
30
+ @activeColor = args[:activeColor] || Savio::Colors::Green
31
31
 
32
- @activeTextColor = args[:activeTextColor] || '#F5F5F5'
33
- @inactiveTextColor = args[:inactiveTextColor] || '#757575'
32
+ @activeTextColor = args[:activeTextColor] || Savio::Colors::White
33
+ @inactiveTextColor = args[:inactiveTextColor] || Savio::Colors::Gray
34
34
 
35
35
  build()
36
36
  end
@@ -152,7 +152,7 @@ module Savio
152
152
  def build()
153
153
  @shown = true
154
154
 
155
- @display = Text.new(@value,x: @x,y: @y,z: @z + 1, size: @size, color: @inactiveTextColor)
155
+ @display = Text.new(@value,x: @x + 0.02 * @length,y: @y,z: @z + 1, size: @size, color: @inactiveTextColor)
156
156
  @height = @display.height * 1.1
157
157
 
158
158
  @container = Rectangle.new(x: @x, y: @y, z: @z, height: @height, width: @length, color: @color)
@@ -25,13 +25,19 @@ module Savio
25
25
  @value = args[:value] || rand(@min..@max)
26
26
  @showValue = args[:showValue] || true
27
27
 
28
- @labelColor = args[:labelColor] || '#F5F5F5'
29
- @sliderColor = args[:sliderColor] || '#757575'
30
- @knobColor = args[:knobColor] || '#5BB36A'
28
+ @labelColor = args[:labelColor] || Savio::Colors::White
29
+ @sliderColor = args[:sliderColor] || Savio::Colors::Gray
30
+ @knobColor = args[:knobColor] || Savio::Colors::Green
31
+
32
+ @onChange = Proc.new {}
31
33
 
32
34
  build()
33
35
  end
34
36
 
37
+ def onChange(&proc)
38
+ @onChange = proc
39
+ end
40
+
35
41
  def style=(style)
36
42
  if style == 'knob' || style == 'fill'
37
43
  @style = style
@@ -91,6 +97,7 @@ module Savio
91
97
  if @showValue == true
92
98
  @label.text = @value.round(2).to_s
93
99
  end
100
+ @onChange.call
94
101
  end
95
102
  end
96
103
 
@@ -1,36 +1,78 @@
1
1
  module Savio
2
- def self.hsv2rgb(hue, saturation, value)
3
-
4
- hue = hue.to_f
5
- saturation = saturation.to_f
6
- value = value.to_f
7
-
8
- chroma = (value * saturation).to_f
9
- hPrime = hue/60.0
10
- x = (chroma * (1 - (hPrime % 2 - 1).abs)).to_f
11
-
12
- if 0 <= hPrime && hPrime < 1
13
- rgb = [chroma, x, 0]
14
- elsif 1 <= hPrime && hPrime < 2
15
- rgb = [x, chroma, 0]
16
- elsif 2 <= hPrime && hPrime < 3
17
- rgb = [0, chroma, x]
18
- elsif 3 <= hPrime && hPrime < 4
19
- rgb = [0, x, chroma]
20
- elsif 4 <= hPrime && hPrime < 5
21
- rgb = [x, 0, chroma]
22
- elsif 5 <= hPrime && hPrime < 6
23
- rgb = [chroma, 0, x]
24
- else
25
- rgb = [0,0,0]
2
+ RgbColor = Struct.new(:r, :g, :b) do
3
+ def self.newFromHSV(hsv)
4
+ rgb = hsv.to_rgb()
5
+ return RgbColor.new(rgb.r,rgb.g,rgb.b)
26
6
  end
7
+ def to_hsv()
8
+ max = [r, g, b].max
9
+ min = [r, g, b].min
10
+ delta = max - min
11
+ v = max
27
12
 
28
- match = (value - chroma).to_f
13
+ if (max != 0.0)
14
+ s = delta / max
15
+ else
16
+ s = 0.0
17
+ end
29
18
 
30
- rgb[0] = (rgb[0] + match).to_f
31
- rgb[1] = (rgb[1] + match).to_f
32
- rgb[2] = (rgb[2] + match).to_f
19
+ if (s == 0.0)
20
+ h = 0.0
21
+ else
22
+ if (r == max)
23
+ h = 0 + (g - b) / delta
24
+ elsif (g == max)
25
+ h = 2 + (b - r) / delta
26
+ elsif (b == max)
27
+ h = 4 + (r - g) / delta
28
+ end
33
29
 
34
- return rgb
30
+ h *= 60.0
31
+
32
+ if (h < 0)
33
+ h += 360.0
34
+ end
35
+ end
36
+ return HsvColor.new(h,s,v)
37
+ end
38
+ end
39
+ HsvColor = Struct.new(:h, :s, :v) do
40
+ def self.newFromRGB(rgb)
41
+ hsv = rgb.to_hsv()
42
+ return HsvColor.new(hsv.h,hsv.s,hsv.v)
43
+ end
44
+ def to_rgb()
45
+ hue = h.to_f
46
+ saturation = s.to_f
47
+ value = v.to_f
48
+
49
+ chroma = (value * saturation).to_f
50
+ hPrime = hue/60.0
51
+ x = (chroma * (1 - (hPrime % 2 - 1).abs)).to_f
52
+
53
+ if 0 <= hPrime && hPrime < 1
54
+ rgb = [chroma, x, 0]
55
+ elsif 1 <= hPrime && hPrime < 2
56
+ rgb = [x, chroma, 0]
57
+ elsif 2 <= hPrime && hPrime < 3
58
+ rgb = [0, chroma, x]
59
+ elsif 3 <= hPrime && hPrime < 4
60
+ rgb = [0, x, chroma]
61
+ elsif 4 <= hPrime && hPrime < 5
62
+ rgb = [x, 0, chroma]
63
+ elsif 5 <= hPrime && hPrime < 6
64
+ rgb = [chroma, 0, x]
65
+ else
66
+ rgb = [0,0,0]
67
+ end
68
+
69
+ match = (value - chroma).to_f
70
+
71
+ rgb[0] = (rgb[0] + match).to_f
72
+ rgb[1] = (rgb[1] + match).to_f
73
+ rgb[2] = (rgb[2] + match).to_f
74
+
75
+ return RgbColor.new(rgb[0],rgb[1],rgb[2])
76
+ end
35
77
  end
36
78
  end
@@ -1,3 +1,3 @@
1
1
  module Savio
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
data/test.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'savio'
2
+
3
+ $colorSlider = ColorSlider.new(x: 200, y:200)
4
+
5
+ update do
6
+ puts $colorSlider.hsv
7
+ end
8
+
9
+ show()
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: savio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - TheRealSavi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-03-13 00:00:00.000000000 Z
11
+ date: 2020-06-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby2d
@@ -42,10 +42,10 @@ files:
42
42
  - bin/setup
43
43
  - lib/.DS_Store
44
44
  - lib/savio.rb
45
- - lib/savio/.DS_Store
46
45
  - lib/savio/Button.rb
47
46
  - lib/savio/ButtonManager.rb
48
47
  - lib/savio/ColorSlider.rb
48
+ - lib/savio/Colors.rb
49
49
  - lib/savio/IORenderable.rb
50
50
  - lib/savio/InputBox.rb
51
51
  - lib/savio/Scene.rb
@@ -54,6 +54,7 @@ files:
54
54
  - lib/savio/io.rb
55
55
  - lib/savio/version.rb
56
56
  - savio.gemspec
57
+ - test.rb
57
58
  homepage: http://www.gibbonsiv.com
58
59
  licenses:
59
60
  - MIT
Binary file