⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gspoint.h

📁 连连看这个游戏都玩过吧
💻 H
字号:
 // GsPoint.h: interface for the GsPoint class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_GSPOINT_H__AF147D06_1744_4086_801C_174E3B937E78__INCLUDED_)
#define AFX_GSPOINT_H__AF147D06_1744_4086_801C_174E3B937E78__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#pragma pack( push, 1)
// --------------------------------------------------------------------------
// TPoint2d class template - Represents a two dimensional point in screen
// coordinates.
// --------------------------------------------------------------------------
template < typename t_coord_arg >
struct GSLIB_API TPoint2d
{
public:
	// Types
	typedef t_coord_arg t_coord;

	// Data members
	t_coord	x;
	t_coord	y;

	// Constructors
	TPoint2d()																	:	x( 0 ),	y( 0 )	{ }
	TPoint2d( t_coord const & x_arg, t_coord const & y_arg )					:	x( x_arg ),	y( y_arg )	{	}

	template < typename t_other_coord >
	TPoint2d( TPoint2d< t_other_coord > const & other )							:	x( other.x ), y( other.y )	{	}

	TPoint2d( TPoint2d const & other )											:	x( other.x ), y( other.y )	{ }

	// Operators
	TPoint2d & operator+=( TPoint2d const & right )								{ x += right.x; y += right.y; return *this;	}
	TPoint2d & operator-=( TPoint2d const & right )								{ x -= right.x; y -= right.y; return *this;	}
	TPoint2d & operator*=( t_coord const & right )								{ x *= right; y *= right; return *this; }
	TPoint2d & operator/=( t_coord const & right )								{ x /= right;	y /= right; return *this;	}
	TPoint2d & operator%=( t_coord const & right )								{ x %= right;	y %= right; return *this;	}

	// Friend functions - defined inline to provide automatic intantiation
	friend bool operator==( TPoint2d const & left, TPoint2d const & right )	{ return left.x == right.x && left.y == right.y; }

	friend bool operator!=( TPoint2d const & left, TPoint2d const & right )	{ return !( left == right ); }

	friend TPoint2d operator+( TPoint2d const & point )	{ return point; }

	friend TPoint2d operator-( TPoint2d const & point )	{ return TPoint2d( -point.x, -point.y ); }

	friend TPoint2d operator+( TPoint2d const & left, TPoint2d const & right )	{ TPoint2d result( left ); return result += right; }

	friend TPoint2d operator-( TPoint2d const & left, TPoint2d const & right )	{ TPoint2d result( left ); return result -= right; }

	friend TPoint2d operator*( TPoint2d const & left, t_coord const & right )	{ TPoint2d result( left ); return result *= right; }

	friend TPoint2d operator*( t_coord const & left, TPoint2d const & right )	{ return right * left; }

	friend TPoint2d operator/( TPoint2d const & left, t_coord const & right )	{ TPoint2d result( left ); return result /= right; }

	friend TPoint2d operator%( TPoint2d const & left, t_coord const & right )	{ TPoint2d result( left ); return result %= right; }
};
//typedef TPoint2d POINT2;


// --------------------------------------------------------------------------
// TRect2d class template - Represents a two dimensional rectangle in
// screen coordinates.
// --------------------------------------------------------------------------

template < typename t_coord_arg >
struct GSLIB_API TRect2d
{
public:
	// Types
	typedef t_coord_arg				t_coord;
	typedef TPoint2d< t_coord >	t_point;

	// Data members
	t_coord	left;
	t_coord	top;
	t_coord	right;
	t_coord	bottom;



	// Constructors
	TRect2d()																											:	left( 0 ),	top( 0 ),	right( 0 ),	bottom( 0 )	{}
	TRect2d( t_coord const & left_arg, t_coord const & top_arg,	t_coord const & right_arg, t_coord const & bottom_arg )	:	left( left_arg ), top( top_arg ),		right( right_arg ),	bottom( bottom_arg ) { }
	TRect2d( t_point const & top_left, t_point const & size )															:	left( top_left.x ), top( top_left.y ), right( top_left.x + size.x ), bottom( top_left.y + size.y )	{ }

	template < typename t_other_coord >	TRect2d( TRect2d< t_other_coord > const & other )								:	left( other.left ),	top( other.top ), right( other.right ),	bottom( other.bottom )	{ }

	TRect2d( TRect2d const & other )																					:	left( other.left ), top( other.top ), right( other.right ),	bottom( other.bottom )	{ }

	// Member functions
	t_coord	height() const																								{ return bottom - top; }
	t_coord	width() const																								{ return right - left; }

