Actual source code: zoom.c
petsc-3.6.4 2016-04-12
2: #include <petscdraw.h> /*I "petscdraw.h" I*/
4: #if defined(PETSC_HAVE_SETJMP_H) && defined(PETSC_HAVE_X)
5: #include <X11/Xlib.h>
6: #include <X11/Xutil.h>
7: #include <setjmp.h>
8: static jmp_buf PetscXIOErrorJumpBuf;
9: static void PetscXIOHandler(Display *dpy)
10: {
11: longjmp(PetscXIOErrorJumpBuf, 1);
12: }
13: #endif
17: /*@C
18: PetscDrawZoom - Allows one to create a graphic that users may zoom into.
20: Collective on PetscDraw
22: Input Parameters:
23: + draw - the window where the graph will be made.
24: . func - users function that draws the graphic
25: - ctx - pointer to any user required data
27: Level: advanced
29: Concepts: graphics^zooming
30: Concepts: drawing^zooming
31: Concepts: zooming^in graphics
33: .seealso:
34: @*/
35: PetscErrorCode PetscDrawZoom(PetscDraw draw,PetscErrorCode (*func)(PetscDraw,void*),void *ctx)
36: {
37: PetscErrorCode ierr;
38: PetscDrawButton button;
39: PetscReal dpause,xc,yc,scale = 1.0,w,h,xr,xl,yr,yl,xmin,xmax,ymin,ymax;
40: PetscBool isnull;
43: PetscDrawIsNull(draw,&isnull);
44: if (isnull) return(0);
46: #if defined(PETSC_HAVE_SETJMP_H) && defined(PETSC_HAVE_X)
47: if (!setjmp(PetscXIOErrorJumpBuf)) XSetIOErrorHandler((XIOErrorHandler)PetscXIOHandler);
48: else {
49: XSetIOErrorHandler(NULL);
50: PetscDrawSetType(draw,PETSC_DRAW_NULL);
51: return(0);
52: }
53: #endif
55: PetscDrawCheckResizedWindow(draw);
56: PetscDrawSynchronizedClear(draw);
57: (*func)(draw,ctx);
58: PetscDrawSynchronizedFlush(draw);
60: PetscDrawGetPause(draw,&dpause);
61: if (dpause >= 0) {
62: PetscSleep(dpause);
63: goto theend;
64: }
65: if (dpause != -1) goto theend;
67: PetscDrawCheckResizedWindow(draw);
68: PetscDrawSynchronizedGetMouseButton(draw,&button,&xc,&yc,0,0);
69: PetscDrawGetCoordinates(draw,&xl,&yl,&xr,&yr);
70: w = xr - xl; xmin = xl; ymin = yl; xmax = xr; ymax = yr;
71: h = yr - yl;
73: if (button != PETSC_BUTTON_NONE) {
74: while (button != PETSC_BUTTON_RIGHT) {
76: PetscDrawSynchronizedClear(draw);
77: if (button == PETSC_BUTTON_LEFT) scale = .5;
78: else if (button == PETSC_BUTTON_CENTER) scale = 2.;
79: xl = scale*(xl + w - xc) + xc - w*scale;
80: xr = scale*(xr - w - xc) + xc + w*scale;
81: yl = scale*(yl + h - yc) + yc - h*scale;
82: yr = scale*(yr - h - yc) + yc + h*scale;
83: w *= scale; h *= scale;
84: PetscDrawSetCoordinates(draw,xl,yl,xr,yr);
86: (*func)(draw,ctx);
87: PetscDrawSynchronizedFlush(draw);
88: PetscDrawCheckResizedWindow(draw);
89: PetscDrawSynchronizedGetMouseButton(draw,&button,&xc,&yc,0,0);
90: }
91: }
92: PetscDrawSetCoordinates(draw,xmin,ymin,xmax,ymax);
93: theend:
94: #if defined(PETSC_HAVE_SETJMP_H) && defined(PETSC_HAVE_X)
95: XSetIOErrorHandler(NULL);
96: #endif
97: return(0);
98: }