Class: Shoes::Star
- Inherits:
-
Common::ArtElement
- Object
- Common::UIElement
- Common::ArtElement
- Shoes::Star
- Defined in:
- shoes-core/lib/shoes/star.rb
Constant Summary collapse
- STYLES =
{ fill: Shoes::COLORS[:black] }.freeze
- REDRAW_OFFSET_FACTOR =
Redrawing needs a bit of extra room. We offset by this factor, then extend our size by twice that to evenly surround the whole thing.
4
- REDRAW_SIZING_FACTOR =
REDRAW_OFFSET_FACTOR * 2
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
- #center_point ⇒ Object
- #center_point=(point) ⇒ Object
-
#create_dimensions(left, top, points, outer, inner) ⇒ Object
Don’t use param defaults as DSL explicit passes nil for missing params.
- #in_bounds?(x, y) ⇒ Boolean
- #redraw_height ⇒ Object
- #redraw_left ⇒ Object
- #redraw_top ⇒ Object
- #redraw_width ⇒ Object
Methods inherited from Common::ArtElement
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?, #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
#center_point ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'shoes-core/lib/shoes/star.rb', line 67 def center_point if style[:center] Point.new(left, top) else center_x = left + (element_width * 0.5).to_i center_y = top + (element_height * 0.5).to_i Point.new(center_x, center_y) end end |
#center_point=(point) ⇒ Object
77 78 79 80 81 82 83 84 85 |
# File 'shoes-core/lib/shoes/star.rb', line 77 def center_point=(point) if style[:center] self.left = point.x self.top = point.y else self.left = point.x - (width * 0.5).to_i self.top = point.y - (height * 0.5).to_i end end |
#create_dimensions(left, top, points, outer, inner) ⇒ Object
Don’t use param defaults as DSL explicit passes nil for missing params
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'shoes-core/lib/shoes/star.rb', line 9 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 |
#in_bounds?(x, y) ⇒ Boolean
33 34 35 36 37 38 |
# File 'shoes-core/lib/shoes/star.rb', line 33 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 |
#redraw_height ⇒ Object
63 64 65 |
# File 'shoes-core/lib/shoes/star.rb', line 63 def redraw_height element_height + strokewidth.ceil * REDRAW_SIZING_FACTOR end |
#redraw_left ⇒ Object
45 46 47 48 49 50 |
# File 'shoes-core/lib/shoes/star.rb', line 45 def redraw_left return 0 unless element_left calculated_left = element_left calculated_left -= width * 0.5 if center calculated_left - strokewidth.ceil * REDRAW_OFFSET_FACTOR end |
#redraw_top ⇒ Object
52 53 54 55 56 57 |
# File 'shoes-core/lib/shoes/star.rb', line 52 def redraw_top return 0 unless element_top calculated_top = element_top calculated_top -= width * 0.5 if center calculated_top - strokewidth.ceil * REDRAW_OFFSET_FACTOR end |
#redraw_width ⇒ Object
59 60 61 |
# File 'shoes-core/lib/shoes/star.rb', line 59 def redraw_width element_width + strokewidth.ceil * REDRAW_SIZING_FACTOR end |