X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=callback.c;h=cd831535fdcb208b02fb39d4f822f207bf6842c1;hb=7069f0a55d9aea7c11d798caec1a93bf35d4ad24;hp=0f481f0ab7481acbc70f747883560d81d0a583d1;hpb=715036074c2087caa603bd1aa489fa88c03e7d02;p=xboard.git diff --git a/callback.c b/callback.c index 0f481f0..cd83153 100644 --- a/callback.c +++ b/callback.c @@ -175,6 +175,32 @@ void AboutProc (object, user_data) /* End Help Menu */ +/* Mode Menu */ + +void MachineWhiteProc(object, user_data) + GtkObject *object; + gpointer user_data; +{ + MachineWhiteEvent(); + return; +} + +void MachineBlackProc(object, user_data) + GtkObject *object; + gpointer user_data; +{ + MachineBlackEvent(); + return; +} + +void TwoMachinesProc(object, user_data) + GtkObject *object; + gpointer user_data; +{ + TwoMachinesEvent(); + return; +} + void IcsClientProc(object, user_data) GtkObject *object; gpointer user_data; @@ -183,6 +209,108 @@ void IcsClientProc(object, user_data) return; } +void +AnalyzeFileProc(object, user_data) + GtkObject *object; + gpointer user_data; +{ + if (!first.analysisSupport) + { + char buf[MSG_SIZ]; + snprintf(buf, sizeof(buf), _("%s does not support analysis"), first.tidy); + DisplayError(buf, 0); + return; + }; + Reset(FALSE, TRUE); + + if (!appData.showThinking) + ShowThinkingProc(NULL,NULL); + + AnalyzeFileEvent(); + FileNamePopUp(_("File to analyze"), "", LoadGamePopUp, "rb"); + AnalysisPeriodicEvent(1); + return; +} + +void +AnalyzeModeProc(object, user_data) + GtkObject *object; + gpointer user_data; +{ + char buf[MSG_SIZ]; + + if (!first.analysisSupport) + { + snprintf(buf, sizeof(buf), _("%s does not support analysis"), first.tidy); + DisplayError(buf, 0); + return; + } + /* [DM] icsEngineAnalyze [HGM] This is horrible code; reverse the gameMode and isEngineAnalyze tests! */ + if (appData.icsActive) + { + if (gameMode != IcsObserving) + { + sprintf(buf,_("You are not observing a game")); + DisplayError(buf, 0); + /* secure check */ + if (appData.icsEngineAnalyze) + { + if (appData.debugMode) + fprintf(debugFP, _("Found unexpected active ICS engine analyze \n")); + ExitAnalyzeMode(); + ModeHighlight(); + } + return; + } + /* if enable, use want disable icsEngineAnalyze */ + if (appData.icsEngineAnalyze) + { + ExitAnalyzeMode(); + ModeHighlight(); + return; + } + appData.icsEngineAnalyze = TRUE; + if (appData.debugMode) + fprintf(debugFP, _("ICS engine analyze starting... \n")); + } + if (!appData.showThinking) + ShowThinkingProc(NULL,NULL); + + AnalyzeModeEvent(); + return; +} + +void +EditGameProc(object, user_data) + GtkObject *object; + gpointer user_data; +{ + EditGameEvent(); + return; +} + +void +EditPositionProc(object, user_data) + GtkObject *object; + gpointer user_data; +{ + EditPositionEvent(); + return; +} + +void +TrainingProc(object, user_data) + GtkObject *object; + gpointer user_data; +{ + TrainingEvent(); + return; +} + + + +/* End Mode Menu */ + /* * File menu */ @@ -277,56 +405,9 @@ SavePositionProc(object, user_data) return; } -void -AnalyzeFileProc(object, user_data) - GtkObject *object; - gpointer user_data; -{ - if (!first.analysisSupport) - { - char buf[MSG_SIZ]; - snprintf(buf, sizeof(buf), _("%s does not support analysis"), first.tidy); - DisplayError(buf, 0); - return; - }; - Reset(FALSE, TRUE); - - if (!appData.showThinking) - ShowThinkingProc(NULL,NULL); - - AnalyzeFileEvent(); - FileNamePopUp(_("File to analyze"), "", LoadGamePopUp, "rb"); - AnalysisPeriodicEvent(1); - return; -} - /* End File Menu */ -void MachineWhiteProc(object, user_data) - GtkObject *object; - gpointer user_data; -{ - MachineWhiteEvent(); - return; -} - -void MachineBlackProc(object, user_data) - GtkObject *object; - gpointer user_data; -{ - MachineBlackEvent(); - return; -} - -void TwoMachinesProc(object, user_data) - GtkObject *object; - gpointer user_data; -{ - TwoMachinesEvent(); - return; -} - void AcceptProc(object, user_data) GtkObject *object; gpointer user_data; @@ -717,6 +798,54 @@ PeriodicUpdatesProc(object, user_data) return; } +void +PremoveProc(object, user_data) + GtkObject *object; + gpointer user_data; +{ + appData.premove = !appData.premove; + return; +} + +void +QuietPlayProc(object, user_data) + GtkObject *object; + gpointer user_data; +{ + appData.quietPlay = !appData.quietPlay; + return; +} + + +void +PonderNextMoveProc(object, user_data) + GtkObject *object; + gpointer user_data; +{ + PonderNextMoveEvent(!appData.ponderNextMove); + return; +} + +void +PopupExitMessageProc(object, user_data) + GtkObject *object; + gpointer user_data; +{ + appData.popupExitMessage = !appData.popupExitMessage; + return; +} + +void +PopupMoveErrorsProc(object, user_data) + GtkObject *object; + gpointer user_data; +{ + appData.popupMoveErrors = !appData.popupMoveErrors; + return; +} + + + /* end option menu */ gboolean CloseWindowProc(GtkWidget *button) @@ -826,177 +955,25 @@ void UserMoveProc(window, event, data) GdkEvent *event; gpointer data; { - int x, y; - Boolean saveAnimate; - static int second = 0; - if (errorExitStatus != -1) return; - if (event->type == GDK_BUTTON_PRESS) ErrorPopDown(); - - if (promotionUp) + if (promotionUp) { - if (event->type == GDK_BUTTON_PRESS) + if (event->type == GDK_BUTTON_PRESS) { - /* todo add promotionshellwidget - XtPopdown(promotionShell); - XtDestroyWidget(promotionShell); */ promotionUp = False; ClearHighlights(); fromX = fromY = -1; } - else + else { return; } } - - x = EventToSquare( (int)event->button.x, BOARD_WIDTH ); - y = EventToSquare( (int)event->button.y, BOARD_HEIGHT ); - if (!flipView && y >= 0) - { - y = BOARD_HEIGHT - 1 - y; - } - if (flipView && x >= 0) - { - x = BOARD_WIDTH - 1 - x; - } - - if (fromX == -1) - { - if (event->type == ButtonPress) - { - /* First square */ - if (OKToStartUserMove(x, y)) - { - fromX = x; - fromY = y; - second = 0; - DragPieceBegin(event->button.x, event->button.y); - if (appData.highlightDragging) - { - SetHighlights(x, y, -1, -1); - } - } - } - return; - } - - /* fromX != -1 */ - if (event->type == GDK_BUTTON_PRESS && gameMode != EditPosition && - x >= 0 && y >= 0) { - ChessSquare fromP; - ChessSquare toP; - /* Check if clicking again on the same color piece */ - fromP = boards[currentMove][fromY][fromX]; - toP = boards[currentMove][y][x]; - if ((WhitePawn <= fromP && fromP <= WhiteKing && - WhitePawn <= toP && toP <= WhiteKing) || - (BlackPawn <= fromP && fromP <= BlackKing && - BlackPawn <= toP && toP <= BlackKing)) { - /* Clicked again on same color piece -- changed his mind */ - second = (x == fromX && y == fromY); - if (appData.highlightDragging) { - SetHighlights(x, y, -1, -1); - } else { - ClearHighlights(); - } - if (OKToStartUserMove(x, y)) { - fromX = x; - fromY = y; - DragPieceBegin(event->button.x, event->button.y); - } - return; - } - } - - if (event->type == GDK_BUTTON_RELEASE && x == fromX && y == fromY) - { - DragPieceEnd(event->button.x, event->button.y); - if (appData.animateDragging) - { - /* Undo animation damage if any */ - DrawPosition(FALSE, NULL); - } - if (second) - { - /* Second up/down in same square; just abort move */ - second = 0; - fromX = fromY = -1; - ClearHighlights(); - gotPremove = 0; - ClearPremoveHighlights(); - } - else - { - /* First upclick in same square; start click-click mode */ - SetHighlights(x, y, -1, -1); - } - return; - } - - /* Completed move */ - toX = x; - toY = y; - saveAnimate = appData.animate; - - if (event->type == GDK_BUTTON_PRESS) - { - /* Finish clickclick move */ - if (appData.animate || appData.highlightLastMove) - { - SetHighlights(fromX, fromY, toX, toY); - } - else - { - ClearHighlights(); - } - } - else - { - /* Finish drag move */ - if (appData.highlightLastMove) - { - SetHighlights(fromX, fromY, toX, toY); - } - else - { - ClearHighlights(); - } - DragPieceEnd(event->button.x, event->button.y); - /* Don't animate move and drag both */ - appData.animate = FALSE; - } - - if (IsPromotion(fromX, fromY, toX, toY)) - { - if (appData.alwaysPromoteToQueen) - { - UserMoveEvent(fromX, fromY, toX, toY, 'q'); - if (!appData.highlightLastMove || gotPremove) ClearHighlights(); - if (gotPremove) SetPremoveHighlights(fromX, fromY, toX, toY); - fromX = fromY = -1; - } - else - { - SetHighlights(fromX, fromY, toX, toY); - PromotionPopUp(); - } - } - else - { - UserMoveEvent(fromX, fromY, toX, toY, NULLCHAR); - - if (!appData.highlightLastMove || gotPremove) ClearHighlights(); - if (gotPremove) SetPremoveHighlights(fromX, fromY, toX, toY); - fromX = fromY = -1; - } - - appData.animate = saveAnimate; - if (appData.animate || appData.animateDragging) { - /* Undo animation damage if needed */ - DrawPosition(FALSE, NULL); - } + + // [HGM] mouse: the rest of the mouse handler is moved to the backend, and called here + if(event->type == GDK_BUTTON_PRESS) LeftClick(Press, (int)event->button.x, (int)event->button.y); + if(event->type == GDK_BUTTON_RELEASE) LeftClick(Release, (int)event->button.x, (int)event->button.y); return; }