home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / gui / precog2_1.lha / Precognition2_1 / src / src.lha / Precognition / gridsnapwindow.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-18  |  10.3 KB  |  338 lines

  1. #include "parms.h"
  2. #include "Precognition.h"
  3. #include "BuilderMethods/BuilderMethods.h"
  4. #include "GridSnapWindow.h"
  5. #include "Menus/MenuStuff.h"
  6. #include "PObject.h"
  7. #include "pcgWindow.h"
  8. #include "GraphicObject.h"
  9. #ifndef __GNUC__
  10. #include <clib/exec_protos.h>
  11. #include <clib/intuition_protos.h>
  12. #endif
  13. #ifdef __GNUC__
  14. #include <proto/exec.h>
  15. #include <proto/intuition.h>
  16. #endif
  17. #ifdef __SASC
  18. #include <proto/exec.h>
  19. #include <proto/intuition.h>
  20. #endif
  21.  
  22. #define SELF &self->pw
  23.  
  24. void GracefulExit( short ExitStatus );
  25.  
  26. #define X1 120
  27. #define X2 X1+80
  28. #define X3 X2+60
  29.  
  30. void GridSettings_Init(
  31.       GridSettings_Iactors           *self,
  32.       GridSettings                   *gridsettings,
  33.       pcgWindow                      *window,
  34.       short                           topedge,
  35.       char                           *title,
  36.       pcg_3DPens                      pens )
  37. {
  38.  
  39.    OutlineBox_Init( &self->outline, 10, topedge+0, 350, 50, pens, title );
  40.    AddGraphicObject( window, (struct GraphicObject *)&self->outline );
  41.  
  42.    IntegerGadget_Init( &self->offset_x, X1, topedge+10, 40, 6,
  43.       pens, "Offset X:" );
  44.    AddInteractor( window, (struct Interactor *)&self->offset_x );
  45.  
  46.    IntegerGadget_Init( &self->offset_y, X2, topedge+10, 40, 6, pens, "Y:" );
  47.    AddInteractor( window, (struct Interactor *)&self->offset_y );
  48.  
  49.    IntegerGadget_Init( &self->gridsize_x, X1, topedge+30, 40, 6,
  50.       pens, "Gridsize X:" );
  51.    AddInteractor( window, (struct Interactor *)&self->gridsize_x );
  52.  
  53.    IntegerGadget_Init( &self->gridsize_y, X2, topedge+30, 40, 6, pens, "Y:" );
  54.    AddInteractor( window, (struct Interactor *)&self->gridsize_y );
  55.  
  56.    CheckBox_Init( &self->OnOff, X3, topedge+18, pens, "Snap on", FALSE );
  57.    AddInteractor( window, (struct Interactor *)&self->OnOff );
  58. }
  59.  
  60. void GridSettings_CleanUp( GridSettings_Iactors *self )
  61. {
  62.    CleanUp( (struct PObject *)&self->outline );
  63.    CleanUp( (struct PObject *)&self->offset_x );
  64.    CleanUp( (struct PObject *)&self->offset_y );
  65.    CleanUp( (struct PObject *)&self->gridsize_x );
  66.    CleanUp( (struct PObject *)&self->gridsize_y );
  67.    CleanUp( (struct PObject *)&self->OnOff );
  68. }
  69.  
  70. void GridSettings_SetSettings( GridSettings_Iactors *self, GridSettings gs )
  71. {
  72.    SetValue( (Valuator *)&self->OnOff,      gs.OnOff );
  73.    SetValue( (Valuator *)&self->offset_x,   gs.offset.x );
  74.    SetValue( (Valuator *)&self->offset_y,   gs.offset.y );
  75.    SetValue( (Valuator *)&self->gridsize_x, gs.gridsize.x );
  76.    SetValue( (Valuator *)&self->gridsize_y, gs.gridsize.y );
  77. }
  78.  
  79. void GridSettings_PutSettings( GridSettings_Iactors *self, GridSettings *gs )
  80. {
  81.    gs->OnOff      = Value( (Valuator *)&self->OnOff );
  82.    gs->offset.x   = Value( (Valuator *)&self->offset_x );
  83.    gs->offset.y   = Value( (Valuator *)&self->offset_y );
  84.    gs->gridsize.x = Value( (Valuator *)&self->gridsize_x );
  85.    gs->gridsize.y = Value( (Valuator *)&self->gridsize_y );
  86. }
  87.  
  88.  
  89. void GridSnapWindow_CleanUp( GridSnapWindow *self )
  90. {
  91.    GridSettings_CleanUp( &self->location );
  92.    GridSettings_CleanUp( &self->size );
  93. }
  94.  
  95.  
  96.  
  97. void GridSnap_SetSettings( GridSnapWindow *w )
  98. {
  99.    GridSettings_SetSettings( &w->location, w->gridinfo.location );
  100.    GridSettings_SetSettings( &w->size,     w->gridinfo.size );
  101. }
  102.  
  103.  
  104. void GridSnap_PutSettings( GridSnapWindow *w )
  105. {
  106.    GridSettings_PutSettings( &w->location, &w->gridinfo.location );
  107.    GridSettings_PutSettings( &w->size,     &w->gridinfo.size );
  108. }
  109.  
  110.  
  111.  
  112.  
  113. UWORD GridSnap_ParseMenuEvent( GridSnapWindow *self,
  114.                                USHORT          MenuNumber,
  115.                                Window         *window )
  116. {
  117.    pcg_MenuItem *item;
  118.    UWORD response = 0;
  119.  
  120.    if( MenuNumber == MENUNULL ) return 0;
  121.  
  122.    item = (pcg_MenuItem *)
  123.       ItemAddress( window->MenuStrip, MenuNumber );
  124.  
  125.    switch( item->ItemID )
  126.    {
  127.       case EDIT_GRID_ID:
  128.          if( self->pw.Window ) /* window is open */
  129.          {
  130.             WindowToFront( self->pw.Window );
  131.             Activate( (struct Interactor *)SELF, TRUE );
  132.          }
  133.          else
  134.          {
  135.             GridSnap_SetSettings( self );
  136.             pcgOpenWindow( SELF );
  137.             Refresh( (struct Interactor *)SELF );
  138.          }
  139.          Activate( (struct Interactor *)&self->location.offset_x, TRUE );
  140.  
  141.          response = RESPONDED | CHANGED_STATE;
  142.          break;
  143.  
  144.       case EDIT_GRID_SIZ_ID:
  145.          self->gridinfo.size.OnOff = ! self->gridinfo.size.OnOff;
  146.          SetValue( (Valuator *)&self->size.OnOff, self->gridinfo.size.OnOff );
  147.          if( self->pw.Window )
  148.             Render( (struct GraphicObject *)&self->size.OnOff, RPort( (struct pcgWindow *)SELF ) );
  149.          response = RESPONDED | CHANGED_STATE;
  150.          GridSnap_SetSettings( self );
  151.          break;
  152.  
  153.       case EDIT_GRID_LOC_ID:
  154.          self->gridinfo.location.OnOff = ! self->gridinfo.location.OnOff;
  155.          SetValue( (Valuator *)&self->location.OnOff, self->gridinfo.location.OnOff );
  156.          if( self->pw.Window )
  157.             Render( (struct GraphicObject *)&self->location.OnOff, RPort( (struct pcgWindow *)SELF ) );
  158.          response = RESPONDED | CHANGED_STATE;
  159.          GridSnap_SetSettings( self );
  160.          break;
  161.    }
  162.  
  163.    return( (UWORD)( response | GridSnap_ParseMenuEvent( self, item->NextSelect, window ) ) );
  164. }
  165.  
  166.  
  167. USHORT GridSnap_Respond( GridSnapWindow *self, IntuiMessage *event )
  168. {
  169.    Window         *iwindow; /* Intuition Window */
  170.    USHORT          response = 0;
  171.  
  172.  
  173.    iwindow = iWindow( SELF );
  174.  
  175.    switch( event->Class )
  176.    {
  177.  
  178.       case CLOSEWINDOW:
  179.          if( event->IDCMPWindow == iwindow )
  180.          {
  181.             pcgCloseWindow( SELF );
  182.             response = RESPONDED | CHANGED_STATE;
  183.          }
  184.          break;
  185.  
  186.       case REFRESHWINDOW:
  187.          if( event->IDCMPWindow == iwindow )
  188.          {
  189.             BeginRefresh( iwindow );
  190.             Refresh( (struct Interactor *)SELF );
  191.             EndRefresh( iwindow, TRUE );
  192.             response = RESPONDED | CHANGED_STATE;
  193.          }
  194.          break;
  195.  
  196.       case MENUPICK:
  197.          response = GridSnap_ParseMenuEvent( self,
  198.                         event->Code, event->IDCMPWindow );
  199.          break;
  200.  
  201.       case MENUVERIFY:
  202.          mnu_SetCheckMark( (struct pcg_MenuItem *)&mi_Grid_Loc, self->gridinfo.location.OnOff );
  203.          mnu_SetCheckMark( (struct pcg_MenuItem *)&mi_Grid_Size, self->gridinfo.size.OnOff );
  204.          response = RESPONDED | CHANGED_STATE;
  205.          break;
  206.  
  207.  
  208.       default:
  209.          if( Respond( (struct Interactor *)&self->location.offset_x, event ) & DEACTIVATED )
  210.          {
  211.             ActivateNext( (struct Interactor *)&self->location.offset_x );
  212.             response = RESPONDED | CHANGED_STATE;
  213.          }
  214.  
  215.          if( Respond( (struct Interactor *)&self->location.offset_y, event ) & DEACTIVATED )
  216.          {
  217.             ActivateNext( (struct Interactor *)&self->location.offset_y );
  218.             response = RESPONDED | CHANGED_STATE;
  219.          }
  220.          if( Respond( (struct Interactor *)&self->location.gridsize_x, event ) & DEACTIVATED )
  221.          {
  222.             ActivateNext( (struct Interactor *)&self->location.gridsize_x );
  223.             response = RESPONDED | CHANGED_STATE;
  224.          }
  225.  
  226.          if( Respond( (struct Interactor *)&self->location.gridsize_y, event ) & DEACTIVATED )
  227.          {
  228.             ActivateNext( (struct Interactor *)&self->location.gridsize_y );
  229.             response = RESPONDED | CHANGED_STATE;
  230.          }
  231.  
  232.          if( Respond( (struct Interactor *)&self->location.OnOff, event ) & CHANGED_STATE )
  233.             response = RESPONDED | CHANGED_STATE;
  234.  
  235.          if( Respond( (struct Interactor *)&self->size.offset_x, event ) & DEACTIVATED )
  236.          {
  237.             response = RESPONDED | CHANGED_STATE;
  238.             ActivateNext( (struct Interactor *)&self->size.offset_x );
  239.          }
  240.  
  241.          if( Respond( (struct Interactor *)&self->size.offset_y, event ) & DEACTIVATED )
  242.          {
  243.             ActivateNext( (struct Interactor *)&self->size.offset_y );
  244.             response = RESPONDED | CHANGED_STATE;
  245.          }
  246.  
  247.          if( Respond( (struct Interactor *)&self->size.gridsize_x, event ) & DEACTIVATED )
  248.          {
  249.             ActivateNext( (struct Interactor *)&self->size.gridsize_x );
  250.             response = RESPONDED | CHANGED_STATE;
  251.          }
  252.  
  253.          if( Respond( (struct Interactor *)&self->size.gridsize_y, event ) & DEACTIVATED )
  254.          {
  255.             ActivateNext( (struct Interactor *)&self->size.gridsize_y );
  256.             response = RESPONDED | CHANGED_STATE;
  257.          }
  258.  
  259.          if( Respond( (struct Interactor *)&self->size.OnOff, event ) & CHANGED_STATE )
  260.             response = RESPONDED | CHANGED_STATE;
  261.  
  262.  
  263.          /* update gridinfo. */
  264.          if( response & CHANGED_STATE )
  265.          {
  266.             GridSnap_PutSettings( self );
  267.          }
  268.  
  269.    }
  270.  
  271.    return response;
  272. }
  273.  
  274.  
  275. BOOL GridSnapWindow_elaborated = FALSE;
  276.  
  277. struct pcgWindowClass GridSnapWindow_Class;
  278.  
  279. void GridSnapWindowClass_Init( struct pcgWindowClass *class )
  280. {
  281.    pcgWindowClass_Init( (struct pcgWindowClass *) class );
  282.    class->isa                 = pcgWindowClass();
  283.    class->Respond             = (USHORT(*)(Interactor *, IntuiMessage *))GridSnap_Respond;
  284.    class->CleanUp             = (void(*)(PObject *))GridSnapWindow_CleanUp;
  285. }
  286.  
  287.  
  288. struct pcgWindowClass *GridSnapWindowClass( void )
  289. {
  290.    if (! GridSnapWindow_elaborated)
  291.    {
  292.       GridSnapWindowClass_Init( &GridSnapWindow_Class );
  293.       GridSnapWindow_elaborated = TRUE;
  294.    }
  295.  
  296.    return &GridSnapWindow_Class;
  297. }
  298.  
  299. void GridSnapWindow_Init(
  300.       GridSnapWindow        *self,
  301.       Screen                *screen,
  302.       struct MsgPort        *sharedport,
  303.       pcg_3DPens             pens )
  304. {
  305.  
  306.    pcgWindow_Init( SELF, 20,250, 370, 140, 1, 1, (USHORT)-1, (USHORT)-1, "GridSnap Controls",
  307.       CLOSEWINDOW | MENUPICK | MENUVERIFY | REFRESHWINDOW,
  308.       ACTIVATE | SIMPLE_REFRESH | WINDOWCLOSE | WINDOWDEPTH | WINDOWDRAG,
  309.       screen );
  310.  
  311.    self->pw.isa = GridSnapWindowClass();
  312.    self->pw.SharedUserPort = sharedport;
  313.  
  314.    self->gridinfo.size.OnOff           = TRUE;
  315.    self->gridinfo.size.offset.x        = 0;
  316.    self->gridinfo.size.offset.y        = 0;
  317.    self->gridinfo.size.gridsize.x      = 4;
  318.    self->gridinfo.size.gridsize.y      = 4;
  319.  
  320.    self->gridinfo.location.OnOff       = TRUE;
  321.    self->gridinfo.location.offset.x    = 0;
  322.    self->gridinfo.location.offset.y    = 0;
  323.    self->gridinfo.location.gridsize.x  = 4;
  324.    self->gridinfo.location.gridsize.y  = 4;
  325.  
  326.    GridSettings_Init( &self->location, &self->gridinfo.location, SELF, 20,
  327.       " Location Snap ", pens );
  328.  
  329.    GridSettings_Init( &self->size, &self->gridinfo.size, SELF, 80,
  330.       " Size Snap ", pens );
  331.  
  332. }
  333.  
  334.  
  335.  
  336.  
  337.  
  338.