Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static Window* s_Window = nullptr;
- static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
- WindowsWindow::WindowsWindow(WindowDescriptor& a_WindowDescriptor)
- : Window(a_WindowDescriptor)
- {
- // Set static
- s_Window = this;
- }
- bool WindowsWindow::Initialize()
- {
- // Zero out the memory
- WNDCLASSEX wc;
- ZeroMemory(&wc, sizeof(WNDCLASSEX));
- // Fill in the struct with the needed information
- wc.cbSize = sizeof(WNDCLASSEX);
- wc.style = CS_HREDRAW | CS_VREDRAW;
- wc.lpfnWndProc = WndProc;
- wc.hInstance = GetModuleHandle(NULL);
- wc.hIcon = LoadIcon(wc.hInstance, MAKEINTRESOURCE(IDI_ICON1));
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
- wc.lpszClassName = m_WindowClass.c_str();
- wc.hIconSm = LoadIcon(wc.hInstance, IDI_APPLICATION);
- // Register window class
- RegisterClassEx(&wc);
- // Create the actual window instance
- m_WindowHandle = CreateWindowEx(NULL, m_WindowClass.c_str(), m_WindowTitle.c_str(), WS_OVERLAPPEDWINDOW,
- m_WindowPositionX, m_WindowPositionY, m_Dimensions[m_CurrentDimension].GetWidth(), m_Dimensions[m_CurrentDimension].GetHeight(), NULL, NULL, GetModuleHandle(NULL), NULL);
- return true;
- }
- bool WindowsWindow::Terminate()
- {
- // Destroys the window
- if (m_WindowHandle)
- {
- DestroyWindow(m_WindowHandle);
- m_WindowHandle = nullptr;
- }
- return true;
- }
- void WindowsWindow::UpdateWindow(const float a_DeltaTime)
- {
- MSG msg;
- while (PeekMessage(&msg, m_WindowHandle, 0, 0, PM_REMOVE))
- {
- // Return when painting
- // I know this is a sin...
- if (msg.message == WM_PAINT)
- return;
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- }
- void WindowsWindow::Show()
- {
- ::ShowWindow(m_WindowHandle, SW_SHOW);
- }
- void WindowsWindow::Hide()
- {
- ::ShowWindow(m_WindowHandle, SW_HIDE);
- }
- static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
- {
- // sort through and find what code to run for the message given
- switch (message)
- {
- // close the applCcation entirely
- case WM_DESTROY:
- {
- // Broadcast event
- Event::EventSystem::Broadcast<Event::WindowCloseEvent>();
- PostQuitMessage(0);
- Chlorine::Core::Engine::GetInstance()->RequestStop();
- return 0;
- }
- break;
- case WM_WINDOWPOSCHANGED:
- case WM_WINDOWPOSCHANGING:
- {
- WINDOWPOS* w = (WINDOWPOS*)(lParam);
- std::cout << "CX: " << w->cx << ", CY: " << w->cy << std::endl;
- }
- break;
- case WM_SIZE:
- {
- if (hwnd != (HWND)s_Window->GetNativeWindowHandle())
- {
- std::cout << "hello";
- }
- // Will only happen if it is a resizable window
- unsigned int width = LOWORD(lParam);
- unsigned int height = HIWORD(lParam);
- char type = char(wParam);
- // Minimize
- if (width == 0 || height == 0)
- break;
- // Maximize
- if (width == s_Window->GetWidth() && height == s_Window->GetHeight())
- break;
- // Set the custom dimensions
- s_Window->SetWindowDimensionID(CHLORINE_WINDOW_DIMENSION_CUSTOM);
- s_Window->SetWindowCustomDimension(width, height);
- // Broadcast event
- Event::EventSystem::Broadcast<Event::WindowResizeEvent>((Event::WindowResizeType)type, width, height);
- }
- break;
- case WM_MOVE:
- {
- unsigned int positionX = LOWORD(lParam);
- unsigned int positionY = HIWORD(lParam);
- // Broadcast event
- Event::EventSystem::Broadcast<Event::WindowMoveEvent>(positionX, positionY);
- // s_Window->SetWindowPosition(positionX, positionY);
- }
- break;
- case WM_LBUTTONDOWN:
- {
- // Broadcast event
- Event::EventSystem::Broadcast<Event::InputMousePressEvent>(CHLORINE_MOUSE_BUTTON_LEFT);
- }
- break;
- case WM_LBUTTONUP:
- {
- // Broadcast event
- Event::EventSystem::Broadcast<Event::InputMouseReleaseEvent>(CHLORINE_MOUSE_BUTTON_LEFT);
- }
- break;
- case WM_INPUT:
- {
- }
- break;
- }
- // Handle any messages the switch statement didn't
- return DefWindowProc(hwnd, message, wParam, lParam);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement