aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarry Jeffery <harry@exec64.co.uk>2017-12-07 21:11:47 +0000
committerHarry Jeffery <harry@exec64.co.uk>2017-12-07 21:11:47 +0000
commit45bf3b3099ba192b115335889e0aaa9381beb879 (patch)
treed689633ae9633b68b5f03ba32f7c334ce64fad49
parent8f3d69f3e83560b168cc43afc57ca52126b81c8d (diff)
downloadimv-45bf3b3099ba192b115335889e0aaa9381beb879.tar.gz
Make viepwort interface opaque
-rw-r--r--src/imv.c20
-rw-r--r--src/viewport.c37
-rw-r--r--src/viewport.h25
3 files changed, 65 insertions, 17 deletions
diff --git a/src/imv.c b/src/imv.c
index 9bbd492..b54ada2 100644
--- a/src/imv.c
+++ b/src/imv.c
@@ -551,7 +551,7 @@ int imv_run(struct imv *imv)
imv_loader_load(imv->loader, current_path,
imv->stdin_image_data, imv->stdin_image_data_len);
imv->loading = true;
- imv->view->playing = true;
+ imv_viewport_set_playing(imv->view, true);
char title[1024];
generate_env_text(imv, &title[0], sizeof title, imv->title_text);
@@ -578,7 +578,7 @@ int imv_run(struct imv *imv)
/* if we're playing an animated gif, tell the loader how much time has
* passed */
- if(imv->view->playing) {
+ if(imv_viewport_is_playing(imv->view)) {
unsigned int dt = current_time - last_time;
/* We cap the delta-time to 100 ms so that if imv is asleep for several
* seconds or more (e.g. suspended), upon waking up it doesn't try to
@@ -860,7 +860,13 @@ static void render_window(struct imv *imv)
}
/* draw our actual image */
- imv_image_draw(imv->image, imv->view->x, imv->view->y, imv->view->scale);
+ {
+ int x, y;
+ double scale;
+ imv_viewport_get_offset(imv->view, &x, &y);
+ imv_viewport_get_scale(imv->view, &scale);
+ imv_image_draw(imv->image, x, y, scale);
+ }
/* if the overlay needs to be drawn, draw that too */
if(imv->overlay_enabled && imv->font) {
@@ -1291,8 +1297,12 @@ static void update_env_vars(struct imv *imv)
snprintf(str, sizeof str, "%d", imv_image_height(imv->image));
setenv("imv_height", str, 1);
- snprintf(str, sizeof str, "%d", (int)(imv->view->scale * 100.0));
- setenv("imv_scale", str, 1);
+ {
+ double scale;
+ imv_viewport_get_scale(imv->view, &scale);
+ snprintf(str, sizeof str, "%d", (int)(scale * 100.0));
+ setenv("imv_scale", str, 1);
+ }
snprintf(str, sizeof str, "%zu", imv->slideshow_image_duration / 1000);
setenv("imv_slidshow_duration", str, 1);
diff --git a/src/viewport.c b/src/viewport.c
index a5df9df..65a269b 100644
--- a/src/viewport.c
+++ b/src/viewport.c
@@ -1,5 +1,15 @@
#include "viewport.h"
+struct imv_viewport {
+ SDL_Window *window;
+ double scale;
+ int x, y;
+ int fullscreen;
+ int redraw;
+ int playing;
+ int locked;
+};
+
struct imv_viewport *imv_viewport_create(SDL_Window *window)
{
struct imv_viewport *view = malloc(sizeof(struct imv_viewport));
@@ -27,6 +37,16 @@ void imv_viewport_toggle_fullscreen(struct imv_viewport *view)
}
}
+void imv_viewport_set_playing(struct imv_viewport *view, bool playing)
+{
+ view->playing = playing;
+}
+
+bool imv_viewport_is_playing(struct imv_viewport *view)
+{
+ return view->playing;
+}
+
void imv_viewport_toggle_playing(struct imv_viewport *view)
{
view->playing = !view->playing;
@@ -40,6 +60,23 @@ void imv_viewport_scale_to_actual(struct imv_viewport *view, const struct imv_im
imv_viewport_center(view, image);
}
+void imv_viewport_get_offset(struct imv_viewport *view, int *x, int *y)
+{
+ if(x) {
+ *x = view->x;
+ }
+ if(y) {
+ *y = view->y;
+ }
+}
+
+void imv_viewport_get_scale(struct imv_viewport *view, double *scale)
+{
+ if(scale) {
+ *scale = view->scale;
+ }
+}
+
void imv_viewport_move(struct imv_viewport *view, int x, int y,
const struct imv_image *image)
{
diff --git a/src/viewport.h b/src/viewport.h
index bda55f1..fd7a6cf 100644
--- a/src/viewport.h
+++ b/src/viewport.h
@@ -1,18 +1,11 @@
#ifndef IMV_VIEWPORT_H
#define IMV_VIEWPORT_H
+#include <stdbool.h>
#include <SDL2/SDL.h>
#include "image.h"
-struct imv_viewport {
- SDL_Window *window;
- double scale;
- int x, y;
- int fullscreen;
- int redraw;
- int playing;
- int locked;
-};
+struct imv_viewport;
/* Used to signify how a a user requested a zoom */
enum imv_zoom_source {
@@ -29,11 +22,20 @@ void imv_viewport_free(struct imv_viewport *view);
/* Toggle their viewport's fullscreen mode. Triggers a redraw */
void imv_viewport_toggle_fullscreen(struct imv_viewport *view);
+/* Set playback of animated gifs */
+void imv_viewport_set_playing(struct imv_viewport *view, bool playing);
+
+/* Get playback status of animated gifs */
+bool imv_viewport_is_playing(struct imv_viewport *view);
+
/* Toggle playback of animated gifs */
void imv_viewport_toggle_playing(struct imv_viewport *view);
-/* Reset the viewport to its initial settings */
-void imv_viewport_reset(struct imv_viewport *view);
+/* Fetch viewport offset/position */
+void imv_viewport_get_offset(struct imv_viewport *view, int *x, int *y);
+
+/* Fetch viewport scale */
+void imv_viewport_get_scale(struct imv_viewport *view, double *scale);
/* Pan the view by the given amounts without letting the image get too far
* off-screen */
@@ -71,5 +73,4 @@ int imv_viewport_needs_redraw(struct imv_viewport *view);
#endif
-
/* vim:set ts=2 sts=2 sw=2 et: */