00001 #include "bcbitmap.h"
00002 #include "bcpixmap.h"
00003 #include "bcwindowbase.h"
00004 #include "vframe.h"
00005
00006
00007 #include <unistd.h>
00008
00009 BC_Pixmap::BC_Pixmap(BC_WindowBase *parent_window,
00010 VFrame *frame,
00011 int mode,
00012 int icon_offset)
00013 {
00014 BC_Bitmap *opaque_bitmap, *alpha_bitmap, *mask_bitmap;
00015 if(frame->get_color_model() != BC_RGBA8888 &&
00016 mode == PIXMAP_ALPHA)
00017 mode = PIXMAP_OPAQUE;
00018 this->mode = mode;
00019
00020
00021 if(use_opaque())
00022 {
00023 opaque_bitmap = new BC_Bitmap(parent_window,
00024 frame->get_w(),
00025 frame->get_h(),
00026 parent_window->get_color_model(),
00027 0);
00028 opaque_bitmap->set_bg_color(parent_window->get_bg_color());
00029 opaque_bitmap->read_frame(frame,
00030 0,
00031 0,
00032 frame->get_w(),
00033 frame->get_h());
00034
00035 }
00036
00037 if(use_alpha())
00038 {
00039 alpha_bitmap = new BC_Bitmap(parent_window,
00040 frame->get_w(),
00041 frame->get_h(),
00042 BC_TRANSPARENCY,
00043 0);
00044
00045 if(frame->get_color_model() != BC_RGBA8888)
00046 printf("BC_Pixmap::BC_Pixmap: PIXMAP_ALPHA but frame doesn't have alpha.\n");
00047 alpha_bitmap->read_frame(frame,
00048 0,
00049 0,
00050 frame->get_w(),
00051 frame->get_h());
00052 }
00053
00054 initialize(parent_window,
00055 frame->get_w(),
00056 frame->get_h(),
00057 mode);
00058
00059 if(use_opaque())
00060 {
00061 opaque_bitmap->write_drawable(opaque_pixmap,
00062 top_level->gc,
00063 0,
00064 0,
00065 0,
00066 0,
00067 w,
00068 h,
00069 1);
00070 delete opaque_bitmap;
00071 }
00072
00073 if(use_alpha())
00074 {
00075 alpha_bitmap->write_drawable(alpha_pixmap,
00076 copy_gc,
00077 0,
00078 0,
00079 icon_offset ? 2 : 0,
00080 icon_offset ? 2 : 0,
00081 w,
00082 h,
00083 1);
00084 delete alpha_bitmap;
00085 XFreeGC(top_level->display, copy_gc);
00086
00087 XSetClipMask(top_level->display, alpha_gc, alpha_pixmap);
00088 }
00089 }
00090
00091 BC_Pixmap::BC_Pixmap(BC_WindowBase *parent_window, int w, int h)
00092 {
00093 initialize(parent_window, w, h, PIXMAP_OPAQUE);
00094 }
00095
00096
00097 BC_Pixmap::~BC_Pixmap()
00098 {
00099 if(use_opaque())
00100 {
00101 XFreePixmap(top_level->display, opaque_pixmap);
00102 }
00103
00104 if(use_alpha())
00105 {
00106 XFreeGC(top_level->display, alpha_gc);
00107 XFreePixmap(top_level->display, alpha_pixmap);
00108 }
00109 }
00110
00111 int BC_Pixmap::initialize(BC_WindowBase *parent_window, int w, int h, int mode)
00112 {
00113 unsigned long gcmask = GCGraphicsExposures | GCForeground | GCBackground | GCFunction;
00114 XGCValues gcvalues;
00115 gcvalues.graphics_exposures = 0;
00116 gcvalues.foreground = 0;
00117 gcvalues.background = 1;
00118 gcvalues.function = GXcopy;
00119
00120 this->w = w;
00121 this->h = h;
00122 this->parent_window = parent_window;
00123 this->mode = mode;
00124 top_level = parent_window->top_level;
00125
00126 if(use_opaque())
00127 {
00128 opaque_pixmap = XCreatePixmap(top_level->display,
00129 top_level->win,
00130 w,
00131 h,
00132 top_level->default_depth);
00133 #ifdef HAVE_XFT
00134 opaque_xft_draw = XftDrawCreate(top_level->display,
00135 opaque_pixmap,
00136 top_level->vis,
00137 top_level->cmap);
00138 #endif
00139 }
00140
00141 if(use_alpha())
00142 {
00143 alpha_pixmap = XCreatePixmap(top_level->display,
00144 top_level->win,
00145 w,
00146 h,
00147 1);
00148
00149 alpha_gc = XCreateGC(top_level->display,
00150 top_level->win,
00151 gcmask,
00152 &gcvalues);
00153
00154 copy_gc = XCreateGC(top_level->display,
00155 alpha_pixmap,
00156 gcmask,
00157 &gcvalues);
00158
00159 #ifdef HAVE_XFT
00160 alpha_xft_draw = XftDrawCreateBitmap(top_level->display,
00161 alpha_pixmap);
00162 #endif
00163 }
00164
00165 return 0;
00166 }
00167
00168 void BC_Pixmap::resize(int w, int h)
00169 {
00170 Pixmap new_pixmap = XCreatePixmap(top_level->display,
00171 top_level->win,
00172 w,
00173 h,
00174 top_level->default_depth);
00175 XCopyArea(top_level->display,
00176 opaque_pixmap,
00177 new_pixmap,
00178 top_level->gc,
00179 0,
00180 0,
00181 get_w(),
00182 get_h(),
00183 0,
00184 0);
00185 this->w = w;
00186 this->h = h;
00187 XFreePixmap(top_level->display, opaque_pixmap);
00188 opaque_pixmap = new_pixmap;
00189 }
00190
00191
00192 void BC_Pixmap::copy_area(int x, int y, int w, int h, int x2, int y2)
00193 {
00194 XCopyArea(top_level->display,
00195 opaque_pixmap,
00196 opaque_pixmap,
00197 top_level->gc,
00198 x,
00199 y,
00200 w,
00201 h,
00202 x2,
00203 y2);
00204 }
00205
00206 int BC_Pixmap::write_drawable(Drawable &pixmap,
00207 int dest_x,
00208 int dest_y,
00209 int dest_w,
00210 int dest_h,
00211 int src_x,
00212 int src_y)
00213 {
00214
00215 if(dest_w < 0)
00216 {
00217 dest_w = w;
00218 src_x = 0;
00219 }
00220
00221 if(dest_h < 0)
00222 {
00223 dest_h = h;
00224 src_y = 0;
00225 }
00226
00227 if(use_alpha())
00228 {
00229 XSetClipOrigin(top_level->display, alpha_gc, dest_x - src_x, dest_y - src_y);
00230 XCopyArea(top_level->display,
00231 this->opaque_pixmap,
00232 pixmap,
00233 alpha_gc,
00234 src_x,
00235 src_y,
00236 dest_w,
00237 dest_h,
00238 dest_x,
00239 dest_y);
00240 }
00241 else
00242 if(use_opaque())
00243 {
00244 XCopyArea(top_level->display,
00245 this->opaque_pixmap,
00246 pixmap,
00247 top_level->gc,
00248 src_x,
00249 src_y,
00250 dest_w,
00251 dest_h,
00252 dest_x,
00253 dest_y);
00254 }
00255
00256
00257 return 0;
00258 }
00259
00260 void BC_Pixmap::draw_vframe(VFrame *frame,
00261 int dest_x,
00262 int dest_y,
00263 int dest_w,
00264 int dest_h,
00265 int src_x,
00266 int src_y)
00267 {
00268 parent_window->draw_vframe(frame,
00269 dest_x,
00270 dest_y,
00271 dest_w,
00272 dest_h,
00273 src_x,
00274 src_y,
00275 0,
00276 0,
00277 this);
00278 }
00279
00280 void BC_Pixmap::draw_pixmap(BC_Pixmap *pixmap,
00281 int dest_x,
00282 int dest_y,
00283 int dest_w,
00284 int dest_h,
00285 int src_x,
00286 int src_y)
00287 {
00288 pixmap->write_drawable(this->opaque_pixmap,
00289 dest_x,
00290 dest_y,
00291 dest_w,
00292 dest_h,
00293 src_x,
00294 src_y);
00295 }
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307 int BC_Pixmap::get_w()
00308 {
00309 return w;
00310 }
00311
00312 int BC_Pixmap::get_h()
00313 {
00314 return h;
00315 }
00316
00317 int BC_Pixmap::get_w_fixed()
00318 {
00319 return w - 1;
00320 }
00321
00322 int BC_Pixmap::get_h_fixed()
00323 {
00324 return h - 1;
00325 }
00326
00327 Pixmap BC_Pixmap::get_pixmap()
00328 {
00329 return opaque_pixmap;
00330 }
00331
00332 Pixmap BC_Pixmap::get_alpha()
00333 {
00334 return alpha_pixmap;
00335 }
00336
00337 int BC_Pixmap::use_opaque()
00338 {
00339 return 1;
00340 }
00341
00342 int BC_Pixmap::use_alpha()
00343 {
00344 return mode == PIXMAP_ALPHA;
00345 }