rcade_menu 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.ruby-version +1 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/examples/welcome_menu.rb +33 -0
- data/lib/rcade/menu/menu.rb +104 -0
- data/lib/rcade/menu/option.rb +33 -0
- data/lib/rcade/menu/option_styles.rb +59 -0
- data/lib/rcade/menu/screen.rb +54 -0
- data/lib/rcade_menu.rb +8 -0
- data/rcade_menu.gemspec +24 -0
- metadata +127 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8dbd805dd4b5a8be18296e63c0c94d1944f98cee
|
4
|
+
data.tar.gz: 25b5f1cc42b38ec0b3e97c9d84fbc80ad13fd39e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c697439cc8fd5267e26c21377d8e8f2924f11553a25325d15e4ceb67dcf934444ff981876ee09bea4887944ff29414b2b602fad1b6a106fc9d79f2d2f4b334cf
|
7
|
+
data.tar.gz: 881638543b4e5125f9784b73e101f4fab0b7a641b29952b3b005c77264621206e36f3b9e803b6a651f4ee1709fe2186931e0c0fcad757776a57abd39f59fa603
|
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.0.0-p247
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Andrew Havens
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Rcade::Menu
|
2
|
+
|
3
|
+
A set of components for building Gosu menu screens.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'rcade_menu'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install rcade_menu
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
See [examples directory](https://github.com/ruby-rcade/rcade_menu/tree/master/examples) for usage.
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require_relative '../lib/rcade_menu'
|
4
|
+
|
5
|
+
class WelcomeMenu < Rcade::Menu::Screen
|
6
|
+
|
7
|
+
menu_position bottom: 50, x: :center # 50px from the bottom, centered on x axis
|
8
|
+
|
9
|
+
menu_alignment :vertical # stack options vertically, or use :horizontal
|
10
|
+
|
11
|
+
option_styles do
|
12
|
+
font_family 'Helvetica'
|
13
|
+
font_size 40
|
14
|
+
color '#fff' # or :white
|
15
|
+
opacity 0.5
|
16
|
+
border_width 1
|
17
|
+
border_color :white
|
18
|
+
selected do # override defaults
|
19
|
+
opacity 1.0
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
option 'Start' do
|
24
|
+
puts 'Start was selected'
|
25
|
+
end
|
26
|
+
|
27
|
+
option 'Options' do
|
28
|
+
puts 'Options was selected'
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
WelcomeMenu.new(800, 600, false).show
|
@@ -0,0 +1,104 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Rcade
|
4
|
+
module Menu
|
5
|
+
class Menu
|
6
|
+
|
7
|
+
attr_accessor :options, :option_styles
|
8
|
+
attr_accessor :width, :height
|
9
|
+
attr_accessor :alignment
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@options = []
|
13
|
+
@option_styles = OptionStyles.new
|
14
|
+
@selected_option = 0
|
15
|
+
end
|
16
|
+
|
17
|
+
def add_option(label_text, &callback)
|
18
|
+
@options << Option.new(label_text, &callback)
|
19
|
+
end
|
20
|
+
|
21
|
+
def decrement_selection
|
22
|
+
@selected_option -= 1 unless @selected_option == 0
|
23
|
+
end
|
24
|
+
|
25
|
+
def increment_selection
|
26
|
+
@selected_option += 1 unless @selected_option == @options.count - 1
|
27
|
+
end
|
28
|
+
|
29
|
+
def select_current_option
|
30
|
+
@options[@selected_option].callback.call
|
31
|
+
end
|
32
|
+
|
33
|
+
def position(x: nil, y: nil, top: nil, right: nil, bottom: nil, left: nil)
|
34
|
+
if x.nil?
|
35
|
+
x = left if left
|
36
|
+
x = -(right) if right
|
37
|
+
x = 0 unless x
|
38
|
+
end
|
39
|
+
@x = x
|
40
|
+
|
41
|
+
if y.nil?
|
42
|
+
y = top if top
|
43
|
+
y = -(bottom) if bottom
|
44
|
+
y = 0 unless y
|
45
|
+
end
|
46
|
+
@y = y
|
47
|
+
end
|
48
|
+
|
49
|
+
# assumes all options are the same width
|
50
|
+
def width
|
51
|
+
if alignment == :vertical
|
52
|
+
@width ||= @options.first.width
|
53
|
+
else
|
54
|
+
@width ||= @options.count * @options.first.width
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# assumes all options are the same height
|
59
|
+
def height
|
60
|
+
if alignment == :vertical
|
61
|
+
@height ||= @options.count * @options.first.height
|
62
|
+
else
|
63
|
+
@height ||= @options.first.height
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def offset_left(window)
|
68
|
+
@offset_left ||= case @x
|
69
|
+
when :left then 0
|
70
|
+
when :center then window.width / 2 - width
|
71
|
+
when :right then window.width - width
|
72
|
+
else @x < 0 ? @x + window.width - width : @x
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def offset_top(window)
|
77
|
+
@offset_top ||= case @y
|
78
|
+
when :top then 0
|
79
|
+
when :center then window.height / 2 - height
|
80
|
+
when :bottom then window.height - height
|
81
|
+
else @y < 0 ? @y + window.height - height : @y
|
82
|
+
end
|
83
|
+
@offset_top
|
84
|
+
end
|
85
|
+
|
86
|
+
def render(window)
|
87
|
+
options.each_with_index do |option, i|
|
88
|
+
option.window = window
|
89
|
+
option.styles = @option_styles
|
90
|
+
x = offset_left(window)
|
91
|
+
y = offset_top(window)
|
92
|
+
|
93
|
+
x += i * option.width if alignment == :horizontal
|
94
|
+
y += i * option.height if alignment == :vertical
|
95
|
+
z = 0 # TODO
|
96
|
+
selected = @selected_option == i
|
97
|
+
|
98
|
+
option.render(x, y, z, selected)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Rcade
|
4
|
+
module Menu
|
5
|
+
class Option
|
6
|
+
|
7
|
+
attr_accessor :text, :callback
|
8
|
+
attr_accessor :window, :styles
|
9
|
+
|
10
|
+
def initialize(text, &callback)
|
11
|
+
@text = text
|
12
|
+
@callback = callback
|
13
|
+
end
|
14
|
+
|
15
|
+
def width
|
16
|
+
styles.label(window).text_width(@text)
|
17
|
+
end
|
18
|
+
|
19
|
+
def height
|
20
|
+
styles.label(window).height
|
21
|
+
end
|
22
|
+
|
23
|
+
def render(x, y, z, selected)
|
24
|
+
if selected
|
25
|
+
styles.selected.label(window).draw(@text, x, y, z, 1.0, 1.0, styles.selected.color)
|
26
|
+
else
|
27
|
+
styles.label(window).draw(@text, x, y, z, 1.0, 1.0, styles.color)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Rcade
|
4
|
+
module Menu
|
5
|
+
class OptionStyles
|
6
|
+
|
7
|
+
def initialize(parent = nil)
|
8
|
+
@parent = parent
|
9
|
+
end
|
10
|
+
|
11
|
+
%w(font_family font_size border_width border_color).each do |name|
|
12
|
+
define_method name do |value = nil|
|
13
|
+
instance_variable_set "@#{name}", value if value
|
14
|
+
set_value = instance_variable_get "@#{name}"
|
15
|
+
return @parent.send(name) if set_value.nil? and @parent
|
16
|
+
set_value
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def opacity(value = nil)
|
21
|
+
@opacity = value unless value.nil?
|
22
|
+
return @parent.opacity if @opacity.nil? and @parent
|
23
|
+
@opacity ||= 1.0
|
24
|
+
end
|
25
|
+
|
26
|
+
def color(value = nil)
|
27
|
+
if value
|
28
|
+
if value.is_a? Symbol
|
29
|
+
@color = Color.named(value)
|
30
|
+
else
|
31
|
+
@color = Color.from_hex(value)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
@color = @parent.color if @color.nil? and @parent
|
35
|
+
@color.opacity(opacity)
|
36
|
+
end
|
37
|
+
|
38
|
+
def border?
|
39
|
+
border_width && border_color
|
40
|
+
end
|
41
|
+
|
42
|
+
def height(value)
|
43
|
+
@height = value if value
|
44
|
+
@height.nil? ? @font_size : @height
|
45
|
+
end
|
46
|
+
|
47
|
+
def label(window)
|
48
|
+
@label ||= Gosu::Font.new(window, font_family, font_size)
|
49
|
+
end
|
50
|
+
|
51
|
+
def selected(&block)
|
52
|
+
@selected_styles ||= self.class.new(self)
|
53
|
+
@selected_styles.instance_eval(&block) if block_given?
|
54
|
+
@selected_styles
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Rcade
|
4
|
+
module Menu
|
5
|
+
class Screen < Gosu::Window
|
6
|
+
|
7
|
+
def self.inherited(subclass)
|
8
|
+
subclass.extend DSL
|
9
|
+
end
|
10
|
+
|
11
|
+
module DSL
|
12
|
+
def menu
|
13
|
+
@menu ||= Menu.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def option_styles(&block)
|
17
|
+
menu.option_styles.instance_eval(&block) if block_given?
|
18
|
+
end
|
19
|
+
|
20
|
+
def menu_position(args)
|
21
|
+
menu.position(args)
|
22
|
+
end
|
23
|
+
|
24
|
+
def menu_alignment(alignment)
|
25
|
+
menu.alignment = alignment
|
26
|
+
end
|
27
|
+
|
28
|
+
def option(label_text, &callback)
|
29
|
+
menu.add_option(label_text, &callback)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def menu
|
34
|
+
self.class.menu
|
35
|
+
end
|
36
|
+
|
37
|
+
def button_down(button)
|
38
|
+
case button
|
39
|
+
when Quit then close
|
40
|
+
when Enter then menu.select_current_option
|
41
|
+
when P1Up then menu.decrement_selection if menu.alignment == :vertical
|
42
|
+
when P1Down then menu.increment_selection if menu.alignment == :vertical
|
43
|
+
when P1Left then menu.decrement_selection if menu.alignment == :horizontal
|
44
|
+
when P1Right then menu.increment_selection if menu.alignment == :horizontal
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def draw
|
49
|
+
menu.render(self)
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/lib/rcade_menu.rb
ADDED
data/rcade_menu.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "rcade_menu"
|
5
|
+
spec.version = "0.0.1"
|
6
|
+
spec.authors = ["Andrew Havens"]
|
7
|
+
spec.email = ["email@andrewhavens.com"]
|
8
|
+
spec.description = %q{A set of components for building Gosu menu screens.}
|
9
|
+
spec.summary = %q{A set of components for building Gosu menu screens.}
|
10
|
+
spec.homepage = "https://github.com/ruby-rcade/rcade_menu"
|
11
|
+
spec.license = "MIT"
|
12
|
+
|
13
|
+
spec.files = `git ls-files`.split($/)
|
14
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
15
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
16
|
+
spec.require_paths = ["lib"]
|
17
|
+
|
18
|
+
spec.add_dependency 'gosu'
|
19
|
+
spec.add_dependency 'rcade_controls'
|
20
|
+
spec.add_dependency 'rcade_colors'
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rcade_menu
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrew Havens
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-08-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: gosu
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rcade_controls
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rcade_colors
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.3'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.3'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: A set of components for building Gosu menu screens.
|
84
|
+
email:
|
85
|
+
- email@andrewhavens.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- .gitignore
|
91
|
+
- .ruby-version
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- examples/welcome_menu.rb
|
97
|
+
- lib/rcade/menu/menu.rb
|
98
|
+
- lib/rcade/menu/option.rb
|
99
|
+
- lib/rcade/menu/option_styles.rb
|
100
|
+
- lib/rcade/menu/screen.rb
|
101
|
+
- lib/rcade_menu.rb
|
102
|
+
- rcade_menu.gemspec
|
103
|
+
homepage: https://github.com/ruby-rcade/rcade_menu
|
104
|
+
licenses:
|
105
|
+
- MIT
|
106
|
+
metadata: {}
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options: []
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - '>='
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - '>='
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
requirements: []
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 2.0.3
|
124
|
+
signing_key:
|
125
|
+
specification_version: 4
|
126
|
+
summary: A set of components for building Gosu menu screens.
|
127
|
+
test_files: []
|