(svn r8803) [cpp_gui] -Codechange: point structures (Point, Point16) made compatible cpp_gui
authorKUDr
Sun, 18 Feb 2007 19:45:00 +0000
branchcpp_gui
changeset 6259 0f36789984b1
parent 6258 a2f86b8fd99b
child 6260 740c702f6871
(svn r8803) [cpp_gui] -Codechange: point structures (Point, Point16) made compatible
-PointT has now base PointRawT without constructor (plain struct compatible with unions)
-struct Point declared in gfx.h replaced by PointT<int>
-use of Point in WindowEvent::we union members replaced by PointRawT<int>
src/gfx.h
src/misc/rect.hpp
src/rail_cmd.cpp
src/viewport.cpp
src/window.h
--- a/src/gfx.h	Sun Feb 18 14:17:28 2007 +0000
+++ b/src/gfx.h	Sun Feb 18 19:45:00 2007 +0000
@@ -3,6 +3,7 @@
 #ifndef GFX_H
 #define GFX_H
 
+#include "misc/rect.hpp"
 
 enum WindowKeyCodes {
 	WKC_SHIFT = 0x8000,
@@ -91,10 +92,6 @@
 typedef int32 CursorID;
 typedef byte Pixel;
 
-typedef struct Point {
-	int x,y;
-} Point;
-
 typedef struct Rect {
 	int left,top,right,bottom;
 } Rect;
--- a/src/misc/rect.hpp	Sun Feb 18 14:17:28 2007 +0000
+++ b/src/misc/rect.hpp	Sun Feb 18 19:45:00 2007 +0000
@@ -2,19 +2,33 @@
 #ifndef RECT_H
 #define RECT_H
 
+/** Template based point without ctor/dtor (raw) for use in unions */
+template <typename T> struct PointRawT {
+	T x, y;
+
+	PointRawT operator -() const
+	{
+		PointRawT pt = {-x, -y};
+		return pt;
+	}
+};
+
 /** Template based point */
-template <typename T> struct PointT {
-	T x, y;
+template <typename T> struct PointT : public PointRawT<T> {
 
 	PointT(T x_a = 0, T y_a = 0)
-		: x(x_a), y(y_a)
-	{}
+	{
+		x = x_a;
+		y = y_a;
+	}
 
-	template <typename Ta> PointT(const PointT<Ta> &src)
-		: x((T)src.x), y((T)src.y)
-	{}
+	template <typename Ta> PointT(const PointRawT<Ta> &src)
+	{
+		x = (T)src.x;
+		y = (T)src.y;
+	}
 
-	PointT& operator =(const PointT &src)
+	PointT& operator =(const PointRawT &src)
 	{
 		x = (T)src.x;
 		y = (T)src.y;
@@ -32,32 +46,32 @@
 		y += dy;
 	}
 
-	void DoMove(const PointT &offset)
+	void DoMove(const PointRawT &offset)
 	{
 		DoMove((T)offset.x, (T)offset.y);
 	}
 
-	PointT operator +(const PointT &offset) const
+	PointT operator +(const PointRawT &offset) const
 	{
-		PointT pt;
+		PointT pt(*this);
 		pt.DoMove(offset);
 		return pt;
 	}
 
-	PointT operator -(const PointT &offset) const
+	PointT operator -(const PointRawT &offset) const
 	{
-		PointT pt;
+		PointT pt(*this);
 		pt.DoMove(-offset);
 		return pt;
 	}
 
-	PointT& operator +=(const PointT &offset)
+	PointT& operator +=(const PointRawT &offset)
 	{
 		DoMove(offset);
 		return *this;
 	}
 
-	PointT& operator -=(const PointT &offset)
+	PointT& operator -=(const PointRawT &offset)
 	{
 		DoMove(-offset);
 		return *this;
@@ -149,17 +163,17 @@
 		bottom_right.y = top_left.y + val - 1;
 	}
 
-	void SetTopLeft(const PointT<T> &pt)
+	void SetTopLeft(const PointRawT<T> &pt)
 	{
 		top_left = pt;
 	}
 
-	void SetBottomRight(const PointT<T> &pt)
+	void SetBottomRight(const PointRawT<T> &pt)
 	{
 		bottom_right = pt;
 	}
 
-	bool PtInRect(const PointT<T> &pt) const
+	bool PtInRect(const PointRawT<T> &pt) const
 	{
 		return (top_left.x <= pt.x && pt.x <= bottom_right.x && top_left.y <= pt.y && pt.y <= bottom_right.y);
 	}
@@ -176,39 +190,39 @@
 		DoMove(PointT<T>(dx, dy));
 	}
 
-	void DoMove(const PointT<T> &offset)
+	void DoMove(const PointRawT<T> &offset)
 	{
 		top_left.DoMove(offset);
 		bottom_right.DoMove(offset);
 	}
 
-	RectT operator +(const PointT<T> &offset) const
+	RectT operator +(const PointRawT<T> &offset) const
 	{
-		RectT r;
+		RectT r(*this);
 		r.DoMove(offset);
 		return r;
 	}
 
-	RectT operator -(const PointT<T> &offset) const
+	RectT operator -(const PointRawT<T> &offset) const
 	{
-		RectT r;
+		RectT r(*this);
 		r.DoMove(-offset);
 		return r;
 	}
 
-	RectT& operator +=(const PointT<T> &offset)
+	RectT& operator +=(const PointRawT<T> &offset)
 	{
 		DoMove(offset);
 		return *this;
 	}
 
-	RectT& operator -=(const PointT<T> &offset)
+	RectT& operator -=(const PointRawT<T> &offset)
 	{
 		DoMove(-offset);
 		return *this;
 	}
 
-	void DoUnion(const PointT<T> &pt)
+	void DoUnion(const PointRawT<T> &pt)
 	{
 		if (pt.x < top_left.x) {
 			top_left.x = pt.x;
@@ -239,8 +253,11 @@
 
 
 
+typedef PointRawT<int> PointRaw;
+
 typedef PointT<int16> Point16;
 typedef PointT<int32> Point32;
+typedef PointT<int>   Point;
 
 typedef RectT<int16> Rect16;
 typedef RectT<int32> Rect32;
--- a/src/rail_cmd.cpp	Sun Feb 18 14:17:28 2007 +0000
+++ b/src/rail_cmd.cpp	Sun Feb 18 19:45:00 2007 +0000
@@ -1019,7 +1019,7 @@
 static void DrawSingleSignal(TileIndex tile, byte condition, uint image, uint pos)
 {
 	bool side = (_opt.road_side != 0) && _patches.signal_side;
-	static const Point SignalPositions[2][12] = {
+	static const PointRaw SignalPositions[2][12] = {
 		{      /* Signals on the left side */
 		/*  LEFT      LEFT      RIGHT     RIGHT     UPPER     UPPER */
 			{ 8,  5}, {14,  1}, { 1, 14}, { 9, 11}, { 1,  0}, { 3, 10},
--- a/src/viewport.cpp	Sun Feb 18 14:17:28 2007 +0000
+++ b/src/viewport.cpp	Sun Feb 18 19:45:00 2007 +0000
@@ -327,7 +327,7 @@
 
 	if ( (uint)(x -= vp->left) >= (uint)vp->width ||
 				(uint)(y -= vp->top) >= (uint)vp->height) {
-				Point pt = {-1, -1};
+				Point pt(-1, -1);
 				return pt;
 	}
 
--- a/src/window.h	Sun Feb 18 14:17:28 2007 +0000
+++ b/src/window.h	Sun Feb 18 19:45:00 2007 +0000
@@ -192,25 +192,25 @@
 	byte event;
 	union {
 		struct{
-			Point pt;
+			PointRaw pt;
 			int widget;
 		} click;
 
 		struct {
-			Point pt;
+			PointRaw pt;
 			TileIndex tile;
 			TileIndex starttile;
 			int userdata;
 		} place;
 
 		struct {
-			Point pt;
+			PointRaw pt;
 			int widget;
 		} dragdrop;
 
 		struct {
-			Point size;
-			Point diff;
+			PointRaw size;
+			PointRaw diff;
 		} sizing;
 
 		struct {
@@ -218,7 +218,7 @@
 		} edittext;
 
 		struct {
-			Point pt;
+			PointRaw pt;
 		} popupmenu;
 
 		struct {
@@ -227,7 +227,7 @@
 		} dropdown;
 
 		struct {
-			Point pt;
+			PointRaw pt;
 			int widget;
 		} mouseover;
 
@@ -244,7 +244,7 @@
 		} message;
 
 		struct {
-			Point delta;   // delta position against position of last call
+			PointRaw delta;   // delta position against position of last call
 		} scroll;
 
 		struct {
@@ -509,7 +509,6 @@
 	BaseWindow *parent;
 	byte custom[WINDOW_CUSTOM_SIZE];
 
-//	BaseWindow(int x, int y, int w, int h, WindowProc *proc, WindowClass cls, const OldWidget *widget, int wnd_number);
 	BaseWindow(const WindowDesc *desc, WindowNumber num = 0);
 	virtual bool Create(const WindowDesc *desc, WindowNumber num = 0);