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

📄 wg_tooltip.cpp

📁 一个小巧的嵌入式图形系统wGUI, 可以用VC编译
💻 CPP
字号:
// wg_tooltip.cpp//// CToolTip interface////// 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_tooltip.h"namespace wGui{CToolTip::CToolTip(CWindow* pToolWindow, std::string sText, CRGBColor& FontColor, CRGBColor& BGColor, CFontEngine* pFontEngine) :	CWindow(CRect(), pToolWindow),	m_FontColor(FontColor){  m_sClassName = "CToolTip";	m_sWindowText = sText;	if (pFontEngine)	{		m_pFontEngine = pFontEngine;	}	else	{		m_pFontEngine = CApplication::Instance()->GetDefaultFontEngine();	}	std::auto_ptr<CRenderedString> pRenderedString(new CRenderedString(		m_pFontEngine, sText, CRenderedString::VALIGN_TOP, CRenderedString::HALIGN_LEFT));	m_pRenderedString = pRenderedString;	m_pTimer = new CTimer(this);	//Now resize the window so that it fits the Tooltip text	CPoint Dims;	m_pRenderedString->GetMetrics(&Dims, 0, 0);	m_BoundingRect = CRect(CPoint(0, 0), Dims + CPoint(4, 4));	m_BGColor = BGColor;	CMessageServer::Instance().RegisterMessageClient(this, CMessage::MOUSE_MOVE);	CMessageServer::Instance().RegisterMessageClient(this, CMessage::CTRL_TIMER);}CToolTip::~CToolTip(void){}void CToolTip::ShowTip(const CPoint& DrawPoint){	SetWindowRect(m_BoundingRect + DrawPoint);	SetVisible(true);	StartDrawProc();}void CToolTip::HideTip(void){	SetVisible(false);	CMessageServer::Instance().QueueMessage(new CMessage(CMessage::APP_PAINT, 0, this));}void CToolTip::Draw(void) const{	CWindow::Draw();	CPainter Painter(m_pSDLSurface);	Painter.DrawRect(m_WindowRect, false);	CRect SubRect(m_WindowRect);	SubRect.Grow(-2);	m_pRenderedString->Draw(m_pSDLSurface, SubRect, SubRect.TopLeft(), m_FontColor);}void CToolTip::MoveWindow(const CPoint& MoveDistance){	CWindow::MoveWindow(MoveDistance);	m_BoundingRect = m_BoundingRect + MoveDistance;}bool CToolTip::HandleMessage(CMessage* pMessage){	bool bHandled = false;	if (pMessage)	{		switch(pMessage->MessageType())		{			case CMessage::CTRL_TIMER:			{				wGui::TIntMessage* pTimerMessage = dynamic_cast<wGui::TIntMessage*>(pMessage);				if (pTimerMessage && pMessage->Destination() == this)				{					// Timer has expired, so it's time to show the tooltip					ShowTip(m_LastMousePosition + CPoint(-6, 18));					bHandled = true;				}				break;			}		case CMessage::MOUSE_MOVE:		{			// We don't want to mess with the underlying control, so don't trap any MOUSE_MOVE messages			CMouseMessage* pMouseMessage = dynamic_cast<CMouseMessage*>(pMessage);			if (pMouseMessage)			{				m_LastMousePosition = pMouseMessage->Point;				m_pTimer->StopTimer();				if (IsVisible())				{					HideTip();				}				if (m_pParentWindow->GetWindowRect().HitTest(m_LastMousePosition) == CRect::RELPOS_INSIDE)				{					m_pTimer->StartTimer(1000);				}			}		}		default :			bHandled = CWindow::HandleMessage(pMessage);			break;		}	}	return bHandled;}}

⌨️ 快捷键说明

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