PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

PocketHAL/PocketFrog Orientation

Hi PHAL's fans!

Can you confirm that pockethal holds its orientation variables regarding of pocketpc orientation?

For example, if i develop my application in portrait mode and i launch it in a landscape pocketpc, m_config.orientation is always ORIENTATION_NORMAL or pockethal change its value to ORIENTATION_ROTATE90CCW/ORIENTATION_ROTATE90CW?

And if i develop my application with ORIENTATION_ROTATE90CW and i launch it in a portrait pocketpc, m_config.orientation will be ORIENTATION_NORMAL?

Thanks in advance! ;)
Yes, m_config.orientation is independent of wm2003's mode. Should be the same for wm5.
Thanks for your answer ;)

So can you also confirm that pocketfrog internal remapping routines (for dpad arrows and stylus) cant't work when pocketpc is in landscape mode because they always assume that device is in standard portrait mode?

I noticed that when i start a pocketfrog portrait application in a landscape pocketpc, stylus are wrong mapped.
:twisted:
I'm using last pocketfrog 0.8.1 with last pockethal 0.7.7b (or 0.7.7c can't remember :D)
I checked again, with stylus and buttons...

Image is portrait, stylus is portrait and correct, but buttons are rotated (incorrect).

Seems different from what you say. I may have modified PFrog at some point. Don't remember at the moment - I'll have to look at the code when I get a chance.
Please let me know something when you have some time to check that,
i'm going to kill my brain in order to make it work with all screen rotations :evil:
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 :D)

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:
int iDeviceScreenRotation;

So it will look like:

Code:

// Configuration
struct Config
{
LPCTSTR szWindowName; // Window title
Orientation orientation; // Screen orientation (default = ORIENTATION_NORTH)

int iDeviceScreenRotation; // device orientation
}



In game.cpp add this code on in Game::Init (i added it just before):

Code:
// Init input
if (!PHAL::GetKeyList( &m;_keys, m_config.orientation ))
return false;


I had to declare also some structs that the API call will fill because they're not present in ppc2002 sdk.

Code:
/////////////////////////////////////////////////
//
//
// 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
/////////////////////////////////////////////////


Now on my pfrog games, i can get real pocketpc orientation with:
Code:
m_config.iDeviceScreenRotation
it will be 0,90,180,270 according to current device orientation.
While with:
Code:
m_config.orientation

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.. :D
Here's what I have in my device to logic functions. Note that the entire section for buttons is commented out, and I had forgotten that I fixed the stylus...

Basically, what I've got works correctly with the stylus, but not with the buttons (maybe I just need to uncomment the code below?)

Code:

void Game::DeviceToLogical( int& button ) const
{
#if defined(_WIN32_WCE)
/*
switch (m_config.orientation)
{
case ORIENTATION_ROTATE90CCW:
if (button == m_keys.vkUp) button = m_keys.vkRight;
else if (button == m_keys.vkLeft) button = m_keys.vkUp;
else if (button == m_keys.vkDown) button = m_keys.vkLeft;
else if (button == m_keys.vkRight) button = m_keys.vkDown;
break;

case ORIENTATION_ROTATE90CW:
if (button == m_keys.vkUp) button = m_keys.vkLeft;
else if (button == m_keys.vkLeft) button = m_keys.vkDown;
else if (button == m_keys.vkDown) button = m_keys.vkRight;
else if (button == m_keys.vkRight) button = m_keys.vkUp;
break;

case ORIENTATION_ROTATE180:
if (button == m_keys.vkUp) button = m_keys.vkDown;
else if (button == m_keys.vkLeft) button = m_keys.vkRight;
else if (button == m_keys.vkDown) button = m_keys.vkUp;
else if (button == m_keys.vkRight) button = m_keys.vkLeft;
break;
}
*/
#endif
}



