instiki/vendor/madeleine-0.7.1/samples/painter.rb
2005-01-15 20:26:54 +00:00

60 lines
1.2 KiB
Ruby
Executable file

#
# Simple drawing program to show Madeleine's logging feature.
#
# When you restart the program, your old artwork is still there.
#
# (Note: The GUI components used here aren't marshal-able,
# so in a real app you would have to do custom marshaling for
# the Painter class to get working snapshots. Then again, in a real
# app you wouldn't use the GUI components to hold the app's data,
# would you?)
#
$LOAD_PATH.unshift(".." + File::SEPARATOR + "lib")
require 'madeleine'
require 'tkclass'
class Painter
def initialize(canvas)
@canvas = canvas
end
def draw(x, y)
line = Line.new(@canvas, x, y, x + 1, y + 1)
line.fill('black')
end
end
class PaintCommand
def initialize(x, y)
@x, @y = x, y
end
def execute(system)
system.draw(@x, @y)
end
end
root = TkRoot.new() { title "Madeleine Painter" }
canvas = Canvas.new(root)
canvas.pack
$madeleine = Madeleine::SnapshotMadeleine.new("painter-demo") { Painter.new(canvas) }
canvas.bind("1",
proc {|x, y|
$madeleine.execute_command(PaintCommand.new(x, y))
},
"%x %y")
canvas.bind("B1-Motion",
proc {|x, y|
$madeleine.execute_command(PaintCommand.new(x, y))
},
"%x %y")
Tk.mainloop