class GosuEnhanced::Size
Hold a 2-dimensional size and allow for inflation / deflation
Attributes
Height in pixels
Width in pixels
Public Class Methods
Initialise a size
-
wid
Width -
ht
Height
# File lib/gosu_enhanced/size.rb, line 17 def initialize(wid, ht) @width = wid @height = ht validate(0, 0) end
Public Instance Methods
Return whether the other
size is identical in both dimensions
# File lib/gosu_enhanced/size.rb, line 72 def ==(other) width == other.width && height == other.height end
Create a new size with the dimensions DEcreased in the width direction by by_w
and in the height direction by by_h
.
by_w and by_h can be a Fixnum, or another Size
.
# File lib/gosu_enhanced/size.rb, line 37 def deflate(by_w, by_h = nil) dup.deflate!(by_w, by_h) end
DEcrease the dimensions of the current Size
in the width direction by by_w
and in the height direction by by_h
.
by_w and by_h can be a Fixnum, or another Size
.
# File lib/gosu_enhanced/size.rb, line 62 def deflate!(by_w, by_h = nil) if by_w.respond_to? :width inflate!(-by_w.width, -by_w.height) else inflate!(-by_w, -by_h) end end
Create a new size with the dimensions INcreased in the width direction by by_w
and in the height direction by by_h
.
by_w and by_h can be a Fixnum, or another Size
.
# File lib/gosu_enhanced/size.rb, line 28 def inflate(by_w, by_h = nil) dup.inflate!(by_w, by_h) end
INcrease the dimensions of the current Size
in the width direction by by_w
and in the height direction by by_h
.
by_w and by_h can be a Fixnum, or another Size
.
# File lib/gosu_enhanced/size.rb, line 46 def inflate!(by_w, by_h = nil) return inflate_by_size(by_w) if by_w.respond_to? :width validate(by_w, by_h) @width += by_w @height += by_h self end
Return a string representation of the width and height of the current Size
# File lib/gosu_enhanced/size.rb, line 79 def to_s "<GosuEnhanced::Size #{width}x#{height}>" end
Private Instance Methods
Change the dimensions using the dimensions of another Size
.
# File lib/gosu_enhanced/size.rb, line 93 def inflate_by_size(sz) width = sz.width height = sz.height validate(width, height) @width += width @height += height self end
Check that the passed dimension deltas do not make either dimension of Size
negative.
# File lib/gosu_enhanced/size.rb, line 88 def validate(by_w, by_h) raise 'Cannot make size negative' if width + by_w < 0 || height + by_h < 0 end