class EduDraw::Sheet
A Sheet
is a 2D-Canvas that can be drawn on using {Pen}
Attributes
@private All pens created by and for this sheet
Public Class Methods
Creates a new Sheet
@param x [Fixnum] width in pixels @param y [Fixnum] height in pixels @param title [String] Caption of the window
# 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
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
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
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
Makes gosu display the system mouse cursor
# File lib/edu_draw/sheet.rb, line 49 def needs_cursor? true end
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