17
17
* along with this program; if not, write to the Free Software
18
18
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
20
* $Id: image.c,v 1.68 2006/05/22 17:53:26 mshopf Exp $
20
* $Id: image.c,v 1.71 2006/09/03 01:26:58 fsck-p Exp $
23
23
#ifdef HAVE_CONFIG_H
656
659
w = p->width / 3;
663
* XFillPolygon doesn't yield equally shaped arbitrary sized small triangles
664
* because of its filling algorithm (see also fill-rule in XCreateGC(3X11)
665
* as for which pixels are drawn on the boundary).
666
* So we handcraft them using XDrawSegments applying Bresenham's algorithm.
669
/* Coords of the enclosing rectangle for the triangle: */
670
/* Pay attention to integer precision loss and calculate */
671
/* carefully to obtain symmetrical and centered shapes. */
672
x1 = ((w - 1) / 2) - (w / 4);
673
x2 = ((w - 1) / 2) + (w / 4);
674
y1 = ((h - 1) / 2) - (h / 4);
675
y2 = ((h - 1) / 2) + (h / 4);
680
if(direction == DIRECTION_UP || direction == DIRECTION_DOWN) {
684
segments = (XSegment *) xitk_xmalloc(sizeof(XSegment) * nsegments);
686
if(direction == DIRECTION_DOWN) {
694
for(s = 0; s < nsegments; s++) {
695
segments[s].y1 = y; segments[s].x1 = x1;
696
segments[s].y2 = y; segments[s].x2 = x2;
699
if((dd += dx) >= dy) {
707
} while((dd += dy) < dx);
712
else if(direction == DIRECTION_LEFT || direction == DIRECTION_RIGHT) {
716
segments = (XSegment *) xitk_xmalloc(sizeof(XSegment) * nsegments);
718
if(direction == DIRECTION_RIGHT) {
726
for(s = 0; s < nsegments; s++) {
727
segments[s].x1 = x; segments[s].y1 = y1;
728
segments[s].x2 = x; segments[s].y2 = y2;
731
if((dd += dy) >= dx) {
739
} while((dd += dx) < dy);
745
XITK_WARNING("direction '%d' is unhandled.\n", direction);
659
749
XLOCK(im->x.disp);
660
750
XSetForeground(im->x.disp, p->image->gc, xitk_get_pixel_color_black(im));
661
751
XUNLOCK(im->x.disp);
663
753
for(i = 0; i < 3; i++) {
665
if(direction == DIRECTION_UP) {
666
x1 = (w / 2) + offset;
669
x2 = ((w / 4) * 3) + offset;
672
x3 = (w / 4) + offset;
675
else if(direction == DIRECTION_DOWN) {
676
x1 = (w / 2) + offset;
679
x2 = (w / 4) + offset;
682
x3 = ((w / 4) * 3) + offset;
685
else if(direction == DIRECTION_LEFT) {
686
x1 = ((w / 4) * 3) + offset;
689
x2 = ((w / 4) * 3) + offset;
692
x3 = (w / 4) + offset;
695
else if(direction == DIRECTION_RIGHT) {
696
x1 = (w / 4) + offset;
699
x2 = ((w / 4) * 3) + offset;
702
x3 = (w / 4) + offset;
706
XITK_WARNING("direction '%d' is unhandled.\n", direction);
756
for(s = 0; s < nsegments; s++) {
757
segments[s].x1++; segments[s].y1++;
758
segments[s].x2++; segments[s].y2++;
726
762
XLOCK(im->x.disp);
727
XFillPolygon(im->x.disp, p->image->pixmap, p->image->gc,
728
&points[0], 4, Complex, CoordModeOrigin);
763
XDrawSegments(im->x.disp, p->image->pixmap, p->image->gc,
764
&segments[0], nsegments);
729
765
XUNLOCK(im->x.disp);
767
for(s = 0; s < nsegments; s++) {
763
805
XSetForeground(im->x.disp, p->gc, xitk_get_pixel_color_black(im));
765
807
XDrawLine(im->x.disp, p->pixmap, p->gc, x, y, (x + excstart), y);
766
XDrawLine(im->x.disp, p->pixmap, p->gc, (x + excstop), y, (x + width), y);
808
XDrawLine(im->x.disp, p->pixmap, p->gc, (x + excstop), y, (x + width - 1), y);
767
809
XDrawLine(im->x.disp, p->pixmap, p->gc, x, y, x, (y + height));
768
810
XUNLOCK(im->x.disp);
774
816
XSetForeground(im->x.disp, p->gc, xitk_get_pixel_color_white(im));
776
818
XDrawLine(im->x.disp, p->pixmap, p->gc, (x + width), y, (x + width), (y + height));
777
XDrawLine(im->x.disp, p->pixmap, p->gc, x, (y + height), (x + width), (y + height));
819
XDrawLine(im->x.disp, p->pixmap, p->gc, (x + 1), (y + height), (x + width), (y + height));
778
820
XUNLOCK(im->x.disp);
794
836
XSetForeground(im->x.disp, p->gc, xitk_get_pixel_color_darkgray(im));
796
838
XDrawLine(im->x.disp, p->pixmap, p->gc, x, y, (x + excstart), y);
797
XDrawLine(im->x.disp, p->pixmap, p->gc, (x + excstop), y, (x + width), y);
839
XDrawLine(im->x.disp, p->pixmap, p->gc, (x + excstop), y, (x + width - 1), y);
798
840
XDrawLine(im->x.disp, p->pixmap, p->gc, x, y, x, (y + height));
799
841
XUNLOCK(im->x.disp);
805
847
XSetForeground(im->x.disp, p->gc, xitk_get_pixel_color_white(im));
807
849
XDrawLine(im->x.disp, p->pixmap, p->gc, (x + width), y, (x + width), (y + height));
808
XDrawLine(im->x.disp, p->pixmap, p->gc, x, (y + height), (x + width), (y + height));
850
XDrawLine(im->x.disp, p->pixmap, p->gc, (x + 1), (y + height), (x + width), (y + height));
809
851
XUNLOCK(im->x.disp);
825
867
else if(relief == DRAW_INNER)
826
868
XSetForeground(im->x.disp, p->gc, dcolor);
828
XDrawLine(im->x.disp, p->pixmap, p->gc, x, y, (x + width), y);
870
XDrawLine(im->x.disp, p->pixmap, p->gc, x, y, (x + width - 1), y);
829
871
XDrawLine(im->x.disp, p->pixmap, p->gc, x, y, x, (y + height));
830
872
XUNLOCK(im->x.disp);
836
878
XSetForeground(im->x.disp, p->gc, lcolor);
838
880
XDrawLine(im->x.disp, p->pixmap, p->gc, (x + width), y, (x + width), (y + height));
839
XDrawLine(im->x.disp, p->pixmap, p->gc, x, (y + height), (x + width), (y + height));
881
XDrawLine(im->x.disp, p->pixmap, p->gc, (x + 1), (y + height), (x + width), (y + height));
840
882
XUNLOCK(im->x.disp);
1310
1352
xitk_font_t *fs = NULL;
1312
1354
int yoff = 0, xstart = 0, xstop = 0, fheight = 0, fwidth = 0;
1356
char *titlebuf = NULL;
1313
1357
char buf[BUFSIZ];
1315
1359
ABORT_IF_NULL(im);
1316
1360
ABORT_IF_NULL(p);
1363
int ascent, descent;
1365
int maxfwidth = (w - 12);
1367
titlelen = strlen(title);
1320
1370
fs = xitk_font_load_font(im->x.disp, (fontname ? fontname : DEFAULT_FONT_12));
1321
1371
xitk_font_set_font(fs, p->gc);
1322
fheight = xitk_font_get_string_height(fs, title);
1323
fwidth = xitk_font_get_string_length(fs, title);
1325
if(fwidth >= (w - 12)) {
1328
memset(&buf, 0, sizeof(buf));
1329
/* Limit the title to width of frame */
1372
xitk_font_text_extent(fs, title, titlelen, NULL, NULL, &fwidth, &ascent, &descent);
1373
fheight = ascent + descent;
1375
/* Limit title to frame width */
1376
if(fwidth > maxfwidth) {
1377
char dots[] = "...";
1378
int dotslen = strlen(dots);
1381
/* Cut title, append dots */
1382
xitk_font_text_extent(fs, dots, dotslen, NULL, NULL, &dotsfwidth, NULL, NULL);
1332
snprintf(buf, nchar, "%s", title);
1333
} while(xitk_font_get_string_length(fs, buf) < (w - 12));
1334
/* Cut title, add three dots a the end */
1336
snprintf(buf, nchar, "%s", title);
1385
xitk_font_text_extent(fs, title, titlelen, NULL, NULL, &fwidth, NULL, NULL);
1386
} while((fwidth + dotsfwidth) > maxfwidth);
1387
{ /* Cut possible incomplete multibyte character at the end */
1389
while((titlelen > 0) &&
1390
(xitk_font_text_extent(fs, title, (titlelen - 1), NULL, NULL, &fwidth1, NULL, NULL),
1394
if(titlelen > (sizeof(buf) - dotslen - 1)) /* Should never happen, */
1395
titlelen = (sizeof(buf) - dotslen - 1); /* just to be sure ... */
1396
strncpy(buf, title, titlelen), buf[titlelen] = '\0';
1398
fwidth += dotsfwidth;
1399
titlelen += dotslen;
1342
fwidth = xitk_font_get_string_length(fs, buf);
1345
1404
sty[0] = (style == DRAW_INNER) ? DRAW_INNER : DRAW_OUTTER;
1350
1409
yoff = (fheight>>1);
1352
xstop = fwidth + 12;
1354
1414
_draw_rectangular_box_light(im, p, x, (y - yoff),
1356
w, (h - yoff), sty[0]);
1416
w, (h - fheight + yoff), sty[0]);
1361
1421
_draw_rectangular_box_light(im, p, (x + 1), ((y - yoff) + 1),
1363
(w - 2), ((h - yoff) - 2), sty[1]);
1423
(w - 2), ((h - fheight + yoff) - 2), sty[1]);
1366
1426
XLOCK(im->x.disp);
1367
1427
XSetForeground(im->x.disp, p->gc, xitk_get_pixel_color_black(im));
1368
xitk_font_draw_string(fs, p->pixmap, p->gc, (x + 6), y, buf, strlen(buf));
1428
xitk_font_draw_string(fs, p->pixmap, p->gc, (x + 6), y, titlebuf, titlelen);
1369
1429
XUNLOCK(im->x.disp);
1371
1431
xitk_font_unload_font(fs);