diff --git a/GUI/Win32/Canvas.py b/GUI/Win32/Canvas.py index ecdba0b..d70c65a 100644 --- a/GUI/Win32/Canvas.py +++ b/GUI/Win32/Canvas.py @@ -119,7 +119,11 @@ class Canvas(GCanvas): def set_fillcolor(self, c): state = self._state 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): return self._state.textcolor diff --git a/GUI/Win32/Colors.py b/GUI/Win32/Colors.py index 0adabb6..c0fbdca 100644 --- a/GUI/Win32/Colors.py +++ b/GUI/Win32/Colors.py @@ -7,21 +7,25 @@ import win32con as wc, win32api as api 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._red = red - color._green = green - color._blue = blue - color._alpha = alpha - color._win_color = ( - int(red * 255) | - int(green * 255) << 8 | - int(blue * 255) << 16) - color._win_argb = ( - int(blue * 255) | - int(green * 255) << 8 | - int(red * 255) << 16 | - int(alpha * 255) << 24) + color.image = image + if image: + color.image = im._win_image + else: + color._red = red + color._green = green + color._blue = blue + color._alpha = alpha + color._win_color = ( + int(red * 255) | + int(green * 255) << 8 | + int(blue * 255) << 16) + color._win_argb = ( + int(blue * 255) | + int(green * 255) << 8 | + int(red * 255) << 16 | + int(alpha * 255) << 24) return color selection_forecolor = Color._from_win_color( diff --git a/GUI/Win32/GDIPlus.py b/GUI/Win32/GDIPlus.py index 788bfa7..e2ac0ee 100644 --- a/GUI/Win32/GDIPlus.py +++ b/GUI/Win32/GDIPlus.py @@ -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 "" + +#-------------------------------------------------------------------- + class Font(object): def __init__(self, family, size, style): diff --git a/lightningbeam.py b/lightningbeam.py index f38e545..3cdf2f7 100755 --- a/lightningbeam.py +++ b/lightningbeam.py @@ -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") elif "linux" in svlgui.PLATFORM: 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.onMouseDown = onMouseDownObj im.onMouseMove = onMouseMoveObj