class GosuEnhanced::Size

Hold a 2-dimensional size and allow for inflation / deflation

Attributes

height[R]

Height in pixels

width[R]

Width in pixels

Public Class Methods

new(wid, ht) click to toggle source

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

==(other) click to toggle source

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
deflate(by_w, by_h = nil) click to toggle source

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
deflate!(by_w, by_h = nil) click to toggle source

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
inflate(by_w, by_h = nil) click to toggle source

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
inflate!(by_w, by_h = nil) click to toggle source

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
to_s() click to toggle source

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

inflate_by_size(sz) click to toggle source

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
validate(by_w, by_h) click to toggle source

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