X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=xboard.c;h=edf20c609fec627179cf1cbb589f12df7947202c;hb=bf1467b590e28b4dc641a3c753ce728b90d42081;hp=88bc31db48efda2bb2c4db441f095e944d555d3b;hpb=292d1fc96afcdd5aececf3ec0da28c56bfb1a5a6;p=xboard.git diff --git a/xboard.c b/xboard.c index 88bc31d..edf20c6 100644 --- a/xboard.c +++ b/xboard.c @@ -5,7 +5,7 @@ * Massachusetts. * * Enhancements Copyright 1992-2001, 2002, 2003, 2004, 2005, 2006, - * 2007, 2008, 2009 Free Software Foundation, Inc. + * 2007, 2008, 2009, 2010 Free Software Foundation, Inc. * * The following terms apply to Digital Equipment Corporation's copyright * interest in XBoard: @@ -49,6 +49,8 @@ *------------------------------------------------------------------------ ** See the file ChangeLog for a revision history. */ +#define HIGHDRAG 1 + #include "config.h" #include @@ -256,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, @@ -440,6 +444,8 @@ void TimeControlProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)) void NewVariantProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void FirstSettingsProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void SecondSettingsProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); +void GameListOptionsPopUp P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); +void GameListOptionsPopDown P(()); void ShufflePopDown P(()); void EnginePopDown P(()); void UciPopDown P(()); @@ -660,6 +666,7 @@ MenuItem optionsMenu[] = { {N_("Engine #1 Settings ..."), FirstSettingsProc}, {N_("Engine #2 Settings ..."), SecondSettingsProc}, {N_("Time Control ..."), TimeControlProc}, + {N_("Game List ..."), GameListOptionsPopUp}, {"----", NothingProc}, {N_("Always Queen"), AlwaysQueenProc}, {N_("Animate Dragging"), AnimateDraggingProc}, @@ -832,6 +839,8 @@ XtActionsRec boardActions[] = { { "DrawPosition", DrawPositionProc }, { "HandleUserMove", HandleUserMove }, { "AnimateUserMove", AnimateUserMove }, + { "HandlePV", HandlePV }, + { "UnLoadPV", UnLoadPV }, { "FileNameAction", FileNameAction }, { "AskQuestionProc", AskQuestionProc }, { "AskQuestionReplyAction", AskQuestionReplyAction }, @@ -844,6 +853,7 @@ XtActionsRec boardActions[] = { { "LoadNextGameProc", LoadNextGameProc }, { "LoadPrevGameProc", LoadPrevGameProc }, { "LoadSelectedProc", LoadSelectedProc }, + { "SetFilterProc", SetFilterProc }, { "ReloadGameProc", ReloadGameProc }, { "LoadPositionProc", LoadPositionProc }, { "LoadNextPositionProc", LoadNextPositionProc }, @@ -945,6 +955,7 @@ XtActionsRec boardActions[] = { { "FileNamePopDown", (XtActionProc) FileNamePopDown }, { "AskQuestionPopDown", (XtActionProc) AskQuestionPopDown }, { "GameListPopDown", (XtActionProc) GameListPopDown }, + { "GameListOptionsPopDown", (XtActionProc) GameListOptionsPopDown }, { "PromotionPopDown", (XtActionProc) PromotionPopDown }, { "HistoryPopDown", (XtActionProc) HistoryPopDown }, { "EngineOutputPopDown", (XtActionProc) EngineOutputPopDown }, @@ -988,6 +999,8 @@ char boardTranslations[] = ": HandleUserMove() \n \ : HandleUserMove() \n \ : AnimateUserMove() \n \ + : HandlePV() \n \ + : PieceMenuPopup(menuB) \n \ Shift: XawPositionSimpleMenu(menuB) XawPositionSimpleMenu(menuD)\ PieceMenuPopup(menuB) \n \ Any: XawPositionSimpleMenu(menuW) XawPositionSimpleMenu(menuD) \ @@ -1258,7 +1271,6 @@ BoardToTop() #define SEPCHAR " " // these two must some day move to frontend.h, when they are implemented -Boolean MoveHistoryIsUp(); Boolean GameListIsUp(); // The option definition and parsing code common to XBoard and WinBoard is collected in this file @@ -1277,7 +1289,7 @@ colorVariable[] = { &appData.darkSquareColor, &appData.highlightSquareColor, &appData.premoveHighlightColor, - NULL, + &appData.lowTimeWarningColor, NULL, NULL, NULL, @@ -1288,9 +1300,25 @@ colorVariable[] = { NULL }; +// [HGM] font: keep a font for each square size, even non-stndard ones +#define NUM_SIZES 18 +#define MAX_SIZE 130 +Boolean fontSet[NUM_FONTS], fontValid[NUM_FONTS][MAX_SIZE]; +char *fontTable[NUM_FONTS][MAX_SIZE]; + void ParseFont(char *name, int number) { // in XBoard, only 2 of the fonts are currently implemented, and we just copy their name + int size; + if(sscanf(name, "size%d:", &size)) { + // [HGM] font: font is meant for specific boardSize (likely from settings file); + // defer processing it until we know if it matches our board size + if(size >= 0 && sizeargLoc) { + char *name, buf[MSG_SIZ]; + int i, n = (int)ad->argLoc; + switch(n) { case 0: // CLOCK_FONT name = appData.clockFont; break; @@ -1365,9 +1395,14 @@ SaveFontArg(FILE *f, ArgDescriptor *ad) default: return; } -// 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); + for(i=0; iargName, i, fontTable[n][i]); } void @@ -1808,7 +1843,14 @@ main(argc, argv) fontPxlSize = szd->fontPxlSize; smallLayout = szd->smallLayout; tinyLayout = szd->tinyLayout; + // [HGM] font: use defaults from settings file if available and not overruled } + if(!fontSet[CLOCK_FONT] && fontValid[CLOCK_FONT][squareSize]) + appData.clockFont = fontTable[CLOCK_FONT][squareSize]; + if(!fontSet[MESSAGE_FONT] && fontValid[MESSAGE_FONT][squareSize]) + appData.font = fontTable[MESSAGE_FONT][squareSize]; + if(!fontSet[COORD_FONT] && fontValid[COORD_FONT][squareSize]) + appData.coordFont = fontTable[COORD_FONT][squareSize]; /* Now, using squareSize as a hint, find a good XPM/XIM set size */ if (strlen(appData.pixmapDirectory) > 0) { @@ -2427,7 +2469,7 @@ XBoard square size (hint): %d\n\ /* Why is the following needed on some versions of X instead * of a translation? */ - XtAddEventHandler(boardWidget, ExposureMask, False, + XtAddEventHandler(boardWidget, ExposureMask|PointerMotionMask, False, (XtEventHandler) EventProc, NULL); /* end why */ @@ -3672,39 +3714,18 @@ void PieceMenuPopup(w, event, params, num_params) String *params; Cardinal *num_params; { - String whichMenu; - if (event->type != ButtonPress) return; - if (errorUp) ErrorPopDown(); - switch (gameMode) { - case EditPosition: - case IcsExamining: - whichMenu = params[0]; - break; - case IcsPlayingWhite: - case IcsPlayingBlack: - case EditGame: - case MachinePlaysWhite: - case MachinePlaysBlack: - if (appData.testLegality && - gameInfo.variant != VariantBughouse && - gameInfo.variant != VariantCrazyhouse) return; - SetupDropMenu(); - whichMenu = "menuD"; - break; - default: - return; + String whichMenu; int menuNr; + if (event->type == ButtonRelease) + menuNr = RightClick(Release, event->xbutton.x, event->xbutton.y, &pmFromX, &pmFromY); + else if (event->type == ButtonPress) + menuNr = RightClick(Press, event->xbutton.x, event->xbutton.y, &pmFromX, &pmFromY); + switch(menuNr) { + case 0: whichMenu = params[0]; break; + case 1: SetupDropMenu(); whichMenu = "menuD"; break; + case 2: + case -1: if (errorUp) ErrorPopDown(); + default: return; } - - if (((pmFromX = EventToSquare(event->xbutton.x, BOARD_WIDTH)) < 0) || - ((pmFromY = EventToSquare(event->xbutton.y, BOARD_HEIGHT)) < 0)) { - pmFromX = pmFromY = -1; - return; - } - if (flipView) - pmFromX = BOARD_WIDTH - 1 - pmFromX; - else - pmFromY = BOARD_HEIGHT - 1 - pmFromY; - XtPopupSpringLoaded(XtNameToWidget(boardWidget, whichMenu)); } @@ -3812,14 +3833,18 @@ SetHighlights(fromX, fromY, toX, toY) if (hi1X >= 0 && hi1Y >= 0) { drawHighlight(hi1X, hi1Y, lineGC); } + } // [HGM] first erase both, then draw new! + if (hi2X != toX || hi2Y != toY) { + if (hi2X >= 0 && hi2Y >= 0) { + drawHighlight(hi2X, hi2Y, lineGC); + } + } + if (hi1X != fromX || hi1Y != fromY) { if (fromX >= 0 && fromY >= 0) { drawHighlight(fromX, fromY, highlineGC); } } if (hi2X != toX || hi2Y != toY) { - if (hi2X >= 0 && hi2Y >= 0) { - drawHighlight(hi2X, hi2Y, lineGC); - } if (toX >= 0 && toY >= 0) { drawHighlight(toX, toY, highlineGC); } @@ -4177,6 +4202,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); + } } @@ -4194,6 +4223,8 @@ void EventProc(widget, unused, event) if (event->xexpose.count > 0) return; /* no clipping is done */ XDrawPosition(widget, True, NULL); break; + case MotionNotify: + if(SeekGraphClick(Press, event->xbutton.x, event->xbutton.y, 1)) break; default: return; } @@ -4274,6 +4305,36 @@ static int check_castle_draw(newb, oldb, rrow, rcol) return 0; } +// [HGM] seekgraph: some low-level drawing routines cloned from xevalgraph +void DrawSeekAxis( int x, int y, int xTo, int yTo ) +{ + XDrawLine(xDisplay, xBoardWindow, lineGC, x, y, xTo, yTo); +} + +void DrawSeekBackground( int left, int top, int right, int bottom ) +{ + XFillRectangle(xDisplay, xBoardWindow, lightSquareGC, left, top, right-left, bottom-top); +} + +void DrawSeekText(char *buf, int x, int y) +{ + XDrawString(xDisplay, xBoardWindow, coordGC, x, y+4, buf, strlen(buf)); +} + +void DrawSeekDot(int x, int y, int colorNr) +{ + int square = colorNr & 0x80; + GC color; + colorNr &= 0x7F; + color = colorNr == 0 ? prelineGC : colorNr == 1 ? darkSquareGC : highlineGC; + if(square) + XFillRectangle(xDisplay, xBoardWindow, color, + x-squareSize/9, y-squareSize/9, 2*squareSize/9, 2*squareSize/9); + else + XFillArc(xDisplay, xBoardWindow, color, + x-squareSize/8, y-squareSize/8, squareSize/4, squareSize/4, 0, 64*360); +} + static int damage[BOARD_RANKS][BOARD_FILES]; /* @@ -4291,6 +4352,8 @@ void XDrawPosition(w, repaint, board) Arg args[16]; int rrow, rcol; + if(DrawSeekGraph()) return; // [HGM] seekgraph: suppress any drawing if seek graph up + if (board == NULL) { if (!lastBoardValid) return; board = lastBoard; @@ -4430,6 +4493,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; @@ -8606,7 +8675,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);