diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2020-11-25 22:02:43 -0500 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2020-11-25 22:02:43 -0500 |
commit | 346acd202547c3ecb315ff7980f505643bacc77e (patch) | |
tree | 4884f16e6528bbf3576878944f49989ecc0979c9 /main.c | |
parent | 8461f5dec71f5d63d8ffba2ae1bb73ce2e74a000 (diff) |
more scrolling
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 17 |
1 files changed, 13 insertions, 4 deletions
@@ -66,6 +66,7 @@ int main(void) { bool quit = false; TextBuffer text_buffer; + text_buffer_create(&text_buffer, font); { FILE *fp = fopen("main.c", "r"); @@ -84,6 +85,7 @@ int main(void) { while (SDL_PollEvent(&event)) { + // @TODO: make a function to handle text buffer events switch (event.type) { case SDL_QUIT: quit = true; @@ -94,6 +96,16 @@ int main(void) { double scroll_speed = 2.5; text_buffer_scroll(&text_buffer, dx * scroll_speed, dy * scroll_speed); } break; + case SDL_KEYDOWN: { + switch (event.key.keysym.sym) { + case SDLK_PAGEUP: + text_buffer_scroll(&text_buffer, 0, -text_buffer_num_rows(&text_buffer)); + break; + case SDLK_PAGEDOWN: + text_buffer_scroll(&text_buffer, 0, +text_buffer_num_rows(&text_buffer)); + break; + } + } break; } } @@ -115,13 +127,10 @@ int main(void) { text_buffer_scroll(&text_buffer, 0, -scroll_amount); if (keyboard_state[SDL_SCANCODE_DOWN]) text_buffer_scroll(&text_buffer, 0, +scroll_amount); - // @TODO: get this to work - #if 0 if (keyboard_state[SDL_SCANCODE_LEFT]) text_buffer_scroll(&text_buffer, -scroll_amount, 0); if (keyboard_state[SDL_SCANCODE_RIGHT]) text_buffer_scroll(&text_buffer, +scroll_amount, 0); - #endif } @@ -142,7 +151,7 @@ int main(void) { { float x1 = 50, y1 = 50, x2 = window_widthf-50, y2 = window_heightf-50; - text_buffer_render(&text_buffer, font, x1, y1, x2, y2); + text_buffer_render(&text_buffer, x1, y1, x2, y2); if (text_has_err()) { printf("Text error: %s\n", text_get_err()); break; |