As observed earlier, dragging an image outside the screen
leads to a crash.  Reason for this is the fact that the
call XGetImage only succeeds when the image is entirily
on the screen (not necessarily visible)

While fixing the functions involved I also changed
occurences of NSRect to XRectangle when the coordinates
are Xcoordinates.  This gets rid of a lot of floats and 
problems when using non-integer coordinates.

There are still a few (minor) problems left, all of
them in:

-[XGGState visibleRectForWindow:]

A)  I had to put a -1 on the size, otherwise 
        it would still fail in some circumstances.
        But I can not figure out why.

B)  It traverse the X windows list everytime,
        so this might be a performance hit.
        But I did not notice it.  
        
More serious is:

C)  It still might fail if between the invocation 
        of this method and the actual call to
        XGetImage.  
        I don't know enough about X programming
        to now how to solve this.

        I definitely need to find my XLib books
        again :-(


Wim Oudshoorn



This mail sould contain:

1. ChangeLog
2. Diff
3. a new file XGGeometry.h 
               


-----[ ChangeLog ]  ----------------------------------------------------

2001-11-17  Willem Rein Oudshoorn  <[EMAIL PROTECTED]>

        * xgps-devel/Source/XGGState.m 
        ([XGGState -visibleRectForWindow:]): new method
        ([XGGState -_compositeGState:sourcefromRect:fromRecttoPoint:toPointop:op]):
        cleaned up, replaced lots of floats with integers, fixed bug that
        caused a call to RGetXImage with wrong parameters.
        ([XGGState -DPSimage:]): cleaned up somewhat, replaced lots of
        floats with integers.

        * xgps-devel/Source/XGDrawingEngine.h (_bitmap_combine_alpha) 
        (_bitmap_combine_alpha): updated forward declaration.

        * xgps-devel/Source/XGContext.m: Changed emace editing mode from
        C++ to ObjectiveC

        * xgps-devel/Source/XGBitmap.m (_pixmap_combine_alpha) 
        (_bitmap_combine_alpha): Replaced floats with integers.

        * xgps-devel/Headers/gnustep/xgps/XGGeometry.h: new file

        * xgps/Headers/gnustep/xgps/XGGState.h: Added missing
        NSGraphicsContext.h include

/* -*- mode: ObjC -*-

   <title>XGGeometry</title>

   <abstract>Point and rectangle manipulations for X-structures</abstract>
   
   Written by:  <author name="Wim 
Oudshoorn"><email>[EMAIL PROTECTED]</email></author>
   Date: Nov, 2001
   
   This file is part of the GNU Objective C User Interface Library.

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.
   
   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.
   
   You should have received a copy of the GNU Library General Public
   License along with this library; if not, write to the Free
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
   */

/*
  This file implements the NSGeometry manipulation functions for
  the XPoint and XRectangle structures.

  So most code is copied from NSGeometry, with only the structs changed
*/

#ifndef _XGGeometry_h_INCLUDE
#define _XGGeometry_h_INCLUDE

#include <AppKit/NSAffineTransform.h>
#include <X11/Xlib.h>
#include "XGGState.h"


static inline XPoint
XGMakePoint (short x, short y)
{
  XPoint p;

  p.x = x;
  p.y = y;

  return p;
}

static inline XRectangle
XGMakeRect (short x, short y, unsigned short w, unsigned short h)
{
  XRectangle rect;

  rect.x = x;
  rect.y = y;
  rect.width = w;
  rect.height = h;

  return rect;
} 


static inline short
XGMinX (XRectangle aRect)
{
  return aRect.x;
}

static inline short
XGMinY (XRectangle aRect)
{
  return aRect.y;
}


static inline short
XGMaxX (XRectangle aRect)
{
  return aRect.x + aRect.width;
}

static inline short
XGMaxY (XRectangle aRect)
{
  return aRect.y + aRect.height;
}

static inline short
XGWidth (XRectangle aRect)
{
  return aRect.width;
}

static inline short
XGHeight (XRectangle aRect)
{
  return aRect.height;
}


static inline XRectangle
XGIntersectionRect (XRectangle aRect, XRectangle bRect)
{
  if (XGMaxX (aRect) <= XGMinX (bRect) || XGMaxX (bRect) <= XGMinX (aRect)
      || XGMaxY (aRect) <= XGMinY (bRect) || XGMaxY (bRect) <= XGMinY (aRect))
    {
      return XGMakeRect (0, 0, 0, 0);
    }
  else
    {
      XRectangle rect;

      if (XGMinX (aRect) <= XGMinX (bRect))
        rect.x = bRect.x;
      else
        rect.x = aRect.x;

      if (XGMaxX (aRect) >= XGMaxX (bRect))
        rect.width = XGMaxX (bRect) - rect.x;
      else
        rect.width = XGMaxX (aRect) - rect.x;

      if (XGMinY (aRect) <= XGMinY (bRect))
        rect.y = bRect.y;
      else
        rect.y = aRect.y;

      if (XGMaxY (aRect) >= XGMaxY (bRect))
        rect.height = XGMaxY (bRect) - rect.y;
      else
        rect.height = XGMaxY (aRect) - rect.y;

      return rect;
    }
}


static inline BOOL
XGIsEmptyRect (XRectangle aRect)
{
  if (aRect.width == 0 || aRect.height == 0)
    return YES;
  else
    return NO;
}


/* Quick floor using C casts <called gs_floor only to avoid clashes if
   math.h is included> - TODO - use floor from math.h if it won't make
   an appreciable difference on speed - will it ? */
static inline int gs_floor (float f)
{
  if (f >= 0)
    {
      return (int)f;
    }
  else
    {
      int g = (int)f;
      
      if (f - ((float)g) > 0)
        {
          return g - 1;
        }
      else
        {
          return g;
        }
    }
}

/*
 *      Inline functions to convert from OpenStep view coordinates or
 *      OpenStep window coordinates to X window coordinates.
 */
static inline XPoint
XGWindowPointToX (XGGState *s, NSPoint p)
{
  XPoint newPoint;

  newPoint.x = gs_floor(p.x + s->offset.x);

  newPoint.y = gs_floor(s->offset.y - p.y);

  return newPoint;
}

static inline XRectangle
XGWindowRectToX (XGGState *s, NSRect r)
{
  XRectangle newRect;

  newRect.x = gs_floor(r.origin.x + s->offset.x);
  /* We gs_floor the extreme points, and get the width as the difference */
  newRect.width = gs_floor(r.origin.x + s->offset.x + r.size.width) 
                  - newRect.x;

  newRect.y = gs_floor(s->offset.y - r.origin.y - r.size.height);
  newRect.height = gs_floor(s->offset.y - r.origin.y) - newRect.y;

  return newRect;
}

/*
 *      Inline functions to convert from OpenStep view coordinates or
 *      OpenStep window coordinates to X window coordinates.
 */

static inline XPoint
XGViewPointToX(XGGState *s, NSPoint p)
{
  p = [s->ctm pointInMatrixSpace: p];
  return XGWindowPointToX(s, p);
}

static inline XRectangle
XGViewRectToX(XGGState *s, NSRect r)
{
  r = [s->ctm rectInMatrixSpace: r];
  return XGWindowRectToX(s, r);
}

#endif  /* _XGGeometry_h_INCLUDE */

Attachment: cvs-diff-2-edited.gz
Description: xgps-diff

Reply via email to