home *** CD-ROM | disk | FTP | other *** search
-
-
- /*
- ** $VER: Example 2.20 (28.11.95)
- ** SwazBlanker Release 2.20
- **
- ** Example SwazBlanker Module Source
- **
- ** (C) Copyright 1992-95 David Swasbrook,
- ** All Rights Reserved
- */
-
- /********************************************************************
-
- Well here is some example source for SwazBlanker 2.20
-
- * SB_Init() interface to get invocation method.
-
- * uses "swazconfig.library" support for shared
- configuration file
-
- * Sorry that this source is not 100% documented. Any
- problems please email swaz@ait.ac.nz
-
- ********************************************************************/
-
-
- #include <stdio.h>
-
- #include <proto/exec.h>
- #include <proto/dos.h>
- #include <proto/intuition.h>
-
- #include <proto/swazblanker.h>
- #include <proto/swazconfig.h>
- #include <libraries/swazblanker.h>
- #include <libraries/swazconfig.h>
-
- /*
- ** Setup the library bases we need to open
- */
- struct SwazBlankerBase *SwazBlankerBase;
- struct SwazConfigBase *SwazConfigBase;
-
- /*
- ** Standard version string
- */
- #define VERSION 2
- #define REVISION 20
-
- extern UBYTE VersionStr[] = "$VER: ExampleBlanker 2.20 (28.11.95)";
- extern UBYTE NameStr[] = "ExampleBlanker";
- extern UBYTE Name[] = "Example";
-
- /*
- ** SwazBlanker ID string
- **
- ** The blanker identification string used to be different, i have
- ** changed to the new format and now the blanker is run with the
- ** argument INFO to query the necessary info... this way it can
- ** easily be localized.
- **
- */
- extern UBYTE ID[] = "\0$BLANKER:Ver 2:";
-
-
-
- /*
- ** SwazBlanker Init Structure
- */
- struct SBInit *SBInit;
-
-
- struct BPrefs {
- LONG Option1;
- WORD Option2;
- WORD Option3;
- };
- struct BPrefs BPrefs;
-
-
- #define DEF_OPTION1 57
- #define DEF_OPTION2 127
- #define DEF_OPTION3 33
-
-
- STRPTR CFT[] = {
- "Option1",
- "Option2",
- "Option3",
- NULL
- };
-
- #define CFT_OPTION1 0
- #define CFT_OPTION2 1
- #define CFT_OPTION3 2
-
-
- LONG CF_GetNumeric( APTR cf, STRPTR Name, LONG def )
- {
- struct SC_ConfigVar *cv;
- STRPTR s;
- LONG v;
-
- s = 0;
- if( cv = SC_FindConfigVar( cf, Name ) )
- s = cv->Data;
-
- if( s ) {
- if( StrToLong( s, &v ) == -1 ) v = def;
- }
- else v = def;
-
- return( v );
- }
-
- STRPTR FmtNumeric( STRPTR b, LONG v )
- {
- sprintf(b,"%ld",v);
- return( b );
- }
-
- void DefaultPrefs( struct BPrefs *p )
- {
- p->Option1 = 0;
- p->Option2 = 1;
- p->Option3 = 2;
- }
-
- void LoadPrefs( struct BPrefs *p, STRPTR FileName )
- {
-
- APTR cf;
-
- DefaultPrefs( p );
-
- if( cf = SC_ReadConfig( FileName, &*Name ) )
- {
- p->Option1 = CF_GetNumeric( cf, CFT[ CFT_OPTION1 ], DEF_OPTION1 );
- p->Option2 = CF_GetNumeric( cf, CFT[ CFT_OPTION2 ], DEF_OPTION2 );
- p->Option3 = CF_GetNumeric( cf, CFT[ CFT_OPTION3 ], DEF_OPTION3 );
-
- SC_FreeConfig( cf );
- }
- }
-
- void SavePrefs( struct BPrefs *p, STRPTR FileName )
- {
- APTR cf;
- UBYTE V[32];
-
- if( cf = SC_ReadConfig( FileName, &*Name ) )
- {
- SC_SetConfigVarByName( cf, CFT[ CFT_OPTION1 ], FmtNumeric( &*V, p->Option1 ) );
- SC_SetConfigVarByName( cf, CFT[ CFT_OPTION2 ], FmtNumeric( &*V, p->Option2 ) );
- SC_SetConfigVarByName( cf, CFT[ CFT_OPTION3 ], FmtNumeric( &*V, p->Option3 ) );
-
- SC_WriteConfig( cf, FileName, &*Name );
- SC_FreeConfig( cf );
- }
- }
-
-
-
-
-
-
-
- /****** exampleblanker/Prefs() ***********************************
- *
- * SYNTAX
- * Prefs()
- *
- * FUNCTION
- * This is the preferences configuration interface for
- * the blanker.
- *
- * NOTE
- * Your user-interface should use the same font as set in
- * the SwazBlanker preferences. This can be obtained
- * from the SwazBlanker semaphore ssem->InterfaceFont.
- * This is pointer to a string, Eg "Helvetica 11".
- *
- *****************************************************************/
- void Prefs(void)
- {
- ULONG r;
- struct BlankerPrefsNode *bpn;
- struct EasyStruct es = {
- sizeof(struct EasyStruct),
- 0,
- "Example Blanker",
- "No configuration required",
- "Save|Use|Cancel" };
-
- LoadPrefs( &BPrefs, SwazBlankerBase->UseFileName );
-
- if( bpn = SB_AddPrefsTaskTagList( &*NameStr, NULL ) )
- {
- switch( EasyRequest(NULL,&es,NULL,NULL) )
- {
- case 0: /*** CANCEL ***/
- break;
- case 1: /*** SAVE ***/
- SavePrefs( &BPrefs, SwazBlankerBase->SaveFileName );
- SavePrefs( &BPrefs, SwazBlankerBase->UseFileName );
- break;
- case 2: /*** USE ONLY ***/
- SavePrefs( &BPrefs, SwazBlankerBase->UseFileName );
- break;
- }
- SB_RemPrefsTask( bpn );
- }
-
- }
-
-
-
- /*
- ** To do help simply:
- **
- APTR SBHelp=NULL;
-
- SBHelp = SB_HelpTags(
- &*Name, NULL,
- SBHELP_BlankerPrefs, bpn,
- SBHELP_Directory, TRUE,
- TAG_DONE);
- .
- .
- .
-
- SB_HelpClose( SBHelp );
-
- */
-
- /****** exampleblanker/Blank() ***********************************
- *
- * SYNTAX
- * Blank()
- *
- * FUNCTION
- * This is the actual blanker routine.
- *
- *****************************************************************/
- void Blank(void)
- {
- struct Screen *screen;
- struct Window *window;
- WORD CSpec[] = { 0,0,0,0, -1 };
-
- screen = SB_OpenScreenTags(
- SA_DisplayID, 0,
- SA_Depth, 1,
- SA_Colors, &CSpec,
- TAG_DONE);
-
- if(screen)
- {
- window = SB_OpenWindowTags(
- WA_CustomScreen,screen,
- TAG_DONE);
-
- if(window)
- {
- SB_SetBlankerScreen( screen, window ); /* Set the blankers screen and window */
- SB_BlankerReady(); /* Tell SwazBlanker we are working */
-
- Wait(SIGBREAKF_CTRL_C); /* Wait for abort signal */
-
- SB_ClrBlankerScreen( screen, window ); /* Restore old screen */
- CloseWindow(window);
- }
- CloseScreen(screen);
- }
- }
-
- /****************************************************************
-
- Please examine this startup code carefully, it has changed from
- prior version of the Example.c blanker source code. Please check
- the SBInit->Method when your module is invoked.
-
- If you choose to use swazconfig.library you may wish to share the
- same config file as specified by:
-
- SwazBlankerBase->UseFileName = env:matrix/SwazBlanker.conf
-
- and SwazBlankerBase->SaveFileName = envarc:matrix/SwazBlanker.conf
-
- Use your module name for the name of your data section.
-
- ***************************************************************/
- void main (int argc, char **argv)
- {
- if( SwazBlankerBase = (struct SwazBlankerBase *) OpenLibrary( "swazblanker.library", 42 ) )
- {
- if( SwazConfigBase = (struct SwazConfigBase *) OpenLibrary( "swazconfig.library", 1 ) )
- {
- if( SBInit = SB_InitTags( SBINIT_Name,"Example", TAG_DONE ) )
- {
- switch( SBInit->Method )
- {
- case SBINIT_METHOD_BLANK: /* We need to blank the screen */
- LoadPrefs( &BPrefs, SwazBlankerBase->UseFileName );
- Blank();
- break;
- case SBINIT_METHOD_PREFS: /* Need to invoke the preferences editor */
- Prefs();
- break;
- case SBINIT_METHOD_INFO:
- SB_PrintInfoTags( SBInit,
- SBINFO_Author, "Authors Name (Nick)",
- SBINFO_EMail, "Author@somesite.amiga.com",
- SBINFO_ShortDesc, "Very short description",
- SBINFO_LongDesc, "Long multi line description",
- SBINFO_Version, VERSION,
- SBINFO_Revision, REVISION,
- // SBINFO_Time, &TimeStr[6],
- SBINFO_CPULoading, SBINFOLOAD_MEDIUM,
- TAG_DONE );
- }
- SB_FreeInit( SBInit );
- }
- CloseLibrary( (struct Library *) SwazBlankerBase );
- }
- CloseLibrary( (struct Library *) SwazConfigBase );
- }
- }
-