XPUIGraphics¶
To use:
import xp
Functions¶
- drawWindow(left, bottom, right, top, style=1)¶
- Parameters
left (int) –
bottom (int) –
right (int) –
top (int) – dimensions of window
style (int) – XPWindowStyle
Draw a window of the given dimensions at the given offset on the virtual screen in a given style. The window is automatically scaled as appropriate using a bitmap scaling technique (scaling or repeating) as appropriate to the style. Window styles are XPWindowStyle.
Unlike drawing widgets,
drawWindow()needs to be done within a draw callback, so that it gets drawn every frame.There is no “handle” to this window: you stop drawing it and it goes away.
Note
Laminar documentation lists parameters as (x1, y1, x2, y2, style). For consistency with widget and window routines, I’m using (left, bottom, right, top). Yes, other routines use a different ordering, but at least we’ll remain consistent on nomenclature.)
>>> def MyDraw(phase, before, refCon): ... xp.drawWindow(100, 100, 300, 200, style=refCon) ... return 1 ... >>> xp.registerDrawCallback(MyDraw, refCon=1)
Official SDK XPDrawWindow
- getWindowDefaultDimensions(style)¶
- Parameters
style (int) – XPWindowStyle
- Returns
Tuple (width: int, height: int)
This routine returns the default dimensions (width, height) for a window, given its style (XPWindowStyle). Output is either a minimum or fixed value depending on whether the window is scalable.
>>> xp.getWindowDefaultDimensions(xp.Window_MainWindow) (100, 100)
[Since you’ll specify the window size via
drawWindow()and all of them are scalable, this function seems extraneous.]Official SDK XPGetWindowDefaultDimensions
- drawElement(left, bottom, right, top, style, lit=0)¶
- Parameters
left (int) –
bottom (int) –
right (int) –
top (int) – dimensions of element
style (int) – XPElementStyle
lit (int) – 1= draw “lit” version of element.
Draws a given element at an offset on the virtual screen in set dimensions. EVEN if the element is not scalable, it will be scaled if the width and height do not match the preferred dimensions; it’ll just look ugly. Pass lit=1 to see the lit version of the element; if the element cannot be lit this is ignored.
style is one of XPElementStyle.
Warning
Not all element styles are drawn correctly. Bug has been filed with Laminar 17-November-2021.
>>> def MyDraw(phase, before, refCon): ... (width, height, canBeLit) = xp.getElementDefaultDimensions(style=refCon['element']) ... xp.drawElement(10, 10, 10+width, 10+height, style=refCon['element']) ... if canBeLit: ... xp.drawElement(10 + width + 20, 10, 10 + width + width + 20, 10+height, style=refCon['element'], lit=1) ... return 1 ... >>> refCon = {'element': xp.Element_Airport} >>> xp.registerDrawCallback(MyDraw, refCon=refCon) >>> refCon['element'] = xp.Element_VORWithCompassRose >>> xp.unregisterDrawCallback(MyDraw, refCon=refCon)
Official SDK XPDrawElement
- getElementDefaultDimensions(style)¶
- Parameters
style (XPElementStyle) – XPElementStyle
- Returns
Tuple[width: int, height: int, canBeLit: int]
Returns the recommended or minimum dimensions of a given UI element style XPElementStyle as a tuple (width, height, canBeLit).
canBeLit tells whether the element has both a lit and unlit state.
>>> xp.getElementDefaultDimensions(xp.Element_Airport) (15, 15, 0)
Official SDK XPGetElementDefaultDimensions
- drawTrack(left, bottom, right, top, minValue, maxValue, value, style, lit=0) None:¶
- Parameters
left (int) –
bottom (int) –
right (int) –
top (int) – dimensions of track element
minValue (int) –
maxValue (int) – range of the track
value (int) – placement of thumb
style – XPTrackStyle
lit (int) – 1= hightlight track
This routine draws a track. You pass in the track dimensions, range of possible values, initial value, style (XPTrackStyle) and if it should be lit. The orientation (horizontal vs. vertical) will be determined based on dimensions.
>>> def MyDraw(phase, before, refCon): ... xp.drawTrack(10, 100, 30, 300, refCon['minValue'], refCon['maxValue'], 25, style=refCon['style']) ... xp.drawTrack(60, 100, 80, 300, refCon['minValue'], refCon['maxValue'], 25, style=refCon['style'], lit=1) ... xp.drawTrack(10, 70, 210, 90, refCon['minValue'], refCon['maxValue'], 25, style=refCon['style']) ... xp.drawTrack(10, 40, 210, 60, refCon['minValue'], refCon['maxValue'], 25, style=refCon['style'], lit=1) ... return 1 ... >>> refCon = {'minValue': 0, 'maxValue': 100, 'style': xp.Track_ScrollBar} >>> xp.registerDrawCallback(MyDraw, refCon=refCon)
Note
“Drawing” does not manage clicks, so you’ll still have to do that by responding to either
MouseDownwindow events, orMsg_MouseDownwidget events (if this track is placed within a widget.) See example code inXPListBox.py, available underResources/plugins/XPPython3.Official SDK XPDrawTrack
- getTrackDefaultDimensions(style)¶
- Parameters
style – XPTrackStyle
- Returns
Tuple[width: int, canBeLit: int]
This routine returns a track’s default smaller dimension as a tuple
(width, canBeLit).All tracks are scalable in the larger dimension. It also returns whether a track can be lit.
>>> xp.getTrackDefaultDimensions(xp.Track_ScrollBar) (11, 1)
Official SDK XPGetTrackDefaultDimensions
- getTrackMetrics(left, bottom, right, top, minValue, maxValue, value, style)¶
- Parameters
left (int) –
bottom (int) –
right (int) –
top (int) – dimensions of track element
minValue (int) –
maxValue (int) – range of the track
value (int) – placement of thumb
style – XPTrackStyle
- Returns
TrackMetrics instance
Returns a structure with metrics for the given track. If you want to write UI code to manipulate a track, this routine helps you know where the mouse locations are. For most other elements, the rectangle the element is drawn in is enough information. However, the track drawing routine does some automatic placement; this routine lets you know where things ended up. You pass almost everything you would pass to the draw routine. You get out the orientation, and other useful stuff as an object with the following attributes:
.isVertical: 1= true.downBtnSize: int.downPageSize: int.thumbSize: int.upPageSize: int.upBtnSize: intBesides orientation, you get five dimensions for the five parts of a scrollbar, which are the down button, down area (area before the thumb), the thumb, and the up area and button. For horizontal scrollers, the left button decreases; for vertical scrollers, the top button decreases.
(Tracks don’t have to be drawn to retrieve this information.)
>>> info = xp.getTrackMetrics(10, 100, 30, 300, 0, 100, 25, xp.Track_ScrollBar) >>> info.isVertical 1 >>> print(info) <TrackMetrics {isVertical: 1, downBtnSize: 14, downPageSize: 39, thumbSize: 16, upPageSize:118, upBtnSize: 13}>
Currently (XP12) widget button sizes don’t change based on size of track or contents. This means the down button, up button and thumb always remain the same. The down page and up page sizes reflect the “space” between the up/down button and the thumb. Summing the five metrics will always equal the longer dimension of the track.
Official SDK XPGetTrackMetrics
Constants¶
XPWindowStyle¶
There are a few built-in window styles in X-Plane that you can use.
WindowStyle |
Example |
|---|---|
An LCD screen that shows help. |
|
A dialog box window. |
|
A panel or frame within a dialog box window. |
|
An LCD screen within a panel to hold text displays. |
|
A list view within a panel for scrolling file names, etc. |
|
XPElementStyle¶
Elements are individually drawable UI things like push buttons, etc. The style defines what kind of element you are drawing. Elements can be stretched in one or two dimensions (depending on the element). Some elements can be lit.
Element
Scalable Axes
Required background
- Element_TextField¶
=6
x
metal
- Element_CheckBox¶
=9
none
metal
- Element_CheckBoxLit¶
=10
none
metal
- Element_WindowCloseBox¶
=14
none
window header
- Element_WindowCloseBoxPressed¶
=15
none
window header
- Element_PushButton¶
=16
x
metal
- Element_PushButtonLit¶
=17
x
metal
- Element_OilPlatform¶
=24
none
any
- Element_OilPlatformSmall¶
=25
none
any
- Element_Ship¶
=26
none
any
- Element_ILSGlideScope¶
=27
none
any
- Element_MarkerLeft¶
=28
none
any
- Element_Airport¶
=29
none
any
- Element_Waypoint¶
=30
none
any
- Element_NDB¶
=31
none
any
- Element_VOR¶
=32
none
any
- Element_RadioTower¶
=33
none
any
- Element_AircraftCarrier¶
=34
none
any
- Element_Fire¶
=35
none
any
- Element_MarkerRight¶
=36
none
any
- Element_CustomObject¶
=37
none
any
- Element_CoolingTower¶
=38
none
any
- Element_SmokeStack¶
=39
none
any
- Element_Building¶
=40
none
any
- Element_PowerLine¶
=41
none
any
- Element_CopyButtons¶
=45
none
metal
- Element_CopyButtonsWithEditingGrid¶
=46
none
metal
- Element_EditingGrid¶
=47
x, y
metal
- Element_ScrollBar¶
=48
THIS CAN PROBABLY BE REMOVED
- Element_VORWithCompassRose¶
=49
none
any
- Element_Zoomer¶
=51
none
metal
- Element_TextFieldMiddle¶
=52
x, y
metal
- Element_LittleDownArrow¶
=53
none
metal
- Element_LittleUpArrow¶
=54
none
metal
- Element_WindowDragBar¶
=61
none
metal
- Element_WindowDragBarSmooth¶
=62
none
metal
Warning
Not all elements draw correctly with XP 11.55+. Bug has been filed with Laminar 17-November-2021.
XPTrackStyle¶
A track is a UI element that displays a value vertically or horizontally. X-Plane has three kinds of tracks: scroll bars, sliders, and progress bars. Tracks can be displayed either horizontally or vertically; tracks will choose their own layout based on the larger dimension of their dimensions (e.g. they know if they are tall or wide). Sliders may be lit or unlit (showing the user manipulating them).
TrackStyle |
Example unlit /lit, Vertical / Horizontal |
Flipped, minValue > maxValue |
|---|---|---|
ScrollBar - this is a standard scroll bar with arrows and a thumb to drag. The longer dimension will scale, but the shorter dimension will always display the same (e.g., you can make the bar longer, but you cannot make it fatter.) |
|
|
Slider - this is a simple track with a ball in the middle that can be slid. |
|
|
Progress - this is a progress indicator showing how a long task is going. |
|
|
