diff options
author | Harry Jeffery <harry@exec64.co.uk> | 2015-11-27 13:53:19 +0000 |
---|---|---|
committer | Harry Jeffery <harry@exec64.co.uk> | 2015-11-27 13:53:19 +0000 |
commit | 5f6fb9fb0d5cf523d810e5d3812d8172c5eaa50e (patch) | |
tree | 4413a6a514d855609e4dfcfb80a3efc605f386b2 /src/viewport.c | |
parent | b17cb802d0b008e886e194972e661a65b0b28aa9 (diff) | |
download | imv-5f6fb9fb0d5cf523d810e5d3812d8172c5eaa50e.tar.gz |
Retrive viewport image dimensions from texture, not loader
Diffstat (limited to 'src/viewport.c')
-rw-r--r-- | src/viewport.c | 48 |
1 files changed, 22 insertions, 26 deletions
diff --git a/src/viewport.c b/src/viewport.c index f53c0fa..a4004ad 100644 --- a/src/viewport.c +++ b/src/viewport.c @@ -43,21 +43,17 @@ void imv_viewport_toggle_fullscreen(struct imv_viewport *view) } } -void imv_viewport_toggle_playing(struct imv_viewport *view, struct imv_loader *ldr) +void imv_viewport_toggle_playing(struct imv_viewport *view, struct imv_texture *tex) { - if(view->playing) { - view->playing = 0; - } else if(imv_loader_is_animated(ldr)) { - view->playing = 1; - } + view->playing = !view->playing; } -void imv_viewport_scale_to_actual(struct imv_viewport *view, const struct imv_loader *ldr) +void imv_viewport_scale_to_actual(struct imv_viewport *view, const struct imv_texture *tex) { view->scale = 1; view->redraw = 1; view->locked = 1; - imv_viewport_center(view, ldr); + imv_viewport_center(view, tex); } void imv_viewport_move(struct imv_viewport *view, int x, int y) @@ -68,30 +64,30 @@ void imv_viewport_move(struct imv_viewport *view, int x, int y) view->locked = 1; } -void imv_viewport_zoom(struct imv_viewport *view, const struct imv_loader *ldr, enum imv_zoom_source src, int amount) +void imv_viewport_zoom(struct imv_viewport *view, const struct imv_texture *tex, enum imv_zoom_source src, int amount) { double prev_scale = view->scale; int x, y, ww, wh; SDL_GetWindowSize(view->window, &ww, &wh); - /* x and y cordinates are relative to the loader */ + /* x and y cordinates are relative to the image */ if(src == IMV_ZOOM_MOUSE) { SDL_GetMouseState(&x, &y); x -= view->x; y -= view->y; } else { - x = view->scale * ldr->width / 2; - y = view->scale * ldr->height / 2; + x = view->scale * tex->width / 2; + y = view->scale * tex->height / 2; } - const int scaled_width = ldr->width * view->scale; - const int scaled_height = ldr->height * view->scale; + const int scaled_width = tex->width * view->scale; + const int scaled_height = tex->height * view->scale; const int ic_x = view->x + scaled_width/2; const int ic_y = view->y + scaled_height/2; const int wc_x = ww/2; const int wc_y = wh/2; - double delta_scale = 0.04 * ww * amount / ldr->width; + double delta_scale = 0.04 * ww * amount / tex->width; view->scale += delta_scale; const double min_scale = 0.1; @@ -128,35 +124,35 @@ void imv_viewport_zoom(struct imv_viewport *view, const struct imv_loader *ldr, view->locked = 1; } -void imv_viewport_center(struct imv_viewport *view, const struct imv_loader* ldr) +void imv_viewport_center(struct imv_viewport *view, const struct imv_texture *tex) { int ww, wh; SDL_GetWindowSize(view->window, &ww, &wh); - view->x = (ww - ldr->width * view->scale) / 2; - view->y = (wh - ldr->height * view->scale) / 2; + view->x = (ww - tex->width * view->scale) / 2; + view->y = (wh - tex->height * view->scale) / 2; view->locked = 1; view->redraw = 1; } -void imv_viewport_scale_to_window(struct imv_viewport *view, const struct imv_loader* ldr) +void imv_viewport_scale_to_window(struct imv_viewport *view, const struct imv_texture *tex) { int ww, wh; SDL_GetWindowSize(view->window, &ww, &wh); double window_aspect = (double)ww / (double)wh; - double image_aspect = (double)ldr->width / (double)ldr->height; + double image_aspect = (double)tex->width / (double)tex->height; if(window_aspect > image_aspect) { /* Image will become too tall before it becomes too wide */ - view->scale = (double)wh / (double)ldr->height; + view->scale = (double)wh / (double)tex->height; } else { /* Image will become too wide before it becomes too tall */ - view->scale = (double)ww / (double)ldr->width; + view->scale = (double)ww / (double)tex->width; } - imv_viewport_center(view, ldr); + imv_viewport_center(view, tex); view->locked = 0; } @@ -170,13 +166,13 @@ void imv_viewport_set_title(struct imv_viewport *view, char* title) SDL_SetWindowTitle(view->window, title); } -void imv_viewport_updated(struct imv_viewport *view, struct imv_loader* ldr) +void imv_viewport_updated(struct imv_viewport *view, struct imv_texture *tex) { view->redraw = 1; if(view->locked) { return; } - imv_viewport_scale_to_window(view, ldr); - imv_viewport_center(view, ldr); + imv_viewport_scale_to_window(view, tex); + imv_viewport_center(view, tex); } |