Added image textures in Windows

This commit is contained in:
Skyler Lehmkuhl 2013-01-19 19:57:44 -05:00
parent 0b6ef387e9
commit 63c59d220e
4 changed files with 48 additions and 16 deletions

View File

@ -119,6 +119,10 @@ class Canvas(GCanvas):
def set_fillcolor(self, c): def set_fillcolor(self, c):
state = self._state state = self._state
state.fillcolor = c state.fillcolor = c
if self.fillcolor.image:
tb = gdip.TextureBrush(self.fillcolor.image)
state.win_fill_brush = tb
else:
state.win_fill_brush = gdip.SolidBrush(c._win_argb) state.win_fill_brush = gdip.SolidBrush(c._win_argb)
def get_textcolor(self): def get_textcolor(self):

View File

@ -7,8 +7,12 @@
import win32con as wc, win32api as api import win32con as wc, win32api as api
from GUI import Color from GUI import Color
def rgb(red, green, blue, alpha = 1.0): def rgb(red, green, blue, alpha = 1.0, image = False, im = ''):
color = Color() color = Color()
color.image = image
if image:
color.image = im._win_image
else:
color._red = red color._red = red
color._green = green color._green = green
color._blue = blue color._blue = blue

View File

@ -159,6 +159,21 @@ class SolidBrush(object):
#-------------------------------------------------------------------- #--------------------------------------------------------------------
class TextureBrush(object):
def __init__(self, image):
ptr = c_void_p()
wg.GdipCreateTexture(image.ptr, 4, byref(ptr))
self.ptr = ptr
def __del__(self, wg = wg):
wg.GdipDeleteBrush(self.ptr)
def __str__(self):
return "<TextureBrush>"
#--------------------------------------------------------------------
class Font(object): class Font(object):
def __init__(self, family, size, style): def __init__(self, family, size, style):

View File

@ -697,7 +697,16 @@ def import_to_stage(widget=None):
os.system("sips -s format png "+thefile+" --out "+svlgui.SECURETEMPDIR+"/"+".".join(thefile.split("/")[-1].split(".")[:-1])+".png") os.system("sips -s format png "+thefile+" --out "+svlgui.SECURETEMPDIR+"/"+".".join(thefile.split("/")[-1].split(".")[:-1])+".png")
elif "linux" in svlgui.PLATFORM: elif "linux" in svlgui.PLATFORM:
os.system("convert "+thefile+" "+svlgui.SECURETEMPDIR+"/"+".".join(thefile.split("/")[-1].split(".")[:-1])+".png") os.system("convert "+thefile+" "+svlgui.SECURETEMPDIR+"/"+".".join(thefile.split("/")[-1].split(".")[:-1])+".png")
thefile = svlgui.SECURETEMPDIR+"/"+".".join(thefile.split("/")[-1].split(".")[:-1])+".png" elif svlgui.PLATFORM=="win32":
from PIL import Image
im = Image.open(thefile)
# Use alpha channel if available (e.g. GIF)
transparency = im.info["transparency"] if 'transparency' in im.info else None
if transparency:
im.save(svlgui.SECURETEMPDIR+"\\"+".".join(thefile.split("\\")[-1].split(".")[:-1])+".png", transparency=transparency)
else:
im.save(svlgui.SECURETEMPDIR+"\\"+".".join(thefile.split("\\")[-1].split(".")[:-1])+".png")
thefile = svlgui.SECURETEMPDIR+svlgui.sep+".".join(thefile.split(svlgui.sep)[-1].split(".")[:-1])+".png"
im = box(100,100,200,200,svlgui.Color(thefile)) im = box(100,100,200,200,svlgui.Color(thefile))
im.onMouseDown = onMouseDownObj im.onMouseDown = onMouseDownObj
im.onMouseMove = onMouseMoveObj im.onMouseMove = onMouseMoveObj