From fa4df0897c42bf74bfc280ee6bbf8c306ed8fd23 Mon Sep 17 00:00:00 2001 From: cclark Date: Tue, 14 Feb 2017 13:07:07 +0000 Subject: [PATCH] Orientation commands and file selections In the current implementation, the orientation commands (rotate, mirror etc.) affect only the single image that has focus. With this commit, the right-click menu orientation commands affect only the single image the right-click is made upon. The orientation commands from the main menu Edit/Orientation will affect all selected files. --- src/collect-table.c | 8 ------- src/image.c | 50 +++++++++++++++++++++++++++++--------------- src/image.h | 2 +- src/img-view.c | 12 +++++------ src/layout_image.c | 43 +++++++++++++++++++++++++++++++++++-- src/typedefs.h | 14 ++++++++++++- src/view_file_icon.c | 14 ------------- 7 files changed, 94 insertions(+), 49 deletions(-) diff --git a/src/collect-table.c b/src/collect-table.c index 3efe8712..e6927800 100644 --- a/src/collect-table.c +++ b/src/collect-table.c @@ -62,14 +62,6 @@ enum { CTABLE_COLUMN_COUNT }; -typedef enum { - SELECTION_NONE = 0, - SELECTION_SELECTED = 1 << 0, - SELECTION_PRELIGHT = 1 << 1, - SELECTION_FOCUS = 1 << 2 -} SelectionType; - - #define INFO_SELECTED(x) (x->flag_mask & SELECTION_SELECTED) diff --git a/src/image.c b/src/image.c index 89750a32..57e1d05d 100644 --- a/src/image.c +++ b/src/image.c @@ -375,7 +375,7 @@ static void image_post_process_tile_color_cb(PixbufRenderer *pr, GdkPixbuf **pix } -void image_alter_orientation(ImageWindow *imd, AlterType type) +void image_alter_orientation(ImageWindow *imd, FileData *fd_n, AlterType type) { static const gint rotate_90[] = {1, 6, 7, 8, 5, 2, 3, 4, 1}; static const gint rotate_90_cc[] = {1, 8, 5, 6, 7, 4, 1, 2, 3}; @@ -383,37 +383,49 @@ void image_alter_orientation(ImageWindow *imd, AlterType type) static const gint mirror[] = {1, 2, 1, 4, 3, 6, 5, 8, 7}; static const gint flip[] = {1, 4, 3, 2, 1, 8, 7, 6, 5}; + gint orientation; - if (!imd || !imd->pr || !imd->image_fd) return; + if (!imd || !imd->pr || !imd->image_fd || !fd_n) return; - if (imd->orientation < 1 || imd->orientation > 8) imd->orientation = 1; + orientation = EXIF_ORIENTATION_TOP_LEFT; + { + if (fd_n->user_orientation) + { + orientation = fd_n->user_orientation; + } + else + if (options->metadata.write_orientation) + { + orientation = metadata_read_int(fd_n, ORIENTATION_KEY, EXIF_ORIENTATION_TOP_LEFT); + } + } switch (type) { case ALTER_ROTATE_90: - imd->orientation = rotate_90[imd->orientation]; + orientation = rotate_90[orientation]; break; case ALTER_ROTATE_90_CC: - imd->orientation = rotate_90_cc[imd->orientation]; + orientation = rotate_90_cc[orientation]; break; case ALTER_ROTATE_180: - imd->orientation = rotate_180[imd->orientation]; + orientation = rotate_180[orientation]; break; case ALTER_MIRROR: - imd->orientation = mirror[imd->orientation]; + orientation = mirror[orientation]; break; case ALTER_FLIP: - imd->orientation = flip[imd->orientation]; + orientation = flip[orientation]; break; case ALTER_NONE: - imd->orientation = imd->image_fd->exif_orientation ? imd->image_fd->exif_orientation : 1; + orientation = fd_n->exif_orientation ? fd_n->exif_orientation : 1; break; default: return; break; } - if (imd->orientation != (imd->image_fd->exif_orientation ? imd->image_fd->exif_orientation : 1)) + if (orientation != (fd_n->exif_orientation ? fd_n->exif_orientation : 1)) { if (!options->metadata.write_orientation) { @@ -422,29 +434,33 @@ void image_alter_orientation(ImageWindow *imd, AlterType type) we must however handle switching metadata.write_orientation on and off, therefore we just disable referencing new fd's, not unreferencing the old ones */ - if (imd->image_fd->user_orientation == 0) file_data_ref(imd->image_fd); - imd->image_fd->user_orientation = imd->orientation; + if (fd_n->user_orientation == 0) file_data_ref(fd_n); + fd_n->user_orientation = orientation; } } else { - if (imd->image_fd->user_orientation != 0) file_data_unref(imd->image_fd); - imd->image_fd->user_orientation = 0; + if (fd_n->user_orientation != 0) file_data_unref(fd_n); + fd_n->user_orientation = 0; } if (options->metadata.write_orientation) { if (type == ALTER_NONE) { - metadata_write_revert(imd->image_fd, ORIENTATION_KEY); + metadata_write_revert(fd_n, ORIENTATION_KEY); } else { - metadata_write_int(imd->image_fd, ORIENTATION_KEY, imd->orientation); + metadata_write_int(fd_n, ORIENTATION_KEY, orientation); } } - pixbuf_renderer_set_orientation((PixbufRenderer *)imd->pr, imd->orientation); + if (imd->image_fd == fd_n && !(options->metadata.write_orientation && !options->image.exif_rotate_enable)) + { + imd->orientation = orientation; + pixbuf_renderer_set_orientation((PixbufRenderer *)imd->pr, orientation); + } } void image_set_desaturate(ImageWindow *imd, gboolean desaturate) diff --git a/src/image.h b/src/image.h index b429861c..38e7e008 100644 --- a/src/image.h +++ b/src/image.h @@ -85,7 +85,7 @@ void image_scroll_to_point(ImageWindow *imd, gint x, gint y, gdouble x_align, gdouble y_align); void image_get_scroll_center(ImageWindow *imd, gdouble *x, gdouble *y); void image_set_scroll_center(ImageWindow *imd, gdouble x, gdouble y); -void image_alter_orientation(ImageWindow *imd, AlterType type); +void image_alter_orientation(ImageWindow *imd, FileData *fd, AlterType type); void image_set_desaturate(ImageWindow *imd, gboolean desaturate); gboolean image_get_desaturate(ImageWindow *imd); diff --git a/src/img-view.c b/src/img-view.c index f4768ddf..35b0ca37 100644 --- a/src/img-view.c +++ b/src/img-view.c @@ -421,13 +421,13 @@ static gboolean view_window_key_press_cb(GtkWidget *widget, GdkEventKey *event, switch (event->keyval) { case 'R': case 'r': - image_alter_orientation(imd, ALTER_ROTATE_180); + image_alter_orientation(imd, imd->image_fd, ALTER_ROTATE_180); break; case 'M': case 'm': - image_alter_orientation(imd, ALTER_MIRROR); + image_alter_orientation(imd, imd->image_fd, ALTER_MIRROR); break; case 'F': case 'f': - image_alter_orientation(imd, ALTER_FLIP); + image_alter_orientation(imd, imd->image_fd, ALTER_FLIP); break; case 'G': case 'g': image_set_desaturate(imd, !image_get_desaturate(imd)); @@ -531,10 +531,10 @@ static gboolean view_window_key_press_cb(GtkWidget *widget, GdkEventKey *event, view_overlay_toggle(vw); break; case ']': - image_alter_orientation(imd, ALTER_ROTATE_90); + image_alter_orientation(imd, imd->image_fd, ALTER_ROTATE_90); break; case '[': - image_alter_orientation(imd, ALTER_ROTATE_90_CC); + image_alter_orientation(imd, imd->image_fd, ALTER_ROTATE_90_CC); break; case GDK_KEY_Delete: case GDK_KEY_KP_Delete: if (options->file_ops.enable_delete_key) @@ -1081,7 +1081,7 @@ static void view_alter_cb(GtkWidget *widget, gpointer data) type = GPOINTER_TO_INT(data); if (!vw) return; - image_alter_orientation(vw->imd, type); + image_alter_orientation(vw->imd, vw->imd->image_fd, type); } static void view_wallpaper_cb(GtkWidget *widget, gpointer data) diff --git a/src/layout_image.c b/src/layout_image.c index 966808fa..049e328c 100644 --- a/src/layout_image.c +++ b/src/layout_image.c @@ -48,6 +48,7 @@ #include /* for keyboard values */ +#define FILE_COLUMN_POINTER 0 static GtkWidget *layout_image_pop_menu(LayoutWindow *lw); static void layout_image_set_buttons(LayoutWindow *lw); @@ -484,7 +485,7 @@ static void li_pop_menu_alter_cb(GtkWidget *widget, gpointer data) lw = submenu_item_get_data(widget); type = (AlterType)GPOINTER_TO_INT(data); - image_alter_orientation(lw->image, type); + image_alter_orientation(lw->image, lw->image->image_fd, type); } static void li_pop_menu_new_cb(GtkWidget *widget, gpointer data) @@ -1062,7 +1063,45 @@ void layout_image_alter_orientation(LayoutWindow *lw, AlterType type) { if (!layout_valid(&lw)) return; - image_alter_orientation(lw->image, type); + GtkTreeModel *store; + GList *work; + GtkTreeSelection *selection; + GtkTreePath *tpath; + FileData *fd_n; + GtkTreeIter iter; + IconData *id; + + if (!lw || !lw->vf) return; + + if (lw->vf->type == FILEVIEW_ICON) + { + if (!VFICON(lw->vf)->selection) return; + work = VFICON(lw->vf)->selection; + } + else + { + selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(lw->vf->listview)); + work = gtk_tree_selection_get_selected_rows(selection, &store); + } + + while (work) + { + if (lw->vf->type == FILEVIEW_ICON) + { + id = work->data; + fd_n = id->fd; + work = work->next; + } + else + { + tpath = work->data; + gtk_tree_model_get_iter(store, &iter, tpath); + gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &fd_n, -1); + work = work->next; + } + + image_alter_orientation(lw->image, fd_n, type); + } } void layout_image_reset_orientation(LayoutWindow *lw) diff --git a/src/typedefs.h b/src/typedefs.h index 678a1499..56e347e6 100644 --- a/src/typedefs.h +++ b/src/typedefs.h @@ -843,7 +843,19 @@ struct _ViewFileInfoList guint select_idle_id; /* event source id */ }; -struct _IconData; +typedef enum { + SELECTION_NONE = 0, + SELECTION_SELECTED = 1 << 0, + SELECTION_PRELIGHT = 1 << 1, + SELECTION_FOCUS = 1 << 2 +} SelectionType; + +typedef struct _IconData IconData; +struct _IconData +{ + SelectionType selected; + FileData *fd; +}; struct _ViewFileInfoIcon { diff --git a/src/view_file_icon.c b/src/view_file_icon.c index 1457f81a..920c1e5d 100644 --- a/src/view_file_icon.c +++ b/src/view_file_icon.c @@ -60,20 +60,6 @@ enum { FILE_COLUMN_COUNT }; -typedef enum { - SELECTION_NONE = 0, - SELECTION_SELECTED = 1 << 0, - SELECTION_PRELIGHT = 1 << 1, - SELECTION_FOCUS = 1 << 2 -} SelectionType; - -typedef struct _IconData IconData; -struct _IconData -{ - SelectionType selected; - FileData *fd; -}; - static gint vficon_index_by_id(ViewFile *vf, IconData *in_id); static IconData *vficon_icon_data(ViewFile *vf, FileData *fd) -- 2.20.1