panda_canvas 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +3 -2
- data/lib/panda_canvas/canvas.rb +27 -0
- data/lib/panda_canvas/version.rb +5 -5
- data/lib/panda_canvas.rb +25 -39
- metadata +3 -2
data/README.rdoc
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
= Panda Canvas
|
2
2
|
|
3
|
-
Panda Canvas is an educational 2D drawing canvas on top of Gosu and TexPlay.
|
4
|
-
|
3
|
+
Panda Canvas is an educational 2D drawing canvas on top of {Gosu}[http://www.libgosu.org/] and {TexPlay}[http://github.com/banister/texplay].
|
4
|
+
|
5
|
+
It is created as a teaching tool for the {Computer Club n.a. 8-bit Panda}[http://panda.tsi.lv].
|
5
6
|
|
6
7
|
== Installation
|
7
8
|
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'texplay'
|
2
|
+
require 'fiber'
|
3
|
+
|
4
|
+
module PandaCanvas
|
5
|
+
|
6
|
+
class Canvas < Gosu::Window
|
7
|
+
|
8
|
+
attr_reader :image
|
9
|
+
|
10
|
+
def initialize(width, height, fiber)
|
11
|
+
super(width, height, false)
|
12
|
+
self.caption = 'Panda Canvas'
|
13
|
+
@image = TexPlay.create_image(self, width, height)
|
14
|
+
@fiber = fiber
|
15
|
+
end
|
16
|
+
|
17
|
+
def draw
|
18
|
+
@image.draw(0, 0, 0)
|
19
|
+
end
|
20
|
+
|
21
|
+
def update
|
22
|
+
@fiber.resume if @fiber.alive?
|
23
|
+
end
|
24
|
+
|
25
|
+
end # Canvas
|
26
|
+
|
27
|
+
end # PandaCanvas
|
data/lib/panda_canvas/version.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
class PandaCanvas
|
2
|
-
|
3
|
-
# PandaCanvas version.
|
4
|
-
VERSION = '0.
|
5
|
-
|
1
|
+
class PandaCanvas
|
2
|
+
|
3
|
+
# PandaCanvas version.
|
4
|
+
VERSION = '0.2.0'
|
5
|
+
|
6
6
|
end # end PandaCanvas
|
data/lib/panda_canvas.rb
CHANGED
@@ -1,50 +1,36 @@
|
|
1
|
+
libdir = File.dirname(__FILE__)
|
2
|
+
$:.unshift(libdir) unless $:.include?(libdir)
|
3
|
+
|
1
4
|
require 'texplay'
|
5
|
+
require 'panda_canvas/canvas'
|
2
6
|
|
3
|
-
|
7
|
+
module PandaCanvas
|
4
8
|
|
5
|
-
|
6
|
-
# A list of +commands+ of the form +[:method, [*args]]+ is passed to be executed.
|
7
|
-
def initialize(width, height, commands)
|
8
|
-
super(width, height, false)
|
9
|
-
self.caption = 'Panda Canvas'
|
10
|
-
@image = TexPlay.create_image(self, width, height)
|
11
|
-
@commands = commands
|
12
|
-
end
|
9
|
+
class << self
|
13
10
|
|
14
|
-
|
15
|
-
def update
|
16
|
-
unless @commands.empty?
|
17
|
-
@commands.slice!(0...@commands.index(FLUSH_SIGNATURE)).each do |command|
|
18
|
-
@image.send command[0], *command[1]
|
19
|
-
end
|
20
|
-
@commands.shift
|
21
|
-
end
|
22
|
-
end
|
11
|
+
attr_reader :canvas
|
23
12
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
13
|
+
def draw(width=640, height=480, &block)
|
14
|
+
@canvas = Canvas.new(width, height, Fiber.new(&block))
|
15
|
+
@canvas.show
|
16
|
+
end
|
28
17
|
|
29
|
-
end #
|
18
|
+
end # class << self
|
30
19
|
|
31
|
-
|
32
|
-
__height__ = 480
|
33
|
-
__commands__ = []
|
34
|
-
IMAGE_METHODS = (Gosu::Image.public_instance_methods + [:flush]).freeze
|
35
|
-
FLUSH_SIGNATURE = [:flush, []].freeze
|
20
|
+
end # PandaCanvas
|
36
21
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
22
|
+
def method_missing(sym, *args)
|
23
|
+
found = false
|
24
|
+
if PandaCanvas.canvas
|
25
|
+
@panda_canvas_image ||= PandaCanvas.canvas.image
|
26
|
+
if @panda_canvas_image.respond_to? sym
|
27
|
+
pci = @panda_canvas_image
|
28
|
+
self.class.instance_eval do
|
29
|
+
define_method(sym) {|*args| pci.send sym, *args }
|
30
|
+
end
|
31
|
+
self.send sym, *args
|
32
|
+
found = true
|
43
33
|
end
|
44
34
|
end
|
45
|
-
|
46
|
-
|
47
|
-
at_exit do
|
48
|
-
__commands__ << FLUSH_SIGNATURE
|
49
|
-
PandaCanvas.new(__width__, __height__, __commands__).show if $!.nil?
|
35
|
+
super(sym, *args) unless found
|
50
36
|
end
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
7
|
+
- 2
|
8
8
|
- 0
|
9
|
-
version: 0.
|
9
|
+
version: 0.2.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Dimitry Solovyov
|
@@ -56,6 +56,7 @@ extensions: []
|
|
56
56
|
extra_rdoc_files: []
|
57
57
|
|
58
58
|
files:
|
59
|
+
- lib/panda_canvas/canvas.rb
|
59
60
|
- lib/panda_canvas/version.rb
|
60
61
|
- lib/panda_canvas.rb
|
61
62
|
- LICENSE
|