Skip to content
Snippets Groups Projects
Commit 8821ce80 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

Partially fix zoom mode

Does not yet work with initial zoom value != 100%
parent ab405711
No related branches found
No related tags found
No related merge requests found
......@@ -126,11 +126,16 @@ static void feh_event_handle_ButtonPress(XEvent * ev)
opt.mode = MODE_ZOOM;
winwid->mode = MODE_ZOOM;
D(3, ("click offset is %d,%d\n", ev->xbutton.x, ev->xbutton.y));
winwid->click_offset_x = ev->xbutton.x - winwid->im_x;
winwid->click_offset_y = ev->xbutton.y - winwid->im_y;
winwid->im_click_offset_x = winwid->click_offset_x / winwid->zoom;
winwid->im_click_offset_y = winwid->click_offset_y / winwid->zoom;
winwid->click_offset_x = ev->xbutton.x;
winwid->click_offset_y = ev->xbutton.y;
winwid->old_zoom = winwid->zoom;
winwid->zoom = 1.0;
/* required to adjust the image position in zoom mode */
winwid->orig_im_x = winwid->im_x;
winwid->orig_im_y = winwid->im_y;
/* center the image */
if (winwid->full_screen) {
winwid->im_x = (scr_width - winwid->im_w) >> 1;
winwid->im_y = (scr_height - winwid->im_h) >> 1;
......@@ -146,17 +151,9 @@ static void feh_event_handle_ButtonPress(XEvent * ev)
winwid->im_y = 0;
}
}
if (winwid->im_click_offset_x < 30)
winwid->im_click_offset_x = 30;
if (winwid->im_click_offset_y < 0)
winwid->im_click_offset_y = 0;
if (winwid->im_click_offset_x > winwid->im_w)
winwid->im_click_offset_x = winwid->im_w;
if (winwid->im_click_offset_y > winwid->im_h)
winwid->im_click_offset_y = winwid->im_h;
if (winwid->click_offset_x < 30)
winwid->click_offset_x = 30;
if (winwid->click_offset_x < 0)
winwid->click_offset_x = 0;
if (winwid->click_offset_y < 0)
winwid->click_offset_y = 0;
if (winwid->click_offset_x > winwid->w)
......@@ -425,21 +422,27 @@ static void feh_event_handle_MotionNotify(XEvent * ev)
winwid = winwidget_get_from_window(ev->xmotion.window);
if (winwid) {
winwid->zoom = ((double) ev->xmotion.x - (double) winwid->click_offset_x) / 64.0;
if (winwid->zoom < 0)
winwid->zoom = 1.0 + ((winwid->zoom * 64.0) / ((double)
(winwid->click_offset_x + 1)));
if (ev->xmotion.x > winwid->click_offset_x)
winwid->zoom = winwid->old_zoom + (
((double) ev->xmotion.x - (double) winwid->click_offset_x)
/ 128.0);
/*/ ((double) (winwid->click_offset_x + 1)));*/
else
winwid->zoom += 1.0;
winwid->zoom = winwid->old_zoom - (
((double) winwid->click_offset_x - (double) ev->xmotion.x)
/ 128.0);
/*/ ((double) (winwid->click_offset_x + 1)));*/
if (winwid->zoom < 0.01)
winwid->zoom = 0.01;
/* calculate change in zoom and move im_x and im_y respectively to
enable zooming to the clicked spot... */
/* for now, center around im_click_offset_x and im_click_offset_y */
winwid->im_x = (winwid->w / 2) - (winwid->im_click_offset_x * winwid->zoom);
winwid->im_y = (winwid->h / 2) - (winwid->im_click_offset_y * winwid->zoom);
/* center around click_offset */
winwid->im_x = winwid->click_offset_x
- (winwid->click_offset_x * winwid->zoom);
/*+ (winwid->orig_im_x * winwid->zoom);*/
winwid->im_y = winwid->click_offset_y
- (winwid->click_offset_y * winwid->zoom);
/*+ (winwid->orig_im_y * winwid->zoom);*/
winwidget_render_image(winwid, 0, 0);
}
......
......@@ -69,11 +69,10 @@ static winwidget winwidget_allocate(void)
ret->im_x = 0;
ret->im_y = 0;
ret->zoom = 1.0;
ret->old_zoom = 1.0;
ret->click_offset_x = 0;
ret->click_offset_y = 0;
ret->im_click_offset_x = 0;
ret->im_click_offset_y = 0;
ret->has_rotated = 0;
D_RETURN(4, ret);
......@@ -911,14 +910,13 @@ void feh_debug_print_winwid(winwidget w)
"h = %d\n" "im_w = %d\n" "im_h = %d\n" "im_angle = %f\n"
"type = %d\n" "had_resize = %d\n" "im = %p\n" "GC = %p\n"
"pixmap = %ld\n" "name = %s\n" "file = %p\n" "mode = %d\n"
"im_x = %d\n" "im_y = %d\n" "zoom = %f\n"
"im_x = %d\n" "im_y = %d\n" "zoom = %f\n" "old_zoom = %f\n"
"click_offset_x = %d\n" "click_offset_y = %d\n"
"im_click_offset_x = %d\n" "im_click_offset_y = %d\n"
"has_rotated = %d\n", (void *)w, w->win, w->w, w->h, w->im_w,
w->im_h, w->im_angle, w->type, w->had_resize, w->im, (void *)w->gc,
w->bg_pmap, w->name, (void *)w->file, w->mode, w->im_x, w->im_y,
w->zoom, w->click_offset_x, w->click_offset_y,
w->im_click_offset_x, w->im_click_offset_y, w->has_rotated);
w->zoom, w->old_zoom, w->click_offset_x, w->click_offset_y,
w->has_rotated);
}
void winwidget_reset_image(winwidget winwid)
......
......@@ -92,20 +92,27 @@ struct __winwidget {
gib_list *file;
unsigned char visible;
/* Stuff for zooming */
/* panning, zooming, etc. */
unsigned char mode;
unsigned char caption_entry; /* are we in caption entry mode? */
unsigned char caption_entry;
/* image offset from window top left */
int im_x;
int im_y;
/* same, as cache for zoom mode */
int orig_im_x;
int orig_im_y;
/* From 0 (not visible) to 1.00 (actual size)
* all the way up to INT_MAX (eww)
*/
double zoom;
double old_zoom;
/* New stuff */
int im_x; /* image offset from window top left */
int im_y; /* image offset from window top left */
double zoom; /* From 0 (not visible) to 1.00 (actual size)
all the way up to INT_MAX (ouch) */
int click_offset_x;
int click_offset_y;
int im_click_offset_x;
int im_click_offset_y;
unsigned char has_rotated;
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment