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 #include "workarounds.h"
41 void BC_WindowBase::copy_area(int x1, int y1, int x2, int y2, int w, int h, BC_Pixmap *pixmap)
43 XCopyArea(top_level->display,
44 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
45 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
46 top_level->gc, x1, y1, w, h, x2, y2);
50 void BC_WindowBase::draw_box(int x, int y, int w, int h, BC_Pixmap *pixmap)
52 //if(x == 0) printf("BC_WindowBase::draw_box %d %d %d %d\n", x, y, w, h);
53 XFillRectangle(top_level->display,
54 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
55 top_level->gc, x, y, w, h);
59 void BC_WindowBase::draw_circle(int x, int y, int w, int h, BC_Pixmap *pixmap)
61 XDrawArc(top_level->display,
62 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
63 top_level->gc, x, y, (w - 1), (h - 2), 0 * 64, 360 * 64);
66 void BC_WindowBase::draw_arc(int x, int y, int w, int h,
67 int start_angle, int angle_length, BC_Pixmap *pixmap)
69 XDrawArc(top_level->display,
70 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
71 top_level->gc, x, y, (w - 1), (h - 2), start_angle * 64,
75 void BC_WindowBase::draw_disc(int x, int y, int w, int h, BC_Pixmap *pixmap)
77 XFillArc(top_level->display,
78 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
79 top_level->gc, x, y, (w - 1), (h - 2), 0 * 64, 360 * 64);
82 void BC_WindowBase::clear_box(int x, int y, int w, int h, BC_Pixmap *pixmap)
85 Pixmap xpixmap = pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap;
86 XFillRectangle(top_level->display, xpixmap, top_level->gc, x, y, w, h);
89 void BC_WindowBase::draw_text_line(int x, int y, const char *text, int len,
93 if( get_resources()->use_xft ) {
94 draw_xft_text(x, y, text, len, pixmap);
99 Pixmap xpixmap = pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap;
100 if( get_resources()->use_fontset ) {
101 XFontSet fontset = top_level->get_curr_fontset();
103 XmbDrawString(top_level->display, xpixmap, fontset,
104 top_level->gc, x, y, text, len);
109 //printf("BC_WindowBase::draw_text 3\n");
110 XDrawString(top_level->display, xpixmap, top_level->gc, x, y, text, len);
113 void BC_WindowBase::draw_text(int x, int y, const char *text, int length,
116 if( length < 0 ) length = strlen(text);
117 //int boldface = top_level->current_font & BOLDFACE;
118 int font = top_level->current_font & 0xff;
120 switch(top_level->current_font) {
121 case MEDIUM_7SEGMENT:
122 for(int i = 0; i < length; i++) {
123 VFrame *image, **img7seg = get_resources()->medium_7segment;
126 case '0': case '1': case '2': case '3': case '4':
127 case '5': case '6': case '7': case '8': case '9':
128 image = img7seg[ch-'0']; break;
129 case ':': image = img7seg[10]; break;
130 case '.': image = img7seg[11]; break;
131 case 'a': case 'b': case 'c':
132 case 'd': case 'e': case 'f': ch -= 'a'-'A';
133 case 'A': case 'B': case 'C': /* fallthru */
134 case 'D': case 'E': case 'F':
135 image = img7seg[12+ch-'A']; break;
137 case '-': image = img7seg[19]; break;
139 case ' ': image = img7seg[18]; break;
142 draw_vframe(image, x, y - image->get_h());
148 if(top_level->get_xft_struct(top_level->current_font)) {
149 draw_xft_text(x, y, text, length, pixmap);
153 for(int i = 0, j = 0; i <= length; i++) {
154 if(text[i] == '\n' || text[i] == 0) {
155 if(get_resources()->use_fontset && top_level->get_curr_fontset()) {
156 XmbDrawString(top_level->display,
157 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
158 top_level->get_curr_fontset(),
159 top_level->gc, x, y, &text[j], i-j);
162 XDrawString(top_level->display,
163 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
164 top_level->gc, x, y, &text[j], i-j);
167 y += get_text_height(font);
174 void BC_WindowBase::draw_utf8_text(int x, int y,
175 const char *text, int length, BC_Pixmap *pixmap)
177 if(length < 0) length = strlen(text);
179 if(top_level->get_xft_struct(top_level->current_font))
190 for(int i = 0, j = 0; i <= length; i++)
192 if(text[i] == '\n' || text[i] == 0)
194 if(get_resources()->use_fontset && top_level->get_curr_fontset())
196 XmbDrawString(top_level->display,
197 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
198 top_level->get_curr_fontset(),
207 XDrawString(top_level->display,
208 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
217 y += get_text_height(MEDIUMFONT);
222 void BC_WindowBase::draw_xft_text(int x, int y,
223 const char *text, int length, BC_Pixmap *pixmap, int is_utf8)
226 wchar_t wide_text[l];
227 length = BC_Resources::encode(
228 is_utf8 ? "UTF8" : BC_Resources::encoding, BC_Resources::wide_encoding,
229 (char*)text, length, (char*)wide_text, l*sizeof(wchar_t)) / sizeof(wchar_t);
230 draw_xft_text(x, y, wide_text, length, pixmap);
233 void BC_WindowBase::draw_xft_text(int x, int y,
234 const wchar_t *text, int length, BC_Pixmap *pixmap)
237 const wchar_t *wsp = text, *wep = wsp + length;
238 int font = top_level->current_font;
240 const wchar_t *wcp = wsp;
241 while( wcp < wep && *wcp != '\n' ) ++wcp;
244 draw_single_text(1, font, x, y, wsp, len, pixmap);
245 if( wcp >= wep ) break;
247 dy = get_text_height(font);
253 void BC_WindowBase::xft_draw_string(XftColor *xft_color, XftFont *xft_font,
254 int x, int y, const FcChar32 *fc, int len, BC_Pixmap *pixmap)
256 Pixmap draw_pixmap = 0;
257 XftDraw *xft_draw = (XftDraw *)
258 (pixmap ? pixmap->opaque_xft_draw : this->pixmap->opaque_xft_draw);
259 int src_x = x, src_y = y, src_w = 0, src_h = 0;
261 XGetGCValues(top_level->display, top_level->gc, GCFunction, &values);
262 if( values.function != GXcopy ) {
263 XSetFunction(top_level->display, top_level->gc, GXcopy);
265 xftTextExtents32(top_level->display, xft_font, fc, len, &info);
266 src_w = info.width; src_h = info.height;
267 draw_pixmap = XCreatePixmap(top_level->display, top_level->win,
268 src_w, src_h, top_level->default_depth);
269 int color = get_color(); set_color(0);
270 XFillRectangle(top_level->display, draw_pixmap, top_level->gc, 0, 0, src_w, src_h);
272 xft_draw = xftDrawCreate(top_level->display, draw_pixmap,
273 top_level->vis, top_level->cmap);
274 src_x = info.x; src_y = info.y;
276 xftDrawString32(xft_draw, xft_color, xft_font, src_x, src_y, fc, len);
277 if( values.function != GXcopy ) {
278 XSetFunction(top_level->display, top_level->gc, values.function);
279 Pixmap xpixmap = pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap;
280 XCopyArea(top_level->display, draw_pixmap, xpixmap,
281 top_level->gc, 0, 0, src_w, src_h, x, y);
282 XFreePixmap(top_level->display, draw_pixmap);
283 xftDrawDestroy(xft_draw);
287 int BC_WindowBase::get_single_text_width(int font, const wchar_t *text, int length)
289 return draw_single_text(0, font, 0,0, text, length);
292 int BC_WindowBase::draw_single_text(int draw, int font,
293 int x, int y, const wchar_t *text, int length, BC_Pixmap *pixmap)
296 length = wcslen(text);
297 if( !length ) return 0;
299 if( !get_resources()->use_xft ) {
301 if( !get_font_struct(font) ) return 0;
302 XChar2b xtext[length], *xp = xtext;
303 for( int i=0; i<length; ++i,++xp ) {
304 xp->byte1 = (unsigned char) (text[i] >> 8);
305 xp->byte2 = (unsigned char) (text[i] & 0xff);
308 XDrawString16(top_level->display,
309 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
310 top_level->gc, x, y, xtext, length);
312 return XTextWidth16(get_font_struct(font), xtext, length);
319 color.red = (top_level->current_color & 0xff0000) >> 16;
320 color.red |= color.red << 8;
321 color.green = (top_level->current_color & 0xff00) >> 8;
322 color.green |= color.green << 8;
323 color.blue = (top_level->current_color & 0xff);
324 color.blue |= color.blue << 8;
325 color.alpha = 0xffff;
327 xftColorAllocValue(top_level->display, top_level->vis, top_level->cmap,
332 XftFont *basefont = top_level->get_xft_struct(font);
333 XftFont *curfont = 0, *altfont = 0;
334 const wchar_t *up = text, *ubp = up, *uep = ubp + length;
337 XftFont *xft_font = 0;
338 if( xftCharExists(top_level->display, basefont, *up) )
341 if( xftCharExists(top_level->display, altfont, *up))
344 xftFontClose(top_level->display, altfont);
349 FcPattern *pattern = BC_Resources::find_similar_font(*up, basefont->pattern);
352 fcPatternGetDouble(basefont->pattern, FC_PIXEL_SIZE, 0, &psize);
353 fcPatternAddDouble(pattern, FC_PIXEL_SIZE, psize);
354 fcPatternDel(pattern, FC_SCALABLE);
355 xft_font = altfont = xftFontOpenPattern(top_level->display, pattern);
360 if( xft_font != curfont ) {
361 if( curfont && up > ubp ) {
363 xft_draw_string(&xft_color, curfont, x, y,
364 (const FcChar32*)ubp, up-ubp, pixmap);
367 xftTextExtents32(top_level->display, curfont,
368 (const FcChar32*)ubp, up-ubp, &extents);
371 ubp = up; curfont = xft_font;
376 if( curfont && up > ubp ) {
378 xft_draw_string(&xft_color, curfont, x, y,
379 (const FcChar32*)ubp, up-ubp, pixmap);
382 xftTextExtents32(top_level->display, curfont,
383 (const FcChar32*)ubp, up-ubp, &extents);
388 xftFontClose(top_level->display, altfont);
390 xftColorFree(top_level->display, top_level->vis, top_level->cmap, &xft_color);
395 void BC_WindowBase::truncate_text(char *result, const char *text, int w)
397 int new_w = get_text_width(current_font, text);
401 const char* separator = "...";
402 int separator_w = get_text_width(current_font, separator);
406 strcpy(result, separator);
410 int text_len = strlen(text);
411 // widen middle gap until it fits
412 for(int i = text_len / 2; i > 0; i--)
414 strncpy(result, text, i);
416 strcat(result, separator);
417 strncat(result, text + text_len - i, i);
418 result[i + strlen(separator) + i] = 0;
419 new_w = get_text_width(current_font, result);
420 //printf("BC_WindowBase::truncate_text %d %d %d %s\n", __LINE__, new_w, w, result);
421 if(new_w < w) return;
425 strcpy(result, separator);
430 strcpy(result, text);
434 void BC_WindowBase::draw_center_text(int x, int y, const char *text, int length)
436 if(length < 0) length = strlen(text);
437 int w = get_text_width(current_font, text, length);
439 draw_text(x, y, text, length);
442 void BC_WindowBase::draw_line(int x1, int y1, int x2, int y2, BC_Pixmap *pixmap)
444 // Some X drivers can't draw 0 length lines
445 if(x1 == x2 && y1 == y2)
447 draw_pixel(x1, y1, pixmap);
451 XDrawLine(top_level->display,
452 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
461 void BC_WindowBase::draw_polygon(ArrayList<int> *x, ArrayList<int> *y, BC_Pixmap *pixmap)
463 int npoints = MIN(x->total, y->total);
464 XPoint *points = new XPoint[npoints];
466 for(int i = 0; i < npoints; i++)
468 points[i].x = x->values[i];
469 points[i].y = y->values[i];
472 XDrawLines(top_level->display,
473 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
482 void BC_WindowBase::fill_polygon(ArrayList<int> *x, ArrayList<int> *y, BC_Pixmap *pixmap)
484 int npoints = MIN(x->total, y->total);
485 XPoint *points = new XPoint[npoints];
487 for(int i = 0; i < npoints; i++)
489 points[i].x = x->values[i];
490 points[i].y = y->values[i];
493 XFillPolygon(top_level->display,
494 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
505 void BC_WindowBase::draw_rectangle(int x, int y, int w, int h)
507 XDrawRectangle(top_level->display,
508 pixmap->opaque_pixmap,
516 void BC_WindowBase::draw_3d_border(int x,
526 top_level->get_resources()->border_shadow2,
527 top_level->get_resources()->border_shadow1,
528 top_level->get_resources()->border_light1,
529 top_level->get_resources()->border_light2);
533 void BC_WindowBase::draw_3d_border(int x,
547 ux = x+w-1; uy = y+h-1;
550 draw_line(x, y, ux, y);
551 draw_line(x, y, x, uy);
553 draw_line(lx, ly, ux - 1, ly);
554 draw_line(lx, ly, lx, uy - 1);
557 draw_line(ux, ly, ux, uy);
558 draw_line(lx, uy, ux, uy);
560 draw_line(x + w, y, x + w, y + h);
561 draw_line(x, y + h, x + w, y + h);
564 void BC_WindowBase::draw_3d_box(int x,
580 ux = x+w-1; uy = y+h-1;
583 draw_box(x, y, w, h, pixmap);
586 draw_line(x, y, ux, y, pixmap);
587 draw_line(x, y, x, uy, pixmap);
589 draw_line(lx, ly, ux - 1, ly, pixmap);
590 draw_line(lx, ly, lx, uy - 1, pixmap);
593 draw_line(ux, ly, ux, uy, pixmap);
594 draw_line(lx, uy, ux, uy, pixmap);
596 draw_line(x + w, y, x + w, y + h, pixmap);
597 draw_line(x, y + h, x + w, y + h, pixmap);
600 void BC_WindowBase::draw_colored_box(int x, int y, int w, int h, int down, int highlighted)
605 draw_3d_box(x, y, w, h,
606 top_level->get_resources()->button_light,
607 top_level->get_resources()->button_highlighted,
608 top_level->get_resources()->button_highlighted,
609 top_level->get_resources()->button_shadow,
612 draw_3d_box(x, y, w, h,
613 top_level->get_resources()->button_light,
614 top_level->get_resources()->button_up,
615 top_level->get_resources()->button_up,
616 top_level->get_resources()->button_shadow,
621 // need highlighting for toggles
623 draw_3d_box(x, y, w, h,
624 top_level->get_resources()->button_shadow,
626 top_level->get_resources()->button_up,
627 top_level->get_resources()->button_up,
628 top_level->get_resources()->button_light);
630 draw_3d_box(x, y, w, h,
631 top_level->get_resources()->button_shadow,
633 top_level->get_resources()->button_down,
634 top_level->get_resources()->button_down,
635 top_level->get_resources()->button_light);
640 void BC_WindowBase::draw_border(char *text, int x, int y, int w, int h)
642 int left_indent = 20;
646 lx = x + 1; ly = y + 1;
647 ux = x + w - 1; uy = y + h - 1;
650 if(text && text[0] != 0)
653 set_font(MEDIUMFONT);
654 draw_text(x + left_indent, y + get_text_height(MEDIUMFONT) / 2, text);
657 set_color(top_level->get_resources()->button_shadow);
658 draw_line(x, y, x + left_indent - 5, y);
659 draw_line(x, y, x, uy);
660 draw_line(x + left_indent + 5 + get_text_width(MEDIUMFONT, text), y, ux, y);
661 draw_line(x, y, x, uy);
662 draw_line(ux, ly, ux, uy);
663 draw_line(lx, uy, ux, uy);
664 set_color(top_level->get_resources()->button_light);
665 draw_line(lx, ly, x + left_indent - 5 - 1, ly);
666 draw_line(lx, ly, lx, uy - 1);
667 draw_line(x + left_indent + 5 + get_text_width(MEDIUMFONT, text), ly, ux - 1, ly);
668 draw_line(lx, ly, lx, uy - 1);
669 draw_line(x + w, y, x + w, y + h);
670 draw_line(x, y + h, x + w, y + h);
673 void BC_WindowBase::draw_triangle_down_flat(int x, int y, int w, int h)
675 int x1, y1, x2, y2, x3;
678 x1 = x; x2 = x + w / 2; x3 = x + w - 1;
679 y1 = y; y2 = y + h - 1;
681 point[0].x = x2; point[0].y = y2; point[1].x = x3;
682 point[1].y = y1; point[2].x = x1; point[2].y = y1;
684 XFillPolygon(top_level->display,
685 pixmap->opaque_pixmap,
693 void BC_WindowBase::draw_triangle_up(int x, int y, int w, int h,
694 int light1, int light2, int middle, int shadow1, int shadow2)
696 int x1, y1, x2, y2, x3;
699 x1 = x; y1 = y; x2 = x + w / 2;
700 y2 = y + h - 1; x3 = x + w - 1;
703 point[0].x = x2; point[0].y = y1; point[1].x = x3;
704 point[1].y = y2; point[2].x = x1; point[2].y = y2;
707 XFillPolygon(top_level->display,
708 pixmap->opaque_pixmap,
715 // bottom and top right
717 draw_line(x3, y2-1, x1, y2-1);
718 draw_line(x2-1, y1, x3-1, y2);
720 draw_line(x3, y2, x1, y2);
721 draw_line(x2, y1, x3, y2);
725 draw_line(x2+1, y1, x1+1, y2);
727 draw_line(x2, y1, x1, y2);
730 void BC_WindowBase::draw_triangle_down(int x, int y, int w, int h,
731 int light1, int light2, int middle, int shadow1, int shadow2)
733 int x1, y1, x2, y2, x3;
736 x1 = x; x2 = x + w / 2; x3 = x + w - 1;
737 y1 = y; y2 = y + h - 1;
739 point[0].x = x2; point[0].y = y2; point[1].x = x3;
740 point[1].y = y1; point[2].x = x1; point[2].y = y1;
743 XFillPolygon(top_level->display,
744 pixmap->opaque_pixmap,
751 // top and bottom left
753 draw_line(x3-1, y1+1, x1+1, y1+1);
754 draw_line(x1+1, y1, x2+1, y2);
756 draw_line(x3, y1, x1, y1);
757 draw_line(x1, y1, x2, y2);
761 draw_line(x3-1, y1, x2-1, y2);
763 draw_line(x3, y1, x2, y2);
766 void BC_WindowBase::draw_triangle_left(int x, int y, int w, int h,
767 int light1, int light2, int middle, int shadow1, int shadow2)
769 int x1, y1, x2, y2, y3;
773 y1 = y; x1 = x; y2 = y + h / 2;
774 x2 = x + w - 1; y3 = y + h - 1;
776 point[0].x = x1; point[0].y = y2; point[1].x = x2;
777 point[1].y = y1; point[2].x = x2; point[2].y = y3;
780 XFillPolygon(top_level->display,
781 pixmap->opaque_pixmap,
788 // right and bottom right
790 draw_line(x2-1, y1, x2-1, y3-1);
791 draw_line(x2, y3-1, x1, y2-1);
793 draw_line(x2, y1, x2, y3);
794 draw_line(x2, y3, x1, y2);
798 draw_line(x1, y2, x2, y1);
800 draw_line(x1, y2+1, x2, y1+1);
803 void BC_WindowBase::draw_triangle_right(int x, int y, int w, int h,
804 int light1, int light2, int middle, int shadow1, int shadow2)
806 int x1, y1, x2, y2, y3;
809 y1 = y; y2 = y + h / 2; y3 = y + h - 1;
810 x1 = x; x2 = x + w - 1;
812 point[0].x = x1; point[0].y = y1; point[1].x = x2;
813 point[1].y = y2; point[2].x = x1; point[2].y = y3;
816 XFillPolygon(top_level->display,
817 pixmap->opaque_pixmap,
824 // left and top right
826 draw_line(x1+1, y3, x1+1, y1);
827 draw_line(x1, y1+1, x2, y2+1);
829 draw_line(x1, y3, x1, y1);
830 draw_line(x1, y1, x2, y2);
834 draw_line(x2, y2-1, x1, y3-1);
836 draw_line(x2, y2, x1, y3);
840 void BC_WindowBase::draw_check(int x, int y)
842 const int w = 15, h = 15;
843 draw_line(x + 3, y + h / 2 + 0, x + 6, y + h / 2 + 2);
844 draw_line(x + 3, y + h / 2 + 1, x + 6, y + h / 2 + 3);
845 draw_line(x + 6, y + h / 2 + 2, x + w - 4, y + h / 2 - 3);
846 draw_line(x + 3, y + h / 2 + 2, x + 6, y + h / 2 + 4);
847 draw_line(x + 6, y + h / 2 + 2, x + w - 4, y + h / 2 - 3);
848 draw_line(x + 6, y + h / 2 + 3, x + w - 4, y + h / 2 - 2);
849 draw_line(x + 6, y + h / 2 + 4, x + w - 4, y + h / 2 - 1);
852 void BC_WindowBase::draw_tiles(BC_Pixmap *tile, int origin_x, int origin_y, int x, int y, int w, int h)
857 draw_box(x, y, w, h);
861 XSetFillStyle(top_level->display, top_level->gc, FillTiled);
862 // Don't know how slow this is
863 XSetTile(top_level->display, top_level->gc, tile->get_pixmap());
864 XSetTSOrigin(top_level->display, top_level->gc, origin_x, origin_y);
865 draw_box(x, y, w, h);
866 XSetFillStyle(top_level->display, top_level->gc, FillSolid);
870 void BC_WindowBase::draw_top_tiles(BC_WindowBase *parent_window, int x, int y, int w, int h)
873 int origin_x, origin_y;
874 XTranslateCoordinates(top_level->display,
883 draw_tiles(parent_window->bg_pixmap,
892 void BC_WindowBase::draw_top_background(BC_WindowBase *parent_window,
901 XLockDisplay(top_level->display);
903 XTranslateCoordinates(top_level->display,
912 XCopyArea(top_level->display,
913 parent_window->pixmap->opaque_pixmap,
914 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
923 XUnlockDisplay(top_level->display);
926 void BC_WindowBase::draw_background(int x, int y, int w, int h)
930 draw_tiles(bg_pixmap, 0, 0, x, y, w, h);
934 clear_box(x, y, w, h);
938 void BC_WindowBase::draw_bitmap(BC_Bitmap *bitmap,
950 // Hide cursor if video enabled
951 update_video_cursor();
953 //printf("BC_WindowBase::draw_bitmap %d dest_y=%d\n", __LINE__, dest_y);
954 if(dest_w <= 0 || dest_h <= 0)
956 // Use hardware scaling to canvas dimensions if proper color model.
957 if(bitmap->get_color_model() == BC_YUV420P)
964 dest_w = bitmap->get_w();
965 dest_h = bitmap->get_h();
969 if(src_w <= 0 || src_h <= 0)
971 src_w = bitmap->get_w();
972 src_h = bitmap->get_h();
977 bitmap->write_drawable(win,
992 bitmap->write_drawable(pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
1002 //printf("BC_WindowBase::draw_bitmap 2\n");
1006 void BC_WindowBase::draw_pixel(int x, int y, BC_Pixmap *pixmap)
1008 XDrawPoint(top_level->display,
1009 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
1016 void BC_WindowBase::draw_pixmap(BC_Pixmap *pixmap,
1025 pixmap->write_drawable(dst ? dst->opaque_pixmap : this->pixmap->opaque_pixmap,
1034 void BC_WindowBase::draw_vframe(VFrame *frame,
1045 if(dest_w <= 0) dest_w = frame->get_w() - src_x;
1046 if(dest_h <= 0) dest_h = frame->get_h() - src_y;
1047 if(src_w <= 0) src_w = frame->get_w() - src_x;
1048 if(src_h <= 0) src_h = frame->get_h() - src_y;
1049 CLAMP(src_x, 0, frame->get_w() - 1);
1050 CLAMP(src_y, 0, frame->get_h() - 1);
1051 if(src_x + src_w > frame->get_w()) src_w = frame->get_w() - src_x;
1052 if(src_y + src_h > frame->get_h()) src_h = frame->get_h() - src_y;
1054 if(!temp_bitmap) temp_bitmap = new BC_Bitmap(this,
1060 temp_bitmap->match_params(dest_w,
1065 temp_bitmap->read_frame(frame,
1075 draw_bitmap(temp_bitmap,
1088 void BC_WindowBase::draw_tooltip(const char *text)
1091 text = tooltip_text;
1092 if(tooltip_popup && text)
1094 int w = tooltip_popup->get_w(), h = tooltip_popup->get_h();
1095 tooltip_popup->set_color(get_resources()->tooltip_bg_color);
1096 tooltip_popup->draw_box(0, 0, w, h);
1097 tooltip_popup->set_color(BLACK);
1098 tooltip_popup->draw_rectangle(0, 0, w, h);
1099 tooltip_popup->set_font(MEDIUMFONT);
1100 tooltip_popup->draw_text(TOOLTIP_MARGIN,
1101 get_text_ascent(MEDIUMFONT) + TOOLTIP_MARGIN,
1106 void BC_WindowBase::slide_left(int distance)
1110 XCopyArea(top_level->display,
1111 pixmap->opaque_pixmap,
1112 pixmap->opaque_pixmap,
1123 void BC_WindowBase::slide_right(int distance)
1127 XCopyArea(top_level->display,
1128 pixmap->opaque_pixmap,
1129 pixmap->opaque_pixmap,
1140 void BC_WindowBase::slide_up(int distance)
1144 XCopyArea(top_level->display,
1145 pixmap->opaque_pixmap,
1146 pixmap->opaque_pixmap,
1154 set_color(bg_color);
1155 XFillRectangle(top_level->display,
1156 pixmap->opaque_pixmap,
1165 void BC_WindowBase::slide_down(int distance)
1169 XCopyArea(top_level->display,
1170 pixmap->opaque_pixmap,
1171 pixmap->opaque_pixmap,
1179 set_color(bg_color);
1180 XFillRectangle(top_level->display,
1181 pixmap->opaque_pixmap,
1190 // 3 segments in separate pixmaps. Obsolete.
1191 void BC_WindowBase::draw_3segment(int x,
1195 BC_Pixmap *left_image,
1196 BC_Pixmap *mid_image,
1197 BC_Pixmap *right_image,
1200 if(w <= 0 || h <= 0) return;
1201 int left_boundary = left_image->get_w_fixed();
1202 int right_boundary = w - right_image->get_w_fixed();
1203 for(int i = 0; i < w; )
1207 if(i < left_boundary)
1210 if(i < right_boundary)
1213 image = right_image;
1215 int output_w = image->get_w_fixed();
1217 if(i < left_boundary)
1219 if(i + output_w > left_boundary) output_w = left_boundary - i;
1222 if(i < right_boundary)
1224 if(i + output_w > right_boundary) output_w = right_boundary - i;
1227 if(i + output_w > w) output_w = w - i;
1229 image->write_drawable(pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
1240 // 3 segments in separate vframes. Obsolete.
1241 void BC_WindowBase::draw_3segment(int x,
1247 VFrame *right_image,
1250 if(w <= 0 || h <= 0) return;
1251 int left_boundary = left_image->get_w_fixed();
1252 int right_boundary = w - right_image->get_w_fixed();
1255 for(int i = 0; i < w; )
1259 if(i < left_boundary)
1262 if(i < right_boundary)
1265 image = right_image;
1267 int output_w = image->get_w_fixed();
1269 if(i < left_boundary)
1271 if(i + output_w > left_boundary) output_w = left_boundary - i;
1274 if(i < right_boundary)
1276 if(i + output_w > right_boundary) output_w = right_boundary - i;
1279 if(i + output_w > w) output_w = w - i;
1293 if(output_w == 0) break;
1298 // Draw all 3 segments in a single vframe for a changing level
1303 // <------------------------------------------------------------>
1307 // <-------------------------------------------------------------------->
1309 // |-------------------|----------------------|------------------|
1312 void BC_WindowBase::draw_3segmenth(int x,
1327 void BC_WindowBase::draw_3segmenth(int x,
1335 if(total_w <= 0 || w <= 0 || h <= 0) return;
1336 int third_image = image->get_w() / 3;
1337 int half_image = image->get_w() / 2;
1338 //int left_boundary = third_image;
1339 //int right_boundary = total_w - third_image;
1341 int left_in_w = third_image;
1342 int left_out_x = total_x;
1343 int left_out_w = third_image;
1344 int right_in_x = image->get_w() - third_image;
1345 int right_in_w = third_image;
1346 int right_out_x = total_x + total_w - third_image;
1347 int right_out_w = third_image;
1348 int center_out_x = total_x + third_image;
1349 int center_out_w = total_w - third_image * 2;
1350 //int image_x, image_w;
1352 //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",
1353 // left_out_x, left_out_w, center_out_x, center_out_w, right_out_x, right_out_w);
1357 left_in_w -= x - left_out_x;
1358 left_out_w -= x - left_out_x;
1359 left_in_x += x - left_out_x;
1360 left_out_x += x - left_out_x;
1363 if(left_out_x + left_out_w > x + w)
1365 left_in_w -= (left_out_x + left_out_w) - (x + w);
1366 left_out_w -= (left_out_x + left_out_w) - (x + w);
1371 right_in_w -= x - right_out_x;
1372 right_out_w -= x - right_out_x;
1373 right_in_x += x - right_out_x;
1374 right_out_x += x - right_out_x;
1377 if(right_out_x + right_out_w > x + w)
1379 right_in_w -= (right_out_x + right_out_w) - (x + w);
1380 right_out_w -= (right_out_x + right_out_w) - (x + w);
1383 if(center_out_x < x)
1385 center_out_w -= x - center_out_x;
1386 center_out_x += x - center_out_x;
1389 if(center_out_x + center_out_w > x + w)
1391 center_out_w -= (center_out_x + center_out_w) - (x + w);
1394 if(!temp_bitmap) temp_bitmap = new BC_Bitmap(top_level,
1399 temp_bitmap->match_params(image->get_w(),
1403 temp_bitmap->read_frame(image,
1410 //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",
1411 // left_out_x, left_out_w, center_out_x, center_out_w, right_out_x, right_out_w);
1414 draw_bitmap(temp_bitmap,
1422 -1, // src width and height are meaningless in video_off mode
1429 draw_bitmap(temp_bitmap,
1437 -1, // src width and height are meaningless in video_off mode
1442 for(int pixel = center_out_x;
1443 pixel < center_out_x + center_out_w;
1444 pixel += half_image)
1446 int fragment_w = half_image;
1447 if(fragment_w + pixel > center_out_x + center_out_w)
1448 fragment_w = (center_out_x + center_out_w) - pixel;
1450 //printf("BC_WindowBase::draw_3segment 2 pixel=%d fragment_w=%d\n", pixel, fragment_w);
1451 draw_bitmap(temp_bitmap,
1459 -1, // src width and height are meaningless in video_off mode
1472 void BC_WindowBase::draw_3segmenth(int x,
1480 if(w <= 0 || total_w <= 0) return;
1481 if(!src) printf("BC_WindowBase::draw_3segmenth src=0\n");
1482 int quarter_src = src->get_w() / 4;
1483 int half_src = src->get_w() / 2;
1484 //int left_boundary = quarter_src;
1485 //int right_boundary = total_w - quarter_src;
1487 int left_in_w = quarter_src;
1488 int left_out_x = total_x;
1489 int left_out_w = quarter_src;
1490 int right_in_x = src->get_w() - quarter_src;
1491 int right_in_w = quarter_src;
1492 int right_out_x = total_x + total_w - quarter_src;
1493 int right_out_w = quarter_src;
1494 int center_out_x = total_x + quarter_src;
1495 int center_out_w = total_w - quarter_src * 2;
1498 //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",
1499 // left_out_x, left_out_w, center_out_x, center_out_w, right_out_x, right_out_w);
1503 left_in_w -= x - left_out_x;
1504 left_out_w -= x - left_out_x;
1505 left_in_x += x - left_out_x;
1506 left_out_x += x - left_out_x;
1509 if(left_out_x + left_out_w > x + w)
1511 left_in_w -= (left_out_x + left_out_w) - (x + w);
1512 left_out_w -= (left_out_x + left_out_w) - (x + w);
1517 right_in_w -= x - right_out_x;
1518 right_out_w -= x - right_out_x;
1519 right_in_x += x - right_out_x;
1520 right_out_x += x - right_out_x;
1523 if(right_out_x + right_out_w > x + w)
1525 right_in_w -= (right_out_x + right_out_w) - (x + w);
1526 right_out_w -= (right_out_x + right_out_w) - (x + w);
1529 if(center_out_x < x)
1531 center_out_w -= x - center_out_x;
1532 center_out_x += x - center_out_x;
1535 if(center_out_x + center_out_w > x + w)
1537 center_out_w -= (center_out_x + center_out_w) - (x + w);
1541 //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",
1542 // left_out_x, left_out_w, center_out_x, center_out_w, right_out_x, right_out_w);
1567 for(int pixel = center_out_x;
1568 pixel < center_out_x + center_out_w;
1571 int fragment_w = half_src;
1572 if(fragment_w + pixel > center_out_x + center_out_w)
1573 fragment_w = (center_out_x + center_out_w) - pixel;
1575 //printf("BC_WindowBase::draw_3segment 2 pixel=%d fragment_w=%d\n", pixel, fragment_w);
1589 void BC_WindowBase::draw_3segmenth(int x,
1596 int third_image = src->get_w() / 3;
1597 int half_output = w / 2;
1598 //int left_boundary = third_image;
1599 //int right_boundary = w - third_image;
1601 int left_in_w = third_image;
1603 int left_out_w = third_image;
1604 int right_in_x = src->get_w() - third_image;
1605 int right_in_w = third_image;
1606 int right_out_x = x + w - third_image;
1607 int right_out_w = third_image;
1608 //int image_x, image_w;
1610 //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",
1611 // left_out_x, left_out_w, center_out_x, center_out_w, right_out_x, right_out_w);
1613 if(left_out_w > half_output)
1615 left_in_w -= left_out_w - half_output;
1616 left_out_w -= left_out_w - half_output;
1619 if(right_out_x < x + half_output)
1621 right_in_w -= x + half_output - right_out_x;
1622 right_out_w -= x + half_output - right_out_x;
1623 right_in_x += x + half_output - right_out_x;
1624 right_out_x += x + half_output - right_out_x;
1627 //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",
1628 // left_out_x, left_out_w, center_out_x, center_out_w, right_out_x, right_out_w);
1653 for(int pixel = left_out_x + left_out_w;
1654 pixel < right_out_x;
1655 pixel += third_image)
1657 int fragment_w = third_image;
1658 if(fragment_w + pixel > right_out_x)
1659 fragment_w = right_out_x - pixel;
1661 //printf("BC_WindowBase::draw_3segment 2 pixel=%d fragment_w=%d\n", pixel, fragment_w);
1680 void BC_WindowBase::draw_3segmentv(int x,
1687 int third_image = src->get_h() / 3;
1688 int half_output = h / 2;
1689 //int left_boundary = third_image;
1690 //int right_boundary = h - third_image;
1692 int left_in_h = third_image;
1694 int left_out_h = third_image;
1695 int right_in_y = src->get_h() - third_image;
1696 int right_in_h = third_image;
1697 int right_out_y = y + h - third_image;
1698 int right_out_h = third_image;
1699 //int image_y, image_h;
1702 if(left_out_h > half_output)
1704 left_in_h -= left_out_h - half_output;
1705 left_out_h -= left_out_h - half_output;
1708 if(right_out_y < y + half_output)
1710 right_in_h -= y + half_output - right_out_y;
1711 right_out_h -= y + half_output - right_out_y;
1712 right_in_y += y + half_output - right_out_y;
1713 right_out_y += y + half_output - right_out_y;
1717 if(!temp_bitmap) temp_bitmap = new BC_Bitmap(top_level,
1722 temp_bitmap->match_params(src->get_w(),
1726 temp_bitmap->read_frame(src,
1735 draw_bitmap(temp_bitmap,
1750 draw_bitmap(temp_bitmap,
1763 for(int pixel = left_out_y + left_out_h;
1764 pixel < right_out_y;
1765 pixel += third_image)
1767 int fragment_h = third_image;
1768 if(fragment_h + pixel > right_out_y)
1769 fragment_h = right_out_y - pixel;
1771 //printf("BC_WindowBase::draw_3segment 2 pixel=%d fragment_w=%d\n", pixel, fragment_w);
1772 draw_bitmap(temp_bitmap,
1786 void BC_WindowBase::draw_3segmentv(int x,
1793 int third_image = src->get_h() / 3;
1794 int half_output = h / 2;
1795 //int left_boundary = third_image;
1796 //int right_boundary = h - third_image;
1798 int left_in_h = third_image;
1800 int left_out_h = third_image;
1801 int right_in_y = src->get_h() - third_image;
1802 int right_in_h = third_image;
1803 int right_out_y = y + h - third_image;
1804 int right_out_h = third_image;
1805 //int image_y, image_h;
1808 if(left_out_h > half_output)
1810 left_in_h -= left_out_h - half_output;
1811 left_out_h -= left_out_h - half_output;
1814 if(right_out_y < y + half_output)
1816 right_in_h -= y + half_output - right_out_y;
1817 right_out_h -= y + half_output - right_out_y;
1818 right_in_y += y + half_output - right_out_y;
1819 right_out_y += y + half_output - right_out_y;
1846 for(int pixel = left_out_y + left_out_h;
1847 pixel < right_out_y;
1848 pixel += third_image)
1850 int fragment_h = third_image;
1851 if(fragment_h + pixel > right_out_y)
1852 fragment_h = right_out_y - pixel;
1854 //printf("BC_WindowBase::draw_3segment 2 pixel=%d fragment_w=%d\n", pixel, fragment_w);
1867 void BC_WindowBase::draw_9segment(int x,
1874 if(w <= 0 || h <= 0) return;
1876 int in_x_third = src->get_w() / 3;
1877 int in_y_third = src->get_h() / 3;
1878 int out_x_half = w / 2;
1879 int out_y_half = h / 2;
1885 int in_x2 = MIN(in_x_third, out_x_half);
1886 int in_y2 = MIN(in_y_third, out_y_half);
1890 int out_x3 = MAX(w - out_x_half, w - in_x_third);
1892 int in_x3 = src->get_w() - (out_x4 - out_x3);
1893 //int in_x4 = src->get_w();
1895 int out_y3 = MAX(h - out_y_half, h - in_y_third);
1897 int in_y3 = src->get_h() - (out_y4 - out_y3);
1898 //int in_y4 = src->get_h();
1912 for(int i = out_x2; i < out_x3; i += in_x3 - in_x2)
1916 int w = MIN(in_x3 - in_x2, out_x3 - i);
1945 for(int i = out_y2; i < out_y3; i += in_y3 - in_y2)
1949 int h = MIN(in_y3 - in_y2, out_y3 - i);
1962 // Segment 5 * n * n
1963 for(int i = out_y2; i < out_y3; i += in_y3 - in_y2 /* in_y_third */)
1967 int h = MIN(in_y3 - in_y2 /* in_y_third */, out_y3 - i);
1970 for(int j = out_x2; j < out_x3; j += in_x3 - in_x2 /* in_x_third */)
1972 int w = MIN(in_x3 - in_x2 /* in_x_third */, out_x3 - j);
1987 for(int i = out_y2; i < out_y3; i += in_y3 - in_y2)
1991 int h = MIN(in_y3 - in_y2, out_y3 - i);
2018 for(int i = out_x2; i < out_x3; i += in_x3 - in_x2)
2022 int w = MIN(in_x3 - in_y2, out_x3 - i);
2048 void BC_WindowBase::draw_9segment(int x,
2055 if(w <= 0 || h <= 0) return;
2057 int in_x_third = src->get_w() / 3;
2058 int in_y_third = src->get_h() / 3;
2059 int out_x_half = w / 2;
2060 int out_y_half = h / 2;
2066 int in_x2 = MIN(in_x_third, out_x_half);
2067 int in_y2 = MIN(in_y_third, out_y_half);
2071 int out_x3 = MAX(w - out_x_half, w - in_x_third);
2073 int in_x3 = src->get_w() - (out_x4 - out_x3);
2074 int in_x4 = src->get_w();
2076 int out_y3 = MAX(h - out_y_half, h - in_y_third);
2078 int in_y3 = src->get_h() - (out_y4 - out_y3);
2079 int in_y4 = src->get_h();
2081 //printf("PFCFrame::draw_9segment 1 %d %d %d %d\n", out_x1, out_x2, out_x3, out_x4);
2082 //printf("PFCFrame::draw_9segment 2 %d %d %d %d\n", in_x1, in_x2, in_x3, in_x4);
2083 //printf("PFCFrame::draw_9segment 2 %d %d %d %d\n", in_y1, in_y2, in_y3, in_y4);
2085 if(!temp_bitmap) temp_bitmap = new BC_Bitmap(top_level,
2090 temp_bitmap->match_params(src->get_w(),
2094 temp_bitmap->read_frame(src,
2101 draw_bitmap(temp_bitmap,
2115 for(int i = out_x2; i < out_x3; i += in_x3 - in_x2)
2119 int w = MIN(in_x3 - in_x2, out_x3 - i);
2120 draw_bitmap(temp_bitmap,
2139 draw_bitmap(temp_bitmap,
2154 for(int i = out_y2; i < out_y3; i += in_y3 - in_y2)
2158 int h = MIN(in_y3 - in_y2, out_y3 - i);
2159 draw_bitmap(temp_bitmap,
2174 // Segment 5 * n * n
2175 for(int i = out_y2; i < out_y3; i += in_y3 - in_y2)
2179 int h = MIN(in_y3 - in_y2, out_y3 - i);
2182 for(int j = out_x2; j < out_x3; j += in_x3 - in_x2)
2184 int w = MIN(in_x3 - in_x2, out_x3 - j);
2186 draw_bitmap(temp_bitmap,
2202 for(int i = out_y2; i < out_y3; i += in_y_third)
2206 int h = MIN(in_y_third, out_y3 - i);
2207 draw_bitmap(temp_bitmap,
2225 draw_bitmap(temp_bitmap,
2239 for(int i = out_x2; i < out_x3; i += in_x_third)
2243 int w = MIN(in_x_third, out_x3 - i);
2244 draw_bitmap(temp_bitmap,
2261 draw_bitmap(temp_bitmap,