Main Page | Class Hierarchy | Class List | File List | Class Members | Related Pages

D:/Programming/GUI Editor (Source)/GUIEventHandler.cpp

00001 #include "StdAfx.h" 00002 #include "GUI.h" 00003 00004 CGUIEventHandler::CGUIEventHandler(UINT MaxMessages) 00005 { 00006 m_uiMessageCount = MaxMessages; 00007 m_pMessages = new tGUIMessage[MaxMessages]; 00008 m_uiLastUnusedMessage = 0; 00009 } 00010 00011 CGUIEventHandler::~CGUIEventHandler() 00012 { 00013 if(m_pMessages !=NULL) 00014 SAFEDEL_ARRAY(m_pMessages) 00015 } 00016 00017 int CGUIEventHandler::PostMessage(CGUIElement *pSender, CGUIElement *pReceiver, eGUIMessage eMessage, DWORD lParam, DWORD wParam, UINT uiTimeoutMs) 00018 { 00019 tGUIMessage *NewMessage = NULL; 00020 UINT NewUnusedMessage = 0; 00021 00022 00023 for (UINT i=0; i<m_uiMessageCount; i++) 00024 { 00025 if(m_pMessages[i].bUsed == false && NewMessage != NULL) 00026 { 00027 m_uiLastUnusedMessage = i; 00028 break; 00029 } 00030 00031 if(m_pMessages[i].bUsed == false && NewMessage == NULL) 00032 NewMessage = (tGUIMessage *)&m_pMessages[i]; 00033 } 00034 00035 if(NewMessage !=NULL) 00036 { 00037 NewMessage->pReceiver = pReceiver; 00038 NewMessage->pSender = pSender; 00039 NewMessage->uiMessage = eMessage; 00040 NewMessage->dwTimeout = uiTimeoutMs; 00041 NewMessage->dwCreateTime = m_Timer.GetAbsoluteTime(); 00042 NewMessage->dwParam[0] = lParam; 00043 NewMessage->dwParam[1] = wParam; 00044 NewMessage->bUsed = true; 00045 00046 return 1; 00047 } 00048 00049 return 0; 00050 } 00051 00052 void CGUIEventHandler::Dispatch(bool bOnce) 00053 { 00054 for (int i=0; i<m_uiMessageCount; i++) 00055 { 00056 tGUIMessage *pMessage = (tGUIMessage *)&m_pMessages[i]; 00057 if(m_pMessages[i].bUsed) 00058 { 00059 double CurrentTime = m_Timer.GetAbsoluteTime(); 00060 if(CurrentTime - m_pMessages[i].dwCreateTime) 00061 { 00062 if(pMessage->pReceiver !=NULL) 00063 { 00064 pMessage->pReceiver->ProcessMessage(*pMessage); 00065 if(bOnce) 00066 pMessage->bUsed = false; 00067 } 00068 } 00069 } 00070 } 00071 } 00072 00073 tGUIMessage *CGUIEventHandler::GetMessage(UINT uiIndex) 00074 { 00075 if(uiIndex >=0 && uiIndex < m_uiMessageCount) 00076 return (tGUIMessage *)&m_pMessages[uiIndex]; 00077 00078 return NULL; 00079 } 00080 00081 void CGUIEventHandler::Flush() 00082 { 00083 for (int i=0; i<m_uiMessageCount; i++) 00084 { 00085 tGUIMessage *pMessage = (tGUIMessage *)&m_pMessages[i]; 00086 pMessage->bUsed = false; 00087 pMessage->uiMessage = 0; 00088 pMessage->pSender = pMessage->pReceiver = NULL; 00089 } 00090 }

Generated on Sun Jul 17 21:34:27 2005 for OpenGL GUI by doxygen 1.3.8