Class: Clogs::Shape

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

Overview

shape { move_to ...; line_to ... } -- Shoes records the commands and the display service replays them.

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, #paint, #parent_content_width, #positioned?, #rotation, #stroke_paint, #strokewidth, #top

Methods inherited from Drawable

#add_child, #app, #clickable?, #contains?, #destroy_self, #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, #paint, #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

#draw(painter, x, y) ⇒ Object



217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/clogs/drawables/shapes.rb', line 217

def draw(painter, x, y)
  painter.draw(fill: fill_paint, stroke: stroke_paint, thickness: strokewidth) do |p|
    started = false
    Array(style(:shape_commands)).each do |cmd|
      name, *args = cmd
      case name.to_s
      when "move_to"
        p.move_to(x + args[0], y + args[1])
        started = true
      when "line_to"
        p.move_to(x + args[0], y + args[1]) unless started
        started = true
        p.line_to(x + args[0], y + args[1])
      when "curve_to"
        p.curve_to(x + args[2], y + args[3], x + args[4], y + args[5], x + args[0], y + args[1])
      when "arc_to"
        p.arc_to(x + args[0], y + args[1], args[2], args[4].to_f, args[5].to_f - args[4].to_f)
      end
    end
  end
end

#measure(_available_width) ⇒ Object



206
207
208
209
210
211
212
213
214
215
# File 'lib/clogs/drawables/shapes.rb', line 206

def measure(_available_width)
  xs = []
  ys = []
  Array(style(:shape_commands)).each do |cmd|
    _name, *args = cmd
    args.each_slice(2) { |px, py| xs << px.to_f; ys << py.to_f if py }
  end
  @width = xs.empty? ? 0 : xs.max.ceil
  @height = ys.empty? ? 0 : ys.max.ceil
end