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

📄 wg_checkbox.cpp

📁 一个小巧的嵌入式图形系统wGUI, 可以用VC编译
💻 CPP
字号:
// wg_checkbox.cpp//// CCheckBox 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_checkbox.h"#include "wg_message_server.h"namespace wGui{CCheckBox::CCheckBox(const CRect& WindowRect, CWindow* pParent) :	CWindow(WindowRect, pParent),	m_eCheckBoxState(UNCHECKED),	m_MouseButton(0){  m_sClassName = "CCheckBox";	m_BGColor = COLOR_WHITE;	CMessageServer::Instance().RegisterMessageClient(this, CMessage::MOUSE_BUTTONUP);	CMessageServer::Instance().RegisterMessageClient(this, CMessage::CTRL_LCLICK);}CCheckBox::~CCheckBox(void){}void CCheckBox::SetCheckBoxState(EState eState){	if (m_eCheckBoxState != eState)	{		m_eCheckBoxState = eState;		StartDrawProc();	}}void CCheckBox::Draw(void) const{	CWindow::Draw();	CRect SubRect(m_WindowRect);	SubRect.Grow(-1);	CPainter Painter(m_pSDLSurface);	Painter.DrawRect(m_WindowRect, false, COLOR_BLACK);	if (m_eCheckBoxState != DISABLED)	{		Painter.DrawRect(SubRect, false, COLOR_LIGHTGRAY);		Painter.DrawHLine(SubRect.Left(), SubRect.Right(), SubRect.Top(), COLOR_DARKGRAY);		Painter.DrawVLine(SubRect.Top(), SubRect.Bottom(), SubRect.Left(), COLOR_DARKGRAY);		SubRect.Grow(-2);		if (m_eCheckBoxState == CHECKED)		{			Painter.DrawLine(SubRect.TopLeft(), SubRect.BottomRight(), DEFAULT_LINE_COLOR);			Painter.DrawLine(SubRect.BottomLeft(), SubRect.TopRight(), DEFAULT_LINE_COLOR);		}	}}bool CCheckBox::OnMouseButtonDown(CPoint Point, unsigned int Button){	bool bResult = false; 	if (! CWindow::OnMouseButtonDown(Point, Button) && m_bVisible && (m_WindowRect.HitTest(Point) == CRect::RELPOS_INSIDE) &&		(m_eCheckBoxState != DISABLED))	{		m_MouseButton = Button;		bResult = true;	}	return bResult;}bool CCheckBox::OnMouseButtonUp(CPoint Point, unsigned int Button){	bool bResult = false;	if (! CWindow::OnMouseButtonUp(Point, Button) && m_bVisible && (m_WindowRect.HitTest(Point) == CRect::RELPOS_INSIDE) &&		(m_eCheckBoxState != DISABLED) && (m_MouseButton == Button))	{		CMessage::EMessageType MessageType =  CMessage::UNKNOWN;		switch (m_MouseButton)		{		case CMouseMessage::LEFT:			MessageType = CMessage::CTRL_LCLICK;			break;		case CMouseMessage::RIGHT:			MessageType = CMessage::CTRL_RCLICK;			break;		case CMouseMessage::MIDDLE:			MessageType = CMessage::CTRL_MCLICK;			break;		}		CMessageServer::Instance().QueueMessage(new TIntMessage(MessageType, this, this, 0));		bResult = true;	}	return bResult;}bool CCheckBox::HandleMessage(CMessage* pMessage){	bool bHandled = false;	if (pMessage)	{		switch(pMessage->MessageType())		{		case CMessage::MOUSE_BUTTONUP:		{			CMouseMessage* pMouseMessage = dynamic_cast<CMouseMessage*>(pMessage);			if (pMouseMessage && (m_WindowRect.HitTest(pMouseMessage->Point) != CRect::RELPOS_INSIDE)				&& (m_MouseButton == pMouseMessage->Button) && (m_eCheckBoxState != DISABLED))			{				m_MouseButton = 0;				bHandled = true;			}			break;		}		case CMessage::CTRL_LCLICK:			if (pMessage->Destination() == this)			{				switch (m_eCheckBoxState)				{				case UNCHECKED:					SetCheckBoxState(CHECKED);					CMessageServer::Instance().QueueMessage(new TIntMessage(CMessage::CTRL_VALUECHANGE, m_pParentWindow, this, 1));					break;				case CHECKED:					SetCheckBoxState(UNCHECKED);					CMessageServer::Instance().QueueMessage(new TIntMessage(CMessage::CTRL_VALUECHANGE, m_pParentWindow, this, 0));					break;				default:					break;				}				bHandled = true;			}			break;		default :			bHandled = CWindow::HandleMessage(pMessage);			break;		}	}	return bHandled;}}

⌨️ 快捷键说明

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