Module CorsixTH.CorsixTH.Lua.window
Base class for user-interface dialogs.
Functions
| Button:enable (enable) | Enable or disable a button. |
| Button:handleClick (mouse_button) | Called whenever a click on the button should be handled. |
| Button:setLabel (label, font, align) | Convenience function to allow setLabel to be called on a button, not only its panel. |
| Button:setPosition (x, y) | Set the position of a button. |
| Button:setSize (width, height) | Set the size of a button. |
| Button:setToggleState (state) | Set the toggle state of the button to the provided state. |
| Button:setVisible (visibility) | Set the visibility of the button. |
| Button:toggle () | Flip the toggle state of the button (on -> off, or off -> on). |
| HotkeyBox:HotkeyBox () | A window element used to accept hotkey configurations. |
| HotkeyBox:abort () | Set the box to not active and run abort callback, if any |
| HotkeyBox:confirm () | Set the box to not active and run confirm callback, if any |
| HotkeyBox:setActive (active) | Set the hotkeybox active status to true or false, taking care of any additional things that need to be done: deactivate any other hotkeyboxes, handle blinking cursor, keyboard repeat on/off, set button state accordingly |
| Panel:Panel () | The basic component which makes up most `Window`s. |
| Panel:clipLine (line, limit) | Checks if a given line drawn with the panel's label font would be longer than the given limit and if so, shortens it enough to fit including "..." at the end |
| Panel:drawLabel (canvas, x, y, limit) | Draw function for the label on a panel |
| Panel:setAutoClip (mode) | Specifies whether auto clip (clipping text at the end so it fits) is enabled for this panel |
| Panel:setLabel (label, font, align) | Specify a label to be drawn on top of the panel. |
| Panel:setPosition (x, y) | Set the position of a panel. |
| Panel:setSize (width, height) | Set the size of a panel. |
| Panel:setVisible (visibility) | Set the visibility of the panel. |
| Scrollbar:Scrollbar () | A window element used to scroll in lists |
| Scrollbar:getXorY () | Get the pixel position of the slider in the axis which the slider can move |
| Scrollbar:setXorY (xy) | Set the pixel position of the slider in the axis which the slider can move |
| Textbox:Textbox () | A window element used to enter text. |
| Textbox:abort () | Set the box to not active and run abort callback, if any |
| Textbox:confirm () | Set the box to not active and run confirm callback, if any |
| Textbox:keyInput (char, rawchar) | Handles special characters such as Enter. |
| Textbox:setActive (active) | Set the textbox active status to true or false, taking care of any additional things that need to be done: deactivate any other textboxes, handle blinking cursor, keyboard repeat on/off, set button state accordingly |
| Textbox:textInput (text) | Handles actual text input. |
| Window:afterLoad (old, new) | Stub to be extended in subclasses, if needed. |
| Window:getTooltipAt (x, y) | Query the window for tooltip text to display for a particular position. |
| Window:makeDynamicTooltip (callback, x, y, r, b, tooltip_x, tooltip_y) | Create a dynamic tooltip to be displayed in a certain region. |
| Window:makeTooltip (text, x, y, r, b, tooltip_x, tooltip_y) | Create a static (non-changeable) tooltip to be displayed in a certain region. |
Functions
- Button:enable (enable)
-
Enable or disable a button.
Parameters:
- enable (boolean) Whether to enable (true) or disable (false) the button.
- Button:handleClick (mouse_button)
-
Called whenever a click on the button should be handled. This depends on the type of button.
Normally this is called when a MouseUp occurs over the button (if the MouseDown occurred over
this or another button). However for repeat buttons, it is called once on MouseDown and, after
a short delay, repeatedly.
Parameters:
- mouse_button (string) either "left" or "right"
- Button:setLabel (label, font, align)
-
Convenience function to allow setLabel to be called on a button, not only its panel.
see Panel:setLabel
Parameters:
- label
- font
- align
- Button:setPosition (x, y)
-
Set the position of a button.
Parameters:
- x (int) New horizontal position of the button.
- y (int) New vertical position of the button.
- Button:setSize (width, height)
-
Set the size of a button.
Parameters:
- width (int) New width of the button.
- height (int) New height of the button.
- Button:setToggleState (state)
-
Set the toggle state of the button to the provided state.
Parameters:
- state (boolean) Desired state of the toggle button.
- Button:setVisible (visibility)
-
Set the visibility of the button.
Parameters:
- visibility (bool) New visibility of the button.
- Button:toggle ()
- Flip the toggle state of the button (on -> off, or off -> on).
- HotkeyBox:HotkeyBox ()
- A window element used to accept hotkey configurations.
- HotkeyBox:abort ()
- Set the box to not active and run abort callback, if any
- HotkeyBox:confirm ()
- Set the box to not active and run confirm callback, if any
- HotkeyBox:setActive (active)
-
Set the hotkeybox active status to true or false, taking care of any
additional things that need to be done: deactivate any other hotkeyboxes,
handle blinking cursor, keyboard repeat on/off, set button state accordingly
Parameters:
- active (boolean) whether to activate (true) or deactivate (false) the box
- Panel:Panel ()
- The basic component which makes up most `Window`s. The visual parts of most ingame dialogs are sprites from a sprite sheet. A `Panel` is an instance of a particular sprite, consisting of a sprite index and a position. It is advantageous to construct dialogs out of panels (using `Window:addPanel`) as the common operations on panels (like drawing them and hit-testing against them) are implemented in the `Window` class, thus reducing the amount of work that each individual dialog has to do.
- Panel:clipLine (line, limit)
-
Checks if a given line drawn with the panel's label font would be longer than the given limit
and if so, shortens it enough to fit including "..." at the end
Parameters:
- line (string) the line to modify
- limit (int) the maximum length in pixels the line should have
Returns:
-
the possibly modified line
- Panel:drawLabel (canvas, x, y, limit)
-
Draw function for the label on a panel
Parameters:
- canvas The canvas to draw on (can be nil for test)
- x x position to start drawing on
- y y position to start drawing on
- limit (nil or {int, int}) limit after which line and with character on that line to stop drawing
Returns:
-
y and x end positions after drawing
- Panel:setAutoClip (mode)
-
Specifies whether auto clip (clipping text at the end so it fits) is enabled for this panel
Parameters:
- mode (boolean) true to activate, false to deactivate.
- Panel:setLabel (label, font, align)
-
Specify a label to be drawn on top of the panel.
Note: This works only with ColourPanel and BevelPanel, not normal (sprite) panels.
Parameters:
- label (string) The text to be drawn on top of the label.
- font (font) [optional] The font to use. Default is Font01V in QData.
- align (string) [optional] Alignment for non-multiline labels (multiline is always left) can be either of "left", "center", "right"
- Panel:setPosition (x, y)
-
Set the position of a panel.
Parameters:
- x (int) New horizontal position of the panel.
- y (int) New vertical position of the panel.
- Panel:setSize (width, height)
-
Set the size of a panel.
Parameters:
- width (int) New width of the panel.
- height (int) New height of the panel.
- Panel:setVisible (visibility)
-
Set the visibility of the panel.
Parameters:
- visibility (bool) New visibility of the panel.
- Scrollbar:Scrollbar ()
- A window element used to scroll in lists
- Scrollbar:getXorY ()
- Get the pixel position of the slider in the axis which the slider can move
- Scrollbar:setXorY (xy)
-
Set the pixel position of the slider in the axis which the slider can move
Parameters:
- xy
- Textbox:Textbox ()
- A window element used to enter text.
- Textbox:abort ()
- Set the box to not active and run abort callback, if any
- Textbox:confirm ()
- Set the box to not active and run confirm callback, if any
- Textbox:keyInput (char, rawchar)
-
Handles special characters such as Enter. Normal text input is processed in the textInput function.
Note though that this function still returns true if it appears to be a characters being entered.
Parameters:
- char
- rawchar
- Textbox:setActive (active)
-
Set the textbox active status to true or false, taking care of any
additional things that need to be done: deactivate any other textboxes,
handle blinking cursor, keyboard repeat on/off, set button state accordingly
Parameters:
- active (boolean) whether to activate (true) or deactivate (false) the box
- Textbox:textInput (text)
-
Handles actual text input.
Parameters:
- text
- Window:afterLoad (old, new)
-
Stub to be extended in subclasses, if needed.
Parameters:
- old
- new
- Window:getTooltipAt (x, y)
-
Query the window for tooltip text to display for a particular position.
Tooltips are either associated with buttons, panels, or a region.
(see Button:setTooltip, Panel:setTooltip, Window:make[Dynamic]Tooltip)
Button tooltips take precedence over region tooltips, which again take precedence over panels.
Returns tooltip in form of { text = .. , x = .. , y = .. } or nil for no tooltip.
Parameters:
- x (integer) The X coordinate relative to the top-left corner.
- y (integer) The Y coordinate relative to the top-left corner.
- Window:makeDynamicTooltip (callback, x, y, r, b, tooltip_x, tooltip_y)
-
Create a dynamic tooltip to be displayed in a certain region.
tooltip_x and tooltip_y are optional; if not specified, it will default to top center of region.
Parameters:
- callback (function) A function that returns the string to display or nil for no tooltip.
- x (integer) The X coordinate relative to the top-left corner.
- y (integer) The Y coordinate relative to the top-left corner.
- r (integer) The right (X + width) coordinate relative to the top-left corner.
- b (integer) The bottom (Y + height) coordinate relative to the top-left corner.
- tooltip_x (integer) [optional] The X coordinate to display the tooltip at.
- tooltip_y (integer) [optional] The Y coordinate to display the tooltip at.
- Window:makeTooltip (text, x, y, r, b, tooltip_x, tooltip_y)
-
Create a static (non-changeable) tooltip to be displayed in a certain region.
tooltip_x and tooltip_y are optional; if not specified, it will default to top center of region.
Parameters:
- text (string) The string to display.
- x (integer) The X coordinate relative to the top-left corner.
- y (integer) The Y coordinate relative to the top-left corner.
- r (integer) The right (X + width) coordinate relative to the top-left corner.
- b (integer) The bottom (Y + height) coordinate relative to the top-left corner.
- tooltip_x (integer) [optional] The X coordinate to display the tooltip at.
- tooltip_y (integer) [optional] The Y coordinate to display the tooltip at.