Actual source code: zoom.c
1: /*$Id: zoom.c,v 1.20 2001/03/23 23:20:24 balay Exp $*/
3: #include petscdraw.h
5: #undef __FUNCT__
7: /*@C
8: PetscDrawZoom - Allows one to create a graphic that users may zoom into.
10: Collective on PetscDraw
12: Input Parameters:
13: + draw - the window where the graph will be made.
14: . func - users function that draws the graphic
15: - ctx - pointer to any user required data
17: Level: advanced
19: Concepts: graphics^zooming
20: Concepts: drawing^zooming
21: Concepts: zooming^in graphics
23: .seealso:
24: @*/
25: int PetscDrawZoom(PetscDraw draw,int (*func)(PetscDraw,void *),void *ctx)
26: {
27: int ierr,pause;
28: PetscDrawButton button;
29: PetscReal xc,yc,scale = 1.0,w,h,xr,xl,yr,yl,xmin,xmax,ymin,ymax;
30: PetscTruth isnull;
33: PetscDrawIsNull(draw,&isnull);
34: if (isnull) return(0);
36: PetscDrawSynchronizedClear(draw);
37: (*func)(draw,ctx);
38: PetscDrawSynchronizedFlush(draw);
40: PetscDrawGetPause(draw,&pause);
41: if (pause >= 0) {
42: PetscSleep(pause);
43: return(0);
44: }
46: PetscDrawCheckResizedWindow(draw);
47: PetscDrawSynchronizedGetMouseButton(draw,&button,&xc,&yc,0,0);
48: PetscDrawGetCoordinates(draw,&xl,&yl,&xr,&yr);
49: w = xr - xl; xmin = xl; ymin = yl; xmax = xr; ymax = yr;
50: h = yr - yl;
52: if (button != BUTTON_NONE) {
53: while (button != BUTTON_RIGHT) {
55: PetscDrawSynchronizedClear(draw);
56: if (button == BUTTON_LEFT) scale = .5;
57: else if (button == BUTTON_CENTER) scale = 2.;
58: xl = scale*(xl + w - xc) + xc - w*scale;
59: xr = scale*(xr - w - xc) + xc + w*scale;
60: yl = scale*(yl + h - yc) + yc - h*scale;
61: yr = scale*(yr - h - yc) + yc + h*scale;
62: w *= scale; h *= scale;
63: PetscDrawSetCoordinates(draw,xl,yl,xr,yr);
65: (*func)(draw,ctx);
66: PetscDrawCheckResizedWindow(draw);
67: PetscDrawSynchronizedGetMouseButton(draw,&button,&xc,&yc,0,0);
68: }
69: }
71: PetscDrawSetCoordinates(draw,xmin,ymin,xmax,ymax);
73: return(0);
74: }