![]() |
Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members
![]() |
00001 /******************************************************************************** 00002 * * 00003 * P o i n t C l a s s * 00004 * * 00005 ********************************************************************************* 00006 * Copyright (C) 1994,2009 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 * $Id: FXPoint.h,v 1.19 2009/01/06 13:07:26 fox Exp $ * 00022 ********************************************************************************/ 00023 #ifndef FXPOINT_H 00024 #define FXPOINT_H 00025 00026 #ifndef FXSIZE_H 00027 #include "FXSize.h" 00028 #endif 00029 00030 namespace FX { 00031 00032 00033 /// Point 00034 class FXAPI FXPoint { 00035 public: 00036 FXshort x; 00037 FXshort y; 00038 public: 00039 00040 /// Constructors 00041 FXPoint(){ } 00042 FXPoint(const FXSize& s):x(s.w),y(s.h){ } 00043 FXPoint(const FXPoint& p):x(p.x),y(p.y){ } 00044 FXPoint(FXshort xx,FXshort yy):x(xx),y(yy){ } 00045 00046 /// Test if zero 00047 FXbool operator!() const { return x==0 && y==0; } 00048 00049 /// Equality 00050 FXbool operator==(const FXPoint& p) const { return x==p.x && y==p.y; } 00051 FXbool operator!=(const FXPoint& p) const { return x!=p.x || y!=p.y; } 00052 00053 /// Assignment 00054 FXPoint& operator=(const FXPoint& p){ x=p.x; y=p.y; return *this; } 00055 00056 /// Set value from another point 00057 FXPoint& set(const FXPoint& p){ x=p.x; y=p.y; return *this; } 00058 00059 /// Set value from components 00060 FXPoint& set(FXshort xx,FXshort yy){ x=xx; y=yy; return *this; } 00061 00062 /// Assignment operators 00063 FXPoint& operator+=(const FXPoint& p){ x+=p.x; y+=p.y; return *this; } 00064 FXPoint& operator-=(const FXPoint& p){ x-=p.x; y-=p.y; return *this; } 00065 FXPoint& operator*=(FXshort c){ x*=c; y*=c; return *this; } 00066 FXPoint& operator/=(FXshort c){ x/=c; y/=c; return *this; } 00067 00068 /// Unary 00069 FXPoint operator+() const { return *this; } 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
![]() |