void
GetActualPlacement (Widget wg, WindowPlacement *wp)
{
- Arg args[16];
- Dimension w, h;
- Position x, y;
XWindowAttributes winAt;
Window win, dummy;
- int i, rx, ry;
+ int rx, ry;
if(!wg) return;
- win = XtWindow(wg);
- XGetWindowAttributes(xDisplay, win, &winAt); // this works, where XtGetValues on XtNx, XtNy does not!
- XTranslateCoordinates (xDisplay, win, winAt.root, -winAt.border_width, -winAt.border_width, &rx, &ry, &dummy);
- wp->x = rx - winAt.x;
- wp->y = ry - winAt.y;
- wp->height = winAt.height;
- wp->width = winAt.width;
- frameX = winAt.x; frameY = winAt.y; // remember to decide if windows touch
+ win = XtWindow(wg);
+ XGetWindowAttributes(xDisplay, win, &winAt); // this works, where XtGetValues on XtNx, XtNy does not!
+ XTranslateCoordinates (xDisplay, win, winAt.root, -winAt.border_width, -winAt.border_width, &rx, &ry, &dummy);
+ wp->x = rx - winAt.x;
+ wp->y = ry - winAt.y;
+ wp->height = winAt.height;
+ wp->width = winAt.width;
+ frameX = winAt.x; frameY = winAt.y; // remember to decide if windows touch
}
void
void
InitDrawingSizes (BoardSize boardSize, int flags)
{ // [HGM] resize is functional now, but for board format changes only (nr of ranks, files)
- Dimension timerWidth, boardWidth, boardHeight, w, h, sep, bor, wr, hr;
- Arg args[16];
- XtGeometryResult gres;
+ Dimension boardWidth, boardHeight, w, h;
int i;
static Dimension oldWidth, oldHeight;
static VariantClass oldVariant;
- static int oldMono = -1;
+ static int oldMono = -1, oldTwoBoards = 0;
if(!formWidget) return;
+ if(oldTwoBoards && !twoBoards) PopDown(DummyDlg);
+ oldTwoBoards = twoBoards;
+
if(appData.overrideLineGap >= 0) lineGap = appData.overrideLineGap;
boardWidth = lineGap + BOARD_WIDTH * (squareSize + lineGap);
boardHeight = lineGap + BOARD_HEIGHT * (squareSize + lineGap);
forceMono |= MakeOneColor(appData.blackPieceColor, &blackPieceColor);
forceMono |= MakeOneColor(appData.highlightSquareColor, &highlightSquareColor);
forceMono |= MakeOneColor(appData.premoveHighlightColor, &premoveHighlightColor);
+ if (appData.lowTimeWarning)
+ forceMono |= MakeOneColor(appData.lowTimeWarningColor, &lowTimeWarningColor);
if(appData.dialogColor[0]) MakeOneColor(appData.dialogColor, &dialogColor);
if(appData.buttonColor[0]) MakeOneColor(appData.buttonColor, &buttonColor);
CreateAnyPieces();
}
+void
+InitializeFonts (int clockFontPxlSize, int coordFontPxlSize, int fontPxlSize)
+{ // detervtomine what fonts to use, and create them
+ XrmValue vTo;
+ XrmDatabase xdb;
+
+ if(!fontIsSet[CLOCK_FONT] && fontValid[CLOCK_FONT][squareSize])
+ appData.clockFont = fontTable[CLOCK_FONT][squareSize];
+ if(!fontIsSet[MESSAGE_FONT] && fontValid[MESSAGE_FONT][squareSize])
+ appData.font = fontTable[MESSAGE_FONT][squareSize];
+ if(!fontIsSet[COORD_FONT] && fontValid[COORD_FONT][squareSize])
+ appData.coordFont = fontTable[COORD_FONT][squareSize];
+
+#if ENABLE_NLS
+ appData.font = InsertPxlSize(appData.font, fontPxlSize);
+ appData.clockFont = InsertPxlSize(appData.clockFont, clockFontPxlSize);
+ appData.coordFont = InsertPxlSize(appData.coordFont, coordFontPxlSize);
+ fontSet = CreateFontSet(appData.font);
+ clockFontSet = CreateFontSet(appData.clockFont);
+ {
+ /* For the coordFont, use the 0th font of the fontset. */
+ XFontSet coordFontSet = CreateFontSet(appData.coordFont);
+ XFontStruct **font_struct_list;
+ XFontSetExtents *fontSize;
+ char **font_name_list;
+ XFontsOfFontSet(coordFontSet, &font_struct_list, &font_name_list);
+ coordFontID = XLoadFont(xDisplay, font_name_list[0]);
+ coordFontStruct = XQueryFont(xDisplay, coordFontID);
+ fontSize = XExtentsOfFontSet(fontSet); // [HGM] figure out how much vertical space font takes
+ textHeight = fontSize->max_logical_extent.height + 5; // add borderWidth
+ }
+#else
+ appData.font = FindFont(appData.font, fontPxlSize);
+ appData.clockFont = FindFont(appData.clockFont, clockFontPxlSize);
+ appData.coordFont = FindFont(appData.coordFont, coordFontPxlSize);
+ clockFontID = XLoadFont(xDisplay, appData.clockFont);
+ clockFontStruct = XQueryFont(xDisplay, clockFontID);
+ coordFontID = XLoadFont(xDisplay, appData.coordFont);
+ coordFontStruct = XQueryFont(xDisplay, coordFontID);
+ // textHeight in !NLS mode!
+#endif
+ countFontID = coordFontID; // [HGM] holdings
+ countFontStruct = coordFontStruct;
+
+ xdb = XtDatabase(xDisplay);
+#if ENABLE_NLS
+ XrmPutLineResource(&xdb, "*international: True");
+ vTo.size = sizeof(XFontSet);
+ vTo.addr = (XtPointer) &fontSet;
+ XrmPutResource(&xdb, "*fontSet", XtRFontSet, &vTo);
+#else
+ XrmPutStringResource(&xdb, "*font", appData.font);
+#endif
+}
+
int
main (int argc, char **argv)
{
- int i, j, clockFontPxlSize, coordFontPxlSize, fontPxlSize;
+ int i, clockFontPxlSize, coordFontPxlSize, fontPxlSize;
XSetWindowAttributes window_attributes;
Arg args[16];
- Dimension timerWidth, boardWidth, boardHeight, w, h, sep, bor, wr, hr;
- XrmValue vFrom, vTo;
- XtGeometryResult gres;
+ Dimension boardWidth, boardHeight, w, h;
char *p;
- XrmDatabase xdb;
int forceMono = False;
srandom(time(0)); // [HGM] book: make random truly random
#ifdef ENABLE_NLS
XtSetLanguageProc(NULL, NULL, NULL);
+ if (appData.debugMode) {
+ fprintf(debugFP, "locale = %s\n", setlocale(LC_ALL, NULL));
+ }
+
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
#endif
- shellWidget =
- XtAppInitialize(&appContext, "XBoard", shellOptions,
- XtNumber(shellOptions),
- &argc, argv, xboardResources, NULL, 0);
appData.boardSize = "";
InitAppData(ConvertToLine(argc, argv));
p = getenv("HOME");
snprintf(gameCopyFilename,i, "%s/.xboard%05uc.pgn", p, getpid());
snprintf(gamePasteFilename,i, "%s/.xboard%05up.pgn", p, getpid());
- XtGetApplicationResources(shellWidget, (XtPointer) &appData,
- clientResources, XtNumber(clientResources),
- NULL, 0);
-
{ // [HGM] initstring: kludge to fix bad bug. expand '\n' characters in init string and computer string.
static char buf[MSG_SIZ];
EscapeExpand(buf, appData.firstInitString);
setbuf(debugFP, NULL);
}
-#if ENABLE_NLS
- if (appData.debugMode) {
- fprintf(debugFP, "locale = %s\n", setlocale(LC_ALL, NULL));
- }
-#endif
-
/* [HGM,HR] make sure board size is acceptable */
if(appData.NrFiles > BOARD_FILES ||
appData.NrRanks > BOARD_RANKS )
#endif
InitBackEnd1();
+ gameInfo.variant = StringToVariant(appData.variant);
+ InitPosition(FALSE);
+
+ shellWidget =
+ XtAppInitialize(&appContext, "XBoard", shellOptions,
+ XtNumber(shellOptions),
+ &argc, argv, xboardResources, NULL, 0);
+
+ XtGetApplicationResources(shellWidget, (XtPointer) &appData,
+ clientResources, XtNumber(clientResources),
+ NULL, 0);
+
xDisplay = XtDisplay(shellWidget);
xScreen = DefaultScreen(xDisplay);
wm_delete_window = XInternAtom(xDisplay, "WM_DELETE_WINDOW", True);
- gameInfo.variant = StringToVariant(appData.variant);
- InitPosition(FALSE);
-
+ /*
+ * determine size, based on supplied or remembered -size, or screen size
+ */
if (isdigit(appData.boardSize[0])) {
i = sscanf(appData.boardSize, "%d,%d,%d,%d,%d,%d,%d", &squareSize,
&lineGap, &clockFontPxlSize, &coordFontPxlSize,
tinyLayout = szd->tinyLayout;
// [HGM] font: use defaults from settings file if available and not overruled
}
- if(!fontIsSet[CLOCK_FONT] && fontValid[CLOCK_FONT][squareSize])
- appData.clockFont = fontTable[CLOCK_FONT][squareSize];
- if(!fontIsSet[MESSAGE_FONT] && fontValid[MESSAGE_FONT][squareSize])
- appData.font = fontTable[MESSAGE_FONT][squareSize];
- if(!fontIsSet[COORD_FONT] && fontValid[COORD_FONT][squareSize])
- appData.coordFont = fontTable[COORD_FONT][squareSize];
/* Now, using squareSize as a hint, find a good XPM/XIM set size */
if (strlen(appData.pixmapDirectory) > 0) {
/*
* Determine what fonts to use.
*/
-#if ENABLE_NLS
- appData.font = InsertPxlSize(appData.font, fontPxlSize);
- appData.clockFont = InsertPxlSize(appData.clockFont, clockFontPxlSize);
- appData.coordFont = InsertPxlSize(appData.coordFont, coordFontPxlSize);
- fontSet = CreateFontSet(appData.font);
- clockFontSet = CreateFontSet(appData.clockFont);
- {
- /* For the coordFont, use the 0th font of the fontset. */
- XFontSet coordFontSet = CreateFontSet(appData.coordFont);
- XFontStruct **font_struct_list;
- XFontSetExtents *fontSize;
- char **font_name_list;
- XFontsOfFontSet(coordFontSet, &font_struct_list, &font_name_list);
- coordFontID = XLoadFont(xDisplay, font_name_list[0]);
- coordFontStruct = XQueryFont(xDisplay, coordFontID);
- fontSize = XExtentsOfFontSet(fontSet); // [HGM] figure out how much vertical space font takes
- textHeight = fontSize->max_logical_extent.height + 5; // add borderWidth
- }
-#else
- appData.font = FindFont(appData.font, fontPxlSize);
- appData.clockFont = FindFont(appData.clockFont, clockFontPxlSize);
- appData.coordFont = FindFont(appData.coordFont, coordFontPxlSize);
- clockFontID = XLoadFont(xDisplay, appData.clockFont);
- clockFontStruct = XQueryFont(xDisplay, clockFontID);
- coordFontID = XLoadFont(xDisplay, appData.coordFont);
- coordFontStruct = XQueryFont(xDisplay, coordFontID);
- // textHeight in !NLS mode!
-#endif
- countFontID = coordFontID; // [HGM] holdings
- countFontStruct = coordFontStruct;
-
- xdb = XtDatabase(xDisplay);
-#if ENABLE_NLS
- XrmPutLineResource(&xdb, "*international: True");
- vTo.size = sizeof(XFontSet);
- vTo.addr = (XtPointer) &fontSet;
- XrmPutResource(&xdb, "*fontSet", XtRFontSet, &vTo);
-#else
- XrmPutStringResource(&xdb, "*font", appData.font);
-#endif
+ InitializeFonts(clockFontPxlSize, coordFontPxlSize, fontPxlSize);
/*
* Detect if there are not enough colors available and adapt.
appData.monoMode = True;
}
- if (appData.lowTimeWarning && !appData.monoMode) {
- vFrom.addr = (caddr_t) appData.lowTimeWarningColor;
- vFrom.size = strlen(appData.lowTimeWarningColor);
- XtConvert(shellWidget, XtRString, &vFrom, XtRPixel, &vTo);
- if (vTo.addr == NULL)
- appData.monoMode = True;
- else
- lowTimeWarningColor = *(Pixel *) vTo.addr;
- }
-
if (appData.monoMode && appData.debugMode) {
fprintf(stderr, _("white pixel = 0x%lx, black pixel = 0x%lx\n"),
(unsigned long) XWhitePixel(xDisplay, xScreen),
#else
&clockFonStruct);
#endif
- boardWidget = optList[22].handle;
- menuBarWidget = optList[ 0].handle;
- dropMenu = optList[25].handle;
- titleWidget = optList[optList[10].type != -1 ? 10 : 13].handle;
+ boardWidget = optList[W_BOARD].handle;
+ menuBarWidget = optList[W_MENU].handle;
+ dropMenu = optList[W_DROP].handle;
+ titleWidget = optList[optList[W_TITLE].type != -1 ? W_TITLE : W_SMALL].handle;
formWidget = XtParent(boardWidget);
XtSetArg(args[0], XtNbackground, &timerBackgroundPixel);
XtSetArg(args[1], XtNforeground, &timerForegroundPixel);
- XtGetValues(optList[11].handle, args, 2);
+ XtGetValues(optList[W_WHITE].handle, args, 2);
if (appData.showButtonBar) { // can't we use timer pixels for this? (Or better yet, just black & white?)
XtSetArg(args[0], XtNbackground, &buttonBackgroundPixel);
XtSetArg(args[1], XtNforeground, &buttonForegroundPixel);
- XtGetValues(optList[18].handle, args, 2);
+ XtGetValues(optList[W_PAUSE].handle, args, 2);
}
AppendEnginesToMenu(appData.recentEngineList);
static void
CreateGCs (int redo)
{
- XtGCMask value_mask = GCLineWidth | GCLineStyle | GCForeground
- | GCBackground | GCFunction | GCPlaneMask;
XGCValues gc_values;
GC copyInvertedGC;
Pixel white = XWhitePixel(xDisplay, xScreen);
void
EnableButtonBar (int state)
{
- XtSetSensitive(optList[15].handle, state);
+ XtSetSensitive(optList[W_BUTTON].handle, state);
}
void
KeyBindingProc (Widget w, XEvent *event, String *prms, Cardinal *nprms)
{ // [HGM] new method of key binding: specify MenuItem(FlipView) in stead of FlipViewProc in translation string
- int i;
- char *p;
MenuItem *item;
if(*nprms == 0) return;
item = MenuNameToItem(prms[0]);
void
AppendMenuItem (char *msg, int n)
{
- CreateMenuItem((Widget) optList[6].textValue, msg, (XtCallbackProc) MenuEngineSelect, n);
+ CreateMenuItem((Widget) optList[W_ENGIN].textValue, msg, (XtCallbackProc) MenuEngineSelect, n);
}
void
fileProc = proc; /* I can't see a way not */
fileOpenMode = openMode; /* to use globals here */
{ // [HGM] use file-selector dialog stolen from Ghostview
- int index; // this is not supported yet
+ // int index; // this is not supported yet
Browse(BoardWindow, label, (def[0] ? def : NULL), filter, False, openMode, &openName, &openFP);
}
}
{
if (frozen) return;
/* Grab by a widget that doesn't accept input */
- XtAddGrab(optList[14].handle, TRUE, FALSE);
+ XtAddGrab(optList[W_MESSG].handle, TRUE, FALSE);
frozen = 1;
}
ThawUI ()
{
if (!frozen) return;
- XtRemoveGrab(optList[14].handle);
+ XtRemoveGrab(optList[W_MESSG].handle);
frozen = 0;
}
Pixel oldbg, oldfg;
XtSetArg(args[0], XtNbackground, &oldbg);
XtSetArg(args[1], XtNforeground, &oldfg);
- XtGetValues(optList[18].handle,
+ XtGetValues(optList[W_PAUSE].handle,
args, 2);
XtSetArg(args[0], XtNbackground, oldfg);
XtSetArg(args[1], XtNforeground, oldbg);
}
- XtSetValues(optList[18].handle, args, 2);
+ XtSetValues(optList[W_PAUSE].handle, args, 2);
}
}