Krolyxon
Commit 56142bd

Branches

Refs →

nsxiv56142bd

Refactored merged rotation code

Author
Bert Münnich
Date
2013-08-10 15:55 +0200
Parent
7e51c35
Commit
56142bd3bafedf51882b368ab08a580ac98f2619

+20 −30

5 files changed

  1. M commands.c +5 −12
  2. M config.def.h +3 −3
  3. M image.c +7 −10
  4. M image.h +1 −1
  5. M types.h +4 −4
M commands.c View
@@ -397,21 +397,14 @@ bool i_fit_to_img(arg_t a)
397397
398398 bool i_rotate(arg_t a)
399399 {
400− rotate_t rot = (rotate_t) a;
400+ degree_t degree = (degree_t) a;
401401
402402 if (mode == MODE_IMAGE) {
403− if (rot == ROTATE_90) {
404− img_rotate(&img, 1);
405− return true;
406− } else if (rot == ROTATE_270) {
407− img_rotate(&img, 3);
408− return true;
409− } else if (rot == ROTATE_180) {
410− img_rotate(&img, 2);
411− return true;
412− }
403+ img_rotate(&img, degree);
404+ return true;
405+ } else {
406+ return false;
413407 }
414− return false;
415408 }
416409
417410 bool i_flip(arg_t a)
M config.def.h View
@@ -114,9 +114,9 @@ static const keymap_t keys[] = {
114114 { false, XK_E, i_fit_to_win, (arg_t) SCALE_HEIGHT },
115115 { false, XK_W, i_fit_to_img, (arg_t) None },
116116
117− { false, XK_less, i_rotate, (arg_t) ROTATE_270 },
118− { false, XK_greater, i_rotate, (arg_t) ROTATE_90 },
119− { false, XK_question, i_rotate, (arg_t) ROTATE_180 },
117+ { false, XK_less, i_rotate, (arg_t) DEGREE_270 },
118+ { false, XK_greater, i_rotate, (arg_t) DEGREE_90 },
119+ { false, XK_question, i_rotate, (arg_t) DEGREE_180 },
120120
121121 { false, XK_backslash, i_flip, (arg_t) FLIP_HORIZONTAL },
122122 { false, XK_bar, i_flip, (arg_t) FLIP_VERTICAL },
M image.c View
@@ -650,25 +650,22 @@ bool img_pan_edge(img_t *img, direction_t dir)
650650 }
651651 }
652652
653−void img_rotate(img_t *img, int d)
653+void img_rotate(img_t *img, degree_t d)
654654 {
655− win_t *win;
656655 int ox, oy, tmp;
657656
658657 if (img == NULL || img->im == NULL || img->win == NULL)
659658 return;
660659
661− win = img->win;
662− ox = d == 1 ? img->x : win->w - img->x - img->w * img->zoom;
663− oy = d == 3 ? img->y : win->h - img->y - img->h * img->zoom;
664−
665660 imlib_context_set_image(img->im);
666− /* rotates by `90 * d` degrees in the clockwise direction */
667661 imlib_image_orientate(d);
668662
669− if (d == 1 || d == 3) {
670− img->x = oy + (win->w - win->h) / 2;
671− img->y = ox + (win->h - win->w) / 2;
663+ if (d == DEGREE_90 || d == DEGREE_270) {
664+ ox = d == DEGREE_90 ? img->x : img->win->w - img->x - img->w * img->zoom;
665+ oy = d == DEGREE_270 ? img->y : img->win->h - img->y - img->h * img->zoom;
666+
667+ img->x = oy + (img->win->w - img->win->h) / 2;
668+ img->y = ox + (img->win->h - img->win->w) / 2;
672669
673670 tmp = img->w;
674671 img->w = img->h;
M image.h View
@@ -76,7 +76,7 @@ bool img_move(img_t*, float, float);
7676 bool img_pan(img_t*, direction_t, int);
7777 bool img_pan_edge(img_t*, direction_t);
7878
79−void img_rotate(img_t*, int);
79+void img_rotate(img_t*, degree_t);
8080 void img_flip(img_t*, flipdir_t);
8181
8282 void img_toggle_antialias(img_t*);
M types.h View
@@ -39,10 +39,10 @@ typedef enum {
3939 } direction_t;
4040
4141 typedef enum {
42− ROTATE_90,
43− ROTATE_270,
44− ROTATE_180
45−} rotate_t;
42+ DEGREE_90 = 1,
43+ DEGREE_180 = 2,
44+ DEGREE_270 = 3
45+} degree_t;
4646
4747 typedef enum {
4848 FLIP_HORIZONTAL,