Fixed pixel-wise panning by chaning x, y vars to float

This commit is contained in:
Bert Münnich 2011-10-16 18:31:01 +02:00
parent 4f5ce2e828
commit 8dcb54705a
2 changed files with 11 additions and 11 deletions

16
image.c
View file

@ -554,8 +554,8 @@ bool img_zoom_out(img_t *img) {
return false; return false;
} }
bool img_move(img_t *img, int dx, int dy) { bool img_move(img_t *img, float dx, float dy) {
int ox, oy; float ox, oy;
if (img == NULL || img->im == NULL) if (img == NULL || img->im == NULL)
return false; return false;
@ -581,13 +581,13 @@ bool img_pan(img_t *img, direction_t dir, int d) {
* d = 0: 1/5 of screen * d = 0: 1/5 of screen
* d > 0: num of pixels * d > 0: num of pixels
*/ */
int x, y; float x, y;
if (img == NULL || img->im == NULL || img->win == NULL) if (img == NULL || img->im == NULL || img->win == NULL)
return false; return false;
if (d > 0) { if (d > 0) {
x = y = MAX(1, d * img->zoom); x = y = MAX(1, (float) d * img->zoom);
} else { } else {
x = img->win->w / (d < 0 ? 1 : 5); x = img->win->w / (d < 0 ? 1 : 5);
y = img->win->h / (d < 0 ? 1 : 5); y = img->win->h / (d < 0 ? 1 : 5);
@ -595,13 +595,13 @@ bool img_pan(img_t *img, direction_t dir, int d) {
switch (dir) { switch (dir) {
case DIR_LEFT: case DIR_LEFT:
return img_move(img, x, 0); return img_move(img, x, 0.0);
case DIR_RIGHT: case DIR_RIGHT:
return img_move(img, -x, 0); return img_move(img, -x, 0.0);
case DIR_UP: case DIR_UP:
return img_move(img, 0, y); return img_move(img, 0.0, y);
case DIR_DOWN: case DIR_DOWN:
return img_move(img, 0, -y); return img_move(img, 0.0, -y);
} }
return false; return false;
} }

View file

@ -43,8 +43,8 @@ typedef struct {
int h; int h;
win_t *win; win_t *win;
int x; float x;
int y; float y;
scalemode_t scalemode; scalemode_t scalemode;
float zoom; float zoom;
@ -75,7 +75,7 @@ bool img_zoom(img_t*, float);
bool img_zoom_in(img_t*); bool img_zoom_in(img_t*);
bool img_zoom_out(img_t*); bool img_zoom_out(img_t*);
bool img_move(img_t*, int, int); 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);