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

📄 wg_rect.cpp

📁 一个小巧的嵌入式图形系统wGUI, 可以用VC编译
💻 CPP
字号:
// wg_rect.cpp//// CRect class implementation////// Copyright (c) 2002 Rob Wiskow// rob-dev@boxedchaos.com//// This library is free software; you can redistribute it and/or// modify it under the terms of the GNU Lesser General Public// License as published by the Free Software Foundation; either// version 2.1 of the License, or (at your option) any later version.//// This library is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU// Lesser General Public License for more details.//// You should have received a copy of the GNU Lesser General Public// License along with this library; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA//#include "wgui_include_config.h"#include "wg_rect.h"#include "wg_error.h"#include <algorithm>#ifdef WIN32#include <limits>#endif // WIN32namespace wGui{SDL_Rect CRect::SDLRect(void) const{#ifdef WIN32#ifndef MSVC6  // There are problems with VC6 and these std lib template classes	if (m_Left < std::numeric_limits<short int>::min() ||m_Left > std::numeric_limits<short int>::max()		|| m_Top < std::numeric_limits<short int>::min() ||m_Top > std::numeric_limits<short int>::max()		|| m_Right < std::numeric_limits<short int>::min() ||m_Right > std::numeric_limits<short int>::max()		|| m_Bottom < std::numeric_limits<short int>::min() ||m_Bottom > std::numeric_limits<short int>::max())	{		throw(Wg_Ex_Range("CRect::SDLRect : Out of range - converting int to short int!"));	}#endif // MSVC6#endif // WIN32	SDL_Rect sdlRect;	//Normalize the rect...	sdlRect.x = static_cast<short int>(std::min(m_Left, m_Right));	sdlRect.y = static_cast<short int>(std::min(m_Top, m_Bottom));	sdlRect.w = static_cast<short int>(Width());	sdlRect.h = static_cast<short int>(Height());	return sdlRect;}// assignment operatorCRect& CRect::operator=(const CRect& r){	m_Top = r.Top();	m_Left = r.Left();	m_Right = r.Right();	m_Bottom = r.Bottom();	return *this;}CRect CRect::operator+(const CPoint& p) const{	CRect result(m_Left + p.XPos(), m_Top + p.YPos(), m_Right + p.XPos(), m_Bottom + p.YPos());	return result;}CRect CRect::operator-(const CPoint& p) const{	CRect result(m_Left - p.XPos(), m_Top - p.YPos(), m_Right - p.XPos(), m_Bottom - p.YPos());	return result;}CRect& CRect::Grow(int iGrowAmount){	m_Top -= iGrowAmount;	m_Left -= iGrowAmount;	m_Right += iGrowAmount;	m_Bottom += iGrowAmount;	return *this;}CRect& CRect::Move(int iOffsetX, int iOffsetY){	m_Top += iOffsetX;	m_Left += iOffsetY;	m_Right += iOffsetX;	m_Bottom += iOffsetY;	return *this;}bool CRect::Overlaps(const CRect& r){	bool bOverlap = false;	if (HitTest(r.TopLeft()) == RELPOS_INSIDE || HitTest(r.TopRight()) == RELPOS_INSIDE || HitTest(r.BottomRight()) == RELPOS_INSIDE		|| HitTest(r.BottomLeft()) == RELPOS_INSIDE || r.HitTest(TopLeft()) == RELPOS_INSIDE || r.HitTest(TopRight()) == RELPOS_INSIDE		|| r.HitTest(BottomRight()) == RELPOS_INSIDE || r.HitTest(BottomLeft()) == RELPOS_INSIDE)	{		bOverlap = true;	}// TODO: Still need to check for one more case where no corner lies in another rect	return bOverlap;}void CRect::ClipTo(const CRect& r){	if (m_Left < r.Left())	{		m_Left = r.Left();	}	if (m_Right < r.Left())	{		m_Right = r.Left();	}	if (m_Top < r.Top())	{		m_Top = r.Top();	}	if (m_Bottom < r.Top())	{		m_Bottom = r.Top();	}	if (m_Right > r.Right())	{		m_Right = r.Right();	}	if (m_Left > r.Right())	{		m_Left = r.Right();	}	if (m_Bottom > r.Bottom())	{		m_Bottom = r.Bottom();	}	if (m_Top > r.Bottom())	{		m_Top = r.Bottom();	}}// test to see if the point lies within the rectunsigned int CRect::HitTest(const CPoint& p) const{	unsigned int eRelPos = 0;	eRelPos |= (p.XPos() < m_Left) ? RELPOS_LEFT : 0;	eRelPos |= (p.YPos() < m_Top) ? RELPOS_ABOVE: 0;	eRelPos |= (p.XPos() > m_Right) ? RELPOS_RIGHT : 0;	eRelPos |= (p.YPos() > m_Bottom) ? RELPOS_BELOW: 0;	eRelPos |= (p.XPos() >= m_Left && p.XPos() <= m_Right &&		p.YPos() >= m_Top && p.YPos() <= m_Bottom) ? RELPOS_INSIDE : 0;	return eRelPos;}}

⌨️ 快捷键说明

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