	t_point	top_left() const																							{ return t_point( left, top ); }
	t_point	top_right() const																							{ return t_point( right, top );	}
	t_point	bottom_left() const																							{ return t_point( left, bottom ); }
	t_point	bottom_right() const																						{ return t_point( right, bottom ); }

	t_point	size() const																								{ return t_point( width(), height() ); }

	bool	contains( TRect2d const & arg ) const																		{ return		left <= arg.left &&	right >= arg.right &&	top <= arg.top	&&	bottom >= arg.bottom; }
                                              // true if rectangle entirely                 // contains arg.

	// Operators
	TRect2d & operator+=( t_point const & point )																		{ left += point.x; top += point.y; right += point.x; bottom += point.y;	return *this; }
	TRect2d & operator-=( t_point const & point )																		{ left -= point.x; top -= point.y; right -= point.x; bottom -= point.y; return *this; }
	TRect2d & operator*=( t_coord const & arg )																			{ left *= arg; top *= arg; right *= arg; bottom *= arg;	return *this; }
	TRect2d & operator/=( t_coord const & arg )																			{ left /= arg; top /= arg; right /= arg; bottom /= arg;	return *this; }

	// Friend functions - defined inline to provide automatic intantiation
	friend bool operator==( TRect2d const & left, TRect2d const & right )												{ return		left.left == right.left	&&	left.top == right.top && left.right == right.right	&&	left.bottom == right.bottom; }

	friend bool operator!=( TRect2d const & left, TRect2d const & right )												{ return !( left == right ); }

	friend TRect2d operator+( TRect2d const & left, t_point const & right )												{ TRect2d result( left ); return result += right; }

	friend TRect2d operator+( t_point const & left, TRect2d const & right )												{ return right + left; }

	friend TRect2d operator-( TRect2d const & left, t_point const & right )												{ TRect2d result( left ); return result -= right; }

	friend TRect2d operator*( TRect2d const & left, t_coord const & right )												{ TRect2d result( left ); return result *= right; }

	friend TRect2d operator*( t_coord const & left, TRect2d const & right )												{ return right * left; }

	friend TRect2d operator/( TRect2d const & left, t_coord const & right )												{ TRect2d result( left ); return result /= right; }
};
//typedef TRect2d RECT2;
// --------------------------------------------------------------------------
// Inline free functions for TRect2d
// --------------------------------------------------------------------------

template < typename t_coord >
inline GSLIB_API bool is_point_in_rect( TPoint2d< t_coord > const & point, TRect2d< t_coord > const & rect )						{ return		point.x >= rect.left &&	point.x < rect.right &&	point.y >= rect.top &&	point.y < rect.bottom; }

template < typename t_coord >
inline GSLIB_API bool is_normalized( TRect2d< t_coord > const & rect )															{ return rect.left <= rect.right && rect.top <= rect.bottom; }

template < typename t_coord >
inline GSLIB_API void normalize( TRect2d< t_coord > & rect )																		{ if ( rect.left > rect.right ) std::swap( rect.left, rect.right ); if ( rect.top > rect.bottom )std::swap( rect.top, rect.bottom ); }

template < typename t_coord >
inline GSLIB_API bool intersect( TRect2d< t_coord > const & first, TRect2d< t_coord > const & second )							{ return		first.left < second.right && second.left < first.right && first.top < second.bottom	&& second.top < first.bottom; }

template < typename t_coord >
inline GSLIB_API void assign_intersection( TRect2d< t_coord > & first, TRect2d< t_coord > const & second )						{ if ( second.left > first.left ) first.left = second.left; if ( second.top > first.top ) first.top = second.top; if ( second.right < first.right )first.right = second.right;	if ( second.bottom < first.bottom )first.bottom = second.bottom; }

template < typename t_coord >
inline GSLIB_API TRect2d< t_coord > intersection( TRect2d< t_coord > const & first, TRect2d< t_coord > const & second )			{ TRect2d< t_coord > result( first ); assign_intersection( result, second ); return result; }

template < typename t_coord >
inline GSLIB_API void assign_extent( TRect2d< t_coord > & first, TRect2d< t_coord > const & second )								{ if ( second.left < first.left ) first.left = second.left; if ( second.top < first.top )first.top = second.top;	if ( second.right > first.right )first.right = second.right; if ( second.bottom > first.bottom )first.bottom = second.bottom; }

template < typename t_coord >
inline GSLIB_API TRect2d< t_coord > get_extent( TRect2d< t_coord > const & first, TRect2d< t_coord > const & second )				{ TRect2d< t_coord > result( first );	assign_extent( result, second ); return result; }

