gosu_enhanced 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1ef82237800c5e7fd75f41a937f99d7b808404ab
4
- data.tar.gz: b98df43837d6c32aea1ac89ed56535312aba3122
3
+ metadata.gz: e2699bea318f54f161b957521611d3d040b35ff3
4
+ data.tar.gz: c813f99173dde10a796a5c6b43e8c0ce7264203b
5
5
  SHA512:
6
- metadata.gz: a72b1e8286b8db6942610d7a3c5ecae0ea1f0406266141867e242d38359cf9b9bde2b0d89b5ff267f1142d725f6d43e854e76e724f29faa9daef78e84118bce0
7
- data.tar.gz: ffb4c4a46f40322495bed1705429e7e36d13a439aa8c7dcfb2a0502d9c25c17c9bd215c2da938a98a58645cdf31586b9534addd1cf0a9673180f6ea6b5c2be3d
6
+ metadata.gz: 715bfe01bfdbd958bff4cd54b439d131ce28c0d3de3cac6981581f8dade51f426483ad97f2a0b06fe6debbc2f678019380ada333331c35e6c73c4e61240b650a
7
+ data.tar.gz: e4f0de31b1089d43bc69d9518dd8f1fee678bb82fef2c360db9473e60f0ea962be73c535c08209fd968a5ea73172f8797f2429fc9de2411c059fad56ab9bd2ca
@@ -1,24 +1,24 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gosu_enhanced (0.4.1)
5
- gosu (~> 0.10)
4
+ gosu_enhanced (0.4.2)
5
+ gosu (~> 0.10.4)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- gosu (0.10.1.2)
11
- minitest (5.8.0)
10
+ gosu (0.10.4)
11
+ minitest (5.8.3)
12
12
  rake (10.4.2)
13
13
 
14
14
  PLATFORMS
15
15
  ruby
16
16
 
17
17
  DEPENDENCIES
18
- bundler (~> 1.10)
18
+ bundler (~> 1.11)
19
19
  gosu_enhanced!
20
20
  minitest (~> 5.8)
21
21
  rake (~> 10.0)
22
22
 
23
23
  BUNDLED WITH
24
- 1.10.6
24
+ 1.11.2
@@ -8,12 +8,12 @@ Gem::Specification.new do |spec|
8
8
  spec.version = GosuEnhanced::VERSION
9
9
  spec.authors = ['Julian Nicholls']
10
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 co-ordinatess
13
- and rectangle sizes respectively.
14
- Updated window class to draw rectangles and lines in a single colour more easily.
15
- Updated font class to measure text and return co-ordinates to centre a piece
16
- of text in a rectangle size.)
11
+ spec.summary = 'Extra and enhanced versions of some Gosu classes.'
12
+ spec.description = %(Point, Size, and Region classes to hold pixel
13
+ co-ordinates and rectangle sizes respectively. An updated window class to draw
14
+ rectangles and lines in a single colour more easily. Updated font class to
15
+ measure text and return co-ordinates to centre a piece of text in a rectangle
16
+ size.)
17
17
  spec.homepage = 'https://github.com/JulianNicholls/gosu_enhanced-gem'
18
18
  spec.license = 'MIT'
19
19
 
@@ -22,9 +22,9 @@ of text in a rectangle size.)
22
22
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
23
23
  spec.require_paths = ['lib']
24
24
 
25
- spec.add_runtime_dependency 'gosu', '~> 0.10'
25
+ spec.add_runtime_dependency 'gosu', '~> 0.10.4'
26
26
 
27
- spec.add_development_dependency 'bundler', '~> 1.10'
27
+ spec.add_development_dependency 'bundler', '~> 1.11'
28
28
  spec.add_development_dependency 'rake', '~> 10.0'
29
29
  spec.add_development_dependency 'minitest', '~> 5.8'
30
30
  end
@@ -1,8 +1,8 @@
1
1
  # Gosu is the module that the Gosu library uses. It is re-opened here to allow
2
2
  # access to the Window and Font classes.
3
3
  module Gosu
