Refactored merged rotation code
This commit is contained in:
parent
7e51c35801
commit
56142bd3ba
15
commands.c
15
commands.c
@ -397,22 +397,15 @@ bool i_fit_to_img(arg_t a)
|
|||||||
|
|
||||||
bool i_rotate(arg_t a)
|
bool i_rotate(arg_t a)
|
||||||
{
|
{
|
||||||
rotate_t rot = (rotate_t) a;
|
degree_t degree = (degree_t) a;
|
||||||
|
|
||||||
if (mode == MODE_IMAGE) {
|
if (mode == MODE_IMAGE) {
|
||||||
if (rot == ROTATE_90) {
|
img_rotate(&img, degree);
|
||||||
img_rotate(&img, 1);
|
|
||||||
return true;
|
return true;
|
||||||
} else if (rot == ROTATE_270) {
|
} else {
|
||||||
img_rotate(&img, 3);
|
|
||||||
return true;
|
|
||||||
} else if (rot == ROTATE_180) {
|
|
||||||
img_rotate(&img, 2);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool i_flip(arg_t a)
|
bool i_flip(arg_t a)
|
||||||
{
|
{
|
||||||
|
@ -114,9 +114,9 @@ static const keymap_t keys[] = {
|
|||||||
{ false, XK_E, i_fit_to_win, (arg_t) SCALE_HEIGHT },
|
{ false, XK_E, i_fit_to_win, (arg_t) SCALE_HEIGHT },
|
||||||
{ false, XK_W, i_fit_to_img, (arg_t) None },
|
{ false, XK_W, i_fit_to_img, (arg_t) None },
|
||||||
|
|
||||||
{ false, XK_less, i_rotate, (arg_t) ROTATE_270 },
|
{ false, XK_less, i_rotate, (arg_t) DEGREE_270 },
|
||||||
{ false, XK_greater, i_rotate, (arg_t) ROTATE_90 },
|
{ false, XK_greater, i_rotate, (arg_t) DEGREE_90 },
|
||||||
{ false, XK_question, i_rotate, (arg_t) ROTATE_180 },
|
{ false, XK_question, i_rotate, (arg_t) DEGREE_180 },
|
||||||
|
|
||||||
{ false, XK_backslash, i_flip, (arg_t) FLIP_HORIZONTAL },
|
{ false, XK_backslash, i_flip, (arg_t) FLIP_HORIZONTAL },
|
||||||
{ false, XK_bar, i_flip, (arg_t) FLIP_VERTICAL },
|
{ false, XK_bar, i_flip, (arg_t) FLIP_VERTICAL },
|
||||||
|
17
image.c
17
image.c
@ -650,25 +650,22 @@ bool img_pan_edge(img_t *img, direction_t dir)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void img_rotate(img_t *img, int d)
|
void img_rotate(img_t *img, degree_t d)
|
||||||
{
|
{
|
||||||
win_t *win;
|
|
||||||
int ox, oy, tmp;
|
int ox, oy, tmp;
|
||||||
|
|
||||||
if (img == NULL || img->im == NULL || img->win == NULL)
|
if (img == NULL || img->im == NULL || img->win == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
win = img->win;
|
|
||||||
ox = d == 1 ? img->x : win->w - img->x - img->w * img->zoom;
|
|
||||||
oy = d == 3 ? img->y : win->h - img->y - img->h * img->zoom;
|
|
||||||
|
|
||||||
imlib_context_set_image(img->im);
|
imlib_context_set_image(img->im);
|
||||||
/* rotates by `90 * d` degrees in the clockwise direction */
|
|
||||||
imlib_image_orientate(d);
|
imlib_image_orientate(d);
|
||||||
|
|
||||||
if (d == 1 || d == 3) {
|
if (d == DEGREE_90 || d == DEGREE_270) {
|
||||||
img->x = oy + (win->w - win->h) / 2;
|
ox = d == DEGREE_90 ? img->x : img->win->w - img->x - img->w * img->zoom;
|
||||||
img->y = ox + (win->h - win->w) / 2;
|
oy = d == DEGREE_270 ? img->y : img->win->h - img->y - img->h * img->zoom;
|
||||||
|
|
||||||
|
img->x = oy + (img->win->w - img->win->h) / 2;
|
||||||
|
img->y = ox + (img->win->h - img->win->w) / 2;
|
||||||
|
|
||||||
tmp = img->w;
|
tmp = img->w;
|
||||||
img->w = img->h;
|
img->w = img->h;
|
||||||
|
2
image.h
2
image.h
@ -76,7 +76,7 @@ bool img_move(img_t*, float, float);
|
|||||||
bool img_pan(img_t*, direction_t, int);
|
bool img_pan(img_t*, direction_t, int);
|
||||||
bool img_pan_edge(img_t*, direction_t);
|
bool img_pan_edge(img_t*, direction_t);
|
||||||
|
|
||||||
void img_rotate(img_t*, int);
|
void img_rotate(img_t*, degree_t);
|
||||||
void img_flip(img_t*, flipdir_t);
|
void img_flip(img_t*, flipdir_t);
|
||||||
|
|
||||||
void img_toggle_antialias(img_t*);
|
void img_toggle_antialias(img_t*);
|
||||||
|
Loading…
Reference in New Issue
Block a user