1 ////////////////////////////////////////////////////////////////////////////////////////
2 //
3 // Nestopia - NES/Famicom emulator written in C++
4 //
5 // Copyright (C) 2003-2008 Martin Freij
6 //
7 // This file is part of Nestopia.
8 //
9 // Nestopia is free software; you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation; either version 2 of the License, or
12 // (at your option) any later version.
13 //
14 // Nestopia is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 // GNU General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with Nestopia; if not, write to the Free Software
21 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22 //
23 ////////////////////////////////////////////////////////////////////////////////////////
24 
25 #ifndef NST_WINDOW_POINT_H
26 #define NST_WINDOW_POINT_H
27 
28 #pragma once
29 
30 #include "NstMain.hpp"
31 #include <windows.h>
32 
33 namespace Nestopia
34 {
35 	namespace Window
36 	{
37 		struct Point : POINT
38 		{
39 			enum Scaling
40 			{
41 				SCALE_BELOW,
42 				SCALE_ABOVE,
43 				SCALE_NEAREST
44 			};
45 
46 			uint ScaleToFit(uint,uint,Scaling,uint=UINT_MAX);
47 
PointNestopia::Window::Point48 			Point(int v=0)
49 			{
50 				x = v;
51 				y = v;
52 			}
53 
PointNestopia::Window::Point54 			Point(int a,int b)
55 			{
56 				x = a;
57 				y = b;
58 			}
59 
PointNestopia::Window::Point60 			Point(const POINT& p)
61 			{
62 				x = p.x;
63 				y = p.y;
64 			}
65 
PointNestopia::Window::Point66 			Point(const RECT& r)
67 			{
68 				x = r.right - r.left;
69 				y = r.bottom - r.top;
70 			}
71 
SetNestopia::Window::Point72 			Point& Set(int a,int b)
73 			{
74 				x = a;
75 				y = b;
76 				return *this;
77 			}
78 
operator =Nestopia::Window::Point79 			Point& operator = (const POINT& p)
80 			{
81 				x = p.x;
82 				y = p.y;
83 				return *this;
84 			}
85 
operator =Nestopia::Window::Point86 			Point& operator = (int v)
87 			{
88 				x = v;
89 				y = v;
90 				return *this;
91 			}
92 
operator =Nestopia::Window::Point93 			Point& operator = (const RECT& r)
94 			{
95 				x = r.right - r.left;
96 				y = r.bottom - r.top;
97 				return *this;
98 			}
99 
operator ==Nestopia::Window::Point100 			bool operator == (const Point& p) const { return x == p.x && y == p.y; }
operator !=Nestopia::Window::Point101 			bool operator != (const Point& p) const { return x != p.x || y != p.y; }
operator <Nestopia::Window::Point102 			bool operator <  (const Point& p) const { return x * y <  p.x * p.y;   }
operator >Nestopia::Window::Point103 			bool operator >  (const Point& p) const { return x * y >  p.x * p.y;   }
operator <=Nestopia::Window::Point104 			bool operator <= (const Point& p) const { return x * y <= p.x * p.y;   }
operator >=Nestopia::Window::Point105 			bool operator >= (const Point& p) const { return x * y >= p.x * p.y;   }
106 
operator !Nestopia::Window::Point107 			bool operator ! () const
108 			{
109 				return (x | y) == 0;
110 			}
111 
operator []Nestopia::Window::Point112 			long& operator [] (uint i)
113 			{
114 				return (&x)[i];
115 			}
116 
operator []Nestopia::Window::Point117 			const long& operator [] (uint i) const
118 			{
119 				return (&x)[i];
120 			}
121 
operator +=Nestopia::Window::Point122 			Point& operator += (const Point& p) { x += p.x; y += p.y; return *this; }
operator -=Nestopia::Window::Point123 			Point& operator -= (const Point& p) { x -= p.x; y -= p.y; return *this; }
operator *=Nestopia::Window::Point124 			Point& operator *= (const Point& p) { x *= p.x; y *= p.y; return *this; }
operator /=Nestopia::Window::Point125 			Point& operator /= (const Point& p) { x /= p.x; y /= p.y; return *this; }
126 
operator +Nestopia::Window::Point127 			Point operator + (const Point& p) const { return Point( x + p.x, y + p.y ); }
operator -Nestopia::Window::Point128 			Point operator - (const Point& p) const { return Point( x - p.x, y - p.y ); }
operator *Nestopia::Window::Point129 			Point operator * (const Point& p) const { return Point( x * p.x, y * p.y ); }
operator /Nestopia::Window::Point130 			Point operator / (const Point& p) const { return Point( x / p.x, y / p.y ); }
131 
operator +(int v,const Point & p)132 			friend Point operator + (int v,const Point& p) { return Point( p.x + v, p.y + v ); }
operator *(int v,const Point & p)133 			friend Point operator * (int v,const Point& p) { return Point( p.x * v, p.y * v ); }
134 
CenterNestopia::Window::Point135 			Point Center() const
136 			{
137 				return Point( x / 2, y / 2 );
138 			}
139 
ScaleToFitNestopia::Window::Point140 			uint ScaleToFit(const Point& p,Scaling s,uint f=UINT_MAX)
141 			{
142 				return ScaleToFit( p.x, p.y, s, f );
143 			}
144 
ClientTransformNestopia::Window::Point145 			Point& ClientTransform(HWND hWnd)
146 			{
147 				::ScreenToClient( hWnd, this );
148 				return *this;
149 			}
150 
ScreenTransformNestopia::Window::Point151 			Point& ScreenTransform(HWND hWnd)
152 			{
153 				::ClientToScreen( hWnd, this );
154 				return *this;
155 			}
156 
157 			struct Client;
158 			struct Picture;
159 			struct NonClient;
160 		};
161 
162 		struct Point::Client : Point
163 		{
164 			Client(HWND);
165 		};
166 
167 		struct Point::Picture : Point
168 		{
169 			Picture(HWND);
170 		};
171 
172 		struct Point::NonClient : Point
173 		{
174 			NonClient(HWND);
175 		};
176 	}
177 }
178 
179 #endif
180