r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / guicast / bcwindowdraw.C
blob1b361e58c6099e9f5e647d8c1174d3cc4f00055d
1 #include "bcbitmap.h"
2 #include "bcpixmap.h"
3 #include "bcpopup.h"
4 #include "bcresources.h"
5 #include "bcwindowbase.h"
6 #include "clip.h"
7 #include "colors.h"
8 #include "fonts.h"
9 #include "vframe.h"
10 #include <string.h>
12 void BC_WindowBase::copy_area(int x1, int y1, int x2, int y2, int w, int h, BC_Pixmap *pixmap)
14         XCopyArea(top_level->display, 
15                 pixmap ? pixmap->opaque_pixmap : this->pixmap, 
16                 pixmap ? pixmap->opaque_pixmap : this->pixmap, 
17                 top_level->gc, 
18                 x1, 
19                 y1, 
20                 w,
21         h, 
22                 x2, 
23                 y2);
27 void BC_WindowBase::draw_box(int x, int y, int w, int h, BC_Pixmap *pixmap)
29 //if(x == 0) printf("BC_WindowBase::draw_box %d %d %d %d\n", x, y, w, h);
30         XFillRectangle(top_level->display, 
31                 pixmap ? pixmap->opaque_pixmap : this->pixmap, 
32                 top_level->gc, 
33                 x, 
34                 y, 
35                 w, 
36                 h);
39 void BC_WindowBase::draw_circle(int x, int y, int w, int h, BC_Pixmap *pixmap)
41         XDrawArc(top_level->display, 
42                 pixmap ? pixmap->opaque_pixmap : this->pixmap, 
43                 top_level->gc, 
44                 x, 
45                 y, 
46                 (w - 1), 
47                 (h - 2), 
48                 0 * 64, 
49                 360 * 64);
52 void BC_WindowBase::draw_disc(int x, int y, int w, int h, BC_Pixmap *pixmap)
54         XFillArc(top_level->display, 
55                 pixmap ? pixmap->opaque_pixmap : this->pixmap, 
56                 top_level->gc, 
57                 x, 
58                 y, 
59                 (w - 1), 
60                 (h - 2), 
61                 0 * 64, 
62                 360 * 64);
65 void BC_WindowBase::clear_box(int x, int y, int w, int h, BC_Pixmap *pixmap)
67         set_color(bg_color);
68         XFillRectangle(top_level->display, 
69                 pixmap ? pixmap->opaque_pixmap : this->pixmap, 
70                 top_level->gc, 
71                 x, 
72                 y, 
73                 w, 
74                 h);
77 void BC_WindowBase::draw_text(int x, int y, char *text, int length, BC_Pixmap *pixmap)
79         if(length < 0) length = strlen(text);
80         int boldface = top_level->current_font & BOLDFACE;
81         int font = top_level->current_font & 0xff;
83         switch(font)
84         {
85                 case MEDIUM_7SEGMENT:
86                         for(int i = 0; i < length; i++)
87                         {
88                                 VFrame *image;
89                                 switch(text[i])
90                                 {
91                                         case '0':
92                                                 image = get_resources()->medium_7segment[0];
93                                                 break;
94                                         case '1':
95                                                 image = get_resources()->medium_7segment[1];
96                                                 break;
97                                         case '2':
98                                                 image = get_resources()->medium_7segment[2];
99                                                 break;
100                                         case '3':
101                                                 image = get_resources()->medium_7segment[3];
102                                                 break;
103                                         case '4':
104                                                 image = get_resources()->medium_7segment[4];
105                                                 break;
106                                         case '5':
107                                                 image = get_resources()->medium_7segment[5];
108                                                 break;
109                                         case '6':
110                                                 image = get_resources()->medium_7segment[6];
111                                                 break;
112                                         case '7':
113                                                 image = get_resources()->medium_7segment[7];
114                                                 break;
115                                         case '8':
116                                                 image = get_resources()->medium_7segment[8];
117                                                 break;
118                                         case '9':
119                                                 image = get_resources()->medium_7segment[9];
120                                                 break;
121                                         case ':':
122                                                 image = get_resources()->medium_7segment[10];
123                                                 break;
124                                         case '.':
125                                                 image = get_resources()->medium_7segment[11];
126                                                 break;
127                                         case 'a':
128                                         case 'A':
129                                                 image = get_resources()->medium_7segment[12];
130                                                 break;
131                                         case 'b':
132                                         case 'B':
133                                                 image = get_resources()->medium_7segment[13];
134                                                 break;
135                                         case 'c':
136                                         case 'C':
137                                                 image = get_resources()->medium_7segment[14];
138                                                 break;
139                                         case 'd':
140                                         case 'D':
141                                                 image = get_resources()->medium_7segment[15];
142                                                 break;
143                                         case 'e':
144                                         case 'E':
145                                                 image = get_resources()->medium_7segment[16];
146                                                 break;
147                                         case 'f':
148                                         case 'F':
149                                                 image = get_resources()->medium_7segment[17];
150                                                 break;
151                                         case ' ':
152                                                 image = get_resources()->medium_7segment[18];
153                                                 break;
154                                         case '-':
155                                                 image = get_resources()->medium_7segment[19];
156                                                 break;
157                                         default:
158                                                 image = get_resources()->medium_7segment[18];
159                                                 break;
160                                 }
162                                 draw_vframe(image, 
163                                         x, 
164                                         y - image->get_h());
165                                 x += image->get_w();
166                         }
167                         break;
169                 default:
170                 {
171                         int color = get_color();
172                         if(boldface) set_color(BLACK);
174                         for(int k = (boldface ? 1 : 0); k >= 0; k--)
175                         {
176                                 for(int i = 0, j = 0, x2 = x, y2 = y; 
177                                         i <= length; 
178                                         i++)
179                                 {
180                                         if(text[i] == '\n' || text[i] == 0)
181                                         {
182                                                 if(get_resources()->use_fontset && top_level->get_curr_fontset())
183                                                 XmbDrawString(top_level->display, 
184                                                 pixmap ? pixmap->opaque_pixmap : this->pixmap, 
185                                                 top_level->get_curr_fontset(),
186                                                 top_level->gc, 
187                                                 x2 + k, 
188                                                 y2 + k, 
189                                                 &text[j], 
190                                                 i - j);
191                                                 else
192                                                         XDrawString(top_level->display, 
193                                                                 pixmap ? pixmap->opaque_pixmap : this->pixmap, 
194                                                                 top_level->gc, 
195                                                                 x2 + k, 
196                                                                 y2 + k, 
197                                                                 &text[j], 
198                                                                 i - j);
199                                                 j = i + 1;
200                                                 y2 += get_text_height(MEDIUMFONT);
201                                         }
202                                 }
203                                 if(boldface) set_color(color);
204                         }
205                         break;
206                 }
207         }
210 void BC_WindowBase::draw_center_text(int x, int y, char *text, int length)
212         if(length < 0) length = strlen(text);
213         int w = get_text_width(current_font, text, length);
214         x -= w / 2;
215         draw_text(x, y, text, length);
218 void BC_WindowBase::draw_line(int x1, int y1, int x2, int y2, BC_Pixmap *pixmap)
220         XDrawLine(top_level->display, 
221                 pixmap ? pixmap->opaque_pixmap : this->pixmap, 
222                 top_level->gc, 
223                 x1, 
224                 y1, 
225                 x2, 
226                 y2);
229 void BC_WindowBase::draw_polygon(ArrayList<int> *x, ArrayList<int> *y, BC_Pixmap *pixmap)
231         int npoints = MIN(x->total, y->total);
232         XPoint *points = new XPoint[npoints];
234         for(int i = 0; i < npoints; i++)
235         {
236                 points[i].x = x->values[i];
237                 points[i].y = y->values[i];
238         }
240         XDrawLines(top_level->display,
241         pixmap ? pixmap->opaque_pixmap : this->pixmap,
242         top_level->gc,
243         points,
244         npoints,
245         CoordModeOrigin);
247         delete [] points;
251 void BC_WindowBase::draw_rectangle(int x, int y, int w, int h)
253         XDrawRectangle(top_level->display, 
254                 pixmap, 
255                 top_level->gc, 
256                 x, 
257                 y, 
258                 w - 1, 
259                 h - 1);
262 void BC_WindowBase::draw_3d_border(int x, int y, int w, int h, 
263         int light1, int light2, int shadow1, int shadow2)
265         int lx, ly, ux, uy;
267         h--; w--;
269         lx = x+1;  ly = y+1;
270         ux = x+w-1;  uy = y+h-1;
272         set_color(light1);
273         draw_line(x, y, ux, y);
274         draw_line(x, y, x, uy);
275         set_color(light2);
276         draw_line(lx, ly, ux - 1, ly);
277         draw_line(lx, ly, lx, uy - 1);
279         set_color(shadow1);
280         draw_line(ux, ly, ux, uy);
281         draw_line(lx, uy, ux, uy);
282         set_color(shadow2);
283         draw_line(x + w, y, x + w, y + h);
284         draw_line(x, y + h, x + w, y + h);
287 void BC_WindowBase::draw_3d_box(int x, 
288         int y, 
289         int w, 
290         int h, 
291         int light1, 
292         int light2, 
293         int middle, 
294         int shadow1, 
295         int shadow2,
296         BC_Pixmap *pixmap)
298         int lx, ly, ux, uy;
300         h--; w--;
302         lx = x+1;  ly = y+1;
303         ux = x+w-1;  uy = y+h-1;
305         set_color(middle);
306         draw_box(x, y, w, h, pixmap);
308         set_color(light1);
309         draw_line(x, y, ux, y, pixmap);
310         draw_line(x, y, x, uy, pixmap);
311         set_color(light2);
312         draw_line(lx, ly, ux - 1, ly, pixmap);
313         draw_line(lx, ly, lx, uy - 1, pixmap);
315         set_color(shadow1);
316         draw_line(ux, ly, ux, uy, pixmap);
317         draw_line(lx, uy, ux, uy, pixmap);
318         set_color(shadow2);
319         draw_line(x + w, y, x + w, y + h, pixmap);
320         draw_line(x, y + h, x + w, y + h, pixmap);
323 void BC_WindowBase::draw_colored_box(int x, int y, int w, int h, int down, int highlighted)
325         if(!down)
326         {
327                 if(highlighted)
328                         draw_3d_box(x, y, w, h, 
329                                 top_level->get_resources()->button_light, 
330                                 top_level->get_resources()->button_highlighted, 
331                                 top_level->get_resources()->button_highlighted, 
332                                 top_level->get_resources()->button_shadow,
333                                 BLACK);
334                 else
335                         draw_3d_box(x, y, w, h, 
336                                 top_level->get_resources()->button_light, 
337                                 top_level->get_resources()->button_up, 
338                                 top_level->get_resources()->button_up, 
339                                 top_level->get_resources()->button_shadow,
340                                 BLACK);
341         }
342         else
343         {
344 // need highlighting for toggles
345                 if(highlighted)
346                         draw_3d_box(x, y, w, h, 
347                                 top_level->get_resources()->button_shadow, 
348                                 BLACK, 
349                                 top_level->get_resources()->button_up, 
350                                 top_level->get_resources()->button_up,
351                                 top_level->get_resources()->button_light);
352                 else
353                         draw_3d_box(x, y, w, h, 
354                                 top_level->get_resources()->button_shadow, 
355                                 BLACK, 
356                                 top_level->get_resources()->button_down, 
357                                 top_level->get_resources()->button_down,
358                                 top_level->get_resources()->button_light);
359         }
362 void BC_WindowBase::draw_border(char *text, int x, int y, int w, int h)
364         int left_indent = 20;
365         int lx, ly, ux, uy;
367         h--; w--;
368         lx = x + 1;  ly = y + 1;
369         ux = x + w - 1;  uy = y + h - 1;
371         set_opaque();
372         if(text && text[0] != 0)
373         {
374                 set_color(BLACK);
375                 set_font(MEDIUMFONT);
376                 draw_text(x + left_indent, y + get_text_height(MEDIUMFONT) / 2, text);
377         }
378         
379         set_color(top_level->get_resources()->button_shadow);
380         draw_line(x, y, x + left_indent - 5, y);
381         draw_line(x, y, x, uy);
382         draw_line(x + left_indent + 5 + get_text_width(MEDIUMFONT, text), y, ux, y);
383         draw_line(x, y, x, uy);
384         draw_line(ux, ly, ux, uy);
385         draw_line(lx, uy, ux, uy);
386         set_color(top_level->get_resources()->button_light);
387         draw_line(lx, ly, x + left_indent - 5 - 1, ly);
388         draw_line(lx, ly, lx, uy - 1);
389         draw_line(x + left_indent + 5 + get_text_width(MEDIUMFONT, text), ly, ux - 1, ly);
390         draw_line(lx, ly, lx, uy - 1);
391         draw_line(x + w, y, x + w, y + h);
392         draw_line(x, y + h, x + w, y + h);
395 void BC_WindowBase::draw_triangle_down_flat(int x, int y, int w, int h)
397         int x1, y1, x2, y2, x3, y3;
398         XPoint point[3];
400         x1 = x; x2 = x + w / 2; x3 = x + w - 1;
401         y1 = y; y2 = y + h - 1;
403         point[0].x = x2; point[0].y = y2; point[1].x = x3;
404         point[1].y = y1; point[2].x = x1; point[2].y = y1;
406         XFillPolygon(top_level->display, pixmap, top_level->gc, (XPoint *)point, 3, Nonconvex, CoordModeOrigin);
409 void BC_WindowBase::draw_triangle_up(int x, int y, int w, int h, 
410         int light1, int light2, int middle, int shadow1, int shadow2)
412         int x1, y1, x2, y2, x3, y3;
413         XPoint point[3];
415         x1 = x; y1 = y; x2 = x + w / 2;
416         y2 = y + h - 1; x3 = x + w - 1;
418 // middle
419         point[0].x = x2; point[0].y = y1; point[1].x = x3;
420         point[1].y = y2; point[2].x = x1; point[2].y = y2;
422         set_color(middle);
423         XFillPolygon(top_level->display, pixmap, top_level->gc, (XPoint *)point, 3, Nonconvex, CoordModeOrigin);
425 // bottom and top right
426         set_color(shadow1);
427         draw_line(x3, y2-1, x1, y2-1);
428         draw_line(x2-1, y1, x3-1, y2);
429         set_color(shadow2);
430         draw_line(x3, y2, x1, y2);
431         draw_line(x2, y1, x3, y2);
433 // top left
434         set_color(light2);
435         draw_line(x2+1, y1, x1+1, y2);
436         set_color(light1);
437         draw_line(x2, y1, x1, y2);
440 void BC_WindowBase::draw_triangle_down(int x, int y, int w, int h, 
441         int light1, int light2, int middle, int shadow1, int shadow2)
443         int x1, y1, x2, y2, x3, y3;
444         XPoint point[3];
446         x1 = x; x2 = x + w / 2; x3 = x + w - 1;
447         y1 = y; y2 = y + h - 1;
449         point[0].x = x2; point[0].y = y2; point[1].x = x3;
450         point[1].y = y1; point[2].x = x1; point[2].y = y1;
452         set_color(middle);
453         XFillPolygon(top_level->display, pixmap, top_level->gc, (XPoint *)point, 3, Nonconvex, CoordModeOrigin);
455 // top and bottom left
456         set_color(light2);
457         draw_line(x3-1, y1+1, x1+1, y1+1);
458         draw_line(x1+1, y1, x2+1, y2);
459         set_color(light1);
460         draw_line(x3, y1, x1, y1);
461         draw_line(x1, y1, x2, y2);
463 // bottom right
464         set_color(shadow1);
465         draw_line(x3-1, y1, x2-1, y2);
466         set_color(shadow2);
467         draw_line(x3, y1, x2, y2);
470 void BC_WindowBase::draw_triangle_left(int x, int y, int w, int h, 
471         int light1, int light2, int middle, int shadow1, int shadow2)
473         int x1, y1, x2, y2, x3, y3;
474         XPoint point[3];
476         // draw back arrow
477         y1 = y; x1 = x; y2 = y + h / 2;
478         x2 = x + w - 1; y3 = y + h - 1;
480         point[0].x = x1; point[0].y = y2; point[1].x = x2; 
481         point[1].y = y1; point[2].x = x2; point[2].y = y3;
483         set_color(middle);
484         XFillPolygon(top_level->display, pixmap, top_level->gc, (XPoint *)point, 3, Nonconvex, CoordModeOrigin);
486 // right and bottom right
487         set_color(shadow1);
488         draw_line(x2-1, y1, x2-1, y3-1);
489         draw_line(x2, y3-1, x1, y2-1);
490         set_color(shadow2);
491         draw_line(x2, y1, x2, y3);
492         draw_line(x2, y3, x1, y2);
494 // top left
495         set_color(light1);
496         draw_line(x1, y2, x2, y1);
497         set_color(light2);
498         draw_line(x1, y2+1, x2, y1+1);
501 void BC_WindowBase::draw_triangle_right(int x, int y, int w, int h, 
502         int light1, int light2, int middle, int shadow1, int shadow2)
504         int x1, y1, x2, y2, x3, y3;
505         XPoint point[3];
507         y1 = y; y2 = y + h / 2; y3 = y + h - 1; 
508         x1 = x; x2 = x + w - 1;
510         point[0].x = x1; point[0].y = y1; point[1].x = x2; 
511         point[1].y = y2; point[2].x = x1; point[2].y = y3;
513         set_color(middle);
514         XFillPolygon(top_level->display, pixmap, top_level->gc, (XPoint *)point, 3, Nonconvex, CoordModeOrigin);
516 // left and top right
517         set_color(light2);
518         draw_line(x1+1, y3, x1+1, y1);
519         draw_line(x1, y1+1, x2, y2+1);
520         set_color(light1);
521         draw_line(x1, y3, x1, y1);
522         draw_line(x1, y1, x2, y2);
524 // bottom right
525         set_color(shadow1);
526         draw_line(x2, y2-1, x1, y3-1);
527         set_color(shadow2);
528         draw_line(x2, y2, x1, y3);
532 void BC_WindowBase::draw_check(int x, int y)
534         const int w = 15, h = 15;
535         draw_line(x + 3, y + h / 2 + 0, x + 6, y + h / 2 + 2);
536         draw_line(x + 3, y + h / 2 + 1, x + 6, y + h / 2 + 3);
537         draw_line(x + 6, y + h / 2 + 2, x + w - 4, y + h / 2 - 3);
538         draw_line(x + 3, y + h / 2 + 2, x + 6, y + h / 2 + 4);
539         draw_line(x + 6, y + h / 2 + 2, x + w - 4, y + h / 2 - 3);
540         draw_line(x + 6, y + h / 2 + 3, x + w - 4, y + h / 2 - 2);
541         draw_line(x + 6, y + h / 2 + 4, x + w - 4, y + h / 2 - 1);
544 void BC_WindowBase::draw_tiles(BC_Pixmap *tile, int origin_x, int origin_y, int x, int y, int w, int h)
546         if(!tile)
547         {
548                 set_color(bg_color);
549                 draw_box(x, y, w, h);
550         }
551         else
552         {
553                 XSetFillStyle(top_level->display, top_level->gc, FillTiled);
554 // Don't know how slow this is
555                 XSetTile(top_level->display, top_level->gc, tile->get_pixmap());
556                 XSetTSOrigin(top_level->display, top_level->gc, origin_x, origin_y);
557                 draw_box(x, y, w, h);
558                 XSetFillStyle(top_level->display, top_level->gc, FillSolid);
559         }
562 void BC_WindowBase::draw_top_tiles(BC_WindowBase *parent_window, int x, int y, int w, int h)
564         Window tempwin;
565         int origin_x, origin_y;
566         XTranslateCoordinates(top_level->display, 
567                         parent_window->win, 
568                         win, 
569                         0, 
570                         0, 
571                         &origin_x, 
572                         &origin_y, 
573                         &tempwin);
575         draw_tiles(parent_window->bg_pixmap, 
576                 origin_x,
577                 origin_y,
578                 x,
579                 y,
580                 w,
581                 h);
584 void BC_WindowBase::draw_top_background(BC_WindowBase *parent_window, 
585         int x, 
586         int y, 
587         int w, 
588         int h, 
589         BC_Pixmap *pixmap)
591         Window tempwin;
592         int top_x, top_y;
594         XTranslateCoordinates(top_level->display, 
595                         win, 
596                         parent_window->win, 
597                         x, 
598                         y, 
599                         &top_x, 
600                         &top_y, 
601                         &tempwin);
603         XCopyArea(top_level->display, 
604                 parent_window->pixmap, 
605                 pixmap ? pixmap->opaque_pixmap : this->pixmap, 
606                 top_level->gc, 
607                 top_x, 
608                 top_y, 
609                 w, 
610                 h, 
611                 x, 
612                 y);
615 void BC_WindowBase::draw_background(int x, int y, int w, int h)
617         if(bg_pixmap)
618         {
619                 draw_tiles(bg_pixmap, 0, 0, x, y, w, h);
620         }
621         else
622         {
623                 clear_box(x, y, w, h);
624         }
627 void BC_WindowBase::draw_bitmap(BC_Bitmap *bitmap, 
628         int dont_wait,
629         int dest_x, 
630         int dest_y,
631         int dest_w,
632         int dest_h,
633         int src_x,
634         int src_y,
635         int src_w,
636         int src_h,
637         BC_Pixmap *pixmap)
639 //printf("BC_WindowBase::draw_bitmap 1\n");
640         if(dest_w <= 0 || dest_h <= 0)
641         {
642 // Use hardware scaling to canvas dimensions if proper color model.
643                 if(bitmap->get_color_model() == BC_YUV420P)
644                 {
645                         dest_w = w;
646                         dest_h = h;
647                 }
648                 else
649                 {
650                         dest_w = bitmap->get_w();
651                         dest_h = bitmap->get_h();
652                 }
653         }
655         if(src_w <= 0 || src_h <= 0)
656         {
657                 src_w = bitmap->get_w();
658                 src_h = bitmap->get_h();
659         }
661         if(video_on)
662         {
663                 bitmap->write_drawable(win, 
664                         top_level->gc, 
665                         src_x, 
666                         src_y, 
667                         src_w,
668                         src_h,
669                         dest_x, 
670                         dest_y, 
671                         dest_w, 
672                         dest_h, 
673                         dont_wait);
674                 top_level->flush();
675         }
676         else
677         {
678                 bitmap->write_drawable(pixmap ? pixmap->opaque_pixmap : this->pixmap, 
679                         top_level->gc, 
680                         dest_x, 
681                         dest_y, 
682                         src_x, 
683                         src_y, 
684                         dest_w, 
685                         dest_h, 
686                         dont_wait);
687         }
688 //printf("BC_WindowBase::draw_bitmap 2\n");
692 void BC_WindowBase::draw_pixel(int x, int y, BC_Pixmap *pixmap)
694         XDrawPoint(top_level->display, 
695                 pixmap ? pixmap->opaque_pixmap : this->pixmap, 
696                 top_level->gc, 
697                 x, 
698                 y);
702 void BC_WindowBase::draw_pixmap(BC_Pixmap *pixmap, 
703         int dest_x, 
704         int dest_y,
705         int dest_w,
706         int dest_h,
707         int src_x,
708         int src_y,
709         BC_Pixmap *dst)
711         pixmap->write_drawable(dst ? dst->opaque_pixmap : this->pixmap,
712                         dest_x, 
713                         dest_y,
714                         dest_w,
715                         dest_h,
716                         src_x,
717                         src_y);
720 void BC_WindowBase::draw_vframe(VFrame *frame, 
721                 int dest_x, 
722                 int dest_y, 
723                 int dest_w, 
724                 int dest_h,
725                 int src_x,
726                 int src_y,
727                 int src_w,
728                 int src_h,
729                 BC_Pixmap *pixmap)
731         if(dest_w <= 0) dest_w = frame->get_w() - src_x;
732         if(dest_h <= 0) dest_h = frame->get_h() - src_y;
733         if(src_w <= 0) src_w = frame->get_w() - src_x;
734         if(src_h <= 0) src_h = frame->get_h() - src_y;
735         CLAMP(src_x, 0, frame->get_w() - 1);
736         CLAMP(src_y, 0, frame->get_h() - 1);
737         if(src_x + src_w > frame->get_w()) src_w = frame->get_w() - src_x;
738         if(src_y + src_h > frame->get_h()) src_h = frame->get_h() - src_y;
740         if(!temp_bitmap) temp_bitmap = new BC_Bitmap(top_level, 
741                 dest_w, 
742                 dest_h, 
743                 get_color_model(), 
744                 1);
746         temp_bitmap->match_params(dest_w, 
747                 dest_h, 
748                 get_color_model(), 
749                 1);
751         temp_bitmap->read_frame(frame, 
752                 src_x, 
753                 src_y, 
754                 src_w, 
755                 src_h,
756                 0, 
757                 0, 
758                 dest_w, 
759                 dest_h);
761         draw_bitmap(temp_bitmap, 
762                 0, 
763                 dest_x, 
764                 dest_y,
765                 dest_w,
766                 dest_h,
767                 0,
768                 0,
769                 -1,
770                 -1,
771                 pixmap);
774 void BC_WindowBase::draw_tooltip()
776         if(tooltip_popup)
777         {
778                 int w = tooltip_popup->get_w(), h = tooltip_popup->get_h();
779                 tooltip_popup->set_color(get_resources()->tooltip_bg_color);
780                 tooltip_popup->draw_box(0, 0, w, h);
781                 tooltip_popup->set_color(BLACK);
782                 tooltip_popup->draw_rectangle(0, 0, w, h);
783                 tooltip_popup->set_font(MEDIUMFONT);
784                 tooltip_popup->draw_text(TOOLTIP_MARGIN, 
785                         get_text_ascent(MEDIUMFONT) + TOOLTIP_MARGIN, 
786                         tooltip_text);
787         }
790 void BC_WindowBase::slide_left(int distance)
792         if(distance < w)
793         {
794                 XCopyArea(top_level->display, pixmap, pixmap, top_level->gc, distance, 0, w - distance, h, 0, 0);
795         }
798 void BC_WindowBase::slide_right(int distance)
800         if(distance < w)
801         {
802                 XCopyArea(top_level->display, pixmap, pixmap, top_level->gc, 0, 0, w - distance, h, distance, 0);
803         }
806 void BC_WindowBase::slide_up(int distance)
808         if(distance < h)
809         {
810                 XCopyArea(top_level->display, pixmap, pixmap, top_level->gc, 0, distance, w, h - distance, 0, 0);
811                 set_color(bg_color);
812                 XFillRectangle(top_level->display, pixmap, top_level->gc, 0, h - distance, w, distance);
813         }
816 void BC_WindowBase::slide_down(int distance)
818         if(distance < h)
819         {
820                 XCopyArea(top_level->display, pixmap, pixmap, top_level->gc, 0, 0, w, h - distance, 0, distance);
821                 set_color(bg_color);
822                 XFillRectangle(top_level->display, pixmap, top_level->gc, 0, 0, w, distance);
823         }
826 // 3 segments in separate pixmaps.  Obsolete.
827 void BC_WindowBase::draw_3segment(int x, 
828         int y, 
829         int w, 
830         int h, 
831         BC_Pixmap *left_image,
832         BC_Pixmap *mid_image,
833         BC_Pixmap *right_image,
834         BC_Pixmap *pixmap)
836         if(w <= 0 || h <= 0) return;
837         int left_boundary = left_image->get_w_fixed();
838         int right_boundary = w - right_image->get_w_fixed();
839         for(int i = 0; i < w; )
840         {
841                 BC_Pixmap *image;
843                 if(i < left_boundary)
844                         image = left_image;
845                 else
846                 if(i < right_boundary)
847                         image = mid_image;
848                 else
849                         image = right_image;
851                 int output_w = image->get_w_fixed();
853                 if(i < left_boundary)
854                 {
855                         if(i + output_w > left_boundary) output_w = left_boundary - i;
856                 }
857                 else
858                 if(i < right_boundary)
859                 {
860                         if(i + output_w > right_boundary) output_w = right_boundary - i;
861                 }
862                 else
863                         if(i + output_w > w) output_w = w - i;
865                 image->write_drawable(pixmap ? pixmap->opaque_pixmap : this->pixmap, 
866                                 x + i, 
867                                 y,
868                                 output_w,
869                                 h,
870                                 0,
871                                 0);
873                 i += output_w;
874         }
876 // 3 segments in separate vframes.  Obsolete.
877 void BC_WindowBase::draw_3segment(int x, 
878         int y, 
879         int w, 
880         int h, 
881         VFrame *left_image,
882         VFrame *mid_image,
883         VFrame *right_image,
884         BC_Pixmap *pixmap)
886         if(w <= 0 || h <= 0) return;
887         int left_boundary = left_image->get_w_fixed();
888         int right_boundary = w - right_image->get_w_fixed();
891         for(int i = 0; i < w; )
892         {
893                 VFrame *image;
895                 if(i < left_boundary)
896                         image = left_image;
897                 else
898                 if(i < right_boundary)
899                         image = mid_image;
900                 else
901                         image = right_image;
902                 
903                 int output_w = image->get_w_fixed();
905                 if(i < left_boundary)
906                 {
907                         if(i + output_w > left_boundary) output_w = left_boundary - i;
908                 }
909                 else
910                 if(i < right_boundary)
911                 {
912                         if(i + output_w > right_boundary) output_w = right_boundary - i;
913                 }
914                 else
915                         if(i + output_w > w) output_w = w - i;
917                 if(image)
918                         draw_vframe(image, 
919                                         x + i, 
920                                         y,
921                                         output_w,
922                                         h,
923                                         0,
924                                         0,
925                                         0,
926                                         0,
927                                         pixmap);
929                 if(output_w == 0) break;
930                 i += output_w;
931         }
934 // Draw all 3 segments in a single vframe for a changing level
936 // total_x 
937 // <------>
938 // total_w
939 //         <------------------------------------------------------------>
940 // x
941 // |
942 // w           
943 // <-------------------------------------------------------------------->
944 // output
945 //         |-------------------|----------------------|------------------|
948 void BC_WindowBase::draw_3segmenth(int x, 
949                 int y, 
950                 int w, 
951                 VFrame *image,
952                 BC_Pixmap *pixmap)
954         draw_3segmenth(x, 
955                 y, 
956                 w, 
957                 x,
958                 w,
959                 image,
960                 pixmap);
963 void BC_WindowBase::draw_3segmenth(long x, 
964                 long y, 
965                 long w, 
966                 long total_x,
967                 long total_w,
968                 VFrame *image,
969                 BC_Pixmap *pixmap)
971         if(total_w <= 0 || w <= 0 || h <= 0) return;
972         long third_image = image->get_w() / 3;
973         long half_image = image->get_w() / 2;
974         long left_boundary = third_image;
975         long right_boundary = total_w - third_image;
976         long left_in_x = 0;
977         long left_in_w = third_image;
978         long left_out_x = total_x;
979         long left_out_w = third_image;
980         long right_in_x = image->get_w() - third_image;
981         long right_in_w = third_image;
982         long right_out_x = total_x + total_w - third_image;
983         long right_out_w = third_image;
984         long center_out_x = total_x + third_image;
985         long center_out_w = total_w - third_image * 2;
986         long image_x, image_w;
988 //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", 
989 //      left_out_x, left_out_w, center_out_x, center_out_w, right_out_x, right_out_w);
991         if(left_out_x < x)
992         {
993                 left_in_w -= x - left_out_x;
994                 left_out_w -= x - left_out_x;
995                 left_in_x += x - left_out_x;
996                 left_out_x += x - left_out_x;
997         }
999         if(left_out_x + left_out_w > x + w)
1000         {
1001                 left_in_w -= (left_out_x + left_out_w) - (x + w);
1002                 left_out_w -= (left_out_x + left_out_w) - (x + w);
1003         }
1005         if(right_out_x < x)
1006         {
1007                 right_in_w -= x - right_out_x;
1008                 right_out_w -= x - right_out_x;
1009                 right_in_x += x - right_out_x;
1010                 right_out_x += x - right_out_x;
1011         }
1013         if(right_out_x + right_out_w > x + w)
1014         {
1015                 right_in_w -= (right_out_x + right_out_w) - (x + w);
1016                 right_out_w -= (right_out_x + right_out_w) - (x + w);
1017         }
1019         if(center_out_x < x)
1020         {
1021                 center_out_w -= x - center_out_x;
1022                 center_out_x += x - center_out_x;
1023         }
1025         if(center_out_x + center_out_w > x + w)
1026         {
1027                 center_out_w -= (center_out_x + center_out_w) - (x + w);
1028         }
1030         if(!temp_bitmap) temp_bitmap = new BC_Bitmap(top_level, 
1031                 image->get_w(), 
1032                 image->get_h(), 
1033                 get_color_model(), 
1034                 0);
1035         temp_bitmap->match_params(image->get_w(), 
1036                 image->get_h(), 
1037                 get_color_model(), 
1038                 0);
1039         temp_bitmap->read_frame(image, 
1040                 0, 
1041                 0, 
1042                 image->get_w(), 
1043                 image->get_h());
1046 //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", 
1047 //      left_out_x, left_out_w, center_out_x, center_out_w, right_out_x, right_out_w);
1048         if(left_out_w > 0)
1049         {
1050                 draw_bitmap(temp_bitmap, 
1051                         0, 
1052                         left_out_x, 
1053                         y,
1054                         left_out_w,
1055                         image->get_h(),
1056                         left_in_x,
1057                         0,
1058                         -1,   // src width and height are meaningless in video_off mode
1059                         -1,
1060                         pixmap);
1061         }
1063         if(right_out_w > 0)
1064         {
1065                 draw_bitmap(temp_bitmap, 
1066                         0, 
1067                         right_out_x, 
1068                         y,
1069                         right_out_w,
1070                         image->get_h(),
1071                         right_in_x,
1072                         0,
1073                         -1,   // src width and height are meaningless in video_off mode
1074                         -1,
1075                         pixmap);
1076         }
1078         for(int pixel = center_out_x; 
1079                 pixel < center_out_x + center_out_w; 
1080                 pixel += half_image)
1081         {
1082                 int fragment_w = half_image;
1083                 if(fragment_w + pixel > center_out_x + center_out_w)
1084                         fragment_w = (center_out_x + center_out_w) - pixel;
1086 //printf("BC_WindowBase::draw_3segment 2 pixel=%d fragment_w=%d\n", pixel, fragment_w);
1087                 draw_bitmap(temp_bitmap, 
1088                         0, 
1089                         pixel, 
1090                         y,
1091                         fragment_w,
1092                         image->get_h(),
1093                         third_image,
1094                         0,
1095                         -1,   // src width and height are meaningless in video_off mode
1096                         -1,
1097                         pixmap);
1098         }
1108 void BC_WindowBase::draw_3segmenth(long x, 
1109                 long y, 
1110                 long w, 
1111                 long total_x,
1112                 long total_w,
1113                 BC_Pixmap *src,
1114                 BC_Pixmap *dst)
1116         if(w <= 0 || total_w <= 0) return;
1117         if(!src) printf("BC_WindowBase::draw_3segmenth src=0\n");
1118         long quarter_src = src->get_w() / 4;
1119         long half_src = src->get_w() / 2;
1120         long left_boundary = quarter_src;
1121         long right_boundary = total_w - quarter_src;
1122         long left_in_x = 0;
1123         long left_in_w = quarter_src;
1124         long left_out_x = total_x;
1125         long left_out_w = quarter_src;
1126         long right_in_x = src->get_w() - quarter_src;
1127         long right_in_w = quarter_src;
1128         long right_out_x = total_x + total_w - quarter_src;
1129         long right_out_w = quarter_src;
1130         long center_out_x = total_x + quarter_src;
1131         long center_out_w = total_w - quarter_src * 2;
1132         long src_x, src_w;
1134 //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", 
1135 //      left_out_x, left_out_w, center_out_x, center_out_w, right_out_x, right_out_w);
1137         if(left_out_x < x)
1138         {
1139                 left_in_w -= x - left_out_x;
1140                 left_out_w -= x - left_out_x;
1141                 left_in_x += x - left_out_x;
1142                 left_out_x += x - left_out_x;
1143         }
1145         if(left_out_x + left_out_w > x + w)
1146         {
1147                 left_in_w -= (left_out_x + left_out_w) - (x + w);
1148                 left_out_w -= (left_out_x + left_out_w) - (x + w);
1149         }
1151         if(right_out_x < x)
1152         {
1153                 right_in_w -= x - right_out_x;
1154                 right_out_w -= x - right_out_x;
1155                 right_in_x += x - right_out_x;
1156                 right_out_x += x - right_out_x;
1157         }
1159         if(right_out_x + right_out_w > x + w)
1160         {
1161                 right_in_w -= (right_out_x + right_out_w) - (x + w);
1162                 right_out_w -= (right_out_x + right_out_w) - (x + w);
1163         }
1165         if(center_out_x < x)
1166         {
1167                 center_out_w -= x - center_out_x;
1168                 center_out_x += x - center_out_x;
1169         }
1171         if(center_out_x + center_out_w > x + w)
1172         {
1173                 center_out_w -= (center_out_x + center_out_w) - (x + w);
1174         }
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         {
1181                 draw_pixmap(src, 
1182                         left_out_x, 
1183                         y,
1184                         left_out_w,
1185                         src->get_h(),
1186                         left_in_x,
1187                         0,
1188                         dst);
1189         }
1191         if(right_out_w > 0)
1192         {
1193                 draw_pixmap(src, 
1194                         right_out_x, 
1195                         y,
1196                         right_out_w,
1197                         src->get_h(),
1198                         right_in_x,
1199                         0,
1200                         dst);
1201         }
1203         for(int pixel = center_out_x; 
1204                 pixel < center_out_x + center_out_w; 
1205                 pixel += half_src)
1206         {
1207                 int fragment_w = half_src;
1208                 if(fragment_w + pixel > center_out_x + center_out_w)
1209                         fragment_w = (center_out_x + center_out_w) - pixel;
1211 //printf("BC_WindowBase::draw_3segment 2 pixel=%d fragment_w=%d\n", pixel, fragment_w);
1212                 draw_pixmap(src, 
1213                         pixel, 
1214                         y,
1215                         fragment_w,
1216                         src->get_h(),
1217                         quarter_src,
1218                         0,
1219                         dst);
1220         }
1225 void BC_WindowBase::draw_3segmenth(long x, 
1226                 long y, 
1227                 long w,
1228                 BC_Pixmap *src,
1229                 BC_Pixmap *dst)
1231         if(w <= 0) return;
1232         long third_image = src->get_w() / 3;
1233         long half_output = w / 2;
1234         long left_boundary = third_image;
1235         long right_boundary = w - third_image;
1236         long left_in_x = 0;
1237         long left_in_w = third_image;
1238         long left_out_x = x;
1239         long left_out_w = third_image;
1240         long right_in_x = src->get_w() - third_image;
1241         long right_in_w = third_image;
1242         long right_out_x = x + w - third_image;
1243         long right_out_w = third_image;
1244         long image_x, image_w;
1246 //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", 
1247 //      left_out_x, left_out_w, center_out_x, center_out_w, right_out_x, right_out_w);
1249         if(left_out_w > half_output)
1250         {
1251                 left_in_w -= left_out_w - half_output;
1252                 left_out_w -= left_out_w - half_output;
1253         }
1255         if(right_out_x < x + half_output)
1256         {
1257                 right_in_w -= x + half_output - right_out_x;
1258                 right_out_w -= x + half_output - right_out_x;
1259                 right_in_x += x + half_output - right_out_x;
1260                 right_out_x += x + half_output - right_out_x;
1261         }
1263 //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", 
1264 //      left_out_x, left_out_w, center_out_x, center_out_w, right_out_x, right_out_w);
1265         if(left_out_w > 0)
1266         {
1267                 draw_pixmap(src, 
1268                         left_out_x, 
1269                         y,
1270                         left_out_w,
1271                         src->get_h(),
1272                         left_in_x,
1273                         0,
1274                         dst);
1275         }
1277         if(right_out_w > 0)
1278         {
1279                 draw_pixmap(src, 
1280                         right_out_x, 
1281                         y,
1282                         right_out_w,
1283                         src->get_h(),
1284                         right_in_x,
1285                         0,
1286                         dst);
1287         }
1289         for(int pixel = left_out_x + left_out_w; 
1290                 pixel < right_out_x; 
1291                 pixel += third_image)
1292         {
1293                 int fragment_w = third_image;
1294                 if(fragment_w + pixel > right_out_x)
1295                         fragment_w = right_out_x - pixel;
1297 //printf("BC_WindowBase::draw_3segment 2 pixel=%d fragment_w=%d\n", pixel, fragment_w);
1298                 draw_pixmap(src, 
1299                         pixel, 
1300                         y,
1301                         fragment_w,
1302                         src->get_h(),
1303                         third_image,
1304                         0,
1305                         dst);
1306         }
1316 void BC_WindowBase::draw_3segmentv(long x, 
1317                 long y, 
1318                 long h,
1319                 VFrame *src,
1320                 BC_Pixmap *dst)
1322         if(h <= 0) return;
1323         long third_image = src->get_h() / 3;
1324         long half_output = h / 2;
1325         long left_boundary = third_image;
1326         long right_boundary = h - third_image;
1327         long left_in_y = 0;
1328         long left_in_h = third_image;
1329         long left_out_y = y;
1330         long left_out_h = third_image;
1331         long right_in_y = src->get_h() - third_image;
1332         long right_in_h = third_image;
1333         long right_out_y = y + h - third_image;
1334         long right_out_h = third_image;
1335         long image_y, image_h;
1338         if(left_out_h > half_output)
1339         {
1340                 left_in_h -= left_out_h - half_output;
1341                 left_out_h -= left_out_h - half_output;
1342         }
1344         if(right_out_y < y + half_output)
1345         {
1346                 right_in_h -= y + half_output - right_out_y;
1347                 right_out_h -= y + half_output - right_out_y;
1348                 right_in_y += y + half_output - right_out_y;
1349                 right_out_y += y + half_output - right_out_y;
1350         }
1353         if(!temp_bitmap) temp_bitmap = new BC_Bitmap(top_level, 
1354                 src->get_w(), 
1355                 src->get_h(), 
1356                 get_color_model(), 
1357                 0);
1358         temp_bitmap->match_params(src->get_w(), 
1359                 src->get_h(), 
1360                 get_color_model(), 
1361                 0);
1362         temp_bitmap->read_frame(src, 
1363                 0, 
1364                 0, 
1365                 src->get_w(), 
1366                 src->get_h());
1369         if(left_out_h > 0)
1370         {
1371                 draw_bitmap(temp_bitmap, 
1372                         0,
1373                         x,
1374                         left_out_y, 
1375                         src->get_w(),
1376                         left_out_h,
1377                         0,
1378                         left_in_y,
1379                         -1,
1380                         -1,
1381                         dst);
1382         }
1384         if(right_out_h > 0)
1385         {
1386                 draw_bitmap(temp_bitmap, 
1387                         0,
1388                         x,
1389                         right_out_y, 
1390                         src->get_w(),
1391                         right_out_h,
1392                         0,
1393                         right_in_y,
1394                         -1,
1395                         -1,
1396                         dst);
1397         }
1399         for(int pixel = left_out_y + left_out_h; 
1400                 pixel < right_out_y; 
1401                 pixel += third_image)
1402         {
1403                 int fragment_h = third_image;
1404                 if(fragment_h + pixel > right_out_y)
1405                         fragment_h = right_out_y - pixel;
1407 //printf("BC_WindowBase::draw_3segment 2 pixel=%d fragment_w=%d\n", pixel, fragment_w);
1408                 draw_bitmap(temp_bitmap, 
1409                         0,
1410                         x,
1411                         pixel, 
1412                         src->get_w(),
1413                         fragment_h,
1414                         0,
1415                         third_image,
1416                         -1,
1417                         -1,
1418                         dst);
1419         }
1422 void BC_WindowBase::draw_3segmentv(long x, 
1423                 long y, 
1424                 long h,
1425                 BC_Pixmap *src,
1426                 BC_Pixmap *dst)
1428         if(h <= 0) return;
1429         long third_image = src->get_h() / 3;
1430         long half_output = h / 2;
1431         long left_boundary = third_image;
1432         long right_boundary = h - third_image;
1433         long left_in_y = 0;
1434         long left_in_h = third_image;
1435         long left_out_y = y;
1436         long left_out_h = third_image;
1437         long right_in_y = src->get_h() - third_image;
1438         long right_in_h = third_image;
1439         long right_out_y = y + h - third_image;
1440         long right_out_h = third_image;
1441         long image_y, image_h;
1444         if(left_out_h > half_output)
1445         {
1446                 left_in_h -= left_out_h - half_output;
1447                 left_out_h -= left_out_h - half_output;
1448         }
1450         if(right_out_y < y + half_output)
1451         {
1452                 right_in_h -= y + half_output - right_out_y;
1453                 right_out_h -= y + half_output - right_out_y;
1454                 right_in_y += y + half_output - right_out_y;
1455                 right_out_y += y + half_output - right_out_y;
1456         }
1458         if(left_out_h > 0)
1459         {
1460                 draw_pixmap(src, 
1461                         x,
1462                         left_out_y, 
1463                         src->get_w(),
1464                         left_out_h,
1465                         0,
1466                         left_in_y,
1467                         dst);
1468         }
1470         if(right_out_h > 0)
1471         {
1472                 draw_pixmap(src, 
1473                         x,
1474                         right_out_y, 
1475                         src->get_w(),
1476                         right_out_h,
1477                         0,
1478                         right_in_y,
1479                         dst);
1480         }
1482         for(int pixel = left_out_y + left_out_h; 
1483                 pixel < right_out_y; 
1484                 pixel += third_image)
1485         {
1486                 int fragment_h = third_image;
1487                 if(fragment_h + pixel > right_out_y)
1488                         fragment_h = right_out_y - pixel;
1490 //printf("BC_WindowBase::draw_3segment 2 pixel=%d fragment_w=%d\n", pixel, fragment_w);
1491                 draw_pixmap(src, 
1492                         x,
1493                         pixel, 
1494                         src->get_w(),
1495                         fragment_h,
1496                         0,
1497                         third_image,
1498                         dst);
1499         }
1504 void BC_WindowBase::draw_9segment(long x, 
1505                 long y, 
1506                 long w,
1507                 long h,
1508                 VFrame *src,
1509                 BC_Pixmap *dst)
1511         if(w <= 0 || h <= 0) return;
1513         int in_x_third = src->get_w() / 3;
1514         int in_y_third = src->get_h() / 3;
1515         int out_x_half = w / 2;
1516         int out_y_half = h / 2;
1518         int in_x1 = 0;
1519         int in_y1 = 0;
1520         int out_x1 = 0;
1521         int out_y1 = 0;
1522         int in_x2 = MIN(in_x_third, out_x_half);
1523         int in_y2 = MIN(in_y_third, out_y_half);
1524         int out_x2 = in_x2;
1525         int out_y2 = in_y2;
1527         int out_x3 = MAX(w - out_x_half, w - in_x_third);
1528         int out_x4 = w;
1529         int in_x3 = src->get_w() - (out_x4 - out_x3);
1530         int in_x4 = src->get_w();
1532         int out_y3 = MAX(h - out_y_half, h - in_y_third);
1533         int out_y4 = h;
1534         int in_y3 = src->get_h() - (out_y4 - out_y3);
1535         int in_y4 = src->get_h();
1537 //printf("PFCFrame::draw_9segment 1 %d %d %d %d\n", out_x1, out_x2, out_x3, out_x4);
1538 //printf("PFCFrame::draw_9segment 2 %d %d %d %d\n", in_x1, in_x2, in_x3, in_x4);
1539 //printf("PFCFrame::draw_9segment 2 %d %d %d %d\n", in_y1, in_y2, in_y3, in_y4);
1541         if(!temp_bitmap) temp_bitmap = new BC_Bitmap(top_level, 
1542                 src->get_w(), 
1543                 src->get_h(), 
1544                 get_color_model(), 
1545                 0);
1546         temp_bitmap->match_params(src->get_w(), 
1547                 src->get_h(), 
1548                 get_color_model(), 
1549                 0);
1550         temp_bitmap->read_frame(src, 
1551                 0, 
1552                 0, 
1553                 src->get_w(), 
1554                 src->get_h());
1556 // Segment 1
1557         draw_bitmap(temp_bitmap,
1558                 0,
1559                 x + out_x1, 
1560                 y + out_y1,
1561                 out_x2 - out_x1,
1562                 out_y2 - out_y1,
1563                 in_x1, 
1564                 in_y1, 
1565                 in_x2 - in_x1,
1566                 in_y2 - in_y1, 
1567                 dst);
1570 // Segment 2 * n
1571         for(int i = out_x2; i < out_x3; i += in_x_third)
1572         {
1573                 if(out_x3 - i > 0)
1574                 {
1575                         int w = MIN(in_x_third, out_x3 - i);
1576                         draw_bitmap(temp_bitmap,
1577                                 0,
1578                                 x + i, 
1579                                 y + out_y1,
1580                                 w,
1581                                 out_y2 - out_y1,
1582                                 in_x2, 
1583                                 in_y1, 
1584                                 w,
1585                                 in_y2 - in_y1, 
1586                                 dst);
1587                 }
1588         }
1594 // Segment 3
1595         draw_bitmap(temp_bitmap,
1596                 0,
1597                 x + out_x3, 
1598                 y + out_y1,
1599                 out_x4 - out_x3,
1600                 out_y2 - out_y1,
1601                 in_x3, 
1602                 in_y1, 
1603                 in_x4 - in_x3,
1604                 in_y2 - in_y1, 
1605                 dst);
1609 // Segment 4 * n
1610         for(int i = out_y2; i < out_y3; i += in_y_third)
1611         {
1612                 if(out_y3 - i > 0)
1613                 {
1614                         int h = MIN(in_y_third, out_y3 - i);
1615                         draw_bitmap(temp_bitmap,
1616                                 0,
1617                                 x + out_x1, 
1618                                 y + i,
1619                                 out_x2 - out_x1,
1620                                 h,
1621                                 in_x1, 
1622                                 in_y2, 
1623                                 in_x2 - in_x1,
1624                                 h, 
1625                                 dst);
1626                 }
1627         }
1630 // Segment 5 * n * n
1631         for(int i = out_y2; i < out_y3; i += in_y_third)
1632         {
1633                 if(out_y3 - i > 0)
1634                 {
1635                         int h = MIN(in_y_third, out_y3 - i);
1638                         for(int j = out_x2; j < out_x3; j += in_x_third)
1639                         {
1640                                 int w = MIN(in_x_third, out_x3 - j);
1641                                 if(out_x3 - j > 0)
1642                                         draw_bitmap(temp_bitmap,
1643                                                 0,
1644                                                 x + j, 
1645                                                 y + i,
1646                                                 w,
1647                                                 h,
1648                                                 in_x2, 
1649                                                 in_y2, 
1650                                                 w,
1651                                                 h, 
1652                                                 dst);
1653                         }
1654                 }
1655         }
1657 // Segment 6 * n
1658         for(int i = out_y2; i < out_y3; i += in_y_third)
1659         {
1660                 if(out_y3 - i > 0)
1661                 {
1662                         int h = MIN(in_y_third, out_y3 - i);
1663                         draw_bitmap(temp_bitmap,
1664                                 0,
1665                                 x + out_x3, 
1666                                 y + i,
1667                                 out_x4 - out_x3,
1668                                 h,
1669                                 in_x3, 
1670                                 in_y2, 
1671                                 in_x4 - in_x3,
1672                                 h, 
1673                                 dst);
1674                 }
1675         }
1680 // Segment 7
1681         draw_bitmap(temp_bitmap,
1682                 0,
1683                 x + out_x1, 
1684                 y + out_y3,
1685                 out_x2 - out_x1,
1686                 out_y4 - out_y3,
1687                 in_x1, 
1688                 in_y3, 
1689                 in_x2 - in_x1,
1690                 in_y4 - in_y3, 
1691                 dst);
1694 // Segment 8 * n
1695         for(int i = out_x2; i < out_x3; i += in_x_third)
1696         {
1697                 if(out_x3 - i > 0)
1698                 {
1699                         int w = MIN(in_x_third, out_x3 - i);
1700                         draw_bitmap(temp_bitmap,
1701                                 0,
1702                                 x + i, 
1703                                 y + out_y3,
1704                                 w,
1705                                 out_y4 - out_y3,
1706                                 in_x2, 
1707                                 in_y3, 
1708                                 w,
1709                                 in_y4 - in_y3, 
1710                                 dst);
1711                 }
1712         }
1716 // Segment 9
1717         draw_bitmap(temp_bitmap,
1718                 0,
1719                 x + out_x3, 
1720                 y + out_y3,
1721                 out_x4 - out_x3,
1722                 out_y4 - out_y3,
1723                 in_x3, 
1724                 in_y3, 
1725                 in_x4 - in_x3,
1726                 in_y4 - in_y3, 
1727                 dst);