From 1462e3cc7e5f377eaee349c18e53f62e2e11eb8a Mon Sep 17 00:00:00 2001 From: Jon Dowland Date: Tue, 29 Jan 2008 21:10:18 +0000 Subject: [PATCH] compose the texture in memory and set the displayed image to it --- tools/cleanroom/tmp_cleanui.py | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/tools/cleanroom/tmp_cleanui.py b/tools/cleanroom/tmp_cleanui.py index d8e1578f..1f41c26b 100644 --- a/tools/cleanroom/tmp_cleanui.py +++ b/tools/cleanroom/tmp_cleanui.py @@ -5,10 +5,10 @@ import gtk import gtk.glade class Patch: - def __init__(self, n,w,h): + def __init__(self, n,x,y): self.name = n - self.width = w - self.height =h + self.yoff = x + self.xoff =y class HellowWorldGTK: """This is an Hello World GTK application""" @@ -24,22 +24,41 @@ class HellowWorldGTK: self.wTree = gtk.glade.XML(self.gladefile,"window1") self.image1 = self.wTree.get_widget("orig_texture") - # parse the example texture + # parse the example texture, fetch the width,height; + # create Patch objects and stuff them into a list patches = [] width,height = 0,0 for line in self.example_texture.split("\n"): if len(line) > 0: + # texture definition (we hope) if line[0] != '*': name,width,height = line.split() + # patch list (we hope) else: - junk,name,width,height = line.split() - patches.append(Patch(name,width,height)) + junk,name,y,x= line.split() + patches.append(Patch(name,int(x),int(y))) + # read the patches into pixbufs + # a horrid hack to get them client->server side for patch in patches: self.image1.set_from_file(patch.name.lower() + ".gif") patch.pixbuf = self.image1.get_pixbuf() - self.image1.set_from_file("comp02_1.gif") + texbuf = gtk.gdk.Pixbuf( + patches[0].pixbuf.get_colorspace(), + patches[0].pixbuf.get_has_alpha(), + patches[0].pixbuf.get_bits_per_sample(), + int(width), + int(height)) + + # copy each patch into the texture pixbuf + for patch in patches: + patch.pixbuf.copy_area(0,0, + patch.pixbuf.get_width(), + patch.pixbuf.get_height(), + texbuf, patch.xoff, patch.yoff) + + self.image1.set_from_pixbuf(texbuf) pixbuf = self.image1.get_pixbuf() if pixbuf: scale = 3