Class: Clogs::Line

Inherits:
ArtDrawable show all
Defined in:
lib/clogs/drawables/shapes.rb

Instance Attribute Summary

Attributes inherited from Drawable

#abs_x, #abs_y, #children, #height, #parent, #shoes_linkable_id, #styles, #width, #x, #y

Instance Method Summary collapse

Methods inherited from ArtDrawable

#context_style, #draw_context, #fill_paint, #left, #opaque, #parent_content_width, #positioned?, #rotation, #stroke_paint, #strokewidth, #top

Methods inherited from Drawable

#add_child, #app, #clickable?, #contains?, #destroy_self, #draw, #each_peer, #focus_gained, #focus_lost, #focusable?, for_shoes_class, #hidden?, #initialize, #margin, #needs_layout!, #notify, #on_click, #on_key, #on_mouse_move, #on_release, #positioned?, #properties_changed, #redraw!, #remove_child, #requested_height, #requested_width, #set_parent, #style

Constructor Details

This class inherits a constructor from Clogs::Drawable

Instance Method Details

#measure(available_width) ⇒ Object



131
132
133
134
135
136
# File 'lib/clogs/drawables/shapes.rb', line 131

def measure(available_width)
  @x2 = Style.dimension(style(:x2), available_width).to_i
  @y2 = Style.dimension(style(:y2), available_width).to_i
  @width = (@x2 - left).abs
  @height = (@y2 - top).abs
end

#paint(painter, ox, oy) ⇒ Object

A line's endpoints are both slot coordinates, so it cannot use the usual "draw at my top-left" convention.



140
141
142
143
144
145
# File 'lib/clogs/drawables/shapes.rb', line 140

def paint(painter, ox, oy)
  @abs_x = ox + [left, @x2].min
  @abs_y = oy + [top, @y2].min
  painter.line(ox + left, oy + top, ox + @x2, oy + @y2,
    stroke_paint || [0, 0, 0, 255], thickness: strokewidth)
end