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: /*@C
6: PetscDrawZoom - Allows one to create a graphic that users may zoom into.
8: Collective on PetscDraw
10: Input Parameters:
11: + draw - the window where the graph will be made.
12: . func - users function that draws the graphic
13: - ctx - pointer to any user required data
15: Level: advanced
17: Concepts: graphics^zooming
18: Concepts: drawing^zooming
19: Concepts: zooming^in graphics
21: .seealso:
22: @*/
23: int PetscDrawZoom(PetscDraw draw,int (*func)(PetscDraw,void *),void *ctx)
24: {
25: int ierr,pause;
26: PetscDrawButton button;
27: PetscReal xc,yc,scale = 1.0,w,h,xr,xl,yr,yl,xmin,xmax,ymin,ymax;
28: PetscTruth isnull;
31: PetscDrawIsNull(draw,&isnull);
32: if (isnull) return(0);
34: PetscDrawSynchronizedClear(draw);
35: (*func)(draw,ctx);
36: PetscDrawSynchronizedFlush(draw);
38: PetscDrawGetPause(draw,&pause);
39: if (pause >= 0) {
40: PetscSleep(pause);
41: return(0);
42: }
44: PetscDrawCheckResizedWindow(draw);
45: PetscDrawSynchronizedGetMouseButton(draw,&button,&xc,&yc,0,0);
46: PetscDrawGetCoordinates(draw,&xl,&yl,&xr,&yr);
47: w = xr - xl; xmin = xl; ymin = yl; xmax = xr; ymax = yr;
48: h = yr - yl;
50: if (button != BUTTON_NONE) {
51: while (button != BUTTON_RIGHT) {
53: PetscDrawSynchronizedClear(draw);
54: if (button == BUTTON_LEFT) scale = .5;
55: else if (button == BUTTON_CENTER) scale = 2.;
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: PetscDrawSetCoordinates(draw,xl,yl,xr,yr);
63: (*func)(draw,ctx);
64: PetscDrawCheckResizedWindow(draw);
65: PetscDrawSynchronizedGetMouseButton(draw,&button,&xc,&yc,0,0);
66: }
67: }
69: PetscDrawSetCoordinates(draw,xmin,ymin,xmax,ymax);
71: return(0);
72: }