gosu_enhanced 0.3.4 → 0.3.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 +4 -4
- data/Gemfile.lock +11 -8
- data/README.md +4 -4
- data/Rakefile +3 -3
- data/gosu_enhanced.gemspec +15 -15
- data/lib/gosu_enhanced/enhanced.rb +21 -19
- data/lib/gosu_enhanced/point.rb +38 -20
- data/lib/gosu_enhanced/region.rb +31 -14
- data/lib/gosu_enhanced/size.rb +66 -23
- data/lib/gosu_enhanced/version.rb +3 -2
- data/spec/point_spec.rb +77 -77
- data/spec/region_delegation_spec.rb +78 -78
- data/spec/region_spec.rb +40 -38
- data/spec/size_spec.rb +75 -75
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a951985d3479c4c6c784582a6c62d89033d20a0
|
4
|
+
data.tar.gz: 6abef53400b8d8994e1e43ff69af8e1ceaf0fb6c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef111cb6f34b22de480995f567721e1ca7468d7daab013947376f6aff09e6722c3e4c4ae250e601991751a9fef17474151d06897e2621653539e94a6e5722891
|
7
|
+
data.tar.gz: 30aeb5557b13a7321fcd87f39b7ab06555103fe372f8cd5b9415a233ff676070f76758d6c3dfaeb92ae47ad0130a3a38e6641a173a2a1167bd14eef077129ff2
|
data/Gemfile.lock
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
gosu_enhanced (0.3.
|
5
|
-
gosu (~> 0.
|
4
|
+
gosu_enhanced (0.3.4)
|
5
|
+
gosu (~> 0.10)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
10
|
coderay (1.1.0)
|
11
11
|
diff-lcs (1.2.5)
|
12
|
-
gosu (0.
|
12
|
+
gosu (0.10.0)
|
13
13
|
method_source (0.8.2)
|
14
14
|
pry (0.10.0)
|
15
15
|
coderay (~> 1.1.0)
|
@@ -38,9 +38,12 @@ PLATFORMS
|
|
38
38
|
ruby
|
39
39
|
|
40
40
|
DEPENDENCIES
|
41
|
-
bundler
|
41
|
+
bundler
|
42
42
|
gosu_enhanced!
|
43
|
-
pry
|
44
|
-
rake
|
45
|
-
rspec
|
46
|
-
rspec-nc
|
43
|
+
pry
|
44
|
+
rake
|
45
|
+
rspec
|
46
|
+
rspec-nc
|
47
|
+
|
48
|
+
BUNDLED WITH
|
49
|
+
1.10.6
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
# gosu_enhanced V0.3.
|
1
|
+
# gosu_enhanced V0.3.4
|
2
2
|
|
3
|
-
Some added classes for using Gosu.
|
3
|
+
Some added classes for using Gosu. Updated to use Gosu 0.9.x.
|
4
4
|
|
5
5
|
## Point
|
6
6
|
|
@@ -35,7 +35,7 @@ Add this line to your application's Gemfile:
|
|
35
35
|
|
36
36
|
And then execute:
|
37
37
|
|
38
|
-
$ bundle
|
38
|
+
$ bundle install
|
39
39
|
|
40
40
|
Or install it yourself as:
|
41
41
|
|
@@ -58,5 +58,5 @@ Or install it yourself as:
|
|
58
58
|
I am not affiliated in any way to the authors of the Gosu Gem or
|
59
59
|
[libgosu](libgosu.org).
|
60
60
|
|
61
|
-
Gosu and all documentation © 2001-
|
61
|
+
Gosu and all documentation © 2001-2015 Julian Raschke, Jan Lücker, and
|
62
62
|
other contributors. Gosu is released under the MIT license.
|
data/Rakefile
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'rspec/core/rake_task'
|
2
|
-
require
|
2
|
+
require 'bundler/gem_tasks'
|
3
3
|
|
4
4
|
# Default directory for tests is ./spec
|
5
5
|
# Run with rake spec
|
6
|
-
RSpec::Core::RakeTask.new(
|
6
|
+
RSpec::Core::RakeTask.new(:spec) do |task|
|
7
7
|
task.rspec_opts = ['--color']
|
8
8
|
end
|
9
9
|
|
10
|
-
task :
|
10
|
+
task default: :spec
|
data/gosu_enhanced.gemspec
CHANGED
@@ -4,29 +4,29 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'gosu_enhanced/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'gosu_enhanced'
|
8
8
|
spec.version = GosuEnhanced::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
11
|
-
spec.summary =
|
12
|
-
spec.description = %
|
9
|
+
spec.authors = ['Julian Nicholls']
|
10
|
+
spec.email = ['juliannicholls29@gmail.com']
|
11
|
+
spec.summary = 'Enhanced versions of some Gosu classes.'
|
12
|
+
spec.description = %(Point, Size, and Region classes to hold pixel addresses
|
13
13
|
and rectangle sizes respectively.
|
14
14
|
Updated window class to draw rectangle in a single colour more easily.
|
15
15
|
Updated font class to measure text and return co-ordinates to centre a piece
|
16
|
-
of text in a rectangle size.
|
17
|
-
spec.homepage =
|
18
|
-
spec.license =
|
16
|
+
of text in a rectangle size.)
|
17
|
+
spec.homepage = 'https://github.com/JulianNicholls/gosu_enhanced-gem'
|
18
|
+
spec.license = 'MIT'
|
19
19
|
|
20
20
|
spec.files = `git ls-files -z`.split("\x0")
|
21
21
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
22
22
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
23
|
-
spec.require_paths = [
|
23
|
+
spec.require_paths = ['lib']
|
24
24
|
|
25
|
-
spec.add_runtime_dependency
|
25
|
+
spec.add_runtime_dependency 'gosu', '~> 0.10'
|
26
26
|
|
27
|
-
spec.add_development_dependency
|
28
|
-
spec.add_development_dependency
|
29
|
-
spec.add_development_dependency
|
30
|
-
spec.add_development_dependency
|
31
|
-
spec.add_development_dependency
|
27
|
+
spec.add_development_dependency 'bundler', '~> 1.10'
|
28
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
29
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
30
|
+
spec.add_development_dependency 'rspec-nc', '~> 0.2'
|
31
|
+
spec.add_development_dependency 'pry', '~> 0.10'
|
32
32
|
end
|
@@ -6,22 +6,23 @@ module Gosu
|
|
6
6
|
class Window
|
7
7
|
# Simplify drawing a rectangle in a single colour.
|
8
8
|
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
9
|
+
# +point+ [Point] Top left corner
|
10
|
+
# +size+ [Size] Width and Height
|
11
|
+
# +z_index+ [Fixnum] Z-order
|
12
|
+
# +colour+ [Gosu::Color] Colour of rectangle
|
13
13
|
|
14
|
-
def draw_rectangle(
|
15
|
-
left
|
16
|
-
|
14
|
+
def draw_rectangle(point, size, z_index, colour)
|
15
|
+
left = point.x
|
16
|
+
top = point.y
|
17
|
+
width = size.width
|
18
|
+
height = size.height
|
17
19
|
|
18
20
|
draw_quad(
|
19
21
|
left, top, colour,
|
20
22
|
left + width, top, colour,
|
21
23
|
left + width, top + height, colour,
|
22
24
|
left, top + height, colour,
|
23
|
-
z_index
|
24
|
-
)
|
25
|
+
z_index)
|
25
26
|
end
|
26
27
|
end
|
27
28
|
|
@@ -32,24 +33,25 @@ module Gosu
|
|
32
33
|
|
33
34
|
# Return the width and height of a given string
|
34
35
|
#
|
35
|
-
#
|
36
|
+
# +text+ String to measure
|
36
37
|
#
|
37
|
-
#
|
38
|
+
# return [Size] The height and width of the string.
|
38
39
|
|
39
|
-
def measure(
|
40
|
-
Size.new(
|
40
|
+
def measure(text)
|
41
|
+
Size.new(text_width(text, 1), height)
|
41
42
|
end
|
42
43
|
|
43
44
|
# Return the co-ordnates needed to place a given string in the centre of an
|
44
|
-
# area, both vertically and horizontally
|
45
|
+
# area, both vertically and horizontally.
|
45
46
|
#
|
46
|
-
#
|
47
|
-
#
|
47
|
+
# return [Point] The point to write the string, expressed as an offset
|
48
|
+
# from the top-left corner of the rectangle.
|
48
49
|
#
|
49
|
-
#
|
50
|
+
# +text+ [String] String to centre
|
51
|
+
# +rect+ [Size] Rectangular area size
|
50
52
|
|
51
|
-
def centred_in(
|
52
|
-
size = measure(
|
53
|
+
def centred_in(text, rect)
|
54
|
+
size = measure(text)
|
53
55
|
|
54
56
|
Point.new(
|
55
57
|
(rect.width - size.width) / 2,
|
data/lib/gosu_enhanced/point.rb
CHANGED
@@ -1,33 +1,51 @@
|
|
1
|
+
# Module for gosu_enhanced gem.
|
1
2
|
module GosuEnhanced
|
2
3
|
# Hold a (x, y) pixel position, and allow for offsetting and movement
|
3
|
-
Point = Struct.new(
|
4
|
-
def offset(
|
5
|
-
|
4
|
+
Point = Struct.new(:x, :y) do
|
5
|
+
def offset(by_x, by_y = nil)
|
6
|
+
dup.move_by!(by_x, by_y)
|
6
7
|
end
|
7
8
|
|
8
9
|
# Negative co-ordinates are allowed.
|
9
10
|
|
10
|
-
def move_by!(
|
11
|
-
if by_x.respond_to? :x
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
11
|
+
def move_by!(by_x, by_y = nil)
|
12
|
+
return move_by_point(by_x) if by_x.respond_to? :x
|
13
|
+
return move_by_size(by_x) if by_x.respond_to? :width
|
14
|
+
|
15
|
+
self.x += by_x
|
16
|
+
self.y += by_y
|
17
|
+
|
18
|
+
self
|
19
|
+
end
|
20
|
+
|
21
|
+
def move_to!(new_x, new_y = nil)
|
22
|
+
return move_to_point(new_x) if new_x.respond_to? :x
|
23
|
+
|
24
|
+
self.x = new_x
|
25
|
+
self.y = new_y
|
26
|
+
|
27
|
+
self
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def move_by_point(pt)
|
33
|
+
self.x += pt.x
|
34
|
+
self.y += pt.y
|
35
|
+
|
36
|
+
self
|
37
|
+
end
|
38
|
+
|
39
|
+
def move_by_size(sz)
|
40
|
+
self.x += sz.width
|
41
|
+
self.y += sz.height
|
21
42
|
|
22
43
|
self
|
23
44
|
end
|
24
45
|
|
25
|
-
def
|
26
|
-
|
27
|
-
|
28
|
-
else
|
29
|
-
self.x, self.y = new_x, new_y
|
30
|
-
end
|
46
|
+
def move_to_point(pt)
|
47
|
+
self.x = pt.x
|
48
|
+
self.y = pt.y
|
31
49
|
|
32
50
|
self
|
33
51
|
end
|
data/lib/gosu_enhanced/region.rb
CHANGED
@@ -9,41 +9,58 @@ module GosuEnhanced
|
|
9
9
|
def_delegators :@position, :move_by!, :move_to!, :x, :y
|
10
10
|
def_delegators :@size, :inflate!, :deflate!, :width, :height
|
11
11
|
|
12
|
-
|
12
|
+
# Top left corner
|
13
|
+
attr_reader :position
|
14
|
+
# Overall Width and Height
|
15
|
+
attr_reader :size
|
13
16
|
|
14
|
-
|
15
|
-
|
17
|
+
# Create a new region with specified +pos+ as top left corner and +size+
|
18
|
+
# as width and height
|
19
|
+
def initialize(pos, size)
|
20
|
+
@position = pos.dup
|
21
|
+
@size = size.dup
|
16
22
|
end
|
17
23
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
row.between?( top, top + height - 1 )
|
25
|
-
end
|
24
|
+
# Return whether the region contains the specified +row+ and +col+
|
25
|
+
def contains?(col, row = nil)
|
26
|
+
return contains_point?(col) if col.respond_to? :x
|
27
|
+
|
28
|
+
col.between?(left, left + width - 1) &&
|
29
|
+
row.between?(top, top + height - 1)
|
26
30
|
end
|
27
31
|
|
32
|
+
# Return the topmost co-ordinate
|
28
33
|
def top
|
29
34
|
position.y
|
30
35
|
end
|
31
36
|
|
37
|
+
# Return the leftmost co-oridinate
|
32
38
|
def left
|
33
39
|
position.x
|
34
40
|
end
|
35
41
|
|
36
42
|
# It is necessary to override dup to produce an actual duplicate.
|
37
43
|
def dup
|
38
|
-
Region.new(
|
44
|
+
Region.new(position, size)
|
39
45
|
end
|
40
46
|
|
41
|
-
|
42
|
-
|
47
|
+
# Draw a rectangle on the specified +surface+ at the specified +z_order+
|
48
|
+
# and with the specified +colour+
|
49
|
+
def draw(surface, z_order, colour)
|
50
|
+
surface.draw_rectangle(position, size, z_order, colour)
|
43
51
|
end
|
44
52
|
|
53
|
+
# Return a string representation of the region's position and size
|
45
54
|
def to_s
|
46
55
|
"<GosuEnhanced::Region: #{position}, #{size}>"
|
47
56
|
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
# NODOC
|
61
|
+
def contains_point?(pt)
|
62
|
+
pt.x.between?(left, left + width - 1) &&
|
63
|
+
pt.y.between?(top, top + height - 1)
|
64
|
+
end
|
48
65
|
end
|
49
66
|
end
|
data/lib/gosu_enhanced/size.rb
CHANGED
@@ -1,60 +1,103 @@
|
|
1
1
|
module GosuEnhanced
|
2
2
|
# Hold a 2-dimensional size and allow for inflation / deflation
|
3
3
|
class Size
|
4
|
-
|
4
|
+
# Width in pixels
|
5
|
+
attr_reader :width
|
6
|
+
# Height in pixels
|
7
|
+
attr_reader :height
|
5
8
|
|
6
9
|
# Neither dimension can be negative, since that doesn't make sense.
|
7
10
|
# The values are checked on inflation / deflation.
|
8
11
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
+
# Initialise a size
|
13
|
+
# +wid+ Width
|
14
|
+
# +ht+ Height
|
15
|
+
|
16
|
+
def initialize(wid, ht)
|
17
|
+
@width = wid
|
18
|
+
@height = ht
|
19
|
+
validate(0, 0)
|
12
20
|
end
|
13
21
|
|
14
|
-
|
15
|
-
|
22
|
+
# Create a new size with the dimensions INcreased in the width direction
|
23
|
+
# by +by_w+ and in the height direction by +by_h+.
|
24
|
+
#
|
25
|
+
# by_w and by_h can be a Fixnum, or another Size.
|
26
|
+
|
27
|
+
def inflate(by_w, by_h = nil)
|
28
|
+
dup.inflate!(by_w, by_h)
|
16
29
|
end
|
17
30
|
|
18
|
-
|
19
|
-
|
31
|
+
# Create a new size with the dimensions DEcreased in the width direction
|
32
|
+
# by +by_w+ and in the height direction by +by_h+.
|
33
|
+
#
|
34
|
+
# by_w and by_h can be a Fixnum, or another Size.
|
35
|
+
|
36
|
+
def deflate(by_w, by_h = nil)
|
37
|
+
dup.deflate!(by_w, by_h)
|
20
38
|
end
|
21
39
|
|
22
|
-
|
23
|
-
|
24
|
-
|
40
|
+
# INcrease the dimensions of the current Size in the width direction
|
41
|
+
# by +by_w+ and in the height direction by +by_h+.
|
42
|
+
#
|
43
|
+
# by_w and by_h can be a Fixnum, or another Size.
|
25
44
|
|
26
|
-
|
27
|
-
|
28
|
-
else
|
29
|
-
validate( by_w, by_h )
|
45
|
+
def inflate!(by_w, by_h = nil)
|
46
|
+
return inflate_by_size(by_w) if by_w.respond_to? :width
|
30
47
|
|
31
|
-
|
32
|
-
|
33
|
-
|
48
|
+
validate(by_w, by_h)
|
49
|
+
|
50
|
+
@width += by_w
|
51
|
+
@height += by_h
|
34
52
|
|
35
53
|
self
|
36
54
|
end
|
37
55
|
|
38
|
-
|
56
|
+
# DEcrease the dimensions of the current Size in the width direction
|
57
|
+
# by +by_w+ and in the height direction by +by_h+.
|
58
|
+
#
|
59
|
+
# by_w and by_h can be a Fixnum, or another Size.
|
60
|
+
|
61
|
+
def deflate!(by_w, by_h = nil)
|
39
62
|
if by_w.respond_to? :width
|
40
|
-
inflate!(
|
63
|
+
inflate!(-by_w.width, -by_w.height)
|
41
64
|
else
|
42
|
-
inflate!(
|
65
|
+
inflate!(-by_w, -by_h)
|
43
66
|
end
|
44
67
|
end
|
45
68
|
|
46
|
-
|
69
|
+
# Return whether the +other+ size is identical in both dimensions
|
70
|
+
|
71
|
+
def ==(other)
|
47
72
|
width == other.width && height == other.height
|
48
73
|
end
|
49
74
|
|
75
|
+
# Return a string representation of the width and height of the current
|
76
|
+
# Size
|
77
|
+
|
50
78
|
def to_s
|
51
79
|
"<GosuEnhanced::Size #{width}x#{height}>"
|
52
80
|
end
|
53
81
|
|
54
82
|
private
|
55
83
|
|
56
|
-
|
84
|
+
# Check that the passed dimension deltas do not make either dimension of
|
85
|
+
# Size negative.
|
86
|
+
|
87
|
+
def validate(by_w, by_h)
|
57
88
|
fail 'Cannot make size negative' if width + by_w < 0 || height + by_h < 0
|
58
89
|
end
|
90
|
+
|
91
|
+
# Change the dimensions using the dimensions of another Size.
|
92
|
+
def inflate_by_size(sz)
|
93
|
+
width = sz.width
|
94
|
+
height = sz.height
|
95
|
+
validate(width, height)
|
96
|
+
|
97
|
+
@width += width
|
98
|
+
@height += height
|
99
|
+
|
100
|
+
self
|
101
|
+
end
|
59
102
|
end
|
60
103
|
end
|