gfx reference
The gfx package: gfx.
gfx
function Available
offer fun Available() -> bool uses unsafeWhether this build can open a window at all.
function Backend
offer fun Backend() -> text uses unsafeWhich backend it is: "cocoa", "win32", "x11" or "none".
function Time
offer fun Time() -> f64 uses unsafeSeconds from a clock that does not jump.
function Sleep
offer fun Sleep(seconds: f64) uses unsafeWaits, which is what a frame loop does with the time it has left.
struct Event
offer struct EventWhat happened.
One struct for every kind, laid out exactly as the C one: a flat shape costs a few unused fields and saves every program from taking a tagged union apart.
field kind
var kind: s32 = 0field key
var key: s32 = 0A key for a key event, a button for a mouse one.
field x
var x: s32 = 0field y
var y: s32 = 0field scroll_x
var scroll_x: f64 = 0.0field scroll_y
var scroll_y: f64 = 0.0field width
var width: s32 = 0field height
var height: s32 = 0field modifiers
var modifiers: u32 = 0field code_point
var code_point: u32 = 0What was typed, for a kText event.
field repeat
var repeat: s32 = 0constant kNone
offer const kNone: s32 = 0constant kClosed
offer const kClosed: s32 = 1constant kResized
offer const kResized: s32 = 2constant kPressed
offer const kPressed: s32 = 3constant kReleased
offer const kReleased: s32 = 4constant kMouseDown
offer const kMouseDown: s32 = 5constant kMouseUp
offer const kMouseUp: s32 = 6constant kMouseMoved
offer const kMouseMoved: s32 = 7constant kScrolled
offer const kScrolled: s32 = 8constant kText
offer const kText: s32 = 9constant kFocus
offer const kFocus: s32 = 10constant kBlur
offer const kBlur: s32 = 11constant kDropped
offer const kDropped: s32 = 12Files were dropped on the window: key is how many, and
Window.DropPath answers each one.
constant kScaleChanged
offer const kScaleChanged: s32 = 13The pixel scale changed (another display, a new setting): scroll_x
is the new scale.
constant kGamepadConnected
offer const kGamepadConnected: s32 = 14A pad appeared or went away: key is its slot, 0 to 3.
constant kGamepadDisconnected
offer const kGamepadDisconnected: s32 = 15constant kMouseLeft
offer const kMouseLeft: s32 = 1constant kMouseRight
offer const kMouseRight: s32 = 2constant kMouseMiddle
offer const kMouseMiddle: s32 = 3constant kModShift
offer const kModShift: u32 = 1constant kModControl
offer const kModControl: u32 = 2constant kModAlt
offer const kModAlt: u32 = 4constant kModSuper
offer const kModSuper: u32 = 8constant kKeyA
offer const kKeyA: s32 = 1constant kKeyB
offer const kKeyB: s32 = 2constant kKeyC
offer const kKeyC: s32 = 3constant kKeyD
offer const kKeyD: s32 = 4constant kKeyE
offer const kKeyE: s32 = 5constant kKeyF
offer const kKeyF: s32 = 6constant kKeyG
offer const kKeyG: s32 = 7constant kKeyH
offer const kKeyH: s32 = 8constant kKeyI
offer const kKeyI: s32 = 9constant kKeyJ
offer const kKeyJ: s32 = 10constant kKeyK
offer const kKeyK: s32 = 11constant kKeyL
offer const kKeyL: s32 = 12constant kKeyM
offer const kKeyM: s32 = 13constant kKeyN
offer const kKeyN: s32 = 14constant kKeyO
offer const kKeyO: s32 = 15constant kKeyP
offer const kKeyP: s32 = 16constant kKeyQ
offer const kKeyQ: s32 = 17constant kKeyR
offer const kKeyR: s32 = 18constant kKeyS
offer const kKeyS: s32 = 19constant kKeyT
offer const kKeyT: s32 = 20constant kKeyU
offer const kKeyU: s32 = 21constant kKeyV
offer const kKeyV: s32 = 22constant kKeyW
offer const kKeyW: s32 = 23constant kKeyX
offer const kKeyX: s32 = 24constant kKeyY
offer const kKeyY: s32 = 25constant kKeyZ
offer const kKeyZ: s32 = 26constant kKey0
offer const kKey0: s32 = 27constant kKey1
offer const kKey1: s32 = 28constant kKey2
offer const kKey2: s32 = 29constant kKey3
offer const kKey3: s32 = 30constant kKey4
offer const kKey4: s32 = 31constant kKey5
offer const kKey5: s32 = 32constant kKey6
offer const kKey6: s32 = 33constant kKey7
offer const kKey7: s32 = 34constant kKey8
offer const kKey8: s32 = 35constant kKey9
offer const kKey9: s32 = 36constant kKeySpace
offer const kKeySpace: s32 = 37constant kKeyEnter
offer const kKeyEnter: s32 = 38constant kKeyEscape
offer const kKeyEscape: s32 = 39constant kKeyTab
offer const kKeyTab: s32 = 40constant kKeyBackspace
offer const kKeyBackspace: s32 = 41constant kKeyDelete
offer const kKeyDelete: s32 = 42constant kKeyLeft
offer const kKeyLeft: s32 = 43constant kKeyRight
offer const kKeyRight: s32 = 44constant kKeyUp
offer const kKeyUp: s32 = 45constant kKeyDown
offer const kKeyDown: s32 = 46constant kKeyShift
offer const kKeyShift: s32 = 47constant kKeyControl
offer const kKeyControl: s32 = 48constant kKeyAlt
offer const kKeyAlt: s32 = 49constant kKeySuper
offer const kKeySuper: s32 = 50constant kKeyF1
offer const kKeyF1: s32 = 51constant kKeyF2
offer const kKeyF2: s32 = 52constant kKeyF3
offer const kKeyF3: s32 = 53constant kKeyF4
offer const kKeyF4: s32 = 54constant kKeyF5
offer const kKeyF5: s32 = 55constant kKeyF6
offer const kKeyF6: s32 = 56constant kKeyF7
offer const kKeyF7: s32 = 57constant kKeyF8
offer const kKeyF8: s32 = 58constant kKeyF9
offer const kKeyF9: s32 = 59constant kKeyF10
offer const kKeyF10: s32 = 60constant kKeyF11
offer const kKeyF11: s32 = 61constant kKeyF12
offer const kKeyF12: s32 = 62constant kResizable
offer const kResizable: u32 = 1constant kGl
offer const kGl: u32 = 2Ask for a GL context. Without it the window is for pixels.
constant kHidden
offer const kHidden: u32 = 4class Window
offer class WindowA window, and the only thing that owns one.
IsOpen says whether there is one: a machine with no display answers
false rather than failing, which is what lets the same program run on
a server and say so.
field handle
var handle: *mut u8method deinit
deinitmethod IsOpen
fun IsOpen() -> boolmethod Poll
fun Poll() -> Event uses unsafeThe next thing that happened, or a kNone event when there is
nothing left this turn.
method ShowCursor
fun ShowCursor(visible: bool) uses unsafeShows or hides the pointer over this window.
method SetCursor
fun SetCursor(shape: s32) uses unsafeOne of the kCursor* shapes.
method LockCursor
fun LockCursor(locked: bool) -> bool uses unsafePins the pointer and reports only how far it moved, for mouse-look:
kMouseMoved events then carry the movement in scroll_x and
scroll_y. Says whether the system allowed it.
method SetFullscreen
fun SetFullscreen(on: bool) uses unsafeFull screen on and off.
method IsFullscreen
fun IsFullscreen() -> bool uses unsafemethod SetSize
fun SetSize(width: int, height: int) uses unsafeResizes the content, in pixels.
method SetMinSize
fun SetMinSize(width: int, height: int) uses unsafeThe smallest content size a person can drag the window to; zero for none.
method SetPosition
fun SetPosition(x: int, y: int) uses unsafemethod X
fun X() -> int uses unsafemethod Y
fun Y() -> int uses unsafemethod DropPath
fun DropPath(index: int) -> text uses unsafeA path from the last kDropped event, or an empty text past the
end.
method Width
fun Width() -> int uses unsafeThe content size in pixels, which on a dense display is not the size in points.
method Height
fun Height() -> int uses unsafemethod Scale
fun Scale() -> f64 uses unsafemethod SetTitle
fun SetTitle(title: text) uses unsafemethod Present
fun Present(canvas: &Canvas) uses unsafePuts a canvas on the screen, stretched to the window.
method StartGl
fun StartGl() -> bool uses unsafeMakes this window's GL context current, and says whether there is
one. Only a window opened with kGl has one.
method Swap
fun Swap(hold: bool) uses unsafeShows what GL drew. hold is whether to wait for the display,
which is what keeps a frame loop at the refresh rate.
method Close
fun Close() uses unsafefunction Open
offer fun Open(title: text, width: int, height: int, flags: u32) -> Window uses unsafeOpens a window. A closed one comes back when there is no backend or the system refused.
function GlProc
offer fun GlProc(name: text) -> *mut u8 uses unsafeThe address of a GL entry point, for a program that binds OpenGL itself. Zero when there is none.
function Clipboard
offer fun Clipboard() -> text uses unsafeWhat the clipboard holds, and how to put something there.
function SetClipboard
offer fun SetClipboard(value: text) uses unsafeclass Canvas
offer class CanvasA buffer of pixels, and what can be drawn into it.
0xAARRGGBB, one word per pixel, rows top to bottom: the one format
every backend here takes without converting. A canvas owns its
storage and gives it back when it goes out of scope.
field pixels
var pixels: []mut u32field width
var width: int = 0field height
var height: int = 0method deinit
deinitmethod Clear
fun Clear(colour: u32)method Set
fun Set(x: int, y: int, colour: u32)One pixel, ignored when it is outside: a drawing routine that clamps is one that can be called with anything.
method At
fun At(x: int, y: int) -> u32method Rect
fun Rect(x: int, y: int, w: int, h: int, colour: u32)A filled rectangle, clipped to the canvas.
method Frame
fun Frame(x: int, y: int, w: int, h: int, colour: u32)The outline of a rectangle.
method Line
fun Line(x0: int, y0: int, x1: int, y1: int, colour: u32)A line, by the oldest algorithm there is: integers only, one pixel a step, no gaps.
method Circle
fun Circle(cx: int, cy: int, radius: int, colour: u32)A filled circle, by the distance test: a radius this is used at is small, and the obvious loop is fast enough and obviously right.
method Blit
fun Blit(source: &Canvas, x: int, y: int)Copies another canvas in at x, y, skipping fully transparent
pixels.
function CanvasNew
offer fun CanvasNew(width: int, height: int) -> Canvas uses unsafeA canvas of width by height, all of it opaque black.
function Rgb
offer fun Rgb(red: int, green: int, blue: int) -> u32A colour from parts, each 0 to 255.
function Rgba
offer fun Rgba(red: int, green: int, blue: int, alpha: int) -> u32class Audio
offer class AudioThe default output, played from a queue.
A queue rather than a callback: a callback would be the system's audio thread calling into a tier that may still be compiling, and a program that makes sound has a frame loop to push from anyway (D155).
field handle
var handle: *mut u8field rate
var rate: int = 48000field channels
var channels: int = 2method deinit
deinitmethod IsOpen
fun IsOpen() -> boolmethod Queue
fun Queue(samples: []f32) -> int uses unsafeAdds interleaved frames, each sample between -1 and 1, and answers how many it took.
method Queued
fun Queued() -> int uses unsafeHow many frames are waiting, and how many more fit.
method Room
fun Room() -> int uses unsafemethod Close
fun Close() uses unsafefunction OpenAudio
offer fun OpenAudio(rate: int, channels: int) -> Audio uses unsafeOpens the default output. 48000 and two channels is what to ask for unless there is a reason not to.
constant kCursorArrow
offer const kCursorArrow: s32 = 0constant kCursorHand
offer const kCursorHand: s32 = 1constant kCursorText
offer const kCursorText: s32 = 2constant kCursorCrosshair
offer const kCursorCrosshair: s32 = 3constant kCursorResizeH
offer const kCursorResizeH: s32 = 4constant kCursorResizeV
offer const kCursorResizeV: s32 = 5constant kCursorResizeAll
offer const kCursorResizeAll: s32 = 6constant kMaxGamepads
offer const kMaxGamepads: int = 4constant kPadA
offer const kPadA: s32 = 0constant kPadB
offer const kPadB: s32 = 1constant kPadX
offer const kPadX: s32 = 2constant kPadY
offer const kPadY: s32 = 3constant kPadLeftBumper
offer const kPadLeftBumper: s32 = 4constant kPadRightBumper
offer const kPadRightBumper: s32 = 5constant kPadBack
offer const kPadBack: s32 = 6constant kPadStart
offer const kPadStart: s32 = 7constant kPadGuide
offer const kPadGuide: s32 = 8constant kPadLeftStick
offer const kPadLeftStick: s32 = 9constant kPadRightStick
offer const kPadRightStick: s32 = 10constant kPadDpadUp
offer const kPadDpadUp: s32 = 11constant kPadDpadDown
offer const kPadDpadDown: s32 = 12constant kPadDpadLeft
offer const kPadDpadLeft: s32 = 13constant kPadDpadRight
offer const kPadDpadRight: s32 = 14constant kAxisLeftX
offer const kAxisLeftX: s32 = 0constant kAxisLeftY
offer const kAxisLeftY: s32 = 1constant kAxisRightX
offer const kAxisRightX: s32 = 2constant kAxisRightY
offer const kAxisRightY: s32 = 3constant kAxisLeftTrigger
offer const kAxisLeftTrigger: s32 = 4constant kAxisRightTrigger
offer const kAxisRightTrigger: s32 = 5function GamepadConnected
offer fun GamepadConnected(index: int) -> bool uses unsafeWhether pad index (0 to 3) is plugged in. Events from Poll say
when that changes.
function GamepadName
offer fun GamepadName(index: int) -> text uses unsafefunction GamepadButton
offer fun GamepadButton(index: int, button: s32) -> bool uses unsafefunction GamepadAxis
offer fun GamepadAxis(index: int, axis: s32) -> f64 uses unsafefunction AxisNormalize
offer fun AxisNormalize(raw: int, low: int, high: int) -> f64Scales a raw reading from [low, high] to [-1, 1], clamped; zero
when the range is empty. The same arithmetic every backend does.
function Deadzone
offer fun Deadzone(value: f64, dead: f64) -> f64Ignores a stick resting near the middle: anything inside dead is
zero, and the rest is stretched so the output still reaches 1 and
does not jump at the edge of the zone.
function IsGamepadEvent
offer fun IsGamepadEvent(kind: s32) -> boolWhether an event kind belongs to a pad.
constant kDialogInfo
offer const kDialogInfo: s32 = 0constant kDialogWarning
offer const kDialogWarning: s32 = 1constant kDialogError
offer const kDialogError: s32 = 2constant kButtonsOk
offer const kButtonsOk: s32 = 0constant kButtonsOkCancel
offer const kButtonsOkCancel: s32 = 1constant kButtonsYesNo
offer const kButtonsYesNo: s32 = 2constant kAnswerUnavailable
offer const kAnswerUnavailable: s32 = 0constant kAnswerOk
offer const kAnswerOk: s32 = 1constant kAnswerCancel
offer const kAnswerCancel: s32 = 2constant kAnswerYes
offer const kAnswerYes: s32 = 3constant kAnswerNo
offer const kAnswerNo: s32 = 4function DialogsAvailable
offer fun DialogsAvailable() -> bool uses unsafefunction MessageBox
offer fun MessageBox(title: text, body: text, level: s32, buttons: s32) -> s32 uses unsafeShows a message and answers one of the kAnswer* constants.
function OpenFileDialog
offer fun OpenFileDialog(title: text) -> text? uses unsafeAsks for a file to open. Null when cancelled or unavailable.
function SaveFileDialog
offer fun SaveFileDialog(title: text, name: text) -> text? uses unsafeAsks where to save, starting from name. Null when cancelled or
unavailable.