Beginnings of a simple scene API. Inspired opened-hand's Clutter
This commit is contained in:
parent
2aa23cfa42
commit
a02313d85a
BIN
examples/scene/activity1.png
Normal file
BIN
examples/scene/activity1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.3 KiB |
BIN
examples/scene/activity2.png
Normal file
BIN
examples/scene/activity2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.5 KiB |
BIN
examples/scene/activity3.png
Normal file
BIN
examples/scene/activity3.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.1 KiB |
BIN
examples/scene/activity4.png
Normal file
BIN
examples/scene/activity4.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.7 KiB |
BIN
examples/scene/activity5.png
Normal file
BIN
examples/scene/activity5.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.4 KiB |
BIN
examples/scene/background.png
Normal file
BIN
examples/scene/background.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 69 KiB |
39
examples/scene/scene.py
Executable file
39
examples/scene/scene.py
Executable file
@ -0,0 +1,39 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
import pygtk
|
||||||
|
pygtk.require('2.0')
|
||||||
|
import gtk
|
||||||
|
|
||||||
|
from sugar.scene.Stage import Stage
|
||||||
|
from sugar.scene.Group import Group
|
||||||
|
from sugar.scene.PixbufActor import PixbufActor
|
||||||
|
|
||||||
|
def drawing_area_expose_cb(widget, event, stage):
|
||||||
|
stage.render(widget.window)
|
||||||
|
|
||||||
|
stage = Stage()
|
||||||
|
|
||||||
|
pixbuf = gtk.gdk.pixbuf_new_from_file('background.png')
|
||||||
|
stage.add(PixbufActor(pixbuf))
|
||||||
|
|
||||||
|
icons_group = Group()
|
||||||
|
|
||||||
|
i = 1
|
||||||
|
while i <= 5:
|
||||||
|
pixbuf = gtk.gdk.pixbuf_new_from_file('activity%d.png' % i)
|
||||||
|
icons_group.add(PixbufActor(pixbuf))
|
||||||
|
i += 1
|
||||||
|
|
||||||
|
stage.add(icons_group)
|
||||||
|
|
||||||
|
window = gtk.Window()
|
||||||
|
window.set_default_size(640, 480)
|
||||||
|
|
||||||
|
drawing_area = gtk.DrawingArea()
|
||||||
|
drawing_area.connect('expose_event', drawing_area_expose_cb, stage)
|
||||||
|
window.add(drawing_area)
|
||||||
|
drawing_area.show()
|
||||||
|
|
||||||
|
window.show()
|
||||||
|
|
||||||
|
gtk.main()
|
17
sugar/scene/Actor.py
Normal file
17
sugar/scene/Actor.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
class Actor:
|
||||||
|
def __init__(self):
|
||||||
|
self._x = 0
|
||||||
|
self._y = 0
|
||||||
|
self._width = -1
|
||||||
|
self._height = -1
|
||||||
|
|
||||||
|
def set_position(self, x, y):
|
||||||
|
self._x = x
|
||||||
|
self._y = y
|
||||||
|
|
||||||
|
def set_size(self, width, height):
|
||||||
|
self._width = width
|
||||||
|
self._height = height
|
||||||
|
|
||||||
|
def render(self, window):
|
||||||
|
pass
|
15
sugar/scene/Group.py
Normal file
15
sugar/scene/Group.py
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
from sugar.scene.Actor import Actor
|
||||||
|
|
||||||
|
class Group(Actor):
|
||||||
|
def __init__(self):
|
||||||
|
self._actors = []
|
||||||
|
|
||||||
|
def add(self, actor):
|
||||||
|
self._actors.append(actor)
|
||||||
|
|
||||||
|
def remove(self, actor):
|
||||||
|
self._actors.remove(actor)
|
||||||
|
|
||||||
|
def render(self, drawable):
|
||||||
|
for actor in self._actors:
|
||||||
|
actor.render(drawable)
|
13
sugar/scene/PixbufActor.py
Normal file
13
sugar/scene/PixbufActor.py
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import gtk
|
||||||
|
|
||||||
|
from sugar.scene.Actor import Actor
|
||||||
|
|
||||||
|
class PixbufActor(Actor):
|
||||||
|
def __init__(self, pixbuf):
|
||||||
|
Actor.__init__(self)
|
||||||
|
|
||||||
|
self._pixbuf = pixbuf
|
||||||
|
|
||||||
|
def render(self, drawable):
|
||||||
|
gc = gtk.gdk.GC(drawable)
|
||||||
|
drawable.draw_pixbuf(gc, self._pixbuf, 0, 0, self._x, self._y)
|
5
sugar/scene/Stage.py
Normal file
5
sugar/scene/Stage.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
from sugar.scene.Group import Group
|
||||||
|
|
||||||
|
class Stage(Group):
|
||||||
|
def __init__(self):
|
||||||
|
Group.__init__(self)
|
0
sugar/scene/__init__.py
Normal file
0
sugar/scene/__init__.py
Normal file
Loading…
Reference in New Issue
Block a user