SVN revision: 35902
This commit is contained in:
Kim Woelders 2008-09-09 20:13:02 +00:00
parent 4edfe21515
commit bb8b884ee5
1 changed files with 189 additions and 191 deletions

View File

@ -108,12 +108,12 @@ main(int argc, char **argv)
file = argv[no];
if (display_name == NULL)
display_name = ":0";
display_name = ":0";
disp = XOpenDisplay(display_name);
if (disp == NULL)
{
fprintf(stderr, "Can't open display %s\n", display_name);
return 1;
fprintf(stderr, "Can't open display %s\n", display_name);
return 1;
}
vis = DefaultVisual(disp, DefaultScreen(disp));
depth = DefaultDepth(disp, DefaultScreen(disp));
@ -133,10 +133,10 @@ main(int argc, char **argv)
{
no++;
if (no == argc)
{
fprintf(stderr, "Image format not available\n");
exit(0);
}
{
fprintf(stderr, "Image format not available\n");
exit(0);
}
file = argv[no];
image_width = 0;
im = imlib_load_image(file);
@ -158,196 +158,194 @@ main(int argc, char **argv)
double t1;
XFlush(disp);
XNextEvent(disp, &ev);
switch (ev.type)
XNextEvent(disp, &ev);
switch (ev.type)
{
case ButtonPress:
b = ev.xbutton.button;
x = ev.xbutton.x;
y = ev.xbutton.y;
if (b == 3)
{
case ButtonPress:
b = ev.xbutton.button;
x = ev.xbutton.x;
y = ev.xbutton.y;
if (b == 3)
{
zoom_mode = 1;
zx = x;
zy = y;
imlib_context_set_drawable(pm);
imlib_context_set_image(bg_im);
imlib_context_set_anti_alias(0);
imlib_context_set_dither(0);
imlib_context_set_blend(0);
imlib_render_image_part_on_drawable_at_size
(0, 0, image_width, image_height,
0, 0, image_width, image_height);
XSetWindowBackgroundPixmap(disp, win, pm);
XClearWindow(disp, win);
}
break;
case ButtonRelease:
b = ev.xbutton.button;
x = ev.xbutton.x;
y = ev.xbutton.y;
if (b == 3)
zoom_mode = 0;
if (b == 1)
{
no++;
if (no == argc)
no = argc - 1;
file = argv[no];
image_width = 0;
zoom = 1.0;
zoom_mode = 0;
imlib_context_set_image(im);
imlib_free_image_and_decache();
im = imlib_load_image(file);
while (!im)
{
no++;
if (no == argc)
exit(0);
file = argv[no];
image_width = 0;
im = imlib_load_image(file);
}
imlib_context_set_image(im);
}
if (b == 2)
{
no--;
if (no == 0)
no = 1;
file = argv[no];
image_width = 0;
zoom = 1.0;
zoom_mode = 0;
imlib_context_set_image(im);
imlib_free_image_and_decache();
im = imlib_load_image(file);
while (!im)
{
no--;
if (no == 0)
no = 1;
file = argv[no];
image_width = 0;
im = imlib_load_image(file);
}
imlib_context_set_image(im);
}
break;
case MotionNotify:
while (XCheckTypedWindowEvent
(disp, win, MotionNotify, &ev));
x = ev.xmotion.x;
y = ev.xmotion.y;
if (zoom_mode)
{
int sx, sy, sw, sh, dx, dy, dw, dh;
zoom = ((double)x - (double)zx) / 32.0;
if (zoom < 0)
zoom = 1.0 + ((zoom * 32.0) / ((double)(zx + 1)));
else
zoom += 1.0;
if (zoom <= 0.0001)
zoom = 0.0001;
if (zoom > 1.0)
{
dx = 0;
dy = 0;
dw = image_width;
dh = image_height;
sx = zx - (zx / zoom);
sy = zy - (zy / zoom);
sw = image_width / zoom;
sh = image_height / zoom;
}
else
{
dx = zx - (zx * zoom);
dy = zy - (zy * zoom);
dw = image_width * zoom;
dh = image_height * zoom;
sx = 0;
sy = 0;
sw = image_width;
sh = image_height;
}
imlib_context_set_anti_alias(0);
imlib_context_set_dither(0);
imlib_context_set_blend(0);
imlib_context_set_image(bg_im);
imlib_render_image_part_on_drawable_at_size
(sx, sy, sw, sh, dx, dy, dw, dh);
XSetWindowBackgroundPixmap(disp, win, pm);
XClearWindow(disp, win);
XFlush(disp);
timeout = 1;
}
default:
break;
zoom_mode = 1;
zx = x;
zy = y;
imlib_context_set_drawable(pm);
imlib_context_set_image(bg_im);
imlib_context_set_anti_alias(0);
imlib_context_set_dither(0);
imlib_context_set_blend(0);
imlib_render_image_part_on_drawable_at_size
(0, 0, image_width, image_height,
0, 0, image_width, image_height);
XSetWindowBackgroundPixmap(disp, win, pm);
XClearWindow(disp, win);
}
t1 = 0.2;
tval.tv_sec = (long)t1;
tval.tv_usec = (long)((t1 - ((double)tval.tv_sec)) * 1000000);
xfd = ConnectionNumber(disp);
fdsize = xfd + 1;
FD_ZERO(&fdset);
FD_SET(xfd, &fdset);
if (timeout)
count = select(fdsize, &fdset, NULL, NULL, &tval);
else
count = select(fdsize, &fdset, NULL, NULL, NULL);
if (count < 0)
break;
case ButtonRelease:
b = ev.xbutton.button;
x = ev.xbutton.x;
y = ev.xbutton.y;
if (b == 3)
zoom_mode = 0;
if (b == 1)
{
if ((errno == ENOMEM) || (errno == EINVAL)
|| (errno == EBADF))
exit(1);
}
else
{
if ((count == 0) && (timeout))
no++;
if (no == argc)
no = argc - 1;
file = argv[no];
image_width = 0;
zoom = 1.0;
zoom_mode = 0;
imlib_context_set_image(im);
imlib_free_image_and_decache();
im = imlib_load_image(file);
while (!im)
{
int sx, sy, sw, sh, dx, dy, dw, dh;
if (zoom > 1.0)
{
dx = 0;
dy = 0;
dw = image_width;
dh = image_height;
sx = zx - (zx / zoom);
sy = zy - (zy / zoom);
sw = image_width / zoom;
sh = image_height / zoom;
}
else
{
dx = zx - (zx * zoom);
dy = zy - (zy * zoom);
dw = image_width * zoom;
dh = image_height * zoom;
sx = 0;
sy = 0;
sw = image_width;
sh = image_height;
}
imlib_context_set_anti_alias(1);
imlib_context_set_dither(1);
imlib_context_set_blend(0);
imlib_context_set_image(bg_im);
imlib_render_image_part_on_drawable_at_size
(sx, sy, sw, sh, dx, dy, dw, dh);
XSetWindowBackgroundPixmap(disp, win, pm);
XClearWindow(disp, win);
XFlush(disp);
timeout = 0;
no++;
if (no == argc)
exit(0);
file = argv[no];
image_width = 0;
im = imlib_load_image(file);
}
imlib_context_set_image(im);
}
if (b == 2)
{
no--;
if (no == 0)
no = 1;
file = argv[no];
image_width = 0;
zoom = 1.0;
zoom_mode = 0;
imlib_context_set_image(im);
imlib_free_image_and_decache();
im = imlib_load_image(file);
while (!im)
{
no--;
if (no == 0)
no = 1;
file = argv[no];
image_width = 0;
im = imlib_load_image(file);
}
imlib_context_set_image(im);
}
break;
case MotionNotify:
while (XCheckTypedWindowEvent(disp, win, MotionNotify, &ev));
x = ev.xmotion.x;
y = ev.xmotion.y;
if (zoom_mode)
{
int sx, sy, sw, sh, dx, dy, dw, dh;
zoom = ((double)x - (double)zx) / 32.0;
if (zoom < 0)
zoom = 1.0 + ((zoom * 32.0) / ((double)(zx + 1)));
else
zoom += 1.0;
if (zoom <= 0.0001)
zoom = 0.0001;
if (zoom > 1.0)
{
dx = 0;
dy = 0;
dw = image_width;
dh = image_height;
sx = zx - (zx / zoom);
sy = zy - (zy / zoom);
sw = image_width / zoom;
sh = image_height / zoom;
}
else
{
dx = zx - (zx * zoom);
dy = zy - (zy * zoom);
dw = image_width * zoom;
dh = image_height * zoom;
sx = 0;
sy = 0;
sw = image_width;
sh = image_height;
}
imlib_context_set_anti_alias(0);
imlib_context_set_dither(0);
imlib_context_set_blend(0);
imlib_context_set_image(bg_im);
imlib_render_image_part_on_drawable_at_size
(sx, sy, sw, sh, dx, dy, dw, dh);
XSetWindowBackgroundPixmap(disp, win, pm);
XClearWindow(disp, win);
XFlush(disp);
timeout = 1;
}
default:
break;
}
t1 = 0.2;
tval.tv_sec = (long)t1;
tval.tv_usec = (long)((t1 - ((double)tval.tv_sec)) * 1000000);
xfd = ConnectionNumber(disp);
fdsize = xfd + 1;
FD_ZERO(&fdset);
FD_SET(xfd, &fdset);
if (timeout)
count = select(fdsize, &fdset, NULL, NULL, &tval);
else
count = select(fdsize, &fdset, NULL, NULL, NULL);
if (count < 0)
{
if ((errno == ENOMEM) || (errno == EINVAL) || (errno == EBADF))
exit(1);
}
else
{
if ((count == 0) && (timeout))
{
int sx, sy, sw, sh, dx, dy, dw, dh;
if (zoom > 1.0)
{
dx = 0;
dy = 0;
dw = image_width;
dh = image_height;
sx = zx - (zx / zoom);
sy = zy - (zy / zoom);
sw = image_width / zoom;
sh = image_height / zoom;
}
else
{
dx = zx - (zx * zoom);
dy = zy - (zy * zoom);
dw = image_width * zoom;
dh = image_height * zoom;
sx = 0;
sy = 0;
sw = image_width;
sh = image_height;
}
imlib_context_set_anti_alias(1);
imlib_context_set_dither(1);
imlib_context_set_blend(0);
imlib_context_set_image(bg_im);
imlib_render_image_part_on_drawable_at_size
(sx, sy, sw, sh, dx, dy, dw, dh);
XSetWindowBackgroundPixmap(disp, win, pm);
XClearWindow(disp, win);
XFlush(disp);
timeout = 0;
}
}
}
return 0;
}