aboutsummaryrefslogtreecommitdiffstats
path: root/renderer.c
diff options
context:
space:
mode:
Diffstat (limited to 'renderer.c')
-rw-r--r--renderer.c150
1 files changed, 73 insertions, 77 deletions
diff --git a/renderer.c b/renderer.c
index 3544600..e1fb704 100644
--- a/renderer.c
+++ b/renderer.c
@@ -8,27 +8,27 @@
enum window {
- WIDTH = 800,
- HEIGHT = 600,
+ WIDTH = 800,
+ HEIGHT = 600,
};
static const mu_Color COLOR_BG = {0, 0, 0, 255};
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,
+ [ 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,
+ [ 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,
};
@@ -73,49 +73,47 @@ void r_init(void) {
}
-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 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);
+ }
+ }
+ }
}
-void
-r_handle_input(mu_Context *ctx) {
- SDL_Event e;
- while (SDL_PollEvent(&e)) {
- handle_event(e, ctx);
- }
+void r_handle_input(mu_Context *ctx) {
+ SDL_Event e;
+ while (SDL_PollEvent(&e)) {
+ handle_event(e, ctx);
+ }
}
@@ -227,22 +225,21 @@ static void set_clip_rect(mu_Rect rect) {
}
-static void
-render_command(mu_Command *cmd) {
- switch (cmd->type) {
- case MU_COMMAND_TEXT: {
- draw_text(cmd->text.str, cmd->text.pos, cmd->text.color);
- }
- break; case MU_COMMAND_RECT: {
- draw_rect(cmd->rect.rect, cmd->rect.color);
- }
- break; case MU_COMMAND_ICON: {
- draw_icon(cmd->icon.id, cmd->icon.rect, cmd->icon.color);
- }
- break; case MU_COMMAND_CLIP: {
- set_clip_rect(cmd->clip.rect);
- }
- }
+static void render_command(mu_Command *cmd) {
+ switch (cmd->type) {
+ case MU_COMMAND_TEXT: {
+ draw_text(cmd->text.str, cmd->text.pos, cmd->text.color);
+ }
+ break; case MU_COMMAND_RECT: {
+ draw_rect(cmd->rect.rect, cmd->rect.color);
+ }
+ break; case MU_COMMAND_ICON: {
+ draw_icon(cmd->icon.id, cmd->icon.rect, cmd->icon.color);
+ }
+ break; case MU_COMMAND_CLIP: {
+ set_clip_rect(cmd->clip.rect);
+ }
+ }
}
@@ -253,14 +250,13 @@ static void clear(mu_Color clr) {
}
-void
-r_render(mu_Context *ctx) {
- clear(COLOR_BG);
- mu_Command *cmd = NULL;
- while (mu_next_command(ctx, &cmd)) {
- render_command(cmd);
- }
- r_present();
+void r_render(mu_Context *ctx) {
+ clear(COLOR_BG);
+ mu_Command *cmd = NULL;
+ while (mu_next_command(ctx, &cmd)) {
+ render_command(cmd);
+ }
+ r_present();
}