Class: Shoes::Swt::StarPainter

Inherits:
Common::Painter show all
Defined in:
shoes-swt/lib/shoes/swt/star_painter.rb

Constant Summary

Constants inherited from Common::Painter

Common::Painter::LINECAP

Constants included from Common::Resource

Common::Resource::OPAQUE

Instance Method Summary collapse

Methods inherited from Common::Painter

#after_painted, #before_painted, #draw_setup, #drawing_bottom, #drawing_top, #fill_and_draw, #fill_setup, #initialize, #paint_control, #paint_object, #reset_rotate, #set_rotate

Methods included from Common::Resource

#clip_context_to, #dispose_previous_contexts, #reset_graphics_context, #set_defaults_on_context, #track_graphics_context

Constructor Details

This class inherits a constructor from Shoes::Swt::Common::Painter

Instance Method Details

#add_edge(start, finish) ⇒ Object



31
32
33
# File 'shoes-swt/lib/shoes/swt/star_painter.rb', line 31

def add_edge(start, finish)
  @polygon << start << finish
end

#draw(gc) ⇒ Object



10
11
12
# File 'shoes-swt/lib/shoes/swt/star_painter.rb', line 10

def draw(gc)
  gc.drawPolygon make_polygon(@obj)
end

#fill(gc) ⇒ Object



6
7
8
# File 'shoes-swt/lib/shoes/swt/star_painter.rb', line 6

def fill(gc)
  gc.fillPolygon make_polygon(@obj)
end

#make_edge(i, left, top, outer, inner, points) ⇒ Object



35
36
37
38
39
40
# File 'shoes-swt/lib/shoes/swt/star_painter.rb', line 35

def make_edge(i, left, top, outer, inner, points)
  r = i.even? ? outer : inner
  angle = i * ::Math::PI / points
  add_edge(left + r * ::Math.sin(angle),
           top  + r * ::Math.cos(angle))
end

#make_polygon(obj) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'shoes-swt/lib/shoes/swt/star_painter.rb', line 14

def make_polygon(obj)
  outer = obj.outer
  inner = obj.inner
  points = obj.points
  left = obj.translate_left + obj.element_left
  top = obj.translate_top + drawing_top
  @polygon = []
  add_edge(left, top + outer)
  (1..points * 2).each do |i|
    make_edge(i, left, top, outer, inner, points)
  end

  translate_to_proper_start(obj)

  @polygon
end

#translate_to_proper_start(obj) ⇒ Object

Prior logic centers start on left/top, so translate to where we really want to start.



44
45
46
47
48
49
50
# File 'shoes-swt/lib/shoes/swt/star_painter.rb', line 44

def translate_to_proper_start(obj)
  return if obj.dsl.style[:center]

  @polygon.map! do |x|
    x + obj.element_width / 2
  end
end