1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 """
23 Module for drawing the map to the screen
24 """
25
26 __docformat__ = "epytext"
27
28 import math
29 import logging
30 import cairo
31 import gtk
32
33 import dialogs
34 import mapcontroller
35 import tilegrid
36 import editortools
37
38
39 -class MapGrid(tilegrid.TileGrid, mapcontroller.MapListener):
40 """ Handles drawing the map to the screen """
41
42
43
44 - def __init__(self, controller, statusBar):
45 """
46 @type controller: MapController
47 @param controller: the map controller
48 @type statusBar: gtk.StatusBar
49 @param statusBar: status bar to update
50 """
51 mapcontroller.MapListener.__init__(self, controller)
52 controller.setThumbnailSource(self)
53
54
55 self.selectedShape = None
56
57
58 self.layers = []
59
60
61 self.__statusBar = statusBar
62 self.__contextID = self.__statusBar.get_context_id("Map Grid")
63 self.__lastMessage = -1
64
65 pixelWidth = controller.mapWidth() * controller.mapTileSize()
66 pixelHeight = controller.mapHeight() * controller.mapTileSize()
67 tilegrid.TileGrid.__init__(self, pixelWidth, pixelHeight,
68 controller.mapTileSize())
69 self.layers = self.getController().drawLayers()
70 self.redrawBuffer()
71
72 self.addTool(editortools.TileDrawTool(controller),
73 editortools.TILE_DRAW_ID)
74 self.addTool(editortools.TileDeleteTool(controller),
75 editortools.TILE_DELETE_ID)
76 self.addTool(editortools.PhysicsSelectTool(controller),
77 editortools.PHYSICS_SELECT_ID)
78 self.addTool(editortools.CircleDrawTool(controller),
79 editortools.CIRCLE_DRAW_ID)
80 self.addTool(editortools.PolygonDrawTool(controller),
81 editortools.POLYGON_DRAW_ID)
82 self.addTool(editortools.LightDrawTool(controller),
83 editortools.LIGHT_DRAW_ID)
84
91
92 - def setSize(self, width, height, xOffset, yOffset):
93 tilegrid.TileGrid.setSize(self, width, height, 0, 0)
94 newLayers = []
95 for oldLayer in self.layers:
96 newLayer = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
97 context = cairo.Context(newLayer)
98
99 context.set_source_surface(oldLayer, 0, 0)
100
101 context.rectangle(xOffset if xOffset > 0 else 0,
102 yOffset if yOffset > 0 else 0,
103 oldLayer.get_width(),
104 oldLayer.get_height())
105
106 context.fill()
107 newLayers.append(newLayer)
108 self.layers = newLayers
109
114
115
123
124
125
126
127
131
139
148
153
160
162 ts = self.getController().mapTileSize()
163 context = cairo.Context(self.layers[z])
164 context.set_source_surface(surface, x * ts, y * ts)
165 context.rectangle(x * ts, y * ts, ts, ts)
166 context.set_operator(cairo.OPERATOR_SOURCE)
167 context.fill()
168 self.redrawBuffer()
169 self.queue_draw()
170
172 ts = self.getController().mapTileSize()
173 context = cairo.Context(self.layers[z])
174 context.set_source_rgba(0.0, 0.0, 0.0, 0.0)
175 context.rectangle(x * ts, y * ts, ts, ts)
176 context.set_operator(cairo.OPERATOR_SOURCE)
177 context.fill()
178 self.redrawBuffer()
179 self.queue_draw()
180
184
185
186
187
188