Main Page | Class Hierarchy | Compound List | File List | Compound Members | File Members | Related Pages

AmigaGUI.c

Go to the documentation of this file.
00001 /*
00002  *  Source machine generated by GadToolsBox V2.0b
00003  *  which is (c) Copyright 1991-1993 Jaba Development
00004  *
00005  *  GUI Designed by : Christian Bauer
00006  */
00007 
00008 #include <exec/types.h>
00009 #include <intuition/intuition.h>
00010 #include <intuition/classes.h>
00011 #include <intuition/classusr.h>
00012 #include <intuition/imageclass.h>
00013 #include <intuition/gadgetclass.h>
00014 #include <libraries/gadtools.h>
00015 #include <graphics/displayinfo.h>
00016 #include <graphics/gfxbase.h>
00017 #include <clib/exec_protos.h>
00018 #include <clib/intuition_protos.h>
00019 #include <clib/gadtools_protos.h>
00020 #include <clib/graphics_protos.h>
00021 #include <clib/utility_protos.h>
00022 #include <string.h>
00023 #include "AmigaGUI.h"
00024 
00025 struct Screen         *Scr = NULL;
00026 UBYTE                 *PubScreenName = NULL;
00027 APTR                   VisualInfo = NULL;
00028 struct Window         *PrefsWnd = NULL;
00029 struct Gadget         *PrefsGList = NULL;
00030 struct Menu           *PrefsMenus = NULL;
00031 struct IntuiMessage    PrefsMsg;
00032 UWORD                  PrefsZoom[4];
00033 struct Gadget         *PrefsGadgets[31];
00034 UWORD                  PrefsLeft = 0;
00035 UWORD                  PrefsTop = 16;
00036 UWORD                  PrefsWidth = 561;
00037 UWORD                  PrefsHeight = 238;
00038 UBYTE                 *PrefsWdt = (UBYTE *)"Frodo Preferences";
00039 struct TextAttr       *Font, Attr;
00040 UWORD                  FontX, FontY;
00041 UWORD                  OffX, OffY;
00042 
00043 UBYTE *SIDType0Labels[] = {
00044         (UBYTE *)"None",
00045         (UBYTE *)"Digital (AHI)",
00046         (UBYTE *)"SID Card",
00047         NULL };
00048 
00049 UBYTE *REUSize0Labels[] = {
00050         (UBYTE *)"None",
00051         (UBYTE *)"128K",
00052         (UBYTE *)"256K",
00053         (UBYTE *)"512K",
00054         NULL };
00055 
00056 UBYTE *DriveType80Labels[] = {
00057         (UBYTE *)"DIR",
00058         (UBYTE *)"D64",
00059         (UBYTE *)"T64",
00060         NULL };
00061 
00062 UBYTE *DriveType90Labels[] = {
00063         (UBYTE *)"DIR",
00064         (UBYTE *)"D64",
00065         (UBYTE *)"T64",
00066         NULL };
00067 
00068 UBYTE *DriveType100Labels[] = {
00069         (UBYTE *)"DIR",
00070         (UBYTE *)"D64",
00071         (UBYTE *)"T64",
00072         NULL };
00073 
00074 UBYTE *DriveType110Labels[] = {
00075         (UBYTE *)"DIR",
00076         (UBYTE *)"D64",
00077         (UBYTE *)"T64",
00078         NULL };
00079 
00080 struct IntuiText PrefsIText[] = {
00081         2, 0, JAM1,34, 115, NULL, (UBYTE *)"Drive", NULL };
00082 
00083 #define Prefs_TNUM 1
00084 
00085 struct NewMenu PrefsNewMenu[] = {
00086         NM_TITLE, (STRPTR)"Preferences", NULL, 0, NULL, NULL,
00087         NM_ITEM, (STRPTR)"Open...", (STRPTR)"O", 0, 0L, (APTR)PrefsOpen,
00088         NM_ITEM, (STRPTR)"Save", (STRPTR)"S", 0, 0L, (APTR)PrefsSave,
00089         NM_ITEM, (STRPTR)"Save As...", (STRPTR)"A", 0, 0L, (APTR)PrefsSaveAs,
00090         NM_ITEM, (STRPTR)"Revert", (STRPTR)"R", 0, 0L, (APTR)PrefsRevert,
00091         NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
00092         NM_ITEM, (STRPTR)"OK", NULL, 0, 0L, (APTR)PrefsOK,
00093         NM_ITEM, (STRPTR)"Cancel", NULL, 0, 0L, (APTR)PrefsCancel,
00094         NM_END, NULL, NULL, 0, 0L, NULL };
00095 
00096 UWORD PrefsGTypes[] = {
00097         CHECKBOX_KIND,
00098         CHECKBOX_KIND,
00099         CHECKBOX_KIND,
00100         CHECKBOX_KIND,
00101         CHECKBOX_KIND,
00102         CHECKBOX_KIND,
00103         CHECKBOX_KIND,
00104         CHECKBOX_KIND,
00105         INTEGER_KIND,
00106         INTEGER_KIND,
00107         INTEGER_KIND,
00108         INTEGER_KIND,
00109         INTEGER_KIND,
00110         CYCLE_KIND,
00111         CYCLE_KIND,
00112         STRING_KIND,
00113         CYCLE_KIND,
00114         STRING_KIND,
00115         CYCLE_KIND,
00116         STRING_KIND,
00117         CYCLE_KIND,
00118         STRING_KIND,
00119         CYCLE_KIND,
00120         CHECKBOX_KIND,
00121         CHECKBOX_KIND,
00122         BUTTON_KIND,
00123         BUTTON_KIND,
00124         BUTTON_KIND,
00125         BUTTON_KIND,
00126         BUTTON_KIND,
00127         BUTTON_KIND
00128 };
00129 
00130 struct NewGadget PrefsNGad[] = {
00131         8, 4, 26, 11, (UBYTE *)"Sprite display", NULL, GD_SpritesOn, PLACETEXT_RIGHT, NULL, (APTR)SpritesOnClicked,
00132         8, 16, 26, 11, (UBYTE *)"Sprite collisions", NULL, GD_SpriteCollisions, PLACETEXT_RIGHT, NULL, (APTR)SpriteCollisionsClicked,
00133         8, 28, 26, 11, (UBYTE *)"Joystick connected", NULL, GD_Joystick2On, PLACETEXT_RIGHT, NULL, (APTR)Joystick2OnClicked,
00134         8, 40, 26, 11, (UBYTE *)"Map joystick to port 1", NULL, GD_JoystickSwap, PLACETEXT_RIGHT, NULL, (APTR)JoystickSwapClicked,
00135         8, 52, 26, 11, (UBYTE *)"Limit speed", NULL, GD_LimitSpeed, PLACETEXT_RIGHT, NULL, (APTR)LimitSpeedClicked,
00136         8, 64, 26, 11, (UBYTE *)"Fast reset", NULL, GD_FastReset, PLACETEXT_RIGHT, NULL, (APTR)FastResetClicked,
00137         8, 76, 26, 11, (UBYTE *)"Clear CIA ICR on write", NULL, GD_CIAIRQHack, PLACETEXT_RIGHT, NULL, (APTR)CIAIRQHackClicked,
00138         8, 88, 26, 11, (UBYTE *)"SID filters", NULL, GD_SIDFilters, PLACETEXT_RIGHT, NULL, (APTR)SIDFiltersClicked,
00139         490, 4, 65, 14, (UBYTE *)"Cycles per line (CPU)", NULL, GD_NormalCycles, PLACETEXT_LEFT, NULL, (APTR)NormalCyclesClicked,
00140         490, 19, 65, 14, (UBYTE *)"Cycles per Bad Line (CPU)", NULL, GD_BadLineCycles, PLACETEXT_LEFT, NULL, (APTR)BadLineCyclesClicked,
00141         490, 34, 65, 14, (UBYTE *)"Cycles per line (CIA)", NULL, GD_CIACycles, PLACETEXT_LEFT, NULL, (APTR)CIACyclesClicked,
00142         490, 49, 65, 14, (UBYTE *)"Cycles per line (1541)", NULL, GD_FloppyCycles, PLACETEXT_LEFT, NULL, (APTR)FloppyCyclesClicked,
00143         490, 64, 65, 14, (UBYTE *)"Draw every n-th frame", NULL, GD_SkipFrames, PLACETEXT_LEFT, NULL, (APTR)SkipFramesClicked,
00144         426, 79, 129, 14, (UBYTE *)"SID emulation type", NULL, GD_SIDType, PLACETEXT_LEFT, NULL, (APTR)SIDTypeClicked,
00145         426, 94, 129, 14, (UBYTE *)"REU size", NULL, GD_REUSize, PLACETEXT_LEFT, NULL, (APTR)REUSizeClicked,
00146         47, 123, 401, 14, (UBYTE *)"8", NULL, GD_DrivePath8, PLACETEXT_LEFT, NULL, (APTR)DrivePath8Clicked,
00147         470, 123, 65, 14, NULL, NULL, GD_DriveType8, 0, NULL, (APTR)DriveType8Clicked,
00148         47, 138, 401, 14, (UBYTE *)"9", NULL, GD_DrivePath9, PLACETEXT_LEFT, NULL, (APTR)DrivePath9Clicked,
00149         470, 138, 65, 14, NULL, NULL, GD_DriveType9, 0, NULL, (APTR)DriveType9Clicked,
00150         47, 153, 401, 14, (UBYTE *)"10", NULL, GD_DrivePath10, PLACETEXT_LEFT, NULL, (APTR)DrivePath10Clicked,
00151         470, 153, 65, 14, NULL, NULL, GD_DriveType10, 0, NULL, (APTR)DriveType10Clicked,
00152         47, 168, 401, 14, (UBYTE *)"11", NULL, GD_DrivePath11, PLACETEXT_LEFT, NULL, (APTR)DrivePath11Clicked,
00153         470, 168, 65, 14, NULL, NULL, GD_DriveType11, 0, NULL, (APTR)DriveType11Clicked,
00154         20, 186, 26, 11, (UBYTE *)"Map '/'<->'\' in filenames", NULL, GD_MapSlash, PLACETEXT_RIGHT, NULL, (APTR)MapSlashClicked,
00155         20, 198, 26, 11, (UBYTE *)"Enable 1541 processor emulation", NULL, GD_Emul1541Proc, PLACETEXT_RIGHT, NULL, (APTR)Emul1541ProcClicked,
00156         61, 218, 81, 16, (UBYTE *)"_OK", NULL, GD_OK, PLACETEXT_IN, NULL, (APTR)OKClicked,
00157         416, 218, 81, 16, (UBYTE *)"_Cancel", NULL, GD_Cancel, PLACETEXT_IN, NULL, (APTR)CancelClicked,
00158         448, 123, 20, 14, (UBYTE *)"", NULL, GD_GetDrive8, PLACETEXT_IN, NULL, (APTR)GetDrive8Clicked,
00159         448, 138, 20, 14, (UBYTE *)"", NULL, GD_GetDrive9, PLACETEXT_IN, NULL, (APTR)GetDrive9Clicked,
00160         448, 153, 20, 14, (UBYTE *)"", NULL, GD_GetDrive10, PLACETEXT_IN, NULL, (APTR)GetDrive10Clicked,
00161         448, 168, 20, 14, (UBYTE *)"", NULL, GD_GetDrive11, PLACETEXT_IN, NULL, (APTR)GetDrive11Clicked
00162 };
00163 
00164 ULONG PrefsGTags[] = {
00165         (TAG_DONE),
00166         (TAG_DONE),
00167         (TAG_DONE),
00168         (TAG_DONE),
00169         (TAG_DONE),
00170         (TAG_DONE),
00171         (TAG_DONE),
00172         (TAG_DONE),
00173         (GTIN_Number), 0, (GTIN_MaxChars), 10, (STRINGA_Justification), (GACT_STRINGRIGHT), (TAG_DONE),
00174         (GTIN_Number), 0, (GTIN_MaxChars), 10, (STRINGA_Justification), (GACT_STRINGRIGHT), (TAG_DONE),
00175         (GTIN_Number), 0, (GTIN_MaxChars), 10, (STRINGA_Justification), (GACT_STRINGRIGHT), (TAG_DONE),
00176         (GTIN_Number), 0, (GTIN_MaxChars), 10, (STRINGA_Justification), (GACT_STRINGRIGHT), (TAG_DONE),
00177         (GTIN_Number), 0, (GTIN_MaxChars), 10, (STRINGA_Justification), (GACT_STRINGRIGHT), (TAG_DONE),
00178         (GTCY_Labels), (ULONG)&SIDType0Labels[ 0 ], (TAG_DONE),
00179         (GTCY_Labels), (ULONG)&REUSize0Labels[ 0 ], (TAG_DONE),
00180         (GTST_MaxChars), 256, (TAG_DONE),
00181         (GTCY_Labels), (ULONG)&DriveType80Labels[ 0 ], (TAG_DONE),
00182         (GTST_MaxChars), 256, (TAG_DONE),
00183         (GTCY_Labels), (ULONG)&DriveType90Labels[ 0 ], (TAG_DONE),
00184         (GTST_MaxChars), 256, (TAG_DONE),
00185         (GTCY_Labels), (ULONG)&DriveType100Labels[ 0 ], (TAG_DONE),
00186         (GTST_MaxChars), 256, (TAG_DONE),
00187         (GTCY_Labels), (ULONG)&DriveType110Labels[ 0 ], (TAG_DONE),
00188         (TAG_DONE),
00189         (TAG_DONE),
00190         (GT_Underscore), '_', (TAG_DONE),
00191         (GT_Underscore), '_', (TAG_DONE),
00192         (TAG_DONE),
00193         (TAG_DONE),
00194         (TAG_DONE),
00195         (TAG_DONE)
00196 };
00197 
00198 static UWORD ComputeX( UWORD value )
00199 {
00200         return(( UWORD )((( FontX * value ) + 4 ) / 8 ));
00201 }
00202 
00203 static UWORD ComputeY( UWORD value )
00204 {
00205         return(( UWORD )((( FontY * value ) + 4 ) / 8 ));
00206 }
00207 
00208 static void ComputeFont( UWORD width, UWORD height )
00209 {
00210         Font = &Attr;
00211         Font->ta_Name = (STRPTR)Scr->RastPort.Font->tf_Message.mn_Node.ln_Name;
00212         Font->ta_YSize = FontY = Scr->RastPort.Font->tf_YSize;
00213         FontX = Scr->RastPort.Font->tf_XSize;
00214 
00215         OffX = Scr->WBorLeft;
00216         OffY = Scr->RastPort.TxHeight + Scr->WBorTop + 1;
00217 
00218         if ( width && height ) {
00219                 if (( ComputeX( width ) + OffX + Scr->WBorRight ) > Scr->Width )
00220                         goto UseTopaz;
00221                 if (( ComputeY( height ) + OffY + Scr->WBorBottom ) > Scr->Height )
00222                         goto UseTopaz;
00223         }
00224         return;
00225 
00226 UseTopaz:
00227         Font->ta_Name = (STRPTR)"topaz.font";
00228         FontX = FontY = Font->ta_YSize = 8;
00229 }
00230 
00231 int SetupScreen( void )
00232 {
00233         if ( ! ( Scr = LockPubScreen( PubScreenName )))
00234                 return( 1L );
00235 
00236         ComputeFont( 0, 0 );
00237 
00238         if ( ! ( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))
00239                 return( 2L );
00240 
00241         return( 0L );
00242 }
00243 
00244 void CloseDownScreen( void )
00245 {
00246         if ( VisualInfo ) {
00247                 FreeVisualInfo( VisualInfo );
00248                 VisualInfo = NULL;
00249         }
00250 
00251         if ( Scr        ) {
00252                 UnlockPubScreen( NULL, Scr );
00253                 Scr = NULL;
00254         }
00255 }
00256 
00257 void PrefsRender( void )
00258 {
00259         struct IntuiText        it;
00260         UWORD                   cnt;
00261 
00262         ComputeFont( PrefsWidth, PrefsHeight );
00263 
00264 
00265         for ( cnt = 0; cnt < Prefs_TNUM; cnt++ ) {
00266                 CopyMem(( char * )&PrefsIText[ cnt ], ( char * )&it, (long)sizeof( struct IntuiText ));
00267                 it.ITextFont = Font;
00268                 it.LeftEdge  = OffX + ComputeX( it.LeftEdge ) - ( IntuiTextLength( &it ) >> 1 );
00269                 it.TopEdge   = OffY + ComputeY( it.TopEdge ) - ( Font->ta_YSize >> 1 );
00270                 PrintIText( PrefsWnd->RPort, &it, 0, 0 );
00271         }
00272 }
00273 
00274 int HandlePrefsIDCMP( void )
00275 {
00276         struct IntuiMessage     *m;
00277         struct MenuItem         *n;
00278         int                     (*func)();
00279         BOOL                    running = TRUE;
00280 
00281         while( m = GT_GetIMsg( PrefsWnd->UserPort )) {
00282 
00283                 CopyMem(( char * )m, ( char * )&PrefsMsg, (long)sizeof( struct IntuiMessage ));
00284 
00285                 GT_ReplyIMsg( m );
00286 
00287                 switch ( PrefsMsg.Class ) {
00288 
00289                         case    IDCMP_REFRESHWINDOW:
00290                                 GT_BeginRefresh( PrefsWnd );
00291                                 PrefsRender();
00292                                 GT_EndRefresh( PrefsWnd, TRUE );
00293                                 break;
00294 
00295                         case    IDCMP_VANILLAKEY:
00296                                 running = PrefsVanillaKey();
00297                                 break;
00298 
00299                         case    IDCMP_GADGETUP:
00300                                 func = ( void * )(( struct Gadget * )PrefsMsg.IAddress )->UserData;
00301                                 running = func();
00302                                 break;
00303 
00304                         case    IDCMP_MENUPICK:
00305                                 while( PrefsMsg.Code != MENUNULL ) {
00306                                         n = ItemAddress( PrefsMenus, PrefsMsg.Code );
00307                                         func = (void *)(GTMENUITEM_USERDATA( n ));
00308                                         running = func();
00309                                         PrefsMsg.Code = n->NextSelect;
00310                                 }
00311                                 break;
00312                 }
00313         }
00314         return( running );
00315 }
00316 
00317 int OpenPrefsWindow( void )
00318 {
00319         struct NewGadget        ng;
00320         struct Gadget   *g;
00321         UWORD           lc, tc;
00322         UWORD           wleft = PrefsLeft, wtop = PrefsTop, ww, wh;
00323 
00324         ComputeFont( PrefsWidth, PrefsHeight );
00325 
00326         ww = ComputeX( PrefsWidth );
00327         wh = ComputeY( PrefsHeight );
00328 
00329         if (( wleft + ww + OffX + Scr->WBorRight ) > Scr->Width ) wleft = Scr->Width - ww;
00330         if (( wtop + wh + OffY + Scr->WBorBottom ) > Scr->Height ) wtop = Scr->Height - wh;
00331 
00332         if ( ! ( g = CreateContext( &PrefsGList )))
00333                 return( 1L );
00334 
00335         for( lc = 0, tc = 0; lc < Prefs_CNT; lc++ ) {
00336 
00337                 CopyMem((char * )&PrefsNGad[ lc ], (char * )&ng, (long)sizeof( struct NewGadget ));
00338 
00339                 ng.ng_VisualInfo = VisualInfo;
00340                 ng.ng_TextAttr   = Font;
00341                 ng.ng_LeftEdge   = OffX + ComputeX( ng.ng_LeftEdge );
00342                 ng.ng_TopEdge    = OffY + ComputeY( ng.ng_TopEdge );
00343                 ng.ng_Width      = ComputeX( ng.ng_Width );
00344                 ng.ng_Height     = ComputeY( ng.ng_Height);
00345 
00346                 PrefsGadgets[ lc ] = g = CreateGadgetA((ULONG)PrefsGTypes[ lc ], g, &ng, ( struct TagItem * )&PrefsGTags[ tc ] );
00347 
00348                 while( PrefsGTags[ tc ] ) tc += 2;
00349                 tc++;
00350 
00351                 if ( NOT g )
00352                         return( 2L );
00353         }
00354 
00355         if ( ! ( PrefsMenus = CreateMenus( PrefsNewMenu, GTMN_FrontPen, 0L, TAG_DONE )))
00356                 return( 3L );
00357 
00358         LayoutMenus( PrefsMenus, VisualInfo, TAG_DONE );
00359 
00360                 PrefsZoom[0] = PrefsZoom[1] = 0;
00361         if ( PrefsWdt )
00362                 PrefsZoom[2] = TextLength( &Scr->RastPort, (UBYTE *)PrefsWdt, strlen((char *)PrefsWdt )) + 80;
00363         else
00364                 PrefsZoom[2]  = 80L;
00365                 PrefsZoom[3] = Scr->WBorTop + Scr->RastPort.TxHeight + 1;
00366 
00367         if ( ! ( PrefsWnd = OpenWindowTags( NULL,
00368                                 WA_Left,        wleft,
00369                                 WA_Top,         wtop,
00370                                 WA_Width,       ww + OffX + Scr->WBorRight,
00371                                 WA_Height,      wh + OffY + Scr->WBorBottom,
00372                                 WA_IDCMP,       CHECKBOXIDCMP|INTEGERIDCMP|CYCLEIDCMP|STRINGIDCMP|BUTTONIDCMP|IDCMP_MENUPICK|IDCMP_VANILLAKEY|IDCMP_REFRESHWINDOW,
00373                                 WA_Flags,       WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_SMART_REFRESH|WFLG_SIMPLE_REFRESH|WFLG_ACTIVATE,
00374                                 WA_Gadgets,     PrefsGList,
00375                                 WA_Title,       PrefsWdt,
00376                                 WA_ScreenTitle, "Frodo C64 Emulator",
00377                                 WA_PubScreen,   Scr,
00378                                 WA_Zoom,        PrefsZoom,
00379                                 TAG_DONE )))
00380         return( 4L );
00381 
00382         SetMenuStrip( PrefsWnd, PrefsMenus );
00383         GT_RefreshWindow( PrefsWnd, NULL );
00384 
00385         PrefsRender();
00386 
00387         return( 0L );
00388 }
00389 
00390 void ClosePrefsWindow( void )
00391 {
00392         if ( PrefsMenus      ) {
00393                 ClearMenuStrip( PrefsWnd );
00394                 FreeMenus( PrefsMenus );
00395                 PrefsMenus = NULL;      }
00396 
00397         if ( PrefsWnd        ) {
00398                 CloseWindow( PrefsWnd );
00399                 PrefsWnd = NULL;
00400         }
00401 
00402         if ( PrefsGList      ) {
00403                 FreeGadgets( PrefsGList );
00404                 PrefsGList = NULL;
00405         }
00406 }
00407 

Generated on Tue Feb 8 04:07:17 2005 for E32frodo by doxygen 1.3.3