8 # define _(s) gettext (s)
9 # define N_(s) gettext_noop (s)
15 extern GtkWidget *about;
16 extern GtkWidget *GUI_Window;
17 extern GtkWidget *GUI_Aspect;
18 extern GtkWidget *GUI_Menubar;
19 extern GtkWidget *GUI_Timer;
20 extern GtkWidget *GUI_Buttonbar;
21 extern GtkWidget *GUI_Board;
23 extern char *programVersion;
24 extern int errorExitStatus;
25 extern int promotionUp;
30 extern int squareSize,lineGap;
32 extern int LoadGamePopUp P((FILE *f, int gameNumber, char *title));
33 extern int LoadPosition P((FILE *f, int gameNumber, char *title));
34 extern int SaveGame P((FILE *f, int gameNumber, char *title));
35 extern int SavePosition P((FILE *f, int gameNumber, char *title));
38 ExposeProc(object, user_data)
42 /* do resizing to a fixed aspect ratio */
46 int boardWidth,boardHeight,old,new;
48 nw=GTK_WIDGET(object)->allocation.width;
49 nh=GTK_WIDGET(object)->allocation.height;
52 squareSize = nw/(BOARD_WIDTH*1.05+0.05);
56 lineGap = squareSize*0.05;
58 boardWidth = lineGap + BOARD_WIDTH * (squareSize + lineGap);
59 boardHeight = lineGap + BOARD_HEIGHT * (squareSize + lineGap);
61 /* get the height of the menus, etc. and calculate the aspect ratio */
62 gtk_widget_size_request(GTK_WIDGET(GUI_Menubar), &w);
64 gtk_widget_size_request(GTK_WIDGET(GUI_Timer), &w);
66 gtk_widget_size_request(GTK_WIDGET(GUI_Buttonbar), &w);
69 ratio = ((float)totalh+boardHeight)/((float)boardWidth) ;
71 gtk_widget_set_size_request(GTK_WIDGET(GUI_Board),
72 boardWidth,boardHeight);
74 gtk_aspect_frame_set (GTK_ASPECT_FRAME(GUI_Aspect),0,0,ratio,TRUE);
76 /* recreate pieces with new size... TODO: keep svg in memory and just recreate pixmap instead of reloading files */
79 return FALSE; /* return false, so that other expose events are called too */
83 QuitProc (object, user_data)
92 void InfoProc(object, user_data)
97 snprintf(buf, sizeof(buf), "xterm -e info --directory %s --directory . -f %s &",
103 void ManProc(object, user_data)
108 snprintf(buf, sizeof(buf), "xterm -e man xboard &");
113 void HintProc(object, user_data)
121 void BookProc(object, user_data)
129 void AboutProc (object, user_data)
135 const gchar *authors[] = {"Tim Mann <tim@tim-mann.org>",
137 "Evan Welsh <Evan.Welsh@msdw.com>",
138 "Elmar Bartel <bartel@informatik.tu-muenchen.de>",
141 "Hugh Fisher <Hugh.Fisher@cs.anu.edu.au>",
142 "Allessandro Scotti",
143 "H.G. Muller <h.g.muller AT hccnet DOT nl>",
144 "Eric Mullins <emwine AT earthlink DOT net>",
145 "Arun Persaud <arun@nubati.net>"};
147 /* set up about window */
148 about = GTK_WIDGET(gtk_about_dialog_new());
150 /* fill in some information */
153 char *zippy = " (with Zippy code)";
157 sprintf(buf, "%s%s", programVersion, zippy);
159 gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(about),buf);
161 gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(about),
162 "Copyright 1991 Digital Equipment Corporation\n"
163 "Enhancements Copyright 1992-2009 Free Software Foundation\n"
164 "Enhancements Copyright 2005 Alessandro Scotti");
165 gtk_about_dialog_set_website(GTK_ABOUT_DIALOG(about),"http://www.gnu.org/software/xboard/");
166 gtk_about_dialog_set_authors(GTK_ABOUT_DIALOG(about),authors);
167 gtk_about_dialog_set_translator_credits(GTK_ABOUT_DIALOG(about),
168 " A. Alper (turkish)\n"
169 " A. Persaud (german)\n");
171 /* end set up about window */
172 gtk_dialog_run(GTK_DIALOG (about));
173 gtk_widget_destroy(about);
178 void IcsClientProc(object, user_data)
191 LoadNextGameProc(object, user_data)
200 LoadPrevGameProc(object, user_data)
209 ReloadGameProc(object, user_data)
218 LoadNextPositionProc(object, user_data)
227 LoadPrevPositionProc(object, user_data)
236 ReloadPositionProc(object, user_data)
245 LoadPositionProc(object, user_data)
249 if (gameMode == AnalyzeMode || gameMode == AnalyzeFile)
254 FileNamePopUp(_("Load position file name?"), "", LoadPosition, "rb");
259 SaveGameProc(object, user_data)
263 FileNamePopUp(_("Save game file name?"),
264 DefaultFileName(appData.oldSaveStyle ? "game" : "pgn"),
270 SavePositionProc(object, user_data)
274 FileNamePopUp(_("Save position file name?"),
275 DefaultFileName(appData.oldSaveStyle ? "pos" : "fen"),
281 AnalyzeFileProc(object, user_data)
285 if (!first.analysisSupport)
288 snprintf(buf, sizeof(buf), _("%s does not support analysis"), first.tidy);
289 DisplayError(buf, 0);
294 if (!appData.showThinking)
295 ShowThinkingProc(NULL,NULL);
298 FileNamePopUp(_("File to analyze"), "", LoadGamePopUp, "rb");
299 AnalysisPeriodicEvent(1);
306 void MachineWhiteProc(object, user_data)
314 void MachineBlackProc(object, user_data)
322 void TwoMachinesProc(object, user_data)
330 void AcceptProc(object, user_data)
338 void DeclineProc(object, user_data)
346 void RematchProc(object, user_data)
354 void CallFlagProc(object, user_data)
362 void DrawProc(object, user_data)
370 void AbortProc(object, user_data)
378 void AdjournProc(object, user_data)
386 void ResignProc(object, user_data)
394 void StopObservingProc(object, user_data)
398 StopObservingEvent();
402 void StopExaminingProc(object, user_data)
406 StopExaminingEvent();
410 void AdjuWhiteProc(object, user_data)
414 UserAdjudicationEvent(+1);
418 void AdjuBlackProc(object, user_data)
422 UserAdjudicationEvent(-1);
426 void AdjuDrawProc(object, user_data)
430 UserAdjudicationEvent(0);
434 void BackwardProc(object, user_data)
442 void ForwardProc(object, user_data)
450 void ToStartProc(object, user_data)
458 void ToEndProc(object, user_data)
466 void RevertProc(object, user_data)
474 void TruncateGameProc(object, user_data)
482 void MoveNowProc(object, user_data)
490 void RetractMoveProc(object, user_data)
499 void AutocommProc(object, user_data)
503 appData.autoComment = !appData.autoComment;
507 void AutoflagProc(object, user_data)
511 appData.autoCallFlag = !appData.autoCallFlag;
515 void AutoflipProc(object, user_data)
519 appData.autoFlipView = !appData.autoFlipView;
523 void ShowThinkingProc(object, user_data)
527 appData.showThinking = !appData.showThinking;
533 void HideThinkingProc(object, user_data)
537 appData.hideThinkingFromHuman = !appData.hideThinkingFromHuman;
543 void FlipViewProc(object, user_data)
547 flipView = !flipView;
548 DrawPosition(True, NULL);
553 gboolean CloseWindowProc(GtkWidget *button)
555 gtk_widget_destroy(gtk_widget_get_toplevel(button));
560 ResetProc (object, user_data)
565 EngineOutputPopDown();
568 void WhiteClockProc(object, user_data)
572 if (gameMode == EditPosition || gameMode == IcsExamining) {
573 SetWhiteToPlayEvent();
574 } else if (gameMode == IcsPlayingBlack || gameMode == MachinePlaysWhite) {
579 void BlackClockProc(object, user_data)
583 if (gameMode == EditPosition || gameMode == IcsExamining) {
584 SetBlackToPlayEvent();
585 } else if (gameMode == IcsPlayingWhite || gameMode == MachinePlaysBlack) {
591 void ShowCoordsProc(object, user_data)
595 appData.showCoords = !appData.showCoords;
597 DrawPosition(True, NULL);
600 void ErrorPopDownProc(object, user_data)
604 gtk_widget_destroy(GTK_WIDGET(object));
608 void PauseProc(object, user_data)
612 // todo this toggling of the pause button doesn't seem to work?
613 // e.g. select pause from buttonbar doesn't activate menumode.pause
618 void LoadGameProc(object, user_data)
622 FileNamePopUp(_("Load game file name?"),"",LoadGamePopUp,"rb");
631 void EventProc(window, event, data)
636 /* todo do we still need this?
637 if (!XtIsRealized(widget))
641 switch (event->type) {
643 if (event->expose.count > 0) return; /* no clipping is done */
644 DrawPosition(True, NULL);
653 * event handler for parsing user moves
655 void UserMoveProc(window, event, data)
662 static int second = 0;
664 if (errorExitStatus != -1) return;
666 if (event->type == GDK_BUTTON_PRESS) ErrorPopDown();
670 if (event->type == GDK_BUTTON_PRESS)
672 /* todo add promotionshellwidget
673 XtPopdown(promotionShell);
674 XtDestroyWidget(promotionShell); */
685 x = EventToSquare( (int)event->button.x, BOARD_WIDTH );
686 y = EventToSquare( (int)event->button.y, BOARD_HEIGHT );
687 if (!flipView && y >= 0)
689 y = BOARD_HEIGHT - 1 - y;
691 if (flipView && x >= 0)
693 x = BOARD_WIDTH - 1 - x;
698 if (event->type == ButtonPress)
701 if (OKToStartUserMove(x, y))
706 DragPieceBegin(event->button.x, event->button.y);
707 if (appData.highlightDragging)
709 SetHighlights(x, y, -1, -1);
717 if (event->type == GDK_BUTTON_PRESS && gameMode != EditPosition &&
721 /* Check if clicking again on the same color piece */
722 fromP = boards[currentMove][fromY][fromX];
723 toP = boards[currentMove][y][x];
724 if ((WhitePawn <= fromP && fromP <= WhiteKing &&
725 WhitePawn <= toP && toP <= WhiteKing) ||
726 (BlackPawn <= fromP && fromP <= BlackKing &&
727 BlackPawn <= toP && toP <= BlackKing)) {
728 /* Clicked again on same color piece -- changed his mind */
729 second = (x == fromX && y == fromY);
730 if (appData.highlightDragging) {
731 SetHighlights(x, y, -1, -1);
735 if (OKToStartUserMove(x, y)) {
738 DragPieceBegin(event->button.x, event->button.y);
744 if (event->type == GDK_BUTTON_RELEASE && x == fromX && y == fromY)
746 DragPieceEnd(event->button.x, event->button.y);
747 if (appData.animateDragging)
749 /* Undo animation damage if any */
750 DrawPosition(FALSE, NULL);
754 /* Second up/down in same square; just abort move */
759 ClearPremoveHighlights();
763 /* First upclick in same square; start click-click mode */
764 SetHighlights(x, y, -1, -1);
772 saveAnimate = appData.animate;
774 if (event->type == GDK_BUTTON_PRESS)
776 /* Finish clickclick move */
777 if (appData.animate || appData.highlightLastMove)
779 SetHighlights(fromX, fromY, toX, toY);
788 /* Finish drag move */
789 if (appData.highlightLastMove)
791 SetHighlights(fromX, fromY, toX, toY);
797 DragPieceEnd(event->button.x, event->button.y);
798 /* Don't animate move and drag both */
799 appData.animate = FALSE;
802 if (IsPromotion(fromX, fromY, toX, toY))
804 if (appData.alwaysPromoteToQueen)
806 UserMoveEvent(fromX, fromY, toX, toY, 'q');
807 if (!appData.highlightLastMove || gotPremove) ClearHighlights();
808 if (gotPremove) SetPremoveHighlights(fromX, fromY, toX, toY);
813 SetHighlights(fromX, fromY, toX, toY);
819 UserMoveEvent(fromX, fromY, toX, toY, NULLCHAR);
821 if (!appData.highlightLastMove || gotPremove) ClearHighlights();
822 if (gotPremove) SetPremoveHighlights(fromX, fromY, toX, toY);
826 appData.animate = saveAnimate;
827 if (appData.animate || appData.animateDragging) {
828 /* Undo animation damage if needed */
829 DrawPosition(FALSE, NULL);
835 void GetMoveListProc(object, user_data)
839 appData.getMoveList = !appData.getMoveList;
841 if (appData.getMoveList)
846 // gets set automatically? if we set it with set_active we end up in an endless loop switching between 0 and 1
847 // gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (object),(gboolean) appData.getMoveList );