X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=xboard.c;h=8106b9c80e7ff0419f0f99f065160189ad399d81;hb=d138c95b1f4dad365548a9d77321f626ef704c90;hp=d7ea5a7eb68211d503103e1957bb318d01e15dac;hpb=acca181c7d39eea4904084170f8b5fae08361846;p=xboard.git diff --git a/xboard.c b/xboard.c index d7ea5a7..8106b9c 100644 --- a/xboard.c +++ b/xboard.c @@ -49,6 +49,8 @@ *------------------------------------------------------------------------ ** See the file ChangeLog for a revision history. */ +#define HIGHDRAG 1 + #include "config.h" #include @@ -200,7 +202,9 @@ extern char *getenv(); // must be moved to xengineoutput.h void EngineOutputProc P((Widget w, XEvent *event, - String *prms, Cardinal *nprms)); + String *prms, Cardinal *nprms)); +void EvalGraphProc P((Widget w, XEvent *event, + String *prms, Cardinal *nprms)); #ifdef __EMX__ @@ -254,6 +258,8 @@ void HandleUserMove P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void AnimateUserMove P((Widget w, XEvent * event, String * params, Cardinal * nParams)); +void HandlePV P((Widget w, XEvent * event, + String * params, Cardinal * nParams)); void WhiteClock P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void BlackClock P((Widget w, XEvent *event, @@ -446,6 +452,7 @@ void NewVariantPopDown P(()); void SettingsPopDown P(()); void update_ics_width P(()); int get_term_width P(()); +int CopyMemoProc P(()); /* * XBoard depends on Xt R4 or higher */ @@ -466,6 +473,7 @@ Widget shellWidget, layoutWidget, formWidget, boardWidget, messageWidget, commentShell, promotionShell, whitePieceMenu, blackPieceMenu, dropMenu, menuBarWidget, buttonBarWidget, editShell, errorShell, analysisShell, ICSInputShell, fileNameShell, askQuestionShell; +Widget historyShell, evalGraphShell, gameListShell; XSegment gridSegments[BOARD_RANKS + BOARD_FILES + 2]; XSegment jailGridSegments[BOARD_RANKS + BOARD_FILES + 6]; Font clockFontID, coordFontID, countFontID; @@ -604,9 +612,9 @@ MenuItem modeMenu[] = { {N_("Training"), TrainingProc}, {"----", NothingProc}, {N_("Show Engine Output"), EngineOutputProc}, - {N_("Show Evaluation Graph"), NothingProc}, // [HGM] evalgr: not functional yet + {N_("Show Evaluation Graph"), EvalGraphProc}, {N_("Show Game List"), ShowGameListProc}, - {"Show Move History", HistoryShowProc}, // [HGM] hist: activate 4.2.7 code + {N_("Show Move History"), HistoryShowProc}, // [HGM] hist: activate 4.2.7 code {"----", NothingProc}, {N_("Edit Tags"), EditTagsProc}, {N_("Edit Comment"), EditCommentProc}, @@ -828,6 +836,8 @@ XtActionsRec boardActions[] = { { "DrawPosition", DrawPositionProc }, { "HandleUserMove", HandleUserMove }, { "AnimateUserMove", AnimateUserMove }, + { "HandlePV", HandlePV }, + { "UnLoadPV", UnLoadPV }, { "FileNameAction", FileNameAction }, { "AskQuestionProc", AskQuestionProc }, { "AskQuestionReplyAction", AskQuestionReplyAction }, @@ -864,6 +874,7 @@ XtActionsRec boardActions[] = { { "EditPositionProc", EditPositionProc }, { "TrainingProc", EditPositionProc }, { "EngineOutputProc", EngineOutputProc}, // [HGM] Winboard_x engine-output window + { "EvalGraphProc", EvalGraphProc}, // [HGM] Winboard_x avaluation graph window { "ShowGameListProc", ShowGameListProc }, { "ShowMoveListProc", HistoryShowProc}, { "EditTagsProc", EditCommentProc }, @@ -943,12 +954,14 @@ XtActionsRec boardActions[] = { { "PromotionPopDown", (XtActionProc) PromotionPopDown }, { "HistoryPopDown", (XtActionProc) HistoryPopDown }, { "EngineOutputPopDown", (XtActionProc) EngineOutputPopDown }, + { "EvalGraphPopDown", (XtActionProc) EvalGraphPopDown }, { "ShufflePopDown", (XtActionProc) ShufflePopDown }, { "EnginePopDown", (XtActionProc) EnginePopDown }, { "UciPopDown", (XtActionProc) UciPopDown }, { "TimeControlPopDown", (XtActionProc) TimeControlPopDown }, { "NewVariantPopDown", (XtActionProc) NewVariantPopDown }, { "SettingsPopDown", (XtActionProc) SettingsPopDown }, + { "CopyMemoProc", (XtActionProc) CopyMemoProc }, }; char globalTranslations[] = @@ -981,6 +994,8 @@ char boardTranslations[] = ": HandleUserMove() \n \ : HandleUserMove() \n \ : AnimateUserMove() \n \ + : HandlePV() \n \ + : UnLoadPV() \n \ Shift: XawPositionSimpleMenu(menuB) XawPositionSimpleMenu(menuD)\ PieceMenuPopup(menuB) \n \ Any: XawPositionSimpleMenu(menuW) XawPositionSimpleMenu(menuD) \ @@ -1244,12 +1259,14 @@ BoardToTop() #define JAWS_ARGS #define CW_USEDEFAULT (1<<31) #define ICS_TEXT_MENU_SIZE 90 +#define DEBUG_FILE "xboard.debug" #define SetCurrentDirectory chdir #define GetCurrentDirectory(SIZE, NAME) getcwd(NAME, SIZE) +#define OPTCHAR "-" +#define SEPCHAR " " // these two must some day move to frontend.h, when they are implemented -Boolean EvalGraphIsUp(); -Boolean MoveHistoryIsUp(); +Boolean GameListIsUp(); // The option definition and parsing code common to XBoard and WinBoard is collected in this file #include "args.h" @@ -1257,6 +1274,8 @@ Boolean MoveHistoryIsUp(); // front-end part of option handling // [HGM] This platform-dependent table provides the location for storing the color info +extern char *crWhite, * crBlack; + void * colorVariable[] = { &appData.whitePieceColor, @@ -1265,14 +1284,14 @@ colorVariable[] = { &appData.darkSquareColor, &appData.highlightSquareColor, &appData.premoveHighlightColor, + &appData.lowTimeWarningColor, NULL, NULL, NULL, NULL, NULL, - NULL, - NULL, - NULL, + &crWhite, + &crBlack, NULL }; @@ -1353,7 +1372,9 @@ SaveFontArg(FILE *f, ArgDescriptor *ad) default: return; } - fprintf(f, "/%s=%s\n", ad->argName, name); +// Do not save fonts for now, as the saved font would be board-size specific +// and not suitable for a re-start at another board size +// fprintf(f, OPTCHAR "%s" SEPCHAR "%s\n", ad->argName, name); } void @@ -1364,20 +1385,20 @@ ExportSounds() void SaveAttribsArg(FILE *f, ArgDescriptor *ad) { // here the "argLoc" defines a table index. It could have contained the 'ta' pointer itself, though - fprintf(f, "/%s=%s\n", ad->argName, (&appData.colorShout)[(int)ad->argLoc]); + fprintf(f, OPTCHAR "%s" SEPCHAR "%s\n", ad->argName, (&appData.colorShout)[(int)ad->argLoc]); } void SaveColor(FILE *f, ArgDescriptor *ad) { // in WinBoard the color is an int and has to be converted to text. In X it would be a string already? if(colorVariable[(int)ad->argLoc]) - fprintf(f, "/%s=%s\n", ad->argName, *(char**)colorVariable[(int)ad->argLoc]); + fprintf(f, OPTCHAR "%s" SEPCHAR "%s\n", ad->argName, *(char**)colorVariable[(int)ad->argLoc]); } void SaveBoardSize(FILE *f, char *name, void *addr) { // wrapper to shield back-end from BoardSize & sizeInfo - fprintf(f, "/%s=%s\n", name, appData.boardSize); + fprintf(f, OPTCHAR "%s" SEPCHAR "%s\n", name, appData.boardSize); } void @@ -1385,20 +1406,43 @@ ParseCommPortSettings(char *s) { // no such option in XBoard (yet) } +extern Widget engineOutputShell; +extern Widget tagsShell, editTagsShell; +void +GetActualPlacement(Widget wg, WindowPlacement *wp) +{ + Arg args[16]; + Dimension w, h; + Position x, y; + int i; + + if(!wg) return; + + i = 0; + XtSetArg(args[i], XtNx, &x); i++; + XtSetArg(args[i], XtNy, &y); i++; + XtSetArg(args[i], XtNwidth, &w); i++; + XtSetArg(args[i], XtNheight, &h); i++; + XtGetValues(wg, args, i); + wp->x = x - 4; + wp->y = y - 23; + wp->height = h; + wp->width = w; +} + void GetWindowCoords() { // wrapper to shield use of window handles from back-end (make addressible by number?) -#if 0 // In XBoard this will have to wait until awareness of window parameters is implemented - GetActualPlacement(hwndMain, &wpMain); - GetActualPlacement(hwndConsole, &wpConsole); - GetActualPlacement(commentDialog, &wpComment); - GetActualPlacement(editTagsDialog, &wpTags); - GetActualPlacement(gameListDialog, &wpGameList); - GetActualPlacement(moveHistoryDialog, &wpMoveHistory); - GetActualPlacement(evalGraphDialog, &wpEvalGraph); - GetActualPlacement(engineOutputDialog, &wpEngineOutput); -#endif + GetActualPlacement(shellWidget, &wpMain); + if(EngineOutputIsUp()) GetActualPlacement(engineOutputShell, &wpEngineOutput); else + if(MoveHistoryIsUp()) GetActualPlacement(historyShell, &wpMoveHistory); + if(EvalGraphIsUp()) GetActualPlacement(evalGraphShell, &wpEvalGraph); + if(GameListIsUp()) GetActualPlacement(gameListShell, &wpGameList); + if(commentShell) GetActualPlacement(commentShell, &wpComment); + else GetActualPlacement(editShell, &wpComment); + if(tagsShell) GetActualPlacement(tagsShell, &wpTags); + else GetActualPlacement(editTagsShell, &wpTags); } void @@ -1430,18 +1474,6 @@ EnsureOnScreen(int *x, int *y, int minX, int minY) return; } -Boolean -MoveHistoryIsUp() -{ - return True; // still have to fix this ***************************************************************************** -} - -Boolean -EvalGraphIsUp() -{ - return False; -} - int MainWindowUp() { // [HGM] args: allows testing if main window is realized from back-end @@ -1635,49 +1667,18 @@ main(argc, argv) char *p; XrmDatabase xdb; int forceMono = False; -//define INDIRECTION -#ifdef INDIRECTION - // [HGM] before anything else, expand any indirection files amongst options - char *argvCopy[1000]; // 1000 seems enough - char newArgs[10000]; // holds actual characters - int k = 0; srandom(time(0)); // [HGM] book: make random truly random - j = 0; - for(i=0; i= 1000-2) { printf(_("too many arguments\n")); exit(-1); } -//fprintf(stderr, "arg %s\n", argv[i]); - if(argv[i][0] != '@') argvCopy[j++] = argv[i]; else { - char c; - FILE *f = fopen(argv[i]+1, "rb"); - if(f == NULL) { fprintf(stderr, _("ignore %s\n"), argv[i]); continue; } // do not expand non-existing - argvCopy[j++] = newArgs + k; // get ready for first argument from file - while((c = fgetc(f)) != EOF) { // each line of file inserts 1 argument in the list - if(c == '\n') { - if(j >= 1000-2) { printf(_("too many arguments\n")); exit(-1); } - newArgs[k++] = 0; // terminate current arg - if(k >= 10000-1) { printf(_("too long arguments\n")); exit(-1); } - argvCopy[j++] = newArgs + k; // get ready for next - } else { - if(k >= 10000-1) { printf(_("too long arguments\n")); exit(-1); } - newArgs[k++] = c; - } - } - newArgs[k] = 0; - j--; - fclose(f); - } - } - argvCopy[j] = NULL; - argv = argvCopy; - argc = j; -#endif - setbuf(stdout, NULL); setbuf(stderr, NULL); debugFP = stderr; + if(argc > 1 && (!strcmp(argv[1], "-v" ) || !strcmp(argv[1], "--version" ))) { + printf("%s version %s\n", PACKAGE_NAME, PACKAGE_VERSION); + exit(0); + } + programName = strrchr(argv[0], '/'); if (programName == NULL) programName = argv[0]; @@ -2166,6 +2167,12 @@ XBoard square size (hint): %d\n\ XtRealizeWidget(shellWidget); + if(wpMain.x > 0) { + XtSetArg(args[0], XtNx, wpMain.x); + XtSetArg(args[1], XtNy, wpMain.y); + XtSetValues(shellWidget, args, 2); + } + /* * Correct the width of the message and title widgets. * It is not known why some systems need the extra fudge term. @@ -2431,6 +2438,20 @@ XBoard square size (hint): %d\n\ (XtEventHandler) EventProc, NULL); /* end why */ + /* [AS] Restore layout */ + if( wpMoveHistory.visible ) { + HistoryPopUp(); + } + + if( wpEvalGraph.visible ) + { + EvalGraphPopUp(); + }; + + if( wpEngineOutput.visible ) { + EngineOutputPopUp(); + } + InitBackEnd2(); if (errorExitStatus == -1) { @@ -3659,6 +3680,8 @@ void PieceMenuPopup(w, event, params, num_params) Cardinal *num_params; { String whichMenu; + + if (event->type != ButtonRelease) UnLoadPV(); // [HGM] pv if (event->type != ButtonPress) return; if (errorUp) ErrorPopDown(); switch (gameMode) { @@ -3666,12 +3689,25 @@ void PieceMenuPopup(w, event, params, num_params) case IcsExamining: whichMenu = params[0]; break; + case IcsObserving: + if(!appData.icsEngineAnalyze) return; case IcsPlayingWhite: case IcsPlayingBlack: - case EditGame: + if(!appData.zippyPlay) goto noZip; + case AnalyzeMode: + case AnalyzeFile: case MachinePlaysWhite: case MachinePlaysBlack: - if (appData.testLegality && + case TwoMachinesPlay: // [HGM] pv: use for showing PV + if (!appData.dropMenu) { + LoadPV(event->xbutton.x, event->xbutton.y); + return; + } + if(gameMode == TwoMachinesPlay || gameMode == AnalyzeMode || + gameMode == AnalyzeFile || gameMode == IcsObserving) return; + case EditGame: + noZip: + if (!appData.dropMenu || appData.testLegality && gameInfo.variant != VariantBughouse && gameInfo.variant != VariantCrazyhouse) return; SetupDropMenu(); @@ -4163,6 +4199,10 @@ void DrawSquare(row, column, piece, do_flash) x + 2, y + font_ascent + 1, string, 1); } } + if(marker[row][column]) { + XFillArc(xDisplay, xBoardWindow, marker[row][column] == 2 ? prelineGC : highlineGC, + x + squareSize/4, y+squareSize/4, squareSize/2, squareSize/2, 0, 64*360); + } } @@ -4416,6 +4456,12 @@ void AnimateUserMove (Widget w, XEvent * event, DragPieceMove(event->xmotion.x, event->xmotion.y); } +void HandlePV (Widget w, XEvent * event, + String * params, Cardinal * nParams) +{ // [HGM] pv: walk PV + MovePV(event->xmotion.x, event->xmotion.y, lineGap + BOARD_HEIGHT * (squareSize + lineGap)); +} + Widget CommentCreate(name, text, mutable, callback, lines) char *name, *text; int /*Boolean*/ mutable; @@ -4560,6 +4606,14 @@ Widget CommentCreate(name, text, mutable, callback, lines) #endif /*!NOTDEF*/ if (commentY < 0) commentY = 0; /*avoid positioning top offscreen*/ } + + if(wpComment.width > 0) { + commentX = wpComment.x; + commentY = wpComment.y; + commentW = wpComment.width; + commentH = wpComment.height; + } + j = 0; XtSetArg(args[j], XtNheight, commentH); j++; XtSetArg(args[j], XtNwidth, commentW); j++; @@ -5500,9 +5554,9 @@ void MailMoveProc(w, event, prms, nprms) } /* this variable is shared between CopyPositionProc and SendPositionSelection */ -static char *selected_fen_position=NULL; +char *selected_fen_position=NULL; -static Boolean +Boolean SendPositionSelection(Widget w, Atom *selection, Atom *target, Atom *type_return, XtPointer *value_return, unsigned long *length_return, int *format_return) @@ -5554,6 +5608,7 @@ void CopyPositionProc(w, event, prms, nprms) * have a notion of a position that is selected but not copied. * See http://www.freedesktop.org/wiki/Specifications/ClipboardsWiki */ + if(gameMode == EditPosition) EditPositionDone(TRUE); if (selected_fen_position) free(selected_fen_position); selected_fen_position = (char *)PositionToFEN(currentMove, NULL); if (!selected_fen_position) return; @@ -7520,8 +7575,11 @@ int StartChildProcess(cmdLine, dir, pr) strcpy(buf, cmdLine); p = buf; for (;;) { + while(*p == ' ') p++; argv[i++] = p; - p = strchr(p, ' '); + if(*p == '"' || *p == '\'') + p = strchr(++argv[i-1], *p); + else p = strchr(p, ' '); if (p == NULL) break; *p++ = NULLCHAR; } @@ -8580,7 +8638,7 @@ DragPieceMove(x, y) corner.x = x - player.mouseDelta.x; corner.y = y - player.mouseDelta.y; AnimationFrame(&player, &corner, player.dragPiece); -#if HIGHDRAG +#if HIGHDRAG*0 if (appData.highlightDragging) { int boardX, boardY; BoardSquare(x, y, &boardX, &boardY);