4
- # Add a draw_rectangle() to Window which simplifies drawing a simple rectangle
5
- # in one colour
4
+ # Add draw_rectangle() and draw_simple_line() to Window which simplifies
5
+ # drawing simple rectangles and lines in one colour
6
6
  class Window
7
7
  # Simplify drawing a rectangle in a single colour.
8
8
  #
@@ -40,8 +40,8 @@ module Gosu
40
40
  end
41
41
  end
42
42
 
43
- # Add a measure to return both width and height for a text and a way
44
- # to centre a text in a rectangle.
43
+ # Add a measure to return both width and height for a text and a way to
44
+ # centre a piece of text in a rectangle.
45
45
  class Font
46
46
  include GosuEnhanced
47
47
 
@@ -58,19 +58,16 @@ module Gosu
58
58
  # Return the co-ordnates needed to place a given string in the centre of an
59
59
  # area, both vertically and horizontally.
60
60
  #
61
- # return:: [Point] The point to write the string, expressed as an offset
62
- # from the top-left corner of the rectangle.
63
- #
64
61
  # * +text+ [String] String to centre
65
62
  # * +rect+ [Size] Rectangular area size
63
+ #
64
+ # return:: [Point] The point to write the string, expressed as an offset
65
+ # from the top-left corner of the rectangle.
66
66
 
67
67
  def centred_in(text, rect)
68
68
  size = measure(text)
69
69
 
70
- Point.new(
71
- (rect.width - size.width) / 2,
72
- (rect.height - size.height) / 2
73
- )
70
+ Point((rect.width - size.width) / 2, (rect.height - size.height) / 2)
74
71
  end
75
72
 
76
73
  # Synonym for centred_in, allowing for centre to be spelled center.
@@ -2,12 +2,16 @@
2
2
  module GosuEnhanced
3
3
  # Hold a (x, y) pixel position, and allow for offsetting and movement
4
4
  Point = Struct.new(:x, :y) do
5
+ # Negative co-ordinates are allowed.
6
+
7
+ # Return a new point offset by +by_x+ and +by_y+
8
+ # by_x and by_y can be Fixnum, or another Point, or a Size
5
9
  def offset(by_x, by_y = nil)
6
10
  dup.move_by!(by_x, by_y)
7
11
  end
8
12
 
9
- # Negative co-ordinates are allowed.
10
-
13
+ # Move the current point offset by +by_x+ and +by_y+
14
+ # by_x and by_y can be Fixnum, or another Point, or a Size
11
15
  def move_by!(by_x, by_y = nil)
12
16
  return move_by_point(by_x) if by_x.respond_to? :x
13
17
  return move_by_size(by_x) if by_x.respond_to? :width
@@ -18,6 +22,8 @@ module GosuEnhanced
18
22
  self
19
23
  end
20
24
 
25
+ # Move the current point to the point +new_x+ and +new_y+
26
+ # by_x and by_y can be Fixnum or another Point
21
27
  def move_to!(new_x, new_y = nil)
22
28
  return move_to_point(new_x) if new_x.respond_to? :x
23
29
 
@@ -29,6 +35,7 @@ module GosuEnhanced
29
35
 
30
36
  private
31
37
 
38
+ # Move the current point by the x and y co-ordinates in the Point +pt+
32
39
  def move_by_point(pt)
33
40
  self.x += pt.x
34
41
  self.y += pt.y
@@ -36,6 +43,7 @@ module GosuEnhanced
36
43
  self
37
44
  end
38
45
 
46
+ # Move the current point by the width and height in the Size +sz+
39
47
  def move_by_size(sz)
40
48
  self.x += sz.width
41
49
  self.y += sz.height
@@ -43,6 +51,7 @@ module GosuEnhanced
43
51
  self
44
52
  end
45
53
 
54
+ # Move the current point to the x and y co-ordinates in the point +pt+
46
55
  def move_to_point(pt)
47
56
  self.x = pt.x
48
57
  self.y = pt.y
@@ -62,4 +71,3 @@ module GosuEnhanced
62
71
 
63
72
  module_function :Point
64
73
  end
65
-
@@ -1,5 +1,6 @@
1
1
  require 'forwardable'
2
2
 
3
+ # Module for the Gosu Enhanced gem.
3
4
  module GosuEnhanced
