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,7 +119,11 @@ 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
state.win_fill_brush = gdip.SolidBrush(c._win_argb) 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)
def get_textcolor(self): def get_textcolor(self):
return self._state.textcolor return self._state.textcolor

View File

@ -7,21 +7,25 @@
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._red = red color.image = image
color._green = green if image:
color._blue = blue color.image = im._win_image
color._alpha = alpha else:
color._win_color = ( color._red = red
int(red * 255) | color._green = green
int(green * 255) << 8 | color._blue = blue
int(blue * 255) << 16) color._alpha = alpha
color._win_argb = ( color._win_color = (
int(blue * 255) | int(red * 255) |
int(green * 255) << 8 | int(green * 255) << 8 |
int(red * 255) << 16 | int(blue * 255) << 16)
int(alpha * 255) << 24) color._win_argb = (
int(blue * 255) |
int(green * 255) << 8 |
int(red * 255) << 16 |
int(alpha * 255) << 24)
return color return color
selection_forecolor = Color._from_win_color( selection_forecolor = Color._from_win_color(

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