Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXPoint.h

Go to the documentation of this file.
00001 /********************************************************************************
00002 *                                                                               *
00003 *                             P o i n t    C l a s s                            *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 1994,2006 by Jeroen van der Zijp.   All Rights Reserved.        *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or                 *
00009 * modify it under the terms of the GNU Lesser General Public                    *
00010 * License as published by the Free Software Foundation; either                  *
00011 * version 2.1 of the License, or (at your option) any later version.            *
00012 *                                                                               *
00013 * This library is distributed in the hope that it will be useful,               *
00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU             *
00016 * Lesser General Public License for more details.                               *
00017 *                                                                               *
00018 * You should have received a copy of the GNU Lesser General Public              *
00019 * License along with this library; if not, write to the Free Software           *
00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.    *
00021 *********************************************************************************
00022 * $Id: FXPoint.h,v 1.13 2006/01/22 17:58:07 fox Exp $                           *
00023 ********************************************************************************/
00024 #ifndef FXPOINT_H
00025 #define FXPOINT_H
00026 
00027 #ifndef FXSIZE_H
00028 #include "FXSize.h"
00029 #endif
00030 
00031 namespace FX {
00032 
00033 
00034 /// Point
00035 class FXAPI FXPoint {
00036 public:
00037   FXshort x;
00038   FXshort y;
00039 public:
00040 
00041   /// Constructors
00042   FXPoint(){ }
00043   FXPoint(const FXSize& s):x(s.w),y(s.h){ }
00044   FXPoint(const FXPoint& p):x(p.x),y(p.y){ }
00045   FXPoint(FXshort xx,FXshort yy):x(xx),y(yy){ }
00046 
00047   /// Test if zero
00048   bool operator!() const { return x==0 && y==0; }
00049 
00050   /// Equality
00051   bool operator==(const FXPoint& p) const { return x==p.x && y==p.y; }
00052   bool operator!=(const FXPoint& p) const { return x!=p.x || y!=p.y; }
00053 
00054   /// Assignment
00055   FXPoint& operator=(const FXPoint& p){ x=p.x; y=p.y; return *this; }
00056 
00057   /// Set value from another point
00058   FXPoint& set(const FXPoint& p){ x=p.x; y=p.y; return *this; }
00059 
00060   /// Set value from components
00061   FXPoint& set(FXshort xx,FXshort yy){ x=xx; y=yy; return *this; }
00062 
00063   /// Assignment operators
00064   FXPoint& operator+=(const FXPoint& p){ x+=p.x; y+=p.y; return *this; }
00065   FXPoint& operator-=(const FXPoint& p){ x-=p.x; y-=p.y; return *this; }
00066   FXPoint& operator*=(FXshort c){ x*=c; y*=c; return *this; }
00067   FXPoint& operator/=(FXshort c){ x/=c; y/=c; return *this; }
00068 
00069   /// Negation
00070   FXPoint operator-(){ return FXPoint(-x,-y); }
00071 
00072   /// Addition operators
00073   FXPoint operator+(const FXPoint& p) const { return FXPoint(x+p.x,y+p.y); }
00074   FXPoint operator-(const FXPoint& p) const { return FXPoint(x-p.x,y-p.y); }
00075 
00076   /// Scale operators
00077   friend inline FXPoint operator*(const FXPoint& p,FXshort c);
00078   friend inline FXPoint operator*(FXshort c,const FXPoint& p);
00079   friend inline FXPoint operator/(const FXPoint& p,FXshort c);
00080   friend inline FXPoint operator/(FXshort c,const FXPoint& p);
00081 
00082   /// Save object to a stream
00083   friend FXAPI FXStream& operator<<(FXStream& store,const FXPoint& p);
00084 
00085   /// Load object from a stream
00086   friend FXAPI FXStream& operator>>(FXStream& store,FXPoint& p);
00087   };
00088 
00089 
00090 inline FXPoint operator*(const FXPoint& p,FXshort c){ return FXPoint(p.x*c,p.y*c); }
00091 inline FXPoint operator*(FXshort c,const FXPoint& p){ return FXPoint(c*p.x,c*p.y); }
00092 inline FXPoint operator/(const FXPoint& p,FXshort c){ return FXPoint(p.x/c,p.y/c); }
00093 inline FXPoint operator/(FXshort c,const FXPoint& p){ return FXPoint(c/p.x,c/p.y); }
00094 
00095 extern FXAPI FXStream& operator<<(FXStream& store,const FXPoint& p);
00096 extern FXAPI FXStream& operator>>(FXStream& store,FXPoint& p);
00097 
00098 }
00099 
00100 #endif

Copyright © 1997-2005 Jeroen van der Zijp