home *** CD-ROM | disk | FTP | other *** search
/ Geek 6 / Geek-006.iso / linux / video / xmovie-1.5.3.tar.gz / xmovie-1.5.3.tar / xmovie-1.5.3 / guicast / bcpixmap.C < prev    next >
C/C++ Source or Header  |  2000-11-29  |  5KB  |  323 lines

  1. #include "bcbitmap.h"
  2. #include "bcpixmap.h"
  3. #include "bcwindowbase.h"
  4. #include "vframe.h"
  5.  
  6. BC_Pixmap::BC_Pixmap(BC_WindowBase *parent_window, 
  7.     VFrame *frame, 
  8.     int mode,
  9.     int icon_offset)
  10. {
  11.     BC_Bitmap *opaque_bitmap, *alpha_bitmap, *mask_bitmap;
  12.     this->mode = mode;
  13.  
  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.             1);
  29.     }
  30.  
  31.     if(use_alpha())
  32.     {
  33.         alpha_bitmap = new BC_Bitmap(parent_window, 
  34.                 frame->get_w(), 
  35.                 frame->get_h(), 
  36.                 BC_TRANSPARENCY, 
  37.                 0);
  38.  
  39.         alpha_bitmap->read_frame(frame, 
  40.             0, 
  41.             0, 
  42.             frame->get_w(), 
  43.             frame->get_h(), 
  44.             1);
  45.     }
  46.  
  47.     initialize(parent_window, 
  48.         frame->get_w(), 
  49.         frame->get_h(), 
  50.         mode);
  51.  
  52.     if(use_opaque())
  53.     {
  54.         opaque_bitmap->write_drawable(opaque_pixmap, 
  55.                                 top_level->gc,
  56.                                 0, 
  57.                                 0, 
  58.                                 0, 
  59.                                 0, 
  60.                                 w, 
  61.                                 h, 
  62.                                 1);
  63.         delete opaque_bitmap;
  64.     }
  65.  
  66.     if(use_alpha())
  67.     {
  68.         alpha_bitmap->write_drawable(alpha_pixmap, 
  69.             copy_gc, 
  70.             0, 
  71.             0, 
  72.             icon_offset ? 2 : 0, 
  73.             icon_offset ? 2 : 0, 
  74.             w, 
  75.             h, 
  76.             1);
  77.         delete alpha_bitmap;
  78.         XFreeGC(top_level->display, copy_gc);
  79.  
  80.         XSetClipMask(top_level->display, alpha_gc, alpha_pixmap);
  81.     }
  82. }
  83.  
  84. BC_Pixmap::BC_Pixmap(BC_WindowBase *parent_window, int w, int h)
  85. {
  86.     initialize(parent_window, w, h, PIXMAP_OPAQUE);
  87. }
  88.  
  89. BC_Pixmap::~BC_Pixmap()
  90. {
  91.     if(use_opaque())
  92.     {
  93.         XFreePixmap(top_level->display, opaque_pixmap);
  94.     }
  95.  
  96.     if(use_alpha())
  97.     {
  98.         XFreeGC(top_level->display, alpha_gc);
  99.         XFreePixmap(top_level->display, alpha_pixmap);
  100.     }
  101. }
  102.  
  103. int BC_Pixmap::initialize(BC_WindowBase *parent_window, int w, int h, int mode)
  104. {
  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;
  111.  
  112.     this->w = w;
  113.     this->h = h;
  114.     this->parent_window = parent_window;
  115.     this->mode = mode;
  116.     top_level = parent_window->top_level;
  117.  
  118.     if(use_opaque())
  119.     {
  120.         opaque_pixmap = XCreatePixmap(top_level->display, 
  121.             top_level->win, 
  122.             w, 
  123.             h, 
  124.             top_level->default_depth);
  125.     }
  126.  
  127.     if(use_alpha())
  128.     {
  129.         alpha_pixmap = XCreatePixmap(top_level->display, 
  130.             top_level->win, 
  131.             w, 
  132.             h, 
  133.             1);
  134.  
  135.         alpha_gc = XCreateGC(top_level->display, 
  136.             top_level->win, 
  137.             gcmask, 
  138.             &gcvalues);
  139.  
  140.         copy_gc = XCreateGC(top_level->display,
  141.             alpha_pixmap,
  142.             gcmask,
  143.             &gcvalues);
  144.     }
  145.     
  146.     return 0;
  147. }
  148.  
  149. void BC_Pixmap::resize(int w, int h)
  150. {
  151.     Pixmap new_pixmap = XCreatePixmap(top_level->display, 
  152.             top_level->win, 
  153.             w, 
  154.             h, 
  155.             top_level->default_depth);
  156.     XCopyArea(top_level->display,
  157.         opaque_pixmap,
  158.         new_pixmap,
  159.         top_level->gc,
  160.         0,
  161.         0,
  162.         get_w(),
  163.         get_h(),
  164.         0,
  165.         0);
  166.     this->w = w;
  167.     this->h = h;
  168.     XFreePixmap(top_level->display, opaque_pixmap);
  169.     opaque_pixmap = new_pixmap;
  170. }
  171.  
  172.  
  173. void BC_Pixmap::copy_area(int x, int y, int w, int h, int x2, int y2)
  174. {
  175.     XCopyArea(top_level->display,
  176.         opaque_pixmap,
  177.         opaque_pixmap,
  178.         top_level->gc,
  179.         x,
  180.         y,
  181.         w,
  182.         h,
  183.         x2,
  184.         y2);
  185. }
  186.  
  187. int BC_Pixmap::write_drawable(Drawable &pixmap, 
  188.             int dest_x, 
  189.             int dest_y,
  190.             int dest_w,
  191.             int dest_h,
  192.             int src_x,
  193.             int src_y)
  194. {
  195.     if(dest_w < 0)
  196.     {
  197.         dest_w = w;
  198.         src_x = 0;
  199.     }
  200.     
  201.     if(dest_h < 0)
  202.     {
  203.         dest_h = h;
  204.         src_y = 0;
  205.     }
  206.  
  207.     if(use_alpha())
  208.     {
  209.         XSetClipOrigin(top_level->display, alpha_gc, dest_x, dest_y);
  210.         XCopyArea(top_level->display, 
  211.             this->opaque_pixmap, 
  212.             pixmap, 
  213.             alpha_gc, 
  214.             src_x, 
  215.             src_y, 
  216.             dest_w, 
  217.             dest_h, 
  218.             dest_x, 
  219.             dest_y);
  220.     }
  221.     else
  222.     if(use_opaque())
  223.     {
  224.         XCopyArea(top_level->display, 
  225.             this->opaque_pixmap, 
  226.             pixmap, 
  227.             top_level->gc, 
  228.             src_x, 
  229.             src_y, 
  230.             dest_w, 
  231.             dest_h, 
  232.             dest_x, 
  233.             dest_y);
  234.     }
  235.  
  236.     return 0;
  237. }
  238.  
  239. void BC_Pixmap::draw_vframe(VFrame *frame, 
  240.         int dest_x, 
  241.         int dest_y, 
  242.         int dest_w, 
  243.         int dest_h,
  244.         int src_x,
  245.         int src_y)
  246. {
  247.     parent_window->draw_vframe(frame, 
  248.         dest_x, 
  249.         dest_y, 
  250.         dest_w, 
  251.         dest_h,
  252.         src_x,
  253.         src_y,
  254.         this);
  255. }
  256.  
  257. void BC_Pixmap::draw_pixmap(BC_Pixmap *pixmap, 
  258.     int dest_x, 
  259.     int dest_y,
  260.     int dest_w,
  261.     int dest_h,
  262.     int src_x,
  263.     int src_y)
  264. {
  265.     pixmap->write_drawable(this->opaque_pixmap,
  266.             dest_x, 
  267.             dest_y,
  268.             dest_w,
  269.             dest_h,
  270.             src_x,
  271.             src_y);
  272. }
  273.  
  274.  
  275.  
  276.  
  277.  
  278.  
  279.  
  280.  
  281.  
  282.  
  283.  
  284. int BC_Pixmap::get_w()
  285. {
  286.     return w;
  287. }
  288.  
  289. int BC_Pixmap::get_h()
  290. {
  291.     return h;
  292. }
  293.  
  294. int BC_Pixmap::get_w_fixed()
  295. {
  296.     return w - 1;
  297. }
  298.  
  299. int BC_Pixmap::get_h_fixed()
  300. {
  301.     return h - 1;
  302. }
  303.  
  304. Pixmap BC_Pixmap::get_pixmap()
  305. {
  306.     return opaque_pixmap;
  307. }
  308.  
  309. Pixmap BC_Pixmap::get_alpha()
  310. {
  311.     return alpha_pixmap;
  312. }
  313.  
  314. int BC_Pixmap::use_opaque()
  315. {
  316.     return 1;
  317. }
  318.  
  319. int BC_Pixmap::use_alpha()
  320. {
  321.     return mode == PIXMAP_ALPHA;
  322. }
  323.