CopperWindow.h

Go to the documentation of this file.
00001 #ifndef _COPPER_WINDOW_H
00002 #define _COPPER_WINDOW_H
00003 
00004 #include "MercuryObject.h"
00005 #include <map>
00006 
00008 struct CopperKeypress
00009 {
00010     char cLetter;
00011     enum {
00012         KEY_DOWN,
00013         KEY_UP
00014     } pType;
00015 };
00016 
00018 struct CopperMouseEvent
00019 {
00020     int x;
00021     int y;
00022     enum {
00023         MOUSE_MOVE,
00024         MOUSE_DOWN,
00025         MOUSE_UP,
00026         MOUSE_IN,
00027         MOUSE_OUT
00028     } pType;
00029 };
00030 
00032 struct CSTMessagePair
00033 {
00034     MString Message;
00035     MString Data;
00036     bool Use() { return Message.length() != 0 || Data.length() != 0; }
00037     void Broadcast() { if (Use()) MESSAGEMAN->BroadcastMessage( Message, PStack(PSElement(Data) )); }
00038 };
00039 
00040 
00041 class ScreenCopper;
00042 
00044 class CopperWindow : public MercuryObject
00045 {
00046 public:
00047     virtual ~CopperWindow();
00048     virtual void Init( CopperWindow * pParent, const MString & sName );
00049 //  virtual void Update( const float dTime );
00050     virtual void KeyPress( const CopperKeypress & pKeypress );
00051     virtual bool MouseEvent( const CopperMouseEvent & pMouseEvent );
00052     virtual bool IsMouseEventOnTarget( const CopperMouseEvent & pMouseEvent );
00053 
00054     virtual bool IsFocusable() = 0;
00055 
00056     MString GetFocus();
00057     void SetFocus( const MString & sFocus );
00058 
00059     void SetWidth( float fWidth ) { m_fWidth = fWidth; }
00060     void SetHeight( float fHeight ) { m_fHeight = fHeight; }
00061 
00062     float GetWidth() { return m_fWidth; }
00063     float GetHeight() { return m_fHeight; }
00064     CLASS_RTTI( CopperWindow, MercuryObject );
00065 protected:
00066     CSTMessagePair  m_pBrdOverOn;
00067     CSTMessagePair  m_pBrdOverOff;
00068     CSTMessagePair  m_pBrdUpInTarget;
00069     CSTMessagePair  m_pBrdUpOutTarget;
00070     CSTMessagePair  m_pBrdDown;
00071 
00072     CopperWindow *  m_pParent;
00073     MVector < CopperWindow * > m_vWindows;
00074     int         m_iCurrentFocus;
00075     float       m_fHeight, m_fWidth;
00076     int         m_iLastMouseWindow;
00077 };
00078 
00079 
00080 
00081 //NOTE: This type of self-registering system is almost an
00082 //exact rip-off of the one in Rage (for StepMania). The following
00083 //few lines are (c) 2001-2005 Chris Danford, Glenn Maynard
00084 //and fall under the MIT/X11 license listed at the bottom of this 
00085 //document.
00086 
00087 typedef CopperWindow* (*NewCopperFunction)(const MString& sClassName);
00088 void RegisterCopperWindow( const MString& sClassName, NewCopperFunction pfn );
00089 
00090 #define REGISTER_COPPER_CLASS( className ) \
00091     static CopperWindow* Create##className( const MString &sName ) \
00092     { CopperWindow *pRet = new className( /*sName*/ ); return pRet; } \
00093     struct Register##className { \
00094         Register##className() { RegisterCopperWindow( #className,Create##className); } \
00095     }; \
00096     static Register##className register_##className;
00097 
00098 extern std::map< MString, NewCopperFunction >  *ToMakeWindows;
00099 
00100 CopperWindow * GetCopperByClass( const MString & sClassName, const MString & sWindowName );
00101 
00102 //End of Rage-based registering system.
00103 
00104 #endif
00105 
00106 /*
00107  * (c) 2005 Joshua Allen, Charles Lohr
00108  * All rights reserved.
00109  *
00110  * Certain parts of the code (as noted)
00111  * (c) 2001-2005 Chris Danford, Glenn Maynard
00112  * All rights reserved.
00113  * 
00114  * Permission is hereby granted, free of charge, to any person obtaining a
00115  * copy of this software and associated documentation files (the
00116  * "Software"), to deal in the Software without restriction, including
00117  * without limitation the rights to use, copy, modify, merge, publish,
00118  * distribute, and/or sell copies of the Software, and to permit persons to
00119  * whom the Software is furnished to do so, provided that the above
00120  * copyright notice(s) and this permission notice appear in all copies of
00121  * the Software and that both the above copyright notice(s) and this
00122  * permission notice appear in supporting documentation.
00123  * 
00124  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00125  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00126  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
00127  * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
00128  * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
00129  * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
00130  * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
00131  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00132  * PERFORMANCE OF THIS SOFTWARE.
00133  */

Hosted by SourceForge.net Logo