Sha256: e746e9e290dc1e9928ec5310811c90e7a94110bc8486ecd658dce1b4080cd091

Contents?: true

Size: 1.36 KB

Versions: 4

Compression:

Stored size: 1.36 KB

Contents

# frozen_string_literal: true
class Shoes
  class Star < Common::ArtElement
    style_with :angle, :art_styles, :common_styles, :dimensions, :inner, :outer, :points
    STYLES = { angle: 0, fill: Shoes::COLORS[:black] }.freeze

    # Don't use param defaults as DSL explicit passes nil for missing params
    def create_dimensions(left, top, points, outer, inner)
      left ||= @style[:left] || 0
      top  ||= @style[:top] || 0

      points ||= @style[:points] || 10
      outer  ||= @style[:outer] || 100.0
      inner  ||= @style[:inner] || 50.0

      # 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
      style[:outer]  = @dimensions.width / 2
      style[:inner]  = inner_dimensions.width / 2
      style[:points] = points
    end

    def in_bounds?(x, y)
      dx = width / 2.0
      dy = height / 2.0
      element_left - dx <= x && x <= element_right - dx &&
        element_top - dy <= y && y <= element_bottom - dy
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
shoes-core-4.0.0.pre12 lib/shoes/star.rb
shoes-core-4.0.0.pre11 lib/shoes/star.rb
shoes-core-4.0.0.pre10 lib/shoes/star.rb
shoes-core-4.0.0.pre9 lib/shoes/star.rb