00001 #include "StdAfx.h" 00002 #include "Mouse.h" 00003 00004 CMouse::CMouse() 00005 { 00006 m_uipKeys = new UINT[8]; 00007 m_uiKeyCount = 8; 00008 } 00009 00010 CMouse::~CMouse() 00011 { 00012 Destroy(); 00013 } 00014 00015 int CMouse::Create() 00016 { 00017 #ifdef DIRECT_INPUT 00018 if(m_pDIDevice == NULL) 00019 { 00020 HRESULT Result = g_pDI->CreateDevice(GUID_SysMouse, &m_pDIDevice, NULL); 00021 if(FAILED(Result)) 00022 return 0; 00023 00024 m_pDIDevice->SetDataFormat( &c_dfDIMouse2 ); 00025 return 1; 00026 } 00027 #endif 00028 00029 return 1; 00030 } 00031 00032 UINT CMouse::Poll() 00033 { 00034 if(m_uipKeys == NULL) 00035 return 0; 00036 00037 POINT Point; 00038 ::GetCursorPos(&Point); 00039 00040 m_PrevCursorPos.x = m_CursorPos.x; 00041 m_PrevCursorPos.y = m_CursorPos.y; 00042 00043 m_CursorPos.x = Point.x; 00044 m_CursorPos.y = Point.y; 00045 00046 #ifdef DIRECT_INPUT 00047 if(m_pDIDevice !=NULL) 00048 { 00049 m_pDIDevice->Acquire(); 00050 ZeroMemory(&m_MouseState, sizeof(DIMOUSESTATE2)); 00051 00052 //HRESULT Result = m_pDIDevice->GetDeviceState(sizeof(DIMOUSESTATE2), &m_MouseState); 00053 00054 //for (UINT i=0; i<m_uiKeyCount; i++) 00055 // m_uipKeys[i] = m_MouseState.rgbButtons[i]; 00056 } 00057 #endif 00058 00059 return 1; 00060 } 00061 00062 UINT CMouse::GetKeyState(UINT uiKeyIndex) 00063 { 00064 if(m_uipKeys !=NULL) 00065 return m_uipKeys[uiKeyIndex]; 00066 00067 return 0; 00068 } 00069 00070 void CMouse::SetCursorPos(int x, int y) 00071 { 00072 m_CursorPos.x = x; m_CursorPos.y = y; 00073 } 00074 00075 tVERTEX2d& CMouse::GetCursorPos() 00076 { 00077 return m_CursorPos; 00078 } 00079 00080 tVERTEX2d& CMouse::GetPrevCursorPos() 00081 { 00082 return m_PrevCursorPos; 00083 } 00084 00085 bool CMouse::IsButtonDown(UINT uiButtonIndex) 00086 { 00087 return (GetKeyState(uiButtonIndex) == KEY_DOWN); 00088 } 00089 00090 bool CMouse::IsButtonUp(UINT uiButtonIndex) 00091 { 00092 if(GetKeyState(uiButtonIndex) == KEY_UP) 00093 return true; 00094 00095 return false; 00096 } 00097 00098 void CMouse::Destroy() 00099 { 00100 00101 } 00102 00103 bool CMouse::IsOfType(eEntityType eType) 00104 { 00105 if(eType == Entity_Mouse) 00106 return true; 00107 00108 return CEntity::IsOfType(eType); 00109 }