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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fdfb20c8fb5079f40adf28f07762babe6a844f1c
4
- data.tar.gz: 6dd6cfd4a944a7e1888c423d878c7fd4835c67e6
3
+ metadata.gz: 3a951985d3479c4c6c784582a6c62d89033d20a0
4
+ data.tar.gz: 6abef53400b8d8994e1e43ff69af8e1ceaf0fb6c
5
5
  SHA512:
6
- metadata.gz: e27f8d50b970ee5a7b9b41b6ecb76fa1da3597cbcfb10df3af0d44c8b9a7fcb4840061b828a92fefc5a26291132680fc2ddb71e03a6e5da6a2c0798e54d6333f
7
- data.tar.gz: 35804c2dac06b6b21ebd527c1617c16e626003c9b622063f46a7dca4eb9de003010c2aaaecb064d649618f8def62ad4c4f72156999c4bdf140b5c39d30536a0d
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.3)
5
- gosu (~> 0.7)
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.7.50)
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 (~> 1.6)
41
+ bundler
42
42
  gosu_enhanced!
43
- pry (~> 0.10)
44
- rake (~> 0.9)
45
- rspec (~> 3.0)
46
- rspec-nc (~> 0.0)
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.2
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-2014 Julian Raschke, Jan Lücker, and
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 "bundler/gem_tasks"
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( :spec ) do |task|
6
+ RSpec::Core::RakeTask.new(:spec) do |task|
7
7
  task.rspec_opts = ['--color']
8
8
  end
9
9
 
10
- task :default => :spec
10
+ task default: :spec
@@ -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 = "gosu_enhanced"
7
+ spec.name = 'gosu_enhanced'
8
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 = %{Point, Size, and Region classes to hold pixel addresses
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 = "https://github.com/JulianNicholls/gosu_enhanced-gem"
18
- spec.license = "MIT"
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 = ["lib"]
23
+ spec.require_paths = ['lib']
24
24
 
25
- spec.add_runtime_dependency "gosu", "~> 0.9"
25
+ spec.add_runtime_dependency 'gosu', '~> 0.10'
26
26
 
27
- spec.add_development_dependency "bundler", "~> 1.6"
28
- spec.add_development_dependency "rake", "~> 0.9"
29
- spec.add_development_dependency "rspec", "~> 3.0"
30
- spec.add_development_dependency "rspec-nc", "~> 0.0"
31
- spec.add_development_dependency "pry", "~> 0.10"
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
- # @param point [Point] Top left corner
10
- # @param size [Size] Width and Height
11
- # @param z_index [Fixnum] Z-order
12
- # @param colour [Gosu::Color] Colour of rectangle
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( point, size, z_index, colour )
15
- left, top = point.x, point.y
16
- width, height = size.width, size.height
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
- # @param text [String] String to measure
36
+ # +text+ String to measure
36
37
  #
37
- # @return [Size] The height and width of the string.
38
+ # return [Size] The height and width of the string.
38
39
 
39
- def measure( text )
40
- Size.new( text_width( text, 1 ), height )
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
- # @param text [String] String to centre
47
- # @param rect [Size] Rectangular area size
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
- # @return [Point] The point to write the string, expressed as an offset from the top-left corner of the rectangle.
50
+ # +text+ [String] String to centre
51
+ # +rect+ [Size] Rectangular area size
50
52
 
51
- def centred_in( text, rect )
52
- size = measure( text )
53
+ def centred_in(text, rect)
54
+ size = measure(text)
53
55
 
54
56
  Point.new(
55
57
  (rect.width - size.width) / 2,
@@ -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( :x, :y ) do
4
- def offset( by_x, by_y = nil )
5
- self.dup.move_by!( by_x, by_y )
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!( by_x, by_y = nil )
11
- if by_x.respond_to? :x
12
- self.x += by_x.x
13
- self.y += by_x.y
14
- elsif by_x.respond_to? :width
15
- self.x += by_x.width
16
- self.y += by_x.height
17
- else
18
- self.x += by_x
19
- self.y += by_y
20
- end
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 move_to!( new_x, new_y = nil )
26
- if new_x.respond_to? :x
27
- self.x, self.y = new_x.x, new_x.y
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
@@ -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
- attr_reader :position, :size
12
+ # Top left corner
13
+ attr_reader :position
14
+ # Overall Width and Height
15
+ attr_reader :size
13
16
 
14
- def initialize( pos, size )
15
- @position, @size = pos.dup, size.dup
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
- def contains?( col, row = nil )
19
- if col.respond_to? :x
20
- col.x.between?( left, left + width - 1 ) &&
21
- col.y.between?( top, top + height - 1 )
22
- else
23
- col.between?( left, left + width - 1 ) &&
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( position, size )
44
+ Region.new(position, size)
39
45
  end
40
46
 
41
- def draw( surface, z_order, colour )
42
- surface.draw_rectangle( position, size, z_order, colour )
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
@@ -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
- attr_reader :width, :height
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
- def initialize( w, h )
10
- @width, @height = w, h
11
- validate( 0, 0 )
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
- def inflate( by_w, by_h = nil )
15
- self.dup.inflate!( by_w, by_h )
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
- def deflate( by_w, by_h = nil )
19
- self.dup.deflate!( by_w, by_h )
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
- def inflate!( by_w, by_h = nil )
23
- if by_w.respond_to? :width
24
- validate( by_w.width, by_w.height )
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
- @width += by_w.width
27
- @height += by_w.height
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
- @width += by_w
32
- @height += by_h
33
- end
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
- def deflate!( by_w, by_h = nil )
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!( -by_w.width, -by_w.height )
63
+ inflate!(-by_w.width, -by_w.height)
41
64
  else
42
- inflate!( -by_w, -by_h )
65
+ inflate!(-by_w, -by_h)
43
66
  end
44
67
  end
45
68
 
46
- def ==( other )
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
- def validate( by_w, by_h )
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
@@ -1,4 +1,5 @@
1
-
1
+ # Version of the gosu_enhanced gem.
2
2
  module GosuEnhanced
3
- VERSION = '0.3.4'
3
+ # gosu_enhanced gem version
4
+ VERSION = '0.3.5'
4
5
  end