From 0acc60a8a75b095c69fbf9b8df8db37a4d522a6e Mon Sep 17 00:00:00 2001 From: Arun Persaud Date: Sun, 26 Jul 2009 13:56:08 -0700 Subject: [PATCH] First step for a GTK version this version doesn't do much, apart from an "quit" button that seems to work. Lots of things need to be still changed: * there is still a lot of calls to X... function in the code * lots of printf("Debug...") (used those instead of a debugger) * some X-code has just been commented out, but has not been replaced with the GTK code ... guess the list is long at the moment ;) --- Makefile.am | 7 +- backend.c | 60 ++- callback.c | 377 +++++++++++++ callback.h | 14 + gtk-interface.xml | 618 +++++++++++++++++++++ interface.c | 77 +++ interface.h | 23 + xboard.c | 1580 ++++++++++++++++++----------------------------------- 8 files changed, 1688 insertions(+), 1068 deletions(-) create mode 100644 callback.c create mode 100644 callback.h create mode 100644 gtk-interface.xml create mode 100644 interface.c create mode 100644 interface.h diff --git a/Makefile.am b/Makefile.am index b72e3e5..d9a98ef 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,8 +1,9 @@ bin_PROGRAMS = xboard -xboard_SOURCES = backend.c lists.c pgntags.c xedittags.c xhistory.c zippy.c childio.c moves.c uci.c xengineoutput.c xoptions.c gamelist.c parser.l xboard.c xgamelist.c book.c +xboard_SOURCES = backend.c lists.c pgntags.c xedittags.c xhistory.c zippy.c childio.c moves.c uci.c xengineoutput.c xoptions.c gamelist.c parser.l xboard.c xgamelist.c book.c callback.c interface.c + +AM_CPPFLAGS=-DINFODIR='"$(infodir)"' @GTK_CFLAGS@ +AM_LDFLAGS= -lm @XAW_LIBS@ @GTK_LIBS@ -AM_CPPFLAGS=-DINFODIR='"$(infodir)"' -AM_LDFLAGS= -lm @XAW_LIBS@ info_TEXINFOS = copyright.texi xboard.texi man6_MANS = xboard.man diff --git a/backend.c b/backend.c index ff989cd..5df4fc6 100644 --- a/backend.c +++ b/backend.c @@ -1076,6 +1076,8 @@ ParseTimeControl(tc, ti, mps) void InitBackEnd2() { + printf ("DEBUG: in init backend 2\n"); + if (appData.debugMode) { fprintf(debugFP, "%s\n", programVersion); } @@ -1091,15 +1093,22 @@ InitBackEnd2() if(appData.loadPositionIndex >= 0) appData.loadPositionIndex = -1; if(appData.loadGameIndex >= 0) appData.loadGameIndex = -1; } + printf ("DEBUG: before reset\n"); Reset(TRUE, FALSE); + printf ("DEBUG: after reset\n"); if (appData.noChessProgram || first.protocolVersion == 1) { + printf ("DEBUG: first if\n"); InitBackEnd3(); } else { + printf ("DEBUG: second if 0\n"); /* kludge: allow timeout for initial "feature" commands */ FreezeUI(); + printf ("DEBUG: second if 1\n"); DisplayMessage("", _("Starting chess program")); + printf ("DEBUG: second if 2\n"); ScheduleDelayedEvent(InitBackEnd3, FEATURE_TIMEOUT); - } + printf ("DEBUG: second if 3\n"); } + printf ("DEBUG: end of init2\n"); } void @@ -4494,6 +4503,8 @@ InitPosition(redraw) oldh = gameInfo.holdingsWidth, oldv = gameInfo.variant; + printf ("DEBUG: in init position\n"); + currentMove = forwardMostMove = backwardMostMove = 0; if(appData.icsActive) shuffleOpenings = FALSE; // [HGM] shuffle: in ICS mode, only shuffle on ICS request @@ -4631,6 +4642,7 @@ InitPosition(redraw) shuffleOpenings = 1; break; } + printf ("DEBUG: in init position 1\n"); overrule = 0; if(appData.NrFiles >= 0) { @@ -4689,6 +4701,9 @@ InitPosition(redraw) initialPosition[BOARD_HEIGHT-2][j] = BlackBishop; } + printf ("DEBUG: in init position 2\n"); + + if( nrCastlingRights == -1) { /* [HGM] Build normal castling rights (must be done after board sizing!) */ /* This sets default castling rights from none to normal corners */ @@ -4737,8 +4752,11 @@ InitPosition(redraw) startedFromSetupPosition = TRUE; } - CopyBoard(boards[0], initialPosition); + printf ("DEBUG: in init position 3\n"); + + CopyBoard(boards[0], initialPosition); + printf ("DEBUG: in init position 3.1\n"); if(oldx != gameInfo.boardWidth || oldy != gameInfo.boardHeight || oldh != gameInfo.holdingsWidth @@ -4751,10 +4769,16 @@ InitPosition(redraw) gameInfo.variant == VariantFalcon #endif ) + { + printf ("DEBUG: in init position 3.2\n"); InitDrawingSizes(-2 ,0); + } + printf ("DEBUG: init position 99\n"); if (redraw) DrawPosition(TRUE, boards[currentMove]); + + printf ("DEBUG: end init position\n"); } void @@ -7770,7 +7794,7 @@ GameEnds(result, resultDetails, whosays) StopClocks(); if (!isIcsGame && !appData.noChessProgram) SetUserThinkingEnables(); - + /* [HGM] if a machine claims the game end we verify this claim */ if(gameMode == TwoMachinesPlay && appData.testClaims) { if(appData.testLegality && whosays >= GE_ENGINE1 ) { @@ -7821,6 +7845,7 @@ GameEnds(result, resultDetails, whosays) } /* (Claiming a loss is accepted no questions asked!) */ } + /* [HGM] bare: don't allow bare King to win */ if((gameInfo.holdingsWidth == 0 || gameInfo.variant == VariantSuper || gameInfo.variant == VariantGreat) && gameInfo.variant != VariantLosers && gameInfo.variant != VariantGiveaway @@ -7843,7 +7868,6 @@ GameEnds(result, resultDetails, whosays) } } - if(serverMoves != NULL && !loadFlag) { char c = '='; if(result==WhiteWins) c = '+'; if(result==BlackWins) c = '-'; @@ -8133,6 +8157,7 @@ Reset(redraw, init) int redraw, init; { int i; + printf ("DEBUG: in reset\n"); if (appData.debugMode) { fprintf(debugFP, "Reset(%d, %d) from gameMode %d\n", @@ -8158,6 +8183,9 @@ Reset(redraw, init) white_holding[0] = black_holding[0] = NULLCHAR; ClearProgramStats(); opponentKibitzes = FALSE; // [HGM] kibitz: do not reserve space in engine-output window in zippy mode + + printf ("DEBUG: in reset 1\n"); + ResetFrontEnd(); ClearHighlights(); @@ -8166,7 +8194,11 @@ Reset(redraw, init) gotPremove = FALSE; alarmSounded = FALSE; + printf ("DEBUG: in reset 2\n"); + + GameEnds((ChessMove) 0, NULL, GE_PLAYER); + printf ("DEBUG: in reset2.1\n"); if(appData.serverMovesName != NULL) { /* [HGM] prepare to make moves file for broadcasting */ clock_t t = clock(); @@ -8180,17 +8212,24 @@ Reset(redraw, init) serverMoves = fopen(appData.serverMovesName, "w"); } + printf ("DEBUG: in reset 3\n"); + ExitAnalyzeMode(); gameMode = BeginningOfGame; ModeHighlight(); + printf ("DEBUG: in reset 3.0.1\n"); + if(appData.icsActive) gameInfo.variant = VariantNormal; InitPosition(redraw); + printf ("DEBUG: in reset 3.0.1.1\n"); for (i = 0; i < MAX_MOVES; i++) { if (commentList[i] != NULL) { free(commentList[i]); commentList[i] = NULL; } } + printf ("DEBUG: in reset 3.1\n"); + ResetClocks(); timeRemaining[0][0] = whiteTimeRemaining; timeRemaining[1][0] = blackTimeRemaining; @@ -8200,9 +8239,17 @@ Reset(redraw, init) if (init) { InitChessProgram(&first, startedFromSetupPosition); } - DisplayTitle(""); + + printf ("DEBUG: in reset 4\n"); + + + GUI_DisplayTitle(""); + printf ("DEBUG: in reset 5\n"); DisplayMessage("", ""); + printf ("DEBUG: in reset 6\n"); HistorySet(parseList, backwardMostMove, forwardMostMove, currentMove-1); + + printf ("DEBUG: end reset \n"); } void @@ -13147,6 +13194,8 @@ StopClocks() if (!StopClockTimer()) return; if (!appData.clockMode) return; + printf("Debug: in stop clocks\n"); + GetTimeMark(&now); lastTickLength = SubtractTimeMarks(&now, &tickStartTM); @@ -13160,6 +13209,7 @@ StopClocks() DisplayBlackClock(blackTimeRemaining, !WhiteOnMove(currentMove)); } CheckFlags(); + printf("Debug: end stop clocks\n"); } /* Start clock of player on move. Time may have been reset, so diff --git a/callback.c b/callback.c new file mode 100644 index 0000000..c9aa4f0 --- /dev/null +++ b/callback.c @@ -0,0 +1,377 @@ +#include +#include "common.h" +#include +#include "backend.h" + +#ifdef ENABLE_NLS +# define _(s) gettext (s) +# define N_(s) gettext_noop (s) +#else +# define _(s) (s) +# define N_(s) s +#endif + + +extern GtkWidget *about; +extern GtkWidget *GUI_Window; + +extern char *programVersion; +extern int errorExitStatus; +extern int promotionUp; +extern int fromX; +extern int fromY; +extern int toX; +extern int toY; + +void +QuitProc (object, user_data) + GtkObject *object; + gpointer user_data; +{ + gtk_main_quit(); + ExitEvent(0); +} + +void AboutProc (object, user_data) + GtkObject *object; + gpointer user_data; +{ + GtkWidget *about; + + const gchar *authors[] = {"Tim Mann ", + "John Chanak", + "Evan Welsh ", + "Elmar Bartel ", + "Jochen Wiedmann", + "Frank McIngvale", + "Hugh Fisher ", + "Allessandro Scotti", + "H.G. Muller ", + "Eric Mullins ", + "Arun Persaud "}; + + /* set up about window */ + about = GTK_WIDGET(gtk_about_dialog_new()); + + /* fill in some information */ + char buf[MSG_SIZ]; +#if ZIPPY + char *zippy = " (with Zippy code)"; +#else + char *zippy = ""; +#endif + sprintf(buf, "%s%s", programVersion, zippy); + + gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(about),buf); + + gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(about), + "Copyright 1991 Digital Equipment Corporation\n" + "Enhancements Copyright 1992-2009 Free Software Foundation\n" + "Enhancements Copyright 2005 Alessandro Scotti"); + gtk_about_dialog_set_website(GTK_ABOUT_DIALOG(about),"http://www.gnu.org/software/xboard/"); + gtk_about_dialog_set_authors(GTK_ABOUT_DIALOG(about),authors); + gtk_about_dialog_set_translator_credits(GTK_ABOUT_DIALOG(about), + " A. Alper (turkish)\n" + " A. Persaud (german)\n"); + + /* end set up about window */ + gtk_dialog_run(GTK_DIALOG (about)); + gtk_widget_destroy(about); +} + +void LoadNextGameProc(object, user_data) + GtkObject *object; + gpointer user_data; +{ + ReloadGame(1); + return; +} + +void LoadPrevGameProc(object, user_data) + GtkObject *object; + gpointer user_data; +{ + ReloadGame(-1); + return; +} + +void ReloadGameProc(object, user_data) + GtkObject *object; + gpointer user_data; +{ + ReloadGame(0); + return; +} + + +gboolean CloseWindowProc(GtkWidget *button) +{ + gtk_widget_destroy(gtk_widget_get_toplevel(button)); + return TRUE; +} + +void +ResetProc (object, user_data) + GtkObject *object; + gpointer user_data; +{ + ResetGameEvent(); + AnalysisPopDown(); +} + +void WhiteClockProc(object, user_data) + GtkObject *object; + gpointer user_data; +{ + if (gameMode == EditPosition || gameMode == IcsExamining) { + SetWhiteToPlayEvent(); + } else if (gameMode == IcsPlayingBlack || gameMode == MachinePlaysWhite) { + CallFlagEvent(); + } +} + +void BlackClockProc(object, user_data) + GtkObject *object; + gpointer user_data; +{ + if (gameMode == EditPosition || gameMode == IcsExamining) { + SetBlackToPlayEvent(); + } else if (gameMode == IcsPlayingWhite || gameMode == MachinePlaysBlack) { + CallFlagEvent(); + } +} + + +void ShowCoordsProc(object, user_data) + GtkObject *object; + gpointer user_data; +{ + appData.showCoords = !appData.showCoords; + + DrawPosition(True, NULL); +} + +void ErrorPopDownProc(object, user_data) + GtkObject *object; + gpointer user_data; +{ + gtk_widget_destroy(GTK_WIDGET(object)); + ErrorPopDown(); +} + +void PauseProc(object, user_data) + GtkObject *object; + gpointer user_data; +{ + // todo this toggling of the pause button doesn't seem to work? + // e.g. select pause from buttonbar doesn't activate menumode.pause + // fprintf(stderr,"DEBUG: in pause\n"); + // fflush(stderr); + PauseEvent(); +} + + +void LoadGameProc(object, user_data) + GtkObject *object; + gpointer user_data; +{ + GtkWidget *dialog; + dialog = gtk_file_chooser_dialog_new (_("Load game file name?"), + GTK_WINDOW(GUI_Window), + GTK_FILE_CHOOSER_ACTION_OPEN, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, + NULL); + if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) + { + char *filename; + FILE *f; + + filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); + + //see loadgamepopup + f = fopen(filename, "rb"); + if (f == NULL) { + DisplayError(_("Failed to open file"), errno); + } else { + /* TODO add indec */ + (void) LoadGamePopUp(f, 0, filename); + } + g_free (filename); + } + gtk_widget_destroy (dialog); + ModeHighlight(); +} + + +/************* + * EVENTS + *************/ + +void EventProc(window, event, data) + GtkWindow *window; + GdkEvent *event; + gpointer data; +{ + /* todo do we still need this? + if (!XtIsRealized(widget)) + return; + */ + + switch (event->type) { + case GDK_EXPOSE: + if (event->expose.count > 0) return; /* no clipping is done */ + DrawPosition(True, NULL); + break; + default: + return; + } +} + + +/* + * event handler for parsing user moves + */ +void UserMoveProc(window, event, data) + GtkWindow *window; + 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 (event->type == GDK_BUTTON_PRESS) { + /* todo add promotionshellwidget + XtPopdown(promotionShell); + XtDestroyWidget(promotionShell); */ + promotionUp = False; + ClearHighlights(); + fromX = fromY = -1; + } 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); + } +} diff --git a/callback.h b/callback.h new file mode 100644 index 0000000..db9e377 --- /dev/null +++ b/callback.h @@ -0,0 +1,14 @@ +void QuitProc P((GtkObject *object, gpointer user_data)); +void ResetProc P((GtkObject *object, gpointer user_data)); +void WhiteClockProc P((GtkObject *object, gpointer user_data)); +void BlackClockProc P((GtkObject *object, gpointer user_data)); +void AboutProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); +void ShowCoordsProc P((GtkObject *object, gpointer user_data)); +void ErrorPopDownProc P((GtkObject *object, gpointer user_data)); +void PauseProc P((GtkObject *object, gpointer user_data)); +void LoadNextGameProc P((GtkObject *object, gpointer user_data)); +void LoadPrevGameProc P((GtkObject *object, gpointer user_data)); +void ReloadGameProc P((GtkObject *object, gpointer user_data)); +void EventProc P((GtkWindow *window, GdkEvent *event, gpointer data)); +void UserMoveProc P((GtkWindow *window, GdkEvent *event, gpointer data)); +gboolean CloseWindowProc P((GtkWidget *button)); diff --git a/gtk-interface.xml b/gtk-interface.xml new file mode 100644 index 0000000..a54b00b --- /dev/null +++ b/gtk-interface.xml @@ -0,0 +1,618 @@ + + + + + + XBoard + + + + True + 0 + none + 0.80000001192092896 + + + True + vertical + + + True + + + True + _File + True + + + True + + + True + Reset Game + True + + + + + True + + + + + Load Game + True + image1 + False + + + + + True + Load Next Game + True + + + + + True + Load Previous Game + True + + + + + True + Reload Same Game + True + + + + + True + Save Game + True + + + + + True + + + + + True + Copy Game + True + + + + + True + Paste Game + True + + + + + True + + + + + True + Load Position + True + + + + + True + Load Next Position + True + + + + + True + Load Previous Position + True + + + + + True + Reload Same Position + True + + + + + True + Save Position + True + + + + + True + + + + + True + Copy Position + True + + + + + True + Paste Position + True + + + + + True + + + + + True + Mail Move + True + + + + + True + Reload CMail Message + True + + + + + True + + + + + gtk-quit + True + True + True + + + + + + + + + + True + _Mode + True + + + True + + + True + Machine White + True + True + + + + + True + Machine Black + True + True + + + + + True + Two Machines + True + True + + + + + + + + + True + _Action + True + + + + + True + _Step + True + + + True + + + True + Retract Move + True + + + + + + + + + True + _Options + True + + + True + + + True + Always Queen + True + + + + + True + Animate Dragging + True + + + + + True + Animate Moving + True + + + + + True + Auto Comment + True + + + + + True + Auto Flag + True + + + + + True + Auto Flip View + True + + + + + True + Auto Observe + True + + + + + True + Auto Raise Board + True + + + + + True + Auto Save + True + + + + + True + Blindfold + True + + + + + True + Flash Moves + True + + + + + True + Flip View + True + + + + + True + Get Move List + True + + + + + True + Highlight Last Move + True + + + + + True + Move Sound + True + + + + + True + ICS Alarm + True + + + + + True + Old Save Style + True + + + + + True + Periodic Updates + True + + + + + True + Ponder Next Move + True + + + + + True + Popup Exit Message + True + + + + + True + Popup Move Errors + True + + + + + True + Premove + True + + + + + True + Quiet Play + True + + + + + True + Show Coords + True + + + + + True + Show Thinking + True + + + + + True + Test Legality + True + + + + + + + + + True + _Help + True + + + True + + + gtk-about + True + True + True + + + + + + + + + False + 0 + + + + + True + + + True + + + + True + White: + + + + + 0 + + + + + True + + + + True + Black: + + + + + 1 + + + + + 1 + + + + + True + + + True + not your turn + True + + + 0 + + + + + << + True + True + True + + + False + False + 1 + + + + + < + True + True + True + + + False + False + 2 + + + + + P + True + True + True + + + + False + False + 3 + + + + + > + True + True + True + + + False + False + 4 + + + + + >> + True + True + True + + + False + False + 5 + + + + + False + 2 + + + + + True + + + + + + 3 + + + + + + + + + True + 0.40000000596046448 + gtk-open + + diff --git a/interface.c b/interface.c new file mode 100644 index 0000000..056a44e --- /dev/null +++ b/interface.c @@ -0,0 +1,77 @@ +#include "config.h" + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "common.h" +#include "frontend.h" +#include "backend.h" +#include "moves.h" +#include "xboard.h" +#include "childio.h" +#include "xgamelist.h" +#include "xhistory.h" +#include "xedittags.h" +#include "gettext.h" +#include "callback.h" + +#ifdef ENABLE_NLS +# define _(s) gettext (s) +# define N_(s) gettext_noop (s) +#else +# define _(s) (s) +# define N_(s) s +#endif + + + +GdkPixbuf *load_pixbuf(char *filename) +{ + GdkPixbuf *image; + + image = gdk_pixbuf_new_from_file(filename,NULL); + + if(image == NULL) + { + fprintf(stderr,_("Error: couldn't load file: %s\n"),filename); + exit(1); + } + return image; +} + +void GUI_DisplayTitle(text) + char *text; +{ + char title[MSG_SIZ]; + extern GtkWidget *GUI_Window; + + if (text == NULL) text = ""; + + /* todo + if (appData.titleInWindow) { + i = 0; + XtSetArg(args[i], XtNlabel, text); i++; + XtSetValues(titleWidget, args, i); + } */ + + if (*text != NULLCHAR) { + strcpy(title, text); + } else if (appData.icsActive) { + sprintf(title, "%s: %s", programName, appData.icsHost); + } else if (appData.cmailGameName[0] != NULLCHAR) { + sprintf(title, "%s: %s", programName, "CMail"); + } else if (appData.noChessProgram) { + strcpy(title, programName); + } else { + sprintf(title, "%s: %s", programName, first.tidy); + } + gtk_window_set_title(GTK_WINDOW(GUI_Window),title); +} diff --git a/interface.h b/interface.h new file mode 100644 index 0000000..9704012 --- /dev/null +++ b/interface.h @@ -0,0 +1,23 @@ +/* GTK widgets */ +GtkBuilder *builder=NULL; + +GtkWidget *GUI_Window=NULL; +GtkWidget *GUI_Board=NULL; +GtkWidget *GUI_Whiteclock=NULL; +GtkWidget *GUI_Blackclock=NULL; +gint boardWidth; +gint boardHeight; + + +GdkPixbuf *WindowIcon=NULL; +GdkPixbuf *WhiteIcon=NULL; +GdkPixbuf *BlackIcon=NULL; +GdkPixbuf *SVGpieces[12]; +GdkPixbuf *SVGLightSquare=NULL; +GdkPixbuf *SVGDarkSquare=NULL; +GdkPixbuf *SVGNeutralSquare=NULL; + +GdkCursor *BoardCursor=NULL; + + +GdkPixbuf *load_pixbuf(char *filename); diff --git a/xboard.c b/xboard.c index b739ed0..f23b848 100644 --- a/xboard.c +++ b/xboard.c @@ -182,6 +182,10 @@ extern char *getenv(); #include "bitmaps/bitmaps.h" #endif +#include +#include +#include + #include "bitmaps/icon_white.bm" #include "bitmaps/icon_black.bm" #include "bitmaps/checkmark.bm" @@ -195,6 +199,8 @@ extern char *getenv(); #include "xhistory.h" #include "xedittags.h" #include "gettext.h" +#include "callback.h" +#include "interface.h" // must be moved to xengineoutput.h @@ -244,12 +250,9 @@ void PieceMenuPopup P((Widget w, XEvent *event, String *params, Cardinal *num_params)); static void PieceMenuSelect P((Widget w, ChessSquare piece, caddr_t junk)); static void DropMenuSelect P((Widget w, ChessSquare piece, caddr_t junk)); -void ReadBitmap P((Pixmap *pm, String name, unsigned char bits[], - u_int wreq, u_int hreq)); void CreateGrid P((void)); int EventToSquare P((int x, int limit)); void DrawSquare P((int row, int column, ChessSquare piece, int do_flash)); -void EventProc P((Widget widget, caddr_t unused, XEvent *event)); void HandleUserMove P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void AnimateUserMove P((Widget w, XEvent * event, @@ -260,8 +263,6 @@ void BlackClock P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void DrawPositionProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); -void XDrawPosition P((Widget w, /*Boolean*/int repaint, - Board board)); void CommentPopUp P((char *title, char *label)); void CommentPopDown P((void)); void CommentCallback P((Widget w, XtPointer client_data, @@ -288,14 +289,6 @@ void EditCommentPopDown P((void)); void EditCommentCallback P((Widget w, XtPointer client_data, XtPointer call_data)); void SelectCommand P((Widget w, XtPointer client_data, XtPointer call_data)); -void ResetProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); -void LoadGameProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); -void LoadNextGameProc P((Widget w, XEvent *event, String *prms, - Cardinal *nprms)); -void LoadPrevGameProc P((Widget w, XEvent *event, String *prms, - Cardinal *nprms)); -void ReloadGameProc P((Widget w, XEvent *event, String *prms, - Cardinal *nprms)); void LoadPositionProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void LoadNextPositionProc P((Widget w, XEvent *event, String *prms, @@ -316,8 +309,6 @@ void SavePositionProc P((Widget w, XEvent *event, void MailMoveProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void ReloadCmailMsgProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); -void QuitProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); -void PauseProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void MachineBlackProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void MachineWhiteProc P((Widget w, XEvent *event, @@ -402,8 +393,6 @@ void PopupExitMessageProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void PremoveProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void QuietPlayProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); -void ShowCoordsProc P((Widget w, XEvent *event, String *prms, - Cardinal *nprms)); void ShowThinkingProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void HideThinkingProc P((Widget w, XEvent *event, String *prms, @@ -415,7 +404,6 @@ void ManProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void HintProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void BookProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void AboutGameProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); -void AboutProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void DebugProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void NothingProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); void Iconify P((Widget w, XEvent *event, String *prms, Cardinal *nprms)); @@ -427,9 +415,9 @@ void ErrorPopUp P((char *title, char *text, int modal)); void ErrorPopDown P((void)); static char *ExpandPathName P((char *path)); static void CreateAnimVars P((void)); -static void DragPieceBegin P((int x, int y)); +void DragPieceBegin P((int x, int y)); static void DragPieceMove P((int x, int y)); -static void DragPieceEnd P((int x, int y)); +void DragPieceEnd P((int x, int y)); static void DrawDragPiece P((void)); char *ModeToWidgetName P((GameMode mode)); void EngineOutputUpdate( FrontEndProgramStats * stats ); @@ -466,7 +454,7 @@ Widget shellWidget, layoutWidget, formWidget, boardWidget, messageWidget, commentShell, promotionShell, whitePieceMenu, blackPieceMenu, dropMenu, menuBarWidget, buttonBarWidget, editShell, errorShell, analysisShell, ICSInputShell, fileNameShell, askQuestionShell; -XSegment gridSegments[(BOARD_SIZE + 1) * 2]; +GdkSegment gridSegments[(BOARD_SIZE + 1) * 2]; XSegment jailGridSegments[(BOARD_SIZE + 3) * 2]; Font clockFontID, coordFontID, countFontID; XFontStruct *clockFontStruct, *coordFontStruct, *countFontStruct; @@ -543,14 +531,9 @@ static Pixmap xpmMask[BlackKing + 1]; SizeDefaults sizeDefaults[] = SIZE_DEFAULTS; MenuItem fileMenu[] = { - {N_("New Game"), ResetProc}, {N_("New Shuffle Game ..."), ShuffleMenuProc}, {N_("New Variant ..."), NewVariantProc}, // [HGM] variant: not functional yet {"----", NothingProc}, - {N_("Load Game"), LoadGameProc}, - {N_("Load Next Game"), LoadNextGameProc}, - {N_("Load Previous Game"), LoadPrevGameProc}, - {N_("Reload Same Game"), ReloadGameProc}, {N_("Save Game"), SaveGameProc}, {"----", NothingProc}, {N_("Copy Game"), CopyGameProc}, @@ -568,7 +551,6 @@ MenuItem fileMenu[] = { {N_("Mail Move"), MailMoveProc}, {N_("Reload CMail Message"), ReloadCmailMsgProc}, {"----", NothingProc}, - {N_("Exit"), QuitProc}, {NULL, NULL} }; @@ -591,7 +573,6 @@ MenuItem modeMenu[] = { {N_("Edit Tags"), EditTagsProc}, {N_("Edit Comment"), EditCommentProc}, {N_("ICS Input Box"), IcsInputBoxProc}, - {N_("Pause"), PauseProc}, {NULL, NULL} }; @@ -662,7 +643,6 @@ MenuItem optionsMenu[] = { {N_("Popup Move Errors"), PopupMoveErrorsProc}, {N_("Premove"), PremoveProc}, {N_("Quiet Play"), QuietPlayProc}, - {N_("Show Coords"), ShowCoordsProc}, {N_("Hide Thinking"), HideThinkingProc}, {N_("Test Legality"), TestLegalityProc}, {NULL, NULL} @@ -675,7 +655,6 @@ MenuItem helpMenu[] = { {N_("Hint"), HintProc}, {N_("Book"), BookProc}, {"----", NothingProc}, - {N_("About XBoard"), AboutProc}, {NULL, NULL} }; @@ -693,7 +672,7 @@ Menu menuBar[] = { MenuItem buttonBar[] = { {"<<", ToStartProc}, {"<", BackwardProc}, - {PAUSE_BUTTON, PauseProc}, + // {PAUSE_BUTTON, PauseProc}, {">", ForwardProc}, {">>", ToEndProc}, {NULL, NULL} @@ -1778,12 +1757,7 @@ XtActionsRec boardActions[] = { { "WhiteClock", WhiteClock }, { "BlackClock", BlackClock }, { "Iconify", Iconify }, - { "ResetProc", ResetProc }, - { "LoadGameProc", LoadGameProc }, - { "LoadNextGameProc", LoadNextGameProc }, - { "LoadPrevGameProc", LoadPrevGameProc }, { "LoadSelectedProc", LoadSelectedProc }, - { "ReloadGameProc", ReloadGameProc }, { "LoadPositionProc", LoadPositionProc }, { "LoadNextPositionProc", LoadNextPositionProc }, { "LoadPrevPositionProc", LoadPrevPositionProc }, @@ -1796,7 +1770,6 @@ XtActionsRec boardActions[] = { { "SavePositionProc", SavePositionProc }, { "MailMoveProc", MailMoveProc }, { "ReloadCmailMsgProc", ReloadCmailMsgProc }, - { "QuitProc", QuitProc }, { "MachineWhiteProc", MachineWhiteProc }, { "MachineBlackProc", MachineBlackProc }, { "AnalysisModeProc", AnalyzeModeProc }, @@ -1813,7 +1786,6 @@ XtActionsRec boardActions[] = { { "EditCommentProc", EditCommentProc }, { "IcsAlarmProc", IcsAlarmProc }, { "IcsInputBoxProc", IcsInputBoxProc }, - { "PauseProc", PauseProc }, { "AcceptProc", AcceptProc }, { "DeclineProc", DeclineProc }, { "RematchProc", RematchProc }, @@ -1861,7 +1833,6 @@ XtActionsRec boardActions[] = { { "PopupMoveErrorsProc", PopupMoveErrorsProc }, { "PremoveProc", PremoveProc }, { "QuietPlayProc", QuietPlayProc }, - { "ShowCoordsProc", ShowCoordsProc }, { "ShowThinkingProc", ShowThinkingProc }, { "HideThinkingProc", HideThinkingProc }, { "TestLegalityProc", TestLegalityProc }, @@ -1870,7 +1841,6 @@ XtActionsRec boardActions[] = { { "HintProc", HintProc }, { "BookProc", BookProc }, { "AboutGameProc", AboutGameProc }, - { "AboutProc", AboutProc }, { "DebugProc", DebugProc }, { "NothingProc", NothingProc }, { "CommentPopDown", (XtActionProc) CommentPopDown }, @@ -1895,16 +1865,10 @@ XtActionsRec boardActions[] = { char globalTranslations[] = ":R: ResignProc() \n \ - :r: ResetProc() \n \ - :g: LoadGameProc() \n \ - :N: LoadNextGameProc() \n \ - :P: LoadPrevGameProc() \n \ - :Q: QuitProc() \n \ :F: ToEndProc() \n \ :f: ForwardProc() \n \ :B: ToStartProc() \n \ :b: BackwardProc() \n \ - :p: PauseProc() \n \ :d: DrawProc() \n \ :t: CallFlagProc() \n \ :i: Iconify() \n \ @@ -2196,54 +2160,54 @@ void InitDrawingSizes(BoardSize boardSize, int flags) /* * Enable shell resizing. */ - shellArgs[0].value = (XtArgVal) &w; - shellArgs[1].value = (XtArgVal) &h; - XtGetValues(shellWidget, shellArgs, 2); - - shellArgs[4].value = 2*w; shellArgs[2].value = 10; - shellArgs[5].value = 2*h; shellArgs[3].value = 10; - XtSetValues(shellWidget, &shellArgs[2], 4); - - XtSetArg(args[0], XtNdefaultDistance, &sep); - XtGetValues(formWidget, args, 1); +// shellArgs[0].value = (XtArgVal) &w; +// shellArgs[1].value = (XtArgVal) &h; +// XtGetValues(shellWidget, shellArgs, 2); +// +// shellArgs[4].value = 2*w; shellArgs[2].value = 10; +// shellArgs[5].value = 2*h; shellArgs[3].value = 10; +// XtSetValues(shellWidget, &shellArgs[2], 4); +// +// XtSetArg(args[0], XtNdefaultDistance, &sep); +// XtGetValues(formWidget, args, 1); boardWidth = lineGap + BOARD_WIDTH * (squareSize + lineGap); boardHeight = lineGap + BOARD_HEIGHT * (squareSize + lineGap); CreateGrid(); - XtSetArg(args[0], XtNwidth, boardWidth); - XtSetArg(args[1], XtNheight, boardHeight); - XtSetValues(boardWidget, args, 2); +// XtSetArg(args[0], XtNwidth, boardWidth); +// XtSetArg(args[1], XtNheight, boardHeight); +// XtSetValues(boardWidget, args, 2); timerWidth = (boardWidth - sep) / 2; - XtSetArg(args[0], XtNwidth, timerWidth); - XtSetValues(whiteTimerWidget, args, 1); - XtSetValues(blackTimerWidget, args, 1); - - XawFormDoLayout(formWidget, False); +// XtSetArg(args[0], XtNwidth, timerWidth); +// XtSetValues(whiteTimerWidget, args, 1); +// XtSetValues(blackTimerWidget, args, 1); +// +// XawFormDoLayout(formWidget, False); if (appData.titleInWindow) { i = 0; - XtSetArg(args[i], XtNborderWidth, &bor); i++; - XtSetArg(args[i], XtNheight, &h); i++; - XtGetValues(titleWidget, args, i); +// XtSetArg(args[i], XtNborderWidth, &bor); i++; +// XtSetArg(args[i], XtNheight, &h); i++; +// XtGetValues(titleWidget, args, i); if (smallLayout) { w = boardWidth - 2*bor; } else { - XtSetArg(args[0], XtNwidth, &w); - XtGetValues(menuBarWidget, args, 1); +// XtSetArg(args[0], XtNwidth, &w); +// XtGetValues(menuBarWidget, args, 1); w = boardWidth - w - sep - 2*bor - 2; // WIDTH_FUDGE } - gres = XtMakeResizeRequest(titleWidget, w, h, &wr, &hr); - if (gres != XtGeometryYes && appData.debugMode) { - fprintf(stderr, - _("%s: titleWidget geometry error %d %d %d %d %d\n"), - programName, gres, w, h, wr, hr); - } +// gres = XtMakeResizeRequest(titleWidget, w, h, &wr, &hr); +// if (gres != XtGeometryYes && appData.debugMode) { +// fprintf(stderr, +// _("%s: titleWidget geometry error %d %d %d %d %d\n"), +// programName, gres, w, h, wr, hr); +// } } - XawFormDoLayout(formWidget, True); + // XawFormDoLayout(formWidget, True); /* * Inhibit shell resizing. @@ -2252,7 +2216,7 @@ void InitDrawingSizes(BoardSize boardSize, int flags) shellArgs[1].value = h = (XtArgVal) boardHeight + marginH; shellArgs[4].value = shellArgs[2].value = w; shellArgs[5].value = shellArgs[3].value = h; - XtSetValues(shellWidget, &shellArgs[0], 6); + // XtSetValues(shellWidget, &shellArgs[0], 6); // [HGM] pieces: tailor piece bitmaps to needs of specific variant // (only for xpm) @@ -2395,6 +2359,30 @@ main(argc, argv) XtAppInitialize(&appContext, "XBoard", shellOptions, XtNumber(shellOptions), &argc, argv, xboardResources, NULL, 0); + + gtk_init (&argc, &argv); + + /* parse glade file */ + + builder = gtk_builder_new (); + gtk_builder_add_from_file (builder, "gtk-interface.xml", NULL); + + GUI_Window = GTK_WIDGET (gtk_builder_get_object (builder, "MainWindow")); + if(!GUI_Window) printf("Error: gtk_builder didn't work!\n"); + GUI_Board = GTK_WIDGET (gtk_builder_get_object (builder, "Board")); + if(!GUI_Board) printf("Error: gtk_builder didn't work!\n"); + GUI_Whiteclock = GTK_WIDGET (gtk_builder_get_object (builder, "WhiteClock")); + if(!GUI_Whiteclock) printf("Error: gtk_builder didn't work!\n"); + GUI_Blackclock = GTK_WIDGET (gtk_builder_get_object (builder, "BlackClock")); + if(!GUI_Blackclock) printf("Error: gtk_builder didn't work!\n"); + + gtk_builder_connect_signals (builder, NULL); + // don't unref the builder, since we use it to get references to widgets + // g_object_unref (G_OBJECT (builder)); + + printf("DEBUG:finished building gtk\n"); + /* end parse glade file */ + if (argc > 1) { fprintf(stderr, _("%s: unrecognized argument %s\n"), programName, argv[1]); @@ -2712,7 +2700,9 @@ XBoard square size (hint): %d\n\ textColors[ColorNone].fg = textColors[ColorNone].bg = -1; textColors[ColorNone].attr = 0; - XtAppAddActions(appContext, boardActions, XtNumber(boardActions)); + printf("DEBUG: I'm here 0\n"); + + // XtAppAddActions(appContext, boardActions, XtNumber(boardActions)); /* * widget hierarchy @@ -2756,6 +2746,7 @@ XBoard square size (hint): %d\n\ XtSetArg(args[1], XtNtop, XtChainTop); XtSetArg(args[2], XtNbottom, XtChainTop); XtSetValues(blackTimerWidget, args, 3); + printf("DEBUG: I'm here 1\n"); if (appData.titleInWindow) { widgetList[j++] = titleWidget = @@ -2775,137 +2766,156 @@ XBoard square size (hint): %d\n\ XtSetValues(buttonBarWidget, args, 4); } - widgetList[j++] = messageWidget = - XtCreateWidget("message", labelWidgetClass, formWidget, - messageArgs, XtNumber(messageArgs)); - XtSetArg(args[0], XtNtop, XtChainTop); - XtSetArg(args[1], XtNbottom, XtChainTop); - XtSetValues(messageWidget, args, 2); - - widgetList[j++] = boardWidget = - XtCreateWidget("board", widgetClass, formWidget, boardArgs, - XtNumber(boardArgs)); +// widgetList[j++] = messageWidget = +// XtCreateWidget("message", labelWidgetClass, formWidget, +// messageArgs, XtNumber(messageArgs)); +// XtSetArg(args[0], XtNtop, XtChainTop); +// XtSetArg(args[1], XtNbottom, XtChainTop); +// XtSetValues(messageWidget, args, 2); +// +// widgetList[j++] = boardWidget = +// XtCreateWidget("board", widgetClass, formWidget, boardArgs, +// XtNumber(boardArgs)); +// +// XtManageChildren(widgetList, j); +// +// timerWidth = (boardWidth - sep) / 2; +// XtSetArg(args[0], XtNwidth, timerWidth); +// XtSetValues(whiteTimerWidget, args, 1); +// XtSetValues(blackTimerWidget, args, 1); +// +// XtSetArg(args[0], XtNbackground, &timerBackgroundPixel); +// XtSetArg(args[1], XtNforeground, &timerForegroundPixel); +// XtGetValues(whiteTimerWidget, args, 2); +// +// if (appData.showButtonBar) { +// XtSetArg(args[0], XtNbackground, &buttonBackgroundPixel); +// XtSetArg(args[1], XtNforeground, &buttonForegroundPixel); +// XtGetValues(XtNameToWidget(buttonBarWidget, PAUSE_BUTTON), args, 2); +// } +// - XtManageChildren(widgetList, j); + /* + * gtk set properties of widgets + */ - timerWidth = (boardWidth - sep) / 2; - XtSetArg(args[0], XtNwidth, timerWidth); - XtSetValues(whiteTimerWidget, args, 1); - XtSetValues(blackTimerWidget, args, 1); + /* set board size */ + gtk_widget_set_size_request(GTK_WIDGET(GUI_Board), + boardWidth,boardHeight); - XtSetArg(args[0], XtNbackground, &timerBackgroundPixel); - XtSetArg(args[1], XtNforeground, &timerForegroundPixel); - XtGetValues(whiteTimerWidget, args, 2); + /* end gtk set properties of widgets */ - if (appData.showButtonBar) { - XtSetArg(args[0], XtNbackground, &buttonBackgroundPixel); - XtSetArg(args[1], XtNforeground, &buttonForegroundPixel); - XtGetValues(XtNameToWidget(buttonBarWidget, PAUSE_BUTTON), args, 2); - } + printf("DEBUG: made it.\n"); /* * formWidget uses these constraints but they are stored * in the children. */ - i = 0; - XtSetArg(args[i], XtNfromHoriz, 0); i++; - XtSetValues(menuBarWidget, args, i); - if (appData.titleInWindow) { - if (smallLayout) { - i = 0; - XtSetArg(args[i], XtNfromVert, menuBarWidget); i++; - XtSetValues(whiteTimerWidget, args, i); - i = 0; - XtSetArg(args[i], XtNfromVert, menuBarWidget); i++; - XtSetArg(args[i], XtNfromHoriz, whiteTimerWidget); i++; - XtSetValues(blackTimerWidget, args, i); - i = 0; - XtSetArg(args[i], XtNfromVert, whiteTimerWidget); i++; - XtSetArg(args[i], XtNjustify, XtJustifyLeft); i++; - XtSetValues(titleWidget, args, i); - i = 0; - XtSetArg(args[i], XtNfromVert, titleWidget); i++; - XtSetArg(args[i], XtNresizable, (XtArgVal) True); i++; - XtSetValues(messageWidget, args, i); - if (appData.showButtonBar) { - i = 0; - XtSetArg(args[i], XtNfromVert, titleWidget); i++; - XtSetArg(args[i], XtNfromHoriz, messageWidget); i++; - XtSetValues(buttonBarWidget, args, i); - } - } else { - i = 0; - XtSetArg(args[i], XtNfromVert, titleWidget); i++; - XtSetValues(whiteTimerWidget, args, i); - i = 0; - XtSetArg(args[i], XtNfromVert, titleWidget); i++; - XtSetArg(args[i], XtNfromHoriz, whiteTimerWidget); i++; - XtSetValues(blackTimerWidget, args, i); - i = 0; - XtSetArg(args[i], XtNfromHoriz, menuBarWidget); i++; - XtSetValues(titleWidget, args, i); - i = 0; - XtSetArg(args[i], XtNfromVert, whiteTimerWidget); i++; - XtSetArg(args[i], XtNresizable, (XtArgVal) True); i++; - XtSetValues(messageWidget, args, i); - if (appData.showButtonBar) { - i = 0; - XtSetArg(args[i], XtNfromVert, whiteTimerWidget); i++; - XtSetArg(args[i], XtNfromHoriz, messageWidget); i++; - XtSetValues(buttonBarWidget, args, i); - } - } - } else { - i = 0; - XtSetArg(args[i], XtNfromVert, menuBarWidget); i++; - XtSetValues(whiteTimerWidget, args, i); - i = 0; - XtSetArg(args[i], XtNfromVert, menuBarWidget); i++; - XtSetArg(args[i], XtNfromHoriz, whiteTimerWidget); i++; - XtSetValues(blackTimerWidget, args, i); - i = 0; - XtSetArg(args[i], XtNfromVert, whiteTimerWidget); i++; - XtSetArg(args[i], XtNresizable, (XtArgVal) True); i++; - XtSetValues(messageWidget, args, i); - if (appData.showButtonBar) { - i = 0; - XtSetArg(args[i], XtNfromVert, whiteTimerWidget); i++; - XtSetArg(args[i], XtNfromHoriz, messageWidget); i++; - XtSetValues(buttonBarWidget, args, i); - } - } - i = 0; - XtSetArg(args[0], XtNfromVert, messageWidget); - XtSetArg(args[1], XtNtop, XtChainTop); - XtSetArg(args[2], XtNbottom, XtChainBottom); - XtSetArg(args[3], XtNleft, XtChainLeft); - XtSetArg(args[4], XtNright, XtChainRight); - XtSetValues(boardWidget, args, 5); - - XtRealizeWidget(shellWidget); +// i = 0; +// XtSetArg(args[i], XtNfromHoriz, 0); i++; +// XtSetValues(menuBarWidget, args, i); +// if (appData.titleInWindow) { +// if (smallLayout) { +// printf("DEBUG: made it a.\n"); +// i = 0; +// XtSetArg(args[i], XtNfromVert, menuBarWidget); i++; +// XtSetValues(whiteTimerWidget, args, i); +// i = 0; +// XtSetArg(args[i], XtNfromVert, menuBarWidget); i++; +// XtSetArg(args[i], XtNfromHoriz, whiteTimerWidget); i++; +// XtSetValues(blackTimerWidget, args, i); +// i = 0; +// XtSetArg(args[i], XtNfromVert, whiteTimerWidget); i++; +// XtSetArg(args[i], XtNjustify, XtJustifyLeft); i++; +// XtSetValues(titleWidget, args, i); +// i = 0; +// XtSetArg(args[i], XtNfromVert, titleWidget); i++; +// XtSetArg(args[i], XtNresizable, (XtArgVal) True); i++; +// XtSetValues(messageWidget, args, i); +// if (appData.showButtonBar) { +// i = 0; +// XtSetArg(args[i], XtNfromVert, titleWidget); i++; +// XtSetArg(args[i], XtNfromHoriz, messageWidget); i++; +// XtSetValues(buttonBarWidget, args, i); +// } +// } else { +// printf("DEBUG: made it b.\n"); +// i = 0; +// XtSetArg(args[i], XtNfromVert, titleWidget); i++; +// XtSetValues(whiteTimerWidget, args, i); +// i = 0; +// XtSetArg(args[i], XtNfromVert, titleWidget); i++; +// XtSetArg(args[i], XtNfromHoriz, whiteTimerWidget); i++; +// XtSetValues(blackTimerWidget, args, i); +// i = 0; +// XtSetArg(args[i], XtNfromHoriz, menuBarWidget); i++; +// XtSetValues(titleWidget, args, i); +// i = 0; +// XtSetArg(args[i], XtNfromVert, whiteTimerWidget); i++; +// XtSetArg(args[i], XtNresizable, (XtArgVal) True); i++; +// XtSetValues(messageWidget, args, i); +// if (appData.showButtonBar) { +// i = 0; +// XtSetArg(args[i], XtNfromVert, whiteTimerWidget); i++; +// XtSetArg(args[i], XtNfromHoriz, messageWidget); i++; +// XtSetValues(buttonBarWidget, args, i); +// } +// } +// } else { printf("DEBUG: made it c.\n"); +// +// i = 0; +// XtSetArg(args[i], XtNfromVert, menuBarWidget); i++; +// XtSetValues(whiteTimerWidget, args, i); +// i = 0; +// XtSetArg(args[i], XtNfromVert, menuBarWidget); i++; +// XtSetArg(args[i], XtNfromHoriz, whiteTimerWidget); i++; +// XtSetValues(blackTimerWidget, args, i); +// i = 0; +// XtSetArg(args[i], XtNfromVert, whiteTimerWidget); i++; +// XtSetArg(args[i], XtNresizable, (XtArgVal) True); i++; +// XtSetValues(messageWidget, args, i); +// if (appData.showButtonBar) { +// i = 0; +// XtSetArg(args[i], XtNfromVert, whiteTimerWidget); i++; +// XtSetArg(args[i], XtNfromHoriz, messageWidget); i++; +// XtSetValues(buttonBarWidget, args, i); +// } +// } +// printf("DEBUG: made it 1.\n"); +// i = 0; +// XtSetArg(args[0], XtNfromVert, messageWidget); +// XtSetArg(args[1], XtNtop, XtChainTop); +// XtSetArg(args[2], XtNbottom, XtChainBottom); +// XtSetArg(args[3], XtNleft, XtChainLeft); +// XtSetArg(args[4], XtNright, XtChainRight); +// XtSetValues(boardWidget, args, 5); +// +// XtRealizeWidget(shellWidget); +// + printf("DEBUG: made it 2.\n"); /* * Correct the width of the message and title widgets. * It is not known why some systems need the extra fudge term. * The value "2" is probably larger than needed. */ - XawFormDoLayout(formWidget, False); + // XawFormDoLayout(formWidget, False); #define WIDTH_FUDGE 2 - i = 0; - XtSetArg(args[i], XtNborderWidth, &bor); i++; - XtSetArg(args[i], XtNheight, &h); i++; - XtGetValues(messageWidget, args, i); +// i = 0; +// XtSetArg(args[i], XtNborderWidth, &bor); i++; +// XtSetArg(args[i], XtNheight, &h); i++; +// XtGetValues(messageWidget, args, i); if (appData.showButtonBar) { - i = 0; - XtSetArg(args[i], XtNwidth, &w); i++; - XtGetValues(buttonBarWidget, args, i); - w = boardWidth - w - sep - 2*bor - WIDTH_FUDGE; +// i = 0; +// XtSetArg(args[i], XtNwidth, &w); i++; +// XtGetValues(buttonBarWidget, args, i); +// w = boardWidth - w - sep - 2*bor - WIDTH_FUDGE; } else { - w = boardWidth - 2*bor + 1; /*!! +1 compensates for kludge below */ +// w = boardWidth - 2*bor + 1; /*!! +1 compensates for kludge below */ } - - gres = XtMakeResizeRequest(messageWidget, w, h, &wr, &hr); +// +// gres = XtMakeResizeRequest(messageWidget, w, h, &wr, &hr); if (gres != XtGeometryYes && appData.debugMode) { fprintf(stderr, _("%s: messageWidget geometry error %d %d %d %d %d\n"), programName, gres, w, h, wr, hr); @@ -2915,238 +2925,193 @@ XBoard square size (hint): %d\n\ /* The size used for the child widget in layout lags one resize behind its true size, so we resize a second time, 1 pixel smaller. Yeech! */ w--; - gres = XtMakeResizeRequest(messageWidget, w, h, &wr, &hr); +// gres = XtMakeResizeRequest(messageWidget, w, h, &wr, &hr); if (gres != XtGeometryYes && appData.debugMode) { fprintf(stderr, _("%s: messageWidget geometry error %d %d %d %d %d\n"), programName, gres, w, h, wr, hr); } /* !! end hack */ - XtSetArg(args[0], XtNleft, XtChainLeft); // [HGM] glue ends for good run-time sizing - XtSetArg(args[1], XtNright, XtChainRight); - XtSetValues(messageWidget, args, 2); - +// XtSetArg(args[0], XtNleft, XtChainLeft); // [HGM] glue ends for good run-time sizing +// XtSetArg(args[1], XtNright, XtChainRight); +// XtSetValues(messageWidget, args, 2); +// if (appData.titleInWindow) { i = 0; - XtSetArg(args[i], XtNborderWidth, &bor); i++; - XtSetArg(args[i], XtNheight, &h); i++; - XtGetValues(titleWidget, args, i); +// XtSetArg(args[i], XtNborderWidth, &bor); i++; +// XtSetArg(args[i], XtNheight, &h); i++; +// XtGetValues(titleWidget, args, i); if (smallLayout) { w = boardWidth - 2*bor; } else { - XtSetArg(args[0], XtNwidth, &w); - XtGetValues(menuBarWidget, args, 1); - w = boardWidth - w - sep - 2*bor - WIDTH_FUDGE; +// XtSetArg(args[0], XtNwidth, &w); +// XtGetValues(menuBarWidget, args, 1); +// w = boardWidth - w - sep - 2*bor - WIDTH_FUDGE; } - gres = XtMakeResizeRequest(titleWidget, w, h, &wr, &hr); +// gres = XtMakeResizeRequest(titleWidget, w, h, &wr, &hr); if (gres != XtGeometryYes && appData.debugMode) { fprintf(stderr, _("%s: titleWidget geometry error %d %d %d %d %d\n"), programName, gres, w, h, wr, hr); } } - XawFormDoLayout(formWidget, True); - - xBoardWindow = XtWindow(boardWidget); - +// XawFormDoLayout(formWidget, True); +// +// xBoardWindow = XtWindow(boardWidget); +// // [HGM] it seems the layout code ends here, but perhaps the color stuff is size independent and would // not need to go into InitDrawingSizes(). #endif - /* - * Create X checkmark bitmap and initialize option menu checks. - */ - ReadBitmap(&xMarkPixmap, "checkmark.bm", - checkmark_bits, checkmark_width, checkmark_height); - XtSetArg(args[0], XtNleftBitmap, xMarkPixmap); if (appData.alwaysPromoteToQueen) { - XtSetValues(XtNameToWidget(menuBarWidget, "menuOptions.Always Queen"), - args, 1); + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (gtk_builder_get_object (builder, "menuOptions.Always Queen")),TRUE); } if (appData.animateDragging) { - XtSetValues(XtNameToWidget(menuBarWidget, - "menuOptions.Animate Dragging"), - args, 1); + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (gtk_builder_get_object (builder, "menuOptions.Animate Dragging")),TRUE); } if (appData.animate) { - XtSetValues(XtNameToWidget(menuBarWidget, "menuOptions.Animate Moving"), - args, 1); + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (gtk_builder_get_object (builder, "menuOptions.Animate Moving")),TRUE); } if (appData.autoComment) { - XtSetValues(XtNameToWidget(menuBarWidget, "menuOptions.Auto Comment"), - args, 1); + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (gtk_builder_get_object (builder, "menuOptions.Auto Comment")),TRUE); } if (appData.autoCallFlag) { - XtSetValues(XtNameToWidget(menuBarWidget, "menuOptions.Auto Flag"), - args, 1); + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (gtk_builder_get_object (builder, "menuOptions.Auto Flag")),TRUE); } if (appData.autoFlipView) { - XtSetValues(XtNameToWidget(menuBarWidget,"menuOptions.Auto Flip View"), - args, 1); + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (gtk_builder_get_object (builder, "menuOptions.Auto Flip View")),TRUE); } if (appData.autoObserve) { - XtSetValues(XtNameToWidget(menuBarWidget, "menuOptions.Auto Observe"), - args, 1); + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (gtk_builder_get_object (builder, "menuOptions.Auto Observe")),TRUE); } if (appData.autoRaiseBoard) { - XtSetValues(XtNameToWidget(menuBarWidget, - "menuOptions.Auto Raise Board"), args, 1); + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (gtk_builder_get_object (builder, "menuOptions.Auto Raise Board")),TRUE); } if (appData.autoSaveGames) { - XtSetValues(XtNameToWidget(menuBarWidget, "menuOptions.Auto Save"), - args, 1); + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (gtk_builder_get_object (builder, "menuOptions.Auto Save")),TRUE); } if (appData.saveGameFile[0] != NULLCHAR) { - /* Can't turn this off from menu */ - XtSetValues(XtNameToWidget(menuBarWidget, "menuOptions.Auto Save"), - args, 1); - XtSetSensitive(XtNameToWidget(menuBarWidget, "menuOptions.Auto Save"), - False); - + /* Can't turn this off from menu */ + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (gtk_builder_get_object (builder, "menuOptions.Auto Save")),TRUE); + gtk_action_set_sensitive(GTK_ACTION (gtk_builder_get_object (builder, "menuOptions.Auto Save")),FALSE); } if (appData.blindfold) { - XtSetValues(XtNameToWidget(menuBarWidget, - "menuOptions.Blindfold"), args, 1); + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (gtk_builder_get_object (builder, "menuOptions.Blindfold")),TRUE); } if (appData.flashCount > 0) { - XtSetValues(XtNameToWidget(menuBarWidget, - "menuOptions.Flash Moves"), - args, 1); + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (gtk_builder_get_object (builder, "menuOptions.Flash Moves")),TRUE); } if (appData.getMoveList) { - XtSetValues(XtNameToWidget(menuBarWidget, "menuOptions.Get Move List"), - args, 1); + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (gtk_builder_get_object (builder, "menuOptions.Get Move List")),TRUE); } #if HIGHDRAG if (appData.highlightDragging) { - XtSetValues(XtNameToWidget(menuBarWidget, - "menuOptions.Highlight Dragging"), - args, 1); + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (gtk_builder_get_object (builder, "menuOptions.Highlight Dragging")),TRUE); } #endif if (appData.highlightLastMove) { - XtSetValues(XtNameToWidget(menuBarWidget, - "menuOptions.Highlight Last Move"), - args, 1); + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (gtk_builder_get_object (builder, "menuOptions.Highlight Last Move")),TRUE); } if (appData.icsAlarm) { - XtSetValues(XtNameToWidget(menuBarWidget, "menuOptions.ICS Alarm"), - args, 1); + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (gtk_builder_get_object (builder, "menuOptions.ICS Alarm")),TRUE); } if (appData.ringBellAfterMoves) { - XtSetValues(XtNameToWidget(menuBarWidget, "menuOptions.Move Sound"), - args, 1); + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (gtk_builder_get_object (builder, "menuOptions.Move Sound")),TRUE); } if (appData.oldSaveStyle) { - XtSetValues(XtNameToWidget(menuBarWidget, - "menuOptions.Old Save Style"), args, 1); + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (gtk_builder_get_object (builder, "menuOptions.Old Save Style")),TRUE); } if (appData.periodicUpdates) { - XtSetValues(XtNameToWidget(menuBarWidget, - "menuOptions.Periodic Updates"), args, 1); + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (gtk_builder_get_object (builder, "menuOptions.Periodic Updates")),TRUE); } if (appData.ponderNextMove) { - XtSetValues(XtNameToWidget(menuBarWidget, - "menuOptions.Ponder Next Move"), args, 1); + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (gtk_builder_get_object (builder, "menuOptions.Ponder Next Move")),TRUE); } if (appData.popupExitMessage) { - XtSetValues(XtNameToWidget(menuBarWidget, - "menuOptions.Popup Exit Message"), args, 1); + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (gtk_builder_get_object (builder, "menuOptions.Popup Exit Message")),TRUE); } if (appData.popupMoveErrors) { - XtSetValues(XtNameToWidget(menuBarWidget, - "menuOptions.Popup Move Errors"), args, 1); + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (gtk_builder_get_object (builder, "menuOptions.Popup Move Errors")),TRUE); } if (appData.premove) { - XtSetValues(XtNameToWidget(menuBarWidget, - "menuOptions.Premove"), args, 1); + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (gtk_builder_get_object (builder, "menuOptions.Premove")),TRUE); } if (appData.quietPlay) { - XtSetValues(XtNameToWidget(menuBarWidget, - "menuOptions.Quiet Play"), args, 1); + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (gtk_builder_get_object (builder, "menuOptions.Quit Play")),TRUE); } if (appData.showCoords) { - XtSetValues(XtNameToWidget(menuBarWidget, "menuOptions.Show Coords"), - args, 1); + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (gtk_builder_get_object (builder, "menuOptions.Show Coords")),TRUE); } - if (appData.hideThinkingFromHuman) { - XtSetValues(XtNameToWidget(menuBarWidget, "menuOptions.Hide Thinking"), - args, 1); + if (appData.showThinking) { + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (gtk_builder_get_object (builder, "menuOptions.Show Thinking")),TRUE); } if (appData.testLegality) { - XtSetValues(XtNameToWidget(menuBarWidget,"menuOptions.Test Legality"), - args, 1); + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (gtk_builder_get_object (builder, "menuOptions.Test Legality")),TRUE); } /* * Create an icon. */ - ReadBitmap(&wIconPixmap, "icon_white.bm", - icon_white_bits, icon_white_width, icon_white_height); - ReadBitmap(&bIconPixmap, "icon_black.bm", - icon_black_bits, icon_black_width, icon_black_height); - iconPixmap = wIconPixmap; - i = 0; - XtSetArg(args[i], XtNiconPixmap, iconPixmap); i++; - XtSetValues(shellWidget, args, i); - - /* - * Create a cursor for the board widget. - */ - window_attributes.cursor = XCreateFontCursor(xDisplay, XC_hand2); - XChangeWindowAttributes(xDisplay, xBoardWindow, - CWCursor, &window_attributes); - - /* - * Inhibit shell resizing. - */ - shellArgs[0].value = (XtArgVal) &w; - shellArgs[1].value = (XtArgVal) &h; - XtGetValues(shellWidget, shellArgs, 2); - shellArgs[4].value = shellArgs[2].value = w; - shellArgs[5].value = shellArgs[3].value = h; - XtSetValues(shellWidget, &shellArgs[2], 4); - marginW = w - boardWidth; // [HGM] needed to set new shellWidget size when we resize board - marginH = h - boardHeight; - - CatchDeleteWindow(shellWidget, "QuitProc"); +// ReadBitmap(&wIconPixmap, "icon_white.bm", +// icon_white_bits, icon_white_width, icon_white_height); +// ReadBitmap(&bIconPixmap, "icon_black.bm", +// icon_black_bits, icon_black_width, icon_black_height); +// iconPixmap = wIconPixmap; +// i = 0; +// XtSetArg(args[i], XtNiconPixmap, iconPixmap); i++; +// XtSetValues(shellWidget, args, i); +// + + printf("DEBUG: creating svgs.\n"); + + /* load square colors */ + SVGLightSquare = load_pixbuf("svg/LightSquare.svg"); + SVGDarkSquare = load_pixbuf("svg/DarkSquare.svg"); + SVGNeutralSquare = load_pixbuf("svg/NeutralSquare.svg"); + + /* use two icons to indicate if it is white's or black's turn */ + WhiteIcon = load_pixbuf("svg/icon_white.svg"); + BlackIcon = load_pixbuf("svg/icon_black.svg"); + WindowIcon = WhiteIcon; + gtk_window_set_icon(GTK_WINDOW(GUI_Window),WindowIcon); + + /* do resizing to a fixed aspect ratio */ + GdkGeometry hints; + hints.min_aspect = 0.8; + hints.max_aspect = 0.8; + gtk_window_set_geometry_hints (GTK_WINDOW (GUI_Window), + GTK_WIDGET (GUI_Window), + &hints, + GDK_HINT_ASPECT); + + /* realize window */ + gtk_widget_show (GUI_Window); CreateGCs(); CreateGrid(); -#if HAVE_LIBXPM - if (appData.bitmapDirectory[0] != NULLCHAR) { - CreatePieces(); - } else { - CreateXPMPieces(); - } -#else - CreateXIMPieces(); - /* Create regular pieces */ - if (!useImages) CreatePieces(); -#endif + CreatePieces(); CreatePieceMenus(); if (appData.animate || appData.animateDragging) CreateAnimVars(); - XtAugmentTranslations(formWidget, - XtParseTranslationTable(globalTranslations)); - XtAugmentTranslations(boardWidget, - XtParseTranslationTable(boardTranslations)); - XtAugmentTranslations(whiteTimerWidget, - XtParseTranslationTable(whiteTranslations)); - XtAugmentTranslations(blackTimerWidget, - XtParseTranslationTable(blackTranslations)); - - /* Why is the following needed on some versions of X instead - * of a translation? */ - XtAddEventHandler(boardWidget, ExposureMask, False, - (XtEventHandler) EventProc, NULL); - /* end why */ + printf("DEBUG: created stuff.\n"); + +// XtAugmentTranslations(formWidget, +// XtParseTranslationTable(globalTranslations)); +// XtAugmentTranslations(boardWidget, +// XtParseTranslationTable(boardTranslations)); +// XtAugmentTranslations(whiteTimerWidget, +// XtParseTranslationTable(whiteTranslations)); +// XtAugmentTranslations(blackTimerWidget, +// XtParseTranslationTable(blackTranslations)); +// InitBackEnd2(); + printf("DEBUG: back end initiated.\n"); + if (errorExitStatus == -1) { if (appData.icsActive) { /* We now wait until we see "login:" from the ICS before @@ -3164,7 +3129,20 @@ XBoard square size (hint): %d\n\ gameInfo.boardWidth = 0; // [HGM] pieces: kludge to ensure InitPosition() calls InitDrawingSizes() InitPosition(TRUE); - XtAppMainLoop(appContext); + /* + * Create a cursor for the board widget. + * (This needs to be called after the window has been created to have access to board-window) + */ + + BoardCursor = gdk_cursor_new(GDK_HAND2); + gdk_window_set_cursor(GUI_Board->window, BoardCursor); + gdk_cursor_destroy(BoardCursor); + + /* end cursor */ + printf("DEBUG: going into main.\n"); + + gtk_main (); + if (appData.debugMode) fclose(debugFP); // [DM] debug return 0; } @@ -3247,22 +3225,27 @@ ResetFrontEnd() typedef struct { char *name; - Boolean value; + gboolean value; } Enables; void SetMenuEnables(enab) Enables *enab; { - Widget w; - if (!menuBarWidget) return; + GObject *o; + + if (!builder) return; while (enab->name != NULL) { - w = XtNameToWidget(menuBarWidget, enab->name); - if (w == NULL) { - DisplayError(enab->name, 0); - } else { - XtSetSensitive(w, enab->value); - } + o = gtk_builder_get_object(builder, enab->name); + if(GTK_IS_WIDGET(o)) + gtk_widget_set_sensitive(GTK_WIDGET (o),enab->value); + else + { + if(GTK_IS_ACTION(o)) + gtk_action_set_sensitive(GTK_ACTION (o),enab->value); + else + DisplayError(enab->name, 0); + } enab++; } } @@ -3691,423 +3674,31 @@ void CreateGCs() } } -void loadXIM(xim, xmask, filename, dest, mask) - XImage *xim; - XImage *xmask; - char *filename; - Pixmap *dest; - Pixmap *mask; -{ - int x, y, w, h, p; - FILE *fp; - Pixmap temp; - XGCValues values; - GC maskGC; - - fp = fopen(filename, "rb"); - if (!fp) { - fprintf(stderr, _("%s: error loading XIM!\n"), programName); - exit(1); - } - - w = fgetc(fp); - h = fgetc(fp); - - for (y=0; ydepth); - XPutImage(xDisplay, *dest, lightSquareGC, xim, - 0, 0, 0, 0, w, h); - - /* create Pixmap of clipmask - Note: We assume the white/black pieces have the same - outline, so we make only 6 masks. This is okay - since the XPM clipmask routines do the same. */ - if (xmask) { - temp = XCreatePixmap(xDisplay, DefaultRootWindow(xDisplay), - w, h, xim->depth); - XPutImage(xDisplay, temp, lightSquareGC, xmask, - 0, 0, 0, 0, w, h); - - /* now create the 1-bit version */ - *mask = XCreatePixmap(xDisplay, DefaultRootWindow(xDisplay), - w, h, 1); - - values.foreground = 1; - values.background = 0; - - /* Don't use XtGetGC, not read only */ - maskGC = XCreateGC(xDisplay, *mask, - GCForeground | GCBackground, &values); - XCopyPlane(xDisplay, temp, *mask, maskGC, - 0, 0, squareSize, squareSize, 0, 0, 1); - XFreePixmap(xDisplay, temp); - } -} - - -char pieceBitmapNames[] = "pnbrqfeacwmohijgdvlsukpnsl"; - -void CreateXIMPieces() -{ - int piece, kind; - char buf[MSG_SIZ]; - u_int ss; - static char *ximkind[] = { "ll", "ld", "dl", "dd" }; - XImage *ximtemp; - - ss = squareSize; - - /* The XSynchronize calls were copied from CreatePieces. - Not sure if needed, but can't hurt */ - XSynchronize(xDisplay, True); /* Work-around for xlib/xt - buffering bug */ - - /* temp needed by loadXIM() */ - ximtemp = XGetImage(xDisplay, DefaultRootWindow(xDisplay), - 0, 0, ss, ss, AllPlanes, XYPixmap); - - if (strlen(appData.pixmapDirectory) == 0) { - useImages = 0; - } else { - useImages = 1; - if (appData.monoMode) { - DisplayFatalError(_("XIM pieces cannot be used in monochrome mode"), - 0, 2); - ExitEvent(2); - } - fprintf(stderr, _("\nLoading XIMs...\n")); - /* Load pieces */ - for (piece = (int) WhitePawn; piece <= (int) WhiteKing + 4; piece++) { - fprintf(stderr, "%d", piece+1); - for (kind=0; kind<4; kind++) { - fprintf(stderr, "."); - snprintf(buf, sizeof(buf), "%s/%s%c%s%u.xim", - ExpandPathName(appData.pixmapDirectory), - piece <= (int) WhiteKing ? "" : "w", - pieceBitmapNames[piece], - ximkind[kind], ss); - ximPieceBitmap[kind][piece] = - XGetImage(xDisplay, DefaultRootWindow(xDisplay), - 0, 0, ss, ss, AllPlanes, XYPixmap); - if (appData.debugMode) - fprintf(stderr, _("(File:%s:) "), buf); - loadXIM(ximPieceBitmap[kind][piece], - ximtemp, buf, - &(xpmPieceBitmap2[kind][piece]), - &(ximMaskPm2[piece])); - if(piece <= (int)WhiteKing) - xpmPieceBitmap[kind][piece] = xpmPieceBitmap2[kind][piece]; - } - fprintf(stderr," "); - } - /* Load light and dark squares */ - /* If the LSQ and DSQ pieces don't exist, we will - draw them with solid squares. */ - snprintf(buf,sizeof(buf), "%s/lsq%u.xim", ExpandPathName(appData.pixmapDirectory), ss); - if (access(buf, 0) != 0) { - useImageSqs = 0; - } else { - useImageSqs = 1; - fprintf(stderr, _("light square ")); - ximLightSquare= - XGetImage(xDisplay, DefaultRootWindow(xDisplay), - 0, 0, ss, ss, AllPlanes, XYPixmap); - if (appData.debugMode) - fprintf(stderr, _("(File:%s:) "), buf); - - loadXIM(ximLightSquare, NULL, buf, &xpmLightSquare, NULL); - fprintf(stderr, _("dark square ")); - snprintf(buf,sizeof(buf), "%s/dsq%u.xim", - ExpandPathName(appData.pixmapDirectory), ss); - if (appData.debugMode) - fprintf(stderr, _("(File:%s:) "), buf); - ximDarkSquare= - XGetImage(xDisplay, DefaultRootWindow(xDisplay), - 0, 0, ss, ss, AllPlanes, XYPixmap); - loadXIM(ximDarkSquare, NULL, buf, &xpmDarkSquare, NULL); - xpmJailSquare = xpmLightSquare; - } - fprintf(stderr, _("Done.\n")); - } - XSynchronize(xDisplay, False); /* Work-around for xlib/xt buffering bug */ -} - -#if HAVE_LIBXPM -void CreateXPMPieces() -{ - int piece, kind, r; - char buf[MSG_SIZ]; - u_int ss = squareSize; - XpmAttributes attr; - static char *xpmkind[] = { "ll", "ld", "dl", "dd" }; - XpmColorSymbol symbols[4]; - -#if 0 - /* Apparently some versions of Xpm don't define XpmFormat at all --tpm */ - if (appData.debugMode) { - fprintf(stderr, "XPM Library Version: %d.%d%c\n", - XpmFormat, XpmVersion, (char)('a' + XpmRevision - 1)); - } -#endif - - /* The XSynchronize calls were copied from CreatePieces. - Not sure if needed, but can't hurt */ - XSynchronize(xDisplay, True); /* Work-around for xlib/xt buffering bug */ - - /* Setup translations so piece colors match square colors */ - symbols[0].name = "light_piece"; - symbols[0].value = appData.whitePieceColor; - symbols[1].name = "dark_piece"; - symbols[1].value = appData.blackPieceColor; - symbols[2].name = "light_square"; - symbols[2].value = appData.lightSquareColor; - symbols[3].name = "dark_square"; - symbols[3].value = appData.darkSquareColor; - - attr.valuemask = XpmColorSymbols; - attr.colorsymbols = symbols; - attr.numsymbols = 4; - - if (appData.monoMode) { - DisplayFatalError(_("XPM pieces cannot be used in monochrome mode"), - 0, 2); - ExitEvent(2); - } - if (strlen(appData.pixmapDirectory) == 0) { - XpmPieces* pieces = builtInXpms; - useImages = 1; - /* Load pieces */ - while (pieces->size != squareSize && pieces->size) pieces++; - if (!pieces->size) { - fprintf(stderr, _("No builtin XPM pieces of size %d\n"), squareSize); - exit(1); - } - for (piece = (int) WhitePawn; piece <= (int) WhiteKing + 4; piece++) { - for (kind=0; kind<4; kind++) { - - if ((r=XpmCreatePixmapFromData(xDisplay, xBoardWindow, - pieces->xpm[piece][kind], - &(xpmPieceBitmap2[kind][piece]), - NULL, &attr)) != 0) { - fprintf(stderr, _("Error %d loading XPM image \"%s\"\n"), - r, buf); - exit(1); - } - if(piece <= (int) WhiteKing) - xpmPieceBitmap[kind][piece] = xpmPieceBitmap2[kind][piece]; - } - } - useImageSqs = 0; - xpmJailSquare = xpmLightSquare; - } else { - useImages = 1; - - fprintf(stderr, _("\nLoading XPMs...\n")); - - /* Load pieces */ - for (piece = (int) WhitePawn; piece <= (int) WhiteKing + 4; piece++) { - fprintf(stderr, "%d ", piece+1); - for (kind=0; kind<4; kind++) { - snprintf(buf, sizeof(buf), "%s/%s%c%s%u.xpm", - ExpandPathName(appData.pixmapDirectory), - piece > (int) WhiteKing ? "w" : "", - pieceBitmapNames[piece], - xpmkind[kind], ss); - if (appData.debugMode) { - fprintf(stderr, _("(File:%s:) "), buf); - } - if ((r=XpmReadFileToPixmap(xDisplay, xBoardWindow, buf, - &(xpmPieceBitmap2[kind][piece]), - NULL, &attr)) != 0) { - fprintf(stderr, _("Error %d loading XPM file \"%s\"\n"), - r, buf); - exit(1); - } - if(piece <= (int) WhiteKing) - xpmPieceBitmap[kind][piece] = xpmPieceBitmap2[kind][piece]; - } - } - /* Load light and dark squares */ - /* If the LSQ and DSQ pieces don't exist, we will - draw them with solid squares. */ - fprintf(stderr, _("light square ")); - snprintf(buf, sizeof(buf), "%s/lsq%u.xpm", ExpandPathName(appData.pixmapDirectory), ss); - if (access(buf, 0) != 0) { - useImageSqs = 0; - } else { - useImageSqs = 1; - if (appData.debugMode) - fprintf(stderr, _("(File:%s:) "), buf); - - if ((r=XpmReadFileToPixmap(xDisplay, xBoardWindow, buf, - &xpmLightSquare, NULL, &attr)) != 0) { - fprintf(stderr, _("Error %d loading XPM file \"%s\"\n"), r, buf); - exit(1); - } - fprintf(stderr, _("dark square ")); - snprintf(buf, sizeof(buf), "%s/dsq%u.xpm", - ExpandPathName(appData.pixmapDirectory), ss); - if (appData.debugMode) { - fprintf(stderr, _("(File:%s:) "), buf); - } - if ((r=XpmReadFileToPixmap(xDisplay, xBoardWindow, buf, - &xpmDarkSquare, NULL, &attr)) != 0) { - fprintf(stderr, _("Error %d loading XPM file \"%s\"\n"), r, buf); - exit(1); - } - } - xpmJailSquare = xpmLightSquare; - fprintf(stderr, _("Done.\n")); - } - XSynchronize(xDisplay, False); /* Work-around for xlib/xt - buffering bug */ -} -#endif /* HAVE_LIBXPM */ - -#if HAVE_LIBXPM -/* No built-in bitmaps */ void CreatePieces() { - int piece, kind; - char buf[MSG_SIZ]; - u_int ss = squareSize; - - XSynchronize(xDisplay, True); /* Work-around for xlib/xt - buffering bug */ - - for (kind = SOLID; kind <= (appData.monoMode ? OUTLINE : SOLID); kind++) { - for (piece = (int) WhitePawn; piece <= (int) WhiteKing + 4; piece++) { - sprintf(buf, "%s%c%u%c.bm", piece > (int)WhiteKing ? "w" : "", - pieceBitmapNames[piece], - ss, kind == SOLID ? 's' : 'o'); - ReadBitmap(&pieceBitmap2[kind][piece], buf, NULL, ss, ss); - if(piece <= (int)WhiteKing) - pieceBitmap[kind][piece] = pieceBitmap2[kind][piece]; - } - } + /* order of pieces + WhitePawn, WhiteKnight, WhiteBishop, WhiteRook, WhiteQueen, WhiteKing, + BlackPawn, BlackKnight, BlackBishop, BlackRook, BlackQueen, BlackKing, + */ - XSynchronize(xDisplay, False); /* Work-around for xlib/xt - buffering bug */ -} -#else -/* With built-in bitmaps */ -void CreatePieces() -{ - BuiltInBits* bib = builtInBits; - int piece, kind; - char buf[MSG_SIZ]; - u_int ss = squareSize; - - XSynchronize(xDisplay, True); /* Work-around for xlib/xt - buffering bug */ - - while (bib->squareSize != ss && bib->squareSize != 0) bib++; - - for (kind = SOLID; kind <= (appData.monoMode ? OUTLINE : SOLID); kind++) { - for (piece = (int) WhitePawn; piece <= (int) WhiteKing + 4; piece++) { - sprintf(buf, "%s%c%u%c.bm", piece > (int)WhiteKing ? "w" : "", - pieceBitmapNames[piece], - ss, kind == SOLID ? 's' : 'o'); - ReadBitmap(&pieceBitmap2[kind][piece], buf, - bib->bits[kind][piece], ss, ss); - if(piece <= (int)WhiteKing) - pieceBitmap[kind][piece] = pieceBitmap2[kind][piece]; - } - } + SVGpieces[WhitePawn] = load_pixbuf("svg/WhitePawn.svg"); + SVGpieces[WhiteKnight] = load_pixbuf("svg/WhiteKnight.svg"); + SVGpieces[WhiteBishop] = load_pixbuf("svg/WhiteBishop.svg"); + SVGpieces[WhiteRook] = load_pixbuf("svg/WhiteRook.svg"); + SVGpieces[WhiteQueen] = load_pixbuf("svg/WhiteQueen.svg"); + SVGpieces[WhiteKing] = load_pixbuf("svg/WhiteKing.svg"); - XSynchronize(xDisplay, False); /* Work-around for xlib/xt - buffering bug */ -} -#endif + SVGpieces[BlackPawn] = load_pixbuf("svg/BlackPawn.svg"); + SVGpieces[BlackKnight] = load_pixbuf("svg/BlackKnight.svg"); + SVGpieces[BlackBishop] = load_pixbuf("svg/BlackBishop.svg"); + SVGpieces[BlackRook] = load_pixbuf("svg/BlackRook.svg"); + SVGpieces[BlackQueen] = load_pixbuf("svg/BlackQueen.svg"); + SVGpieces[BlackKing] = load_pixbuf("svg/BlackKing.svg"); -void ReadBitmap(pm, name, bits, wreq, hreq) - Pixmap *pm; - String name; - unsigned char bits[]; - u_int wreq, hreq; -{ - int x_hot, y_hot; - u_int w, h; - int errcode; - char msg[MSG_SIZ], fullname[MSG_SIZ]; - - if (*appData.bitmapDirectory != NULLCHAR) { - strcpy(fullname, appData.bitmapDirectory); - strcat(fullname, "/"); - strcat(fullname, name); - errcode = XReadBitmapFile(xDisplay, xBoardWindow, fullname, - &w, &h, pm, &x_hot, &y_hot); - fprintf(stderr, "load %s\n", name); - if (errcode != BitmapSuccess) { - switch (errcode) { - case BitmapOpenFailed: - snprintf(msg, sizeof(msg), _("Can't open bitmap file %s"), fullname); - break; - case BitmapFileInvalid: - snprintf(msg, sizeof(msg), _("Invalid bitmap in file %s"), fullname); - break; - case BitmapNoMemory: - snprintf(msg, sizeof(msg), _("Ran out of memory reading bitmap file %s"), - fullname); - break; - default: - snprintf(msg, sizeof(msg), _("Unknown XReadBitmapFile error %d on file %s"), - errcode, fullname); - break; - } - fprintf(stderr, _("%s: %s...using built-in\n"), - programName, msg); - } else if (w != wreq || h != hreq) { - fprintf(stderr, - _("%s: Bitmap %s is %dx%d, not %dx%d...using built-in\n"), - programName, fullname, w, h, wreq, hreq); - } else { - return; - } - } - if (bits == NULL) { -#if 0 - fprintf(stderr, _("%s: No built-in bitmap for %s; giving up\n"), - programName, name); - exit(1); -#endif - ; // [HGM] bitmaps: make it non-fatal if we have no bitmap; - } else { - *pm = XCreateBitmapFromData(xDisplay, xBoardWindow, (char *) bits, - wreq, hreq); - } + return; } + void CreateGrid() { int i, j; @@ -4292,32 +3883,32 @@ CreatePieceMenus() Arg args[16]; ChessSquare selection; - whitePieceMenu = CreatePieceMenu("menuW", 0); - blackPieceMenu = CreatePieceMenu("menuB", 1); - - XtRegisterGrabAction(PieceMenuPopup, True, - (unsigned)(ButtonPressMask|ButtonReleaseMask), - GrabModeAsync, GrabModeAsync); - - XtSetArg(args[0], XtNlabel, _("Drop")); - dropMenu = XtCreatePopupShell("menuD", simpleMenuWidgetClass, - boardWidget, args, 1); - for (i = 0; i < DROP_MENU_SIZE; i++) { - String item = dropMenuStrings[i]; - - if (strcmp(item, "----") == 0) { - entry = XtCreateManagedWidget(item, smeLineObjectClass, - dropMenu, NULL, 0); - } else { - XtSetArg(args[0], XtNlabel, XtNewString(_(item))); - entry = XtCreateManagedWidget(item, smeBSBObjectClass, - dropMenu, args, 1); - selection = dropMenuTranslation[i]; - XtAddCallback(entry, XtNcallback, - (XtCallbackProc) DropMenuSelect, - (caddr_t) selection); - } - } +// whitePieceMenu = CreatePieceMenu("menuW", 0); +// blackPieceMenu = CreatePieceMenu("menuB", 1); +// +// XtRegisterGrabAction(PieceMenuPopup, True, +// (unsigned)(ButtonPressMask|ButtonReleaseMask), +// GrabModeAsync, GrabModeAsync); +// +// XtSetArg(args[0], XtNlabel, _("Drop")); +// dropMenu = XtCreatePopupShell("menuD", simpleMenuWidgetClass, +// boardWidget, args, 1); +// for (i = 0; i < DROP_MENU_SIZE; i++) { +// String item = dropMenuStrings[i]; +// +// if (strcmp(item, "----") == 0) { +// entry = XtCreateManagedWidget(item, smeLineObjectClass, +// dropMenu, NULL, 0); +// } else { +// XtSetArg(args[0], XtNlabel, XtNewString(_(item))); +// entry = XtCreateManagedWidget(item, smeBSBObjectClass, +// dropMenu, args, 1); +// selection = dropMenuTranslation[i]; +// XtAddCallback(entry, XtNcallback, +// (XtCallbackProc) DropMenuSelect, +// (caddr_t) selection); +// } +// } } void SetupDropMenu() @@ -4553,36 +4144,52 @@ static void BlankSquare(x, y, color, piece, dest) Drawable dest; { if (useImages && useImageSqs) { - Pixmap pm; - switch (color) { - case 1: /* light */ - pm = xpmLightSquare; - break; - case 0: /* dark */ - pm = xpmDarkSquare; - break; - case 2: /* neutral */ - default: - pm = xpmJailSquare; - break; - } - XCopyArea(xDisplay, pm, dest, wlPieceGC, 0, 0, - squareSize, squareSize, x, y); + GdkPixbuf *pb; + switch (color) { + case 1: /* light */ + pb = SVGLightSquare; + break; + case 0: /* dark */ + pb = SVGDarkSquare; + break; + case 2: /* neutral */ + default: + pb = SVGNeutralSquare; + break; + } + gdk_draw_pixbuf(GDK_WINDOW(GUI_Board->window),NULL,pb,0,0,x,y,-1,-1, GDK_RGB_DITHER_NORMAL, 0, 0); } else { - GC gc; - switch (color) { - case 1: /* light */ - gc = lightSquareGC; - break; - case 0: /* dark */ - gc = darkSquareGC; - break; - case 2: /* neutral */ - default: - gc = jailSquareGC; - break; - } - XFillRectangle(xDisplay, dest, gc, x, y, squareSize, squareSize); + GdkGC *gc; + GdkColor tmp; + + gc = gdk_gc_new(GDK_WINDOW(GUI_Board->window)); + + switch (color) { + case 1: /* light */ + // gc = lightSquareGC; + tmp.green=60000; + tmp.red=63330; + tmp.blue=60000; + gdk_gc_set_rgb_fg_color(gc, &tmp); + break; + case 0: /* dark */ + // gc = darkSquareGC; + tmp.green=10000; + tmp.red=13330; + tmp.blue=1234; + gdk_gc_set_rgb_fg_color(gc, &tmp); + break; + case 2: /* neutral */ + default: + // gc = jailSquareGC; + tmp.green=30000; + tmp.red=33330; + tmp.blue=30234; + gdk_gc_set_rgb_fg_color(gc, &tmp); + break; + } + gdk_draw_rectangle(GDK_WINDOW(GUI_Board->window),gc,1,x,y,squareSize,squareSize); + } } @@ -4858,33 +4465,6 @@ void DrawSquare(row, column, piece, do_flash) } -/* Why is this needed on some versions of X? */ -void EventProc(widget, unused, event) - Widget widget; - caddr_t unused; - XEvent *event; -{ - if (!XtIsRealized(widget)) - return; - - switch (event->type) { - case Expose: - if (event->xexpose.count > 0) return; /* no clipping is done */ - XDrawPosition(widget, True, NULL); - break; - default: - return; - } -} -/* end why */ - -void DrawPosition(fullRedraw, board) - /*Boolean*/int fullRedraw; - Board board; -{ - XDrawPosition(boardWidget, fullRedraw, board); -} - /* Returns 1 if there are "too many" differences between b1 and b2 (i.e. more than 1 move was made) */ static int too_many_diffs(b1, b2) @@ -4957,8 +4537,7 @@ static int damage[BOARD_SIZE][BOARD_SIZE]; /* * event handler for redrawing the board */ -void XDrawPosition(w, repaint, board) - Widget w; +void DrawPosition( repaint, board) /*Boolean*/int repaint; Board board; { @@ -4969,6 +4548,9 @@ void XDrawPosition(w, repaint, board) Arg args[16]; int rrow, rcol; + printf ("DEBUG: in draw position\n"); + + if (board == NULL) { if (!lastBoardValid) return; board = lastBoard; @@ -4984,8 +4566,12 @@ void XDrawPosition(w, repaint, board) * but this causes a very distracting flicker. */ + printf ("DEBUG: in draw position 0.1\n"); + + if (!repaint && lastBoardValid && lastFlipView == flipView) { + printf ("DEBUG: in draw position 0.1a\n"); /* If too much changes (begin observing new game, etc.), don't do flashing */ do_flash = too_many_diffs(board, lastBoard) ? 0 : 1; @@ -5019,8 +4605,26 @@ void XDrawPosition(w, repaint, board) } } else { if (lineGap > 0) - XDrawSegments(xDisplay, xBoardWindow, lineGC, - gridSegments, BOARD_HEIGHT + BOARD_WIDTH + 2); + { + /* todo move GC to setupgc */ + GdkGC *gtklineGC=NULL; + GdkColor tmp; + + gtklineGC = gdk_gc_new(GDK_WINDOW(GUI_Board->window)); + + tmp.green=60000; + tmp.red=0; + tmp.blue=1234; + gdk_gc_set_rgb_fg_color(gtklineGC, &tmp); + + tmp.green=60000; + tmp.red=60000; + tmp.blue=61234; + gdk_gc_set_rgb_bg_color(gtklineGC, &tmp); + + gdk_draw_segments(GUI_Board->window,gtklineGC, + gridSegments, BOARD_HEIGHT + BOARD_WIDTH + 2 ); + } for (i = 0; i < BOARD_HEIGHT; i++) for (j = 0; j < BOARD_WIDTH; j++) { @@ -5050,7 +4654,7 @@ void XDrawPosition(w, repaint, board) /* If piece being dragged around board, must redraw that too */ DrawDragPiece(); - XSync(xDisplay, False); + // XSync(xDisplay, False); } @@ -5063,7 +4667,7 @@ void DrawPositionProc(w, event, prms, nprms) String *prms; Cardinal *nprms; { - XDrawPosition(w, True, NULL); + DrawPosition(True, NULL); } @@ -6038,68 +5642,30 @@ void ErrorPopUp(title, label, modal) char *title, *label; int modal; { - Arg args[16]; - Widget dialog, layout; - Position x, y; - int xx, yy; - Window junk; - Dimension bw_width, pw_width; - Dimension pw_height; - int i; - - i = 0; - XtSetArg(args[i], XtNresizable, True); i++; - XtSetArg(args[i], XtNtitle, title); i++; - errorShell = - XtCreatePopupShell("errorpopup", transientShellWidgetClass, - shellWidget, args, i); - layout = - XtCreateManagedWidget(layoutName, formWidgetClass, errorShell, - layoutArgs, XtNumber(layoutArgs)); - - i = 0; - XtSetArg(args[i], XtNlabel, label); i++; - XtSetArg(args[i], XtNborderWidth, 0); i++; - dialog = XtCreateManagedWidget("dialog", dialogWidgetClass, - layout, args, i); - - XawDialogAddButton(dialog, _("ok"), ErrorCallback, (XtPointer) dialog); - - XtRealizeWidget(errorShell); - CatchDeleteWindow(errorShell, "ErrorPopDown"); - - i = 0; - XtSetArg(args[i], XtNwidth, &bw_width); i++; - XtGetValues(boardWidget, args, i); - i = 0; - XtSetArg(args[i], XtNwidth, &pw_width); i++; - XtSetArg(args[i], XtNheight, &pw_height); i++; - XtGetValues(errorShell, args, i); - -#ifdef NOTDEF - /* This code seems to tickle an X bug if it is executed too soon - after xboard starts up. The coordinates get transformed as if - the main window was positioned at (0, 0). - */ - XtTranslateCoords(boardWidget, (bw_width - pw_width) / 2, - 0 - pw_height + squareSize / 3, &x, &y); -#else - XTranslateCoordinates(xDisplay, XtWindow(boardWidget), - RootWindowOfScreen(XtScreen(boardWidget)), - (bw_width - pw_width) / 2, - 0 - pw_height + squareSize / 3, &xx, &yy, &junk); - x = xx; - y = yy; -#endif - if (y < 0) y = 0; /*avoid positioning top offscreen*/ - - i = 0; - XtSetArg(args[i], XtNx, x); i++; - XtSetArg(args[i], XtNy, y); i++; - XtSetValues(errorShell, args, i); - - errorUp = True; - XtPopup(errorShell, modal ? XtGrabExclusive : XtGrabNone); + GtkWidget *dialog; + + printf ("DEBUG: error %s %s\n\n",title,label); + + dialog = gtk_message_dialog_new(GTK_WINDOW(GUI_Window), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_CLOSE, + (gchar *)label); + + gtk_window_set_title(GTK_WINDOW(dialog),(gchar *) title); + if(modal) + { + gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_destroy(GTK_WIDGET(dialog)); + } + else + { + g_signal_connect_swapped (dialog, "response", + G_CALLBACK (ErrorPopDownProc), + dialog); + errorUp = True; + gtk_widget_show(GTK_WIDGET(dialog)); + } } /* Disable all user input other than deleting the window */ @@ -6108,7 +5674,7 @@ void FreezeUI() { if (frozen) return; /* Grab by a widget that doesn't accept input */ - XtAddGrab(messageWidget, TRUE, FALSE); + // XtAddGrab(messageWidget, TRUE, FALSE); frozen = 1; } @@ -6229,15 +5795,6 @@ void ModeHighlight() /* * Button/menu procedures */ -void ResetProc(w, event, prms, nprms) - Widget w; - XEvent *event; - String *prms; - Cardinal *nprms; -{ - ResetGameEvent(); - AnalysisPopDown(); -} int LoadGamePopUp(f, gameNumber, title) FILE *f; @@ -6260,44 +5817,6 @@ int LoadGamePopUp(f, gameNumber, title) return LoadGame(f, gameNumber, title, FALSE); } -void LoadGameProc(w, event, prms, nprms) - Widget w; - XEvent *event; - String *prms; - Cardinal *nprms; -{ - if (gameMode == AnalyzeMode || gameMode == AnalyzeFile) { - Reset(FALSE, TRUE); - } - FileNamePopUp(_("Load game file name?"), "", LoadGamePopUp, "rb"); -} - -void LoadNextGameProc(w, event, prms, nprms) - Widget w; - XEvent *event; - String *prms; - Cardinal *nprms; -{ - ReloadGame(1); -} - -void LoadPrevGameProc(w, event, prms, nprms) - Widget w; - XEvent *event; - String *prms; - Cardinal *nprms; -{ - ReloadGame(-1); -} - -void ReloadGameProc(w, event, prms, nprms) - Widget w; - XEvent *event; - String *prms; - Cardinal *nprms; -{ - ReloadGame(0); -} void LoadNextPositionProc(w, event, prms, nprms) Widget w; @@ -6562,26 +6081,6 @@ void AutoSaveGame() SaveGameProc(NULL, NULL, NULL, NULL); } - -void QuitProc(w, event, prms, nprms) - Widget w; - XEvent *event; - String *prms; - Cardinal *nprms; -{ - ExitEvent(0); -} - -void PauseProc(w, event, prms, nprms) - Widget w; - XEvent *event; - String *prms; - Cardinal *nprms; -{ - PauseEvent(); -} - - void MachineBlackProc(w, event, prms, nprms) Widget w; XEvent *event; @@ -7417,27 +6916,6 @@ void QuietPlayProc(w, event, prms, nprms) args, 1); } -void ShowCoordsProc(w, event, prms, nprms) - Widget w; - XEvent *event; - String *prms; - Cardinal *nprms; -{ - Arg args[16]; - - appData.showCoords = !appData.showCoords; - - if (appData.showCoords) { - XtSetArg(args[0], XtNleftBitmap, xMarkPixmap); - } else { - XtSetArg(args[0], XtNleftBitmap, None); - } - XtSetValues(XtNameToWidget(menuBarWidget, "menuOptions.Show Coords"), - args, 1); - - DrawPosition(True, NULL); -} - void ShowThinkingProc(w, event, prms, nprms) Widget w; XEvent *event; @@ -7526,28 +7004,6 @@ void BookProc(w, event, prms, nprms) BookEvent(); } -void AboutProc(w, event, prms, nprms) - Widget w; - XEvent *event; - String *prms; - Cardinal *nprms; -{ - char buf[MSG_SIZ]; -#if ZIPPY - char *zippy = " (with Zippy code)"; -#else - char *zippy = ""; -#endif - snprintf(buf, sizeof(buf), "%s%s\n\n%s\n%s\n%s\n\n%s%s\n%s", - programVersion, zippy, - "Copyright 1991 Digital Equipment Corporation", - "Enhancements Copyright 1992-2009 Free Software Foundation", - "Enhancements Copyright 2005 Alessandro Scotti", - PACKAGE, " is free software and carries NO WARRANTY;", - "see the file COPYING for more information."); - ErrorPopUp(_("About XBoard"), buf, FALSE); -} - void DebugProc(w, event, prms, nprms) Widget w; XEvent *event; @@ -7589,7 +7045,7 @@ void Iconify(w, event, prms, nprms) } void DisplayMessage(message, extMessage) - char *message, *extMessage; + gchar *message, *extMessage; { char buf[MSG_SIZ]; Arg arg; @@ -7602,8 +7058,9 @@ void DisplayMessage(message, extMessage) message = extMessage; } } - XtSetArg(arg, XtNlabel, message); - XtSetValues(messageWidget, &arg, 1); + + printf("TODO: message %s\n",message); + gtk_label_set_text( GTK_LABEL(gtk_builder_get_object (builder, "Messages")),message); } void DisplayTitle(text) @@ -8218,40 +7675,48 @@ StartClockTimer(millisec) void DisplayTimerLabel(w, color, timer, highlight) - Widget w; + GtkWidget *w; char *color; long timer; int highlight; { - char buf[MSG_SIZ]; - Arg args[16]; - - /* check for low time warning */ - Pixel foregroundOrWarningColor = timerForegroundPixel; - - if (timer > 0 && - appData.lowTimeWarning && - (timer / 1000) < appData.icsAlarmTime) - foregroundOrWarningColor = lowTimeWarningColor; - - if (appData.clockMode) { - sprintf(buf, "%s: %s", color, TimeString(timer)); - XtSetArg(args[0], XtNlabel, buf); - } else { - sprintf(buf, "%s ", color); - XtSetArg(args[0], XtNlabel, buf); - } - - if (highlight) { - - XtSetArg(args[1], XtNbackground, foregroundOrWarningColor); - XtSetArg(args[2], XtNforeground, timerBackgroundPixel); - } else { - XtSetArg(args[1], XtNbackground, timerBackgroundPixel); - XtSetArg(args[2], XtNforeground, foregroundOrWarningColor); - } - - XtSetValues(w, args, 3); + gchar buf[MSG_SIZ]; + + + if (appData.clockMode) { + sprintf(buf, "%s: %s", color, TimeString(timer)); + } else { + sprintf(buf, "%s ", color); + } + gtk_label_set_text(GTK_LABEL(w),buf); + + /* check for low time warning */ +// Pixel foregroundOrWarningColor = timerForegroundPixel; + +// if (timer > 0 && +// appData.lowTimeWarning && +// (timer / 1000) < appData.icsAlarmTime) +// foregroundOrWarningColor = lowTimeWarningColor; +// +// if (appData.clockMode) { +// sprintf(buf, "%s: %s", color, TimeString(timer)); +// XtSetArg(args[0], XtNlabel, buf); +// } else { +// sprintf(buf, "%s ", color); +// XtSetArg(args[0], XtNlabel, buf); +// } +// +// if (highlight) { +// +// XtSetArg(args[1], XtNbackground, foregroundOrWarningColor); +// XtSetArg(args[2], XtNforeground, timerBackgroundPixel); +// } else { +// XtSetArg(args[1], XtNbackground, timerBackgroundPixel); +// XtSetArg(args[2], XtNforeground, foregroundOrWarningColor); +// } +// +// XtSetValues(w, args, 3); +// } void @@ -8259,15 +7724,13 @@ DisplayWhiteClock(timeRemaining, highlight) long timeRemaining; int highlight; { - Arg args[16]; + if(appData.noGUI) return; - if(appData.noGUI) return; - DisplayTimerLabel(whiteTimerWidget, _("White"), timeRemaining, highlight); - if (highlight && iconPixmap == bIconPixmap) { - iconPixmap = wIconPixmap; - XtSetArg(args[0], XtNiconPixmap, iconPixmap); - XtSetValues(shellWidget, args, 1); - } + DisplayTimerLabel(GUI_Whiteclock, _("White"), timeRemaining, highlight); + if (highlight && WindowIcon == BlackIcon) { + WindowIcon = WhiteIcon; + gtk_window_set_icon(GTK_WINDOW(GUI_Window),WindowIcon); + } } void @@ -8275,14 +7738,11 @@ DisplayBlackClock(timeRemaining, highlight) long timeRemaining; int highlight; { - Arg args[16]; - if(appData.noGUI) return; - DisplayTimerLabel(blackTimerWidget, _("Black"), timeRemaining, highlight); - if (highlight && iconPixmap == wIconPixmap) { - iconPixmap = bIconPixmap; - XtSetArg(args[0], XtNiconPixmap, iconPixmap); - XtSetValues(shellWidget, args, 1); + DisplayTimerLabel(GUI_Blackclock, _("Black"), timeRemaining, highlight); + if (highlight && WindowIcon == WhiteIcon) { + WindowIcon = BlackIcon; + gtk_window_set_icon(GTK_WINDOW(GUI_Window),WindowIcon); } } @@ -8831,7 +8291,7 @@ CreateAnimVars () if (xpmDone && gameInfo.variant == old) return; if(xpmDone) old = gameInfo.variant; // first time pieces might not be created yet - XGetWindowAttributes(xDisplay, xBoardWindow, &info); + // XGetWindowAttributes(xDisplay, xBoardWindow, &info); InitAnimState(&game, &info); InitAnimState(&player, &info); @@ -9305,7 +8765,7 @@ AnimateMove(board, fromX, fromY, toX, toY) damage[toY][toX] = True; } -static void +void DragPieceBegin(x, y) int x; int y; { @@ -9384,7 +8844,7 @@ DragPieceMove(x, y) #endif } -static void +void DragPieceEnd(x, y) int x; int y; { -- 1.7.0.4