Sha256: e4b4ca91193601c20a4bef2bec984ec3bfb67dfd28035bc097f338be2ff24c33

Contents?: true

Size: 1.24 KB

Versions: 7

Compression:

Stored size: 1.24 KB

Contents

#
# 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

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
madeleine-0.9.0 samples/painter.rb
madeleine-0.9.0.pre samples/painter.rb
madeleine-0.8.0 samples/painter.rb
madeleine-0.8.0.pre samples/painter.rb
madeleine-0.7.3 samples/painter.rb
madeleine-0.7.2 samples/painter.rb
madeleine-0.7.1 samples/painter.rb