gosu_enhanced 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +21 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +42 -0
- data/LICENSE.txt +22 -0
- data/README.md +49 -0
- data/Rakefile +10 -0
- data/gosu_enhanced.gemspec +31 -0
- data/lib/gosu_enhanced.rb +7 -0
- data/lib/gosu_enhanced/enhanced.rb +40 -0
- data/lib/gosu_enhanced/point.rb +32 -0
- data/lib/gosu_enhanced/size.rb +55 -0
- data/lib/gosu_enhanced/version.rb +3 -0
- data/spec/point_spec.rb +112 -0
- data/spec/size_spec.rb +133 -0
- data/spec/spec_helper.rb +3 -0
- metadata +149 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8c8c0ff47fba5b897c2f6066b9f4306cdae9f42b
|
4
|
+
data.tar.gz: ad4815c8c03d03ab0483b7b77f094e68a7a26eed
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 197ec5637526f565b3594ed2e3653812c753bdcf45336cfecd0e05ed28936fc32ce239541052835934f738f2ecbde49c3fc8d34d9bc806a49942f37bf64976d7
|
7
|
+
data.tar.gz: d50c833a17e528fca792fa1ea0c3a9ac656fa9ec0b274833b7b74a99e0d10953c70196a3893db943dfe5fa42bc647e56b9d8b54522a5235eb0fecdcf106a5d15
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
gosu_enhanced (0.1.0)
|
5
|
+
gosu (~> 0.7)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
coderay (1.1.0)
|
11
|
+
diff-lcs (1.2.5)
|
12
|
+
gosu (0.7.50)
|
13
|
+
method_source (0.8.2)
|
14
|
+
pry (0.9.12.6)
|
15
|
+
coderay (~> 1.0)
|
16
|
+
method_source (~> 0.8)
|
17
|
+
slop (~> 3.4)
|
18
|
+
rake (0.9.2.2)
|
19
|
+
rspec (2.14.1)
|
20
|
+
rspec-core (~> 2.14.0)
|
21
|
+
rspec-expectations (~> 2.14.0)
|
22
|
+
rspec-mocks (~> 2.14.0)
|
23
|
+
rspec-core (2.14.8)
|
24
|
+
rspec-expectations (2.14.5)
|
25
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
26
|
+
rspec-mocks (2.14.6)
|
27
|
+
rspec-nc (0.0.6)
|
28
|
+
rspec (~> 2.9)
|
29
|
+
terminal-notifier (~> 1.4.2)
|
30
|
+
slop (3.5.0)
|
31
|
+
terminal-notifier (1.4.2)
|
32
|
+
|
33
|
+
PLATFORMS
|
34
|
+
ruby
|
35
|
+
|
36
|
+
DEPENDENCIES
|
37
|
+
bundler (~> 1.6)
|
38
|
+
gosu_enhanced!
|
39
|
+
pry (~> 0.9)
|
40
|
+
rake (~> 0.9)
|
41
|
+
rspec (~> 2.0)
|
42
|
+
rspec-nc (~> 0.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Julian Nicholls
|
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,49 @@
|
|
1
|
+
# GosuEnhanced
|
2
|
+
|
3
|
+
Some added classes for using Gosu.
|
4
|
+
|
5
|
+
## Point
|
6
|
+
|
7
|
+
Holds a set of (x, y) co-ordinates. Allows for offsetting and moving by another Point
|
8
|
+
or a pair of co-ordinates.
|
9
|
+
|
10
|
+
## Size
|
11
|
+
|
12
|
+
Holds a (width, height) size. Allows for inflation / deflation with another size or
|
13
|
+
a pair of sizes.
|
14
|
+
|
15
|
+
## Gosu::Window
|
16
|
+
|
17
|
+
Added #draw_rectangle which draws a simple rectangle specified with a Point and Size
|
18
|
+
in one colour.
|
19
|
+
|
20
|
+
## Gosu::Font
|
21
|
+
|
22
|
+
Added #measure and #centred_in which measure a piece of text and centre it in a
|
23
|
+
given Size.
|
24
|
+
|
25
|
+
## Installation
|
26
|
+
|
27
|
+
Add this line to your application's Gemfile:
|
28
|
+
|
29
|
+
gem 'gosu_enhanced'
|
30
|
+
|
31
|
+
And then execute:
|
32
|
+
|
33
|
+
$ bundle
|
34
|
+
|
35
|
+
Or install it yourself as:
|
36
|
+
|
37
|
+
$ gem install gosu_enhanced
|
38
|
+
|
39
|
+
## Usage
|
40
|
+
|
41
|
+
TODO: Write usage instructions here
|
42
|
+
|
43
|
+
## Contributing
|
44
|
+
|
45
|
+
1. Fork it ( https://github.com/[my-github-username]/gosu_enhanced/fork )
|
46
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
47
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
48
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
49
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'rspec/core/rake_task'
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
|
4
|
+
# Default directory for tests is ./spec
|
5
|
+
# Run with rake spec
|
6
|
+
RSpec::Core::RakeTask.new( :spec ) do |task|
|
7
|
+
task.rspec_opts = ['--color', '--format', 'nested']
|
8
|
+
end
|
9
|
+
|
10
|
+
task :default => :spec
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'gosu_enhanced/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "gosu_enhanced"
|
8
|
+
spec.version = GosuEnhanced::VERSION
|
9
|
+
spec.authors = ["Julian Nicholls"]
|
10
|
+
spec.email = ["juliannicholls29@gmail.com"]
|
11
|
+
spec.summary = %q{Enhanced versions of some Gosu classes.}
|
12
|
+
spec.description = %q{Point and Size classes to hold pixel addresses and
|
13
|
+
rectangle sizes respectively. Updated window class to draw rectangle in a single
|
14
|
+
colour more easily. Updated font class to measure text and return co-ordinates
|
15
|
+
to centre a piece of text in a rectangle size.}
|
16
|
+
spec.homepage = ""
|
17
|
+
spec.license = "MIT"
|
18
|
+
|
19
|
+
spec.files = `git ls-files -z`.split("\x0")
|
20
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
21
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_runtime_dependency "gosu", "~> 0.7"
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
27
|
+
spec.add_development_dependency "rake", "~> 0.9"
|
28
|
+
spec.add_development_dependency "rspec", "~> 2.0"
|
29
|
+
spec.add_development_dependency "rspec-nc", "~> 0.0"
|
30
|
+
spec.add_development_dependency "pry", "~> 0.9"
|
31
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Gosu
|
2
|
+
# Add a draw_rectangle() to Window which simplifies drawing a simple rectangle
|
3
|
+
# in one colour
|
4
|
+
class Window
|
5
|
+
def draw_rectangle( point, size, z_index, colour )
|
6
|
+
left, top = point.x, point.y
|
7
|
+
width, height = size.width, size.height
|
8
|
+
|
9
|
+
draw_quad(
|
10
|
+
left, top, colour,
|
11
|
+
left + width, top, colour,
|
12
|
+
left + width, top + height, colour,
|
13
|
+
left, top + height, colour,
|
14
|
+
z_index
|
15
|
+
)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# Add a measure to return both width and height for a text and a way
|
20
|
+
# to centre a text in a rectangle
|
21
|
+
|
22
|
+
class Font
|
23
|
+
include GosuEnhanced
|
24
|
+
|
25
|
+
def measure( text )
|
26
|
+
Size.new( text_width( text, 1 ), height )
|
27
|
+
end
|
28
|
+
|
29
|
+
def centred_in( text, rect )
|
30
|
+
size = measure( text )
|
31
|
+
|
32
|
+
Point.new(
|
33
|
+
(rect.width - size.width) / 2,
|
34
|
+
(rect.height - size.height) / 2
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
alias_method :centered_in, :centred_in
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module GosuEnhanced
|
2
|
+
# Hold a (x, y) pixel position, and allow for offsetting and movement
|
3
|
+
class Point < Struct.new( :x, :y )
|
4
|
+
def offset( by_x, by_y = nil )
|
5
|
+
if by_x.respond_to? :x
|
6
|
+
Point.new( x + by_x.x, y + by_x.y )
|
7
|
+
else
|
8
|
+
Point.new( x + by_x, y + by_y )
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
# Negative co-ordinates are allowed.
|
13
|
+
|
14
|
+
def move_by!( by_x, by_y = nil )
|
15
|
+
if by_x.respond_to? :x
|
16
|
+
self.x += by_x.x
|
17
|
+
self.y += by_x.y
|
18
|
+
else
|
19
|
+
self.x += by_x
|
20
|
+
self.y += by_y
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def move_to!( new_x, new_y = nil )
|
25
|
+
if new_x.respond_to? :x
|
26
|
+
self.x, self.y = new_x.x, new_x.y
|
27
|
+
else
|
28
|
+
self.x, self.y = new_x, new_y
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module GosuEnhanced
|
2
|
+
# Hold a 2-dimensional size and allow for inflation / deflation
|
3
|
+
class Size < Struct.new( :width, :height )
|
4
|
+
# Inflation with a negative value or deflation is not allowed to make a
|
5
|
+
# dimension negative.
|
6
|
+
|
7
|
+
def inflate( by_w, by_h = nil )
|
8
|
+
if by_w.respond_to? :width
|
9
|
+
validate( by_w.width, by_w.height )
|
10
|
+
|
11
|
+
Size.new( width + by_w.width, height + by_w.height )
|
12
|
+
else
|
13
|
+
validate( by_w, by_h )
|
14
|
+
|
15
|
+
Size.new( width + by_w, height + by_h )
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def deflate( by_w, by_h = nil )
|
20
|
+
if by_w.respond_to? :width
|
21
|
+
inflate( -by_w.width, -by_w.height )
|
22
|
+
else
|
23
|
+
inflate( -by_w, -by_h )
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def inflate!( by_w, by_h = nil )
|
28
|
+
if by_w.respond_to? :width
|
29
|
+
validate( by_w.width, by_w.height )
|
30
|
+
|
31
|
+
self.width += by_w.width
|
32
|
+
self.height += by_w.height
|
33
|
+
else
|
34
|
+
validate( by_w, by_h )
|
35
|
+
|
36
|
+
self.width += by_w
|
37
|
+
self.height += by_h
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def deflate!( by_w, by_h = nil )
|
42
|
+
if by_w.respond_to? :width
|
43
|
+
inflate!( -by_w.width, -by_w.height )
|
44
|
+
else
|
45
|
+
inflate!( -by_w, -by_h )
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def validate( by_w, by_h )
|
52
|
+
fail "Cannot make size negative" if width + by_w < 0 || height + by_h < 0
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/spec/point_spec.rb
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe GosuEnhanced::Point do
|
4
|
+
describe '#initialize' do
|
5
|
+
it 'should work with two values' do
|
6
|
+
point = GosuEnhanced::Point.new( 10, 20 )
|
7
|
+
expect( point.x ).to eq 10
|
8
|
+
expect( point.y ).to eq 20
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#offset' do
|
13
|
+
it 'should work with another Point' do
|
14
|
+
point = GosuEnhanced::Point.new( 10, 20 )
|
15
|
+
opoint = point.offset( GosuEnhanced::Point.new( 30, 40 ) )
|
16
|
+
expect( opoint.x ).to eq 40
|
17
|
+
expect( opoint.y ).to eq 60
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should work with two positive values' do
|
21
|
+
point = GosuEnhanced::Point.new( 10, 20 )
|
22
|
+
opoint = point.offset( 40, 50 )
|
23
|
+
expect( opoint.x ).to eq 50
|
24
|
+
expect( opoint.y ).to eq 70
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should work with two negative values' do
|
28
|
+
point = GosuEnhanced::Point.new( 60, 80 )
|
29
|
+
opoint = point.offset( -40, -50 )
|
30
|
+
expect( opoint.x ).to eq 20
|
31
|
+
expect( opoint.y ).to eq 30
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should work with values that result in negative co-ordinates' do
|
35
|
+
point = GosuEnhanced::Point.new( 60, 80 )
|
36
|
+
opoint = point.offset( -80, -150 )
|
37
|
+
expect( opoint.x ).to eq -20
|
38
|
+
expect( opoint.y ).to eq -70
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '#move_by!' do
|
43
|
+
it 'should work with another Point' do
|
44
|
+
point = GosuEnhanced::Point.new( 10, 20 )
|
45
|
+
point.move_by!( GosuEnhanced::Point.new( 30, 40 ) )
|
46
|
+
expect( point.x ).to eq 40
|
47
|
+
expect( point.y ).to eq 60
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should work with two positive values' do
|
51
|
+
point = GosuEnhanced::Point.new( 10, 20 )
|
52
|
+
point.move_by!( 40, 50 )
|
53
|
+
expect( point.x ).to eq 50
|
54
|
+
expect( point.y ).to eq 70
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should work with two negative values' do
|
58
|
+
point = GosuEnhanced::Point.new( 60, 80 )
|
59
|
+
point.move_by!( -40, -50 )
|
60
|
+
expect( point.x ).to eq 20
|
61
|
+
expect( point.y ).to eq 30
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should work with values that result in negative co-ordinates' do
|
65
|
+
point = GosuEnhanced::Point.new( 60, 80 )
|
66
|
+
point.move_by!( -80, -150 )
|
67
|
+
expect( point.x ).to eq -20
|
68
|
+
expect( point.y ).to eq -70
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe '#move_to!' do
|
73
|
+
it 'should work with another Point' do
|
74
|
+
point = GosuEnhanced::Point.new( 10, 20 )
|
75
|
+
point.move_to!( GosuEnhanced::Point.new( 30, 40 ) )
|
76
|
+
expect( point.x ).to eq 30
|
77
|
+
expect( point.y ).to eq 40
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'should work with two positive values' do
|
81
|
+
point = GosuEnhanced::Point.new( 10, 20 )
|
82
|
+
point.move_to!( 40, 50 )
|
83
|
+
expect( point.x ).to eq 40
|
84
|
+
expect( point.y ).to eq 50
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'should work with two negative values' do
|
88
|
+
point = GosuEnhanced::Point.new( 60, 80 )
|
89
|
+
point.move_to!( -40, -50 )
|
90
|
+
expect( point.x ).to eq -40
|
91
|
+
expect( point.y ).to eq -50
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
# This might seem laboured, but I have run foul of dup before
|
96
|
+
|
97
|
+
describe '#dup' do
|
98
|
+
it 'should make a copy of the Point' do
|
99
|
+
point = GosuEnhanced::Point.new( 10, 20 )
|
100
|
+
npoint = point.dup
|
101
|
+
expect( point.x ).to eq 10
|
102
|
+
expect( point.y ).to eq 20
|
103
|
+
expect( npoint.x ).to eq 10
|
104
|
+
expect( npoint.y ).to eq 20
|
105
|
+
point.move_to!( 40, 50 )
|
106
|
+
expect( point.x ).to eq 40
|
107
|
+
expect( point.y ).to eq 50
|
108
|
+
expect( npoint.x ).to eq 10
|
109
|
+
expect( npoint.y ).to eq 20
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
data/spec/size_spec.rb
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe GosuEnhanced::Size do
|
4
|
+
describe '#initialize' do
|
5
|
+
it 'should work with two values' do
|
6
|
+
size = GosuEnhanced::Size.new( 10, 20 )
|
7
|
+
expect( size.width ).to eq 10
|
8
|
+
expect( size.height ).to eq 20
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#inflate' do
|
13
|
+
it 'should work with another Size' do
|
14
|
+
size = GosuEnhanced::Size.new( 10, 20 )
|
15
|
+
esize = size.inflate( GosuEnhanced::Size.new( 30, 40 ) )
|
16
|
+
expect( esize.width ).to eq 40
|
17
|
+
expect( esize.height ).to eq 60
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should work with two values' do
|
21
|
+
size = GosuEnhanced::Size.new( 10, 20 )
|
22
|
+
esize = size.inflate( 40, 50 )
|
23
|
+
expect( esize.width ).to eq 50
|
24
|
+
expect( esize.height ).to eq 70
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should work with two explicitly negative values' do
|
28
|
+
size = GosuEnhanced::Size.new( 40, 50 )
|
29
|
+
esize = size.inflate( -30, -20 )
|
30
|
+
expect( esize.width ).to eq 10
|
31
|
+
expect( esize.height ).to eq 30
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should raise an error with out-of-range values' do
|
35
|
+
size = GosuEnhanced::Size.new( 40, 50 )
|
36
|
+
expect { esize = size.inflate( -50, -20 ) }.to raise_error Exception
|
37
|
+
expect { esize = size.inflate( -30, -60 ) }.to raise_error Exception
|
38
|
+
expect { esize = size.inflate( -50, -70 ) }.to raise_error Exception
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '#deflate' do
|
43
|
+
it 'should work with another Size' do
|
44
|
+
size = GosuEnhanced::Size.new( 60, 80 )
|
45
|
+
esize = size.deflate( GosuEnhanced::Size.new( 30, 40 ) )
|
46
|
+
expect( esize.width ).to eq 30
|
47
|
+
expect( esize.height ).to eq 40
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should work with two values' do
|
51
|
+
size = GosuEnhanced::Size.new( 70, 60 )
|
52
|
+
esize = size.deflate( 40, 50 )
|
53
|
+
expect( esize.width ).to eq 30
|
54
|
+
expect( esize.height ).to eq 10
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should raise an error for out-of-range values' do
|
58
|
+
size = GosuEnhanced::Size.new( 70, 60 )
|
59
|
+
expect { esize = size.deflate( 80, 50 ) }.to raise_error Exception
|
60
|
+
expect { esize = size.deflate( 60, 70 ) }.to raise_error Exception
|
61
|
+
expect { esize = size.deflate( 80, 70 ) }.to raise_error Exception
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe '#inflate!' do
|
66
|
+
it 'should work with another Size' do
|
67
|
+
size = GosuEnhanced::Size.new( 10, 20 )
|
68
|
+
size.inflate!( GosuEnhanced::Size.new( 30, 40 ) )
|
69
|
+
expect( size.width ).to eq 40
|
70
|
+
expect( size.height ).to eq 60
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'should work with two values' do
|
74
|
+
size = GosuEnhanced::Size.new( 10, 20 )
|
75
|
+
size.inflate!( 40, 50 )
|
76
|
+
expect( size.width ).to eq 50
|
77
|
+
expect( size.height ).to eq 70
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'should work with two explicitly negative values' do
|
81
|
+
size = GosuEnhanced::Size.new( 40, 50 )
|
82
|
+
size.inflate!( -30, -20 )
|
83
|
+
expect( size.width ).to eq 10
|
84
|
+
expect( size.height ).to eq 30
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'should raise an error with out-of-range values' do
|
88
|
+
size = GosuEnhanced::Size.new( 40, 50 )
|
89
|
+
expect { size.inflate!( -50, -20 ) }.to raise_error Exception
|
90
|
+
expect { size.inflate!( -30, -60 ) }.to raise_error Exception
|
91
|
+
expect { size.inflate!( -50, -70 ) }.to raise_error Exception
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe '#deflate!' do
|
96
|
+
it 'should work with another Size' do
|
97
|
+
size = GosuEnhanced::Size.new( 60, 80 )
|
98
|
+
size.deflate!( GosuEnhanced::Size.new( 30, 40 ) )
|
99
|
+
expect( size.width ).to eq 30
|
100
|
+
expect( size.height ).to eq 40
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'should work with two values' do
|
104
|
+
size = GosuEnhanced::Size.new( 70, 60 )
|
105
|
+
size.deflate!( 40, 50 )
|
106
|
+
expect( size.width ).to eq 30
|
107
|
+
expect( size.height ).to eq 10
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'should raise an error for out-of-range values' do
|
111
|
+
size = GosuEnhanced::Size.new( 70, 60 )
|
112
|
+
expect { size.deflate!( 80, 50 ) }.to raise_error Exception
|
113
|
+
expect { size.deflate!( 60, 70 ) }.to raise_error Exception
|
114
|
+
expect { size.deflate!( 80, 70 ) }.to raise_error Exception
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe '#dup' do
|
119
|
+
it 'should make a copy of the Size' do
|
120
|
+
size = GosuEnhanced::Size.new( 10, 20 )
|
121
|
+
nsize = size.dup
|
122
|
+
expect( size.width ).to eq 10
|
123
|
+
expect( size.height ).to eq 20
|
124
|
+
expect( nsize.width ).to eq 10
|
125
|
+
expect( nsize.height ).to eq 20
|
126
|
+
size.inflate!( 40, 50 )
|
127
|
+
expect( size.width ).to eq 50
|
128
|
+
expect( size.height ).to eq 70
|
129
|
+
expect( nsize.width ).to eq 10
|
130
|
+
expect( nsize.height ).to eq 20
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gosu_enhanced
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Julian Nicholls
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-12 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.7'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.6'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.9'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.9'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec-nc
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.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.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.9'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.9'
|
97
|
+
description: "Point and Size classes to hold pixel addresses and \nrectangle sizes
|
98
|
+
respectively. Updated window class to draw rectangle in a single \ncolour more easily.
|
99
|
+
Updated font class to measure text and return co-ordinates \nto centre a piece of
|
100
|
+
text in a rectangle size."
|
101
|
+
email:
|
102
|
+
- juliannicholls29@gmail.com
|
103
|
+
executables: []
|
104
|
+
extensions: []
|
105
|
+
extra_rdoc_files: []
|
106
|
+
files:
|
107
|
+
- ".gitignore"
|
108
|
+
- Gemfile
|
109
|
+
- Gemfile.lock
|
110
|
+
- LICENSE.txt
|
111
|
+
- README.md
|
112
|
+
- Rakefile
|
113
|
+
- gosu_enhanced.gemspec
|
114
|
+
- lib/gosu_enhanced.rb
|
115
|
+
- lib/gosu_enhanced/enhanced.rb
|
116
|
+
- lib/gosu_enhanced/point.rb
|
117
|
+
- lib/gosu_enhanced/size.rb
|
118
|
+
- lib/gosu_enhanced/version.rb
|
119
|
+
- spec/point_spec.rb
|
120
|
+
- spec/size_spec.rb
|
121
|
+
- spec/spec_helper.rb
|
122
|
+
homepage: ''
|
123
|
+
licenses:
|
124
|
+
- MIT
|
125
|
+
metadata: {}
|
126
|
+
post_install_message:
|
127
|
+
rdoc_options: []
|
128
|
+
require_paths:
|
129
|
+
- lib
|
130
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
requirements: []
|
141
|
+
rubyforge_project:
|
142
|
+
rubygems_version: 2.2.2
|
143
|
+
signing_key:
|
144
|
+
specification_version: 4
|
145
|
+
summary: Enhanced versions of some Gosu classes.
|
146
|
+
test_files:
|
147
|
+
- spec/point_spec.rb
|
148
|
+
- spec/size_spec.rb
|
149
|
+
- spec/spec_helper.rb
|