Skip to content

Object Orientation and Position

shairontoledo edited this page Sep 13, 2010 · 2 revisions

There are two ways that you can work; the relative position with automatic cursor and absolute position passing the coordinate x,y to object or specifying in the body of the document.

Relative

next_row()

Jump to the next row. It‘s the same as jump_rows(1).

 doc=RGhost::Document.new 
doc.show "Row 1" 
doc.next_row 
doc.show "Row 2" 
doc.next_row 
doc.show "Row 3" 

show_next_row(text,show_options)

Executes show and the method next_row. The result of the code below is the same as above.

doc=RGhost::Document.new 
doc.show "Row 1" 
doc.show_next_row “Row 2”
doc.show_next_row “Row 3”

goto_row(row_number)

The class method goto positions the cursor based on page row number. Example:

d=Document.new 
d.goto_row 15 
d.show "You're on row 15" 
d.goto_row 3 
d.show "Now you're on row 3" 

Or without facade

d=RGhost::Document.new 
d.set Cursor.goto_row(15) 
d.set Show.new(" You're on row 15") 
d.set Cursor.goto_row(3) 
d.set Show.new("Now you're on row 3") 

jump_rows(rows)

Jumps n rows relative to the current row

d=RGhost::Document.new 
d.jump_rows 4    # jump four rows below 
d.jump_rows -5   # go back up five rows

Absolute

moveto(point={:x => :limit_left, :y => :current_row )

Moves cursor to absolute point relative to default source point x=0 and y=0 of the page. It doesn’t interfere with the row positions.

doc=RGhost::Document.new 
doc.moveto :x=> 10, :y=> 5 
doc.show "Hello Girls!!!" 

rmoveto(point={:x => :limit_left, :y => :current_row )

It works the same way as moveto; the only difference is that it’s relative to the current point.

doc=RGhost::Document.new 
doc.moveto :x=> 10, :y=> 5 
doc.show "Hello Girls!!!" 
doc.rmoveto :x => 5               # move to x=> 15 (10 plus 5) maintaining y => 5 

translate(point={:x =>0 , :y => 0})

It changes the default point to a new point(dislocate)

doc=RGhost::Document.new 
doc.translate :x=> 2, :y=> 1 
#the translate method dislocates to :x=> 2, :y=> 1, so the moveto(0,0) will refer to the same    point (2,1).
doc.moveto :x => 0,:y => 0 
doc.translate :x=> -2, :y=> -1  # returns to default source point 

rotate(angle)

Rotates all objects after executing them, passing the angle as argument.

d=RGhost::Document.new 
d.rotate 90 
 #do something 
 d.rotate -90  # goes back to source angle 

Using it inside newpath block

d=RGhost::Document.new 
d.newpath do |n|
  n.moveto :x => 5, :y => 5
  n.rotate 90 
  n.show 'Foo'
end

Using it inside graphic block


d=RGhost::Document.new 
d.graphic do |g|
  g.moveto :x => 5, :y => 5
  g.rotate 90 
  g.show 'Foo'
end