home *** CD-ROM | disk | FTP | other *** search
EPOC OPL Source | 1998-08-12 | 12.2 KB | 471 lines |
-
-
- APP Cat, 268437309 REM Reserved uid. Do not use for other apps
- CAPTION "Cat", 1
- ICON "CatIcon.mbm"
- ENDA
-
- REM Cat.opl Released as public domain January 1998
- REM Feel free to use any routines in this file.
-
- REM VARIABLE NAMING CONVENTION.
- REM Constants are prefixed with K
- REM Global variables are prefixed with G
- REM Recived procedure parameters are prefixed with P
- REM All other variables are local
-
- REM Cat.mbm contains 28 bitmaps. Each one is loaded in turn to
- REM create an animation.
-
- INCLUDE "CONST.OPH"
-
- CONST KMenuKeyPressed% = 148
- CONST KCloseApp% = -1
-
- CONST Kx = 25 REM Top left position of cat window
- CONST Ky = 80
-
- CONST KCatSpeed = 2 REM Lower value for faster cat. Do not set to zero. Default 2
-
- DECLARE EXTERNAL
- EXTERNAL GetFileNameAndExtension$:(PFileName$)
- EXTERNAL GetNumberOfBitmapsInMbm&:(MbmName$)
- EXTERNAL GetBitmapWidth&:(PMbmName$, PBitmapNumber%)
- EXTERNAL GetBitmapHeight&:(PMbmName$, PBitmapNumber%)
- EXTERNAL HideDefaultWindow:
- EXTERNAL CreateCatWindow%:(Px%, Py%, PWidth&, PHeight&)
- EXTERNAL ShowBitmap:(FileName$, BitmapIndex%, WindowId%, X%, Y%)
- EXTERNAL CheckForEvent:
- EXTERNAL ClearKeyboardBuffer:
- EXTERNAL ShowMenu:
- EXTERNAL GetAppPath$:
- EXTERNAL ReportFileMissingToUser:(PFileName$, PAdvise1$, PAdvise2$, PAdvise3$)
- EXTERNAL ReportErrorToUser:(DialogTitle$, PErrorCode&)
- EXTERNAL About:
- EXTERNAL ExitProgram:
-
-
- PROC Main:
- LOCAL MbmName$(255)
-
- LOCAL CatWindow%
-
- LOCAL BitmapIndex%
- LOCAL NumberOfBitmapsInFile&
- LOCAL BitmapWidth&
- LOCAL BitmapHeight&
-
- MbmName$ = GetAppPath$: + "Cat.mbm"
-
- rem--------------------------------------
- REM This section gets details about cat.mbm
- rem--------------------------------------
-
- IF NOT EXIST(MbmName$)
- ReportFileMissingToUser:(GetFileNameAndExtension$:(MbmName$), "Place Cat.app and Cat.mbm", "in the same folder", "")
- ExitProgram:
- ENDIF
-
- BitmapIndex% = 1
-
- NumberOfBitmapsInFile& = GetNumberOfBitmapsInMbm&:(MbmName$)
-
- IF NumberOfBitmapsInFile& < 0
- ReportErrorToUser:("Error opening cat.mbm", NumberOfBitmapsInFile&)
- ExitProgram:
- ENDIF
-
- BitmapWidth& = GetBitmapWidth&:(MbmName$, BitmapIndex%)
-
- BitmapHeight& = GetBitmapHeight&:(MbmName$, BitmapIndex%)
-
- rem--------------------------------------
- REM This section sets up the screen
- rem--------------------------------------
-
- HideDefaultWindow:
-
- CatWindow% = CreateCatWindow%:(Kx, Ky, BitmapWidth&, BitmapHeight&)
-
- WHILE 1
-
- rem--------------------------------------
- REM Start with first bitmap in file
- rem--------------------------------------
-
- BitmapIndex% = 1
-
- WHILE BitmapIndex% < NumberOfBitmapsInFile&
-
- rem--------------------------------------
- REM This procedure checks for system
- REM messages and key presses
- rem--------------------------------------
-
- CheckForEvent:
-
- rem--------------------------------------
- REM This section displays the next bitmap
- rem--------------------------------------
-
- ShowBitmap:(GetAppPath$: + "Cat.mbm", BitmapIndex%, CatWindow%, 0, 0)
-
- BitmapIndex% = BitmapIndex% + 1
-
- rem--------------------------------------
- REM Increase or decrease PAUSE to adjust speed
- rem--------------------------------------
-
- PAUSE KCatSpeed
-
- ENDWH
- ENDWH
- ENDP
-
- rem--------------------------------------
- REM This function returns a filename and extension
- REM from a full file path specification
- REM Called from Main:
- rem--------------------------------------
- PROC GetFileNameAndExtension$:(PFileName$)
- LOCAL Off%(6)
- LOCAL FileName$(33)
- LOCAL Extension$(4)
-
- FileName$ = MID$(PARSE$(PFileName$, PFileName$, Off%()), Off%(4), Off%(5) - Off%(4))
- Extension$ = MID$(PARSE$(PFileName$, PFileName$, Off%()), Off%(5), 4)
-
- RETURN FileName$ + Extension$
- ENDP
-
-
- rem--------------------------------------
- REM returns the number of bitmaps in an mbm PMbmName$
- REM or < 0 = error number
- REM Called from Main:
- rem--------------------------------------
- PROC GetNumberOfBitmapsInMbm&:(PMbmName$)
- LOCAL FileHandle%
- LOCAL CheckForError&
- LOCAL OffsetToInfoTable&
- LOCAL OffsetOfInfoTable&
- LOCAL NumberOfBitmaps&
-
- CheckForError& = IOOPEN(FileHandle%, PMbmName$, $0600)
-
- rem--------------------------------------
- REM Error opening file
- rem--------------------------------------
- IF CheckForError&
- IOCLOSE(FileHandle%)
- RETURN CheckForError&
- ENDIF
-
- OffsetToInfoTable& = 16
-
- IOSEEK(FileHandle%, 1, OffsetToInfoTable&)
- IOREAD(FileHandle%, ADDR(OffsetOfInfoTable&), 4)
- IOSEEK(FileHandle%, 1, OffsetOfInfoTable&)
- IOREAD(FileHandle%, ADDR(NumberOfBitmaps&), 4)
- IOCLOSE(FileHandle%)
-
- RETURN NumberOfBitmaps&
- ENDP
-
-
- rem--------------------------------------
- REM Returns the width of bitmap number
- REM PBitmapNumber% in an mbm file PMbmName$
- REM Called from Main:
- rem--------------------------------------
- PROC GetBitmapWidth&:(PMbmName$, PBitmapNumber%)
- LOCAL CheckForError&
- LOCAL FileHandle%
-
- LOCAL OffsetOfPointerToInfoTable&
- LOCAL OffsetOfInfoTable&
- LOCAL OffsetOfPointerToBitmapRecord&
- LOCAL OffsetOfBitmapRecord&
-
- LOCAL NumberOfBitmaps&
- LOCAL BitmapWidth&
-
- CheckForError& = IOOPEN(FileHandle%, PMbmName$, $0600)
-
- rem--------------------------------------
- REM Error opening file
- rem--------------------------------------
- IF CheckForError&
- IOCLOSE(FileHandle%)
- RETURN CheckForError&
- ENDIF
-
- rem--------------------------------------
- REM This section checks that PBitmapNumber%
- REM is not greater than the number of bitmaps
- REM in the file
- rem--------------------------------------
-
- OffsetOfPointerToInfoTable& = 16
-
- IOSEEK(FileHandle%, 1, OffsetOfPointerToInfoTable&)
- IOREAD(FileHandle%, ADDR(OffsetOfInfoTable&), 4)
- IOSEEK(FileHandle%, 1, OffsetOfInfoTable&)
- IOREAD(FileHandle%, ADDR(NumberOfBitmaps&), 4)
-
- rem--------------------------------------
- REM Return code for general failure
- REM if bitmaps less than PBitmapNumber%
- rem--------------------------------------
- IF NumberOfBitmaps& < PBitmapNumber%
- RETURN -1
- ENDIF
-
- rem--------------------------------------
- REM This section returns the width
- REM of bitmap number PBitmapNumber%
- rem--------------------------------------
-
- OffsetOfPointerToBitmapRecord& = OffsetOfInfoTable& + (PBitmapNumber% * 4)
- IOSEEK(FileHandle%, 1, OffsetOfPointerToBitmapRecord&)
- IOREAD(FileHandle%, ADDR(OffsetOfBitmapRecord&), 4)
- OffsetOfBitmapRecord& = OffsetOfBitmapRecord& + 8
- IOSEEK(FileHandle%, 1, OffsetOfBitmapRecord&)
- IOREAD(FileHandle%, ADDR(BitmapWidth&), 4)
- IOCLOSE(FileHandle%)
-
- RETURN BitmapWidth&
- ENDP
-
-
- rem--------------------------------------
- REM Returns the height of bitmap number
- REM PBitmapNumber% in an mbm file PMbmName$
- REM Called from Main:
- rem--------------------------------------
- PROC GetBitmapHeight&:(PMbmName$, PBitmapNumber%)
- LOCAL CheckForError&
- LOCAL FileHandle%
-
- LOCAL OffsetOfPointerToInfoTable&
- LOCAL OffsetOfInfoTable&
- LOCAL OffsetOfPointerToBitmapRecord&
- LOCAL OffsetOfBitmapRecord&
-
- LOCAL NumberOfBitmaps&
- LOCAL BitmapHeight&
-
- CheckForError& = IOOPEN(FileHandle%, PMbmName$, $0600)
-
- rem--------------------------------------
- REM Error opening file
- rem--------------------------------------
- IF CheckForError&
- IOCLOSE(FileHandle%)
- RETURN CheckForError&
- ENDIF
-
- rem--------------------------------------
- REM This section checks that PBitmapNumber%
- REM is not greater than the number of bitmaps
- REM in the file
- rem--------------------------------------
-
- OffsetOfPointerToInfoTable& = 16
-
- IOSEEK(FileHandle%, 1, OffsetOfPointerToInfoTable&)
- IOREAD(FileHandle%, ADDR(OffsetOfInfoTable&), 4)
- IOSEEK(FileHandle%, 1, OffsetOfInfoTable&)
- IOREAD(FileHandle%, ADDR(NumberOfBitmaps&), 4)
-
- rem--------------------------------------
- REM Return code for general failure
- REM if bitmaps less than PBitmapNumber%
- rem--------------------------------------
- IF NumberOfBitmaps& < PBitmapNumber%
- RETURN -1
- ENDIF
-
- rem--------------------------------------
- REM This section returns the height
- REM of bitmap number PBitmapNumber%
- rem--------------------------------------
-
- OffsetOfPointerToBitmapRecord& = OffsetOfInfoTable& + (PBitmapNumber% * 4)
- IOSEEK(FileHandle%, 1, OffsetOfPointerToBitmapRecord&)
- IOREAD(FileHandle%, ADDR(OffsetOfBitmapRecord&), 4)
- OffsetOfBitmapRecord& = OffsetOfBitmapRecord& + 12
- IOSEEK(FileHandle%, 1, OffsetOfBitmapRecord&)
- IOREAD(FileHandle%, ADDR(BitmapHeight&), 4)
- IOCLOSE(FileHandle%)
-
- RETURN BitmapHeight&
- ENDP
-
-
- rem--------------------------------------
- REM Called from Main:
- rem--------------------------------------
- PROC HideDefaultWindow:
- gUSE 1
- gSETWIN 0, 0, 0, 0
- rem gVISIBLE OFF
- ENDP
-
-
- rem--------------------------------------
- REM Called from Main:
- rem--------------------------------------
- PROC CreateCatWindow%:(Px%, Py%, PWidth&, PHeight&)
- LOCAL CatWindow%
- CatWindow% = gCREATE(Px%, Py%, PWidth&, PHeight&, KgCreateVisible%, KgCreate4ColourMode%)
- RETURN CatWindow%
- ENDP
-
-
- rem--------------------------------------
- REM loads an MBM PFileName$ into window PWindowId%
- REM Bitmap number PBitmapIndex% at PX%, PY%
- REM Replacing any bitmap already there
- REM Called from Main:
- rem--------------------------------------
- PROC ShowBitmap:(PFileName$, PBitmapIndex%, PWindowId%, PX%, PY%)
- LOCAL BitmapId%
- LOCAL BitmapWidth%
- LOCAL BitmapHeight%
-
- BitmapId% = gLOADBIT(PFileName$, KgLoadBitReadOnly%, PBitmapIndex%)
-
- BitmapWidth% = gWIDTH
- BitmapHeight% = gHEIGHT
-
- gUSE PWindowId%
-
- gAT PX%, PY%
- gCOPY BitmapId%, 0, 0, BitmapWidth%, BitmapHeight%, KtModeReplace%
-
- gCLOSE BitmapId%
- ENDP
-
-
- rem--------------------------------------
- REM This procedure checks whether a 'Close file'
- REM message has been received from the system
- REM or whether a key has been pressed
- REM Called from Main:
- rem--------------------------------------
- PROC CheckForEvent:
- LOCAL ev&(16)
- LOCAL Status%
-
- ClearKeyboardBuffer:
-
- GETEVENTA32 Status%, ev&()
- IF ev&(1) = KEvCommand&
- ExitProgram:
- ELSEIF (ev&(3) = 69) AND (ev&(4) = KKmodControl%)
- ExitProgram:
- ELSEIF (ev&(3) = 69) AND (ev&(4) = KKmodControl% + KKmodCaps%)
- ExitProgram:
- ELSEIF (ev&(3) = 65) AND (ev&(4) = KKmodControl%)
- About:
- ELSEIF (ev&(3) = 65) AND (ev&(4) = KKmodControl% + KKmodCaps%)
- About:
- ELSEIF ev&(3) = KMenuKeyPressed%
- ShowMenu:
- ENDIF
- ENDP
-
-
- rem--------------------------------------
- REM Need to call this procedure for
- REM GETEVENTA32 to work. Don't know why !
- REM Called from CheckForEvent%:
- rem--------------------------------------
- PROC ClearKeyboardBuffer:
- WHILE KEY
- ENDWH
- ENDP
-
-
- rem--------------------------------------
- REM Called from CheckForEvent:
- rem--------------------------------------
- PROC ShowMenu:
- LOCAL MenuItem%
- mINIT
- mCARD "Cat","About Cat",%a,"Close",%e
- MenuItem% = MENU
- IF MenuItem% = %a
- About:
- ELSEIF MenuItem% = %e
- ExitProgram:
- ENDIF
- ENDP
-
-
- rem--------------------------------------
- REM GetAppPath$: returns the path of
- REM the running application or opo
- REM Called from Main:
- rem--------------------------------------
- PROC GetAppPath$:
- LOCAL off%(6)
- RETURN LEFT$(PARSE$("",CMD$(1),off%()),off%(4) - 1)
- ENDP
-
-
- rem--------------------------------------
- REM Called from Main:
- rem--------------------------------------
- PROC ReportFileMissingToUser:(PFileName$, PAdvise1$, PAdvise2$, PAdvise3$)
- dINIT PFileName$ + " not found"
- dTEXT "",PAdvise1$
- dTEXT "",PAdvise2$
- dBUTTONS "Ok",13
- DIALOG
- ENDP
-
-
- rem--------------------------------------
- REM Called from Main:
- rem--------------------------------------
- PROC ReportErrorToUser:(DialogTitle$, PErrorCode&)
- dINIT DialogTitle$
- dTEXT "","The following error has occurred"
- dTEXT ""," "
- dTEXT "",ERR$(PErrorCode&)
- dTEXT ""," "
- dBUTTONS "Ok",13
- DIALOG
- ENDP
-
-
- rem--------------------------------------
- REM Called from ShowMenu:
- rem--------------------------------------
- PROC About:
- dINIT " About Cat V1.0"
- dTEXT ""," © Richard Wakelin 1998"
- dTEXT ""," Released as freeware"
- dTEXT ""," Email"
- dTEXT ""," rbenno@cix.compulink.co.uk."
- dTEXT "","106305,466@compuserve.com"
- dTEXT ""," Web"
- dTEXT "","http://ourworld/compuserve.com"
- dTEXT ""," /homepages/RWakelin"
- rem dBUTTONS "Ok",13
- DIALOG
- ENDP
-
-
- rem--------------------------------------
- REM Called from CheckForEvent%: and ShowMenu:
- rem--------------------------------------
- PROC ExitProgram:
- REM Place any clean up code here
- STOP
- ENDP
-
-
-