4 * Copyright (C) 1997-2014 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include "bcresources.h"
26 #include "bcsignals.h"
27 #include "bcsynchronous.h"
29 #include "bcwindowbase.h"
39 void BC_WindowBase::copy_area(int x1, int y1, int x2, int y2, int w, int h, BC_Pixmap *pixmap)
41 XCopyArea(top_level->display,
42 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
43 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
44 top_level->gc, x1, y1, w, h, x2, y2);
48 void BC_WindowBase::draw_box(int x, int y, int w, int h, BC_Pixmap *pixmap)
50 //if(x == 0) printf("BC_WindowBase::draw_box %d %d %d %d\n", x, y, w, h);
51 XFillRectangle(top_level->display,
52 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
53 top_level->gc, x, y, w, h);
57 void BC_WindowBase::draw_circle(int x, int y, int w, int h, BC_Pixmap *pixmap)
59 XDrawArc(top_level->display,
60 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
61 top_level->gc, x, y, (w - 1), (h - 2), 0 * 64, 360 * 64);
64 void BC_WindowBase::draw_arc(int x, int y, int w, int h,
65 int start_angle, int angle_length, BC_Pixmap *pixmap)
67 XDrawArc(top_level->display,
68 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
69 top_level->gc, x, y, (w - 1), (h - 2), start_angle * 64,
73 void BC_WindowBase::draw_disc(int x, int y, int w, int h, BC_Pixmap *pixmap)
75 XFillArc(top_level->display,
76 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
77 top_level->gc, x, y, (w - 1), (h - 2), 0 * 64, 360 * 64);
80 void BC_WindowBase::clear_box(int x, int y, int w, int h, BC_Pixmap *pixmap)
83 Pixmap xpixmap = pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap;
84 XFillRectangle(top_level->display, xpixmap, top_level->gc, x, y, w, h);
87 void BC_WindowBase::draw_text_line(int x, int y, const char *text, int len,
91 if( get_resources()->use_xft ) {
92 draw_xft_text(x, y, text, len, pixmap);
96 Pixmap xpixmap = pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap;
97 if( get_resources()->use_fontset ) {
98 XFontSet fontset = top_level->get_curr_fontset();
100 XmbDrawString(top_level->display, xpixmap, fontset,
101 top_level->gc, x, y, text, len);
106 //printf("BC_WindowBase::draw_text 3\n");
107 XDrawString(top_level->display, xpixmap, top_level->gc, x, y, text, len);
110 void BC_WindowBase::draw_text(int x, int y, const char *text, int length,
113 if( length < 0 ) length = strlen(text);
114 //int boldface = top_level->current_font & BOLDFACE;
115 int font = top_level->current_font & 0xff;
117 switch(top_level->current_font) {
118 case MEDIUM_7SEGMENT:
119 for(int i = 0; i < length; i++) {
120 VFrame *image, **img7seg = get_resources()->medium_7segment;
123 case '0': case '1': case '2': case '3': case '4':
124 case '5': case '6': case '7': case '8': case '9':
125 image = img7seg[ch-'0']; break;
126 case ':': image = img7seg[10]; break;
127 case '.': image = img7seg[11]; break;
128 case 'a': case 'b': case 'c':
129 case 'd': case 'e': case 'f': ch -= 'a'-'A';
130 case 'A': case 'B': case 'C': /* fallthru */
131 case 'D': case 'E': case 'F':
132 image = img7seg[12+ch-'A']; break;
134 case '-': image = img7seg[19]; break;
136 case ' ': image = img7seg[18]; break;
139 draw_vframe(image, x, y - image->get_h());
145 if(top_level->get_xft_struct(top_level->current_font)) {
146 draw_xft_text(x, y, text, length, pixmap);
150 for(int i = 0, j = 0; i <= length; i++) {
151 if(text[i] == '\n' || text[i] == 0) {
152 if(get_resources()->use_fontset && top_level->get_curr_fontset()) {
153 XmbDrawString(top_level->display,
154 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
155 top_level->get_curr_fontset(),
156 top_level->gc, x, y, &text[j], i-j);
159 XDrawString(top_level->display,
160 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
161 top_level->gc, x, y, &text[j], i-j);
164 y += get_text_height(font);
172 void BC_WindowBase::draw_utf8_text(int x, int y,
173 const char *text, int length, BC_Pixmap *pixmap)
175 if(length < 0) length = strlen(text);
177 if(top_level->get_xft_struct(top_level->current_font))
188 for(int i = 0, j = 0; i <= length; i++)
190 if(text[i] == '\n' || text[i] == 0)
192 if(get_resources()->use_fontset && top_level->get_curr_fontset())
194 XmbDrawString(top_level->display,
195 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
196 top_level->get_curr_fontset(),
205 XDrawString(top_level->display,
206 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
215 y += get_text_height(MEDIUMFONT);
220 void BC_WindowBase::draw_xft_text(int x, int y,
221 const char *text, int length, BC_Pixmap *pixmap, int is_utf8)
224 wchar_t wide_text[l];
225 length = BC_Resources::encode(
226 is_utf8 ? "UTF8" : BC_Resources::encoding, BC_Resources::wide_encoding,
227 (char*)text, length, (char*)wide_text, l*sizeof(wchar_t)) / sizeof(wchar_t);
228 draw_xft_text(x, y, wide_text, length, pixmap);
231 void BC_WindowBase::draw_xft_text(int x, int y,
232 const wchar_t *text, int length, BC_Pixmap *pixmap)
235 const wchar_t *wsp = text, *wep = wsp + length;
237 const wchar_t *wcp = wsp;
238 while( wcp < wep && *wcp != '\n' ) ++wcp;
241 draw_wtext(x, y, wsp, len, pixmap);
242 if( wcp >= wep ) break;
244 dy = get_text_height(top_level->current_font);
250 int BC_WindowBase::wcharpos(const wchar_t *text, XftFont *font, int length,
257 int bpos = charpos[-1];
259 for(int i = 0; i < length; i++)
261 XftTextExtents32(top_level->display,
263 (const FcChar32*)text,
266 charpos[i] = extents.xOff + bpos;
268 return charpos[length - 1] - bpos;
272 XftTextExtents32(top_level->display,
274 (const FcChar32*)text,
281 void BC_WindowBase::draw_wtext(int x, int y,
282 const wchar_t *text, int length, BC_Pixmap *pixmap, int *charpos)
286 const wchar_t *up, *ubp;
289 XftFont *curfont, *nextfont, *altfont, *basefont;
292 length = wcslen(text);
299 color.red = (top_level->current_color & 0xff0000) >> 16;
300 color.red |= color.red << 8;
301 color.green = (top_level->current_color & 0xff00) >> 8;
302 color.green |= color.green << 8;
303 color.blue = (top_level->current_color & 0xff);
304 color.blue |= color.blue << 8;
305 color.alpha = 0xffff;
307 XftColorAllocValue(top_level->display,
313 basefont = top_level->get_xft_struct(top_level->current_font);
315 curfont = nextfont = basefont;
320 for(up = text; up < &text[length]; up++)
322 if(XftCharExists(top_level->display, basefont, *up))
324 else if(altfont && XftCharExists(top_level->display, altfont, *up))
329 XftFontClose(top_level->display, altfont);
331 if( (newpat = BC_Resources::find_similar_font(*up, basefont->pattern)) != 0 ) {
334 FcPatternGetDouble(basefont->pattern, FC_PIXEL_SIZE,
336 FcPatternAddDouble(newpat, FC_PIXEL_SIZE, psize);
337 FcPatternDel(newpat, FC_SCALABLE);
338 altfont = XftFontOpenPattern(top_level->display,
349 if(nextfont != curfont)
352 XftDrawString32((XftDraw*)(pixmap ? pixmap->opaque_xft_draw : this->pixmap->opaque_xft_draw),
357 (const FcChar32*)ubp,
361 cp = &charpos[ubp - text + 1];
363 x += wcharpos(ubp, curfont, l, cp);
371 XftDrawString32((XftDraw*)(pixmap ? pixmap->opaque_xft_draw : this->pixmap->opaque_xft_draw),
376 (const FcChar32*)ubp,
379 wcharpos(ubp, curfont, up - ubp, &charpos[ubp - text + 1]);
383 XftFontClose(top_level->display, altfont);
385 XftColorFree(top_level->display,
391 void BC_WindowBase::truncate_text(char *result, const char *text, int w)
393 int new_w = get_text_width(current_font, text);
397 const char* separator = "...";
398 int separator_w = get_text_width(current_font, separator);
402 strcpy(result, separator);
406 int text_len = strlen(text);
407 // widen middle gap until it fits
408 for(int i = text_len / 2; i > 0; i--)
410 strncpy(result, text, i);
412 strcat(result, separator);
413 strncat(result, text + text_len - i, i);
414 result[i + strlen(separator) + i] = 0;
415 new_w = get_text_width(current_font, result);
416 //printf("BC_WindowBase::truncate_text %d %d %d %s\n", __LINE__, new_w, w, result);
417 if(new_w < w) return;
421 strcpy(result, separator);
426 strcpy(result, text);
430 void BC_WindowBase::draw_center_text(int x, int y, const char *text, int length)
432 if(length < 0) length = strlen(text);
433 int w = get_text_width(current_font, text, length);
435 draw_text(x, y, text, length);
438 void BC_WindowBase::draw_line(int x1, int y1, int x2, int y2, BC_Pixmap *pixmap)
440 // Some X drivers can't draw 0 length lines
441 if(x1 == x2 && y1 == y2)
443 draw_pixel(x1, y1, pixmap);
447 XDrawLine(top_level->display,
448 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
457 void BC_WindowBase::draw_polygon(ArrayList<int> *x, ArrayList<int> *y, BC_Pixmap *pixmap)
459 int npoints = MIN(x->total, y->total);
460 XPoint *points = new XPoint[npoints];
462 for(int i = 0; i < npoints; i++)
464 points[i].x = x->values[i];
465 points[i].y = y->values[i];
468 XDrawLines(top_level->display,
469 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
478 void BC_WindowBase::fill_polygon(ArrayList<int> *x, ArrayList<int> *y, BC_Pixmap *pixmap)
480 int npoints = MIN(x->total, y->total);
481 XPoint *points = new XPoint[npoints];
483 for(int i = 0; i < npoints; i++)
485 points[i].x = x->values[i];
486 points[i].y = y->values[i];
489 XFillPolygon(top_level->display,
490 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
501 void BC_WindowBase::draw_rectangle(int x, int y, int w, int h)
503 XDrawRectangle(top_level->display,
504 pixmap->opaque_pixmap,
512 void BC_WindowBase::draw_3d_border(int x,
522 top_level->get_resources()->border_shadow2,
523 top_level->get_resources()->border_shadow1,
524 top_level->get_resources()->border_light1,
525 top_level->get_resources()->border_light2);
529 void BC_WindowBase::draw_3d_border(int x,
543 ux = x+w-1; uy = y+h-1;
546 draw_line(x, y, ux, y);
547 draw_line(x, y, x, uy);
549 draw_line(lx, ly, ux - 1, ly);
550 draw_line(lx, ly, lx, uy - 1);
553 draw_line(ux, ly, ux, uy);
554 draw_line(lx, uy, ux, uy);
556 draw_line(x + w, y, x + w, y + h);
557 draw_line(x, y + h, x + w, y + h);
560 void BC_WindowBase::draw_3d_box(int x,
576 ux = x+w-1; uy = y+h-1;
579 draw_box(x, y, w, h, pixmap);
582 draw_line(x, y, ux, y, pixmap);
583 draw_line(x, y, x, uy, pixmap);
585 draw_line(lx, ly, ux - 1, ly, pixmap);
586 draw_line(lx, ly, lx, uy - 1, pixmap);
589 draw_line(ux, ly, ux, uy, pixmap);
590 draw_line(lx, uy, ux, uy, pixmap);
592 draw_line(x + w, y, x + w, y + h, pixmap);
593 draw_line(x, y + h, x + w, y + h, pixmap);
596 void BC_WindowBase::draw_colored_box(int x, int y, int w, int h, int down, int highlighted)
601 draw_3d_box(x, y, w, h,
602 top_level->get_resources()->button_light,
603 top_level->get_resources()->button_highlighted,
604 top_level->get_resources()->button_highlighted,
605 top_level->get_resources()->button_shadow,
608 draw_3d_box(x, y, w, h,
609 top_level->get_resources()->button_light,
610 top_level->get_resources()->button_up,
611 top_level->get_resources()->button_up,
612 top_level->get_resources()->button_shadow,
617 // need highlighting for toggles
619 draw_3d_box(x, y, w, h,
620 top_level->get_resources()->button_shadow,
622 top_level->get_resources()->button_up,
623 top_level->get_resources()->button_up,
624 top_level->get_resources()->button_light);
626 draw_3d_box(x, y, w, h,
627 top_level->get_resources()->button_shadow,
629 top_level->get_resources()->button_down,
630 top_level->get_resources()->button_down,
631 top_level->get_resources()->button_light);
636 void BC_WindowBase::draw_border(char *text, int x, int y, int w, int h)
638 int left_indent = 20;
642 lx = x + 1; ly = y + 1;
643 ux = x + w - 1; uy = y + h - 1;
646 if(text && text[0] != 0)
649 set_font(MEDIUMFONT);
650 draw_text(x + left_indent, y + get_text_height(MEDIUMFONT) / 2, text);
653 set_color(top_level->get_resources()->button_shadow);
654 draw_line(x, y, x + left_indent - 5, y);
655 draw_line(x, y, x, uy);
656 draw_line(x + left_indent + 5 + get_text_width(MEDIUMFONT, text), y, ux, y);
657 draw_line(x, y, x, uy);
658 draw_line(ux, ly, ux, uy);
659 draw_line(lx, uy, ux, uy);
660 set_color(top_level->get_resources()->button_light);
661 draw_line(lx, ly, x + left_indent - 5 - 1, ly);
662 draw_line(lx, ly, lx, uy - 1);
663 draw_line(x + left_indent + 5 + get_text_width(MEDIUMFONT, text), ly, ux - 1, ly);
664 draw_line(lx, ly, lx, uy - 1);
665 draw_line(x + w, y, x + w, y + h);
666 draw_line(x, y + h, x + w, y + h);
669 void BC_WindowBase::draw_triangle_down_flat(int x, int y, int w, int h)
671 int x1, y1, x2, y2, x3;
674 x1 = x; x2 = x + w / 2; x3 = x + w - 1;
675 y1 = y; y2 = y + h - 1;
677 point[0].x = x2; point[0].y = y2; point[1].x = x3;
678 point[1].y = y1; point[2].x = x1; point[2].y = y1;
680 XFillPolygon(top_level->display,
681 pixmap->opaque_pixmap,
689 void BC_WindowBase::draw_triangle_up(int x, int y, int w, int h,
690 int light1, int light2, int middle, int shadow1, int shadow2)
692 int x1, y1, x2, y2, x3;
695 x1 = x; y1 = y; x2 = x + w / 2;
696 y2 = y + h - 1; x3 = x + w - 1;
699 point[0].x = x2; point[0].y = y1; point[1].x = x3;
700 point[1].y = y2; point[2].x = x1; point[2].y = y2;
703 XFillPolygon(top_level->display,
704 pixmap->opaque_pixmap,
711 // bottom and top right
713 draw_line(x3, y2-1, x1, y2-1);
714 draw_line(x2-1, y1, x3-1, y2);
716 draw_line(x3, y2, x1, y2);
717 draw_line(x2, y1, x3, y2);
721 draw_line(x2+1, y1, x1+1, y2);
723 draw_line(x2, y1, x1, y2);
726 void BC_WindowBase::draw_triangle_down(int x, int y, int w, int h,
727 int light1, int light2, int middle, int shadow1, int shadow2)
729 int x1, y1, x2, y2, x3;
732 x1 = x; x2 = x + w / 2; x3 = x + w - 1;
733 y1 = y; y2 = y + h - 1;
735 point[0].x = x2; point[0].y = y2; point[1].x = x3;
736 point[1].y = y1; point[2].x = x1; point[2].y = y1;
739 XFillPolygon(top_level->display,
740 pixmap->opaque_pixmap,
747 // top and bottom left
749 draw_line(x3-1, y1+1, x1+1, y1+1);
750 draw_line(x1+1, y1, x2+1, y2);
752 draw_line(x3, y1, x1, y1);
753 draw_line(x1, y1, x2, y2);
757 draw_line(x3-1, y1, x2-1, y2);
759 draw_line(x3, y1, x2, y2);
762 void BC_WindowBase::draw_triangle_left(int x, int y, int w, int h,
763 int light1, int light2, int middle, int shadow1, int shadow2)
765 int x1, y1, x2, y2, y3;
769 y1 = y; x1 = x; y2 = y + h / 2;
770 x2 = x + w - 1; y3 = y + h - 1;
772 point[0].x = x1; point[0].y = y2; point[1].x = x2;
773 point[1].y = y1; point[2].x = x2; point[2].y = y3;
776 XFillPolygon(top_level->display,
777 pixmap->opaque_pixmap,
784 // right and bottom right
786 draw_line(x2-1, y1, x2-1, y3-1);
787 draw_line(x2, y3-1, x1, y2-1);
789 draw_line(x2, y1, x2, y3);
790 draw_line(x2, y3, x1, y2);
794 draw_line(x1, y2, x2, y1);
796 draw_line(x1, y2+1, x2, y1+1);
799 void BC_WindowBase::draw_triangle_right(int x, int y, int w, int h,
800 int light1, int light2, int middle, int shadow1, int shadow2)
802 int x1, y1, x2, y2, y3;
805 y1 = y; y2 = y + h / 2; y3 = y + h - 1;
806 x1 = x; x2 = x + w - 1;
808 point[0].x = x1; point[0].y = y1; point[1].x = x2;
809 point[1].y = y2; point[2].x = x1; point[2].y = y3;
812 XFillPolygon(top_level->display,
813 pixmap->opaque_pixmap,
820 // left and top right
822 draw_line(x1+1, y3, x1+1, y1);
823 draw_line(x1, y1+1, x2, y2+1);
825 draw_line(x1, y3, x1, y1);
826 draw_line(x1, y1, x2, y2);
830 draw_line(x2, y2-1, x1, y3-1);
832 draw_line(x2, y2, x1, y3);
836 void BC_WindowBase::draw_check(int x, int y)
838 const int w = 15, h = 15;
839 draw_line(x + 3, y + h / 2 + 0, x + 6, y + h / 2 + 2);
840 draw_line(x + 3, y + h / 2 + 1, x + 6, y + h / 2 + 3);
841 draw_line(x + 6, y + h / 2 + 2, x + w - 4, y + h / 2 - 3);
842 draw_line(x + 3, y + h / 2 + 2, x + 6, y + h / 2 + 4);
843 draw_line(x + 6, y + h / 2 + 2, x + w - 4, y + h / 2 - 3);
844 draw_line(x + 6, y + h / 2 + 3, x + w - 4, y + h / 2 - 2);
845 draw_line(x + 6, y + h / 2 + 4, x + w - 4, y + h / 2 - 1);
848 void BC_WindowBase::draw_tiles(BC_Pixmap *tile, int origin_x, int origin_y, int x, int y, int w, int h)
853 draw_box(x, y, w, h);
857 XSetFillStyle(top_level->display, top_level->gc, FillTiled);
858 // Don't know how slow this is
859 XSetTile(top_level->display, top_level->gc, tile->get_pixmap());
860 XSetTSOrigin(top_level->display, top_level->gc, origin_x, origin_y);
861 draw_box(x, y, w, h);
862 XSetFillStyle(top_level->display, top_level->gc, FillSolid);
866 void BC_WindowBase::draw_top_tiles(BC_WindowBase *parent_window, int x, int y, int w, int h)
869 int origin_x, origin_y;
870 XTranslateCoordinates(top_level->display,
879 draw_tiles(parent_window->bg_pixmap,
888 void BC_WindowBase::draw_top_background(BC_WindowBase *parent_window,
897 XLockDisplay(top_level->display);
899 XTranslateCoordinates(top_level->display,
908 XCopyArea(top_level->display,
909 parent_window->pixmap->opaque_pixmap,
910 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
919 XUnlockDisplay(top_level->display);
922 void BC_WindowBase::draw_background(int x, int y, int w, int h)
926 draw_tiles(bg_pixmap, 0, 0, x, y, w, h);
930 clear_box(x, y, w, h);
934 void BC_WindowBase::draw_bitmap(BC_Bitmap *bitmap,
947 // Hide cursor if video enabled
948 update_video_cursor();
950 //printf("BC_WindowBase::draw_bitmap 1\n");
951 if(dest_w <= 0 || dest_h <= 0)
953 // Use hardware scaling to canvas dimensions if proper color model.
954 if(bitmap->get_color_model() == BC_YUV420P)
961 dest_w = bitmap->get_w();
962 dest_h = bitmap->get_h();
966 if(src_w <= 0 || src_h <= 0)
968 src_w = bitmap->get_w();
969 src_h = bitmap->get_h();
974 bitmap->write_drawable(win,
989 bitmap->write_drawable(pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
999 //printf("BC_WindowBase::draw_bitmap 2\n");
1003 void BC_WindowBase::draw_pixel(int x, int y, BC_Pixmap *pixmap)
1005 XDrawPoint(top_level->display,
1006 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
1013 void BC_WindowBase::draw_pixmap(BC_Pixmap *pixmap,
1022 pixmap->write_drawable(dst ? dst->opaque_pixmap : this->pixmap->opaque_pixmap,
1031 void BC_WindowBase::draw_vframe(VFrame *frame,
1042 if(dest_w <= 0) dest_w = frame->get_w() - src_x;
1043 if(dest_h <= 0) dest_h = frame->get_h() - src_y;
1044 if(src_w <= 0) src_w = frame->get_w() - src_x;
1045 if(src_h <= 0) src_h = frame->get_h() - src_y;
1046 CLAMP(src_x, 0, frame->get_w() - 1);
1047 CLAMP(src_y, 0, frame->get_h() - 1);
1048 if(src_x + src_w > frame->get_w()) src_w = frame->get_w() - src_x;
1049 if(src_y + src_h > frame->get_h()) src_h = frame->get_h() - src_y;
1051 if(!temp_bitmap) temp_bitmap = new BC_Bitmap(this,
1057 temp_bitmap->match_params(dest_w,
1062 temp_bitmap->read_frame(frame,
1072 draw_bitmap(temp_bitmap,
1085 void BC_WindowBase::draw_tooltip()
1087 if(tooltip_popup && tooltip_text)
1089 int w = tooltip_popup->get_w(), h = tooltip_popup->get_h();
1090 tooltip_popup->set_color(get_resources()->tooltip_bg_color);
1091 tooltip_popup->draw_box(0, 0, w, h);
1092 tooltip_popup->set_color(BLACK);
1093 tooltip_popup->draw_rectangle(0, 0, w, h);
1094 tooltip_popup->set_font(MEDIUMFONT);
1095 tooltip_popup->draw_text(TOOLTIP_MARGIN,
1096 get_text_ascent(MEDIUMFONT) + TOOLTIP_MARGIN,
1101 void BC_WindowBase::slide_left(int distance)
1105 XCopyArea(top_level->display,
1106 pixmap->opaque_pixmap,
1107 pixmap->opaque_pixmap,
1118 void BC_WindowBase::slide_right(int distance)
1122 XCopyArea(top_level->display,
1123 pixmap->opaque_pixmap,
1124 pixmap->opaque_pixmap,
1135 void BC_WindowBase::slide_up(int distance)
1139 XCopyArea(top_level->display,
1140 pixmap->opaque_pixmap,
1141 pixmap->opaque_pixmap,
1149 set_color(bg_color);
1150 XFillRectangle(top_level->display,
1151 pixmap->opaque_pixmap,
1160 void BC_WindowBase::slide_down(int distance)
1164 XCopyArea(top_level->display,
1165 pixmap->opaque_pixmap,
1166 pixmap->opaque_pixmap,
1174 set_color(bg_color);
1175 XFillRectangle(top_level->display,
1176 pixmap->opaque_pixmap,
1185 // 3 segments in separate pixmaps. Obsolete.
1186 void BC_WindowBase::draw_3segment(int x,
1190 BC_Pixmap *left_image,
1191 BC_Pixmap *mid_image,
1192 BC_Pixmap *right_image,
1195 if(w <= 0 || h <= 0) return;
1196 int left_boundary = left_image->get_w_fixed();
1197 int right_boundary = w - right_image->get_w_fixed();
1198 for(int i = 0; i < w; )
1202 if(i < left_boundary)
1205 if(i < right_boundary)
1208 image = right_image;
1210 int output_w = image->get_w_fixed();
1212 if(i < left_boundary)
1214 if(i + output_w > left_boundary) output_w = left_boundary - i;
1217 if(i < right_boundary)
1219 if(i + output_w > right_boundary) output_w = right_boundary - i;
1222 if(i + output_w > w) output_w = w - i;
1224 image->write_drawable(pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
1235 // 3 segments in separate vframes. Obsolete.
1236 void BC_WindowBase::draw_3segment(int x,
1242 VFrame *right_image,
1245 if(w <= 0 || h <= 0) return;
1246 int left_boundary = left_image->get_w_fixed();
1247 int right_boundary = w - right_image->get_w_fixed();
1250 for(int i = 0; i < w; )
1254 if(i < left_boundary)
1257 if(i < right_boundary)
1260 image = right_image;
1262 int output_w = image->get_w_fixed();
1264 if(i < left_boundary)
1266 if(i + output_w > left_boundary) output_w = left_boundary - i;
1269 if(i < right_boundary)
1271 if(i + output_w > right_boundary) output_w = right_boundary - i;
1274 if(i + output_w > w) output_w = w - i;
1288 if(output_w == 0) break;
1293 // Draw all 3 segments in a single vframe for a changing level
1298 // <------------------------------------------------------------>
1302 // <-------------------------------------------------------------------->
1304 // |-------------------|----------------------|------------------|
1307 void BC_WindowBase::draw_3segmenth(int x,
1322 void BC_WindowBase::draw_3segmenth(int x,
1330 if(total_w <= 0 || w <= 0 || h <= 0) return;
1331 int third_image = image->get_w() / 3;
1332 int half_image = image->get_w() / 2;
1333 //int left_boundary = third_image;
1334 //int right_boundary = total_w - third_image;
1336 int left_in_w = third_image;
1337 int left_out_x = total_x;
1338 int left_out_w = third_image;
1339 int right_in_x = image->get_w() - third_image;
1340 int right_in_w = third_image;
1341 int right_out_x = total_x + total_w - third_image;
1342 int right_out_w = third_image;
1343 int center_out_x = total_x + third_image;
1344 int center_out_w = total_w - third_image * 2;
1345 //int image_x, image_w;
1347 //printf("BC_WindowBase::draw_3segment 1 left_out_x=%d left_out_w=%d center_out_x=%d center_out_w=%d right_out_x=%d right_out_w=%d\n",
1348 // left_out_x, left_out_w, center_out_x, center_out_w, right_out_x, right_out_w);
1352 left_in_w -= x - left_out_x;
1353 left_out_w -= x - left_out_x;
1354 left_in_x += x - left_out_x;
1355 left_out_x += x - left_out_x;
1358 if(left_out_x + left_out_w > x + w)
1360 left_in_w -= (left_out_x + left_out_w) - (x + w);
1361 left_out_w -= (left_out_x + left_out_w) - (x + w);
1366 right_in_w -= x - right_out_x;
1367 right_out_w -= x - right_out_x;
1368 right_in_x += x - right_out_x;
1369 right_out_x += x - right_out_x;
1372 if(right_out_x + right_out_w > x + w)
1374 right_in_w -= (right_out_x + right_out_w) - (x + w);
1375 right_out_w -= (right_out_x + right_out_w) - (x + w);
1378 if(center_out_x < x)
1380 center_out_w -= x - center_out_x;
1381 center_out_x += x - center_out_x;
1384 if(center_out_x + center_out_w > x + w)
1386 center_out_w -= (center_out_x + center_out_w) - (x + w);
1389 if(!temp_bitmap) temp_bitmap = new BC_Bitmap(top_level,
1394 temp_bitmap->match_params(image->get_w(),
1398 temp_bitmap->read_frame(image,
1405 //printf("BC_WindowBase::draw_3segment 2 left_out_x=%d left_out_w=%d center_out_x=%d center_out_w=%d right_out_x=%d right_out_w=%d\n",
1406 // left_out_x, left_out_w, center_out_x, center_out_w, right_out_x, right_out_w);
1409 draw_bitmap(temp_bitmap,
1417 -1, // src width and height are meaningless in video_off mode
1424 draw_bitmap(temp_bitmap,
1432 -1, // src width and height are meaningless in video_off mode
1437 for(int pixel = center_out_x;
1438 pixel < center_out_x + center_out_w;
1439 pixel += half_image)
1441 int fragment_w = half_image;
1442 if(fragment_w + pixel > center_out_x + center_out_w)
1443 fragment_w = (center_out_x + center_out_w) - pixel;
1445 //printf("BC_WindowBase::draw_3segment 2 pixel=%d fragment_w=%d\n", pixel, fragment_w);
1446 draw_bitmap(temp_bitmap,
1454 -1, // src width and height are meaningless in video_off mode
1467 void BC_WindowBase::draw_3segmenth(int x,
1475 if(w <= 0 || total_w <= 0) return;
1476 if(!src) printf("BC_WindowBase::draw_3segmenth src=0\n");
1477 int quarter_src = src->get_w() / 4;
1478 int half_src = src->get_w() / 2;
1479 //int left_boundary = quarter_src;
1480 //int right_boundary = total_w - quarter_src;
1482 int left_in_w = quarter_src;
1483 int left_out_x = total_x;
1484 int left_out_w = quarter_src;
1485 int right_in_x = src->get_w() - quarter_src;
1486 int right_in_w = quarter_src;
1487 int right_out_x = total_x + total_w - quarter_src;
1488 int right_out_w = quarter_src;
1489 int center_out_x = total_x + quarter_src;
1490 int center_out_w = total_w - quarter_src * 2;
1493 //printf("BC_WindowBase::draw_3segment 1 left_out_x=%d left_out_w=%d center_out_x=%d center_out_w=%d right_out_x=%d right_out_w=%d\n",
1494 // left_out_x, left_out_w, center_out_x, center_out_w, right_out_x, right_out_w);
1498 left_in_w -= x - left_out_x;
1499 left_out_w -= x - left_out_x;
1500 left_in_x += x - left_out_x;
1501 left_out_x += x - left_out_x;
1504 if(left_out_x + left_out_w > x + w)
1506 left_in_w -= (left_out_x + left_out_w) - (x + w);
1507 left_out_w -= (left_out_x + left_out_w) - (x + w);
1512 right_in_w -= x - right_out_x;
1513 right_out_w -= x - right_out_x;
1514 right_in_x += x - right_out_x;
1515 right_out_x += x - right_out_x;
1518 if(right_out_x + right_out_w > x + w)
1520 right_in_w -= (right_out_x + right_out_w) - (x + w);
1521 right_out_w -= (right_out_x + right_out_w) - (x + w);
1524 if(center_out_x < x)
1526 center_out_w -= x - center_out_x;
1527 center_out_x += x - center_out_x;
1530 if(center_out_x + center_out_w > x + w)
1532 center_out_w -= (center_out_x + center_out_w) - (x + w);
1536 //printf("BC_WindowBase::draw_3segment 2 left_out_x=%d left_out_w=%d center_out_x=%d center_out_w=%d right_out_x=%d right_out_w=%d\n",
1537 // left_out_x, left_out_w, center_out_x, center_out_w, right_out_x, right_out_w);
1562 for(int pixel = center_out_x;
1563 pixel < center_out_x + center_out_w;
1566 int fragment_w = half_src;
1567 if(fragment_w + pixel > center_out_x + center_out_w)
1568 fragment_w = (center_out_x + center_out_w) - pixel;
1570 //printf("BC_WindowBase::draw_3segment 2 pixel=%d fragment_w=%d\n", pixel, fragment_w);
1584 void BC_WindowBase::draw_3segmenth(int x,
1591 int third_image = src->get_w() / 3;
1592 int half_output = w / 2;
1593 //int left_boundary = third_image;
1594 //int right_boundary = w - third_image;
1596 int left_in_w = third_image;
1598 int left_out_w = third_image;
1599 int right_in_x = src->get_w() - third_image;
1600 int right_in_w = third_image;
1601 int right_out_x = x + w - third_image;
1602 int right_out_w = third_image;
1603 //int image_x, image_w;
1605 //printf("BC_WindowBase::draw_3segment 1 left_out_x=%d left_out_w=%d center_out_x=%d center_out_w=%d right_out_x=%d right_out_w=%d\n",
1606 // left_out_x, left_out_w, center_out_x, center_out_w, right_out_x, right_out_w);
1608 if(left_out_w > half_output)
1610 left_in_w -= left_out_w - half_output;
1611 left_out_w -= left_out_w - half_output;
1614 if(right_out_x < x + half_output)
1616 right_in_w -= x + half_output - right_out_x;
1617 right_out_w -= x + half_output - right_out_x;
1618 right_in_x += x + half_output - right_out_x;
1619 right_out_x += x + half_output - right_out_x;
1622 //printf("BC_WindowBase::draw_3segment 2 left_out_x=%d left_out_w=%d center_out_x=%d center_out_w=%d right_out_x=%d right_out_w=%d\n",
1623 // left_out_x, left_out_w, center_out_x, center_out_w, right_out_x, right_out_w);
1648 for(int pixel = left_out_x + left_out_w;
1649 pixel < right_out_x;
1650 pixel += third_image)
1652 int fragment_w = third_image;
1653 if(fragment_w + pixel > right_out_x)
1654 fragment_w = right_out_x - pixel;
1656 //printf("BC_WindowBase::draw_3segment 2 pixel=%d fragment_w=%d\n", pixel, fragment_w);
1675 void BC_WindowBase::draw_3segmentv(int x,
1682 int third_image = src->get_h() / 3;
1683 int half_output = h / 2;
1684 //int left_boundary = third_image;
1685 //int right_boundary = h - third_image;
1687 int left_in_h = third_image;
1689 int left_out_h = third_image;
1690 int right_in_y = src->get_h() - third_image;
1691 int right_in_h = third_image;
1692 int right_out_y = y + h - third_image;
1693 int right_out_h = third_image;
1694 //int image_y, image_h;
1697 if(left_out_h > half_output)
1699 left_in_h -= left_out_h - half_output;
1700 left_out_h -= left_out_h - half_output;
1703 if(right_out_y < y + half_output)
1705 right_in_h -= y + half_output - right_out_y;
1706 right_out_h -= y + half_output - right_out_y;
1707 right_in_y += y + half_output - right_out_y;
1708 right_out_y += y + half_output - right_out_y;
1712 if(!temp_bitmap) temp_bitmap = new BC_Bitmap(top_level,
1717 temp_bitmap->match_params(src->get_w(),
1721 temp_bitmap->read_frame(src,
1730 draw_bitmap(temp_bitmap,
1745 draw_bitmap(temp_bitmap,
1758 for(int pixel = left_out_y + left_out_h;
1759 pixel < right_out_y;
1760 pixel += third_image)
1762 int fragment_h = third_image;
1763 if(fragment_h + pixel > right_out_y)
1764 fragment_h = right_out_y - pixel;
1766 //printf("BC_WindowBase::draw_3segment 2 pixel=%d fragment_w=%d\n", pixel, fragment_w);
1767 draw_bitmap(temp_bitmap,
1781 void BC_WindowBase::draw_3segmentv(int x,
1788 int third_image = src->get_h() / 3;
1789 int half_output = h / 2;
1790 //int left_boundary = third_image;
1791 //int right_boundary = h - third_image;
1793 int left_in_h = third_image;
1795 int left_out_h = third_image;
1796 int right_in_y = src->get_h() - third_image;
1797 int right_in_h = third_image;
1798 int right_out_y = y + h - third_image;
1799 int right_out_h = third_image;
1800 //int image_y, image_h;
1803 if(left_out_h > half_output)
1805 left_in_h -= left_out_h - half_output;
1806 left_out_h -= left_out_h - half_output;
1809 if(right_out_y < y + half_output)
1811 right_in_h -= y + half_output - right_out_y;
1812 right_out_h -= y + half_output - right_out_y;
1813 right_in_y += y + half_output - right_out_y;
1814 right_out_y += y + half_output - right_out_y;
1841 for(int pixel = left_out_y + left_out_h;
1842 pixel < right_out_y;
1843 pixel += third_image)
1845 int fragment_h = third_image;
1846 if(fragment_h + pixel > right_out_y)
1847 fragment_h = right_out_y - pixel;
1849 //printf("BC_WindowBase::draw_3segment 2 pixel=%d fragment_w=%d\n", pixel, fragment_w);
1862 void BC_WindowBase::draw_9segment(int x,
1869 if(w <= 0 || h <= 0) return;
1871 int in_x_third = src->get_w() / 3;
1872 int in_y_third = src->get_h() / 3;
1873 int out_x_half = w / 2;
1874 int out_y_half = h / 2;
1880 int in_x2 = MIN(in_x_third, out_x_half);
1881 int in_y2 = MIN(in_y_third, out_y_half);
1885 int out_x3 = MAX(w - out_x_half, w - in_x_third);
1887 int in_x3 = src->get_w() - (out_x4 - out_x3);
1888 //int in_x4 = src->get_w();
1890 int out_y3 = MAX(h - out_y_half, h - in_y_third);
1892 int in_y3 = src->get_h() - (out_y4 - out_y3);
1893 //int in_y4 = src->get_h();
1907 for(int i = out_x2; i < out_x3; i += in_x3 - in_x2)
1911 int w = MIN(in_x3 - in_x2, out_x3 - i);
1940 for(int i = out_y2; i < out_y3; i += in_y3 - in_y2)
1944 int h = MIN(in_y3 - in_y2, out_y3 - i);
1957 // Segment 5 * n * n
1958 for(int i = out_y2; i < out_y3; i += in_y3 - in_y2 /* in_y_third */)
1962 int h = MIN(in_y3 - in_y2 /* in_y_third */, out_y3 - i);
1965 for(int j = out_x2; j < out_x3; j += in_x3 - in_x2 /* in_x_third */)
1967 int w = MIN(in_x3 - in_x2 /* in_x_third */, out_x3 - j);
1982 for(int i = out_y2; i < out_y3; i += in_y3 - in_y2)
1986 int h = MIN(in_y3 - in_y2, out_y3 - i);
2013 for(int i = out_x2; i < out_x3; i += in_x3 - in_x2)
2017 int w = MIN(in_x3 - in_y2, out_x3 - i);
2043 void BC_WindowBase::draw_9segment(int x,
2050 if(w <= 0 || h <= 0) return;
2052 int in_x_third = src->get_w() / 3;
2053 int in_y_third = src->get_h() / 3;
2054 int out_x_half = w / 2;
2055 int out_y_half = h / 2;
2061 int in_x2 = MIN(in_x_third, out_x_half);
2062 int in_y2 = MIN(in_y_third, out_y_half);
2066 int out_x3 = MAX(w - out_x_half, w - in_x_third);
2068 int in_x3 = src->get_w() - (out_x4 - out_x3);
2069 int in_x4 = src->get_w();
2071 int out_y3 = MAX(h - out_y_half, h - in_y_third);
2073 int in_y3 = src->get_h() - (out_y4 - out_y3);
2074 int in_y4 = src->get_h();
2076 //printf("PFCFrame::draw_9segment 1 %d %d %d %d\n", out_x1, out_x2, out_x3, out_x4);
2077 //printf("PFCFrame::draw_9segment 2 %d %d %d %d\n", in_x1, in_x2, in_x3, in_x4);
2078 //printf("PFCFrame::draw_9segment 2 %d %d %d %d\n", in_y1, in_y2, in_y3, in_y4);
2080 if(!temp_bitmap) temp_bitmap = new BC_Bitmap(top_level,
2085 temp_bitmap->match_params(src->get_w(),
2089 temp_bitmap->read_frame(src,
2096 draw_bitmap(temp_bitmap,
2110 for(int i = out_x2; i < out_x3; i += in_x3 - in_x2)
2114 int w = MIN(in_x3 - in_x2, out_x3 - i);
2115 draw_bitmap(temp_bitmap,
2134 draw_bitmap(temp_bitmap,
2149 for(int i = out_y2; i < out_y3; i += in_y3 - in_y2)
2153 int h = MIN(in_y3 - in_y2, out_y3 - i);
2154 draw_bitmap(temp_bitmap,
2169 // Segment 5 * n * n
2170 for(int i = out_y2; i < out_y3; i += in_y3 - in_y2)
2174 int h = MIN(in_y3 - in_y2, out_y3 - i);
2177 for(int j = out_x2; j < out_x3; j += in_x3 - in_x2)
2179 int w = MIN(in_x3 - in_x2, out_x3 - j);
2181 draw_bitmap(temp_bitmap,
2197 for(int i = out_y2; i < out_y3; i += in_y_third)
2201 int h = MIN(in_y_third, out_y3 - i);
2202 draw_bitmap(temp_bitmap,
2220 draw_bitmap(temp_bitmap,
2234 for(int i = out_x2; i < out_x3; i += in_x_third)
2238 int w = MIN(in_x_third, out_x3 - i);
2239 draw_bitmap(temp_bitmap,
2256 draw_bitmap(temp_bitmap,