]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/wxOGL.py
added wxWindows shared library to link of OpenGL wxWindows shared library
[wxWidgets.git] / wxPython / demo / wxOGL.py
CommitLineData
e91a9dfc
RD
1
2from wxPython.wx import *
3from wxPython.ogl import *
4
96bfd053
RD
5import images
6
e91a9dfc
RD
7#----------------------------------------------------------------------
8# This creates some pens and brushes that the OGL library uses.
9
10wxOGLInitialize()
11
12#----------------------------------------------------------------------
13
14class DiamondShape(wxPolygonShape):
15 def __init__(self, w=0.0, h=0.0):
16 wxPolygonShape.__init__(self)
17 if w == 0.0:
18 w = 60.0
19 if h == 0.0:
20 h = 60.0
21
22 ## Either wxRealPoints or 2-tuples of floats works.
23
24 #points = [ wxRealPoint(0.0, -h/2.0),
25 # wxRealPoint(w/2.0, 0.0),
26 # wxRealPoint(0.0, h/2.0),
27 # wxRealPoint(-w/2.0, 0.0),
28 # ]
29 points = [ (0.0, -h/2.0),
30 (w/2.0, 0.0),
31 (0.0, h/2.0),
32 (-w/2.0, 0.0),
33 ]
34
35 self.Create(points)
36
37
38#----------------------------------------------------------------------
39
40class RoundedRectangleShape(wxRectangleShape):
41 def __init__(self, w=0.0, h=0.0):
42 wxRectangleShape.__init__(self, w, h)
43 self.SetCornerRadius(-0.3)
44
45
46#----------------------------------------------------------------------
47
48class MyEvtHandler(wxShapeEvtHandler):
49 def __init__(self, log, frame):
50 wxShapeEvtHandler.__init__(self)
51 self.log = log
52 self.statbarFrame = frame
53
e91a9dfc
RD
54 def UpdateStatusBar(self, shape):
55 x,y = shape.GetX(), shape.GetY()
56 width, height = shape.GetBoundingBoxMax()
57 self.statbarFrame.SetStatusText("Pos: (%d,%d) Size: (%d, %d)" %
58 (x, y, width, height))
59
60
61 def OnLeftClick(self, x, y, keys = 0, attachment = 0):
62 shape = self.GetShape()
63 canvas = shape.GetCanvas()
64 dc = wxClientDC(canvas)
65 canvas.PrepareDC(dc)
66
67 if shape.Selected():
68 shape.Select(false, dc)
69 canvas.Redraw(dc)
70 else:
71 redraw = false
72 shapeList = canvas.GetDiagram().GetShapeList()
73 toUnselect = []
74 for s in shapeList:
75 if s.Selected():
76 # If we unselect it now then some of the objects in
77 # shapeList will become invalid (the control points are
78 # shapes too!) and bad things will happen...
79 toUnselect.append(s)
80
81 shape.Select(true, dc)
82
83 if toUnselect:
84 for s in toUnselect:
85 s.Select(false, dc)
86 canvas.Redraw(dc)
87
88 self.UpdateStatusBar(shape)
89
90
91 def OnEndDragLeft(self, x, y, keys = 0, attachment = 0):
92 shape = self.GetShape()
93 self.base_OnEndDragLeft(x, y, keys, attachment)
94 if not shape.Selected():
95 self.OnLeftClick(x, y, keys, attachment)
96 self.UpdateStatusBar(shape)
97
98
99 def OnSize(self, x, y):
100 self.base_OnSize(x, y)
101 self.UpdateStatusBar(self.GetShape())
102
103
104# def OnMovePost(self, dc, x, y, oldX, oldY, display):
105# self.base_OnMovePost(dc, x, y, oldX, oldY, display)
106# self.UpdateStatusBar(self.GetShape())
107
108
109 def OnRightClick(self, *dontcare):
110 self.log.WriteText("%s\n" % self.GetShape())
111
112
113#----------------------------------------------------------------------
114
115class TestWindow(wxShapeCanvas):
116 def __init__(self, parent, log, frame):
117 wxShapeCanvas.__init__(self, parent)
118
f6bcfd97
BP
119 maxWidth = 1000
120 maxHeight = 1000
121 self.SetScrollbars(20, 20, maxWidth/20, maxHeight/20)
122
e91a9dfc
RD
123 self.log = log
124 self.frame = frame
125 self.SetBackgroundColour(wxWHITE)
126 self.diagram = wxDiagram()
127 self.SetDiagram(self.diagram)
128 self.diagram.SetCanvas(self)
129 self.shapes = []
f3d9dc1d 130 self.save_gdi = []
e91a9dfc 131
2f90df85
RD
132 rRectBrush = wxBrush(wxNamedColour("MEDIUM TURQUOISE"), wxSOLID)
133
134 self.MyAddShape(wxCircleShape(80), 100, 100, wxPen(wxBLUE, 3), wxGREEN_BRUSH, "Circle")
135 self.MyAddShape(wxRectangleShape(85, 50), 305, 60, wxBLACK_PEN, wxLIGHT_GREY_BRUSH, "Rectangle")
136 self.MyAddShape(DiamondShape(90, 90), 345, 235, wxPen(wxBLUE, 3, wxDOT), wxRED_BRUSH, "Polygon")
137 self.MyAddShape(RoundedRectangleShape(95,70), 140, 255, wxPen(wxRED, 1), rRectBrush, "Rounded Rect")
e91a9dfc 138
96bfd053 139 bmp = images.getTest2Bitmap()
f3d9dc1d
RD
140 mask = wxMaskColour(bmp, wxBLUE)
141 bmp.SetMask(mask)
f3d9dc1d
RD
142
143 s = wxBitmapShape()
144 s.SetBitmap(bmp)
145 self.MyAddShape(s, 225, 150, None, None, "Bitmap")
146
e91a9dfc
RD
147 dc = wxClientDC(self)
148 self.PrepareDC(dc)
149 for x in range(len(self.shapes)):
150 fromShape = self.shapes[x]
151 if x+1 == len(self.shapes):
152 toShape = self.shapes[0]
153 else:
154 toShape = self.shapes[x+1]
155 line = wxLineShape()
156 line.SetCanvas(self)
157 line.SetPen(wxBLACK_PEN)
158 line.SetBrush(wxBLACK_BRUSH)
159 line.AddArrow(ARROW_ARROW)
160 line.MakeLineControlPoints(2)
161 fromShape.AddLine(line, toShape)
162 self.diagram.AddShape(line)
163 line.Show(true)
164
165 # for some reason, the shapes have to be moved for the line to show up...
166 fromShape.Move(dc, fromShape.GetX(), fromShape.GetY())
167
168
169
2f90df85 170 def MyAddShape(self, shape, x, y, pen, brush, text):
f3d9dc1d 171 shape.SetDraggable(true, true)
e91a9dfc
RD
172 shape.SetCanvas(self)
173 shape.SetX(x)
174 shape.SetY(y)
f3d9dc1d
RD
175 if pen: shape.SetPen(pen)
176 if brush: shape.SetBrush(brush)
177 if text: shape.AddText(text)
e91a9dfc
RD
178 #shape.SetShadowMode(SHADOW_RIGHT)
179 self.diagram.AddShape(shape)
180 shape.Show(true)
181
182 evthandler = MyEvtHandler(self.log, self.frame)
183 evthandler.SetShape(shape)
184 evthandler.SetPreviousHandler(shape.GetEventHandler())
185 shape.SetEventHandler(evthandler)
186
187 self.shapes.append(shape)
188
189
f3d9dc1d 190
e91a9dfc
RD
191 def __del__(self):
192 for shape in self.diagram.GetShapeList():
193 if shape.GetParent() == None:
194 shape.SetCanvas(None)
195 shape.Destroy()
856e03b7 196 self.diagram.Destroy()
e91a9dfc
RD
197
198
199#----------------------------------------------------------------------
200
201def runTest(frame, nb, log):
202 win = TestWindow(nb, log, frame)
203 return win
204
205#----------------------------------------------------------------------
206
207class __Cleanup:
208 cleanup = wxOGLCleanUp
209 def __del__(self):
210 self.cleanup()
211
212# when this module gets cleaned up then wxOGLCleanUp() will get called
213__cu = __Cleanup()
214
215
216
217
218
219
220
221
222overview = """\
223The Object Graphics Library is a library supporting the creation and
224manipulation of simple and complex graphic images on a canvas.
225
226"""
227
228