// ---------------------------------------------------------------
// data structure for screen coordinates
// ---------------------------------------------------------------
struct GSLIB_API SScreenPoint : public POINT
{
//	int x;
//	int y;
	// Constructors
	SScreenPoint();
	SScreenPoint( int new_x, int new_y );
	SScreenPoint( TPoint2d< int > const & other );
	SScreenPoint( SScreenPoint const & other );

	// Operators
	SScreenPoint & operator+=( SScreenPoint const & right );
	SScreenPoint & operator-=( SScreenPoint const & right );
	SScreenPoint & operator*=( int right );
	SScreenPoint & operator/=( int right );
	SScreenPoint & operator%=( int right );
	SScreenPoint & operator<<=( int right );
	SScreenPoint & operator>>=( int right );


	operator TPoint2d< int >() const;
};
typedef SScreenPoint GPOINT;

// ---------------------------------------------------------------
// data structure for screen rectangles
// ---------------------------------------------------------------
struct GSLIB_API SScreenRect : public RECT
{
//	int		left;
//	int		top;
//	int		right;
//	int		bottom;
	// Constructors
	SScreenRect();
	SScreenRect( int left, int top, int right, int bottom );
	SScreenRect( SScreenPoint const & top_left, SScreenPoint const & size );
	SScreenRect( TRect2d< int > const & other );
	SScreenRect( SScreenRect const & other );

	// Member functions
	int height() const;
	int width() const;

	SScreenPoint top_left() const;
	SScreenPoint top_right() const;
	SScreenPoint bottom_left() const;
	SScreenPoint bottom_right() const;

	SScreenPoint size() const;

	bool           contains( SScreenRect const& arg ) const; // true if rectangle entirely
                                                               // contains arg.
	// Operators
	SScreenRect & operator+=( SScreenPoint const & point );
	SScreenRect & operator-=( SScreenPoint const & point );
	SScreenRect & operator*=( int arg );
	SScreenRect & operator/=( int arg );
	SScreenRect & operator<<=( int arg );
	SScreenRect & operator>>=( int arg );

	void expand(GPOINT pt);
	void expand(LONG size);

	void make_extern( SScreenRect const & rect );
	void make_clipper( SScreenRect const & rect );
	//void make_fit( SScreenRect const & rect );
	void make_room( SScreenRect const & rect );

	operator TRect2d< int >() const;
};
typedef SScreenRect GRECT;

// ---------------------------------------------------------------
// inline SScreenRect free functions
// ---------------------------------------------------------------
inline GSLIB_API bool  operator==( SScreenRect const & left, SScreenRect const & right );

inline GSLIB_API bool operator!=( SScreenRect const & left, SScreenRect const & right );

inline GSLIB_API SScreenRect operator+( SScreenRect const & left, SScreenPoint const & right );

inline GSLIB_API SScreenRect operator+( SScreenPoint const & left, SScreenRect const & right );

inline GSLIB_API SScreenRect operator-( SScreenRect const & left, SScreenPoint const & right );

inline GSLIB_API SScreenRect operator*( SScreenRect const & left, int right );

inline GSLIB_API SScreenRect operator*( int left, SScreenRect const & right );

inline GSLIB_API SScreenRect operator/( SScreenRect const & left, int right );

inline GSLIB_API SScreenRect operator<<( SScreenRect const & left, int right );

inline GSLIB_API SScreenRect operator>>( SScreenRect const & left, int right );

inline GSLIB_API bool is_point_in_rect( SScreenPoint const & point, SScreenRect const & rect );

inline GSLIB_API bool is_normalized( SScreenRect const & rect );

inline GSLIB_API void normalize( SScreenRect & rect );

inline GSLIB_API bool intersect( SScreenRect const & left, SScreenRect const & right );

inline GSLIB_API SScreenRect intersection( SScreenRect const & left, SScreenRect const & right );

inline GSLIB_API SScreenRect get_extent( SScreenRect const& left, SScreenRect const& right );

inline GSLIB_API std::streambuf & operator<<( std::streambuf & stream, SScreenRect const & rect );

inline GSLIB_API std::streambuf & operator>>( std::streambuf & stream, SScreenRect & rect );




typedef std::list<SScreenRect>				GRECTLIST;


typedef TPoint2d<FLOAT>				FPOINT;
typedef TRect2d<FLOAT>				FRECT;


struct GSLIB_API SCoordinateFilter
{
	GPOINT	base_point;
	float	rotate_angle;
	float	width_scale;
	float	height_scale;
};



#pragma pack(pop)





#endif // !defined(AFX_GSPOINT_H__AF147D06_1744_4086_801C_174E3B937E78__INCLUDED_)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -