wxPython: wxDC problem

Carole Valentin carole at autosim.no
Tue Apr 23 11:21:29 EDT 2002


Hello,

I have a road map drawn in a wxDC and some cars in the same wxDC.
When the cars are moving, I would like to redraw only them and not the
entire map.
So I don't want to change a part of the map, but I want to have an
independant wxDC
for my cars which are moving on the map.
Do you think that what I am asking for is possible?
How can I do that?
Does the wxDC::SetClippingRegion method create an independant wxDC?

Thank you very much,
Carole.


Here is a part of my code:
*******************

class MapWindow(wxWindow):


#-----------------------------------------------------------------------

    def __init__(self, parent, ID_MAP, pos=wxPoint(10,10),\
                 size=wxDefaultSize):

        EVT_PAINT(self, self.onPaint)


#-----------------------------------------------------------------------

    def onPaint(self, event):

        dc = wxPaintDC(self)
        self.drawMap(dc)


#-----------------------------------------------------------------------

    def drawMap(self, dc = None):

        dc.Clear()

        # I draw each lane of each road
        for i in range(len(self.myTerrain.roads)):
             for j in range(len(self.myTerrain.roads[i].lanes)):
                 for k in
range(len(self.myTerrain.road[i].lanes[j].lanePointsCentral) - 1):
                      line =
self.coefZoom*self.myTerrain.roads[i].lanes[j].width
                      dc.SetPen(wxPen(wxNamedColour('grey'), line ))
                      dc.DrawLine(
self.coefZoom*self.myTerrain.roads[i].lanes[j].lanePointsCentral[k].x
+
self.xGap ,\

self.coefZoom*self.myTerrain.roads[i].lanes[j].lanePointsCentral[k].y
+
self.yGap ,\

self.coefZoom*self.myTerrain.roads[i].lanes[j].lanePointsCentral[k+1].x
+ self.xGap ,\

self.coefZoom*self.myTerrain.roads[i].lanes[j].lanePointsCentral[k+1].y
+ self.yGap )


        # I draw only one car for the moment
        # carCorners = [ (x1,y1), (x2,y2), (x3,y3), (x4,y4) ]
        # carCorners = each corner of the rectangle which 
        # represents the car

        dc.SetPen(wxPen(wxNamedColour('BLACK'), 3))
        dc.DrawPolygon([
[self.coefZoom*self.myVehicle.carCorners[0][0]
+ self.xGap,\
                         
self.coefZoom*self.myVehicle.carCorners[0][1]
+ self.yGap],\
                        
[self.coefZoom*self.myVehicle.carCorners[1][0]
+ self.xGap,\
                         
self.coefZoom*self.myVehicle.carCorners[1][1]
+ self.yGap],\
                        
[self.coefZoom*self.myVehicle.carCorners[2][0]
+ self.xGap,\
                         
self.coefZoom*self.myVehicle.carCorners[2][1]
+ self.yGap],\
                        
[self.coefZoom*self.myVehicle.carCorners[3][0]
+ self.xGap,\
                         
self.coefZoom*self.myVehicle.carCorners[3][1]
+ self.yGap] ])



More information about the Python-list mailing list