4
5
  # Hold a rectangular region specified by a Point and a Size
5
6
  # Most functions are delegated to the constituent Point and Size
@@ -15,7 +16,8 @@ module GosuEnhanced
15
16
  attr_reader :size
16
17
 
17
18
  # Create a new region with specified +pos+ as top left corner and +size+
18
- # as width and height.
19
+ # as width and height. The stored positions are copies of the passed
20
+ # position and size to avoid aliasing.
19
21
  #
20
22
  # Alternatively, can be initialized with 2 +Point+s.
21
23
 
@@ -23,7 +25,7 @@ module GosuEnhanced
23
25
  size = Size.new(size.x - pos.x, size.y - pos.y) if size.respond_to? :x
24
26
 
25
27
  @position = pos.dup
26
- @size = size.dup
28
+ @size = size.dup
27
29
  end
28
30
 
29
31
  # Return whether the region contains the specified +row+ and +col+
@@ -45,6 +47,7 @@ module GosuEnhanced
45
47
  position.x
46
48
  end
47
49
 
50
+ # Duplicate a Region, must be done explicitly to avoid aliasing.
48
51
  def dup
49
52
  Region.new(position, size)
50
53
  end
@@ -62,12 +65,15 @@ module GosuEnhanced
62
65
 
63
66
  private
64
67
 
68
+ # Return whether the passed Point +pt+ is contained within the current
69
+ # Region.
65
70
  def contains_point?(pt)
66
71
  pt.x.between?(left, left + width - 1) &&
67
72
  pt.y.between?(top, top + height - 1)
68
73
  end
69
74
  end
70
75
 
76
+ # Utility function to create a new Region
71
77
  def Region(pos, size)
72
78
  Region.new(pos, size)
73
79
  end
@@ -1,3 +1,4 @@
1
+ # Module for the Gosu Enhanced gem.
1
2
  module GosuEnhanced
2
3
  # Hold a 2-dimensional size and allow for inflation / deflation
3
4
  class Size
@@ -14,7 +15,7 @@ module GosuEnhanced
14
15
  # * +ht+ Height
15
16
 
16
17
  def initialize(wid, ht)
17
- @width = wid
18
+ @width = wid
18
19
  @height = ht
19
20
  validate(0, 0)
20
21
  end
@@ -47,7 +48,7 @@ module GosuEnhanced
47
48
 
48
49
  validate(by_w, by_h)
49
50
 
50
- @width += by_w
51
+ @width += by_w
51
52
  @height += by_h
52
53
 
53
54
  self
@@ -1,5 +1,5 @@
1
1
  # Version of the gosu_enhanced gem.
2
2
  module GosuEnhanced
3
3
  # gosu_enhanced gem version
4
- VERSION = '0.4.2'
4
+ VERSION = '0.4.3'
5
5
  end
@@ -22,7 +22,7 @@ describe GosuEnhanced::Point do
22
22
  point.y.must_equal(-20)
23
23
  end
24
24
 
25
- it "should work with the utility function" do
25
+ it 'should work with the utility function' do
26
26
  point = GosuEnhanced::Point(10, 20)
27
27
  point.x.must_equal 10
28
28
  point.y.must_equal 20
@@ -68,35 +68,35 @@ describe GosuEnhanced::Point do
68
68
 
69
69
  describe '#move_by!' do
70
70
  it 'should work with another Point' do
71
- point = GosuEnhanced::Point.new(10, 20)
71
+ point = GosuEnhanced::Point.new(10, 20)
72
72
  point.move_by!(GosuEnhanced::Point.new(30, 40))
73
73
  point.x.must_equal 40
74
74
  point.y.must_equal 60
75
75
  end
76
76
 
77
77
  it 'should work with a Size' do
78
- point = GosuEnhanced::Point.new(10, 20)
78
+ point = GosuEnhanced::Point.new(10, 20)
79
79
  point.move_by!(GosuEnhanced::Size.new(40, 50))
80
80
  point.x.must_equal 50
81
81
  point.y.must_equal 70
82
82
  end
83
83
 
84
84
  it 'should work with two positive values' do
