aboutsummaryrefslogtreecommitdiffstats
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c65
1 files changed, 1 insertions, 64 deletions
diff --git a/main.c b/main.c
index 1d0b3bc..ac6e1a3 100644
--- a/main.c
+++ b/main.c
@@ -32,23 +32,6 @@ static const mu_Color COLOR_BASEFOCUS = COLOR_BASE;
static const mu_Color COLOR_SCROLLBASE = WHITE;
static const mu_Color COLOR_SCROLLTHUMB = WHITE;
-static const char button_map[256] = {
- [ SDL_BUTTON_LEFT & 0xff ] = MU_MOUSE_LEFT,
- [ SDL_BUTTON_RIGHT & 0xff ] = MU_MOUSE_RIGHT,
- [ SDL_BUTTON_MIDDLE & 0xff ] = MU_MOUSE_MIDDLE,
-};
-
-static const char key_map[256] = {
- [ SDLK_LSHIFT & 0xff ] = MU_KEY_SHIFT,
- [ SDLK_RSHIFT & 0xff ] = MU_KEY_SHIFT,
- [ SDLK_LCTRL & 0xff ] = MU_KEY_CTRL,
- [ SDLK_RCTRL & 0xff ] = MU_KEY_CTRL,
- [ SDLK_LALT & 0xff ] = MU_KEY_ALT,
- [ SDLK_RALT & 0xff ] = MU_KEY_ALT,
- [ SDLK_RETURN & 0xff ] = MU_KEY_RETURN,
- [ SDLK_BACKSPACE & 0xff ] = MU_KEY_BACKSPACE,
-};
-
/* Function declarations. */
@@ -56,8 +39,6 @@ static void set_style(mu_Context *ctx);
static int text_width(mu_Font font, const char *text, int len);
static int text_height(mu_Font font);
static void main_loop(mu_Context *ctx, UI *ui);
-static void handle_events(mu_Context *ctx);
-static void handle_event(SDL_Event e, mu_Context *ctx);
static void process_frame(mu_Context *ctx, UI *ui);
static void main_window(mu_Context *ctx, UI *ui);
static void render(mu_Context *ctx);
@@ -121,57 +102,13 @@ text_height(mu_Font font) {
static void
main_loop(mu_Context *ctx, UI *ui) {
for (;;) {
- handle_events(ctx);
+ r_handle_input(ctx);
process_frame(ctx, ui);
render(ctx);
}
}
static void
-handle_events(mu_Context *ctx) {
- SDL_Event e;
- while (SDL_PollEvent(&e)) {
- handle_event(e, ctx);
- }
-}
-
-static void
-handle_event(SDL_Event e, mu_Context *ctx) {
- switch (e.type) {
- case SDL_QUIT: {
- exit(EXIT_SUCCESS);
- }
- break; case SDL_MOUSEMOTION: {
- mu_input_mousemove(ctx, e.motion.x, e.motion.y);
- }
- break; case SDL_MOUSEWHEEL: {
- mu_input_scroll(ctx, 0, e.wheel.y * -30);
- }
- break; case SDL_TEXTINPUT: {
- mu_input_text(ctx, e.text.text);
- }
- break; case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: {
- int b = button_map[e.button.button & 0xff];
- if (b && e.type == SDL_MOUSEBUTTONDOWN) {
- mu_input_mousedown(ctx, e.button.x, e.button.y, b);
- }
- if (b && e.type == SDL_MOUSEBUTTONUP) {
- mu_input_mouseup(ctx, e.button.x, e.button.y, b);
- }
- }
- break; case SDL_KEYDOWN: case SDL_KEYUP: {
- int c = key_map[e.key.keysym.sym & 0xff];
- if (c && e.type == SDL_KEYDOWN) {
- mu_input_keydown(ctx, c);
- }
- if (c && e.type == SDL_KEYUP) {
- mu_input_keyup(ctx, c);
- }
- }
- }
-}
-
-static void
process_frame(mu_Context *ctx, UI *ui) {
mu_begin(ctx);
main_window(ctx, ui);