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

📄 wg_window.h

📁 一个小巧的嵌入式图形系统wGUI, 可以用VC编译
💻 H
字号:
// wg_window.h//// CWindow interface// this serves as the base of all window derived classes//// 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//#ifndef _WG_WINDOW_H_#define _WG_WINDOW_H_#include "wg_rect.h"#include "wg_color.h"#include "wg_message_client.h"#include <string>#include <list>#include "SDL.h"namespace wGui{//! A base class with all the basic properties needed by a window//! CWindow i inherits from the CMessageClient class so that any 'window' can recieve messages//! CWindow provides the basic properties and methods needed to define a window//! Almost all controls and views will be derived from thisclass CWindow : public CMessageClient{public:	//! The constructor will automatically register the new window with the specified parent as a child (if a parent is given)	//! The parent is then responsible for destroying the window  	//! \param WindowRect A CRect that defines the outer limits of the control	//! \param pParent A pointer to the parent window	CWindow(const CRect& WindowRect, CWindow* pParent);	//! The CWindow destructor will automatically deregister itself with it's parent (if it had one)	virtual ~CWindow(void);	//! Giving a control a new WindowRect will move and resize the control	//! \param WindowRect A CRect that defines the outer limits of the control	virtual void SetWindowRect(const CRect& WindowRect);	//! \return A copy of the CRect that the window represents	virtual CRect GetWindowRect(void) const { return m_WindowRect; }	//! Move the window and any child windows	//! \param MoveDistance The relative distance to move the window	virtual void MoveWindow(const CPoint& MoveDistance);	//! The ClientRect describes the internal area of the control	//! By default, this is initialized to the value of the WindowRect	//! The ClientRect is useful for windows that will contain other windows	//! Internally it's represented via the window's coordinates	//! \return The client area CRect	virtual CRect GetClientRect(void) const;	//! Set the window's background color	//! \param Color A CRGBColor that represents the background color	virtual void SetBGColor(const CRGBColor& Color) { m_BGColor = Color; }	//! Retrieve a window's background color	//! \return A CRGBColor object that represents the background color	virtual CRGBColor GetBGColor(void) { return m_BGColor; }	//! Describes the ancestor that is desired	enum EAncestor {		PARENT, //!< return the direct parent of the window		ROOT //!< climb the parent chain all the way until the root and return it	};	//! GetAncestor will return an ancestor of the window (using it's parent chain) based upon the requested ancestor	//! \param eAncestor The desired ancestor of the window	//! \return A pointer to the ancestor window, 0 is the window has no ancestors	virtual CWindow* GetAncestor(EAncestor eAncestor) const;	//! Find out if the window is a child of another specified window	//! \param pWindow A pointer to the window that we're testing to see if this is a child of	//! \return true if the window is a child of the specified window, this will return false if the specified window is the same as the current window	virtual bool IsChildOf(CWindow* pWindow) const;	//! Get the visibility of the control	//! \return true if the control is visible	virtual bool IsVisible(void) { return m_bVisible; }	//! Set the visibility of the control, and all of it's children	//! \param bVisible Set to false to hide the control	virtual void SetVisible(bool bVisible);	//! \return A pointer to the window's SDL surface	virtual SDL_Surface* GetSDLSurface(void) { return m_pSDLSurface; }	//! Translate the given CRect into screen coordinates	//! \param Rect A CRect in client coordinates	virtual CRect ClientToScreen(const CRect& Rect) const { return Rect + GetClientRect().TopLeft(); }	//! Translate the given CPoint into screen coordinates	//! \param Point A CPoint in client coordinates	virtual CPoint ClientToScreen(const CPoint& Point) const { return Point + GetClientRect().TopLeft(); }	//! Set the WindowText of the control	//! \param sText The text to assign to the window	virtual void SetWindowText(const std::string& sText);	//! Return the WindowText for the current window	//! \return The WindowText	virtual std::string GetWindowText(void) { return m_sWindowText; }	//! Return the classname for the object	//! \return The classname of the object	virtual const std::string& GetClassName(void) { return m_sClassName; }	//! The rendering chain for windows	//! DrawProc() is the primary draw method and calls the other draw methods	virtual void DrawProc(void) const;	//! Render the background for the control	//! Draws the background as a filled CRect	virtual void DrawBG(void) const;	//! Render the control itself	virtual void Draw(void) const;	//! Call DrawProc() for any children of the current windows	virtual void DrawChildren(void) const;	//! The last chance to do any further drawing	virtual void DrawPostChild(void) const;	//! This calls DrawProc, then updates the relevant screen area	virtual void StartDrawProc(void) const;	//! Transfer the ownership of the window, so it has a new parent	//! \param pNewParent A pointer to a window that should be set as the parent	virtual void SetNewParent(CWindow* pNewParent);	//! This is called whenever the window is clicked on by the mouse	//! Only the topmost window that bounds the point will be called by the system	//! \param Point The point where the mouse clicked	//! \param Button A bitfield indicating which button the window was clicked with	//! \return False by default, if an overridden control uses the click, then it should return true if it's in the bounds of the window	virtual bool OnMouseButtonDown(CPoint Point, unsigned int Button);	//! This is called whenever the a mouse button is released in a window	//! Only the topmost window that bounds the point will be called by the system	//! \param Point The point where the mouse clicked	//! \param Button A bitfield indicating which button the window was clicked with	//! \return False by default, if an overridden control uses the click, then it should return true if it's in the bounds of the window	virtual bool OnMouseButtonUp(CPoint Point, unsigned int Button);	// CMessageClient overrides	//! Attempt to handle the given message	//! CWindows handle any APP_PAINT messages that have them marked as the destination	//! \return true if the object handled the message (the message will not be given to any other handlers)	virtual bool HandleMessage(CMessage* pMessage);protected:	// Registering and Deregistering child windows is automatically handled by the constructors and destructors	//! Register pWindow as a child	//! \param pWindow A pointer to the child window	virtual void RegisterChildWindow(CWindow* pWindow);	//! Deregister pWindow as a child	//! \param pWindow A pointer to the child window	virtual void DeregisterChildWindow(CWindow* pWindow);	//! The Window Text (not directly used by CWindow)	std::string m_sWindowText;	//! The area the control occupies	CRect m_WindowRect;	//! Background color of the window	CRGBColor m_BGColor;	//! The client area of the window, represented in the window's coordinates where (0,0) is the top left corner of the window	CRect m_ClientRect;	//! Pointer to the parent window	CWindow* m_pParentWindow;	//! A list of child windows	std::list<CWindow*> m_ChildWindows;	//! A pointer to the SDL surface that the window exists on, and should use for drawing itself	SDL_Surface* m_pSDLSurface;	//! If this is false, the control will not draw itself	bool m_bVisible;	//! A string that identifies the class	std::string m_sClassName;private:	void operator=(CWindow) { }  //!< The assignment operator is not allowed for CWindow objects};}#endif // _WG_WINDOW_H_

⌨️ 快捷键说明

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