moved renderer to submodule

This commit is contained in:
Alessandro Mauri 2025-10-25 17:11:00 +02:00
parent 7b036ccee2
commit bd31f562fc
6 changed files with 5 additions and 1152 deletions

3
.gitmodules vendored
View File

@ -10,3 +10,6 @@
path = lib/vendor
url = https://github.com/c3lang/vendor
ignore = dirty
[submodule "lib/ugui_sdl.c3l"]
path = lib/ugui_sdl.c3l
url = https://git.alemauri.eu/alema/ugui_sdl.c3l.git

View File

@ -1,9 +1,5 @@
C3FLAGS = -g
main: src/main.c3 src/renderer.c3 $(wildcard lib/ugui/src/*.c3)
main: src/main.c3 $(wildcard lib/ugui.c3l/src/*.c3) $(wildcard lib/ugui_sdl.c3l/)
make -C resources/shaders
c3c build ${C3FLAGS}
test_renderer: test_renderer.c3 src/renderer.c3 resources/shaders/source/*
scripts/compile_shaders.sh
c3c compile -g -O0 test_renderer.c3 src/renderer.c3 --libdir lib --lib sdl3 --lib ugui

1
lib/ugui_sdl.c3l Submodule

@ -0,0 +1 @@
Subproject commit 050624fd67c2d80190114c7774ccfa64b0f449b9

View File

@ -1,97 +0,0 @@
module ugui::sdl::ren;
import std::io;
import std::ascii;
import ugui;
import sdl3;
<*
@param [&inout] ctx
*>
fn bool? Ctx.handle_events(&ctx)
{
bool quit = false;
ugui::ModKeys mod_set, mod_reset;
ugui::MouseButtons btn;
sdl::Event e;
while (sdl::poll_event(&e)) {
switch (e.type) {
case EVENT_QUIT:
quit = true;
case EVENT_KEY_UP:
ctx.input_key_release();
nextcase;
case EVENT_KEY_DOWN:
ctx.input_key_press();
if (e.key.repeat) ctx.input_key_repeat();
bool down = e.type == EVENT_KEY_DOWN;
switch (e.key.key) {
case K_RCTRL: mod_set.rctrl = down; mod_reset.rctrl = !down;
case K_LCTRL: mod_set.lctrl = down; mod_reset.lctrl = !down;
case K_RSHIFT: mod_set.rshift = down; mod_reset.rshift = !down;
case K_LSHIFT: mod_set.lshift = down; mod_reset.lshift = !down;
case K_BACKSPACE: mod_set.bkspc = down; mod_reset.bkspc = !down;
case K_DELETE: mod_set.del = down; mod_reset.del = !down;
case K_HOME: mod_set.home = down; mod_reset.home = !down;
case K_END: mod_set.end = down; mod_reset.end = !down;
case K_UP: mod_set.up = down; mod_reset.up = !down;
case K_DOWN: mod_set.down = down; mod_reset.down = !down;
case K_LEFT: mod_set.left = down; mod_reset.left = !down;
case K_RIGHT: mod_set.right = down; mod_reset.right = !down;
}
ctx.input_mod_keys(mod_set, true);
ctx.input_mod_keys(mod_reset, false);
// pressing ctrl+key or alt+key does not generate a character as such no
// TEXT_INPUT event is generated. When those keys are pressed we have to
// do manual text input, bummer
ModKeys mod = ctx.get_mod();
if (e.type == EVENT_KEY_DOWN && (mod.lctrl || mod.rctrl)) {
if (ascii::is_alnum_m((uint)e.key.key)) {
ctx.input_char((char)e.key.key);
}
}
if (e.type == EVENT_KEY_DOWN && e.key.key == K_RETURN) ctx.input_char('\n');
case EVENT_TEXT_INPUT:
ctx.input_text_utf8(e.text.text.str_view());
case EVENT_WINDOW_RESIZED:
ctx.input_window_size((short)e.window.data1, (short)e.window.data2)!;
case EVENT_WINDOW_FOCUS_GAINED:
ctx.input_changefocus(true);
case EVENT_WINDOW_FOCUS_LOST:
ctx.input_changefocus(false);
case EVENT_MOUSE_MOTION:
ctx.input_mouse_abs((short)e.motion.x, (short)e.motion.y);
case EVENT_MOUSE_WHEEL:
ctx.input_mouse_wheel((short)e.wheel.integer_x, (short)e.wheel.integer_y);
case EVENT_MOUSE_BUTTON_DOWN: nextcase;
case EVENT_MOUSE_BUTTON_UP:
sdl::MouseButtonFlags mb = sdl::get_mouse_state(null, null);
btn = {
.btn_left = !!(mb & BUTTON_LMASK),
.btn_right = !!(mb & BUTTON_RMASK),
.btn_middle = !!(mb & BUTTON_MMASK),
.btn_4 = !!(mb & BUTTON_X1MASK),
.btn_5 = !!(mb & BUTTON_X2MASK),
};
ctx.input_mouse_button(btn);
case EVENT_POLL_SENTINEL: break;
default:
io::eprintfn("unhandled event: %s", e.type);
}
}
return quit;
}
fn void pre(sdl::Window* win) => sdl::start_text_input(win);
// TODO: this has to be a function of Ctx if we want to set the fps internally
fn void wait_events(uint timeout_ms = 0)
{
sdl::wait_event_timeout(null, timeout_ms);
}

View File

@ -1,10 +0,0 @@
{
"provides" : "ugui_sdl3",
"targets" : {
"linux-x64" : {
"link-args" : [],
"dependencies" : ["sdl3", "ugui"],
"linked-libraries" : []
}
}
}

File diff suppressed because it is too large Load Diff