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);
171 void BC_WindowBase::draw_utf8_text(int x, int y,
172 const char *text, int length, BC_Pixmap *pixmap)
174 if(length < 0) length = strlen(text);
176 if(top_level->get_xft_struct(top_level->current_font))
187 for(int i = 0, j = 0; i <= length; i++)
189 if(text[i] == '\n' || text[i] == 0)
191 if(get_resources()->use_fontset && top_level->get_curr_fontset())
193 XmbDrawString(top_level->display,
194 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
195 top_level->get_curr_fontset(),
204 XDrawString(top_level->display,
205 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
214 y += get_text_height(MEDIUMFONT);
219 void BC_WindowBase::draw_xft_text(int x, int y,
220 const char *text, int length, BC_Pixmap *pixmap, int is_utf8)
223 wchar_t wide_text[l];
224 length = BC_Resources::encode(
225 is_utf8 ? "UTF8" : BC_Resources::encoding, BC_Resources::wide_encoding,
226 (char*)text, length, (char*)wide_text, l*sizeof(wchar_t)) / sizeof(wchar_t);
227 draw_xft_text(x, y, wide_text, length, pixmap);
230 void BC_WindowBase::draw_xft_text(int x, int y,
231 const wchar_t *text, int length, BC_Pixmap *pixmap)
234 const wchar_t *wsp = text, *wep = wsp + length;
236 const wchar_t *wcp = wsp;
237 while( wcp < wep && *wcp != '\n' ) ++wcp;
240 draw_wtext(x, y, wsp, len, pixmap);
241 if( wcp >= wep ) break;
243 dy = get_text_height(top_level->current_font);
249 int BC_WindowBase::wcharpos(const wchar_t *text, XftFont *font, int length,
256 int bpos = charpos[-1];
258 for(int i = 0; i < length; i++)
260 XftTextExtents32(top_level->display,
262 (const FcChar32*)text,
265 charpos[i] = extents.xOff + bpos;
267 return charpos[length - 1] - bpos;
271 XftTextExtents32(top_level->display,
273 (const FcChar32*)text,
280 void BC_WindowBase::draw_wtext(int x, int y,
281 const wchar_t *text, int length, BC_Pixmap *pixmap, int *charpos)
283 if( !get_resources()->use_xft ) {
284 if( !get_font_struct(current_font) ) return;
285 XChar2b xtext[length], *xp = xtext;
286 for( int i=0; i<length; ++i,++xp ) {
287 xp->byte1 = (unsigned char) (text[i] >> 8);
288 xp->byte2 = (unsigned char) (text[i] & 0xff);
290 XDrawString16(top_level->display,
291 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
292 top_level->gc, x, y, xtext, length);
297 const wchar_t *up, *ubp;
300 XftFont *curfont, *nextfont, *altfont, *basefont;
303 length = wcslen(text);
310 color.red = (top_level->current_color & 0xff0000) >> 16;
311 color.red |= color.red << 8;
312 color.green = (top_level->current_color & 0xff00) >> 8;
313 color.green |= color.green << 8;
314 color.blue = (top_level->current_color & 0xff);
315 color.blue |= color.blue << 8;
316 color.alpha = 0xffff;
318 XftColorAllocValue(top_level->display,
324 basefont = top_level->get_xft_struct(top_level->current_font);
326 curfont = nextfont = basefont;
331 for(up = text; up < &text[length]; up++)
333 if(XftCharExists(top_level->display, basefont, *up))
335 else if(altfont && XftCharExists(top_level->display, altfont, *up))
340 XftFontClose(top_level->display, altfont);
342 if( (newpat = BC_Resources::find_similar_font(*up, basefont->pattern)) != 0 ) {
345 FcPatternGetDouble(basefont->pattern, FC_PIXEL_SIZE,
347 FcPatternAddDouble(newpat, FC_PIXEL_SIZE, psize);
348 FcPatternDel(newpat, FC_SCALABLE);
349 altfont = XftFontOpenPattern(top_level->display,
360 if(nextfont != curfont)
363 XftDrawString32((XftDraw*)(pixmap ? pixmap->opaque_xft_draw : this->pixmap->opaque_xft_draw),
368 (const FcChar32*)ubp,
372 cp = &charpos[ubp - text + 1];
374 x += wcharpos(ubp, curfont, l, cp);
382 XftDrawString32((XftDraw*)(pixmap ? pixmap->opaque_xft_draw : this->pixmap->opaque_xft_draw),
387 (const FcChar32*)ubp,
390 wcharpos(ubp, curfont, up - ubp, &charpos[ubp - text + 1]);
394 XftFontClose(top_level->display, altfont);
396 XftColorFree(top_level->display,
402 void BC_WindowBase::truncate_text(char *result, const char *text, int w)
404 int new_w = get_text_width(current_font, text);
408 const char* separator = "...";
409 int separator_w = get_text_width(current_font, separator);
413 strcpy(result, separator);
417 int text_len = strlen(text);
418 // widen middle gap until it fits
419 for(int i = text_len / 2; i > 0; i--)
421 strncpy(result, text, i);
423 strcat(result, separator);
424 strncat(result, text + text_len - i, i);
425 result[i + strlen(separator) + i] = 0;
426 new_w = get_text_width(current_font, result);
427 //printf("BC_WindowBase::truncate_text %d %d %d %s\n", __LINE__, new_w, w, result);
428 if(new_w < w) return;
432 strcpy(result, separator);
437 strcpy(result, text);
441 void BC_WindowBase::draw_center_text(int x, int y, const char *text, int length)
443 if(length < 0) length = strlen(text);
444 int w = get_text_width(current_font, text, length);
446 draw_text(x, y, text, length);
449 void BC_WindowBase::draw_line(int x1, int y1, int x2, int y2, BC_Pixmap *pixmap)
451 // Some X drivers can't draw 0 length lines
452 if(x1 == x2 && y1 == y2)
454 draw_pixel(x1, y1, pixmap);
458 XDrawLine(top_level->display,
459 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
468 void BC_WindowBase::draw_polygon(ArrayList<int> *x, ArrayList<int> *y, BC_Pixmap *pixmap)
470 int npoints = MIN(x->total, y->total);
471 XPoint *points = new XPoint[npoints];
473 for(int i = 0; i < npoints; i++)
475 points[i].x = x->values[i];
476 points[i].y = y->values[i];
479 XDrawLines(top_level->display,
480 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
489 void BC_WindowBase::fill_polygon(ArrayList<int> *x, ArrayList<int> *y, BC_Pixmap *pixmap)
491 int npoints = MIN(x->total, y->total);
492 XPoint *points = new XPoint[npoints];
494 for(int i = 0; i < npoints; i++)
496 points[i].x = x->values[i];
497 points[i].y = y->values[i];
500 XFillPolygon(top_level->display,
501 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
512 void BC_WindowBase::draw_rectangle(int x, int y, int w, int h)
514 XDrawRectangle(top_level->display,
515 pixmap->opaque_pixmap,
523 void BC_WindowBase::draw_3d_border(int x,
533 top_level->get_resources()->border_shadow2,
534 top_level->get_resources()->border_shadow1,
535 top_level->get_resources()->border_light1,
536 top_level->get_resources()->border_light2);
540 void BC_WindowBase::draw_3d_border(int x,
554 ux = x+w-1; uy = y+h-1;
557 draw_line(x, y, ux, y);
558 draw_line(x, y, x, uy);
560 draw_line(lx, ly, ux - 1, ly);
561 draw_line(lx, ly, lx, uy - 1);
564 draw_line(ux, ly, ux, uy);
565 draw_line(lx, uy, ux, uy);
567 draw_line(x + w, y, x + w, y + h);
568 draw_line(x, y + h, x + w, y + h);
571 void BC_WindowBase::draw_3d_box(int x,
587 ux = x+w-1; uy = y+h-1;
590 draw_box(x, y, w, h, pixmap);
593 draw_line(x, y, ux, y, pixmap);
594 draw_line(x, y, x, uy, pixmap);
596 draw_line(lx, ly, ux - 1, ly, pixmap);
597 draw_line(lx, ly, lx, uy - 1, pixmap);
600 draw_line(ux, ly, ux, uy, pixmap);
601 draw_line(lx, uy, ux, uy, pixmap);
603 draw_line(x + w, y, x + w, y + h, pixmap);
604 draw_line(x, y + h, x + w, y + h, pixmap);
607 void BC_WindowBase::draw_colored_box(int x, int y, int w, int h, int down, int highlighted)
612 draw_3d_box(x, y, w, h,
613 top_level->get_resources()->button_light,
614 top_level->get_resources()->button_highlighted,
615 top_level->get_resources()->button_highlighted,
616 top_level->get_resources()->button_shadow,
619 draw_3d_box(x, y, w, h,
620 top_level->get_resources()->button_light,
621 top_level->get_resources()->button_up,
622 top_level->get_resources()->button_up,
623 top_level->get_resources()->button_shadow,
628 // need highlighting for toggles
630 draw_3d_box(x, y, w, h,
631 top_level->get_resources()->button_shadow,
633 top_level->get_resources()->button_up,
634 top_level->get_resources()->button_up,
635 top_level->get_resources()->button_light);
637 draw_3d_box(x, y, w, h,
638 top_level->get_resources()->button_shadow,
640 top_level->get_resources()->button_down,
641 top_level->get_resources()->button_down,
642 top_level->get_resources()->button_light);
647 void BC_WindowBase::draw_border(char *text, int x, int y, int w, int h)
649 int left_indent = 20;
653 lx = x + 1; ly = y + 1;
654 ux = x + w - 1; uy = y + h - 1;
657 if(text && text[0] != 0)
660 set_font(MEDIUMFONT);
661 draw_text(x + left_indent, y + get_text_height(MEDIUMFONT) / 2, text);
664 set_color(top_level->get_resources()->button_shadow);
665 draw_line(x, y, x + left_indent - 5, y);
666 draw_line(x, y, x, uy);
667 draw_line(x + left_indent + 5 + get_text_width(MEDIUMFONT, text), y, ux, y);
668 draw_line(x, y, x, uy);
669 draw_line(ux, ly, ux, uy);
670 draw_line(lx, uy, ux, uy);
671 set_color(top_level->get_resources()->button_light);
672 draw_line(lx, ly, x + left_indent - 5 - 1, ly);
673 draw_line(lx, ly, lx, uy - 1);
674 draw_line(x + left_indent + 5 + get_text_width(MEDIUMFONT, text), ly, ux - 1, ly);
675 draw_line(lx, ly, lx, uy - 1);
676 draw_line(x + w, y, x + w, y + h);
677 draw_line(x, y + h, x + w, y + h);
680 void BC_WindowBase::draw_triangle_down_flat(int x, int y, int w, int h)
682 int x1, y1, x2, y2, x3;
685 x1 = x; x2 = x + w / 2; x3 = x + w - 1;
686 y1 = y; y2 = y + h - 1;
688 point[0].x = x2; point[0].y = y2; point[1].x = x3;
689 point[1].y = y1; point[2].x = x1; point[2].y = y1;
691 XFillPolygon(top_level->display,
692 pixmap->opaque_pixmap,
700 void BC_WindowBase::draw_triangle_up(int x, int y, int w, int h,
701 int light1, int light2, int middle, int shadow1, int shadow2)
703 int x1, y1, x2, y2, x3;
706 x1 = x; y1 = y; x2 = x + w / 2;
707 y2 = y + h - 1; x3 = x + w - 1;
710 point[0].x = x2; point[0].y = y1; point[1].x = x3;
711 point[1].y = y2; point[2].x = x1; point[2].y = y2;
714 XFillPolygon(top_level->display,
715 pixmap->opaque_pixmap,
722 // bottom and top right
724 draw_line(x3, y2-1, x1, y2-1);
725 draw_line(x2-1, y1, x3-1, y2);
727 draw_line(x3, y2, x1, y2);
728 draw_line(x2, y1, x3, y2);
732 draw_line(x2+1, y1, x1+1, y2);
734 draw_line(x2, y1, x1, y2);
737 void BC_WindowBase::draw_triangle_down(int x, int y, int w, int h,
738 int light1, int light2, int middle, int shadow1, int shadow2)
740 int x1, y1, x2, y2, x3;
743 x1 = x; x2 = x + w / 2; x3 = x + w - 1;
744 y1 = y; y2 = y + h - 1;
746 point[0].x = x2; point[0].y = y2; point[1].x = x3;
747 point[1].y = y1; point[2].x = x1; point[2].y = y1;
750 XFillPolygon(top_level->display,
751 pixmap->opaque_pixmap,
758 // top and bottom left
760 draw_line(x3-1, y1+1, x1+1, y1+1);
761 draw_line(x1+1, y1, x2+1, y2);
763 draw_line(x3, y1, x1, y1);
764 draw_line(x1, y1, x2, y2);
768 draw_line(x3-1, y1, x2-1, y2);
770 draw_line(x3, y1, x2, y2);
773 void BC_WindowBase::draw_triangle_left(int x, int y, int w, int h,
774 int light1, int light2, int middle, int shadow1, int shadow2)
776 int x1, y1, x2, y2, y3;
780 y1 = y; x1 = x; y2 = y + h / 2;
781 x2 = x + w - 1; y3 = y + h - 1;
783 point[0].x = x1; point[0].y = y2; point[1].x = x2;
784 point[1].y = y1; point[2].x = x2; point[2].y = y3;
787 XFillPolygon(top_level->display,
788 pixmap->opaque_pixmap,
795 // right and bottom right
797 draw_line(x2-1, y1, x2-1, y3-1);
798 draw_line(x2, y3-1, x1, y2-1);
800 draw_line(x2, y1, x2, y3);
801 draw_line(x2, y3, x1, y2);
805 draw_line(x1, y2, x2, y1);
807 draw_line(x1, y2+1, x2, y1+1);
810 void BC_WindowBase::draw_triangle_right(int x, int y, int w, int h,
811 int light1, int light2, int middle, int shadow1, int shadow2)
813 int x1, y1, x2, y2, y3;
816 y1 = y; y2 = y + h / 2; y3 = y + h - 1;
817 x1 = x; x2 = x + w - 1;
819 point[0].x = x1; point[0].y = y1; point[1].x = x2;
820 point[1].y = y2; point[2].x = x1; point[2].y = y3;
823 XFillPolygon(top_level->display,
824 pixmap->opaque_pixmap,
831 // left and top right
833 draw_line(x1+1, y3, x1+1, y1);
834 draw_line(x1, y1+1, x2, y2+1);
836 draw_line(x1, y3, x1, y1);
837 draw_line(x1, y1, x2, y2);
841 draw_line(x2, y2-1, x1, y3-1);
843 draw_line(x2, y2, x1, y3);
847 void BC_WindowBase::draw_check(int x, int y)
849 const int w = 15, h = 15;
850 draw_line(x + 3, y + h / 2 + 0, x + 6, y + h / 2 + 2);
851 draw_line(x + 3, y + h / 2 + 1, x + 6, y + h / 2 + 3);
852 draw_line(x + 6, y + h / 2 + 2, x + w - 4, y + h / 2 - 3);
853 draw_line(x + 3, y + h / 2 + 2, x + 6, y + h / 2 + 4);
854 draw_line(x + 6, y + h / 2 + 2, x + w - 4, y + h / 2 - 3);
855 draw_line(x + 6, y + h / 2 + 3, x + w - 4, y + h / 2 - 2);
856 draw_line(x + 6, y + h / 2 + 4, x + w - 4, y + h / 2 - 1);
859 void BC_WindowBase::draw_tiles(BC_Pixmap *tile, int origin_x, int origin_y, int x, int y, int w, int h)
864 draw_box(x, y, w, h);
868 XSetFillStyle(top_level->display, top_level->gc, FillTiled);
869 // Don't know how slow this is
870 XSetTile(top_level->display, top_level->gc, tile->get_pixmap());
871 XSetTSOrigin(top_level->display, top_level->gc, origin_x, origin_y);
872 draw_box(x, y, w, h);
873 XSetFillStyle(top_level->display, top_level->gc, FillSolid);
877 void BC_WindowBase::draw_top_tiles(BC_WindowBase *parent_window, int x, int y, int w, int h)
880 int origin_x, origin_y;
881 XTranslateCoordinates(top_level->display,
890 draw_tiles(parent_window->bg_pixmap,
899 void BC_WindowBase::draw_top_background(BC_WindowBase *parent_window,
908 XLockDisplay(top_level->display);
910 XTranslateCoordinates(top_level->display,
919 XCopyArea(top_level->display,
920 parent_window->pixmap->opaque_pixmap,
921 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
930 XUnlockDisplay(top_level->display);
933 void BC_WindowBase::draw_background(int x, int y, int w, int h)
937 draw_tiles(bg_pixmap, 0, 0, x, y, w, h);
941 clear_box(x, y, w, h);
945 void BC_WindowBase::draw_bitmap(BC_Bitmap *bitmap,
958 // Hide cursor if video enabled
959 update_video_cursor();
961 //printf("BC_WindowBase::draw_bitmap 1\n");
962 if(dest_w <= 0 || dest_h <= 0)
964 // Use hardware scaling to canvas dimensions if proper color model.
965 if(bitmap->get_color_model() == BC_YUV420P)
972 dest_w = bitmap->get_w();
973 dest_h = bitmap->get_h();
977 if(src_w <= 0 || src_h <= 0)
979 src_w = bitmap->get_w();
980 src_h = bitmap->get_h();
985 bitmap->write_drawable(win,
1000 bitmap->write_drawable(pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
1010 //printf("BC_WindowBase::draw_bitmap 2\n");
1014 void BC_WindowBase::draw_pixel(int x, int y, BC_Pixmap *pixmap)
1016 XDrawPoint(top_level->display,
1017 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
1024 void BC_WindowBase::draw_pixmap(BC_Pixmap *pixmap,
1033 pixmap->write_drawable(dst ? dst->opaque_pixmap : this->pixmap->opaque_pixmap,
1042 void BC_WindowBase::draw_vframe(VFrame *frame,
1053 if(dest_w <= 0) dest_w = frame->get_w() - src_x;
1054 if(dest_h <= 0) dest_h = frame->get_h() - src_y;
1055 if(src_w <= 0) src_w = frame->get_w() - src_x;
1056 if(src_h <= 0) src_h = frame->get_h() - src_y;
1057 CLAMP(src_x, 0, frame->get_w() - 1);
1058 CLAMP(src_y, 0, frame->get_h() - 1);
1059 if(src_x + src_w > frame->get_w()) src_w = frame->get_w() - src_x;
1060 if(src_y + src_h > frame->get_h()) src_h = frame->get_h() - src_y;
1062 if(!temp_bitmap) temp_bitmap = new BC_Bitmap(this,
1068 temp_bitmap->match_params(dest_w,
1073 temp_bitmap->read_frame(frame,
1083 draw_bitmap(temp_bitmap,
1096 void BC_WindowBase::draw_tooltip()
1098 if(tooltip_popup && tooltip_text)
1100 int w = tooltip_popup->get_w(), h = tooltip_popup->get_h();
1101 tooltip_popup->set_color(get_resources()->tooltip_bg_color);
1102 tooltip_popup->draw_box(0, 0, w, h);
1103 tooltip_popup->set_color(BLACK);
1104 tooltip_popup->draw_rectangle(0, 0, w, h);
1105 tooltip_popup->set_font(MEDIUMFONT);
1106 tooltip_popup->draw_text(TOOLTIP_MARGIN,
1107 get_text_ascent(MEDIUMFONT) + TOOLTIP_MARGIN,
1112 void BC_WindowBase::slide_left(int distance)
1116 XCopyArea(top_level->display,
1117 pixmap->opaque_pixmap,
1118 pixmap->opaque_pixmap,
1129 void BC_WindowBase::slide_right(int distance)
1133 XCopyArea(top_level->display,
1134 pixmap->opaque_pixmap,
1135 pixmap->opaque_pixmap,
1146 void BC_WindowBase::slide_up(int distance)
1150 XCopyArea(top_level->display,
1151 pixmap->opaque_pixmap,
1152 pixmap->opaque_pixmap,
1160 set_color(bg_color);
1161 XFillRectangle(top_level->display,
1162 pixmap->opaque_pixmap,
1171 void BC_WindowBase::slide_down(int distance)
1175 XCopyArea(top_level->display,
1176 pixmap->opaque_pixmap,
1177 pixmap->opaque_pixmap,
1185 set_color(bg_color);
1186 XFillRectangle(top_level->display,
1187 pixmap->opaque_pixmap,
1196 // 3 segments in separate pixmaps. Obsolete.
1197 void BC_WindowBase::draw_3segment(int x,
1201 BC_Pixmap *left_image,
1202 BC_Pixmap *mid_image,
1203 BC_Pixmap *right_image,
1206 if(w <= 0 || h <= 0) return;
1207 int left_boundary = left_image->get_w_fixed();
1208 int right_boundary = w - right_image->get_w_fixed();
1209 for(int i = 0; i < w; )
1213 if(i < left_boundary)
1216 if(i < right_boundary)
1219 image = right_image;
1221 int output_w = image->get_w_fixed();
1223 if(i < left_boundary)
1225 if(i + output_w > left_boundary) output_w = left_boundary - i;
1228 if(i < right_boundary)
1230 if(i + output_w > right_boundary) output_w = right_boundary - i;
1233 if(i + output_w > w) output_w = w - i;
1235 image->write_drawable(pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
1246 // 3 segments in separate vframes. Obsolete.
1247 void BC_WindowBase::draw_3segment(int x,
1253 VFrame *right_image,
1256 if(w <= 0 || h <= 0) return;
1257 int left_boundary = left_image->get_w_fixed();
1258 int right_boundary = w - right_image->get_w_fixed();
1261 for(int i = 0; i < w; )
1265 if(i < left_boundary)
1268 if(i < right_boundary)
1271 image = right_image;
1273 int output_w = image->get_w_fixed();
1275 if(i < left_boundary)
1277 if(i + output_w > left_boundary) output_w = left_boundary - i;
1280 if(i < right_boundary)
1282 if(i + output_w > right_boundary) output_w = right_boundary - i;
1285 if(i + output_w > w) output_w = w - i;
1299 if(output_w == 0) break;
1304 // Draw all 3 segments in a single vframe for a changing level
1309 // <------------------------------------------------------------>
1313 // <-------------------------------------------------------------------->
1315 // |-------------------|----------------------|------------------|
1318 void BC_WindowBase::draw_3segmenth(int x,
1333 void BC_WindowBase::draw_3segmenth(int x,
1341 if(total_w <= 0 || w <= 0 || h <= 0) return;
1342 int third_image = image->get_w() / 3;
1343 int half_image = image->get_w() / 2;
1344 //int left_boundary = third_image;
1345 //int right_boundary = total_w - third_image;
1347 int left_in_w = third_image;
1348 int left_out_x = total_x;
1349 int left_out_w = third_image;
1350 int right_in_x = image->get_w() - third_image;
1351 int right_in_w = third_image;
1352 int right_out_x = total_x + total_w - third_image;
1353 int right_out_w = third_image;
1354 int center_out_x = total_x + third_image;
1355 int center_out_w = total_w - third_image * 2;
1356 //int image_x, image_w;
1358 //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",
1359 // left_out_x, left_out_w, center_out_x, center_out_w, right_out_x, right_out_w);
1363 left_in_w -= x - left_out_x;
1364 left_out_w -= x - left_out_x;
1365 left_in_x += x - left_out_x;
1366 left_out_x += x - left_out_x;
1369 if(left_out_x + left_out_w > x + w)
1371 left_in_w -= (left_out_x + left_out_w) - (x + w);
1372 left_out_w -= (left_out_x + left_out_w) - (x + w);
1377 right_in_w -= x - right_out_x;
1378 right_out_w -= x - right_out_x;
1379 right_in_x += x - right_out_x;
1380 right_out_x += x - right_out_x;
1383 if(right_out_x + right_out_w > x + w)
1385 right_in_w -= (right_out_x + right_out_w) - (x + w);
1386 right_out_w -= (right_out_x + right_out_w) - (x + w);
1389 if(center_out_x < x)
1391 center_out_w -= x - center_out_x;
1392 center_out_x += x - center_out_x;
1395 if(center_out_x + center_out_w > x + w)
1397 center_out_w -= (center_out_x + center_out_w) - (x + w);
1400 if(!temp_bitmap) temp_bitmap = new BC_Bitmap(top_level,
1405 temp_bitmap->match_params(image->get_w(),
1409 temp_bitmap->read_frame(image,
1416 //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",
1417 // left_out_x, left_out_w, center_out_x, center_out_w, right_out_x, right_out_w);
1420 draw_bitmap(temp_bitmap,
1428 -1, // src width and height are meaningless in video_off mode
1435 draw_bitmap(temp_bitmap,
1443 -1, // src width and height are meaningless in video_off mode
1448 for(int pixel = center_out_x;
1449 pixel < center_out_x + center_out_w;
1450 pixel += half_image)
1452 int fragment_w = half_image;
1453 if(fragment_w + pixel > center_out_x + center_out_w)
1454 fragment_w = (center_out_x + center_out_w) - pixel;
1456 //printf("BC_WindowBase::draw_3segment 2 pixel=%d fragment_w=%d\n", pixel, fragment_w);
1457 draw_bitmap(temp_bitmap,
1465 -1, // src width and height are meaningless in video_off mode
1478 void BC_WindowBase::draw_3segmenth(int x,
1486 if(w <= 0 || total_w <= 0) return;
1487 if(!src) printf("BC_WindowBase::draw_3segmenth src=0\n");
1488 int quarter_src = src->get_w() / 4;
1489 int half_src = src->get_w() / 2;
1490 //int left_boundary = quarter_src;
1491 //int right_boundary = total_w - quarter_src;
1493 int left_in_w = quarter_src;
1494 int left_out_x = total_x;
1495 int left_out_w = quarter_src;
1496 int right_in_x = src->get_w() - quarter_src;
1497 int right_in_w = quarter_src;
1498 int right_out_x = total_x + total_w - quarter_src;
1499 int right_out_w = quarter_src;
1500 int center_out_x = total_x + quarter_src;
1501 int center_out_w = total_w - quarter_src * 2;
1504 //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",
1505 // left_out_x, left_out_w, center_out_x, center_out_w, right_out_x, right_out_w);
1509 left_in_w -= x - left_out_x;
1510 left_out_w -= x - left_out_x;
1511 left_in_x += x - left_out_x;
1512 left_out_x += x - left_out_x;
1515 if(left_out_x + left_out_w > x + w)
1517 left_in_w -= (left_out_x + left_out_w) - (x + w);
1518 left_out_w -= (left_out_x + left_out_w) - (x + w);
1523 right_in_w -= x - right_out_x;
1524 right_out_w -= x - right_out_x;
1525 right_in_x += x - right_out_x;
1526 right_out_x += x - right_out_x;
1529 if(right_out_x + right_out_w > x + w)
1531 right_in_w -= (right_out_x + right_out_w) - (x + w);
1532 right_out_w -= (right_out_x + right_out_w) - (x + w);
1535 if(center_out_x < x)
1537 center_out_w -= x - center_out_x;
1538 center_out_x += x - center_out_x;
1541 if(center_out_x + center_out_w > x + w)
1543 center_out_w -= (center_out_x + center_out_w) - (x + w);
1547 //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",
1548 // left_out_x, left_out_w, center_out_x, center_out_w, right_out_x, right_out_w);
1573 for(int pixel = center_out_x;
1574 pixel < center_out_x + center_out_w;
1577 int fragment_w = half_src;
1578 if(fragment_w + pixel > center_out_x + center_out_w)
1579 fragment_w = (center_out_x + center_out_w) - pixel;
1581 //printf("BC_WindowBase::draw_3segment 2 pixel=%d fragment_w=%d\n", pixel, fragment_w);
1595 void BC_WindowBase::draw_3segmenth(int x,
1602 int third_image = src->get_w() / 3;
1603 int half_output = w / 2;
1604 //int left_boundary = third_image;
1605 //int right_boundary = w - third_image;
1607 int left_in_w = third_image;
1609 int left_out_w = third_image;
1610 int right_in_x = src->get_w() - third_image;
1611 int right_in_w = third_image;
1612 int right_out_x = x + w - third_image;
1613 int right_out_w = third_image;
1614 //int image_x, image_w;
1616 //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",
1617 // left_out_x, left_out_w, center_out_x, center_out_w, right_out_x, right_out_w);
1619 if(left_out_w > half_output)
1621 left_in_w -= left_out_w - half_output;
1622 left_out_w -= left_out_w - half_output;
1625 if(right_out_x < x + half_output)
1627 right_in_w -= x + half_output - right_out_x;
1628 right_out_w -= x + half_output - right_out_x;
1629 right_in_x += x + half_output - right_out_x;
1630 right_out_x += x + half_output - right_out_x;
1633 //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",
1634 // left_out_x, left_out_w, center_out_x, center_out_w, right_out_x, right_out_w);
1659 for(int pixel = left_out_x + left_out_w;
1660 pixel < right_out_x;
1661 pixel += third_image)
1663 int fragment_w = third_image;
1664 if(fragment_w + pixel > right_out_x)
1665 fragment_w = right_out_x - pixel;
1667 //printf("BC_WindowBase::draw_3segment 2 pixel=%d fragment_w=%d\n", pixel, fragment_w);
1686 void BC_WindowBase::draw_3segmentv(int x,
1693 int third_image = src->get_h() / 3;
1694 int half_output = h / 2;
1695 //int left_boundary = third_image;
1696 //int right_boundary = h - third_image;
1698 int left_in_h = third_image;
1700 int left_out_h = third_image;
1701 int right_in_y = src->get_h() - third_image;
1702 int right_in_h = third_image;
1703 int right_out_y = y + h - third_image;
1704 int right_out_h = third_image;
1705 //int image_y, image_h;
1708 if(left_out_h > half_output)
1710 left_in_h -= left_out_h - half_output;
1711 left_out_h -= left_out_h - half_output;
1714 if(right_out_y < y + half_output)
1716 right_in_h -= y + half_output - right_out_y;
1717 right_out_h -= y + half_output - right_out_y;
1718 right_in_y += y + half_output - right_out_y;
1719 right_out_y += y + half_output - right_out_y;
1723 if(!temp_bitmap) temp_bitmap = new BC_Bitmap(top_level,
1728 temp_bitmap->match_params(src->get_w(),
1732 temp_bitmap->read_frame(src,
1741 draw_bitmap(temp_bitmap,
1756 draw_bitmap(temp_bitmap,
1769 for(int pixel = left_out_y + left_out_h;
1770 pixel < right_out_y;
1771 pixel += third_image)
1773 int fragment_h = third_image;
1774 if(fragment_h + pixel > right_out_y)
1775 fragment_h = right_out_y - pixel;
1777 //printf("BC_WindowBase::draw_3segment 2 pixel=%d fragment_w=%d\n", pixel, fragment_w);
1778 draw_bitmap(temp_bitmap,
1792 void BC_WindowBase::draw_3segmentv(int x,
1799 int third_image = src->get_h() / 3;
1800 int half_output = h / 2;
1801 //int left_boundary = third_image;
1802 //int right_boundary = h - third_image;
1804 int left_in_h = third_image;
1806 int left_out_h = third_image;
1807 int right_in_y = src->get_h() - third_image;
1808 int right_in_h = third_image;
1809 int right_out_y = y + h - third_image;
1810 int right_out_h = third_image;
1811 //int image_y, image_h;
1814 if(left_out_h > half_output)
1816 left_in_h -= left_out_h - half_output;
1817 left_out_h -= left_out_h - half_output;
1820 if(right_out_y < y + half_output)
1822 right_in_h -= y + half_output - right_out_y;
1823 right_out_h -= y + half_output - right_out_y;
1824 right_in_y += y + half_output - right_out_y;
1825 right_out_y += y + half_output - right_out_y;
1852 for(int pixel = left_out_y + left_out_h;
1853 pixel < right_out_y;
1854 pixel += third_image)
1856 int fragment_h = third_image;
1857 if(fragment_h + pixel > right_out_y)
1858 fragment_h = right_out_y - pixel;
1860 //printf("BC_WindowBase::draw_3segment 2 pixel=%d fragment_w=%d\n", pixel, fragment_w);
1873 void BC_WindowBase::draw_9segment(int x,
1880 if(w <= 0 || h <= 0) return;
1882 int in_x_third = src->get_w() / 3;
1883 int in_y_third = src->get_h() / 3;
1884 int out_x_half = w / 2;
1885 int out_y_half = h / 2;
1891 int in_x2 = MIN(in_x_third, out_x_half);
1892 int in_y2 = MIN(in_y_third, out_y_half);
1896 int out_x3 = MAX(w - out_x_half, w - in_x_third);
1898 int in_x3 = src->get_w() - (out_x4 - out_x3);
1899 //int in_x4 = src->get_w();
1901 int out_y3 = MAX(h - out_y_half, h - in_y_third);
1903 int in_y3 = src->get_h() - (out_y4 - out_y3);
1904 //int in_y4 = src->get_h();
1918 for(int i = out_x2; i < out_x3; i += in_x3 - in_x2)
1922 int w = MIN(in_x3 - in_x2, out_x3 - i);
1951 for(int i = out_y2; i < out_y3; i += in_y3 - in_y2)
1955 int h = MIN(in_y3 - in_y2, out_y3 - i);
1968 // Segment 5 * n * n
1969 for(int i = out_y2; i < out_y3; i += in_y3 - in_y2 /* in_y_third */)
1973 int h = MIN(in_y3 - in_y2 /* in_y_third */, out_y3 - i);
1976 for(int j = out_x2; j < out_x3; j += in_x3 - in_x2 /* in_x_third */)
1978 int w = MIN(in_x3 - in_x2 /* in_x_third */, out_x3 - j);
1993 for(int i = out_y2; i < out_y3; i += in_y3 - in_y2)
1997 int h = MIN(in_y3 - in_y2, out_y3 - i);
2024 for(int i = out_x2; i < out_x3; i += in_x3 - in_x2)
2028 int w = MIN(in_x3 - in_y2, out_x3 - i);
2054 void BC_WindowBase::draw_9segment(int x,
2061 if(w <= 0 || h <= 0) return;
2063 int in_x_third = src->get_w() / 3;
2064 int in_y_third = src->get_h() / 3;
2065 int out_x_half = w / 2;
2066 int out_y_half = h / 2;
2072 int in_x2 = MIN(in_x_third, out_x_half);
2073 int in_y2 = MIN(in_y_third, out_y_half);
2077 int out_x3 = MAX(w - out_x_half, w - in_x_third);
2079 int in_x3 = src->get_w() - (out_x4 - out_x3);
2080 int in_x4 = src->get_w();
2082 int out_y3 = MAX(h - out_y_half, h - in_y_third);
2084 int in_y3 = src->get_h() - (out_y4 - out_y3);
2085 int in_y4 = src->get_h();
2087 //printf("PFCFrame::draw_9segment 1 %d %d %d %d\n", out_x1, out_x2, out_x3, out_x4);
2088 //printf("PFCFrame::draw_9segment 2 %d %d %d %d\n", in_x1, in_x2, in_x3, in_x4);
2089 //printf("PFCFrame::draw_9segment 2 %d %d %d %d\n", in_y1, in_y2, in_y3, in_y4);
2091 if(!temp_bitmap) temp_bitmap = new BC_Bitmap(top_level,
2096 temp_bitmap->match_params(src->get_w(),
2100 temp_bitmap->read_frame(src,
2107 draw_bitmap(temp_bitmap,
2121 for(int i = out_x2; i < out_x3; i += in_x3 - in_x2)
2125 int w = MIN(in_x3 - in_x2, out_x3 - i);
2126 draw_bitmap(temp_bitmap,
2145 draw_bitmap(temp_bitmap,
2160 for(int i = out_y2; i < out_y3; i += in_y3 - in_y2)
2164 int h = MIN(in_y3 - in_y2, out_y3 - i);
2165 draw_bitmap(temp_bitmap,
2180 // Segment 5 * n * n
2181 for(int i = out_y2; i < out_y3; i += in_y3 - in_y2)
2185 int h = MIN(in_y3 - in_y2, out_y3 - i);
2188 for(int j = out_x2; j < out_x3; j += in_x3 - in_x2)
2190 int w = MIN(in_x3 - in_x2, out_x3 - j);
2192 draw_bitmap(temp_bitmap,
2208 for(int i = out_y2; i < out_y3; i += in_y_third)
2212 int h = MIN(in_y_third, out_y3 - i);
2213 draw_bitmap(temp_bitmap,
2231 draw_bitmap(temp_bitmap,
2245 for(int i = out_x2; i < out_x3; i += in_x_third)
2249 int w = MIN(in_x_third, out_x3 - i);
2250 draw_bitmap(temp_bitmap,
2267 draw_bitmap(temp_bitmap,