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::xft_draw_string(XftColor *xft_color, XftFont *xft_font,
281 int x, int y, const FcChar32 *fc, int len, BC_Pixmap *pixmap)
283 Pixmap draw_pixmap = 0;
284 XftDraw *xft_draw = (XftDraw *)
285 (pixmap ? pixmap->opaque_xft_draw : this->pixmap->opaque_xft_draw);
286 int src_x = x, src_y = y, src_w = 0, src_h = 0;
288 XGetGCValues(top_level->display, top_level->gc, GCFunction, &values);
289 if( values.function != GXcopy ) {
290 XSetFunction(top_level->display, top_level->gc, GXcopy);
292 XftTextExtents32(top_level->display, xft_font, fc, len, &info);
293 src_w = info.width; src_h = info.height;
294 draw_pixmap = XCreatePixmap(top_level->display, top_level->win,
295 src_w, src_h, top_level->default_depth);
296 int color = get_color(); set_color(0);
297 XFillRectangle(top_level->display, draw_pixmap, top_level->gc, 0, 0, src_w, src_h);
299 xft_draw = XftDrawCreate(top_level->display, draw_pixmap,
300 top_level->vis, top_level->cmap);
301 src_x = info.x; src_y = info.y;
303 XftDrawString32(xft_draw, xft_color, xft_font, src_x, src_y, fc, len);
304 if( values.function != GXcopy ) {
305 XSetFunction(top_level->display, top_level->gc, values.function);
306 Pixmap xpixmap = pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap;
307 XCopyArea(top_level->display, draw_pixmap, xpixmap,
308 top_level->gc, 0, 0, src_w, src_h, x, y);
309 XFreePixmap(top_level->display, draw_pixmap);
310 XftDrawDestroy(xft_draw);
314 void BC_WindowBase::draw_wtext(int x, int y,
315 const wchar_t *text, int length, BC_Pixmap *pixmap, int *charpos)
317 if( !get_resources()->use_xft ) {
318 if( !get_font_struct(current_font) ) return;
319 XChar2b xtext[length], *xp = xtext;
320 for( int i=0; i<length; ++i,++xp ) {
321 xp->byte1 = (unsigned char) (text[i] >> 8);
322 xp->byte2 = (unsigned char) (text[i] & 0xff);
324 XDrawString16(top_level->display,
325 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
326 top_level->gc, x, y, xtext, length);
331 const wchar_t *up, *ubp;
334 XftFont *curfont, *nextfont, *altfont, *basefont;
337 length = wcslen(text);
344 color.red = (top_level->current_color & 0xff0000) >> 16;
345 color.red |= color.red << 8;
346 color.green = (top_level->current_color & 0xff00) >> 8;
347 color.green |= color.green << 8;
348 color.blue = (top_level->current_color & 0xff);
349 color.blue |= color.blue << 8;
350 color.alpha = 0xffff;
352 XftColorAllocValue(top_level->display,
358 basefont = top_level->get_xft_struct(top_level->current_font);
360 curfont = nextfont = basefont;
365 for(up = text; up < &text[length]; up++)
367 if(XftCharExists(top_level->display, basefont, *up))
369 else if(altfont && XftCharExists(top_level->display, altfont, *up))
374 XftFontClose(top_level->display, altfont);
376 if( (newpat = BC_Resources::find_similar_font(*up, basefont->pattern)) != 0 ) {
379 FcPatternGetDouble(basefont->pattern, FC_PIXEL_SIZE,
381 FcPatternAddDouble(newpat, FC_PIXEL_SIZE, psize);
382 FcPatternDel(newpat, FC_SCALABLE);
383 altfont = XftFontOpenPattern(top_level->display,
394 if(nextfont != curfont)
397 xft_draw_string(&xft_color, curfont, x, y,
398 (const FcChar32*)ubp, l, pixmap);
401 cp = &charpos[ubp - text + 1];
403 x += wcharpos(ubp, curfont, l, cp);
411 xft_draw_string(&xft_color, curfont, x, y,
412 (const FcChar32*)ubp, up - ubp, pixmap);
414 wcharpos(ubp, curfont, up - ubp, &charpos[ubp - text + 1]);
418 XftFontClose(top_level->display, altfont);
420 XftColorFree(top_level->display,
426 void BC_WindowBase::truncate_text(char *result, const char *text, int w)
428 int new_w = get_text_width(current_font, text);
432 const char* separator = "...";
433 int separator_w = get_text_width(current_font, separator);
437 strcpy(result, separator);
441 int text_len = strlen(text);
442 // widen middle gap until it fits
443 for(int i = text_len / 2; i > 0; i--)
445 strncpy(result, text, i);
447 strcat(result, separator);
448 strncat(result, text + text_len - i, i);
449 result[i + strlen(separator) + i] = 0;
450 new_w = get_text_width(current_font, result);
451 //printf("BC_WindowBase::truncate_text %d %d %d %s\n", __LINE__, new_w, w, result);
452 if(new_w < w) return;
456 strcpy(result, separator);
461 strcpy(result, text);
465 void BC_WindowBase::draw_center_text(int x, int y, const char *text, int length)
467 if(length < 0) length = strlen(text);
468 int w = get_text_width(current_font, text, length);
470 draw_text(x, y, text, length);
473 void BC_WindowBase::draw_line(int x1, int y1, int x2, int y2, BC_Pixmap *pixmap)
475 // Some X drivers can't draw 0 length lines
476 if(x1 == x2 && y1 == y2)
478 draw_pixel(x1, y1, pixmap);
482 XDrawLine(top_level->display,
483 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
492 void BC_WindowBase::draw_polygon(ArrayList<int> *x, ArrayList<int> *y, BC_Pixmap *pixmap)
494 int npoints = MIN(x->total, y->total);
495 XPoint *points = new XPoint[npoints];
497 for(int i = 0; i < npoints; i++)
499 points[i].x = x->values[i];
500 points[i].y = y->values[i];
503 XDrawLines(top_level->display,
504 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
513 void BC_WindowBase::fill_polygon(ArrayList<int> *x, ArrayList<int> *y, BC_Pixmap *pixmap)
515 int npoints = MIN(x->total, y->total);
516 XPoint *points = new XPoint[npoints];
518 for(int i = 0; i < npoints; i++)
520 points[i].x = x->values[i];
521 points[i].y = y->values[i];
524 XFillPolygon(top_level->display,
525 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
536 void BC_WindowBase::draw_rectangle(int x, int y, int w, int h)
538 XDrawRectangle(top_level->display,
539 pixmap->opaque_pixmap,
547 void BC_WindowBase::draw_3d_border(int x,
557 top_level->get_resources()->border_shadow2,
558 top_level->get_resources()->border_shadow1,
559 top_level->get_resources()->border_light1,
560 top_level->get_resources()->border_light2);
564 void BC_WindowBase::draw_3d_border(int x,
578 ux = x+w-1; uy = y+h-1;
581 draw_line(x, y, ux, y);
582 draw_line(x, y, x, uy);
584 draw_line(lx, ly, ux - 1, ly);
585 draw_line(lx, ly, lx, uy - 1);
588 draw_line(ux, ly, ux, uy);
589 draw_line(lx, uy, ux, uy);
591 draw_line(x + w, y, x + w, y + h);
592 draw_line(x, y + h, x + w, y + h);
595 void BC_WindowBase::draw_3d_box(int x,
611 ux = x+w-1; uy = y+h-1;
614 draw_box(x, y, w, h, pixmap);
617 draw_line(x, y, ux, y, pixmap);
618 draw_line(x, y, x, uy, pixmap);
620 draw_line(lx, ly, ux - 1, ly, pixmap);
621 draw_line(lx, ly, lx, uy - 1, pixmap);
624 draw_line(ux, ly, ux, uy, pixmap);
625 draw_line(lx, uy, ux, uy, pixmap);
627 draw_line(x + w, y, x + w, y + h, pixmap);
628 draw_line(x, y + h, x + w, y + h, pixmap);
631 void BC_WindowBase::draw_colored_box(int x, int y, int w, int h, int down, int highlighted)
636 draw_3d_box(x, y, w, h,
637 top_level->get_resources()->button_light,
638 top_level->get_resources()->button_highlighted,
639 top_level->get_resources()->button_highlighted,
640 top_level->get_resources()->button_shadow,
643 draw_3d_box(x, y, w, h,
644 top_level->get_resources()->button_light,
645 top_level->get_resources()->button_up,
646 top_level->get_resources()->button_up,
647 top_level->get_resources()->button_shadow,
652 // need highlighting for toggles
654 draw_3d_box(x, y, w, h,
655 top_level->get_resources()->button_shadow,
657 top_level->get_resources()->button_up,
658 top_level->get_resources()->button_up,
659 top_level->get_resources()->button_light);
661 draw_3d_box(x, y, w, h,
662 top_level->get_resources()->button_shadow,
664 top_level->get_resources()->button_down,
665 top_level->get_resources()->button_down,
666 top_level->get_resources()->button_light);
671 void BC_WindowBase::draw_border(char *text, int x, int y, int w, int h)
673 int left_indent = 20;
677 lx = x + 1; ly = y + 1;
678 ux = x + w - 1; uy = y + h - 1;
681 if(text && text[0] != 0)
684 set_font(MEDIUMFONT);
685 draw_text(x + left_indent, y + get_text_height(MEDIUMFONT) / 2, text);
688 set_color(top_level->get_resources()->button_shadow);
689 draw_line(x, y, x + left_indent - 5, y);
690 draw_line(x, y, x, uy);
691 draw_line(x + left_indent + 5 + get_text_width(MEDIUMFONT, text), y, ux, y);
692 draw_line(x, y, x, uy);
693 draw_line(ux, ly, ux, uy);
694 draw_line(lx, uy, ux, uy);
695 set_color(top_level->get_resources()->button_light);
696 draw_line(lx, ly, x + left_indent - 5 - 1, ly);
697 draw_line(lx, ly, lx, uy - 1);
698 draw_line(x + left_indent + 5 + get_text_width(MEDIUMFONT, text), ly, ux - 1, ly);
699 draw_line(lx, ly, lx, uy - 1);
700 draw_line(x + w, y, x + w, y + h);
701 draw_line(x, y + h, x + w, y + h);
704 void BC_WindowBase::draw_triangle_down_flat(int x, int y, int w, int h)
706 int x1, y1, x2, y2, x3;
709 x1 = x; x2 = x + w / 2; x3 = x + w - 1;
710 y1 = y; y2 = y + h - 1;
712 point[0].x = x2; point[0].y = y2; point[1].x = x3;
713 point[1].y = y1; point[2].x = x1; point[2].y = y1;
715 XFillPolygon(top_level->display,
716 pixmap->opaque_pixmap,
724 void BC_WindowBase::draw_triangle_up(int x, int y, int w, int h,
725 int light1, int light2, int middle, int shadow1, int shadow2)
727 int x1, y1, x2, y2, x3;
730 x1 = x; y1 = y; x2 = x + w / 2;
731 y2 = y + h - 1; x3 = x + w - 1;
734 point[0].x = x2; point[0].y = y1; point[1].x = x3;
735 point[1].y = y2; point[2].x = x1; point[2].y = y2;
738 XFillPolygon(top_level->display,
739 pixmap->opaque_pixmap,
746 // bottom and top right
748 draw_line(x3, y2-1, x1, y2-1);
749 draw_line(x2-1, y1, x3-1, y2);
751 draw_line(x3, y2, x1, y2);
752 draw_line(x2, y1, x3, y2);
756 draw_line(x2+1, y1, x1+1, y2);
758 draw_line(x2, y1, x1, y2);
761 void BC_WindowBase::draw_triangle_down(int x, int y, int w, int h,
762 int light1, int light2, int middle, int shadow1, int shadow2)
764 int x1, y1, x2, y2, x3;
767 x1 = x; x2 = x + w / 2; x3 = x + w - 1;
768 y1 = y; y2 = y + h - 1;
770 point[0].x = x2; point[0].y = y2; point[1].x = x3;
771 point[1].y = y1; point[2].x = x1; point[2].y = y1;
774 XFillPolygon(top_level->display,
775 pixmap->opaque_pixmap,
782 // top and bottom left
784 draw_line(x3-1, y1+1, x1+1, y1+1);
785 draw_line(x1+1, y1, x2+1, y2);
787 draw_line(x3, y1, x1, y1);
788 draw_line(x1, y1, x2, y2);
792 draw_line(x3-1, y1, x2-1, y2);
794 draw_line(x3, y1, x2, y2);
797 void BC_WindowBase::draw_triangle_left(int x, int y, int w, int h,
798 int light1, int light2, int middle, int shadow1, int shadow2)
800 int x1, y1, x2, y2, y3;
804 y1 = y; x1 = x; y2 = y + h / 2;
805 x2 = x + w - 1; y3 = y + h - 1;
807 point[0].x = x1; point[0].y = y2; point[1].x = x2;
808 point[1].y = y1; point[2].x = x2; point[2].y = y3;
811 XFillPolygon(top_level->display,
812 pixmap->opaque_pixmap,
819 // right and bottom right
821 draw_line(x2-1, y1, x2-1, y3-1);
822 draw_line(x2, y3-1, x1, y2-1);
824 draw_line(x2, y1, x2, y3);
825 draw_line(x2, y3, x1, y2);
829 draw_line(x1, y2, x2, y1);
831 draw_line(x1, y2+1, x2, y1+1);
834 void BC_WindowBase::draw_triangle_right(int x, int y, int w, int h,
835 int light1, int light2, int middle, int shadow1, int shadow2)
837 int x1, y1, x2, y2, y3;
840 y1 = y; y2 = y + h / 2; y3 = y + h - 1;
841 x1 = x; x2 = x + w - 1;
843 point[0].x = x1; point[0].y = y1; point[1].x = x2;
844 point[1].y = y2; point[2].x = x1; point[2].y = y3;
847 XFillPolygon(top_level->display,
848 pixmap->opaque_pixmap,
855 // left and top right
857 draw_line(x1+1, y3, x1+1, y1);
858 draw_line(x1, y1+1, x2, y2+1);
860 draw_line(x1, y3, x1, y1);
861 draw_line(x1, y1, x2, y2);
865 draw_line(x2, y2-1, x1, y3-1);
867 draw_line(x2, y2, x1, y3);
871 void BC_WindowBase::draw_check(int x, int y)
873 const int w = 15, h = 15;
874 draw_line(x + 3, y + h / 2 + 0, x + 6, y + h / 2 + 2);
875 draw_line(x + 3, y + h / 2 + 1, x + 6, y + h / 2 + 3);
876 draw_line(x + 6, y + h / 2 + 2, x + w - 4, y + h / 2 - 3);
877 draw_line(x + 3, y + h / 2 + 2, x + 6, y + h / 2 + 4);
878 draw_line(x + 6, y + h / 2 + 2, x + w - 4, y + h / 2 - 3);
879 draw_line(x + 6, y + h / 2 + 3, x + w - 4, y + h / 2 - 2);
880 draw_line(x + 6, y + h / 2 + 4, x + w - 4, y + h / 2 - 1);
883 void BC_WindowBase::draw_tiles(BC_Pixmap *tile, int origin_x, int origin_y, int x, int y, int w, int h)
888 draw_box(x, y, w, h);
892 XSetFillStyle(top_level->display, top_level->gc, FillTiled);
893 // Don't know how slow this is
894 XSetTile(top_level->display, top_level->gc, tile->get_pixmap());
895 XSetTSOrigin(top_level->display, top_level->gc, origin_x, origin_y);
896 draw_box(x, y, w, h);
897 XSetFillStyle(top_level->display, top_level->gc, FillSolid);
901 void BC_WindowBase::draw_top_tiles(BC_WindowBase *parent_window, int x, int y, int w, int h)
904 int origin_x, origin_y;
905 XTranslateCoordinates(top_level->display,
914 draw_tiles(parent_window->bg_pixmap,
923 void BC_WindowBase::draw_top_background(BC_WindowBase *parent_window,
932 XLockDisplay(top_level->display);
934 XTranslateCoordinates(top_level->display,
943 XCopyArea(top_level->display,
944 parent_window->pixmap->opaque_pixmap,
945 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
954 XUnlockDisplay(top_level->display);
957 void BC_WindowBase::draw_background(int x, int y, int w, int h)
961 draw_tiles(bg_pixmap, 0, 0, x, y, w, h);
965 clear_box(x, y, w, h);
969 void BC_WindowBase::draw_bitmap(BC_Bitmap *bitmap,
982 // Hide cursor if video enabled
983 update_video_cursor();
985 //printf("BC_WindowBase::draw_bitmap 1\n");
986 if(dest_w <= 0 || dest_h <= 0)
988 // Use hardware scaling to canvas dimensions if proper color model.
989 if(bitmap->get_color_model() == BC_YUV420P)
996 dest_w = bitmap->get_w();
997 dest_h = bitmap->get_h();
1001 if(src_w <= 0 || src_h <= 0)
1003 src_w = bitmap->get_w();
1004 src_h = bitmap->get_h();
1009 bitmap->write_drawable(win,
1024 bitmap->write_drawable(pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
1034 //printf("BC_WindowBase::draw_bitmap 2\n");
1038 void BC_WindowBase::draw_pixel(int x, int y, BC_Pixmap *pixmap)
1040 XDrawPoint(top_level->display,
1041 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
1048 void BC_WindowBase::draw_pixmap(BC_Pixmap *pixmap,
1057 pixmap->write_drawable(dst ? dst->opaque_pixmap : this->pixmap->opaque_pixmap,
1066 void BC_WindowBase::draw_vframe(VFrame *frame,
1077 if(dest_w <= 0) dest_w = frame->get_w() - src_x;
1078 if(dest_h <= 0) dest_h = frame->get_h() - src_y;
1079 if(src_w <= 0) src_w = frame->get_w() - src_x;
1080 if(src_h <= 0) src_h = frame->get_h() - src_y;
1081 CLAMP(src_x, 0, frame->get_w() - 1);
1082 CLAMP(src_y, 0, frame->get_h() - 1);
1083 if(src_x + src_w > frame->get_w()) src_w = frame->get_w() - src_x;
1084 if(src_y + src_h > frame->get_h()) src_h = frame->get_h() - src_y;
1086 if(!temp_bitmap) temp_bitmap = new BC_Bitmap(this,
1092 temp_bitmap->match_params(dest_w,
1097 temp_bitmap->read_frame(frame,
1107 draw_bitmap(temp_bitmap,
1120 void BC_WindowBase::draw_tooltip(const char *text)
1123 text = tooltip_text;
1124 if(tooltip_popup && text)
1126 int w = tooltip_popup->get_w(), h = tooltip_popup->get_h();
1127 tooltip_popup->set_color(get_resources()->tooltip_bg_color);
1128 tooltip_popup->draw_box(0, 0, w, h);
1129 tooltip_popup->set_color(BLACK);
1130 tooltip_popup->draw_rectangle(0, 0, w, h);
1131 tooltip_popup->set_font(MEDIUMFONT);
1132 tooltip_popup->draw_text(TOOLTIP_MARGIN,
1133 get_text_ascent(MEDIUMFONT) + TOOLTIP_MARGIN,
1138 void BC_WindowBase::slide_left(int distance)
1142 XCopyArea(top_level->display,
1143 pixmap->opaque_pixmap,
1144 pixmap->opaque_pixmap,
1155 void BC_WindowBase::slide_right(int distance)
1159 XCopyArea(top_level->display,
1160 pixmap->opaque_pixmap,
1161 pixmap->opaque_pixmap,
1172 void BC_WindowBase::slide_up(int distance)
1176 XCopyArea(top_level->display,
1177 pixmap->opaque_pixmap,
1178 pixmap->opaque_pixmap,
1186 set_color(bg_color);
1187 XFillRectangle(top_level->display,
1188 pixmap->opaque_pixmap,
1197 void BC_WindowBase::slide_down(int distance)
1201 XCopyArea(top_level->display,
1202 pixmap->opaque_pixmap,
1203 pixmap->opaque_pixmap,
1211 set_color(bg_color);
1212 XFillRectangle(top_level->display,
1213 pixmap->opaque_pixmap,
1222 // 3 segments in separate pixmaps. Obsolete.
1223 void BC_WindowBase::draw_3segment(int x,
1227 BC_Pixmap *left_image,
1228 BC_Pixmap *mid_image,
1229 BC_Pixmap *right_image,
1232 if(w <= 0 || h <= 0) return;
1233 int left_boundary = left_image->get_w_fixed();
1234 int right_boundary = w - right_image->get_w_fixed();
1235 for(int i = 0; i < w; )
1239 if(i < left_boundary)
1242 if(i < right_boundary)
1245 image = right_image;
1247 int output_w = image->get_w_fixed();
1249 if(i < left_boundary)
1251 if(i + output_w > left_boundary) output_w = left_boundary - i;
1254 if(i < right_boundary)
1256 if(i + output_w > right_boundary) output_w = right_boundary - i;
1259 if(i + output_w > w) output_w = w - i;
1261 image->write_drawable(pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
1272 // 3 segments in separate vframes. Obsolete.
1273 void BC_WindowBase::draw_3segment(int x,
1279 VFrame *right_image,
1282 if(w <= 0 || h <= 0) return;
1283 int left_boundary = left_image->get_w_fixed();
1284 int right_boundary = w - right_image->get_w_fixed();
1287 for(int i = 0; i < w; )
1291 if(i < left_boundary)
1294 if(i < right_boundary)
1297 image = right_image;
1299 int output_w = image->get_w_fixed();
1301 if(i < left_boundary)
1303 if(i + output_w > left_boundary) output_w = left_boundary - i;
1306 if(i < right_boundary)
1308 if(i + output_w > right_boundary) output_w = right_boundary - i;
1311 if(i + output_w > w) output_w = w - i;
1325 if(output_w == 0) break;
1330 // Draw all 3 segments in a single vframe for a changing level
1335 // <------------------------------------------------------------>
1339 // <-------------------------------------------------------------------->
1341 // |-------------------|----------------------|------------------|
1344 void BC_WindowBase::draw_3segmenth(int x,
1359 void BC_WindowBase::draw_3segmenth(int x,
1367 if(total_w <= 0 || w <= 0 || h <= 0) return;
1368 int third_image = image->get_w() / 3;
1369 int half_image = image->get_w() / 2;
1370 //int left_boundary = third_image;
1371 //int right_boundary = total_w - third_image;
1373 int left_in_w = third_image;
1374 int left_out_x = total_x;
1375 int left_out_w = third_image;
1376 int right_in_x = image->get_w() - third_image;
1377 int right_in_w = third_image;
1378 int right_out_x = total_x + total_w - third_image;
1379 int right_out_w = third_image;
1380 int center_out_x = total_x + third_image;
1381 int center_out_w = total_w - third_image * 2;
1382 //int image_x, image_w;
1384 //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",
1385 // left_out_x, left_out_w, center_out_x, center_out_w, right_out_x, right_out_w);
1389 left_in_w -= x - left_out_x;
1390 left_out_w -= x - left_out_x;
1391 left_in_x += x - left_out_x;
1392 left_out_x += x - left_out_x;
1395 if(left_out_x + left_out_w > x + w)
1397 left_in_w -= (left_out_x + left_out_w) - (x + w);
1398 left_out_w -= (left_out_x + left_out_w) - (x + w);
1403 right_in_w -= x - right_out_x;
1404 right_out_w -= x - right_out_x;
1405 right_in_x += x - right_out_x;
1406 right_out_x += x - right_out_x;
1409 if(right_out_x + right_out_w > x + w)
1411 right_in_w -= (right_out_x + right_out_w) - (x + w);
1412 right_out_w -= (right_out_x + right_out_w) - (x + w);
1415 if(center_out_x < x)
1417 center_out_w -= x - center_out_x;
1418 center_out_x += x - center_out_x;
1421 if(center_out_x + center_out_w > x + w)
1423 center_out_w -= (center_out_x + center_out_w) - (x + w);
1426 if(!temp_bitmap) temp_bitmap = new BC_Bitmap(top_level,
1431 temp_bitmap->match_params(image->get_w(),
1435 temp_bitmap->read_frame(image,
1442 //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",
1443 // left_out_x, left_out_w, center_out_x, center_out_w, right_out_x, right_out_w);
1446 draw_bitmap(temp_bitmap,
1454 -1, // src width and height are meaningless in video_off mode
1461 draw_bitmap(temp_bitmap,
1469 -1, // src width and height are meaningless in video_off mode
1474 for(int pixel = center_out_x;
1475 pixel < center_out_x + center_out_w;
1476 pixel += half_image)
1478 int fragment_w = half_image;
1479 if(fragment_w + pixel > center_out_x + center_out_w)
1480 fragment_w = (center_out_x + center_out_w) - pixel;
1482 //printf("BC_WindowBase::draw_3segment 2 pixel=%d fragment_w=%d\n", pixel, fragment_w);
1483 draw_bitmap(temp_bitmap,
1491 -1, // src width and height are meaningless in video_off mode
1504 void BC_WindowBase::draw_3segmenth(int x,
1512 if(w <= 0 || total_w <= 0) return;
1513 if(!src) printf("BC_WindowBase::draw_3segmenth src=0\n");
1514 int quarter_src = src->get_w() / 4;
1515 int half_src = src->get_w() / 2;
1516 //int left_boundary = quarter_src;
1517 //int right_boundary = total_w - quarter_src;
1519 int left_in_w = quarter_src;
1520 int left_out_x = total_x;
1521 int left_out_w = quarter_src;
1522 int right_in_x = src->get_w() - quarter_src;
1523 int right_in_w = quarter_src;
1524 int right_out_x = total_x + total_w - quarter_src;
1525 int right_out_w = quarter_src;
1526 int center_out_x = total_x + quarter_src;
1527 int center_out_w = total_w - quarter_src * 2;
1530 //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",
1531 // left_out_x, left_out_w, center_out_x, center_out_w, right_out_x, right_out_w);
1535 left_in_w -= x - left_out_x;
1536 left_out_w -= x - left_out_x;
1537 left_in_x += x - left_out_x;
1538 left_out_x += x - left_out_x;
1541 if(left_out_x + left_out_w > x + w)
1543 left_in_w -= (left_out_x + left_out_w) - (x + w);
1544 left_out_w -= (left_out_x + left_out_w) - (x + w);
1549 right_in_w -= x - right_out_x;
1550 right_out_w -= x - right_out_x;
1551 right_in_x += x - right_out_x;
1552 right_out_x += x - right_out_x;
1555 if(right_out_x + right_out_w > x + w)
1557 right_in_w -= (right_out_x + right_out_w) - (x + w);
1558 right_out_w -= (right_out_x + right_out_w) - (x + w);
1561 if(center_out_x < x)
1563 center_out_w -= x - center_out_x;
1564 center_out_x += x - center_out_x;
1567 if(center_out_x + center_out_w > x + w)
1569 center_out_w -= (center_out_x + center_out_w) - (x + w);
1573 //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",
1574 // left_out_x, left_out_w, center_out_x, center_out_w, right_out_x, right_out_w);
1599 for(int pixel = center_out_x;
1600 pixel < center_out_x + center_out_w;
1603 int fragment_w = half_src;
1604 if(fragment_w + pixel > center_out_x + center_out_w)
1605 fragment_w = (center_out_x + center_out_w) - pixel;
1607 //printf("BC_WindowBase::draw_3segment 2 pixel=%d fragment_w=%d\n", pixel, fragment_w);
1621 void BC_WindowBase::draw_3segmenth(int x,
1628 int third_image = src->get_w() / 3;
1629 int half_output = w / 2;
1630 //int left_boundary = third_image;
1631 //int right_boundary = w - third_image;
1633 int left_in_w = third_image;
1635 int left_out_w = third_image;
1636 int right_in_x = src->get_w() - third_image;
1637 int right_in_w = third_image;
1638 int right_out_x = x + w - third_image;
1639 int right_out_w = third_image;
1640 //int image_x, image_w;
1642 //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",
1643 // left_out_x, left_out_w, center_out_x, center_out_w, right_out_x, right_out_w);
1645 if(left_out_w > half_output)
1647 left_in_w -= left_out_w - half_output;
1648 left_out_w -= left_out_w - half_output;
1651 if(right_out_x < x + half_output)
1653 right_in_w -= x + half_output - right_out_x;
1654 right_out_w -= x + half_output - right_out_x;
1655 right_in_x += x + half_output - right_out_x;
1656 right_out_x += x + half_output - right_out_x;
1659 //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",
1660 // left_out_x, left_out_w, center_out_x, center_out_w, right_out_x, right_out_w);
1685 for(int pixel = left_out_x + left_out_w;
1686 pixel < right_out_x;
1687 pixel += third_image)
1689 int fragment_w = third_image;
1690 if(fragment_w + pixel > right_out_x)
1691 fragment_w = right_out_x - pixel;
1693 //printf("BC_WindowBase::draw_3segment 2 pixel=%d fragment_w=%d\n", pixel, fragment_w);
1712 void BC_WindowBase::draw_3segmentv(int x,
1719 int third_image = src->get_h() / 3;
1720 int half_output = h / 2;
1721 //int left_boundary = third_image;
1722 //int right_boundary = h - third_image;
1724 int left_in_h = third_image;
1726 int left_out_h = third_image;
1727 int right_in_y = src->get_h() - third_image;
1728 int right_in_h = third_image;
1729 int right_out_y = y + h - third_image;
1730 int right_out_h = third_image;
1731 //int image_y, image_h;
1734 if(left_out_h > half_output)
1736 left_in_h -= left_out_h - half_output;
1737 left_out_h -= left_out_h - half_output;
1740 if(right_out_y < y + half_output)
1742 right_in_h -= y + half_output - right_out_y;
1743 right_out_h -= y + half_output - right_out_y;
1744 right_in_y += y + half_output - right_out_y;
1745 right_out_y += y + half_output - right_out_y;
1749 if(!temp_bitmap) temp_bitmap = new BC_Bitmap(top_level,
1754 temp_bitmap->match_params(src->get_w(),
1758 temp_bitmap->read_frame(src,
1767 draw_bitmap(temp_bitmap,
1782 draw_bitmap(temp_bitmap,
1795 for(int pixel = left_out_y + left_out_h;
1796 pixel < right_out_y;
1797 pixel += third_image)
1799 int fragment_h = third_image;
1800 if(fragment_h + pixel > right_out_y)
1801 fragment_h = right_out_y - pixel;
1803 //printf("BC_WindowBase::draw_3segment 2 pixel=%d fragment_w=%d\n", pixel, fragment_w);
1804 draw_bitmap(temp_bitmap,
1818 void BC_WindowBase::draw_3segmentv(int x,
1825 int third_image = src->get_h() / 3;
1826 int half_output = h / 2;
1827 //int left_boundary = third_image;
1828 //int right_boundary = h - third_image;
1830 int left_in_h = third_image;
1832 int left_out_h = third_image;
1833 int right_in_y = src->get_h() - third_image;
1834 int right_in_h = third_image;
1835 int right_out_y = y + h - third_image;
1836 int right_out_h = third_image;
1837 //int image_y, image_h;
1840 if(left_out_h > half_output)
1842 left_in_h -= left_out_h - half_output;
1843 left_out_h -= left_out_h - half_output;
1846 if(right_out_y < y + half_output)
1848 right_in_h -= y + half_output - right_out_y;
1849 right_out_h -= y + half_output - right_out_y;
1850 right_in_y += y + half_output - right_out_y;
1851 right_out_y += y + half_output - right_out_y;
1878 for(int pixel = left_out_y + left_out_h;
1879 pixel < right_out_y;
1880 pixel += third_image)
1882 int fragment_h = third_image;
1883 if(fragment_h + pixel > right_out_y)
1884 fragment_h = right_out_y - pixel;
1886 //printf("BC_WindowBase::draw_3segment 2 pixel=%d fragment_w=%d\n", pixel, fragment_w);
1899 void BC_WindowBase::draw_9segment(int x,
1906 if(w <= 0 || h <= 0) return;
1908 int in_x_third = src->get_w() / 3;
1909 int in_y_third = src->get_h() / 3;
1910 int out_x_half = w / 2;
1911 int out_y_half = h / 2;
1917 int in_x2 = MIN(in_x_third, out_x_half);
1918 int in_y2 = MIN(in_y_third, out_y_half);
1922 int out_x3 = MAX(w - out_x_half, w - in_x_third);
1924 int in_x3 = src->get_w() - (out_x4 - out_x3);
1925 //int in_x4 = src->get_w();
1927 int out_y3 = MAX(h - out_y_half, h - in_y_third);
1929 int in_y3 = src->get_h() - (out_y4 - out_y3);
1930 //int in_y4 = src->get_h();
1944 for(int i = out_x2; i < out_x3; i += in_x3 - in_x2)
1948 int w = MIN(in_x3 - in_x2, out_x3 - i);
1977 for(int i = out_y2; i < out_y3; i += in_y3 - in_y2)
1981 int h = MIN(in_y3 - in_y2, out_y3 - i);
1994 // Segment 5 * n * n
1995 for(int i = out_y2; i < out_y3; i += in_y3 - in_y2 /* in_y_third */)
1999 int h = MIN(in_y3 - in_y2 /* in_y_third */, out_y3 - i);
2002 for(int j = out_x2; j < out_x3; j += in_x3 - in_x2 /* in_x_third */)
2004 int w = MIN(in_x3 - in_x2 /* in_x_third */, out_x3 - j);
2019 for(int i = out_y2; i < out_y3; i += in_y3 - in_y2)
2023 int h = MIN(in_y3 - in_y2, out_y3 - i);
2050 for(int i = out_x2; i < out_x3; i += in_x3 - in_x2)
2054 int w = MIN(in_x3 - in_y2, out_x3 - i);
2080 void BC_WindowBase::draw_9segment(int x,
2087 if(w <= 0 || h <= 0) return;
2089 int in_x_third = src->get_w() / 3;
2090 int in_y_third = src->get_h() / 3;
2091 int out_x_half = w / 2;
2092 int out_y_half = h / 2;
2098 int in_x2 = MIN(in_x_third, out_x_half);
2099 int in_y2 = MIN(in_y_third, out_y_half);
2103 int out_x3 = MAX(w - out_x_half, w - in_x_third);
2105 int in_x3 = src->get_w() - (out_x4 - out_x3);
2106 int in_x4 = src->get_w();
2108 int out_y3 = MAX(h - out_y_half, h - in_y_third);
2110 int in_y3 = src->get_h() - (out_y4 - out_y3);
2111 int in_y4 = src->get_h();
2113 //printf("PFCFrame::draw_9segment 1 %d %d %d %d\n", out_x1, out_x2, out_x3, out_x4);
2114 //printf("PFCFrame::draw_9segment 2 %d %d %d %d\n", in_x1, in_x2, in_x3, in_x4);
2115 //printf("PFCFrame::draw_9segment 2 %d %d %d %d\n", in_y1, in_y2, in_y3, in_y4);
2117 if(!temp_bitmap) temp_bitmap = new BC_Bitmap(top_level,
2122 temp_bitmap->match_params(src->get_w(),
2126 temp_bitmap->read_frame(src,
2133 draw_bitmap(temp_bitmap,
2147 for(int i = out_x2; i < out_x3; i += in_x3 - in_x2)
2151 int w = MIN(in_x3 - in_x2, out_x3 - i);
2152 draw_bitmap(temp_bitmap,
2171 draw_bitmap(temp_bitmap,
2186 for(int i = out_y2; i < out_y3; i += in_y3 - in_y2)
2190 int h = MIN(in_y3 - in_y2, out_y3 - i);
2191 draw_bitmap(temp_bitmap,
2206 // Segment 5 * n * n
2207 for(int i = out_y2; i < out_y3; i += in_y3 - in_y2)
2211 int h = MIN(in_y3 - in_y2, out_y3 - i);
2214 for(int j = out_x2; j < out_x3; j += in_x3 - in_x2)
2216 int w = MIN(in_x3 - in_x2, out_x3 - j);
2218 draw_bitmap(temp_bitmap,
2234 for(int i = out_y2; i < out_y3; i += in_y_third)
2238 int h = MIN(in_y_third, out_y3 - i);
2239 draw_bitmap(temp_bitmap,
2257 draw_bitmap(temp_bitmap,
2271 for(int i = out_x2; i < out_x3; i += in_x_third)
2275 int w = MIN(in_x_third, out_x3 - i);
2276 draw_bitmap(temp_bitmap,
2293 draw_bitmap(temp_bitmap,