About:

GNUGoS60 is a port of the FSF's GNU Go game engine to Nokia's S60 smartphone platform running on SymbianOS.

It is Free Software.

Saturday, September 09, 2006

Multiple Resolutions



S60 now supports lots of resolutions as you may be aware. It's easy to test these out in the emulator. For example here is the board in Double Resoluton Landscape mode , and below is the the old standard S60 resolution.


I had been worried about getting this working because of all the problems I have seen in applications handling this incorrectly, but turns out it's extermely simple to do (for a change), at least with the limited UI I have at the moment. Pretty much just implement the HandleResourceChange method in your view, and any controls that need to care about it. For gnugo so far it turns out that only the main view needs to handle it to reposition the board control, and any others I may add. The board itself gets away with just handling size change events.
void CgnugoAppView::HandleResourceChange( TInt aType )
{
// Call the baseclass handler
CCoeControl::HandleResourceChange( aType );

if ( aType==KEikDynamicLayoutVariantSwitch )
{
// If it's a layout switch, then recalculate the positions of the
// controls. In this case, only the go board control.
TRect rect = Rect ();

if (rect.Width () > rect.Height ()) {
rect.SetWidth (rect.Height ());
} else {
rect.SetHeight (rect.Width ());
}
if (iBoardControl) iBoardControl->SetRect (rect);
}

// call the (default) handler in the control.
if (iBoardControl) iBoardControl->HandleResourceChange (aType);
}
I found that as I was experimenting with various things that it was better if the main view also implemented both of the PositionChanged and SizeChanged methods.
void CgnugoAppView::PositionChanged( )
{
// call the baseclass handler
CCoeControl::PositionChanged ();

TPoint position = Position ();

// call the sub control handler
if (iBoardControl) iBoardControl->SetPosition (position);
}
The Position Changed one is not really needed so much, but better to implement it now, than start worndering why something doesn't work in the future.
void CgnugoAppView::SizeChanged( )
{
// call the baseclass handler
CCoeControl::SizeChanged ();

TSize size = Size ();

if (size.iWidth > size.iHeight) {
size.iWidth = size.iHeight;
} else {
size.iHeight = size.iWidth;
}
// call the sub control handler
if (iBoardControl) iBoardControl->SetSize (size);
}
The SizeChanged one is needed, since the layout change affects directly to the size of the sub controls.

This gives me a nice resolution and layout independant GUI, at least on S60 3rd edition devices. I think I may have to revisit it again for the 2nd edition port.

0 comments: