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;
33 ExposeProc(object, user_data)
37 /* do resizing to a fixed aspect ratio */
41 int boardWidth,boardHeight,old,new;
43 nw=GTK_WIDGET(object)->allocation.width;
44 nh=GTK_WIDGET(object)->allocation.height;
47 squareSize = nw/(BOARD_WIDTH*1.05+0.05);
51 lineGap = squareSize*0.05;
53 boardWidth = lineGap + BOARD_WIDTH * (squareSize + lineGap);
54 boardHeight = lineGap + BOARD_HEIGHT * (squareSize + lineGap);
56 /* get the height of the menus, etc. and calculate the aspect ratio */
57 gtk_widget_size_request(GTK_WIDGET(GUI_Menubar), &w);
59 gtk_widget_size_request(GTK_WIDGET(GUI_Timer), &w);
61 gtk_widget_size_request(GTK_WIDGET(GUI_Buttonbar), &w);
64 ratio = ((float)totalh+boardHeight)/((float)boardWidth) ;
66 gtk_widget_set_size_request(GTK_WIDGET(GUI_Board),
67 boardWidth,boardHeight);
69 gtk_aspect_frame_set (GTK_ASPECT_FRAME(GUI_Aspect),0,0,ratio,TRUE);
71 /* recreate pieces with new size... TODO: keep svg in memory and just recreate pixmap instead of reloading files */
74 return FALSE; /* return false, so that other expose events are called too */
78 QuitProc (object, user_data)
87 void InfoProc(object, user_data)
92 snprintf(buf, sizeof(buf), "xterm -e info --directory %s --directory . -f %s &",
98 void ManProc(object, user_data)
103 snprintf(buf, sizeof(buf), "xterm -e man xboard &");
108 void HintProc(object, user_data)
116 void BookProc(object, user_data)
124 void AboutProc (object, user_data)
130 const gchar *authors[] = {"Tim Mann <tim@tim-mann.org>",
132 "Evan Welsh <Evan.Welsh@msdw.com>",
133 "Elmar Bartel <bartel@informatik.tu-muenchen.de>",
136 "Hugh Fisher <Hugh.Fisher@cs.anu.edu.au>",
137 "Allessandro Scotti",
138 "H.G. Muller <h.g.muller AT hccnet DOT nl>",
139 "Eric Mullins <emwine AT earthlink DOT net>",
140 "Arun Persaud <arun@nubati.net>"};
142 /* set up about window */
143 about = GTK_WIDGET(gtk_about_dialog_new());
145 /* fill in some information */
148 char *zippy = " (with Zippy code)";
152 sprintf(buf, "%s%s", programVersion, zippy);
154 gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(about),buf);
156 gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(about),
157 "Copyright 1991 Digital Equipment Corporation\n"
158 "Enhancements Copyright 1992-2009 Free Software Foundation\n"
159 "Enhancements Copyright 2005 Alessandro Scotti");
160 gtk_about_dialog_set_website(GTK_ABOUT_DIALOG(about),"http://www.gnu.org/software/xboard/");
161 gtk_about_dialog_set_authors(GTK_ABOUT_DIALOG(about),authors);
162 gtk_about_dialog_set_translator_credits(GTK_ABOUT_DIALOG(about),
163 " A. Alper (turkish)\n"
164 " A. Persaud (german)\n");
166 /* end set up about window */
167 gtk_dialog_run(GTK_DIALOG (about));
168 gtk_widget_destroy(about);
173 void IcsClientProc(object, user_data)
185 void LoadNextGameProc(object, user_data)
193 void LoadPrevGameProc(object, user_data)
201 void ReloadGameProc(object, user_data)
210 void LoadNextPositionProc(object, user_data)
218 void LoadPrevPositionProc(object, user_data)
226 void ReloadPositionProc(object, user_data)
237 void MachineWhiteProc(object, user_data)
245 void MachineBlackProc(object, user_data)
253 void TwoMachinesProc(object, user_data)
261 void AcceptProc(object, user_data)
269 void DeclineProc(object, user_data)
277 void RematchProc(object, user_data)
285 void CallFlagProc(object, user_data)
293 void DrawProc(object, user_data)
301 void AbortProc(object, user_data)
309 void AdjournProc(object, user_data)
317 void ResignProc(object, user_data)
325 void StopObservingProc(object, user_data)
329 StopObservingEvent();
333 void StopExaminingProc(object, user_data)
337 StopExaminingEvent();
341 void AdjuWhiteProc(object, user_data)
345 UserAdjudicationEvent(+1);
349 void AdjuBlackProc(object, user_data)
353 UserAdjudicationEvent(-1);
357 void AdjuDrawProc(object, user_data)
361 UserAdjudicationEvent(0);
365 void BackwardProc(object, user_data)
373 void ForwardProc(object, user_data)
381 void ToStartProc(object, user_data)
389 void ToEndProc(object, user_data)
397 void RevertProc(object, user_data)
405 void TruncateGameProc(object, user_data)
413 void MoveNowProc(object, user_data)
421 void RetractMoveProc(object, user_data)
430 void AutocommProc(object, user_data)
434 appData.autoComment = !appData.autoComment;
438 void AutoflagProc(object, user_data)
442 appData.autoCallFlag = !appData.autoCallFlag;
446 void AutoflipProc(object, user_data)
450 appData.autoFlipView = !appData.autoFlipView;
454 void ShowThinkingProc(object, user_data)
458 appData.showThinking = !appData.showThinking;
464 void HideThinkingProc(object, user_data)
468 appData.hideThinkingFromHuman = !appData.hideThinkingFromHuman;
474 void FlipViewProc(object, user_data)
478 flipView = !flipView;
479 DrawPosition(True, NULL);
484 gboolean CloseWindowProc(GtkWidget *button)
486 gtk_widget_destroy(gtk_widget_get_toplevel(button));
491 ResetProc (object, user_data)
496 EngineOutputPopDown();
499 void WhiteClockProc(object, user_data)
503 if (gameMode == EditPosition || gameMode == IcsExamining) {
504 SetWhiteToPlayEvent();
505 } else if (gameMode == IcsPlayingBlack || gameMode == MachinePlaysWhite) {
510 void BlackClockProc(object, user_data)
514 if (gameMode == EditPosition || gameMode == IcsExamining) {
515 SetBlackToPlayEvent();
516 } else if (gameMode == IcsPlayingWhite || gameMode == MachinePlaysBlack) {
522 void ShowCoordsProc(object, user_data)
526 appData.showCoords = !appData.showCoords;
528 DrawPosition(True, NULL);
531 void ErrorPopDownProc(object, user_data)
535 gtk_widget_destroy(GTK_WIDGET(object));
539 void PauseProc(object, user_data)
543 // todo this toggling of the pause button doesn't seem to work?
544 // e.g. select pause from buttonbar doesn't activate menumode.pause
549 void LoadGameProc(object, user_data)
554 dialog = gtk_file_chooser_dialog_new (_("Load game file name?"),
555 GTK_WINDOW(GUI_Window),
556 GTK_FILE_CHOOSER_ACTION_OPEN,
557 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
558 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
560 if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
565 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
568 f = fopen(filename, "rb");
571 DisplayError(_("Failed to open file"), errno);
576 (void) LoadGamePopUp(f, 0, filename);
581 gtk_widget_destroy (dialog);
592 void EventProc(window, event, data)
597 /* todo do we still need this?
598 if (!XtIsRealized(widget))
602 switch (event->type) {
604 if (event->expose.count > 0) return; /* no clipping is done */
605 DrawPosition(True, NULL);
614 * event handler for parsing user moves
616 void UserMoveProc(window, event, data)
623 static int second = 0;
625 if (errorExitStatus != -1) return;
627 if (event->type == GDK_BUTTON_PRESS) ErrorPopDown();
631 if (event->type == GDK_BUTTON_PRESS)
633 /* todo add promotionshellwidget
634 XtPopdown(promotionShell);
635 XtDestroyWidget(promotionShell); */
646 x = EventToSquare( (int)event->button.x, BOARD_WIDTH );
647 y = EventToSquare( (int)event->button.y, BOARD_HEIGHT );
648 if (!flipView && y >= 0)
650 y = BOARD_HEIGHT - 1 - y;
652 if (flipView && x >= 0)
654 x = BOARD_WIDTH - 1 - x;
659 if (event->type == ButtonPress)
662 if (OKToStartUserMove(x, y))
667 DragPieceBegin(event->button.x, event->button.y);
668 if (appData.highlightDragging)
670 SetHighlights(x, y, -1, -1);
678 if (event->type == GDK_BUTTON_PRESS && gameMode != EditPosition &&
682 /* Check if clicking again on the same color piece */
683 fromP = boards[currentMove][fromY][fromX];
684 toP = boards[currentMove][y][x];
685 if ((WhitePawn <= fromP && fromP <= WhiteKing &&
686 WhitePawn <= toP && toP <= WhiteKing) ||
687 (BlackPawn <= fromP && fromP <= BlackKing &&
688 BlackPawn <= toP && toP <= BlackKing)) {
689 /* Clicked again on same color piece -- changed his mind */
690 second = (x == fromX && y == fromY);
691 if (appData.highlightDragging) {
692 SetHighlights(x, y, -1, -1);
696 if (OKToStartUserMove(x, y)) {
699 DragPieceBegin(event->button.x, event->button.y);
705 if (event->type == GDK_BUTTON_RELEASE && x == fromX && y == fromY)
707 DragPieceEnd(event->button.x, event->button.y);
708 if (appData.animateDragging)
710 /* Undo animation damage if any */
711 DrawPosition(FALSE, NULL);
715 /* Second up/down in same square; just abort move */
720 ClearPremoveHighlights();
724 /* First upclick in same square; start click-click mode */
725 SetHighlights(x, y, -1, -1);
733 saveAnimate = appData.animate;
735 if (event->type == GDK_BUTTON_PRESS)
737 /* Finish clickclick move */
738 if (appData.animate || appData.highlightLastMove)
740 SetHighlights(fromX, fromY, toX, toY);
749 /* Finish drag move */
750 if (appData.highlightLastMove)
752 SetHighlights(fromX, fromY, toX, toY);
758 DragPieceEnd(event->button.x, event->button.y);
759 /* Don't animate move and drag both */
760 appData.animate = FALSE;
763 if (IsPromotion(fromX, fromY, toX, toY))
765 if (appData.alwaysPromoteToQueen)
767 UserMoveEvent(fromX, fromY, toX, toY, 'q');
768 if (!appData.highlightLastMove || gotPremove) ClearHighlights();
769 if (gotPremove) SetPremoveHighlights(fromX, fromY, toX, toY);
774 SetHighlights(fromX, fromY, toX, toY);
780 UserMoveEvent(fromX, fromY, toX, toY, NULLCHAR);
782 if (!appData.highlightLastMove || gotPremove) ClearHighlights();
783 if (gotPremove) SetPremoveHighlights(fromX, fromY, toX, toY);
787 appData.animate = saveAnimate;
788 if (appData.animate || appData.animateDragging) {
789 /* Undo animation damage if needed */
790 DrawPosition(FALSE, NULL);
796 void GetMoveListProc(object, user_data)
800 appData.getMoveList = !appData.getMoveList;
802 if (appData.getMoveList)
807 // gets set automatically? if we set it with set_active we end up in an endless loop switching between 0 and 1
808 // gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (object),(gboolean) appData.getMoveList );