Class: Clogs::ArtDrawable

Inherits:
Drawable
  • Object
show all
Defined in:
lib/clogs/drawables/shapes.rb

Overview

Shoes' art drawables. In Shoes these always carry their own left/top and so are positioned within the current slot rather than flowed.

Direct Known Subclasses

Arc, Arrow, Line, Oval, Rect, Shape, Star

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 Drawable

#add_child, #app, #clickable?, #contains?, #destroy_self, #draw, #each_peer, #focus_gained, #focus_lost, #focusable?, for_shoes_class, #hidden?, #initialize, #margin, #measure, #needs_layout!, #notify, #on_click, #on_key, #on_mouse_move, #on_release, #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

#context_style(name) ⇒ Object



45
46
47
48
# File 'lib/clogs/drawables/shapes.rb', line 45

def context_style(name)
  value = style(name)
  value.nil? ? draw_context[name.to_s] : value
end

#draw_contextObject

Shoes' fill, stroke, strokewidth and rotate are draw context styles: set once on a slot, inherited by every art drawable made inside it. Lacci copies them onto drawables that declare them as their own styles, but drawables like Line and Shape do not, so the draw context has to be consulted directly.



41
42
43
# File 'lib/clogs/drawables/shapes.rb', line 41

def draw_context
  @styles["draw_context"] || {}
end

#fill_paintObject

nofill and nostroke arrive as fully transparent colours rather than as nil, so treat zero alpha as "do not paint this".



52
53
54
# File 'lib/clogs/drawables/shapes.rb', line 52

def fill_paint
  opaque(Style.color(context_style(:fill), nil))
end

#leftObject



24
25
26
# File 'lib/clogs/drawables/shapes.rb', line 24

def left
  Style.dimension(style(:left), parent_content_width).to_i
end

#opaque(color) ⇒ Object



60
61
62
# File 'lib/clogs/drawables/shapes.rb', line 60

def opaque(color)
  color && color[3].to_i.positive? ? color : nil
end

#paint(painter, ox, oy) ⇒ Object

Art drawables paint relative to the slot, honouring any rotation from the draw context.



74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/clogs/drawables/shapes.rb', line 74

def paint(painter, ox, oy)
  @abs_x = ox + @x
  @abs_y = oy + @y
  if rotation.zero?
    draw(painter, @abs_x, @abs_y)
  else
    painter.save do |p|
      p.rotate(rotation, @abs_x + @width / 2.0, @abs_y + @height / 2.0)
      draw(p, @abs_x, @abs_y)
    end
  end
end

#parent_content_widthObject



32
33
34
# File 'lib/clogs/drawables/shapes.rb', line 32

def parent_content_width
  @parent.respond_to?(:instance_variable_get) ? (@parent&.instance_variable_get(:@content_width) || 0) : 0
end

#positioned?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/clogs/drawables/shapes.rb', line 20

def positioned?
  true
end

#rotationObject



68
69
70
# File 'lib/clogs/drawables/shapes.rb', line 68

def rotation
  context_style(:rotate).to_f
end

#stroke_paintObject



56
57
58
# File 'lib/clogs/drawables/shapes.rb', line 56

def stroke_paint
  opaque(Style.color(context_style(:stroke), nil))
end

#strokewidthObject



64
65
66
# File 'lib/clogs/drawables/shapes.rb', line 64

def strokewidth
  (context_style(:strokewidth) || 1).to_i
end

#topObject



28
29
30
# File 'lib/clogs/drawables/shapes.rb', line 28

def top
  Style.dimension(style(:top), parent_content_width).to_i
end