2010 October 12 / j|d|a|v|i|s|@|c|a|r|l|e|t|o|n|.|e|d|u

Window

All programs that use the Bopagopa library must begin by instantiating a Window object. At any given time one window is current. The window handles all user events (such as keyboard and mouse) and system events (such as idling). The window keeps a Renderer3D (that handles the display of the 3D scene) and a Renderer2D (that handles the display of the 2D overlays over the 3D scene).

Basic Methods

__init__(self, width=512, height=512, title="Bopagopa")

Initializes the window and its connection to OpenGL. Sets up a variety of defaults.

needsRedrawing(self)

Informs the window that it needs to redraw itself on its next pass through the event loop.

getRenderer3D(self)

Returns the window's 3D renderer, which may be None.

setRenderer3D(self, renderer)

Sets the window's 3D renderer, which may be None.

getRenderer2D(self)

Returns the window's 2D renderer, which may be None.

setRenderer2D(self, renderer)

Sets the window's 2D renderer, which may be None.

getWorld(self)

Returns the Open Dynamics Engine (ODE) World in which the window's 3D bodies live.

getWidth(self)

Returns the width of the window in pixels.

getHeight(self)

Returns the height of the window in pixels.

setColor(self, rgb)

Sets the window's background RGB color; alpha is forced to be 1.0.

getColor(self)

Returns the window's background RGB color; alpha is always 1.0.

setIsFullScreen(self, isFullScreen)

Sets the window to full-screen mode (True) or windowed mode (False). The default is False.

getIsFullScreen(self)

Returns whether the window is in full-screen mode.

setIsWireframe(self, isWireframe)

Sets the window to display wireframes (True) or filled polygons (False). The default is False.

getIsWireframe(self)

Returns whether the window is in wireframe mode or not.

Animation Methods

getAnimations(self)

Returns the window's list of active Animations and Delays. The user can alter this list (append, pop, etc.) as desired.

makeDelayer(self, duration, function, arguments)

Shortcut for creating a Delay and appending it to the window's animations. The delayed action takes place duration seconds in the future.

makePositioner(self, duration, function, startArgs, endArgs, repetitions=1.0, rescaler=None)

Shortcut for creating a PositionAnimation and appending it to the window's animations. The animation starts immediately and lasts for the given duration (in seconds).

makeDisplacer(self, duration, function, zeroArgs, displacementArgs, repetitions=1.0, rescaler=None)

Shortcut for creating a DisplacementAnimation and appending it to the window's animations. The animation starts immediately and lasts for the given duration (in seconds).

trackTime(self, function)

Shortcut for creating a DisplacementAnimation that tracks real time. That is, on each frame of the animation the given function (or method) is called with a single float argument: the number of seconds that have passed since the last frame of the animation. (On the first frame, this is the number of seconds that have passed since the start of the animation.)

User Interface Methods

mouseIsDown(self)

Returns a Boolean indicating whether the mouse button is down.

getMouse(self)

Returns the (x, y) integer coordinates of the mouse pointer, relative to the bottom left corner of the window.

shiftKeyWasDown(self)

Returns Boolean indicating whether the shift key was down at the time of the most recent user interface event.

controlKeyWasDown(self)

Returns Boolean indicating whether the control key was down at the time of the most recent user interface event.

altKeyWasDown(self)

Returns Boolean indicating whether the alt key was down at the time of the most recent user interface event.

pick(self, xy)

The input xy is a screen coordinate pair (with origin in the bottom left corner). Returns a pair (index, coords) as follows. If index is None, then no body is at (x, y). If index is not None and coords is None, then index indicates which 2D body is at (x, y), by its index in the Renderer2D's list of bodies. If index is not None and coords is not None, then index indicates which 3D body is at (x, y) and coords is the approximate XYZ world coordinates of that spot on the body. Warning: Can handle at most about 127 2D bodies and about 127 3D bodies.

setKeyboardHandler(self, function)

Sets the keyboard handler function, which should have interface keyboardHandler(xy, key). In addition to common characters, there are special characters GLUT_KEY_LEFT, GLUT_KEY_RIGHT, GLUT_KEY_UP, GLUT_KEY_DOWN, GLUT_KEY_PAGE_UP, GLUT_KEY_PAGE_DOWN, GLUT_KEY_HOME, GLUT_KEY_END, GLUT_KEY_INSERT, GLUT_KEY_F1, ..., GLUT_KEY_F12 (which can be found in the module OpenGL.GLUT).

setClickHandlerEmpty(self, function)

Sets the handler function for clicks on empty space, which should have interface clickHandlerEmpty(xy).

setBeginDragHandlerEmpty(self, function)

Sets the handler function for beginning drags on empty space, which should have interface beginDragHandlerEmpty(xyStarting, xyCurrent).

setDragHandlerEmpty(self, function)

Sets the handler function for drags on empty space, which should have interface dragHandlerEmpty(xyStarting, xyPrevious, xyCurrent).

setEndDragHandlerEmpty(self, function)

Sets the handler function for ending drags on empty space, which should have interface endDragHandlerEmpty(xyStarting, xyPrevious, xyFinal).

setClickHandler2D(self, function)

Sets the handler function for clicks on 2D bodies, which should have interface clickHandler2D(xy, name).

setBeginDragHandler2D(self, function)

Sets the handler function for beginning drags on 2D bodies, which should have interface beginDragHandler2D(xyStarting, xyCurrent, name).

setDragHandler2D(self, function)

Sets the handler function for drags on 2D bodies, which should have interface dragHandler2D(xyStarting, xyPrevious, xyCurrent, name).

setEndDragHandler2D(self, function)

Sets the handler function for ending drags on 2D bodies, which should have interface endDragHandler2D(xyStarting, xyPrevious, xyFinal, name).

setClickHandler3D(self, function)

Sets the handler function for clicks on 3D bodies, which should have interface clickHandler3D(xy, name, xyz).

setBeginDragHandler3D(self, function)

Sets the handler function for beginning drags on 3D bodies, which should have interface beginDragHandler3D(xyStarting, xyCurrent, name, xyzStarting).

setDragHandler3D(self, function)

Sets the handler function for drags on 3D bodies, which should have interface dragHandler3D(xyStarting, xyPrevious, xyCurrent, name, xyzStarting).

setEndDragHandler3D(self, function)

Sets the handler function for ending drags on 3D bodies, which should have interface endDragHandler3D(xyStarting, xyPrevious, xyFinal, name, xyzStarting).

setMenuHandler(self, function, names)

Sets the menu and menu handler function that are attached to the right mouse button. The names argument is a list of distinct strings that appear as the menu items. The handler function should take a single string --- the menu item that was selected. Passing None for either argument disables the menu.

Getting the Current Window

getWindow()

Returns the current Bopagopa window --- the one that's receiving user interface events.