/****************************************************************************************** * Chili Direct3D Engine * * Copyright 2018 PlanetChili * * * * This file is part of Chili Direct3D Engine. * * * * Chili Direct3D Engine is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * The Chili Direct3D Engine is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with The Chili Direct3D Engine. If not, see . * ******************************************************************************************/ #pragma once #include "ChiliWin.h" #include "ChiliException.h" #include "Keyboard.h" #include "Mouse.h" #include "Graphics.h" #include #include class Window { public: class Exception : public ChiliException { using ChiliException::ChiliException; public: static std::string TranslateErrorCode(HRESULT hr) noexcept; }; class HrException : public Exception { public: HrException(int line, const char* file, HRESULT hr) noexcept; const char* what() const noexcept override; const char* GetType() const noexcept override; HRESULT GetErrorCode() const noexcept; std::string GetErrorDescription() const noexcept; private: HRESULT hr; }; class NoGfxException : public Exception { public: using Exception::Exception; const char* GetType() const noexcept override; }; private: // singleton manages registration/cleanup of window class class WindowClass { public: static const char* GetName() noexcept; static HINSTANCE GetInstance() noexcept; private: WindowClass() noexcept; ~WindowClass(); WindowClass(const WindowClass&) = delete; WindowClass& operator=(const WindowClass&) = delete; static constexpr const char* wndClassName = "Chili Direct3D Engine Window"; static WindowClass wndClass; HINSTANCE hInst; }; public: Window(int width, int height, const char* name); ~Window(); Window(const Window&) = delete; Window& operator=(const Window&) = delete; void SetTitle(const std::string& title); static std::optional ProcessMessages() noexcept; Graphics& Gfx(); private: static LRESULT CALLBACK HandleMsgSetup(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) noexcept; static LRESULT CALLBACK HandleMsgThunk(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) noexcept; LRESULT HandleMsg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) noexcept; public: Keyboard kbd; Mouse mouse; private: int width; int height; HWND hWnd; // 成员变量gfx在Window的构造函数执行的过程中才会被初始化,因此定义指针变量,用于初始化gfx std::unique_ptr pGfx; };