Actual source code: zoom.c
petsc-3.13.6 2020-09-29
2: #include <petscdraw.h>
4: /*@C
5: PetscDrawZoom - Allows one to create a graphic that users may zoom into.
7: Collective on PetscDraw
9: Input Parameters:
10: + draw - the window where the graph will be made.
11: . func - users function that draws the graphic
12: - ctx - pointer to any user required data
14: Level: advanced
16: .seealso:
17: @*/
18: PetscErrorCode PetscDrawZoom(PetscDraw draw,PetscErrorCode (*func)(PetscDraw,void*),void *ctx)
19: {
20: PetscErrorCode ierr;
21: PetscDrawButton button;
22: PetscReal dpause,xc,yc,scale = 1.0,w,h,xr,xl,yr,yl,xmin,xmax,ymin,ymax;
23: PetscBool isnull;
26: PetscDrawIsNull(draw,&isnull);
27: if (isnull) return(0);
29: PetscDrawCheckResizedWindow(draw);
30: PetscDrawClear(draw);
31: PetscDrawCollectiveBegin(draw);
32: (*func)(draw,ctx);
33: PetscDrawCollectiveEnd(draw);
34: PetscDrawFlush(draw);
36: PetscDrawGetPause(draw,&dpause);
37: if (dpause >= 0) {
38: PetscSleep(dpause);
39: goto theend;
40: }
41: if (dpause != -1) goto theend;
43: PetscDrawGetMouseButton(draw,&button,&xc,&yc,NULL,NULL);
44: PetscDrawGetCoordinates(draw,&xl,&yl,&xr,&yr);
45: xmin = xl; xmax = xr; w = xr - xl;
46: ymin = yl; ymax = yr; h = yr - yl;
48: while (button != PETSC_BUTTON_NONE && button != PETSC_BUTTON_RIGHT) {
49: switch (button) {
50: case PETSC_BUTTON_LEFT: scale = 0.5; break;
51: case PETSC_BUTTON_CENTER: scale = 2.0; break;
52: case PETSC_BUTTON_WHEEL_UP: scale = 8/10.; break;
53: case PETSC_BUTTON_WHEEL_DOWN: scale = 10/8.; break;
54: default: scale = 1.0;
55: }
56: xl = scale*(xl + w - xc) + xc - w*scale;
57: xr = scale*(xr - w - xc) + xc + w*scale;
58: yl = scale*(yl + h - yc) + yc - h*scale;
59: yr = scale*(yr - h - yc) + yc + h*scale;
60: w *= scale; h *= scale;
61: PetscDrawClear(draw);
62: PetscDrawSetCoordinates(draw,xl,yl,xr,yr);
63: PetscDrawCollectiveBegin(draw);
64: (*func)(draw,ctx);
65: PetscDrawCollectiveEnd(draw);
66: PetscDrawFlush(draw);
67: PetscDrawGetMouseButton(draw,&button,&xc,&yc,NULL,NULL);
68: }
69: PetscDrawSetCoordinates(draw,xmin,ymin,xmax,ymax);
70: theend:
71: return(0);
72: }