aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarry Jeffery <harry@exec64.co.uk>2015-11-27 13:53:19 +0000
committerHarry Jeffery <harry@exec64.co.uk>2015-11-27 13:53:19 +0000
commit5f6fb9fb0d5cf523d810e5d3812d8172c5eaa50e (patch)
tree4413a6a514d855609e4dfcfb80a3efc605f386b2
parentb17cb802d0b008e886e194972e661a65b0b28aa9 (diff)
downloadimv-5f6fb9fb0d5cf523d810e5d3812d8172c5eaa50e.tar.gz
Retrive viewport image dimensions from texture, not loader
-rw-r--r--src/main.c18
-rw-r--r--src/viewport.c48
-rw-r--r--src/viewport.h14
3 files changed, 38 insertions, 42 deletions
diff --git a/src/main.c b/src/main.c
index 5a9c54c..3552a6b 100644
--- a/src/main.c
+++ b/src/main.c
@@ -309,24 +309,24 @@ int main(int argc, char** argv)
case SDLK_EQUALS:
case SDLK_i:
case SDLK_UP:
- imv_viewport_zoom(&view, &ldr, IMV_ZOOM_KEYBOARD, 1);
+ imv_viewport_zoom(&view, &tex, IMV_ZOOM_KEYBOARD, 1);
break;
case SDLK_MINUS:
case SDLK_o:
case SDLK_DOWN:
- imv_viewport_zoom(&view, &ldr, IMV_ZOOM_KEYBOARD, -1);
+ imv_viewport_zoom(&view, &tex, IMV_ZOOM_KEYBOARD, -1);
break;
- case SDLK_a: imv_viewport_scale_to_actual(&view, &ldr);break;
- case SDLK_r: imv_viewport_scale_to_window(&view, &ldr);break;
- case SDLK_c: imv_viewport_center(&view, &ldr); break;
+ case SDLK_a: imv_viewport_scale_to_actual(&view, &tex);break;
+ case SDLK_r: imv_viewport_scale_to_window(&view, &tex);break;
+ case SDLK_c: imv_viewport_center(&view, &tex); break;
case SDLK_j: imv_viewport_move(&view, 0, -50); break;
case SDLK_k: imv_viewport_move(&view, 0, 50); break;
case SDLK_h: imv_viewport_move(&view, 50, 0); break;
case SDLK_l: imv_viewport_move(&view, -50, 0); break;
case SDLK_x: imv_navigator_remove_current_path(&nav); break;
case SDLK_f: imv_viewport_toggle_fullscreen(&view); break;
- case SDLK_PERIOD: imv_loader_load_next_frame(&ldr); break;
- case SDLK_SPACE: imv_viewport_toggle_playing(&view, &ldr);break;
+ case SDLK_PERIOD: imv_loader_load_next_frame(&ldr); break;
+ case SDLK_SPACE: imv_viewport_toggle_playing(&view, &tex);break;
case SDLK_p: puts(imv_navigator_get_current_path(&nav));break;
case SDLK_d:
g_options.overlay = !g_options.overlay;
@@ -335,7 +335,7 @@ int main(int argc, char** argv)
}
break;
case SDL_MOUSEWHEEL:
- imv_viewport_zoom(&view, &ldr, IMV_ZOOM_MOUSE, e.wheel.y);
+ imv_viewport_zoom(&view, &tex, IMV_ZOOM_MOUSE, e.wheel.y);
break;
case SDL_MOUSEMOTION:
if(e.motion.state & SDL_BUTTON_LMASK) {
@@ -343,7 +343,7 @@ int main(int argc, char** argv)
}
break;
case SDL_WINDOWEVENT:
- imv_viewport_updated(&view, &ldr);
+ imv_viewport_updated(&view, &tex);
break;
}
}
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);
}
diff --git a/src/viewport.h b/src/viewport.h
index ad3ac23..606c155 100644
--- a/src/viewport.h
+++ b/src/viewport.h
@@ -19,7 +19,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <SDL2/SDL.h>
-#include "loader.h"
+#include "texture.h"
struct imv_viewport {
SDL_Window *window;
@@ -40,15 +40,15 @@ void imv_init_viewport(struct imv_viewport *view, SDL_Window *window);
void imv_destroy_viewport(struct imv_viewport *view);
void imv_viewport_toggle_fullscreen(struct imv_viewport*);
-void imv_viewport_toggle_playing(struct imv_viewport*, struct imv_loader*);
+void imv_viewport_toggle_playing(struct imv_viewport*, struct imv_texture*);
void imv_viewport_reset(struct imv_viewport*);
void imv_viewport_move(struct imv_viewport*, int, int);
-void imv_viewport_zoom(struct imv_viewport*, const struct imv_loader*, enum imv_zoom_source, int);
-void imv_viewport_center(struct imv_viewport*, const struct imv_loader*);
-void imv_viewport_scale_to_actual(struct imv_viewport*, const struct imv_loader*);
-void imv_viewport_scale_to_window(struct imv_viewport*, const struct imv_loader*);
+void imv_viewport_zoom(struct imv_viewport*, const struct imv_texture*, enum imv_zoom_source, int);
+void imv_viewport_center(struct imv_viewport*, const struct imv_texture*);
+void imv_viewport_scale_to_actual(struct imv_viewport*, const struct imv_texture*);
+void imv_viewport_scale_to_window(struct imv_viewport*, const struct imv_texture*);
void imv_viewport_set_redraw(struct imv_viewport*);
void imv_viewport_set_title(struct imv_viewport*, char*);
-void imv_viewport_updated(struct imv_viewport*, struct imv_loader*);
+void imv_viewport_updated(struct imv_viewport*, struct imv_texture*);
#endif