aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJose Diez <jose.manuel.diez@gmail.com>2015-11-11 16:05:32 +0000
committerJose Diez <jose.manuel.diez@gmail.com>2015-11-11 16:05:32 +0000
commitc53ca5a9c59626a90551e2eaa00ad3e4247b3734 (patch)
tree52530100ced9dd7d20bc95d031a51b07a70796b3 /src
parentee3c3432cbc4a988c534b00cb274a11e3e23d6f8 (diff)
downloadimv-c53ca5a9c59626a90551e2eaa00ad3e4247b3734.tar.gz
Viewport: autoscale and center by default unless interacted with
Diffstat (limited to 'src')
-rw-r--r--src/main.c11
-rw-r--r--src/viewport.c17
-rw-r--r--src/viewport.h2
3 files changed, 21 insertions, 9 deletions
diff --git a/src/main.c b/src/main.c
index 2efeec3..e9134f5 100644
--- a/src/main.c
+++ b/src/main.c
@@ -28,12 +28,11 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#include "viewport.h"
struct {
- int autoscale;
int fullscreen;
int stdin;
int center;
int recursive;
-} g_options = {0,0,0,0,0};
+} g_options = {0,0,0,0};
void print_usage(const char* name)
{
@@ -44,7 +43,6 @@ void print_usage(const char* name)
" -i: Read paths from stdin. One path per line.\n"
" -r: Recursively search input paths.\n"
" -f: Start in fullscreen mode\n"
- " -s: Auto scale images to fit window\n"
" -c: Center images in the window\n"
" -h: Print this help\n"
"\n"
@@ -77,7 +75,6 @@ void parse_arg(const char* name, const char* arg)
for(const char *o = arg; *o != 0; ++o) {
switch(*o) {
case 'f': g_options.fullscreen = 1; break;
- case 's': g_options.autoscale = 1; break;
case 'c': g_options.center = 1; break;
case 'i': g_options.stdin = 1; break;
case 'r': g_options.recursive = 1; break;
@@ -213,7 +210,7 @@ int main(int argc, char** argv)
}
break;
case SDL_WINDOWEVENT:
- imv_viewport_set_redraw(&view);
+ imv_viewport_updated(&view, &img);
break;
}
}
@@ -243,10 +240,6 @@ int main(int argc, char** argv)
imv_viewport_set_title(&view, title);
imv_viewport_reset(&view);
}
- /* Autoscale if requested */
- if(g_options.autoscale) {
- imv_viewport_scale_to_window(&view, &img);
- }
if(g_options.center) {
imv_viewport_center(&view, &img);
}
diff --git a/src/viewport.c b/src/viewport.c
index 1630604..46c6ae7 100644
--- a/src/viewport.c
+++ b/src/viewport.c
@@ -26,6 +26,7 @@ void imv_init_viewport(struct imv_viewport *view, SDL_Window *window)
view->scale = 1;
view->x = view->y = view->fullscreen = view->redraw = 0;
view->playing = 1;
+ view->locked = 0;
}
void imv_destroy_viewport(struct imv_viewport *view)
@@ -59,6 +60,7 @@ void imv_viewport_reset(struct imv_viewport *view)
view->scale = 1;
view->x = view->y = 0;
view->redraw = 1;
+ view->locked = 0;
}
void imv_viewport_move(struct imv_viewport *view, int x, int y)
@@ -66,6 +68,7 @@ void imv_viewport_move(struct imv_viewport *view, int x, int y)
view->x += x;
view->y += y;
view->redraw = 1;
+ view->locked = 1;
}
void imv_viewport_zoom(struct imv_viewport *view, int amount)
@@ -76,6 +79,7 @@ void imv_viewport_zoom(struct imv_viewport *view, int amount)
else if (view->scale < 0.01)
view->scale = 0.1;
view->redraw = 1;
+ view->locked = 1;
}
void imv_viewport_center(struct imv_viewport *view, const struct imv_image* img)
@@ -86,6 +90,7 @@ void imv_viewport_center(struct imv_viewport *view, const struct imv_image* img)
view->x = (ww - img->width * view->scale) / 2;
view->y = (wh - img->height * view->scale) / 2;
+ view->locked = 0;
view->redraw = 1;
}
@@ -106,6 +111,7 @@ void imv_viewport_scale_to_window(struct imv_viewport *view, const struct imv_im
}
imv_viewport_center(view, img);
+ view->locked = 0;
}
void imv_viewport_set_redraw(struct imv_viewport *view)
@@ -117,3 +123,14 @@ 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_image* img)
+{
+ view->redraw = 1;
+ if(view->locked) {
+ return;
+ }
+
+ imv_viewport_scale_to_window(view, img);
+ imv_viewport_center(view, img);
+}
diff --git a/src/viewport.h b/src/viewport.h
index 2cff15c..5fb763a 100644
--- a/src/viewport.h
+++ b/src/viewport.h
@@ -30,6 +30,7 @@ struct imv_viewport {
int fullscreen;
int redraw;
int playing;
+ int locked;
};
void imv_init_viewport(struct imv_viewport *view, SDL_Window *window);
@@ -44,5 +45,6 @@ void imv_viewport_center(struct imv_viewport*, const struct imv_image*);
void imv_viewport_scale_to_window(struct imv_viewport*, const struct imv_image*);
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_image*);
#endif