Class: Shoes::Oval

Inherits:
Common::ArtElement show all
Defined in:
shoes-core/lib/shoes/oval.rb

Constant Summary collapse

STYLES =
{ fill: Shoes::COLORS[:black] }.freeze

Constants inherited from Common::ArtElement

Common::ArtElement::REDRAW_OFFSET_FACTOR, Common::ArtElement::REDRAW_SIZING_FACTOR

Constants included from Common::Style

Common::Style::DEFAULT_STYLES, Common::Style::STYLE_GROUPS

Instance Attribute Summary

Attributes included from Common::Clickable

#pass_coordinates

Attributes inherited from Common::UIElement

#app, #dimensions, #gui, #parent

Instance Method Summary collapse

Methods inherited from Common::ArtElement

#painted?, #redraw_height, #redraw_left, #redraw_top, #redraw_width

Methods included from Common::Translate

#clear_translate, #translate_left, #translate_top

Methods included from Common::Stroke

#update_stroke

Methods included from Common::Rotate

#needs_rotate?

Methods included from Common::Fill

#update_fill

Methods included from Common::Clickable

#click, #pass_coordinates?, #register_click, #release

Methods inherited from Common::UIElement

#add_to_parent, #after_initialize, #before_initialize, #create_backend, #handle_block, #initialize, #needs_rotate?, #painted?, #redraw_height, #redraw_left, #redraw_top, #redraw_width, #update_fill, #update_stroke

Methods included from Common::Style

#applicable_app_styles, #create_style_hash, included, #style, #style_init

Methods included from Common::SafelyEvaluate

#safely_evaluate

Methods included from Common::Remove

#remove

Methods included from Common::Positioning

#_position, #displace, #move

Methods included from Common::Visibility

#hidden?, #hidden_from_view?, #hide, #outside_parent_view?, #show, #toggle, #visible?

Methods included from Common::Inspect

#inspect, #to_s

Methods included from Common::Attachable

#attached_to

Constructor Details

This class inherits a constructor from Shoes::Common::UIElement

Instance Method Details

#create_dimensions(left, top, width, height) ⇒ Object


8
9
10
11
12
13
14
15
# File 'shoes-core/lib/shoes/oval.rb', line 8

def create_dimensions(left, top, width, height)
  left   ||= @style[:left] || 0
  top    ||= @style[:top] || 0
  width  ||= @style[:width] || @style[:diameter] || (@style[:radius] || 0) * 2
  height ||= @style[:height] || width

  @dimensions = AbsoluteDimensions.new left, top, width, height, @style
end

#in_bounds?(x, y) ⇒ Boolean

Returns:

  • (Boolean)

19
20
21
22
23
24
25
26
27
28
29
30
# File 'shoes-core/lib/shoes/oval.rb', line 19

def in_bounds?(x, y)
  radius_x = width.to_f / 2
  radius_y = height.to_f / 2

  middle_x = left + radius_x
  middle_y = top + radius_y

  x_side = (((x - middle_x)**2).to_f / radius_x**2)
  y_side = (((y - middle_y)**2).to_f / radius_y**2)

  x_side + y_side <= 1
end