From c10469264d70075a26a13ac2db5281822a2a2210 Mon Sep 17 00:00:00 2001 From: David Maciejak Date: Thu, 4 Dec 2014 13:25:55 +0700 Subject: [PATCH] WINGs: add functions to set widget background image With this patch we can set widget background image. As now, only background color was available. --- WINGs/WINGs/WINGs.h | 4 ++++ WINGs/WINGs/WINGsP.h | 4 ++++ WINGs/widgets.c | 15 +++++++++++++++ WINGs/wmisc.c | 14 +++++++++++--- WINGs/wview.c | 17 ++++++++++++++++- 5 files changed, 50 insertions(+), 4 deletions(-) diff --git a/WINGs/WINGs/WINGs.h b/WINGs/WINGs/WINGs.h index e460ef43..ca7be553 100644 --- a/WINGs/WINGs/WINGs.h +++ b/WINGs/WINGs/WINGs.h @@ -930,6 +930,10 @@ void WMSetWidgetBackgroundColor(WMWidget *w, WMColor *color); WMColor* WMGetWidgetBackgroundColor(WMWidget *w); +void WMSetWidgetBackgroundPixmap(WMWidget *w, WMPixmap *pix); + +WMPixmap *WMGetWidgetBackgroundPixmap(WMWidget *w); + void WMMapSubwidgets(WMWidget *w); void WMUnmapSubwidgets(WMWidget *w); diff --git a/WINGs/WINGs/WINGsP.h b/WINGs/WINGs/WINGsP.h index 2484b25d..fc18b1cb 100644 --- a/WINGs/WINGs/WINGsP.h +++ b/WINGs/WINGs/WINGsP.h @@ -572,6 +572,8 @@ struct W_View { void *hangedData; /* data holder for user program */ WMColor *backColor; + WMPixmap *backImage; + Cursor cursor; @@ -664,6 +666,8 @@ void W_ResizeView(W_View *view, unsigned int width, unsigned int height); void W_SetViewBackgroundColor(W_View *view, WMColor *color); +void W_SetViewBackgroundPixmap(W_View *view, WMPixmap *pix); + void W_SetViewCursor(W_View *view, Cursor cursor); void W_SetFocusOfTopLevel(W_View *toplevel, W_View *view); diff --git a/WINGs/widgets.c b/WINGs/widgets.c index 75b44e70..87fa9d62 100644 --- a/WINGs/widgets.c +++ b/WINGs/widgets.c @@ -960,6 +960,21 @@ WMColor *WMGetWidgetBackgroundColor(WMWidget * w) return W_VIEW(w)->backColor; } +void WMSetWidgetBackgroundPixmap(WMWidget *w, WMPixmap *pix) +{ + if (!pix) + return; + + W_SetViewBackgroundPixmap(W_VIEW(w), pix); + if (W_VIEW(w)->flags.mapped) + WMRedisplayWidget(w); +} + +WMPixmap *WMGetWidgetBackgroundPixmap(WMWidget *w) +{ + return W_VIEW(w)->backImage; +} + void WMRaiseWidget(WMWidget * w) { W_RaiseView(W_VIEW(w)); diff --git a/WINGs/wmisc.c b/WINGs/wmisc.c index 331dc401..ba4c8a6a 100644 --- a/WINGs/wmisc.c +++ b/WINGs/wmisc.c @@ -220,12 +220,20 @@ W_PaintTextAndImage(W_View * view, int wrap, WMColor * textColor, W_Font * font, XFillRectangle(screen->display, d, WMColorGC(backColor), 0, 0, view->size.width, view->size.height); } else { + if (view->attribs.background_pixmap) { #ifndef DOUBLE_BUFFER - XClearWindow(screen->display, d); + XClearWindow(screen->display, d); #else - XSetForeground(screen->display, screen->copyGC, view->attribs.background_pixel); - XFillRectangle(screen->display, d, screen->copyGC, 0, 0, view->size.width, view->size.height); + XCopyArea(screen->display, view->attribs.background_pixmap, d, screen->copyGC, 0, 0, view->size.width, view->size.height, 0, 0); #endif + } else { +#ifndef DOUBLE_BUFFER + XClearWindow(screen->display, d); +#else + XSetForeground(screen->display, screen->copyGC, view->attribs.background_pixel); + XFillRectangle(screen->display, d, screen->copyGC, 0, 0, view->size.width, view->size.height); +#endif + } } if (relief == WRFlat) { diff --git a/WINGs/wview.c b/WINGs/wview.c index 20662447..610e640a 100644 --- a/WINGs/wview.c +++ b/WINGs/wview.c @@ -100,7 +100,8 @@ static W_View *createView(W_Screen * screen, W_View * parent) view->attribFlags = CWEventMask | CWBitGravity; view->attribs = defAtts; - view->attribFlags |= CWBackPixel | CWColormap | CWBorderPixel; + view->attribFlags |= CWBackPixel | CWColormap | CWBorderPixel | CWBackPixmap; + view->attribs.background_pixmap = None; view->attribs.background_pixel = W_PIXEL(screen->gray); view->attribs.border_pixel = W_PIXEL(screen->black); view->attribs.colormap = screen->colormap; @@ -496,6 +497,20 @@ void W_SetViewBackgroundColor(W_View * view, WMColor * color) } } +void W_SetViewBackgroundPixmap(W_View *view, WMPixmap *pix) +{ + if (view->backImage) + WMReleasePixmap(view->backImage); + view->backImage = WMRetainPixmap(pix); + + view->attribFlags |= CWBackPixmap; + view->attribs.background_pixmap = pix->pixmap; + if (view->flags.realized) { + XSetWindowBackgroundPixmap(view->screen->display, view->window, pix->pixmap); + XClearWindow(view->screen->display, view->window); + } +} + void W_SetViewCursor(W_View * view, Cursor cursor) { view->cursor = cursor;