savio 0.1.1 → 0.1.2

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: 94f357a3819daf51a638f59c3467b55e80f0076c51e69bc106aac402a752650f
4
- data.tar.gz: b00b804986834a8ac252ba9c90814b550c0c5361f2f4cee1aeb7936ebbe3ef94
3
+ metadata.gz: 3b9718ed09ba01941d92b7d59dabf07b88e4fe6d44c39f8d3d10e06b8467c7ca
4
+ data.tar.gz: f86e29857ba48e2b9108058674517106b74acd5bcdb55438ad50e71ade537ace
5
5
  SHA512:
6
- metadata.gz: 327c6bdce586b41a05bfdf539a5baf2d9cb9b76d7911f9cb7f8116546917f3866343446440775c28939ff0c02c35acbad04082b0ebaebf7af0f113770232b054
7
- data.tar.gz: a638f761b674dd600aa510abfba0beac19ab6f6a56efd3f3d586cf817a9e4bc5dc0bcefe6e8aa8730b707413a11fee7a70fa306c64fd8016946d94db3ad376fb
6
+ metadata.gz: acc7c66f028e73ab48b15367a933c0fc10c6d41839ea495646578281ba659e4146e10fb74159aad703a2955511b37ed2009a69dcfef274cbf9c4d70d0558179a
7
+ data.tar.gz: 65c9e78ac89080304c0315ffe36699658aa43321a12ef8847a6a697db9dc86ba2d8ad4c93ee40b27e103458174aef880e86a17d10999f3d23095403db4d17935
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  # | *Sav***IO**
2
+ [![Gem Version](https://badge.fury.io/rb/savio.svg)](https://badge.fury.io/rb/savio)
2
3
  ## What is it?
3
4
 
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 :
@@ -47,7 +48,7 @@ then in your program do:
47
48
 
48
49
  ### Params:
49
50
 
50
- all SavIO object's parameters are optional, if it is not defined then it will use the deafult.
51
+ all SavIO object's parameters are optional, if it is not defined then it will use the default.
51
52
 
52
53
  | Variable | Description | Default |
53
54
  |--|--|--|
@@ -55,8 +56,8 @@ all SavIO object's parameters are optional, if it is not defined then it will us
55
56
  | y | The y Position | 0
56
57
  | z | The z Position | 1
57
58
  | size | The scaling value | 10
58
- | enabled | If the slider slides | true
59
- | displayName | The label on top | "Default"
59
+ | enabled | If the object can be interacted with by the user | true
60
+ | displayName | The name of the object | "Default"
60
61
  | draggingEnabled | If the object itself can be moved around the window | false
61
62
  | dragType | "move" or "duplicate" If draggingEnabled is true, this is what happens when it drags | "move"
62
63
  | shown | If the object is shown or not | true
@@ -85,9 +86,9 @@ all SavIO object's parameters are optional, if it is not defined then it will us
85
86
  |min | The minimum value of the slider | 0
86
87
  |max | The maximum value of the slider | 100
87
88
  |value| The value of the slider | Random between min and max
88
- |showValue| If the value should be shown| true
89
+ |showValue| If the value label should be shown| true
89
90
  |labelColor| The color of the labels| '#F5F5F5'
90
- |sliderColor|Color of the slider line | '#757575'
91
+ |sliderColor| Color of the slider line | '#757575'
91
92
  |knobColor| Color of the sliders knob | '#5BB36A'
92
93
 
93
94
  ### Example:
@@ -99,7 +100,8 @@ all SavIO object's parameters are optional, if it is not defined then it will us
99
100
  | Method | Description |
100
101
  |--|--|
101
102
  |.moveKnob(**x**) | Moves the knob to that **x** pixel location on the screen and finds and sets equivalent value for the slider |
102
- | .setValue(**value**) | Sets the sliders value to that **value** and moves the knob there |
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)|
103
105
 
104
106
  ### Basic Usage:
105
107
 
@@ -115,34 +117,52 @@ all SavIO object's parameters are optional, if it is not defined then it will us
115
117
  |--|--|--|
116
118
  |value | Anything you want to be tied to the button | 0
117
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
118
125
  |buttonManager | The manager that controls this button | nil
119
126
  |enforceManager| When a manager is defined, whether the manager should force this button to follow its rule | true
120
- |baseColor| The color of the labels| '#F5F5F5'
121
- |selectedColor|Color of the slider line | '#00B3EC'
122
- |labelColor| Color of the sliders knob | '#F5F5F5'
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'
123
130
 
124
131
  ### Example:
125
132
 
126
- buttonBob = Button.new(
133
+ clickyBob = Button.new(
127
134
  x: 830, y: 90,
128
135
  displayName: "Enable Bob?",
129
- selectedColor: "purple"
136
+ selectedColor: "purple",
137
+ type : 'clicker'
130
138
  )
139
+ -----
140
+ anotherButton = Button.new(
141
+ x: 830, y: 150,
142
+ displayName: "Enable flux capacitors?",
143
+ )
144
+
131
145
 
132
146
  ### Methods:
133
147
  ----
134
148
  | Method | Description |
135
149
  |--|--|
136
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. |
137
- | .deslect(*enforce*) | Deselects the button. *enforce* works the same as .select() *(see above)* |
151
+ |.deselect(*enforce*) | Deselects the button. *enforce* works the same as .select() *(see above)* |
138
152
  |.toggle(*enforce*) | Toggles the buttons Selection state. *enforce* works the same as .select() *(see above)*
139
-
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)|
140
156
 
141
157
  ### Basic Usage:
142
158
 
143
- if buttonBob.selected == true
159
+ clickyBob.onClick do
144
160
  puts "Bob is now enabled! Hi Bob!"
145
161
  end
162
+ -----
163
+ if anotherButton.selected == true do
164
+ puts "Flux capacitors now enabled"
165
+ end
146
166
 
147
167
  # | ButtonManager:
148
168
  Now I'm sure after reading how a **button** works you're saying, "What in the hell is a **manager**?"
@@ -220,6 +240,7 @@ A **ButtonManager** is a simple and easy way to **manage a group of multiple but
220
240
  |.select() | Focuses the text box and lets you type in it |
221
241
  |.deselect() | Loses focus of the text box and finalizes value|
222
242
  |.toggle() | Toggles the selection value of the text box |
243
+ |.selected=(**bool**) | Selects or deselects the text box based on the **bool** |
223
244
 
224
245
  ### Basic Usage:
225
246
 
@@ -3,7 +3,7 @@ module Savio
3
3
  include IORenderable
4
4
 
5
5
  attr_accessor :value, :enforceManager
6
- attr_reader :selected, :buttonManager
6
+ attr_reader :selected, :buttonManager, :style, :length, :height, :type, :timeLastClicked, :cooldownTime
7
7
 
8
8
  @@buttons = []
9
9
  def self.buttons
@@ -21,10 +21,12 @@ module Savio
21
21
  @selectedColor = args[:selectedColor] || '#00B3EC'
22
22
  @labelColor = args[:labelColor] || '#F5F5F5'
23
23
 
24
+ @cooldownTime = args[:cooldownTime] || 0.0
25
+ @timeLastClicked = 0.0
26
+
24
27
  @selected = args[:selected] || false
25
28
 
26
29
  @buttonManager = args[:buttonManager] || nil
27
-
28
30
  @enforceManager = args[:enforceManager] || true
29
31
 
30
32
  @type = args[:type] || 'toggle'
@@ -32,16 +34,43 @@ module Savio
32
34
  @type = 'toggle'
33
35
  end
34
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
+
35
49
  @onClick = Proc.new {}
36
50
 
37
51
  build()
38
52
  end
39
53
 
54
+ def size=(size)
55
+ @length = size * 10
56
+ @height = size * 1.2
57
+ super(size)
58
+ end
40
59
  def type=(newType)
41
60
  if newType == 'toggle' || newType == 'clicker'
42
61
  @type = newType
43
62
  end
44
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
45
74
 
46
75
  def baseColor=(c)
47
76
  @baseColor = c
@@ -56,6 +85,14 @@ module Savio
56
85
  rebuild()
57
86
  end
58
87
 
88
+ def selected=(bool)
89
+ if bool == true
90
+ select()
91
+ elsif bool == false
92
+ deselect()
93
+ end
94
+ end
95
+
59
96
  def onClick(&proc)
60
97
  @onClick = proc
61
98
  end
@@ -79,21 +116,22 @@ module Savio
79
116
  end
80
117
 
81
118
  def select(enforce = @enforceManager)
82
- click()
83
- if enforce == true && @buttonManager != nil
84
- @buttonManager.select(self)
85
- else
86
- @selectCircle.add
87
- @selected = true
88
- if @type == 'clicker'
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
89
127
  if @type == 'clicker'
90
128
  fade = Thread.new {
91
129
  @selectCircle.add
92
130
  sleep(0.06)
93
131
  @selectCircle.remove
94
132
  }
133
+ deselect(enforce)
95
134
  end
96
- deselect(enforce)
97
135
  end
98
136
  end
99
137
  end
@@ -140,26 +178,48 @@ module Savio
140
178
 
141
179
  def build()
142
180
  @shown = true
143
-
144
- @nameLabel = Text.new(
145
- @displayName.to_s,
146
- x: @x + @size * 2, y: @y - @size * 1.5,
147
- size: @size * 2,
148
- color: @labelColor,
149
- z: @z
150
- )
151
- @baseCircle = Circle.new(
152
- x: @x, y: @y,
153
- radius: @size,
154
- color: @baseColor,
155
- z: @z
156
- )
157
- @selectCircle = Circle.new(
158
- x: @x, y: @y,
159
- radius: @size * 0.8,
160
- color: @selectedColor,
161
- z: @z+1
162
- )
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
163
223
 
164
224
  if @buttonManager == nil
165
225
  if @selected
@@ -16,6 +16,8 @@ module Savio
16
16
 
17
17
  @selected = args[:selected] || false
18
18
 
19
+ @size = args[:size] || 20
20
+
19
21
  @shift = false
20
22
 
21
23
  @value = args[:value] || @displayName
@@ -96,6 +98,14 @@ module Savio
96
98
  @display.text = @value + "|"
97
99
  end
98
100
 
101
+ def selected=(bool)
102
+ if bool == true
103
+ select()
104
+ elsif bool == false
105
+ deselect()
106
+ end
107
+ end
108
+
99
109
  def select()
100
110
  @selected = true
101
111
 
@@ -72,6 +72,10 @@ module Savio
72
72
  end
73
73
  end
74
74
 
75
+ def value=(value)
76
+ setValue(value)
77
+ end
78
+
75
79
  def setValue(value)
76
80
  if value.between?(@min, @max)
77
81
  to_max = @x + @length
@@ -31,7 +31,16 @@ on :mouse do |event|
31
31
  Button.buttons.each do |button|
32
32
 
33
33
  if button.draggingEnabled
34
- if event.x.between?(button.x-button.size,button.x+button.size) && event.y.between?(button.y-button.size,button.y+button.size)
34
+ check = Struct.new(:x,:y).new(false,false)
35
+ case button.style
36
+ when 'box'
37
+ check.y = event.y.between?(button.y,button.y+button.height)
38
+ check.x = event.x.between?(button.x,button.x+button.length)
39
+ when 'badge'
40
+ check.x = event.x.between?(button.x-button.size,button.x+button.size)
41
+ check.y = event.y.between?(button.y-button.size,button.y+button.size)
42
+ end
43
+ if check.x && check.y
35
44
  button.allowDrag = true
36
45
  end
37
46
  if button.allowDrag
@@ -45,7 +54,16 @@ on :mouse do |event|
45
54
  Button.buttons.each do |button|
46
55
 
47
56
  if button.shown && button.enabled
48
- if event.x.between?(button.x-button.size,button.x+button.size) && event.y.between?(button.y-button.size,button.y+button.size)
57
+ check = Struct.new(:x,:y).new(false,false)
58
+ case button.style
59
+ when 'box'
60
+ check.y = event.y.between?(button.y,button.y+button.height)
61
+ check.x = event.x.between?(button.x,button.x+button.length)
62
+ when 'badge'
63
+ check.x = event.x.between?(button.x-button.size,button.x+button.size)
64
+ check.y = event.y.between?(button.y-button.size,button.y+button.size)
65
+ end
66
+ if check.x && check.y
49
67
  if button.buttonManager == nil
50
68
  button.toggle
51
69
  else
@@ -1,3 +1,3 @@
1
1
  module Savio
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
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.1
4
+ version: 0.1.2
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-12 00:00:00.000000000 Z
11
+ date: 2020-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby2d