eg-overlay-ui#
local ui = require 'eg-overlay-ui'
Top Level Elements
Layout Containers
UI Elements
Colors#
All colors in EG-Overlay are represented by 32bit integers in RGBA format. This
may sound complicated, but it is actually incredibly convenient for module
authors as colors can be specified in hex format, similar to CSS. For example,
red at 100% opacity is 0xFF0000FF
, green is 0x00FF00FF
,
and blue is 0x0000FFFF
.
Fonts#
Important
EG-Overlay uses FreeType2 to render glyphs onscreen. This means that any font that FreeType2 supports can be used, however module authors are encouraged to use the fonts configured in the overlay settings.
Due to the rendering and caching system, fonts are not directly exposed to Lua. Instead, all UI elements that use fonts take the following arguments on creation:
Font path
Font size
Font weight
Font slant
Font width
The font path is the path to the actual font file. This can be a static/single font file or a variable font containing multiple styles. If a font does not support the given style parameters (weight, slant, width) they will be ignored. If style parameters are omitted, defaults will be used.
Implementation Detail
Fonts are rendered using a textured quad for each glyph. To attain useable performance, glyphs are pre-rendered to a texture array that is then used to render glyphs each frame.
Unlike many other UI frameworks, this pre-rendering is not static. Each font face, size, weight, slant, and width combination has a 512x512xN texture array, where N is a variable number of layers that are created as needed. When a unique font combination is requested a texture array with a single layer is created and pre-rendered with the standard ASCII glyphs.
Additional glyphs are pre-rendered the first time they are requested. This means that the UI may suffer a performance hit on the first frame a new glyph is rendered, but all subsequent frames should be unaffected.
UI Events#
Most UI elements can send events to event handlers in Lua. Such elements
implement addeventhandler
and removeeventhandler
methods. Some elements
do not emit events by default and need to be enabled using an events
method.
Event handler functions are passed a single argument, a string describing the event:
Value |
Description |
---|---|
|
Mouse button 1 (left) pressed. |
|
Mouse button 2 (right) pressed. |
|
Mouse button 3 (middle) pressed. |
|
Mouse button 4 pressed. |
|
Mouse button 5 pressed. |
|
An unknown mouse button is pressed. |
|
Mouse button 1 (left) released. |
|
Mouse button 2 (right) released. |
|
Mouse button 3 (middle) released. |
|
Mouse button 4 released. |
|
Mouse button 5 released. |
|
An unknown mouse button is released. |
|
Mouse cursor moved (over the element). |
|
Mouse wheel scrolled up. |
|
Mouse wheel scrolled down. |
|
Mouse wheel scrolled left. |
|
Mouse wheel scrolled right. |
|
Mouse cursor entered the element area. |
|
Mouse cursor left the element area. |
|
Element now has focus (keyboard input). |
|
Element no longer has focus. |
Note
Elements may send additional events not listed here.
Important
Events are sent to Lua like any other event, asynchronously. This means that there may be some delay between an event occurring and the event handler being called in Lua. However, events still should arrive in the same order that they occurred.
Core UI#
- class eg-overlay-ui.uielement#
This is not an actual class accessible from Lua, but represents any UI Element.
Version History
Version
Notes
0.0.1
Added
- eg-overlay-ui.addtoplevelelement(uielement)#
Add an element to the list of top level elements. Top level elements are the only elements drawn automatically.
Note
Normally only windows are top level elements, however any UI element can be specified here to have it drawn independently of a window.
If
uielement
is already a top level element this function has no effect.- Parameters:
uielement – The UI element to draw.
Version History
Version
Notes
0.0.1
Added
0.1.0
Renamed from add_top_level_element to addtoplevelelement
- eg-overlay-ui.removetoplevelelement(uielement)#
Remove a top level element previously added with
addtoplevelelement()
.- Parameters:
uielement – The UI element to hide.
Version History
Version
Notes
0.0.1
Added
0.1.0
Renamed from remove_top_level_element to removetoplevelelement
- eg-overlay-ui.mouseposition()#
Returns the x,y coordinates of the mouse cursor. These coordinates are relative to the overlay’s client rectangle, i.e. 0,0 is the top left.
- Returns:
X,Y
- Return type:
Example#local x,y = ui.mouse_position()
Version History
Version
Notes
0.0.1
Added
0.1.0
Renamed from mouse_position to mouseposition