aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichal Koutenský <koutak.m@gmail.com>2015-11-13 22:35:25 +0100
committerHarry Jeffery <harry@exec64.co.uk>2015-11-13 21:45:01 +0000
commit3151dca2eeb110adabb5788c665d17bd89d6a9c7 (patch)
treeeb55fc95609d46896d41a7d0cd99b14a1123900e /src
parent0b2be425c3427f0c1d311b4523c107b25a0e8c0c (diff)
downloadimv-3151dca2eeb110adabb5788c665d17bd89d6a9c7.tar.gz
imv_navigator_set_path
Diffstat (limited to 'src')
-rw-r--r--src/main.c14
-rw-r--r--src/navigator.c10
-rw-r--r--src/navigator.h1
3 files changed, 17 insertions, 8 deletions
diff --git a/src/main.c b/src/main.c
index 9cd9563..44a4a6c 100644
--- a/src/main.c
+++ b/src/main.c
@@ -31,7 +31,7 @@ struct {
int stdin;
int recursive;
int actual;
- long int start_at;
+ int start_at;
} g_options = {0,0,0,0,0};
void print_usage(const char* name)
@@ -48,7 +48,7 @@ void print_usage(const char* name)
" -h: Print this help\n"
"\n"
"Options:\n"
- " -n NUM: Starts at picture number NUM.\n"
+ " -n NUM: Start at picture number NUM.\n"
"\n"
"Mouse:\n"
" Click+Drag to Pan\n"
@@ -93,7 +93,7 @@ void parse_args(int argc, char** argv)
const char* name = argv[0];
char o;
char* end;
- long int n;
+ int n;
while((o = getopt(argc, argv, "firahn:")) != -1) {
switch(o) {
@@ -108,9 +108,9 @@ void parse_args(int argc, char** argv)
case 'n':
n = strtol(optarg,&end,0);
if(*end != '\0' || n <= 0) {
- fprintf(stderr, "Warning: wrong value for '-n'.\n");
+ fprintf(stderr, "Warning: wrong value for '-n'.\n");
} else {
- g_options.start_at = n - 1;
+ g_options.start_at = n - 1;
}
break;
case '?':
@@ -203,9 +203,7 @@ int main(int argc, char** argv)
double last_time = SDL_GetTicks() / 1000.0;
- for(long int i = 0; i < g_options.start_at; ++i) {
- imv_navigator_next_path(&nav);
- }
+ imv_navigator_set_path(&nav, g_options.start_at);
int quit = 0;
while(!quit) {
diff --git a/src/navigator.c b/src/navigator.c
index 1974f8a..d719791 100644
--- a/src/navigator.c
+++ b/src/navigator.c
@@ -175,6 +175,16 @@ void imv_navigator_remove_current_path(struct imv_navigator *nav)
nav->changed = 1;
}
+void imv_navigator_set_path(struct imv_navigator *nav, const int path)
+{
+ if(path <= 0 || path >= nav->num_paths) {
+ return;
+ }
+ int prev_path = nav->cur_path;
+ nav->cur_path = path;
+ nav->changed = prev_path != nav->cur_path;
+}
+
int imv_navigator_has_changed(struct imv_navigator *nav)
{
if(nav->changed) {
diff --git a/src/navigator.h b/src/navigator.h
index c6d4f8e..c06bcce 100644
--- a/src/navigator.h
+++ b/src/navigator.h
@@ -37,6 +37,7 @@ const char *imv_navigator_get_current_path(struct imv_navigator *nav);
void imv_navigator_next_path(struct imv_navigator *nav);
void imv_navigator_prev_path(struct imv_navigator *nav);
void imv_navigator_remove_current_path(struct imv_navigator *nav);
+void imv_navigator_set_path(struct imv_navigator *nav, const int path);
int imv_navigator_has_changed(struct imv_navigator *nav);