commit 2efc3a678f4a4694acb57bc368771c5be11c02f3
parent 57faa9486d0b2fb31a184501f5267461d2febccc
Author: Phil Carmody <pc+xzoom@asdf.org>
Date: Thu, 21 Nov 2013 17:38:45 +0200
xzoom: extract all the drawing into a helper function
Keep it self-contained, and therefore easier to skip in its
entirety.
Signed-off-by: Phil Carmody <pc+xzoom@asdf.org>
Signed-off-by: Christoph Lohmann <20h@r-36.net>
Diffstat:
xzoom.c | | | 117 | ++++++++++++++++++++++++++++++++++++++++++------------------------------------- |
1 file changed, 62 insertions(+), 55 deletions(-)
diff --git a/xzoom.c b/xzoom.c
@@ -316,6 +316,67 @@ void scale32(void)
}
+void xzoom(int buttonpressed)
+{
+ char title[80];
+
+#ifdef XSHM
+ XShmGetImage(dpy, RootWindowOfScreen(scr), ximage[SRC],
+ xgrab, ygrab, AllPlanes);
+#else
+ XGetSubImage(dpy, RootWindowOfScreen(scr),
+ xgrab, ygrab, width[SRC], height[SRC], AllPlanes,
+ ZPixmap, ximage[SRC], 0, 0);
+#endif
+#ifdef FRAME
+ if(buttonpressed) { /* show the frame */
+ XDrawRectangle(dpy, RootWindowOfScreen(scr), framegc, xgrab, ygrab, width[SRC]-1, height[SRC]-1);
+ XSync(dpy, False);
+ }
+#endif
+
+ if (depth == 8)
+ scale8();
+ else if (depth <= 8*sizeof(short))
+ scale16();
+ else if (depth <= 8*sizeof(int))
+ scale32();
+
+#ifdef XSHM
+ XShmPutImage(dpy, win, gc, ximage[DST], 0, 0, 0, 0, width[DST], height[DST], False);
+#else
+ XPutImage(dpy, win, gc, ximage[DST], 0, 0, 0, 0, width[DST], height[DST]);
+#endif
+ if(set_title) {
+ if(magx == magy && !flipx && !flipy && !flipxy)
+ sprintf(title, "%s x%d", progname, magx);
+ else
+ sprintf(title, "%s X %s%d%s Y %s%d",
+ progname,
+ flipx?"-":"", magx,
+ flipxy?" <=>":";",
+ flipy?"-":"", magy);
+ XChangeProperty(dpy, win, XA_WM_NAME, XA_STRING, 8,
+ PropModeReplace,
+ (unsigned char *)title, strlen(title));
+ set_title = False;
+ }
+#ifdef TIMER
+ {
+ struct timeval current_time;
+ double DT;
+
+ gettimeofday(¤t_time, NULL);
+ DT = current_time.tv_sec - old_time.tv_sec;
+ DT += 1e-6*(current_time.tv_usec - old_time.tv_usec);
+ sprintf(title, "DT=%6.3f", DT);
+ XDrawString(dpy, win, gc, 20, 20, title, strlen(title));
+ old_time = current_time;
+ }
+#endif
+ XSync(dpy, 0);
+}
+
int
main(int argc, char **argv) {
XSetWindowAttributes xswa;
@@ -840,61 +901,7 @@ main(int argc, char **argv) {
}
-#ifdef XSHM
- XShmGetImage(dpy, RootWindowOfScreen(scr), ximage[SRC],
- xgrab, ygrab, AllPlanes);
-#else
- XGetSubImage(dpy, RootWindowOfScreen(scr),
- xgrab, ygrab, width[SRC], height[SRC], AllPlanes,
- ZPixmap, ximage[SRC], 0, 0);
-#endif
-#ifdef FRAME
- if(buttonpressed) { /* show the frame */
- XDrawRectangle(dpy, RootWindowOfScreen(scr), framegc, xgrab, ygrab, width[SRC]-1, height[SRC]-1);
- XSync(dpy, False);
- }
-#endif
-
- if (depth == 8)
- scale8();
- else if (depth <= 8*sizeof(short))
- scale16();
- else if (depth <= 8*sizeof(int))
- scale32();
-
-#ifdef XSHM
- XShmPutImage(dpy, win, gc, ximage[DST], 0, 0, 0, 0, width[DST], height[DST], False);
-#else
- XPutImage(dpy, win, gc, ximage[DST], 0, 0, 0, 0, width[DST], height[DST]);
-#endif
- if(set_title) {
- if(magx == magy && !flipx && !flipy && !flipxy)
- sprintf(title, "%s x%d", progname, magx);
- else
- sprintf(title, "%s X %s%d%s Y %s%d",
- progname,
- flipx?"-":"", magx,
- flipxy?" <=>":";",
- flipy?"-":"", magy);
- XChangeProperty(dpy, win, XA_WM_NAME, XA_STRING, 8,
- PropModeReplace,
- (unsigned char *)title, strlen(title));
- set_title = False;
- }
-#ifdef TIMER
- {
- struct timeval current_time;
- double DT;
-
- gettimeofday(¤t_time, NULL);
- DT = current_time.tv_sec - old_time.tv_sec;
- DT += 1e-6*(current_time.tv_usec - old_time.tv_usec);
- sprintf(title, "DT=%6.3f", DT);
- XDrawString(dpy, win, gc, 20, 20, title, strlen(title));
- old_time = current_time;
- }
-#endif
- XSync(dpy, 0);
+ xzoom(buttonpressed);
#ifdef NO_USLEEP
#define usleep(_t) \