| 29 | } |
| 30 | |
| 31 | MouseState MouseState::GetMouseState(HWND hwnd) |
| 32 | { |
| 33 | POINT pos; |
| 34 | if (!GetCursorPos(&pos)) |
| 35 | throw Win32Exception(GetLastError()); |
| 36 | |
| 37 | if (hwnd != NULL) |
| 38 | if(!ScreenToClient(hwnd, &pos)) |
| 39 | throw Win32Exception(GetLastError()); |
| 40 | |
| 41 | MouseState newState; |
| 42 | newState.X = pos.x; |
| 43 | newState.Y = pos.y; |
| 44 | newState.DX = pos.x - prevState.X; |
| 45 | newState.DY = pos.y - prevState.Y; |
| 46 | |
| 47 | newState.LButton.Pressed = (GetKeyState(VK_LBUTTON) & 0x8000) > 0; |
| 48 | newState.LButton.RisingEdge = newState.LButton.Pressed && !prevState.LButton.Pressed; |
| 49 | newState.LButton.RisingEdge = !newState.LButton.Pressed && prevState.LButton.Pressed; |
| 50 | |
| 51 | newState.MButton.Pressed = (GetKeyState(VK_MBUTTON) & 0x8000) > 0; |
| 52 | newState.MButton.RisingEdge = newState.MButton.Pressed && !prevState.MButton.Pressed; |
| 53 | newState.MButton.RisingEdge = !newState.MButton.Pressed && prevState.MButton.Pressed; |
| 54 | |
| 55 | newState.RButton.Pressed = (GetKeyState(VK_RBUTTON) & 0x8000) > 0; |
| 56 | newState.RButton.RisingEdge = newState.RButton.Pressed && !prevState.RButton.Pressed; |
| 57 | newState.RButton.RisingEdge = !newState.RButton.Pressed && prevState.RButton.Pressed; |
| 58 | |
| 59 | if (hwnd != NULL) |
| 60 | { |
| 61 | RECT clientRect; |
| 62 | if (!::GetClientRect(hwnd, &clientRect)) |
| 63 | throw Win32Exception(GetLastError()); |
| 64 | newState.IsOverWindow = (pos.x >= 0 && pos.x < clientRect.right |
| 65 | && pos.y >= 0 && pos.y < clientRect.bottom); |
| 66 | } |
| 67 | else |
| 68 | newState.IsOverWindow = false; |
| 69 | |
| 70 | prevState = newState; |
| 71 | return prevState; |
| 72 | } |
| 73 | |
| 74 | void MouseState::SetCursorPos(int x, int y, HWND hwnd) |
| 75 | { |
nothing calls this directly
no test coverage detected