C API: Player editor module (sona_editor.h)¶
An optional library, sona_editor: the player-facing editor, the same screens as 360sona.com's, drawn by the SDK for keyboard, gamepad, mouse and touch. Include sona_editor.h and link sona_editor. The guide: Player editor.
sona_editor_defaults¶
void sona_editor_defaults(sona_editor_options *o);
| Parameter and type | Meaning |
|---|---|
osona_editor_options * |
The sona_editor_options to fill with the defaults (required) |
Returns Nothing.
Example:
sona_editor_options x_editor_options;
memset(&x_editor_options, 0, sizeof x_editor_options);
x_editor_options.size = sizeof x_editor_options;
sona_editor_defaults(&x_editor_options);
size set, 1280 x 720 (sona_editor_resize changes it), seed 1, everything else zero.
sona_editor_theme_defaults¶
void sona_editor_theme_defaults(sona_editor_theme *t, uint32_t which);
| Parameter and type | Meaning |
|---|---|
tsona_editor_theme * |
The sona_editor_theme to fill with the defaults (required) |
whichuint32_t |
Which built-in theme |
Returns Nothing.
Example:
sona_editor_theme x_editor_theme;
memset(&x_editor_theme, 0, sizeof x_editor_theme);
x_editor_theme.size = sizeof x_editor_theme;
sona_editor_theme_defaults(&x_editor_theme, 0);
which: SONA_EDITOR_THEME_LIGHT (360sona.com's editor) or _DARK (the console slate).
sona_editor_open¶
sona_result sona_editor_open(sona_ctx *ctx, const sona_editor_options *o,
const sona_editor_theme *theme,
sona_editor **out);
| Parameter and type | Meaning |
|---|---|
ctxsona_ctx * |
The context (required) |
oconst sona_editor_options * |
The options, a sona_editor_options (required) |
themeconst sona_editor_theme * |
A sona_editor_theme (required) |
outsona_editor ** |
Receives the new editor (required) |
Returns SONA_OK. Errors SONA_E_ARGUMENT, SONA_E_MEMORY, SONA_E_CORRUPT (what each means).
theme NULL: the light (site) theme. SONA_E_ARGUMENT without a catalogue, for MODE_WARDROBE without a start manifest, or a start manifest that does not parse; SONA_E_CORRUPT for font bytes that do not load.
sona_editor_close¶
void sona_editor_close(sona_editor *ed);
| Parameter and type | Meaning |
|---|---|
edsona_editor * |
The editor (required) |
Returns Nothing.
Removes its avatars from the ctx.
sona_editor_set_theme¶
sona_result sona_editor_set_theme(sona_editor *ed,
const sona_editor_theme *theme);
| Parameter and type | Meaning |
|---|---|
edsona_editor * |
The editor (required) |
themeconst sona_editor_theme * |
A sona_editor_theme (required) |
Returns SONA_OK. Errors SONA_E_ARGUMENT, SONA_E_MEMORY (what each means).
Changes the colours and sizes from the next frame. NULL: the light (site) theme.
sona_editor_resize¶
sona_result sona_editor_resize(sona_editor *ed, uint32_t width,
uint32_t height);
| Parameter and type | Meaning |
|---|---|
edsona_editor * |
The editor (required) |
widthuint32_t |
The picture's width in pixels |
heightuint32_t |
The picture's height in pixels |
Returns SONA_OK. Errors SONA_E_ARGUMENT, SONA_E_MEMORY (what each means).
The editor's size in pixels, the size of the target it is drawn into.
sona_editor_feed¶
sona_result sona_editor_feed(sona_editor *ed, const sona_editor_input *in);
| Parameter and type | Meaning |
|---|---|
edsona_editor * |
The editor (required) |
inconst sona_editor_input * |
A sona_editor_input (required) |
Returns SONA_OK. Errors SONA_E_ARGUMENT (what each means).
One input event (SONA_EDITOR_IN_*): a gamepad button or axis, a key, a typed character for the search box, a pointer or touch, or the wheel.
sona_editor_update¶
uint32_t sona_editor_update(sona_editor *ed, double dt);
| Parameter and type | Meaning |
|---|---|
edsona_editor * |
The editor (required) |
dtdouble |
Seconds since the last call |
Returns uint32_t.
Advances dt seconds: stick repeat, animations, avatar builds and (unless HOST_UPDATES) sona_update on the ctx. Returns SONA_EDITOR_RUNNING, _DONE or _CANCELLED (and keeps returning it).
sona_editor_status¶
uint32_t sona_editor_status(const sona_editor *ed);
| Parameter and type | Meaning |
|---|---|
edconst sona_editor * |
The editor (required) |
Returns uint32_t.
SONA_EDITOR_RUNNING, _DONE or _CANCELLED, as the last sona_editor_update returned.
sona_editor_result¶
sona_result sona_editor_result(const sona_editor *ed,
uint8_t out[SONA_MANIFEST_BYTES]);
| Parameter and type | Meaning |
|---|---|
edconst sona_editor * |
The editor (required) |
outuint8_t [SONA_MANIFEST_BYTES] |
Receives the manifest's 1,000 bytes (required) |
Returns SONA_OK. Errors SONA_E_ARGUMENT (what each means).
The avatar as it stands (at any time): SONA_MANIFEST_BYTES. After CANCELLED it is the start manifest.
sona_editor_set_search¶
sona_result sona_editor_set_search(sona_editor *ed, const char *text);
| Parameter and type | Meaning |
|---|---|
edsona_editor * |
The editor (required) |
textconst char * |
The search text, UTF-8; NULL clears it (required) |
Returns SONA_OK. Errors SONA_E_ARGUMENT (what each means).
The search box of the wardrobe and the item screens, for hosts with an on-screen keyboard (UTF-8; NULL clears).
sona_editor_set_screen¶
sona_result sona_editor_set_screen(sona_editor *ed, uint32_t screen);
| Parameter and type | Meaning |
|---|---|
edsona_editor * |
The editor (required) |
screenuint32_t |
A SONA_EDITOR_SCREEN_* |
Returns SONA_OK. Errors SONA_E_ARGUMENT (what each means).
Moves to a screen of the mode (a deprecated id to the screen that took its place). SONA_E_ARGUMENT for one the mode does not have, SONA_EDITOR_SCREEN_LOOKS in SONA_EDITOR_MODE_FULL among them.
sona_editor_screen_get¶
uint32_t sona_editor_screen_get(const sona_editor *ed);
| Parameter and type | Meaning |
|---|---|
edconst sona_editor * |
The editor (required) |
Returns uint32_t.
The screen shown now.
sona_editor_screens¶
uint32_t sona_editor_screens(const sona_editor *ed, uint32_t *out,
uint32_t cap);
| Parameter and type | Meaning |
|---|---|
edconst sona_editor * |
The editor (required) |
outuint32_t * |
Receives the values (required) |
capuint32_t |
How many entries out holds |
Returns uint32_t.
The mode's screens in tab order: writes up to cap of them (out may be NULL) and returns how many there are.
sona_editor_busy¶
int sona_editor_busy(const sona_editor *ed);
| Parameter and type | Meaning |
|---|---|
edconst sona_editor * |
The editor (required) |
Returns int.
1 while an avatar is still building (the shown one or a change on its way); thumbnails do not count. A change that fails to build leaves the last avatar that did on screen; when the first one fails, nothing shows and busy is 0.
sona_editor_build_failures¶
uint32_t sona_editor_build_failures(const sona_editor *ed);
| Parameter and type | Meaning |
|---|---|
edconst sona_editor * |
The editor (required) |
Returns uint32_t.
How many avatar builds failed since open (the screen reader is told each time).
sona_editor_avatar¶
sona_avatar *sona_editor_avatar(const sona_editor *ed);
| Parameter and type | Meaning |
|---|---|
edconst sona_editor * |
The editor (required) |
Returns sona_avatar *.
The avatar on the editor's stage now, or NULL while the first one builds. It is the editor's: read it or hide it, never remove it. Each choice in the editor makes a new one, so ask again each frame. A host that draws the avatar layer itself uses it to fade the stage's avatar in and out.
sona_editor_undo¶
int sona_editor_undo(sona_editor *ed, int redo);
| Parameter and type | Meaning |
|---|---|
edsona_editor * |
The editor (required) |
redoint |
1 for redo, 0 for undo |
Returns int.
Undoes the last change (redo 0) or redoes the last undone one (redo 1), for a host that draws the stage's own
undo and redo buttons. Returns 1 when it stepped, 0 when there was nothing to step to. The editor keeps 32 steps.
sona_editor_can_undo¶
int sona_editor_can_undo(const sona_editor *ed, int redo);
| Parameter and type | Meaning |
|---|---|
edconst sona_editor * |
The editor (required) |
redoint |
1 for redo, 0 for undo |
Returns int.
1 when sona_editor_undo with the same redo would step: use it to grey out the buttons.
sona_editor_zoom¶
double sona_editor_zoom(sona_editor *ed, double set);
| Parameter and type | Meaning |
|---|---|
edsona_editor * |
The editor (required) |
setdouble |
A matched set's index |
Returns double.
The stage's zoom: 1 is the editor's own framing, from 0.6 to 3. A set above 0 sets it (clamped to that range);
0 only reads it. Returns the zoom now.
sona_editor_turn¶
void sona_editor_turn(sona_editor *ed, double degrees);
| Parameter and type | Meaning |
|---|---|
edsona_editor * |
The editor (required) |
degreesdouble |
How far to turn the avatar, degrees |
Returns Nothing.
Turns the avatar on the stage by degrees, as a drag across the stage does.
sona_editor_view¶
sona_result sona_editor_view(const sona_editor *ed, sona_view *out);
| Parameter and type | Meaning |
|---|---|
edconst sona_editor * |
The editor (required) |
outsona_view * |
Receives the sona_view (required) |
Returns SONA_OK. Errors SONA_E_ARGUMENT (what each means).
The camera the avatar layer is drawn with (framed into avatar_rect of the full target).
sona_editor_draw¶
sona_result sona_editor_draw(sona_editor *ed, sona_renderer *r,
const sona_target *t,
const sona_draw_options *opts);
| Parameter and type | Meaning |
|---|---|
edsona_editor * |
The editor (required) |
rsona_renderer * |
The renderer (required) |
tconst sona_target * |
Where the frame lands, a sona_target (required) |
optsconst sona_draw_options * |
The options, a sona_draw_options (NULL: the defaults) |
Returns SONA_OK. Errors SONA_E_ARGUMENT, SONA_E_UNSUPPORTED, SONA_E_LIMIT, SONA_E_MEMORY, SONA_E_CONTEXT (what each means).
The editor into t: sona_draw with the editor's view and the theme's background, without the credit (the UI draws it), and the UI layer over it as r's overlay (rasterised on the CPU where it changed, uploaded where it changed, blended by the renderer; r has no overlay again afterwards); then up to two pending thumbnails (sona_item_preview_snapshot and sona_snapshot on r). opts NULL: defaults; its clear and the NO_CREDIT flag are the editor's. The UI is drawn at the editor's size over the whole target: resize the editor to the target.
sona_editor_draw_avatar¶
sona_result sona_editor_draw_avatar(sona_editor *ed, sona_renderer *r,
const sona_target *t,
const sona_draw_options *opts);
| Parameter and type | Meaning |
|---|---|
edsona_editor * |
The editor (required) |
rsona_renderer * |
The renderer (required) |
tconst sona_target * |
Where the frame lands, a sona_target (required) |
optsconst sona_draw_options * |
The options, a sona_draw_options (required) |
Returns SONA_OK. Errors SONA_E_ARGUMENT, SONA_E_UNSUPPORTED, SONA_E_LIMIT, SONA_E_MEMORY, SONA_E_CONTEXT (what each means).
The avatar layer alone (and the thumbnails), for a host that draws the UI layer with its own 2D pass.
sona_editor_thumbnails¶
uint32_t sona_editor_thumbnails(sona_editor *ed, sona_renderer *r,
uint32_t budget);
| Parameter and type | Meaning |
|---|---|
edsona_editor * |
The editor (required) |
rsona_renderer * |
The renderer (required) |
budgetuint32_t |
How many pictures to draw this call |
Returns uint32_t.
Renders up to budget pending thumbnails on r, for hosts that draw the avatar layer with their own sona_draw.
sona_editor_draw_data_get¶
sona_result sona_editor_draw_data_get(sona_editor *ed,
sona_editor_draw_data *out);
| Parameter and type | Meaning |
|---|---|
edsona_editor * |
The editor (required) |
outsona_editor_draw_data * |
Receives the sona_editor_draw_data (required) |
Returns SONA_OK. Errors SONA_E_ARGUMENT, SONA_E_MEMORY (what each means).
The UI layer as of the last sona_editor_update. Pointers stay valid until the next update, resize or close.
sona_editor_texture_get¶
sona_result sona_editor_texture_get(sona_editor *ed, uint32_t id,
sona_editor_texture *out);
| Parameter and type | Meaning |
|---|---|
edsona_editor * |
The editor (required) |
iduint32_t |
The id, as the call that made it gave it |
outsona_editor_texture * |
Receives the sona_editor_texture (required) |
Returns SONA_OK. Errors SONA_E_ARGUMENT (what each means).
A texture the draw data names by id, with its pixels (straight RGBA8, owned by the editor) and the rectangle that changed since an older revision, for a host that draws the UI layer itself.
sona_editor_render_ui¶
sona_result sona_editor_render_ui(sona_editor *ed, uint8_t *rgba,
uint32_t width, uint32_t height,
uint32_t stride, int over);
| Parameter and type | Meaning |
|---|---|
edsona_editor * |
The editor (required) |
rgbauint8_t * |
Receives straight RGBA8, row 0 at the top (required) |
widthuint32_t |
The picture's width in pixels |
heightuint32_t |
The picture's height in pixels |
strideuint32_t |
Bytes from one row to the next |
overint |
1 to blend over what rgba holds, 0 to replace it |
Returns SONA_OK. Errors SONA_E_ARGUMENT, SONA_E_MEMORY (what each means).
The UI layer rasterised on the CPU into width x height straight RGBA8 (stride in bytes, 0: width * 4). over 1: blended over what rgba holds (a snapshot of the avatar layer); 0: cleared to transparent first.
sona_editor_snapshot¶
sona_result sona_editor_snapshot(sona_editor *ed, sona_renderer *r,
uint8_t *rgba);
| Parameter and type | Meaning |
|---|---|
edsona_editor * |
The editor (required) |
rsona_renderer * |
The renderer (required) |
rgbauint8_t * |
Receives straight RGBA8, row 0 at the top (required) |
Returns SONA_OK. Errors SONA_E_ARGUMENT, SONA_E_UNSUPPORTED, SONA_E_LIMIT, SONA_E_MEMORY, SONA_E_CONTEXT, SONA_E_READBACK (what each means).
The whole picture into rgba (width * height * 4 of the editor's size): sona_snapshot of the avatar layer, then render_ui over it. For screenshots, tests and servers.
sona_editor_control_count¶
uint32_t sona_editor_control_count(const sona_editor *ed);
| Parameter and type | Meaning |
|---|---|
edconst sona_editor * |
The editor (required) |
Returns uint32_t.
Every control on screen, in reading order, and the focused one.
sona_editor_control_get¶
sona_result sona_editor_control_get(const sona_editor *ed, uint32_t index,
sona_editor_control *out);
| Parameter and type | Meaning |
|---|---|
edconst sona_editor * |
The editor (required) |
indexuint32_t |
Which one, from 0 |
outsona_editor_control * |
Receives the sona_editor_control (required) |
Returns SONA_OK. Errors SONA_E_ARGUMENT, SONA_E_NOT_FOUND (what each means).
Control index in reading order: its id, role, flags, rectangle, value, place in its group, label, value text and hint ("Wear it"), for a screen reader or a test.
sona_editor_focus_get¶
sona_result sona_editor_focus_get(const sona_editor *ed,
sona_editor_control *out);
| Parameter and type | Meaning |
|---|---|
edconst sona_editor * |
The editor (required) |
outsona_editor_control * |
Receives the sona_editor_control (required) |
Returns SONA_OK. Errors SONA_E_ARGUMENT, SONA_E_NOT_FOUND (what each means).
SONA_E_NOT_FOUND when nothing has focus (pointer-only use).
sona_editor_announcement¶
uint32_t sona_editor_announcement(sona_editor *ed, char *out, uint32_t cap);
| Parameter and type | Meaning |
|---|---|
edsona_editor * |
The editor (required) |
outchar * |
Receives the text, NUL-terminated (required) |
capuint32_t |
How many entries out holds |
Returns uint32_t.
What a screen reader should say since the last call ("Wardrobe, tab, 6 of 6", "Blue Hoodie, 3 of 120, worn"): copies it (UTF-8, NUL-terminated, cut at cap) and returns its length; 0 when nothing changed.
sona_editor_struct_size¶
uint32_t sona_editor_struct_size(const char *name);
| Parameter and type | Meaning |
|---|---|
nameconst char * |
A public struct's name (required) |
Returns uint32_t.
Example:
uint32_t x_got = sona_editor_struct_size("sona_config");
printf("sona_editor_struct_size: %lld\n", (long long)x_got);
sizeof a public struct of this header by name, for the bindings' layout checks; 0 when unknown.
sona_editor_struct_offset¶
uint32_t sona_editor_struct_offset(const char *struct_dot_field);
| Parameter and type | Meaning |
|---|---|
struct_dot_fieldconst char * |
"struct.field" (required) |
Returns uint32_t.
Example:
uint32_t x_got = sona_editor_struct_offset("example");
printf("sona_editor_struct_offset: %lld\n", (long long)x_got);
offsetof a field by "struct.field"; UINT32_MAX when unknown.
This page as Markdown · All the docs as one file (llms-full.txt)