]>
Commit | Line | Data |
---|---|---|
6ed100b4 RD |
1 | import wx |
2 | ||
3 | class TestPanel(wx.Panel): | |
4 | def __init__(self, *args, **kw): | |
5 | wx.Panel.__init__(self, *args, **kw) | |
6 | self.Bind(wx.EVT_PAINT, self.OnPaint) | |
7 | ||
8 | def OnPaint(self, evt): | |
9 | gc = wx.GraphicsContext.Create(wx.PaintDC(self)) | |
10 | ||
11 | pen = wx.Pen("navy", 2) | |
12 | gc.SetPen(pen) | |
13 | brush = wx.Brush((255,32,32,128)) | |
14 | gc.SetBrush(brush) | |
15 | gc.PushState() | |
16 | ||
17 | path = gc.CreatePath() | |
18 | path.MoveToPoint(50, 50) | |
19 | path.AddLineToPoint(25,25) | |
20 | path.AddLineToPoint(50,25) | |
21 | path.AddLineToPoint(50,50) | |
22 | path.CloseSubpath() | |
23 | ||
24 | gc.DrawPath(path) | |
25 | ||
26 | gc.Scale(2,2) | |
27 | gc.Translate(10,5) | |
28 | gc.DrawPath(path) | |
29 | ||
30 | gc.Translate(50,0) | |
31 | gc.FillPath(path) | |
32 | gc.Translate(0,5) | |
33 | gc.StrokePath(path) | |
34 | gc.Translate(0,5) | |
35 | ||
36 | brush = wx.Brush((32,32,255,128)) | |
37 | gc.SetBrush(brush) | |
38 | ||
39 | gc.FillPath(path) | |
40 | gc.Translate(50,0) | |
41 | gc.DrawPath(path) | |
42 | ||
43 | gc.PopState() | |
44 | ||
45 | points = [ (5.2, 5.9), | |
46 | (50, 50), | |
47 | (35, 50), | |
48 | (25,40), | |
49 | wx.Point2D(20.5,50.9), | |
50 | wx.Point2D(5,25), | |
51 | (5,6) | |
52 | ] | |
53 | ||
54 | gc.Translate(0, 150) | |
55 | gc.DrawLines(points) | |
56 | gc.Translate(75, 0) | |
57 | gc.StrokeLines(points) | |
58 | ||
59 | ||
60 | begin = [ (0,0), | |
61 | (0,10), | |
62 | (0,20), | |
63 | (0,30), | |
64 | (0,40), | |
65 | (0,50), | |
66 | ] | |
67 | ||
68 | end = [ (50,0), | |
69 | (50,10), | |
70 | (50,20), | |
71 | (50,30), | |
72 | (50,40), | |
73 | (50,50), | |
74 | ] | |
75 | ||
76 | # in a floating point coordinate system the center of the | |
77 | # pixel is actually at x+0.5, y+0.5, so with anti-aliasing | |
78 | # turned on we'll get a crisper line by positioning our line | |
79 | # segments at the 0.5 offset. For this test we'll just let | |
80 | # the GC do the translation for us. | |
81 | gc.Translate(0.5, 0.5) | |
82 | ||
83 | pen = wx.Pen("purple", 1) | |
84 | gc.SetPen(pen) | |
85 | ||
86 | gc.Translate(75, 0) | |
87 | gc.StrokeLineSegements(begin, end) | |
88 | ||
89 | gc.Translate(75, 0) | |
90 | gc.Scale(2,2) | |
91 | gc.StrokeLineSegements(begin, end) | |
92 | gc.DrawLines(points) | |
93 | ||
94 | del path | |
95 | ||
96 | ||
97 | app = wx.App(False) | |
98 | frm = wx.Frame(None) | |
99 | pnl = TestPanel(frm) | |
100 | frm.Show() | |
101 | app.MainLoop() |