void System::ProcessInput() { // Check if we should quit if (m_input->IsKeyDown(GLFW_KEY_ESCAPE)) isRunning = false; if (Graphics::Get()->GetCurrentlySelected() != nullptr) { if (m_input->IsKeyDown(GLFW_KEY_W)) { Graphics::Get()->GetCurrentlySelected()->Transform( &((*Graphics::Get()->GetCurrentlySelected()->GetPosition()) + vec3(0.0f, 0.0f, TRANSLATION_AMOUNT*m_timer->GetDeltaTime())), Graphics::Get()->GetCurrentlySelected()->GetRotation(), Graphics::Get()->GetCurrentlySelected()->GetScale() ); } if (m_input->IsKeyDown(GLFW_KEY_S)) { Graphics::Get()->GetCurrentlySelected()->Transform( &((*Graphics::Get()->GetCurrentlySelected()->GetPosition()) + vec3(0.0f, 0.0f, -TRANSLATION_AMOUNT*m_timer->GetDeltaTime())), Graphics::Get()->GetCurrentlySelected()->GetRotation(), Graphics::Get()->GetCurrentlySelected()->GetScale() ); } if (m_input->IsKeyDown(GLFW_KEY_A)) { Graphics::Get()->GetCurrentlySelected()->Transform( &((*Graphics::Get()->GetCurrentlySelected()->GetPosition()) + vec3(TRANSLATION_AMOUNT*m_timer->GetDeltaTime(), 0.0f, 0.0f)), Graphics::Get()->GetCurrentlySelected()->GetRotation(), Graphics::Get()->GetCurrentlySelected()->GetScale() ); } if (m_input->IsKeyDown(GLFW_KEY_D)) { Graphics::Get()->GetCurrentlySelected()->Transform( &((*Graphics::Get()->GetCurrentlySelected()->GetPosition()) + vec3(-TRANSLATION_AMOUNT*m_timer->GetDeltaTime(), 0.0f, 0.0f)), Graphics::Get()->GetCurrentlySelected()->GetRotation(), Graphics::Get()->GetCurrentlySelected()->GetScale() ); } if (m_input->IsKeyDown(GLFW_KEY_Q)) { Graphics::Get()->GetCurrentlySelected()->Transform( &((*Graphics::Get()->GetCurrentlySelected()->GetPosition()) + vec3(0.0f, TRANSLATION_AMOUNT*m_timer->GetDeltaTime(), 0.0f)), Graphics::Get()->GetCurrentlySelected()->GetRotation(), Graphics::Get()->GetCurrentlySelected()->GetScale() ); } if (m_input->IsKeyDown(GLFW_KEY_Z)) { Graphics::Get()->GetCurrentlySelected()->Transform( &((*Graphics::Get()->GetCurrentlySelected()->GetPosition()) + vec3(0.0f, -TRANSLATION_AMOUNT*m_timer->GetDeltaTime(), 0.0f)), Graphics::Get()->GetCurrentlySelected()->GetRotation(), Graphics::Get()->GetCurrentlySelected()->GetScale() ); } if (m_input->IsKeyDown(GLFW_KEY_E)) { Graphics::Get()->GetCurrentlySelected()->Transform( Graphics::Get()->GetCurrentlySelected()->GetPosition(), &((*Graphics::Get()->GetCurrentlySelected()->GetRotation()) + vec3(ROTATION_AMOUNT*m_timer->GetDeltaTime(), 0.0f, 0.0f)), Graphics::Get()->GetCurrentlySelected()->GetScale() ); } if (m_input->IsKeyDown(GLFW_KEY_R)) { Graphics::Get()->GetCurrentlySelected()->Transform( Graphics::Get()->GetCurrentlySelected()->GetPosition(), &((*Graphics::Get()->GetCurrentlySelected()->GetRotation()) + vec3(0.0f, ROTATION_AMOUNT*m_timer->GetDeltaTime(), 0.0f)), Graphics::Get()->GetCurrentlySelected()->GetScale() ); } if (m_input->IsKeyDown(GLFW_KEY_T)) { Graphics::Get()->GetCurrentlySelected()->Transform( Graphics::Get()->GetCurrentlySelected()->GetPosition(), &((*Graphics::Get()->GetCurrentlySelected()->GetRotation()) + vec3(0.0f, 0.0f, ROTATION_AMOUNT*m_timer->GetDeltaTime())), Graphics::Get()->GetCurrentlySelected()->GetScale() ); } if (m_input->IsKeyDown(GLFW_KEY_F)) { Graphics::Get()->GetCurrentlySelected()->Transform( Graphics::Get()->GetCurrentlySelected()->GetPosition(), &((*Graphics::Get()->GetCurrentlySelected()->GetRotation()) + vec3(-ROTATION_AMOUNT*m_timer->GetDeltaTime(), 0.0f, 0.0f)), Graphics::Get()->GetCurrentlySelected()->GetScale() ); } if (m_input->IsKeyDown(GLFW_KEY_G)) { Graphics::Get()->GetCurrentlySelected()->Transform( Graphics::Get()->GetCurrentlySelected()->GetPosition(), &((*Graphics::Get()->GetCurrentlySelected()->GetRotation()) + vec3(0.0f, -ROTATION_AMOUNT*m_timer->GetDeltaTime(), 0.0f)), Graphics::Get()->GetCurrentlySelected()->GetScale() ); } if (m_input->IsKeyDown(GLFW_KEY_H)) { Graphics::Get()->GetCurrentlySelected()->Transform( Graphics::Get()->GetCurrentlySelected()->GetPosition(), &((*Graphics::Get()->GetCurrentlySelected()->GetRotation()) + vec3(0.0f, 0.0f, -ROTATION_AMOUNT*m_timer->GetDeltaTime())), Graphics::Get()->GetCurrentlySelected()->GetScale() ); } } // process mouse to rotate camera if (m_input->IsMouseButtonDown(GLFW_MOUSE_BUTTON_2)) { glfwSetInputMode(Graphics::Get()->GetWindowPtr(), GLFW_CURSOR, GLFW_CURSOR_DISABLED); ProcessCameraMovement(); // reset mouse for the next frame glfwSetCursorPos(Graphics::Get()->GetWindowPtr(), WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2); } else { glfwSetInputMode(Graphics::Get()->GetWindowPtr(), GLFW_CURSOR, GLFW_CURSOR_NORMAL); } if (m_input->IsMouseButtonDown(GLFW_MOUSE_BUTTON_1)) { if (m_timer->GetCurrentTime() - m_timer->GetFlag(0) > 250) { m_timer->SetFlag(0); ProcessMouseClick(); } } }
//************************************************************************************** BOOL CBCGPDlgImpl::PreTranslateMessage(MSG* pMsg) { switch (pMsg->message) { case WM_SYSKEYDOWN: case WM_CONTEXTMENU: if (CBCGPPopupMenu::GetActiveMenu() != NULL && ::IsWindow (CBCGPPopupMenu::GetActiveMenu()->m_hWnd) && pMsg->wParam == VK_MENU) { CBCGPPopupMenu::GetActiveMenu()->SendMessage (WM_CLOSE); return TRUE; } break; case WM_SYSKEYUP: if (CBCGPPopupMenu::GetActiveMenu() != NULL && ::IsWindow (CBCGPPopupMenu::GetActiveMenu()->m_hWnd)) { return TRUE; // To prevent system menu opening } break; case WM_KEYDOWN: //----------------------------------------- // Pass keyboard action to the active menu: //----------------------------------------- if (CBCGPPopupMenu::GetActiveMenu() != NULL && ::IsWindow (CBCGPPopupMenu::GetActiveMenu()->m_hWnd)) { CBCGPPopupMenu::GetActiveMenu()->SendMessage (WM_KEYDOWN, (int) pMsg->wParam); return TRUE; } #ifndef BCGP_EXCLUDE_RIBBON #ifndef _BCGSUITE_ if (m_bBackstageMode && (pMsg->wParam == VK_HOME || pMsg->wParam == VK_ESCAPE)) { for (CWnd* pWndParent = m_Dlg.GetParent(); pWndParent != NULL; pWndParent = pWndParent->GetParent()) { CBCGPRibbonBackstageView* pView = DYNAMIC_DOWNCAST(CBCGPRibbonBackstageView, pWndParent); if (pView != NULL) { if (pMsg->wParam == VK_HOME) { #define MAX_CLASS_NAME 255 #define EDIT_CLASS _T("Edit") TCHAR lpszClassName [MAX_CLASS_NAME + 1]; if (CWnd::GetFocus()->GetSafeHwnd() != NULL) { ::GetClassName (CWnd::GetFocus()->GetSafeHwnd (), lpszClassName, MAX_CLASS_NAME); CString strClass = lpszClassName; if (strClass == EDIT_CLASS) { return FALSE; } } pView->SetFocus(); } else // Escape { pView->SendMessage(WM_CLOSE); } return TRUE; } } return TRUE; } #endif #endif break; case WM_LBUTTONDOWN: case WM_RBUTTONDOWN: case WM_RBUTTONUP: case WM_MBUTTONDOWN: case WM_MBUTTONUP: { CPoint pt (BCG_GET_X_LPARAM(pMsg->lParam), BCG_GET_Y_LPARAM(pMsg->lParam)); CWnd* pWnd = CWnd::FromHandle (pMsg->hwnd); if (pWnd != NULL && ::IsWindow (pMsg->hwnd)) { pWnd->ClientToScreen (&pt); } if (ProcessMouseClick (pt)) { return TRUE; } if (!::IsWindow (pMsg->hwnd)) { return TRUE; } } break; case WM_NCLBUTTONDOWN: case WM_NCLBUTTONUP: case WM_NCRBUTTONDOWN: case WM_NCRBUTTONUP: case WM_NCMBUTTONDOWN: case WM_NCMBUTTONUP: if (ProcessMouseClick (CPoint (BCG_GET_X_LPARAM(pMsg->lParam), BCG_GET_Y_LPARAM(pMsg->lParam)))) { return TRUE; } if (pMsg->message == WM_NCRBUTTONUP && pMsg->hwnd == m_Dlg.GetSafeHwnd () && IsOwnerDrawCaption ()) { CPoint pt (BCG_GET_X_LPARAM(pMsg->lParam), BCG_GET_Y_LPARAM(pMsg->lParam)); UINT nHit = OnNcHitTest (pt); if (nHit == HTCAPTION || nHit == HTSYSMENU) { CMenu* pMenu = m_Dlg.GetSystemMenu (FALSE); if (pMenu->GetSafeHmenu () != NULL && ::IsMenu (pMenu->GetSafeHmenu ())) { UINT uiRes = ::TrackPopupMenu (pMenu->GetSafeHmenu(), TPM_LEFTBUTTON | TPM_RETURNCMD, pt.x, pt.y, 0, m_Dlg.GetSafeHwnd (), NULL); if (uiRes != 0) { m_Dlg.SendMessage (WM_SYSCOMMAND, uiRes); return TRUE; } } } } break; case WM_MOUSEWHEEL: if (CBCGPPopupMenu::GetActiveMenu() != NULL && ::IsWindow (CBCGPPopupMenu::GetActiveMenu()->m_hWnd) && CBCGPPopupMenu::GetActiveMenu()->IsScrollable ()) { CBCGPPopupMenu::GetActiveMenu()->SendMessage (WM_MOUSEWHEEL, pMsg->wParam, pMsg->lParam); } #ifndef BCGP_EXCLUDE_RIBBON #ifndef _BCGSUITE_ else { CPoint ptCursor; ::GetCursorPos (&ptCursor); CWnd* pWnd = CWnd::WindowFromPoint(ptCursor); CBCGPRibbonGalleryCtrl* pGalleryCtrl = DYNAMIC_DOWNCAST(CBCGPRibbonGalleryCtrl, pWnd); if (pGalleryCtrl != NULL) { pGalleryCtrl->SendMessage (WM_MOUSEWHEEL, pMsg->wParam, pMsg->lParam); return TRUE; } } #endif #endif break; case WM_MOUSEMOVE: { CPoint pt (BCG_GET_X_LPARAM(pMsg->lParam), BCG_GET_Y_LPARAM(pMsg->lParam)); CWnd* pWnd = CWnd::FromHandle (pMsg->hwnd); if (pWnd != NULL) { pWnd->ClientToScreen (&pt); } if (ProcessMouseMove (pt)) { return TRUE; } } } return FALSE; }