X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=winboard%2Fwinboard.c;h=5249c921ea4a542a70ef1f6408ea6af263d2a61d;hb=a009a27e8c1e0bfa818f12fdcae675d0babc510a;hp=722b9c819bca68abf33db830dbd03c500355ef05;hpb=6445f59125a3dff0cbb9426a0c0bd300a31075d1;p=xboard.git diff --git a/winboard/winboard.c b/winboard/winboard.c index 722b9c8..5249c92 100644 --- a/winboard/winboard.c +++ b/winboard/winboard.c @@ -5,7 +5,7 @@ * Massachusetts. * * Enhancements Copyright 1992-2001, 2002, 2003, 2004, 2005, 2006, - * 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc. + * 2007, 2008, 2009, 2010, 2011, 2012, 2013 Free Software Foundation, Inc. * * Enhancements Copyright 2005 Alessandro Scotti * @@ -100,8 +100,10 @@ extern int whiteFlag, blackFlag; Boolean flipClock = FALSE; extern HANDLE chatHandle[]; -extern int ics_type; +extern enum ICS_TYPE ics_type; +int MySearchPath P((char *installDir, char *name, char *fullname)); +int MyGetFullPathName P((char *name, char *fullname)); void DisplayHoldingsCount(HDC hdc, int x, int y, int align, int copyNumber); VOID NewVariantPopup(HWND hwnd); int FinishMove P((ChessMove moveType, int fromX, int fromY, int toX, int toY, @@ -156,14 +158,13 @@ char *programName; char *settingsFileName; Boolean saveSettingsOnExit; char installDir[MSG_SIZ]; -char homeDir[MSG_SIZ]; int errorExitStatus; BoardSize boardSize; Boolean chessProgram; //static int boardX, boardY; int minX, minY; // [HGM] placement: volatile limits on upper-left corner -int squareSize, lineGap, minorSize; +int squareSize, lineGap, minorSize, border; static int winW, winH; static RECT messageRect, whiteRect, blackRect, leftLogoRect, rightLogoRect; // [HGM] logo static int logoHeight = 0; @@ -250,11 +251,12 @@ Boolean barbaric; // flag indicating if translation is needed #define ABOUTBOX -1 /* not sure why these are needed */ #define ABOUTBOX2 -1 -int dialogItems[][40] = { +int dialogItems[][42] = { { ABOUTBOX, IDOK, OPT_MESS, 400 }, { DLG_TimeControl, IDC_Babble, OPT_TCUseMoves, OPT_TCUseInc, OPT_TCUseFixed, OPT_TCtext1, OPT_TCtext2, OPT_TCitext1, OPT_TCitext2, OPT_TCftext, GPB_Factors, IDC_Factor1, IDC_Factor2, IDOK, IDCANCEL }, -{ DLG_LoadOptions, OPT_Autostep, OPT_AStext1, IDOK, IDCANCEL }, +{ DLG_LoadOptions, OPT_Autostep, OPT_AStext1, OPT_Exact, OPT_Subset, OPT_Struct, OPT_Material, OPT_Range, OPT_Difference, + OPT_elo1t, OPT_elo2t, OPT_datet, OPT_Stretch, OPT_Stretcht, OPT_Reversed, OPT_SearchMode, OPT_Mirror, OPT_thresholds, IDOK, IDCANCEL }, { DLG_SaveOptions, OPT_Autosave, OPT_AVPrompt, OPT_AVToFile, OPT_AVBrowse, 801, OPT_PGN, OPT_Old, OPT_OutOfBookInfo, IDOK, IDCANCEL }, { 1536, 1090, IDC_Directories, 1089, 1091, IDOK, IDCANCEL, 1038, IDC_IndexNr, 1037 }, @@ -294,7 +296,7 @@ int dialogItems[][40] = { OPT_ChooseTellColor, OPT_ChooseChallengeColor, OPT_ChooseRequestColor, OPT_ChooseSeekColor, OPT_ChooseNormalColor, OPT_ChooseBackgroundColor, OPT_DefaultColors, OPT_DontColorize, IDC_Boxes, GPB_Colors, GPB_Premove, - GPB_General, GPB_Alarm }, + GPB_General, GPB_Alarm, OPT_AutoCreate }, { DLG_BoardOptions, IDOK, IDCANCEL, OPT_SizeTiny, OPT_SizeTeeny, OPT_SizeDinky, OPT_SizePetite, OPT_SizeSlim, OPT_SizeSmall, OPT_SizeMediocre, OPT_SizeMiddling, OPT_SizeAverage, OPT_SizeModerate, OPT_SizeMedium, OPT_SizeBulky, OPT_SizeLarge, @@ -302,7 +304,7 @@ int dialogItems[][40] = { OPT_ChooseLightSquareColor, OPT_ChooseDarkSquareColor, OPT_ChooseWhitePieceColor, OPT_ChooseBlackPieceColor, OPT_ChooseHighlightSquareColor, OPT_ChoosePremoveHighlightColor, OPT_Monochrome, OPT_AllWhite, OPT_UpsideDown, OPT_DefaultBoardColors, GPB_Colors, - IDC_Light, IDC_Dark, IDC_White, IDC_Black, IDC_High, IDC_PreHigh, GPB_Size }, + IDC_Light, IDC_Dark, IDC_White, IDC_Black, IDC_High, IDC_PreHigh, GPB_Size, OPT_Bitmaps, OPT_PieceFont, OPT_Grid }, { DLG_NewVariant, IDOK, IDCANCEL, OPT_VariantNormal, OPT_VariantFRC, OPT_VariantWildcastle, OPT_VariantNocastle, OPT_VariantLosers, OPT_VariantGiveaway, OPT_VariantSuicide, OPT_Variant3Check, OPT_VariantTwoKings, OPT_VariantAtomic, OPT_VariantCrazyhouse, @@ -314,7 +316,8 @@ int dialogItems[][40] = { IDC_Width, IDC_Hand, IDC_Pieces, IDC_Def }, { DLG_Fonts, IDOK, IDCANCEL, OPT_ChooseClockFont, OPT_ChooseMessageFont, OPT_ChooseCoordFont, OPT_ChooseTagFont, OPT_ChooseCommentsFont, OPT_ChooseConsoleFont, OPT_ChooseMoveHistoryFont, OPT_DefaultFonts, - OPT_ClockFont, OPT_MessageFont, OPT_CoordFont, OPT_EditTagsFont, + OPT_ClockFont, OPT_MessageFont, OPT_CoordFont, OPT_EditTagsFont, OPT_ChoosePieceFont, OPT_MessageFont8, + OPT_SampleGameListFont, OPT_ChooseGameListFont, OPT_MessageFont7, OPT_CommentsFont, OPT_MessageFont5, GPB_Current, GPB_All, OPT_MessageFont6 }, { DLG_NewGameFRC, IDC_NFG_Label, IDC_NFG_Random, IDOK, IDCANCEL }, { DLG_GameListOptions, IDC_GLT, IDC_GLT_Up, IDC_GLT_Down, IDC_GLT_Restore, @@ -333,7 +336,7 @@ int dialogItems[][40] = { { 0 } }; -static char languageBuf[50000], *foreign[1000], *english[1000], *languageFile[MSG_SIZ]; +static char languageBuf[70000], *foreign[1000], *english[1000], *languageFile[MSG_SIZ]; static int lastChecked; static char oldLanguage[MSG_SIZ], *menuText[10][30]; extern int tinyLayout; @@ -387,11 +390,16 @@ T_(char *s) { // return the translation of the given string // efficiency can be improved a lot... int i=0; + static char buf[MSG_SIZ]; //if(appData.debugMode) fprintf(debugFP, "T_(%s)\n", s); if(!barbaric) return s; if(!s) return ""; // sanity while(english[i]) { if(!strcmp(s, english[i])) return foreign[i]; + if(english[i][0] == '%' && strstr(s, english[i]+1) == s) { // allow translation of strings with variable ending + snprintf(buf, MSG_SIZ, "%s%s", foreign[i], s + strlen(english[i]+1)); // keep unmatched portion + return buf; + } i++; } return s; @@ -429,7 +437,7 @@ TranslateOneMenu(int i, HMENU subMenu) info.dwTypeData = buf; info.cch = sizeof(buf); GetMenuItemInfo(subMenu, j, TRUE, &info); - if(i < 10) { + if(i < 10) { if(menuText[i][j]) safeStrCpy(buf, menuText[i][j], sizeof(buf)/sizeof(buf[0]) ); else menuText[i][j] = strdup(buf); // remember original on first change } @@ -486,6 +494,30 @@ TranslateMenus(int addLanguage) #endif +#define IDM_RecentEngines 3000 + +void +RecentEngineMenu (char *s) +{ + if(appData.icsActive) return; + if(appData.recentEngines > 0 && *s) { // feature is on, and list non-empty + HMENU mainMenu = GetMenu(hwndMain); + HMENU subMenu = GetSubMenu(mainMenu, 5); // Engine menu + int i=IDM_RecentEngines; + recentEngines = strdup(appData.recentEngineList); // remember them as they are in menu + AppendMenu(subMenu, MF_SEPARATOR, (UINT_PTR) 0, NULL); + while(*s) { + char *p = strchr(s, '\n'); + if(p == NULL) return; // malformed! + *p = NULLCHAR; + AppendMenu(subMenu, MF_ENABLED|MF_STRING|MF_UNCHECKED, (UINT_PTR) i++, (LPCTSTR) s); + *p = '\n'; + s = p+1; + } + } +} + + typedef struct { char *name; int squareSize; @@ -521,24 +553,24 @@ SizeInfo sizeInfo[] = #define MF(x) {x, {{0,}, 0. }, {0, }, 0} MyFont fontRec[NUM_SIZES][NUM_FONTS] = { - { MF(CLOCK_FONT_TINY), MF(MESSAGE_FONT_TINY), MF(COORD_FONT_TINY), MF(CONSOLE_FONT_TINY), MF(COMMENT_FONT_TINY), MF(EDITTAGS_FONT_TINY), MF(MOVEHISTORY_FONT_ALL) }, - { MF(CLOCK_FONT_TEENY), MF(MESSAGE_FONT_TEENY), MF(COORD_FONT_TEENY), MF(CONSOLE_FONT_TEENY), MF(COMMENT_FONT_TEENY), MF(EDITTAGS_FONT_TEENY), MF(MOVEHISTORY_FONT_ALL) }, - { MF(CLOCK_FONT_DINKY), MF(MESSAGE_FONT_DINKY), MF(COORD_FONT_DINKY), MF(CONSOLE_FONT_DINKY), MF(COMMENT_FONT_DINKY), MF(EDITTAGS_FONT_DINKY), MF(MOVEHISTORY_FONT_ALL) }, - { MF(CLOCK_FONT_PETITE), MF(MESSAGE_FONT_PETITE), MF(COORD_FONT_PETITE), MF(CONSOLE_FONT_PETITE), MF(COMMENT_FONT_PETITE), MF(EDITTAGS_FONT_PETITE), MF(MOVEHISTORY_FONT_ALL) }, - { MF(CLOCK_FONT_SLIM), MF(MESSAGE_FONT_SLIM), MF(COORD_FONT_SLIM), MF(CONSOLE_FONT_SLIM), MF(COMMENT_FONT_SLIM), MF(EDITTAGS_FONT_SLIM), MF(MOVEHISTORY_FONT_ALL) }, - { MF(CLOCK_FONT_SMALL), MF(MESSAGE_FONT_SMALL), MF(COORD_FONT_SMALL), MF(CONSOLE_FONT_SMALL), MF(COMMENT_FONT_SMALL), MF(EDITTAGS_FONT_SMALL), MF(MOVEHISTORY_FONT_ALL) }, - { MF(CLOCK_FONT_MEDIOCRE), MF(MESSAGE_FONT_MEDIOCRE), MF(COORD_FONT_MEDIOCRE), MF(CONSOLE_FONT_MEDIOCRE), MF(COMMENT_FONT_MEDIOCRE), MF(EDITTAGS_FONT_MEDIOCRE), MF(MOVEHISTORY_FONT_ALL) }, - { MF(CLOCK_FONT_MIDDLING), MF(MESSAGE_FONT_MIDDLING), MF(COORD_FONT_MIDDLING), MF(CONSOLE_FONT_MIDDLING), MF(COMMENT_FONT_MIDDLING), MF(EDITTAGS_FONT_MIDDLING), MF(MOVEHISTORY_FONT_ALL) }, - { MF(CLOCK_FONT_AVERAGE), MF(MESSAGE_FONT_AVERAGE), MF(COORD_FONT_AVERAGE), MF(CONSOLE_FONT_AVERAGE), MF(COMMENT_FONT_AVERAGE), MF(EDITTAGS_FONT_AVERAGE), MF(MOVEHISTORY_FONT_ALL) }, - { MF(CLOCK_FONT_MODERATE), MF(MESSAGE_FONT_MODERATE), MF(COORD_FONT_MODERATE), MF(CONSOLE_FONT_MODERATE), MF(COMMENT_FONT_MODERATE), MF(EDITTAGS_FONT_MODERATE), MF(MOVEHISTORY_FONT_ALL) }, - { MF(CLOCK_FONT_MEDIUM), MF(MESSAGE_FONT_MEDIUM), MF(COORD_FONT_MEDIUM), MF(CONSOLE_FONT_MEDIUM), MF(COMMENT_FONT_MEDIUM), MF(EDITTAGS_FONT_MEDIUM), MF(MOVEHISTORY_FONT_ALL) }, - { MF(CLOCK_FONT_BULKY), MF(MESSAGE_FONT_BULKY), MF(COORD_FONT_BULKY), MF(CONSOLE_FONT_BULKY), MF(COMMENT_FONT_BULKY), MF(EDITTAGS_FONT_BULKY), MF(MOVEHISTORY_FONT_ALL) }, - { MF(CLOCK_FONT_LARGE), MF(MESSAGE_FONT_LARGE), MF(COORD_FONT_LARGE), MF(CONSOLE_FONT_LARGE), MF(COMMENT_FONT_LARGE), MF(EDITTAGS_FONT_LARGE), MF(MOVEHISTORY_FONT_ALL) }, - { MF(CLOCK_FONT_BIG), MF(MESSAGE_FONT_BIG), MF(COORD_FONT_BIG), MF(CONSOLE_FONT_BIG), MF(COMMENT_FONT_BIG), MF(EDITTAGS_FONT_BIG), MF(MOVEHISTORY_FONT_ALL) }, - { MF(CLOCK_FONT_HUGE), MF(MESSAGE_FONT_HUGE), MF(COORD_FONT_HUGE), MF(CONSOLE_FONT_HUGE), MF(COMMENT_FONT_HUGE), MF(EDITTAGS_FONT_HUGE), MF(MOVEHISTORY_FONT_ALL) }, - { MF(CLOCK_FONT_GIANT), MF(MESSAGE_FONT_GIANT), MF(COORD_FONT_GIANT), MF(CONSOLE_FONT_GIANT), MF(COMMENT_FONT_GIANT), MF(EDITTAGS_FONT_GIANT), MF(MOVEHISTORY_FONT_ALL) }, - { MF(CLOCK_FONT_COLOSSAL), MF(MESSAGE_FONT_COLOSSAL), MF(COORD_FONT_COLOSSAL), MF(CONSOLE_FONT_COLOSSAL), MF(COMMENT_FONT_COLOSSAL), MF(EDITTAGS_FONT_COLOSSAL), MF(MOVEHISTORY_FONT_ALL) }, - { MF(CLOCK_FONT_TITANIC), MF(MESSAGE_FONT_TITANIC), MF(COORD_FONT_TITANIC), MF(CONSOLE_FONT_TITANIC), MF(COMMENT_FONT_TITANIC), MF(EDITTAGS_FONT_TITANIC), MF(MOVEHISTORY_FONT_ALL) }, + { MF(CLOCK_FONT_TINY), MF(MESSAGE_FONT_TINY), MF(COORD_FONT_TINY), MF(CONSOLE_FONT_TINY), MF(COMMENT_FONT_TINY), MF(EDITTAGS_FONT_TINY), MF(MOVEHISTORY_FONT_ALL), MF(GAMELIST_FONT_ALL) }, + { MF(CLOCK_FONT_TEENY), MF(MESSAGE_FONT_TEENY), MF(COORD_FONT_TEENY), MF(CONSOLE_FONT_TEENY), MF(COMMENT_FONT_TEENY), MF(EDITTAGS_FONT_TEENY), MF(MOVEHISTORY_FONT_ALL), MF(GAMELIST_FONT_ALL) }, + { MF(CLOCK_FONT_DINKY), MF(MESSAGE_FONT_DINKY), MF(COORD_FONT_DINKY), MF(CONSOLE_FONT_DINKY), MF(COMMENT_FONT_DINKY), MF(EDITTAGS_FONT_DINKY), MF(MOVEHISTORY_FONT_ALL), MF(GAMELIST_FONT_ALL) }, + { MF(CLOCK_FONT_PETITE), MF(MESSAGE_FONT_PETITE), MF(COORD_FONT_PETITE), MF(CONSOLE_FONT_PETITE), MF(COMMENT_FONT_PETITE), MF(EDITTAGS_FONT_PETITE), MF(MOVEHISTORY_FONT_ALL), MF(GAMELIST_FONT_ALL) }, + { MF(CLOCK_FONT_SLIM), MF(MESSAGE_FONT_SLIM), MF(COORD_FONT_SLIM), MF(CONSOLE_FONT_SLIM), MF(COMMENT_FONT_SLIM), MF(EDITTAGS_FONT_SLIM), MF(MOVEHISTORY_FONT_ALL), MF(GAMELIST_FONT_ALL) }, + { MF(CLOCK_FONT_SMALL), MF(MESSAGE_FONT_SMALL), MF(COORD_FONT_SMALL), MF(CONSOLE_FONT_SMALL), MF(COMMENT_FONT_SMALL), MF(EDITTAGS_FONT_SMALL), MF(MOVEHISTORY_FONT_ALL), MF(GAMELIST_FONT_ALL) }, + { MF(CLOCK_FONT_MEDIOCRE), MF(MESSAGE_FONT_MEDIOCRE), MF(COORD_FONT_MEDIOCRE), MF(CONSOLE_FONT_MEDIOCRE), MF(COMMENT_FONT_MEDIOCRE), MF(EDITTAGS_FONT_MEDIOCRE), MF(MOVEHISTORY_FONT_ALL), MF(GAMELIST_FONT_ALL) }, + { MF(CLOCK_FONT_MIDDLING), MF(MESSAGE_FONT_MIDDLING), MF(COORD_FONT_MIDDLING), MF(CONSOLE_FONT_MIDDLING), MF(COMMENT_FONT_MIDDLING), MF(EDITTAGS_FONT_MIDDLING), MF(MOVEHISTORY_FONT_ALL), MF(GAMELIST_FONT_ALL) }, + { MF(CLOCK_FONT_AVERAGE), MF(MESSAGE_FONT_AVERAGE), MF(COORD_FONT_AVERAGE), MF(CONSOLE_FONT_AVERAGE), MF(COMMENT_FONT_AVERAGE), MF(EDITTAGS_FONT_AVERAGE), MF(MOVEHISTORY_FONT_ALL), MF(GAMELIST_FONT_ALL) }, + { MF(CLOCK_FONT_MODERATE), MF(MESSAGE_FONT_MODERATE), MF(COORD_FONT_MODERATE), MF(CONSOLE_FONT_MODERATE), MF(COMMENT_FONT_MODERATE), MF(EDITTAGS_FONT_MODERATE), MF(MOVEHISTORY_FONT_ALL), MF(GAMELIST_FONT_ALL) }, + { MF(CLOCK_FONT_MEDIUM), MF(MESSAGE_FONT_MEDIUM), MF(COORD_FONT_MEDIUM), MF(CONSOLE_FONT_MEDIUM), MF(COMMENT_FONT_MEDIUM), MF(EDITTAGS_FONT_MEDIUM), MF(MOVEHISTORY_FONT_ALL), MF(GAMELIST_FONT_ALL) }, + { MF(CLOCK_FONT_BULKY), MF(MESSAGE_FONT_BULKY), MF(COORD_FONT_BULKY), MF(CONSOLE_FONT_BULKY), MF(COMMENT_FONT_BULKY), MF(EDITTAGS_FONT_BULKY), MF(MOVEHISTORY_FONT_ALL), MF(GAMELIST_FONT_ALL) }, + { MF(CLOCK_FONT_LARGE), MF(MESSAGE_FONT_LARGE), MF(COORD_FONT_LARGE), MF(CONSOLE_FONT_LARGE), MF(COMMENT_FONT_LARGE), MF(EDITTAGS_FONT_LARGE), MF(MOVEHISTORY_FONT_ALL), MF(GAMELIST_FONT_ALL) }, + { MF(CLOCK_FONT_BIG), MF(MESSAGE_FONT_BIG), MF(COORD_FONT_BIG), MF(CONSOLE_FONT_BIG), MF(COMMENT_FONT_BIG), MF(EDITTAGS_FONT_BIG), MF(MOVEHISTORY_FONT_ALL), MF(GAMELIST_FONT_ALL) }, + { MF(CLOCK_FONT_HUGE), MF(MESSAGE_FONT_HUGE), MF(COORD_FONT_HUGE), MF(CONSOLE_FONT_HUGE), MF(COMMENT_FONT_HUGE), MF(EDITTAGS_FONT_HUGE), MF(MOVEHISTORY_FONT_ALL), MF(GAMELIST_FONT_ALL) }, + { MF(CLOCK_FONT_GIANT), MF(MESSAGE_FONT_GIANT), MF(COORD_FONT_GIANT), MF(CONSOLE_FONT_GIANT), MF(COMMENT_FONT_GIANT), MF(EDITTAGS_FONT_GIANT), MF(MOVEHISTORY_FONT_ALL), MF(GAMELIST_FONT_ALL) }, + { MF(CLOCK_FONT_COLOSSAL), MF(MESSAGE_FONT_COLOSSAL), MF(COORD_FONT_COLOSSAL), MF(CONSOLE_FONT_COLOSSAL), MF(COMMENT_FONT_COLOSSAL), MF(EDITTAGS_FONT_COLOSSAL), MF(MOVEHISTORY_FONT_ALL), MF (GAMELIST_FONT_ALL) }, + { MF(CLOCK_FONT_TITANIC), MF(MESSAGE_FONT_TITANIC), MF(COORD_FONT_TITANIC), MF(CONSOLE_FONT_TITANIC), MF(COMMENT_FONT_TITANIC), MF(EDITTAGS_FONT_TITANIC), MF(MOVEHISTORY_FONT_ALL), MF(GAMELIST_FONT_ALL) }, }; MyFont *font[NUM_SIZES][NUM_FONTS]; @@ -731,7 +763,8 @@ void ThawUI() #define JAWS_INIT #define JAWS_ARGS #define JAWS_ALT_INTERCEPT -#define JAWS_KB_NAVIGATION +#define JAWS_KBUP_NAVIGATION +#define JAWS_KBDOWN_NAVIGATION #define JAWS_MENU_ITEMS #define JAWS_SILENCE #define JAWS_REPLAY @@ -890,16 +923,19 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, void SetUserLogo() { // update user logo if necessary - static char oldUserName[MSG_SIZ], *curName; + static char oldUserName[MSG_SIZ], dir[MSG_SIZ], *curName; if(appData.autoLogo) { curName = UserName(); if(strcmp(curName, oldUserName)) { - snprintf(oldUserName, MSG_SIZ, "logos\\%s.bmp", curName); + GetCurrentDirectory(MSG_SIZ, dir); + SetCurrentDirectory(installDir); + snprintf(oldUserName, MSG_SIZ, "logos\\%s.bmp", curName); userLogo = LoadImage( 0, oldUserName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE ); safeStrCpy(oldUserName, curName, sizeof(oldUserName)/sizeof(oldUserName[0]) ); if(userLogo == NULL) userLogo = LoadImage( 0, "logos\\dummy.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE ); + SetCurrentDirectory(dir); /* return to prev directory */ } } } @@ -957,8 +993,11 @@ EnsureOnScreen(int *x, int *y, int minX, int minY) } VOID -LoadLogo(ChessProgramState *cps, int n) +LoadLogo(ChessProgramState *cps, int n, Boolean ics) { + char buf[MSG_SIZ], dir[MSG_SIZ]; + GetCurrentDirectory(MSG_SIZ, dir); + SetCurrentDirectory(installDir); if( appData.logo[n] && appData.logo[n][0] != NULLCHAR) { cps->programLogo = LoadImage( 0, appData.logo[n], IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE ); @@ -966,10 +1005,47 @@ LoadLogo(ChessProgramState *cps, int n) fprintf( debugFP, "Unable to load logo bitmap '%s'\n", appData.logo[n] ); } } else if(appData.autoLogo) { - if(appData.firstDirectory && appData.directory[n][0]) { - char buf[MSG_SIZ]; - snprintf(buf, MSG_SIZ, "%s/logo.bmp", appData.directory[n]); - cps->programLogo = LoadImage( 0, buf, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE ); + if(ics) { // [HGM] logo: in ICS mode second can be used for ICS + char *opponent = ""; + if(gameMode == IcsPlayingWhite) opponent = gameInfo.black; + if(gameMode == IcsPlayingBlack) opponent = gameInfo.white; + sprintf(buf, "logos\\%s\\%s.bmp", appData.icsHost, opponent); + if(!*opponent || !(cps->programLogo = LoadImage( 0, buf, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE ))) { + sprintf(buf, "logos\\%s.bmp", appData.icsHost); + cps->programLogo = LoadImage( 0, buf, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE ); + } + } else + if(appData.directory[n] && appData.directory[n][0]) { + SetCurrentDirectory(appData.directory[n]); + cps->programLogo = LoadImage( 0, "logo.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE ); + } + } + SetCurrentDirectory(dir); /* return to prev directory */ +} + +VOID +InitTextures() +{ + ZeroMemory( &backTextureSquareInfo, sizeof(backTextureSquareInfo) ); + backTextureSquareSize = 0; // kludge to force recalculation of texturemode + + if( appData.liteBackTextureFile && appData.liteBackTextureFile[0] != NULLCHAR && appData.liteBackTextureFile[0] != '*' ) { + if(liteBackTexture) DeleteObject(liteBackTexture); + liteBackTexture = LoadImage( 0, appData.liteBackTextureFile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE ); + liteBackTextureMode = appData.liteBackTextureMode; + + if (liteBackTexture == NULL && appData.debugMode) { + fprintf( debugFP, "Unable to load lite texture bitmap '%s'\n", appData.liteBackTextureFile ); + } + } + + if( appData.darkBackTextureFile && appData.darkBackTextureFile[0] != NULLCHAR && appData.darkBackTextureFile[0] != '*' ) { + if(darkBackTexture) DeleteObject(darkBackTexture); + darkBackTexture = LoadImage( 0, appData.darkBackTextureFile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE ); + darkBackTextureMode = appData.darkBackTextureMode; + + if (darkBackTexture == NULL && appData.debugMode) { + fprintf( debugFP, "Unable to load dark texture bitmap '%s'\n", appData.darkBackTextureFile ); } } } @@ -990,7 +1066,6 @@ InitInstance(HINSTANCE hInstance, int nCmdShow, LPSTR lpCmdLine) } else { GetCurrentDirectory(MSG_SIZ, installDir); } - safeStrCpy(homeDir, installDir, MSG_SIZ); gameInfo.boardWidth = gameInfo.boardHeight = 8; // [HGM] won't have open window otherwise screenWidth = screenHeight = 1000; // [HGM] placement: kludge to allow calling EnsureOnScreen from InitAppData InitAppData(lpCmdLine); /* Get run-time parameters */ @@ -1030,25 +1105,8 @@ InitInstance(HINSTANCE hInstance, int nCmdShow, LPSTR lpCmdLine) } /* [HGM] logo: Load logos if specified (must be done before InitDrawingSizes) */ - LoadLogo(&first, 0); - - if( appData.secondLogo && appData.secondLogo[0] != NULLCHAR) { - second.programLogo = LoadImage( 0, appData.secondLogo, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE ); - - if (second.programLogo == NULL && appData.debugMode) { - fprintf( debugFP, "Unable to load logo bitmap '%s'\n", appData.secondLogo ); - } - } else if(appData.autoLogo) { - char buf[MSG_SIZ]; - if(appData.icsActive) { // [HGM] logo: in ICS mode second can be used for ICS - snprintf(buf, MSG_SIZ, "logos\\%s.bmp", appData.icsHost); - second.programLogo = LoadImage( 0, buf, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE ); - } else - if(appData.secondDirectory && appData.secondDirectory[0]) { - snprintf(buf, MSG_SIZ, "%s\\logo.bmp", appData.secondDirectory); - second.programLogo = LoadImage( 0, buf, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE ); - } - } + LoadLogo(&first, 0, FALSE); + LoadLogo(&second, 1, appData.icsActive); SetUserLogo(); @@ -1071,29 +1129,12 @@ InitInstance(HINSTANCE hInstance, int nCmdShow, LPSTR lpCmdLine) } InitDrawingSizes(boardSize, 0); + RecentEngineMenu(appData.recentEngineList); InitMenuChecks(); buttonCount = GetSystemMetrics(SM_CMOUSEBUTTONS); /* [AS] Load textures if specified */ - ZeroMemory( &backTextureSquareInfo, sizeof(backTextureSquareInfo) ); - - if( appData.liteBackTextureFile && appData.liteBackTextureFile[0] != NULLCHAR && appData.liteBackTextureFile[0] != '*' ) { - liteBackTexture = LoadImage( 0, appData.liteBackTextureFile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE ); - liteBackTextureMode = appData.liteBackTextureMode; - - if (liteBackTexture == NULL && appData.debugMode) { - fprintf( debugFP, "Unable to load lite texture bitmap '%s'\n", appData.liteBackTextureFile ); - } - } - - if( appData.darkBackTextureFile && appData.darkBackTextureFile[0] != NULLCHAR && appData.darkBackTextureFile[0] != '*' ) { - darkBackTexture = LoadImage( 0, appData.darkBackTextureFile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE ); - darkBackTextureMode = appData.darkBackTextureMode; - - if (darkBackTexture == NULL && appData.debugMode) { - fprintf( debugFP, "Unable to load dark texture bitmap '%s'\n", appData.darkBackTextureFile ); - } - } + InitTextures(); mysrandom( (unsigned) time(NULL) ); @@ -1133,15 +1174,6 @@ InitInstance(HINSTANCE hInstance, int nCmdShow, LPSTR lpCmdLine) 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE); #endif ShowWindow(hwndConsole, nCmdShow); - if(appData.chatBoxes) { // [HGM] chat: open chat boxes - char buf[MSG_SIZ], *p = buf, *q; - safeStrCpy(buf, appData.chatBoxes, sizeof(buf)/sizeof(buf[0]) ); - do { - q = strchr(p, ';'); - if(q) *q++ = 0; - if(*p) ChatPopUp(p); - } while(p=q); - } SetActiveWindow(hwndConsole); } if(!appData.noGUI) UpdateWindow(hwnd); else ShowWindow(hwnd, SW_MINIMIZE); @@ -1172,6 +1204,7 @@ InitMenuChecks() #define OPTCHAR "/" #define SEPCHAR "=" +#define TOPLEVEL 0 #include "args.h" @@ -1240,21 +1273,22 @@ ParseFontName(char *name, MyFontParams *mfp) q = strchr(p, ':'); if (q) { if (q - p >= sizeof(mfp->faceName)) - ExitArgError(_("Font name too long:"), name); + ExitArgError(_("Font name too long:"), name, TRUE); memcpy(mfp->faceName, p, q - p); mfp->faceName[q - p] = NULLCHAR; p = q + 1; } else { q = mfp->faceName; + while (*p && !isdigit(*p)) { *q++ = *p++; if (q - mfp->faceName >= sizeof(mfp->faceName)) - ExitArgError(_("Font name too long:"), name); + ExitArgError(_("Font name too long:"), name, TRUE); } while (q > mfp->faceName && q[-1] == ' ') q--; *q = NULLCHAR; } - if (!*p) ExitArgError(_("Font point size missing:"), name); + if (!*p) ExitArgError(_("Font point size missing:"), name, TRUE); mfp->pointSize = (float) atof(p); mfp->bold = (strchr(p, 'b') != NULL); mfp->italic = (strchr(p, 'i') != NULL); @@ -1360,7 +1394,7 @@ ParseBoardSize(void *addr, char *name) } bs++; } - ExitArgError(_("Unrecognized board size value"), name); + ExitArgError(_("Unrecognized board size value"), name, TRUE); } void @@ -1981,7 +2015,8 @@ void CreatePiecesFromFont() return; } - if( appData.renderPiecesWithFont == NULL || appData.renderPiecesWithFont[0] == NULLCHAR || appData.renderPiecesWithFont[0] == '*' ) { + if( !appData.useFont || appData.renderPiecesWithFont == NULL || + appData.renderPiecesWithFont[0] == NULLCHAR || appData.renderPiecesWithFont[0] == '*' ) { fontBitmapSquareSize = -1; return; } @@ -2081,9 +2116,15 @@ void CreatePiecesFromFont() HBITMAP DoLoadBitmap(HINSTANCE hinst, char *piece, int squareSize, char *suffix) { - char name[128]; + char name[128], buf[MSG_SIZ]; snprintf(name, sizeof(name)/sizeof(name[0]), "%s%d%s", piece, squareSize, suffix); + if(appData.pieceDirectory[0]) { + HBITMAP res; + snprintf(buf, MSG_SIZ, "%s\\%s.bmp", appData.pieceDirectory, name); + res = LoadImage( 0, buf, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE ); + if(res) return res; + } if (gameInfo.event && strcmp(gameInfo.event, "Easter Egg Hunt") == 0 && strcmp(name, "k80s") == 0) { @@ -2210,12 +2251,28 @@ InitDrawingSizes(BoardSize boardSize, int flags) RECT crect, wrect, oldRect; int offby; LOGBRUSH logbrush; + VariantClass v = gameInfo.variant; int suppressVisibleEffects = 0; // [HGM] kludge to request updating sizeInfo only if((int)boardSize >= 1000 ) { boardSize -= 1000; suppressVisibleEffects = 1; } /* [HGM] call with -2 uses old size (for if nr of files, ranks changes) */ if(boardSize == (BoardSize)(-2) ) boardSize = oldBoardSize; + oldBoardSize = boardSize; + + if(boardSize != SizeMiddling && boardSize != SizePetite && boardSize != SizeBulky && !appData.useFont) + { // correct board size to one where built-in pieces exist + if((v == VariantCapablanca || v == VariantGothic || v == VariantGrand || v == VariantCapaRandom || v == VariantJanus || v == VariantSuper) + && (boardSize < SizePetite || boardSize > SizeBulky) // Archbishop and Chancellor available in entire middle range + || (v == VariantShogi && boardSize != SizeModerate) // Japanese-style Shogi + || v == VariantKnightmate || v == VariantSChess || v == VariantXiangqi || v == VariantSpartan + || v == VariantShatranj || v == VariantMakruk || v == VariantGreat || v == VariantFairy ) { + if(boardSize < SizeMediocre) boardSize = SizePetite; else + if(boardSize > SizeModerate) boardSize = SizeBulky; else + boardSize = SizeMiddling; + } + } + if(!appData.useFont && boardSize == SizePetite && (v == VariantShogi || v == VariantKnightmate)) boardSize = SizeMiddling; // no Unicorn in Petite oldRect.left = wpMain.x; //[HGM] placement: remember previous window params oldRect.top = wpMain.y; @@ -2227,6 +2284,7 @@ InitDrawingSizes(BoardSize boardSize, int flags) squareSize = sizeInfo[boardSize].squareSize; lineGap = sizeInfo[boardSize].lineGap; minorSize = 0; /* [HGM] Kludge to see if demagnified pieces need to be shifted */ + border = appData.useBorder && appData.border[0] ? squareSize/2 : 0; if( appData.overrideLineGap >= 0 && appData.overrideLineGap <= 5 ) { lineGap = appData.overrideLineGap; @@ -2251,8 +2309,8 @@ InitDrawingSizes(BoardSize boardSize, int flags) DrawMenuBar(hwndMain); } - boardWidth = BoardWidth(boardSize, BOARD_WIDTH); - boardHeight = BoardWidth(boardSize, BOARD_HEIGHT); + boardWidth = BoardWidth(boardSize, BOARD_WIDTH) + 2*border; + boardHeight = BoardWidth(boardSize, BOARD_HEIGHT) + 2*border; /* Get text area sizes */ hdc = GetDC(hwndMain); @@ -2324,7 +2382,6 @@ InitDrawingSizes(BoardSize boardSize, int flags) sizeInfo[boardSize].cliWidth = boardRect.right + OUTER_MARGIN; sizeInfo[boardSize].cliHeight = boardRect.bottom + OUTER_MARGIN; - oldBoardSize = boardSize; oldTinyLayout = tinyLayout; winW = 2 * GetSystemMetrics(SM_CXFRAME) + boardRect.right + OUTER_MARGIN; winH = 2 * GetSystemMetrics(SM_CYFRAME) + GetSystemMetrics(SM_CYMENU) + @@ -2424,20 +2481,20 @@ InitDrawingSizes(BoardSize boardSize, int flags) /* [HGM] Loop had to be split in part for vert. and hor. lines */ for (i = 0; i < BOARD_HEIGHT + 1; i++) { - gridEndpoints[i*2].x = boardRect.left + lineGap / 2; + gridEndpoints[i*2].x = boardRect.left + lineGap / 2 + border; gridEndpoints[i*2].y = gridEndpoints[i*2 + 1].y = - boardRect.top + lineGap / 2 + (i * (squareSize + lineGap)); + boardRect.top + lineGap / 2 + (i * (squareSize + lineGap)) + border; gridEndpoints[i*2 + 1].x = boardRect.left + lineGap / 2 + - BOARD_WIDTH * (squareSize + lineGap); + BOARD_WIDTH * (squareSize + lineGap) + border; gridVertexCounts[i*2] = gridVertexCounts[i*2 + 1] = 2; } for (i = 0; i < BOARD_WIDTH + 1; i++) { - gridEndpoints[i*2 + BOARD_HEIGHT*2 + 2].y = boardRect.top + lineGap / 2; + gridEndpoints[i*2 + BOARD_HEIGHT*2 + 2].y = boardRect.top + lineGap / 2 + border; gridEndpoints[i*2 + BOARD_HEIGHT*2 + 2].x = gridEndpoints[i*2 + 1 + BOARD_HEIGHT*2 + 2].x = boardRect.left + - lineGap / 2 + (i * (squareSize + lineGap)); + lineGap / 2 + (i * (squareSize + lineGap)) + border; gridEndpoints[i*2 + 1 + BOARD_HEIGHT*2 + 2].y = - boardRect.top + BOARD_HEIGHT * (squareSize + lineGap); + boardRect.top + BOARD_HEIGHT * (squareSize + lineGap) + border; gridVertexCounts[i*2] = gridVertexCounts[i*2 + 1] = 2; } } @@ -2690,19 +2747,19 @@ VOID SquareToPos(int row, int column, int * x, int * y) { if (flipView) { - *x = boardRect.left + lineGap + ((BOARD_WIDTH-1)-column) * (squareSize + lineGap); - *y = boardRect.top + lineGap + row * (squareSize + lineGap); + *x = boardRect.left + lineGap + ((BOARD_WIDTH-1)-column) * (squareSize + lineGap) + border; + *y = boardRect.top + lineGap + row * (squareSize + lineGap) + border; } else { - *x = boardRect.left + lineGap + column * (squareSize + lineGap); - *y = boardRect.top + lineGap + ((BOARD_HEIGHT-1)-row) * (squareSize + lineGap); + *x = boardRect.left + lineGap + column * (squareSize + lineGap) + border; + *y = boardRect.top + lineGap + ((BOARD_HEIGHT-1)-row) * (squareSize + lineGap) + border; } } VOID DrawCoordsOnDC(HDC hdc) { - static char files[24] = {'0', '1','2','3','4','5','6','7','8','9','0','1','1','0','9','8','7','6','5','4','3','2','1','0'}; - static char ranks[24] = {'l', 'k','j','i','h','g','f','e','d','c','b','a','a','b','c','d','e','f','g','h','i','j','k','l'}; + static char files[] = "0123456789012345678901221098765432109876543210"; + static char ranks[] = "wvutsrqponmlkjihgfedcbaabcdefghijklmnopqrstuvw"; char str[2] = { NULLCHAR, NULLCHAR }; int oldMode, oldAlign, x, y, start, i; HFONT oldFont; @@ -2711,7 +2768,7 @@ DrawCoordsOnDC(HDC hdc) if (!appData.showCoords) return; - start = flipView ? 1-(ONE!='1') : 23+(ONE!='1')-BOARD_HEIGHT; + start = flipView ? 1-(ONE!='1') : 45+(ONE!='1')-BOARD_HEIGHT; oldBrush = SelectObject(hdc, GetStockObject(BLACK_BRUSH)); oldMode = SetBkMode(hdc, (appData.monoMode ? OPAQUE : TRANSPARENT)); @@ -2721,15 +2778,23 @@ DrawCoordsOnDC(HDC hdc) y = boardRect.top + lineGap; x = boardRect.left + lineGap + gameInfo.holdingsWidth*(squareSize + lineGap); + if(border) { + SetTextAlign(hdc, TA_RIGHT|TA_TOP); + x += border - lineGap - 4; y += squareSize - 6; + } else SetTextAlign(hdc, TA_LEFT|TA_TOP); for (i = 0; i < BOARD_HEIGHT; i++) { str[0] = files[start + i]; - ExtTextOut(hdc, x + 2, y + 1, 0, NULL, str, 1, NULL); + ExtTextOut(hdc, x + 2 - (border ? gameInfo.holdingsWidth * (squareSize + lineGap) : 0), y + 1, 0, NULL, str, 1, NULL); y += squareSize + lineGap; } - start = flipView ? 12-(BOARD_RGHT-BOARD_LEFT) : 12; + start = flipView ? 23-(BOARD_RGHT-BOARD_LEFT) : 23; + if(border) { + SetTextAlign(hdc, TA_LEFT|TA_TOP); + x += -border + 4; y += border - squareSize + 6; + } else SetTextAlign(hdc, TA_RIGHT|TA_BOTTOM); for (i = 0; i < BOARD_RGHT - BOARD_LEFT; i++) { str[0] = ranks[start + i]; @@ -2766,14 +2831,14 @@ DrawHighlightOnDC(HDC hdc, BOOLEAN on, int x, int y, int pen) if (lineGap == 0) return; if (flipView) { x1 = boardRect.left + - lineGap/2 + ((BOARD_WIDTH-1)-x) * (squareSize + lineGap); + lineGap/2 + ((BOARD_WIDTH-1)-x) * (squareSize + lineGap) + border; y1 = boardRect.top + - lineGap/2 + y * (squareSize + lineGap); + lineGap/2 + y * (squareSize + lineGap) + border; } else { x1 = boardRect.left + - lineGap/2 + x * (squareSize + lineGap); + lineGap/2 + x * (squareSize + lineGap) + border; y1 = boardRect.top + - lineGap/2 + ((BOARD_HEIGHT-1)-y) * (squareSize + lineGap); + lineGap/2 + ((BOARD_HEIGHT-1)-y) * (squareSize + lineGap) + border; } hPen = pen ? premovePen : highlightPen; oldPen = SelectObject(hdc, on ? hPen : gridPen); @@ -2851,7 +2916,9 @@ DrawPieceOnDC(HDC hdc, ChessSquare piece, int color, int sqcolor, int x, int y, BitBlt(hdc, x, y, squareSize, squareSize, tmphdc, 0, 0, sqcolor ? SRCCOPY : NOTSRCCOPY); } else { + HBRUSH xBrush = whitePieceBrush; tmpSize = squareSize; + if(appData.pieceDirectory[0]) xBrush = GetStockObject(WHITE_BRUSH); if(minorSize && ((piece >= (int)WhiteNightrider && piece <= WhiteGrasshopper) || (piece >= (int)BlackNightrider && piece <= BlackGrasshopper)) ) { @@ -2864,7 +2931,7 @@ DrawPieceOnDC(HDC hdc, ChessSquare piece, int color, int sqcolor, int x, int y, if (color || appData.allWhite ) { oldBitmap = SelectObject(tmphdc, PieceBitmap(piece, WHITE_PIECE)); if( color ) - oldBrush = SelectObject(hdc, whitePieceBrush); + oldBrush = SelectObject(hdc, xBrush); else oldBrush = SelectObject(hdc, blackPieceBrush); if(appData.upsideDown && color==flipView) StretchBlt(hdc, x+tmpSize, y+tmpSize, -tmpSize, -tmpSize, tmphdc, 0, 0, tmpSize, tmpSize, 0x00B8074A); @@ -2876,6 +2943,18 @@ DrawPieceOnDC(HDC hdc, ChessSquare piece, int color, int sqcolor, int x, int y, StretchBlt(hdc, x+tmpSize, y+tmpSize, -tmpSize, -tmpSize, tmphdc, 0, 0, tmpSize, tmpSize, SRCAND); else BitBlt(hdc, x, y, tmpSize, tmpSize, tmphdc, 0, 0, SRCAND); + } else if(appData.pieceDirectory[0]) { + oldBitmap = SelectObject(tmphdc, PieceBitmap(piece, WHITE_PIECE)); + oldBrush = SelectObject(hdc, xBrush); + if(appData.upsideDown && color==flipView) + StretchBlt(hdc, x+tmpSize, y+tmpSize, -tmpSize, -tmpSize, tmphdc, 0, 0, tmpSize, tmpSize, 0x00B8074A); + else + BitBlt(hdc, x, y, tmpSize, tmpSize, tmphdc, 0, 0, 0x00B8074A); + SelectObject(tmphdc, PieceBitmap(piece, SOLID_PIECE)); + if(appData.upsideDown && color==flipView) + StretchBlt(hdc, x+tmpSize, y+tmpSize, -tmpSize, -tmpSize, tmphdc, 0, 0, tmpSize, tmpSize, SRCAND); + else + BitBlt(hdc, x, y, tmpSize, tmpSize, tmphdc, 0, 0, SRCAND); } else { /* Use square color for details of black pieces */ oldBitmap = SelectObject(tmphdc, PieceBitmap(piece, SOLID_PIECE)); @@ -3263,6 +3342,40 @@ BOOL DrawPositionNeedsFullRepaint() return result; } +static HBITMAP borderBitmap; + +VOID +DrawBackgroundOnDC(HDC hdc) +{ + + BITMAP bi; + HDC tmphdc; + HBITMAP hbm; + static char oldBorder[MSG_SIZ]; + int w = 600, h = 600, mode; + + if(strcmp(appData.border, oldBorder)) { // load new one when old one no longer valid + strncpy(oldBorder, appData.border, MSG_SIZ-1); + borderBitmap = LoadImage( 0, appData.border, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE ); + } + if(borderBitmap == NULL) { // loading failed, use white + FillRect( hdc, &boardRect, whitePieceBrush ); + return; + } + tmphdc = CreateCompatibleDC(hdc); + hbm = SelectObject(tmphdc, borderBitmap); + if( GetObject( borderBitmap, sizeof(bi), &bi ) > 0 ) { + w = bi.bmWidth; + h = bi.bmHeight; + } + mode = SetStretchBltMode(hdc, COLORONCOLOR); + StretchBlt(hdc, boardRect.left, boardRect.top, boardRect.right - boardRect.left, + boardRect.bottom - boardRect.top, tmphdc, 0, 0, w, h, SRCCOPY); + SetStretchBltMode(hdc, mode); + SelectObject(tmphdc, hbm); + DeleteDC(tmphdc); +} + VOID DrawBoardOnDC(HDC hdc, Board board, HDC tmphdc) { @@ -3330,7 +3443,7 @@ DrawBoardOnDC(HDC hdc, Board board, HDC tmphdc) DrawPieceOnDC(hdc, piece, piece_color, square_color, x, y, tmphdc); } } - else if( backTextureSquareInfo[row][column].mode > 0 ) { + else if( appData.useBitmaps && backTextureSquareInfo[row][column].mode > 0 ) { /* [AS] Draw the square using a texture bitmap */ HBITMAP hbm = SelectObject( texture_hdc, square_color ? liteBackTexture : darkBackTexture ); int r = row, c = column; // [HGM] do not flip board in flipView @@ -3388,7 +3501,10 @@ DrawLogoOnDC(HDC hdc, RECT logoRect, HBITMAP logo) HBITMAP hbm; int w = 100, h = 50; - if(logo == NULL) return; + if(logo == NULL) { + if(!logoHeight) return; + FillRect( hdc, &logoRect, whitePieceBrush ); + } // GetClientRect(hwndMain, &Rect); // bufferBitmap = CreateCompatibleBitmap(hdc, Rect.right-Rect.left+1, // Rect.bottom-Rect.top+1); @@ -3446,6 +3562,15 @@ DisplayLogos() } } +void +UpdateLogos(int display) +{ // called after loading new engine(s), in tourney or from menu + LoadLogo(&first, 0, FALSE); + LoadLogo(&second, 1, appData.icsActive); + InitDrawingSizes(-2, 0); // adapt layout of board window to presence/absence of logos + if(display) DisplayLogos(); +} + static HDC hdcSeek; // [HGM] seekgraph @@ -3502,6 +3627,14 @@ void DrawSeekDot(int x, int y, int color) SelectObject(hdcSeek, oldBrush); } +void DrawSeekOpen() +{ +} + +void DrawSeekClose() +{ +} + VOID HDCDrawPosition(HDC hdc, BOOLEAN repaint, Board board) { @@ -3761,6 +3894,7 @@ HDCDrawPosition(HDC hdc, BOOLEAN repaint, Board board) Ellipse(hdcmem, x-r, y-r, x+r, y+r); SelectObject(hdcmem, oldBrush); } else { + if(border) DrawBackgroundOnDC(hdcmem); DrawGridOnDC(hdcmem); if(nr == 0) { // [HGM] dual: decide which highlights to draw DrawHighlightsOnDC(hdcmem, &highlightInfo, HIGHLIGHT_PEN); @@ -4014,11 +4148,11 @@ PaintProc(HWND hwnd) int EventToSquare(x, limit) int x, limit; { - if (x <= 0) + if (x <= border) return -2; - if (x < lineGap) + if (x < lineGap + border) return -1; - x -= lineGap; + x -= lineGap + border; if ((x % (squareSize + lineGap)) >= squareSize) return -1; x /= (squareSize + lineGap); @@ -4064,10 +4198,11 @@ SetupDropMenu(HMENU hmenu) } } -void DragPieceBegin(int x, int y) +void DragPieceBegin(int x, int y, Boolean instantly) { dragInfo.lastpos.x = boardRect.left + x; dragInfo.lastpos.y = boardRect.top + y; + if(instantly) dragInfo.pos = dragInfo.lastpos; dragInfo.from.x = fromX; dragInfo.from.y = fromY; dragInfo.piece = boards[currentMove][fromY][fromX]; @@ -4126,9 +4261,9 @@ MouseEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) switch (message) { case WM_LBUTTONDOWN: if (PtInRect((LPRECT) &whiteRect, pt)) { - ClockClick(flipClock); + ClockClick(flipClock); break; } else if (PtInRect((LPRECT) &blackRect, pt)) { - ClockClick(!flipClock); + ClockClick(!flipClock); break; } dragInfo.start.x = dragInfo.start.y = -1; dragInfo.from = dragInfo.start; @@ -4208,9 +4343,9 @@ MouseEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) if(y == -2) { /* [HGM] right mouse button in clock area edit-game mode ups clock */ if (PtInRect((LPRECT) &whiteRect, pt)) { - if (gameMode == EditGame || GetKeyState(VK_SHIFT) < 0) AdjustClock(flipClock, 1); + if (GetKeyState(VK_SHIFT) < 0) AdjustClock(flipClock, 1); } else if (PtInRect((LPRECT) &blackRect, pt)) { - if (gameMode == EditGame || GetKeyState(VK_SHIFT) < 0) AdjustClock(!flipClock, 1); + if (GetKeyState(VK_SHIFT) < 0) AdjustClock(!flipClock, 1); } break; } @@ -4236,7 +4371,7 @@ MouseEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) } break; case 2: - SetCapture(hwndMain); + SetCapture(hwndMain); break; case 1: hmenu = LoadMenu(hInst, "DropPieceMenu"); @@ -4406,14 +4541,6 @@ PromotionPopUp() PromotionPopup(hwndMain); } -/* Toggle ShowThinking */ -VOID -ToggleShowThinking() -{ - appData.showThinking = !appData.showThinking; - ShowThinkingEvent(); -} - VOID LoadGameDialog(HWND hwnd, char* title) { @@ -4554,6 +4681,7 @@ WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) char fileTitle[MSG_SIZ]; char buf[MSG_SIZ]; static SnapData sd; + static int peek=0; switch (message) { @@ -4581,7 +4709,23 @@ WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) MouseEvent(hwnd, message, wParam, lParam); break; - JAWS_KB_NAVIGATION + case WM_KEYUP: + if((char)wParam == '\b') { + ForwardEvent(); peek = 0; + } + + JAWS_KBUP_NAVIGATION + + break; + + case WM_KEYDOWN: + if((char)wParam == '\b') { + if(!peek) BackwardEvent(), peek = 1; + } + + JAWS_KBDOWN_NAVIGATION + + break; case WM_CHAR: @@ -4726,6 +4870,10 @@ WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) } break; + case IDM_CreateBook: + CreateBookEvent(); + break; + case IDM_CopyGame: CopyGameToClipboard(); break; @@ -4868,52 +5016,13 @@ WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) break; case IDM_AnalysisMode: - if (!first.analysisSupport) { - snprintf(buf, MSG_SIZ, _("%s does not support analysis"), first.tidy); - DisplayError(buf, 0); - } else { + if(AnalyzeModeEvent()) { SAY("analyzing current position"); - /* [DM] icsEngineAnlyze [HGM] Why is this front-end??? */ - if (appData.icsActive) { - if (gameMode != IcsObserving) { - snprintf(buf, MSG_SIZ, "You are not observing a game"); - DisplayError(buf, 0); - /* secure check */ - if (appData.icsEngineAnalyze) { - if (appData.debugMode) - fprintf(debugFP, "Found unexpected active ICS engine analyze \n"); - ExitAnalyzeMode(); - ModeHighlight(); - break; - } - break; - } else { - /* if enable, user want disable icsEngineAnalyze */ - if (appData.icsEngineAnalyze) { - ExitAnalyzeMode(); - ModeHighlight(); - break; - } - appData.icsEngineAnalyze = TRUE; - if (appData.debugMode) fprintf(debugFP, "ICS engine analyze starting...\n"); - } - } - if (!appData.showThinking) ToggleShowThinking(); - AnalyzeModeEvent(); } break; case IDM_AnalyzeFile: - if (!first.analysisSupport) { - char buf[MSG_SIZ]; - snprintf(buf, MSG_SIZ, _("%s does not support analysis"), first.tidy); - DisplayError(buf, 0); - } else { - if (!appData.showThinking) ToggleShowThinking(); - AnalyzeFileEvent(); - LoadGameDialog(hwnd, _("Analyze Game from File")); - AnalysisPeriodicEvent(1); - } + AnalyzeFileEvent(); break; case IDM_IcsClient: @@ -4944,9 +5053,12 @@ WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) EditTagsPopUp(firstChessProgramNames, &firstChessProgramNames); break; - case IDM_EditProgs2: - LoadEnginePopUp(hwndMain); -// EditTagsPopUp(secondChessProgramNames, &secondChessProgramNames); + case IDM_LoadProg1: + LoadEnginePopUp(hwndMain, 0); + break; + + case IDM_LoadProg2: + LoadEnginePopUp(hwndMain, 1); break; case IDM_EditServers: @@ -5049,6 +5161,11 @@ WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) SetFocus(hwndMain); break; + case OPT_GameListNext: // [HGM] forward these two accelerators to Game List + case OPT_GameListPrev: + if(gameListDialog) SendMessage(gameListDialog, WM_COMMAND, wmId, 0); + break; + case IDM_Revert: RevertEvent(FALSE); break; @@ -5095,6 +5212,10 @@ WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) BoardOptionsPopup(hwnd); break; + case IDM_ThemeOptions: + ThemeOptionsPopup(hwnd); + break; + case IDM_EnginePlayOptions: EnginePlayOptionsPopup(hwnd); break; @@ -5410,6 +5531,9 @@ WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) break; default: + if(wmId >= IDM_RecentEngines && wmId < IDM_RecentEngines + appData.recentEngines) + RecentEngineEvent(wmId - IDM_RecentEngines); + else if(wmId > IDM_English && wmId < IDM_English+20) { LoadLanguageFile(languageFile[wmId - IDM_English - 1]); TranslateMenus(0); @@ -5618,7 +5742,7 @@ MyLoadSound(MySound *ms) struct stat st; FILE *f; - if (ms->data) free(ms->data); + if (ms->data && ms->flag) free(ms->data); ms->data = NULL; switch (ms->name[0]) { @@ -5639,6 +5763,7 @@ MyLoadSound(MySound *ms) HANDLE h = FindResource(hInst, ms->name + 1, "WAVE"); if (h == NULL) break; ms->data = (void *)LoadResource(hInst, h); + ms->flag = 0; // not maloced, so cannot be freed! if (h == NULL) break; ok = TRUE; } @@ -5649,6 +5774,7 @@ MyLoadSound(MySound *ms) if (f == NULL) break; if (fstat(fileno(f), &st) < 0) break; ms->data = malloc(st.st_size); + ms->flag = 1; if (fread(ms->data, st.st_size, 1, f) < 1) break; fclose(f); ok = TRUE; @@ -6119,10 +6245,11 @@ StartupDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) safeStrCpy(buf, "/fcp=", sizeof(buf)/sizeof(buf[0]) ); GetDlgItemText(hDlg, OPT_ChessEngineName, buf + strlen(buf), sizeof(buf) - strlen(buf)); p = buf; + comboLine = strdup(p+5); // [HGM] recent: remember complete line of first combobox ParseArgs(StringGet, &p); safeStrCpy(buf, singleList ? "/fcp=" : "/scp=", sizeof(buf)/sizeof(buf[0]) ); GetDlgItemText(hDlg, OPT_SecondChessEngineName, buf + strlen(buf), sizeof(buf) - strlen(buf)); - p = buf; + p = buf; SwapEngines(singleList); // temporarily swap first and second, to load a second 'first', ... ParseArgs(StringGet, &p); SwapEngines(singleList); // ... and then make it 'second' @@ -6432,10 +6559,10 @@ TypeInMoveDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) case WM_COMMAND: switch (LOWORD(wParam)) { - case IDOK: + case IDOK: shiftKey = GetKeyState(VK_SHIFT) < 0; // [HGM] remember last shift status - GetDlgItemText(hDlg, OPT_Move, move, sizeof(move)); + GetDlgItemText(hDlg, OPT_Move, move, sizeof(move)); TypeInDoneEvent(move); EndDialog(hDlg, TRUE); return TRUE; @@ -7398,7 +7525,7 @@ DisplayHoldingsCount(HDC hdc, int x, int y, int rightAlign, int copyNumber) HFONT oldFont; RECT rect; - if(copyNumber > 1) + if(copyNumber > 1) snprintf(buf, sizeof(buf)/sizeof(buf[0]),"%d", copyNumber); else buf[0] = 0; oldFg = SetTextColor(hdc, RGB(255, 255, 255)); /* white */ @@ -7430,6 +7557,7 @@ DisplayAClock(HDC hdc, int timeRemaining, int highlight, COLORREF oldFg, oldBg; HFONT oldFont; + if (twoBoards && partnerUp) return; if (appData.clockMode) { if (tinyLayout) snprintf(buf, sizeof(buf)/sizeof(buf[0]), "%c %s %s", color[0], TimeString(timeRemaining), flagFell); @@ -7794,7 +7922,8 @@ Enables icsEnables[] = { { IDM_MoveNow, MF_BYCOMMAND|MF_GRAYED }, { IDM_Hint, MF_BYCOMMAND|MF_GRAYED }, { IDM_Book, MF_BYCOMMAND|MF_GRAYED }, - { IDM_EditProgs2, MF_BYCOMMAND|MF_GRAYED }, + { IDM_LoadProg1, MF_BYCOMMAND|MF_GRAYED }, + { IDM_LoadProg2, MF_BYCOMMAND|MF_GRAYED }, { IDM_IcsOptions, MF_BYCOMMAND|MF_ENABLED }, { IDM_Engine1Options, MF_BYCOMMAND|MF_GRAYED }, { IDM_Engine2Options, MF_BYCOMMAND|MF_GRAYED }, @@ -8148,8 +8277,8 @@ DisplayMessage(char *str1, char *str2) if (len > remain) len = remain; strncat(messageText, str2, len); } - messageText[MESSAGE_TEXT_MAX - 1] = NULLCHAR; - safeStrCpy(lastMsg, messageText, MSG_SIZ); + messageText[MESSAGE_TEXT_MAX - 1] = NULLCHAR; + safeStrCpy(lastMsg, messageText, MSG_SIZ); if (hwndMain == NULL || IsIconic(hwndMain)) return; @@ -8509,7 +8638,19 @@ DisplayIcsInteractionTitle(char *str) char consoleTitle[MSG_SIZ]; snprintf(consoleTitle, MSG_SIZ, "%s: %s", szConsoleTitle, str); - SetWindowText(hwndConsole, consoleTitle); + SetWindowText(hwndConsole, consoleTitle); + + if(appData.chatBoxes) { // [HGM] chat: open chat boxes + char buf[MSG_SIZ], *p = buf, *q; + safeStrCpy(buf, appData.chatBoxes, sizeof(buf)/sizeof(buf[0]) ); + do { + q = strchr(p, ';'); + if(q) *q++ = 0; + if(*p) ChatPopUp(p); + } while(p=q); + } + + SetActiveWindow(hwndMain); } void @@ -8599,6 +8740,12 @@ PlayAlarmSound() MyPlaySound(&sounds[(int)SoundAlarm]); } +VOID +PlayTellSound() +{ + MyPlaySound(&textAttribs[ColorTell].sound); +} + VOID EchoOn() @@ -8831,6 +8978,37 @@ IDLE_PRIORITY_CLASS 0x00000040 return 0x00000040; } +void RunCommand(char *cmdLine) +{ + /* Now create the child process. */ + STARTUPINFO siStartInfo; + PROCESS_INFORMATION piProcInfo; + + siStartInfo.cb = sizeof(STARTUPINFO); + siStartInfo.lpReserved = NULL; + siStartInfo.lpDesktop = NULL; + siStartInfo.lpTitle = NULL; + siStartInfo.dwFlags = STARTF_USESTDHANDLES; + siStartInfo.cbReserved2 = 0; + siStartInfo.lpReserved2 = NULL; + siStartInfo.hStdInput = NULL; + siStartInfo.hStdOutput = NULL; + siStartInfo.hStdError = NULL; + + CreateProcess(NULL, + cmdLine, /* command line */ + NULL, /* process security attributes */ + NULL, /* primary thread security attrs */ + TRUE, /* handles are inherited */ + DETACHED_PROCESS|CREATE_NEW_PROCESS_GROUP, + NULL, /* use parent's environment */ + NULL, + &siStartInfo, /* STARTUPINFO pointer */ + &piProcInfo); /* receives PROCESS_INFORMATION */ + + CloseHandle(piProcInfo.hThread); +} + /* Start a child process running the given program. The process's standard output can be read from "from", and its standard input can be written to "to". @@ -8914,9 +9092,6 @@ StartChildProcess(char *cmdLine, char *dir, ProcRef *pr) * dir relative to the directory WinBoard loaded from. */ GetCurrentDirectory(MSG_SIZ, buf); SetCurrentDirectory(installDir); - // kludgey way to update logos in tourney, as long as back-end can't do it - if(!strcmp(cmdLine, first.program)) LoadLogo(&first, 0); else - if(!strcmp(cmdLine, second.program)) LoadLogo(&second, 1); SetCurrentDirectory(dir); /* Now create the child process. */ @@ -9093,6 +9268,7 @@ OpenTCP(char *host, char *port, ProcRef *pr) ChildProc *cp; int err; SOCKET s; + struct sockaddr_in sa, mysa; struct hostent FAR *hp; unsigned short uport; @@ -9569,6 +9745,12 @@ OutputToProcess(ProcRef pr, char *message, int count, int *outError) return outCount; } +void +DoSleep(int n) +{ + if(n != 0) Sleep(n); +} + int OutputToProcessDelayed(ProcRef pr, char *message, int count, int *outError, long msdelay) @@ -9589,7 +9771,7 @@ CmailSigHandlerCallBack(InputSourceRef isr, VOIDSTAR closure, /* see wedittags.c for Edit Tags functions */ -VOID +int ICSInitScript() { FILE *f; @@ -9601,8 +9783,10 @@ ICSInitScript() if (f != NULL) { ProcessICSInitScript(f); fclose(f); + return TRUE; } } + return FALSE; } @@ -9758,11 +9942,11 @@ ScreenSquare(column, row, pt) int column; int row; POINT * pt; { if (flipView) { - pt->x = lineGap + ((BOARD_WIDTH-1)-column) * (squareSize + lineGap); - pt->y = lineGap + row * (squareSize + lineGap); + pt->x = lineGap + ((BOARD_WIDTH-1)-column) * (squareSize + lineGap) + border; + pt->y = lineGap + row * (squareSize + lineGap) + border; } else { - pt->x = lineGap + column * (squareSize + lineGap); - pt->y = lineGap + ((BOARD_HEIGHT-1)-row) * (squareSize + lineGap); + pt->x = lineGap + column * (squareSize + lineGap) + border; + pt->y = lineGap + ((BOARD_HEIGHT-1)-row) * (squareSize + lineGap) + border; } } @@ -9810,14 +9994,6 @@ Tween(start, mid, finish, factor, frames, nFrames) } void -HistorySet( char movelist[][2*MOVE_LEN], int first, int last, int current ) -{ - MoveHistorySet( movelist, first, last, current, pvInfoList ); - - EvalGraphSet( first, last, current, pvInfoList ); -} - -void SettingsPopUp(ChessProgramState *cps) { // [HGM] wrapper needed because handles must not be passed through back-end EngineOptionsPopup(savedHwnd, cps); @@ -9838,3 +10014,24 @@ int flock(int fid, int code) } return 0; } + +char * +Col2Text (int n) +{ + static int i=0; + static char col[8][20]; + COLORREF color = *(COLORREF *) colorVariable[n]; + i = i+1 & 7; + snprintf(col[i], 20, "#%02lx%02lx%02lx", color&0xff, (color>>8)&0xff, (color>>16)&0xff); + return col[i]; +} + +void +ActivateTheme (int new) +{ // Redo initialization of features depending on options that can occur in themes + InitTextures(); + if(new) InitDrawingColors(); + fontBitmapSquareSize = 0; // request creation of new font pieces + InitDrawingSizes(-2, 0); + InvalidateRect(hwndMain, NULL, TRUE); +}