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

FXPoint.h
Go to the documentation of this file.
1 /********************************************************************************
2 * *
3 * P o i n t C l a s s *
4 * *
5 *********************************************************************************
6 * Copyright (C) 1994,2006 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or *
9 * modify it under the terms of the GNU Lesser General Public *
10 * License as published by the Free Software Foundation; either *
11 * version 2.1 of the License, or (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16 * Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public *
19 * License along with this library; if not, write to the Free Software *
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
21 *********************************************************************************
22 * $Id: FXPoint.h,v 1.13 2006/01/22 17:58:07 fox Exp $ *
23 ********************************************************************************/
24 #ifndef FXPOINT_H
25 #define FXPOINT_H
26 
27 #ifndef FXSIZE_H
28 #include "FXSize.h"
29 #endif
30 
31 namespace FX {
32 
33 
34 /// Point
35 class FXAPI FXPoint {
36 public:
39 public:
40 
41  /// Constructors
42  FXPoint(){ }
43  FXPoint(const FXSize& s):x(s.w),y(s.h){ }
44  FXPoint(const FXPoint& p):x(p.x),y(p.y){ }
45  FXPoint(FXshort xx,FXshort yy):x(xx),y(yy){ }
46 
47  /// Test if zero
48  bool operator!() const { return x==0 && y==0; }
49 
50  /// Equality
51  bool operator==(const FXPoint& p) const { return x==p.x && y==p.y; }
52  bool operator!=(const FXPoint& p) const { return x!=p.x || y!=p.y; }
53 
54  /// Assignment
55  FXPoint& operator=(const FXPoint& p){ x=p.x; y=p.y; return *this; }
56 
57  /// Set value from another point
58  FXPoint& set(const FXPoint& p){ x=p.x; y=p.y; return *this; }
59 
60  /// Set value from components
61  FXPoint& set(FXshort xx,FXshort yy){ x=xx; y=yy; return *this; }
62 
63  /// Assignment operators
64  FXPoint& operator+=(const FXPoint& p){ x+=p.x; y+=p.y; return *this; }
65  FXPoint& operator-=(const FXPoint& p){ x-=p.x; y-=p.y; return *this; }
66  FXPoint& operator*=(FXshort c){ x*=c; y*=c; return *this; }
67  FXPoint& operator/=(FXshort c){ x/=c; y/=c; return *this; }
68 
69  /// Negation
70  FXPoint operator-(){ return FXPoint(-x,-y); }
71 
72  /// Addition operators
73  FXPoint operator+(const FXPoint& p) const { return FXPoint(x+p.x,y+p.y); }
74  FXPoint operator-(const FXPoint& p) const { return FXPoint(x-p.x,y-p.y); }
75 
76  /// Scale operators
77  friend inline FXPoint operator*(const FXPoint& p,FXshort c);
78  friend inline FXPoint operator*(FXshort c,const FXPoint& p);
79  friend inline FXPoint operator/(const FXPoint& p,FXshort c);
80  friend inline FXPoint operator/(FXshort c,const FXPoint& p);
81 
82  /// Save object to a stream
83  friend FXAPI FXStream& operator<<(FXStream& store,const FXPoint& p);
84 
85  /// Load object from a stream
86  friend FXAPI FXStream& operator>>(FXStream& store,FXPoint& p);
87  };
88 
89 
90 inline FXPoint operator*(const FXPoint& p,FXshort c){ return FXPoint(p.x*c,p.y*c); }
91 inline FXPoint operator*(FXshort c,const FXPoint& p){ return FXPoint(c*p.x,c*p.y); }
92 inline FXPoint operator/(const FXPoint& p,FXshort c){ return FXPoint(p.x/c,p.y/c); }
93 inline FXPoint operator/(FXshort c,const FXPoint& p){ return FXPoint(c/p.x,c/p.y); }
94 
95 extern FXAPI FXStream& operator<<(FXStream& store,const FXPoint& p);
96 extern FXAPI FXStream& operator>>(FXStream& store,FXPoint& p);
97 
98 }
99 
100 #endif
FXMat3d operator/(const FXMat3d &a, FXdouble x)
FXPoint operator-()
Negation.
Definition: FXPoint.h:70
FXStream & operator>>(FXStream &store, FXDate &d)
FXPoint & operator=(const FXPoint &p)
Assignment.
Definition: FXPoint.h:55
short FXshort
Definition: fxdefs.h:395
FXPoint & operator*=(FXshort c)
Definition: FXPoint.h:66
Size.
Definition: FXSize.h:32
FXPoint & operator-=(const FXPoint &p)
Definition: FXPoint.h:65
#define FXAPI
Definition: fxdefs.h:122
FXPoint(const FXSize &s)
Definition: FXPoint.h:43
bool operator!() const
Test if zero.
Definition: FXPoint.h:48
FXPoint & set(const FXPoint &p)
Set value from another point.
Definition: FXPoint.h:58
FXPoint operator+(const FXPoint &p) const
Addition operators.
Definition: FXPoint.h:73
FXPoint()
Constructors.
Definition: FXPoint.h:42
FXPoint operator-(const FXPoint &p) const
Definition: FXPoint.h:74
A stream is a way to serialize data and objects into a byte stream.
Definition: FXStream.h:99
FXPoint & operator/=(FXshort c)
Definition: FXPoint.h:67
bool operator!=(const FXPoint &p) const
Definition: FXPoint.h:52
FXPoint(const FXPoint &p)
Definition: FXPoint.h:44
FXshort y
Definition: FXPoint.h:38
Definition: FX4Splitter.h:31
FXshort x
Definition: FXPoint.h:37
FXPoint & operator+=(const FXPoint &p)
Assignment operators.
Definition: FXPoint.h:64
Point.
Definition: FXPoint.h:35
bool operator==(const FXPoint &p) const
Equality.
Definition: FXPoint.h:51
FXPoint(FXshort xx, FXshort yy)
Definition: FXPoint.h:45
FXPoint & set(FXshort xx, FXshort yy)
Set value from components.
Definition: FXPoint.h:61
FXStream & operator<<(FXStream &store, const FXDate &d)
FXMat3d operator*(FXdouble x, const FXMat3d &a)

Copyright © 1997-2005 Jeroen van der Zijp