XLua2 API Ref XPLMPanelGraphics Latest - 4.4.0-d4

Panel Graphics Hot Zones

These routines define interactive touch zones on a panel surface. You call XPLMAccumulateTouchZone during your drawing callback to declare rectangular regions that respond to mouse clicks or touches. Each zone can either fire an X-Plane command automatically or deliver raw touch events to a callback you register with XPLMAvionicsSetTouchEventHandler.


XPLMTouchZone

enum

This enumeration specifies how a touch zone responds to user interaction.

Name Value Description
xplm_TouchZone_Nothing 0 The zone is registered but takes no action when touched.
xplm_TouchZone_Command 1 The zone fires an XPLMCommandRef when touched (begin on mouse-down, end on mouse-up).
xplm_TouchZone_Identifier 2 The zone delivers touch events to the callback registered via XPLMAvionicsSetTouchEventHandler, identified by the zone's identifier field.

XPLMTouchEvent_f

callback

Your touch event callback is invoked when the user interacts with a touch zone whose type is xplm_TouchZone_Identifier. You receive the zone's identifier, the mouse status, the current position, the delta from the initial click point, and the mouse button involved.

function my_TouchEvent_callback(
    identifier,    -- int
    status,        -- XPLMMouseStatus
    x,             -- int
    y,             -- int
    dx,            -- int
    dy,            -- int
    button,        -- int
    ref            -- any Lua var/table
)
    -- your code here
end

XPLMTouchZoneSpec_t

struct

XPLMTouchZoneSpec_t describes a single interactive touch zone on the panel. Pass a pointer to this struct to XPLMAccumulateTouchZone during your drawing callback. The structure may be expanded in future SDKs - always set structSize to the size of your structure in bytes.

local My_TouchZoneSpec_t = {
    structSize  = 0,       -- int
    type        = nil,     -- XPLMTouchZone
    command     = nil,     -- XPLMCommandRef
    identifier  = 0,       -- int
    left        = 0,       -- int
    top         = 0,       -- int
    right       = 0,       -- int
    bottom      = 0,       -- int
}

XPLMAccumulateTouchZone

function

This function registers a touch zone for the current frame. Call this during your avionics drawing callback each frame for every interactive region on your panel. Zones registered later take priority over earlier ones when they overlap.

Returns true if the zone is currently being clicked or held by the user, false otherwise. You can use this to provide visual feedback (for example, drawing a button in its pressed state).

-- returns boolean -> assign to local/var
local my_result = XPLMAccumulateTouchZone(
    inSpec     -- see XPLMTouchZoneSpec_t
)

See associated types:


XPLMAvionicsSetTouchEventHandler

function

This function registers a callback to receive touch events for zones of type xplm_TouchZone_Identifier on a specific avionics device. When the user interacts with an identifier-type zone, your callback is invoked with the zone's identifier and the mouse event details.

  • avionic: the avionics device handle (from XPLMRegisterAvionicsCallbacksEx or XPLMCreateAvionicsEx).
  • handler: your XPLMTouchEvent_f callback.
  • ref: a reference pointer passed through to your callback.
XPLMAvionicsSetTouchEventHandler(
    avionic,    -- XPLMAvionicsID
    handler,    -- see XPLMTouchEvent_f
    ref         -- any Lua var/table
)

See associated types:


XPLMWindowSetTouchEventHandler

function

XPLMWindowSetTouchEventHandler(
    window,     -- XPLMWindowID
    handler,    -- see XPLMTouchEvent_f
    ref         -- any Lua var/table
)

See associated types: