diff --git a/misc/symbian/ClassiCube.mmh b/misc/symbian/ClassiCube.mmh new file mode 100644 index 000000000..0c9c8fbd3 --- /dev/null +++ b/misc/symbian/ClassiCube.mmh @@ -0,0 +1,46 @@ +TARGETTYPE exe +UID 0x100039CE 0xE212A5C2 + +USERINCLUDE ../../src +USERINCLUDE ../../src/freetype + +LIBRARY euser.lib +LIBRARY apgrfx.lib +LIBRARY cone.lib +LIBRARY avkon.lib +LIBRARY fbscli.lib +LIBRARY ws32.lib +LIBRARY hal.lib +LIBRARY efsrv.lib +LIBRARY apparc.lib +LIBRARY eikcore.lib +LIBRARY eikdlg.lib +LIBRARY mediaclientaudiostream.lib + +LIBRARY libc.lib +LIBRARY libm.lib +LIBRARY libdl.lib +LIBRARY libpthread.lib + +STATICLIBRARY ClassiCube_bearssl.lib + +SOURCEPATH ../../src +SOURCE Animations.c Audio.c Audio_Null.c AxisLinesRenderer.c Bitmap.c Block.c BlockPhysics.c Builder.c Camera.c Chat.c Commands.c Deflate.c Drawer.c Drawer2D.c Entity.c EntityComponents.c EntityRenderers.c EnvRenderer.c Event.c ExtMath.c FancyLighting.c Formats.c Game.c GameVersion.c Generator.c Graphics_GL1.c Graphics_SoftGPU.c Gui.c HeldBlockRenderer.c Http_Worker.c Input.c InputHandler.c Inventory.c IsometricDrawer.c LBackend.c LScreens.c LWeb.c LWidgets.c Launcher.c Lighting.c Logger.c MapRenderer.c MenuOptions.c Menus.c Model.c Options.c PackedCol.c Particle.c Physics.c Picking.c Platform_Posix.c Protocol.c Queue.c Resources.c SSL.c Screens.c SelOutlineRenderer.c SelectionBox.c Server.c Stream.c String.c SystemFonts.c TexturePack.c TouchUI.c Utils.c Vectors.c Widgets.c World.c _autofit.c _cff.c _ftbase.c _ftbitmap.c _ftglyph.c _ftinit.c _ftsynth.c _psaux.c _pshinter.c _psmodule.c _sfnt.c _smooth.c _truetype.c _type1.c Vorbis.c Platform_Symbian.cpp Graphics_GL2.c Window_Symbian.cpp Audio_Symbian.cpp Certs.c + +SOURCEPATH . +START RESOURCE classicube.rss +HEADER +TARGETPATH \resource\apps +LANG SC +END + +START RESOURCE classicube_reg.rss +TARGETPATH \private\10003a3f\import\apps +END + +CAPABILITY NetworkServices ReadUserData UserEnvironment WriteUserData + +EPOCSTACKSIZE 0x14000 +EPOCHEAPSIZE 0x80000 0x4000000 + +#include "common.mmh" \ No newline at end of file diff --git a/misc/symbian/ClassiCube.pkg b/misc/symbian/ClassiCube.pkg index 33b3cc473..d2c1e7201 100644 --- a/misc/symbian/ClassiCube.pkg +++ b/misc/symbian/ClassiCube.pkg @@ -15,7 +15,7 @@ IF( version(0x20009a80, <, 1, 5, 0) ) AND NOT (EXISTS("Z:\sys\bin\libc.dll") OR ENDIF IF exists("z:\system\install\Series60v5.2.sis") ; Symbian^3 - "$(EPOCROOT)Epoc32\release\$(PLATFORM)\$(TARGET)\ClassiCube_sym3.exe" - "!:\sys\bin\ClassiCube.exe" + "$(EPOCROOT)Epoc32\release\$(PLATFORM)\$(TARGET)\ClassiCube.exe" - "!:\sys\bin\ClassiCube.exe" ELSE IF exists("z:\system\install\Series60v5.0.sis") ; Symbian 9.4 "$(EPOCROOT)Epoc32\release\$(PLATFORM)\$(TARGET)\ClassiCube_s60v5.exe" - "!:\sys\bin\ClassiCube.exe" diff --git a/misc/symbian/ClassiCube_common.mmh b/misc/symbian/ClassiCube_common.mmh deleted file mode 100644 index a042f396d..000000000 --- a/misc/symbian/ClassiCube_common.mmh +++ /dev/null @@ -1,59 +0,0 @@ -TARGETTYPE exe -UID 0x100039CE 0xE212A5C2 - -SYSTEMINCLUDE /epoc32 -SYSTEMINCLUDE /epoc32/include -SYSTEMINCLUDE /epoc32/include/mw -SYSTEMINCLUDE /epoc32/include/app -SYSTEMINCLUDE /epoc32/include/platform -SYSTEMINCLUDE /epoc32/include/platform/mw -SYSTEMINCLUDE /epoc32/include/platform/app -SYSTEMINCLUDE /epoc32/include/gles -SYSTEMINCLUDE /epoc32/include/stdapis -SYSTEMINCLUDE /epoc32/include/stdapis/sys -//SYSTEMINCLUDE /epoc32/include/libc - -USERINCLUDE ../../src -USERINCLUDE ../../src/freetype -USERINCLUDE ../../third_party/bearssl - -MACRO SYMBIAN_OE_POSIX_SIGNALS - -LIBRARY euser.lib -LIBRARY apgrfx.lib -LIBRARY cone.lib -LIBRARY avkon.lib -LIBRARY fbscli.lib -LIBRARY ws32.lib -LIBRARY hal.lib -LIBRARY mediaclientaudiostream.lib - -LIBRARY libc.lib -LIBRARY libm.lib -LIBRARY libdl.lib -LIBRARY libpthread.lib - -STATICLIBRARY libcrt0.lib - -#ifdef ARMCC -OPTION ARMCC -Otime --diag_suppress 1296 --diag_suppress 1293 --diag_suppress 66 -OPTION_REPLACE ARMCC --cpu 6 -OPTION_REPLACE ARMCC --fpu softvfp+vfpv2 --fpmode fast -OPTION_REPLACE ARMCC -O2 -O3 -#endif - -SOURCEPATH ../../src -SOURCE Animations.c Audio.c Audio_Null.c AxisLinesRenderer.c Bitmap.c Block.c BlockPhysics.c Builder.c Camera.c Certs.c Chat.c Commands.c Deflate.c Drawer.c Drawer2D.c Entity.c EntityComponents.c EntityRenderers.c EnvRenderer.c Event.c ExtMath.c FancyLighting.c Formats.c Game.c GameVersion.c Generator.c Graphics_GL1.c Graphics_SoftGPU.c Gui.c HeldBlockRenderer.c Http_Worker.c Input.c InputHandler.c Inventory.c IsometricDrawer.c LBackend.c LScreens.c LWeb.c LWidgets.c Launcher.c Lighting.c Logger.c MapRenderer.c MenuOptions.c Menus.c Model.c Options.c PackedCol.c Particle.c Physics.c Picking.c Platform_Posix.c Protocol.c Queue.c Resources.c SSL.c Screens.c SelOutlineRenderer.c SelectionBox.c Server.c Stream.c String.c SystemFonts.c TexturePack.c TouchUI.c Utils.c Vectors.c Widgets.c World.c _autofit.c _cff.c _ftbase.c _ftbitmap.c _ftglyph.c _ftinit.c _ftsynth.c _psaux.c _pshinter.c _psmodule.c _sfnt.c _smooth.c _truetype.c _type1.c Vorbis.c Platform_Symbian.cpp Graphics_GL2.c Window_Symbian.cpp Audio_Symbian.cpp - -SOURCEPATH ../../third_party/bearssl -SOURCE aes_big_cbcdec.c aes_big_cbcenc.c aes_big_ctr.c aes_big_ctrcbc.c aes_big_dec.c aes_big_enc.c aes_common.c aesctr_drbg.c aes_x86ni.c aes_x86ni_cbcdec.c aes_x86ni_cbcenc.c aes_x86ni_ctr.c aes_x86ni_ctrcbc.c asn1enc.c ccm.c ccopy.c chacha20_ct.c chacha20_sse2.c dec32be.c dec32le.c dec64be.c dec64le.c dig_oid.c dig_size.c ec_all_m31.c ec_c25519_i31.c ec_c25519_m31.c ec_c25519_m62.c ec_c25519_m64.c ec_curve25519.c ec_default.c ecdsa_atr.c ecdsa_default_vrfy_asn1.c ecdsa_default_vrfy_raw.c ecdsa_i31_bits.c ecdsa_i31_vrfy_asn1.c ecdsa_i31_vrfy_raw.c ec_p256_m31.c ec_p256_m62.c ec_p256_m64.c ec_prime_i31.c ec_secp256r1.c ec_secp384r1.c ec_secp521r1.c enc32be.c enc32le.c enc64be.c enc64le.c gcm.c ghash_ctmul64.c ghash_ctmul.c ghash_pclmul.c hmac.c hmac_ct.c hmac_drbg.c i31_add.c i31_bitlen.c i31_decmod.c i31_decode.c i31_decred.c i31_encode.c i31_fmont.c i31_iszero.c i31_moddiv.c i31_modpow2.c i31_modpow.c i31_montmul.c i31_mulacc.c i31_muladd.c i31_ninv31.c i31_reduce.c i31_rshift.c i31_sub.c i31_tmont.c i32_div32.c i62_modpow2.c md5.c md5sha1.c multihash.c poly1305_ctmul.c poly1305_ctmulq.c prf.c prf_md5sha1.c prf_sha256.c prf_sha384.c rsa_default_pkcs1_vrfy.c rsa_default_priv.c rsa_default_pub.c rsa_i31_pkcs1_vrfy.c rsa_i31_priv.c rsa_i31_pub.c rsa_i62_pkcs1_vrfy.c rsa_i62_priv.c rsa_i62_pub.c rsa_pkcs1_sig_unpad.c sha1.c sha2big.c sha2small.c ssl_client.c ssl_client_default_rsapub.c ssl_client_full.c ssl_engine.c ssl_engine_default_aescbc.c ssl_engine_default_aesccm.c ssl_engine_default_aesgcm.c ssl_engine_default_chapol.c ssl_engine_default_ec.c ssl_engine_default_ecdsa.c ssl_engine_default_rsavrfy.c ssl_hashes.c ssl_hs_client.c ssl_io.c ssl_rec_cbc.c ssl_rec_ccm.c ssl_rec_chapol.c ssl_rec_gcm.c x509_minimal.c x509_minimal_full.c - -CAPABILITY NetworkServices ReadUserData UserEnvironment WriteUserData - -EPOCSTACKSIZE 0x14000 -EPOCHEAPSIZE 0x80000 0x4000000 - -#ifdef _DEBUG -DEBUGGABLE_UDEBONLY -SRCDBG -#endif diff --git a/misc/symbian/ClassiCube_s60v3.mmp b/misc/symbian/ClassiCube_s60v3.mmp index da4c84cba..acaba614a 100644 --- a/misc/symbian/ClassiCube_s60v3.mmp +++ b/misc/symbian/ClassiCube_s60v3.mmp @@ -4,15 +4,4 @@ ARMFPU softvfp LIBRARY libgles_cm.lib -SOURCEPATH . -START RESOURCE classicube.rss -HEADER -TARGETPATH \resource\apps -LANG SC -END - -START RESOURCE classicube_reg.rss -TARGETPATH \private\10003a3f\import\apps -END - -#include "ClassiCube_common.mmh" \ No newline at end of file +#include "ClassiCube.mmh" \ No newline at end of file diff --git a/misc/symbian/ClassiCube_s60v5.mmp b/misc/symbian/ClassiCube_s60v5.mmp index 2ef3d8ffa..9539dc53d 100644 --- a/misc/symbian/ClassiCube_s60v5.mmp +++ b/misc/symbian/ClassiCube_s60v5.mmp @@ -10,15 +10,4 @@ ALWAYS_BUILD_AS_ARM LIBRARY libgles_cm.lib -SOURCEPATH . -START RESOURCE classicube.rss -HEADER -TARGETPATH \resource\apps -LANG SC -END - -START RESOURCE classicube_reg.rss -TARGETPATH \private\10003a3f\import\apps -END - -#include "ClassiCube_common.mmh" \ No newline at end of file +#include "ClassiCube.mmh" \ No newline at end of file diff --git a/misc/symbian/ClassiCube_sym3.mmp b/misc/symbian/ClassiCube_sym3.mmp index 9e1ccc74d..8be599715 100644 --- a/misc/symbian/ClassiCube_sym3.mmp +++ b/misc/symbian/ClassiCube_sym3.mmp @@ -1,4 +1,4 @@ -TARGET ClassiCube_sym3.exe +TARGET ClassiCube.exe MACRO CC_BUILD_SYMBIAN_3 MACRO CC_BUILD_SYMBIAN_LIBGLESV2 @@ -12,15 +12,4 @@ ALWAYS_BUILD_AS_ARM LIBRARY libglesv2.lib LIBRARY libegl.lib -SOURCEPATH . -START RESOURCE classicube.rss -HEADER -TARGETPATH \resource\apps -LANG SC -END - -START RESOURCE classicube_reg.rss -TARGETPATH \private\10003a3f\import\apps -END - -#include "ClassiCube_common.mmh" \ No newline at end of file +#include "ClassiCube.mmh" \ No newline at end of file diff --git a/misc/symbian/bearssl.mmp b/misc/symbian/bearssl.mmp new file mode 100644 index 000000000..5cd3c2dba --- /dev/null +++ b/misc/symbian/bearssl.mmp @@ -0,0 +1,10 @@ +TARGETTYPE LIB +TARGET ClassiCube_bearssl.lib + +USERINCLUDE ../../third_party/bearssl/inc +USERINCLUDE ../../third_party/bearssl/src + +SOURCEPATH ../../third_party/bearssl +SOURCE aes_big_cbcdec.c aes_big_cbcenc.c aes_big_ctr.c aes_big_ctrcbc.c aes_big_dec.c aes_big_enc.c aes_common.c aes_x86ni.c aes_x86ni_cbcdec.c aes_x86ni_cbcenc.c aes_x86ni_ctr.c aes_x86ni_ctrcbc.c aesctr_drbg.c asn1enc.c ccm.c ccopy.c chacha20_ct.c chacha20_sse2.c dec32be.c dec32le.c dec64be.c dec64le.c dig_oid.c dig_size.c ec_all_m31.c ec_c25519_i31.c ec_c25519_m31.c ec_c25519_m62.c ec_c25519_m64.c ec_curve25519.c ec_default.c ec_p256_m31.c ec_p256_m62.c ec_p256_m64.c ec_prime_i31.c ec_secp256r1.c ec_secp384r1.c ec_secp521r1.c ecdsa_atr.c ecdsa_default_vrfy_asn1.c ecdsa_default_vrfy_raw.c ecdsa_i31_bits.c ecdsa_i31_vrfy_asn1.c ecdsa_i31_vrfy_raw.c enc32be.c enc32le.c enc64be.c enc64le.c gcm.c ghash_ctmul.c ghash_ctmul64.c ghash_pclmul.c hmac.c hmac_ct.c hmac_drbg.c i31_add.c i31_bitlen.c i31_decmod.c i31_decode.c i31_decred.c i31_encode.c i31_fmont.c i31_iszero.c i31_moddiv.c i31_modpow.c i31_modpow2.c i31_montmul.c i31_mulacc.c i31_muladd.c i31_ninv31.c i31_reduce.c i31_rshift.c i31_sub.c i31_tmont.c i32_div32.c i62_modpow2.c md5.c md5sha1.c multihash.c poly1305_ctmul.c poly1305_ctmulq.c prf.c prf_md5sha1.c prf_sha256.c prf_sha384.c rsa_default_pkcs1_vrfy.c rsa_default_priv.c rsa_default_pub.c rsa_i31_pkcs1_vrfy.c rsa_i31_priv.c rsa_i31_pub.c rsa_i62_pkcs1_vrfy.c rsa_i62_priv.c rsa_i62_pub.c rsa_pkcs1_sig_unpad.c sha1.c sha2big.c sha2small.c ssl_client.c ssl_client_default_rsapub.c ssl_client_full.c ssl_engine.c ssl_engine_default_aescbc.c ssl_engine_default_aesccm.c ssl_engine_default_aesgcm.c ssl_engine_default_chapol.c ssl_engine_default_ec.c ssl_engine_default_ecdsa.c ssl_engine_default_rsavrfy.c ssl_hashes.c ssl_hs_client.c ssl_io.c ssl_rec_cbc.c ssl_rec_ccm.c ssl_rec_chapol.c ssl_rec_gcm.c x509_minimal.c x509_minimal_full.c + +#include "common.mmh" \ No newline at end of file diff --git a/misc/symbian/bld.inf b/misc/symbian/bld.inf index b5dd41a10..6664be610 100644 --- a/misc/symbian/bld.inf +++ b/misc/symbian/bld.inf @@ -3,6 +3,7 @@ DEFAULT PRJ_MMPFILES gnumakefile Icons_scalable_dc.mk +bearssl.mmp ClassiCube_sym3.mmp ClassiCube_s60v5.mmp ClassiCube_s60v3.mmp diff --git a/misc/symbian/classicube.rss b/misc/symbian/classicube.rss index b8315b615..aa63488fd 100644 --- a/misc/symbian/classicube.rss +++ b/misc/symbian/classicube.rss @@ -9,6 +9,8 @@ NAME CUBE RESOURCE RSS_SIGNATURE { } RESOURCE TBUF { buf="ClassiCube"; } +RESOURCE EIK_APP_INFO { } + rls_string STRING_app_caption_string "ClassiCube" rls_string STRING_app_short_caption_string "ClassiCube" diff --git a/misc/symbian/common.mmh b/misc/symbian/common.mmh new file mode 100644 index 000000000..fa98b912b --- /dev/null +++ b/misc/symbian/common.mmh @@ -0,0 +1,30 @@ +MACRO SYMBIAN_OE_POSIX_SIGNALS + +SYSTEMINCLUDE /epoc32 +SYSTEMINCLUDE /epoc32/include +SYSTEMINCLUDE /epoc32/include/mw +SYSTEMINCLUDE /epoc32/include/app +SYSTEMINCLUDE /epoc32/include/platform +SYSTEMINCLUDE /epoc32/include/platform/mw +SYSTEMINCLUDE /epoc32/include/platform/app +SYSTEMINCLUDE /epoc32/include/gles +SYSTEMINCLUDE /epoc32/include/stdapis + +SYSTEMINCLUDE . + +USERINCLUDE ../../third_party/bearssl/inc +USERINCLUDE ../../third_party/bearssl/src + +#ifdef ARMCC +OPTION ARMCC -Otime --diag_suppress 1296 --diag_suppress 1293 --diag_suppress 66 +#ifndef ARMV5 +OPTION_REPLACE ARMCC --cpu 6 +OPTION_REPLACE ARMCC --fpu softvfp+vfpv2 --fpmode fast +OPTION_REPLACE ARMCC -O2 -O3 +#endif +#endif + +DEBUGGABLE_UDEBONLY +#ifdef _DEBUG +SRCDBG +#endif \ No newline at end of file diff --git a/src/Camera.c b/src/Camera.c index 30442f324..30d98ab0f 100644 --- a/src/Camera.c +++ b/src/Camera.c @@ -378,7 +378,7 @@ static void OnInit(void) { #ifdef CC_BUILD_WIN Camera.Sensitivity = Options_GetInt(OPT_SENSITIVITY, 1, 200, 40); -#elif defined CC_BUILD_SYMBIAN && defined CC_BUILD_TOUCH +#elif defined CC_BUILD_SYMBIAN_3 || defined CC_BUILD_SYMBIAN_S60V5 Camera.Sensitivity = Options_GetInt(OPT_SENSITIVITY, 1, 200, 70); #else Camera.Sensitivity = Options_GetInt(OPT_SENSITIVITY, 1, 200, 30); diff --git a/src/Core.h b/src/Core.h index 375972ca2..3dc3cea14 100644 --- a/src/Core.h +++ b/src/Core.h @@ -607,6 +607,8 @@ typedef cc_uint8 cc_bool; #define CC_BUILD_EGL #define CC_BUILD_MAXSTACK (16 * 1024) #define CC_BUILD_LOWMEM + #define CC_BUILD_TOUCH + #define CC_NOMAIN #define DEFAULT_NET_BACKEND CC_NET_BACKEND_BUILTIN #define DEFAULT_SSL_BACKEND CC_SSL_BACKEND_BEARSSL @@ -615,9 +617,6 @@ typedef cc_uint8 cc_bool; #else #define DEFAULT_GFX_BACKEND CC_GFX_BACKEND_GL1 #endif - #if defined CC_BUILD_SYMBIAN_3 || defined CC_BUILD_SYMBIAN_S60V5 - #define CC_BUILD_TOUCH - #endif #endif #endif diff --git a/src/Gui.c b/src/Gui.c index 046a24f81..0632586c1 100644 --- a/src/Gui.c +++ b/src/Gui.c @@ -124,7 +124,7 @@ static void LoadOptions(void) { Gui.ShowFPS = Options_GetBool(OPT_SHOW_FPS, true); Gui.RawInventoryScale = Options_GetFloat(OPT_INVENTORY_SCALE, 0.25f, 5.0f, 1.0f); -#if defined CC_BUILD_SYMBIAN && defined CC_BUILD_TOUCH +#if defined CC_BUILD_SYMBIAN_3 || defined CC_BUILD_SYMBIAN_S60V5 Gui.RawHotbarScale = Options_GetFloat(OPT_HOTBAR_SCALE, 0.25f, 5.0f, 2.0f); #else Gui.RawHotbarScale = Options_GetFloat(OPT_HOTBAR_SCALE, 0.25f, 5.0f, 1.0f); diff --git a/src/Platform_Symbian.cpp b/src/Platform_Symbian.cpp index 9c71a1403..62db0f8aa 100644 --- a/src/Platform_Symbian.cpp +++ b/src/Platform_Symbian.cpp @@ -55,24 +55,6 @@ const char* Platform_AppNameSuffix = ""; cc_uint8 Platform_Flags = PLAT_FLAG_SINGLE_PROCESS | PLAT_FLAG_APP_EXIT; cc_bool Platform_ReadonlyFilesystem; -/*########################################################################################################################* -*-----------------------------------------------------Main entrypoint-----------------------------------------------------* -*#########################################################################################################################*/ -#include "main_impl.h" - -int main(int argc, char** argv) { - cc_result res; - SetupProgram(argc, argv); - - do { - res = RunProgram(argc, argv); - } while (Window_Main.Exists); - - Window_Free(); - Process_Exit(res); - return res; -} - /*########################################################################################################################* *---------------------------------------------------------Memory----------------------------------------------------------* diff --git a/src/Window_Symbian.cpp b/src/Window_Symbian.cpp index c2f2017b7..f9f7609fc 100644 --- a/src/Window_Symbian.cpp +++ b/src/Window_Symbian.cpp @@ -11,6 +11,14 @@ #include #include #include +#include +#include +#include +#include +#include +#include +#include +#include extern "C" { #include #include @@ -22,9 +30,23 @@ extern "C" { #include "Graphics.h" #include "Game.h" #include "VirtualKeyboard.h" +#include "Platform.h" +#include "Options.h" +#include "Server.h" +#include "LScreens.h" +#include "Http.h" +#include "main_impl.h" } +class CCContainer; + static cc_bool launcherMode; +static cc_bool gameRunning = false; + +const TUid KUidClassiCube = {0xE212A5C2}; + +static CCContainer* container; + static const BindMapping symbian_binds[BIND_COUNT] = { { CCKEY_UP, 0 }, // BIND_FORWARD { CCKEY_DOWN, 0 }, // BIND_BACKWARDS @@ -66,215 +88,160 @@ static const BindMapping symbian_binds[BIND_COUNT] = { { '1', 0 }, { '3', 0 } /* BIND_HOTBAR_LEFT, BIND_HOTBAR_RIGHT */ }; - -class CWindow; - -CWindow* window; - -static void ConvertToUnicode(TDes& dst, const char* src, size_t length) { - if (!src) return; - - cc_unichar* uni = reinterpret_cast (const_cast (dst.Ptr())); - for (int i = 0; i < length; i++) { - *uni++ = Convert_CP437ToUnicode(src[i]); - } - *uni = '\0'; - dst.SetLength(length); -} - -static void ConvertToUnicode(TDes& dst, const cc_string* src) { - ConvertToUnicode(dst, src->buffer, (size_t)src->length); -} - -class CWindow : public CBase -{ -public: - static CWindow* NewL(); - void HandleWsEvent(const TWsEvent& aEvent); - void AllocFrameBuffer(int width, int height); - void DrawFramebuffer(Rect2D r, struct Bitmap* bmp); - void FreeFrameBuffer(); - void ProcessEvents(float delta); - void RequestClose(); - void InitEvents(); - cc_result OpenBrowserL(const cc_string* url); - ~CWindow(); - - TWsEvent iWsEvent; - TRequestStatus iWsEventStatus; - RWindow* iWindow; - -private: - CWindow(); - void ConstructL(); - void CreateWindowL(); - - RWsSession iWsSession; - RWindowGroup iWindowGroup; - CWsScreenDevice* iWsScreenDevice; - CWindowGc* iWindowGc; - CFbsBitmap* iBitmap; - CApaWindowGroupName* iWindowGroupName; - - TBool iEventsInitialized; +// Event management +enum CCEventType { + CC_NONE, + CC_KEY_DOWN, CC_KEY_UP, CC_KEY_INPUT, + CC_TOUCH_ADD, CC_TOUCH_REMOVE +}; +struct CCEvent { + int type; + int i1, i2, i3; }; -// +#define EVENTS_DEFAULT_MAX 30 +static void* events_mutex; +static int events_count, events_capacity; +static CCEvent* events_list, events_default[EVENTS_DEFAULT_MAX]; -CWindow* CWindow::NewL() { - CWindow* self = new (ELeave) CWindow(); - CleanupStack::PushL(self); - self->ConstructL(); - CleanupStack::Pop(self); - return self; +static void Events_Init(void) { + events_mutex = Mutex_Create("Symbian events"); + events_capacity = EVENTS_DEFAULT_MAX; + events_list = events_default; } -void CWindow::CreateWindowL() { - TPixelsTwipsAndRotation pixnrot; - iWsScreenDevice->GetScreenModeSizeAndRotation(iWsScreenDevice->CurrentScreenMode(), pixnrot); +static void Events_Push(const CCEvent* event) { + if (!events_mutex) return; + Mutex_Lock(events_mutex); + { + if (events_count >= events_capacity) { + Utils_Resize((void**)&events_list, &events_capacity, + sizeof(CCEvent), EVENTS_DEFAULT_MAX, 20); + } + events_list[events_count++] = *event; + } + Mutex_Unlock(events_mutex); +} - iWindow->SetExtent(TPoint(0, 0), pixnrot.iPixelSize); - iWindow->SetRequiredDisplayMode(iWsScreenDevice->DisplayMode()); -#ifdef CC_BUILD_SYMBIAN_3 - iWindow->EnableAdvancedPointers(); -#endif - iWindow->Activate(); - iWindow->SetVisible(ETrue); - iWindow->SetNonFading(ETrue); - iWindow->SetShadowDisabled(ETrue); - iWindow->EnableRedrawStore(EFalse); - iWindow->EnableVisibilityChangeEvents(); - iWindow->SetNonTransparent(); - iWindow->SetBackgroundColor(); - iWindow->SetOrdinalPosition(0); - // Enable drag events - iWindow->PointerFilter(EPointerFilterDrag, 0); +static cc_bool Events_Pull(CCEvent* event) { + cc_bool found = false; + + Mutex_Lock(events_mutex); + { + if (events_count) { + *event = events_list[0]; + for (int i = 1; i < events_count; i++) { + events_list[i - 1] = events_list[i]; + } + events_count--; + found = true; + } + } + Mutex_Unlock(events_mutex); + return found; +} - WindowInfo.Focused = true; - WindowInfo.Exists = true; - WindowInfo.Handle.ptr = (void*) iWindow; -#ifdef CC_BUILD_TOUCH - WindowInfo.SoftKeyboard = SOFT_KEYBOARD_VIRTUAL; -#endif - - TInt w = pixnrot.iPixelSize.iWidth, - h = pixnrot.iPixelSize.iHeight; - - DisplayInfo.Width = w; - DisplayInfo.Height = h; - - WindowInfo.Width = w; - WindowInfo.Height = h; +class CCApp: public CAknApplication { +private: + CApaDocument* CreateDocumentL(); + TUid AppDllUid() const; +}; +LOCAL_C CApaApplication* NewApplication(); - WindowInfo.UIScaleX = DEFAULT_UI_SCALE_X; - WindowInfo.UIScaleY = DEFAULT_UI_SCALE_Y; - if (w <= 360) { - DisplayInfo.ScaleX = 0.5f; - DisplayInfo.ScaleY = 0.5f; - } else { - DisplayInfo.ScaleX = 1; - DisplayInfo.ScaleY = 1; +GLDEF_C TInt E32Main(); + +class CCContainer: public CCoeControl, MCoeControlObserver { +public: + void ConstructL(const TRect& aRect, CAknAppUi* aAppUi); + virtual ~CCContainer(); + + void DrawFramebuffer(Rect2D r, struct Bitmap* bmp); + static TInt LoopCallBack(TAny* aInstance); + void RestartTimerL(TInt aInterval); + +private: + void SizeChanged(); + void HandleResourceChange(TInt aType); + TInt CountComponentControls() const; + CCoeControl* ComponentControl(TInt aIndex) const; + void Draw(const TRect& aRect) const; + virtual void HandleControlEventL(CCoeControl*, TCoeEvent); + virtual void HandlePointerEventL(const TPointerEvent& aPointerEvent); + +public: + CAknAppUi* iAppUi; + CFbsBitmap* iBitmap; + CPeriodic* iPeriodic; +}; + +class CCDocument: public CAknDocument { +public: + static CCDocument* NewL(CEikApplication& aApp); + virtual ~CCDocument(); + +protected: + void ConstructL(); + +public: + CCDocument(CEikApplication& aApp); + +private: + CEikAppUi* CreateAppUiL(); +}; + +class CCAppUi: public CAknAppUi { +public: + void ConstructL(); + virtual ~CCAppUi(); + +private: + void DynInitMenuPaneL(TInt aResourceId, CEikMenuPane* aMenuPane); + void HandleCommandL(TInt aCommand); + virtual TKeyResponse HandleKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType); + virtual void HandleForegroundEventL(TBool aForeground); + +private: + CCContainer* iAppContainer; +}; + +// CCApp implementation + +TUid CCApp::AppDllUid() const { + return KUidClassiCube; +} + +CApaDocument* CCApp::CreateDocumentL() { + return CCDocument::NewL(*this); +} + +CApaApplication* NewApplication() { + return new CCApp; +} + +TInt E32Main() { + return EikStart::RunApplication(NewApplication); +} + +// CCAppUi implementation + +void CCAppUi::ConstructL() { + BaseConstructL(); + iAppContainer = new (ELeave) CCContainer; + iAppContainer->SetMopParent(this); + iAppContainer->ConstructL(ClientRect(), this); + AddToStackL(iAppContainer); +} + +CCAppUi::~CCAppUi() { + if (iAppContainer) { + RemoveFromStack(iAppContainer); + delete iAppContainer; } } -CWindow::CWindow() { - -} +void CCAppUi::DynInitMenuPaneL(TInt, CEikMenuPane*) { } -CWindow::~CWindow() { - if (iWindowGc) { - delete iWindowGc; - iWindowGc = NULL; - } - if (iWindow) { - iWindow->SetOrdinalPosition(KOrdinalPositionSwitchToOwningWindow); - iWindow->Close(); - delete iWindow; - iWindow = NULL; - } - if (iWsScreenDevice) { - delete iWsScreenDevice; - iWsScreenDevice = NULL; - } -} - -void CWindow::ConstructL() { - delete CActiveScheduler::Current(); - CActiveScheduler* actScheduler = new (ELeave) CActiveScheduler(); - CActiveScheduler::Install(actScheduler); - - CCoeEnv* env = CCoeEnv::Static(); - if (!env) { - User::Panic(_L("CoeEnv::Static not initialized"), 0); - } - - iWsSession = env->WsSession(); - iWsScreenDevice = new (ELeave) CWsScreenDevice(iWsSession); - User::LeaveIfError(iWsScreenDevice->Construct()); - - iWindowGroup = RWindowGroup(iWsSession); - User::LeaveIfError(iWindowGroup.Construct(reinterpret_cast(this) - 1)); - iWindowGroup.SetOrdinalPosition(0); - iWindowGroup.EnableScreenChangeEvents(); -#ifdef CC_BUILD_TOUCH - iWindowGroup.EnableReceiptOfFocus(EFalse); -#else - iWindowGroup.EnableReceiptOfFocus(ETrue); -#endif - - iWindowGroupName = CApaWindowGroupName::NewL(iWsSession, iWindowGroup.Identifier()); - iWindowGroupName->SetAppUid(TUid::Uid(0xE212A5C2)); - iWindowGroupName->SetCaptionL(_L("ClassiCube")); - iWindowGroupName->SetHidden(EFalse); - iWindowGroupName->SetSystem(EFalse); - iWindowGroupName->SetRespondsToShutdownEvent(ETrue); - iWindowGroupName->SetWindowGroupName(iWindowGroup); - - iWindow = new (ELeave) RWindow(iWsSession); - - TInt err = iWindow->Construct(iWindowGroup, reinterpret_cast(this)); - User::LeaveIfError(err); - - TRAP(err, CreateWindowL()); - if (err) { - User::Panic(_L("Window creation failed"), err); - } - - RWindowGroup rootWin = CCoeEnv::Static()->RootWin(); - CApaWindowGroupName* rootWindGroupName = 0; - TRAP_IGNORE(rootWindGroupName = CApaWindowGroupName::NewL(iWsSession, rootWin.Identifier())); - if (rootWindGroupName) { - rootWindGroupName->SetHidden(ETrue); - rootWindGroupName->SetWindowGroupName(rootWin); - } - - TDisplayMode displayMode = iWindow->DisplayMode(); - TInt bufferSize = 0; - - switch (displayMode) { - case EColor4K: - bufferSize = 12; - break; - case EColor64K: - bufferSize = 16; - break; - case EColor16M: - bufferSize = 24; - break; - case EColor16MU: - case EColor16MA: - bufferSize = 32; - break; - default: - break; - } - - DisplayInfo.Depth = bufferSize; - - iWsSession.EventReadyCancel(); -} - -static int ConvertKey(TInt aScanCode) { +static CC_INLINE int MapScanCode(TInt aScanCode, TInt aModifiers) { // TODO array? switch (aScanCode) { case EStdKeyBackspace: @@ -304,12 +271,48 @@ static int ConvertKey(TInt aScanCode) { case EStdKeyDelete: return CCKEY_DELETE; case EStdKeyLeftArrow: + if (aModifiers & EModifierRotateBy90) { + return CCKEY_UP; + } + if (aModifiers & EModifierRotateBy180) { + return CCKEY_RIGHT; + } + if (aModifiers & EModifierRotateBy270) { + return CCKEY_DOWN; + } return CCKEY_LEFT; case EStdKeyRightArrow: + if (aModifiers & EModifierRotateBy90) { + return CCKEY_DOWN; + } + if (aModifiers & EModifierRotateBy180) { + return CCKEY_LEFT; + } + if (aModifiers & EModifierRotateBy270) { + return CCKEY_UP; + } return CCKEY_RIGHT; case EStdKeyUpArrow: + if (aModifiers & EModifierRotateBy90) { + return CCKEY_RIGHT; + } + if (aModifiers & EModifierRotateBy180) { + return CCKEY_DOWN; + } + if (aModifiers & EModifierRotateBy270) { + return CCKEY_LEFT; + } return CCKEY_UP; case EStdKeyDownArrow: + if (aModifiers & EModifierRotateBy90) { + return CCKEY_LEFT; + } + if (aModifiers & EModifierRotateBy180) { + return CCKEY_UP; + } + if (aModifiers & EModifierRotateBy270) { + return CCKEY_RIGHT; + } return CCKEY_DOWN; case EStdKeyLeftShift: return CCKEY_LSHIFT; @@ -413,7 +416,7 @@ static int ConvertKey(TInt aScanCode) { return CCKEY_VOLUME_UP; case EStdKeyDecVolume: return CCKEY_VOLUME_DOWN; - + // softkeys case EStdKeyDevice0: // left soft return CCKEY_F1; @@ -422,209 +425,339 @@ static int ConvertKey(TInt aScanCode) { case EStdKeyDevice3: // d-pad center return CCKEY_ENTER; } - - return aScanCode; + + return aScanCode < INPUT_COUNT ? aScanCode : INPUT_NONE; } -void CWindow::HandleWsEvent(const TWsEvent& aWsEvent) { - TInt eventType = aWsEvent.Type(); - switch (eventType) { - case EEventKeyDown: { - Input_Set(ConvertKey(aWsEvent.Key()->iScanCode), true); +TKeyResponse CCAppUi::HandleKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType) { + if (!events_mutex) return EKeyWasNotConsumed; + + CCEvent event = { 0 }; + event.i1 = MapScanCode(aKeyEvent.iScanCode, aKeyEvent.iModifiers); + switch (aType) { + case EEventKey: { + int code = aKeyEvent.iCode; + if (code != 0 && (code < ENonCharacterKeyBase || code > ENonCharacterKeyBase + ENonCharacterKeyCount)) { + event.i1 = code; + event.type = CC_KEY_INPUT; + Events_Push(&event); + return EKeyWasConsumed; + } break; } + case EEventKeyDown: { + if (event.i1 != INPUT_NONE) { + event.type = CC_KEY_DOWN; + Events_Push(&event); + } + return EKeyWasConsumed; + } case EEventKeyUp: { - Input_Set(ConvertKey(aWsEvent.Key()->iScanCode), false); - break; - } - case EEventScreenDeviceChanged: - //case 27: /* EEventDisplayChanged */ - { - TPixelsTwipsAndRotation pixnrot; - iWsScreenDevice->GetScreenModeSizeAndRotation(iWsScreenDevice->CurrentScreenMode(), pixnrot); - if (pixnrot.iPixelSize != iWindow->Size()) { - iWindow->SetExtent(TPoint(0, 0), pixnrot.iPixelSize); - - TInt w = pixnrot.iPixelSize.iWidth, - h = pixnrot.iPixelSize.iHeight; - - DisplayInfo.Width = w; - DisplayInfo.Height = h; - - WindowInfo.Width = w; - WindowInfo.Height = h; - - Event_RaiseVoid(&WindowEvents.Resized); + if (event.i1 != INPUT_NONE) { + event.type = CC_KEY_UP; + Events_Push(&event); } - Event_RaiseVoid(&WindowEvents.RedrawNeeded); - break; + return EKeyWasConsumed; } - case EEventFocusLost: { -#if 0 // TODO - if (!WindowInfo.Focused) break; - WindowInfo.Focused = false; - - Event_RaiseVoid(&WindowEvents.FocusChanged); -#endif - break; } - case EEventFocusGained: { - if (!WindowInfo.Focused) { - WindowInfo.Focused = true; - - Event_RaiseVoid(&WindowEvents.FocusChanged); - } - Event_RaiseVoid(&WindowEvents.RedrawNeeded); - break; - } - // shutdown request from task manager - case KAknShutOrHideApp: { + return EKeyWasNotConsumed; +} + +void CCAppUi::HandleForegroundEventL(TBool aForeground) { + WindowInfo.Inactive = !aForeground; + Event_RaiseVoid(&WindowEvents.InactiveChanged); + +} + +void CCAppUi::HandleCommandL(TInt aCommand) { + switch (aCommand) { + case EAknSoftkeyBack: + case EEikCmdExit: { WindowInfo.Exists = false; - RequestClose(); + Window_RequestClose(); + Exit(); break; } - // shutdown request from system (out of memory) - case EEventUser: { - TApaSystemEvent apaSystemEvent = *(TApaSystemEvent*) aWsEvent.EventData(); - if (apaSystemEvent == EApaSystemEventShutdown) { - WindowInfo.Exists = false; - RequestClose(); + default: + break; + } +} + +// CCContainer implementation +TInt CCContainer::LoopCallBack(TAny*) { + if (!WindowInfo.Exists) { + Window_RequestClose(); + container->iAppUi->Exit(); + return EFalse; + } + + // launcher -> game -> launcher -> ... loop + launcher: + if (!gameRunning) { + if (Launcher_Tick()) { + return ETrue; } - break; + Launcher_Finish(); + + // run game + gameRunning = true; + Game_Setup(); + container->RestartTimerL(100); } - case EEventWindowVisibilityChanged: { - if (aWsEvent.Handle() == reinterpret_cast(this)) { - WindowInfo.Inactive = (aWsEvent.VisibilityChanged()->iFlags & TWsVisibilityChangedEvent::EFullyVisible) == 0; - Event_RaiseVoid(&WindowEvents.InactiveChanged); - } - break; + + if (!Game_Running) { + // return to launcher + gameRunning = false; + Game_Free(); + Launcher_Setup(); + container->RestartTimerL(10000); + goto launcher; } -#ifdef CC_BUILD_TOUCH - case EEventPointer: { + Game_RenderFrame(); + return ETrue; +} + +void CCContainer::RestartTimerL(TInt aInterval) { + if (iPeriodic) { + iPeriodic->Cancel(); + } else { + iPeriodic = CPeriodic::NewL(CActive::EPriorityIdle); + } + iPeriodic->Start(aInterval, aInterval, TCallBack(CCContainer::LoopCallBack, this)); +} + +void CCContainer::ConstructL(const TRect& aRect, CAknAppUi* aAppUi) { + iAppUi = aAppUi; + + // create window + CreateWindowL(); + SetExtentToWholeScreen(); + + // enable multi-touch and drag events #ifdef CC_BUILD_SYMBIAN_3 - TAdvancedPointerEvent* pointer = aWsEvent.Pointer(); - long num = pointer->IsAdvancedPointerEvent() ? pointer->PointerNumber() : 0; -#else - TPointerEvent* pointer = aWsEvent.Pointer(); - long num = 0; + Window().EnableAdvancedPointers(); #endif - TPoint pos = pointer->iPosition; - switch (pointer->iType) { - case TPointerEvent::EButton1Down: - Input_AddTouch(num, pos.iX, pos.iY); - break; - case TPointerEvent::EDrag: - Input_AddTouch(num, pos.iX, pos.iY); - break; - case TPointerEvent::EButton1Up: - Input_RemoveTouch(num, pos.iX, pos.iY); - break; - default: - break; - } + EnableDragEvents(); + + ActivateL(); + container = this; + + SetupProgram(0, 0); + + TSize size = Size(); + WindowInfo.Focused = true; + WindowInfo.Exists = true; + WindowInfo.Handle.ptr = (void*) &Window(); +#ifdef CC_BUILD_TOUCH + WindowInfo.SoftKeyboard = SOFT_KEYBOARD_VIRTUAL; +#endif + + DisplayInfo.Width = size.iWidth; + DisplayInfo.Height = size.iHeight; + + WindowInfo.Width = size.iWidth; + WindowInfo.Height = size.iHeight; + + WindowInfo.UIScaleX = DEFAULT_UI_SCALE_X; + WindowInfo.UIScaleY = DEFAULT_UI_SCALE_Y; + if (size.iWidth <= 360) { + DisplayInfo.ScaleX = 0.5f; + DisplayInfo.ScaleY = 0.5f; + } else { + DisplayInfo.ScaleX = 1; + DisplayInfo.ScaleY = 1; + } + + TDisplayMode displayMode = Window().DisplayMode(); + TInt bufferSize = 0; + + switch (displayMode) { + case EColor4K: + bufferSize = 12; + break; + case EColor64K: + bufferSize = 16; + break; + case EColor16M: + bufferSize = 24; + break; + case EColor16MU: + case EColor16MA: + bufferSize = 32; + break; + default: break; } -#endif - } + DisplayInfo.Depth = bufferSize; + + Launcher_Setup(); + // reduced tickrate for launcher + RestartTimerL(10000); } -void CWindow::AllocFrameBuffer(int width, int height) { - FreeFrameBuffer(); - if (!iWindowGc) { - iWindowGc = new (ELeave) CWindowGc(iWsScreenDevice); - iWindowGc->Construct(); - } - iBitmap = new CFbsBitmap(); - iBitmap->Create(TSize(width, height), EColor16MA); +CCContainer::~CCContainer() { + delete iPeriodic; } -void CWindow::FreeFrameBuffer() { - if (iWindowGc != NULL) { - delete iWindowGc; - iWindowGc = NULL; - } - if (iBitmap != NULL) { +void CCContainer::SizeChanged() { + TSize size = Size(); + if (iBitmap) { delete iBitmap; iBitmap = NULL; } + iBitmap = new CFbsBitmap(); + TInt err = iBitmap->Create(size, EColor16MA); + if (err) { + Process_Abort("Failed to create bitmap"); + return; + } + + DisplayInfo.Width = size.iWidth; + DisplayInfo.Height = size.iHeight; + if (!launcherMode) { + if (size.iWidth <= 360) { + DisplayInfo.ScaleX = 0.5f; + DisplayInfo.ScaleY = 0.5f; + } else { + DisplayInfo.ScaleX = 1; + DisplayInfo.ScaleY = 1; + } + } + WindowInfo.Width = size.iWidth; + WindowInfo.Height = size.iHeight; + Event_RaiseVoid(&WindowEvents.Resized); + DrawNow(); } -void CWindow::DrawFramebuffer(Rect2D r, struct Bitmap* bmp) { - if (!iWindowGc) return; - iWindow->Invalidate(/*TRect(r.x, r.y, r.width, r.height)*/); - iWindow->BeginRedraw(); - iWindowGc->Activate(*iWindow); +void CCContainer::HandleResourceChange(TInt aType) { + switch (aType) { + case KEikDynamicLayoutVariantSwitch: + SetExtentToWholeScreen(); + break; + } +} +TInt CCContainer::CountComponentControls() const { + return 0; +} + +CCoeControl* CCContainer::ComponentControl(TInt) const { + return NULL; +} + +void CCContainer::Draw(const TRect& aRect) const { + if (iBitmap && launcherMode) { + SystemGc().BitBlt(TPoint(0, 0), iBitmap); + } + // do nothing in 3d mode +} + +void CCContainer::DrawFramebuffer(Rect2D r, struct Bitmap* bmp) { if (iBitmap) { -// iBitmap->BeginDataAccess(); iBitmap->LockHeap(); TUint8* data = (TUint8*) iBitmap->DataAddress(); + if (!data) { + Process_Abort("Bitmap data address is null"); + return; + } const TUint8* src = (TUint8*) bmp->scan0; for (TInt row = bmp->height - 1; row >= 0; --row) { memcpy(data, src, bmp->width * BITMAPCOLOR_SIZE); src += bmp->width * BITMAPCOLOR_SIZE; data += iBitmap->DataStride(); } -// iBitmap->EndDataAccess(); iBitmap->UnlockHeap(); - - iWindowGc->BitBlt(TPoint(0, 0), iBitmap/*, TRect(r.x, r.y, r.width, r.height)*/); } - iWindowGc->Deactivate(); - iWindow->EndRedraw(); - iWsSession.Flush(); + DrawDeferred(); } -void CWindow::ProcessEvents(float delta) { - RThread thread; - TInt error = KErrNone; - while (thread.RequestCount()) { - CActiveScheduler::RunIfReady(error, CActive::EPriorityIdle); - User::WaitForAnyRequest(); - } - - while (iWsEventStatus != KRequestPending) { - iWsSession.GetEvent(window->iWsEvent); - HandleWsEvent(window->iWsEvent); - iWsEventStatus = KRequestPending; - iWsSession.EventReady(&iWsEventStatus); - } +void CCContainer::HandleControlEventL(CCoeControl*, TCoeEvent) { } -void CWindow::RequestClose() { - Event_RaiseVoid(&WindowEvents.Closing); -} - -void CWindow::InitEvents() { - iWindow->Invalidate(); - iWindow->BeginRedraw(); - iWindow->EndRedraw(); - iWsSession.Flush(); - if (iEventsInitialized) - return; - iEventsInitialized = ETrue; - iWsEventStatus = KRequestPending; - iWsSession.EventReady(&iWsEventStatus); -} - -cc_result CWindow::OpenBrowserL(const cc_string* url) { -#if defined CC_BUILD_SYMBIAN_3 || defined CC_BUILD_SYMBIAN_S60V5 - TUid browserUid = {0x10008D39}; +void CCContainer::HandlePointerEventL(const TPointerEvent& aPointerEvent) { +#ifdef CC_BUILD_TOUCH + CCEvent event = { 0 }; +#ifdef CC_BUILD_SYMBIAN_3 + const TAdvancedPointerEvent* advpointer = aPointerEvent.AdvancedPointerEvent(); + event.i1 = advpointer != NULL ? advpointer->PointerNumber() : 0; #else - TUid browserUid = {0x1020724D}; + event.i1 = 0; #endif - TApaTaskList tasklist(window->iWsSession); + TPoint pos = aPointerEvent.iPosition; + event.i2 = pos.iX; + event.i3 = pos.iY; + switch (aPointerEvent.iType) { + case TPointerEvent::EButton1Down: + event.type = CC_TOUCH_ADD; + break; + case TPointerEvent::EDrag: + event.type = CC_TOUCH_ADD; + break; + case TPointerEvent::EButton1Up: + event.type = CC_TOUCH_REMOVE; + break; + default: + break; + } + if (event.type) Events_Push(&event); +#endif + CCoeControl::HandlePointerEventL(aPointerEvent); +} + +// CCDocument implementation + +CCDocument::CCDocument(CEikApplication& aApp) : + CAknDocument(aApp) { +} + +CCDocument::~CCDocument() { +} + +void CCDocument::ConstructL() { +} + +CCDocument* CCDocument::NewL(CEikApplication& aApp) { + CCDocument* self = new (ELeave) CCDocument(aApp); + CleanupStack::PushL(self); + self->ConstructL(); + CleanupStack::Pop(); + + return self; +} + +CEikAppUi* CCDocument::CreateAppUiL() { + return new (ELeave) CCAppUi; +} + +static void ConvertToUnicode(TDes& dst, const char* src, size_t length) { + if (!src) return; + + cc_unichar* uni = reinterpret_cast(const_cast (dst.Ptr())); + for (int i = 0; i < length; i++) { + *uni++ = Convert_CP437ToUnicode(src[i]); + } + *uni = '\0'; + dst.SetLength(length); +} + +static CC_INLINE void ConvertToUnicode(TDes& dst, const cc_string* src) { + ConvertToUnicode(dst, src->buffer, (size_t)src->length); +} + +static cc_result OpenBrowserL(const cc_string* url) { + TUid browserUid = {0x10008D39}; + TApaTaskList tasklist(CEikonEnv::Static()->WsSession()); TApaTask task = tasklist.FindApp(browserUid); - + if (task.Exists()) { task.BringToForeground(); - task.SendMessage(TUid::Uid(0), TPtrC8((TUint8 *)url->buffer, (TInt)url->length)); + task.SendMessage(TUid::Uid(0), TPtrC8((TUint8 *) url->buffer, (TInt) url->length)); } else { RApaLsSession ls; if (!ls.Handle()) { User::LeaveIfError(ls.Connect()); } - + TThreadId tid; TBuf buf; ConvertToUnicode(buf, url); @@ -634,53 +767,43 @@ cc_result CWindow::OpenBrowserL(const cc_string* url) { return 0; } +static void ShowDialogL(const char* title, const char* msg) { + // TODO: use text box or something instead to fix line breaks + CAknInformationNote* note = new (ELeave) CAknInformationNote(true); + TBuf<512> msgBuf; + ConvertToUnicode(msgBuf, msg, String_Length(msg)); + note->ExecuteLD(msgBuf); +} + +// Window implementation + void Window_PreInit(void) { //NormDevice.defaultBinds = symbian_binds; TODO only use on devices with limited hardware - - CCoeEnv* env = new (ELeave) CCoeEnv(); - TRAPD(err, env->ConstructL(ETrue, 0)); - - if (err != KErrNone) { - User::Panic(_L("Failed to create CoeEnv"), 0); - } } void Window_Init(void) { - TRAPD(err, window = CWindow::NewL()); - if (err) { - User::Panic(_L("Failed to initialize CWindow"), err); - } - + Events_Init(); #ifdef CC_BUILD_TOUCH - //TBool touch = AknLayoutUtils::PenEnabled(); - - bool touch = true; + bool touch = AknLayoutUtils::PenEnabled(); + Input_SetTouchMode(touch); Gui_SetTouchUI(touch); #endif } void Window_Free(void) { - if (window) { - delete window; - window = NULL; - } - - CCoeEnv::Static()->DestroyEnvironment(); - delete CCoeEnv::Static(); } void Window_Create2D(int width, int height) { launcherMode = true; - window->InitEvents(); + container->SetExtentToWholeScreen(); } void Window_Create3D(int width, int height) { launcherMode = false; - window->InitEvents(); + container->SetExtentToWholeScreen(); } -void Window_Destroy(void) { -} +void Window_Destroy(void) { } void Window_SetTitle(const cc_string* title) { } @@ -688,65 +811,96 @@ void Clipboard_GetText(cc_string* value) { } void Clipboard_SetText(const cc_string* value) { } -int Window_GetWindowState(void) { return WINDOW_STATE_FULLSCREEN; } +int Window_GetWindowState(void) { + return WINDOW_STATE_FULLSCREEN; +} -cc_result Window_EnterFullscreen(void) { return 0; } +cc_result Window_EnterFullscreen(void) { + return 0; +} -cc_result Window_ExitFullscreen(void) { return 0; } +cc_result Window_ExitFullscreen(void) { + return 0; +} int Window_IsObscured(void) { return WindowInfo.Inactive; } -void Window_Show(void) { } +void Window_Show(void) { +} -void Window_SetSize(int width, int height) { } +void Window_SetSize(int width, int height) { +} void Window_RequestClose(void) { - window->RequestClose(); + Event_RaiseVoid(&WindowEvents.Closing); } void Window_ProcessEvents(float delta) { - window->ProcessEvents(delta); + CCEvent event; + while (Events_Pull(&event)) { + switch (event.type) { + case CC_KEY_DOWN: + Input_SetPressed(event.i1); + break; + case CC_KEY_UP: + Input_SetReleased(event.i1); + break; + case CC_KEY_INPUT: + Event_RaiseInt(&InputEvents.Press, event.i1); + break; +#ifdef CC_BUILD_TOUCH + case CC_TOUCH_ADD: + Input_AddTouch(static_cast(event.i1), event.i2, event.i3); + break; + case CC_TOUCH_REMOVE: + Input_RemoveTouch(static_cast(event.i1), event.i2, event.i3); + break; +#endif + } + } } -void Window_EnableRawMouse(void) { Input.RawMode = true; } - -void Window_UpdateRawMouse(void) { } - -void Window_DisableRawMouse(void) { Input.RawMode = false; } - -void Gamepads_Init(void) { - +void Window_EnableRawMouse(void) { + Input.RawMode = true; } -void Gamepads_Process(float delta) { - +void Window_UpdateRawMouse(void) { } + +void Window_DisableRawMouse(void) { + Input.RawMode = false; } +void Gamepads_Init(void) { } + +void Gamepads_Process(float delta) { } + void ShowDialogCore(const char* title, const char* msg) { - // TODO - static const cc_string t2 = String_Init((char*) title, String_Length(title), String_Length(title)); - Logger_Log(&t2); - static const cc_string msg2 = String_Init((char*) msg, String_Length(msg), String_Length(msg)); - Logger_Log(&msg2); - + TRAP_IGNORE(ShowDialogL(title, msg)); } void OnscreenKeyboard_Open(struct OpenKeyboardArgs* args) { +#ifdef CC_BUILD_TOUCH VirtualKeyboard_Open(args, launcherMode); +#endif } void OnscreenKeyboard_SetText(const cc_string* text) { +#ifdef CC_BUILD_TOUCH VirtualKeyboard_SetText(text); +#endif } void OnscreenKeyboard_Close(void) { +#ifdef CC_BUILD_TOUCH VirtualKeyboard_Close(); +#endif } void Window_LockLandscapeOrientation(cc_bool lock) { - // TODO + container->iAppUi->SetOrientationL(lock ? CAknAppUiBase::EAppUiOrientationLandscape : CAknAppUiBase::EAppUiOrientationAutomatic); + container->SetExtentToWholeScreen(); } static void Cursor_GetRawPos(int* x, int* y) { *x = 0; *y = 0; } @@ -765,15 +919,13 @@ void Window_AllocFramebuffer(struct Bitmap* bmp, int width, int height) { bmp->scan0 = (BitmapCol*)Mem_Alloc(width * height, BITMAPCOLOR_SIZE, "bitmap"); bmp->width = width; bmp->height = height; - window->AllocFrameBuffer(width, height); } void Window_DrawFramebuffer(Rect2D r, struct Bitmap* bmp) { - window->DrawFramebuffer(r, bmp); + container->DrawFramebuffer(r, bmp); } void Window_FreeFramebuffer(struct Bitmap* bmp) { - window->FreeFrameBuffer(); Mem_Free(bmp->scan0); } @@ -799,7 +951,7 @@ void GLContext_Create(void) { cc_result Process_StartOpen(const cc_string* args) { TInt err = 0; - TRAP(err, err = window->OpenBrowserL(args)); + TRAP(err, err = OpenBrowserL(args)); return (cc_result) err; }