2004-03-10 01:52:36 -05:00
|
|
|
|
|
|
|
import wx # This module uses the new wx namespace
|
|
|
|
from Main import opj
|
|
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
2004-08-25 23:03:16 -04:00
|
|
|
msg = "Some text will appear mixed in the image's shadow..."
|
2004-03-10 01:52:36 -05: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-25 23:03:16 -04:00
|
|
|
dc.DrawText("Bitmap alpha blending (on all ports but gtk+ 1.2)",
|
2004-05-01 22:41:33 -04:00
|
|
|
25,25)
|
|
|
|
|
2004-03-10 01:52:36 -05:00
|
|
|
bmp = wx.Bitmap(opj('bitmaps/toucan.png'))
|
2004-08-25 23:03:16 -04: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 17:57:16 -04:00
|
|
|
img = bmp.ConvertToImage()
|
2004-08-25 23:03:16 -04: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 17:57:16 -04:00
|
|
|
bmp = img.ConvertToBitmap()
|
2004-08-25 23:03:16 -04:00
|
|
|
|
2004-03-10 02:01:52 -05:00
|
|
|
|
2004-05-01 22:41:33 -04:00
|
|
|
dc.DrawBitmap(bmp, 25,100, True)
|
2004-03-10 01:52:36 -05:00
|
|
|
|
|
|
|
dc.SetFont(self.GetFont())
|
|
|
|
y = 75
|
|
|
|
for line in range(10):
|
|
|
|
y += dc.GetCharHeight() + 5
|
2004-05-01 22:41:33 -04:00
|
|
|
dc.DrawText(msg, 200, y)
|
|
|
|
dc.DrawBitmap(bmp, 250,100, True)
|
2004-03-10 01:52:36 -05: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 01:56:57 -05:00
|
|
|
wxMSW and wxMac now support alpha channels of supported image
|
2004-03-15 17:57:03 -05:00
|
|
|
types, and will properly blend that channel when drawing a
|
2004-03-10 01:52:36 -05:00
|
|
|
bitmap. It is not supported yet on wxGTK, (if you would like to
|
|
|
|
change that please submit a patch!)
|
|
|
|
|
2004-03-10 02:01:52 -05: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 01:52:36 -05:00
|
|
|
</body></html>
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
import sys,os
|
|
|
|
import run
|
|
|
|
run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
|
|
|
|
|