# HG changeset patch # User jwt@33b003aa-7bff-0310-803a-e67f0ece8222 # Date 1217984580 0 # Node ID d5658e6c34f5bcc39c9e3dbb611aa85bc460a664 # Parent ec653fde64d3413d725c0c9e0c9722e24a5ec0ae Added scrolling support the the editor client. diff -r ec653fde64d3 -r d5658e6c34f5 clients/editor/plugins/mapeditor.py --- a/clients/editor/plugins/mapeditor.py Tue Aug 05 17:37:49 2008 +0000 +++ b/clients/editor/plugins/mapeditor.py Wed Aug 06 01:03:00 2008 +0000 @@ -1,5 +1,4 @@ # MapEditor is a plugin for Fifedit. It allows for selection and visual editing of maps. -# MapEditor must be pumped (see pump). import math @@ -14,6 +13,9 @@ from pychan.manager import DEFAULT_STYLE DEFAULT_STYLE['default']['base_color'] = fife.Color(85,128,151) +SCROLL_TOLERANCE = 30 +SCROLL_SPEED = 1.0 + states = ('NOTHING_LOADED', 'VIEWING', 'INSERTING', 'REMOVING', 'MOVING') for s in states: globals()[s] = s @@ -147,6 +149,8 @@ self._altdown = False self._dragx = NOT_INITIALIZED self._dragy = NOT_INITIALIZED + self._scrollx = 0 + self._scrolly = 0 self._mapselector = MapSelection(self._selectLayer, self._selectObject) self._objectselector = None @@ -417,7 +421,30 @@ self._dragy = NOT_INITIALIZED def mouseMoved(self, evt): - pass + if self._camera: + screen_x = self._engine.getRenderBackend().getWidth() + screen_y = self._engine.getRenderBackend().getHeight() + ratio = float(screen_x) / screen_y + + mouse_x = evt.getX() + mouse_y = evt.getY() + + self._scrollx = 0 + self._scrolly = 0 + + if mouse_y <= SCROLL_TOLERANCE: + # up + self._scrolly = SCROLL_SPEED * ratio + if mouse_x >= screen_x - SCROLL_TOLERANCE: + # right + self._scrollx = -SCROLL_SPEED + if mouse_y >= screen_y - SCROLL_TOLERANCE: + # bottom + self._scrolly = -SCROLL_SPEED * ratio + if mouse_x <= SCROLL_TOLERANCE: + # left + self._scrollx = SCROLL_SPEED + def mouseEntered(self, evt): pass def mouseExited(self, evt): @@ -498,4 +525,6 @@ elif keyval in (fife.Key.LEFT_ALT, fife.Key.RIGHT_ALT): self._altdown = False - + def pump(self): + if self._scrollx != 0 or self._scrolly != 0: + self._moveCamera(self._scrollx * self._engine.getTimeManager().getTimeDelta(), self._scrolly * self._engine.getTimeManager().getTimeDelta()) diff -r ec653fde64d3 -r d5658e6c34f5 clients/editor/run.py --- a/clients/editor/run.py Tue Aug 05 17:37:49 2008 +0000 +++ b/clients/editor/run.py Wed Aug 06 01:03:00 2008 +0000 @@ -73,6 +73,7 @@ return EditorListener(self) def _pump(self): + self.mapedit.pump() if self.maploader.newMap: self.mapedit.editMap(self.maploader.newMap.getId()) self.importer.addDirs(self.maploader.newMap.importDirs)