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)
500 AutocommProc(object, user_data)
504 appData.autoComment = !appData.autoComment;
509 AutoflagProc(object, user_data)
513 appData.autoCallFlag = !appData.autoCallFlag;
518 AutoflipProc(object, user_data)
522 appData.autoFlipView = !appData.autoFlipView;
527 ShowThinkingProc(object, user_data)
531 appData.showThinking = !appData.showThinking;
538 HideThinkingProc(object, user_data)
542 appData.hideThinkingFromHuman = !appData.hideThinkingFromHuman;
549 FlipViewProc(object, user_data)
553 flipView = !flipView;
554 DrawPosition(True, NULL);
559 AlwaysQueenProc(object, user_data)
563 appData.alwaysPromoteToQueen = !appData.alwaysPromoteToQueen;
568 AnimateDraggingProc(object, user_data)
572 appData.animateDragging = !appData.animateDragging;
574 if (appData.animateDragging)
576 // TODO convert to gtk
584 AnimateMovingProc(object, user_data)
588 appData.animate = !appData.animate;
592 // TODO convert to gtk
600 AutobsProc(object, user_data)
604 appData.autoObserve = !appData.autoObserve;
609 AutoraiseProc(object, user_data)
613 appData.autoRaiseBoard = !appData.autoRaiseBoard;
618 AutosaveProc(object, user_data)
622 appData.autoSaveGames = !appData.autoSaveGames;
627 BlindfoldProc(object, user_data)
631 appData.blindfold = !appData.blindfold;
632 DrawPosition(True, NULL);
637 TestLegalityProc(object, user_data)
641 appData.testLegality = !appData.testLegality;
646 FlashMovesProc(object, user_data)
650 if (appData.flashCount == 0)
652 appData.flashCount = 3;
656 appData.flashCount = -appData.flashCount;
659 // TODO: check if this is working correct*/
665 HighlightDraggingProc(object, user_data)
669 /* TODO: connect to option menu */
670 appData.highlightDragging = !appData.highlightDragging;
676 HighlightLastMoveProc(object, user_data)
680 appData.highlightLastMove = !appData.highlightLastMove;
685 IcsAlarmProc(object, user_data)
689 appData.icsAlarm = !appData.icsAlarm;
694 MoveSoundProc(object, user_data)
698 appData.ringBellAfterMoves = !appData.ringBellAfterMoves;
703 OldSaveStyleProc(object, user_data)
707 appData.oldSaveStyle = !appData.oldSaveStyle;
712 PeriodicUpdatesProc(object, user_data)
716 PeriodicUpdatesEvent(!appData.periodicUpdates);
720 /* end option menu */
722 gboolean CloseWindowProc(GtkWidget *button)
724 gtk_widget_destroy(gtk_widget_get_toplevel(button));
729 ResetProc (object, user_data)
734 EngineOutputPopDown();
737 void WhiteClockProc(object, user_data)
741 if (gameMode == EditPosition || gameMode == IcsExamining) {
742 SetWhiteToPlayEvent();
743 } else if (gameMode == IcsPlayingBlack || gameMode == MachinePlaysWhite) {
748 void BlackClockProc(object, user_data)
752 if (gameMode == EditPosition || gameMode == IcsExamining) {
753 SetBlackToPlayEvent();
754 } else if (gameMode == IcsPlayingWhite || gameMode == MachinePlaysBlack) {
760 void ShowCoordsProc(object, user_data)
764 appData.showCoords = !appData.showCoords;
766 DrawPosition(True, NULL);
769 void ErrorPopDownProc(object, user_data)
773 gtk_widget_destroy(GTK_WIDGET(object));
777 void PauseProc(object, user_data)
781 // todo this toggling of the pause button doesn't seem to work?
782 // e.g. select pause from buttonbar doesn't activate menumode.pause
787 void LoadGameProc(object, user_data)
791 FileNamePopUp(_("Load game file name?"),"",LoadGamePopUp,"rb");
800 void EventProc(window, event, data)
805 /* todo do we still need this?
806 if (!XtIsRealized(widget))
810 switch (event->type) {
812 if (event->expose.count > 0) return; /* no clipping is done */
813 DrawPosition(True, NULL);
822 * event handler for parsing user moves
824 void UserMoveProc(window, event, data)
831 static int second = 0;
833 if (errorExitStatus != -1) return;
835 if (event->type == GDK_BUTTON_PRESS) ErrorPopDown();
839 if (event->type == GDK_BUTTON_PRESS)
841 /* todo add promotionshellwidget
842 XtPopdown(promotionShell);
843 XtDestroyWidget(promotionShell); */
854 x = EventToSquare( (int)event->button.x, BOARD_WIDTH );
855 y = EventToSquare( (int)event->button.y, BOARD_HEIGHT );
856 if (!flipView && y >= 0)
858 y = BOARD_HEIGHT - 1 - y;
860 if (flipView && x >= 0)
862 x = BOARD_WIDTH - 1 - x;
867 if (event->type == ButtonPress)
870 if (OKToStartUserMove(x, y))
875 DragPieceBegin(event->button.x, event->button.y);
876 if (appData.highlightDragging)
878 SetHighlights(x, y, -1, -1);
886 if (event->type == GDK_BUTTON_PRESS && gameMode != EditPosition &&
890 /* Check if clicking again on the same color piece */
891 fromP = boards[currentMove][fromY][fromX];
892 toP = boards[currentMove][y][x];
893 if ((WhitePawn <= fromP && fromP <= WhiteKing &&
894 WhitePawn <= toP && toP <= WhiteKing) ||
895 (BlackPawn <= fromP && fromP <= BlackKing &&
896 BlackPawn <= toP && toP <= BlackKing)) {
897 /* Clicked again on same color piece -- changed his mind */
898 second = (x == fromX && y == fromY);
899 if (appData.highlightDragging) {
900 SetHighlights(x, y, -1, -1);
904 if (OKToStartUserMove(x, y)) {
907 DragPieceBegin(event->button.x, event->button.y);
913 if (event->type == GDK_BUTTON_RELEASE && x == fromX && y == fromY)
915 DragPieceEnd(event->button.x, event->button.y);
916 if (appData.animateDragging)
918 /* Undo animation damage if any */
919 DrawPosition(FALSE, NULL);
923 /* Second up/down in same square; just abort move */
928 ClearPremoveHighlights();
932 /* First upclick in same square; start click-click mode */
933 SetHighlights(x, y, -1, -1);
941 saveAnimate = appData.animate;
943 if (event->type == GDK_BUTTON_PRESS)
945 /* Finish clickclick move */
946 if (appData.animate || appData.highlightLastMove)
948 SetHighlights(fromX, fromY, toX, toY);
957 /* Finish drag move */
958 if (appData.highlightLastMove)
960 SetHighlights(fromX, fromY, toX, toY);
966 DragPieceEnd(event->button.x, event->button.y);
967 /* Don't animate move and drag both */
968 appData.animate = FALSE;
971 if (IsPromotion(fromX, fromY, toX, toY))
973 if (appData.alwaysPromoteToQueen)
975 UserMoveEvent(fromX, fromY, toX, toY, 'q');
976 if (!appData.highlightLastMove || gotPremove) ClearHighlights();
977 if (gotPremove) SetPremoveHighlights(fromX, fromY, toX, toY);
982 SetHighlights(fromX, fromY, toX, toY);
988 UserMoveEvent(fromX, fromY, toX, toY, NULLCHAR);
990 if (!appData.highlightLastMove || gotPremove) ClearHighlights();
991 if (gotPremove) SetPremoveHighlights(fromX, fromY, toX, toY);
995 appData.animate = saveAnimate;
996 if (appData.animate || appData.animateDragging) {
997 /* Undo animation damage if needed */
998 DrawPosition(FALSE, NULL);
1004 void GetMoveListProc(object, user_data)
1008 appData.getMoveList = !appData.getMoveList;
1010 if (appData.getMoveList)
1015 // gets set automatically? if we set it with set_active we end up in an endless loop switching between 0 and 1
1016 // gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (object),(gboolean) appData.getMoveList );