The theme selection method is very primitive: #ifdef NEW_LOOK #include <newtheme.c> #else #include <oldlook.c> #endif
but it should be easy to select at compile time, and at the moment I don't feel like doing anything more elaborate. Sorry for the slow progress guys, I am working on this, life just happens to get in the way every now and then. Regards, Johann
>From fef81a6929142e7d53a3fae7eb82c0141d8bc410 Mon Sep 17 00:00:00 2001 From: Johann Haarhoff <[email protected]> Date: Thu, 15 Apr 2010 00:10:12 +0200 Subject: [PATCH] Cairo buttons can now be themed paintButton now stamps the surface created in wtheme.c onto buttons. Themes are selectable by #defining NEW_LOOK, or OLD_LOOK, but this has to be built into configure somehow. --- WINGs/Makefile.am | 3 +- WINGs/TODO | 6 + WINGs/WINGs/WINGs.h | 3 + WINGs/WINGs/WINGsP.h | 6 +- WINGs/WINGs/wtheme.h | 5 + WINGs/newtheme.c | 129 +++++++++++++ WINGs/oldtheme.c | 114 +++++++++++ WINGs/wbutton.c | 25 ++- WINGs/wcolor.c | 11 + WINGs/wfont.c | 2 +- WINGs/wmisc.c | 517 +++++++++++++++++++++++++++---------------------- WINGs/wtheme.c | 8 + WINGs/wview.c | 6 +- test/cairo/draw.c | 111 ++--------- 14 files changed, 607 insertions(+), 339 deletions(-) create mode 100644 WINGs/WINGs/wtheme.h create mode 100644 WINGs/newtheme.c create mode 100644 WINGs/oldtheme.c create mode 100644 WINGs/wtheme.c diff --git a/WINGs/Makefile.am b/WINGs/Makefile.am index b055717..b0ab92d 100644 --- a/WINGs/Makefile.am +++ b/WINGs/Makefile.am @@ -52,7 +52,8 @@ libWINGs_la_SOURCES = \ wpixmap.c \ wprogressindicator.c \ wview.c \ - wwindow.c + wwindow.c \ + wtheme.c libWUtil_la_SOURCES = \ array.c \ diff --git a/WINGs/TODO b/WINGs/TODO index 7132ef9..fc6a12b 100644 --- a/WINGs/TODO +++ b/WINGs/TODO @@ -1,3 +1,9 @@ +JH + +- change WM*ColorSpec to return a cairo_pattern if appropriate +- make the PaintText* methods paint the bg using the cairo_pattern + this should make theming easy + - move paint to idle handlers - check if its useful to add some WMBrowserSelectionDidChangeNotification (actually a pass-through for WMListSelectionDidChangeNotification). diff --git a/WINGs/WINGs/WINGs.h b/WINGs/WINGs/WINGs.h index 43e4b7a..abff8f9 100644 --- a/WINGs/WINGs/WINGs.h +++ b/WINGs/WINGs/WINGs.h @@ -8,6 +8,7 @@ #include <cairo.h> #define WINGS_H_VERSION 20041030 +#define NEW_LOOK 1 #ifdef __cplusplus @@ -856,6 +857,8 @@ void WMColorSpecSet(cairo_t *cairo, WMColorSpec *color); WMColorSpec WMBlackColorSpec(); WMColorSpec WMGrayColorSpec(); +WMColorSpec WMLightGrayColorSpec(); +WMColorSpec WMTransparentColorSpec(); WMColorSpec WMWhiteColorSpec(); WMColorSpec WMDarkGrayColorSpec(); diff --git a/WINGs/WINGs/WINGsP.h b/WINGs/WINGs/WINGsP.h index 403d455..ee4789f 100644 --- a/WINGs/WINGs/WINGsP.h +++ b/WINGs/WINGs/WINGsP.h @@ -33,6 +33,8 @@ extern "C" { #define XDND_VERSION 3 +#define NEW_LOOK 1 + typedef struct W_Application { char *applicationName; @@ -503,8 +505,8 @@ void W_SetViewCursor(W_View *view, Cursor cursor); void W_DrawRelief(W_Screen *scr, cairo_t *cairo, int x, int y, unsigned int width, unsigned int height, WMReliefType relief); -void W_DrawButtonRelief(W_Screen *scr, cairo_t *cairo, int x, int y, unsigned int width, unsigned int height, - WMReliefType relief); +//void W_DrawButtonRelief(W_Screen *scr, cairo_t *cairo, int x, int y, unsigned int width, unsigned int height, +// WMReliefType relief, unsigned int pushLight); void W_CallDestroyHandlers(W_View *view); diff --git a/WINGs/WINGs/wtheme.h b/WINGs/WINGs/wtheme.h new file mode 100644 index 0000000..d5848a2 --- /dev/null +++ b/WINGs/WINGs/wtheme.h @@ -0,0 +1,5 @@ +#include "WINGsP.h" + +void W_DrawButtonDarkBack(cairo_t *cairo, WMButton *bPtr, unsigned int width, unsigned int height, WMReliefType relief); +void W_DrawButtonLightBack(cairo_t *cairo, WMButton *bPtr, unsigned int width, unsigned int height, WMReliefType relief); +void W_DrawButtonRelief(cairo_t *cairo, unsigned int width, unsigned int height, WMReliefType relief); diff --git a/WINGs/newtheme.c b/WINGs/newtheme.c new file mode 100644 index 0000000..b32590c --- /dev/null +++ b/WINGs/newtheme.c @@ -0,0 +1,129 @@ +#include <wtheme.h> + +void W_DrawButtonDarkBack(cairo_t *cairo, WMButton *bPtr, unsigned int width, unsigned int height, WMReliefType relief) +{ + cairo_save(cairo); + + WMColorSpec topfill = WMLightGrayColorSpec(); + WMColorSpec bottomfill = WMGrayColorSpec(); + + //draw main gradient + cairo_pattern_t *linpat; + linpat = cairo_pattern_create_linear(0, 0, 0, height); + cairo_pattern_add_color_stop_rgba(linpat, 0, topfill.red/255.0, topfill.green/255.0, topfill.blue/255.0, topfill.alpha/255.0); + cairo_pattern_add_color_stop_rgba(linpat, 1, bottomfill.red/255.0, bottomfill.green/255.0, bottomfill.blue/255.0, bottomfill.alpha/255.0); + cairo_set_source(cairo, linpat); + cairo_rectangle(cairo, 0, 0, width, height); + cairo_fill(cairo); + cairo_stroke(cairo); + + cairo_restore(cairo); + cairo_pattern_destroy(linpat); +} + +void W_DrawButtonLightBack(cairo_t *cairo, WMButton *bPtr, unsigned int width, unsigned int height, WMReliefType relief) +{ + cairo_save(cairo); + + WMColorSpec topfill = WMWhiteColorSpec(); + WMColorSpec bottomfill = WMLightGrayColorSpec(); + + //draw main gradient + cairo_pattern_t *linpat; + linpat = cairo_pattern_create_linear(0, 0, 0, height); + cairo_pattern_add_color_stop_rgba(linpat, 0, topfill.red/255.0, topfill.green/255.0, topfill.blue/255.0, topfill.alpha/255.0); + cairo_pattern_add_color_stop_rgba(linpat, 1, bottomfill.red/255.0, bottomfill.green/255.0, bottomfill.blue/255.0, bottomfill.alpha/255.0); + cairo_set_source(cairo, linpat); +// cairo_set_source_rgb(cairo, 1,1,1); + cairo_rectangle(cairo, 0, 0, width, height); + cairo_fill(cairo); + cairo_stroke(cairo); + + cairo_restore(cairo); + cairo_pattern_destroy(linpat); +} + +void W_DrawButtonRelief(cairo_t *cairo, unsigned int width, unsigned int height, WMReliefType relief) +{ + cairo_save(cairo); + + WMColorSpec outerlefttop; + WMColorSpec innerlefttop; + WMColorSpec outerbottomright; + WMColorSpec innerbottomright; + + switch (relief) { + case WRSimple: + { + outerlefttop = WMBlackColorSpec(); + outerbottomright = WMBlackColorSpec(); + innerlefttop = WMTransparentColorSpec(); + innerbottomright = WMTransparentColorSpec(); + break; + } + case WRRaised: + { + outerlefttop = WMWhiteColorSpec(); + outerbottomright = WMBlackColorSpec(); + innerlefttop = WMTransparentColorSpec(); + innerbottomright = WMDarkGrayColorSpec(); + break; + } + case WRSunken: + { + outerlefttop = WMDarkGrayColorSpec(); + outerbottomright = WMWhiteColorSpec(); + innerlefttop = WMBlackColorSpec(); + innerbottomright = WMTransparentColorSpec(); + break; + } + case WRPushed: + { + outerlefttop = WMBlackColorSpec(); + outerbottomright = WMWhiteColorSpec(); + innerlefttop = WMTransparentColorSpec(); + innerbottomright = WMTransparentColorSpec(); + break; + } + case WRRidge: + { + outerlefttop = WMWhiteColorSpec(); + outerbottomright = WMDarkGrayColorSpec(); + innerlefttop = WMTransparentColorSpec(); + innerbottomright = WMTransparentColorSpec(); + break; + } + case WRGroove: + { + outerlefttop = WMDarkGrayColorSpec(); + outerbottomright = WMDarkGrayColorSpec(); + innerlefttop = WMTransparentColorSpec(); + innerbottomright = WMTransparentColorSpec(); + break; + } + } + + cairo_set_line_width(cairo,1); + + WMColorSpecSet(cairo,&outerlefttop); + cairo_rectangle(cairo,0,0,width-1,0); + cairo_rectangle(cairo,0,0,0,height-1); + cairo_stroke(cairo); + + WMColorSpecSet(cairo,&innerlefttop); + cairo_rectangle(cairo,1,1,width-2,0); + cairo_rectangle(cairo,1,1,0,height-2); + cairo_stroke(cairo); + + WMColorSpecSet(cairo,&innerbottomright); + cairo_rectangle(cairo,1,height-2,width-1,1); + cairo_rectangle(cairo,width-2,1,1,height-2); + cairo_stroke(cairo); + + WMColorSpecSet(cairo,&outerbottomright); + cairo_rectangle(cairo,0,height-1,width,1); + cairo_rectangle(cairo,width-1,0,1,height); + cairo_stroke(cairo); + + cairo_restore(cairo); +} diff --git a/WINGs/oldtheme.c b/WINGs/oldtheme.c new file mode 100644 index 0000000..c5b77d5 --- /dev/null +++ b/WINGs/oldtheme.c @@ -0,0 +1,114 @@ +#include <wtheme.h> + +void W_DrawButtonDarkBack(cairo_t *cairo, WMButton *bPtr, unsigned int width, unsigned int height, WMReliefType relief) +{ + cairo_save(cairo); + + WMColorSpec fill = WMGrayColorSpec(); + + cairo_set_source_rgba(cairo, fill.red/255.0, fill.green/255.0, fill.blue/255.0, fill.alpha/255.0); + cairo_rectangle(cairo, 0, 0, width, height); + cairo_fill(cairo); + cairo_stroke(cairo); + + cairo_restore(cairo); +} + +void W_DrawButtonLightBack(cairo_t *cairo, WMButton *bPtr, unsigned int width, unsigned int height, WMReliefType relief) +{ + cairo_save(cairo); + + WMColorSpec fill = WMWhiteColorSpec(); + + cairo_set_source_rgba(cairo, fill.red/255.0, fill.green/255.0, fill.blue/255.0, fill.alpha/255.0); + cairo_rectangle(cairo, 0, 0, width, height); + cairo_fill(cairo); + cairo_stroke(cairo); + + cairo_restore(cairo); +} + +void W_DrawButtonRelief(cairo_t *cairo, unsigned int width, unsigned int height, WMReliefType relief) +{ + cairo_save(cairo); + + WMColorSpec outerlefttop; + WMColorSpec innerlefttop; + WMColorSpec outerbottomright; + WMColorSpec innerbottomright; + + switch (relief) { + case WRSimple: + { + outerlefttop = WMBlackColorSpec(); + outerbottomright = WMBlackColorSpec(); + innerlefttop = WMTransparentColorSpec(); + innerbottomright = WMTransparentColorSpec(); + break; + } + case WRRaised: + { + outerlefttop = WMWhiteColorSpec(); + outerbottomright = WMBlackColorSpec(); + innerlefttop = WMTransparentColorSpec(); + innerbottomright = WMDarkGrayColorSpec(); + break; + } + case WRSunken: + { + outerlefttop = WMDarkGrayColorSpec(); + outerbottomright = WMWhiteColorSpec(); + innerlefttop = WMBlackColorSpec(); + innerbottomright = WMTransparentColorSpec(); + break; + } + case WRPushed: + { + outerlefttop = WMBlackColorSpec(); + outerbottomright = WMWhiteColorSpec(); + innerlefttop = WMTransparentColorSpec(); + innerbottomright = WMTransparentColorSpec(); + break; + } + case WRRidge: + { + outerlefttop = WMWhiteColorSpec(); + outerbottomright = WMDarkGrayColorSpec(); + innerlefttop = WMTransparentColorSpec(); + innerbottomright = WMTransparentColorSpec(); + break; + } + case WRGroove: + { + outerlefttop = WMDarkGrayColorSpec(); + outerbottomright = WMDarkGrayColorSpec(); + innerlefttop = WMTransparentColorSpec(); + innerbottomright = WMTransparentColorSpec(); + break; + } + } + + cairo_set_line_width(cairo,1); + + WMColorSpecSet(cairo,&outerlefttop); + cairo_rectangle(cairo,0,0,width-1,0); + cairo_rectangle(cairo,0,0,0,height-1); + cairo_stroke(cairo); + + WMColorSpecSet(cairo,&innerlefttop); + cairo_rectangle(cairo,1,1,width-2,0); + cairo_rectangle(cairo,1,1,0,height-2); + cairo_stroke(cairo); + + WMColorSpecSet(cairo,&innerbottomright); + cairo_rectangle(cairo,1,height-2,width-1,1); + cairo_rectangle(cairo,width-2,1,1,height-2); + cairo_stroke(cairo); + + WMColorSpecSet(cairo,&outerbottomright); + cairo_rectangle(cairo,0,height-1,width,1); + cairo_rectangle(cairo,width-1,0,1,height); + cairo_stroke(cairo); + + cairo_restore(cairo); +} diff --git a/WINGs/wbutton.c b/WINGs/wbutton.c index 77e4cdd..7304a17 100644 --- a/WINGs/wbutton.c +++ b/WINGs/wbutton.c @@ -1,5 +1,6 @@ #include "WINGsP.h" +#include "wtheme.h" typedef struct W_Button { W_Class widgetClass; @@ -453,14 +454,16 @@ void WMSetButtonPeriodicDelay(WMButton * bPtr, float delay, float interval) bPtr->periodicDelay = delay; } -static void paintButton(Button * bPtr) +static void paintButton(WMButton * bPtr) { - cairo_t *cr= W_CreateCairoForView(W_VIEW(bPtr)); + cairo_t *cr = W_CreateCairoForView(W_VIEW(bPtr)); W_Screen *scrPtr = bPtr->view->screen; WMReliefType relief; int offset; const char *caption; WMImage *image; + unsigned int lightbg = 0; + WMColorSpec textColor; WMColorSpec backColor; @@ -488,8 +491,7 @@ static void paintButton(Button * bPtr) if (bPtr->flags.selected) { if (bPtr->flags.stateLight) { - backColor = WMWhiteColorSpec(); - textColor = WMBlackColorSpec(); + lightbg = 1; } if (bPtr->flags.stateChange) { @@ -512,8 +514,7 @@ static void paintButton(Button * bPtr) offset = 1; } if (bPtr->flags.pushLight) { - backColor = WMWhiteColorSpec(); - textColor = WMBlackColorSpec(); + lightbg = 1; } if (bPtr->flags.pushChange) { @@ -525,16 +526,18 @@ static void paintButton(Button * bPtr) } } + if (lightbg == 1) { + W_DrawButtonLightBack(cr, bPtr, bPtr->view->size.width, bPtr->view->size.height,relief); + } else { + W_DrawButtonDarkBack(cr, bPtr, bPtr->view->size.width, bPtr->view->size.height,relief); + } - W_DrawButtonRelief(scrPtr, cr, 0, 0, - bPtr->view->size.width, bPtr->view->size.height, - relief); + W_DrawButtonRelief(cr, bPtr->view->size.width, bPtr->view->size.height, relief); - relief= WRFlat; W_PaintTextAndImage(scrPtr, cr, bPtr->view, True, &textColor, (bPtr->font!=NULL ? bPtr->font : scrPtr->normalFont), relief, caption, bPtr->flags.alignment, image, - bPtr->flags.imagePosition, NULL, offset); + bPtr->flags.imagePosition, &backColor, offset); if (image) WMDestroyImage(image); diff --git a/WINGs/wcolor.c b/WINGs/wcolor.c index 8d0ac7a..929c45c 100644 --- a/WINGs/wcolor.c +++ b/WINGs/wcolor.c @@ -334,6 +334,17 @@ WMColorSpec WMBlackColorSpec() return spec; } +WMColorSpec WMTransparentColorSpec() +{ + WMColorSpec spec= {0, 0, 0, 0}; + return spec; +} + +WMColorSpec WMLightGrayColorSpec() +{ + WMColorSpec spec= {194, 190, 194, 0xff}; + return spec; +} WMColorSpec WMGrayColorSpec() { diff --git a/WINGs/wfont.c b/WINGs/wfont.c index 775ef88..b9b32aa 100644 --- a/WINGs/wfont.c +++ b/WINGs/wfont.c @@ -234,7 +234,7 @@ unsigned int WMFontHeight(WMFont * font) cairo_scaled_font_extents(font->metrics, &extents); - return extents.height; + return (extents.ascent); } char *WMGetFontName(WMFont * font) diff --git a/WINGs/wmisc.c b/WINGs/wmisc.c index 0413654..fb3bb06 100644 --- a/WINGs/wmisc.c +++ b/WINGs/wmisc.c @@ -3,203 +3,262 @@ #include <ctype.h> -static void curve_rectangle(cairo_t *cr, - double x0, double y0, double rect_width, double rect_height, - double radius) -{ - double x1,y1; - - x1=x0+rect_width; - y1=y0+rect_height; - if (!rect_width || !rect_height) - return; - if (rect_width/2<radius) { - if (rect_height/2<radius) { - cairo_move_to (cr, x0, (y0 + y1)/2); - cairo_curve_to (cr, x0 ,y0, x0, y0, (x0 + x1)/2, y0); - cairo_curve_to (cr, x1, y0, x1, y0, x1, (y0 + y1)/2); - cairo_curve_to (cr, x1, y1, x1, y1, (x1 + x0)/2, y1); - cairo_curve_to (cr, x0, y1, x0, y1, x0, (y0 + y1)/2); - } else { - cairo_move_to (cr, x0, y0 + radius); - cairo_curve_to (cr, x0 ,y0, x0, y0, (x0 + x1)/2, y0); - cairo_curve_to (cr, x1, y0, x1, y0, x1, y0 + radius); - cairo_line_to (cr, x1 , y1 - radius); - cairo_curve_to (cr, x1, y1, x1, y1, (x1 + x0)/2, y1); - cairo_curve_to (cr, x0, y1, x0, y1, x0, y1- radius); - } - } else { - if (rect_height/2<radius) { - cairo_move_to (cr, x0, (y0 + y1)/2); - cairo_curve_to (cr, x0 , y0, x0 , y0, x0 + radius, y0); - cairo_line_to (cr, x1 - radius, y0); - cairo_curve_to (cr, x1, y0, x1, y0, x1, (y0 + y1)/2); - cairo_curve_to (cr, x1, y1, x1, y1, x1 - radius, y1); - cairo_line_to (cr, x0 + radius, y1); - cairo_curve_to (cr, x0, y1, x0, y1, x0, (y0 + y1)/2); - } else { - cairo_move_to (cr, x0, y0 + radius); - cairo_curve_to (cr, x0 , y0, x0 , y0, x0 + radius, y0); - cairo_line_to (cr, x1 - radius, y0); - cairo_curve_to (cr, x1, y0, x1, y0, x1, y0 + radius); - cairo_line_to (cr, x1 , y1 - radius); - cairo_curve_to (cr, x1, y1, x1, y1, x1 - radius, y1); - cairo_line_to (cr, x0 + radius, y1); - cairo_curve_to (cr, x0, y1, x0, y1, x0, y1- radius); - } - } - cairo_close_path (cr); -} - -void W_DrawButtonRelief(W_Screen *scr, cairo_t *cairo, int x, int y, unsigned int width, unsigned int height, - WMReliefType relief) -{ - unsigned char border[4]= {0x00, 0x00, 0x00, 0x70}; - //unsigned char color1[4]= {0x8c, 0xb1, 0xbc, 0xff}; - //unsigned char color2[4]= {0xcb, 0xf3, 0xff, 0xff}; - unsigned char color1[4]= {0x0, 0x0, 0x0, 0xff}; - unsigned char color2[4]= {0xcf, 0xcf, 0xcf, 0xff}; - unsigned char scolor1[4]= {0xff, 0xff, 0xff, 0xe5}; - unsigned char scolor2[4]= {0xff, 0xff, 0xff, 0x70}; - cairo_pattern_t *shine; - cairo_pattern_t *base; - - x+=1; - y+=1; - width-=2; - height-=2; - - cairo_save(cairo); - - shine= cairo_pattern_create_linear(0, 0, 0, height*2/5); - cairo_pattern_add_color_stop_rgba(shine, 0, - scolor1[0]/255.0, scolor1[1]/255.0, scolor1[2]/255.0, - scolor1[3]/255.0); - cairo_pattern_add_color_stop_rgba(shine, 1, - scolor2[0]/255.0, scolor2[1]/255.0, scolor2[2]/255.0, - scolor2[3]/255.0); - - base= cairo_pattern_create_linear(0, 0, 0, height-1); - cairo_pattern_add_color_stop_rgba(base, 0, - color1[0]/255.0, color1[1]/255.0, color1[2]/255.0, - color1[3]/255.0); - cairo_pattern_add_color_stop_rgba(base, 1, - color2[0]/255.0, color2[1]/255.0, color2[2]/255.0, - color2[3]/255.0); - - - curve_rectangle(cairo, x, y, width-1, height-1, height*2/3); - cairo_set_source(cairo, base); - cairo_fill_preserve(cairo); - cairo_clip(cairo); - - curve_rectangle(cairo, x, y, width-1, height*2/5, width); - cairo_set_source(cairo, shine); - cairo_fill(cairo); - - curve_rectangle(cairo, x, y, width-1, height-1, height*2/3); - cairo_set_source_rgba(cairo, border[0]/255.0, border[1]/255.0, border[2]/255.0, border[3]/255.0); - cairo_set_line_width(cairo, 2.0); - cairo_stroke(cairo); - - cairo_pattern_destroy(shine); - cairo_pattern_destroy(base); - - cairo_restore(cairo); -} +//static void curve_rectangle(cairo_t *cr, +// double x0, double y0, double rect_width, double rect_height, +// double radius) +//{ +// double x1,y1; +// +// x1=x0+rect_width; +// y1=y0+rect_height; +// if (!rect_width || !rect_height) +// return; +// if (rect_width/2<radius) { +// if (rect_height/2<radius) { +// cairo_move_to (cr, x0, (y0 + y1)/2); +// cairo_curve_to (cr, x0 ,y0, x0, y0, (x0 + x1)/2, y0); +// cairo_curve_to (cr, x1, y0, x1, y0, x1, (y0 + y1)/2); +// cairo_curve_to (cr, x1, y1, x1, y1, (x1 + x0)/2, y1); +// cairo_curve_to (cr, x0, y1, x0, y1, x0, (y0 + y1)/2); +// } else { +// cairo_move_to (cr, x0, y0 + radius); +// cairo_curve_to (cr, x0 ,y0, x0, y0, (x0 + x1)/2, y0); +// cairo_curve_to (cr, x1, y0, x1, y0, x1, y0 + radius); +// cairo_line_to (cr, x1 , y1 - radius); +// cairo_curve_to (cr, x1, y1, x1, y1, (x1 + x0)/2, y1); +// cairo_curve_to (cr, x0, y1, x0, y1, x0, y1- radius); +// } +// } else { +// if (rect_height/2<radius) { +// cairo_move_to (cr, x0, (y0 + y1)/2); +// cairo_curve_to (cr, x0 , y0, x0 , y0, x0 + radius, y0); +// cairo_line_to (cr, x1 - radius, y0); +// cairo_curve_to (cr, x1, y0, x1, y0, x1, (y0 + y1)/2); +// cairo_curve_to (cr, x1, y1, x1, y1, x1 - radius, y1); +// cairo_line_to (cr, x0 + radius, y1); +// cairo_curve_to (cr, x0, y1, x0, y1, x0, (y0 + y1)/2); +// } else { +// cairo_move_to (cr, x0, y0 + radius); +// cairo_curve_to (cr, x0 , y0, x0 , y0, x0 + radius, y0); +// cairo_line_to (cr, x1 - radius, y0); +// cairo_curve_to (cr, x1, y0, x1, y0, x1, y0 + radius); +// cairo_line_to (cr, x1 , y1 - radius); +// cairo_curve_to (cr, x1, y1, x1, y1, x1 - radius, y1); +// cairo_line_to (cr, x0 + radius, y1); +// cairo_curve_to (cr, x0, y1, x0, y1, x0, y1- radius); +// } +// } +// cairo_close_path (cr); +//} +// +//void W_DrawButtonRelief(W_Screen *scr, cairo_t *cairo, int x, int y, unsigned int width, unsigned int height, +// WMReliefType relief, unsigned int pushLight) +//{ +// cairo_save(cairo); +// +// WMColorSpec outerlefttop; +// WMColorSpec innerlefttop; +// WMColorSpec outerbottomright; +// WMColorSpec innerbottomright; +// +//#define NEW_LOOK 1 +//#ifdef NEW_LOOK +//#define TOPFILL WMLightGrayColorSpec() +//#define BOTFILL WMGrayColorSpec() +//#else +//#define TOPFILL WMGrayColorSpec() +//#define BOTFILL WMGrayColorSpec() +//#endif +// +// WMColorSpec topfill = TOPFILL; +// WMColorSpec bottomfill = BOTFILL; +// +// //the highlight colors depend on the button relief +// switch (relief) { +// case WRSimple: +// { +// outerlefttop = WMBlackColorSpec(); +// outerbottomright = WMBlackColorSpec(); +// innerlefttop = WMTransparentColorSpec(); +// innerbottomright = WMTransparentColorSpec(); +// break; +// } +// case WRRaised: +// { +// outerlefttop = WMWhiteColorSpec(); +// outerbottomright = WMBlackColorSpec(); +// innerlefttop = WMTransparentColorSpec(); +// innerbottomright = WMDarkGrayColorSpec(); +// break; +// } +// case WRSunken: +// { +// outerlefttop = WMDarkGrayColorSpec(); +// outerbottomright = WMWhiteColorSpec(); +// innerlefttop = WMBlackColorSpec(); +// innerbottomright = WMTransparentColorSpec(); +// break; +// } +// case WRPushed: +// { +// if (pushLight) { +// topfill = WMWhiteColorSpec(); +// bottomfill = WMWhiteColorSpec(); +// } +// outerlefttop = WMBlackColorSpec(); +// outerbottomright = WMWhiteColorSpec(); +// innerlefttop = WMTransparentColorSpec(); +// innerbottomright = WMTransparentColorSpec(); +// break; +// } +// case WRRidge: +// { +// outerlefttop = WMWhiteColorSpec(); +// outerbottomright = WMDarkGrayColorSpec(); +// innerlefttop = WMTransparentColorSpec(); +// innerbottomright = WMTransparentColorSpec(); +// break; +// } +// case WRGroove: +// { +// outerlefttop = WMDarkGrayColorSpec(); +// outerbottomright = WMDarkGrayColorSpec(); +// innerlefttop = WMTransparentColorSpec(); +// innerbottomright = WMTransparentColorSpec(); +// break; +// } +// } +// +// //draw main gradient +// cairo_pattern_t *linpat; +// linpat = cairo_pattern_create_linear(0, 0, 0, height); +// cairo_pattern_add_color_stop_rgba(linpat, 0, topfill.red/255.0, topfill.green/255.0, topfill.blue/255.0, topfill.alpha/255.0); +// cairo_pattern_add_color_stop_rgba(linpat, 0, bottomfill.red/255.0, bottomfill.green/255.0, bottomfill.blue/255.0, bottomfill.alpha/255.0); +// cairo_set_source(cairo, linpat); +// cairo_rectangle(cairo, 0, 0, width, height); +// cairo_fill(cairo); +// cairo_stroke(cairo); +// +// //draw highlights +// cairo_set_line_width(cairo,1); +// +// WMColorSpecSet(cairo,&outerlefttop); +// cairo_rectangle(cairo,0,0,width-1,0); +// cairo_rectangle(cairo,0,0,0,height-1); +// cairo_stroke(cairo); +// +// WMColorSpecSet(cairo,&innerlefttop); +// cairo_rectangle(cairo,1,1,width-2,0); +// cairo_rectangle(cairo,1,1,0,height-2); +// cairo_stroke(cairo); +// +// WMColorSpecSet(cairo,&innerbottomright); +// cairo_rectangle(cairo,1,height-2,width-1,1); +// cairo_rectangle(cairo,width-2,1,1,height-2); +// cairo_stroke(cairo); +// +// WMColorSpecSet(cairo,&outerbottomright); +// cairo_rectangle(cairo,0,height-1,width,1); +// cairo_rectangle(cairo,width-1,0,1,height); +// cairo_stroke(cairo); +// +// cairo_pattern_destroy(linpat); +// +// cairo_restore(cairo); +//} void W_DrawRelief(W_Screen *scr, cairo_t *cairo, int x, int y, unsigned int width, unsigned int height, WMReliefType relief) { - WMColorSpec b; - WMColorSpec w; - WMColorSpec d; - WMColorSpec l; - - switch (relief) { - case WRSimple: - WMColorSpecSet(cairo, &b); - cairo_rectangle(cairo, x, y, width-1, height-1); - cairo_stroke(cairo); - return; - - case WRRaised: - b= WMBlackColorSpec(); - w= WMWhiteColorSpec(); - d= WMDarkGrayColorSpec(); - l= WMGrayColorSpec(); - break; - - case WRSunken: - l= WMBlackColorSpec(); - b= WMWhiteColorSpec(); - w= WMDarkGrayColorSpec(); - d= WMGrayColorSpec(); - break; - - case WRPushed: - l= w= WMBlackColorSpec(); - d= b= WMWhiteColorSpec(); - break; - - case WRRidge: - l= b= WMDarkGrayColorSpec(); - d= w= WMWhiteColorSpec(); - break; - - case WRGroove: - w= d= WMDarkGrayColorSpec(); - l= b= WMWhiteColorSpec(); - break; - - default: - return; - } - /* top left */ - WMColorSpecSet(cairo, &w); - cairo_move_to(cairo, x, y); - cairo_line_to(cairo, x+width-1, y); - cairo_stroke(cairo); - if (width > 2 && relief != WRRaised && relief!=WRPushed) { - WMColorSpecSet(cairo, &l); - cairo_move_to(cairo, x+1, y+1); - cairo_line_to(cairo, x+width-3, y+1); - cairo_stroke(cairo); - } - - WMColorSpecSet(cairo, &w); - cairo_move_to(cairo, x, y); - cairo_line_to(cairo, x, y+height-1); - cairo_stroke(cairo); - if (height > 2 && relief != WRRaised && relief!=WRPushed) { - WMColorSpecSet(cairo, &l); - cairo_move_to(cairo, x+1, y+1); - cairo_line_to(cairo, x+1, y+height-3); - cairo_stroke(cairo); - } - - /* bottom right */ - WMColorSpecSet(cairo, &b); - cairo_move_to(cairo, x, y+height-1); - cairo_line_to(cairo, x+width-1, y+height-1); - cairo_stroke(cairo); - if (width > 2 && relief!=WRPushed) { - WMColorSpecSet(cairo, &d); - cairo_move_to(cairo, x+1, y+height-2); - cairo_line_to(cairo, x+width-2, y+height-2); - cairo_stroke(cairo); - } - - WMColorSpecSet(cairo, &b); - cairo_move_to(cairo, x+width-1, y); - cairo_line_to(cairo, x+width-1, y+height-1); - cairo_stroke(cairo); - if (height > 2 && relief!=WRPushed) { - WMColorSpecSet(cairo, &d); - cairo_move_to(cairo, x+width-2, y+1); - cairo_line_to(cairo, x+width-2, y+height-2); - cairo_stroke(cairo); - } +// WMColorSpec b; +// WMColorSpec w; +// WMColorSpec d; +// WMColorSpec l; +// +// switch (relief) { +// case WRSimple: +// WMColorSpecSet(cairo, &b); +// cairo_rectangle(cairo, x, y, width-1, height-1); +// cairo_stroke(cairo); +// return; +// +// case WRRaised: +// b= WMBlackColorSpec(); +// w= WMWhiteColorSpec(); +// d= WMDarkGrayColorSpec(); +// l= WMGrayColorSpec(); +// break; +// +// case WRSunken: +// l= WMBlackColorSpec(); +// b= WMWhiteColorSpec(); +// w= WMDarkGrayColorSpec(); +// d= WMGrayColorSpec(); +// break; +// +// case WRPushed: +// l= w= WMBlackColorSpec(); +// d= b= WMWhiteColorSpec(); +// break; +// +// case WRRidge: +// l= b= WMDarkGrayColorSpec(); +// d= w= WMWhiteColorSpec(); +// break; +// +// case WRGroove: +// w= d= WMDarkGrayColorSpec(); +// l= b= WMWhiteColorSpec(); +// break; +// +// default: +// return; +// } +// /* top left */ +// WMColorSpecSet(cairo, &w); +// cairo_move_to(cairo, x, y); +// cairo_line_to(cairo, x+width-1, y); +// cairo_stroke(cairo); +// if (width > 2 && relief != WRRaised && relief!=WRPushed) { +// WMColorSpecSet(cairo, &l); +// cairo_move_to(cairo, x+1, y+1); +// cairo_line_to(cairo, x+width-3, y+1); +// cairo_stroke(cairo); +// } +// +// WMColorSpecSet(cairo, &w); +// cairo_move_to(cairo, x, y); +// cairo_line_to(cairo, x, y+height-1); +// cairo_stroke(cairo); +// if (height > 2 && relief != WRRaised && relief!=WRPushed) { +// WMColorSpecSet(cairo, &l); +// cairo_move_to(cairo, x+1, y+1); +// cairo_line_to(cairo, x+1, y+height-3); +// cairo_stroke(cairo); +// } +// +// /* bottom right */ +// WMColorSpecSet(cairo, &b); +// cairo_move_to(cairo, x, y+height-1); +// cairo_line_to(cairo, x+width-1, y+height-1); +// cairo_stroke(cairo); +// if (width > 2 && relief!=WRPushed) { +// WMColorSpecSet(cairo, &d); +// cairo_move_to(cairo, x+1, y+height-2); +// cairo_line_to(cairo, x+width-2, y+height-2); +// cairo_stroke(cairo); +// } +// +// WMColorSpecSet(cairo, &b); +// cairo_move_to(cairo, x+width-1, y); +// cairo_line_to(cairo, x+width-1, y+height-1); +// cairo_stroke(cairo); +// if (height > 2 && relief!=WRPushed) { +// WMColorSpecSet(cairo, &d); +// cairo_move_to(cairo, x+width-2, y+1); +// cairo_line_to(cairo, x+width-2, y+height-2); +// cairo_stroke(cairo); +// } } static int findNextWord(const char *text, int limit) @@ -225,7 +284,7 @@ static int fitText(const char *text, WMFont * font, int width, int wrap) if (!wrap || beforecrlf == 0) return beforecrlf; - //XXX w = WMWidthOfString(font, text, beforecrlf); + w = WMWidthOfString(font, text); if (w <= width) { /* text up to first crlf fits */ return beforecrlf; @@ -236,14 +295,14 @@ static int fitText(const char *text, WMFont * font, int width, int wrap) word2 = word1 + findNextWord(text + word1, beforecrlf - word1); if (word2 >= beforecrlf) break; - //XXXw = WMWidthOfString(font, text, word2); + w = WMWidthOfString(font, text); if (w > width) break; word1 = word2; } for (i = word1; i < word2; i++) { - //XXXw = WMWidthOfString(font, text, i); + w = WMWidthOfString(font, text); if (w > width) { break; } @@ -331,35 +390,35 @@ void W_PaintText(cairo_t *cairo, WMFont *font, int x, int y, int count; int fheight = WMFontHeight(font); - //line_x= x + (width - WMWidthOfString(font, ptr))/2; - //WMDrawString(cairo, color, font, line_x, y, ptr); - //return; - - while (length > 0) { - count = fitText(ptr, font, width, wrap); - - line_width = WMWidthOfString(font, text); - - if (alignment == WALeft) - line_x = x; - else if (alignment == WARight) - line_x = x + width - line_width; - else - line_x = x + (width - line_width) / 2; - - WMDrawString(cairo, color, font, line_x, y, ptr); - - if (wrap && ptr[count] != '\n') - y += fheight; - - while (ptr[count] && ptr[count] == '\n') { - y += fheight; - count++; - } - - ptr += count; - length -= count; - } + line_x= x + (width - WMWidthOfString(font, ptr))/2; + WMDrawString(cairo, color, font, line_x, y, ptr); + return; + +// while (length > 0) { +// count = fitText(ptr, font, width, wrap); +// +// line_width = WMWidthOfString(font, text); +// +// if (alignment == WALeft) +// line_x = x; +// else if (alignment == WARight) +// line_x = x + width - line_width; +// else +// line_x = x + (width - line_width) / 2; +// +// WMDrawString(cairo, color, font, line_x, y, ptr); +// +// if (wrap && ptr[count] != '\n') +// y += fheight; +// +// while (ptr[count] && ptr[count] == '\n') { +// y += fheight; +// count++; +// } +// +// ptr += count; +// length -= count; +// } } void W_PaintTextAndImage(W_Screen *screen, cairo_t *cairo, W_View *view, int wrap, WMColorSpec *textColor, W_Font *font, @@ -372,12 +431,6 @@ void W_PaintTextAndImage(W_Screen *screen, cairo_t *cairo, W_View *view, int wra cairo_save(cairo); - if (backColor) - { - cairo_rectangle(cairo, 0, 0, view->size.width, view->size.height); - WMColorSpecSet(cairo, backColor); - cairo_fill(cairo); - } if (relief == WRFlat) { x = 0; y = 0; @@ -458,7 +511,7 @@ void W_PaintTextAndImage(W_Screen *screen, cairo_t *cairo, W_View *view, int wra } /* draw relief */ - W_DrawRelief(screen, cairo, 0, 0, view->size.width, view->size.height, relief); + //W_DrawRelief(screen, cairo, 0, 0, view->size.width, view->size.height, relief); } WMPoint wmkpoint(int x, int y) diff --git a/WINGs/wtheme.c b/WINGs/wtheme.c new file mode 100644 index 0000000..6d6c148 --- /dev/null +++ b/WINGs/wtheme.c @@ -0,0 +1,8 @@ +#include <wtheme.h> + +#define NEW_THEME +#ifdef NEW_THEME +#include <newtheme.c> +#else +#include <oldtheme.c> +#endif diff --git a/WINGs/wview.c b/WINGs/wview.c index d0893ea..c3806bc 100644 --- a/WINGs/wview.c +++ b/WINGs/wview.c @@ -109,7 +109,7 @@ static W_View *createView(W_Screen * screen, W_View * parent) view->attribs = defAtts; view->attribFlags |= CWBackPixel|CWColormap|CWBorderPixel; - view->attribs.background_pixel = WMCreateRGBAColor(screen,0,0,0,0,0); + view->attribs.background_pixel = WhitePixel(screen->display,screen->screen); view->attribs.border_pixel = 0; view->attribs.colormap = screen->colormap; @@ -405,12 +405,12 @@ cairo_t* W_CreateCairoForView(W_View *view) cairo_surface_t *surface; cairo_t *cairo; - surface= cairo_xlib_surface_create(W_VIEW_DISPLAY(view), + surface = cairo_xlib_surface_create(W_VIEW_DISPLAY(view), W_VIEW_DRAWABLE(view), W_VIEW_SCREEN(view)->visual, W_VIEW_WIDTH(view), W_VIEW_HEIGHT(view)); - cairo= cairo_create(surface); + cairo = cairo_create(surface); cairo_surface_destroy(surface); cairo_translate(cairo, 0.5, 0.5); cairo_set_line_width(cairo, 1.0); diff --git a/test/cairo/draw.c b/test/cairo/draw.c index 515d4b6..ba4a4b2 100644 --- a/test/cairo/draw.c +++ b/test/cairo/draw.c @@ -11,111 +11,44 @@ * cairo code you want to try in draw and very quickly see the results * -- JH */ -static void curve_rectangle(cairo_t *cr, - double x0, double y0, double rect_width, double rect_height, - double radius) -{ - double x1,y1; - - x1=x0+rect_width; - y1=y0+rect_height; - if (!rect_width || !rect_height) - return; - if (rect_width/2<radius) { - if (rect_height/2<radius) { - cairo_move_to (cr, x0, (y0 + y1)/2); - cairo_curve_to (cr, x0 ,y0, x0, y0, (x0 + x1)/2, y0); - cairo_curve_to (cr, x1, y0, x1, y0, x1, (y0 + y1)/2); - cairo_curve_to (cr, x1, y1, x1, y1, (x1 + x0)/2, y1); - cairo_curve_to (cr, x0, y1, x0, y1, x0, (y0 + y1)/2); - } else { - cairo_move_to (cr, x0, y0 + radius); - cairo_curve_to (cr, x0 ,y0, x0, y0, (x0 + x1)/2, y0); - cairo_curve_to (cr, x1, y0, x1, y0, x1, y0 + radius); - cairo_line_to (cr, x1 , y1 - radius); - cairo_curve_to (cr, x1, y1, x1, y1, (x1 + x0)/2, y1); - cairo_curve_to (cr, x0, y1, x0, y1, x0, y1- radius); - } - } else { - if (rect_height/2<radius) { - cairo_move_to (cr, x0, (y0 + y1)/2); - cairo_curve_to (cr, x0 , y0, x0 , y0, x0 + radius, y0); - cairo_line_to (cr, x1 - radius, y0); - cairo_curve_to (cr, x1, y0, x1, y0, x1, (y0 + y1)/2); - cairo_curve_to (cr, x1, y1, x1, y1, x1 - radius, y1); - cairo_line_to (cr, x0 + radius, y1); - cairo_curve_to (cr, x0, y1, x0, y1, x0, (y0 + y1)/2); - } else { - cairo_move_to (cr, x0, y0 + radius); - cairo_curve_to (cr, x0 , y0, x0 , y0, x0 + radius, y0); - cairo_line_to (cr, x1 - radius, y0); - cairo_curve_to (cr, x1, y0, x1, y0, x1, y0 + radius); - cairo_line_to (cr, x1 , y1 - radius); - cairo_curve_to (cr, x1, y1, x1, y1, x1 - radius, y1); - cairo_line_to (cr, x0 + radius, y1); - cairo_curve_to (cr, x0, y1, x0, y1, x0, y1- radius); - } - } - cairo_close_path (cr); -} void draw(Display *dpy, Screen *scr, Visual *vis, Window win) { cairo_surface_t *surf; cairo_t *ct; - - int width=200; - int height = 50; - int x = 10; - int y = 10; - - unsigned char border[4]= {0x00, 0x00, 0x00, 0x70}; - //unsigned char color1[4]= {0x8c, 0xb1, 0xbc, 0xff}; - //unsigned char color2[4]= {0xcb, 0xf3, 0xff, 0xff}; - unsigned char color1[4]= {0x0, 0x0, 0x0, 0xff}; - unsigned char color2[4]= {0xcf, 0xcf, 0xcf, 0xff}; - unsigned char scolor1[4]= {0xff, 0xff, 0xff, 0xe5}; - unsigned char scolor2[4]= {0xff, 0xff, 0xff, 0x70}; + cairo_pattern_t *linpat; + int height = 35; + int width = 130; surf = (cairo_surface_t *) cairo_xlib_surface_create(dpy, win, vis, 500, 500); ct = cairo_create(surf); - cairo_pattern_t *shine; - cairo_pattern_t *base; - - shine= cairo_pattern_create_linear(0, 0, 0, height*2/5); - cairo_pattern_add_color_stop_rgba(shine, 0, - scolor1[0]/255.0, scolor1[1]/255.0, scolor1[2]/255.0, - scolor1[3]/255.0); - cairo_pattern_add_color_stop_rgba(shine, 1, - scolor2[0]/255.0, scolor2[1]/255.0, scolor2[2]/255.0, - scolor2[3]/255.0); - - base= cairo_pattern_create_linear(0, 0, 0, height-1); - cairo_pattern_add_color_stop_rgba(base, 0, - color1[0]/255.0, color1[1]/255.0, color1[2]/255.0, - color1[3]/255.0); - cairo_pattern_add_color_stop_rgba(base, 1, - color2[0]/255.0, color2[1]/255.0, color2[2]/255.0, - color2[3]/255.0); - - - curve_rectangle(ct, x, y, width-1, height-1, height*2/3); - cairo_set_source(ct, base); - cairo_fill_preserve(ct); - cairo_clip(ct); - - curve_rectangle(ct, x, y, width-1, height*2/5, width); - cairo_set_source(ct, shine); + //cairo_set_line_width(ct, 1); + + linpat = cairo_pattern_create_linear(0,0,0,height); + cairo_pattern_add_color_stop_rgb(linpat, 0, 194.0/255, 190.0/255, 194.0/255); + cairo_pattern_add_color_stop_rgb(linpat, 1, 174.0/255, 170.0/255, 174.0/255); + cairo_set_source(ct,linpat); + cairo_rectangle(ct,0,0,width,height); cairo_fill(ct); - curve_rectangle(ct, x, y, width-1, height-1, height*2/3); - cairo_set_source_rgba(ct, border[0]/255.0, border[1]/255.0, border[2]/255.0, border[3]/255.0); - cairo_set_line_width(ct, 2.0); - cairo_stroke(ct); + cairo_set_source_rgb(ct, 1, 1, 1); + cairo_rectangle(ct,0,0,1,height-1); + cairo_rectangle(ct,0,0,width-1,1); + cairo_fill(ct); + + cairo_set_source_rgb(ct, 81.0/255, 85.0/255, 81.0/255); + cairo_rectangle(ct,1,height-2,width-1,1); + cairo_rectangle(ct,width-2,1,1,height-1); + cairo_fill(ct); - cairo_pattern_destroy(shine); - cairo_pattern_destroy(base); + cairo_set_source_rgb(ct, 0, 0, 0); + cairo_rectangle(ct,0,height-1,width,1); + cairo_rectangle(ct,width-1,0,1,height); + cairo_fill(ct); + + cairo_stroke(ct); + cairo_pattern_destroy(linpat); cairo_destroy(ct); cairo_surface_destroy(surf); } -- 1.6.0.3
