Niels, I've cc'd this to the floatcanvas list:
http://mail.mithis.com/cgi-bin/mailman/listinfo/floatcanvas I like to use that for correspondence, so it gets archived, and others can join the conversation. Niels Menke wrote: > I have so far completed a GUI with a workspace where objects can be > dragged upon. It sports a DotGrid in the background. Sounds like a good start. > However, i have a severe problem with scrolling being very sluggish as > soon as several objects are on the Workspace/DotGrid. I'm somewhat > unable to figure out the problem. As the FloatCanvas demos are nice and > fast even with more objects, I put a fair bit of effort into that. > A snippet of how i move the workspace: > > In the Workspace class > > def OnMouseMotion(self, event): > self.__x, self.__y = event.GetPosition() > # execute only, if the current mouse position is different from the > last one > if (self.__x, self.__y) != (self.__lastX, self.__lastY): > # moves the workspace > if event.RightIsDown(): > deltaX = self.__x - self.__lastX > deltaY = self.__y - self.__lastY > self.__updateWorkspaceView(-deltaX, -deltaY) > [...] > > > def __updateWorkspaceView(self, deltaX, deltaY): > # get the client rect > clientSize = self.GetClientSize() > > # get necessary properties > dimensions = self.__workspace.pref_standard.dimensions > > # calculate the worldpos min and max after scrolling > worldPosMin = self.canvas.PixelToWorld((deltaX, deltaY)) > worldPosMax = self.canvas.PixelToWorld((clientSize[0]+deltaX, > clientSize[1]+deltaY)) > > # if the next position is outside of the workspace, correct the > scrolling deltas > if worldPosMin[0] < 0: > deltaX -= worldPosMin[0] > if worldPosMin[1] < clientSize[1]: > deltaY -= clientSize[1]-worldPosMin[1] > if worldPosMax[0] > dimensions.x: > deltaX -= worldPosMax[0]-dimensions.x > if worldPosMax[1] > dimensions.y-clientSize[1]: > deltaY += worldPosMax[1]-(dimensions.y-clientSize[1]) > > self.canvas.MoveImage((deltaX, deltaY), "Pixel") > > Is there anything wrong with this particular code or any typical > bottlenecks? A couple issues: 1) you've got a fair bit of extra math in there that is probably already provided by FloatCanvas -- I'd have to look closer to see exactly what, but it sure likes you're doing too much work. Also, it looks like you're mixing world and pixel coords: deltaX -= worldPosMin[0] or did I miss something? But that's not your performance problem. 2) you end up calling MoveImage with every mouse event. MoveImage requires a complete re-draw, so that's a LOT of re-draws. This looks an awful lot like the Move Mode that is built in, but in that mode, I move just the buffered bitmap until the user has let go of the mouse, then do a re-draw. Why aren't you using that? In fact, One of the reason's I chose "panning" rather than scrollbars is that I could better control how often a re-draw is called for. What version of FloatCanvas are you using? i recommend the latests version from SVN, which you can find here: http://morticia.cs.dal.ca/FloatCanvas/ -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception [EMAIL PROTECTED] _______________________________________________ FloatCanvas mailing list [email protected] http://mail.mithis.com/cgi-bin/mailman/listinfo/floatcanvas
