Skip to content

C++ class: Window

Index · Français

Description

Noncopyable native x64 window with asynchronous creation.

Qualified name : gaspardos::Window.

Header : bindings/cpp/gaspardos.hpp. C++98.

When to use it

Create a window, consume READY, then draw.

Simple program example

#include "gaspardos.hpp"
#include <cstdio>
#include <cstring>

int main()
{
    gaspardos::Window  window;
    GO64_WindowOptions options = {};
    options.width              = 1000;
    options.height             = 700;
    std::strcpy(options.title, "Example");
    if (window.create(options) < 0)
        return 1;
    for (unsigned i = 0; i < 10000 && !window.ready(); ++i)
    {
        GO64_Event event  = {};
        int64_t    result = window.event(event);
        if (result < 0 && result != -11)
            return 1;
        if (result == 0 && (event.type == GO64_ERROR || event.type == 15))
            return 1;
        GO64_yield();
    }
    if (!window.ready())
        return 1;
    GO64_Drawing drawing = {};
    drawing.width        = 200;
    drawing.height       = 100;
    if (window.fill(drawing) < 0)
        return 1;
    return window.close() == 0 ? 0 : 1;
}

Building from Windows

Save the program above as build/api-examples/Window.cpp from the repository root. Create the directory if necessary.

PowerShell — from the repository root:

New-Item -ItemType Directory -Force build/api-examples | Out-Null
& .\build-x64-install\bin\x86_64-gaspardos-gcc.exe -std=gnu1x -O2 -mno-red-zone -c bindings/native/gaspardos_x64_syscall.c -o build/api-examples/syscall.o
if ($LASTEXITCODE -ne 0) { throw "C compilation failed" }
& .\build-x64-install\bin\x86_64-gaspardos-g++.exe -std=c++98 -O2 -Ibindings/cpp build/api-examples/Window.cpp build/api-examples/syscall.o -o build/api-examples/Window-x64.elf
if ($LASTEXITCODE -ne 0) { throw "C++ compilation/link failed" }

Run the ELF on GaspardOS, not Windows. The driver supplies CRT and libraries. Prepare the required volumes/services; examples bound their waits and may exit on backpressure rather than retry. Successful compilation does not validate kernel execution.

The headers, implementation files, native wrappers and complete examples are available under Source files.

Class methods

Window()

Handle -1 and ready false.

~Window()

Try destruction once.

int64_t handle() const

Raw handle.

int64_t close()

Destroy; clear ready on success; retain handle on failure.

bool ready() const

True after consuming GO64_READY, false after GO64_ERROR.

int64_t create(const GO64_WindowOptions& options)

Pass options to syscall; handle or error; -16 if already created.

int64_t event(GO64_Event& e, bool wait = false)

Poll by default; wait=true waits according to the kernel; -9 when closed. Update ready.

int64_t fill(const GO64_Drawing& d)

GO64_Drawing rectangle; -9 when closed, -11 before READY.

int64_t text(const GO64_Drawing& d)

NUL-terminated text (128 bytes in Drawing); same conditions as fill.

int64_t focus()

Request focus; -9 when closed.

int64_t blit(const GO64_Blit& tile)

Copy an RGBX8888 tile (at most 256 × 256) into the UI queue using syscall 146. -9 when closed, -11 before READY or on backpressure; zero means copied and accepted. For a full image use FramebufferPresenter.

Native contract

LP64 ABI, 32-bit wchar_t, no packing. Native negative results are not errno. Handle -11 with yield and an application limit. Referenced objects must outlive their users; do not copy handle owners. File uses stdio/errno and invalidates its stream on close, even on error.