85
- point = GosuEnhanced::Point.new(10, 20)
85
+ point = GosuEnhanced::Point.new(10, 20)
86
86
  point.move_by!(40, 50)
87
87
  point.x.must_equal 50
88
88
  point.y.must_equal 70
89
89
  end
90
90
 
91
91
  it 'should work with two negative values' do
92
- point = GosuEnhanced::Point.new(60, 80)
92
+ point = GosuEnhanced::Point.new(60, 80)
93
93
  point.move_by!(-40, -50)
94
94
  point.x.must_equal 20
95
95
  point.y.must_equal 30
96
96
  end
97
97
 
98
98
  it 'should work with values that result in negative co-ordinates' do
99
- point = GosuEnhanced::Point.new(60, 80)
99
+ point = GosuEnhanced::Point.new(60, 80)
100
100
  point.move_by!(-80, -150)
101
101
  point.x.must_equal(-20)
102
102
  point.y.must_equal(-70)
@@ -105,21 +105,21 @@ describe GosuEnhanced::Point do
105
105
 
106
106
  describe '#move_to!' do
107
107
  it 'should work with another Point' do
108
- point = GosuEnhanced::Point.new(10, 20)
108
+ point = GosuEnhanced::Point.new(10, 20)
109
109
  point.move_to!(GosuEnhanced::Point.new(30, 40))
110
110
  point.x.must_equal 30
111
111
  point.y.must_equal 40
112
112
  end
113
113
 
114
114
  it 'should work with two positive values' do
115
- point = GosuEnhanced::Point.new(10, 20)
115
+ point = GosuEnhanced::Point.new(10, 20)
116
116
  point.move_to!(40, 50)
117
117
  point.x.must_equal 40
118
118
  point.y.must_equal 50
119
119
  end
120
120
 
121
121
  it 'should work with two negative values' do
122
- point = GosuEnhanced::Point.new(60, 80)
122
+ point = GosuEnhanced::Point.new(60, 80)
123
123
  point.move_to!(-40, -50)
124
124
  point.x.must_equal(-40)
125
125
  point.y.must_equal(-50)
@@ -150,7 +150,7 @@ describe GosuEnhanced::Point do
150
150
 
151
151
  describe '#to_s' do
152
152
  it 'should render usefully.' do
153
- point = GosuEnhanced::Point.new(10, 20)
153
+ point = GosuEnhanced::Point.new(10, 20)
154
154
  point.to_s.must_equal '#<struct GosuEnhanced::Point x=10, y=20>'
155
155
  end
156
156
  end
@@ -44,7 +44,7 @@ describe GosuEnhanced::Size do
44
44
  end
45
45
 
46
46
  it 'should raise an error with out-of-range values' do
47
- size = GosuEnhanced::Size.new(40, 50)
47
+ size = GosuEnhanced::Size.new(40, 50)
48
48
  expect { size.inflate(-50, -20) }.must_raise Exception
49
49
  expect { size.inflate(-30, -60) }.must_raise Exception
50
50
  expect { size.inflate(-50, -70) }.must_raise Exception
@@ -67,7 +67,7 @@ describe GosuEnhanced::Size do
67
67
  end
68
68
 
69
69
  it 'should raise an error for out-of-range values' do
70
- size = GosuEnhanced::Size.new(70, 60)
70
+ size = GosuEnhanced::Size.new(70, 60)
71
71
  expect { size.deflate(80, 50) }.must_raise Exception
72
72
  expect { size.deflate(60, 70) }.must_raise Exception
73
73
  expect { size.deflate(80, 70) }.must_raise Exception
@@ -76,28 +76,28 @@ describe GosuEnhanced::Size do
76
76
 
77
77
  describe '#inflate!' do
78
78
  it 'should work with another Size' do
79
- size = GosuEnhanced::Size.new(10, 20)
79
+ size = GosuEnhanced::Size.new(10, 20)
80
80
  size.inflate!(GosuEnhanced::Size.new(30, 40))
81
81
  size.width.must_equal 40
82
82
  size.height.must_equal 60
83
83
  end
84
84
 
85
85
  it 'should work with two values' do
86
- size = GosuEnhanced::Size.new(10, 20)
86
+ size = GosuEnhanced::Size.new(10, 20)
87
87
  size.inflate!(40, 50)
