Merge branch 'ct' of git.pipapo.org:cinelerra-ct into ct
[cinelerra_cv/ct.git] / guicast / bcwindowdraw.C
blob5ab9e27b9c494b2aeb1d84c6d704998b59247492
1 #include "bcbitmap.h"
2 #include "bcpixmap.h"
3 #include "bcpopup.h"
4 #include "bcresources.h"
5 #include "bcsignals.h"
6 #include "bcsynchronous.h"
7 #include "bctimer.h"
8 #include "bcwindowbase.h"
9 #include "clip.h"
10 #include "colors.h"
11 #include "cursors.h"
12 #include "fonts.h"
13 #include "vframe.h"
14 #include <string.h>
16 void BC_WindowBase::copy_area(int x1, int y1, int x2, int y2, int w, int h, BC_Pixmap *pixmap)
18         XCopyArea(top_level->display, 
19                 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap, 
20                 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap, 
21                 top_level->gc, 
22                 x1, 
23                 y1, 
24                 w,
25         h, 
26                 x2, 
27                 y2);
31 void BC_WindowBase::draw_box(int x, int y, int w, int h, BC_Pixmap *pixmap)
33 //if(x == 0) printf("BC_WindowBase::draw_box %d %d %d %d\n", x, y, w, h);
34         XFillRectangle(top_level->display, 
35                 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap, 
36                 top_level->gc, 
37                 x, 
38                 y, 
39                 w, 
40                 h);
44 void BC_WindowBase::draw_circle(int x, int y, int w, int h, BC_Pixmap *pixmap)
46         XDrawArc(top_level->display, 
47                 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap, 
48                 top_level->gc, 
49                 x, 
50                 y, 
51                 (w - 1), 
52                 (h - 2), 
53                 0 * 64, 
54                 360 * 64);
57 void BC_WindowBase::draw_disc(int x, int y, int w, int h, BC_Pixmap *pixmap)
59         XFillArc(top_level->display, 
60                 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap, 
61                 top_level->gc, 
62                 x, 
63                 y, 
64                 (w - 1), 
65                 (h - 2), 
66                 0 * 64, 
67                 360 * 64);
70 void BC_WindowBase::clear_box(int x, int y, int w, int h, BC_Pixmap *pixmap)
72         set_color(bg_color);
73         XFillRectangle(top_level->display, 
74                 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap, 
75                 top_level->gc, 
76                 x, 
77                 y, 
78                 w, 
79                 h);
82 void BC_WindowBase::draw_text(int x, 
83         int y, 
84         char *text, 
85         int length, 
86         BC_Pixmap *pixmap)
88         if(length < 0) length = strlen(text);
89         int boldface = top_level->current_font & BOLDFACE;
90         int font = top_level->current_font & 0xff;
92         switch(font)
93         {
94                 case MEDIUM_7SEGMENT:
95                         for(int i = 0; i < length; i++)
96                         {
97                                 VFrame *image;
98                                 switch(text[i])
99                                 {
100                                         case '0':
101                                                 image = get_resources()->medium_7segment[0];
102                                                 break;
103                                         case '1':
104                                                 image = get_resources()->medium_7segment[1];
105                                                 break;
106                                         case '2':
107                                                 image = get_resources()->medium_7segment[2];
108                                                 break;
109                                         case '3':
110                                                 image = get_resources()->medium_7segment[3];
111                                                 break;
112                                         case '4':
113                                                 image = get_resources()->medium_7segment[4];
114                                                 break;
115                                         case '5':
116                                                 image = get_resources()->medium_7segment[5];
117                                                 break;
118                                         case '6':
119                                                 image = get_resources()->medium_7segment[6];
120                                                 break;
121                                         case '7':
122                                                 image = get_resources()->medium_7segment[7];
123                                                 break;
124                                         case '8':
125                                                 image = get_resources()->medium_7segment[8];
126                                                 break;
127                                         case '9':
128                                                 image = get_resources()->medium_7segment[9];
129                                                 break;
130                                         case ':':
131                                                 image = get_resources()->medium_7segment[10];
132                                                 break;
133                                         case '.':
134                                                 image = get_resources()->medium_7segment[11];
135                                                 break;
136                                         case 'a':
137                                         case 'A':
138                                                 image = get_resources()->medium_7segment[12];
139                                                 break;
140                                         case 'b':
141                                         case 'B':
142                                                 image = get_resources()->medium_7segment[13];
143                                                 break;
144                                         case 'c':
145                                         case 'C':
146                                                 image = get_resources()->medium_7segment[14];
147                                                 break;
148                                         case 'd':
149                                         case 'D':
150                                                 image = get_resources()->medium_7segment[15];
151                                                 break;
152                                         case 'e':
153                                         case 'E':
154                                                 image = get_resources()->medium_7segment[16];
155                                                 break;
156                                         case 'f':
157                                         case 'F':
158                                                 image = get_resources()->medium_7segment[17];
159                                                 break;
160                                         case ' ':
161                                                 image = get_resources()->medium_7segment[18];
162                                                 break;
163                                         case '-':
164                                                 image = get_resources()->medium_7segment[19];
165                                                 break;
166                                         default:
167                                                 image = get_resources()->medium_7segment[18];
168                                                 break;
169                                 }
171                                 draw_vframe(image, 
172                                         x, 
173                                         y - image->get_h());
174                                 x += image->get_w();
175                         }
176                         break;
178                 default:
179                 {
180 // Set drawing color for dropshadow
181                         int color = get_color();
182                         if(boldface) set_color(BLACK);
185                         for(int k = (boldface ? 1 : 0); k >= 0; k--)
186                         {
187                                 for(int i = 0, j = 0, x2 = x, y2 = y; 
188                                         i <= length; 
189                                         i++)
190                                 {
191                                         if(text[i] == '\n' || text[i] == 0)
192                                         {
193 #ifdef HAVE_XFT
194                                                 if(get_resources()->use_xft && 
195                                                         top_level->get_xft_struct(top_level->current_font))
196                                                 {
197                                                         draw_xft_text(x,
198                                                                 y,
199                                                                 text,
200                                                                 length,
201                                                                 pixmap,
202                                                                 x2,
203                                                                 k,
204                                                                 y2,
205                                                                 j,
206                                                                 i);
207                                                 }
208                                                 else
209 #endif
210                                                 if(get_resources()->use_fontset && top_level->get_curr_fontset())
211                                                 {
212                                                 XmbDrawString(top_level->display, 
213                                                 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap, 
214                                                 top_level->get_curr_fontset(),
215                                                 top_level->gc, 
216                                                 x2 + k, 
217                                                 y2 + k, 
218                                                 &text[j], 
219                                                 i - j);
220                                                 }
221                                                 else
222                                                 {
223 //printf("BC_WindowBase::draw_text 3\n");
224                                                         XDrawString(top_level->display, 
225                                                                 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap, 
226                                                                 top_level->gc, 
227                                                                 x2 + k, 
228                                                                 y2 + k, 
229                                                                 &text[j], 
230                                                                 i - j);
231                                                 }
235                                                 j = i + 1;
236                                                 y2 += get_text_height(MEDIUMFONT);
237                                         }
238                                 }
239                                 if(boldface) set_color(color);
240                         }
241                         break;
242                 }
243         }
246 void BC_WindowBase::draw_xft_text(int x, 
247         int y, 
248         char *text, 
249         int length, 
250         BC_Pixmap *pixmap,
251         int x2,
252         int k,
253         int y2,
254         int j,
255         int i)
257 #ifdef HAVE_XFT
258 // printf("BC_WindowBase::draw_xft_text_synch 1 %d %p\n", 
259 // get_resources()->use_xft, 
260 // top_level->get_xft_struct(top_level->current_font));
261         XRenderColor color;
262         XftColor xft_color;
263         color.red = (top_level->current_color & 0xff0000) >> 16;
264         color.red |= color.red << 8;
265         color.green = (top_level->current_color & 0xff00) >> 8;
266         color.green |= color.green << 8;
267         color.blue = (top_level->current_color & 0xff);
268         color.blue |= color.blue << 8;
269         color.alpha = 0xffff;
271         XftColorAllocValue(top_level->display,
272                 top_level->vis,
273                 top_level->cmap,
274                 &color,
275                 &xft_color);
277 // printf("BC_WindowBase::draw_text 1 %u   %p %p %p %d %d %s %d\n",
278 // xft_color.pixel,
279 // pixmap ? pixmap->opaque_xft_draw : this->xft_drawable,
280 // &xft_color,
281 // top_level->get_xft_struct(top_level->current_font),
282 // x2 + k, 
283 // y2 + k,
284 // (FcChar8*)&text[j],
285 // i - j);
286         XftDrawString8 (
287                 (XftDraw*)(pixmap ? pixmap->opaque_xft_draw : this->pixmap->opaque_xft_draw),
288                 &xft_color,
289                 top_level->get_xft_struct(top_level->current_font),
290                 x2 + k, 
291                 y2 + k,
292                 (FcChar8*)&text[j],
293                 i - j);
294         XftColorFree(top_level->display,
295             top_level->vis,
296             top_level->cmap,
297             &xft_color);
298 #endif
302 void BC_WindowBase::draw_center_text(int x, int y, char *text, int length)
304         if(length < 0) length = strlen(text);
305         int w = get_text_width(current_font, text, length);
306         x -= w / 2;
307         draw_text(x, y, text, length);
310 void BC_WindowBase::draw_line(int x1, int y1, int x2, int y2, BC_Pixmap *pixmap)
312         XDrawLine(top_level->display, 
313                 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap, 
314                 top_level->gc, 
315                 x1, 
316                 y1, 
317                 x2, 
318                 y2);
321 void BC_WindowBase::draw_polygon(ArrayList<int> *x, ArrayList<int> *y, BC_Pixmap *pixmap)
323         int npoints = MIN(x->total, y->total);
324         XPoint *points = new XPoint[npoints];
326         for(int i = 0; i < npoints; i++)
327         {
328                 points[i].x = x->values[i];
329                 points[i].y = y->values[i];
330         }
332         XDrawLines(top_level->display,
333         pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap,
334         top_level->gc,
335         points,
336         npoints,
337         CoordModeOrigin);
339         delete [] points;
343 void BC_WindowBase::draw_rectangle(int x, int y, int w, int h)
345         XDrawRectangle(top_level->display, 
346                 pixmap->opaque_pixmap, 
347                 top_level->gc, 
348                 x, 
349                 y, 
350                 w - 1, 
351                 h - 1);
354 void BC_WindowBase::draw_3d_border(int x, int y, int w, int h, 
355         int light1, int light2, int shadow1, int shadow2)
357         int lx, ly, ux, uy;
359         h--; w--;
361         lx = x+1;  ly = y+1;
362         ux = x+w-1;  uy = y+h-1;
364         set_color(light1);
365         draw_line(x, y, ux, y);
366         draw_line(x, y, x, uy);
367         set_color(light2);
368         draw_line(lx, ly, ux - 1, ly);
369         draw_line(lx, ly, lx, uy - 1);
371         set_color(shadow1);
372         draw_line(ux, ly, ux, uy);
373         draw_line(lx, uy, ux, uy);
374         set_color(shadow2);
375         draw_line(x + w, y, x + w, y + h);
376         draw_line(x, y + h, x + w, y + h);
379 void BC_WindowBase::draw_3d_box(int x, 
380         int y, 
381         int w, 
382         int h, 
383         int light1, 
384         int light2, 
385         int middle, 
386         int shadow1, 
387         int shadow2,
388         BC_Pixmap *pixmap)
390         int lx, ly, ux, uy;
392         h--; w--;
394         lx = x+1;  ly = y+1;
395         ux = x+w-1;  uy = y+h-1;
397         set_color(middle);
398         draw_box(x, y, w, h, pixmap);
400         set_color(light1);
401         draw_line(x, y, ux, y, pixmap);
402         draw_line(x, y, x, uy, pixmap);
403         set_color(light2);
404         draw_line(lx, ly, ux - 1, ly, pixmap);
405         draw_line(lx, ly, lx, uy - 1, pixmap);
407         set_color(shadow1);
408         draw_line(ux, ly, ux, uy, pixmap);
409         draw_line(lx, uy, ux, uy, pixmap);
410         set_color(shadow2);
411         draw_line(x + w, y, x + w, y + h, pixmap);
412         draw_line(x, y + h, x + w, y + h, pixmap);
415 void BC_WindowBase::draw_colored_box(int x, int y, int w, int h, int down, int highlighted)
417         if(!down)
418         {
419                 if(highlighted)
420                         draw_3d_box(x, y, w, h, 
421                                 top_level->get_resources()->button_light, 
422                                 top_level->get_resources()->button_highlighted, 
423                                 top_level->get_resources()->button_highlighted, 
424                                 top_level->get_resources()->button_shadow,
425                                 BLACK);
426                 else
427                         draw_3d_box(x, y, w, h, 
428                                 top_level->get_resources()->button_light, 
429                                 top_level->get_resources()->button_up, 
430                                 top_level->get_resources()->button_up, 
431                                 top_level->get_resources()->button_shadow,
432                                 BLACK);
433         }
434         else
435         {
436 // need highlighting for toggles
437                 if(highlighted)
438                         draw_3d_box(x, y, w, h, 
439                                 top_level->get_resources()->button_shadow, 
440                                 BLACK, 
441                                 top_level->get_resources()->button_up, 
442                                 top_level->get_resources()->button_up,
443                                 top_level->get_resources()->button_light);
444                 else
445                         draw_3d_box(x, y, w, h, 
446                                 top_level->get_resources()->button_shadow, 
447                                 BLACK, 
448                                 top_level->get_resources()->button_down, 
449                                 top_level->get_resources()->button_down,
450                                 top_level->get_resources()->button_light);
451         }
454 void BC_WindowBase::draw_border(char *text, int x, int y, int w, int h)
456         int left_indent = 20;
457         int lx, ly, ux, uy;
459         h--; w--;
460         lx = x + 1;  ly = y + 1;
461         ux = x + w - 1;  uy = y + h - 1;
463         set_opaque();
464         if(text && text[0] != 0)
465         {
466                 set_color(BLACK);
467                 set_font(MEDIUMFONT);
468                 draw_text(x + left_indent, y + get_text_height(MEDIUMFONT) / 2, text);
469         }
470         
471         set_color(top_level->get_resources()->button_shadow);
472         draw_line(x, y, x + left_indent - 5, y);
473         draw_line(x, y, x, uy);
474         draw_line(x + left_indent + 5 + get_text_width(MEDIUMFONT, text), y, ux, y);
475         draw_line(x, y, x, uy);
476         draw_line(ux, ly, ux, uy);
477         draw_line(lx, uy, ux, uy);
478         set_color(top_level->get_resources()->button_light);
479         draw_line(lx, ly, x + left_indent - 5 - 1, ly);
480         draw_line(lx, ly, lx, uy - 1);
481         draw_line(x + left_indent + 5 + get_text_width(MEDIUMFONT, text), ly, ux - 1, ly);
482         draw_line(lx, ly, lx, uy - 1);
483         draw_line(x + w, y, x + w, y + h);
484         draw_line(x, y + h, x + w, y + h);
487 void BC_WindowBase::draw_triangle_down_flat(int x, int y, int w, int h)
489         int x1, y1, x2, y2, x3, y3;
490         XPoint point[3];
492         x1 = x; x2 = x + w / 2; x3 = x + w - 1;
493         y1 = y; y2 = y + h - 1;
495         point[0].x = x2; point[0].y = y2; point[1].x = x3;
496         point[1].y = y1; point[2].x = x1; point[2].y = y1;
498         XFillPolygon(top_level->display, 
499                 pixmap->opaque_pixmap, 
500                 top_level->gc, 
501                 (XPoint *)point, 
502                 3, 
503                 Nonconvex, 
504                 CoordModeOrigin);
507 void BC_WindowBase::draw_triangle_up(int x, int y, int w, int h, 
508         int light1, int light2, int middle, int shadow1, int shadow2)
510         int x1, y1, x2, y2, x3, y3;
511         XPoint point[3];
513         x1 = x; y1 = y; x2 = x + w / 2;
514         y2 = y + h - 1; x3 = x + w - 1;
516 // middle
517         point[0].x = x2; point[0].y = y1; point[1].x = x3;
518         point[1].y = y2; point[2].x = x1; point[2].y = y2;
520         set_color(middle);
521         XFillPolygon(top_level->display, 
522                 pixmap->opaque_pixmap, 
523                 top_level->gc, 
524                 (XPoint *)point, 
525                 3, 
526                 Nonconvex, 
527                 CoordModeOrigin);
529 // bottom and top right
530         set_color(shadow1);
531         draw_line(x3, y2-1, x1, y2-1);
532         draw_line(x2-1, y1, x3-1, y2);
533         set_color(shadow2);
534         draw_line(x3, y2, x1, y2);
535         draw_line(x2, y1, x3, y2);
537 // top left
538         set_color(light2);
539         draw_line(x2+1, y1, x1+1, y2);
540         set_color(light1);
541         draw_line(x2, y1, x1, y2);
544 void BC_WindowBase::draw_triangle_down(int x, int y, int w, int h, 
545         int light1, int light2, int middle, int shadow1, int shadow2)
547         int x1, y1, x2, y2, x3, y3;
548         XPoint point[3];
550         x1 = x; x2 = x + w / 2; x3 = x + w - 1;
551         y1 = y; y2 = y + h - 1;
553         point[0].x = x2; point[0].y = y2; point[1].x = x3;
554         point[1].y = y1; point[2].x = x1; point[2].y = y1;
556         set_color(middle);
557         XFillPolygon(top_level->display, 
558                 pixmap->opaque_pixmap, 
559                 top_level->gc, 
560                 (XPoint *)point, 
561                 3, 
562                 Nonconvex, 
563                 CoordModeOrigin);
565 // top and bottom left
566         set_color(light2);
567         draw_line(x3-1, y1+1, x1+1, y1+1);
568         draw_line(x1+1, y1, x2+1, y2);
569         set_color(light1);
570         draw_line(x3, y1, x1, y1);
571         draw_line(x1, y1, x2, y2);
573 // bottom right
574         set_color(shadow1);
575         draw_line(x3-1, y1, x2-1, y2);
576         set_color(shadow2);
577         draw_line(x3, y1, x2, y2);
580 void BC_WindowBase::draw_triangle_left(int x, int y, int w, int h, 
581         int light1, int light2, int middle, int shadow1, int shadow2)
583         int x1, y1, x2, y2, x3, y3;
584         XPoint point[3];
586         // draw back arrow
587         y1 = y; x1 = x; y2 = y + h / 2;
588         x2 = x + w - 1; y3 = y + h - 1;
590         point[0].x = x1; point[0].y = y2; point[1].x = x2; 
591         point[1].y = y1; point[2].x = x2; point[2].y = y3;
593         set_color(middle);
594         XFillPolygon(top_level->display, 
595                 pixmap->opaque_pixmap, 
596                 top_level->gc, 
597                 (XPoint *)point, 
598                 3, 
599                 Nonconvex, 
600                 CoordModeOrigin);
602 // right and bottom right
603         set_color(shadow1);
604         draw_line(x2-1, y1, x2-1, y3-1);
605         draw_line(x2, y3-1, x1, y2-1);
606         set_color(shadow2);
607         draw_line(x2, y1, x2, y3);
608         draw_line(x2, y3, x1, y2);
610 // top left
611         set_color(light1);
612         draw_line(x1, y2, x2, y1);
613         set_color(light2);
614         draw_line(x1, y2+1, x2, y1+1);
617 void BC_WindowBase::draw_triangle_right(int x, int y, int w, int h, 
618         int light1, int light2, int middle, int shadow1, int shadow2)
620         int x1, y1, x2, y2, x3, y3;
621         XPoint point[3];
623         y1 = y; y2 = y + h / 2; y3 = y + h - 1; 
624         x1 = x; x2 = x + w - 1;
626         point[0].x = x1; point[0].y = y1; point[1].x = x2; 
627         point[1].y = y2; point[2].x = x1; point[2].y = y3;
629         set_color(middle);
630         XFillPolygon(top_level->display, 
631                 pixmap->opaque_pixmap, 
632                 top_level->gc, 
633                 (XPoint *)point, 
634                 3, 
635                 Nonconvex, 
636                 CoordModeOrigin);
638 // left and top right
639         set_color(light2);
640         draw_line(x1+1, y3, x1+1, y1);
641         draw_line(x1, y1+1, x2, y2+1);
642         set_color(light1);
643         draw_line(x1, y3, x1, y1);
644         draw_line(x1, y1, x2, y2);
646 // bottom right
647         set_color(shadow1);
648         draw_line(x2, y2-1, x1, y3-1);
649         set_color(shadow2);
650         draw_line(x2, y2, x1, y3);
654 void BC_WindowBase::draw_check(int x, int y)
656         const int w = 15, h = 15;
657         draw_line(x + 3, y + h / 2 + 0, x + 6, y + h / 2 + 2);
658         draw_line(x + 3, y + h / 2 + 1, x + 6, y + h / 2 + 3);
659         draw_line(x + 6, y + h / 2 + 2, x + w - 4, y + h / 2 - 3);
660         draw_line(x + 3, y + h / 2 + 2, x + 6, y + h / 2 + 4);
661         draw_line(x + 6, y + h / 2 + 2, x + w - 4, y + h / 2 - 3);
662         draw_line(x + 6, y + h / 2 + 3, x + w - 4, y + h / 2 - 2);
663         draw_line(x + 6, y + h / 2 + 4, x + w - 4, y + h / 2 - 1);
666 void BC_WindowBase::draw_tiles(BC_Pixmap *tile, int origin_x, int origin_y, int x, int y, int w, int h)
668         if(!tile)
669         {
670                 set_color(bg_color);
671                 draw_box(x, y, w, h);
672         }
673         else
674         {
675                 XSetFillStyle(top_level->display, top_level->gc, FillTiled);
676 // Don't know how slow this is
677                 XSetTile(top_level->display, top_level->gc, tile->get_pixmap());
678                 XSetTSOrigin(top_level->display, top_level->gc, origin_x, origin_y);
679                 draw_box(x, y, w, h);
680                 XSetFillStyle(top_level->display, top_level->gc, FillSolid);
681         }
684 void BC_WindowBase::draw_top_tiles(BC_WindowBase *parent_window, int x, int y, int w, int h)
686         Window tempwin;
687         int origin_x, origin_y;
688         XTranslateCoordinates(top_level->display, 
689                         parent_window->win, 
690                         win, 
691                         0, 
692                         0, 
693                         &origin_x, 
694                         &origin_y, 
695                         &tempwin);
697         draw_tiles(parent_window->bg_pixmap, 
698                 origin_x,
699                 origin_y,
700                 x,
701                 y,
702                 w,
703                 h);
706 void BC_WindowBase::draw_top_background(BC_WindowBase *parent_window, 
707         int x, 
708         int y, 
709         int w, 
710         int h, 
711         BC_Pixmap *pixmap)
713         Window tempwin;
714         int top_x, top_y;
716         XTranslateCoordinates(top_level->display, 
717                         win, 
718                         parent_window->win, 
719                         x, 
720                         y, 
721                         &top_x, 
722                         &top_y, 
723                         &tempwin);
725         XCopyArea(top_level->display, 
726                 parent_window->pixmap->opaque_pixmap, 
727                 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap, 
728                 top_level->gc, 
729                 top_x, 
730                 top_y, 
731                 w, 
732                 h, 
733                 x, 
734                 y);
737 void BC_WindowBase::draw_background(int x, int y, int w, int h)
739         if(bg_pixmap)
740         {
741                 draw_tiles(bg_pixmap, 0, 0, x, y, w, h);
742         }
743         else
744         {
745                 clear_box(x, y, w, h);
746         }
749 void BC_WindowBase::draw_bitmap(BC_Bitmap *bitmap, 
750         int dont_wait,
751         int dest_x, 
752         int dest_y,
753         int dest_w,
754         int dest_h,
755         int src_x,
756         int src_y,
757         int src_w,
758         int src_h,
759         BC_Pixmap *pixmap)
762 // Hide cursor if video enabled
763         update_video_cursor();
765 //printf("BC_WindowBase::draw_bitmap 1\n");
766         if(dest_w <= 0 || dest_h <= 0)
767         {
768 // Use hardware scaling to canvas dimensions if proper color model.
769                 if(bitmap->get_color_model() == BC_YUV420P)
770                 {
771                         dest_w = w;
772                         dest_h = h;
773                 }
774                 else
775                 {
776                         dest_w = bitmap->get_w();
777                         dest_h = bitmap->get_h();
778                 }
779         }
781         if(src_w <= 0 || src_h <= 0)
782         {
783                 src_w = bitmap->get_w();
784                 src_h = bitmap->get_h();
785         }
787         if(video_on)
788         {
789                 bitmap->write_drawable(win, 
790                         top_level->gc, 
791                         src_x, 
792                         src_y, 
793                         src_w,
794                         src_h,
795                         dest_x, 
796                         dest_y, 
797                         dest_w, 
798                         dest_h, 
799                         dont_wait);
800                 top_level->flush();
801         }
802         else
803         {
804                 bitmap->write_drawable(pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap, 
805                         top_level->gc, 
806                         dest_x, 
807                         dest_y, 
808                         src_x, 
809                         src_y, 
810                         dest_w, 
811                         dest_h, 
812                         dont_wait);
813         }
814 //printf("BC_WindowBase::draw_bitmap 2\n");
818 void BC_WindowBase::draw_pixel(int x, int y, BC_Pixmap *pixmap)
820         XDrawPoint(top_level->display, 
821                 pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap, 
822                 top_level->gc, 
823                 x, 
824                 y);
828 void BC_WindowBase::draw_pixmap(BC_Pixmap *pixmap, 
829         int dest_x, 
830         int dest_y,
831         int dest_w,
832         int dest_h,
833         int src_x,
834         int src_y,
835         BC_Pixmap *dst)
837         pixmap->write_drawable(dst ? dst->opaque_pixmap : this->pixmap->opaque_pixmap,
838                         dest_x, 
839                         dest_y,
840                         dest_w,
841                         dest_h,
842                         src_x,
843                         src_y);
846 void BC_WindowBase::draw_vframe(VFrame *frame, 
847                 int dest_x, 
848                 int dest_y, 
849                 int dest_w, 
850                 int dest_h,
851                 int src_x,
852                 int src_y,
853                 int src_w,
854                 int src_h,
855                 BC_Pixmap *pixmap)
857         if(dest_w <= 0) dest_w = frame->get_w() - src_x;
858         if(dest_h <= 0) dest_h = frame->get_h() - src_y;
859         if(src_w <= 0) src_w = frame->get_w() - src_x;
860         if(src_h <= 0) src_h = frame->get_h() - src_y;
861         CLAMP(src_x, 0, frame->get_w() - 1);
862         CLAMP(src_y, 0, frame->get_h() - 1);
863         if(src_x + src_w > frame->get_w()) src_w = frame->get_w() - src_x;
864         if(src_y + src_h > frame->get_h()) src_h = frame->get_h() - src_y;
866         if(!temp_bitmap) temp_bitmap = new BC_Bitmap(this, 
867                 dest_w, 
868                 dest_h, 
869                 get_color_model(), 
870                 1);
872         temp_bitmap->match_params(dest_w, 
873                 dest_h, 
874                 get_color_model(), 
875                 1);
877         temp_bitmap->read_frame(frame, 
878                 src_x, 
879                 src_y, 
880                 src_w, 
881                 src_h,
882                 0, 
883                 0, 
884                 dest_w, 
885                 dest_h);
887         draw_bitmap(temp_bitmap, 
888                 0, 
889                 dest_x, 
890                 dest_y,
891                 dest_w,
892                 dest_h,
893                 0,
894                 0,
895                 -1,
896                 -1,
897                 pixmap);
900 void BC_WindowBase::draw_tooltip()
902         if(tooltip_popup)
903         {
904                 int w = tooltip_popup->get_w(), h = tooltip_popup->get_h();
905                 tooltip_popup->set_color(get_resources()->tooltip_bg_color);
906                 tooltip_popup->draw_box(0, 0, w, h);
907                 tooltip_popup->set_color(BLACK);
908                 tooltip_popup->draw_rectangle(0, 0, w, h);
909                 tooltip_popup->set_font(MEDIUMFONT);
910                 tooltip_popup->draw_text(TOOLTIP_MARGIN, 
911                         get_text_ascent(MEDIUMFONT) + TOOLTIP_MARGIN, 
912                         tooltip_text);
913         }
916 void BC_WindowBase::slide_left(int distance)
918         if(distance < w)
919         {
920                 XCopyArea(top_level->display, 
921                         pixmap->opaque_pixmap, 
922                         pixmap->opaque_pixmap, 
923                         top_level->gc, 
924                         distance, 
925                         0, 
926                         w - distance, 
927                         h, 
928                         0, 
929                         0);
930         }
933 void BC_WindowBase::slide_right(int distance)
935         if(distance < w)
936         {
937                 XCopyArea(top_level->display, 
938                         pixmap->opaque_pixmap, 
939                         pixmap->opaque_pixmap, 
940                         top_level->gc, 
941                         0, 
942                         0, 
943                         w - distance, 
944                         h, 
945                         distance, 
946                         0);
947         }
950 void BC_WindowBase::slide_up(int distance)
952         if(distance < h)
953         {
954                 XCopyArea(top_level->display, 
955                         pixmap->opaque_pixmap, 
956                         pixmap->opaque_pixmap, 
957                         top_level->gc, 
958                         0, 
959                         distance, 
960                         w, 
961                         h - distance, 
962                         0, 
963                         0);
964                 set_color(bg_color);
965                 XFillRectangle(top_level->display, 
966                         pixmap->opaque_pixmap, 
967                         top_level->gc, 
968                         0, 
969                         h - distance, 
970                         w, 
971                         distance);
972         }
975 void BC_WindowBase::slide_down(int distance)
977         if(distance < h)
978         {
979                 XCopyArea(top_level->display, 
980                         pixmap->opaque_pixmap, 
981                         pixmap->opaque_pixmap, 
982                         top_level->gc, 
983                         0, 
984                         0, 
985                         w, 
986                         h - distance, 
987                         0, 
988                         distance);
989                 set_color(bg_color);
990                 XFillRectangle(top_level->display, 
991                         pixmap->opaque_pixmap, 
992                         top_level->gc, 
993                         0, 
994                         0, 
995                         w, 
996                         distance);
997         }
1000 // 3 segments in separate pixmaps.  Obsolete.
1001 void BC_WindowBase::draw_3segment(int x, 
1002         int y, 
1003         int w, 
1004         int h, 
1005         BC_Pixmap *left_image,
1006         BC_Pixmap *mid_image,
1007         BC_Pixmap *right_image,
1008         BC_Pixmap *pixmap)
1010         if(w <= 0 || h <= 0) return;
1011         int left_boundary = left_image->get_w_fixed();
1012         int right_boundary = w - right_image->get_w_fixed();
1013         for(int i = 0; i < w; )
1014         {
1015                 BC_Pixmap *image;
1017                 if(i < left_boundary)
1018                         image = left_image;
1019                 else
1020                 if(i < right_boundary)
1021                         image = mid_image;
1022                 else
1023                         image = right_image;
1025                 int output_w = image->get_w_fixed();
1027                 if(i < left_boundary)
1028                 {
1029                         if(i + output_w > left_boundary) output_w = left_boundary - i;
1030                 }
1031                 else
1032                 if(i < right_boundary)
1033                 {
1034                         if(i + output_w > right_boundary) output_w = right_boundary - i;
1035                 }
1036                 else
1037                         if(i + output_w > w) output_w = w - i;
1039                 image->write_drawable(pixmap ? pixmap->opaque_pixmap : this->pixmap->opaque_pixmap, 
1040                                 x + i, 
1041                                 y,
1042                                 output_w,
1043                                 h,
1044                                 0,
1045                                 0);
1047                 i += output_w;
1048         }
1050 // 3 segments in separate vframes.  Obsolete.
1051 void BC_WindowBase::draw_3segment(int x, 
1052         int y, 
1053         int w, 
1054         int h, 
1055         VFrame *left_image,
1056         VFrame *mid_image,
1057         VFrame *right_image,
1058         BC_Pixmap *pixmap)
1060         if(w <= 0 || h <= 0) return;
1061         int left_boundary = left_image->get_w_fixed();
1062         int right_boundary = w - right_image->get_w_fixed();
1065         for(int i = 0; i < w; )
1066         {
1067                 VFrame *image;
1069                 if(i < left_boundary)
1070                         image = left_image;
1071                 else
1072                 if(i < right_boundary)
1073                         image = mid_image;
1074                 else
1075                         image = right_image;
1076                 
1077                 int output_w = image->get_w_fixed();
1079                 if(i < left_boundary)
1080                 {
1081                         if(i + output_w > left_boundary) output_w = left_boundary - i;
1082                 }
1083                 else
1084                 if(i < right_boundary)
1085                 {
1086                         if(i + output_w > right_boundary) output_w = right_boundary - i;
1087                 }
1088                 else
1089                         if(i + output_w > w) output_w = w - i;
1091                 if(image)
1092                         draw_vframe(image, 
1093                                         x + i, 
1094                                         y,
1095                                         output_w,
1096                                         h,
1097                                         0,
1098                                         0,
1099                                         0,
1100                                         0,
1101                                         pixmap);
1103                 if(output_w == 0) break;
1104                 i += output_w;
1105         }
1108 // Draw all 3 segments in a single vframe for a changing level
1110 // total_x 
1111 // <------>
1112 // total_w
1113 //         <------------------------------------------------------------>
1114 // x
1115 // |
1116 // w           
1117 // <-------------------------------------------------------------------->
1118 // output
1119 //         |-------------------|----------------------|------------------|
1122 void BC_WindowBase::draw_3segmenth(int x, 
1123                 int y, 
1124                 int w, 
1125                 VFrame *image,
1126                 BC_Pixmap *pixmap)
1128         draw_3segmenth(x, 
1129                 y, 
1130                 w, 
1131                 x,
1132                 w,
1133                 image,
1134                 pixmap);
1137 void BC_WindowBase::draw_3segmenth(int x, 
1138                 int y, 
1139                 int w, 
1140                 int total_x,
1141                 int total_w,
1142                 VFrame *image,
1143                 BC_Pixmap *pixmap)
1145         if(total_w <= 0 || w <= 0 || h <= 0) return;
1146         int third_image = image->get_w() / 3;
1147         int half_image = image->get_w() / 2;
1148         int left_boundary = third_image;
1149         int right_boundary = total_w - third_image;
1150         int left_in_x = 0;
1151         int left_in_w = third_image;
1152         int left_out_x = total_x;
1153         int left_out_w = third_image;
1154         int right_in_x = image->get_w() - third_image;
1155         int right_in_w = third_image;
1156         int right_out_x = total_x + total_w - third_image;
1157         int right_out_w = third_image;
1158         int center_out_x = total_x + third_image;
1159         int center_out_w = total_w - third_image * 2;
1160         int image_x, image_w;
1162 //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", 
1163 //      left_out_x, left_out_w, center_out_x, center_out_w, right_out_x, right_out_w);
1165         if(left_out_x < x)
1166         {
1167                 left_in_w -= x - left_out_x;
1168                 left_out_w -= x - left_out_x;
1169                 left_in_x += x - left_out_x;
1170                 left_out_x += x - left_out_x;
1171         }
1173         if(left_out_x + left_out_w > x + w)
1174         {
1175                 left_in_w -= (left_out_x + left_out_w) - (x + w);
1176                 left_out_w -= (left_out_x + left_out_w) - (x + w);
1177         }
1179         if(right_out_x < x)
1180         {
1181                 right_in_w -= x - right_out_x;
1182                 right_out_w -= x - right_out_x;
1183                 right_in_x += x - right_out_x;
1184                 right_out_x += x - right_out_x;
1185         }
1187         if(right_out_x + right_out_w > x + w)
1188         {
1189                 right_in_w -= (right_out_x + right_out_w) - (x + w);
1190                 right_out_w -= (right_out_x + right_out_w) - (x + w);
1191         }
1193         if(center_out_x < x)
1194         {
1195                 center_out_w -= x - center_out_x;
1196                 center_out_x += x - center_out_x;
1197         }
1199         if(center_out_x + center_out_w > x + w)
1200         {
1201                 center_out_w -= (center_out_x + center_out_w) - (x + w);
1202         }
1204         if(!temp_bitmap) temp_bitmap = new BC_Bitmap(top_level, 
1205                 image->get_w(), 
1206                 image->get_h(), 
1207                 get_color_model(), 
1208                 0);
1209         temp_bitmap->match_params(image->get_w(), 
1210                 image->get_h(), 
1211                 get_color_model(), 
1212                 0);
1213         temp_bitmap->read_frame(image, 
1214                 0, 
1215                 0, 
1216                 image->get_w(), 
1217                 image->get_h());
1220 //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", 
1221 //      left_out_x, left_out_w, center_out_x, center_out_w, right_out_x, right_out_w);
1222         if(left_out_w > 0)
1223         {
1224                 draw_bitmap(temp_bitmap, 
1225                         0, 
1226                         left_out_x, 
1227                         y,
1228                         left_out_w,
1229                         image->get_h(),
1230                         left_in_x,
1231                         0,
1232                         -1,   // src width and height are meaningless in video_off mode
1233                         -1,
1234                         pixmap);
1235         }
1237         if(right_out_w > 0)
1238         {
1239                 draw_bitmap(temp_bitmap, 
1240                         0, 
1241                         right_out_x, 
1242                         y,
1243                         right_out_w,
1244                         image->get_h(),
1245                         right_in_x,
1246                         0,
1247                         -1,   // src width and height are meaningless in video_off mode
1248                         -1,
1249                         pixmap);
1250         }
1252         for(int pixel = center_out_x; 
1253                 pixel < center_out_x + center_out_w; 
1254                 pixel += half_image)
1255         {
1256                 int fragment_w = half_image;
1257                 if(fragment_w + pixel > center_out_x + center_out_w)
1258                         fragment_w = (center_out_x + center_out_w) - pixel;
1260 //printf("BC_WindowBase::draw_3segment 2 pixel=%d fragment_w=%d\n", pixel, fragment_w);
1261                 draw_bitmap(temp_bitmap, 
1262                         0, 
1263                         pixel, 
1264                         y,
1265                         fragment_w,
1266                         image->get_h(),
1267                         third_image,
1268                         0,
1269                         -1,   // src width and height are meaningless in video_off mode
1270                         -1,
1271                         pixmap);
1272         }
1282 void BC_WindowBase::draw_3segmenth(int x, 
1283                 int y, 
1284                 int w, 
1285                 int total_x,
1286                 int total_w,
1287                 BC_Pixmap *src,
1288                 BC_Pixmap *dst)
1290         if(w <= 0 || total_w <= 0) return;
1291         if(!src) printf("BC_WindowBase::draw_3segmenth src=0\n");
1292         int quarter_src = src->get_w() / 4;
1293         int half_src = src->get_w() / 2;
1294         int left_boundary = quarter_src;
1295         int right_boundary = total_w - quarter_src;
1296         int left_in_x = 0;
1297         int left_in_w = quarter_src;
1298         int left_out_x = total_x;
1299         int left_out_w = quarter_src;
1300         int right_in_x = src->get_w() - quarter_src;
1301         int right_in_w = quarter_src;
1302         int right_out_x = total_x + total_w - quarter_src;
1303         int right_out_w = quarter_src;
1304         int center_out_x = total_x + quarter_src;
1305         int center_out_w = total_w - quarter_src * 2;
1306         int src_x, src_w;
1308 //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", 
1309 //      left_out_x, left_out_w, center_out_x, center_out_w, right_out_x, right_out_w);
1311         if(left_out_x < x)
1312         {
1313                 left_in_w -= x - left_out_x;
1314                 left_out_w -= x - left_out_x;
1315                 left_in_x += x - left_out_x;
1316                 left_out_x += x - left_out_x;
1317         }
1319         if(left_out_x + left_out_w > x + w)
1320         {
1321                 left_in_w -= (left_out_x + left_out_w) - (x + w);
1322                 left_out_w -= (left_out_x + left_out_w) - (x + w);
1323         }
1325         if(right_out_x < x)
1326         {
1327                 right_in_w -= x - right_out_x;
1328                 right_out_w -= x - right_out_x;
1329                 right_in_x += x - right_out_x;
1330                 right_out_x += x - right_out_x;
1331         }
1333         if(right_out_x + right_out_w > x + w)
1334         {
1335                 right_in_w -= (right_out_x + right_out_w) - (x + w);
1336                 right_out_w -= (right_out_x + right_out_w) - (x + w);
1337         }
1339         if(center_out_x < x)
1340         {
1341                 center_out_w -= x - center_out_x;
1342                 center_out_x += x - center_out_x;
1343         }
1345         if(center_out_x + center_out_w > x + w)
1346         {
1347                 center_out_w -= (center_out_x + center_out_w) - (x + w);
1348         }
1351 //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", 
1352 //      left_out_x, left_out_w, center_out_x, center_out_w, right_out_x, right_out_w);
1353         if(left_out_w > 0)
1354         {
1355                 draw_pixmap(src, 
1356                         left_out_x, 
1357                         y,
1358                         left_out_w,
1359                         src->get_h(),
1360                         left_in_x,
1361                         0,
1362                         dst);
1363         }
1365         if(right_out_w > 0)
1366         {
1367                 draw_pixmap(src, 
1368                         right_out_x, 
1369                         y,
1370                         right_out_w,
1371                         src->get_h(),
1372                         right_in_x,
1373                         0,
1374                         dst);
1375         }
1377         for(int pixel = center_out_x; 
1378                 pixel < center_out_x + center_out_w; 
1379                 pixel += half_src)
1380         {
1381                 int fragment_w = half_src;
1382                 if(fragment_w + pixel > center_out_x + center_out_w)
1383                         fragment_w = (center_out_x + center_out_w) - pixel;
1385 //printf("BC_WindowBase::draw_3segment 2 pixel=%d fragment_w=%d\n", pixel, fragment_w);
1386                 draw_pixmap(src, 
1387                         pixel, 
1388                         y,
1389                         fragment_w,
1390                         src->get_h(),
1391                         quarter_src,
1392                         0,
1393                         dst);
1394         }
1399 void BC_WindowBase::draw_3segmenth(int x, 
1400                 int y, 
1401                 int w,
1402                 BC_Pixmap *src,
1403                 BC_Pixmap *dst)
1405         if(w <= 0) return;
1406         int third_image = src->get_w() / 3;
1407         int half_output = w / 2;
1408         int left_boundary = third_image;
1409         int right_boundary = w - third_image;
1410         int left_in_x = 0;
1411         int left_in_w = third_image;
1412         int left_out_x = x;
1413         int left_out_w = third_image;
1414         int right_in_x = src->get_w() - third_image;
1415         int right_in_w = third_image;
1416         int right_out_x = x + w - third_image;
1417         int right_out_w = third_image;
1418         int image_x, image_w;
1420 //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", 
1421 //      left_out_x, left_out_w, center_out_x, center_out_w, right_out_x, right_out_w);
1423         if(left_out_w > half_output)
1424         {
1425                 left_in_w -= left_out_w - half_output;
1426                 left_out_w -= left_out_w - half_output;
1427         }
1429         if(right_out_x < x + half_output)
1430         {
1431                 right_in_w -= x + half_output - right_out_x;
1432                 right_out_w -= x + half_output - right_out_x;
1433                 right_in_x += x + half_output - right_out_x;
1434                 right_out_x += x + half_output - right_out_x;
1435         }
1437 //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", 
1438 //      left_out_x, left_out_w, center_out_x, center_out_w, right_out_x, right_out_w);
1439         if(left_out_w > 0)
1440         {
1441                 draw_pixmap(src, 
1442                         left_out_x, 
1443                         y,
1444                         left_out_w,
1445                         src->get_h(),
1446                         left_in_x,
1447                         0,
1448                         dst);
1449         }
1451         if(right_out_w > 0)
1452         {
1453                 draw_pixmap(src, 
1454                         right_out_x, 
1455                         y,
1456                         right_out_w,
1457                         src->get_h(),
1458                         right_in_x,
1459                         0,
1460                         dst);
1461         }
1463         for(int pixel = left_out_x + left_out_w; 
1464                 pixel < right_out_x; 
1465                 pixel += third_image)
1466         {
1467                 int fragment_w = third_image;
1468                 if(fragment_w + pixel > right_out_x)
1469                         fragment_w = right_out_x - pixel;
1471 //printf("BC_WindowBase::draw_3segment 2 pixel=%d fragment_w=%d\n", pixel, fragment_w);
1472                 draw_pixmap(src, 
1473                         pixel, 
1474                         y,
1475                         fragment_w,
1476                         src->get_h(),
1477                         third_image,
1478                         0,
1479                         dst);
1480         }
1490 void BC_WindowBase::draw_3segmentv(int x, 
1491                 int y, 
1492                 int h,
1493                 VFrame *src,
1494                 BC_Pixmap *dst)
1496         if(h <= 0) return;
1497         int third_image = src->get_h() / 3;
1498         int half_output = h / 2;
1499         int left_boundary = third_image;
1500         int right_boundary = h - third_image;
1501         int left_in_y = 0;
1502         int left_in_h = third_image;
1503         int left_out_y = y;
1504         int left_out_h = third_image;
1505         int right_in_y = src->get_h() - third_image;
1506         int right_in_h = third_image;
1507         int right_out_y = y + h - third_image;
1508         int right_out_h = third_image;
1509         int image_y, image_h;
1512         if(left_out_h > half_output)
1513         {
1514                 left_in_h -= left_out_h - half_output;
1515                 left_out_h -= left_out_h - half_output;
1516         }
1518         if(right_out_y < y + half_output)
1519         {
1520                 right_in_h -= y + half_output - right_out_y;
1521                 right_out_h -= y + half_output - right_out_y;
1522                 right_in_y += y + half_output - right_out_y;
1523                 right_out_y += y + half_output - right_out_y;
1524         }
1527         if(!temp_bitmap) temp_bitmap = new BC_Bitmap(top_level, 
1528                 src->get_w(), 
1529                 src->get_h(), 
1530                 get_color_model(), 
1531                 0);
1532         temp_bitmap->match_params(src->get_w(), 
1533                 src->get_h(), 
1534                 get_color_model(), 
1535                 0);
1536         temp_bitmap->read_frame(src, 
1537                 0, 
1538                 0, 
1539                 src->get_w(), 
1540                 src->get_h());
1543         if(left_out_h > 0)
1544         {
1545                 draw_bitmap(temp_bitmap, 
1546                         0,
1547                         x,
1548                         left_out_y, 
1549                         src->get_w(),
1550                         left_out_h,
1551                         0,
1552                         left_in_y,
1553                         -1,
1554                         -1,
1555                         dst);
1556         }
1558         if(right_out_h > 0)
1559         {
1560                 draw_bitmap(temp_bitmap, 
1561                         0,
1562                         x,
1563                         right_out_y, 
1564                         src->get_w(),
1565                         right_out_h,
1566                         0,
1567                         right_in_y,
1568                         -1,
1569                         -1,
1570                         dst);
1571         }
1573         for(int pixel = left_out_y + left_out_h; 
1574                 pixel < right_out_y; 
1575                 pixel += third_image)
1576         {
1577                 int fragment_h = third_image;
1578                 if(fragment_h + pixel > right_out_y)
1579                         fragment_h = right_out_y - pixel;
1581 //printf("BC_WindowBase::draw_3segment 2 pixel=%d fragment_w=%d\n", pixel, fragment_w);
1582                 draw_bitmap(temp_bitmap, 
1583                         0,
1584                         x,
1585                         pixel, 
1586                         src->get_w(),
1587                         fragment_h,
1588                         0,
1589                         third_image,
1590                         -1,
1591                         -1,
1592                         dst);
1593         }
1596 void BC_WindowBase::draw_3segmentv(int x, 
1597                 int y, 
1598                 int h,
1599                 BC_Pixmap *src,
1600                 BC_Pixmap *dst)
1602         if(h <= 0) return;
1603         int third_image = src->get_h() / 3;
1604         int half_output = h / 2;
1605         int left_boundary = third_image;
1606         int right_boundary = h - third_image;
1607         int left_in_y = 0;
1608         int left_in_h = third_image;
1609         int left_out_y = y;
1610         int left_out_h = third_image;
1611         int right_in_y = src->get_h() - third_image;
1612         int right_in_h = third_image;
1613         int right_out_y = y + h - third_image;
1614         int right_out_h = third_image;
1615         int image_y, image_h;
1618         if(left_out_h > half_output)
1619         {
1620                 left_in_h -= left_out_h - half_output;
1621                 left_out_h -= left_out_h - half_output;
1622         }
1624         if(right_out_y < y + half_output)
1625         {
1626                 right_in_h -= y + half_output - right_out_y;
1627                 right_out_h -= y + half_output - right_out_y;
1628                 right_in_y += y + half_output - right_out_y;
1629                 right_out_y += y + half_output - right_out_y;
1630         }
1632         if(left_out_h > 0)
1633         {
1634                 draw_pixmap(src, 
1635                         x,
1636                         left_out_y, 
1637                         src->get_w(),
1638                         left_out_h,
1639                         0,
1640                         left_in_y,
1641                         dst);
1642         }
1644         if(right_out_h > 0)
1645         {
1646                 draw_pixmap(src, 
1647                         x,
1648                         right_out_y, 
1649                         src->get_w(),
1650                         right_out_h,
1651                         0,
1652                         right_in_y,
1653                         dst);
1654         }
1656         for(int pixel = left_out_y + left_out_h; 
1657                 pixel < right_out_y; 
1658                 pixel += third_image)
1659         {
1660                 int fragment_h = third_image;
1661                 if(fragment_h + pixel > right_out_y)
1662                         fragment_h = right_out_y - pixel;
1664 //printf("BC_WindowBase::draw_3segment 2 pixel=%d fragment_w=%d\n", pixel, fragment_w);
1665                 draw_pixmap(src, 
1666                         x,
1667                         pixel, 
1668                         src->get_w(),
1669                         fragment_h,
1670                         0,
1671                         third_image,
1672                         dst);
1673         }
1677 void BC_WindowBase::draw_9segment(int x, 
1678                 int y, 
1679                 int w,
1680                 int h,
1681                 BC_Pixmap *src,
1682                 BC_Pixmap *dst)
1684         if(w <= 0 || h <= 0) return;
1686         int in_x_third = src->get_w() / 3;
1687         int in_y_third = src->get_h() / 3;
1688         int out_x_half = w / 2;
1689         int out_y_half = h / 2;
1691         int in_x1 = 0;
1692         int in_y1 = 0;
1693         int out_x1 = 0;
1694         int out_y1 = 0;
1695         int in_x2 = MIN(in_x_third, out_x_half);
1696         int in_y2 = MIN(in_y_third, out_y_half);
1697         int out_x2 = in_x2;
1698         int out_y2 = in_y2;
1700         int out_x3 = MAX(w - out_x_half, w - in_x_third);
1701         int out_x4 = w;
1702         int in_x3 = src->get_w() - (out_x4 - out_x3);
1703         int in_x4 = src->get_w();
1705         int out_y3 = MAX(h - out_y_half, h - in_y_third);
1706         int out_y4 = h;
1707         int in_y3 = src->get_h() - (out_y4 - out_y3);
1708         int in_y4 = src->get_h();
1710 // Segment 1
1711         draw_pixmap(src,
1712                 x + out_x1, 
1713                 y + out_y1,
1714                 out_x2 - out_x1,
1715                 out_y2 - out_y1,
1716                 in_x1, 
1717                 in_y1, 
1718                 dst);
1721 // Segment 2 * n
1722         for(int i = out_x2; i < out_x3; i += in_x3 - in_x2)
1723         {
1724                 if(out_x3 - i > 0)
1725                 {
1726                         int w = MIN(in_x3 - in_x2, out_x3 - i);
1727                         draw_pixmap(src,
1728                                 x + i, 
1729                                 y + out_y1,
1730                                 w,
1731                                 out_y2 - out_y1,
1732                                 in_x2, 
1733                                 in_y1, 
1734                                 dst);
1735                 }
1736         }
1742 // Segment 3
1743         draw_pixmap(src,
1744                 x + out_x3, 
1745                 y + out_y1,
1746                 out_x4 - out_x3,
1747                 out_y2 - out_y1,
1748                 in_x3, 
1749                 in_y1, 
1750                 dst);
1754 // Segment 4 * n
1755         for(int i = out_y2; i < out_y3; i += in_y3 - in_y2)
1756         {
1757                 if(out_y3 - i > 0)
1758                 {
1759                         int h = MIN(in_y3 - in_y2, out_y3 - i);
1760                         draw_pixmap(src,
1761                                 x + out_x1, 
1762                                 y + i,
1763                                 out_x2 - out_x1,
1764                                 h,
1765                                 in_x1, 
1766                                 in_y2, 
1767                                 dst);
1768                 }
1769         }
1772 // Segment 5 * n * n
1773         for(int i = out_y2; i < out_y3; i += in_y3 - in_y2 /* in_y_third */)
1774         {
1775                 if(out_y3 - i > 0)
1776                 {
1777                         int h = MIN(in_y3 - in_y2 /* in_y_third */, out_y3 - i);
1780                         for(int j = out_x2; j < out_x3; j += in_x3 - in_x2 /* in_x_third */)
1781                         {
1782                                 int w = MIN(in_x3 - in_x2 /* in_x_third */, out_x3 - j);
1783                                 if(out_x3 - j > 0)
1784                                         draw_pixmap(src,
1785                                                 x + j, 
1786                                                 y + i,
1787                                                 w,
1788                                                 h,
1789                                                 in_x2, 
1790                                                 in_y2, 
1791                                                 dst);
1792                         }
1793                 }
1794         }
1796 // Segment 6 * n
1797         for(int i = out_y2; i < out_y3; i += in_y3 - in_y2)
1798         {
1799                 if(out_y3 - i > 0)
1800                 {
1801                         int h = MIN(in_y3 - in_y2, out_y3 - i);
1802                         draw_pixmap(src,
1803                                 x + out_x3, 
1804                                 y + i,
1805                                 out_x4 - out_x3,
1806                                 h,
1807                                 in_x3, 
1808                                 in_y2, 
1809                                 dst);
1810                 }
1811         }
1816 // Segment 7
1817         draw_pixmap(src,
1818                 x + out_x1, 
1819                 y + out_y3,
1820                 out_x2 - out_x1,
1821                 out_y4 - out_y3,
1822                 in_x1, 
1823                 in_y3, 
1824                 dst);
1827 // Segment 8 * n
1828         for(int i = out_x2; i < out_x3; i += in_x3 - in_x2)
1829         {
1830                 if(out_x3 - i > 0)
1831                 {
1832                         int w = MIN(in_x3 - in_y2, out_x3 - i);
1833                         draw_pixmap(src,
1834                                 x + i, 
1835                                 y + out_y3,
1836                                 w,
1837                                 out_y4 - out_y3,
1838                                 in_x2, 
1839                                 in_y3, 
1840                                 dst);
1841                 }
1842         }
1846 // Segment 9
1847         draw_pixmap(src,
1848                 x + out_x3, 
1849                 y + out_y3,
1850                 out_x4 - out_x3,
1851                 out_y4 - out_y3,
1852                 in_x3, 
1853                 in_y3, 
1854                 dst);
1858 void BC_WindowBase::draw_9segment(int x, 
1859                 int y, 
1860                 int w,
1861                 int h,
1862                 VFrame *src,
1863                 BC_Pixmap *dst)
1865         if(w <= 0 || h <= 0) return;
1867         int in_x_third = src->get_w() / 3;
1868         int in_y_third = src->get_h() / 3;
1869         int out_x_half = w / 2;
1870         int out_y_half = h / 2;
1872         int in_x1 = 0;
1873         int in_y1 = 0;
1874         int out_x1 = 0;
1875         int out_y1 = 0;
1876         int in_x2 = MIN(in_x_third, out_x_half);
1877         int in_y2 = MIN(in_y_third, out_y_half);
1878         int out_x2 = in_x2;
1879         int out_y2 = in_y2;
1881         int out_x3 = MAX(w - out_x_half, w - in_x_third);
1882         int out_x4 = w;
1883         int in_x3 = src->get_w() - (out_x4 - out_x3);
1884         int in_x4 = src->get_w();
1886         int out_y3 = MAX(h - out_y_half, h - in_y_third);
1887         int out_y4 = h;
1888         int in_y3 = src->get_h() - (out_y4 - out_y3);
1889         int in_y4 = src->get_h();
1891 //printf("PFCFrame::draw_9segment 1 %d %d %d %d\n", out_x1, out_x2, out_x3, out_x4);
1892 //printf("PFCFrame::draw_9segment 2 %d %d %d %d\n", in_x1, in_x2, in_x3, in_x4);
1893 //printf("PFCFrame::draw_9segment 2 %d %d %d %d\n", in_y1, in_y2, in_y3, in_y4);
1895         if(!temp_bitmap) temp_bitmap = new BC_Bitmap(top_level, 
1896                 src->get_w(), 
1897                 src->get_h(), 
1898                 get_color_model(), 
1899                 0);
1900         temp_bitmap->match_params(src->get_w(), 
1901                 src->get_h(), 
1902                 get_color_model(), 
1903                 0);
1904         temp_bitmap->read_frame(src, 
1905                 0, 
1906                 0, 
1907                 src->get_w(), 
1908                 src->get_h());
1910 // Segment 1
1911         draw_bitmap(temp_bitmap,
1912                 0,
1913                 x + out_x1, 
1914                 y + out_y1,
1915                 out_x2 - out_x1,
1916                 out_y2 - out_y1,
1917                 in_x1, 
1918                 in_y1, 
1919                 in_x2 - in_x1,
1920                 in_y2 - in_y1, 
1921                 dst);
1924 // Segment 2 * n
1925         for(int i = out_x2; i < out_x3; i += in_x3 - in_x2)
1926         {
1927                 if(out_x3 - i > 0)
1928                 {
1929                         int w = MIN(in_x3 - in_x2, out_x3 - i);
1930                         draw_bitmap(temp_bitmap,
1931                                 0,
1932                                 x + i, 
1933                                 y + out_y1,
1934                                 w,
1935                                 out_y2 - out_y1,
1936                                 in_x2, 
1937                                 in_y1, 
1938                                 w,
1939                                 in_y2 - in_y1, 
1940                                 dst);
1941                 }
1942         }
1948 // Segment 3
1949         draw_bitmap(temp_bitmap,
1950                 0,
1951                 x + out_x3, 
1952                 y + out_y1,
1953                 out_x4 - out_x3,
1954                 out_y2 - out_y1,
1955                 in_x3, 
1956                 in_y1, 
1957                 in_x4 - in_x3,
1958                 in_y2 - in_y1, 
1959                 dst);
1963 // Segment 4 * n
1964         for(int i = out_y2; i < out_y3; i += in_y3 - in_y2)
1965         {
1966                 if(out_y3 - i > 0)
1967                 {
1968                         int h = MIN(in_y3 - in_y2, out_y3 - i);
1969                         draw_bitmap(temp_bitmap,
1970                                 0,
1971                                 x + out_x1, 
1972                                 y + i,
1973                                 out_x2 - out_x1,
1974                                 h,
1975                                 in_x1, 
1976                                 in_y2, 
1977                                 in_x2 - in_x1,
1978                                 h, 
1979                                 dst);
1980                 }
1981         }
1984 // Segment 5 * n * n
1985         for(int i = out_y2; i < out_y3; i += in_y3 - in_y2)
1986         {
1987                 if(out_y3 - i > 0)
1988                 {
1989                         int h = MIN(in_y3 - in_y2, out_y3 - i);
1992                         for(int j = out_x2; j < out_x3; j += in_x3 - in_x2)
1993                         {
1994                                 int w = MIN(in_x3 - in_x2, out_x3 - j);
1995                                 if(out_x3 - j > 0)
1996                                         draw_bitmap(temp_bitmap,
1997                                                 0,
1998                                                 x + j, 
1999                                                 y + i,
2000                                                 w,
2001                                                 h,
2002                                                 in_x2, 
2003                                                 in_y2, 
2004                                                 w,
2005                                                 h, 
2006                                                 dst);
2007                         }
2008                 }
2009         }
2011 // Segment 6 * n
2012         for(int i = out_y2; i < out_y3; i += in_y_third)
2013         {
2014                 if(out_y3 - i > 0)
2015                 {
2016                         int h = MIN(in_y_third, out_y3 - i);
2017                         draw_bitmap(temp_bitmap,
2018                                 0,
2019                                 x + out_x3, 
2020                                 y + i,
2021                                 out_x4 - out_x3,
2022                                 h,
2023                                 in_x3, 
2024                                 in_y2, 
2025                                 in_x4 - in_x3,
2026                                 h, 
2027                                 dst);
2028                 }
2029         }
2034 // Segment 7
2035         draw_bitmap(temp_bitmap,
2036                 0,
2037                 x + out_x1, 
2038                 y + out_y3,
2039                 out_x2 - out_x1,
2040                 out_y4 - out_y3,
2041                 in_x1, 
2042                 in_y3, 
2043                 in_x2 - in_x1,
2044                 in_y4 - in_y3, 
2045                 dst);
2048 // Segment 8 * n
2049         for(int i = out_x2; i < out_x3; i += in_x_third)
2050         {
2051                 if(out_x3 - i > 0)
2052                 {
2053                         int w = MIN(in_x_third, out_x3 - i);
2054                         draw_bitmap(temp_bitmap,
2055                                 0,
2056                                 x + i, 
2057                                 y + out_y3,
2058                                 w,
2059                                 out_y4 - out_y3,
2060                                 in_x2, 
2061                                 in_y3, 
2062                                 w,
2063                                 in_y4 - in_y3, 
2064                                 dst);
2065                 }
2066         }
2070 // Segment 9
2071         draw_bitmap(temp_bitmap,
2072                 0,
2073                 x + out_x3, 
2074                 y + out_y3,
2075                 out_x4 - out_x3,
2076                 out_y4 - out_y3,
2077                 in_x3, 
2078                 in_y3, 
2079                 in_x4 - in_x3,
2080                 in_y4 - in_y3, 
2081                 dst);
2093 //      Local Variables:
2094 //      mode: C++
2095 //      c-file-style: "linux"
2096 //      End: