Skip to content

Commit

Permalink
Use a specific enum for image.zoom_mode values (ZoomMode) and
Browse files Browse the repository at this point in the history
simplify calls to image_zoom_get_default(), dropping last parameter
which was always options->image.zoom_mode.
  • Loading branch information
Laurent Monin committed Jul 15, 2008
1 parent e51449e commit 46f96c8
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 50 deletions.
32 changes: 12 additions & 20 deletions src/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -1312,29 +1312,21 @@ gchar *image_zoom_get_as_text(ImageWindow *imd)
return g_strdup_printf("%.*f :%s%.*f", pl, l, approx, pr, r);
}

gdouble image_zoom_get_default(ImageWindow *imd, gint mode)
gdouble image_zoom_get_default(ImageWindow *imd)
{
gdouble zoom;
gdouble zoom = 1.0;

if (mode == ZOOM_RESET_ORIGINAL)
{
zoom = 1.0;
}
else if (mode == ZOOM_RESET_FIT_WINDOW)
{
switch (options->image.zoom_mode)
{
case ZOOM_RESET_ORIGINAL:
break;
case ZOOM_RESET_FIT_WINDOW:
zoom = 0.0;
}
else
{
if (imd)
{
zoom = image_zoom_get(imd);
}
else
{
zoom = 1.0;
}
}
break;
case ZOOM_RESET_NONE:
if (imd) zoom = image_zoom_get(imd);
break;
}

return zoom;
}
Expand Down
2 changes: 1 addition & 1 deletion src/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void image_zoom_set_fill_geometry(ImageWindow *imd, gint vertical);
gdouble image_zoom_get(ImageWindow *imd);
gdouble image_zoom_get_real(ImageWindow *imd);
gchar *image_zoom_get_as_text(ImageWindow *imd);
gdouble image_zoom_get_default(ImageWindow *imd, gint mode);
gdouble image_zoom_get_default(ImageWindow *imd);

/* read ahead, pass NULL to cancel */
void image_prebuffer_set(ImageWindow *imd, FileData *fd);
Expand Down
26 changes: 13 additions & 13 deletions src/img-view.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ static void view_collection_step(ViewWindow *vw, gint next)

if (info)
{
image_change_from_collection(imd, cd, info, image_zoom_get_default(imd, options->image.zoom_mode));
image_change_from_collection(imd, cd, info, image_zoom_get_default(imd));

if (read_ahead_info) image_prebuffer_set(imd, read_ahead_info->fd);
}
Expand Down Expand Up @@ -166,7 +166,7 @@ static void view_collection_step_to_end(ViewWindow *vw, gint last)

if (info)
{
image_change_from_collection(imd, cd, info, image_zoom_get_default(imd, options->image.zoom_mode));
image_change_from_collection(imd, cd, info, image_zoom_get_default(imd));
if (read_ahead_info) image_prebuffer_set(imd, read_ahead_info->fd);
}
}
Expand Down Expand Up @@ -226,7 +226,7 @@ static void view_list_step(ViewWindow *vw, gint next)

vw->list_pointer = work;
fd = work->data;
image_change_fd(imd, fd, image_zoom_get_default(imd, options->image.zoom_mode));
image_change_fd(imd, fd, image_zoom_get_default(imd));