88
88
  size.width.must_equal 50
89
89
  size.height.must_equal 70
90
90
  end
91
91
 
92
92
  it 'should work with negative values' do
93
- size = GosuEnhanced::Size.new(40, 50)
93
+ size = GosuEnhanced::Size.new(40, 50)
94
94
  size.inflate!(-30, -20)
95
95
  size.width.must_equal 10
96
96
  size.height.must_equal 30
97
97
  end
98
98
 
99
99
  it 'should raise an error with out-of-range values' do
100
- size = GosuEnhanced::Size.new(40, 50)
100
+ size = GosuEnhanced::Size.new(40, 50)
101
101
  expect { size.inflate!(-50, -20) }.must_raise Exception
102
102
  expect { size.inflate!(-30, -60) }.must_raise Exception
103
103
  expect { size.inflate!(-50, -70) }.must_raise Exception
@@ -106,21 +106,21 @@ describe GosuEnhanced::Size do
106
106
 
107
107
  describe '#deflate!' do
108
108
  it 'should work with another Size' do
109
- size = GosuEnhanced::Size.new(60, 80)
109
+ size = GosuEnhanced::Size.new(60, 80)
110
110
  size.deflate!(GosuEnhanced::Size.new(30, 40))
111
111
  size.width.must_equal 30
112
112
  size.height.must_equal 40
113
113
  end
114
114
 
115
115
  it 'should work with two values' do
116
- size = GosuEnhanced::Size.new(70, 60)
116
+ size = GosuEnhanced::Size.new(70, 60)
117
117
  size.deflate!(40, 50)
118
118
  size.width.must_equal 30
119
119
  size.height.must_equal 10
120
120
  end
121
121
 
122
122
  it 'should raise an error for out-of-range values' do
123
- size = GosuEnhanced::Size.new(70, 60)
123
+ size = GosuEnhanced::Size.new(70, 60)
124
124
  expect { size.deflate!(80, 50) }.must_raise Exception
125
125
  expect { size.deflate!(60, 70) }.must_raise Exception
126
126
  expect { size.deflate!(80, 70) }.must_raise Exception
@@ -149,7 +149,7 @@ describe GosuEnhanced::Size do
149
149
 
150
150
  describe '#to_s' do
151
151
  it 'should render usefully' do
152
- size = GosuEnhanced::Size.new(10, 20)
152
+ size = GosuEnhanced::Size.new(10, 20)
153
153
  size.to_s.must_equal '<GosuEnhanced::Size 10x20>'
154
154
  end
155
155
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gosu_enhanced
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Nicholls
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-11 00:00:00.000000000 Z
11
+ date: 2016-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gosu
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.10'
19
+ version: 0.10.4
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.10'
26
+ version: 0.10.4
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.10'
33
+ version: '1.11'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.10'
40
+ version: '1.11'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -67,11 +67,11 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '5.8'
69
69
  description: |-
70
- Point, Size, and Region classes to hold pixel co-ordinatess
71
- and rectangle sizes respectively.
72
- Updated window class to draw rectangles and lines in a single colour more easily.
73
- Updated font class to measure text and return co-ordinates to centre a piece
74
- of text in a rectangle size.
70
+ Point, Size, and Region classes to hold pixel
71
+ co-ordinates and rectangle sizes respectively. An updated window class to draw
72
+ rectangles and lines in a single colour more easily. Updated font class to
73
+ measure text and return co-ordinates to centre a piece of text in a rectangle
74
+ size.
75
75
  email:
76
76
  - juliannicholls29@gmail.com
77
77
  executables: []
@@ -116,10 +116,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
116
  version: '0'
117
117
  requirements: []
118
118
  rubyforge_project:
119
- rubygems_version: 2.4.5.1
119
+ rubygems_version: 2.4.8
120
120
  signing_key:
121
121
  specification_version: 4
122
- summary: Enhanced versions of some Gosu classes.
122
+ summary: Extra and enhanced versions of some Gosu classes.
123
123
  test_files:
124
124
  - test/point_test.rb
125
125
  - test/region_delegation_test.rb