Class: Shoes::Shape
- Inherits:
-
Common::ArtElement
- Object
- Common::UIElement
- Common::ArtElement
- Shoes::Shape
- Defined in:
- shoes-core/lib/shoes/shape.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 collapse
-
#blk ⇒ Object
readonly
Returns the value of attribute blk.
-
#bottom_bound ⇒ Object
readonly
Returns the value of attribute bottom_bound.
-
#left_bound ⇒ Object
readonly
Returns the value of attribute left_bound.
-
#right_bound ⇒ Object
readonly
Returns the value of attribute right_bound.
-
#top_bound ⇒ Object
readonly
Returns the value of attribute top_bound.
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Attributes included from Common::Clickable
Attributes inherited from Common::UIElement
#app, #dimensions, #gui, #parent
Instance Method Summary collapse
- #after_initialize(*_) ⇒ Object
-
#arc_to(x, y, width, height, start_angle, arc_angle) ⇒ Shoes::Shape
Draws an arc.
- #create_dimensions(left, top) ⇒ Object
-
#curve_to(cx1, cy1, cx2, cy2, x, y) ⇒ Shoes::Shape
Draws a curve.
- #element_height ⇒ Object
- #element_width ⇒ Object
- #fixed_height? ⇒ Boolean
- #handle_block(blk) ⇒ Object
- #height ⇒ Object
-
#in_bounds?(x, y) ⇒ Boolean
Determines if a given point is in the boundary of the shape.
-
#initialize(*args) ⇒ Shape
constructor
A new instance of Shape.
-
#line_to(x, y) ⇒ Shoes::Shape
Draws a line from the current position to the given point.
-
#move(left, top) ⇒ Shoes::Shape
Moves the shape.
-
#move_to(x, y) ⇒ Shoes::Shape
Moves the drawing “pen” to the given point.
- #redraw_height ⇒ Object
- #redraw_left ⇒ Object
- #redraw_top ⇒ Object
- #redraw_width ⇒ Object
- #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, #before_initialize, #create_backend, #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
#initialize(*args) ⇒ Shape
Returns a new instance of Shape.
10 11 12 13 14 15 16 17 18 |
# File 'shoes-core/lib/shoes/shape.rb', line 10 def initialize(*args) @bottom_bound = nil @left_bound = nil @right_bound = nil @top_bound = nil @x = nil @y = nil super end |
Instance Attribute Details
#blk ⇒ Object (readonly)
Returns the value of attribute blk.
5 6 7 |
# File 'shoes-core/lib/shoes/shape.rb', line 5 def blk @blk end |
#bottom_bound ⇒ Object (readonly)
Returns the value of attribute bottom_bound.
5 6 7 |
# File 'shoes-core/lib/shoes/shape.rb', line 5 def bottom_bound @bottom_bound end |
#left_bound ⇒ Object (readonly)
Returns the value of attribute left_bound.
5 6 7 |
# File 'shoes-core/lib/shoes/shape.rb', line 5 def left_bound @left_bound end |
#right_bound ⇒ Object (readonly)
Returns the value of attribute right_bound.
5 6 7 |
# File 'shoes-core/lib/shoes/shape.rb', line 5 def right_bound @right_bound end |
#top_bound ⇒ Object (readonly)
Returns the value of attribute top_bound.
5 6 7 |
# File 'shoes-core/lib/shoes/shape.rb', line 5 def top_bound @top_bound end |
#x ⇒ Object (readonly)
Returns the value of attribute x.
5 6 7 |
# File 'shoes-core/lib/shoes/shape.rb', line 5 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
5 6 7 |
# File 'shoes-core/lib/shoes/shape.rb', line 5 def y @y end |
Instance Method Details
#after_initialize(*_) ⇒ Object
34 35 36 37 38 39 40 |
# File 'shoes-core/lib/shoes/shape.rb', line 34 def after_initialize(*_) @before_drawing = true @app.eval_with_additional_context self, &@blk # If we haven't drawn enough to get our bounds, default them out update_bounds([0], [0]) if @left_bound.nil? end |
#arc_to(x, y, width, height, start_angle, arc_angle) ⇒ Shoes::Shape
Draws an arc
147 148 149 150 151 152 153 |
# File 'shoes-core/lib/shoes/shape.rb', line 147 def arc_to(x, y, width, height, start_angle, arc_angle) update_bounds_rect(x - width / 2, y - height / 2, x + width / 2, y + height / 2) @x = x @y = y @gui.arc_to(x, y, width, height, start_angle, arc_angle) self end |
#create_dimensions(left, top) ⇒ Object
20 21 22 23 24 25 |
# File 'shoes-core/lib/shoes/shape.rb', line 20 def create_dimensions(left, top) left ||= @style[:left] || 0 top ||= @style[:top] || 0 @dimensions = AbsoluteDimensions.new left, top end |
#curve_to(cx1, cy1, cx2, cy2, x, y) ⇒ Shoes::Shape
Draws a curve
130 131 132 133 134 135 136 |
# File 'shoes-core/lib/shoes/shape.rb', line 130 def curve_to(cx1, cy1, cx2, cy2, x, y) update_bounds([@x, cx1, cx2, x], [@y, cy1, cy2, y]) @x = x @y = y @gui.curve_to(cx1, cy1, cx2, cy2, x, y) self end |
#element_height ⇒ Object
55 56 57 58 |
# File 'shoes-core/lib/shoes/shape.rb', line 55 def element_height return super unless @bottom_bound && @top_bound @bottom_bound - @top_bound end |
#element_width ⇒ Object
50 51 52 53 |
# File 'shoes-core/lib/shoes/shape.rb', line 50 def element_width return super unless @right_bound && @left_bound @right_bound - @left_bound end |
#fixed_height? ⇒ Boolean
60 61 62 |
# File 'shoes-core/lib/shoes/shape.rb', line 60 def fixed_height? false end |
#handle_block(blk) ⇒ Object
27 28 29 30 31 32 |
# File 'shoes-core/lib/shoes/shape.rb', line 27 def handle_block(blk) # Will register click from styles if present, but blk is for drawing! register_click @blk = blk end |
#height ⇒ Object
46 47 48 |
# File 'shoes-core/lib/shoes/shape.rb', line 46 def height @app.height end |
#in_bounds?(x, y) ⇒ Boolean
Determines if a given point is in the boundary of the shape. Given the many possibilities of what a shape could contain, this just checks the outer bounding box of the shape, nothing more sophisticated.
158 159 160 161 |
# File 'shoes-core/lib/shoes/shape.rb', line 158 def in_bounds?(x, y) (@left_bound..@right_bound).cover?(x) && (@top_bound..@bottom_bound).cover?(y) end |
#line_to(x, y) ⇒ Shoes::Shape
Draws a line from the current position to the given point
101 102 103 104 105 106 107 |
# File 'shoes-core/lib/shoes/shape.rb', line 101 def line_to(x, y) update_bounds_rect(@x, @y, x, y) @x = x @y = y @gui.line_to(x, y) self end |
#move(left, top) ⇒ Shoes::Shape
Moves the shape
89 90 91 92 93 94 |
# File 'shoes-core/lib/shoes/shape.rb', line 89 def move(left, top) self.left = left self.top = top @gui.update_position self end |
#move_to(x, y) ⇒ Shoes::Shape
Moves the drawing “pen” to the given point
114 115 116 117 118 119 |
# File 'shoes-core/lib/shoes/shape.rb', line 114 def move_to(x, y) @x = x @y = y @gui.move_to(x, y) self end |
#redraw_height ⇒ Object
79 80 81 82 |
# File 'shoes-core/lib/shoes/shape.rb', line 79 def redraw_height return 0 unless element_height element_height + 2 * strokewidth.to_i end |
#redraw_left ⇒ Object
64 65 66 67 |
# File 'shoes-core/lib/shoes/shape.rb', line 64 def redraw_left return 0 unless @left_bound @left_bound - strokewidth.to_i end |
#redraw_top ⇒ Object
69 70 71 72 |
# File 'shoes-core/lib/shoes/shape.rb', line 69 def redraw_top return 0 unless @top_bound @top_bound - strokewidth.to_i end |
#redraw_width ⇒ Object
74 75 76 77 |
# File 'shoes-core/lib/shoes/shape.rb', line 74 def redraw_width return 0 unless element_width element_width + 2 * strokewidth.to_i end |
#width ⇒ Object
42 43 44 |
# File 'shoes-core/lib/shoes/shape.rb', line 42 def width @app.width end |