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 void BC_WindowBase::xft_draw_string(XftColor *xft_color, XftFont *xft_font,
250 int x, int y, const FcChar32 *fc, int len, BC_Pixmap *pixmap)
252 Pixmap draw_pixmap = 0;
253 XftDraw *xft_draw = (XftDraw *)
254 (pixmap ? pixmap->opaque_xft_draw : this->pixmap->opaque_xft_draw);
255 int src_x = x, src_y = y, src_w = 0, src_h = 0;
257 XGetGCValues(top_level->display, top_level->gc, GCFunction, &values);
258 if( values.function != GXcopy ) {
259 XSetFunction(top_level->display, top_level->gc, GXcopy);
261 XftTextExtents32(top_level->display, xft_font, fc, len, &info);
262 src_w = info.width; src_h = info.height;
263 draw_pixmap = XCreatePixmap(top_level->display, top_level->win,
264 src_w, src_h, top_level->default_depth);
265 int color = get_color(); set_color(0);
266 XFillRectangle(top_level->display, draw_pixmap, top_level->gc, 0, 0, src_w, src_h);
268 xft_draw = XftDrawCreate(top_level->display, draw_pixmap,
269 top_level->vis, top_level->cmap);
270 src_x = info.x; src_y = info.y;
272 XftDrawString32(xft_draw, xft_color, xft_font, src_x, src_y, fc, len);
273 if( values.function != GXcopy ) {
274 XSetFunction(top_level->display, top_level->gc, values.function);
275 Pixmap xpixmap = pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap;
276 XCopyArea(top_level->display, draw_pixmap, xpixmap,
277 top_level->gc, 0, 0, src_w, src_h, x, y);
278 XFreePixmap(top_level->display, draw_pixmap);
279 XftDrawDestroy(xft_draw);
283 void BC_WindowBase::draw_wtext(int x, int y,
284 const wchar_t *text, int length, BC_Pixmap *pixmap)
286 if( !get_resources()->use_xft ) {
287 if( !get_font_struct(current_font) ) return;
288 XChar2b xtext[length], *xp = xtext;
289 for( int i=0; i<length; ++i,++xp ) {
290 xp->byte1 = (unsigned char) (text[i] >> 8);
291 xp->byte2 = (unsigned char) (text[i] & 0xff);
293 XDrawString16(top_level->display,
294 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
295 top_level->gc, x, y, xtext, length);
300 const wchar_t *up, *ubp;
303 XftFont *curfont, *nextfont, *altfont, *basefont;
306 length = wcslen(text);
311 color.red = (top_level->current_color & 0xff0000) >> 16;
312 color.red |= color.red << 8;
313 color.green = (top_level->current_color & 0xff00) >> 8;
314 color.green |= color.green << 8;
315 color.blue = (top_level->current_color & 0xff);
316 color.blue |= color.blue << 8;
317 color.alpha = 0xffff;
319 XftColorAllocValue(top_level->display,
325 basefont = top_level->get_xft_struct(top_level->current_font);
327 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 xft_draw_string(&xft_color, curfont, x, y,
364 (const FcChar32*)ubp, l, pixmap);
367 XftTextExtents32(top_level->display, curfont,
368 (const FcChar32*)ubp, l, &extents);
378 xft_draw_string(&xft_color, curfont, x, y,
379 (const FcChar32*)ubp, up - ubp, pixmap);
383 XftFontClose(top_level->display, altfont);
385 XftColorFree(top_level->display,
391 void BC_WindowBase::truncate_text(char *result, const char *text, int w)
393 int new_w = get_text_width(current_font, text);
397 const char* separator = "...";
398 int separator_w = get_text_width(current_font, separator);
402 strcpy(result, separator);
406 int text_len = strlen(text);
407 // widen middle gap until it fits
408 for(int i = text_len / 2; i > 0; i--)
410 strncpy(result, text, i);
412 strcat(result, separator);
413 strncat(result, text + text_len - i, i);
414 result[i + strlen(separator) + i] = 0;
415 new_w = get_text_width(current_font, result);
416 //printf("BC_WindowBase::truncate_text %d %d %d %s\n", __LINE__, new_w, w, result);
417 if(new_w < w) return;
421 strcpy(result, separator);
426 strcpy(result, text);
430 void BC_WindowBase::draw_center_text(int x, int y, const char *text, int length)
432 if(length < 0) length = strlen(text);
433 int w = get_text_width(current_font, text, length);
435 draw_text(x, y, text, length);
438 void BC_WindowBase::draw_line(int x1, int y1, int x2, int y2, BC_Pixmap *pixmap)
440 // Some X drivers can't draw 0 length lines
441 if(x1 == x2 && y1 == y2)
443 draw_pixel(x1, y1, pixmap);
447 XDrawLine(top_level->display,
448 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
457 void BC_WindowBase::draw_polygon(ArrayList<int> *x, ArrayList<int> *y, BC_Pixmap *pixmap)
459 int npoints = MIN(x->total, y->total);
460 XPoint *points = new XPoint[npoints];
462 for(int i = 0; i < npoints; i++)
464 points[i].x = x->values[i];
465 points[i].y = y->values[i];
468 XDrawLines(top_level->display,
469 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
478 void BC_WindowBase::fill_polygon(ArrayList<int> *x, ArrayList<int> *y, BC_Pixmap *pixmap)
480 int npoints = MIN(x->total, y->total);
481 XPoint *points = new XPoint[npoints];
483 for(int i = 0; i < npoints; i++)
485 points[i].x = x->values[i];
486 points[i].y = y->values[i];
489 XFillPolygon(top_level->display,
490 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
501 void BC_WindowBase::draw_rectangle(int x, int y, int w, int h)
503 XDrawRectangle(top_level->display,
504 pixmap->opaque_pixmap,
512 void BC_WindowBase::draw_3d_border(int x,
522 top_level->get_resources()->border_shadow2,
523 top_level->get_resources()->border_shadow1,
524 top_level->get_resources()->border_light1,
525 top_level->get_resources()->border_light2);
529 void BC_WindowBase::draw_3d_border(int x,
543 ux = x+w-1; uy = y+h-1;
546 draw_line(x, y, ux, y);
547 draw_line(x, y, x, uy);
549 draw_line(lx, ly, ux - 1, ly);
550 draw_line(lx, ly, lx, uy - 1);
553 draw_line(ux, ly, ux, uy);
554 draw_line(lx, uy, ux, uy);
556 draw_line(x + w, y, x + w, y + h);
557 draw_line(x, y + h, x + w, y + h);
560 void BC_WindowBase::draw_3d_box(int x,
576 ux = x+w-1; uy = y+h-1;
579 draw_box(x, y, w, h, pixmap);
582 draw_line(x, y, ux, y, pixmap);
583 draw_line(x, y, x, uy, pixmap);
585 draw_line(lx, ly, ux - 1, ly, pixmap);
586 draw_line(lx, ly, lx, uy - 1, pixmap);
589 draw_line(ux, ly, ux, uy, pixmap);
590 draw_line(lx, uy, ux, uy, pixmap);
592 draw_line(x + w, y, x + w, y + h, pixmap);
593 draw_line(x, y + h, x + w, y + h, pixmap);
596 void BC_WindowBase::draw_colored_box(int x, int y, int w, int h, int down, int highlighted)
601 draw_3d_box(x, y, w, h,
602 top_level->get_resources()->button_light,
603 top_level->get_resources()->button_highlighted,
604 top_level->get_resources()->button_highlighted,
605 top_level->get_resources()->button_shadow,
608 draw_3d_box(x, y, w, h,
609 top_level->get_resources()->button_light,
610 top_level->get_resources()->button_up,
611 top_level->get_resources()->button_up,
612 top_level->get_resources()->button_shadow,
617 // need highlighting for toggles
619 draw_3d_box(x, y, w, h,
620 top_level->get_resources()->button_shadow,
622 top_level->get_resources()->button_up,
623 top_level->get_resources()->button_up,
624 top_level->get_resources()->button_light);
626 draw_3d_box(x, y, w, h,
627 top_level->get_resources()->button_shadow,
629 top_level->get_resources()->button_down,
630 top_level->get_resources()->button_down,
631 top_level->get_resources()->button_light);
636 void BC_WindowBase::draw_border(char *text, int x, int y, int w, int h)
638 int left_indent = 20;
642 lx = x + 1; ly = y + 1;
643 ux = x + w - 1; uy = y + h - 1;
646 if(text && text[0] != 0)
649 set_font(MEDIUMFONT);
650 draw_text(x + left_indent, y + get_text_height(MEDIUMFONT) / 2, text);
653 set_color(top_level->get_resources()->button_shadow);
654 draw_line(x, y, x + left_indent - 5, y);
655 draw_line(x, y, x, uy);
656 draw_line(x + left_indent + 5 + get_text_width(MEDIUMFONT, text), y, ux, y);
657 draw_line(x, y, x, uy);
658 draw_line(ux, ly, ux, uy);
659 draw_line(lx, uy, ux, uy);
660 set_color(top_level->get_resources()->button_light);
661 draw_line(lx, ly, x + left_indent - 5 - 1, ly);
662 draw_line(lx, ly, lx, uy - 1);
663 draw_line(x + left_indent + 5 + get_text_width(MEDIUMFONT, text), ly, ux - 1, ly);
664 draw_line(lx, ly, lx, uy - 1);
665 draw_line(x + w, y, x + w, y + h);
666 draw_line(x, y + h, x + w, y + h);
669 void BC_WindowBase::draw_triangle_down_flat(int x, int y, int w, int h)
671 int x1, y1, x2, y2, x3;
674 x1 = x; x2 = x + w / 2; x3 = x + w - 1;
675 y1 = y; y2 = y + h - 1;
677 point[0].x = x2; point[0].y = y2; point[1].x = x3;
678 point[1].y = y1; point[2].x = x1; point[2].y = y1;
680 XFillPolygon(top_level->display,
681 pixmap->opaque_pixmap,
689 void BC_WindowBase::draw_triangle_up(int x, int y, int w, int h,
690 int light1, int light2, int middle, int shadow1, int shadow2)
692 int x1, y1, x2, y2, x3;
695 x1 = x; y1 = y; x2 = x + w / 2;
696 y2 = y + h - 1; x3 = x + w - 1;
699 point[0].x = x2; point[0].y = y1; point[1].x = x3;
700 point[1].y = y2; point[2].x = x1; point[2].y = y2;
703 XFillPolygon(top_level->display,
704 pixmap->opaque_pixmap,
711 // bottom and top right
713 draw_line(x3, y2-1, x1, y2-1);
714 draw_line(x2-1, y1, x3-1, y2);
716 draw_line(x3, y2, x1, y2);
717 draw_line(x2, y1, x3, y2);
721 draw_line(x2+1, y1, x1+1, y2);
723 draw_line(x2, y1, x1, y2);
726 void BC_WindowBase::draw_triangle_down(int x, int y, int w, int h,
727 int light1, int light2, int middle, int shadow1, int shadow2)
729 int x1, y1, x2, y2, x3;
732 x1 = x; x2 = x + w / 2; x3 = x + w - 1;
733 y1 = y; y2 = y + h - 1;
735 point[0].x = x2; point[0].y = y2; point[1].x = x3;
736 point[1].y = y1; point[2].x = x1; point[2].y = y1;
739 XFillPolygon(top_level->display,
740 pixmap->opaque_pixmap,
747 // top and bottom left
749 draw_line(x3-1, y1+1, x1+1, y1+1);
750 draw_line(x1+1, y1, x2+1, y2);
752 draw_line(x3, y1, x1, y1);
753 draw_line(x1, y1, x2, y2);
757 draw_line(x3-1, y1, x2-1, y2);
759 draw_line(x3, y1, x2, y2);
762 void BC_WindowBase::draw_triangle_left(int x, int y, int w, int h,
763 int light1, int light2, int middle, int shadow1, int shadow2)
765 int x1, y1, x2, y2, y3;
769 y1 = y; x1 = x; y2 = y + h / 2;
770 x2 = x + w - 1; y3 = y + h - 1;
772 point[0].x = x1; point[0].y = y2; point[1].x = x2;
773 point[1].y = y1; point[2].x = x2; point[2].y = y3;
776 XFillPolygon(top_level->display,
777 pixmap->opaque_pixmap,
784 // right and bottom right
786 draw_line(x2-1, y1, x2-1, y3-1);
787 draw_line(x2, y3-1, x1, y2-1);
789 draw_line(x2, y1, x2, y3);
790 draw_line(x2, y3, x1, y2);
794 draw_line(x1, y2, x2, y1);
796 draw_line(x1, y2+1, x2, y1+1);
799 void BC_WindowBase::draw_triangle_right(int x, int y, int w, int h,
800 int light1, int light2, int middle, int shadow1, int shadow2)
802 int x1, y1, x2, y2, y3;
805 y1 = y; y2 = y + h / 2; y3 = y + h - 1;
806 x1 = x; x2 = x + w - 1;
808 point[0].x = x1; point[0].y = y1; point[1].x = x2;
809 point[1].y = y2; point[2].x = x1; point[2].y = y3;
812 XFillPolygon(top_level->display,
813 pixmap->opaque_pixmap,
820 // left and top right
822 draw_line(x1+1, y3, x1+1, y1);
823 draw_line(x1, y1+1, x2, y2+1);
825 draw_line(x1, y3, x1, y1);
826 draw_line(x1, y1, x2, y2);
830 draw_line(x2, y2-1, x1, y3-1);
832 draw_line(x2, y2, x1, y3);
836 void BC_WindowBase::draw_check(int x, int y)
838 const int w = 15, h = 15;
839 draw_line(x + 3, y + h / 2 + 0, x + 6, y + h / 2 + 2);
840 draw_line(x + 3, y + h / 2 + 1, x + 6, y + h / 2 + 3);
841 draw_line(x + 6, y + h / 2 + 2, x + w - 4, y + h / 2 - 3);
842 draw_line(x + 3, y + h / 2 + 2, x + 6, y + h / 2 + 4);
843 draw_line(x + 6, y + h / 2 + 2, x + w - 4, y + h / 2 - 3);
844 draw_line(x + 6, y + h / 2 + 3, x + w - 4, y + h / 2 - 2);
845 draw_line(x + 6, y + h / 2 + 4, x + w - 4, y + h / 2 - 1);
848 void BC_WindowBase::draw_tiles(BC_Pixmap *tile, int origin_x, int origin_y, int x, int y, int w, int h)
853 draw_box(x, y, w, h);
857 XSetFillStyle(top_level->display, top_level->gc, FillTiled);
858 // Don't know how slow this is
859 XSetTile(top_level->display, top_level->gc, tile->get_pixmap());
860 XSetTSOrigin(top_level->display, top_level->gc, origin_x, origin_y);
861 draw_box(x, y, w, h);
862 XSetFillStyle(top_level->display, top_level->gc, FillSolid);
866 void BC_WindowBase::draw_top_tiles(BC_WindowBase *parent_window, int x, int y, int w, int h)
869 int origin_x, origin_y;
870 XTranslateCoordinates(top_level->display,
879 draw_tiles(parent_window->bg_pixmap,
888 void BC_WindowBase::draw_top_background(BC_WindowBase *parent_window,
897 XLockDisplay(top_level->display);
899 XTranslateCoordinates(top_level->display,
908 XCopyArea(top_level->display,
909 parent_window->pixmap->opaque_pixmap,
910 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
919 XUnlockDisplay(top_level->display);
922 void BC_WindowBase::draw_background(int x, int y, int w, int h)
926 draw_tiles(bg_pixmap, 0, 0, x, y, w, h);
930 clear_box(x, y, w, h);
934 void BC_WindowBase::draw_bitmap(BC_Bitmap *bitmap,
947 // Hide cursor if video enabled
948 update_video_cursor();
950 //printf("BC_WindowBase::draw_bitmap 1\n");
951 if(dest_w <= 0 || dest_h <= 0)
953 // Use hardware scaling to canvas dimensions if proper color model.
954 if(bitmap->get_color_model() == BC_YUV420P)
961 dest_w = bitmap->get_w();
962 dest_h = bitmap->get_h();
966 if(src_w <= 0 || src_h <= 0)
968 src_w = bitmap->get_w();
969 src_h = bitmap->get_h();
974 bitmap->write_drawable(win,
989 bitmap->write_drawable(pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
999 //printf("BC_WindowBase::draw_bitmap 2\n");
1003 void BC_WindowBase::draw_pixel(int x, int y, BC_Pixmap *pixmap)
1005 XDrawPoint(top_level->display,
1006 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
1013 void BC_WindowBase::draw_pixmap(BC_Pixmap *pixmap,
1022 pixmap->write_drawable(dst ? dst->opaque_pixmap : this->pixmap->opaque_pixmap,
1031 void BC_WindowBase::draw_vframe(VFrame *frame,
1042 if(dest_w <= 0) dest_w = frame->get_w() - src_x;
1043 if(dest_h <= 0) dest_h = frame->get_h() - src_y;
1044 if(src_w <= 0) src_w = frame->get_w() - src_x;
1045 if(src_h <= 0) src_h = frame->get_h() - src_y;
1046 CLAMP(src_x, 0, frame->get_w() - 1);
1047 CLAMP(src_y, 0, frame->get_h() - 1);
1048 if(src_x + src_w > frame->get_w()) src_w = frame->get_w() - src_x;
1049 if(src_y + src_h > frame->get_h()) src_h = frame->get_h() - src_y;
1051 if(!temp_bitmap) temp_bitmap = new BC_Bitmap(this,
1057 temp_bitmap->match_params(dest_w,
1062 temp_bitmap->read_frame(frame,
1072 draw_bitmap(temp_bitmap,
1085 void BC_WindowBase::draw_tooltip(const char *text)
1088 text = tooltip_text;
1089 if(tooltip_popup && text)
1091 int w = tooltip_popup->get_w(), h = tooltip_popup->get_h();
1092 tooltip_popup->set_color(get_resources()->tooltip_bg_color);
1093 tooltip_popup->draw_box(0, 0, w, h);
1094 tooltip_popup->set_color(BLACK);
1095 tooltip_popup->draw_rectangle(0, 0, w, h);
1096 tooltip_popup->set_font(MEDIUMFONT);
1097 tooltip_popup->draw_text(TOOLTIP_MARGIN,
1098 get_text_ascent(MEDIUMFONT) + TOOLTIP_MARGIN,
1103 void BC_WindowBase::slide_left(int distance)
1107 XCopyArea(top_level->display,
1108 pixmap->opaque_pixmap,
1109 pixmap->opaque_pixmap,
1120 void BC_WindowBase::slide_right(int distance)
1124 XCopyArea(top_level->display,
1125 pixmap->opaque_pixmap,
1126 pixmap->opaque_pixmap,
1137 void BC_WindowBase::slide_up(int distance)
1141 XCopyArea(top_level->display,
1142 pixmap->opaque_pixmap,
1143 pixmap->opaque_pixmap,
1151 set_color(bg_color);
1152 XFillRectangle(top_level->display,
1153 pixmap->opaque_pixmap,
1162 void BC_WindowBase::slide_down(int distance)
1166 XCopyArea(top_level->display,
1167 pixmap->opaque_pixmap,
1168 pixmap->opaque_pixmap,
1176 set_color(bg_color);
1177 XFillRectangle(top_level->display,
1178 pixmap->opaque_pixmap,
1187 // 3 segments in separate pixmaps. Obsolete.
1188 void BC_WindowBase::draw_3segment(int x,
1192 BC_Pixmap *left_image,
1193 BC_Pixmap *mid_image,
1194 BC_Pixmap *right_image,
1197 if(w <= 0 || h <= 0) return;
1198 int left_boundary = left_image->get_w_fixed();
1199 int right_boundary = w - right_image->get_w_fixed();
1200 for(int i = 0; i < w; )
1204 if(i < left_boundary)
1207 if(i < right_boundary)
1210 image = right_image;
1212 int output_w = image->get_w_fixed();
1214 if(i < left_boundary)
1216 if(i + output_w > left_boundary) output_w = left_boundary - i;
1219 if(i < right_boundary)
1221 if(i + output_w > right_boundary) output_w = right_boundary - i;
1224 if(i + output_w > w) output_w = w - i;
1226 image->write_drawable(pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
1237 // 3 segments in separate vframes. Obsolete.
1238 void BC_WindowBase::draw_3segment(int x,
1244 VFrame *right_image,
1247 if(w <= 0 || h <= 0) return;
1248 int left_boundary = left_image->get_w_fixed();
1249 int right_boundary = w - right_image->get_w_fixed();
1252 for(int i = 0; i < w; )
1256 if(i < left_boundary)
1259 if(i < right_boundary)
1262 image = right_image;
1264 int output_w = image->get_w_fixed();
1266 if(i < left_boundary)
1268 if(i + output_w > left_boundary) output_w = left_boundary - i;
1271 if(i < right_boundary)
1273 if(i + output_w > right_boundary) output_w = right_boundary - i;
1276 if(i + output_w > w) output_w = w - i;
1290 if(output_w == 0) break;
1295 // Draw all 3 segments in a single vframe for a changing level
1300 // <------------------------------------------------------------>
1304 // <-------------------------------------------------------------------->
1306 // |-------------------|----------------------|------------------|
1309 void BC_WindowBase::draw_3segmenth(int x,
1324 void BC_WindowBase::draw_3segmenth(int x,
1332 if(total_w <= 0 || w <= 0 || h <= 0) return;
1333 int third_image = image->get_w() / 3;
1334 int half_image = image->get_w() / 2;
1335 //int left_boundary = third_image;
1336 //int right_boundary = total_w - third_image;
1338 int left_in_w = third_image;
1339 int left_out_x = total_x;
1340 int left_out_w = third_image;
1341 int right_in_x = image->get_w() - third_image;
1342 int right_in_w = third_image;
1343 int right_out_x = total_x + total_w - third_image;
1344 int right_out_w = third_image;
1345 int center_out_x = total_x + third_image;
1346 int center_out_w = total_w - third_image * 2;
1347 //int image_x, image_w;
1349 //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",
1350 // left_out_x, left_out_w, center_out_x, center_out_w, right_out_x, right_out_w);
1354 left_in_w -= x - left_out_x;
1355 left_out_w -= x - left_out_x;
1356 left_in_x += x - left_out_x;
1357 left_out_x += x - left_out_x;
1360 if(left_out_x + left_out_w > x + w)
1362 left_in_w -= (left_out_x + left_out_w) - (x + w);
1363 left_out_w -= (left_out_x + left_out_w) - (x + w);
1368 right_in_w -= x - right_out_x;
1369 right_out_w -= x - right_out_x;
1370 right_in_x += x - right_out_x;
1371 right_out_x += x - right_out_x;
1374 if(right_out_x + right_out_w > x + w)
1376 right_in_w -= (right_out_x + right_out_w) - (x + w);
1377 right_out_w -= (right_out_x + right_out_w) - (x + w);
1380 if(center_out_x < x)
1382 center_out_w -= x - center_out_x;
1383 center_out_x += x - center_out_x;
1386 if(center_out_x + center_out_w > x + w)
1388 center_out_w -= (center_out_x + center_out_w) - (x + w);
1391 if(!temp_bitmap) temp_bitmap = new BC_Bitmap(top_level,
1396 temp_bitmap->match_params(image->get_w(),
1400 temp_bitmap->read_frame(image,
1407 //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",
1408 // left_out_x, left_out_w, center_out_x, center_out_w, right_out_x, right_out_w);
1411 draw_bitmap(temp_bitmap,
1419 -1, // src width and height are meaningless in video_off mode
1426 draw_bitmap(temp_bitmap,
1434 -1, // src width and height are meaningless in video_off mode
1439 for(int pixel = center_out_x;
1440 pixel < center_out_x + center_out_w;
1441 pixel += half_image)
1443 int fragment_w = half_image;
1444 if(fragment_w + pixel > center_out_x + center_out_w)
1445 fragment_w = (center_out_x + center_out_w) - pixel;
1447 //printf("BC_WindowBase::draw_3segment 2 pixel=%d fragment_w=%d\n", pixel, fragment_w);
1448 draw_bitmap(temp_bitmap,
1456 -1, // src width and height are meaningless in video_off mode
1469 void BC_WindowBase::draw_3segmenth(int x,
1477 if(w <= 0 || total_w <= 0) return;
1478 if(!src) printf("BC_WindowBase::draw_3segmenth src=0\n");
1479 int quarter_src = src->get_w() / 4;
1480 int half_src = src->get_w() / 2;
1481 //int left_boundary = quarter_src;
1482 //int right_boundary = total_w - quarter_src;
1484 int left_in_w = quarter_src;
1485 int left_out_x = total_x;
1486 int left_out_w = quarter_src;
1487 int right_in_x = src->get_w() - quarter_src;
1488 int right_in_w = quarter_src;
1489 int right_out_x = total_x + total_w - quarter_src;
1490 int right_out_w = quarter_src;
1491 int center_out_x = total_x + quarter_src;
1492 int center_out_w = total_w - quarter_src * 2;
1495 //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",
1496 // left_out_x, left_out_w, center_out_x, center_out_w, right_out_x, right_out_w);
1500 left_in_w -= x - left_out_x;
1501 left_out_w -= x - left_out_x;
1502 left_in_x += x - left_out_x;
1503 left_out_x += x - left_out_x;
1506 if(left_out_x + left_out_w > x + w)
1508 left_in_w -= (left_out_x + left_out_w) - (x + w);
1509 left_out_w -= (left_out_x + left_out_w) - (x + w);
1514 right_in_w -= x - right_out_x;
1515 right_out_w -= x - right_out_x;
1516 right_in_x += x - right_out_x;
1517 right_out_x += x - right_out_x;
1520 if(right_out_x + right_out_w > x + w)
1522 right_in_w -= (right_out_x + right_out_w) - (x + w);
1523 right_out_w -= (right_out_x + right_out_w) - (x + w);
1526 if(center_out_x < x)
1528 center_out_w -= x - center_out_x;
1529 center_out_x += x - center_out_x;
1532 if(center_out_x + center_out_w > x + w)
1534 center_out_w -= (center_out_x + center_out_w) - (x + w);
1538 //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",
1539 // left_out_x, left_out_w, center_out_x, center_out_w, right_out_x, right_out_w);
1564 for(int pixel = center_out_x;
1565 pixel < center_out_x + center_out_w;
1568 int fragment_w = half_src;
1569 if(fragment_w + pixel > center_out_x + center_out_w)
1570 fragment_w = (center_out_x + center_out_w) - pixel;
1572 //printf("BC_WindowBase::draw_3segment 2 pixel=%d fragment_w=%d\n", pixel, fragment_w);
1586 void BC_WindowBase::draw_3segmenth(int x,
1593 int third_image = src->get_w() / 3;
1594 int half_output = w / 2;
1595 //int left_boundary = third_image;
1596 //int right_boundary = w - third_image;
1598 int left_in_w = third_image;
1600 int left_out_w = third_image;
1601 int right_in_x = src->get_w() - third_image;
1602 int right_in_w = third_image;
1603 int right_out_x = x + w - third_image;
1604 int right_out_w = third_image;
1605 //int image_x, image_w;
1607 //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",
1608 // left_out_x, left_out_w, center_out_x, center_out_w, right_out_x, right_out_w);
1610 if(left_out_w > half_output)
1612 left_in_w -= left_out_w - half_output;
1613 left_out_w -= left_out_w - half_output;
1616 if(right_out_x < x + half_output)
1618 right_in_w -= x + half_output - right_out_x;
1619 right_out_w -= x + half_output - right_out_x;
1620 right_in_x += x + half_output - right_out_x;
1621 right_out_x += x + half_output - right_out_x;
1624 //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",
1625 // left_out_x, left_out_w, center_out_x, center_out_w, right_out_x, right_out_w);
1650 for(int pixel = left_out_x + left_out_w;
1651 pixel < right_out_x;
1652 pixel += third_image)
1654 int fragment_w = third_image;
1655 if(fragment_w + pixel > right_out_x)
1656 fragment_w = right_out_x - pixel;
1658 //printf("BC_WindowBase::draw_3segment 2 pixel=%d fragment_w=%d\n", pixel, fragment_w);
1677 void BC_WindowBase::draw_3segmentv(int x,
1684 int third_image = src->get_h() / 3;
1685 int half_output = h / 2;
1686 //int left_boundary = third_image;
1687 //int right_boundary = h - third_image;
1689 int left_in_h = third_image;
1691 int left_out_h = third_image;
1692 int right_in_y = src->get_h() - third_image;
1693 int right_in_h = third_image;
1694 int right_out_y = y + h - third_image;
1695 int right_out_h = third_image;
1696 //int image_y, image_h;
1699 if(left_out_h > half_output)
1701 left_in_h -= left_out_h - half_output;
1702 left_out_h -= left_out_h - half_output;
1705 if(right_out_y < y + half_output)
1707 right_in_h -= y + half_output - right_out_y;
1708 right_out_h -= y + half_output - right_out_y;
1709 right_in_y += y + half_output - right_out_y;
1710 right_out_y += y + half_output - right_out_y;
1714 if(!temp_bitmap) temp_bitmap = new BC_Bitmap(top_level,
1719 temp_bitmap->match_params(src->get_w(),
1723 temp_bitmap->read_frame(src,
1732 draw_bitmap(temp_bitmap,
1747 draw_bitmap(temp_bitmap,
1760 for(int pixel = left_out_y + left_out_h;
1761 pixel < right_out_y;
1762 pixel += third_image)
1764 int fragment_h = third_image;
1765 if(fragment_h + pixel > right_out_y)
1766 fragment_h = right_out_y - pixel;
1768 //printf("BC_WindowBase::draw_3segment 2 pixel=%d fragment_w=%d\n", pixel, fragment_w);
1769 draw_bitmap(temp_bitmap,
1783 void BC_WindowBase::draw_3segmentv(int x,
1790 int third_image = src->get_h() / 3;
1791 int half_output = h / 2;
1792 //int left_boundary = third_image;
1793 //int right_boundary = h - third_image;
1795 int left_in_h = third_image;
1797 int left_out_h = third_image;
1798 int right_in_y = src->get_h() - third_image;
1799 int right_in_h = third_image;
1800 int right_out_y = y + h - third_image;
1801 int right_out_h = third_image;
1802 //int image_y, image_h;
1805 if(left_out_h > half_output)
1807 left_in_h -= left_out_h - half_output;
1808 left_out_h -= left_out_h - half_output;
1811 if(right_out_y < y + half_output)
1813 right_in_h -= y + half_output - right_out_y;
1814 right_out_h -= y + half_output - right_out_y;
1815 right_in_y += y + half_output - right_out_y;
1816 right_out_y += y + half_output - right_out_y;
1843 for(int pixel = left_out_y + left_out_h;
1844 pixel < right_out_y;
1845 pixel += third_image)
1847 int fragment_h = third_image;
1848 if(fragment_h + pixel > right_out_y)
1849 fragment_h = right_out_y - pixel;
1851 //printf("BC_WindowBase::draw_3segment 2 pixel=%d fragment_w=%d\n", pixel, fragment_w);
1864 void BC_WindowBase::draw_9segment(int x,
1871 if(w <= 0 || h <= 0) return;
1873 int in_x_third = src->get_w() / 3;
1874 int in_y_third = src->get_h() / 3;
1875 int out_x_half = w / 2;
1876 int out_y_half = h / 2;
1882 int in_x2 = MIN(in_x_third, out_x_half);
1883 int in_y2 = MIN(in_y_third, out_y_half);
1887 int out_x3 = MAX(w - out_x_half, w - in_x_third);
1889 int in_x3 = src->get_w() - (out_x4 - out_x3);
1890 //int in_x4 = src->get_w();
1892 int out_y3 = MAX(h - out_y_half, h - in_y_third);
1894 int in_y3 = src->get_h() - (out_y4 - out_y3);
1895 //int in_y4 = src->get_h();
1909 for(int i = out_x2; i < out_x3; i += in_x3 - in_x2)
1913 int w = MIN(in_x3 - in_x2, out_x3 - i);
1942 for(int i = out_y2; i < out_y3; i += in_y3 - in_y2)
1946 int h = MIN(in_y3 - in_y2, out_y3 - i);
1959 // Segment 5 * n * n
1960 for(int i = out_y2; i < out_y3; i += in_y3 - in_y2 /* in_y_third */)
1964 int h = MIN(in_y3 - in_y2 /* in_y_third */, out_y3 - i);
1967 for(int j = out_x2; j < out_x3; j += in_x3 - in_x2 /* in_x_third */)
1969 int w = MIN(in_x3 - in_x2 /* in_x_third */, out_x3 - j);
1984 for(int i = out_y2; i < out_y3; i += in_y3 - in_y2)
1988 int h = MIN(in_y3 - in_y2, out_y3 - i);
2015 for(int i = out_x2; i < out_x3; i += in_x3 - in_x2)
2019 int w = MIN(in_x3 - in_y2, out_x3 - i);
2045 void BC_WindowBase::draw_9segment(int x,
2052 if(w <= 0 || h <= 0) return;
2054 int in_x_third = src->get_w() / 3;
2055 int in_y_third = src->get_h() / 3;
2056 int out_x_half = w / 2;
2057 int out_y_half = h / 2;
2063 int in_x2 = MIN(in_x_third, out_x_half);
2064 int in_y2 = MIN(in_y_third, out_y_half);
2068 int out_x3 = MAX(w - out_x_half, w - in_x_third);
2070 int in_x3 = src->get_w() - (out_x4 - out_x3);
2071 int in_x4 = src->get_w();
2073 int out_y3 = MAX(h - out_y_half, h - in_y_third);
2075 int in_y3 = src->get_h() - (out_y4 - out_y3);
2076 int in_y4 = src->get_h();
2078 //printf("PFCFrame::draw_9segment 1 %d %d %d %d\n", out_x1, out_x2, out_x3, out_x4);
2079 //printf("PFCFrame::draw_9segment 2 %d %d %d %d\n", in_x1, in_x2, in_x3, in_x4);
2080 //printf("PFCFrame::draw_9segment 2 %d %d %d %d\n", in_y1, in_y2, in_y3, in_y4);
2082 if(!temp_bitmap) temp_bitmap = new BC_Bitmap(top_level,
2087 temp_bitmap->match_params(src->get_w(),
2091 temp_bitmap->read_frame(src,
2098 draw_bitmap(temp_bitmap,
2112 for(int i = out_x2; i < out_x3; i += in_x3 - in_x2)
2116 int w = MIN(in_x3 - in_x2, out_x3 - i);
2117 draw_bitmap(temp_bitmap,
2136 draw_bitmap(temp_bitmap,
2151 for(int i = out_y2; i < out_y3; i += in_y3 - in_y2)
2155 int h = MIN(in_y3 - in_y2, out_y3 - i);
2156 draw_bitmap(temp_bitmap,
2171 // Segment 5 * n * n
2172 for(int i = out_y2; i < out_y3; i += in_y3 - in_y2)
2176 int h = MIN(in_y3 - in_y2, out_y3 - i);
2179 for(int j = out_x2; j < out_x3; j += in_x3 - in_x2)
2181 int w = MIN(in_x3 - in_x2, out_x3 - j);
2183 draw_bitmap(temp_bitmap,
2199 for(int i = out_y2; i < out_y3; i += in_y_third)
2203 int h = MIN(in_y_third, out_y3 - i);
2204 draw_bitmap(temp_bitmap,
2222 draw_bitmap(temp_bitmap,
2236 for(int i = out_x2; i < out_x3; i += in_x_third)
2240 int w = MIN(in_x_third, out_x3 - i);
2241 draw_bitmap(temp_bitmap,
2258 draw_bitmap(temp_bitmap,