]>
Commit | Line | Data |
---|---|---|
59780c72 RD |
1 | |
2 | import wx | |
3 | ||
4 | #---------------------------------------------------------------------- | |
5 | ||
6 | class TestPanel(wx.Panel): | |
7 | def __init__(self, parent, log): | |
8 | self.log = log | |
9 | wx.Panel.__init__(self, parent, -1) | |
59780c72 RD |
10 | self.Bind(wx.EVT_PAINT, self.OnPaint) |
11 | ||
41c4b3ef RD |
12 | txt = """\ |
13 | If this build of wxPython includes the new wx.GCDC class (which | |
14 | provides the wx.DC API on top of the new wx.GraphicsContext class) | |
15 | then these squares should be transparent. | |
16 | """ | |
2f72b58a RD |
17 | wx.StaticText(self, -1, txt, (20, 20)) |
18 | ||
19 | ||
59780c72 | 20 | def OnPaint(self, evt): |
41c4b3ef RD |
21 | pdc = wx.PaintDC(self) |
22 | try: | |
23 | dc = wx.GCDC(pdc) | |
24 | except: | |
25 | dc = pdc | |
59780c72 | 26 | rect = wx.Rect(0,0, 100, 100) |
2f72b58a RD |
27 | for RGB, pos in [((178, 34, 34), ( 50, 90)), |
28 | (( 35, 142, 35), (110, 150)), | |
29 | (( 0, 0, 139), (170, 90)) | |
59780c72 RD |
30 | ]: |
31 | r, g, b = RGB | |
32 | penclr = wx.Colour(r, g, b, wx.ALPHA_OPAQUE) | |
33 | brushclr = wx.Colour(r, g, b, 128) # half transparent | |
34 | dc.SetPen(wx.Pen(penclr)) | |
35 | dc.SetBrush(wx.Brush(brushclr)) | |
36 | rect.SetPosition(pos) | |
d1a7e73e | 37 | dc.DrawRoundedRectangleRect(rect, 8) |
cbfc9df6 RD |
38 | |
39 | # some additional testing stuff | |
40 | #dc.SetPen(wx.Pen(wx.Colour(0,0,255, 196))) | |
41 | #dc.SetBrush(wx.Brush(wx.Colour(0,0,255, 64))) | |
42 | #dc.DrawCircle(50, 275, 25) | |
43 | #dc.DrawEllipse(100, 275, 75, 50) | |
44 | ||
59780c72 RD |
45 | |
46 | #---------------------------------------------------------------------- | |
47 | ||
48 | def runTest(frame, nb, log): | |
49 | win = TestPanel(nb, log) | |
50 | return win | |
51 | ||
52 | #---------------------------------------------------------------------- | |
53 | ||
54 | ||
55 | ||
56 | overview = """<html><body> | |
57 | <h2><center>Alpha Drawing</center></h2> | |
58 | ||
51aad6d3 RD |
59 | The wx.GCDC class is a class that implemented the wx.DC API using the |
60 | new wx.GraphicsContext class, and so it supports anti-aliased drawing | |
61 | using pens and brushes, that can optionally also be drawn using an | |
62 | alpha transparency. (On the Mac all the DC classes are using this new | |
63 | implementation.) This is accomplished by enabling the wx.Colour class | |
64 | to have a fourth component for the alpha value, where 0 is fully | |
65 | transparent, and 255 is fully opaque. | |
2f72b58a | 66 | |
59780c72 RD |
67 | </body></html> |
68 | """ | |
69 | ||
70 | ||
71 | ||
72 | if __name__ == '__main__': | |
73 | import sys,os | |
74 | import run | |
75 | run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:]) | |
76 |