//fixme: don't use hard coded values for width and height
void Game::DeviceToLogical( Point& P ) const
{
switch (m_config.orientation)
{
case ORIENTATION_ROTATE90CCW:
swap( P.x, P.y );
//JLE 02/27/2006
P.x = stylusheight - 1 - P.x;
break;

case ORIENTATION_ROTATE90CW:
swap( P.x, P.y );
P.y = styluswidth - 1 - P.y;
break;

case ORIENTATION_ROTATE180:
P.x = styluswidth - 1 - P.x;
P.y = stylusheight - 1 - P.y;
break;
}
}


styluswidth and stylusheight are defined in game's private class in game.h.

They are set at the end of Game::Init()
Code:

// In case ORIENTATION_UNKNOWN was selected
m_config.orientation = m_display->GetOrientation();

// JLE 02/27/2006
stylusheight = m_display->GetHeight();
styluswidth = m_display->GetWidth();
if (m_config.orientation == ORIENTATION_ROTATE90CW || m_config.orientation == ORIENTATION_ROTATE90CCW)
swap( stylusheight, styluswidth );

Mmmh..you're checking only for pockethal orientation, at this point..i'm really stucked... 8O

If pocketpc is set in landscape mode 320x240 and we launch a portrait 240x320 pocketfrog application, how can this work for you if pockethal consider only its screen orientation? 8O
(so in that case it won't map the coordinates)
Maybe it's the device you're using? Or the version I've got?

I'm using PHal 0.7.7c (I think) with an axim X30.

Seems to me that it would be a function of PHal to give you the buttons correctly... via the
PHAL::GetKeyList( &m_keys, m_config.orientation )

Just to make sure we're clear:
*your programs correctly handle the buttons but not the stylus.
*My programs are correct with stylus but not buttons.


Should I post a checkout program to see if it's the same on your device?
Yes please if you post a test program, this would be great!


This was the situation before i modified pocketfrog:

Actually, with latest pocketfrog 0.8.1 (no patches) and latest pockethal 0.7.7 the game gives always wrong mapped stylus (and buttons) when pocketpc isn't in portrait default mode.

If i try a demo pockethal application with m_config.orient = normal/90cw/90ccw/180 on a portrait pocketpc, the pocketfrog correctly remap buttons and stylus.

I tried it on my Asus MyPal A636N (this is my first and unique wm5 device at the moment :( )
Here's a test program...

Reports the status of dpad and stylus. You can change the PFrog orientation, but it requires a restart...

On my x30, the only issue is the dpad when started in wm2003 portrait mode.
Attachments:
ButtonTest.zip (55 KB)
Wow! Stylus works well with every pocketpc/pockethal combination with your sample! 8O
I'll implement your patch on my pocketfrog and will recheck all again :cry:
I tried to use your detection code to fix the button rotation issue, but my setup is EVC3/wm2003. It reports devmode.dmDisplayOrientation==0 no matter what...

Actually, I noticed that it looks like my device flips to portrait just before my app runs. Then on exit, I see a brief portrait image just before it returns to landscape.

I think I've spent enough time on this, and if anyone complains - just tell them to run it in portrait mode.

Of course, if you come up with something that works, I'll use it.
Oh, that's strange that code works perfectly on WM5 and all structs was taken from 2003 sdk :o

Anyway..thanks a lot for your time :D
I really appreciate that.
Just for information, on Fujitsu Siemens PocketLoox 720 the Button Test demo works right for stylus, but does not work right for buttons. Or may be I do not understand how it should work. :)

In landscape, when the "up" button is pressed (which points to the screen), the Button Demo reports "right".

On the other way, It seems logical, because when I hold device in landscape mode, this button points to the right...

So, what the demo should tell us in landscape mode, when the "up" button is pressed? (which points to screen)
In landscape mode, the device 'up' is no longer 'up'... It can get confusing.

In landscape mode, it should rotate the screen and buttons 90 degrees... So the physical top of the device is now the right. So, assuming the display rotated and the physical up is now right, it sounds correct.

I was going to attach a picture explaining it, but images are not allowed now.