Well, i'd like to share with community this piece of code i made in order to get device orientation (as said fast_rx, is NOT the pockethal one!)
Starting from this code, i'm going to code a correct stylus/dpad mapping also for devices not in portrait mode (as soon fast_rx confirms me that he had to modify PFrog too

)
Basically it's only an API call, but this is available only on PPC2003 Second Edition devices and later so this code try to call the function dynamically and works well also on ppc2002 and ppc2003 and it compiles well also on EVC++3.
This code is a patch for pocketfrog 0.8.1 source.
In game.h find struct Config and add:
- Code: Select all
1
| int iDeviceScreenRotation;
|
| 1 lines; 1 keywds; 0 nums; 1 ops; 0 strs; 0 coms Syntactic Coloring v0.4 - Dan East |
So it will look like:
- Code: Select all
1 2 3 4 5 6 7 8 9
| // Configuration struct Config { LPCTSTR szWindowName; // Window title Orientation orientation; // Screen orientation (default = ORIENTATION_NORTH)
int iDeviceScreenRotation; // device orientation }
|
| 9 lines; 2 keywds; 0 nums; 5 ops; 0 strs; 4 coms Syntactic Coloring v0.4 - Dan East |
In game.cpp add this code on in Game::Init (i added it just before):
- Code: Select all
1 2 3
| // Init input if (!PHAL::GetKeyList( &m_keys, m_config.orientation )) return false;
|
| 3 lines; 3 keywds; 0 nums; 11 ops; 0 strs; 1 coms Syntactic Coloring v0.4 - Dan East |
I had to declare also some structs that the API call will fill because they're not present in ppc2002 sdk.
- Code: Select all
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
| ///////////////////////////////////////////////// // // // Detect pocketpc screen orientation // this is NOT the pockethal one! #if defined(FROG_PPC)
typedef struct d_evicemodeA { BYTE dmDeviceName[CCHDEVICENAME]; WORD dmSpecVersion; WORD dmDriverVersion; WORD dmSize; WORD dmDriverExtra; DWORD dmFields; short dmOrientation; short dmPaperSize; short dmPaperLength; short dmPaperWidth; short dmScale; short dmCopies; short dmDefaultSource; short dmPrintQuality; short dmColor; short dmDuplex; short dmYResolution; short dmTTOption; short dmCollate; BYTE dmFormName[CCHFORMNAME]; WORD dmLogPixels; DWORD dmBitsPerPel; DWORD dmPelsWidth; DWORD dmPelsHeight; DWORD dmDisplayFlags; DWORD dmDisplayFrequency; DWORD dmICMMethod; DWORD dmICMIntent; DWORD dmMediaType; DWORD dmDitherType; DWORD dmICCManufacturer; DWORD dmICCModel; DWORD dmPanningWidth; DWORD dmPanningHeight; DWORD dmDisplayOrientation; } DEVMODEA_WM5, *PDEVMODEA_WM5, *NPDEVMODEA_WM5, *LPDEVMODEA_WM5;
typedef struct d_evicemodeW { WCHAR dmDeviceName[CCHDEVICENAME]; WORD dmSpecVersion; WORD dmDriverVersion; WORD dmSize; WORD dmDriverExtra; DWORD dmFields; short dmOrientation; short dmPaperSize; short dmPaperLength; short dmPaperWidth; short dmScale; short dmCopies; short dmDefaultSource; short dmPrintQuality; short dmColor; short dmDuplex; short dmYResolution; short dmTTOption; short dmCollate; WCHAR dmFormName[CCHFORMNAME]; WORD dmLogPixels; DWORD dmBitsPerPel; DWORD dmPelsWidth; DWORD dmPelsHeight; DWORD dmDisplayFlags; DWORD dmDisplayFrequency; DWORD dmDisplayOrientation; } DEVMODEW_WM5, *PDEVMODEW_WM5, *NPDEVMODEW_WM5, *LPDEVMODEW_WM5;
#ifdef UNICODE typedef DEVMODEW_WM5 DEVMODE_WM5; typedef PDEVMODEW_WM5 PDEVMODE_WM5; typedef NPDEVMODEW_WM5 NPDEVMODE_WM5; typedef LPDEVMODEW_WM5 LPDEVMODE_WM5; #else typedef DEVMODEA_WM5 DEVMODE_WM5; typedef PDEVMODEA_WM5 PDEVMODE_WM5; typedef NPDEVMODEA_WM5 NPDEVMODE_WM5; typedef LPDEVMODEA_WM5 LPDEVMODE_WM5; #endif
// start DLL API call
typedef LONG (CALLBACK* LPFNDLLFUNC1)(LPCTSTR, LPDEVMODE_WM5, HWND, DWORD, LPVOID);
LPFNDLLFUNC1 lpfnDllFunc1; HINSTANCE h = LoadLibrary(_T("CoreDLL.dll")); if (h != NULL) { lpfnDllFunc1 = (LPFNDLLFUNC1)GetProcAddress(h,_T("ChangeDisplaySettingsEx")); if (lpfnDllFunc1) { /*DEVMODE */DEVMODE_WM5 devmode = {0}; devmode.dmSize = sizeof(DEVMODE_WM5); devmode.dmFields = /*DM_DISPLAYORIENTATION*/0x00800000L; lpfnDllFunc1(NULL, &devmode, 0, /*CDS_TEST*/0x00000002, NULL);
if (devmode.dmDisplayOrientation==0 /*DMDO_0*/) m_config.iDeviceScreenRotation=0; else if (devmode.dmDisplayOrientation==1 /*DMDO_90*/) m_config.iDeviceScreenRotation=90; else if (devmode.dmDisplayOrientation==2 /*DMDO_180*/) m_config.iDeviceScreenRotation=180; else if (devmode.dmDisplayOrientation==4 /*DMDO_270*/) m_config.iDeviceScreenRotation=270; else m_config.iDeviceScreenRotation=0;
} else { // GetProcAddress failed! We'll assume standard orientation m_config.iDeviceScreenRotation=0; } FreeLibrary(h); } else { // LoadLibrary failed - we'll assume standard orientation m_config.iDeviceScreenRotation=0; } #else // On desktop, assume always standard orientation m_config.iDeviceScreenRotation=0; #endif // // // End of PocketPC Screen orientation detect /////////////////////////////////////////////////
|
| 130 lines; 59 keywds; 16 nums; 205 ops; 2 strs; 20 coms Syntactic Coloring v0.4 - Dan East |
Now on my pfrog games, i can get real pocketpc orientation with:
- Code: Select all
1
| m_config.iDeviceScreenRotation
|
| 1 lines; 0 keywds; 0 nums; 1 ops; 0 strs; 0 coms Syntactic Coloring v0.4 - Dan East |
it will be 0,90,180,270 according to current device orientation.
While with:
- Code: Select all
1
| m_config.orientation
|
| 1 lines; 0 keywds; 0 nums; 1 ops; 0 strs; 0 coms Syntactic Coloring v0.4 - Dan East |
i have PocketHal screen orientation
I tested on my wm5 device and it gave correct values on all orientations, i don't know if this will be useful for someone, but who knows..
