From 51d91d63181f82f605a8b9de6d280622ef697630 Mon Sep 17 00:00:00 2001 From: nirav Date: Fri, 28 Sep 2018 07:57:47 +0530 Subject: Refactoring --- src/file.c | 2 ++ src/file.h | 4 ---- src/image.c | 14 ++++++++++++++ src/image.h | 10 ++-------- src/input.c | 18 +++++++++--------- 5 files changed, 27 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/file.c b/src/file.c index dcbcbf0..459fc5d 100644 --- a/src/file.c +++ b/src/file.c @@ -9,6 +9,8 @@ #include #include +static int curr_file_index, file_list_count; +static char **file_list; static char **extensions = NULL; char *get_filename_ext(const char *file_name) diff --git a/src/file.h b/src/file.h index 7e8c167..a2fbd6c 100644 --- a/src/file.h +++ b/src/file.h @@ -1,10 +1,6 @@ #ifndef __FILE_H #define __FILE_H -char **file_list; -char *curr_file_name; -int curr_file_index, file_list_count; - int scan(const char *file_name); char *get_next_file(); char *get_prev_file(); diff --git a/src/image.c b/src/image.c index 6150988..23a76e0 100644 --- a/src/image.c +++ b/src/image.c @@ -2,6 +2,14 @@ #include "window.h" #include +static GtkWidget *image; +static GdkPixbuf *pixbuf; +static GdkPixbuf *curr_pixbuf; +static int pixbuf_width, pixbuf_height, curr_pixbuf_width, curr_pixbuf_height; +static double aspect_ratio; +static double curr_zoom; +static enum scale_mode curr_scale_mod; + GtkWidget *new_image() { image = gtk_image_new(); @@ -13,6 +21,7 @@ int load_image(char *file_name) GError *error = NULL; if (pixbuf != NULL) g_object_unref(pixbuf); + gtk_image_clear(GTK_IMAGE(image)); pixbuf = gdk_pixbuf_new_from_file(file_name, &error); if (error) return -1; @@ -95,3 +104,8 @@ void zoom(int type) update_pixbuf(); } + +enum scale_mode get_current_scale_mode() +{ + return curr_scale_mod; +} diff --git a/src/image.h b/src/image.h index dfbd9ff..f248924 100644 --- a/src/image.h +++ b/src/image.h @@ -8,18 +8,12 @@ enum scale_mode { fit = 0, zoomed = 1, -} curr_scale_mod; - -GtkWidget *image; -GdkPixbuf *pixbuf; -GdkPixbuf *curr_pixbuf; -int pixbuf_width, pixbuf_height, curr_pixbuf_width, curr_pixbuf_height; -double aspect_ratio; -double curr_zoom; +}; GtkWidget *new_image(); int load_image(char *file_name); void fit_image(); void zoom(int type); +enum scale_mode get_current_scale_mode(); #endif diff --git a/src/input.c b/src/input.c index 457cdcc..6e78a84 100644 --- a/src/input.c +++ b/src/input.c @@ -68,31 +68,31 @@ void handle_key_press(GdkEvent *event) prev(); break; case GDK_KEY_Up: - if (curr_scale_mod == fit || state & GDK_SHIFT_MASK) + if (get_current_scale_mode() == fit || state & GDK_SHIFT_MASK) prev(); else scroll_window(0, -SCROLLAMMOUNT); break; case GDK_KEY_Down: - if (curr_scale_mod == fit || state & GDK_SHIFT_MASK) + if (get_current_scale_mode() == fit || state & GDK_SHIFT_MASK) next(); else scroll_window(0, SCROLLAMMOUNT); break; case GDK_KEY_Right: - if (curr_scale_mod == fit || state & GDK_SHIFT_MASK) + if (get_current_scale_mode() == fit || state & GDK_SHIFT_MASK) next(); else scroll_window(SCROLLAMMOUNT, 0); break; case GDK_KEY_Left: - if (curr_scale_mod == fit || state & GDK_SHIFT_MASK) + if (get_current_scale_mode() == fit || state & GDK_SHIFT_MASK) prev(); else scroll_window(-SCROLLAMMOUNT, 0); break; case GDK_KEY_j: - if (curr_scale_mod == fit) + if (get_current_scale_mode() == fit) next(); else scroll_window(0, SCROLLAMMOUNT); @@ -101,7 +101,7 @@ void handle_key_press(GdkEvent *event) next(); break; case GDK_KEY_k: - if (curr_scale_mod == fit) + if (get_current_scale_mode() == fit) prev(); else scroll_window(0, -SCROLLAMMOUNT); @@ -110,7 +110,7 @@ void handle_key_press(GdkEvent *event) prev(); break; case GDK_KEY_l: - if (curr_scale_mod == fit) + if (get_current_scale_mode() == fit) next(); else scroll_window(SCROLLAMMOUNT, 0); @@ -119,7 +119,7 @@ void handle_key_press(GdkEvent *event) next(); break; case GDK_KEY_h: - if (curr_scale_mod == fit) + if (get_current_scale_mode() == fit) prev(); else scroll_window(-SCROLLAMMOUNT, 0); @@ -205,7 +205,7 @@ gboolean resize_done(gpointer data) void handle_resize() { - if (curr_scale_mod != fit) + if (get_current_scale_mode() != fit) return; static guint id = 0; if (id) -- cgit v1.2.3