/* * Call UpdateMostList to update the movelist in the GTK hint window. * For example, after new evaluations, rollouts or toggle of MWC/Equity. * */ extern void MoveListUpdate ( const hintdata *phd ) { unsigned int i, j, colNum; char sz[ 32 ]; cubeinfo ci; movelist *pml = phd->pml; int col = phd->fDetails ? 8 : 2; int showWLTree = showMoveListDetail && !phd->fDetails; int offset = (phd->fDetails) ? 0 : MIN_COLUMN_COUNT - DETAIL_COLUMN_COUNT; GtkTreeIter iter; GtkListStore *store; store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(phd->pwMoves))); gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter); if (!psHighlight) { /* Get highlight style first time in */ GtkStyle *psTemp; GtkStyle *psMoves = gtk_widget_get_style(phd->pwMoves); GetStyleFromRCFile(&psHighlight, "move-done", psMoves); /* Use correct background colour when selected */ memcpy(&psHighlight->bg[GTK_STATE_SELECTED], &psMoves->bg[GTK_STATE_SELECTED], sizeof(GdkColor)); /* Also get colour to use for w/l stats in detail view */ GetStyleFromRCFile(&psTemp, "move-winlossfg", psMoves); memcpy(&wlCol, &psTemp->fg[GTK_STATE_NORMAL], sizeof(GdkColor)); g_object_unref(psTemp); } /* This function should only be called when the game state matches the move list. */ g_assert( ms.fMove == 0 || ms.fMove == 1 ); GetMatchStateCubeInfo( &ci, &ms ); rBest = pml->amMoves[ 0 ].rScore; if (!showWLTree) gtk_tree_view_column_set_title(gtk_tree_view_get_column(GTK_TREE_VIEW(phd->pwMoves), col), (fOutputMWC && ms.nMatchTo) ? _("MWC") : _("Equity")); for( i = 0; i < pml->cMoves; i++ ) { float *ar = pml->amMoves[ i ].arEvalMove; int rankKnown; char *highlight_sz; if (showWLTree) gtk_list_store_set(store, &iter, 0, pml->amMoves + i, -1); else gtk_list_store_set(store, &iter, ML_COL_DATA + offset, pml->amMoves + i, -1); rankKnown = 1; if( i && i == pml->cMoves - 1 && phd->piHighlight && i == *phd->piHighlight ) /* The move made is the last on the list. Some moves might have been deleted to fit this one in */ { /* Lets count how many moves are possible to see if this is the last move */ movelist ml; int dice[2]; memcpy(dice, ms.anDice, sizeof(dice)); if (!dice[0]) { /* If the dice have got lost, try to find them */ moverecord* pmr = (moverecord*)plLastMove->plNext->p; if (pmr) { dice[0] = pmr->anDice[0]; dice[1] = pmr->anDice[1]; } } GenerateMoves(&ml, msBoard(), dice[0], dice[1], FALSE); if (i < ml.cMoves - 1) rankKnown = 0; } highlight_sz = (phd->piHighlight && *phd->piHighlight == i) ? "*" : ""; if (rankKnown) sprintf( sz, "%s%s%d", pml->amMoves[i].cmark ? "+" : "", highlight_sz, i + 1 ); else sprintf( sz, "%s%s??", pml->amMoves[i].cmark ? "+" : "", highlight_sz ); if (showWLTree) { gtk_list_store_set(store, &iter, 1, rankKnown ? (int)i + 1 : -1, -1); goto skipoldcode; } else gtk_list_store_set(store, &iter, ML_COL_RANK, sz, -1); FormatEval( sz, &pml->amMoves[ i ].esMove ); gtk_list_store_set(store, &iter, ML_COL_TYPE, sz, -1); /* gwc */ if ( phd->fDetails ) { colNum = ML_COL_WIN; for( j = 0; j < 5; j++ ) { if (j == 3) { gtk_list_store_set(store, &iter, colNum, OutputPercent(1.0f - ar[ OUTPUT_WIN ] ), -1); colNum++; } gtk_list_store_set(store, &iter, colNum, OutputPercent(ar[j]), -1); colNum++; } } /* cubeless equity */ gtk_list_store_set(store, &iter, ML_COL_EQUITY + offset, OutputEquity( pml->amMoves[ i ].rScore, &ci, TRUE ), -1); if (i != 0) { gtk_list_store_set(store, &iter, ML_COL_DIFF + offset, OutputEquityDiff( pml->amMoves[ i ].rScore, rBest, &ci ), -1); } gtk_list_store_set(store, &iter, ML_COL_MOVE + offset, FormatMove( sz, msBoard(), pml->amMoves[ i ].anMove ), -1); /* highlight row */ if (phd->piHighlight && *phd->piHighlight == i) { char buf[20]; sprintf(buf, "#%02x%02x%02x", psHighlight->fg[GTK_STATE_SELECTED].red / 256, psHighlight->fg[GTK_STATE_SELECTED].green / 256, psHighlight->fg[GTK_STATE_SELECTED].blue / 256); gtk_list_store_set(store, &iter, ML_COL_FGCOL + offset, buf, -1); } else gtk_list_store_set(store, &iter, ML_COL_FGCOL + offset, NULL, -1); skipoldcode: /* Messy as 3 copies of code at moment... */ gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter); } }
extern GtkWidget* GL_Create(void) { GtkStyle *ps; gint nMaxWidth; char *asz[] = {NULL, NULL, NULL}; PangoRectangle logical_rect; PangoLayout *layout; asz[0] = _("#"); pwGameList = gtk_clist_new_with_titles(3, asz); gtk_widget_set_can_focus (pwGameList, FALSE); gtk_clist_set_selection_mode( GTK_CLIST( pwGameList ), GTK_SELECTION_BROWSE ); gtk_clist_column_titles_passive( GTK_CLIST( pwGameList ) ); GL_SetNames(); gtk_clist_set_column_justification( GTK_CLIST( pwGameList ), 0, GTK_JUSTIFY_RIGHT ); gtk_clist_set_column_resizeable( GTK_CLIST( pwGameList ), 0, FALSE ); gtk_clist_set_column_resizeable( GTK_CLIST( pwGameList ), 1, FALSE ); gtk_clist_set_column_resizeable( GTK_CLIST( pwGameList ), 2, FALSE ); gtk_widget_ensure_style( pwGameList ); GetStyleFromRCFile(&ps, "gnubg", gtk_widget_get_style( pwGameList ) ); ps->base[ GTK_STATE_SELECTED ] = ps->base[ GTK_STATE_ACTIVE ] = ps->base[ GTK_STATE_NORMAL ] = gtk_widget_get_style( pwGameList )->base[ GTK_STATE_NORMAL ]; ps->fg[ GTK_STATE_SELECTED ] = ps->fg[ GTK_STATE_ACTIVE ] = ps->fg[ GTK_STATE_NORMAL ] = gtk_widget_get_style( pwGameList )->fg[ GTK_STATE_NORMAL ]; gtk_widget_set_style( pwGameList, ps ); psGameList = gtk_style_copy( ps ); psGameList->bg[ GTK_STATE_SELECTED ] = psGameList->bg[ GTK_STATE_NORMAL ] = ps->base[ GTK_STATE_NORMAL ]; psCurrent = gtk_style_copy( psGameList ); psCurrent->bg[ GTK_STATE_SELECTED ] = psCurrent->bg[ GTK_STATE_NORMAL ] = psCurrent->base[ GTK_STATE_SELECTED ] = psCurrent->base[ GTK_STATE_NORMAL ] = psGameList->fg[ GTK_STATE_NORMAL ]; psCurrent->fg[ GTK_STATE_SELECTED ] = psCurrent->fg[ GTK_STATE_NORMAL ] = psGameList->bg[ GTK_STATE_NORMAL ]; GetStyleFromRCFile(&psCubeErrors[SKILL_VERYBAD], "gamelist-cube-blunder", psGameList); GetStyleFromRCFile(&psCubeErrors[SKILL_BAD], "gamelist-cube-error", psGameList); GetStyleFromRCFile(&psCubeErrors[SKILL_DOUBTFUL], "gamelist-cube-doubtful", psGameList); GetStyleFromRCFile(&psChequerErrors[SKILL_VERYBAD], "gamelist-chequer-blunder", psGameList); GetStyleFromRCFile(&psChequerErrors[SKILL_BAD], "gamelist-chequer-error", psGameList); GetStyleFromRCFile(&psChequerErrors[SKILL_DOUBTFUL], "gamelist-chequer-doubtful", psGameList); GetStyleFromRCFile(&psLucky[LUCK_VERYBAD], "gamelist-luck-bad", psGameList); GetStyleFromRCFile(&psLucky[LUCK_VERYGOOD], "gamelist-luck-good", psGameList); layout = gtk_widget_create_pango_layout(pwGameList, "99"); pango_layout_get_pixel_extents (layout, NULL, &logical_rect); g_object_unref (layout); nMaxWidth = logical_rect.width; gtk_clist_set_column_width( GTK_CLIST( pwGameList ), 0, nMaxWidth ); layout = gtk_widget_create_pango_layout(pwGameList, " (set board AAAAAAAAAAAAAA)"); pango_layout_get_pixel_extents (layout, NULL, &logical_rect); g_object_unref (layout); nMaxWidth = logical_rect.width; gtk_clist_set_column_width( GTK_CLIST( pwGameList ), 1, nMaxWidth - 30); gtk_clist_set_column_width( GTK_CLIST( pwGameList ), 2, nMaxWidth - 30); g_signal_connect( G_OBJECT( pwGameList ), "select-row", G_CALLBACK( GameListSelectRow ), NULL ); return pwGameList; }