When palm button loses focus to board obj, post event to be handled

after focus event, and on handling it inval rect of focus ring on
button.  This fixes drawing glitch where palm remembers pixels behind
focus ring but they're not right.
This commit is contained in:
ehouse 2006-12-20 04:49:24 +00:00
parent bcf80fcdc9
commit b551142f5f
2 changed files with 54 additions and 32 deletions

View file

@ -1,4 +1,4 @@
/* -*-mode: C; fill-column: 77; c-basic-offset: 4; compile-command: "make ARCH=68K_ONLY MEMDEBUG=TRUE"; -*- */ /* -*-mode: C; fill-column: 77; c-basic-offset: 4; compile-command: "make ARCH=ARM_ONLY MEMDEBUG=TRUE"; -*- */
/* /*
* Copyright 1999 - 2004 by Eric House (xwords@eehouse.org). All rights reserved. * Copyright 1999 - 2004 by Eric House (xwords@eehouse.org). All rights reserved.
* *
@ -1090,6 +1090,7 @@ startApplication( PalmAppGlobals** globalsP )
getResString, getResString,
&globals->drawingPrefs ); &globals->drawingPrefs );
/* ifdef BLUETOOTH??? */
if ( !globals->gState.reserved1 ) { if ( !globals->gState.reserved1 ) {
palmaskFromStrId( globals, STR_ABOUT_CONTENT, STR_ABOUT_TITLE ); palmaskFromStrId( globals, STR_ABOUT_CONTENT, STR_ABOUT_TITLE );
globals->gState.reserved1 = XP_TRUE; globals->gState.reserved1 = XP_TRUE;
@ -2042,15 +2043,37 @@ hresRect( PalmAppGlobals* globals, RectangleType* r )
} }
#ifdef XWFEATURE_FIVEWAY #ifdef XWFEATURE_FIVEWAY
static void
invalRectAroundButton( PalmAppGlobals* globals, XP_U16 objectID )
{
RectangleType rect;
getObjectBounds( objectID, &rect );
rect.topLeft.x -= 3;
rect.topLeft.y -= 3;
rect.extent.x += 6;
rect.extent.y += 6;
hresRect( globals, &rect );
board_invalRect( globals->game.board, (XP_Rect*)&rect );
}
static XP_Bool
isBoardObject( XP_U16 id )
{
return id == XW_BOARD_GADGET_ID
|| id == XW_SCOREBOARD_GADGET_ID
|| id == XW_TRAY_GADGET_ID;
}
static XP_Bool static XP_Bool
handleFocusEvent( PalmAppGlobals* globals, const EventType* event, handleFocusEvent( PalmAppGlobals* globals, const EventType* event,
XP_Bool* drawP ) XP_Bool* drawP )
{ {
XP_Bool handled = XP_FALSE;
XP_Bool redraw = XP_FALSE;
XP_U16 objectID = event->data.frmObjectFocusTake.objectID; XP_U16 objectID = event->data.frmObjectFocusTake.objectID;
XP_Bool isBoardObj = isBoardObject( objectID );
XP_Bool take; XP_Bool take;
XP_Bool drawBoard = XP_FALSE; BoardObjectType typ;
XP_ASSERT( &event->data.frmObjectFocusTake.objectID XP_ASSERT( &event->data.frmObjectFocusTake.objectID
== &event->data.frmObjectFocusLost.objectID ); == &event->data.frmObjectFocusLost.objectID );
@ -2059,39 +2082,32 @@ handleFocusEvent( PalmAppGlobals* globals, const EventType* event,
/* XP_LOGF( "%s(%s,%s)", __FUNCTION__, frmObjId_2str(objectID), */ /* XP_LOGF( "%s(%s,%s)", __FUNCTION__, frmObjId_2str(objectID), */
/* (take? "take":"lost") ); */ /* (take? "take":"lost") ); */
switch ( objectID ) { /* Need to invalidate the neighborhood of buttons on which palm draws the
case XW_BOARD_GADGET_ID: focus ring when they lose focus -- to redraw where the focus ring may
case XW_SCOREBOARD_GADGET_ID: have been. No need unless we have the focus now, however, since we'll
case XW_TRAY_GADGET_ID: otherwise have drawn the object correctly (unfocussed). */
handled = XP_TRUE;
drawBoard = !take;
break;
case XW_MAIN_DONE_BUTTON_ID: if ( (!take) && (!isBoardObj) && isBoardObject( getFocusOwner() ) ) {
case XW_MAIN_JUGGLE_BUTTON_ID: EventType event;
case XW_MAIN_TRADE_BUTTON_ID: event.eType = updateAfterFocusEvent;
case XW_MAIN_HIDE_BUTTON_ID: event.data.generic.datum[0] = objectID;
redraw = XP_TRUE; EvtAddEventToQueue( &event );
break;
} }
if ( handled ) { /* Board needs to know about any change involving it, including something
BoardObjectType typ = (objectID - XW_BOARD_GADGET_ID) + OBJ_BOARD; else taking the focus it may think it has. Why? Because takes
drawBoard = board_focusChanged( globals->game.board, typ, take ) preceed losses, yet the board must draw itself without focus before
|| drawBoard; some button draws itself with focus and snags as part of the
if ( take ) { background the board in focussed state. */
typ = isBoardObj? OBJ_BOARD + (objectID - XW_BOARD_GADGET_ID) : OBJ_NONE;
*drawP = board_focusChanged( globals->game.board, typ, take );
if ( isBoardObj && take ) {
FrmSetFocus( globals->mainForm, FrmSetFocus( globals->mainForm,
FrmGetObjectIndex( globals->mainForm, objectID ) ); FrmGetObjectIndex( globals->mainForm, objectID ) );
} }
}
if ( redraw ) {
drawBitmapButton( globals, XW_MAIN_HIDE_BUTTON_ID,
TRAY_BUTTONS_BMP_RES_ID, XP_FALSE );
}
*drawP = drawBoard; return isBoardObj;
return handled;
} /* handleFocusEvent */ } /* handleFocusEvent */
#endif #endif
@ -2191,6 +2207,11 @@ mainViewHandleEvent( EventPtr event )
FrmUpdateForm( 0, frmRedrawUpdateCode ); /* <- why is this necessary? */ FrmUpdateForm( 0, frmRedrawUpdateCode ); /* <- why is this necessary? */
break; break;
case updateAfterFocusEvent:
invalRectAroundButton( globals, event->data.generic.datum[0] );
draw = XP_TRUE;
break;
case winExitEvent: case winExitEvent:
if ( event->data.winExit.exitWindow == (WinHandle)FrmGetActiveForm() ) { if ( event->data.winExit.exitWindow == (WinHandle)FrmGetActiveForm() ) {
globals->menuIsDown = true; globals->menuIsDown = true;

View file

@ -340,6 +340,7 @@ enum { dictSelectedEvent = firstUserEvent /* 0x6000 */
,loadGameEvent ,loadGameEvent
,prefsChangedEvent ,prefsChangedEvent
,openSavedGameEvent ,openSavedGameEvent
,updateAfterFocusEvent
#if defined XWFEATURE_BLUETOOTH || defined XWFEATURE_RELAY #if defined XWFEATURE_BLUETOOTH || defined XWFEATURE_RELAY
,connsSettingChgEvent ,connsSettingChgEvent
#endif #endif