Actual source code: zoom.c
petsc-3.11.4 2019-09-28
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: Concepts: graphics^zooming
17: Concepts: drawing^zooming
18: Concepts: zooming^in graphics
20: .seealso:
21: @*/
22: PetscErrorCode PetscDrawZoom(PetscDraw draw,PetscErrorCode (*func)(PetscDraw,void*),void *ctx)
23: {
24: PetscErrorCode ierr;
25: PetscDrawButton button;
26: PetscReal dpause,xc,yc,scale = 1.0,w,h,xr,xl,yr,yl,xmin,xmax,ymin,ymax;
27: PetscBool isnull;
30: PetscDrawIsNull(draw,&isnull);
31: if (isnull) return(0);
33: PetscDrawCheckResizedWindow(draw);
34: PetscDrawClear(draw);
35: PetscDrawCollectiveBegin(draw);
36: (*func)(draw,ctx);
37: PetscDrawCollectiveEnd(draw);
38: PetscDrawFlush(draw);
40: PetscDrawGetPause(draw,&dpause);
41: if (dpause >= 0) {
42: PetscSleep(dpause);
43: goto theend;
44: }
45: if (dpause != -1) goto theend;
47: PetscDrawGetMouseButton(draw,&button,&xc,&yc,NULL,NULL);
48: PetscDrawGetCoordinates(draw,&xl,&yl,&xr,&yr);
49: xmin = xl; xmax = xr; w = xr - xl;
50: ymin = yl; ymax = yr; h = yr - yl;
52: while (button != PETSC_BUTTON_NONE && button != PETSC_BUTTON_RIGHT) {
53: switch (button) {
54: case PETSC_BUTTON_LEFT: scale = 0.5; break;
55: case PETSC_BUTTON_CENTER: scale = 2.0; break;
56: case PETSC_BUTTON_WHEEL_UP: scale = 8/10.; break;
57: case PETSC_BUTTON_WHEEL_DOWN: scale = 10/8.; break;
58: default: scale = 1.0;
59: }
60: xl = scale*(xl + w - xc) + xc - w*scale;
61: xr = scale*(xr - w - xc) + xc + w*scale;
62: yl = scale*(yl + h - yc) + yc - h*scale;
63: yr = scale*(yr - h - yc) + yc + h*scale;
64: w *= scale; h *= scale;
65: PetscDrawClear(draw);
66: PetscDrawSetCoordinates(draw,xl,yl,xr,yr);
67: PetscDrawCollectiveBegin(draw);
68: (*func)(draw,ctx);
69: PetscDrawCollectiveEnd(draw);
70: PetscDrawFlush(draw);
71: PetscDrawGetMouseButton(draw,&button,&xc,&yc,NULL,NULL);
72: }
73: PetscDrawSetCoordinates(draw,xmin,ymin,xmax,ymax);
74: theend:
75: return(0);
76: }