Skip to content

C++ class: NativePainter

Index · Français

Description

Painter adapter for a Window.

Qualified name : gaspardos::gui::NativePainter.

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

When to use it

Draw widgets in an actual GaspardOS window.

Simple program example

#include "gui.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;
    gaspardos::gui::NativePainter painter(window);
    if (painter.text(10, 10, 0x202020, "hello") < 0)
        return 1;
    return window.close() == 0 ? 0 : 1;
}

Building from Windows

Save the program above as build/api-examples/NativePainter.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/NativePainter.cpp build/api-examples/syscall.o -o build/api-examples/NativePainter-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

explicit NativePainter(Window& window)

Keep a window reference; it must outlive the painter.

int64_t fill(int x, int y, int w, int h, uint32_t color)

Build Drawing and call Window::fill; same errors.

int64_t text(int x, int y, uint32_t color, const char* value)

Copy at most 127 bytes, NUL-terminate; UTF-8 splitting is possible.

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.