diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-05-20 16:53:25 +0200 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-05-20 16:53:25 +0200 |
| commit | 322c1a49f59d3fc6441804bbbb29da22567e4bcb (patch) | |
| tree | 1806d82a7f5cecdf4c256da86454ddf2530305cd /src/event.c | |
| parent | 5d6b59778a7346317ddfc549c350c0960a7a54a7 (diff) | |
| download | mandelbrot-322c1a49f59d3fc6441804bbbb29da22567e4bcb.tar.gz mandelbrot-322c1a49f59d3fc6441804bbbb29da22567e4bcb.tar.bz2 mandelbrot-322c1a49f59d3fc6441804bbbb29da22567e4bcb.zip | |
Correct resize, linear iterpolation draft
Diffstat (limited to 'src/event.c')
| -rw-r--r-- | src/event.c | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/src/event.c b/src/event.c index 9d384fc..d5f1180 100644 --- a/src/event.c +++ b/src/event.c @@ -6,6 +6,7 @@ static void st_move_horizontal(State *state, bool move_right); static void st_move_vertical(State *state, bool move_down); static void st_set_key(SDL_Keycode sym, bool value); static void st_apply_keys(State *state); +static void st_resize(State *state, int new_width, int new_height); static bool g_key_states[] = { [KEY_UP] = false, @@ -60,22 +61,37 @@ void event_handle(State *state) case SDL_WINDOWEVENT: if (e.window.event == SDL_WINDOWEVENT_RESIZED) - { - double w_ratio = (double)state->width / (double)e.window.data1; - double h_ratio = (double)state->height / (double)e.window.data2; - SDL_GL_GetDrawableSize(state->window, &state->width, &state->height); - GL_CALL(glViewport(0, 0, state->width, state->height)); - state->real_start /= w_ratio; - state->real_end /= w_ratio; - state->imag_start /= h_ratio; - state->imag_end /= h_ratio; - } + st_resize(state, e.window.data1, e.window.data2); break; } } st_apply_keys(state); } +void st_resize(State *state, int new_width, int new_height) +{ + double w_delta = ((double)new_width - (double)state->width) / 2.0; + double h_delta = ((double)new_height - (double)state->height) / 2.0; + + double real_dist = state->real_end - state->real_start; + double imag_dist = state->imag_end - state->imag_start; + + double width_real_ratio = (double)state->width / real_dist; + double height_imag_ratio = (double)state->height / imag_dist; + + w_delta /= width_real_ratio; + h_delta /= height_imag_ratio; + + state->real_start -= w_delta; + state->real_end += w_delta; + + state->imag_start -= h_delta; + state->imag_end += h_delta; + + SDL_GL_GetDrawableSize(state->window, &state->width, &state->height); + GL_CALL(glViewport(0, 0, state->width, state->height)); +} + static void st_set_key(SDL_Keycode sym, bool value) { switch (sym) |
