From bf3465a52edbeb1d394a4f3ffc766890c4a1aab5 Mon Sep 17 00:00:00 2001 From: H.G. Muller Date: Wed, 8 Jun 2011 17:33:34 +0200 Subject: [PATCH] Fix display of logos The logo files are now sought relative to the WinBoard install directory. Non-existing logos cause clearing of the logo, rather than letting the logo of the prevous engine hang. Logo change is requested explicitly from the back-end (when an engine is initialized for a new game), rather than using the kludge in StartChileProcess. This required a dummy UpdateLogos routine in the XBoard front-end. --- backend.c | 4 ++- frontend.h | 1 + winboard/winboard.c | 62 ++++++++++++++++++++++++++------------------------ xboard.c | 6 +++++ 4 files changed, 42 insertions(+), 31 deletions(-) diff --git a/backend.c b/backend.c index 7309370..4fba970 100644 --- a/backend.c +++ b/backend.c @@ -861,6 +861,7 @@ ReplaceEngine(ChessProgramState *cps, int n) appData.noChessProgram = FALSE; appData.clockMode = TRUE; InitEngine(cps, n); + UpdateLogos(TRUE); if(n) return; // only startup first engine immediately; second can wait savCps = cps; // parameter to LoadEngine passed as globals, to allow scheduled calling :-( LoadEngine(); @@ -9838,6 +9839,7 @@ NextTourneyGame(int nr, int *swapColors) InitEngine(&first, 0); // initialize ChessProgramStates based on new settings. InitEngine(&second, 1); CommonEngineInit(); // after this TwoMachinesEvent will create correct engine processes + UpdateLogos(FALSE); // leave display to ModeHiglight() return 1; } @@ -12854,7 +12856,7 @@ TwoMachinesEvent P((void)) gameMode = TwoMachinesPlay; pausing = FALSE; - ModeHighlight(); + ModeHighlight(); // [HGM] logo: this triggers display update of logos SetGameInfo(); DisplayTwoMachinesTitle(); firstMove = TRUE; diff --git a/frontend.h b/frontend.h index 9cee154..e63f661 100644 --- a/frontend.h +++ b/frontend.h @@ -119,6 +119,7 @@ int StopClockTimer P((void)); void StartClockTimer P((long millisec)); void DisplayWhiteClock P((long timeRemaining, int highlight)); void DisplayBlackClock P((long timeRemaining, int highlight)); +void UpdateLogos P((int display)); int LoadGameTimerRunning P((void)); int StopLoadGameTimer P((void)); diff --git a/winboard/winboard.c b/winboard/winboard.c index 1655d40..b5ba50d 100644 --- a/winboard/winboard.c +++ b/winboard/winboard.c @@ -889,16 +889,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 */ } } } @@ -956,8 +959,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 ); @@ -965,12 +971,16 @@ 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 + 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 */ } BOOL @@ -1028,25 +1038,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(); @@ -3386,7 +3379,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); @@ -3444,6 +3440,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 @@ -8912,9 +8917,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. */ diff --git a/xboard.c b/xboard.c index 5ea91bb..f6eee62 100644 --- a/xboard.c +++ b/xboard.c @@ -9001,3 +9001,9 @@ void DrawArrowHighlight(int fromX, int fromY, int toX,int toY) if( IsDrawArrowEnabled() && fromX >= 0 && fromY >= 0 && toX >= 0 && toY >= 0) DrawArrowBetweenSquares(fromX, fromY, toX, toY); } + +void UpdateLogos(int displ) +{ + return; // no logos in XBoard yet +} + -- 1.7.0.4