r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / guicast / bcpixmap.C
blob14e42b2bec12c997b27db4e0c4582bac7ea9c186
1 #include "bcbitmap.h"
2 #include "bcpixmap.h"
3 #include "bcwindowbase.h"
4 #include "vframe.h"
6 BC_Pixmap::BC_Pixmap(BC_WindowBase *parent_window, 
7         VFrame *frame, 
8         int mode,
9         int icon_offset)
11         BC_Bitmap *opaque_bitmap, *alpha_bitmap, *mask_bitmap;
12         this->mode = mode;
14 // Temporary bitmaps
15         if(use_opaque())
16         {
17                 opaque_bitmap = new BC_Bitmap(parent_window, 
18                                         frame->get_w(), 
19                                         frame->get_h(), 
20                                         parent_window->get_color_model(), 
21                                         0);
22                 opaque_bitmap->set_bg_color(parent_window->get_bg_color());
23                 opaque_bitmap->read_frame(frame, 
24                         0, 
25                         0, 
26                         frame->get_w(), 
27                         frame->get_h());
28         }
30         if(use_alpha())
31         {
32                 alpha_bitmap = new BC_Bitmap(parent_window, 
33                                 frame->get_w(), 
34                                 frame->get_h(), 
35                                 BC_TRANSPARENCY, 
36                                 0);
38                 alpha_bitmap->read_frame(frame, 
39                         0, 
40                         0, 
41                         frame->get_w(), 
42                         frame->get_h());
43         }
45         initialize(parent_window, 
46                 frame->get_w(), 
47                 frame->get_h(), 
48                 mode);
50         if(use_opaque())
51         {
52                 opaque_bitmap->write_drawable(opaque_pixmap, 
53                                                                 top_level->gc,
54                                                                 0, 
55                                                                 0, 
56                                                                 0, 
57                                                                 0, 
58                                                                 w, 
59                                                                 h, 
60                                                                 1);
61                 delete opaque_bitmap;
62         }
64         if(use_alpha())
65         {
66                 alpha_bitmap->write_drawable(alpha_pixmap, 
67                         copy_gc, 
68                         0, 
69                         0, 
70                         icon_offset ? 2 : 0, 
71                         icon_offset ? 2 : 0, 
72                         w, 
73                         h, 
74                         1);
75                 delete alpha_bitmap;
76                 XFreeGC(top_level->display, copy_gc);
78                 XSetClipMask(top_level->display, alpha_gc, alpha_pixmap);
79         }
82 BC_Pixmap::BC_Pixmap(BC_WindowBase *parent_window, int w, int h)
84         initialize(parent_window, w, h, PIXMAP_OPAQUE);
88 BC_Pixmap::~BC_Pixmap()
90         if(use_opaque())
91         {
92                 XFreePixmap(top_level->display, opaque_pixmap);
93         }
95         if(use_alpha())
96         {
97                 XFreeGC(top_level->display, alpha_gc);
98                 XFreePixmap(top_level->display, alpha_pixmap);
99         }
102 int BC_Pixmap::initialize(BC_WindowBase *parent_window, int w, int h, int mode)
104 //printf("BC_Pixmap::initialize 1\n");
105         unsigned long gcmask = GCGraphicsExposures | GCForeground | GCBackground | GCFunction;
106         XGCValues gcvalues;
107         gcvalues.graphics_exposures = 0;        // prevent expose events for every redraw
108         gcvalues.foreground = 0;
109         gcvalues.background = 1;
110         gcvalues.function = GXcopy;
112 //printf("BC_Pixmap::initialize 1\n");
113         this->w = w;
114         this->h = h;
115         this->parent_window = parent_window;
116         this->mode = mode;
117         top_level = parent_window->top_level;
119 //printf("BC_Pixmap::initialize 1\n");
120         if(use_opaque())
121         {
122                 opaque_pixmap = XCreatePixmap(top_level->display, 
123                         top_level->win, 
124                         w, 
125                         h, 
126                         top_level->default_depth);
127         }
129 //printf("BC_Pixmap::initialize 1\n");
130         if(use_alpha())
131         {
132                 alpha_pixmap = XCreatePixmap(top_level->display, 
133                         top_level->win, 
134                         w, 
135                         h, 
136                         1);
138 //printf("BC_Pixmap::initialize 1\n");
139                 alpha_gc = XCreateGC(top_level->display, 
140                         top_level->win, 
141                         gcmask, 
142                         &gcvalues);
144 //printf("BC_Pixmap::initialize 1\n");
145                 copy_gc = XCreateGC(top_level->display,
146                         alpha_pixmap,
147                         gcmask,
148                         &gcvalues);
149         }
150         
151 //printf("BC_Pixmap::initialize 2\n");
152         return 0;
155 void BC_Pixmap::resize(int w, int h)
157         Pixmap new_pixmap = XCreatePixmap(top_level->display, 
158                         top_level->win, 
159                         w, 
160                         h, 
161                         top_level->default_depth);
162         XCopyArea(top_level->display,
163                 opaque_pixmap,
164                 new_pixmap,
165                 top_level->gc,
166                 0,
167                 0,
168                 get_w(),
169                 get_h(),
170                 0,
171                 0);
172         this->w = w;
173         this->h = h;
174         XFreePixmap(top_level->display, opaque_pixmap);
175         opaque_pixmap = new_pixmap;
179 void BC_Pixmap::copy_area(int x, int y, int w, int h, int x2, int y2)
181         XCopyArea(top_level->display,
182                 opaque_pixmap,
183                 opaque_pixmap,
184                 top_level->gc,
185                 x,
186                 y,
187                 w,
188                 h,
189                 x2,
190                 y2);
193 int BC_Pixmap::write_drawable(Drawable &pixmap, 
194                         int dest_x, 
195                         int dest_y,
196                         int dest_w,
197                         int dest_h,
198                         int src_x,
199                         int src_y)
201 //printf("BC_Pixmap::write_drawable 1\n");
202         if(dest_w < 0)
203         {
204                 dest_w = w;
205                 src_x = 0;
206         }
207         
208         if(dest_h < 0)
209         {
210                 dest_h = h;
211                 src_y = 0;
212         }
214         if(use_alpha())
215         {
216                 XSetClipOrigin(top_level->display, alpha_gc, dest_x - src_x, dest_y - src_y);
217                 XCopyArea(top_level->display, 
218                         this->opaque_pixmap, 
219                         pixmap, 
220                         alpha_gc, 
221                         src_x, 
222                         src_y, 
223                         dest_w, 
224                         dest_h, 
225                         dest_x, 
226                         dest_y);
227         }
228         else
229         if(use_opaque())
230         {
231                 XCopyArea(top_level->display, 
232                         this->opaque_pixmap, 
233                         pixmap, 
234                         top_level->gc, 
235                         src_x, 
236                         src_y, 
237                         dest_w, 
238                         dest_h, 
239                         dest_x, 
240                         dest_y);
241         }
242 //printf("BC_Pixmap::write_drawable 2\n");
244         return 0;
247 void BC_Pixmap::draw_vframe(VFrame *frame, 
248                 int dest_x, 
249                 int dest_y, 
250                 int dest_w, 
251                 int dest_h,
252                 int src_x,
253                 int src_y)
255         parent_window->draw_vframe(frame, 
256                 dest_x, 
257                 dest_y, 
258                 dest_w, 
259                 dest_h,
260                 src_x,
261                 src_y,
262                 0,
263                 0,
264                 this);
267 void BC_Pixmap::draw_pixmap(BC_Pixmap *pixmap, 
268         int dest_x, 
269         int dest_y,
270         int dest_w,
271         int dest_h,
272         int src_x,
273         int src_y)
275         pixmap->write_drawable(this->opaque_pixmap,
276                         dest_x, 
277                         dest_y,
278                         dest_w,
279                         dest_h,
280                         src_x,
281                         src_y);
294 int BC_Pixmap::get_w()
296         return w;
299 int BC_Pixmap::get_h()
301         return h;
304 int BC_Pixmap::get_w_fixed()
306         return w - 1;
309 int BC_Pixmap::get_h_fixed()
311         return h - 1;
314 Pixmap BC_Pixmap::get_pixmap()
316         return opaque_pixmap;
319 Pixmap BC_Pixmap::get_alpha()
321         return alpha_pixmap;
324 int BC_Pixmap::use_opaque()
326         return 1;
329 int BC_Pixmap::use_alpha()
331         return mode == PIXMAP_ALPHA;