Sha256: cccbfa0d352b248732c7764bbc0c1b41d8d1dee42ca085f20f4e70c33da7f8f2

Contents?: true

Size: 1.43 KB

Versions: 1

Compression:

Stored size: 1.43 KB

Contents

class Shoes
  class Star
    include CommonMethods
    include Common::Fill
    include Common::Stroke
    include Common::Style
    include Common::Clickable
    include DimensionsDelegations

    attr_reader :app, :gui, :angle, :dimensions, :outer, :inner, :points,
                :parent

    def initialize(app, parent, left, top, points, outer, inner, opts = {}, &blk)
      @app = app

      # Careful not to turn Fixnum to Float, lest Dimensions make you relative!
      width = outer*2

      # Ignore calculated height on Dimensions--will force to match width
      @dimensions = AbsoluteDimensions.new left, top, width, 0
      @dimensions.height = @dimensions.width

      # Calculate the inner dimensions, which might be relative too
      inner_dimensions = AbsoluteDimensions.new 0, 0, inner*2, 0

      # Get actual outer/inner from the dimension to handle relative values
      @outer = @dimensions.width / 2
      @inner = inner_dimensions.width / 2

      @points = points
      @angle = opts[:angle] || 0
      @style = Shoes::Common::Fill::DEFAULTS.merge(Shoes::Common::Stroke::DEFAULTS).merge(opts)
      @style[:strokewidth] ||= 1
      @parent = parent
      @parent.add_child self

      @gui = Shoes.backend_for(self, &blk)

      clickable_options(opts)
    end

    def in_bounds?(x, y)
      dx = width / 2.0
      dy = height / 2.0
      left - dx <= x and x <= right - dx and top - dy <= y and y <= bottom - dy
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
shoes-4.0.0.pre1 lib/shoes/star.rb