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))
181 draw_xft_text(x, y, text, length, pixmap, 1);
185 for(int i = 0, j = 0; i <= length; i++)
187 if(text[i] == '\n' || text[i] == 0)
189 if(get_resources()->use_fontset && top_level->get_curr_fontset())
191 XmbDrawString(top_level->display,
192 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
193 top_level->get_curr_fontset(), top_level->gc,
194 x, y, &text[j], i - j);
198 XDrawString(top_level->display,
199 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
201 x, y, &text[j], i - j);
205 y += get_text_height(MEDIUMFONT);
210 void BC_WindowBase::draw_xft_text(int x, int y,
211 const char *text, int length, BC_Pixmap *pixmap, int is_utf8)
214 wchar_t wide_text[l];
215 length = BC_Resources::encode(
216 is_utf8 ? "UTF8" : BC_Resources::encoding, BC_Resources::wide_encoding,
217 (char*)text, length, (char*)wide_text, l*sizeof(wchar_t)) / sizeof(wchar_t);
218 draw_xft_text(x, y, wide_text, length, pixmap);
221 void BC_WindowBase::draw_xft_text(int x, int y,
222 const wchar_t *text, int length, BC_Pixmap *pixmap)
225 const wchar_t *wsp = text, *wep = wsp + length;
226 int font = top_level->current_font;
228 const wchar_t *wcp = wsp;
229 while( wcp < wep && *wcp != '\n' ) ++wcp;
232 draw_single_text(1, font, x, y, wsp, len, pixmap);
233 if( wcp >= wep ) break;
235 dy = get_text_height(font);
241 void BC_WindowBase::xft_draw_string(XftColor *xft_color, XftFont *xft_font,
242 int x, int y, const FcChar32 *fc, int len, BC_Pixmap *pixmap)
244 Pixmap draw_pixmap = 0;
245 XftDraw *xft_draw = (XftDraw *)
246 (pixmap ? pixmap->opaque_xft_draw : this->pixmap->opaque_xft_draw);
247 int src_x = x, src_y = y, src_w = 0, src_h = 0;
249 XGetGCValues(top_level->display, top_level->gc, GCFunction, &values);
250 if( values.function != GXcopy ) {
251 XSetFunction(top_level->display, top_level->gc, GXcopy);
253 xftTextExtents32(top_level->display, xft_font, fc, len, &info);
254 src_w = info.width; src_h = info.height;
255 draw_pixmap = XCreatePixmap(top_level->display, top_level->win,
256 src_w, src_h, top_level->default_depth);
257 int color = get_color(); set_color(0);
258 XFillRectangle(top_level->display, draw_pixmap, top_level->gc, 0, 0, src_w, src_h);
260 xft_draw = xftDrawCreate(top_level->display, draw_pixmap,
261 top_level->vis, top_level->cmap);
262 src_x = info.x; src_y = info.y;
264 xftDrawString32(xft_draw, xft_color, xft_font, src_x, src_y, fc, len);
265 if( values.function != GXcopy ) {
266 XSetFunction(top_level->display, top_level->gc, values.function);
267 Pixmap xpixmap = pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap;
268 XCopyArea(top_level->display, draw_pixmap, xpixmap,
269 top_level->gc, 0, 0, src_w, src_h, x, y);
270 XFreePixmap(top_level->display, draw_pixmap);
271 xftDrawDestroy(xft_draw);
275 int BC_WindowBase::get_single_text_width(int font, const wchar_t *text, int length)
277 return draw_single_text(0, font, 0,0, text, length);
280 int BC_WindowBase::draw_single_text(int draw, int font,
281 int x, int y, const wchar_t *text, int length, BC_Pixmap *pixmap)
284 length = wcslen(text);
285 if( !length ) return 0;
287 if( !get_resources()->use_xft ) {
289 if( !get_font_struct(font) ) return 0;
290 XChar2b xtext[length], *xp = xtext;
291 for( int i=0; i<length; ++i,++xp ) {
292 xp->byte1 = (unsigned char) (text[i] >> 8);
293 xp->byte2 = (unsigned char) (text[i] & 0xff);
296 XDrawString16(top_level->display,
297 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
298 top_level->gc, x, y, xtext, length);
300 return XTextWidth16(get_font_struct(font), xtext, length);
307 color.red = (top_level->current_color & 0xff0000) >> 16;
308 color.red |= color.red << 8;
309 color.green = (top_level->current_color & 0xff00) >> 8;
310 color.green |= color.green << 8;
311 color.blue = (top_level->current_color & 0xff);
312 color.blue |= color.blue << 8;
313 color.alpha = 0xffff;
315 xftColorAllocValue(top_level->display, top_level->vis, top_level->cmap,
320 XftFont *basefont = top_level->get_xft_struct(font);
321 XftFont *curfont = 0, *altfont = 0;
322 const wchar_t *up = text, *ubp = up, *uep = ubp + length;
325 XftFont *xft_font = 0;
326 if( xftCharExists(top_level->display, basefont, *up) )
329 if( xftCharExists(top_level->display, altfont, *up))
332 xftFontClose(top_level->display, altfont);
337 FcPattern *pattern = BC_Resources::find_similar_font(*up, basefont->pattern);
340 fcPatternGetDouble(basefont->pattern, FC_PIXEL_SIZE, 0, &psize);
341 fcPatternAddDouble(pattern, FC_PIXEL_SIZE, psize);
342 fcPatternDel(pattern, FC_SCALABLE);
343 xft_font = altfont = xftFontOpenPattern(top_level->display, pattern);
348 if( xft_font != curfont ) {
349 if( curfont && up > ubp ) {
351 xft_draw_string(&xft_color, curfont, x, y,
352 (const FcChar32*)ubp, up-ubp, pixmap);
355 xftTextExtents32(top_level->display, curfont,
356 (const FcChar32*)ubp, up-ubp, &extents);
359 ubp = up; curfont = xft_font;
364 if( curfont && up > ubp ) {
366 xft_draw_string(&xft_color, curfont, x, y,
367 (const FcChar32*)ubp, up-ubp, pixmap);
370 xftTextExtents32(top_level->display, curfont,
371 (const FcChar32*)ubp, up-ubp, &extents);
376 xftFontClose(top_level->display, altfont);
378 xftColorFree(top_level->display, top_level->vis, top_level->cmap, &xft_color);
383 void BC_WindowBase::truncate_text(char *result, const char *text, int w)
385 int new_w = get_text_width(current_font, text);
388 const char* separator = "...";
389 int separator_w = get_text_width(current_font, separator);
391 if( separator_w >= w ) {
392 strcpy(result, separator);
396 int text_len = strlen(text);
397 // widen middle gap until it fits
398 for( int i=text_len/2; i>0; --i ) {
399 strncpy(result, text, i);
401 strcat(result, separator);
402 strncat(result, text + text_len - i, i);
403 result[i + strlen(separator) + i] = 0;
404 new_w = get_text_width(current_font, result);
405 //printf("BC_WindowBase::truncate_text %d %d %d %s\n", __LINE__, new_w, w, result);
406 if(new_w < w) return;
410 strcpy(result, separator);
414 strcpy(result, text);
417 void BC_WindowBase::draw_center_text(int x, int y, const char *text, int length)
419 if(length < 0) length = strlen(text);
420 int w = get_text_width(current_font, text, length);
422 draw_text(x, y, text, length);
425 void BC_WindowBase::draw_line(int x1, int y1, int x2, int y2, BC_Pixmap *pixmap)
427 // Some X drivers can't draw 0 length lines
428 if( x1 == x2 && y1 == y2 ) {
429 draw_pixel(x1, y1, pixmap);
432 XDrawLine(top_level->display,
433 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
434 top_level->gc, x1, y1, x2, y2);
438 void BC_WindowBase::draw_polygon(ArrayList<int> *x, ArrayList<int> *y, BC_Pixmap *pixmap)
440 int npoints = MIN(x->total, y->total);
441 XPoint *points = new XPoint[npoints];
443 for( int i=0; i<npoints; ++i ) {
444 points[i].x = x->values[i];
445 points[i].y = y->values[i];
448 XDrawLines(top_level->display,
449 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
450 top_level->gc, points, npoints, CoordModeOrigin);
455 void BC_WindowBase::fill_polygon(ArrayList<int> *x, ArrayList<int> *y, BC_Pixmap *pixmap)
457 int npoints = MIN(x->total, y->total);
458 XPoint *points = new XPoint[npoints];
460 for( int i=0; i<npoints; ++i ) {
461 points[i].x = x->values[i];
462 points[i].y = y->values[i];
465 XFillPolygon(top_level->display,
466 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
467 top_level->gc, points, npoints, Nonconvex, CoordModeOrigin);
473 void BC_WindowBase::draw_rectangle(int x, int y, int w, int h)
475 XDrawRectangle(top_level->display,
476 pixmap->opaque_pixmap, top_level->gc,
480 void BC_WindowBase::draw_3d_border(int x, int y, int w, int h, int is_down)
482 draw_3d_border(x, y, w, h,
483 top_level->get_resources()->border_shadow2,
484 top_level->get_resources()->border_shadow1,
485 top_level->get_resources()->border_light1,
486 top_level->get_resources()->border_light2);
490 void BC_WindowBase::draw_3d_border(int x, int y, int w, int h,
491 int light1, int light2, int shadow1, int shadow2)
498 ux = x+w-1; uy = y+h-1;
501 draw_line(x, y, ux, y);
502 draw_line(x, y, x, uy);
504 draw_line(lx, ly, ux - 1, ly);
505 draw_line(lx, ly, lx, uy - 1);
508 draw_line(ux, ly, ux, uy);
509 draw_line(lx, uy, ux, uy);
511 draw_line(x + w, y, x + w, y + h);
512 draw_line(x, y + h, x + w, y + h);
515 void BC_WindowBase::draw_3d_box(int x, int y, int w, int h,
516 int light1, int light2, int middle, int shadow1, int shadow2,
524 ux = x+w-1; uy = y+h-1;
527 draw_box(x, y, w, h, pixmap);
530 draw_line(x, y, ux, y, pixmap);
531 draw_line(x, y, x, uy, pixmap);
533 draw_line(lx, ly, ux - 1, ly, pixmap);
534 draw_line(lx, ly, lx, uy - 1, pixmap);
537 draw_line(ux, ly, ux, uy, pixmap);
538 draw_line(lx, uy, ux, uy, pixmap);
540 draw_line(x + w, y, x + w, y + h, pixmap);
541 draw_line(x, y + h, x + w, y + h, pixmap);
544 void BC_WindowBase::draw_colored_box(int x, int y, int w, int h, int down, int highlighted)
549 draw_3d_box(x, y, w, h,
550 top_level->get_resources()->button_light,
551 top_level->get_resources()->button_highlighted,
552 top_level->get_resources()->button_highlighted,
553 top_level->get_resources()->button_shadow,
556 draw_3d_box(x, y, w, h,
557 top_level->get_resources()->button_light,
558 top_level->get_resources()->button_up,
559 top_level->get_resources()->button_up,
560 top_level->get_resources()->button_shadow,
565 // need highlighting for toggles
567 draw_3d_box(x, y, w, h,
568 top_level->get_resources()->button_shadow,
570 top_level->get_resources()->button_up,
571 top_level->get_resources()->button_up,
572 top_level->get_resources()->button_light);
574 draw_3d_box(x, y, w, h,
575 top_level->get_resources()->button_shadow,
577 top_level->get_resources()->button_down,
578 top_level->get_resources()->button_down,
579 top_level->get_resources()->button_light);
584 void BC_WindowBase::draw_border(char *text, int x, int y, int w, int h)
586 int left_indent = xS(20);
590 lx = x + 1; ly = y + 1;
591 ux = x + w - 1; uy = y + h - 1;
594 if(text && text[0] != 0)
597 set_font(MEDIUMFONT);
598 draw_text(x + left_indent, y + get_text_height(MEDIUMFONT) / 2, text);
601 set_color(top_level->get_resources()->button_shadow);
602 draw_line(x, y, x + left_indent - xS(5), y);
603 draw_line(x, y, x, uy);
604 draw_line(x + left_indent + xS(5) + get_text_width(MEDIUMFONT, text), y, ux, y);
605 draw_line(x, y, x, uy);
606 draw_line(ux, ly, ux, uy);
607 draw_line(lx, uy, ux, uy);
608 set_color(top_level->get_resources()->button_light);
609 draw_line(lx, ly, x + left_indent - xS(5) - 1, ly);
610 draw_line(lx, ly, lx, uy - 1);
611 draw_line(x + left_indent + xS(5) + get_text_width(MEDIUMFONT, text), ly, ux - 1, ly);
612 draw_line(lx, ly, lx, uy - 1);
613 draw_line(x + w, y, x + w, y + h);
614 draw_line(x, y + h, x + w, y + h);
617 void BC_WindowBase::draw_triangle_down_flat(int x, int y, int w, int h)
619 int x1, y1, x2, y2, x3;
622 x1 = x+1; x2 = x + w/2; x3 = x+w-1;
625 point[0].x = x2; point[0].y = y2;
626 point[1].x = x3; point[1].y = y1;
627 point[2].x = x1; point[2].y = y1;
629 XFillPolygon(top_level->display, pixmap->opaque_pixmap, top_level->gc,
630 (XPoint *)point, 3, Nonconvex, CoordModeOrigin);
631 draw_line(x1,y1, x3,y1);
634 void BC_WindowBase::draw_triangle_up(int x, int y, int w, int h,
635 int light1, int light2, int middle, int shadow1, int shadow2)
637 int x1, y1, x2, y2, x3;
640 x1 = x; y1 = y; x2 = x + w / 2;
641 y2 = y + h - 1; x3 = x + w - 1;
644 point[0].x = x2; point[0].y = y1; point[1].x = x3;
645 point[1].y = y2; point[2].x = x1; point[2].y = y2;
648 XFillPolygon(top_level->display, pixmap->opaque_pixmap, top_level->gc,
649 (XPoint *)point, 3, Nonconvex, CoordModeOrigin);
651 // bottom and top right
653 draw_line(x3, y2-1, x1, y2-1);
654 draw_line(x2-1, y1, x3-1, y2);
656 draw_line(x3, y2, x1, y2);
657 draw_line(x2, y1, x3, y2);
661 draw_line(x2+1, y1, x1+1, y2);
663 draw_line(x2, y1, x1, y2);
666 void BC_WindowBase::draw_triangle_down(int x, int y, int w, int h,
667 int light1, int light2, int middle, int shadow1, int shadow2)
669 int x1, y1, x2, y2, x3;
672 x1 = x; x2 = x + w / 2; x3 = x + w - 1;
673 y1 = y; y2 = y + h - 1;
675 point[0].x = x2; point[0].y = y2; point[1].x = x3;
676 point[1].y = y1; point[2].x = x1; point[2].y = y1;
679 XFillPolygon(top_level->display,
680 pixmap->opaque_pixmap,
687 // top and bottom left
689 draw_line(x3-1, y1+1, x1+1, y1+1);
690 draw_line(x1+1, y1, x2+1, y2);
692 draw_line(x3, y1, x1, y1);
693 draw_line(x1, y1, x2, y2);
697 draw_line(x3-1, y1, x2-1, y2);
699 draw_line(x3, y1, x2, y2);
702 void BC_WindowBase::draw_triangle_left(int x, int y, int w, int h,
703 int light1, int light2, int middle, int shadow1, int shadow2)
705 int x1, y1, x2, y2, y3;
709 y1 = y; x1 = x; y2 = y + h / 2;
710 x2 = x + w - 1; y3 = y + h - 1;
712 point[0].x = x1; point[0].y = y2; point[1].x = x2;
713 point[1].y = y1; point[2].x = x2; point[2].y = y3;
716 XFillPolygon(top_level->display,
717 pixmap->opaque_pixmap,
724 // right and bottom right
726 draw_line(x2-1, y1, x2-1, y3-1);
727 draw_line(x2, y3-1, x1, y2-1);
729 draw_line(x2, y1, x2, y3);
730 draw_line(x2, y3, x1, y2);
734 draw_line(x1, y2, x2, y1);
736 draw_line(x1, y2+1, x2, y1+1);
739 void BC_WindowBase::draw_triangle_right(int x, int y, int w, int h,
740 int light1, int light2, int middle, int shadow1, int shadow2)
742 int x1, y1, x2, y2, y3;
745 y1 = y; y2 = y + h / 2; y3 = y + h - 1;
746 x1 = x; x2 = x + w - 1;
748 point[0].x = x1; point[0].y = y1; point[1].x = x2;
749 point[1].y = y2; point[2].x = x1; point[2].y = y3;
752 XFillPolygon(top_level->display,
753 pixmap->opaque_pixmap,
760 // left and top right
762 draw_line(x1+1, y3, x1+1, y1);
763 draw_line(x1, y1+1, x2, y2+1);
765 draw_line(x1, y3, x1, y1);
766 draw_line(x1, y1, x2, y2);
770 draw_line(x2, y2-1, x1, y3-1);
772 draw_line(x2, y2, x1, y3);
776 void BC_WindowBase::draw_check(int x, int y)
778 int xs3 = xS(3), xs4 = xS(4), xs6 = xS(6);
779 int ys1 = yS(1), ys2 = yS(2), ys3 = yS(3), ys4 = yS(4);
780 const int w = xS(15), h = yS(15), yh2 = y + h/2;
781 draw_line(x + xs3, yh2 + 0, x + xs6, yh2 + ys2);
782 draw_line(x + xs3, yh2 + ys1, x + xs6, yh2 + ys3);
783 draw_line(x + xs6, yh2 + ys2, x + w - xs4, yh2 - ys3);
784 draw_line(x + xs3, yh2 + ys2, x + xs6, yh2 + ys4);
785 draw_line(x + xs6, yh2 + ys2, x + w - xs4, yh2 - ys3);
786 draw_line(x + xs6, yh2 + ys3, x + w - xs4, yh2 - ys2);
787 draw_line(x + xs6, yh2 + ys4, x + w - xs4, yh2 - ys1);
790 void BC_WindowBase::draw_tiles(BC_Pixmap *tile, int origin_x, int origin_y, int x, int y, int w, int h)
794 draw_box(x, y, w, h);
797 XSetFillStyle(top_level->display, top_level->gc, FillTiled);
798 // Don't know how slow this is
799 XSetTile(top_level->display, top_level->gc, tile->get_pixmap());
800 XSetTSOrigin(top_level->display, top_level->gc, origin_x, origin_y);
801 draw_box(x, y, w, h);
802 XSetFillStyle(top_level->display, top_level->gc, FillSolid);
806 void BC_WindowBase::draw_top_tiles(BC_WindowBase *parent_window, int x, int y, int w, int h)
809 int origin_x, origin_y;
810 XTranslateCoordinates(top_level->display,
811 parent_window->win, win,
812 0, 0, &origin_x, &origin_y, &tempwin);
813 draw_tiles(parent_window->bg_pixmap,
818 void BC_WindowBase::draw_top_background(BC_WindowBase *parent_window,
819 int x, int y, int w, int h, BC_Pixmap *pixmap)
823 XLockDisplay(top_level->display);
825 XTranslateCoordinates(top_level->display,
826 win, parent_window->win,
827 x, y, &top_x, &top_y, &tempwin);
829 XCopyArea(top_level->display,
830 parent_window->pixmap->opaque_pixmap,
831 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
832 top_level->gc, top_x, top_y, w, h, x, y);
834 XUnlockDisplay(top_level->display);
837 void BC_WindowBase::draw_background(int x, int y, int w, int h)
840 draw_tiles(bg_pixmap, 0, 0, x, y, w, h);
843 clear_box(x, y, w, h);
847 void BC_WindowBase::draw_bitmap(BC_Bitmap *bitmap, int dont_wait,
848 int dest_x, int dest_y, int dest_w, int dest_h,
849 int src_x, int src_y, int src_w, int src_h,
852 // Hide cursor if video enabled
853 update_video_cursor();
855 //printf("BC_WindowBase::draw_bitmap %d dest_y=%d\n", __LINE__, dest_y);
856 if( dest_w <= 0 || dest_h <= 0 ) {
857 // Use hardware scaling to canvas dimensions if proper color model.
858 if( bitmap->get_color_model() == BC_YUV420P ) {
863 dest_w = bitmap->get_w();
864 dest_h = bitmap->get_h();
868 if( src_w <= 0 || src_h <= 0 ) {
869 src_w = bitmap->get_w();
870 src_h = bitmap->get_h();
874 bitmap->write_drawable(win,
875 top_level->gc, src_x, src_y, src_w, src_h,
876 dest_x, dest_y, dest_w, dest_h, dont_wait);
880 bitmap->write_drawable(pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
881 top_level->gc, dest_x, dest_y, src_x, src_y, dest_w, dest_h, dont_wait);
883 //printf("BC_WindowBase::draw_bitmap 2\n");
887 void BC_WindowBase::draw_pixel(int x, int y, BC_Pixmap *pixmap)
889 XDrawPoint(top_level->display,
890 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
891 top_level->gc, x, y);
895 void BC_WindowBase::draw_pixmap(BC_Pixmap *pixmap,
896 int dest_x, int dest_y, int dest_w, int dest_h,
897 int src_x, int src_y, BC_Pixmap *dst)
899 pixmap->write_drawable(dst ? dst->opaque_pixmap : this->pixmap->opaque_pixmap,
900 dest_x, dest_y, dest_w, dest_h, src_x, src_y);
903 void BC_WindowBase::draw_vframe(VFrame *frame,
904 int dest_x, int dest_y, int dest_w, int dest_h,
905 int src_x, int src_y, int src_w, int src_h,
908 if(dest_w <= 0) dest_w = frame->get_w() - src_x;
909 if(dest_h <= 0) dest_h = frame->get_h() - src_y;
910 if(src_w <= 0) src_w = frame->get_w() - src_x;
911 if(src_h <= 0) src_h = frame->get_h() - src_y;
912 CLAMP(src_x, 0, frame->get_w() - 1);
913 CLAMP(src_y, 0, frame->get_h() - 1);
914 if(src_x + src_w > frame->get_w()) src_w = frame->get_w() - src_x;
915 if(src_y + src_h > frame->get_h()) src_h = frame->get_h() - src_y;
918 temp_bitmap = new BC_Bitmap(this, dest_w, dest_h, get_color_model(), 0);
919 temp_bitmap->match_params(dest_w, dest_h, get_color_model(), 0);
921 temp_bitmap->read_frame(frame,
922 src_x, src_y, src_w, src_h,
923 0, 0, dest_w, dest_h, bg_color);
925 draw_bitmap(temp_bitmap, 0,
926 dest_x, dest_y, dest_w, dest_h,
927 0, 0, -1, -1, pixmap);
930 void BC_WindowBase::draw_tooltip(const char *text)
934 if(tooltip_popup && text)
936 int w = tooltip_popup->get_w(), h = tooltip_popup->get_h();
937 tooltip_popup->set_color(get_resources()->tooltip_bg_color);
938 tooltip_popup->draw_box(0, 0, w, h);
939 tooltip_popup->set_color(BLACK);
940 tooltip_popup->draw_rectangle(0, 0, w, h);
941 tooltip_popup->set_font(MEDIUMFONT);
942 tooltip_popup->draw_text(TOOLTIP_MARGIN,
943 get_text_ascent(MEDIUMFONT) + TOOLTIP_MARGIN,
948 void BC_WindowBase::slide_left(int distance)
952 XCopyArea(top_level->display,
953 pixmap->opaque_pixmap,
954 pixmap->opaque_pixmap,
965 void BC_WindowBase::slide_right(int distance)
969 XCopyArea(top_level->display,
970 pixmap->opaque_pixmap, pixmap->opaque_pixmap, top_level->gc,
971 0, 0, w - distance, h, distance, 0);
975 void BC_WindowBase::slide_up(int distance)
979 XCopyArea(top_level->display,
980 pixmap->opaque_pixmap, pixmap->opaque_pixmap, top_level->gc,
981 0, distance, w, h - distance, 0, 0);
983 XFillRectangle(top_level->display, pixmap->opaque_pixmap, top_level->gc,
984 0, h - distance, w, distance);
988 void BC_WindowBase::slide_down(int distance)
992 XCopyArea(top_level->display,
993 pixmap->opaque_pixmap, pixmap->opaque_pixmap, top_level->gc,
994 0, 0, w, h - distance, 0, distance);
996 XFillRectangle(top_level->display,
997 pixmap->opaque_pixmap, top_level->gc,
1002 // 3 segments in separate pixmaps. Obsolete.
1003 void BC_WindowBase::draw_3segment(int x, int y, int w, int h,
1004 BC_Pixmap *left_image, BC_Pixmap *mid_image,
1005 BC_Pixmap *right_image, BC_Pixmap *pixmap)
1007 if(w <= 0 || h <= 0) return;
1008 int left_boundary = left_image->get_w_fixed();
1009 int right_boundary = w - right_image->get_w_fixed();
1010 for(int i = 0; i < w; )
1014 if(i < left_boundary)
1017 if(i < right_boundary)
1020 image = right_image;
1022 int output_w = image->get_w_fixed();
1024 if(i < left_boundary)
1026 if(i + output_w > left_boundary) output_w = left_boundary - i;
1029 if(i < right_boundary)
1031 if(i + output_w > right_boundary) output_w = right_boundary - i;
1034 if(i + output_w > w) output_w = w - i;
1036 image->write_drawable(pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
1037 x + i, y, output_w, h, 0, 0);
1041 // 3 segments in separate vframes. Obsolete.
1042 void BC_WindowBase::draw_3segment(int x, int y, int w, int h,
1043 VFrame *left_image, VFrame *mid_image,
1044 VFrame *right_image, BC_Pixmap *pixmap)
1046 if(w <= 0 || h <= 0) return;
1047 int left_boundary = left_image->get_w_fixed();
1048 int right_boundary = w - right_image->get_w_fixed();
1051 for(int i = 0; i < w; )
1055 if(i < left_boundary)
1058 if(i < right_boundary)
1061 image = right_image;
1063 int output_w = image->get_w_fixed();
1065 if(i < left_boundary)
1067 if(i + output_w > left_boundary) output_w = left_boundary - i;
1070 if(i < right_boundary)
1072 if(i + output_w > right_boundary) output_w = right_boundary - i;
1075 if(i + output_w > w) output_w = w - i;
1078 draw_vframe(image, x + i, y, output_w, h,
1079 0, 0, 0, 0, pixmap);
1081 if(output_w == 0) break;
1086 // Draw all 3 segments in a single vframe for a changing level
1091 // <------------------------------------------------------------>
1095 // <-------------------------------------------------------------------->
1097 // |-------------------|----------------------|------------------|
1100 void BC_WindowBase::draw_3segmenth(int x, int y, int w,
1101 VFrame *image, BC_Pixmap *pixmap)
1103 draw_3segmenth(x, y, w, x, w, image, pixmap);
1106 void BC_WindowBase::draw_3segmenth(int x, int y, int w,
1107 int total_x, int total_w, VFrame *image,
1110 if(total_w <= 0 || w <= 0 || h <= 0) return;
1111 int third_image = image->get_w() / 3;
1112 int half_image = image->get_w() / 2;
1113 //int left_boundary = third_image;
1114 //int right_boundary = total_w - third_image;
1116 int left_in_w = third_image;
1117 int left_out_x = total_x;
1118 int left_out_w = third_image;
1119 int right_in_x = image->get_w() - third_image;
1120 int right_in_w = third_image;
1121 int right_out_x = total_x + total_w - third_image;
1122 int right_out_w = third_image;
1123 int center_out_x = total_x + third_image;
1124 int center_out_w = total_w - third_image * 2;
1125 //int image_x, image_w;
1127 //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",
1128 // left_out_x, left_out_w, center_out_x, center_out_w, right_out_x, right_out_w);
1132 left_in_w -= x - left_out_x;
1133 left_out_w -= x - left_out_x;
1134 left_in_x += x - left_out_x;
1135 left_out_x += x - left_out_x;
1138 if(left_out_x + left_out_w > x + w)
1140 left_in_w -= (left_out_x + left_out_w) - (x + w);
1141 left_out_w -= (left_out_x + left_out_w) - (x + w);
1146 right_in_w -= x - right_out_x;
1147 right_out_w -= x - right_out_x;
1148 right_in_x += x - right_out_x;
1149 right_out_x += x - right_out_x;
1152 if(right_out_x + right_out_w > x + w)
1154 right_in_w -= (right_out_x + right_out_w) - (x + w);
1155 right_out_w -= (right_out_x + right_out_w) - (x + w);
1158 if(center_out_x < x)
1160 center_out_w -= x - center_out_x;
1161 center_out_x += x - center_out_x;
1164 if(center_out_x + center_out_w > x + w)
1166 center_out_w -= (center_out_x + center_out_w) - (x + w);
1169 if(!temp_bitmap) temp_bitmap = new BC_Bitmap(top_level,
1170 image->get_w(), image->get_h(),
1171 get_color_model(), 0);
1172 temp_bitmap->match_params(image->get_w(), image->get_h(),
1173 get_color_model(), 0);
1174 temp_bitmap->read_frame(image,
1175 0, 0, image->get_w(), image->get_h(), bg_color);
1176 // src width and height are meaningless in video_off mode
1177 //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",
1178 // left_out_x, left_out_w, center_out_x, center_out_w, right_out_x, right_out_w);
1179 if(left_out_w > 0) {
1180 draw_bitmap(temp_bitmap, 0,
1181 left_out_x, y, left_out_w, image->get_h(),
1182 left_in_x, 0, -1, -1, pixmap);
1185 if(right_out_w > 0) {
1186 draw_bitmap(temp_bitmap, 0,
1187 right_out_x, y, right_out_w, image->get_h(),
1188 right_in_x, 0, -1, -1, pixmap);
1191 for( int pixel = center_out_x;
1192 pixel < center_out_x + center_out_w;
1193 pixel += half_image ) {
1194 int fragment_w = half_image;
1195 if(fragment_w + pixel > center_out_x + center_out_w)
1196 fragment_w = (center_out_x + center_out_w) - pixel;
1198 //printf("BC_WindowBase::draw_3segment 2 pixel=%d fragment_w=%d\n", pixel, fragment_w);
1199 draw_bitmap(temp_bitmap, 0,
1200 pixel, y, fragment_w, image->get_h(),
1201 third_image, 0, -1, -1, pixmap);
1206 void BC_WindowBase::draw_3segmenth(int x, int y, int w, int total_x, int total_w,
1207 BC_Pixmap *src, BC_Pixmap *dst)
1209 if(w <= 0 || total_w <= 0) return;
1210 if(!src) printf("BC_WindowBase::draw_3segmenth src=0\n");
1211 int quarter_src = src->get_w() / 4;
1212 int half_src = src->get_w() / 2;
1213 //int left_boundary = quarter_src;
1214 //int right_boundary = total_w - quarter_src;
1216 int left_in_w = quarter_src;
1217 int left_out_x = total_x;
1218 int left_out_w = quarter_src;
1219 int right_in_x = src->get_w() - quarter_src;
1220 int right_in_w = quarter_src;
1221 int right_out_x = total_x + total_w - quarter_src;
1222 int right_out_w = quarter_src;
1223 int center_out_x = total_x + quarter_src;
1224 int center_out_w = total_w - quarter_src * 2;
1227 //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",
1228 // left_out_x, left_out_w, center_out_x, center_out_w, right_out_x, right_out_w);
1232 left_in_w -= x - left_out_x;
1233 left_out_w -= x - left_out_x;
1234 left_in_x += x - left_out_x;
1235 left_out_x += x - left_out_x;
1238 if(left_out_x + left_out_w > x + w)
1240 left_in_w -= (left_out_x + left_out_w) - (x + w);
1241 left_out_w -= (left_out_x + left_out_w) - (x + w);
1246 right_in_w -= x - right_out_x;
1247 right_out_w -= x - right_out_x;
1248 right_in_x += x - right_out_x;
1249 right_out_x += x - right_out_x;
1252 if(right_out_x + right_out_w > x + w)
1254 right_in_w -= (right_out_x + right_out_w) - (x + w);
1255 right_out_w -= (right_out_x + right_out_w) - (x + w);
1258 if(center_out_x < x)
1260 center_out_w -= x - center_out_x;
1261 center_out_x += x - center_out_x;
1264 if(center_out_x + center_out_w > x + w)
1266 center_out_w -= (center_out_x + center_out_w) - (x + w);
1270 //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",
1271 // left_out_x, left_out_w, center_out_x, center_out_w, right_out_x, right_out_w);
1273 draw_pixmap(src, left_out_x, y, left_out_w, src->get_h(), left_in_x, 0, dst);
1276 draw_pixmap(src, right_out_x, y, right_out_w, src->get_h(), right_in_x, 0, dst);
1278 for( int pixel = center_out_x; pixel < center_out_x + center_out_w; pixel += half_src) {
1279 int fragment_w = half_src;
1280 if(fragment_w + pixel > center_out_x + center_out_w)
1281 fragment_w = (center_out_x + center_out_w) - pixel;
1282 //printf("BC_WindowBase::draw_3segment 2 pixel=%d fragment_w=%d\n", pixel, fragment_w);
1283 draw_pixmap(src, pixel, y, fragment_w, src->get_h(), quarter_src, 0, dst);
1289 void BC_WindowBase::draw_3segmenth(int x, int y, int w, BC_Pixmap *src, BC_Pixmap *dst)
1292 int third_image = src->get_w() / 3;
1293 int half_output = w / 2;
1294 //int left_boundary = third_image;
1295 //int right_boundary = w - third_image;
1297 int left_in_w = third_image;
1299 int left_out_w = third_image;
1300 int right_in_x = src->get_w() - third_image;
1301 int right_in_w = third_image;
1302 int right_out_x = x + w - third_image;
1303 int right_out_w = third_image;
1304 //int image_x, image_w;
1306 //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",
1307 // left_out_x, left_out_w, center_out_x, center_out_w, right_out_x, right_out_w);
1309 if(left_out_w > half_output)
1311 left_in_w -= left_out_w - half_output;
1312 left_out_w -= left_out_w - half_output;
1315 if(right_out_x < x + half_output)
1317 right_in_w -= x + half_output - right_out_x;
1318 right_out_w -= x + half_output - right_out_x;
1319 right_in_x += x + half_output - right_out_x;
1320 right_out_x += x + half_output - right_out_x;
1323 //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",
1324 // left_out_x, left_out_w, center_out_x, center_out_w, right_out_x, right_out_w);
1326 draw_pixmap(src, left_out_x, y, left_out_w, src->get_h(), left_in_x, 0, dst);
1329 draw_pixmap(src, right_out_x, y, right_out_w, src->get_h(), right_in_x, 0, dst);
1331 for(int pixel = left_out_x + left_out_w; pixel < right_out_x; pixel += third_image) {
1332 int fragment_w = third_image;
1333 if(fragment_w + pixel > right_out_x)
1334 fragment_w = right_out_x - pixel;
1336 //printf("BC_WindowBase::draw_3segment 2 pixel=%d fragment_w=%d\n", pixel, fragment_w);
1337 draw_pixmap(src, pixel, y, fragment_w, src->get_h(), third_image, 0, dst);
1342 void BC_WindowBase::draw_3segmentv(int x, int y, int h, VFrame *src, BC_Pixmap *dst)
1345 int third_image = src->get_h() / 3;
1346 int half_output = h / 2;
1347 //int left_boundary = third_image;
1348 //int right_boundary = h - third_image;
1350 int left_in_h = third_image;
1352 int left_out_h = third_image;
1353 int right_in_y = src->get_h() - third_image;
1354 int right_in_h = third_image;
1355 int right_out_y = y + h - third_image;
1356 int right_out_h = third_image;
1357 //int image_y, image_h;
1360 if(left_out_h > half_output)
1362 left_in_h -= left_out_h - half_output;
1363 left_out_h -= left_out_h - half_output;
1366 if(right_out_y < y + half_output)
1368 right_in_h -= y + half_output - right_out_y;
1369 right_out_h -= y + half_output - right_out_y;
1370 right_in_y += y + half_output - right_out_y;
1371 right_out_y += y + half_output - right_out_y;
1375 if(!temp_bitmap) temp_bitmap = new BC_Bitmap(top_level,
1380 temp_bitmap->match_params(src->get_w(),
1384 temp_bitmap->read_frame(src,
1385 0, 0, src->get_w(), src->get_h(), bg_color);
1390 draw_bitmap(temp_bitmap, 0, x, left_out_y,
1391 src->get_w(), left_out_h, 0, left_in_y,
1397 draw_bitmap(temp_bitmap, 0, x, right_out_y,
1398 src->get_w(), right_out_h, 0, right_in_y,
1402 for(int pixel = left_out_y + left_out_h;
1403 pixel < right_out_y;
1404 pixel += third_image)
1406 int fragment_h = third_image;
1407 if(fragment_h + pixel > right_out_y)
1408 fragment_h = right_out_y - pixel;
1410 //printf("BC_WindowBase::draw_3segment 2 pixel=%d fragment_w=%d\n", pixel, fragment_w);
1411 draw_bitmap(temp_bitmap, 0, x, pixel,
1412 src->get_w(), fragment_h, 0, third_image,
1417 void BC_WindowBase::draw_3segmentv(int x,
1424 int third_image = src->get_h() / 3;
1425 int half_output = h / 2;
1426 //int left_boundary = third_image;
1427 //int right_boundary = h - third_image;
1429 int left_in_h = third_image;
1431 int left_out_h = third_image;
1432 int right_in_y = src->get_h() - third_image;
1433 int right_in_h = third_image;
1434 int right_out_y = y + h - third_image;
1435 int right_out_h = third_image;
1436 //int image_y, image_h;
1439 if(left_out_h > half_output)
1441 left_in_h -= left_out_h - half_output;
1442 left_out_h -= left_out_h - half_output;
1445 if(right_out_y < y + half_output)
1447 right_in_h -= y + half_output - right_out_y;
1448 right_out_h -= y + half_output - right_out_y;
1449 right_in_y += y + half_output - right_out_y;
1450 right_out_y += y + half_output - right_out_y;
1454 draw_pixmap(src, x, left_out_y, src->get_w(), left_out_h,
1458 draw_pixmap(src, x, right_out_y, src->get_w(), right_out_h,
1459 0, right_in_y, dst);
1461 for(int pixel = left_out_y + left_out_h; pixel < right_out_y; pixel += third_image) {
1462 int fragment_h = third_image;
1463 if(fragment_h + pixel > right_out_y)
1464 fragment_h = right_out_y - pixel;
1466 //printf("BC_WindowBase::draw_3segment 2 pixel=%d fragment_w=%d\n", pixel, fragment_w);
1467 draw_pixmap(src, x, pixel, src->get_w(), fragment_h,
1468 0, third_image, dst);
1473 void BC_WindowBase::draw_9segment(int x, int y, int w, int h,
1474 BC_Pixmap *src, BC_Pixmap *dst)
1476 if(w <= 0 || h <= 0) return;
1478 int in_x_third = src->get_w() / 3;
1479 int in_y_third = src->get_h() / 3;
1480 int out_x_half = w / 2;
1481 int out_y_half = h / 2;
1487 int in_x2 = MIN(in_x_third, out_x_half);
1488 int in_y2 = MIN(in_y_third, out_y_half);
1492 int out_x3 = MAX(w - out_x_half, w - in_x_third);
1494 int in_x3 = src->get_w() - (out_x4 - out_x3);
1495 //int in_x4 = src->get_w();
1497 int out_y3 = MAX(h - out_y_half, h - in_y_third);
1499 int in_y3 = src->get_h() - (out_y4 - out_y3);
1500 //int in_y4 = src->get_h();
1503 draw_pixmap(src, x + out_x1, y + out_y1, out_x2 - out_x1, out_y2 - out_y1,
1507 for(int i = out_x2; i < out_x3; i += in_x3 - in_x2) {
1508 if(out_x3 - i > 0) {
1509 int w = MIN(in_x3 - in_x2, out_x3 - i);
1510 draw_pixmap(src, x + i, y + out_y1, w, out_y2 - out_y1,
1516 draw_pixmap(src, x + out_x3, y + out_y1, out_x4 - out_x3, out_y2 - out_y1,
1520 for(int i = out_y2; i < out_y3; i += in_y3 - in_y2)
1524 int h = MIN(in_y3 - in_y2, out_y3 - i);
1525 draw_pixmap(src, x + out_x1, y + i, out_x2 - out_x1, h,
1530 // Segment 5 * n * n
1531 for(int i = out_y2; i < out_y3; i += in_y3 - in_y2 /* in_y_third */)
1535 int h = MIN(in_y3 - in_y2 /* in_y_third */, out_y3 - i);
1538 for(int j = out_x2; j < out_x3; j += in_x3 - in_x2 /* in_x_third */)
1540 int w = MIN(in_x3 - in_x2 /* in_x_third */, out_x3 - j);
1542 draw_pixmap(src, x + j, y + i, w, h,
1549 for(int i = out_y2; i < out_y3; i += in_y3 - in_y2)
1553 int h = MIN(in_y3 - in_y2, out_y3 - i);
1554 draw_pixmap(src, x + out_x3, y + i, out_x4 - out_x3, h,
1560 draw_pixmap(src, x + out_x1, y + out_y3, out_x2 - out_x1, out_y4 - out_y3,
1564 for(int i = out_x2; i < out_x3; i += in_x3 - in_x2)
1568 int w = MIN(in_x3 - in_y2, out_x3 - i);
1569 draw_pixmap(src, x + i, y + out_y3, w, out_y4 - out_y3,
1575 draw_pixmap(src, x + out_x3, y + out_y3, out_x4 - out_x3, out_y4 - out_y3,
1580 void BC_WindowBase::draw_9segment(int x, int y, int w, int h,
1581 VFrame *src, BC_Pixmap *dst)
1583 if(w <= 0 || h <= 0) return;
1585 int in_x_third = src->get_w() / 3;
1586 int in_y_third = src->get_h() / 3;
1587 int out_x_half = w / 2;
1588 int out_y_half = h / 2;
1594 int in_x2 = MIN(in_x_third, out_x_half);
1595 int in_y2 = MIN(in_y_third, out_y_half);
1599 int out_x3 = MAX(w - out_x_half, w - in_x_third);
1601 int in_x3 = src->get_w() - (out_x4 - out_x3);
1602 int in_x4 = src->get_w();
1604 int out_y3 = MAX(h - out_y_half, h - in_y_third);
1606 int in_y3 = src->get_h() - (out_y4 - out_y3);
1607 int in_y4 = src->get_h();
1609 //printf("PFCFrame::draw_9segment 1 %d %d %d %d\n", out_x1, out_x2, out_x3, out_x4);
1610 //printf("PFCFrame::draw_9segment 2 %d %d %d %d\n", in_x1, in_x2, in_x3, in_x4);
1611 //printf("PFCFrame::draw_9segment 2 %d %d %d %d\n", in_y1, in_y2, in_y3, in_y4);
1613 if(!temp_bitmap) temp_bitmap = new BC_Bitmap(top_level,
1618 temp_bitmap->match_params(src->get_w(),
1622 temp_bitmap->read_frame(src,
1623 0, 0, src->get_w(), src->get_h(), bg_color);
1626 draw_bitmap(temp_bitmap, 0,
1627 x + out_x1, y + out_y1, out_x2 - out_x1, out_y2 - out_y1,
1628 in_x1, in_y1, in_x2 - in_x1, in_y2 - in_y1,
1632 for( int i = out_x2; i < out_x3; i += in_x3 - in_x2 ) {
1633 if( out_x3 - i > 0 ) {
1634 int w = MIN(in_x3 - in_x2, out_x3 - i);
1635 draw_bitmap(temp_bitmap, 0,
1636 x + i, y + out_y1, w, out_y2 - out_y1,
1637 in_x2, in_y1, w, in_y2 - in_y1,
1643 draw_bitmap(temp_bitmap, 0,
1644 x + out_x3, y + out_y1, out_x4 - out_x3, out_y2 - out_y1,
1645 in_x3, in_y1, in_x4 - in_x3, in_y2 - in_y1,
1649 for( int i = out_y2; i < out_y3; i += in_y3 - in_y2 ) {
1650 if( out_y3 - i > 0 ) {
1651 int h = MIN(in_y3 - in_y2, out_y3 - i);
1652 draw_bitmap(temp_bitmap, 0,
1653 x + out_x1, y + i, out_x2 - out_x1, h,
1654 in_x1, in_y2, in_x2 - in_x1, h,
1659 // Segment 5 * n * n
1660 for( int i = out_y2; i < out_y3; i += in_y3 - in_y2 ) {
1661 if( out_y3 - i > 0 ) {
1662 int h = MIN(in_y3 - in_y2, out_y3 - i);
1664 for( int j = out_x2; j < out_x3; j += in_x3 - in_x2 ) {
1665 int w = MIN(in_x3 - in_x2, out_x3 - j);
1667 draw_bitmap(temp_bitmap, 0,
1676 for( int i = out_y2; i < out_y3; i += in_y_third ) {
1677 if( out_y3 - i > 0 ) {
1678 int h = MIN(in_y_third, out_y3 - i);
1679 draw_bitmap(temp_bitmap, 0,
1680 x + out_x3, y + i, out_x4 - out_x3, h,
1681 in_x3, in_y2, in_x4 - in_x3, h,
1687 draw_bitmap(temp_bitmap, 0,
1688 x + out_x1, y + out_y3, out_x2 - out_x1, out_y4 - out_y3,
1689 in_x1, in_y3, in_x2 - in_x1, in_y4 - in_y3,
1693 for( int i = out_x2; i < out_x3; i += in_x_third ) {
1694 if( out_x3 - i > 0 ) {
1695 int w = MIN(in_x_third, out_x3 - i);
1696 draw_bitmap(temp_bitmap, 0,
1697 x + i, y + out_y3, w, out_y4 - out_y3,
1698 in_x2, in_y3, w, in_y4 - in_y3,
1704 draw_bitmap(temp_bitmap, 0,
1705 x + out_x3, y + out_y3, out_x4 - out_x3, out_y4 - out_y3,
1706 in_x3, in_y3, in_x4 - in_x3, in_y4 - in_y3,