Back to index

texmacs  1.0.7.15
x_shadow.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : x_shadow.cpp
00004 * DESCRIPTION: Off-screen drawables under X
00005 * COPYRIGHT  : (C) 2005  Joris van der Hoeven
00006 *******************************************************************************
00007 * This software falls under the GNU general public license version 3 or later.
00008 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
00009 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
00010 ******************************************************************************/
00011 
00012 #include "X11/x_window.hpp"
00013 
00014 /******************************************************************************
00015 * Copying regions
00016 ******************************************************************************/
00017 
00018 void
00019 x_drawable_rep::fetch (SI x1, SI y1, SI x2, SI y2, renderer ren, SI x, SI y) {
00020   ASSERT (ren != NULL, "invalid situation");
00021   if (ren->is_printer ()) return;
00022   x_drawable_rep* src= ren->as_x_drawable ();
00023   if (src->win == win && x1 == x && y1 == y) return;
00024   outer_round (x1, y1, x2, y2);
00025   SI X1= x1, Y1= y1;
00026   x1= max (x1, cx1- ox);
00027   y1= max (y1, cy1- oy);
00028   x2= min (x2, cx2- ox);
00029   y2= min (y2, cy2- oy);
00030   src->decode (X1, Y1);
00031   src->decode (x1, y1);
00032   src->decode (x2, y2);
00033   decode (x, y);
00034   x += x1 - X1;
00035   y += y2 - Y1;
00036   if (x1<x2 && y2<y1)
00037     XCopyArea (dpy, src->win, win, gc, x, y, x2-x1, y1-y2, x1, y2);
00038 }
00039 
00040 /******************************************************************************
00041 * Shadowing
00042 ******************************************************************************/
00043 
00044 void
00045 x_drawable_rep::new_shadow (renderer& ren) {
00046   SI mw, mh, sw, sh;
00047   ((renderer) this) -> get_extents (mw, mh);
00048   if (ren != NULL) {
00049     ren->get_extents (sw, sh);
00050     if (sw == mw && sh == mh) return;
00051     //cout << "Old: " << sw << ", " << sh << "\n";
00052     delete_shadow (ren);
00053   }
00054   //cout << "Create " << mw << ", " << mh << "\n";
00055   ren= (renderer) tm_new<x_drawable_rep> (gui, mw, mh);
00056 }
00057 
00058 void
00059 x_drawable_rep::delete_shadow (renderer& ren) {
00060   if (ren != NULL) {
00061     tm_delete (ren->as_x_drawable ());
00062     ren= NULL;
00063   }
00064 }
00065 
00066 void
00067 x_drawable_rep::get_shadow (renderer ren, SI x1, SI y1, SI x2, SI y2) {
00068   // FIXME: we should use the routine fetch later
00069   ASSERT (ren != NULL, "invalid renderer");
00070   if (ren->is_printer ()) return;
00071   x_drawable_rep* shadow= ren->as_x_drawable ();
00072   outer_round (x1, y1, x2, y2);
00073   x1= max (x1, cx1- ox);
00074   y1= max (y1, cy1- oy);
00075   x2= min (x2, cx2- ox);
00076   y2= min (y2, cy2- oy);
00077   shadow->ox= ox;
00078   shadow->oy= oy;
00079   shadow->cx1= x1+ ox;
00080   shadow->cy1= y1+ oy;
00081   shadow->cx2= x2+ ox;
00082   shadow->cy2= y2+ oy;
00083   shadow->master= this;
00084   decode (x1, y1);
00085   decode (x2, y2);
00086   if (x1<x2 && y2<y1)
00087     XCopyArea (dpy, win, shadow->win, gc, x1, y2, x2-x1, y1-y2, x1, y2);
00088 }
00089 
00090 void
00091 x_drawable_rep::put_shadow (renderer ren, SI x1, SI y1, SI x2, SI y2) {
00092   // FIXME: we should use the routine fetch later
00093   ASSERT (ren != NULL, "invalid renderer");
00094   if (ren->is_printer ()) return;
00095   x_drawable_rep* shadow= ren->as_x_drawable ();
00096   outer_round (x1, y1, x2, y2);
00097   x1= max (x1, cx1- ox);
00098   y1= max (y1, cy1- oy);
00099   x2= min (x2, cx2- ox);
00100   y2= min (y2, cy2- oy);
00101   decode (x1, y1);
00102   decode (x2, y2);
00103   if (x1<x2 && y2<y1)
00104     XCopyArea (dpy, shadow->win, win, gc, x1, y2, x2-x1, y1-y2, x1, y2);
00105 }
00106 
00107 void
00108 x_drawable_rep::apply_shadow (SI x1, SI y1, SI x2, SI y2) {
00109   if (master == NULL) return;
00110   outer_round (x1, y1, x2, y2);
00111   decode (x1, y1);
00112   decode (x2, y2);
00113   master->as_x_drawable()->encode (x1, y1);
00114   master->as_x_drawable()->encode (x2, y2);
00115   master->put_shadow (this, x1, y1, x2, y2);
00116 }