diff 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
line wrap: on
line diff
--- 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())