class EduDraw::Sheet

A Sheet is a 2D-Canvas that can be drawn on using {Pen}

Attributes

pens[R]

@private All pens created by and for this sheet

Public Class Methods

new(x: 100, y: 100, title: "A blank sheet") click to toggle source

Creates a new Sheet

@param x [Fixnum] width in pixels @param y [Fixnum] height in pixels @param title [String] Caption of the window

Calls superclass method
# File lib/edu_draw/sheet.rb, line 15
def initialize(x: 100, y: 100, title: "A blank sheet")
        super x, y, false
        self.caption = title
        @pens = []
end

Public Instance Methods

new_animation_pen(x: 0, y: 0, angle: 0, color: Gosu::Color::GREEN) click to toggle source

Create a new {AnimationPen} that draws something different each frame

@see AnimationPen

@param (see new_pen)

# File lib/edu_draw/sheet.rb, line 41
def new_animation_pen(x: 0, y: 0, angle: 0, color: Gosu::Color::GREEN)
        pen = AnimationPen.new(x: x, y: y, angle: angle, color: color)
        pens << pen
        pen
end
new_pen(x: 0, y: 0, angle: 0, color: Gosu::Color::GREEN) click to toggle source

Creates a new {Pen} that draws on self

@see Pen

@param x [Fixnum] x-coordinate of starting position. Left is 0. @param y [Fixnum] y-coordinate of starting position. Top is 0. @param angle [Fixnum] Direction of pen in degree. 0 points to the right. @param color [Gosu::Color] Color of the pen

# File lib/edu_draw/sheet.rb, line 30
def new_pen(x: 0, y: 0, angle: 0, color: Gosu::Color::GREEN)
        pen = Pen.new(x: x, y: y, angle: angle, color: color)
        pens << pen
        pen
end

Private Instance Methods

draw() click to toggle source

Gosu hook method for drawing window content

# File lib/edu_draw/sheet.rb, line 54
def draw
        pens.map(&:shapes).each do |shapes|
                shapes.each do |shape|
                        method,*args = shape
                        send method, *args
                end
        end
end
needs_cursor?() click to toggle source

Makes gosu display the system mouse cursor

# File lib/edu_draw/sheet.rb, line 49
def needs_cursor?
        true
end
update() click to toggle source

Gosu hook method for updating game state before drawing This is called once per frame

# File lib/edu_draw/sheet.rb, line 65
def update
        pens.each &:update
        if button_down? Gosu::KbEscape
                close
        end
end