savio 0.1.2 → 0.1.5

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: 3b9718ed09ba01941d92b7d59dabf07b88e4fe6d44c39f8d3d10e06b8467c7ca
4
- data.tar.gz: f86e29857ba48e2b9108058674517106b74acd5bcdb55438ad50e71ade537ace
3
+ metadata.gz: 1a8f5301cac1dd32ee16091ccc8591adb75ffaa16914a432ff98a930977dc3ed
4
+ data.tar.gz: 20c6ef7442e96b9f3d05180240fbf98391281b4304238754c4c3b7be248726ad
5
5
  SHA512:
6
- metadata.gz: acc7c66f028e73ab48b15367a933c0fc10c6d41839ea495646578281ba659e4146e10fb74159aad703a2955511b37ed2009a69dcfef274cbf9c4d70d0558179a
7
- data.tar.gz: 65c9e78ac89080304c0315ffe36699658aa43321a12ef8847a6a697db9dc86ba2d8ad4c93ee40b27e103458174aef880e86a17d10999f3d23095403db4d17935
6
+ metadata.gz: 8ee92641fa82e6ce0c73609e8367ae10df5968f5adf6a3313103201fadf665db4f4324cdbcff0f2f336e9e7b7f40b0ca0f143a5c5584ec469c20631980616a49
7
+ data.tar.gz: 0e95bd3a5840fd132b65e06d9df92d75fca22c1432e3f6177b9380546e5fc7a60677ad774ad487e28957c955feb7066a90ce3a0e9e8ed2ec137ce4ed14694d4c
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.2
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - TheRealSavi
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-03-13 00:00:00.000000000 Z
11
+ date: 2022-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby2d
@@ -31,35 +31,13 @@ email:
31
31
  executables: []
32
32
  extensions: []
33
33
  extra_rdoc_files: []
34
- files:
35
- - ".DS_Store"
36
- - ".gitignore"
37
- - Gemfile
38
- - LICENSE.txt
39
- - README.md
40
- - Rakefile
41
- - bin/console
42
- - bin/setup
43
- - lib/.DS_Store
44
- - lib/savio.rb
45
- - lib/savio/.DS_Store
46
- - lib/savio/Button.rb
47
- - lib/savio/ButtonManager.rb
48
- - lib/savio/ColorSlider.rb
49
- - lib/savio/IORenderable.rb
50
- - lib/savio/InputBox.rb
51
- - lib/savio/Scene.rb
52
- - lib/savio/Slider.rb
53
- - lib/savio/hsv2rgb.rb
54
- - lib/savio/io.rb
55
- - lib/savio/version.rb
56
- - savio.gemspec
34
+ files: []
57
35
  homepage: http://www.gibbonsiv.com
58
36
  licenses:
59
37
  - MIT
60
38
  metadata:
61
39
  source_code_uri: https://github.com/TheRealSavi/savio
62
- post_install_message:
40
+ post_install_message:
63
41
  rdoc_options: []
64
42
  require_paths:
65
43
  - lib
@@ -74,8 +52,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
52
  - !ruby/object:Gem::Version
75
53
  version: '0'
76
54
  requirements: []
77
- rubygems_version: 3.0.3
78
- signing_key:
55
+ rubygems_version: 3.1.4
56
+ signing_key:
79
57
  specification_version: 4
80
58
  summary: Adds IO Elements to Ruby2D
81
59
  test_files: []
