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

FXPoint.h

00001 /********************************************************************************
00002 *                                                                               *
00003 *                             P o i n t    C l a s s                            *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 1994,2002 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.3 2002/01/18 22:42:54 jeroen Exp $                         *
00023 ********************************************************************************/
00024 #ifndef FXPOINT_H
00025 #define FXPOINT_H
00026 
00027 
00028 /// Point
00029 class FXAPI FXPoint {
00030 public:
00031   FXshort x;
00032   FXshort y;
00033 public:
00034 
00035   /// Constructors
00036   FXPoint(){ }
00037   FXPoint(const FXSize& s):x(s.w),y(s.h){ }
00038   FXPoint(const FXPoint& p):x(p.x),y(p.y){ }
00039   FXPoint(FXshort xx,FXshort yy):x(xx),y(yy){ }
00040 
00041   /// Equality
00042   friend FXAPI FXbool operator==(const FXPoint& p,const FXPoint& q){ return p.x==q.x && p.y==q.y; }
00043   friend FXAPI FXbool operator!=(const FXPoint& p,const FXPoint& q){ return p.x!=q.x || p.y!=q.y; }
00044 
00045   /// Assignment
00046   FXPoint& operator=(const FXPoint& p){ x=p.x; y=p.y; return *this; }
00047   FXPoint& operator=(const FXSize& s){ x=s.w; y=s.h; return *this; }
00048 
00049   /// Assignment operators
00050   FXPoint& operator+=(const FXPoint& p){ x+=p.x; y+=p.y; return *this; }
00051   FXPoint& operator+=(const FXSize& s){ x+=s.w; y+=s.h; return *this; }
00052   FXPoint& operator-=(const FXPoint& p){ x-=p.x; y-=p.y; return *this; }
00053   FXPoint& operator-=(const FXSize& s){ x-=s.w; y-=s.h; return *this; }
00054   FXPoint& operator*=(FXshort c){ x*=c; y*=c; return *this; }
00055   FXPoint& operator/=(FXshort c){ x/=c; y/=c; return *this; }
00056 
00057   /// Negation
00058   FXPoint operator-(){ return FXPoint(-x,-y); }
00059 
00060   /// Other operators
00061   friend FXAPI FXPoint operator+(const FXPoint& p,const FXPoint& q){ return FXPoint(p.x+q.x,p.y+q.y); }
00062   friend FXAPI FXPoint operator+(const FXPoint& p,const FXSize& s){ return FXPoint(p.x+s.w,p.y+s.h); }
00063   friend FXAPI FXPoint operator+(const FXSize& s,const FXPoint& p){ return FXPoint(s.w+p.x,s.h+p.y); }
00064 
00065   friend FXAPI FXPoint operator-(const FXPoint& p,const FXPoint& q){ return FXPoint(p.x-q.x,p.y-q.y); }
00066   friend FXAPI FXPoint operator-(const FXPoint& p,const FXSize& s){ return FXPoint(p.x-s.w,p.y-s.h); }
00067   friend FXAPI FXPoint operator-(const FXSize& s,const FXPoint& p){ return FXPoint(s.w-p.x,s.h-p.y); }
00068 
00069   friend FXAPI FXPoint operator*(const FXPoint& p,FXshort c){ return FXPoint(p.x*c,p.y*c); }
00070   friend FXAPI FXPoint operator*(FXshort c,const FXPoint& p){ return FXPoint(c*p.x,c*p.y); }
00071   friend FXAPI FXPoint operator/(const FXPoint& p,FXshort c){ return FXPoint(p.x/c,p.y/c); }
00072   friend FXAPI FXPoint operator/(FXshort c,const FXPoint& p){ return FXPoint(c/p.x,c/p.y); }
00073 
00074   /// Save object to a stream
00075   friend FXAPI FXStream& operator<<(FXStream& store,const FXPoint& p);
00076 
00077   /// Load object from a stream
00078   friend FXAPI FXStream& operator>>(FXStream& store,FXPoint& p);
00079   };
00080 
00081 
00082 #endif