if (options->image.enable_read_ahead && work_ahead)
{
Expand Down Expand Up @@ -257,7 +257,7 @@ static void view_list_step_to_end(ViewWindow *vw, gint last)

vw->list_pointer = work;
fd = work->data;
image_change_fd(imd, fd, image_zoom_get_default(imd, options->image.zoom_mode));
image_change_fd(imd, fd, image_zoom_get_default(imd));

if (options->image.enable_read_ahead && work_ahead)
{
Expand Down Expand Up @@ -872,7 +872,7 @@ static ViewWindow *real_view_window_new(FileData *fd, GList *list, CollectionDat
G_CALLBACK(view_window_key_press_cb), vw);
if (cd && info)
{
image_change_from_collection(vw->imd, cd, info, image_zoom_get_default(NULL, options->image.zoom_mode));
image_change_from_collection(vw->imd, cd, info, image_zoom_get_default(NULL));
if (options->image.enable_read_ahead)
{
CollectInfo * r_info = collection_next_by_info(cd, info);
Expand All @@ -884,7 +884,7 @@ static ViewWindow *real_view_window_new(FileData *fd, GList *list, CollectionDat
{
view_window_set_list(vw, list);
vw->list_pointer = vw->list;
image_change_fd(vw->imd, (FileData *)vw->list->data, image_zoom_get_default(NULL, options->image.zoom_mode));
image_change_fd(vw->imd, (FileData *)vw->list->data, image_zoom_get_default(NULL));

if (options->image.enable_read_ahead)
{
Expand All @@ -894,7 +894,7 @@ static ViewWindow *real_view_window_new(FileData *fd, GList *list, CollectionDat
}
else
{
image_change_fd(vw->imd, fd, image_zoom_get_default(NULL, options->image.zoom_mode));
image_change_fd(vw->imd, fd, image_zoom_get_default(NULL));
}

if (image_zoom_get(vw->imd) == 0.0)
Expand Down Expand Up @@ -1386,7 +1386,7 @@ static void view_dir_list_do(ViewWindow *vw, GList *list, gint skip, gint recurs

vw->list_pointer = vw->list;
fd = vw->list->data;
image_change_fd(vw->imd, fd, image_zoom_get_default(vw->imd, options->image.zoom_mode));
image_change_fd(vw->imd, fd, image_zoom_get_default(vw->imd));

work = vw->list->next;
if (options->image.enable_read_ahead && work)
Expand All @@ -1397,7 +1397,7 @@ static void view_dir_list_do(ViewWindow *vw, GList *list, gint skip, gint recurs
}
else
{
image_change_fd(vw->imd, NULL, image_zoom_get_default(vw->imd, options->image.zoom_mode));
image_change_fd(vw->imd, NULL, image_zoom_get_default(vw->imd));
}
}

Expand Down Expand Up @@ -1516,7 +1516,7 @@ static void view_window_get_dnd_data(GtkWidget *widget, GdkDragContext *context,

if (source && info_list)
{
image_change_from_collection(imd, source, info_list->data, image_zoom_get_default(imd, options->image.zoom_mode));
image_change_from_collection(imd, source, info_list->data, image_zoom_get_default(imd));
}
else
{
Expand All @@ -1527,7 +1527,7 @@ static void view_window_get_dnd_data(GtkWidget *widget, GdkDragContext *context,

vw->list_pointer = vw->list;
}
image_change_fd(imd, fd, image_zoom_get_default(imd, options->image.zoom_mode));
image_change_fd(imd, fd, image_zoom_get_default(imd));
}
}
}
Expand Down Expand Up @@ -1633,7 +1633,7 @@ static void view_real_removed(ViewWindow *vw, FileData *fd)
}
if (image_get_fd(imd) == image_fd)
{
image_change_fd(imd, NULL, image_zoom_get_default(imd, options->image.zoom_mode));
image_change_fd(imd, NULL, image_zoom_get_default(imd));
}
}

Expand Down Expand Up @@ -1679,7 +1679,7 @@ static void view_real_removed(ViewWindow *vw, FileData *fd)
fd = NULL;
}

image_change_fd(imd, fd, image_zoom_get_default(imd, options->image.zoom_mode));
image_change_fd(imd, fd, image_zoom_get_default(imd));
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/layout_image.c
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,7 @@ void layout_image_set_fd(LayoutWindow *lw, FileData *fd)

image_get_scroll_center(lw->image, &sx, &sy);

image_change_fd(lw->image, fd, image_zoom_get_default(lw->image, options->image.zoom_mode));
image_change_fd(lw->image, fd, image_zoom_get_default(lw->image));

image_set_scroll_center(lw->image, sx, sy);

Expand Down Expand Up @@ -1273,7 +1273,7 @@ static void layout_image_set_collection_real(LayoutWindow *lw, CollectionData *c
{
if (!layout_valid(&lw)) return;

image_change_from_collection(lw->image, cd, info, image_zoom_get_default(lw->image, options->image.zoom_mode));
image_change_from_collection(lw->image, cd, info, image_zoom_get_default(lw->image));
if (options->image.enable_read_ahead)
{
CollectInfo *r_info;
Expand Down
4 changes: 0 additions & 4 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@

#define GQ_COLLECTION_EXT ".gqv"

#define ZOOM_RESET_ORIGINAL 0
#define ZOOM_RESET_FIT_WINDOW 1
#define ZOOM_RESET_NONE 2

#define SCROLL_RESET_TOPLEFT 0
#define SCROLL_RESET_CENTER 1
#define SCROLL_RESET_NOCHANGE 2
Expand Down
2 changes: 1 addition & 1 deletion src/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ struct _ConfOptions
guint dither_quality;
gboolean enable_read_ahead;

gint zoom_mode;
ZoomMode zoom_mode;
gboolean zoom_2pass;
gboolean zoom_to_fit_allow_expand;
guint zoom_quality;
Expand Down
12 changes: 6 additions & 6 deletions src/rcfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -442,12 +442,12 @@ static gboolean save_options_to(const gchar *utf8_path, ConfOptions *options)
"# fit\n"
"# dont_change\n");
secure_fprintf(ssi, "image.zoom_mode: ");
if (options->image.zoom_mode == ZOOM_RESET_ORIGINAL)
secure_fprintf(ssi, "original\n");
else if (options->image.zoom_mode == ZOOM_RESET_FIT_WINDOW)
secure_fprintf(ssi, "fit\n");
else if (options->image.zoom_mode == ZOOM_RESET_NONE)
secure_fprintf(ssi, "dont_change\n");
switch (options->image.zoom_mode)
{
case ZOOM_RESET_ORIGINAL: secure_fprintf(ssi, "original\n"); break;
case ZOOM_RESET_FIT_WINDOW: secure_fprintf(ssi, "fit\n"); break;
case ZOOM_RESET_NONE: secure_fprintf(ssi, "dont_change\n"); break;
}
WRITE_SEPARATOR();
WRITE_BOOL(image.zoom_2pass);
WRITE_BOOL(image.zoom_to_fit_allow_expand);
Expand Down
6 changes: 3 additions & 3 deletions src/slideshow.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ static gint slideshow_step(SlideShowData *ss, gboolean forward)
if (ss->filelist)
{
ss->slide_fd = file_data_ref((FileData *)g_list_nth_data(ss->filelist, row));
image_change_fd(ss->imd, ss->slide_fd, image_zoom_get_default(ss->imd, options->image.zoom_mode));
image_change_fd(ss->imd, ss->slide_fd, image_zoom_get_default(ss->imd));
}
else if (ss->cd)
{
Expand All @@ -192,15 +192,15 @@ static gint slideshow_step(SlideShowData *ss, gboolean forward)
info = g_list_nth_data(ss->cd->list, row);
ss->slide_fd = file_data_ref(info->fd);

image_change_from_collection(ss->imd, ss->cd, info, image_zoom_get_default(ss->imd, options->image.zoom_mode));
image_change_from_collection(ss->imd, ss->cd, info, image_zoom_get_default(ss->imd));
}
else
{
ss->slide_fd = file_data_ref(layout_list_get_fd(ss->layout, row));

if (ss->from_selection)
{
image_change_fd(ss->imd, ss->slide_fd, image_zoom_get_default(ss->imd, options->image.zoom_mode));
image_change_fd(ss->imd, ss->slide_fd, image_zoom_get_default(ss->imd));
layout_status_update_info(ss->layout, NULL);
}
else
Expand Down
6 changes: 6 additions & 0 deletions src/typedefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
#ifndef TYPEDEFS_H
#define TYPEDEFS_H

typedef enum {
ZOOM_RESET_ORIGINAL = 0,
ZOOM_RESET_FIT_WINDOW = 1,
ZOOM_RESET_NONE = 2
} ZoomMode;

typedef enum {
MOUSE_BUTTON_LEFT = 1,
MOUSE_BUTTON_MIDDLE = 2,
Expand Down

0 comments on commit 46f96c8

Please sign in to comment.