data/.DS_Store DELETED
Binary file
data/.gitignore DELETED
@@ -1,8 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
data/Gemfile DELETED
@@ -1,6 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- # Specify your gem's dependencies in savio.gemspec
4
- gemspec
5
-
6
- gem "rake", "~> 12.0"
data/LICENSE.txt DELETED
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2020 TheRealSavi
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
data/README.md DELETED
@@ -1,252 +0,0 @@
1
- # | *Sav***IO**
2
- [![Gem Version](https://badge.fury.io/rb/savio.svg)](https://badge.fury.io/rb/savio)
3
- ## What is it?
4
-
5
- SavIO is an input/output library created to be used with **Ruby2D**. It adds multiple ways for the user to interact with your application, including :
6
-
7
- - Sliders
8
- - Buttons
9
- - Text Input
10
- - Color Picker (Work In Progress)
11
-
12
- ## How to install?
13
-
14
- Easy! do:
15
-
16
- gem install savio
17
-
18
- then in your program do:
19
-
20
- require "savio"
21
-
22
- ## How do they work?
23
-
24
-
25
- Good question! Part of the goal when developing SavIO was to make it as **intuitive** and **simple** as possible, while also being highly **versatile**, **powerful**, and **customizable**.
26
-
27
- # | ALL OBJECTS
28
- #### All SavIO objects inherit these basic properties.
29
-
30
- #### You can access an array of all SavIO Objects by using Savio.elements
31
- ##### Example:
32
-
33
- Savio.elements.each do |element|
34
- element.x += 1 #Moves all elements over by 1 pixel
35
- end
36
-
37
- ##### SavIO Commands:
38
- Savio.hide #This will hide all elements
39
- Savio.unhide #This will bring them all back
40
- Savio.stop #This stops the mouse and keyboard event listeners
41
- Savio.listen #Starts the mouse and keyboard event listeners
42
- Savio.listening #returns true or false if its listening or not
43
-
44
-
45
- ## **Creation:**
46
-
47
- myAwesomeOBJECT = OBJECTNAME.new(params)
48
-
49
- ### Params:
50
-
51
- all SavIO object's parameters are optional, if it is not defined then it will use the default.
52
-
53
- | Variable | Description | Default |
54
- |--|--|--|
55
- | x | The x position | 0
56
- | y | The y Position | 0
57
- | z | The z Position | 1
58
- | size | The scaling value | 10
59
- | enabled | If the object can be interacted with by the user | true
60
- | displayName | The name of the object | "Default"
61
- | draggingEnabled | If the object itself can be moved around the window | false
62
- | dragType | "move" or "duplicate" If draggingEnabled is true, this is what happens when it drags | "move"
63
- | shown | If the object is shown or not | true
64
-
65
- ### Example:
66
-
67
- `myAwesomeOBJECT = OBJECTNAME.new(x: 100, y: 30, z:2, size: 13, displayName: "Swag")`
68
-
69
-
70
- ### Methods:
71
- ----
72
- | Method | Description |
73
- |--|--|
74
- |.remove() | removes the object from the screen |
75
- | .add() | adds the object back to the screen |
76
- |.rebuild() | rebuilds the object |
77
- |.context() | returns a hash with all the variables that make the object |
78
-
79
- # | Sliders:
80
- **On top of** all the basic parameters and methods a **Slider** can **also** use these:
81
-
82
- ### Params:
83
- | Variable | Description | Default |
84
- |--|--|--|
85
- |length | How long the slider is | 100
86
- |min | The minimum value of the slider | 0
87
- |max | The maximum value of the slider | 100
88
- |value| The value of the slider | Random between min and max
89
- |showValue| If the value label should be shown| true
90
- |labelColor| The color of the labels| '#F5F5F5'
91
- |sliderColor| Color of the slider line | '#757575'
92
- |knobColor| Color of the sliders knob | '#5BB36A'
93
-
94
- ### Example:
95
-
96
- slippyTheSlider = Slider.new(x: 830, y: 40, length: 220, draggingEnabled: true, dragType: "duplicate")
97
-
98
- ### Methods:
99
- ----
100
- | Method | Description |
101
- |--|--|
102
- |.moveKnob(**x**) | Moves the knob to that **x** pixel location on the screen and finds and sets equivalent value for the slider |
103
- |.setValue(**value**)|Sets the sliders value to that value and moves the knob there (same as .value=)|
104
- | .value = **value** | Sets the sliders value to that **value** and moves the knob there (same as .setValue)|
105
-
106
- ### Basic Usage:
107
-
108
- if slippyTheSlider.value == 69
109
- puts "nice"
110
- end
111
-
112
- # | Buttons:
113
- **On top of** all the basic parameters and methods a **Button** can **also** use these:
114
-
115
- ### Params:
116
- | Variable | Description | Default |
117
- |--|--|--|
118
- |value | Anything you want to be tied to the button | 0
119
- |selected | Whether the button is selected or not | false
120
- |type | Whether the button will act normally('toggle') or instantly deselect itself('clicker') | 'toggle'
121
- |style|'box' or 'badge'. Determines the style the button should be rendered with| 'badge'
122
- |length|Only used for the 'box' style. Determines the length of the button| @size * 10
123
- |height|Only used for the 'box' style. Determines the height of the button| @size * 1.2
124
- |cooldownTime|Time needed to wait in seconds until the button may be clicked again| 0.0
125
- |buttonManager | The manager that controls this button | nil
126
- |enforceManager| When a manager is defined, whether the manager should force this button to follow its rule | true
127
- |baseColor| Color shown when the button is deselected| '#F5F5F5'
128
- |selectedColor|Color shown when the button is selected | '#00B3EC'
129
- |labelColor| Color of the buttons displayName label | '#F5F5F5'
130
-
131
- ### Example:
132
-
133
- clickyBob = Button.new(
134
- x: 830, y: 90,
135
- displayName: "Enable Bob?",
136
- selectedColor: "purple",
137
- type : 'clicker'
138
- )
139
- -----
140
- anotherButton = Button.new(
141
- x: 830, y: 150,
142
- displayName: "Enable flux capacitors?",
143
- )
144
-
145
-
146
- ### Methods:
147
- ----
148
- | Method | Description |
149
- |--|--|
150
- |.select(*enforce*) | Selects the button. if left empty *enforce* will be the buttons **@enforceManager** state. when true the manager will enforce its rule on the button. when false, the button will perform as if it were not controlled. |
151
- |.deselect(*enforce*) | Deselects the button. *enforce* works the same as .select() *(see above)* |
152
- |.toggle(*enforce*) | Toggles the buttons Selection state. *enforce* works the same as .select() *(see above)*
153
- |.selected = **bool** | Selects or deselects the button whether given true or false |
154
- |.timeLastClicked| returns the unix time of the last click
155
- | .onClick | Takes in a proc that will be ran every time the button gets selected (See example and basic usage)|
156
-
157
- ### Basic Usage:
158
-
159
- clickyBob.onClick do
160
- puts "Bob is now enabled! Hi Bob!"
161
- end
162
- -----
163
- if anotherButton.selected == true do
164
- puts "Flux capacitors now enabled"
165
- end
166
-
167
- # | ButtonManager:
168
- Now I'm sure after reading how a **button** works you're saying, "What in the hell is a **manager**?"
169
-
170
- ## Let me explain, it's **very simple**.
171
- A **ButtonManager** is a simple and easy way to **manage a group of multiple buttons**. More specifically, it **controls** the state of **all the buttons** in its group **depending on** the state of **all the other buttons** in its group.
172
-
173
- ## This is not considered a standard SavIO Object and does not inherit the typical parameters and methods.
174
-
175
- ### Creation:
176
-
177
- theSwagMaster = ButtonManager.new(type: "checkbox")
178
-
179
-
180
- ### Params:
181
- | Param |Description | Default|
182
- |--|--|--|
183
- | type | either "radio" or "checkbox" Decides how the manager should control its buttons | "radio"
184
-
185
- ### Methods:
186
- ----
187
- | Method | Description |
188
- |--|--|
189
- |.addButton(**button**) | Adds the **button** to the group of buttons controlled by the manager. This is done automatically when a buttons **@buttonManager** is set to the manager. If called this way however, it will also automatically set the buttons **@buttonManager** to this manager, so they will always be linked.|
190
- |.removeButton(**button**, *overwrite*) | Removes the **button** from the group of buttons controlled by the manager. This is done automatically when a buttons **@buttonManager** is changed or removed. *overwrite* is not required and is automatically set to true. When true, this will overwrite the **button**'s **@buttonManager** and set it to nil. When false it will not overwrite the buttons **@buttonManager**. **It is highly recommended not to change this since** it will desynchronize the button and manager and cause issues. It is used internally to prevent recursion when removed the manager from the **button** rather than from the **manager**
191
- |.toggle(**button**) | Toggles the **button** according to the rule of the manager. This is done automatically by the **button** when **button**.toggle() is called and this manager is used. This is true also for .select() and .deselect().
192
- | .select(**button**) | Selects the **button** according to the rule of the manager.
193
- | .deselect(**button**) | Deselects the **button** according to the rule of the manager |
194
-
195
- ### Variables :
196
- |Variable|Description | Type |
197
- |--|--|--|
198
- | buttons |an array of all the buttons that are controlled by this manager |array |
199
- | selected | an array of all the buttons that are currently selected and in control of this manager | array |
200
-
201
-
202
- ### Basic Usage:
203
-
204
- theSwagMaster.selected.each do |button|
205
- puts button.to_s + " Is currently selected!"
206
- end
207
- --
208
-
209
- if theSwagMaster.selected.include?(button)
210
- puts "This button is currently selected!"
211
- end
212
-
213
- # | InputBox:
214
- **On top of** all the basic parameters and methods an **InputBox** can **also** use these:
215
- ### Params:
216
- | Variable | Description | Default |
217
- |--|--|--|
218
- |selected | Whether it is currently focused | false
219
- |value | The current text input in the field | **@displayName**
220
- |displayName | The value shown in the text field when nothing is in it. AKA the default value. if a value was specified, this will be overwritten with it. | **@value** or "Default"
221
- |length| The length of the text box | **@size** * 10
222
- |width| The width of the text box| **@size** * 1.2
223
- |color| The color of the box when not focused| 'gray'
224
- |activeColor|The color of the box when focused | 'green'
225
-
226
- ### Example:
227
-
228
- askMeAnything = InputBox.new(
229
- x: 830, y: 180, size: 30,
230
- activeColor: 'purple',
231
- displayName: "What would you like to ask?"
232
- )
233
-
234
- ### Methods:
235
- ----
236
- | Method | Description |
237
- |--|--|
238
- |.addKey(**key**) | Simulates a key input of given **key** |
239
- | .updateDisplay() | Adds the line follower marker to the text box |
240
- |.select() | Focuses the text box and lets you type in it |
241
- |.deselect() | Loses focus of the text box and finalizes value|
242
- |.toggle() | Toggles the selection value of the text box |
243
- |.selected=(**bool**) | Selects or deselects the text box based on the **bool** |
244
-
245
- ### Basic Usage:
246
-
247
- if askMeAnything.value == "Favorite Color?"
248
- puts "Purple"
249
- end
250
-
251
- # | ColorSlider:
252
- These technically work but I'm not done with them so for now I wont bother with documentation.
data/Rakefile DELETED
@@ -1,2 +0,0 @@
1
- require "bundler/gem_tasks"
2
- task :default => :spec
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "savio"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start(__FILE__)
data/bin/setup DELETED
@@ -1,8 +0,0 @@
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/.DS_Store DELETED
Binary file
data/lib/savio/.DS_Store DELETED
Binary file
data/lib/savio/Button.rb DELETED
@@ -1,245 +0,0 @@
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
- @value = args[:value] || 0
19
-
20
- @baseColor = args[:baseColor] || '#F5F5F5'
21
- @selectedColor = args[:selectedColor] || '#00B3EC'
22
- @labelColor = args[:labelColor] || '#F5F5F5'
23
-
24
- @cooldownTime = args[:cooldownTime] || 0.0
25
- @timeLastClicked = 0.0
26
-
27
- @selected = args[:selected] || false
28
-
29
- @buttonManager = args[:buttonManager] || nil
30
- @enforceManager = args[:enforceManager] || true
31
-
32
- @type = args[:type] || 'toggle'
33
- if @type != 'toggle' && @type != 'clicker'
34
- @type = 'toggle'
35
- end
36
-
37
- @style = args[:style] || 'badge'
38
- if @style != 'box' && @style != 'badge'
39
- @style = 'badge'
40
- end
41
-
42
- if @style == 'box'
43
- @size *= 2
44
- @labelColor = args[:baseColor] || '#01042A'
45
- end
46
- @length = args[:length] || @size * 10
47
- @height = args[:height] || @size * 1.2
48
-
49
- @onClick = Proc.new {}
50
-
51
- build()
52
- end
53
-
54
- def size=(size)
55
- @length = size * 10
56
- @height = size * 1.2
57
- super(size)
58
- end
59
- def type=(newType)
60
- if newType == 'toggle' || newType == 'clicker'
61
- @type = newType
62
- end
63
- end
64
- def style=(style)
65
- if style == 'box' || style == 'badge'
66
- @style = style
67
- rebuild()
68
- end
69
- end
70
-
71
- def cooldownTime=(cooldown)
72
- @cooldownTime = cooldown.to_f
73
- end
74
-
75
- def baseColor=(c)
76
- @baseColor = c
77
- rebuild()
78
- end
79
- def selectedColor=(c)
80
- @selectedColor = c
81
- rebuild()
82
- end
83
- def labelColor=(c)
84
- @labelColor = c
85
- rebuild()
86
- end
87
-
88
- def selected=(bool)
89
- if bool == true
90
- select()
91
- elsif bool == false
92
- deselect()
93
- end
94
- end
95
-
96
- def onClick(&proc)
97
- @onClick = proc
98
- end
99
-
100
- def buttonManager=(newManager)
101
- if @buttonManager != nil
102
- if newManager.class.name != 'Savio::ButtonManager'
103
- raise ArgumentError, 'Given object ' + newManager.to_s + ' is not a ButtonManager. Must be of type ButtonManager'
104
- end
105
- @buttonManager.removeButton(self, false)
106
- end
107
-
108
- if newManager != nil
109
- @buttonManager = newManager
110
- if @buttonManager.buttons.include?(self) != true
111
- @buttonManager.addButton(self)
112
- end
113
- else
114
- @buttonManager = nil
115
- end
116
- end
117
-
118
- def select(enforce = @enforceManager)
119
- if Time.now.to_f - @timeLastClicked.to_f >= @cooldownTime.to_f
120
- @timeLastClicked = Time.now.to_f
121
- click()
122
- if enforce == true && @buttonManager != nil
123
- @buttonManager.select(self)
124
- else
125
- @selectCircle.add
126
- @selected = true
127
- if @type == 'clicker'
128
- fade = Thread.new {
129
- @selectCircle.add
130
- sleep(0.06)
131
- @selectCircle.remove
132
- }
133
- deselect(enforce)
134
- end
135
- end
136
- end
137
- end
138
-
139
- def deselect(enforce = @enforceManager)
140
- if enforce == true && @buttonManager != nil
141
- @buttonManager.deselect(self)
142
- else
143
- @selectCircle.remove
144
- @selected = false
145
- end
146
- end
147
-
148
- def toggle(enforce = @enforceManager)
149
- if @selected
150
- deselect(enforce)
151
- else
152
- select(enforce)
153
- end
154
- end
155
-
156
- def remove()
157
- super()
158
- @nameLabel.remove
159
- @baseCircle.remove
160
- @selectCircle.remove
161
- end
162
-
163
- def add()
164
- super()
165
- @nameLabel.add
166
- @baseCircle.add
167
- @selectCircle.add
168
- if @selected
169
- select()
170
- else
171
- deselect()
172
- end
173
- end
174
-
175
- def click()
176
- @onClick.call()
177
- end
178
-
179
- def build()
180
- @shown = true
181
- case @style
182
- when 'badge'
183
- @baseCircle = Circle.new(
184
- x: @x, y: @y,
185
- radius: @size,
186
- color: @baseColor,
187
- z: @z
188
- )
189
- @selectCircle = Circle.new(
190
- x: @x, y: @y,
191
- radius: @size * 0.8,
192
- color: @selectedColor,
193
- z: @z+1
194
- )
195
- @nameLabel = Text.new(
196
- @displayName.to_s,
197
- x: @x + @size * 2, y: @y - @size * 1.5,
198
- size: @size * 2,
199
- color: @labelColor,
200
- z: @z
201
- )
202
- when 'box'
203
- @baseCircle = Rectangle.new(
204
- x: @x, y: @y,
205
- height: @height, width: @length,
206
- color: @baseColor,
207
- z: @z
208
- )
209
- @selectCircle = Rectangle.new(
210
- x: @x + (@height * 0.1), y: @y + (@height * 0.1),
211
- height: @height - (@height * 0.2), width: @length - (@height * 0.2),
212
- color: @selectedColor,
213
- z: @z+1
214
- )
215
- @nameLabel = Text.new(
216
- @displayName.to_s,
217
- x: @x, y: @y,
218
- size: @size,
219
- color: @labelColor,
220
- z: @z+2
221
- )
222
- end
223
-
224
- if @buttonManager == nil
225
- if @selected
226
- select()
227
- else
228
- deselect()
229
- end
230
- else
231
- if @buttonManager.class.name != 'Savio::ButtonManager'
232
- raise ArgumentError, 'Given object ' + @buttonManager.to_s + ' is not a ButtonManager. Must be of type ButtonManager'
233
- end
234
- @buttonManager.addButton(self)
235
-
236
- if @selected
237
- @buttonManager.select(self)
238
- else
239
- @buttonManager.deselect(self)
240
- end
241
- end
242
-
243
- end
244
- end
245
- end