Compare commits
No commits in common. "bd31f562fc4c5d620d17934e8aee5057f10f7a22" and "a8b7171709461d0018bd7f067ec48e0ab06d519f" have entirely different histories.
bd31f562fc
...
a8b7171709
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -10,6 +10,3 @@
|
|||||||
path = lib/vendor
|
path = lib/vendor
|
||||||
url = https://github.com/c3lang/vendor
|
url = https://github.com/c3lang/vendor
|
||||||
ignore = dirty
|
ignore = dirty
|
||||||
[submodule "lib/ugui_sdl.c3l"]
|
|
||||||
path = lib/ugui_sdl.c3l
|
|
||||||
url = https://git.alemauri.eu/alema/ugui_sdl.c3l.git
|
|
||||||
|
|||||||
6
Makefile
6
Makefile
@ -1,5 +1,9 @@
|
|||||||
C3FLAGS = -g
|
C3FLAGS = -g
|
||||||
|
|
||||||
main: src/main.c3 $(wildcard lib/ugui.c3l/src/*.c3) $(wildcard lib/ugui_sdl.c3l/)
|
main: src/main.c3 src/renderer.c3 $(wildcard lib/ugui/src/*.c3)
|
||||||
make -C resources/shaders
|
make -C resources/shaders
|
||||||
c3c build ${C3FLAGS}
|
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
|
||||||
|
|||||||
@ -279,8 +279,7 @@ fn void? Ctx.frame_end(&ctx)
|
|||||||
ctx.input = ctx.current_input;
|
ctx.input = ctx.current_input;
|
||||||
ctx.current_input.events = {};
|
ctx.current_input.events = {};
|
||||||
ctx.current_input.mouse.scroll = {};
|
ctx.current_input.mouse.scroll = {};
|
||||||
ctx.current_input.mouse.updated = BTN_NONE;
|
ctx.current_input.keyboard = {};
|
||||||
ctx.current_input.keyboard.text_len = 0;
|
|
||||||
|
|
||||||
// DO THE LAYOUT
|
// DO THE LAYOUT
|
||||||
ctx.layout_element_tree()!;
|
ctx.layout_element_tree()!;
|
||||||
|
|||||||
@ -105,10 +105,12 @@ fn void Ctx.input_changefocus(&ctx, bool has_focus)
|
|||||||
ctx.has_focus = has_focus;
|
ctx.has_focus = has_focus;
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: all of these refer to the previous frame's data
|
macro Ctx.mouse_pressed(&ctx) => ctx.current_input.mouse.updated & ctx.current_input.mouse.down;
|
||||||
macro Ctx.mouse_pressed(&ctx) => ctx.input.mouse.updated & ctx.input.mouse.down;
|
macro Ctx.mouse_released(&ctx) => ctx.current_input.mouse.updated & ~ctx.current_input.mouse.down;
|
||||||
macro Ctx.mouse_released(&ctx) => ctx.input.mouse.updated & ~ctx.input.mouse.down;
|
macro Ctx.mouse_down(&ctx) => ctx.current_input.mouse.down;
|
||||||
macro Ctx.mouse_down(&ctx) => ctx.input.mouse.down;
|
|
||||||
|
// FIXME: hthis compairson could be done with a cast using MouseButtons.inner
|
||||||
|
// property but I could not figure out how
|
||||||
macro Ctx.is_mouse_pressed(&ctx, MouseButtons btn) => (ctx.mouse_pressed() & btn) != BTN_NONE;
|
macro Ctx.is_mouse_pressed(&ctx, MouseButtons btn) => (ctx.mouse_pressed() & btn) != BTN_NONE;
|
||||||
macro Ctx.is_mouse_released(&ctx, MouseButtons btn) => (ctx.mouse_released() & btn) != BTN_NONE;
|
macro Ctx.is_mouse_released(&ctx, MouseButtons btn) => (ctx.mouse_released() & btn) != BTN_NONE;
|
||||||
macro Ctx.is_mouse_down(&ctx, MouseButtons btn) => (ctx.mouse_down() & btn) != BTN_NONE;
|
macro Ctx.is_mouse_down(&ctx, MouseButtons btn) => (ctx.mouse_down() & btn) != BTN_NONE;
|
||||||
@ -119,7 +121,7 @@ fn void Ctx.input_mouse_button(&ctx, MouseButtons buttons)
|
|||||||
{
|
{
|
||||||
ctx.current_input.mouse.updated = ctx.current_input.mouse.down ^ buttons;
|
ctx.current_input.mouse.updated = ctx.current_input.mouse.down ^ buttons;
|
||||||
ctx.current_input.mouse.down = buttons;
|
ctx.current_input.mouse.down = buttons;
|
||||||
ctx.current_input.events.mouse_btn = ctx.current_input.mouse.down != BTN_NONE || ctx.current_input.mouse.updated != BTN_NONE;
|
ctx.current_input.events.mouse_btn = (uint)ctx.current_input.mouse.down != 0 || (uint)ctx.current_input.mouse.updated != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mouse was moved, report absolute position
|
// Mouse was moved, report absolute position
|
||||||
@ -224,13 +226,10 @@ fn String Ctx.get_keys(&ctx) => (String)ctx.input.keyboard.text[:ctx.input.keybo
|
|||||||
fn ModKeys Ctx.get_mod(&ctx) => ctx.input.keyboard.modkeys;
|
fn ModKeys Ctx.get_mod(&ctx) => ctx.input.keyboard.modkeys;
|
||||||
|
|
||||||
// Modifier keys, like control or backspace
|
// Modifier keys, like control or backspace
|
||||||
|
// TODO: make this call repetible to input modkeys one by one
|
||||||
<* @param [&inout] ctx *>
|
<* @param [&inout] ctx *>
|
||||||
fn void Ctx.input_mod_keys(&ctx, ModKeys modkeys, bool set)
|
fn void Ctx.input_mod_keys(&ctx, ModKeys modkeys)
|
||||||
{
|
{
|
||||||
if (set) {
|
ctx.current_input.keyboard.modkeys = modkeys;
|
||||||
ctx.current_input.keyboard.modkeys |= modkeys;
|
|
||||||
} else {
|
|
||||||
ctx.current_input.keyboard.modkeys &= ~modkeys;
|
|
||||||
}
|
|
||||||
ctx.current_input.events.mod_key = (uint)ctx.current_input.keyboard.modkeys != 0;
|
ctx.current_input.events.mod_key = (uint)ctx.current_input.keyboard.modkeys != 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1 +0,0 @@
|
|||||||
Subproject commit 050624fd67c2d80190114c7774ccfa64b0f449b9
|
|
||||||
@ -2,7 +2,7 @@
|
|||||||
"langrev": "1",
|
"langrev": "1",
|
||||||
"warnings": ["no-unused"],
|
"warnings": ["no-unused"],
|
||||||
"dependency-search-paths": ["lib", "lib/vendor/libraries"],
|
"dependency-search-paths": ["lib", "lib/vendor/libraries"],
|
||||||
"dependencies": ["sdl3", "ugui", "ugui_sdl3"],
|
"dependencies": ["sdl3", "ugui"],
|
||||||
"features": ["DEBUG_POINTER"],
|
"features": ["DEBUG_POINTER"],
|
||||||
"authors": ["Alessandro Mauri <ale@shitposting.expert>"],
|
"authors": ["Alessandro Mauri <ale@shitposting.expert>"],
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
|
|||||||
84
src/main.c3
84
src/main.c3
@ -1,11 +1,13 @@
|
|||||||
import std::io;
|
import std::io;
|
||||||
|
import cache;
|
||||||
import ugui;
|
import ugui;
|
||||||
import std::time;
|
import std::time;
|
||||||
import std::collections::ringbuffer;
|
import std::collections::ringbuffer;
|
||||||
import std::core::string;
|
import std::core::string;
|
||||||
|
import std::ascii;
|
||||||
import std::core::mem::allocator;
|
import std::core::mem::allocator;
|
||||||
import ugui::sdl::ren;
|
import sdlrenderer::ren;
|
||||||
|
import sdl3::sdl;
|
||||||
|
|
||||||
alias Times = ringbuffer::RingBuffer{time::NanoDuration[128]};
|
alias Times = ringbuffer::RingBuffer{time::NanoDuration[128]};
|
||||||
|
|
||||||
@ -125,15 +127,81 @@ fn int main(String[] args)
|
|||||||
// ========================================================================================== //
|
// ========================================================================================== //
|
||||||
// MAIN LOOP //
|
// MAIN LOOP //
|
||||||
// ========================================================================================== //
|
// ========================================================================================== //
|
||||||
ren::pre(ren.win);
|
sdl::start_text_input(ren.win);
|
||||||
|
|
||||||
bool quit;
|
sdl::Event e;
|
||||||
|
bool quit = false;
|
||||||
|
ugui::ModKeys mod;
|
||||||
|
ugui::MouseButtons btn;
|
||||||
while (!quit) {
|
while (!quit) {
|
||||||
clock.mark();
|
clock.mark();
|
||||||
fps_clock.mark();
|
fps_clock.mark();
|
||||||
sleep_clock.mark();
|
sleep_clock.mark();
|
||||||
|
|
||||||
quit = ui.handle_events()!!;
|
do {
|
||||||
|
switch (e.type) {
|
||||||
|
case EVENT_QUIT:
|
||||||
|
quit = true;
|
||||||
|
case EVENT_KEY_UP:
|
||||||
|
ui.input_key_release();
|
||||||
|
nextcase;
|
||||||
|
case EVENT_KEY_DOWN:
|
||||||
|
ui.input_key_press();
|
||||||
|
if (e.key.repeat) ui.input_key_repeat();
|
||||||
|
|
||||||
|
mod.rctrl = e.key.key == K_RCTRL ? !!(e.type == EVENT_KEY_DOWN) : mod.rctrl;
|
||||||
|
mod.lctrl = e.key.key == K_LCTRL ? !!(e.type == EVENT_KEY_DOWN) : mod.lctrl;
|
||||||
|
mod.rshift = e.key.key == K_RSHIFT ? !!(e.type == EVENT_KEY_DOWN) : mod.rshift;
|
||||||
|
mod.lshift = e.key.key == K_LSHIFT ? !!(e.type == EVENT_KEY_DOWN) : mod.lshift;
|
||||||
|
mod.bkspc = e.key.key == K_BACKSPACE ? !!(e.type == EVENT_KEY_DOWN) : mod.bkspc;
|
||||||
|
mod.del = e.key.key == K_DELETE ? !!(e.type == EVENT_KEY_DOWN) : mod.del;
|
||||||
|
mod.home = e.key.key == K_HOME ? !!(e.type == EVENT_KEY_DOWN) : mod.home;
|
||||||
|
mod.end = e.key.key == K_END ? !!(e.type == EVENT_KEY_DOWN) : mod.end;
|
||||||
|
mod.up = e.key.key == K_UP ? !!(e.type == EVENT_KEY_DOWN) : mod.up;
|
||||||
|
mod.down = e.key.key == K_DOWN ? !!(e.type == EVENT_KEY_DOWN) : mod.down;
|
||||||
|
mod.left = e.key.key == K_LEFT ? !!(e.type == EVENT_KEY_DOWN) : mod.left;
|
||||||
|
mod.right = e.key.key == K_RIGHT ? !!(e.type == EVENT_KEY_DOWN) : mod.right;
|
||||||
|
|
||||||
|
// 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
|
||||||
|
if (e.type == EVENT_KEY_DOWN && (mod.lctrl || mod.rctrl)) {
|
||||||
|
if (ascii::is_alnum_m((uint)e.key.key)) {
|
||||||
|
ui.input_char((char)e.key.key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (e.type == EVENT_KEY_DOWN && e.key.key == K_RETURN) ui.input_char('\n');
|
||||||
|
|
||||||
|
case EVENT_TEXT_INPUT:
|
||||||
|
ui.input_text_utf8(e.text.text.str_view());
|
||||||
|
case EVENT_WINDOW_RESIZED:
|
||||||
|
ui.input_window_size((short)e.window.data1, (short)e.window.data2)!!;
|
||||||
|
case EVENT_WINDOW_FOCUS_GAINED:
|
||||||
|
ui.input_changefocus(true);
|
||||||
|
case EVENT_WINDOW_FOCUS_LOST:
|
||||||
|
ui.input_changefocus(false);
|
||||||
|
case EVENT_MOUSE_MOTION:
|
||||||
|
ui.input_mouse_abs((short)e.motion.x, (short)e.motion.y);
|
||||||
|
case EVENT_MOUSE_WHEEL:
|
||||||
|
ui.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),
|
||||||
|
};
|
||||||
|
case EVENT_POLL_SENTINEL: break;
|
||||||
|
default:
|
||||||
|
io::eprintfn("unhandled event: %s", e.type);
|
||||||
|
}
|
||||||
|
} while(sdl::poll_event(&e));
|
||||||
|
ui.input_mod_keys(mod);
|
||||||
|
ui.input_mouse_button(btn);
|
||||||
|
|
||||||
/* End Input Handling */
|
/* End Input Handling */
|
||||||
|
|
||||||
@ -180,7 +248,7 @@ $endswitch
|
|||||||
// wait for the next event, timeout after 100ms
|
// wait for the next event, timeout after 100ms
|
||||||
int timeout = LIMIT_FPS ? (int)(100.0-sleep_clock.mark().to_ms()-0.5) : 0;
|
int timeout = LIMIT_FPS ? (int)(100.0-sleep_clock.mark().to_ms()-0.5) : 0;
|
||||||
if (ui.skip_frame) timeout = 0;
|
if (ui.skip_frame) timeout = 0;
|
||||||
ren::wait_events(timeout);
|
sdl::wait_event_timeout(&e, timeout);
|
||||||
|
|
||||||
fps = 1.0 / fps_clock.mark().to_sec();
|
fps = 1.0 / fps_clock.mark().to_sec();
|
||||||
frame++;
|
frame++;
|
||||||
@ -385,7 +453,7 @@ fn void calculator(ugui::Ctx* ui, TextEdit* te)
|
|||||||
ui.@div(ugui::@grow(), ugui::@fit(), anchor: CENTER) {
|
ui.@div(ugui::@grow(), ugui::@fit(), anchor: CENTER) {
|
||||||
static bool state;
|
static bool state;
|
||||||
ui.checkbox("boolean", &state, "tick")!!;
|
ui.checkbox("boolean", &state, "tick")!!;
|
||||||
ui.sprite("tux", 32)!!;
|
ui.sprite("tux")!!;
|
||||||
ui.toggle("lmao", &state)!!;
|
ui.toggle("lmao", &state)!!;
|
||||||
}!!;
|
}!!;
|
||||||
ui.@div(ugui::@grow(), ugui::@exact(50), anchor: CENTER, scroll_y: true) {
|
ui.@div(ugui::@grow(), ugui::@exact(50), anchor: CENTER, scroll_y: true) {
|
||||||
|
|||||||
1035
src/renderer.c3
Normal file
1035
src/renderer.c3
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user