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
,
57 unsigned char border
[4]= {0x00, 0x00, 0x00, 0x70};
58 //unsigned char color1[4]= {0x8c, 0xb1, 0xbc, 0xff};
59 //unsigned char color2[4]= {0xcb, 0xf3, 0xff, 0xff};
60 unsigned char color1
[4]= {0x0, 0x0, 0x0, 0xff};
61 unsigned char color2
[4]= {0xcf, 0xcf, 0xcf, 0xff};
62 unsigned char scolor1
[4]= {0xff, 0xff, 0xff, 0xe5};
63 unsigned char scolor2
[4]= {0xff, 0xff, 0xff, 0x70};
64 cairo_pattern_t
*shine
;
65 cairo_pattern_t
*base
;
74 shine
= cairo_pattern_create_linear(0, 0, 0, height
*2/5);
75 cairo_pattern_add_color_stop_rgba(shine
, 0,
76 scolor1
[0]/255.0, scolor1
[1]/255.0, scolor1
[2]/255.0,
78 cairo_pattern_add_color_stop_rgba(shine
, 1,
79 scolor2
[0]/255.0, scolor2
[1]/255.0, scolor2
[2]/255.0,
82 base
= cairo_pattern_create_linear(0, 0, 0, height
-1);
83 cairo_pattern_add_color_stop_rgba(base
, 0,
84 color1
[0]/255.0, color1
[1]/255.0, color1
[2]/255.0,
86 cairo_pattern_add_color_stop_rgba(base
, 1,
87 color2
[0]/255.0, color2
[1]/255.0, color2
[2]/255.0,
91 curve_rectangle(cairo
, x
, y
, width
-1, height
-1, height
*2/3);
92 cairo_set_source(cairo
, base
);
93 cairo_fill_preserve(cairo
);
96 curve_rectangle(cairo
, x
, y
, width
-1, height
*2/5, width
);
97 cairo_set_source(cairo
, shine
);
100 curve_rectangle(cairo
, x
, y
, width
-1, height
-1, height
*2/3);
101 cairo_set_source_rgba(cairo
, border
[0]/255.0, border
[1]/255.0, border
[2]/255.0, border
[3]/255.0);
102 cairo_set_line_width(cairo
, 2.0);
105 cairo_pattern_destroy(shine
);
106 cairo_pattern_destroy(base
);
108 cairo_restore(cairo
);
111 void W_DrawRelief(W_Screen
*scr
, cairo_t
*cairo
, int x
, int y
, unsigned int width
, unsigned int height
,
121 WMColorSpecSet(cairo
, &b
);
122 cairo_rectangle(cairo
, x
, y
, width
-1, height
-1);
127 b
= WMBlackColorSpec();
128 w
= WMWhiteColorSpec();
129 d
= WMDarkGrayColorSpec();
130 l
= WMGrayColorSpec();
134 l
= WMBlackColorSpec();
135 b
= WMWhiteColorSpec();
136 w
= WMDarkGrayColorSpec();
137 d
= WMGrayColorSpec();
141 l
= w
= WMBlackColorSpec();
142 d
= b
= WMWhiteColorSpec();
146 l
= b
= WMDarkGrayColorSpec();
147 d
= w
= WMWhiteColorSpec();
151 w
= d
= WMDarkGrayColorSpec();
152 l
= b
= WMWhiteColorSpec();
159 WMColorSpecSet(cairo
, &w
);
160 cairo_move_to(cairo
, x
, y
);
161 cairo_line_to(cairo
, x
+width
-1, y
);
163 if (width
> 2 && relief
!= WRRaised
&& relief
!=WRPushed
) {
164 WMColorSpecSet(cairo
, &l
);
165 cairo_move_to(cairo
, x
+1, y
+1);
166 cairo_line_to(cairo
, x
+width
-3, y
+1);
170 WMColorSpecSet(cairo
, &w
);
171 cairo_move_to(cairo
, x
, y
);
172 cairo_line_to(cairo
, x
, y
+height
-1);
174 if (height
> 2 && relief
!= WRRaised
&& relief
!=WRPushed
) {
175 WMColorSpecSet(cairo
, &l
);
176 cairo_move_to(cairo
, x
+1, y
+1);
177 cairo_line_to(cairo
, x
+1, y
+height
-3);
182 WMColorSpecSet(cairo
, &b
);
183 cairo_move_to(cairo
, x
, y
+height
-1);
184 cairo_line_to(cairo
, x
+width
-1, y
+height
-1);
186 if (width
> 2 && relief
!=WRPushed
) {
187 WMColorSpecSet(cairo
, &d
);
188 cairo_move_to(cairo
, x
+1, y
+height
-2);
189 cairo_line_to(cairo
, x
+width
-2, y
+height
-2);
193 WMColorSpecSet(cairo
, &b
);
194 cairo_move_to(cairo
, x
+width
-1, y
);
195 cairo_line_to(cairo
, x
+width
-1, y
+height
-1);
197 if (height
> 2 && relief
!=WRPushed
) {
198 WMColorSpecSet(cairo
, &d
);
199 cairo_move_to(cairo
, x
+width
-2, y
+1);
200 cairo_line_to(cairo
, x
+width
-2, y
+height
-2);
205 static int findNextWord(const char *text
, int limit
)
210 len
= strcspn(text
, " \t\n\r");
211 pos
= len
+ strspn(text
+ len
, " \t\n\r");
218 static int fitText(const char *text
, WMFont
* font
, int width
, int wrap
)
220 int i
, w
, beforecrlf
, word1
, word2
;
222 /* text length before first cr/lf */
223 beforecrlf
= strcspn(text
, "\n");
225 if (!wrap
|| beforecrlf
== 0)
228 //XXX w = WMWidthOfString(font, text, beforecrlf);
230 /* text up to first crlf fits */
236 word2
= word1
+ findNextWord(text
+ word1
, beforecrlf
- word1
);
237 if (word2
>= beforecrlf
)
239 //XXXw = WMWidthOfString(font, text, word2);
245 for (i
= word1
; i
< word2
; i
++) {
246 //XXXw = WMWidthOfString(font, text, i);
252 /* keep words complete if possible */
253 if (!isspace(text
[i
]) && word1
> 0) {
255 } else if (isspace(text
[i
]) && i
< beforecrlf
) {
256 /* keep space on current row, so new row has next word in column 1 */
264 static int fitText(char *text
, WMFont
* font
, int width
, int wrap
)
279 w
= WMWidthOfString(font
, text
, i
);
280 } while (w
< width
&& text
[i
] != '\n' && text
[i
] != 0);
285 /* keep words complete */
286 if (!isspace(text
[i
])) {
288 while (j
> 1 && !isspace(text
[j
]) && text
[j
] != 0)
294 i
= strcspn(text
, "\n");
300 int W_GetTextHeight(cairo_t
*cairo
, WMFont
*font
, const char *text
, int width
, int wrap
)
302 const char *ptr
= text
;
304 int length
= strlen(text
);
306 int fheight
= WMFontHeight(font
);
310 count
= fitText(ptr
, font
, width
, wrap
);
314 if (isspace(ptr
[count
]))
323 void W_PaintText(cairo_t
*cairo
, WMFont
*font
, int x
, int y
,
324 int width
, WMAlignment alignment
, WMColorSpec
*color
,
325 int wrap
, const char *text
)
327 const char *ptr
= text
;
328 int length
= strlen(ptr
);
332 int fheight
= WMFontHeight(font
);
334 //line_x= x + (width - WMWidthOfString(font, ptr))/2;
335 //WMDrawString(cairo, color, font, line_x, y, ptr);
339 count
= fitText(ptr
, font
, width
, wrap
);
341 line_width
= WMWidthOfString(font
, text
);
343 if (alignment
== WALeft
)
345 else if (alignment
== WARight
)
346 line_x
= x
+ width
- line_width
;
348 line_x
= x
+ (width
- line_width
) / 2;
350 WMDrawString(cairo
, color
, font
, line_x
, y
, ptr
);
352 if (wrap
&& ptr
[count
] != '\n')
355 while (ptr
[count
] && ptr
[count
] == '\n') {
365 void W_PaintTextAndImage(W_Screen
*screen
, cairo_t
*cairo
, W_View
*view
, int wrap
, WMColorSpec
*textColor
, W_Font
*font
,
366 WMReliefType relief
, const char *text
,
367 WMAlignment alignment
, WMImage
*image
,
368 WMImagePosition position
, WMColorSpec
*backColor
, int ofs
)
377 cairo_rectangle(cairo
, 0, 0, view
->size
.width
, view
->size
.height
);
378 WMColorSpecSet(cairo
, backColor
);
381 if (relief
== WRFlat
) {
384 w
= view
->size
.width
;
385 h
= view
->size
.height
;
389 w
= view
->size
.width
- 3;
390 h
= view
->size
.height
- 3;
393 /* calc. image alignment */
394 if (position
!= WIPNoImage
&& image
!= NULL
) {
398 ix
= (view
->size
.width
- WMGetImageWidth(image
)) / 2;
399 iy
= (view
->size
.height
- WMGetImageHeight(image
)) / 2;
408 iy
= y
+ (h
- WMGetImageHeight(image
)) / 2;
409 x
= x
+ WMGetImageWidth(image
) + 5;
411 w
-= WMGetImageWidth(image
) + 5;
415 ix
= view
->size
.width
- WMGetImageWidth(image
) - x
;
416 iy
= y
+ (h
- WMGetImageHeight(image
)) / 2;
417 w
-= WMGetImageWidth(image
) + 5;
421 ix
= (view
->size
.width
- WMGetImageWidth(image
)) / 2;
422 iy
= h
- WMGetImageHeight(image
);
424 h
-= WMGetImageHeight(image
);
429 ix
= (view
->size
.width
- WMGetImageWidth(image
)) / 2;
431 y
= WMGetImageHeight(image
);
432 h
-= WMGetImageHeight(image
);
439 //XXX XSetClipOrigin(screen->display, screen->clipGC, ix, iy);
440 //XXX XSetClipMask(screen->display, screen->clipGC, image->mask);
443 XCopyPlane(screen->display, image->pixmap, d, screen->clipGC,
444 0, 0, WMGetImageWidth(image), WMGetImageHeight(image), ix, iy, 1);
446 XCopyArea(screen->display, image->pixmap, d, screen->clipGC,
447 0, 0, WMGetImageWidth(image), WMGetImageHeight(image), ix, iy);
452 if (position
!= WIPImageOnly
&& text
!=NULL
) {
455 textHeight
= W_GetTextHeight(cairo
, font
, text
, w
-8, wrap
);
456 W_PaintText(cairo
, font
, x
+ofs
+4, y
+ofs
+ (h
-textHeight
)/2, w
-8,
457 alignment
, textColor
, wrap
, text
);
461 W_DrawRelief(screen
, cairo
, 0, 0, view
->size
.width
, view
->size
.height
, relief
);
464 WMPoint
wmkpoint(int x
, int y
)
474 WMSize
wmksize(unsigned int width
, unsigned int height
)
479 size
.height
= height
;
484 WMRect
wmkrect(int x
, int y
, unsigned int width
, unsigned int height
)
490 rect
.size
.width
= width
;
491 rect
.size
.height
= height
;