Date: 2016-07-24T16:46:57+00:00

Actual source code: zoom.c
petsc-3.7.3 2016-07-24
Report Typos and Errors

      2: #include <petscdraw.h>     /*I "petscdraw.h"  I*/

      6: /*@C
      7:     PetscDrawZoom - Allows one to create a graphic that users may zoom into.

      9:     Collective on PetscDraw

     11:     Input Parameters:
     12: +   draw - the window where the graph will be made.
     13: .   func - users function that draws the graphic
     14: -   ctx - pointer to any user required data

     16:   Level: advanced

     18:   Concepts: graphics^zooming
     19:   Concepts: drawing^zooming
     20:   Concepts: zooming^in graphics

     22: .seealso:
     23: @*/
     24: PetscErrorCode  PetscDrawZoom(PetscDraw draw,PetscErrorCode (*func)(PetscDraw,void*),void *ctx)
     25: {
     26:   PetscErrorCode  ierr;
     27:   PetscDrawButton button;
     28:   PetscReal       dpause,xc,yc,scale = 1.0,w,h,xr,xl,yr,yl,xmin,xmax,ymin,ymax;
     29:   PetscBool       isnull;

     32:   PetscDrawIsNull(draw,&isnull);
     33:   if (isnull) return(0);

     35:   PetscDrawCheckResizedWindow(draw);
     36:   PetscDrawClear(draw);
     37:   PetscDrawCollectiveBegin(draw);
     38:   (*func)(draw,ctx);
     39:   PetscDrawCollectiveEnd(draw);
     40:   PetscDrawFlush(draw);

     42:   PetscDrawGetPause(draw,&dpause);
     43:   if (dpause >= 0) {
     44:     PetscSleep(dpause);
     45:     goto theend;
     46:   }
     47:   if (dpause != -1) goto theend;

     49:   PetscDrawGetMouseButton(draw,&button,&xc,&yc,NULL,NULL);
     50:   PetscDrawGetCoordinates(draw,&xl,&yl,&xr,&yr);
     51:   xmin = xl; xmax = xr; w = xr - xl;
     52:   ymin = yl; ymax = yr; h = yr - yl;

     54:   while (button != PETSC_BUTTON_NONE && button != PETSC_BUTTON_RIGHT) {
     55:     switch (button) {
     56:     case PETSC_BUTTON_LEFT:       scale = 0.5;   break;
     57:     case PETSC_BUTTON_CENTER:     scale = 2.0;   break;
     58:     case PETSC_BUTTON_WHEEL_UP:   scale = 8/10.; break;
     59:     case PETSC_BUTTON_WHEEL_DOWN: scale = 10/8.; break;
     60:     default:                      scale = 1.0;
     61:     }
     62:     xl = scale*(xl + w - xc) + xc - w*scale;
     63:     xr = scale*(xr - w - xc) + xc + w*scale;
     64:     yl = scale*(yl + h - yc) + yc - h*scale;
     65:     yr = scale*(yr - h - yc) + yc + h*scale;
     66:     w *= scale; h *= scale;
     67:     PetscDrawClear(draw);
     68:     PetscDrawSetCoordinates(draw,xl,yl,xr,yr);
     69:     PetscDrawCollectiveBegin(draw);
     70:     (*func)(draw,ctx);
     71:     PetscDrawCollectiveEnd(draw);
     72:     PetscDrawFlush(draw);
     73:     PetscDrawGetMouseButton(draw,&button,&xc,&yc,NULL,NULL);
     74:   }
     75:   PetscDrawSetCoordinates(draw,xmin,ymin,xmax,ymax);
     76: theend:
     77:   return(0);
     78: }