From f2f17eca8134e3c44c48221f544fd739e7d33f76 Mon Sep 17 00:00:00 2001 From: Johann Haarhoff Date: Mon, 29 Mar 2010 21:58:14 +0200 Subject: [PATCH] WINGs buttons and labels now have text Running WINGs/Tests/wtest now draws a label and some buttons with text on them. --- WINGs/Tests/wtest.c | 5 ++- WINGs/WINGs/WINGs.h | 2 +- WINGs/wbutton.c | 4 +- WINGs/wfont.c | 2 +- WINGs/wmisc.c | 9 +++-- test/cairo/draw.c | 109 +++++++++++++++++++++++++++++++++++++++++++++------- 6 files changed, 108 insertions(+), 23 deletions(-) diff --git a/WINGs/Tests/wtest.c b/WINGs/Tests/wtest.c index b1ba52b3..b3bb54f2 100644 --- a/WINGs/Tests/wtest.c +++ b/WINGs/Tests/wtest.c @@ -253,6 +253,7 @@ void testList(WMScreen * scr) WMMapSubwidgets(win); WMMapWidget(win); } +#endif void testButton(WMScreen * scr) { @@ -289,7 +290,6 @@ void testButton(WMScreen * scr) WMMapSubwidgets(win); WMMapWidget(win); } -#endif #ifdef obsolete void testGradientButtons(WMScreen * scr) @@ -540,7 +540,7 @@ void testStuff(WMScreen *scr) button= WMCreateCommandButton(win); WMSetButtonText(button, "OK"); WMResizeWidget(button, 80, 24); - WMMoveWidget(button, 400-80-12, 300-24-12); + WMMoveWidget(button, 400-80-12, 200-24-12); button= WMCreateCommandButton(win); WMSetButtonText(button, "Cancel"); @@ -1008,6 +1008,7 @@ int main(int argc, char **argv) * Put the testSomething() function you want to test here. */ testStuff(scr); + testButton(scr); #if 0 testText(scr); diff --git a/WINGs/WINGs/WINGs.h b/WINGs/WINGs/WINGs.h index cad8d9d0..43e4b7a9 100644 --- a/WINGs/WINGs/WINGs.h +++ b/WINGs/WINGs/WINGs.h @@ -866,7 +866,7 @@ WMColorSpec WMDarkGrayColorSpec(); void WMDrawString(cairo_t *cairo, WMColorSpec *color, WMFont *font, int x, int y, char *text); -int WMWidthOfString(WMFont *font, char *text); +int WMWidthOfString(WMFont *font, const char *text); diff --git a/WINGs/wbutton.c b/WINGs/wbutton.c index 00bdb72e..77e4cdd0 100644 --- a/WINGs/wbutton.c +++ b/WINGs/wbutton.c @@ -497,7 +497,7 @@ static void paintButton(Button * bPtr) caption = bPtr->altCaption; if (bPtr->altImage) image = bPtr->altImage; - textColor = bPtr->altTextColor; + textColor = bPtr->altTextColor; } if (bPtr->flags.statePush && bPtr->flags.bordered) { @@ -521,7 +521,7 @@ static void paintButton(Button * bPtr) caption = bPtr->altCaption; if (bPtr->altImage) image = bPtr->altImage; - textColor = bPtr->altTextColor; + textColor = bPtr->altTextColor; } } diff --git a/WINGs/wfont.c b/WINGs/wfont.c index d6f616a2..775ef88b 100644 --- a/WINGs/wfont.c +++ b/WINGs/wfont.c @@ -290,7 +290,7 @@ WMFont *WMBoldSystemFontOfSize(WMScreen * scrPtr, int size) return font; } -int WMWidthOfString(WMFont *font, char *text) +int WMWidthOfString(WMFont *font, const char *text) { cairo_text_extents_t extents; diff --git a/WINGs/wmisc.c b/WINGs/wmisc.c index b5efbb04..04136548 100644 --- a/WINGs/wmisc.c +++ b/WINGs/wmisc.c @@ -331,14 +331,15 @@ 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; + //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); - //XXX line_width = WMWidthOfString(font, ptr, count); + line_width = WMWidthOfString(font, text); + if (alignment == WALeft) line_x = x; else if (alignment == WARight) diff --git a/test/cairo/draw.c b/test/cairo/draw.c index aded6981..515d4b60 100644 --- a/test/cairo/draw.c +++ b/test/cairo/draw.c @@ -11,27 +11,110 @@ * 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