Class: Shoes::Swt::ArrowPainter

Inherits:
Common::Painter show all
Defined in:
shoes-swt/lib/shoes/swt/arrow_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

#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

#after_paintedObject



60
61
62
# File 'shoes-swt/lib/shoes/swt/arrow_painter.rb', line 60

def after_painted
  clear_path
end

#clear_pathObject



64
65
66
67
# File 'shoes-swt/lib/shoes/swt/arrow_painter.rb', line 64

def clear_path
  @path.dispose unless @path.nil? || @path.disposed?
  @path = nil
end

#disposeObject



56
57
58
# File 'shoes-swt/lib/shoes/swt/arrow_painter.rb', line 56

def dispose
  clear_path
end

#draw(gc) ⇒ Object



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

def draw(gc)
  gc.draw_path(path)
end

#fill(gc) ⇒ Object



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

def fill(gc)
  gc.fill_path(path)
end

#pathObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'shoes-swt/lib/shoes/swt/arrow_painter.rb', line 14

def path
  @path ||= begin
    #
    #                                  body_right
    #
    #  head_top        body_left       |\
    #                                  | \
    #  body_top        |---------------|  \  head_right
    #                  |                   \
    #  body_middle     |           (l,t)    |
    #                  |                   /
    #  body_bottom     |---------------|  /
    #                                  | /
    #  head_bottom                     |/
    #

    body_left   = @obj.translate_left + @obj.left - @obj.width * 0.5
    body_right  = @obj.translate_left + @obj.left + @obj.width * 0.1
    body_top    = @obj.translate_top + drawing_top - @obj.width * 0.2
    body_bottom = @obj.translate_top + drawing_top + @obj.width * 0.2

    middle = @obj.translate_top + drawing_top

    head_right  = @obj.translate_left + @obj.left + @obj.width * 0.5
    head_top    = @obj.translate_top + drawing_top - @obj.width * 0.4
    head_bottom = @obj.translate_top + drawing_top + @obj.width * 0.4

    path = ::Swt::Path.new(::Swt.display)
    path.move_to(body_left, middle)
    path.line_to(body_left, body_top)
    path.line_to(body_right, body_top)
    path.line_to(body_right, head_top)
    path.line_to(head_right, middle)
    path.line_to(body_right, head_bottom)
    path.line_to(body_right, body_bottom)
    path.line_to(body_left, body_bottom)
    path.line_to(body_left, middle)

    path
  end
end