Compare commits
3 Commits
a8b7171709
...
bd31f562fc
| Author | SHA1 | Date | |
|---|---|---|---|
| bd31f562fc | |||
| 7b036ccee2 | |||
| 26f38b342b |
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -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
|
||||
|
||||
6
Makefile
6
Makefile
@ -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
|
||||
|
||||
@ -279,7 +279,8 @@ fn void? Ctx.frame_end(&ctx)
|
||||
ctx.input = ctx.current_input;
|
||||
ctx.current_input.events = {};
|
||||
ctx.current_input.mouse.scroll = {};
|
||||
ctx.current_input.keyboard = {};
|
||||
ctx.current_input.mouse.updated = BTN_NONE;
|
||||
ctx.current_input.keyboard.text_len = 0;
|
||||
|
||||
// DO THE LAYOUT
|
||||
ctx.layout_element_tree()!;
|
||||
|
||||
@ -105,12 +105,10 @@ fn void Ctx.input_changefocus(&ctx, bool has_focus)
|
||||
ctx.has_focus = has_focus;
|
||||
}
|
||||
|
||||
macro Ctx.mouse_pressed(&ctx) => ctx.current_input.mouse.updated & ctx.current_input.mouse.down;
|
||||
macro Ctx.mouse_released(&ctx) => ctx.current_input.mouse.updated & ~ctx.current_input.mouse.down;
|
||||
macro Ctx.mouse_down(&ctx) => ctx.current_input.mouse.down;
|
||||
|
||||
// FIXME: hthis compairson could be done with a cast using MouseButtons.inner
|
||||
// property but I could not figure out how
|
||||
// NOTE: all of these refer to the previous frame's data
|
||||
macro Ctx.mouse_pressed(&ctx) => ctx.input.mouse.updated & ctx.input.mouse.down;
|
||||
macro Ctx.mouse_released(&ctx) => ctx.input.mouse.updated & ~ctx.input.mouse.down;
|
||||
macro Ctx.mouse_down(&ctx) => ctx.input.mouse.down;
|
||||
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_down(&ctx, MouseButtons btn) => (ctx.mouse_down() & btn) != BTN_NONE;
|
||||
@ -121,7 +119,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.down = buttons;
|
||||
ctx.current_input.events.mouse_btn = (uint)ctx.current_input.mouse.down != 0 || (uint)ctx.current_input.mouse.updated != 0;
|
||||
ctx.current_input.events.mouse_btn = ctx.current_input.mouse.down != BTN_NONE || ctx.current_input.mouse.updated != BTN_NONE;
|
||||
}
|
||||
|
||||
// Mouse was moved, report absolute position
|
||||
@ -226,10 +224,13 @@ fn String Ctx.get_keys(&ctx) => (String)ctx.input.keyboard.text[:ctx.input.keybo
|
||||
fn ModKeys Ctx.get_mod(&ctx) => ctx.input.keyboard.modkeys;
|
||||
|
||||
// Modifier keys, like control or backspace
|
||||
// TODO: make this call repetible to input modkeys one by one
|
||||
<* @param [&inout] ctx *>
|
||||
fn void Ctx.input_mod_keys(&ctx, ModKeys modkeys)
|
||||
fn void Ctx.input_mod_keys(&ctx, ModKeys modkeys, bool set)
|
||||
{
|
||||
ctx.current_input.keyboard.modkeys = modkeys;
|
||||
if (set) {
|
||||
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;
|
||||
}
|
||||
|
||||
1
lib/ugui_sdl.c3l
Submodule
1
lib/ugui_sdl.c3l
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 050624fd67c2d80190114c7774ccfa64b0f449b9
|
||||
@ -2,7 +2,7 @@
|
||||
"langrev": "1",
|
||||
"warnings": ["no-unused"],
|
||||
"dependency-search-paths": ["lib", "lib/vendor/libraries"],
|
||||
"dependencies": ["sdl3", "ugui"],
|
||||
"dependencies": ["sdl3", "ugui", "ugui_sdl3"],
|
||||
"features": ["DEBUG_POINTER"],
|
||||
"authors": ["Alessandro Mauri <ale@shitposting.expert>"],
|
||||
"version": "0.1.0",
|
||||
|
||||
82
src/main.c3
82
src/main.c3
@ -1,13 +1,11 @@
|
||||
import std::io;
|
||||
import cache;
|
||||
import ugui;
|
||||
import std::time;
|
||||
import std::collections::ringbuffer;
|
||||
import std::core::string;
|
||||
import std::ascii;
|
||||
import std::core::mem::allocator;
|
||||
import sdlrenderer::ren;
|
||||
import sdl3::sdl;
|
||||
import ugui::sdl::ren;
|
||||
|
||||
|
||||
alias Times = ringbuffer::RingBuffer{time::NanoDuration[128]};
|
||||
|
||||
@ -127,81 +125,15 @@ fn int main(String[] args)
|
||||
// ========================================================================================== //
|
||||
// MAIN LOOP //
|
||||
// ========================================================================================== //
|
||||
sdl::start_text_input(ren.win);
|
||||
ren::pre(ren.win);
|
||||
|
||||
sdl::Event e;
|
||||
bool quit = false;
|
||||
ugui::ModKeys mod;
|
||||
ugui::MouseButtons btn;
|
||||
bool quit;
|
||||
while (!quit) {
|
||||
clock.mark();
|
||||
fps_clock.mark();
|
||||
sleep_clock.mark();
|
||||
|
||||
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);
|
||||
quit = ui.handle_events()!!;
|
||||
|
||||
/* End Input Handling */
|
||||
|
||||
@ -248,7 +180,7 @@ $endswitch
|
||||
// wait for the next event, timeout after 100ms
|
||||
int timeout = LIMIT_FPS ? (int)(100.0-sleep_clock.mark().to_ms()-0.5) : 0;
|
||||
if (ui.skip_frame) timeout = 0;
|
||||
sdl::wait_event_timeout(&e, timeout);
|
||||
ren::wait_events(timeout);
|
||||
|
||||
fps = 1.0 / fps_clock.mark().to_sec();
|
||||
frame++;
|
||||
@ -453,7 +385,7 @@ fn void calculator(ugui::Ctx* ui, TextEdit* te)
|
||||
ui.@div(ugui::@grow(), ugui::@fit(), anchor: CENTER) {
|
||||
static bool state;
|
||||
ui.checkbox("boolean", &state, "tick")!!;
|
||||
ui.sprite("tux")!!;
|
||||
ui.sprite("tux", 32)!!;
|
||||
ui.toggle("lmao", &state)!!;
|
||||
}!!;
|
||||
ui.@div(ugui::@grow(), ugui::@exact(50), anchor: CENTER, scroll_y: true) {
|
||||
|
||||
1035
src/renderer.c3
1035
src/renderer.c3
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user