A full audit of Reaktor's own sources: section banners, return-value and parameter notes, and descriptions of what a function does are gone. What stays records a library, OS or browser quirk, a threading or lifetime rule, or a license. Two comments that still named libdbus are corrected. Code is unchanged; the vendored nk_sdl3_renderer.h keeps its own comments. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1341 lines
45 KiB
C
1341 lines
45 KiB
C
#include <stdarg.h>
|
|
#include "internal.h"
|
|
#include "declare.h"
|
|
#include "anim.h"
|
|
#include "reaktor/launch.h"
|
|
#include "reaktor/main.h"
|
|
|
|
static const char *g_mode = "";
|
|
static const char *g_log;
|
|
static int g_closings, g_frames;
|
|
|
|
static void
|
|
note(const char *what)
|
|
{
|
|
FILE *f;
|
|
|
|
if (!g_log) return;
|
|
f = reaktor_fopen(g_log, "a");
|
|
if (!f) return;
|
|
fprintf(f, "%s\n", what);
|
|
fclose(f);
|
|
}
|
|
|
|
static void
|
|
notef(const char *fmt, ...)
|
|
{
|
|
char line[600];
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
SDL_vsnprintf(line, sizeof line, fmt, ap);
|
|
va_end(ap);
|
|
note(line);
|
|
}
|
|
|
|
static int
|
|
is(const char *mode)
|
|
{
|
|
return SDL_strcmp(g_mode, mode) == 0;
|
|
}
|
|
|
|
static int g_second;
|
|
static struct nk_rect g_field, g_button, g_link, g_combo;
|
|
|
|
static void push_key(App *app, SDL_EventType type, SDL_Keycode key);
|
|
static void push_text(App *app, const char *text);
|
|
static void picked(App *app, const char *const *paths, int count, void *user);
|
|
static void dialog_page(App *app);
|
|
|
|
static void
|
|
push_mouse(App *app, SDL_EventType type, float x, float y)
|
|
{
|
|
SDL_Event e;
|
|
|
|
SDL_zero(e);
|
|
e.type = type;
|
|
if (type == SDL_EVENT_MOUSE_MOTION) {
|
|
e.motion.windowID = SDL_GetWindowID(app->win);
|
|
e.motion.x = x;
|
|
e.motion.y = y;
|
|
} else {
|
|
e.button.windowID = SDL_GetWindowID(app->win);
|
|
e.button.button = SDL_BUTTON_LEFT;
|
|
e.button.down = type == SDL_EVENT_MOUSE_BUTTON_DOWN;
|
|
e.button.clicks = 1;
|
|
e.button.x = x;
|
|
e.button.y = y;
|
|
}
|
|
SDL_PushEvent(&e);
|
|
}
|
|
|
|
static void
|
|
push_click(App *app, float x, float y)
|
|
{
|
|
push_mouse(app, SDL_EVENT_MOUSE_MOTION, x, y);
|
|
push_mouse(app, SDL_EVENT_MOUSE_BUTTON_DOWN, x, y);
|
|
push_mouse(app, SDL_EVENT_MOUSE_BUTTON_UP, x, y);
|
|
}
|
|
|
|
static void
|
|
push_tap(App *app, SDL_Keycode key)
|
|
{
|
|
push_key(app, SDL_EVENT_KEY_DOWN, key);
|
|
push_key(app, SDL_EVENT_KEY_UP, key);
|
|
}
|
|
|
|
static void
|
|
floater_body(App *app, struct nk_context *ctx, int w, int h, void *user)
|
|
{
|
|
static int clicked;
|
|
|
|
(void)w;
|
|
if (SDL_strcmp((const char *)user, "Cover") == 0 && !clicked &&
|
|
nk_input_is_mouse_click_in_rect(&ctx->input, NK_BUTTON_LEFT,
|
|
nk_window_get_bounds(ctx))) {
|
|
clicked = 1;
|
|
note("clicked Cover");
|
|
}
|
|
nk_layout_row_dynamic(ctx, h > 120 ? 120.0f : 28.0f, 1);
|
|
if (reaktor_button_label(app, ctx, (const char *)user)) {
|
|
notef("pressed %s", (const char *)user);
|
|
}
|
|
}
|
|
|
|
static char g_modal_buf[32];
|
|
|
|
static int floater(App *app, const char *name, float w, float h, int modal);
|
|
|
|
static void
|
|
keys_body(App *app, struct nk_context *ctx, int w, int h, void *user)
|
|
{
|
|
(void)app; (void)w; (void)h; (void)user;
|
|
nk_layout_row_dynamic(ctx, 28.0f, 1);
|
|
nk_label(ctx, "keys", NK_TEXT_LEFT);
|
|
if (nk_input_is_key_pressed(&ctx->input, NK_KEY_ENTER)) note("Keys saw Enter");
|
|
}
|
|
|
|
static void
|
|
opener_body(App *app, struct nk_context *ctx, int w, int h, void *user)
|
|
{
|
|
(void)w; (void)h; (void)user;
|
|
nk_layout_row_dynamic(ctx, 28.0f, 1);
|
|
if (reaktor_button_label(app, ctx, "Open")) floater(app, "M2", 140.0f, 60.0f, 1);
|
|
if (reaktor_button_label(app, ctx, "Next")) note("pressed Next");
|
|
}
|
|
|
|
static void
|
|
slider_body(App *app, struct nk_context *ctx, int w, int h, void *user)
|
|
{
|
|
static float val, last;
|
|
unsigned id;
|
|
|
|
(void)w; (void)h; (void)user;
|
|
nk_layout_row_dynamic(ctx, 28.0f, 1);
|
|
id = reaktor_note_here(app, ctx, REAKTOR_A11Y_SLIDER, "floater slider", 0);
|
|
reaktor_slider_bar(app, ctx, id, &val, 0.0f, 10.0f, 1.0f);
|
|
if (val != last) note("floater slider moved");
|
|
last = val;
|
|
}
|
|
|
|
static void
|
|
field_body(App *app, struct nk_context *ctx, int w, int h, void *user)
|
|
{
|
|
static int first = 1;
|
|
|
|
(void)app; (void)w; (void)h; (void)user;
|
|
nk_layout_row_dynamic(ctx, 28.0f, 1);
|
|
if (first) nk_edit_focus(ctx, 0);
|
|
first = 0;
|
|
nk_edit_string_zero_terminated(ctx, NK_EDIT_FIELD, g_modal_buf,
|
|
sizeof g_modal_buf, nk_filter_default);
|
|
}
|
|
|
|
static int
|
|
floater(App *app, const char *name, float w, float h, int modal)
|
|
{
|
|
return reaktor_floater_open(app, &(reaktor_floater){
|
|
.title = name, .w = w, .h = h, .modal = modal,
|
|
.body = SDL_strcmp(name, "Field") == 0 ? field_body
|
|
: SDL_strcmp(name, "Slider") == 0 ? slider_body
|
|
: SDL_strcmp(name, "Keys") == 0 ? keys_body
|
|
: SDL_strcmp(name, "Opener") == 0 ? opener_body : floater_body,
|
|
.user = (void *)name });
|
|
}
|
|
|
|
static const char *
|
|
when(void)
|
|
{
|
|
return reaktor_floaters_modal() ? "under the modal" : "after it";
|
|
}
|
|
|
|
static void
|
|
said(const char *what)
|
|
{
|
|
notef("%s %s", what, when());
|
|
}
|
|
|
|
static void
|
|
hold_page(App *app, struct nk_context *ctx, int w, int h)
|
|
{
|
|
static char buf[32];
|
|
static int active;
|
|
static struct nk_rect item[2];
|
|
static float val, last;
|
|
static int was;
|
|
char line[64];
|
|
unsigned id;
|
|
int open;
|
|
|
|
nk_layout_row_static(ctx, 28.0f, 140, 1);
|
|
if (is("hold-combo-other")) {
|
|
reaktor_note_here(app, ctx, REAKTOR_A11Y_COMBOBOX, "X", 0);
|
|
if (nk_combo_begin_label(ctx, "X", nk_vec2(140.0f, 60.0f))) {
|
|
static int seen;
|
|
|
|
if (!seen) note("X opened");
|
|
seen = 1;
|
|
nk_layout_row_dynamic(ctx, 24.0f, 1);
|
|
nk_combo_item_label(ctx, "x", NK_TEXT_LEFT);
|
|
nk_combo_end(ctx);
|
|
}
|
|
}
|
|
g_field = nk_widget_bounds(ctx);
|
|
if ((is("hold-toast-page") || is("hold-fresh-key")) && g_frames == 1)
|
|
nk_edit_focus(ctx, 0);
|
|
if (is("hold-tab-field") || is("hold-tab-free"))
|
|
reaktor_note_here(app, ctx, REAKTOR_A11Y_TEXTBOX, "noted field", 0);
|
|
{
|
|
nk_flags st = nk_edit_string_zero_terminated(
|
|
ctx, (nk_flags)NK_EDIT_FIELD | (is("hold-fresh-key") ? (nk_flags)NK_EDIT_SIG_ENTER : 0),
|
|
buf, sizeof buf, nk_filter_default);
|
|
|
|
if ((st & NK_EDIT_ACTIVE) && !active && !is("hold-toast-page") &&
|
|
!is("hold-fresh-key")) {
|
|
active = 1;
|
|
said("field active");
|
|
}
|
|
if (is("hold-fresh-key") && (st & NK_EDIT_COMMITED)) {
|
|
note("committed");
|
|
g_second = floater(app, "Keys", 120.0f, 60.0f, 1);
|
|
}
|
|
}
|
|
g_button = nk_widget_bounds(ctx);
|
|
if (reaktor_button_label(app, ctx, "Page")) {
|
|
said("pressed Page");
|
|
if (is("hold-fresh")) g_second = floater(app, "Modal", 400.0f, 400.0f, 1);
|
|
if (is("hold-fresh-tab")) g_second = floater(app, "Modal", 100.0f, 50.0f, 1);
|
|
}
|
|
g_link = nk_widget_bounds(ctx);
|
|
if (reaktor_link_label(app, ctx, "link", 0)) said("pressed link");
|
|
g_combo = nk_widget_bounds(ctx);
|
|
if (is("hold-combo-keys"))
|
|
reaktor_note_here(app, ctx, REAKTOR_A11Y_COMBOBOX, "noted combo", 0);
|
|
open = 0;
|
|
if (nk_combo_begin_label(ctx, "combo", nk_vec2(140.0f, 80.0f))) {
|
|
open = 1;
|
|
nk_layout_row_dynamic(ctx, 24.0f, 1);
|
|
item[0] = nk_widget_bounds(ctx);
|
|
if (nk_combo_item_label(ctx, "first", NK_TEXT_LEFT)) said("picked first");
|
|
item[1] = nk_widget_bounds(ctx);
|
|
if (nk_combo_item_label(ctx, "second", NK_TEXT_LEFT)) said("picked second");
|
|
nk_combo_end(ctx);
|
|
}
|
|
if ((is("hold-combo-keys") || is("hold-combo-other")) && open != was) {
|
|
note(open ? "combo opened" : "combo closed");
|
|
was = open;
|
|
}
|
|
if (reaktor_link_label(app, ctx, "below", 0)) said("pressed below");
|
|
id = reaktor_note_here(app, ctx, REAKTOR_A11Y_SLIDER, "slider", 0);
|
|
reaktor_slider_bar(app, ctx, id, &val, 0.0f, 10.0f, 1.0f);
|
|
if (val != last) said("slider moved");
|
|
last = val;
|
|
|
|
if (is("hold-press")) {
|
|
if (g_frames == 3 || g_frames == 14)
|
|
push_mouse(app, SDL_EVENT_MOUSE_MOTION, g_button.x + 20.0f,
|
|
g_button.y + g_button.h * 0.5f);
|
|
if (g_frames == 4 || g_frames == 17)
|
|
push_click(app, g_link.x + 10.0f, g_link.y + g_link.h * 0.5f);
|
|
if (g_frames == 7 || g_frames == 17) {
|
|
notef("cursor %d", app->want_cursor);
|
|
}
|
|
if (g_frames == 7 || g_frames == 12)
|
|
push_click(app, g_field.x + 20.0f, g_field.y + g_field.h * 0.5f);
|
|
if (g_frames == 10) reaktor_floater_close(app, g_second);
|
|
}
|
|
if (is("hold-popup")) {
|
|
if (g_frames == 3)
|
|
push_click(app, g_combo.x + 20.0f, g_combo.y + g_combo.h * 0.5f);
|
|
if (g_frames == 6) g_second = floater(app, "Modal", 100.0f, 50.0f, 1);
|
|
if (g_frames == 9)
|
|
push_click(app, item[0].x + 10.0f, item[0].y + item[0].h * 0.5f);
|
|
if (g_frames == 12) reaktor_floater_close(app, g_second);
|
|
if (g_frames == 15)
|
|
push_click(app, item[1].x + 10.0f, item[1].y + item[1].h * 0.5f);
|
|
}
|
|
if (is("hold-raise") && g_frames == 3)
|
|
push_click(app, (w - 280.0f) * 0.5f + 8.0f, (h - 160.0f) * 0.5f + 8.0f);
|
|
if (is("hold-keys") && g_frames == 3) push_tap(app, SDLK_TAB);
|
|
if (is("hold-keys") && g_frames == 6) push_tap(app, SDLK_RETURN);
|
|
if (is("hold-reach") && (g_frames == 3 || g_frames == 6)) push_tap(app, SDLK_TAB);
|
|
if (is("hold-reach") && g_frames == 9) push_tap(app, SDLK_RETURN);
|
|
if (is("hold-click")) {
|
|
if (g_frames == 3) push_tap(app, SDLK_TAB);
|
|
if (g_frames == 6) g_second = floater(app, "Modal", 400.0f, 400.0f, 1);
|
|
if (g_frames == 9) push_tap(app, SDLK_RETURN);
|
|
}
|
|
if (is("hold-step") || is("hold-cover") || is("hold-enter")) {
|
|
int tabs = is("hold-step") ? 4 : is("hold-cover") ? 3 : 2;
|
|
|
|
if (g_frames >= 3 && g_frames < 3 + 2 * tabs && (g_frames - 3) % 2 == 0)
|
|
push_tap(app, SDLK_TAB);
|
|
if (is("hold-step") && g_frames == 14)
|
|
g_second = floater(app, "Modal", 100.0f, 50.0f, 1);
|
|
if (is("hold-cover") && g_frames == 14)
|
|
push_click(app, g_combo.x + 20.0f, g_combo.y + g_combo.h * 0.5f);
|
|
if (g_frames == 17)
|
|
push_tap(app, is("hold-step") ? SDLK_RIGHT : SDLK_RETURN);
|
|
if (is("hold-step") && g_frames == 19) reaktor_floater_close(app, g_second);
|
|
if (is("hold-step") && g_frames == 21) push_tap(app, SDLK_RIGHT);
|
|
}
|
|
if (is("hold-fresh-key") && g_frames == 3) push_tap(app, SDLK_RETURN);
|
|
if (is("hold-combo-other")) {
|
|
if (g_frames == 3) push_tap(app, SDLK_TAB);
|
|
if (g_frames == 6)
|
|
push_click(app, g_combo.x + 20.0f, g_combo.y + g_combo.h * 0.5f);
|
|
if (g_frames == 10) push_tap(app, SDLK_RETURN);
|
|
}
|
|
if (is("hold-modal-tab") || is("hold-fresh-tab")) {
|
|
if (g_frames == 3) push_tap(app, SDLK_TAB);
|
|
if (g_frames == 6) {
|
|
push_tap(app, SDLK_RETURN);
|
|
push_tap(app, SDLK_TAB);
|
|
}
|
|
if (g_frames == 12) push_tap(app, SDLK_RETURN);
|
|
}
|
|
if (is("hold-stack") && g_frames == 3) reaktor_floater_close(app, g_second);
|
|
if (is("hold-stack") && g_frames == 6)
|
|
push_click(app, (w - 140.0f) * 0.5f + 70.0f, (h - 60.0f) * 0.5f + 26.0f);
|
|
if ((is("hold-tab-field") || is("hold-tab-free")) && g_frames == 3)
|
|
push_tap(app, SDLK_TAB);
|
|
if (is("hold-combo-keys")) {
|
|
if (g_frames == 3 || g_frames == 5 || g_frames == 7) push_tap(app, SDLK_TAB);
|
|
if (g_frames == 10 || g_frames == 15) push_tap(app, SDLK_RETURN);
|
|
}
|
|
if (is("hold-step-floater")) {
|
|
if (g_frames == 3) push_tap(app, SDLK_TAB);
|
|
if (g_frames == 6) push_tap(app, SDLK_RIGHT);
|
|
}
|
|
if (is("hold-fresh") && g_frames == 3)
|
|
push_click(app, g_button.x + g_button.w * 0.5f, g_button.y + g_button.h * 0.5f);
|
|
if (is("hold-toast-floater") || is("hold-close-toast")) {
|
|
int closing = is("hold-close-toast");
|
|
|
|
if (g_frames == 2)
|
|
push_click(app, g_field.x + 20.0f, g_field.y + g_field.h * 0.5f);
|
|
if (g_frames == 5) push_text(app, "a");
|
|
if (g_frames == 7)
|
|
reaktor_toast(app, &(reaktor_toast_spec){ .text = "toast" });
|
|
if (closing && g_frames == 9)
|
|
g_second = floater(app, "Modal", 100.0f, 50.0f, 1);
|
|
if (closing && g_frames == 11)
|
|
push_mouse(app, SDL_EVENT_MOUSE_MOTION, g_field.x + 30.0f,
|
|
g_field.y + g_field.h * 0.5f);
|
|
if (closing && g_frames == 13) reaktor_floater_close(app, g_second);
|
|
if (g_frames == 16) push_text(app, "b");
|
|
if (g_frames == 20) {
|
|
notef("typed '%s', text input %d", buf, (int)SDL_TextInputActive(app->win));
|
|
}
|
|
}
|
|
if (is("hold-toast") || is("hold-toast-page")) {
|
|
if (g_frames == 2) push_mouse(app, SDL_EVENT_MOUSE_MOTION, 2.0f, 2.0f);
|
|
if (g_frames == 4) push_text(app, "a");
|
|
if (g_frames == 6)
|
|
reaktor_toast(app, &(reaktor_toast_spec){ .text = "toast" });
|
|
if (g_frames == 9) push_text(app, "b");
|
|
if (g_frames == 13) {
|
|
notef("typed '%s', text input %d", is("hold-toast") ? g_modal_buf : buf, (int)SDL_TextInputActive(app->win));
|
|
}
|
|
}
|
|
if (g_frames == 26) {
|
|
char want[32];
|
|
|
|
SDL_snprintf(want, sizeof want, "reaktor-floater-%d", g_second);
|
|
SDL_snprintf(line, sizeof line, "top %s",
|
|
ctx->end && SDL_strcmp(ctx->end->name_string, want) == 0
|
|
? "second" : "other");
|
|
if (is("hold-raise")) note(line);
|
|
reaktor_quit(app, 0);
|
|
}
|
|
reaktor_wake(app);
|
|
}
|
|
|
|
static char g_win_buf[64];
|
|
|
|
static void
|
|
window_page(App *app, struct nk_context *ctx, int w, int h, void *user)
|
|
{
|
|
static int frames;
|
|
|
|
(void)w; (void)h; (void)user;
|
|
frames++;
|
|
nk_layout_row_dynamic(ctx, 28.0f, 1);
|
|
if (frames == 1) nk_edit_focus(ctx, 0);
|
|
nk_edit_string_zero_terminated(ctx, NK_EDIT_FIELD, g_win_buf,
|
|
sizeof g_win_buf, nk_filter_default);
|
|
if (frames == 3)
|
|
push_text(app, "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e\xe3\x81\xae"
|
|
"\xe3\x83\x86\xe3\x82\xad");
|
|
if (frames == 10) {
|
|
notef("window text %d bytes, text input %d", (int)SDL_strlen(g_win_buf), (int)SDL_TextInputActive(app->win));
|
|
reaktor_quit(app, 0);
|
|
}
|
|
app->dirty = 1;
|
|
reaktor_wake(app);
|
|
}
|
|
|
|
static int g_win_frames, g_main_at, g_key_seen, g_win_open;
|
|
static float g_anim;
|
|
static char g_one_buf[16];
|
|
|
|
static void
|
|
win_page(App *app, struct nk_context *ctx, int w, int h, void *user)
|
|
{
|
|
int f = ++g_win_frames, more = f < 30;
|
|
|
|
(void)user;
|
|
if (is("win-hints") && f == 3) {
|
|
SDL_WindowFlags fl = SDL_GetWindowFlags(app->win);
|
|
SDL_Rect d;
|
|
int x, y, ww, wh;
|
|
|
|
SDL_GetDisplayUsableBounds(SDL_GetDisplayForWindow(app->win), &d);
|
|
SDL_GetWindowPosition(app->win, &x, &y);
|
|
SDL_GetWindowSize(app->win, &ww, &wh);
|
|
notef("borderless %d, utility %d, centered %d", !!(fl & SDL_WINDOW_BORDERLESS), !!(fl & SDL_WINDOW_UTILITY), SDL_abs(x + ww / 2 - (d.x + d.w / 2)) <= 1 && SDL_abs(y + wh / 2 - (d.y + d.h / 2)) <= 1);
|
|
reaktor_quit(app, 0);
|
|
}
|
|
if (is("win-keys")) {
|
|
REAKTOR_COLUMN(.w = (float)w, .h = (float)h, .gap = 4.0f) {
|
|
if (reaktor_button(&(reaktor_button_spec){
|
|
.label = "A",
|
|
.box = { .h = 28.0f, .flags = REAKTOR_LAY_FILL_X } }))
|
|
note("pressed A");
|
|
if (reaktor_button(&(reaktor_button_spec){
|
|
.label = "B",
|
|
.box = { .h = 28.0f, .flags = REAKTOR_LAY_FILL_X } }))
|
|
note("pressed B");
|
|
}
|
|
if (f == 3 || f == 6) push_tap(app, SDLK_TAB);
|
|
if (f == 9) push_tap(app, SDLK_RETURN);
|
|
if (f == 30) reaktor_quit(app, 0);
|
|
} else if (is("win-drop")) {
|
|
if (f == 3) {
|
|
SDL_Event e;
|
|
|
|
SDL_zero(e);
|
|
e.type = SDL_EVENT_DROP_FILE;
|
|
e.drop.windowID = SDL_GetWindowID(app->win);
|
|
e.drop.data = "dropped.txt";
|
|
SDL_PushEvent(&e);
|
|
}
|
|
if (f == 12) reaktor_quit(app, 0);
|
|
} else if (is("win-anim")) {
|
|
REAKTOR_COLUMN(.name = "Track", .w = (float)w, .h = (float)h) {
|
|
g_anim = reaktor_animate(reaktor_box_id(), 0, f >= 3 ? 100.0f : 0.0f,
|
|
300.0f, REAKTOR_EASE_LINEAR);
|
|
}
|
|
more = f < 3;
|
|
} else if (is("win-title")) {
|
|
if (f == 2) reaktor_set_title(app, "Retitled");
|
|
if (f == 8) {
|
|
notef("window title '%s', main '%s'", SDL_GetWindowTitle(app->win), SDL_GetWindowTitle(reaktor_main_app()->win));
|
|
reaktor_quit(app, 0);
|
|
}
|
|
} else if (is("win-theme")) {
|
|
static int want;
|
|
|
|
if (f == 2) {
|
|
want = !reaktor_main_app()->dark;
|
|
reaktor_set_theme(app, want ? REAKTOR_THEME_DARK : REAKTOR_THEME_LIGHT);
|
|
}
|
|
if (f == 10) {
|
|
notef("theme followed: main %s, window %s", reaktor_main_app()->dark == want ? "yes" : "no", app->dark == want ? "yes" : "no");
|
|
reaktor_quit(app, 0);
|
|
}
|
|
} else if (is("win-wake")) {
|
|
if (f == 5) g_main_at = g_frames;
|
|
if (f == 30) {
|
|
notef("main frames +%d", g_frames - g_main_at);
|
|
reaktor_quit(app, 0);
|
|
}
|
|
} else if (is("win-one-change")) {
|
|
nk_layout_row_dynamic(ctx, 28.0f, 1);
|
|
if (f == 1) nk_edit_focus(ctx, 0);
|
|
nk_edit_string_zero_terminated(ctx, NK_EDIT_FIELD, g_one_buf,
|
|
sizeof g_one_buf, nk_filter_default);
|
|
if (f == 3) {
|
|
push_text(app, "ab");
|
|
push_tap(app, SDLK_BACKSPACE);
|
|
}
|
|
if (f == 15) {
|
|
notef("field '%s'", g_one_buf);
|
|
reaktor_quit(app, 0);
|
|
}
|
|
} else if (is("win-drag")) {
|
|
more = 0;
|
|
} else if (is("win-picker") || is("win-picker-close")) {
|
|
if (f == 2)
|
|
note(reaktor_file_dialog_open(app, &(reaktor_file_dialog){
|
|
.chosen = picked }) ? "picker open" : "picker refused");
|
|
if (is("win-picker-close") && f == 4) {
|
|
reaktor_window_close(app, g_win_open);
|
|
note("window closing");
|
|
}
|
|
more = f < 4;
|
|
}
|
|
if (more) {
|
|
app->dirty = 1;
|
|
reaktor_wake(app);
|
|
}
|
|
}
|
|
|
|
static int
|
|
open_probe_window(App *app)
|
|
{
|
|
int hints = is("win-hints");
|
|
|
|
return reaktor_window_open(app, &(reaktor_window){
|
|
.window = { .title = "probe", .w = 240, .h = 120, .borderless = hints,
|
|
.centered = hints, .skip_taskbar = hints },
|
|
.page = win_page });
|
|
}
|
|
|
|
static int SDLCALL
|
|
report_anim(void *app)
|
|
{
|
|
SDL_Delay(1500);
|
|
notef("anim %.0f", (double)g_anim);
|
|
reaktor_quit((App *)app, 0);
|
|
return 0;
|
|
}
|
|
|
|
static int SDLCALL
|
|
count_drag(void *app)
|
|
{
|
|
int at;
|
|
|
|
SDL_Delay(1200);
|
|
at = g_win_frames;
|
|
SDL_Delay(3300);
|
|
notef("window frames +%d while dragged", g_win_frames - at);
|
|
reaktor_quit((App *)app, 0);
|
|
return 0;
|
|
}
|
|
|
|
static int SDLCALL
|
|
quit_after(void *app)
|
|
{
|
|
SDL_Delay(6000);
|
|
reaktor_quit((App *)app, 0);
|
|
return 0;
|
|
}
|
|
|
|
static const reaktor_a11y_node *
|
|
last_node(App *app, unsigned char role, const char *name)
|
|
{
|
|
const reaktor_a11y_node *t = app->a11y.node[1 - app->a11y.front];
|
|
int n = app->a11y.count[1 - app->a11y.front], i;
|
|
|
|
for (i = 0; i < n; i++)
|
|
if (t[i].role == role && t[i].name && SDL_strcmp(t[i].name, name) == 0) return &t[i];
|
|
return NULL;
|
|
}
|
|
|
|
static int
|
|
press_role(App *app, unsigned char role, const char *name)
|
|
{
|
|
const reaktor_a11y_node *t = last_node(app, role, name);
|
|
|
|
if (t) push_click(app, t->bounds.x + t->bounds.w * 0.5f, t->bounds.y + t->bounds.h * 0.5f);
|
|
return t != NULL;
|
|
}
|
|
|
|
static void
|
|
answered(App *app, int button, void *user)
|
|
{
|
|
(void)app; (void)user;
|
|
notef("answer %d", button);
|
|
}
|
|
|
|
static void
|
|
ticked(App *app, void *user)
|
|
{
|
|
static int n;
|
|
|
|
notef("tick %d %s", ++n, app == reaktor_main_app() ? "main" : "other");
|
|
if (n == 3) reaktor_timer_stop(*(unsigned *)user);
|
|
}
|
|
|
|
static void
|
|
posted(App *app, void *user)
|
|
{
|
|
(void)app;
|
|
note(SDL_IsMainThread() ? (const char *)user : "posted off the main thread");
|
|
}
|
|
|
|
static int SDLCALL
|
|
post_from_thread(void *app)
|
|
{
|
|
reaktor_post((App *)app, posted, "posted on the main thread");
|
|
return 0;
|
|
}
|
|
|
|
static const char *
|
|
cell(int row, int column, void *user)
|
|
{
|
|
static char text[20][8];
|
|
|
|
(void)column; (void)user;
|
|
SDL_snprintf(text[row], sizeof text[row], "row %d", row);
|
|
return text[row];
|
|
}
|
|
|
|
static int
|
|
row_shown(App *app, int row)
|
|
{
|
|
const reaktor_a11y_node *t;
|
|
char name[8];
|
|
|
|
SDL_snprintf(name, sizeof name, "row %d", row);
|
|
t = last_node(app, REAKTOR_A11Y_LISTITEM, name);
|
|
return t && !(t->state & REAKTOR_A11Y_OFFSCREEN);
|
|
}
|
|
|
|
static Uint64 g_saved_at;
|
|
|
|
static int
|
|
saved_file(int remove)
|
|
{
|
|
char *dir = SDL_GetPrefPath(NULL, "launchtest"), *path = NULL, *text = NULL;
|
|
int has = 0;
|
|
|
|
if (dir) SDL_asprintf(&path, "%ssettings.toml", dir);
|
|
if (path && remove) SDL_RemovePath(path);
|
|
else if (path) {
|
|
text = (char *)SDL_LoadFile(path, NULL);
|
|
has = text && SDL_strstr(text, "\"launchtest.key\" = \"on disk\"") != NULL;
|
|
}
|
|
SDL_free(text);
|
|
SDL_free(path);
|
|
SDL_free(dir);
|
|
return has;
|
|
}
|
|
|
|
static void
|
|
service_page(App *app, struct nk_context *ctx, int w, int h)
|
|
{
|
|
static const char *const buttons[2] = { "Keep", "Save" };
|
|
static unsigned repeat;
|
|
static int chosen = -1, said = -1;
|
|
static float share = 0.5f;
|
|
int split = is("split-keys") || is("split-vkeys");
|
|
|
|
(void)ctx;
|
|
if (is("ask") && g_frames == 2)
|
|
reaktor_ask(app, &(reaktor_question){ .text = "Save it?", .buttons = buttons,
|
|
.count = 2, .answered = answered });
|
|
if (is("ask") && g_frames == 6) note(press_role(app, REAKTOR_A11Y_BUTTON, "Save") ? "pressed" : "no button");
|
|
if (is("timer") && g_frames == 2) {
|
|
repeat = reaktor_timer(app, 50, 1, ticked, &repeat);
|
|
note(repeat ? "timer on" : "timer refused");
|
|
}
|
|
if (is("post") && g_frames == 2)
|
|
SDL_DetachThread(SDL_CreateThread(post_from_thread, "post", app));
|
|
if ((is("save-change") || is("save-timer")) && g_frames == 2) {
|
|
saved_file(1);
|
|
reaktor_setting_set("launchtest.key", "on disk");
|
|
note(saved_file(0) ? "written at once" : "not written yet");
|
|
g_saved_at = SDL_GetTicks();
|
|
}
|
|
if (is("save-timer") && g_saved_at && SDL_GetTicks() - g_saved_at > 600) {
|
|
note(saved_file(0) ? "written after the delay" : "still not written");
|
|
g_saved_at = 0;
|
|
saved_file(1);
|
|
reaktor_quit(app, 0);
|
|
}
|
|
if (is("settings-clear") && g_frames == 2) {
|
|
reaktor_setting_set("launchtest.key", "on disk");
|
|
reaktor_settings_save();
|
|
note(saved_file(0) ? "saved by hand" : "not saved");
|
|
reaktor_settings_clear();
|
|
note(!saved_file(0) && !reaktor_setting("launchtest.key") ? "cleared" : "still there");
|
|
reaktor_quit(app, 0);
|
|
}
|
|
if (is("save-change") && g_frames == 4) {
|
|
saved_file(1);
|
|
reaktor_quit(app, 0);
|
|
}
|
|
if (is("settings") && g_frames == 2) {
|
|
reaktor_setting_set("launchtest.key", "a=b");
|
|
reaktor_setting_set("launchtest.gone", "x");
|
|
reaktor_setting_set("launchtest.gone", NULL);
|
|
notef("setting %s %s", reaktor_setting("launchtest.key"), reaktor_setting("launchtest.gone") ? "kept" : "removed");
|
|
}
|
|
if (is("list") && g_frames == 4) {
|
|
const reaktor_a11y_node *t = last_node(app, REAKTOR_A11Y_LISTITEM, "row 1");
|
|
|
|
if (t) push_click(app, t->bounds.x + 10.0f, t->bounds.y + t->bounds.h * 0.5f);
|
|
}
|
|
if (is("list-keys") && (g_frames == 3 || g_frames == 4)) push_tap(app, SDLK_TAB);
|
|
if (is("list-keys") && g_frames >= 6 && g_frames < 30 && g_frames % 2 == 0)
|
|
push_tap(app, SDLK_DOWN);
|
|
if (is("list-keys") && g_frames == 50) {
|
|
notef("chosen %d, %s", chosen, row_shown(app, chosen) ? "in view" : "out of view");
|
|
}
|
|
if (split && (g_frames == 3 || g_frames == 5)) push_tap(app, SDLK_TAB);
|
|
if (split && (g_frames == 8 || g_frames == 10))
|
|
push_tap(app, is("split-vkeys") ? SDLK_DOWN : SDLK_RIGHT);
|
|
if (split && g_frames == 12) push_tap(app, is("split-vkeys") ? SDLK_UP : SDLK_LEFT);
|
|
if (split && g_frames == 30) {
|
|
notef("split %.2f", share);
|
|
}
|
|
if (is("list") && chosen != said) {
|
|
said = chosen;
|
|
notef("chosen %d", chosen);
|
|
}
|
|
if (g_frames > 60) reaktor_quit(app, 0);
|
|
REAKTOR_FREE(.w = (float)w, .h = (float)h) {
|
|
REAKTOR_COLUMN(.w = (float)w) {
|
|
reaktor_button(&(reaktor_button_spec){ .label = "Hover me",
|
|
.tooltip = "A tip" });
|
|
if (is("list"))
|
|
reaktor_list(&(reaktor_list_spec){ .name = "List", .count = 3,
|
|
.cell = cell, .selected = &chosen });
|
|
if (is("list-keys"))
|
|
reaktor_list(&(reaktor_list_spec){ .name = "List", .count = 20,
|
|
.cell = cell, .selected = &chosen,
|
|
.box = { .h = 100.0f } });
|
|
if (is("split-keys"))
|
|
REAKTOR_ROW(.h = 40.0f, .w = (float)w) {
|
|
REAKTOR_COLUMN(.weight = share, .flags = REAKTOR_LAY_FILL_Y) {}
|
|
reaktor_splitter(&(reaktor_splitter_spec){ .value = &share });
|
|
REAKTOR_COLUMN(.weight = 1.0f - share, .flags = REAKTOR_LAY_FILL_Y) {}
|
|
}
|
|
if (is("split-vkeys"))
|
|
REAKTOR_COLUMN(.h = 120.0f, .w = (float)w) {
|
|
REAKTOR_ROW(.weight = share, .flags = REAKTOR_LAY_FILL_X) {}
|
|
reaktor_splitter(&(reaktor_splitter_spec){ .value = &share,
|
|
.vertical = 1 });
|
|
REAKTOR_ROW(.weight = 1.0f - share, .flags = REAKTOR_LAY_FILL_X) {}
|
|
}
|
|
}
|
|
}
|
|
app->dirty = 1;
|
|
reaktor_wake(app);
|
|
}
|
|
|
|
static const char *
|
|
focused_name(App *app)
|
|
{
|
|
const reaktor_a11y_node *t = app->a11y.node[1 - app->a11y.front];
|
|
int n = app->a11y.count[1 - app->a11y.front], i;
|
|
|
|
for (i = 0; i < n; i++)
|
|
if (t[i].id == app->focus_id) return t[i].name ? t[i].name : "?";
|
|
return "nothing";
|
|
}
|
|
|
|
static const char *
|
|
expanded(App *app)
|
|
{
|
|
const reaktor_a11y_node *t = app->a11y.node[1 - app->a11y.front];
|
|
int n = app->a11y.count[1 - app->a11y.front], i;
|
|
|
|
for (i = 0; i < n; i++)
|
|
if (t[i].role == REAKTOR_A11Y_MENU && (t[i].state & REAKTOR_A11Y_EXPANDED) &&
|
|
t[i].name)
|
|
return t[i].name;
|
|
return "none";
|
|
}
|
|
|
|
static void
|
|
menu_page(App *app, struct nk_context *ctx, int w, int h)
|
|
{
|
|
static reaktor_bool wrap;
|
|
static const reaktor_menu_entry items[] = {
|
|
{ .label = "New", .keys = "Ctrl+N" },
|
|
{ .label = "Open", .disabled = 1 },
|
|
{ NULL },
|
|
{ .label = "Wrap", .checked = &wrap }
|
|
};
|
|
static const reaktor_menu_entry zoom[] = { { .label = "In" }, { .label = "Out" } };
|
|
static const reaktor_menu_entry view[] = {
|
|
{ .label = "Zoom", .items = zoom, .count = 2 }, { .label = "Reset" }
|
|
};
|
|
static const reaktor_menu menus[] = { { "File", items, 4 }, { "View", view, 2 } };
|
|
static const reaktor_menu_entry *pe;
|
|
static int pm = -1;
|
|
|
|
(void)ctx;
|
|
if (g_frames >= 3 && g_frames <= 9 && g_frames % 2 &&
|
|
SDL_strcmp(focused_name(app), "File") != 0)
|
|
push_tap(app, SDLK_TAB);
|
|
if (g_frames == 12 || g_frames == 22 || g_frames == 40 || g_frames == 54 ||
|
|
g_frames == 82)
|
|
push_tap(app, SDLK_RETURN);
|
|
if (g_frames == 18) push_tap(app, SDLK_DOWN);
|
|
if (g_frames == 46) push_tap(app, SDLK_ESCAPE);
|
|
if (g_frames == 60 || g_frames == 66 || g_frames == 76) push_tap(app, SDLK_RIGHT);
|
|
if (g_frames == 72) push_tap(app, SDLK_LEFT);
|
|
if (g_frames == 20 || g_frames == 30 || g_frames == 45 || g_frames == 52 ||
|
|
g_frames == 64 || g_frames == 90 || g_frames == 100 || g_frames == 108) {
|
|
notef("open %s, focus on %s, picked %s in %d, wrap %s", expanded(app), focused_name(app), pe ? pe->label : "nothing", pm, wrap ? "on" : "off");
|
|
}
|
|
if (g_frames == 94 || g_frames == 102) press_role(app, REAKTOR_A11Y_MENU, "File");
|
|
if (g_frames > 112) reaktor_quit(app, 0);
|
|
REAKTOR_FREE(.w = (float)w, .h = (float)h) {
|
|
REAKTOR_COLUMN(.w = (float)w) {
|
|
reaktor_button(&(reaktor_button_spec){ .label = "Before" });
|
|
reaktor_menubar(&(reaktor_menubar_spec){ .menus = menus, .count = 2,
|
|
.picked_menu = &pm, .picked = &pe });
|
|
}
|
|
}
|
|
app->dirty = 1;
|
|
reaktor_wake(app);
|
|
}
|
|
|
|
static const int g_tree_parent[6] = { -1, 0, 1, 1, -1, 4 };
|
|
static const char *g_tree_label[6] = { "A", "A1", "A1a", "A1b", "B", "B1" };
|
|
|
|
static int tree_parent(int n, void *u) { (void)u; return g_tree_parent[n]; }
|
|
static const char *tree_label(int n, void *u) { (void)u; return g_tree_label[n]; }
|
|
|
|
static void
|
|
tree_page(App *app, struct nk_context *ctx, int w, int h)
|
|
{
|
|
static unsigned char open[6];
|
|
static int sel = -1;
|
|
static const SDL_Keycode keys[] = { SDLK_TAB, SDLK_RIGHT, SDLK_RIGHT, SDLK_RIGHT,
|
|
SDLK_DOWN, SDLK_LEFT, SDLK_LEFT };
|
|
int k = (g_frames - 4) / 6;
|
|
|
|
(void)ctx;
|
|
if (g_frames >= 4 && (g_frames - 4) % 6 == 0 && k < (int)SDL_arraysize(keys))
|
|
push_tap(app, keys[k]);
|
|
if (g_frames >= 4 && (g_frames - 4) % 6 == 5 && k < (int)SDL_arraysize(keys)) {
|
|
notef("focus %s, selected %d, open %d%d%d%d%d%d", focused_name(app), sel, open[0], open[1], open[2], open[3], open[4], open[5]);
|
|
}
|
|
if (g_frames == 60) press_role(app, REAKTOR_A11Y_TREEITEM, "B");
|
|
if (g_frames == 66) {
|
|
const reaktor_a11y_node *t = last_node(app, REAKTOR_A11Y_TREEITEM, "B");
|
|
|
|
if (t) push_click(app, t->bounds.x + 15.0f, t->bounds.y + t->bounds.h * 0.5f);
|
|
}
|
|
if (g_frames == 72) {
|
|
notef("clicked: selected %d, B open %d", sel, open[4]);
|
|
}
|
|
if (g_frames > 76) reaktor_quit(app, 0);
|
|
REAKTOR_FREE(.w = (float)w, .h = (float)h) {
|
|
reaktor_tree(&(reaktor_tree_spec){ .name = "Tree", .count = 6,
|
|
.parent = tree_parent, .label = tree_label,
|
|
.open = open, .selected = &sel,
|
|
.box = { .w = (float)w, .h = (float)h } });
|
|
}
|
|
app->dirty = 1;
|
|
reaktor_wake(app);
|
|
}
|
|
|
|
static void
|
|
find_page(App *app, struct nk_context *ctx, int w, int h)
|
|
{
|
|
static char *text, run[601];
|
|
static int len, cap;
|
|
struct nk_window *pw = nk_window_find(ctx, "page");
|
|
|
|
if (g_frames == 3) {
|
|
SDL_memset(run, 'x', 600);
|
|
run[300] = '\n';
|
|
press_role(app, REAKTOR_A11Y_TEXTBOX, "Doc");
|
|
}
|
|
if (g_frames == 8) push_text(app, run);
|
|
if (g_frames == 70) {
|
|
notef("len %d, room %s", len, cap > len ? "kept" : "short");
|
|
reaktor_field_select(app, text, 10, 20);
|
|
}
|
|
if (g_frames == 84 && pw) {
|
|
notef("active %d, selected %d to %d", pw->edit.active, pw->edit.sel_start, pw->edit.sel_end);
|
|
}
|
|
if (g_frames > 88) reaktor_quit(app, 0);
|
|
REAKTOR_FREE(.w = (float)w, .h = (float)h) {
|
|
reaktor_field(&(reaktor_field_spec){ .heap = &text, .heap_cap = &cap, .len = &len,
|
|
.name = "Doc", .multiline = 1,
|
|
.line_numbers = 1,
|
|
.box = { .w = (float)w, .h = (float)h } });
|
|
}
|
|
app->dirty = 1;
|
|
reaktor_wake(app);
|
|
}
|
|
|
|
static void
|
|
spin_page(App *app, struct nk_context *ctx, int w, int h)
|
|
{
|
|
static const char *const items[] = { "a", "b", "c" };
|
|
static const SDL_Keycode keys[] = { SDLK_TAB, SDLK_RIGHT, SDLK_UP, SDLK_RIGHT,
|
|
SDLK_LEFT, SDLK_TAB, SDLK_LEFT };
|
|
static int one, two;
|
|
int k = (g_frames - 4) / 6;
|
|
|
|
(void)ctx;
|
|
if (g_frames >= 4 && (g_frames - 4) % 6 == 0 && k < (int)SDL_arraysize(keys))
|
|
push_tap(app, keys[k]);
|
|
if (g_frames == 50) {
|
|
notef("stops at %d, wraps to %d", one, two);
|
|
}
|
|
if (g_frames > 54) reaktor_quit(app, 0);
|
|
REAKTOR_FREE(.w = (float)w, .h = (float)h) {
|
|
REAKTOR_COLUMN(.w = (float)w) {
|
|
reaktor_spinner(&(reaktor_spinner_spec){ .name = "One", .items = items,
|
|
.count = 3, .chosen = &one });
|
|
reaktor_spinner(&(reaktor_spinner_spec){ .name = "Two", .items = items,
|
|
.count = 3, .chosen = &two,
|
|
.wrap = 1 });
|
|
}
|
|
}
|
|
app->dirty = 1;
|
|
reaktor_wake(app);
|
|
}
|
|
|
|
static void
|
|
date_page(App *app, struct nk_context *ctx, int w, int h)
|
|
{
|
|
static int y, m, d, hh = -1, mm;
|
|
static const SDL_Keycode keys[] = { SDLK_TAB, SDLK_RETURN, SDLK_DOWN, SDLK_LEFT,
|
|
SDLK_LEFT, SDLK_DOWN, SDLK_RETURN, SDLK_TAB,
|
|
SDLK_RETURN, SDLK_UP, SDLK_ESCAPE };
|
|
int k = (g_frames - 4) / 8;
|
|
|
|
(void)ctx;
|
|
if (g_frames >= 4 && (g_frames - 4) % 8 == 0 && k < (int)SDL_arraysize(keys))
|
|
push_tap(app, keys[k]);
|
|
if (g_frames == 16) note(d ? "set too early" : "open, not set");
|
|
if (g_frames == 60) {
|
|
notef("hour %d, focus on %s", hh, focused_name(app));
|
|
}
|
|
if (g_frames == 100) {
|
|
notef("after escape: hour %d, focus on %s", hh, focused_name(app));
|
|
}
|
|
if (g_frames > 104) reaktor_quit(app, 0);
|
|
REAKTOR_FREE(.w = (float)w, .h = (float)h) {
|
|
REAKTOR_ROW(.w = (float)w, .h = 30.0f) {
|
|
if (reaktor_date_pick(&(reaktor_date_spec){ .name = "Date", .year = &y,
|
|
.month = &m, .day = &d })) {
|
|
notef("set %04d-%02d-%02d", y, m, d);
|
|
}
|
|
reaktor_time_pick(&(reaktor_time_spec){ .name = "Time", .hour = &hh,
|
|
.minute = &mm });
|
|
}
|
|
}
|
|
app->dirty = 1;
|
|
reaktor_wake(app);
|
|
}
|
|
|
|
static int g_undo_v;
|
|
|
|
static void undo_minus(void *d) { g_undo_v -= *(int *)d; }
|
|
static void undo_plus(void *d) { g_undo_v += *(int *)d; }
|
|
|
|
static void
|
|
push_chord(App *app, SDL_Keycode key, SDL_Keymod mod)
|
|
{
|
|
SDL_Event e;
|
|
|
|
SDL_zero(e);
|
|
e.type = SDL_EVENT_KEY_DOWN;
|
|
e.key.windowID = SDL_GetWindowID(app->win);
|
|
e.key.key = key;
|
|
e.key.mod = mod;
|
|
e.key.down = true;
|
|
SDL_PushEvent(&e);
|
|
e.type = SDL_EVENT_KEY_UP;
|
|
e.key.down = false;
|
|
SDL_PushEvent(&e);
|
|
}
|
|
|
|
static void
|
|
undo_page(App *app)
|
|
{
|
|
static int one = 1;
|
|
|
|
if (g_frames == 2) {
|
|
reaktor_undo_step s = { "Add", undo_minus, undo_plus, NULL, &one, 0 };
|
|
|
|
reaktor_undo_push(app, &s); g_undo_v++;
|
|
s.label = "Type"; s.merge = 7;
|
|
reaktor_undo_push(app, &s); g_undo_v++;
|
|
reaktor_undo_push(app, &s); g_undo_v++;
|
|
reaktor_undo_group(app, 1);
|
|
s.label = "Paste"; s.merge = 0;
|
|
reaktor_undo_push(app, &s); g_undo_v++;
|
|
reaktor_undo_push(app, &s); g_undo_v++;
|
|
reaktor_undo_group(app, 0);
|
|
reaktor_undo_saved(app);
|
|
}
|
|
if (g_frames == 6 || g_frames == 12) push_chord(app, SDLK_Z, SDL_KMOD_CTRL);
|
|
if (g_frames == 18) push_chord(app, SDLK_Z, SDL_KMOD_CTRL | SDL_KMOD_SHIFT);
|
|
if (g_frames == 4 || g_frames == 16 || g_frames == 24) {
|
|
notef("value %d, undo %s, redo %s, %s", g_undo_v, reaktor_undo_label(app) ? reaktor_undo_label(app) : "-", reaktor_redo_label(app) ? reaktor_redo_label(app) : "-", reaktor_undo_dirty(app) ? "changed" : "saved");
|
|
}
|
|
if (g_frames > 28) reaktor_quit(app, 0);
|
|
app->dirty = 1;
|
|
reaktor_wake(app);
|
|
}
|
|
|
|
static void
|
|
print_body(App *app, struct nk_context *ctx, int index, int w, int h, void *user)
|
|
{
|
|
char line[48];
|
|
|
|
(void)app; (void)ctx; (void)user;
|
|
SDL_snprintf(line, sizeof line, "Page %d of 2", index + 1);
|
|
REAKTOR_FREE(.w = (float)w, .h = (float)h) {
|
|
REAKTOR_COLUMN(.w = (float)w, .gap = 12.0f, .ml = 48.0f, .mt = 48.0f) {
|
|
reaktor_label(&(reaktor_label_spec){ .text = line, .style = "h4" });
|
|
reaktor_label(&(reaktor_label_spec){
|
|
.text = "Printed by Reaktor: the same layout and pixels as on screen." });
|
|
reaktor_button(&(reaktor_button_spec){ .label = "A button on paper",
|
|
.box = { .w = 180.0f } });
|
|
}
|
|
}
|
|
}
|
|
|
|
static void
|
|
printed(App *app, int ok, void *user)
|
|
{
|
|
(void)app;
|
|
note(ok ? "printed" : "print failed");
|
|
(void)user;
|
|
}
|
|
|
|
static void
|
|
print_page_test(App *app)
|
|
{
|
|
if (g_frames == 3) {
|
|
char *pdf = NULL;
|
|
|
|
if (SDL_asprintf(&pdf, "%s.pdf", g_log ? g_log : "launchtest-print") < 0 ||
|
|
!reaktor_print_pdf(app, pdf,
|
|
&(reaktor_print_spec){ .title = "Test", .pages = 2,
|
|
.page = print_body, .done = printed }))
|
|
note("not queued");
|
|
SDL_free(pdf);
|
|
}
|
|
if (g_frames > 40) reaktor_quit(app, 0);
|
|
app->dirty = 1;
|
|
reaktor_wake(app);
|
|
}
|
|
|
|
static void
|
|
confirm_page(App *app)
|
|
{
|
|
SDL_Event e;
|
|
|
|
if (g_frames == 3) {
|
|
SDL_zero(e);
|
|
e.type = SDL_EVENT_WINDOW_CLOSE_REQUESTED;
|
|
e.window.windowID = SDL_GetWindowID(app->win);
|
|
SDL_PushEvent(&e);
|
|
}
|
|
if (g_frames == 10)
|
|
note(press_role(app, REAKTOR_A11Y_BUTTON, is("confirm") ? "Quit" : "Cancel") ? "asked"
|
|
: "not asked");
|
|
if (g_frames == 25) {
|
|
note("still running");
|
|
reaktor_quit(app, 0);
|
|
}
|
|
app->dirty = 1;
|
|
reaktor_wake(app);
|
|
}
|
|
|
|
static void
|
|
leak_page(App *app)
|
|
{
|
|
static int cycle, id;
|
|
static size_t rss0, priv0;
|
|
size_t rss, priv;
|
|
|
|
if (id) {
|
|
reaktor_window_close(app, id);
|
|
id = 0;
|
|
} else if (cycle < 210) {
|
|
id = open_probe_window(app);
|
|
if (++cycle == 10) reaktor_process_memory(&rss0, &priv0);
|
|
} else {
|
|
reaktor_process_memory(&rss, &priv);
|
|
notef("grew %d KB private over 200 windows", (int)(((long long)priv - (long long)priv0) / 1024));
|
|
reaktor_quit(app, 0);
|
|
return;
|
|
}
|
|
app->dirty = 1;
|
|
reaktor_wake(app);
|
|
}
|
|
|
|
static void
|
|
page(App *app, struct nk_context *ctx, int w, int h)
|
|
{
|
|
g_frames++;
|
|
if (is("win-leak")) {
|
|
leak_page(app);
|
|
return;
|
|
}
|
|
if (is("confirm") || is("confirm-cancel")) confirm_page(app);
|
|
if (SDL_strncmp(g_mode, "dialog-", 7) == 0) dialog_page(app);
|
|
if (is("print-pdf")) {
|
|
print_page_test(app);
|
|
return;
|
|
}
|
|
if (is("undo")) {
|
|
undo_page(app);
|
|
return;
|
|
}
|
|
if (is("date-keys")) {
|
|
date_page(app, ctx, w, h);
|
|
return;
|
|
}
|
|
if (is("spin-keys")) {
|
|
spin_page(app, ctx, w, h);
|
|
return;
|
|
}
|
|
if (is("field-find")) {
|
|
find_page(app, ctx, w, h);
|
|
return;
|
|
}
|
|
if (is("tree-keys")) {
|
|
tree_page(app, ctx, w, h);
|
|
return;
|
|
}
|
|
if (is("menu-keys")) {
|
|
menu_page(app, ctx, w, h);
|
|
return;
|
|
}
|
|
if (SDL_strncmp(g_mode, "hold-", 5) == 0) {
|
|
hold_page(app, ctx, w, h);
|
|
return;
|
|
}
|
|
if (is("ask") || is("timer") || is("post") || is("settings") || is("list") ||
|
|
is("tip") || is("list-keys") || is("split-keys") || is("split-vkeys") ||
|
|
is("save-change") || is("save-timer") || is("settings-clear")) {
|
|
service_page(app, ctx, w, h);
|
|
return;
|
|
}
|
|
if (ctx->input.keyboard.text_len > 0) {
|
|
notef("text %.*s", ctx->input.keyboard.text_len, ctx->input.keyboard.text);
|
|
}
|
|
if (is("title")) reaktor_set_title(app, "Renamed");
|
|
REAKTOR_FREE(.w = (float)w, .h = (float)h) {
|
|
reaktor_label(&(reaktor_label_spec){ .text = "launchtest",
|
|
.name = "Mode" });
|
|
}
|
|
}
|
|
|
|
static int SDLCALL
|
|
quit_later(void *app)
|
|
{
|
|
SDL_Delay(300);
|
|
reaktor_quit((App *)app, 7);
|
|
return 0;
|
|
}
|
|
|
|
static int SDLCALL
|
|
request_twice(void *app)
|
|
{
|
|
SDL_Delay(300);
|
|
reaktor_request_quit((App *)app);
|
|
reaktor_request_quit((App *)app);
|
|
return 0;
|
|
}
|
|
|
|
static int SDLCALL
|
|
count_frames(void *app)
|
|
{
|
|
SDL_Delay(1500);
|
|
notef("frames %d", g_frames);
|
|
reaktor_quit((App *)app, 0);
|
|
return 0;
|
|
}
|
|
|
|
static void
|
|
push_key(App *app, SDL_EventType type, SDL_Keycode key)
|
|
{
|
|
SDL_Event e;
|
|
|
|
SDL_zero(e);
|
|
e.type = type;
|
|
e.key.windowID = SDL_GetWindowID(app->win);
|
|
e.key.key = key;
|
|
e.key.down = type == SDL_EVENT_KEY_DOWN;
|
|
SDL_PushEvent(&e);
|
|
}
|
|
|
|
static void
|
|
push_text(App *app, const char *text)
|
|
{
|
|
SDL_Event e;
|
|
|
|
SDL_zero(e);
|
|
e.type = SDL_EVENT_TEXT_INPUT;
|
|
e.text.windowID = SDL_GetWindowID(app->win);
|
|
e.text.text = text;
|
|
SDL_PushEvent(&e);
|
|
}
|
|
|
|
static int
|
|
start(App *app, int argc, char **argv)
|
|
{
|
|
if (argc > 1) g_mode = argv[1];
|
|
if (argc > 2) g_log = argv[2];
|
|
note("start");
|
|
if (is("start-fail")) return 5;
|
|
if (is("tip")) push_mouse(app, SDL_EVENT_MOUSE_MOTION, 60.0f, 30.0f);
|
|
if (is("quit") || is("twice"))
|
|
SDL_DetachThread(SDL_CreateThread(quit_later, "quit", app));
|
|
if (is("request")) SDL_DetachThread(SDL_CreateThread(request_twice, "request", app));
|
|
if (is("title")) {
|
|
reaktor_set_title(app, "Renamed");
|
|
SDL_DetachThread(SDL_CreateThread(count_frames, "frames", app));
|
|
}
|
|
if (is("keyeat")) {
|
|
push_key(app, SDL_EVENT_KEY_DOWN, SDLK_X);
|
|
push_text(app, "x");
|
|
push_key(app, SDL_EVENT_KEY_UP, SDLK_X);
|
|
push_key(app, SDL_EVENT_KEY_DOWN, SDLK_Y);
|
|
push_text(app, "y");
|
|
push_key(app, SDL_EVENT_KEY_UP, SDLK_Y);
|
|
SDL_DetachThread(SDL_CreateThread(count_frames, "frames", app));
|
|
}
|
|
if (is("hold-press")) g_second = floater(app, "Modal", 100.0f, 50.0f, 1);
|
|
if (is("hold-raise")) {
|
|
floater(app, "Under", 280.0f, 160.0f, 0);
|
|
g_second = floater(app, "Modal", 100.0f, 50.0f, 1);
|
|
}
|
|
if (is("hold-keys") || is("hold-stack")) {
|
|
floater(app, "Under", 140.0f, 60.0f, 1);
|
|
g_second = floater(app, "Top", 140.0f, 60.0f, 1);
|
|
}
|
|
if (is("hold-tab-field")) g_second = floater(app, "Cover", 400.0f, 400.0f, 0);
|
|
if (is("hold-modal-tab")) floater(app, "Opener", 160.0f, 110.0f, 1);
|
|
if (is("hold-reach")) {
|
|
floater(app, "Modal", 140.0f, 60.0f, 1);
|
|
g_second = floater(app, "Above", 140.0f, 60.0f, 0);
|
|
}
|
|
if (is("hold-toast")) g_second = floater(app, "Field", 160.0f, 70.0f, 1);
|
|
if (is("hold-step-floater")) g_second = floater(app, "Slider", 160.0f, 70.0f, 1);
|
|
if (is("hold-toast-floater")) g_second = floater(app, "Plain", 100.0f, 50.0f, 0);
|
|
if (is("window-text"))
|
|
reaktor_window_open(app, &(reaktor_window){
|
|
.window = { .title = "text", .w = 240, .h = 80 },
|
|
.page = window_page });
|
|
if (SDL_strncmp(g_mode, "win-", 4) == 0 && !is("win-leak"))
|
|
g_win_open = open_probe_window(app);
|
|
if (is("win-anim")) SDL_DetachThread(SDL_CreateThread(report_anim, "anim", app));
|
|
if (is("win-drag")) SDL_DetachThread(SDL_CreateThread(count_drag, "drag", app));
|
|
if (is("confirm") || is("confirm-cancel"))
|
|
reaktor_set_confirm_close(app, "Close the test?");
|
|
if (is("win-picker") || is("win-picker-close"))
|
|
SDL_DetachThread(SDL_CreateThread(quit_after, "quit", app));
|
|
return 0;
|
|
}
|
|
|
|
static int
|
|
key(App *app, const SDL_Event *e)
|
|
{
|
|
if (is("win-keys") && app->secondary && !g_key_seen) {
|
|
g_key_seen = 1;
|
|
note("key hook in window");
|
|
}
|
|
return is("keyeat") && e->key.key == SDLK_X;
|
|
}
|
|
|
|
static void
|
|
picked(App *app, const char *const *paths, int count, void *user)
|
|
{
|
|
int i;
|
|
|
|
(void)user;
|
|
notef("file in %s: %s", app->secondary ? "window" : "main", count ? paths[0] : "(none)");
|
|
for (i = 1; i < count; i++) {
|
|
notef("and %s", paths[i]);
|
|
}
|
|
if (SDL_strncmp(g_mode, "dialog-", 7) == 0) reaktor_quit(app, 0);
|
|
}
|
|
|
|
static void
|
|
dialog_page(App *app)
|
|
{
|
|
static const reaktor_file_filter text[] = { { "Text", "txt" }, { "All files", "*" } };
|
|
|
|
if (g_frames != 2) return;
|
|
note(reaktor_file_dialog_open(app, &(reaktor_file_dialog){
|
|
.kind = is("dialog-save") ? REAKTOR_FILE_SAVE
|
|
: is("dialog-folder") ? REAKTOR_FOLDER_OPEN : REAKTOR_FILE_OPEN,
|
|
.filters = text, .filter_count = 2, .many = is("dialog-many"),
|
|
.location = SDL_GetBasePath(), .chosen = picked })
|
|
? "dialog open" : "dialog refused");
|
|
note(reaktor_file_dialog_open(app, &(reaktor_file_dialog){ .chosen = picked })
|
|
? "second dialog open" : "second dialog refused");
|
|
}
|
|
|
|
static void
|
|
file_opened(App *app, const char *path)
|
|
{
|
|
notef("file in %s: %s", app->secondary ? "window" : "main", path ? path : "(none)");
|
|
}
|
|
|
|
static int
|
|
closing(App *app, reaktor_quit_reason why)
|
|
{
|
|
(void)app;
|
|
notef("closing %d", (int)why);
|
|
return (is("veto") || is("request")) && ++g_closings == 1;
|
|
}
|
|
|
|
static void
|
|
stop(App *app)
|
|
{
|
|
(void)app;
|
|
note("stop");
|
|
}
|
|
|
|
static const char red_css[] = ":root { --background-body: #ff0000; }\n";
|
|
|
|
int
|
|
main(int argc, char **argv)
|
|
{
|
|
reaktor_launch l = {
|
|
.name = "launchtest",
|
|
.window = { .w = 320, .h = 200, .min_w = 300, .min_h = 180 },
|
|
.css = { { .name = "red.css", .data = red_css,
|
|
.size = sizeof red_css - 1 } },
|
|
.page = page,
|
|
.start = start,
|
|
.key = key,
|
|
.closing = closing,
|
|
.stop = stop,
|
|
.file_opened = file_opened };
|
|
|
|
if (argc > 1 && SDL_strcmp(argv[1], "save-change") == 0)
|
|
l.save_settings = REAKTOR_SAVE_ON_CHANGE;
|
|
if (argc > 1 && SDL_strcmp(argv[1], "save-timer") == 0) {
|
|
l.save_settings = REAKTOR_SAVE_ON_TIMER;
|
|
l.save_ms = 300;
|
|
}
|
|
int rc = launchApp(argc, argv, &l);
|
|
|
|
if (is("twice")) {
|
|
|
|
notef("again %d", launchApp(argc, argv, &l));
|
|
}
|
|
return rc;
|
|
}
|