7:c:{Oûÿ0:c%:¡Àrem *** Event Core OPL Skeleton for ER6 92x0 Apps )rem *** By Ewan Spence and FreEPOC. Please email the )rem *** author if you release an app using this Event Core@©©rem APP "Master",Your UID Here©rem ICON "D:\Programming\Master\Icon.mbm"©rem ENDA©©rem *** Remove the REM from the above three lines, add in your©rem *** UID (email uid@symbian.com to obtain one" in HEX format©rem *** and point the filename to your mbm icon file. This will©rem *** make your translated code appear in Extras as an APP©rem *** rather than an .OPO in the OPL directory.©©INCLUDE "AppFrame.oxh"©INCLUDE "System.oxh"©INCLUDE "Const.oph"©INCLUDE "SendAs.oxh"©©CONST KCBAButton_1%=1©CONST KCBAButton_2%=2©CONST KCBAButton_3%=3©CONST KCBAButton_4%=4©CONST KFreeKeyAddToDesk%=1©CONST KFreeKeyToggleIrDA%=2©CONST KToggleIrDAKey%=154©©rem *** Change the following constants to reflect your details©CONST K_Author_Email$="ewan@freepoc.org"©CONST K_Author_Name$="Ewan Spence"©CONST K_App_Name$="Master"©CONST k_App_Ver$="0.01"©©PROC main:© GLOBAL id%(16),dia%© GLOBAL path$(255),data$(255),drive$(2),gfx$(16)© GLOBAL breakout%,MenuPos%© GLOBAL swidth%,sheight%,mwidth%,mheight%© GLOBAL AfCBA%, AfStatusType%,AfStatusOn%,AfTitleOn%© GLOBAL evStat%,ev&(16),AfCBADefaultButton%© GLOBAL SaCascs$(KMaxSendAsTypes%,KMaxSendAsCaptionLen%)© GLOBAL SaKeys&(KMaxSendAsTypes%),SaMaxTypes&,SaNextFreeKey&© GLOBAL sound_vol%© GLOBAL solution%(4),skill_level%,guess%(4),turn%© GLOBAL cursor%,old_cursor%© © rem *** Insert your GLOBAL variables here© © init:© Init_SetupSendAsKeysAndMenu:© init_app:© breakout%=0© DO© g_event_loop:© UNTIL breakout%<>0© breakout%=0© exit:©ENDP©©PROC init:© LOCAL first%©rem *** SetFlag allows machine to auto switch off. Do not alter this© SetFlags &10000© giPRINT K_App_Name$+", "+K_Author_Name$+" 2002, ver "+K_App_Ver$©©rem *** Set paths to relevant files by checking for .mbm file© gfx$="master.mbm" : data$="\system\apps\master\"© IF EXIST("c:"+data$+gfx$)© path$="c:"+data$© ELSEIF EXIST ("d:"+data$+gfx$)© path$="d:"+data$© ELSE© ALERT ("Support mbm files not found","Please Re-Install "+K_App_Name$+".")© STOP© ENDIF©rem *** INI File Handling, if this is first time app is run (ie no .ini file)©rem *** the first%=1, otherwise first%=0© first%=LoadINIFile:©rem *** Screen dimensions, fixed across all devices© gSETWIN 92,0,640,200© swidth%=640 : sheight%=200© mwidth%=640-92 : mheight%=200 : rem With Left Status Bar© MenuPos%=AfMenuPaneToStartShowing%:©rem *** Set up Command Buttons© AfSetCBAButton:(KCBAButton_1%,"Guess",0,0,"g_HandleCBA")© AfSetCBAButton:(KCBAButton_2%,"Stats",0,0,"g_HandleCBA")© AfSetCBAButton:(KCBAButton_3%,"Prefs",0,0,"g_HandleCBA")© AfSetCBAButton:(KCBAButton_4%,"Close",0,0,"g_HandleCBA")© AfSetTitle:(K_App_Name$,KAfTitleTypeMainTitle%)©rem *** Draw AppFrame (all the toolbars and titles) as Required© AfSetStatus%:(AfStatusType%)© AfSetCBAVisible%:(AfCBA%)© AfSetStatusVisible%:(AfStatusOn%)© AfSetTitleVisible%:(AfTitleOn%)©rem *** Create Initial Graphical Windows ©rem *** 1 = fullscreen window (with large toolbar and title)© id%(1)=gCREATE(92,0,mwidth%,mheight%,0,KDefaultWin256ColorMode%)©rem *** Load Initial Graphics© id%(9)=gLOADBIT(path$+gfx$,0,5) : rem 05 Background Image© id%(10)=gLOADBIT(path$+gfx$,0,2) : rem 05 Balls© id%(11)=gLOADBIT(path$+gfx$,0,4) : rem 04 Cursor© id%(12)=gCREATEBIT(37,37,KDefaultWin256ColorMode%) : rem Background©rem *** Show splash screen if required in your application© rem show_splash:©rem *** First time app is run, Return a 1, else Return a 0© RETURN first%©ENDP©©PROC LoadINIFile:© ONERR replace::© IF EXIST ("c:"+data$+"Core.ini")© OPEN "c:"+data$+"Core.ini",A,sound_vol%,statustype%,cba%,statuson%,titleon%,skill_level%© sound_vol%=A.sound_vol%© AfStatusType%=A.StatusType%© AfCBA%=A.cba%© AfStatusOn%=A.statuson%© AfTitleOn%=A.titleon%© skill_level%=A.skill_level%© CLOSE© RETURN 0© ELSE© rem *** Set initial values here© rem *** Note we set CBA, Title and Toolbars here© sound_vol%=3© AfStatusType%=0© AfCBA%=1© AfStatusOn%=1© AfTitleOn%=0© skill_level%=1© SaveINIFile:© RETURN 1© ENDIF© replace::© ONERR off© TRAP DELETE "c:"+data$+"Core.ini"© LoadINIFile: ©ENDP©©PROC SaveINIFile:© TRAP MKDIR "c:"+data$© TRAP DELETE "c:"+data$+"Core.ini"© CREATE "c:"+data$+"Core.ini",A,sound_vol%,statustype%,cba%,statuson%,titleon%,skill_level%© A.sound_vol%=sound_vol%© A.statustype%=AfStatusType%© A.cba%=AfCBA%© A.statuson%=AfStatusOn%© A.titleon%=AfTitleOn%© A.skill_level%=skill_level%© APPEND© CLOSE©ENDP©©©PROC init_app:© LOCAL foo%© rem *** Set variables© turn%=0© cursor%=1 : old_cursor%=1© foo%=0© DO© foo%=foo%+1© solution%(foo%)=INT(RND*(2+(skill_level%*2)))+1© guess%(foo%)=0© UNTIL foo%=4© init_display:©©ENDP©©©©PROC init_display:© LOCAL foo%©rem *** Copy the background into the main window.© gUSE id%(1)© gAT 0,0© gCOPY id%(9),0,0,548,200,3©rem *** Draw the squares of the grid using supplied bitmap© foo%=-1© DO© foo%=foo%+1© m_showball:(foo%,1,0)© m_showball:(foo%,2,0)© m_showball:(foo%,3,0)© m_showball:(foo%,4,0)© m_showguess:(0,0,foo%)© UNTIL foo%=9©rem *** Draw the outside of the grid and the solution boxes© gAT 5,5 : gBOX 360,145 : gAT 5,157 : gBOX 360,37© gAT 398,5 : gBOX 37,145© gAT 398,41 : gLINEBY 36,0© gAT 398,77 : gLINEBY 36,0© gAT 398,113 : gLINEBY 36,0© gAT 398,157 : gBOX 37,37© gVISIBLE ON©ENDP©©PROC Init_SetupSendAsKeysAndMenu:© LOCAL foo%© SaScanSendAsTypes:© SaMaxTypes&=SaMaximumTypes&:© SaNextFreeKey&=SaNextAvailableHotkey&:© IF SaNextFreeKey&=KSendAsHotKeyStart&© SaNextFreekey&=0© ENDIF© foo%=1© WHILE foo%<=SaMaxTypes&© IF SaCapabilitySupported%:(foo%,KCapabilityBodyText&)© SaCascs$(foo%)=SaCascName$:(foo%)© SaKeys&(foo%)=SaHotKeyValue&:(foo%)© ELSE© SaCascs$(foo%)=""© SaKeys&(foo%)=0© ENDIF© foo%=foo%+1© ENDWH©ENDP©©PROC g_event_loop:© LOCAL c$(255),AfOffered%©rem *** The Main Loop, we stay looping round here© DO©rem *** Get the event (ie whatever has happened)© GETEVENT32 ev&()©rem *** Check Messages from the System© c$=GETCMD$© IF LEFT$(c$,1)=KGetCmdLetterExit$ : Exit:© ELSEIF LEFT$(c$,1)=KGetCmdLetterBackup$ : Exit:© ELSEIF LEFT$(c$,1)=KGetCmdLetterBroughtToFGround$ : rem Brought To Focus© ENDIF© © AfOffered%=AfOfferEvent%:(ev&(1),ev&(3),ev&(4),ev&(5),ev&(6),ev&(7))© IF AfOffered%=0© rem *** Process Event© IF (ev&(KEvAType%)<>KEvKeyDown& AND ev&(KEvAType%)<>KEvKeyUp&)© g_kbddrv:(ev&(KEvAType%),ev&(KEvAKMod%),ev&(KEvAScan%))© ENDIF© ENDIF© UNTIL breakout%<>0©ENDP©©PROC g_kbddrv:(aKey&,aMod&,aScanCode&)© LOCAL Key&,Mod&,CapsLock%,Shift%,Ctrl%,Fn%,AllMods&© LOCAL CtrlShiftMod&,CtrlShiftFnMod&,CtrlFnMod&,ShiftFnMod&©rem *** Calculate modifiers (shift keys, etc)© AllMods&=KKmodShift% OR KKModControl% OR KKModFn%© CtrlShiftMod&=KKModControl% OR KKModShift%© CtrlShiftFnMod&=CtrlShiftMod& OR KKModFn%© ShiftFnMod&=KKModShift% OR KKModFn%© CtrlShiftMod&=KKModControl% OR KKModShift%© CapsLock%=KFalse% : Shift%=KFalse% : Ctrl%=KFalse% : Fn%=KFalse%© Key&=aKey& : Mod&=aMod& ©rem *** Check Caps Lock© IF (aMod&>=KKModCaps% AND aMod&=KKModCaps%+KKModFn% AND aMod&AllMods&)© Mod&=0© ENDIF©rem *** Examine Modifiers© IF (Mod&-KKModFn%)>=0 : Fn%=KTrue% : Mod&=Mod&-KKModFn% : ENDIF© IF (Mod&-KKModControl%)>=0 : Ctrl%=KTrue% : Mod&=Mod&-KKModControl% : ENDIF© IF (Mod&-KKModShift%)>=0 : Shift%=KTrue% : Mod&=Mod&-KKModShift% : ENDIF©rem *** Handle System Keys© IF (Key&=KKeyMenu32&) OR (Key&=KKeySidebarMenu32&)© Key&=g_menu&:© IF (Key&>=ASC("A")) AND (Key&<=ASC("Z"))© Key&=Key&-(ASC("A")-1) : Ctrl%=KTrue% : Shift%=KTrue%© ELSE© Key&=Key&-(ASC("a")-1) : Ctrl%=KTrue% : Shift%=KFalse%© ENDIF© ELSEIF Key&=KKeyHelp32&© giPRINT "Show Help File"© rem SHOWHELP© RETURN© ENDIF©rem *** Modify amd create %? key value© Mod&=0© IF shift% : Mod&=Mod&+KKModShift% : ENDIF© IF ctrl% : Mod&=Mod&+KKModControl% : ENDIF© IF fn% : Mod&=Mod&+KKModFn% : ENDIF© Key&=Key&+ASC("a")-1© IF Mod&=CtrlShiftMod&© Key&=Key&-(ASC("a")-ASC("A"))© ENDIF©rem *** Letter Handler© IF Mod&=0 AND (aScanCode&=KScanEnter%)© rem *** Enter... the default CBA button© rem g_HandleCBA:(AfCBADefaultButton%)© ELSEIF mod&=0 AND (aScanCode&=KScanTab% OR aScanCode&=KScanDel%)© rem *** Bug in OPL, this Prevents Tab/Delete acting as Ctrl-i/-h© RETURN© ELSEIF (Key&=KToggleIrDAKey% AND Fn%=KTrue% AND (Ctrl%=KFalse% AND Shift%=KFalse%)) OR (Key&=SaNextFreeKey&+KFreeKeyToggleIrDA%)© AfToggleIrDA:© RETURN© ELSEIF Fn%©rem *** Ignore any other Fn Keys© RETURN© ELSEIF Key&=SaNextFreeKey&+KFreeKeyAddToDesk%© AfAddToDesk:©rem *** Letter Key (app dependent) from here onwards© ELSEIF Key&=%k : g_prefs:© ELSEIF Key&=%A : g_about:© ELSEIF Key&=%L : afLaunchSystemLog:© ELSEIF Key&=%e : exit:© ENDIF©ENDP©©PROC g_menu&:© LOCAL foo&© mINIT© mCARD "File","Add to Desk",(SaNextFreeKey&+KFreeKeyAddToDesk%)© mCARD "Tools","Preferences...",%k,"About Master...",-%A,"Log",%L,"Receive via infrared",SaNextFreeKey&+KFreeKeyToggleIrDA%© foo&=MENU(MenuPos%)© RETURN foo&©ENDP©©PROC g_HandleCBA:(button&)© rem *** Jump to relevant procedure after CBA button pressed© rem *** Here a giPRINT confirms the button. Edit as needed© IF button&=KCBAButton_1%© giPRINT "Make a Guess"© ELSEIF button&=KCBAButton_2%© giPRINT "View Statistics"© ELSEIF button&=KCBAButton_3%© g_prefs:© ELSEIF button&=KCBAButton_4%© rem *** Cannot call the EXIT: procedure here, so set the© rem *** exit flag and do it in the loop as soon as possible© breakout%=1© ENDIF©ENDP©©©PROC g_about:© LOCAL foo_s%,foo_e&(16)© rem *** LOCK ON means program cannot be told to exit© rem *** by the system.© LOCK ON© id%(16)=gLOADBIT(path$+gfx$,0,1) : rem 01 App Icon© id%(8)=gCREATE(INT(swidth%-310)/2,(INT(sheight%-150)/2)+(15*AfTitleOn%),310,150,0,$411)© gXBORDER 2,$94© rem *** gCOPY your ICON from the mbm file in place of gBOX© gAT 123,18 : gCOPY id%(16),0,0,65,51,3© gFONT 10 : gSTYLE 1 : gAT 5,13© gPRINTB "FreEPOC Presents...",300,3© gFONT 12 : gSTYLE 1 : gAT 5,87© gPRINTB K_App_Name$,300,3© gFONT 10 : gSTYLE 1 : gAT 5,104© gPRINTB "Version "+K_App_Ver$+", © "+K_Author_Name$+", 2002",300,3© gAT 10,110 : gLINEBY 290,0© gFONT 10 : gSTYLE 0 : gAT 5,126© gPRINTB "Any comments? Mail them to",300,3© gFONT 10 : gSTYLE 0 : gAT 5,141© gPRINTB K_Author_Email$,300,3© gVISIBLE ON© rem *** Simple Event Loop that waits for a key but does© rem *** NOT check for system messages.© DO© GETEVENTA32 foo_s%,foo_e&()© GETEVENTC (foo_s%)© PAUSE 2© UNTIL foo_e&(1)=$408 OR foo_e&(1)=$406© PAUSE 0© rem *** Unlock the code so we can recieve System messages again© LOCK OFF© rem *** Close the About box graphical window.© gCLOSE id%(8)©ENDP©©PROC g_prefs:© rem *** Sound play back still not iplemented in ER6 OPL, so© rem *** edit this dialog as needed. Don't foget to alter the © rem *** LOADINIFILE: and SAVEINIFILE: procedures with the© rem *** values you change in Preferences.© sound_vol%=sound_vol%+1© dINIT "Preferences"© dCHOICE skill_level%,"Skill Level","Easy,Medium,Hard"©rem dCHOICE sound_vol%,"Sound Volume","Off,Quiet,Medium,Loud"© dBUTTONS "Close",KdBUTTONEnter%© LOCK ON : DIALOG : LOCK OFF© sound_vol%=sound_vol%-1©ENDP©©PROC m_showball:(foo_turn%,pos%,ball%)© rem *** This procedure prints a ball into the corect grid squae© rem *** using the TURN, POSition and ball numebr passed© gAT (foo_turn%*36)+5,((pos%-1)*36)+5© IF ball%=0© rem *** Special case, if we want to pront an empty square© gCOPY id%(9),(foo_turn%*36)+5,((pos%-1)*36)+5,36,36,0 : rem Background portion© gCOPY id%(10),0,0,36,36,0 © ELSE© gCOPY id%(10),36,0,36,36,1 : rem MASK© gCOPY id%(10),(ball%+1)*36,0,36,36,0 : rem BALL© ENDIF©ENDP©©PROC m_showguess:(right_place%,wrong_place%,foo_turn%)© rem *** Similar to the m_showball;, this works out and© rem *** displays the right and wroonmg guesses© © rem *** This will be completed in the next tutorial, for now© rem *** only the empty square is drawn© © gAT (foo_turn%*36)+5,152+5© IF right_place%=0 AND wrong_place%=0© rem Empty Square© gCOPY id%(9),(foo_turn%*36)+5,152+5,36,36,0 : rem Background portion© gCOPY id%(10),0,0,36,36,0 © ENDIF©ENDP©©©PROC exit:© LOCAL foo%© ONERR JustStop::© SaveINIFile:© rem *** Close all windows as a safety precautions© foo%=0© DO© foo%=foo%+1© IF id%(foo%) : gCLOSE id%(foo%)© ENDIF© UNTIL foo%=16© JustStop::© ONERR OFF© STOP©ENDP©ÐР   :cU0:f%: ):c]0:f%: ) ‚.ÆAc:(TextEd.appc:e04:ð0