6 //static void curve_rectangle(cairo_t *cr,
7 // double x0, double y0, double rect_width, double rect_height,
14 // if (!rect_width || !rect_height)
16 // if (rect_width/2<radius) {
17 // if (rect_height/2<radius) {
18 // cairo_move_to (cr, x0, (y0 + y1)/2);
19 // cairo_curve_to (cr, x0 ,y0, x0, y0, (x0 + x1)/2, y0);
20 // cairo_curve_to (cr, x1, y0, x1, y0, x1, (y0 + y1)/2);
21 // cairo_curve_to (cr, x1, y1, x1, y1, (x1 + x0)/2, y1);
22 // cairo_curve_to (cr, x0, y1, x0, y1, x0, (y0 + y1)/2);
24 // cairo_move_to (cr, x0, y0 + radius);
25 // cairo_curve_to (cr, x0 ,y0, x0, y0, (x0 + x1)/2, y0);
26 // cairo_curve_to (cr, x1, y0, x1, y0, x1, y0 + radius);
27 // cairo_line_to (cr, x1 , y1 - radius);
28 // cairo_curve_to (cr, x1, y1, x1, y1, (x1 + x0)/2, y1);
29 // cairo_curve_to (cr, x0, y1, x0, y1, x0, y1- radius);
32 // if (rect_height/2<radius) {
33 // cairo_move_to (cr, x0, (y0 + y1)/2);
34 // cairo_curve_to (cr, x0 , y0, x0 , y0, x0 + radius, y0);
35 // cairo_line_to (cr, x1 - radius, y0);
36 // cairo_curve_to (cr, x1, y0, x1, y0, x1, (y0 + y1)/2);
37 // cairo_curve_to (cr, x1, y1, x1, y1, x1 - radius, y1);
38 // cairo_line_to (cr, x0 + radius, y1);
39 // cairo_curve_to (cr, x0, y1, x0, y1, x0, (y0 + y1)/2);
41 // cairo_move_to (cr, x0, y0 + radius);
42 // cairo_curve_to (cr, x0 , y0, x0 , y0, x0 + radius, y0);
43 // cairo_line_to (cr, x1 - radius, y0);
44 // cairo_curve_to (cr, x1, y0, x1, y0, x1, y0 + radius);
45 // cairo_line_to (cr, x1 , y1 - radius);
46 // cairo_curve_to (cr, x1, y1, x1, y1, x1 - radius, y1);
47 // cairo_line_to (cr, x0 + radius, y1);
48 // cairo_curve_to (cr, x0, y1, x0, y1, x0, y1- radius);
51 // cairo_close_path (cr);
54 //void W_DrawButtonRelief(W_Screen *scr, cairo_t *cairo, int x, int y, unsigned int width, unsigned int height,
55 // WMReliefType relief, unsigned int pushLight)
59 // WMColorSpec outerlefttop;
60 // WMColorSpec innerlefttop;
61 // WMColorSpec outerbottomright;
62 // WMColorSpec innerbottomright;
66 //#define TOPFILL WMLightGrayColorSpec()
67 //#define BOTFILL WMGrayColorSpec()
69 //#define TOPFILL WMGrayColorSpec()
70 //#define BOTFILL WMGrayColorSpec()
73 // WMColorSpec topfill = TOPFILL;
74 // WMColorSpec bottomfill = BOTFILL;
76 // //the highlight colors depend on the button relief
80 // outerlefttop = WMBlackColorSpec();
81 // outerbottomright = WMBlackColorSpec();
82 // innerlefttop = WMTransparentColorSpec();
83 // innerbottomright = WMTransparentColorSpec();
88 // outerlefttop = WMWhiteColorSpec();
89 // outerbottomright = WMBlackColorSpec();
90 // innerlefttop = WMTransparentColorSpec();
91 // innerbottomright = WMDarkGrayColorSpec();
96 // outerlefttop = WMDarkGrayColorSpec();
97 // outerbottomright = WMWhiteColorSpec();
98 // innerlefttop = WMBlackColorSpec();
99 // innerbottomright = WMTransparentColorSpec();
105 // topfill = WMWhiteColorSpec();
106 // bottomfill = WMWhiteColorSpec();
108 // outerlefttop = WMBlackColorSpec();
109 // outerbottomright = WMWhiteColorSpec();
110 // innerlefttop = WMTransparentColorSpec();
111 // innerbottomright = WMTransparentColorSpec();
116 // outerlefttop = WMWhiteColorSpec();
117 // outerbottomright = WMDarkGrayColorSpec();
118 // innerlefttop = WMTransparentColorSpec();
119 // innerbottomright = WMTransparentColorSpec();
124 // outerlefttop = WMDarkGrayColorSpec();
125 // outerbottomright = WMDarkGrayColorSpec();
126 // innerlefttop = WMTransparentColorSpec();
127 // innerbottomright = WMTransparentColorSpec();
132 // //draw main gradient
133 // cairo_pattern_t *linpat;
134 // linpat = cairo_pattern_create_linear(0, 0, 0, height);
135 // cairo_pattern_add_color_stop_rgba(linpat, 0, topfill.red/255.0, topfill.green/255.0, topfill.blue/255.0, topfill.alpha/255.0);
136 // cairo_pattern_add_color_stop_rgba(linpat, 0, bottomfill.red/255.0, bottomfill.green/255.0, bottomfill.blue/255.0, bottomfill.alpha/255.0);
137 // cairo_set_source(cairo, linpat);
138 // cairo_rectangle(cairo, 0, 0, width, height);
139 // cairo_fill(cairo);
140 // cairo_stroke(cairo);
143 // cairo_set_line_width(cairo,1);
145 // WMColorSpecSet(cairo,&outerlefttop);
146 // cairo_rectangle(cairo,0,0,width-1,0);
147 // cairo_rectangle(cairo,0,0,0,height-1);
148 // cairo_stroke(cairo);
150 // WMColorSpecSet(cairo,&innerlefttop);
151 // cairo_rectangle(cairo,1,1,width-2,0);
152 // cairo_rectangle(cairo,1,1,0,height-2);
153 // cairo_stroke(cairo);
155 // WMColorSpecSet(cairo,&innerbottomright);
156 // cairo_rectangle(cairo,1,height-2,width-1,1);
157 // cairo_rectangle(cairo,width-2,1,1,height-2);
158 // cairo_stroke(cairo);
160 // WMColorSpecSet(cairo,&outerbottomright);
161 // cairo_rectangle(cairo,0,height-1,width,1);
162 // cairo_rectangle(cairo,width-1,0,1,height);
163 // cairo_stroke(cairo);
165 // cairo_pattern_destroy(linpat);
167 // cairo_restore(cairo);
170 void W_DrawRelief(W_Screen
*scr
, cairo_t
*cairo
, int x
, int y
, unsigned int width
, unsigned int height
,
180 // WMColorSpecSet(cairo, &b);
181 // cairo_rectangle(cairo, x, y, width-1, height-1);
182 // cairo_stroke(cairo);
186 // b= WMBlackColorSpec();
187 // w= WMWhiteColorSpec();
188 // d= WMDarkGrayColorSpec();
189 // l= WMGrayColorSpec();
193 // l= WMBlackColorSpec();
194 // b= WMWhiteColorSpec();
195 // w= WMDarkGrayColorSpec();
196 // d= WMGrayColorSpec();
200 // l= w= WMBlackColorSpec();
201 // d= b= WMWhiteColorSpec();
205 // l= b= WMDarkGrayColorSpec();
206 // d= w= WMWhiteColorSpec();
210 // w= d= WMDarkGrayColorSpec();
211 // l= b= WMWhiteColorSpec();
218 // WMColorSpecSet(cairo, &w);
219 // cairo_move_to(cairo, x, y);
220 // cairo_line_to(cairo, x+width-1, y);
221 // cairo_stroke(cairo);
222 // if (width > 2 && relief != WRRaised && relief!=WRPushed) {
223 // WMColorSpecSet(cairo, &l);
224 // cairo_move_to(cairo, x+1, y+1);
225 // cairo_line_to(cairo, x+width-3, y+1);
226 // cairo_stroke(cairo);
229 // WMColorSpecSet(cairo, &w);
230 // cairo_move_to(cairo, x, y);
231 // cairo_line_to(cairo, x, y+height-1);
232 // cairo_stroke(cairo);
233 // if (height > 2 && relief != WRRaised && relief!=WRPushed) {
234 // WMColorSpecSet(cairo, &l);
235 // cairo_move_to(cairo, x+1, y+1);
236 // cairo_line_to(cairo, x+1, y+height-3);
237 // cairo_stroke(cairo);
240 // /* bottom right */
241 // WMColorSpecSet(cairo, &b);
242 // cairo_move_to(cairo, x, y+height-1);
243 // cairo_line_to(cairo, x+width-1, y+height-1);
244 // cairo_stroke(cairo);
245 // if (width > 2 && relief!=WRPushed) {
246 // WMColorSpecSet(cairo, &d);
247 // cairo_move_to(cairo, x+1, y+height-2);
248 // cairo_line_to(cairo, x+width-2, y+height-2);
249 // cairo_stroke(cairo);
252 // WMColorSpecSet(cairo, &b);
253 // cairo_move_to(cairo, x+width-1, y);
254 // cairo_line_to(cairo, x+width-1, y+height-1);
255 // cairo_stroke(cairo);
256 // if (height > 2 && relief!=WRPushed) {
257 // WMColorSpecSet(cairo, &d);
258 // cairo_move_to(cairo, x+width-2, y+1);
259 // cairo_line_to(cairo, x+width-2, y+height-2);
260 // cairo_stroke(cairo);
264 static int findNextWord(const char *text
, int limit
)
269 len
= strcspn(text
, " \t\n\r");
270 pos
= len
+ strspn(text
+ len
, " \t\n\r");
277 static int fitText(const char *text
, WMFont
* font
, int width
, int wrap
)
279 int i
, w
, beforecrlf
, word1
, word2
;
281 /* text length before first cr/lf */
282 beforecrlf
= strcspn(text
, "\n");
284 if (!wrap
|| beforecrlf
== 0)
287 w
= WMWidthOfString(font
, text
);
289 /* text up to first crlf fits */
295 word2
= word1
+ findNextWord(text
+ word1
, beforecrlf
- word1
);
296 if (word2
>= beforecrlf
)
298 w
= WMWidthOfString(font
, text
);
304 for (i
= word1
; i
< word2
; i
++) {
305 w
= WMWidthOfString(font
, text
);
311 /* keep words complete if possible */
312 if (!isspace(text
[i
]) && word1
> 0) {
314 } else if (isspace(text
[i
]) && i
< beforecrlf
) {
315 /* keep space on current row, so new row has next word in column 1 */
323 static int fitText(char *text
, WMFont
* font
, int width
, int wrap
)
338 w
= WMWidthOfString(font
, text
, i
);
339 } while (w
< width
&& text
[i
] != '\n' && text
[i
] != 0);
344 /* keep words complete */
345 if (!isspace(text
[i
])) {
347 while (j
> 1 && !isspace(text
[j
]) && text
[j
] != 0)
353 i
= strcspn(text
, "\n");
359 int W_GetTextHeight(cairo_t
*cairo
, WMFont
*font
, const char *text
, int width
, int wrap
)
361 const char *ptr
= text
;
363 int length
= strlen(text
);
365 int fheight
= WMFontHeight(font
);
369 count
= fitText(ptr
, font
, width
, wrap
);
373 if (isspace(ptr
[count
]))
382 void W_PaintText(cairo_t
*cairo
, WMFont
*font
, int x
, int y
,
383 int width
, WMAlignment alignment
, WMColorSpec
*color
,
384 int wrap
, const char *text
)
386 const char *ptr
= text
;
387 int length
= strlen(ptr
);
391 int fheight
= WMFontHeight(font
);
393 if (alignment
== WALeft
)
395 else if (alignment
== WARight
)
396 line_x
= x
+ width
- WMWidthOfString(font
,ptr
);
398 line_x
= x
+ (width
- WMWidthOfString(font
,ptr
)) / 2;
399 WMDrawString(cairo
, color
, font
, line_x
, y
, ptr
);
402 // while (length > 0) {
403 // count = fitText(ptr, font, width, wrap);
405 // line_width = WMWidthOfString(font, text);
407 // if (alignment == WALeft)
409 // else if (alignment == WARight)
410 // line_x = x + width - line_width;
412 // line_x = x + (width - line_width) / 2;
414 // WMDrawString(cairo, color, font, line_x, y, ptr);
416 // if (wrap && ptr[count] != '\n')
419 // while (ptr[count] && ptr[count] == '\n') {
429 void W_PaintTextAndImage(W_Screen
*screen
, cairo_t
*cairo
, W_View
*view
, int wrap
, WMColorSpec
*textColor
, W_Font
*font
,
430 WMReliefType relief
, const char *text
,
431 WMAlignment alignment
, WMImage
*image
,
432 WMImagePosition position
, WMColorSpec
*backColor
, int ofs
)
439 if (relief
== WRFlat
) {
442 w
= view
->size
.width
;
443 h
= view
->size
.height
;
447 w
= view
->size
.width
- 3;
448 h
= view
->size
.height
- 3;
451 /* calc. image alignment */
452 if (position
!= WIPNoImage
&& image
!= NULL
) {
456 ix
= (view
->size
.width
- WMGetImageWidth(image
)) / 2;
457 iy
= (view
->size
.height
- WMGetImageHeight(image
)) / 2;
466 iy
= y
+ (h
- WMGetImageHeight(image
)) / 2;
467 x
= x
+ WMGetImageWidth(image
) + 5;
469 w
-= WMGetImageWidth(image
) + 5;
473 ix
= view
->size
.width
- WMGetImageWidth(image
) - x
;
474 iy
= y
+ (h
- WMGetImageHeight(image
)) / 2;
475 w
-= WMGetImageWidth(image
) + 5;
479 ix
= (view
->size
.width
- WMGetImageWidth(image
)) / 2;
480 iy
= h
- WMGetImageHeight(image
);
482 h
-= WMGetImageHeight(image
);
487 ix
= (view
->size
.width
- WMGetImageWidth(image
)) / 2;
489 y
= WMGetImageHeight(image
);
490 h
-= WMGetImageHeight(image
);
494 cairo_set_operator(cairo
,CAIRO_OPERATOR_SOURCE
);
497 cairo_set_source_surface(cairo
,image
,ix
+0.5,iy
+0.5);
498 cairo_mask_surface(cairo
,image
,ix
+0.5,iy
+0.5);
500 cairo_set_operator(cairo
,CAIRO_OPERATOR_OVER
);
505 if (position
!= WIPImageOnly
&& text
!=NULL
) {
508 textHeight
= W_GetTextHeight(cairo
, font
, text
, w
-8, wrap
);
509 W_PaintText(cairo
, font
, x
+ofs
+4, y
+ofs
+ (h
-textHeight
)/2, w
-8,
510 alignment
, textColor
, wrap
, text
);
513 cairo_restore(cairo
);
515 //W_DrawRelief(screen, cairo, 0, 0, view->size.width, view->size.height, relief);
518 WMPoint
wmkpoint(int x
, int y
)
528 WMSize
wmksize(unsigned int width
, unsigned int height
)
533 size
.height
= height
;
538 WMRect
wmkrect(int x
, int y
, unsigned int width
, unsigned int height
)
544 rect
.size
.width
= width
;
545 rect
.size
.height
= height
;