Class: RGhost::Polygon

Inherits:
PsObject show all
Defined in:
lib/rghost/polygon.rb

Overview

Draw one shape based in relative node points.

Options

  • :x and :y - Initial position.

  • :content - Facade to ShapeContent with same parameters.

  • :border - Facade to Border with same parameters.

Examples

doc.polygon :x => 3.5, :y => 5.5 do

node :x => 4,  :y => 0
node :x => 0,  :y => -4
node :x => -4, :y => 0
node :x => 0,  :y => 4

end

doc.polygon :x => 3.5, :y => 4.5 do

node :x => 2,  :y => 2
node :x => 2,  :y => -2
node :x => -2, :y => -2

end

doc.polygon :x => 1, :y => 5, :border => => 2, :linejoin => 1 do

node :x => 2,  :y => 2/2
node :x => 2*2,:y => -2
node :x => -1, :y => -3
node :x => 2,  :y => 1
node :x => 3,  :y => 2

end

Constant Summary collapse

DEFAULT_OPTIONS =
{
  :x => :limit_left,
  :y => :current_row,
  :content => RGhost::ShapeContent::DEFAULT_OPTIONS,
  :border =>  RGhost::Border::DEFAULT_OPTIONS
  
  
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from PsObject

#<<, #call, #graphic_scope, #raw, #set, #to_s

Constructor Details

#initialize(options = {}, &block) ⇒ Polygon

Returns a new instance of Polygon.



46
47
48
49
50
51
52
# File 'lib/rghost/polygon.rb', line 46

def initialize(options={},&block)
  super(''){}
  
  @options = DEFAULT_OPTIONS.dup.merge(options)
  @points=[] 
  instance_eval(&block) if block
end

Instance Attribute Details

#pointsObject (readonly)

Returns the value of attribute points.



36
37
38
# File 'lib/rghost/polygon.rb', line 36

def points
  @points
end

Instance Method Details

#node(point) ⇒ Object

Creates new relative point by :x => 2 and :y => 4. Used as instance_eval



54
55
56
# File 'lib/rghost/polygon.rb', line 54

def node(point)
  @points << point
end

#psObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/rghost/polygon.rb', line 58

def ps
  graph=RGhost::Graphic.new 
  graph.set RGhost::Cursor.moveto(@options)
  graph.set RGhost::Border.new(@options[:border]) if @options[:border]
  
  @points.each{|p|  graph.set RGhost::Line.rlineto(p) }
  
  graph.raw :closepath
  #graph.raw :gsave
  graph.set RGhost::ShapeContent.new(@options[:content]) if @options[:content]
  #graph.raw :grestore
  graph.raw :stroke
  graph
      
  
end