Add files via upload

This commit is contained in:
themixray 2021-11-03 20:41:30 +03:00 committed by GitHub
parent 6512fcf347
commit 47419536c1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 20 deletions

View file

@ -9,5 +9,5 @@ from pygame.locals import *
from pygwin.font import * from pygwin.font import *
from pygwin._win import * from pygwin._win import *
from pygwin._pg import pg from pygwin._pg import pg
from pygwin.ui import * import pygwin.ui as ui
gamepad = _gp.gamepad(pg) gamepad = _gp.gamepad(pg)

View file

@ -1,11 +1,11 @@
from pygwin._pg import pg as _pg from pygwin._pg import pg as _pg
from pygwin.surface import surface as _surface from pygwin.surface import surface as _surface
from PIL import Image as _image from PIL import Image as _im
import pickle as _p import pickle as _p
def load(path): def load(path):
if path.endswith('.gif'): if path.endswith('.gif'):
im = Image.open(path) im = _im.open(path)
surfs = [] surfs = []
for i in range(im.n_frames): for i in range(im.n_frames):
im.seek(i) im.seek(i)
@ -15,9 +15,8 @@ def load(path):
surfs.append(surf) surfs.append(surf)
return surfs return surfs
else: else:
image = _pg.image.load(path) surf = _surface(_im.open(path).size)
surf = _surface(image.get_size()) surf.blit(_pg.image.load(path),(0,0))
surf._surface_orig = image
return surf return surf
def save(surface, dest): def save(surface, dest):
@ -27,16 +26,16 @@ def save(surface, dest):
orig = surface._orig orig = surface._orig
_pg.image.save_extended(orig, dest) _pg.image.save_extended(orig, dest)
def toString(surface): def toBytes(surface):
if type(surface) == _surface: try:
orig = surface._surface_orig orig = surface._surface_orig
else: except:
orig = surface._orig 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): def fromBytes(string):
string = _p.loads(string, encoding='latin1') string = _p.loads(string)
surf = _pg.image.fromstring(string[0],tuple(string[1]),"RGBA") surf = _pg.image.fromstring(string[0],tuple(string[1]),"RGBA")
surface = _surface(tuple(string[1])) surface = _surface(tuple(string[1]))
surface._surface_orig = surf surface.blit(surf,(0,0))
return surface return surface

View file

@ -35,13 +35,16 @@ class surface:
self._orig.set_at((x,y),color) self._orig.set_at((x,y),color)
return self.copy() return self.copy()
def blit(self, surf, xy): 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 from pygwin.font import defaultFont as _df
surf = _df.render(surf, 25, (0,0,0)) surf = _df.render(surf, 25, (0,0,0))
try: try:
self._orig.blit(surf._surface_orig, xy) self._orig.blit(surf._surface_orig, xy)
except: except:
try:
self._orig.blit(surf._orig, xy) self._orig.blit(surf._orig, xy)
except:
self._orig.blit(surf, xy)
return self.copy() return self.copy()
def fill(self, color): def fill(self, color):
self._orig.fill(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._orig = self._orig.subsurface((rect.x,rect.y,rect.w,rect.h))
self._size = self._orig.get_size() self._size = self._orig.get_size()
return self.copy() return self.copy()
def scale(self, rect): def scale(self, size):
self._orig = _pg.transform.scale(self._orig, (rect.w, rect.h)) self._orig = _pg.transform.scale(self._orig, size)
self._size = self._orig.get_size() self._size = self._orig.get_size()
return self.copy() return self.copy()
def rotate(self, angle): def rotate(self, angle):
@ -62,9 +65,9 @@ class surface:
self._orig = _pg.transform.flip(self._orig, x, y) self._orig = _pg.transform.flip(self._orig, x, y)
return self.copy() return self.copy()
def blur(self, amt): def blur(self, amt):
if amt < 0: if amt < 0:return self.copy()
return self.copy() scale = (int(self._orig.get_width()*(amt+1)),
scale = (int(self._orig.get_width()*(amt+1)),int(self._orig.get_height()[1]*(amt+1))) int(self._orig.get_height()*(amt+1)))
size = self._orig.get_size() size = self._orig.get_size()
self._orig = _pg.transform.smoothscale(self._orig,scale) self._orig = _pg.transform.smoothscale(self._orig,scale)
self._orig = _pg.transform.smoothscale(self._orig,size) self._orig = _pg.transform.smoothscale(self._orig,size)