Pan by pixel count, if number prefix given

This commit is contained in:
Bert Münnich 2011-10-16 17:39:22 +02:00
parent dc727b8dce
commit 867940ea85
4 changed files with 25 additions and 10 deletions

View file

@ -184,7 +184,7 @@ bool it_move(arg_t a) {
direction_t dir = (direction_t) a;
if (mode == MODE_IMAGE)
return img_pan(&img, dir, false);
return img_pan(&img, dir, prefix);
else
return tns_move_selection(&tns, dir);
}
@ -193,7 +193,7 @@ bool i_pan_screen(arg_t a) {
direction_t dir = (direction_t) a;
if (mode == MODE_IMAGE)
return img_pan(&img, dir, true);
return img_pan(&img, dir, -1);
else
return false;
}

23
image.c
View file

@ -576,19 +576,32 @@ bool img_move(img_t *img, int dx, int dy) {
}
}
bool img_pan(img_t *img, direction_t dir, bool screen) {
bool img_pan(img_t *img, direction_t dir, int d) {
/* d < 0: screen-wise
* d = 0: 1/5 of screen
* d > 0: num of pixels
*/
int x, y;
if (img == NULL || img->im == NULL || img->win == NULL)
return false;
if (d > 0) {
x = y = MAX(1, d * img->zoom);
} else {
x = img->win->w / (d < 0 ? 1 : 5);
y = img->win->h / (d < 0 ? 1 : 5);
}
switch (dir) {
case DIR_LEFT:
return img_move(img, img->win->w / (screen ? 1 : 5), 0);
return img_move(img, x, 0);
case DIR_RIGHT:
return img_move(img, img->win->w / (screen ? 1 : 5) * -1, 0);
return img_move(img, -x, 0);
case DIR_UP:
return img_move(img, 0, img->win->h / (screen ? 1 : 5));
return img_move(img, 0, y);
case DIR_DOWN:
return img_move(img, 0, img->win->h / (screen ? 1 : 5) * -1);
return img_move(img, 0, -y);
}
return false;
}

View file

@ -76,7 +76,7 @@ bool img_zoom_in(img_t*);
bool img_zoom_out(img_t*);
bool img_move(img_t*, int, int);
bool img_pan(img_t*, direction_t, bool);
bool img_pan(img_t*, direction_t, int);
bool img_pan_edge(img_t*, direction_t);
void img_rotate_left(img_t*);

6
main.c
View file

@ -337,9 +337,11 @@ void on_keypress(XKeyEvent *kev) {
XLookupString(kev, &key, 1, &ksym, NULL);
if (key >= '0' && key <= '9' && (kev->state & ControlMask) == 0) {
if ((ksym == XK_Escape || (key >= '0' && key <= '9')) &&
(kev->state & ControlMask) == 0)
{
/* number prefix for commands */
prefix = prefix * 10 + (int) (key - '0');
prefix = ksym == XK_Escape ? 0 : prefix * 10 + (int) (key - '0');
return;
}