📄 gdirect.h
字号:
//
// CGDIRect
//
//
//
// Written by Jason Hattingh
//
// http://www.greystonefx.com
//
// jhattingh@greystonefx.com
//
//
//
//
// Use freely...
//
//
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_GDIRECT_H__2AC1B0EE_504D_4BF8_B567_0766B3555F88__INCLUDED_)
#define AFX_GDIRECT_H__2AC1B0EE_504D_4BF8_B567_0766B3555F88__INCLUDED_
#include <gdiplus.h>
using namespace Gdiplus;
#pragma message(" _Adding library: gdiplus.lib" )
#pragma comment(lib, "gdiplus.lib")
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CGDIRect
{
public:
//
// Construction / Destruction:
//
CGDIRect( int nValue = 0 ) { Assimilate( nValue ); };
CGDIRect( REAL fValue ) { Assimilate( fValue ); };
CGDIRect( Rect rcInit ) { Assimilate( rcInit ); };
CGDIRect( RectF rcInit ) { Assimilate( rcInit ); };
CGDIRect( CRect rcInit ) { Assimilate( rcInit ); };
CGDIRect( CPoint point, CSize size ) { Assimilate( point.x, point.y, point.x + size.cx, point.y + size.cy ); };
CGDIRect( Point point, Size size ) { Assimilate( point.X, point.Y, point.X + size.Width, point.Y + size.Height ); };
CGDIRect( PointF point, SizeF size ) { Assimilate( point.X, point.Y, point.X + size.Width, point.Y + size.Height ); };
CGDIRect( int nLeft, int nTop, int nRight, int nBottom )
{
Assimilate( nLeft, nTop, nRight, nBottom );
};
CGDIRect( REAL Left, REAL Top, REAL Right, REAL Bottom )
{
Assimilate( Left, Top, Right, Bottom );
};
virtual ~CGDIRect() { };
//
// Operators:
//
/////////////////////////////////////////////////////////////////////////////////////////// Function Header
CGDIRect& operator=( CGDIRect& rhs )
///////////////////////////////////////////////////////////////////////////////////////////////////////////
{
return Assimilate( rhs.left, rhs.top, rhs.right, rhs.bottom );
};
/////////////////////////////////////////////////////////////////////////////////////////// Function Header
CGDIRect& operator|=( CGDIRect& rhs )
///////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Join with rhs in holy matrimony ( Union )
//
{
Rect u;
if ( u.Union( u, *this, rhs ) )
return Assimilate( u );
else
return Assimilate( 0 );
};
/////////////////////////////////////////////////////////////////////////////////////////// Function Header
CGDIRect& operator&=( CGDIRect& rhs )
///////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Until intersections do us part...
//
{
Rect i;
if ( i.Intersect( i, *this, rhs ) )
return Assimilate( i );
else
return Assimilate( 0 );
};
/////////////////////////////////////////////////////////////////////////////////////////// Function Header
CGDIRect& operator=( int nValue )
///////////////////////////////////////////////////////////////////////////////////////////////////////////
{
return Assimilate( nValue );
};
/////////////////////////////////////////////////////////////////////////////////////////// Function Header
CGDIRect& operator=( REAL Value )
///////////////////////////////////////////////////////////////////////////////////////////////////////////
{
return Assimilate( Value );
};
//
// A d d i t i o n O v e r l o a d s
//
/////////////////////////////////////////////////////////////////////////////////////////// Function Header
CGDIRect& operator+( CRect& rhs )
///////////////////////////////////////////////////////////////////////////////////////////////////////////
{
return Assimilate( top + (REAL)rhs.top,
left + (REAL)rhs.left,
right + (REAL)rhs.right,
bottom + (REAL)rhs.bottom );
};
/////////////////////////////////////////////////////////////////////////////////////////// Function Header
CGDIRect& operator+( Rect& rhs )
///////////////////////////////////////////////////////////////////////////////////////////////////////////
{
return Assimilate( top + (REAL)rhs.GetTop(),
left + (REAL)rhs.GetLeft(),
right + (REAL)rhs.GetRight(),
bottom + (REAL)rhs.GetBottom() );
};
/////////////////////////////////////////////////////////////////////////////////////////// Function Header
CGDIRect& operator+( RectF& rhs )
///////////////////////////////////////////////////////////////////////////////////////////////////////////
{
return Assimilate( top + rhs.GetTop(),
left + rhs.GetLeft(),
right + rhs.GetRight(),
bottom + rhs.GetBottom() );
};
/////////////////////////////////////////////////////////////////////////////////////////// Function Header
CGDIRect& operator+( CGDIRect& rhs )
///////////////////////////////////////////////////////////////////////////////////////////////////////////
{
return Assimilate( top + rhs.top,
left + rhs.left,
right + rhs.right,
bottom + rhs.bottom );
};
CGDIRect& operator+=( CRect& rhs ) { return Assimilate( CGDIRect(*this) + CGDIRect(rhs) ); };
CGDIRect& operator+=( Rect& rhs ) { return Assimilate( CGDIRect(*this) + CGDIRect(rhs) ); };
CGDIRect& operator+=( RectF& rhs ) { return Assimilate( CGDIRect(*this) + CGDIRect(rhs) ); };
CGDIRect& operator+=( CGDIRect& rhs ) { return Assimilate( CGDIRect(*this) + CGDIRect(rhs) ); };
CGDIRect& operator+=( int nValue ) { return Assimilate( CGDIRect(*this) + CGDIRect(nValue) ); };
CGDIRect& operator+=( REAL fValue ) { return Assimilate( CGDIRect(*this) + CGDIRect(fValue) ); };
//
// S u b t r a c t i o n O v e r l o a d s
//
/////////////////////////////////////////////////////////////////////////////////////////// Function Header
CGDIRect& operator-( CRect& rhs )
///////////////////////////////////////////////////////////////////////////////////////////////////////////
{
return Assimilate( top - (REAL)rhs.top,
left - (REAL)rhs.left,
right - (REAL)rhs.right,
bottom - (REAL)rhs.bottom );
};
/////////////////////////////////////////////////////////////////////////////////////////// Function Header
CGDIRect& operator-( Rect& rhs )
///////////////////////////////////////////////////////////////////////////////////////////////////////////
{
return Assimilate( top - (REAL)rhs.GetTop(),
left - (REAL)rhs.GetLeft(),
right - (REAL)rhs.GetRight(),
bottom - (REAL)rhs.GetBottom() );
};
/////////////////////////////////////////////////////////////////////////////////////////// Function Header
CGDIRect& operator-( RectF& rhs )
///////////////////////////////////////////////////////////////////////////////////////////////////////////
{
return Assimilate( top - rhs.GetTop(),
left - rhs.GetLeft(),
right - rhs.GetRight(),
bottom - rhs.GetBottom() );
};
/////////////////////////////////////////////////////////////////////////////////////////// Function Header
CGDIRect& operator-( CGDIRect& rhs )
///////////////////////////////////////////////////////////////////////////////////////////////////////////
{
return Assimilate( top - rhs.top,
left - rhs.left,
right - rhs.right,
bottom - rhs.bottom );
};
CGDIRect& operator-=( CRect& rhs ) { return Assimilate( CGDIRect(*this) - CGDIRect(rhs) ); };
CGDIRect& operator-=( Rect& rhs ) { return Assimilate( CGDIRect(*this) - CGDIRect(rhs) ); };
CGDIRect& operator-=( RectF& rhs ) { return Assimilate( CGDIRect(*this) - CGDIRect(rhs) ); };
CGDIRect& operator-=( CGDIRect& rhs ) { return Assimilate( CGDIRect(*this) - CGDIRect(rhs) ); };
CGDIRect& operator-=( int nValue ) { return Assimilate( CGDIRect(*this) - CGDIRect(nValue) ); };
CGDIRect& operator-=( REAL fValue ) { return Assimilate( CGDIRect(*this) - CGDIRect(fValue) ); };
//
// C o m p a r i s o n O v e r l o a d s :
//
// Is Equal To?
bool operator==( REAL Value ) { return top == Value && bottom == Value && left == Value && right == Value; };
bool operator==( int nValue ) { return top == nValue && bottom == nValue && left == nValue && right == nValue; };
bool operator==( CGDIRect& rhs ) { return top == rhs.top && bottom == rhs.bottom && left == rhs.left && right == rhs.right; };
bool operator==( CRect& rhs ) { return CGDIRect(rhs) == *this; };
bool operator==( Rect& rhs ) { return CGDIRect(rhs) == *this; };
bool operator==( RectF& rhs ) { return CGDIRect(rhs) == *this; };
// Is Different To?
bool operator!=( REAL Value ) { return top != Value && bottom != Value && left != Value && right != Value; };
bool operator!=( int nValue ) { return top != nValue && bottom != nValue && left != nValue && right != nValue; };
bool operator!=( CGDIRect& rhs ) { return top != rhs.top || bottom != rhs.bottom || left != rhs.left || right != rhs.right; };
bool operator!=( CRect& rhs ) { return CGDIRect(rhs) != *this; };
bool operator!=( Rect& rhs ) { return CGDIRect(rhs) != *this; };
bool operator!=( RectF& rhs ) { return CGDIRect(rhs) != *this; };
//
// S i z e a n d P o s i t i o n :
//
/////////////////////////////////////////////////////////////////////////////////////////// Function Header
void ReplicateBelow( CGDIRect rcSource, REAL nOffset = 0)
///////////////////////////////////////////////////////////////////////////////////////////////////////////
{
top = rcSource.bottom + nOffset;
left = rcSource.left;
SetSize( rcSource );
};
/////////////////////////////////////////////////////////////////////////////////////////// Function Header
void ReplicateAbove( CGDIRect rcSource, REAL Offset = 0)
///////////////////////////////////////////////////////////////////////////////////////////////////////////
{
top = rcSource.top - Height() - Offset;
left = rcSource.left;
SetSize( rcSource );
};
/////////////////////////////////////////////////////////////////////////////////////////// Function Header
void ReplicateLeft( CGDIRect rcSource, REAL Offset = 0)
///////////////////////////////////////////////////////////////////////////////////////////////////////////
{
top = rcSource.top;
left = rcSource.left - rcSource.Width() - Offset;
SetSize( rcSource );
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -