From 8e75200591104332de2a6272fa910f9ab30f3431 Mon Sep 17 00:00:00 2001 From: H.G. Muller Date: Fri, 10 Jun 2011 12:38:08 +0200 Subject: [PATCH] Redo New Shuffle Game dialog with generic popup The buttons are slightly renamed, and in stead of having an 'off' button to clear it, shuffleOpenings now has its own checkbox, which is ticked when a fixed or dynamic random is chosen with the buttons. --- xboard.c | 2 - xoptions.c | 163 ++++++++++++++---------------------------------------------- 2 files changed, 37 insertions(+), 128 deletions(-) diff --git a/xboard.c b/xboard.c index f6eee62..b174c53 100644 --- a/xboard.c +++ b/xboard.c @@ -474,7 +474,6 @@ void LoadOptionsProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)) void SaveOptionsProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void EditBookProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void GameListOptionsPopDown P(()); -void ShufflePopDown P(()); void TimeControlPopDown P(()); void GenericPopDown P(()); void update_ics_width P(()); @@ -1041,7 +1040,6 @@ XtActionsRec boardActions[] = { { "HistoryPopDown", (XtActionProc) HistoryPopDown }, { "EngineOutputPopDown", (XtActionProc) EngineOutputPopDown }, { "EvalGraphPopDown", (XtActionProc) EvalGraphPopDown }, - { "ShufflePopDown", (XtActionProc) ShufflePopDown }, { "TimeControlPopDown", (XtActionProc) TimeControlPopDown }, { "GenericPopDown", (XtActionProc) GenericPopDown }, { "CopyMemoProc", (XtActionProc) CopyMemoProc }, diff --git a/xoptions.c b/xoptions.c index f3e8f67..9612b1f 100644 --- a/xoptions.c +++ b/xoptions.c @@ -104,132 +104,6 @@ void SetFocus(Widget w, XtPointer data, XEvent *event, Boolean *b) previous = w; } -//--------------------------- New Shuffle Game -------------------------------------------- -int shuffleUp; -Widget shuffleShell; - -void ShufflePopDown() -{ - if (!shuffleUp) return; - XtPopdown(shuffleShell); - XtDestroyWidget(shuffleShell); - shuffleUp = False; - ModeHighlight(); -} - -void ShuffleCallback(w, client_data, call_data) - Widget w; - XtPointer client_data, call_data; -{ - String name; - Widget w2; - Arg args[16]; - char buf[MSG_SIZ]; - - XtSetArg(args[0], XtNlabel, &name); - XtGetValues(w, args, 1); - - if (strcmp(name, _("cancel")) == 0) { - ShufflePopDown(); - return; - } - if (strcmp(name, _("off")) == 0) { - ShufflePopDown(); - shuffleOpenings = False; // [HGM] should be moved to New Variant menu, once we have it! - ResetGameEvent(); - return; - } - if (strcmp(name, _("random")) == 0) { - snprintf(buf, MSG_SIZ, "%d", rand()); - XtSetArg(args[0],XtNvalue, buf); // erase bad (non-numeric) value - XtSetValues(XtParent(w), args, 1); - return; - } - if (strcmp(name, _("ok")) == 0) { - int nr; String name; - name = XawDialogGetValueString(w2 = XtParent(w)); - if(sscanf(name ,"%d",&nr) != 1) { - snprintf(buf, MSG_SIZ, "%d", appData.defaultFrcPosition); - XtSetArg(args[0],XtNvalue, buf); // erase bad (non-numeric) value - XtSetValues(w2, args, 1); - return; - } - appData.defaultFrcPosition = nr; - shuffleOpenings = True; - ShufflePopDown(); - ResetGameEvent(); - return; - } -} - -void ShufflePopUp() -{ - Arg args[16]; - Widget popup, layout, dialog, edit; - Window root, child; - int x, y, i; - int win_x, win_y; - unsigned int mask; - char def[MSG_SIZ]; - - i = 0; - XtSetArg(args[i], XtNresizable, True); i++; - XtSetArg(args[i], XtNwidth, DIALOG_SIZE); i++; - shuffleShell = popup = - XtCreatePopupShell(_("New Shuffle Game"), transientShellWidgetClass, - shellWidget, args, i); - - layout = - XtCreateManagedWidget(layoutName, formWidgetClass, popup, - layoutArgs, XtNumber(layoutArgs)); - - snprintf(def, MSG_SIZ, "%d\n", appData.defaultFrcPosition); - i = 0; - XtSetArg(args[i], XtNlabel, _("Start-position number:")); i++; - XtSetArg(args[i], XtNvalue, def); i++; - XtSetArg(args[i], XtNborderWidth, 0); i++; - dialog = XtCreateManagedWidget(_("Shuffle"), dialogWidgetClass, - layout, args, i); - -// XtSetArg(args[0], XtNeditType, XawtextEdit); // [HGM] can't get edit to work decently -// XtSetArg(args[1], XtNuseStringInPlace, False); -// XtSetValues(dialog, args, 2); - - XawDialogAddButton(dialog, _("ok"), ShuffleCallback, (XtPointer) dialog); - XawDialogAddButton(dialog, _("cancel"), ShuffleCallback, (XtPointer) dialog); - XawDialogAddButton(dialog, _("random"), ShuffleCallback, (XtPointer) dialog); - XawDialogAddButton(dialog, _("off"), ShuffleCallback, (XtPointer) dialog); - - XtRealizeWidget(popup); - CatchDeleteWindow(popup, "ShufflePopDown"); - - XQueryPointer(xDisplay, xBoardWindow, &root, &child, - &x, &y, &win_x, &win_y, &mask); - - XtSetArg(args[0], XtNx, x - 10); - XtSetArg(args[1], XtNy, y - 30); - XtSetValues(popup, args, 2); - - XtPopup(popup, XtGrabExclusive); - shuffleUp = True; - - edit = XtNameToWidget(dialog, "*value"); - - XtSetKeyboardFocus(popup, edit); -} - -void ShuffleMenuProc(w, event, prms, nprms) - Widget w; - XEvent *event; - String *prms; - Cardinal *nprms; -{ -// if (gameMode == AnalyzeMode || gameMode == AnalyzeFile) { -// Reset(FALSE, TRUE); -// } - ShufflePopUp(); -} - //--------------------------- Time-Control Menu Popup ---------------------------------- int TimeControlUp; Widget TimeControlShell; @@ -2098,6 +1972,43 @@ void EditBookProc(w, event, prms, nprms) EditBookEvent(); } +void SetRandom P((int n)); + +int ShuffleOK(int n) +{ + ResetGameEvent(); + return 1; +} + +Option shuffleOptions[] = { +{ 0, 0, 50, NULL, (void*) &shuffleOpenings, NULL, NULL, CheckBox, "shuffle" }, +{ 0,-1,1000000000, NULL, (void*) &appData.defaultFrcPosition, "", NULL, Spin, N_("Start-position number:") }, +{ 0, 0, 0, NULL, (void*) &SetRandom, NULL, NULL, Button, "randomize" }, +{ 0, 1, 0, NULL, (void*) &SetRandom, NULL, NULL, Button, "pick fixed" }, +{ 0, 1, 0, NULL, (void*) &ShuffleOK, "", NULL, EndMark , "" } +}; + +void SetRandom(int n) +{ + int r = n==2 ? -1 : rand(); + char buf[MSG_SIZ]; + Arg args[2]; + snprintf(buf, MSG_SIZ, "%d", r); + XtSetArg(args[0],XtNstring, buf); + XtSetValues(shuffleOptions[1].handle, args, 1); + XtSetArg(args[0],XtNstate, True); + XtSetValues(shuffleOptions[0].handle, args, 1); +} + +void ShuffleMenuProc(w, event, prms, nprms) + Widget w; + XEvent *event; + String *prms; + Cardinal *nprms; +{ + GenericPopUp(shuffleOptions, _("New Shuffle Game"), 0); +} + //---------------------------- Chat Windows ---------------------------------------------- void OutputChatMessage(int partner, char *mess) -- 1.7.0.4