Skip to content

Commit

Permalink
Orientation commands and file selections
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cclark committed Feb 14, 2017
1 parent 3c2b3ad commit fa4df08
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 49 deletions.
8 changes: 0 additions & 8 deletions src/collect-table.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
50 changes: 33 additions & 17 deletions src/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -375,45 +375,57 @@ 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};
static const gint rotate_180[] = {1, 3, 4, 1, 2, 7, 8, 5, 6};
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)
{
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
12 changes: 6 additions & 6 deletions src/img-view.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
43 changes: 41 additions & 2 deletions src/layout_image.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

#include <gdk/gdkkeysyms.h> /* for keyboard values */

#define FILE_COLUMN_POINTER 0

static GtkWidget *layout_image_pop_menu(LayoutWindow *lw);
static void layout_image_set_buttons(LayoutWindow *lw);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 13 additions & 1 deletion src/typedefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
14 changes: 0 additions & 14 deletions src/view_file_icon.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit fa4df08

Please sign in to comment.