X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=xboard.c;h=ebd046c954b9c5716a5c73bfddd2b7a018abcb40;hb=a61f78756889e18aa279dc273bd99b9af60468d7;hp=7f1d394a5d80cab14adb7407dd2f640e90270da0;hpb=9d455a7f4ce66cc25d540d4dc5a65fdb1895cc2e;p=xboard.git diff --git a/xboard.c b/xboard.c index 7f1d394..ebd046c 100644 --- a/xboard.c +++ b/xboard.c @@ -256,8 +256,6 @@ void DrawPositionProc P((Widget w, XEvent *event, void CommentClick P((Widget w, XEvent * event, String * params, Cardinal * nParams)); void ICSInputBoxPopUp P((void)); -void FileNamePopUp P((char *label, char *def, char *filter, - FileProc proc, char *openMode)); void SelectCommand P((Widget w, XtPointer client_data, XtPointer call_data)); void KeyBindingProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void QuitWrapper P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); @@ -272,9 +270,7 @@ void DisplayMove P((int moveNumber)); void ICSInitScript P((void)); void SelectMove P((Widget w, XEvent * event, String * params, Cardinal * nParams)); void update_ics_width P(()); -int get_term_width P(()); int CopyMemoProc P(()); -void SetupDropMenu P((void)); /* * XBoard depends on Xt R4 or higher @@ -305,8 +301,6 @@ XFontStruct *coordFontStruct, *countFontStruct; XtAppContext appContext; char *layoutName; -FileProc fileProc; -char *fileOpenMode; char installDir[] = "."; // [HGM] UCI: needed for UCI; probably needs run-time initializtion Position commentX = -1, commentY = -1; @@ -839,23 +833,20 @@ int frameX, frameY; void GetActualPlacement (Widget wg, WindowPlacement *wp) { - Arg args[16]; - Dimension w, h; - Position x, y; XWindowAttributes winAt; Window win, dummy; - int i, rx, ry; + int rx, ry; if(!wg) return; - win = XtWindow(wg); - XGetWindowAttributes(xDisplay, win, &winAt); // this works, where XtGetValues on XtNx, XtNy does not! - XTranslateCoordinates (xDisplay, win, winAt.root, -winAt.border_width, -winAt.border_width, &rx, &ry, &dummy); - wp->x = rx - winAt.x; - wp->y = ry - winAt.y; - wp->height = winAt.height; - wp->width = winAt.width; - frameX = winAt.x; frameY = winAt.y; // remember to decide if windows touch + win = XtWindow(wg); + XGetWindowAttributes(xDisplay, win, &winAt); // this works, where XtGetValues on XtNx, XtNy does not! + XTranslateCoordinates (xDisplay, win, winAt.root, -winAt.border_width, -winAt.border_width, &rx, &ry, &dummy); + wp->x = rx - winAt.x; + wp->y = ry - winAt.y; + wp->height = winAt.height; + wp->width = winAt.width; + frameX = winAt.x; frameY = winAt.y; // remember to decide if windows touch } void @@ -888,7 +879,8 @@ MainWindowUp () return xBoardWindow != 0; } -void SwitchWindow() +void +SwitchWindow () { extern Option dualOptions[]; static Window dual; @@ -930,16 +922,17 @@ ConvertToLine (int argc, char **argv) void InitDrawingSizes (BoardSize boardSize, int flags) { // [HGM] resize is functional now, but for board format changes only (nr of ranks, files) - Dimension timerWidth, boardWidth, boardHeight, w, h, sep, bor, wr, hr; - Arg args[16]; - XtGeometryResult gres; + Dimension boardWidth, boardHeight, w, h; int i; static Dimension oldWidth, oldHeight; static VariantClass oldVariant; - static int oldMono = -1; + static int oldMono = -1, oldTwoBoards = 0; if(!formWidget) return; + if(oldTwoBoards && !twoBoards) PopDown(DummyDlg); + oldTwoBoards = twoBoards; + if(appData.overrideLineGap >= 0) lineGap = appData.overrideLineGap; boardWidth = lineGap + BOARD_WIDTH * (squareSize + lineGap); boardHeight = lineGap + BOARD_HEIGHT * (squareSize + lineGap); @@ -1111,8 +1104,8 @@ InitDrawingParams () void InitializeFonts (int clockFontPxlSize, int coordFontPxlSize, int fontPxlSize) -{ // determine what fonts to use, and create them - XrmValue vFrom, vTo; +{ // detervtomine what fonts to use, and create them + XrmValue vTo; XrmDatabase xdb; if(!fontIsSet[CLOCK_FONT] && fontValid[CLOCK_FONT][squareSize]) @@ -1167,11 +1160,10 @@ InitializeFonts (int clockFontPxlSize, int coordFontPxlSize, int fontPxlSize) int main (int argc, char **argv) { - int i, j, clockFontPxlSize, coordFontPxlSize, fontPxlSize; + int i, clockFontPxlSize, coordFontPxlSize, fontPxlSize; XSetWindowAttributes window_attributes; Arg args[16]; - Dimension timerWidth, boardWidth, boardHeight, w, h, sep, bor, wr, hr; - XtGeometryResult gres; + Dimension boardWidth, boardHeight, w, h; char *p; int forceMono = False; @@ -1193,6 +1185,11 @@ main (int argc, char **argv) programName++; #ifdef ENABLE_NLS + XtSetLanguageProc(NULL, NULL, NULL); + if (appData.debugMode) { + fprintf(debugFP, "locale = %s\n", setlocale(LC_ALL, NULL)); + } + bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); #endif @@ -1256,12 +1253,6 @@ main (int argc, char **argv) XtAppInitialize(&appContext, "XBoard", shellOptions, XtNumber(shellOptions), &argc, argv, xboardResources, NULL, 0); -#ifdef ENABLE_NLS - XtSetLanguageProc(NULL, NULL, NULL); - if (appData.debugMode) { - fprintf(debugFP, "locale = %s\n", setlocale(LC_ALL, NULL)); - } -#endif XtGetApplicationResources(shellWidget, (XtPointer) &appData, clientResources, XtNumber(clientResources), @@ -1467,6 +1458,13 @@ XBoard square size (hint): %d\n\ CreateGrid(); CreateAnyPieces(); + if(appData.logoSize) + { // locate and read user logo + char buf[MSG_SIZ]; + snprintf(buf, MSG_SIZ, "%s/%s.xpm", appData.logoDir, UserName()); + XpmReadFileToPixmap(xDisplay, xBoardWindow, buf, (Pixmap *) &userLogo, NULL, NULL); + } + if (appData.animate || appData.animateDragging) CreateAnimVars(); @@ -1514,6 +1512,7 @@ XBoard square size (hint): %d\n\ gameInfo.boardWidth = 0; // [HGM] pieces: kludge to ensure InitPosition() calls InitDrawingSizes() InitPosition(TRUE); + UpdateLogos(TRUE); // XtSetKeyboardFocus(shellWidget, formWidget); XSetInputFocus(xDisplay, XtWindow(formWidget), RevertToPointerRoot, CurrentTime); @@ -1749,8 +1748,6 @@ CreateOneGC (XGCValues *gc_values, Pixel foreground, Pixel background) static void CreateGCs (int redo) { - XtGCMask value_mask = GCLineWidth | GCLineStyle | GCForeground - | GCBackground | GCFunction | GCPlaneMask; XGCValues gc_values; GC copyInvertedGC; Pixel white = XWhitePixel(xDisplay, xScreen); @@ -2288,7 +2285,7 @@ MarkMenuItem (char *menuRef, int state) } void -EnableMenuItem (char *menuRef, int state) +EnableNamedMenuItem (char *menuRef, int state) { MenuItem *item = MenuNameToItem(menuRef); @@ -2306,7 +2303,7 @@ void SetMenuEnables (Enables *enab) { while (enab->name != NULL) { - EnableMenuItem(enab->name, enab->value); + EnableNamedMenuItem(enab->name, enab->value); enab++; } } @@ -2314,8 +2311,6 @@ SetMenuEnables (Enables *enab) void KeyBindingProc (Widget w, XEvent *event, String *prms, Cardinal *nprms) { // [HGM] new method of key binding: specify MenuItem(FlipView) in stead of FlipViewProc in translation string - int i; - char *p; MenuItem *item; if(*nprms == 0) return; item = MenuNameToItem(prms[0]); @@ -2323,14 +2318,6 @@ KeyBindingProc (Widget w, XEvent *event, String *prms, Cardinal *nprms) } static void -MenuBarSelect (Widget w, caddr_t addr, caddr_t index) -{ - MenuProc *proc = (MenuProc *) addr; - - (proc)(); -} - -static void MenuEngineSelect (Widget w, caddr_t addr, caddr_t index) { RecentEngineEvent((int) (intptr_t) addr); @@ -2403,6 +2390,14 @@ CutOutSquare (int x, int y, int *x0, int *y0, int kind) return 1; } +void +DrawLogo (void *handle, void *logo) +{ + if(!logo || !handle) return; + XCopyArea(xDisplay, (Pixmap) logo, XtWindow((Widget) handle), wlPieceGC, + 0, 0, appData.logoSize, appData.logoSize/2, 0, 0); +} + static void BlankSquare (int x, int y, int color, ChessSquare piece, Drawable dest, int fac) { // [HGM] extra param 'fac' for forcing destination to (0,0) for copying to animation buffer @@ -2817,26 +2812,6 @@ CommentPopDown () PopDown(CommentDlg); } -static char *openName; -FILE *openFP; - -void -DelayedLoad () -{ - (void) (*fileProc)(openFP, 0, openName); -} - -void -FileNamePopUp (char *label, char *def, char *filter, FileProc proc, char *openMode) -{ - fileProc = proc; /* I can't see a way not */ - fileOpenMode = openMode; /* to use globals here */ - { // [HGM] use file-selector dialog stolen from Ghostview - int index; // this is not supported yet - Browse(BoardWindow, label, (def[0] ? def : NULL), filter, False, openMode, &openName, &openFP); - } -} - /* Disable all user input other than deleting the window */ static int frozen = 0; @@ -2902,7 +2877,9 @@ ModeHighlight () MarkMenuItem("Mode.MachineMatch", matchMode && matchGame < appData.matchGames); /* Maybe all the enables should be handled here, not just this one */ - EnableMenuItem("Mode.Training", gameMode == Training || gameMode == PlayFromGameFile); + EnableNamedMenuItem("Mode.Training", gameMode == Training || gameMode == PlayFromGameFile); + + DisplayLogos(optList[W_WHITE-1].handle, optList[W_BLACK+1].handle); } @@ -3162,6 +3139,12 @@ ManInner (Widget w, XEvent *event, String *prms, Cardinal *nprms) } void +ManProc () +{ // called from menu + ManInner(NULL, NULL, NULL, NULL); +} + +void SetWindowTitle (char *text, char *title, char *icon) { Arg args[16]; @@ -3365,7 +3348,7 @@ DisplayTimerLabel (Option *opt, char *color, long timer, int highlight) foregroundOrWarningColor = lowTimeWarningColor; if (appData.clockMode) { - snprintf(buf, MSG_SIZ, "%s: %s", color, TimeString(timer)); + snprintf(buf, MSG_SIZ, "%s:%s%s", color, appData.logoSize && !partnerUp ? "\n" : " ", TimeString(timer)); XtSetArg(args[0], XtNlabel, buf); } else { snprintf(buf, MSG_SIZ, "%s ", color); @@ -3767,9 +3750,30 @@ DrawPolygon (Pnt arrow[], int nr) if(appData.monoMode) arrow[nr] = arrow[0], XDrawLines(xDisplay, xBoardWindow, darkSquareGC, pts, nr+1, CoordModeOrigin); } +static void +LoadLogo (ChessProgramState *cps, int n, Boolean ics) +{ + char buf[MSG_SIZ], *logoName = buf; + if(appData.logo[n][0]) { + logoName = appData.logo[n]; + } else if(appData.autoLogo) { + if(ics) { // [HGM] logo: in ICS mode second can be used for ICS + sprintf(buf, "%s/%s.xpm", appData.logoDir, appData.icsHost); + } else if(appData.directory[n] && appData.directory[n][0]) { + sprintf(buf, "%s/%s.xpm", appData.logoDir, cps->tidy); + } + } + if(logoName[0]) + XpmReadFileToPixmap(xDisplay, xBoardWindow, logoName, (Pixmap *) &(cps->programLogo), NULL, NULL); +} + void UpdateLogos (int displ) { - return; // no logos in XBoard yet + if(optList[W_WHITE-1].handle == NULL) return; + LoadLogo(&first, 0, 0); + LoadLogo(&second, 1, appData.icsActive); + if(displ) DisplayLogos(optList[W_WHITE-1].handle, optList[W_BLACK+1].handle); + return; }