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,2010 by Jeroen van der Zijp.   All Rights Reserved.        *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or modify          *
00009 * it under the terms of the GNU Lesser General Public License as published by   *
00010 * the Free Software Foundation; either version 3 of the License, or             *
00011 * (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                 *
00016 * GNU Lesser General Public License for more details.                           *
00017 *                                                                               *
00018 * You should have received a copy of the GNU Lesser General Public License      *
00019 * along with this program.  If not, see <http://www.gnu.org/licenses/>          *
00020 ********************************************************************************/
00021 #ifndef FXPOINT_H
00022 #define FXPOINT_H
00023 
00024 #ifndef FXSIZE_H
00025 #include "FXSize.h"
00026 #endif
00027 
00028 namespace FX {
00029 
00030 
00031 /// Point
00032 class FXAPI FXPoint {
00033 public:
00034   FXshort x;
00035   FXshort y;
00036 public:
00037 
00038   /// Constructors
00039   FXPoint(){ }
00040   FXPoint(const FXSize& s):x(s.w),y(s.h){ }
00041   FXPoint(const FXPoint& p):x(p.x),y(p.y){ }
00042   FXPoint(FXshort xx,FXshort yy):x(xx),y(yy){ }
00043 
00044   /// Test if zero
00045   FXbool operator!() const { return x==0 && y==0; }
00046 
00047   /// Equality
00048   FXbool operator==(const FXPoint& p) const { return x==p.x && y==p.y; }
00049   FXbool operator!=(const FXPoint& p) const { return x!=p.x || y!=p.y; }
00050 
00051   /// Assignment
00052   FXPoint& operator=(const FXPoint& p){ x=p.x; y=p.y; return *this; }
00053 
00054   /// Set value from another point
00055   FXPoint& set(const FXPoint& p){ x=p.x; y=p.y; return *this; }
00056 
00057   /// Set value from components
00058   FXPoint& set(FXshort xx,FXshort yy){ x=xx; y=yy; return *this; }
00059 
00060   /// Assignment operators
00061   FXPoint& operator+=(const FXPoint& p){ x+=p.x; y+=p.y; return *this; }
00062   FXPoint& operator-=(const FXPoint& p){ x-=p.x; y-=p.y; return *this; }
00063   FXPoint& operator*=(FXshort c){ x*=c; y*=c; return *this; }
00064   FXPoint& operator/=(FXshort c){ x/=c; y/=c; return *this; }
00065 
00066   /// Unary
00067   FXPoint operator+() const { return *this; }
00068   FXPoint operator-(){ return FXPoint(-x,-y); }
00069 
00070   /// Addition operators
00071   FXPoint operator+(const FXPoint& p) const { return FXPoint(x+p.x,y+p.y); }
00072   FXPoint operator-(const FXPoint& p) const { return FXPoint(x-p.x,y-p.y); }
00073   };
00074 
00075 
00076 /// Scale operators
00077 inline FXPoint operator*(const FXPoint& p,FXshort c){ return FXPoint(p.x*c,p.y*c); }
00078 inline FXPoint operator*(FXshort c,const FXPoint& p){ return FXPoint(c*p.x,c*p.y); }
00079 inline FXPoint operator/(const FXPoint& p,FXshort c){ return FXPoint(p.x/c,p.y/c); }
00080 inline FXPoint operator/(FXshort c,const FXPoint& p){ return FXPoint(c/p.x,c/p.y); }
00081 
00082 /// Save object to a stream
00083 extern FXAPI FXStream& operator<<(FXStream& store,const FXPoint& p);
00084 
00085 /// Load object from a stream
00086 extern FXAPI FXStream& operator>>(FXStream& store,FXPoint& p);
00087 
00088 }
00089 
00090 #endif

Copyright © 1997-2010 Jeroen van der Zijp