Mercurial > fife-parpg
comparison clients/editor/plugins/mapeditor.py @ 124:d5658e6c34f5
Added scrolling support the the editor client.
author | jwt@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Wed, 06 Aug 2008 01:03:00 +0000 |
parents | c94c76346027 |
children | ade070598fd1 |
comparison
equal
deleted
inserted
replaced
123:ec653fde64d3 | 124:d5658e6c34f5 |
---|---|
1 # MapEditor is a plugin for Fifedit. It allows for selection and visual editing of maps. | 1 # MapEditor is a plugin for Fifedit. It allows for selection and visual editing of maps. |
2 # MapEditor must be pumped (see pump). | |
3 | 2 |
4 import math | 3 import math |
5 | 4 |
6 import fife | 5 import fife |
7 import plugin | 6 import plugin |
11 from selection import Selection, ClickSelection | 10 from selection import Selection, ClickSelection |
12 from plugins.objectselector import ObjectSelector | 11 from plugins.objectselector import ObjectSelector |
13 | 12 |
14 from pychan.manager import DEFAULT_STYLE | 13 from pychan.manager import DEFAULT_STYLE |
15 DEFAULT_STYLE['default']['base_color'] = fife.Color(85,128,151) | 14 DEFAULT_STYLE['default']['base_color'] = fife.Color(85,128,151) |
15 | |
16 SCROLL_TOLERANCE = 30 | |
17 SCROLL_SPEED = 1.0 | |
16 | 18 |
17 states = ('NOTHING_LOADED', 'VIEWING', 'INSERTING', 'REMOVING', 'MOVING') | 19 states = ('NOTHING_LOADED', 'VIEWING', 'INSERTING', 'REMOVING', 'MOVING') |
18 for s in states: | 20 for s in states: |
19 globals()[s] = s | 21 globals()[s] = s |
20 NOT_INITIALIZED = -9999999 | 22 NOT_INITIALIZED = -9999999 |
145 self._ctrldown = False | 147 self._ctrldown = False |
146 self._shiftdown = False | 148 self._shiftdown = False |
147 self._altdown = False | 149 self._altdown = False |
148 self._dragx = NOT_INITIALIZED | 150 self._dragx = NOT_INITIALIZED |
149 self._dragy = NOT_INITIALIZED | 151 self._dragy = NOT_INITIALIZED |
152 self._scrollx = 0 | |
153 self._scrolly = 0 | |
150 | 154 |
151 self._mapselector = MapSelection(self._selectLayer, self._selectObject) | 155 self._mapselector = MapSelection(self._selectLayer, self._selectObject) |
152 self._objectselector = None | 156 self._objectselector = None |
153 rb = self._engine.getRenderBackend() | 157 rb = self._engine.getRenderBackend() |
154 self._statusbar = StatusBar(rb.getWidth(), rb.getHeight()) | 158 self._statusbar = StatusBar(rb.getWidth(), rb.getHeight()) |
415 | 419 |
416 self._dragx = NOT_INITIALIZED | 420 self._dragx = NOT_INITIALIZED |
417 self._dragy = NOT_INITIALIZED | 421 self._dragy = NOT_INITIALIZED |
418 | 422 |
419 def mouseMoved(self, evt): | 423 def mouseMoved(self, evt): |
420 pass | 424 if self._camera: |
425 screen_x = self._engine.getRenderBackend().getWidth() | |
426 screen_y = self._engine.getRenderBackend().getHeight() | |
427 ratio = float(screen_x) / screen_y | |
428 | |
429 mouse_x = evt.getX() | |
430 mouse_y = evt.getY() | |
431 | |
432 self._scrollx = 0 | |
433 self._scrolly = 0 | |
434 | |
435 if mouse_y <= SCROLL_TOLERANCE: | |
436 # up | |
437 self._scrolly = SCROLL_SPEED * ratio | |
438 if mouse_x >= screen_x - SCROLL_TOLERANCE: | |
439 # right | |
440 self._scrollx = -SCROLL_SPEED | |
441 if mouse_y >= screen_y - SCROLL_TOLERANCE: | |
442 # bottom | |
443 self._scrolly = -SCROLL_SPEED * ratio | |
444 if mouse_x <= SCROLL_TOLERANCE: | |
445 # left | |
446 self._scrollx = SCROLL_SPEED | |
447 | |
421 def mouseEntered(self, evt): | 448 def mouseEntered(self, evt): |
422 pass | 449 pass |
423 def mouseExited(self, evt): | 450 def mouseExited(self, evt): |
424 pass | 451 pass |
425 def mouseClicked(self, evt): | 452 def mouseClicked(self, evt): |
496 elif keyval in (fife.Key.LEFT_SHIFT, fife.Key.RIGHT_SHIFT): | 523 elif keyval in (fife.Key.LEFT_SHIFT, fife.Key.RIGHT_SHIFT): |
497 self._shiftdown = False | 524 self._shiftdown = False |
498 elif keyval in (fife.Key.LEFT_ALT, fife.Key.RIGHT_ALT): | 525 elif keyval in (fife.Key.LEFT_ALT, fife.Key.RIGHT_ALT): |
499 self._altdown = False | 526 self._altdown = False |
500 | 527 |
501 | 528 def pump(self): |
529 if self._scrollx != 0 or self._scrolly != 0: | |
530 self._moveCamera(self._scrollx * self._engine.getTimeManager().getTimeDelta(), self._scrolly * self._engine.getTimeManager().getTimeDelta()) |