2004-03-10 06:52:36 +00:00
|
|
|
|
|
|
|
import wx # This module uses the new wx namespace
|
|
|
|
from Main import opj
|
|
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
2004-08-26 03:03:16 +00:00
|
|
|
msg = "Some text will appear mixed in the image's shadow..."
|
2004-03-10 06:52:36 +00:00
|
|
|
|
|
|
|
class TestPanel(wx.Panel):
|
|
|
|
def __init__(self, parent, log):
|
|
|
|
self.log = log
|
|
|
|
wx.Panel.__init__(self, parent, -1)
|
|
|
|
|
|
|
|
self.Bind(wx.EVT_PAINT, self.OnPaint)
|
|
|
|
|
|
|
|
|
|
|
|
def OnPaint(self, evt):
|
|
|
|
dc = wx.PaintDC(self)
|
|
|
|
dc.SetBackground(wx.Brush("WHITE"))
|
|
|
|
dc.Clear()
|
|
|
|
|
|
|
|
dc.SetFont(wx.Font(16, wx.SWISS, wx.NORMAL, wx.BOLD, True))
|
2004-08-26 03:03:16 +00:00
|
|
|
dc.DrawText("Bitmap alpha blending (on all ports but gtk+ 1.2)",
|
2004-05-02 02:41:33 +00:00
|
|
|
25,25)
|
|
|
|
|
2004-03-10 06:52:36 +00:00
|
|
|
bmp = wx.Bitmap(opj('bitmaps/toucan.png'))
|
2004-08-26 03:03:16 +00:00
|
|
|
if "gtk1" in wx.PlatformInfo:
|
|
|
|
# Try to make up for lack of alpha support in wxGTK (gtk+
|
|
|
|
# 1.2) by converting the alpha blending into a
|
|
|
|
# transparency mask.
|
|
|
|
|
|
|
|
# first convert to a wx.Image
|
2004-08-25 21:57:16 +00:00
|
|
|
img = bmp.ConvertToImage()
|
2004-08-26 03:03:16 +00:00
|
|
|
|
|
|
|
# Then convert the alpha channel to a mask, specifying the
|
|
|
|
# threshold below which alpha will be made fully
|
|
|
|
# transparent
|
|
|
|
img.ConvertAlphaToMask(220)
|
|
|
|
|
|
|
|
# convert back to a wx.Bitmap
|
2004-08-25 21:57:16 +00:00
|
|
|
bmp = img.ConvertToBitmap()
|
2004-08-26 03:03:16 +00:00
|
|
|
|
2004-03-10 07:01:52 +00:00
|
|
|
|
2004-05-02 02:41:33 +00:00
|
|
|
dc.DrawBitmap(bmp, 25,100, True)
|
2004-03-10 06:52:36 +00:00
|
|
|
|
|
|
|
dc.SetFont(self.GetFont())
|
|
|
|
y = 75
|
|
|
|
for line in range(10):
|
|
|
|
y += dc.GetCharHeight() + 5
|
2004-05-02 02:41:33 +00:00
|
|
|
dc.DrawText(msg, 200, y)
|
|
|
|
dc.DrawBitmap(bmp, 250,100, True)
|
2004-03-10 06:52:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
|
|
|
def runTest(frame, nb, log):
|
|
|
|
win = TestPanel(nb, log)
|
|
|
|
return win
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
overview = """<html><body>
|
|
|
|
<h2><center>Images with Alpha</center></h2>
|
|
|
|
|
2004-03-10 06:56:57 +00:00
|
|
|
wxMSW and wxMac now support alpha channels of supported image
|
2004-03-15 22:57:03 +00:00
|
|
|
types, and will properly blend that channel when drawing a
|
2004-03-10 06:52:36 +00:00
|
|
|
bitmap. It is not supported yet on wxGTK, (if you would like to
|
|
|
|
change that please submit a patch!)
|
|
|
|
|
2004-03-10 07:01:52 +00:00
|
|
|
<p>On wxGTK this demo turns the alpha channel into a 1-bit mask, so
|
|
|
|
yes, it looks like crap. Please help us fix it!
|
|
|
|
|
2004-03-10 06:52:36 +00:00
|
|
|
</body></html>
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
import sys,os
|
|
|
|
import run
|
|
|
|
run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
|
|
|
|
|