Class: Shoes::Oval
- Inherits:
-
Common::ArtElement
- Object
- Common::UIElement
- Common::ArtElement
- Shoes::Oval
- Defined in:
- shoes-core/lib/shoes/oval.rb
Constant Summary collapse
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
Attributes inherited from Common::UIElement
#app, #dimensions, #gui, #parent
Instance Method Summary collapse
- #create_dimensions(left, top, width, height) ⇒ Object
-
#in_bounds?(x, y) ⇒ Boolean
Check out math.stackexchange.com/questions/60070/checking-whether-a-point-lies-on-a-wide-line-segment for explanations how the algorithm works.
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
Methods included from Common::Rotate
Methods included from Common::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
Methods included from Common::Remove
Methods included from Common::Positioning
Methods included from Common::Visibility
#hidden?, #hidden_from_view?, #hide, #outside_parent_view?, #show, #toggle, #visible?
Methods included from Common::Inspect
Methods included from Common::Attachable
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
Check out math.stackexchange.com/questions/60070/checking-whether-a-point-lies-on-a-wide-line-segment for explanations how the algorithm works
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 |