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

📄 wg_view.cpp

📁 一个小巧的嵌入式图形系统wGUI, 可以用VC编译
💻 CPP
字号:
// wg_view.cpp//// CView 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_view.h"#include "wg_error.h"#include "wg_painter.h"#include "wg_message_server.h"#include "wg_application.h"namespace wGui{CView* CView::m_pInstance = 0;CView::CView(const CRect& WindowRect, std::string sTitle, bool bResizable, bool bFullScreen) :	CWindow(WindowRect, 0),	m_bResizable(bResizable),	m_bFullScreen(bFullScreen),	m_pMenu(0){  m_sClassName = "CView";	if (m_pInstance)	{		throw(Wg_Ex_App("Cannot have more than one view at a time!"));	}	m_pInstance = this;	m_sWindowText = sTitle;	Uint32 iFlags = SDL_HWSURFACE | SDL_ANYFORMAT;	if (m_bResizable && !m_bFullScreen)	{		iFlags |= SDL_RESIZABLE;	}	if (m_bFullScreen)	{		iFlags |= SDL_FULLSCREEN;		m_bResizable = false;	}	m_pSDLSurface = SDL_SetVideoMode(m_WindowRect.Width(), m_WindowRect.Height(), DEFAULT_BPP, iFlags);	if (m_pSDLSurface == NULL)	{		throw(Wg_Ex_SDL(std::string("Could not set video mode : ") + SDL_GetError()));	}	SDL_WM_SetCaption(m_sWindowText.c_str(), "");	CMessageServer::Instance().RegisterMessageClient(this, CMessage::APP_PAINT);	CMessageServer::Instance().RegisterMessageClient(this, CMessage::CTRL_RESIZE);	CMessageServer::Instance().RegisterMessageClient(this, CMessage::MOUSE_BUTTONDOWN, CMessageServer::PRIORITY_FIRST);	CMessageServer::Instance().RegisterMessageClient(this, CMessage::MOUSE_BUTTONUP, CMessageServer::PRIORITY_FIRST);	// Send a message to the queue so that the view gets painted as soon as the app starts up	CMessageServer::Instance().QueueMessage(new CMessage(CMessage::APP_PAINT, this, this));}CView::~CView(void){	delete m_pMenu;	SDL_FreeSurface(m_pSDLSurface);	if (m_pInstance == this)	{		m_pInstance = 0;	}}void CView::AttachMenu(CMenu* pMenu){	delete m_pMenu;	m_pMenu = pMenu;	if (m_pMenu)	{		m_pMenu->SetWindowRect(CRect(0, 0, m_WindowRect.Width() - 1, m_pMenu->GetWindowRect().Height()));		m_ClientRect.SetTop(m_pMenu->GetWindowRect().Height() + 1);		m_ClientRect.ClipTo(m_WindowRect);	}	else	{		m_ClientRect = m_WindowRect;	}}void CView::SetWindowText(const std::string& sText){	CWindow::SetWindowText(sText);	SDL_WM_SetCaption(m_sWindowText.c_str(), "");}bool CView::HandleMessage(CMessage* pMessage){	bool bHandled = false;	if (pMessage)	{		switch(pMessage->MessageType())		{		case CMessage::APP_PAINT :			if (pMessage->Destination() == this || pMessage->Destination() == 0)			{				StartDrawProc();				// if this is a broadcasted message, don't mark it as handled				bHandled = (pMessage->Destination() == this);			}			break;		case CMessage::CTRL_RESIZE:		{			TPointMessage* pResizeMessage = dynamic_cast<TPointMessage*>(pMessage);			if (pResizeMessage && pResizeMessage->Source() == CApplication::Instance())			{				Uint32 iFlags = SDL_HWSURFACE | SDL_ANYFORMAT;				if(m_bResizable)				{					iFlags |= SDL_RESIZABLE;				}				m_WindowRect.SetBottom(m_WindowRect.Top() + pResizeMessage->Value().YPos());				m_WindowRect.SetRight(m_WindowRect.Left() + pResizeMessage->Value().XPos());				m_ClientRect = CRect(0, 0, m_WindowRect.Width(), m_WindowRect.Height());				m_pSDLSurface = SDL_SetVideoMode(m_WindowRect.Width(), m_WindowRect.Height(), DEFAULT_BPP, iFlags);				StartDrawProc();			}			break;		}		case CMessage::MOUSE_BUTTONDOWN:		{			CMouseMessage* pMouseMessage = dynamic_cast<CMouseMessage*>(pMessage);			if (pMouseMessage && m_WindowRect.HitTest(pMouseMessage->Point) == CRect::RELPOS_INSIDE)			{				OnMouseButtonDown(pMouseMessage->Point, pMouseMessage->Button);			}			break;		}		case CMessage::MOUSE_BUTTONUP:		{			CMouseMessage* pMouseMessage = dynamic_cast<CMouseMessage*>(pMessage);			if (pMouseMessage && m_WindowRect.HitTest(pMouseMessage->Point) == CRect::RELPOS_INSIDE)			{				OnMouseButtonUp(pMouseMessage->Point, pMouseMessage->Button);			}			break;		}		default :			bHandled = CWindow::HandleMessage(pMessage);			break;		}	}	return bHandled;}}

⌨️ 快捷键说明

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