home *** CD-ROM | disk | FTP | other *** search
- #include "parms.h"
- #include "Precognition.h"
- #include "BuilderMethods/BuilderMethods.h"
- #include "GridSnapWindow.h"
- #include "Menus/MenuStuff.h"
- #include "PObject.h"
- #include "pcgWindow.h"
- #include "GraphicObject.h"
- #ifndef __GNUC__
- #include <clib/exec_protos.h>
- #include <clib/intuition_protos.h>
- #endif
- #ifdef __GNUC__
- #include <proto/exec.h>
- #include <proto/intuition.h>
- #endif
- #ifdef __SASC
- #include <proto/exec.h>
- #include <proto/intuition.h>
- #endif
-
- #define SELF &self->pw
-
- void GracefulExit( short ExitStatus );
-
- #define X1 120
- #define X2 X1+80
- #define X3 X2+60
-
- void GridSettings_Init(
- GridSettings_Iactors *self,
- GridSettings *gridsettings,
- pcgWindow *window,
- short topedge,
- char *title,
- pcg_3DPens pens )
- {
-
- OutlineBox_Init( &self->outline, 10, topedge+0, 350, 50, pens, title );
- AddGraphicObject( window, (struct GraphicObject *)&self->outline );
-
- IntegerGadget_Init( &self->offset_x, X1, topedge+10, 40, 6,
- pens, "Offset X:" );
- AddInteractor( window, (struct Interactor *)&self->offset_x );
-
- IntegerGadget_Init( &self->offset_y, X2, topedge+10, 40, 6, pens, "Y:" );
- AddInteractor( window, (struct Interactor *)&self->offset_y );
-
- IntegerGadget_Init( &self->gridsize_x, X1, topedge+30, 40, 6,
- pens, "Gridsize X:" );
- AddInteractor( window, (struct Interactor *)&self->gridsize_x );
-
- IntegerGadget_Init( &self->gridsize_y, X2, topedge+30, 40, 6, pens, "Y:" );
- AddInteractor( window, (struct Interactor *)&self->gridsize_y );
-
- CheckBox_Init( &self->OnOff, X3, topedge+18, pens, "Snap on", FALSE );
- AddInteractor( window, (struct Interactor *)&self->OnOff );
- }
-
- void GridSettings_CleanUp( GridSettings_Iactors *self )
- {
- CleanUp( (struct PObject *)&self->outline );
- CleanUp( (struct PObject *)&self->offset_x );
- CleanUp( (struct PObject *)&self->offset_y );
- CleanUp( (struct PObject *)&self->gridsize_x );
- CleanUp( (struct PObject *)&self->gridsize_y );
- CleanUp( (struct PObject *)&self->OnOff );
- }
-
- void GridSettings_SetSettings( GridSettings_Iactors *self, GridSettings gs )
- {
- SetValue( (Valuator *)&self->OnOff, gs.OnOff );
- SetValue( (Valuator *)&self->offset_x, gs.offset.x );
- SetValue( (Valuator *)&self->offset_y, gs.offset.y );
- SetValue( (Valuator *)&self->gridsize_x, gs.gridsize.x );
- SetValue( (Valuator *)&self->gridsize_y, gs.gridsize.y );
- }
-
- void GridSettings_PutSettings( GridSettings_Iactors *self, GridSettings *gs )
- {
- gs->OnOff = Value( (Valuator *)&self->OnOff );
- gs->offset.x = Value( (Valuator *)&self->offset_x );
- gs->offset.y = Value( (Valuator *)&self->offset_y );
- gs->gridsize.x = Value( (Valuator *)&self->gridsize_x );
- gs->gridsize.y = Value( (Valuator *)&self->gridsize_y );
- }
-
-
- void GridSnapWindow_CleanUp( GridSnapWindow *self )
- {
- GridSettings_CleanUp( &self->location );
- GridSettings_CleanUp( &self->size );
- }
-
-
-
- void GridSnap_SetSettings( GridSnapWindow *w )
- {
- GridSettings_SetSettings( &w->location, w->gridinfo.location );
- GridSettings_SetSettings( &w->size, w->gridinfo.size );
- }
-
-
- void GridSnap_PutSettings( GridSnapWindow *w )
- {
- GridSettings_PutSettings( &w->location, &w->gridinfo.location );
- GridSettings_PutSettings( &w->size, &w->gridinfo.size );
- }
-
-
-
-
- UWORD GridSnap_ParseMenuEvent( GridSnapWindow *self,
- USHORT MenuNumber,
- Window *window )
- {
- pcg_MenuItem *item;
- UWORD response = 0;
-
- if( MenuNumber == MENUNULL ) return 0;
-
- item = (pcg_MenuItem *)
- ItemAddress( window->MenuStrip, MenuNumber );
-
- switch( item->ItemID )
- {
- case EDIT_GRID_ID:
- if( self->pw.Window ) /* window is open */
- {
- WindowToFront( self->pw.Window );
- Activate( (struct Interactor *)SELF, TRUE );
- }
- else
- {
- GridSnap_SetSettings( self );
- pcgOpenWindow( SELF );
- Refresh( (struct Interactor *)SELF );
- }
- Activate( (struct Interactor *)&self->location.offset_x, TRUE );
-
- response = RESPONDED | CHANGED_STATE;
- break;
-
- case EDIT_GRID_SIZ_ID:
- self->gridinfo.size.OnOff = ! self->gridinfo.size.OnOff;
- SetValue( (Valuator *)&self->size.OnOff, self->gridinfo.size.OnOff );
- if( self->pw.Window )
- Render( (struct GraphicObject *)&self->size.OnOff, RPort( (struct pcgWindow *)SELF ) );
- response = RESPONDED | CHANGED_STATE;
- GridSnap_SetSettings( self );
- break;
-
- case EDIT_GRID_LOC_ID:
- self->gridinfo.location.OnOff = ! self->gridinfo.location.OnOff;
- SetValue( (Valuator *)&self->location.OnOff, self->gridinfo.location.OnOff );
- if( self->pw.Window )
- Render( (struct GraphicObject *)&self->location.OnOff, RPort( (struct pcgWindow *)SELF ) );
- response = RESPONDED | CHANGED_STATE;
- GridSnap_SetSettings( self );
- break;
- }
-
- return( (UWORD)( response | GridSnap_ParseMenuEvent( self, item->NextSelect, window ) ) );
- }
-
-
- USHORT GridSnap_Respond( GridSnapWindow *self, IntuiMessage *event )
- {
- Window *iwindow; /* Intuition Window */
- USHORT response = 0;
-
-
- iwindow = iWindow( SELF );
-
- switch( event->Class )
- {
-
- case CLOSEWINDOW:
- if( event->IDCMPWindow == iwindow )
- {
- pcgCloseWindow( SELF );
- response = RESPONDED | CHANGED_STATE;
- }
- break;
-
- case REFRESHWINDOW:
- if( event->IDCMPWindow == iwindow )
- {
- BeginRefresh( iwindow );
- Refresh( (struct Interactor *)SELF );
- EndRefresh( iwindow, TRUE );
- response = RESPONDED | CHANGED_STATE;
- }
- break;
-
- case MENUPICK:
- response = GridSnap_ParseMenuEvent( self,
- event->Code, event->IDCMPWindow );
- break;
-
- case MENUVERIFY:
- mnu_SetCheckMark( (struct pcg_MenuItem *)&mi_Grid_Loc, self->gridinfo.location.OnOff );
- mnu_SetCheckMark( (struct pcg_MenuItem *)&mi_Grid_Size, self->gridinfo.size.OnOff );
- response = RESPONDED | CHANGED_STATE;
- break;
-
-
- default:
- if( Respond( (struct Interactor *)&self->location.offset_x, event ) & DEACTIVATED )
- {
- ActivateNext( (struct Interactor *)&self->location.offset_x );
- response = RESPONDED | CHANGED_STATE;
- }
-
- if( Respond( (struct Interactor *)&self->location.offset_y, event ) & DEACTIVATED )
- {
- ActivateNext( (struct Interactor *)&self->location.offset_y );
- response = RESPONDED | CHANGED_STATE;
- }
- if( Respond( (struct Interactor *)&self->location.gridsize_x, event ) & DEACTIVATED )
- {
- ActivateNext( (struct Interactor *)&self->location.gridsize_x );
- response = RESPONDED | CHANGED_STATE;
- }
-
- if( Respond( (struct Interactor *)&self->location.gridsize_y, event ) & DEACTIVATED )
- {
- ActivateNext( (struct Interactor *)&self->location.gridsize_y );
- response = RESPONDED | CHANGED_STATE;
- }
-
- if( Respond( (struct Interactor *)&self->location.OnOff, event ) & CHANGED_STATE )
- response = RESPONDED | CHANGED_STATE;
-
- if( Respond( (struct Interactor *)&self->size.offset_x, event ) & DEACTIVATED )
- {
- response = RESPONDED | CHANGED_STATE;
- ActivateNext( (struct Interactor *)&self->size.offset_x );
- }
-
- if( Respond( (struct Interactor *)&self->size.offset_y, event ) & DEACTIVATED )
- {
- ActivateNext( (struct Interactor *)&self->size.offset_y );
- response = RESPONDED | CHANGED_STATE;
- }
-
- if( Respond( (struct Interactor *)&self->size.gridsize_x, event ) & DEACTIVATED )
- {
- ActivateNext( (struct Interactor *)&self->size.gridsize_x );
- response = RESPONDED | CHANGED_STATE;
- }
-
- if( Respond( (struct Interactor *)&self->size.gridsize_y, event ) & DEACTIVATED )
- {
- ActivateNext( (struct Interactor *)&self->size.gridsize_y );
- response = RESPONDED | CHANGED_STATE;
- }
-
- if( Respond( (struct Interactor *)&self->size.OnOff, event ) & CHANGED_STATE )
- response = RESPONDED | CHANGED_STATE;
-
-
- /* update gridinfo. */
- if( response & CHANGED_STATE )
- {
- GridSnap_PutSettings( self );
- }
-
- }
-
- return response;
- }
-
-
- BOOL GridSnapWindow_elaborated = FALSE;
-
- struct pcgWindowClass GridSnapWindow_Class;
-
- void GridSnapWindowClass_Init( struct pcgWindowClass *class )
- {
- pcgWindowClass_Init( (struct pcgWindowClass *) class );
- class->isa = pcgWindowClass();
- class->Respond = (USHORT(*)(Interactor *, IntuiMessage *))GridSnap_Respond;
- class->CleanUp = (void(*)(PObject *))GridSnapWindow_CleanUp;
- }
-
-
- struct pcgWindowClass *GridSnapWindowClass( void )
- {
- if (! GridSnapWindow_elaborated)
- {
- GridSnapWindowClass_Init( &GridSnapWindow_Class );
- GridSnapWindow_elaborated = TRUE;
- }
-
- return &GridSnapWindow_Class;
- }
-
- void GridSnapWindow_Init(
- GridSnapWindow *self,
- Screen *screen,
- struct MsgPort *sharedport,
- pcg_3DPens pens )
- {
-
- pcgWindow_Init( SELF, 20,250, 370, 140, 1, 1, (USHORT)-1, (USHORT)-1, "GridSnap Controls",
- CLOSEWINDOW | MENUPICK | MENUVERIFY | REFRESHWINDOW,
- ACTIVATE | SIMPLE_REFRESH | WINDOWCLOSE | WINDOWDEPTH | WINDOWDRAG,
- screen );
-
- self->pw.isa = GridSnapWindowClass();
- self->pw.SharedUserPort = sharedport;
-
- self->gridinfo.size.OnOff = TRUE;
- self->gridinfo.size.offset.x = 0;
- self->gridinfo.size.offset.y = 0;
- self->gridinfo.size.gridsize.x = 4;
- self->gridinfo.size.gridsize.y = 4;
-
- self->gridinfo.location.OnOff = TRUE;
- self->gridinfo.location.offset.x = 0;
- self->gridinfo.location.offset.y = 0;
- self->gridinfo.location.gridsize.x = 4;
- self->gridinfo.location.gridsize.y = 4;
-
- GridSettings_Init( &self->location, &self->gridinfo.location, SELF, 20,
- " Location Snap ", pens );
-
- GridSettings_Init( &self->size, &self->gridinfo.size, SELF, 80,
- " Size Snap ", pens );
-
- }
-
-
-
-
-
-