From: H.G. Muller Date: Wed, 10 Oct 2012 16:45:59 +0000 (+0200) Subject: Fix initial display of logos X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=faa0fea4cf9cc9de2d73add4695af3ed06517787;p=xboard.git Fix initial display of logos The logos were selected and printed during the initialization, before the main event loop was started. So the expose events during widget creation, which created the drawing surfaces, were only processed after the initial drawing of logos, so that there was nothing to draw on! --- diff --git a/dialogs.c b/dialogs.c index 721b2a2..ebdd93c 100644 --- a/dialogs.c +++ b/dialogs.c @@ -1931,7 +1931,7 @@ static int pmFromX = -1, pmFromY = -1; void *userLogo; void -DisplayLogos (void *w1, void *w2) +DisplayLogos (Option *w1, Option *w2) { void *whiteLogo = first.programLogo, *blackLogo = second.programLogo; if(appData.autoLogo) { @@ -2018,14 +2018,14 @@ Option mainOptions[] = { // description of main window in terms of generic dialo Option * LogoW (int n, int x, int y) { - if(n == 10) DisplayLogos(mainOptions[W_WHITE-1].handle, NULL); + if(n == 10) DisplayLogos(&mainOptions[W_WHITE-1], NULL); return NULL; } Option * LogoB (int n, int x, int y) { - if(n == 10) DisplayLogos(NULL, mainOptions[W_BLACK+1].handle); + if(n == 10) DisplayLogos(NULL, &mainOptions[W_BLACK+1]); return NULL; } diff --git a/dialogs.h b/dialogs.h index 64b9552..80209ac 100644 --- a/dialogs.h +++ b/dialogs.h @@ -160,12 +160,12 @@ int ReadScroll P((Option *opt, float *top, float *bottom)); void SetScroll P((Option *opt, float f)); void AddHandler P((Option *opt, int nr)); void SendText P((int n)); -void DisplayLogos P((void *left, void *right)); +void DisplayLogos P((Option *left, Option *right)); void Browse P((DialogClass dlg, char *label, char *proposed, char *ext, Boolean pathFlag, char *mode, char **name, FILE **fp)); void InitDrawingParams P((int reload)); // in draw.c -void DrawLogo P((void *handle, void *logo)); +void DrawLogo P((Option *opt, void *logo)); void ErrorPopUp P((char *title, char *text, int modal)); int ShiftKeys P((void)); void SetClockIcon P((int color)); diff --git a/draw.c b/draw.c index 25965cb..eab7e87 100644 --- a/draw.c +++ b/draw.c @@ -110,7 +110,7 @@ extern char *getenv(); #define SOLID 0 #define OUTLINE 1 Boolean cairoAnimate; -static cairo_surface_t *csBoardWindow, *csBoardBackup, *csDualBoard; +static cairo_surface_t *csBoardWindow, *csDualBoard; static cairo_surface_t *pngPieceImages[2][(int)BlackPawn+4]; // png 256 x 256 images static cairo_surface_t *pngPieceBitmaps[2][(int)BlackPawn]; // scaled pieces as used static cairo_surface_t *pngPieceBitmaps2[2][(int)BlackPawn+4]; // scaled pieces in store @@ -135,7 +135,7 @@ SwitchWindow () csBoardWindow = csDualBoard; dual = !dual; if(!csDualBoard) { - csBoardWindow = GetOutputSurface(&dualOptions[3], 0, 0); + csBoardWindow = DRAWABLE(dualOptions+3); dual = 1; } csDualBoard = cstmp; @@ -538,24 +538,23 @@ CutOutSquare (int x, int y, int *x0, int *y0, int kind) } void -DrawLogo (void *handle, void *logo) +DrawLogo (Option *opt, void *logo) { - cairo_surface_t *img, *cs; + cairo_surface_t *img; cairo_t *cr; int w, h; - if(!logo || !handle) return; - cs = GetOutputSurface(handle, appData.logoSize, appData.logoSize/2); + if(!logo || !opt) return; img = cairo_image_surface_create_from_png (logo); w = cairo_image_surface_get_width (img); h = cairo_image_surface_get_height (img); - cr = cairo_create(cs); + cr = cairo_create(DRAWABLE(opt)); cairo_scale(cr, (float)appData.logoSize/w, appData.logoSize/(2.*h)); cairo_set_source_surface (cr, img, 0, 0); cairo_paint (cr); cairo_destroy (cr); cairo_surface_destroy (img); - cairo_surface_destroy (cs); + GraphExpose(opt, 0, 0, appData.logoSize, appData.logoSize/2); } static void diff --git a/draw.h b/draw.h index a565726..a606214 100644 --- a/draw.h +++ b/draw.h @@ -49,6 +49,8 @@ *------------------------------------------------------------------------ ** See the file ChangeLog for a revision history. */ +#define DRAWABLE(X) ((cairo_surface_t *) ((X)->choice)) + // defined in xboard.c int MakeColors P((void)); void ResizeBoardWindow P((int w, int h, int inhibit)); diff --git a/xboard.c b/xboard.c index 1d0de9f..2ac676d 100644 --- a/xboard.c +++ b/xboard.c @@ -1669,14 +1669,6 @@ SetupDropMenu () } } -cairo_surface_t * -GetOutputSurface(Option *opt, int w, int h) -{ - if(w == 0) w = lineGap + BOARD_WIDTH * (squareSize + lineGap); - if(h == 0) h = lineGap + BOARD_HEIGHT * (squareSize + lineGap); - return cairo_xlib_surface_create(xDisplay, XtWindow(opt->handle), DefaultVisual(xDisplay, 0), w, h); -} - static void do_flash_delay (unsigned long msec) { @@ -1912,7 +1904,7 @@ ModeHighlight () /* Maybe all the enables should be handled here, not just this one */ EnableNamedMenuItem("Mode.Training", gameMode == Training || gameMode == PlayFromGameFile); - DisplayLogos(optList[W_WHITE-1].handle, optList[W_BLACK+1].handle); + DisplayLogos(&optList[W_WHITE-1], &optList[W_BLACK+1]); } @@ -2560,7 +2552,7 @@ UpdateLogos (int displ) 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); + if(displ) DisplayLogos(&optList[W_WHITE-1], &optList[W_BLACK+1]); return; } diff --git a/xoptions.c b/xoptions.c index 32588e8..70ab431 100644 --- a/xoptions.c +++ b/xoptions.c @@ -555,10 +555,14 @@ GraphEventProc(Widget widget, caddr_t client_data, XEvent *event) sizing = ((w != graph->max || h != graph->value) && ((XExposeEvent*)event)->count >= 0); graph->max = w; graph->value = h; if(sizing && ((XExposeEvent*)event)->count > 0) { graph->max = 0; return; } // don't bother if further exposure is pending during resize - if(!graph->textValue || sizing) { - // create surfaces of new size for widget and buffer + if(!graph->textValue || sizing) { // create surfaces of new size for display widget if(graph->textValue) cairo_surface_destroy((cairo_surface_t *)graph->textValue); graph->textValue = (char*) cairo_xlib_surface_create(xDisplay, XtWindow(widget), DefaultVisual(xDisplay, 0), w, h); + } + if(sizing) { // the memory buffer was already created in GenericPopup(), + // to give drawing routines opportunity to use it befor first expose event + // (which are only processed when main gets to the event loop, so after all init!) + // so only change when size is no longer good if(graph->choice) cairo_surface_destroy((cairo_surface_t *) graph->choice); graph->choice = (char**) cairo_image_surface_create (CAIRO_FORMAT_ARGB32, w, h); } @@ -997,6 +1001,7 @@ GenericPopUp (Option *option, char *title, DialogClass dlgNr, DialogClass parent XtAddEventHandler(last, ExposureMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask, False, (XtEventHandler) GraphEventProc, &option[i]); // mandatory user-supplied expose handler if(option[i].min & SAME_ROW) last = forelast, forelast = lastrow; + option[i].choice = (char**) cairo_image_surface_create (CAIRO_FORMAT_ARGB32, option[i].max, option[i].value); // image buffer 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);