X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=xboard.c;h=ecf421ca8599562d5cc294bfd2bf9a9a7467d673;hb=29f26a97a226db6e7bdd0927e67cf5a5ce3dd065;hp=527c3b334a409f7fae24b0d1a9eeff100d705521;hpb=b9fc0b7de303a80d0be96e1ee40917d949370726;p=xboard.git diff --git a/xboard.c b/xboard.c index 527c3b3..ecf421c 100644 --- a/xboard.c +++ b/xboard.c @@ -1686,7 +1686,7 @@ void InitDrawingSizes(BoardSize boardSize, int flags) int i; static Dimension oldWidth, oldHeight; static VariantClass oldVariant; - static int oldDual = -1; + static int oldDual = -1, oldMono = -1; if(!formWidget) return; @@ -1765,7 +1765,7 @@ void InitDrawingSizes(BoardSize boardSize, int flags) // [HGM] pieces: tailor piece bitmaps to needs of specific variant // (only for xpm) - if(gameInfo.variant == oldVariant) return; // and only if variant changed + if(gameInfo.variant != oldVariant) { // and only if variant changed if(useImages) { for(i=0; i<4; i++) { @@ -1833,9 +1833,12 @@ void InitDrawingSizes(BoardSize boardSize, int flags) } } } + } #if HAVE_LIBXPM + if(appData.monoMode == oldMono) CreateAnimVars(); #endif + oldMono = appData.monoMode; } #endif @@ -1943,7 +1946,7 @@ CreateAnyPieces() #if HAVE_LIBXPM if (appData.monoMode && // [HGM] no sense to go on to certain doom (appData.bitmapDirectory == NULL || appData.bitmapDirectory[0] == NULLCHAR)) - appData.bitmapDirectory = DEF_BITMAP_DIR; + appData.bitmapDirectory = strdup(DEF_BITMAP_DIR); if (appData.bitmapDirectory[0] != NULLCHAR) { CreatePieces(); @@ -4639,6 +4642,12 @@ void DrawSquare(row, column, piece, do_flash) } } if(!partnerUp && marker[row][column]) { + if(appData.monoMode) { + XFillArc(xDisplay, xBoardWindow, marker[row][column] == 2 ? darkSquareGC : lightSquareGC, + x + squareSize/4, y+squareSize/4, squareSize/2, squareSize/2, 0, 64*360); + XDrawArc(xDisplay, xBoardWindow, marker[row][column] == 2 ? lightSquareGC : darkSquareGC, + x + squareSize/4, y+squareSize/4, squareSize/2, squareSize/2, 0, 64*360); + } else XFillArc(xDisplay, xBoardWindow, marker[row][column] == 2 ? prelineGC : highlineGC, x + squareSize/4, y+squareSize/4, squareSize/2, squareSize/2, 0, 64*360); } @@ -5124,6 +5133,7 @@ void PromotionPopUp() Position x, y; Dimension bw_width, pw_width; int j; + char *PromoChars = "wglcqrbnkac+=\0"; j = 0; XtSetArg(args[j], XtNwidth, &bw_width); j++; @@ -5147,47 +5157,33 @@ void PromotionPopUp() if(gameInfo.variant != VariantShogi) { if(gameInfo.variant == VariantSpartan && !WhiteOnMove(currentMove)) { - XawDialogAddButton(dialog, _("Warlord"), PromotionCallback, - (XtPointer) dialog); - XawDialogAddButton(dialog, _("General"), PromotionCallback, - (XtPointer) dialog); - XawDialogAddButton(dialog, _("Lieutenant"), PromotionCallback, - (XtPointer) dialog); - XawDialogAddButton(dialog, _("Captain"), PromotionCallback, - (XtPointer) dialog); + XawDialogAddButton(dialog, _("Warlord"), PromotionCallback, PromoChars + 0); + XawDialogAddButton(dialog, _("General"), PromotionCallback, PromoChars + 1); + XawDialogAddButton(dialog, _("Lieutenant"), PromotionCallback, PromoChars + 2); + XawDialogAddButton(dialog, _("Captain"), PromotionCallback, PromoChars + 3); } else { - XawDialogAddButton(dialog, _("Queen"), PromotionCallback, - (XtPointer) dialog); - XawDialogAddButton(dialog, _("Rook"), PromotionCallback, - (XtPointer) dialog); - XawDialogAddButton(dialog, _("Bishop"), PromotionCallback, - (XtPointer) dialog); - XawDialogAddButton(dialog, _("Knight"), PromotionCallback, - (XtPointer) dialog); + XawDialogAddButton(dialog, _("Queen"), PromotionCallback, PromoChars + 4); + XawDialogAddButton(dialog, _("Rook"), PromotionCallback, PromoChars + 5); + XawDialogAddButton(dialog, _("Bishop"), PromotionCallback, PromoChars + 6); + XawDialogAddButton(dialog, _("Knight"), PromotionCallback, PromoChars + 7); } if (!appData.testLegality || gameInfo.variant == VariantSuicide || gameInfo.variant == VariantSpartan && !WhiteOnMove(currentMove) || gameInfo.variant == VariantGiveaway) { - XawDialogAddButton(dialog, _("King"), PromotionCallback, - (XtPointer) dialog); + XawDialogAddButton(dialog, _("King"), PromotionCallback, PromoChars + 8); } if(gameInfo.variant == VariantCapablanca || gameInfo.variant == VariantGothic || gameInfo.variant == VariantCapaRandom) { - XawDialogAddButton(dialog, _("Archbishop"), PromotionCallback, - (XtPointer) dialog); - XawDialogAddButton(dialog, _("Chancellor"), PromotionCallback, - (XtPointer) dialog); + XawDialogAddButton(dialog, _("Archbishop"), PromotionCallback, PromoChars + 9); + XawDialogAddButton(dialog, _("Chancellor"), PromotionCallback, PromoChars + 10); } } else // [HGM] shogi { - XawDialogAddButton(dialog, _("Promote"), PromotionCallback, - (XtPointer) dialog); - XawDialogAddButton(dialog, _("Defer"), PromotionCallback, - (XtPointer) dialog); + XawDialogAddButton(dialog, _("Promote"), PromotionCallback, PromoChars + 11); + XawDialogAddButton(dialog, _("Defer"), PromotionCallback, PromoChars + 12); } - XawDialogAddButton(dialog, _("cancel"), PromotionCallback, - (XtPointer) dialog); + XawDialogAddButton(dialog, _("cancel"), PromotionCallback, PromoChars + 13); XtRealizeWidget(promotionShell); CatchDeleteWindow(promotionShell, "PromotionPopDown"); @@ -5223,31 +5219,17 @@ void PromotionCallback(w, client_data, call_data) Widget w; XtPointer client_data, call_data; { - String name; - Arg args[16]; - int promoChar; - - XtSetArg(args[0], XtNlabel, &name); - XtGetValues(w, args, 1); + int promoChar = * (const char *) client_data; PromotionPopDown(); if (fromX == -1) return; - if (strcmp(name, _("cancel")) == 0) { + if (! promoChar) { fromX = fromY = -1; ClearHighlights(); return; - } else if (strcmp(name, _("Knight")) == 0) { - promoChar = 'n'; - } else if (strcmp(name, _("Promote")) == 0) { - promoChar = '+'; - } else if (strcmp(name, _("Defer")) == 0) { - promoChar = '='; - } else { - promoChar = ToLower(name[0]); } - UserMoveEvent(fromX, fromY, toX, toY, promoChar); if (!appData.highlightLastMove || gotPremove) ClearHighlights(); @@ -5643,11 +5625,19 @@ SendPositionSelection(Widget w, Atom *selection, Atom *target, *value_return = targets_tmp; *type_return = XA_ATOM; *length_return = 2; +#if 0 + // This code leads to a read of value_return out of bounds on 64-bit systems. + // Other code which I have seen always sets *format_return to 32 independent of + // sizeof(Atom) without adjusting *length_return. For instance see TextConvertSelection() + // at http://cgit.freedesktop.org/xorg/lib/libXaw/tree/src/Text.c -- BJ *format_return = 8 * sizeof(Atom); if (*format_return > 32) { *length_return *= *format_return / 32; *format_return = 32; } +#else + *format_return = 32; +#endif return True; } else { return False; @@ -5752,11 +5742,19 @@ SendGameSelection(Widget w, Atom *selection, Atom *target, *value_return = targets_tmp; *type_return = XA_ATOM; *length_return = 2; +#if 0 + // This code leads to a read of value_return out of bounds on 64-bit systems. + // Other code which I have seen always sets *format_return to 32 independent of + // sizeof(Atom) without adjusting *length_return. For instance see TextConvertSelection() + // at http://cgit.freedesktop.org/xorg/lib/libXaw/tree/src/Text.c -- BJ *format_return = 8 * sizeof(Atom); if (*format_return > 32) { *length_return *= *format_return / 32; *format_return = 32; } +#else + *format_return = 32; +#endif return True; } else { return False; @@ -8908,7 +8906,7 @@ void SquareToPos(int rank, int file, int *x, int *y) /* Draw an arrow between two points using current settings */ void DrawArrowBetweenPoints( int s_x, int s_y, int d_x, int d_y ) { - XPoint arrow[7]; + XPoint arrow[8]; double dx, dy, j, k, x, y; if( d_x == s_x ) { @@ -9005,6 +9003,7 @@ void DrawArrowBetweenPoints( int s_x, int s_y, int d_x, int d_y ) } XFillPolygon(xDisplay, xBoardWindow, highlineGC, arrow, 7, Nonconvex, CoordModeOrigin); + if(appData.monoMode) arrow[7] = arrow[0], XDrawLines(xDisplay, xBoardWindow, darkSquareGC, arrow, 8, CoordModeOrigin); // Polygon( hdc, arrow, 7 ); }