diff --git a/pygwin/__init__.py b/pygwin/__init__.py index 0302483..58cbcde 100644 --- a/pygwin/__init__.py +++ b/pygwin/__init__.py @@ -9,5 +9,5 @@ from pygame.locals import * from pygwin.font import * from pygwin._win import * from pygwin._pg import pg -from pygwin.ui import * +import pygwin.ui as ui gamepad = _gp.gamepad(pg) diff --git a/pygwin/image.py b/pygwin/image.py index 77a0937..358b99f 100644 --- a/pygwin/image.py +++ b/pygwin/image.py @@ -1,11 +1,11 @@ from pygwin._pg import pg as _pg from pygwin.surface import surface as _surface -from PIL import Image as _image +from PIL import Image as _im import pickle as _p def load(path): if path.endswith('.gif'): - im = Image.open(path) + im = _im.open(path) surfs = [] for i in range(im.n_frames): im.seek(i) @@ -15,9 +15,8 @@ def load(path): surfs.append(surf) return surfs else: - image = _pg.image.load(path) - surf = _surface(image.get_size()) - surf._surface_orig = image + surf = _surface(_im.open(path).size) + surf.blit(_pg.image.load(path),(0,0)) return surf def save(surface, dest): @@ -27,16 +26,16 @@ def save(surface, dest): orig = surface._orig _pg.image.save_extended(orig, dest) -def toString(surface): - if type(surface) == _surface: +def toBytes(surface): + try: orig = surface._surface_orig - else: + except: orig = surface._orig - return _p.dumps([_pg.image.tostring(orig,"RGBA"),list(surface.size)],0) + return _p.dumps([_pg.image.tostring(orig,"RGBA"),list(surface.size)]) -def fromString(string): - string = _p.loads(string, encoding='latin1') +def fromBytes(string): + string = _p.loads(string) surf = _pg.image.fromstring(string[0],tuple(string[1]),"RGBA") surface = _surface(tuple(string[1])) - surface._surface_orig = surf + surface.blit(surf,(0,0)) return surface diff --git a/pygwin/surface.py b/pygwin/surface.py index b7dc1cc..1d766b5 100644 --- a/pygwin/surface.py +++ b/pygwin/surface.py @@ -35,13 +35,16 @@ class surface: self._orig.set_at((x,y),color) return self.copy() def blit(self, surf, xy): - if type(surf) != surface: + if type(surf) != surface and type(surf) != _pg.Surface: from pygwin.font import defaultFont as _df surf = _df.render(surf, 25, (0,0,0)) try: self._orig.blit(surf._surface_orig, xy) except: - self._orig.blit(surf._orig, xy) + try: + self._orig.blit(surf._orig, xy) + except: + self._orig.blit(surf, xy) return self.copy() def fill(self, color): self._orig.fill(color) @@ -50,8 +53,8 @@ class surface: self._orig = self._orig.subsurface((rect.x,rect.y,rect.w,rect.h)) self._size = self._orig.get_size() return self.copy() - def scale(self, rect): - self._orig = _pg.transform.scale(self._orig, (rect.w, rect.h)) + def scale(self, size): + self._orig = _pg.transform.scale(self._orig, size) self._size = self._orig.get_size() return self.copy() def rotate(self, angle): @@ -62,9 +65,9 @@ class surface: self._orig = _pg.transform.flip(self._orig, x, y) return self.copy() def blur(self, amt): - if amt < 0: - return self.copy() - scale = (int(self._orig.get_width()*(amt+1)),int(self._orig.get_height()[1]*(amt+1))) + if amt < 0:return self.copy() + scale = (int(self._orig.get_width()*(amt+1)), + int(self._orig.get_height()*(amt+1))) size = self._orig.get_size() self._orig = _pg.transform.smoothscale(self._orig,scale) self._orig = _pg.transform.smoothscale(self._orig,size)