RIUI 0.1.0
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 +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +48 -0
- data/LICENSE.txt +21 -0
- data/README.md +104 -0
- data/RIUI.gemspec +29 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/example/SF-Pro-Text-Bold.otf +0 -0
- data/example/example.rb +70 -0
- data/example/tree.png +0 -0
- data/lib/RIUI.rb +8 -0
- data/lib/RIUI/RIActions.rb +47 -0
- data/lib/RIUI/RIButton.rb +62 -0
- data/lib/RIUI/RIImage.rb +21 -0
- data/lib/RIUI/RISlider.rb +128 -0
- data/lib/RIUI/version.rb +3 -0
- metadata +120 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ad50c5595240c667e52504464273b37fbf6907d87e670af33ad61537af7e4d63
|
4
|
+
data.tar.gz: 6e3d9e85d2a4a836a159bebb2d1968a473858b7db9d5b8a5cb6d6c8d8bfac141
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e8446c549bf94554e82c03440180a8997ce29d2a1784c6274af779c0ce84ab50e783f6f292c90514b7f61a76146fb0a18b91c5702f9599ba5abc69c340f523b7
|
7
|
+
data.tar.gz: 5c88ef6c7bd7d61ae974554a6c68ed4d973e55924998f5e630f175c653bad298b735eb29e6624af3fbe1aee023bd38b03022c126d9924f2a193c9821a45eb648
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
RIUI (0.1.0)
|
5
|
+
ruby2d (~> 0.5.1)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
ast (2.4.0)
|
11
|
+
diff-lcs (1.3)
|
12
|
+
hike (1.2.3)
|
13
|
+
opal (0.11.0)
|
14
|
+
ast (>= 2.3.0)
|
15
|
+
hike (~> 1.2)
|
16
|
+
parser (= 2.3.3.1)
|
17
|
+
sourcemap (~> 0.1.0)
|
18
|
+
parser (2.3.3.1)
|
19
|
+
ast (~> 2.2)
|
20
|
+
rake (10.5.0)
|
21
|
+
rspec (3.7.0)
|
22
|
+
rspec-core (~> 3.7.0)
|
23
|
+
rspec-expectations (~> 3.7.0)
|
24
|
+
rspec-mocks (~> 3.7.0)
|
25
|
+
rspec-core (3.7.1)
|
26
|
+
rspec-support (~> 3.7.0)
|
27
|
+
rspec-expectations (3.7.0)
|
28
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
+
rspec-support (~> 3.7.0)
|
30
|
+
rspec-mocks (3.7.0)
|
31
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
32
|
+
rspec-support (~> 3.7.0)
|
33
|
+
rspec-support (3.7.1)
|
34
|
+
ruby2d (0.5.1)
|
35
|
+
opal (~> 0.11)
|
36
|
+
sourcemap (0.1.1)
|
37
|
+
|
38
|
+
PLATFORMS
|
39
|
+
ruby
|
40
|
+
|
41
|
+
DEPENDENCIES
|
42
|
+
RIUI!
|
43
|
+
bundler (~> 1.16)
|
44
|
+
rake (~> 10.0)
|
45
|
+
rspec (~> 3.0)
|
46
|
+
|
47
|
+
BUNDLED WITH
|
48
|
+
1.16.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 lukecrum20
|
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
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
# RIUI
|
2
|
+
|
3
|
+
A small, simple Ruby user interface framework
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'RIUI'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install RIUI
|
20
|
+
|
21
|
+
# Usage
|
22
|
+
|
23
|
+
First include the gem in your Ruby file.
|
24
|
+
```rb
|
25
|
+
include 'RIUI'
|
26
|
+
```
|
27
|
+
|
28
|
+
**Actions:**
|
29
|
+
|
30
|
+
When you create a new view, you must also create a new instace of `RIActions`. This is necessary to provide functionality to UI elements.
|
31
|
+
```rb
|
32
|
+
actions = RIActions.new
|
33
|
+
```
|
34
|
+
You must then add each element to the action class:
|
35
|
+
```rb
|
36
|
+
button = RIButton.new(....)
|
37
|
+
slider = RISlider.new(....)
|
38
|
+
actions.add(button)
|
39
|
+
actions.add(slider)
|
40
|
+
```
|
41
|
+
|
42
|
+
**Buttons:**
|
43
|
+
|
44
|
+
To create a new button object:
|
45
|
+
```rb
|
46
|
+
button = RIButton.new(x: 125, y: 100, width: 150, height: 100, color: "green", hover_color: "blue")
|
47
|
+
```
|
48
|
+
|
49
|
+
See docs for descriptions of each arrtibute
|
50
|
+
|
51
|
+
To add clicking functionality, first create the method you would like to trigger:
|
52
|
+
```rb
|
53
|
+
def click
|
54
|
+
puts 'button clicked'
|
55
|
+
end
|
56
|
+
```
|
57
|
+
Then, create an object with that method:
|
58
|
+
```rb
|
59
|
+
onclick = method(:click)
|
60
|
+
```
|
61
|
+
Alternatively, you can call a method from a class:
|
62
|
+
```rb
|
63
|
+
my_class = MyClass.new
|
64
|
+
onclick = my_class.method(:method_name)
|
65
|
+
```
|
66
|
+
Next, assign the method to the button:
|
67
|
+
```rb
|
68
|
+
button.onClick(onclick: onclick)
|
69
|
+
```
|
70
|
+
|
71
|
+
**Sliders::**
|
72
|
+
|
73
|
+
To create a new slider object:
|
74
|
+
```rb
|
75
|
+
slider = RISlider.new(length: 200, square_size: 10, x: 100, y: 250, ticks: 20)
|
76
|
+
```
|
77
|
+
|
78
|
+
See docs for descriptions of each attribute
|
79
|
+
|
80
|
+
To access the slider's value:
|
81
|
+
```rb
|
82
|
+
slider.value #returns the current value of the slider
|
83
|
+
```
|
84
|
+
To reset the slider to 0 and reset the position of the square:
|
85
|
+
```rb
|
86
|
+
slider.reset
|
87
|
+
```
|
88
|
+
To add call a method when the slider's value changes:
|
89
|
+
```rb
|
90
|
+
def slider_change
|
91
|
+
puts "#{slider.value}
|
92
|
+
end
|
93
|
+
value_changed = method(:slider_change)
|
94
|
+
slider.onChange(onchange: value_changed)
|
95
|
+
```
|
96
|
+
|
97
|
+
|
98
|
+
## Contributing
|
99
|
+
|
100
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/RIUI.
|
101
|
+
|
102
|
+
## License
|
103
|
+
|
104
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/RIUI.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "RIUI/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "RIUI"
|
8
|
+
spec.version = RIUI::VERSION
|
9
|
+
spec.authors = ["lukecrum20"]
|
10
|
+
spec.email = ["lukecrum20@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "A simple user interface framework for Ruby"
|
13
|
+
spec.homepage = "https://github.com/lukecrum/RIUI"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
19
|
+
f.match(%r{^(test|spec|features)/})
|
20
|
+
end
|
21
|
+
spec.bindir = "exe"
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
28
|
+
spec.add_dependency "ruby2d", "~> 0.5.1"
|
29
|
+
end
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "RIUI"
|
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
ADDED
Binary file
|
data/example/example.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
require_relative 'RISlider.rb'
|
2
|
+
require_relative 'RIButton.rb'
|
3
|
+
require_relative 'RIImage.rb'
|
4
|
+
require_relative 'RIActions.rb'
|
5
|
+
|
6
|
+
@image = RIImage.new(x: 500, y: 275, image: "tree.png", width: 100, height: 75)
|
7
|
+
|
8
|
+
def onclick
|
9
|
+
@image.setSize(width: @orig_w, height: @orig_h)
|
10
|
+
@slider1.reset
|
11
|
+
@slider2.reset
|
12
|
+
end
|
13
|
+
def on_slider1_change
|
14
|
+
@image.setSize(height: @slider1.value + @orig_h, width: @slider2.value + @orig_w)
|
15
|
+
end
|
16
|
+
|
17
|
+
def on_slider2_change
|
18
|
+
@image.setSize(height: @slider1.value + @orig_h, width: @slider2.value + @orig_w)
|
19
|
+
end
|
20
|
+
|
21
|
+
actions = RIActions.new
|
22
|
+
onclick = method(:onclick)
|
23
|
+
@button1 = RIButton.new(x: 125, y: 100, width: 150, height: 100, color: "green", hover_color: "blue")
|
24
|
+
@button1.onClick(onclick: onclick)
|
25
|
+
|
26
|
+
@button1.setLabel(text: "Reset", font: "SF-PRO-Text-Bold.otf", size: 25, color: "white")
|
27
|
+
|
28
|
+
@slider1 = RISlider.new(length: 200, square_size: 10, x: 100, y: 250, ticks: 200)
|
29
|
+
@slider1.setColors(line_color: "black", square_color: "blue")
|
30
|
+
@slider1.setLabel(size: 20, font: 'SF-PRO-Text-Bold.otf', color: 'black')
|
31
|
+
slider1Change = method(:on_slider1_change)
|
32
|
+
@slider1.onChange(onchange: slider1Change)
|
33
|
+
|
34
|
+
@slider2 = RISlider.new(length: 200, square_size: 10, x: 100, y: 300, ticks: 200)
|
35
|
+
@slider2.setColors(line_color: "black", square_color: "blue")
|
36
|
+
@slider2.setLabel(size: 20, font: 'SF-PRO-Text-Bold.otf', color: 'black')
|
37
|
+
slider2Change = method(:on_slider2_change)
|
38
|
+
@slider2.onChange(onchange: slider2Change)
|
39
|
+
|
40
|
+
|
41
|
+
actions.add(@slider1)
|
42
|
+
actions.add(@slider2)
|
43
|
+
actions.add(@button1)
|
44
|
+
@orig_h = @image.height
|
45
|
+
@orig_w = @image.width
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
extend Ruby2D::DSL
|
52
|
+
set background: 'white'
|
53
|
+
set title: 'RIUI Example'
|
54
|
+
show
|
55
|
+
|
56
|
+
#on :mouse_down do |e|
|
57
|
+
# if button1.contains(e.x, e.y)
|
58
|
+
# puts 'Reset'
|
59
|
+
# image.setSize(width: @orig_w, height: @orig_h)
|
60
|
+
# slider1.reset
|
61
|
+
# slider2.reset
|
62
|
+
# end
|
63
|
+
#end
|
64
|
+
#update do
|
65
|
+
# slider1.update_actions
|
66
|
+
# slider2.update_actions
|
67
|
+
# if(slider1.active || slider2.active)
|
68
|
+
# image.setSize(height: slider1.value + @orig_h, width: slider2.value + @orig_w)
|
69
|
+
# end
|
70
|
+
#end
|
data/example/tree.png
ADDED
Binary file
|
data/lib/RIUI.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
class RIActions
|
2
|
+
@initialized = false
|
3
|
+
@id = 0
|
4
|
+
def initialize
|
5
|
+
@initialized = true
|
6
|
+
@objects = [0]
|
7
|
+
actions
|
8
|
+
end
|
9
|
+
def add(object)
|
10
|
+
if @objects[0] == 0
|
11
|
+
@objects.pop
|
12
|
+
@objects.push(object)
|
13
|
+
else
|
14
|
+
@objects.push(object)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def holding; @holding; end
|
19
|
+
def active; @active; end
|
20
|
+
def initialized; @initialized; end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def actions
|
25
|
+
extend Ruby2D::DSL
|
26
|
+
@down_action = on :mouse_down do |e|
|
27
|
+
@objects.each do |object|
|
28
|
+
object.mouse_down_actions(e.x, e.y)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
@up_action = on :mouse_up do |e|
|
32
|
+
@objects.each do |object|
|
33
|
+
object.mouse_up_actions
|
34
|
+
end
|
35
|
+
end
|
36
|
+
@hover_action = on :mouse_move do |e|
|
37
|
+
@objects.each do |object|
|
38
|
+
object.mouse_move_actions(e.x, e.y)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
update do
|
42
|
+
@objects.each do |object|
|
43
|
+
object.update_actions
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'ruby2d'
|
2
|
+
|
3
|
+
class RIButton
|
4
|
+
attr_accessor :x, :y, :width, :height, :color, :hover_color, :text, :font, :size, :font_color, :onclick
|
5
|
+
##
|
6
|
+
#x:: X position of the button
|
7
|
+
#y:: Y position of the button
|
8
|
+
#width:: Width of the button
|
9
|
+
#height:: Height of the button
|
10
|
+
#color:: Base color of the button
|
11
|
+
#hover_color:: Color the button will change to when the mouse is hovered over it. Exclude this to have no hover color
|
12
|
+
#text:: Text to show on the button's label
|
13
|
+
#font:: Font of the button's label (note: as of now, you must include the font file within your project for this to work)
|
14
|
+
#size:: Size of the button's label's text
|
15
|
+
#font_color:: Color of the button's label's text
|
16
|
+
##
|
17
|
+
def initialize(opts = [:x, :y, :width, :height, :color, :hover_color, :onclick]) ### Initialize variables and start actions
|
18
|
+
@x = opts[:x] || 0
|
19
|
+
@y = opts[:y] || 0
|
20
|
+
@width = opts[:width] || 100
|
21
|
+
@height = opts[:height] || 50
|
22
|
+
@color = opts[:color] || 'blue'
|
23
|
+
@hover_color = opts[:hover_color] || @color
|
24
|
+
@onclick = opts[:onclick]
|
25
|
+
@rect = Rectangle.new(x: @x, y: @y, z: 0, width: @width, height: @height, color: @color)
|
26
|
+
#actions
|
27
|
+
end
|
28
|
+
|
29
|
+
def contains(x, y) ### Check if the button contains a certain point
|
30
|
+
if @rect.contains?(x, y)
|
31
|
+
true
|
32
|
+
else
|
33
|
+
false
|
34
|
+
end
|
35
|
+
end
|
36
|
+
def onClick(opts = [:onclick])
|
37
|
+
@onclick = opts[:onclick]
|
38
|
+
end
|
39
|
+
def setLabel(opts = [:text, :font, :size, :color]) ### Sets the label of the button
|
40
|
+
@text = opts[:text]
|
41
|
+
@font = opts[:font]
|
42
|
+
@size = opts[:size]
|
43
|
+
@font_color = opts[:font_color]
|
44
|
+
@temp_label = Text.new(x: 0, y: 0, text: @text, font: @font, color: @font_color, size: @size)
|
45
|
+
@label = Text.new(x: @rect.x + (@rect.width / 2) - (@temp_label.width/2), y: @rect.y + (@rect.height / 2) - (@temp_label.height/2), text: @text, font: @font, color: @font_color, size: @size)
|
46
|
+
@temp_label.remove
|
47
|
+
end
|
48
|
+
def mouse_move_actions(x, y)
|
49
|
+
if @rect.contains?(x, y)
|
50
|
+
@rect.color = @hover_color
|
51
|
+
else
|
52
|
+
@rect.color = @color
|
53
|
+
end
|
54
|
+
end
|
55
|
+
def mouse_down_actions(x, y)
|
56
|
+
if @rect.contains?(x, y)
|
57
|
+
@onclick.call
|
58
|
+
end
|
59
|
+
end
|
60
|
+
def mouse_up_actions; end
|
61
|
+
def update_actions; end
|
62
|
+
end
|
data/lib/RIUI/RIImage.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
class RIImage
|
2
|
+
|
3
|
+
attr_accessor :image, :x, :y, :width, :height
|
4
|
+
|
5
|
+
def initialize(opts={})
|
6
|
+
@path = opts[:image] || "/"
|
7
|
+
@x = opts[:x] || 0
|
8
|
+
@y = opts[:y] || 0
|
9
|
+
@width = opts[:width] || 0
|
10
|
+
@height = opts[:height] || 0
|
11
|
+
@image = Image.new(path: @path, x: @x, y: @y, width: @width, height: @height)
|
12
|
+
end
|
13
|
+
def setSize(opts=[:width, :height])
|
14
|
+
@width = opts[:width]
|
15
|
+
@height = opts[:height]
|
16
|
+
@image.remove
|
17
|
+
@image = Image.new(path: @path, x: @x-@width/2, y: @y-@height/2, width: @width, height: @height)
|
18
|
+
end
|
19
|
+
def width; @width; end
|
20
|
+
def height; @height; end
|
21
|
+
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
require 'ruby2d'
|
2
|
+
class RISlider
|
3
|
+
attr_accessor :length, :x, :y, :square_size, :ticks, :line_color, :square_color, :size, :font, :color, :square, :id, :active, :actions, :onchange
|
4
|
+
|
5
|
+
def initialize(opts = [:length, :x, :y, :square_size, :ticks, :actions]) ### Initialize all variables and start functionality
|
6
|
+
extend Ruby2D::DSL
|
7
|
+
@x = opts[:x] || 0
|
8
|
+
@y = opts[:y] || 0
|
9
|
+
@length = opts[:length] || 100
|
10
|
+
@square_size = opts[:square_size] || 10
|
11
|
+
@ticks = opts[:ticks] || 10
|
12
|
+
@label_font = opts[:label_font] || ''
|
13
|
+
@label_size = opts[:label_size] || 20
|
14
|
+
@label_color = opts[:label_color] || 'black'
|
15
|
+
@line_color = opts[:line_color] || 'black'
|
16
|
+
@square_color = opts[:square_color] || 'red'
|
17
|
+
@actions = opts[:actions]
|
18
|
+
@value = 0
|
19
|
+
@line = Line.new(x1: @x, y1: @y, x2: @x + @length, y2: y, color: @line_color)
|
20
|
+
self.square = Square.new(size: @square_size, x: x - (@square_size/2), y: y - (@square_size/2), color: @square_color)
|
21
|
+
setState(active: false)
|
22
|
+
#@actions.add(self)
|
23
|
+
# start_update
|
24
|
+
end
|
25
|
+
|
26
|
+
def setColors(opts = [:square_color, :line_color]) ### Sets the colors of the line and square
|
27
|
+
@line_color = opts[:line_color]
|
28
|
+
@square_color = opts[:square_color]
|
29
|
+
@line.color = @line_color
|
30
|
+
self.square.color = @square_color
|
31
|
+
puts 'colors set'
|
32
|
+
end
|
33
|
+
|
34
|
+
def setLabel(opts = [:size, :font, :color]) ### Creates a label for the slider
|
35
|
+
@label_size = opts[:size]
|
36
|
+
@label_font = opts[:font]
|
37
|
+
@label_color = opts[:color]
|
38
|
+
@label = Text.new(x: @x + @length + 15, y: @y, color: @label_color, font: @label_font, size: @label_size, text: '0')
|
39
|
+
puts 'label set'
|
40
|
+
end
|
41
|
+
def reset
|
42
|
+
self.square.x = @x - (@square_size/2)
|
43
|
+
@value = 0
|
44
|
+
end
|
45
|
+
def onChange(opts = [:onchange])
|
46
|
+
@onCcange = opts[:onchange]
|
47
|
+
end
|
48
|
+
def value; @value; end ### Returns slider's value
|
49
|
+
def active; @active; end
|
50
|
+
def mouse_down_actions(x, y)
|
51
|
+
if self.square.contains?(x, y)
|
52
|
+
setState(active: true)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
def mouse_up_actions
|
56
|
+
setState(active: false)
|
57
|
+
end
|
58
|
+
def mouse_move_actions(x, y); end
|
59
|
+
def update_actions
|
60
|
+
check
|
61
|
+
update_label
|
62
|
+
changed = check_for_change(@old_value, @value)
|
63
|
+
if changed
|
64
|
+
@onchange.call
|
65
|
+
end
|
66
|
+
end
|
67
|
+
private
|
68
|
+
|
69
|
+
def setState(opts=[:active])
|
70
|
+
self.active = opts[:active]
|
71
|
+
end
|
72
|
+
def actions ### Defines mouse click actions
|
73
|
+
extend Ruby2D::DSL
|
74
|
+
@down_action = on :mouse_down do |e|
|
75
|
+
if self.square.contains?(e.x, e.y)
|
76
|
+
setState(active: true)
|
77
|
+
puts 'mouse down'
|
78
|
+
end
|
79
|
+
end
|
80
|
+
@up_action = on :mouse_up do |e|
|
81
|
+
setState(active: false)
|
82
|
+
puts 'mouse up'
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def check ### Checks and updates the square's position while keeping it in bounds of the line
|
87
|
+
@max = @x + @length
|
88
|
+
@min = @x - self.square.size/2
|
89
|
+
@old_value = @value
|
90
|
+
extend Ruby2D::DSL
|
91
|
+
if self.active
|
92
|
+
puts 'active'
|
93
|
+
mouse_x = get :mouse_x
|
94
|
+
if mouse_x < @max && mouse_x > @min
|
95
|
+
self.square.x = mouse_x
|
96
|
+
puts 'moved square'
|
97
|
+
elsif mouse_x > @max
|
98
|
+
self.square.x = @max
|
99
|
+
elsif mouse_x < @min
|
100
|
+
self.square.x = @min
|
101
|
+
end
|
102
|
+
end
|
103
|
+
@value = ((self.square.x.to_f - @min.to_f) / @length.to_f) * @ticks
|
104
|
+
@value = (@value).ceil - 1
|
105
|
+
if @value < 0; @value = 0; end
|
106
|
+
if @value > @ticks; @value = ticks; end
|
107
|
+
end
|
108
|
+
|
109
|
+
def check_for_change(old_value, new_value)
|
110
|
+
if old_value == new_value
|
111
|
+
false
|
112
|
+
else
|
113
|
+
true
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def update_label ### Updates the slider's label when the value changes
|
118
|
+
@label.text = @value
|
119
|
+
end
|
120
|
+
|
121
|
+
def start_update ### Starts update function to be run every frame
|
122
|
+
extend Ruby2D::DSL
|
123
|
+
update do
|
124
|
+
check
|
125
|
+
update_label
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
data/lib/RIUI/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: RIUI
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- lukecrum20
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-06-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: ruby2d
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.5.1
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.5.1
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- lukecrum20@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".travis.yml"
|
79
|
+
- Gemfile
|
80
|
+
- Gemfile.lock
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- RIUI.gemspec
|
84
|
+
- Rakefile
|
85
|
+
- bin/console
|
86
|
+
- bin/setup
|
87
|
+
- example/SF-Pro-Text-Bold.otf
|
88
|
+
- example/example.rb
|
89
|
+
- example/tree.png
|
90
|
+
- lib/RIUI.rb
|
91
|
+
- lib/RIUI/RIActions.rb
|
92
|
+
- lib/RIUI/RIButton.rb
|
93
|
+
- lib/RIUI/RIImage.rb
|
94
|
+
- lib/RIUI/RISlider.rb
|
95
|
+
- lib/RIUI/version.rb
|
96
|
+
homepage: https://github.com/lukecrum/RIUI
|
97
|
+
licenses:
|
98
|
+
- MIT
|
99
|
+
metadata: {}
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
requirements: []
|
115
|
+
rubyforge_project:
|
116
|
+
rubygems_version: 2.7.5
|
117
|
+
signing_key:
|
118
|
+
specification_version: 4
|
119
|
+
summary: A simple user interface framework for Ruby
|
120
|
+
test_files: []
|