From a61f78756889e18aa279dc273bd99b9af60468d7 Mon Sep 17 00:00:00 2001 From: H.G. Muller Date: Thu, 12 Apr 2012 09:30:24 +0200 Subject: [PATCH] Add logo widgets in main board window New options -logoSize and -logoDir are added. The former enables logo display, when non-zero and not too big. The latter is used by -autoLogo. The options -firstLogo and -secondLogo also work. Problem is that the clock height is larger than the logo height, and for now a nasty trick in GenericPopUp is used to position the next element (message field) w.r.t. the clocks, rather than the last element of the row above (the logo): in case of a SAME_ROW Graph element, 'last' is kept at the previous element. --- args.h | 2 + common.h | 2 + dialogs.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- dialogs.h | 24 +++++++++++-------- xboard.c | 43 +++++++++++++++++++++++++++++++++- xoptions.c | 1 + 6 files changed, 129 insertions(+), 16 deletions(-) diff --git a/args.h b/args.h index a08d49b..aa3bcfd 100644 --- a/args.h +++ b/args.h @@ -614,6 +614,8 @@ ArgDescriptor argDescriptors[] = { { "smpCores", ArgInt, (void *) &appData.smpCores, TRUE, (ArgIniType) 1 }, { "egtFormats", ArgString, (void *) &appData.egtFormats, TRUE, (ArgIniType) "" }, { "niceEngines", ArgInt, (void *) &appData.niceEngines, TRUE, INVALID }, + { "logoSize", ArgInt, (void *) &appData.logoSize, XBOARD, INVALID }, + { "logoDir", ArgFilename, (void *) &appData.logoDir, XBOARD, (ArgIniType) "." }, { "firstLogo", ArgFilename, (void *) &appData.firstLogo, FALSE, (ArgIniType) "" }, { "secondLogo", ArgFilename, (void *) &appData.secondLogo, FALSE, (ArgIniType) "" }, { "autoLogo", ArgBoolean, (void *) &appData.autoLogo, TRUE, INVALID }, diff --git a/common.h b/common.h index 2d8162b..09be05a 100644 --- a/common.h +++ b/common.h @@ -436,6 +436,8 @@ typedef struct { Boolean debugMode; Boolean clockMode; char *boardSize; + char *logoDir; + int logoSize; Boolean Iconic; char *searchTime; int searchDepth; diff --git a/dialogs.c b/dialogs.c index e0d1c4e..47efff8 100644 --- a/dialogs.c +++ b/dialogs.c @@ -1831,8 +1831,49 @@ static ChessSquare dropMenuTranslation[DROP_MENU_SIZE] = { static Option *Exp P((int n, int x, int y)); void MenuCallback P((int n)); void SizeKludge P((int n)); +static Option *LogoW P((int n, int x, int y)); +static Option *LogoB P((int n, int x, int y)); static int pmFromX = -1, pmFromY = -1; +void *userLogo; + +void +DisplayLogos (void *w1, void *w2) +{ + void *whiteLogo = first.programLogo, *blackLogo = second.programLogo; + if(appData.autoLogo) { + + switch(gameMode) { // pick logos based on game mode + case IcsObserving: + whiteLogo = second.programLogo; // ICS logo + blackLogo = second.programLogo; + default: + break; + case IcsPlayingWhite: + if(!appData.zippyPlay) whiteLogo = userLogo; + blackLogo = second.programLogo; // ICS logo + break; + case IcsPlayingBlack: + whiteLogo = second.programLogo; // ICS logo + blackLogo = appData.zippyPlay ? first.programLogo : userLogo; + break; + case TwoMachinesPlay: + if(first.twoMachinesColor[0] == 'b') { + whiteLogo = second.programLogo; + blackLogo = first.programLogo; + } + break; + case MachinePlaysWhite: + blackLogo = userLogo; + break; + case MachinePlaysBlack: + whiteLogo = userLogo; + blackLogo = first.programLogo; + } + } + DrawLogo(w1, whiteLogo); + DrawLogo(w2, blackLogo); +} static void PMSelect (int n) @@ -1861,8 +1902,10 @@ Option mainOptions[] = { // description of main window in terms of generic dialo { 0, COMBO_CALLBACK, 0, NULL, (void*)&MenuCallback, NULL, NULL, DropDown, N_("Help") }, { 0, 0, 0, NULL, (void*)&SizeKludge, "", NULL, BoxEnd, "" }, { 0, LR|T2T|BORDER|SAME_ROW, 0, NULL, NULL, "", NULL, Label, "1" }, // optional title in window -{ 0, L2L|T2T, 200, NULL, (void*) &CCB, NULL, NULL, Label, "White" }, // white clock -{ 0, R2R|T2T|SAME_ROW, 200, NULL, (void*) &CCB, NULL, NULL, Label, "Black" }, // black clock +{ 50, LL|TT, 100, NULL, (void*) &LogoW, NULL, NULL, -1, "LogoW" }, // white logo +{ 0, L2L|T2T, 200, NULL, (void*) &CCB, NULL, NULL, Label, "White" }, // white clock +{ 0, R2R|T2T|SAME_ROW, 200, NULL, (void*) &CCB, NULL, NULL, Label, "Black" }, // black clock +{ 50, RR|TT|SAME_ROW, 100, NULL, (void*) &LogoB, NULL, NULL, -1, "LogoB" }, // black logo { 0, LR|T2T|BORDER, 401, NULL, NULL, "", NULL, -1, "2" }, // backup for title in window (if no room for other) { 0, LR|T2T|BORDER, 270, NULL, NULL, "", NULL, Label, "message" }, // message field { 0, RR|TT|SAME_ROW, 125, NULL, NULL, "", NULL, BoxBegin, "" }, // (optional) button bar @@ -1872,13 +1915,27 @@ Option mainOptions[] = { // description of main window in terms of generic dialo { 0, SAME_ROW, 0, NULL, (void*) &ForwardEvent, NULL, NULL, Button, N_(">") }, { 0, SAME_ROW, 0, NULL, (void*) &ToEndEvent, NULL, NULL, Button, N_(">>") }, { 0, 0, 0, NULL, NULL, "", NULL, BoxEnd, "" }, -{ 401, LR|TT, 401, NULL, (char*) &Exp, NULL, NULL, Graph, "shadow board" }, // board +{ 401, LR|TB, 401, NULL, (char*) &Exp, NULL, NULL, Graph, "shadow board" }, // board { 2, COMBO_CALLBACK, 0, NULL, (void*) &PMSelect, NULL, pieceMenuStrings[0], PopUp, "menuW" }, { 2, COMBO_CALLBACK, 0, NULL, (void*) &PMSelect, NULL, pieceMenuStrings[1], PopUp, "menuB" }, { -1, COMBO_CALLBACK, 0, NULL, (void*) &PMSelect, NULL, dropMenuStrings, PopUp, "menuD" }, { 0, NO_OK, 0, NULL, NULL, "", NULL, EndMark , "" } }; +Option * +LogoW (int n, int x, int y) +{ + if(n == 10) DisplayLogos(mainOptions[W_WHITE-1].handle, NULL); + return NULL; +} + +Option * +LogoB (int n, int x, int y) +{ + if(n == 10) DisplayLogos(NULL, mainOptions[W_BLACK+1].handle); + return NULL; +} + void SizeKludge (int n) { // callback called by GenericPopUp immediately after sizing the menu bar @@ -1940,7 +1997,7 @@ Exp (int n, int x, int y) Option * BoardPopUp (int squareSize, int lineGap, void *clockFontThingy) { - int i, size = BOARD_WIDTH*(squareSize + lineGap) + lineGap; + int i, size = BOARD_WIDTH*(squareSize + lineGap) + lineGap, logo = appData.logoSize; mainOptions[W_WHITE].choice = (char**) clockFontThingy; mainOptions[W_BLACK].choice = (char**) clockFontThingy; mainOptions[W_BOARD].value = BOARD_HEIGHT*(squareSize + lineGap) + lineGap; @@ -1950,6 +2007,14 @@ BoardPopUp (int squareSize, int lineGap, void *clockFontThingy) mainOptions[W_MESSG].max = appData.showButtonBar ? size-130 : size-2; // message mainOptions[W_MENU].max = size-40; // menu bar mainOptions[W_TITLE].type = appData.titleInWindow ? Label : -1 ; + if(logo && logo <= size/4) { // Activate logos + mainOptions[W_WHITE-1].type = mainOptions[W_BLACK+1].type = Graph; + mainOptions[W_WHITE-1].max = mainOptions[W_BLACK+1].max = logo; + mainOptions[W_WHITE-1].value= mainOptions[W_BLACK+1].value= logo/2; + mainOptions[W_WHITE].min |= SAME_ROW; + mainOptions[W_WHITE].max = mainOptions[W_BLACK].max -= logo + 4; + mainOptions[W_WHITE].name = mainOptions[W_BLACK].name = "Double\nHeight"; + } if(!appData.showButtonBar) for(i=W_BUTTON; itidy); + } + } + if(logoName[0]) + XpmReadFileToPixmap(xDisplay, xBoardWindow, logoName, (Pixmap *) &(cps->programLogo), NULL, NULL); +} + void UpdateLogos (int displ) { - return; // no logos in XBoard yet + if(optList[W_WHITE-1].handle == NULL) return; + LoadLogo(&first, 0, 0); + LoadLogo(&second, 1, appData.icsActive); + if(displ) DisplayLogos(optList[W_WHITE-1].handle, optList[W_BLACK+1].handle); + return; } diff --git a/xoptions.c b/xoptions.c index 932914e..55a3935 100644 --- a/xoptions.c +++ b/xoptions.c @@ -962,6 +962,7 @@ GenericPopUp (Option *option, char *title, DialogClass dlgNr, DialogClass parent (last = XtCreateManagedWidget("graph", widgetClass, form, args, j)); XtAddEventHandler(last, ExposureMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask, False, (XtEventHandler) GraphEventProc, option[i].target); // mandatory user-supplied expose handler + if(option[i].min & SAME_ROW) last = forelast, forelast = lastrow; break; case PopUp: // note: used only after Graph, so 'last' refers to the Graph widget option[i].handle = (void*) CreateComboPopup(last, option + i, i + 256*dlgNr, TRUE, option[i].value); -- 1.7.0.4