| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdint.h>
- #include <stdbool.h>
- #include <SDL2/SDL.h>
- #pragma GCC diagnostic push
- #pragma GCC diagnostic ignored "-Wall"
- #pragma GCC diagnostic ignored "-Wsign-conversion"
- #pragma GCC diagnostic ignored "-Wdouble-promotion"
- #pragma GCC diagnostic ignored "-Wconversion"
- #define STB_IMAGE_IMPLEMENTATION
- #include "stb_image.h"
- #pragma GCC diagnostic pop
- #define IMP
- #include "app.h"
- #include "vec2.h"
- #include "da.h"
- #include "unwrap.h"
- #include "file.h"
- #include "keybind.h"
- #include "config.h"
- struct app handle_events(struct app app);
- int32_t
- main(int32_t argc, char **argv)
- {
- (void) argc; (void) argv;
- SCE(SDL_Init(SDL_INIT_VIDEO));
- const char *font_path = "./charmap-oldschool_white.png";
- struct app app = app_create("ged");
- app.font = font_create(app.rdr, font_path, 7, 18);
- app.font.scale = 2.0;
- const char *filepath = "./src/main.c";
- enum buffer_err err;
- RET_UNWRAP2(app.buf, err,
- struct ret_buffer_err,
- buffer_load_from_file(app.buf, filepath));
- (void) err;
- uint64_t i = 0;
- while ( app.running == true ) {
- struct buffer *c_buf = &app.buf;
- app = handle_events(app);
- SCE(SDL_SetRenderDrawColor(app.rdr, i & 0xFF, 0, 0, 1));
- SCE(SDL_RenderClear(app.rdr));
- app_render_text(app, c_buf->data.items, c_buf->data.size,
- vec2(0, 0), 0xFFFFFFFF, app.font.scale);
- /* app_render_cursor(app, 0x00FF000F); */
- SDL_RenderPresent(app.rdr);
- ++i;
- }
- SDL_DestroyWindow(app.win.ptr);
- DA_DESTROY(app.buf.data);
- SDL_Quit();
- exit(EXIT_SUCCESS);
- }
- struct app
- handle_events(struct app app)
- {
- SDL_Event e = {0};
- bool done = false;
- while ( SDL_PollEvent(&e) ) {
- switch ( e.type ) {
- case SDL_QUIT: {
- app.running = false;
- } break;
- case SDL_KEYDOWN: {
- SDL_KeyboardEvent key = e.key;
- SDL_Keysym ks = key.keysym;
- struct keybinds kb = keybinds[ks.sym % KEYBINDS_MAX_SIZE];
- for ( size_t i = 0; i < kb.size; ++i ) {
- struct bind b = kb.binds[i];
- if ( b.func == NULL ) {
- continue;
- }
- if ( (! (b.mod == KMOD_NONE
- && b.mod == ks.mod))
- && (! (b.mod & ks.mod)) ) {
- continue;
- }
- app = b.func(app, b.args);
- done = true;
- }
- } break;
- case SDL_TEXTINPUT: {
- if ( done == true ) {
- break;
- }
- char *t = e.text.text;
- while( *t != '\0' ) {
- app.buf = buffer_insert_char(
- app.buf, app.buf.cur, *t++);
- }
- } break;
- case SDL_WINDOWEVENT: {
- WINDOW_UP_SIZE(app.win);
- } break;
- }
- }
- return app;
- }
|