Actual source code: zoom.c

      1: #define PETSC_DLL

     3:  #include petscdraw.h

      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: PetscErrorCode PETSC_DLLEXPORT PetscDrawZoom(PetscDraw draw,PetscErrorCode (*func)(PetscDraw,void *),void *ctx)
     26: {
     27:   PetscErrorCode  ierr;
     28:   int             dpause;
     29:   PetscDrawButton button;
     30:   PetscReal       xc,yc,scale = 1.0,w,h,xr,xl,yr,yl,xmin,xmax,ymin,ymax;
     31:   PetscTruth      isnull;

     34:   PetscDrawIsNull(draw,&isnull);
     35:   if (isnull) return(0);

     37:   PetscDrawSynchronizedClear(draw);
     38:   (*func)(draw,ctx);
     39:   PetscDrawSynchronizedFlush(draw);

     41:   PetscDrawGetPause(draw,&dpause);
     42:   if (dpause >= 0) {
     43:     PetscSleep(dpause);
     44:     return(0);
     45:   }

     47:   PetscDrawCheckResizedWindow(draw);
     48:   PetscDrawSynchronizedGetMouseButton(draw,&button,&xc,&yc,0,0);
     49:   PetscDrawGetCoordinates(draw,&xl,&yl,&xr,&yr);
     50:   w    = xr - xl; xmin = xl; ymin = yl; xmax = xr; ymax = yr;
     51:   h    = yr - yl;

     53:   if (button != BUTTON_NONE) {
     54:     while (button != BUTTON_RIGHT) {

     56:       PetscDrawSynchronizedClear(draw);
     57:       if (button == BUTTON_LEFT)        scale = .5;
     58:       else if (button == BUTTON_CENTER) scale = 2.;
     59:       xl = scale*(xl + w - xc) + xc - w*scale;
     60:       xr = scale*(xr - w - xc) + xc + w*scale;
     61:       yl = scale*(yl + h - yc) + yc - h*scale;
     62:       yr = scale*(yr - h - yc) + yc + h*scale;
     63:       w *= scale; h *= scale;
     64:       PetscDrawSetCoordinates(draw,xl,yl,xr,yr);

     66:       (*func)(draw,ctx);
     67:       PetscDrawCheckResizedWindow(draw);
     68:       PetscDrawSynchronizedGetMouseButton(draw,&button,&xc,&yc,0,0);
     69:     }
     70:   }
     71:   PetscDrawSetCoordinates(draw,xmin,ymin,xmax,ymax);
     72:   return(0);
     73: }