A Simple Discrete-Event Simulation: Part 81

This week and possibly much of next I’m concentrating on updating the fixed content of my website, which means I’m only going to be doing small increments on this project. I’ve decided that the next item to work on is panning a zooming because of something I want to demonstrate in the fixed content. To that end I installed the simplest possible commands to pan the 2D display around within certain limits. Mostly I wanted to verify that I’d added the base x- and y-origins for the viewable area of the screen were added to all of the drawing commands properly.

Here’s the relevant code from the DisplayElement object. It shows how the drawing locations now include the offsets I’ve defined (globalBaseX and globalBaseY):

Here’s the code that does the basic pan. It picks up keystrokes and changes the base x- and y-axis panning origins within limits. When the code is running in its own window there are times when higher priority events consume the messages for the up and down arrow keys, namely when the entire page wants to scroll. When I embed this in an iframe on the website it doesn’t seem to have this problem. However, when it’s in the iframe (like you see it here) you need to click on the canvas to give it the focus. The arrow keys move the display and the home key restore the origin point to its original value. There’s no provision for panning on a mobile device, either, but at least I know the offsets are in correctly.

You may also notice that these calls update the graphics when the simulation is not running, but don’t need to do so when the simulation is running, though the panning action will be much more slow and choppy.

This entry was posted in Simulation and tagged , . Bookmark the permalink.

Leave a Reply