X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=winboard%2Fwinboard.c;h=b86a399157c479292af2011e14d8af2d2cc8cb90;hb=a31d0897123ab90c8d4a8304619834079c3ad5a9;hp=722b9c819bca68abf33db830dbd03c500355ef05;hpb=6445f59125a3dff0cbb9426a0c0bd300a31075d1;p=xboard.git diff --git a/winboard/winboard.c b/winboard/winboard.c index 722b9c8..b86a399 100644 --- a/winboard/winboard.c +++ b/winboard/winboard.c @@ -156,7 +156,6 @@ char *programName; char *settingsFileName; Boolean saveSettingsOnExit; char installDir[MSG_SIZ]; -char homeDir[MSG_SIZ]; int errorExitStatus; BoardSize boardSize; @@ -890,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 */ } } } @@ -957,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 ); @@ -966,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 @@ -990,7 +999,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 +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(); @@ -3388,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); @@ -3446,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 @@ -5618,7 +5621,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 +5642,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 +5653,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; @@ -8914,9 +8919,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. */