Popups

PinballY uses popup boxes to display messages and detailed information. Popup boxes are functionally similar to Windows dialog boxes, but they're visually styled to fit the arcade graphics environment, rather than appearing as separate windows. They're also operable with the basic pin cab buttons rather than requiring a mouse. Popups are mostly limited to information displays, as they don't have a full complement of input controls like Windows dialogs do. PinballY resorts to regular Windows dialogs for anything involving keyboard input or other complex input gestures.

Popup events

When a popup opens or closes, the system fires popupopen and popupclose events (respectively). See PopupEvent for details.

System popups

Here's a list of the system popup display types, with the ID strings reported in the .popupID property of the object returned from mainWindow.getUIMode() while the popup is being displayed.

Custom popups

The mainWindow.showPopup() method lets you create your own completely custom popup dialog, using the same basic display style as the system popups, but with your own custom contents.

The argument to mainWindow.showPopup() is a descriptor object specifying the layout and contents of the popup. The descriptor has the following properties:

Default sizing

If you omit the width and/or height settings in the descriptor, the system figures a default size as follows:

Dynamic layout height

In some cases, you might want to adjust your popup's overall display height according to its contents, so that it's just tall enough to display the specific contents you draw into the popup. The required height might not be predictable in advance, so the popup system gives you a way to calculate the height from your Javascript code, on the fly as you do the drawing. This lets you determine precisely the needed height needed to contain the actual contents you display.

To use a dynamically calculated height, you have to leave all of the "pre-calculated" height elements in the popup descriptor blank. Specifically:

The system can tell that it has to use the "dynamic" method to determine the height when it sees that you haven't provided any way for it to pre-calculate the height, either from an explicit height property or from an implied height based on a backgroundImage property.

When the dynamic height method is required, the system calls your drawing function twice. The first time, the call is only to figure out the height, and doesn't do any actual on-screen drawing. There are three important implications of this two-pass process:

Calculating the height in the drawing function

If you use the "dynamic layout height" procedure described above, your custom drawing function must return a value indicating the desired pixel height for the popup box. This is necessary if you don't specify a height for the popup in the popup descriptor and you don't supply a background image, since that doesn't give the system any way to figure the required height on its own.

To calculate the required height, you should keep track of the positions and heights of the objects you draw, and use that to calculate the overall height needed for the contents. Return the result as the return value from the function.

The system ignores the returned height value if you provide a height explicitly in the original popup descriptor object, or if you specify a background image in the popup descriptor. In either case, the pre-determined height supersedes the custom draw function's calculated height.