From 4425eaa99e47aa5f4d2d7350b00c18affc23c13a Mon Sep 17 00:00:00 2001 From: ehouse Date: Tue, 26 Jan 2010 04:14:18 +0000 Subject: [PATCH] move showColors into CommonPrefs, removing separate storage in linux and wince and removing setter from board and jni APIs. Palm change pending. --- .../eehouse/android/xw4/jni/JNIThread.java | 2 -- .../org/eehouse/android/xw4/jni/XwJNI.java | 1 - xwords4/android/xwjni.c | 9 -------- xwords4/common/board.c | 19 +++++++++-------- xwords4/common/board.h | 2 -- xwords4/common/comtypes.h | 1 + xwords4/linux/gtkmain.c | 2 +- xwords4/linux/linuxmain.c | 1 + xwords4/linux/main.h | 1 + xwords4/wince/cemain.c | 21 +++++++------------ xwords4/wince/cemain.h | 21 +++++++++++++++++-- xwords4/wince/ceprefs.c | 2 -- 12 files changed, 40 insertions(+), 42 deletions(-) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/JNIThread.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/JNIThread.java index 1011ff198..887d2fe7c 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/JNIThread.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/JNIThread.java @@ -132,8 +132,6 @@ public class JNIThread extends Thread { trayHt, // height 4 ); - XwJNI.board_setShowColors( m_jniGamePtr, true ); // get from prefs! - XwJNI.board_invalAll( m_jniGamePtr ); } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/XwJNI.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/XwJNI.java index ab53fc11a..46e08f5e4 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/XwJNI.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/XwJNI.java @@ -51,7 +51,6 @@ public class XwJNI { public static native void board_setPos( int gamePtr, int left, int top, boolean lefty ); public static native void board_setScale( int gamePtr, int hscale, int vscale ); - public static native boolean board_setShowColors( int gamePtr, boolean on ); public static native void board_setScoreboardLoc( int gamePtr, int left, int top, int width, int height, diff --git a/xwords4/android/xwjni.c b/xwords4/android/xwjni.c index b4f236cb8..fd3a76290 100644 --- a/xwords4/android/xwjni.c +++ b/xwords4/android/xwjni.c @@ -415,15 +415,6 @@ Java_org_eehouse_android_xw4_jni_XwJNI_board_1setScale XWJNI_END(); } -JNIEXPORT jboolean JNICALL -Java_org_eehouse_android_xw4_jni_XwJNI_board_1setShowColors -( JNIEnv *env, jclass C, jint gamePtr, jboolean on ) -{ - XWJNI_START(); - board_setShowColors( state->game.board, on ); - XWJNI_END(); -} - JNIEXPORT void JNICALL Java_org_eehouse_android_xw4_jni_XwJNI_board_1setScoreboardLoc ( JNIEnv *env, jclass C, jint gamePtr, jint left, jint top, diff --git a/xwords4/common/board.c b/xwords4/common/board.c index 97682e1b4..c272801ab 100644 --- a/xwords4/common/board.c +++ b/xwords4/common/board.c @@ -90,6 +90,8 @@ static void setArrowFor( BoardCtxt* board, XP_U16 player, XP_U16 col, static XP_Bool setArrowVisible( BoardCtxt* board, XP_Bool visible ); static void invalTradeWindow( BoardCtxt* board, XP_S16 turn, XP_Bool redraw ); +static XP_Bool invalCellsWithTiles( BoardCtxt* board ); + static void setTimerIf( BoardCtxt* board ); static XP_Bool p_board_timerFired( void* closure, XWTimerReason why ); @@ -388,13 +390,16 @@ board_prefsChanged( BoardCtxt* board, CommonPrefs* cp ) { XP_Bool showArrowChanged; XP_Bool hideValChanged; + XP_Bool showColorsChanged; showArrowChanged = cp->showBoardArrow == board->disableArrow; hideValChanged = cp->hideTileValues != board->hideValsInTray; + showColorsChanged = board->showColors != cp->showColors; board->disableArrow = !cp->showBoardArrow; board->hideValsInTray = cp->hideTileValues; board->skipCommitConfirm = cp->skipCommitConfirm; + board->showColors = cp->showColors; if ( showArrowChanged ) { showArrowChanged = setArrowVisible( board, XP_FALSE ); @@ -402,6 +407,10 @@ board_prefsChanged( BoardCtxt* board, CommonPrefs* cp ) if ( hideValChanged ) { board_invalTrayTiles( board, ALLTILES ); } + if ( showColorsChanged ) { + board->scoreBoardInvalid = XP_TRUE; + showColorsChanged = invalCellsWithTiles( board ); + } #ifdef XWFEATURE_SEARCHLIMIT if ( !board->gi->allowHintRect && board->selInfo->hasHintRect ) { @@ -416,7 +425,7 @@ board_prefsChanged( BoardCtxt* board, CommonPrefs* cp ) } #endif - return showArrowChanged || hideValChanged; + return showArrowChanged || hideValChanged || showColorsChanged; } /* board_prefsChanged */ XP_Bool @@ -1399,14 +1408,6 @@ board_toggle_showValues( BoardCtxt* board ) return invalCellsWithTiles( board ) || changed; } /* board_toggle_showValues */ -XP_Bool -board_setShowColors( BoardCtxt* board, XP_Bool showColors ) -{ - board->showColors = showColors; - board->scoreBoardInvalid = XP_TRUE; - return invalCellsWithTiles( board ); -} /* board_setShowColors */ - XP_Bool board_replaceTiles( BoardCtxt* board ) { diff --git a/xwords4/common/board.h b/xwords4/common/board.h index 88091fb46..63d3252c2 100644 --- a/xwords4/common/board.h +++ b/xwords4/common/board.h @@ -93,8 +93,6 @@ XP_Bool board_get_flipped( const BoardCtxt* board ); XP_Bool board_flip( BoardCtxt* board ); XP_Bool board_get_showValues( const BoardCtxt* board ); XP_Bool board_toggle_showValues( BoardCtxt* board ); -XP_Bool board_getShowColors( BoardCtxt* board ); -XP_Bool board_setShowColors( BoardCtxt* board, XP_Bool showColors ); XP_Bool board_replaceTiles( BoardCtxt* board ); XP_Bool board_requestHint( BoardCtxt* board, diff --git a/xwords4/common/comtypes.h b/xwords4/common/comtypes.h index 8c58253fa..8322cbc28 100644 --- a/xwords4/common/comtypes.h +++ b/xwords4/common/comtypes.h @@ -133,6 +133,7 @@ typedef struct CommonPrefs { #ifdef XWFEATURE_SLOW_ROBOT XP_U16 robotThinkMin, robotThinkMax; #endif + XP_Bool showColors; /* applies to all games */ } CommonPrefs; #ifdef XWFEATURE_BLUETOOTH diff --git a/xwords4/linux/gtkmain.c b/xwords4/linux/gtkmain.c index 9fb489dde..311ddd5bb 100644 --- a/xwords4/linux/gtkmain.c +++ b/xwords4/linux/gtkmain.c @@ -543,7 +543,6 @@ configure_event( GtkWidget* widget, GdkEventConfigure* XP_UNUSED(event), board_setPos( globals->cGlobals.game.board, GTK_BOARD_LEFT, boardTop, XP_FALSE ); board_setScale( globals->cGlobals.game.board, hscale, vscale ); - board_setShowColors( globals->cGlobals.game.board, XP_TRUE ); globals->gridOn = XP_TRUE; if ( !!globals->cGlobals.game.comms ) { @@ -2014,6 +2013,7 @@ gtkmain( LaunchParams* params, int argc, char *argv[] ) globals.cp.showBoardArrow = XP_TRUE; globals.cp.hideTileValues = params->hideValues; globals.cp.skipCommitConfirm = params->skipCommitConfirm; + globals.cp.showColors = params->showColors; globals.cp.showRobotScores = params->showRobotScores; #ifdef XWFEATURE_SLOW_ROBOT globals.cp.robotThinkMin = params->robotThinkMin; diff --git a/xwords4/linux/linuxmain.c b/xwords4/linux/linuxmain.c index 5caadee6b..df7d1055e 100644 --- a/xwords4/linux/linuxmain.c +++ b/xwords4/linux/linuxmain.c @@ -778,6 +778,7 @@ main( int argc, char** argv ) mainParams.allowHintRect = XP_TRUE; #endif mainParams.skipCommitConfirm = XP_TRUE; + mainParams.showColors = XP_TRUE; /* serverName = mainParams.info.clientInfo.serverName = "localhost"; */ diff --git a/xwords4/linux/main.h b/xwords4/linux/main.h index a001e9fbc..204b4a94c 100644 --- a/xwords4/linux/main.h +++ b/xwords4/linux/main.h @@ -58,6 +58,7 @@ typedef struct LaunchParams { XP_Bool undoWhenDone; XP_Bool verticalScore; XP_Bool hideValues; + XP_Bool showColors; XP_Bool skipCommitConfirm; XP_Bool needsNewGame; // XP_Bool mainParams; diff --git a/xwords4/wince/cemain.c b/xwords4/wince/cemain.c index af4e64a89..0a5147767 100755 --- a/xwords4/wince/cemain.c +++ b/xwords4/wince/cemain.c @@ -812,7 +812,6 @@ cePositionBoard( CEAppGlobals* globals ) board_setScoreboardLoc( globals->game.board, bparms.adjLeft, bparms.adjTop, bparms.scoreWidth, bparms.scoreHeight, bparms.horiz ); - board_setShowColors( globals->game.board, globals->appPrefs.showColors ); board_setYOffset( globals->game.board, 0 ); board_prefsChanged( globals->game.board, &globals->appPrefs.cp ); @@ -1042,23 +1041,17 @@ canUpdatePrefs( CEAppGlobals* globals, HANDLE fileH, XP_U16 curVersion, CEAppPrefs* prefs ) { XP_Bool success = XP_FALSE; - LOG_FUNC(); - if ( (curVersion == 0x0002) && (CUR_CE_PREFS_FLAGS == 0x0003) ) { - CEAppPrefs0002 oldPrefs; + if ( curVersion == 0x0003 && CUR_CE_PREFS_FLAGS == 0x0004 ) { + /* common prefs has gotten bigger, pushing colors down. */ + CEAppPrefs0003 oldPrefs; XP_U32 nRead; if ( ReadFile( fileH, &oldPrefs, sizeof(oldPrefs), &nRead, NULL ) ) { ceInitPrefs( globals, prefs ); - XP_MEMCPY( &prefs->cp, &oldPrefs.cp, sizeof(prefs->cp) ); - prefs->showColors = oldPrefs.showColors; + XP_MEMCPY( &prefs->cp, &oldPrefs.cp, sizeof(oldPrefs.cp) ); + prefs->cp.showColors = oldPrefs.showColors; + prefs->fullScreen = oldPrefs.fullScreen; - XP_MEMCPY( &prefs->colors[0], &oldPrefs.colors[0], - CE_FOCUS_COLOR*sizeof(prefs->colors[0])); - XP_ASSERT( CE_PLAYER0_COLOR - 1 == CE_FOCUS_COLOR ); - XP_MEMCPY( &prefs->colors[CE_PLAYER0_COLOR], - &oldPrefs.colors[CE_FOCUS_COLOR], - (CE_NUM_COLORS-CE_PLAYER0_COLOR) - * sizeof(prefs->colors[0])); success = XP_TRUE; } else { XP_LOGF( "%s: ReadFile bad", __func__ ); @@ -1269,11 +1262,11 @@ static void ceInitPrefs( CEAppGlobals* globals, CEAppPrefs* prefs ) { prefs->versionFlags = CUR_CE_PREFS_FLAGS; - prefs->showColors = XP_TRUE; prefs->fullScreen = XP_FALSE; prefs->cp.showBoardArrow = XP_TRUE; prefs->cp.showRobotScores = XP_FALSE; + prefs->cp.showColors = XP_TRUE; colorsFromRsrc( globals, prefs ); } /* ceInitPrefs */ diff --git a/xwords4/wince/cemain.h b/xwords4/wince/cemain.h index 19f96fc29..e81e31e54 100755 --- a/xwords4/wince/cemain.h +++ b/xwords4/wince/cemain.h @@ -80,7 +80,8 @@ enum { CE_BONUS0_COLOR, CE_NUM_COLORS /* last */ }; -#define CUR_CE_PREFS_FLAGS 0x0003 /* adds CE_FOCUS_COLOR */ +// #define CUR_CE_PREFS_FLAGS 0x0003 /* adds CE_FOCUS_COLOR */ +#define CUR_CE_PREFS_FLAGS 0x0004 /* moves showColors into CommonPrefs */ /* This is what CEAppPrefs looked like for CUR_CE_PREFS_FLAGS == 0x0002 */ typedef struct CEAppPrefs0002 { @@ -90,6 +91,23 @@ typedef struct CEAppPrefs0002 { XP_Bool showColors; } CEAppPrefs0002; +/* This is what CEAppPrefs looked like for CUR_CE_PREFS_FLAGS == 0x0003 */ +typedef struct _CEAppPrefs0003 { + XP_U16 versionFlags; + struct { + XP_Bool showBoardArrow; /* applies to all games */ + XP_Bool showRobotScores; /* applies to all games */ + XP_Bool hideTileValues; + XP_Bool skipCommitConfirm; /* applies to all games */ +#ifdef XWFEATURE_SLOW_ROBOT + XP_U16 robotThinkMin, robotThinkMax; +#endif + } cp; + COLORREF colors[13]; + XP_Bool showColors; + XP_Bool fullScreen; +} CEAppPrefs0003; + typedef enum { SAB_NONE = 0 ,SAB_PHONEOFF = 1 << 0 @@ -105,7 +123,6 @@ typedef struct CEAppPrefs { XP_U16 versionFlags; CommonPrefs cp; COLORREF colors[CE_NUM_COLORS]; - XP_Bool showColors; XP_Bool fullScreen; } CEAppPrefs; diff --git a/xwords4/wince/ceprefs.c b/xwords4/wince/ceprefs.c index 8b6f721ec..90be83008 100755 --- a/xwords4/wince/ceprefs.c +++ b/xwords4/wince/ceprefs.c @@ -153,7 +153,6 @@ loadStateFromCurPrefs( CEAppGlobals* XP_UNUSED_STANDALONE(globals), #ifdef XWFEATURE_SEARCHLIMIT prefsPrefs->gp.allowHintRect = gi->allowHintRect; #endif - prefsPrefs->showColors = appPrefs->showColors; XP_MEMCPY( &prefsPrefs->cp, &appPrefs->cp, sizeof(prefsPrefs->cp) ); XP_MEMCPY( &prefsPrefs->colors, &appPrefs->colors, @@ -184,7 +183,6 @@ loadCurPrefsFromState( CEAppGlobals* XP_UNUSED_STANDALONE(globals), #ifdef XWFEATURE_SEARCHLIMIT gi->allowHintRect = prefsPrefs->gp.allowHintRect; #endif - appPrefs->showColors = prefsPrefs->showColors; XP_MEMCPY( &appPrefs->cp, &prefsPrefs->cp, sizeof(appPrefs->cp) ); XP_MEMCPY( &appPrefs->colors, &prefsPrefs->colors,