From da7145cc9e058435c377f40764ed45e2c92592f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Wiesner?= Date: Sun, 1 Mar 2020 17:17:24 +0100 Subject: [PATCH] =?UTF-8?q?Kezdeti=20=C3=A1llapot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 2 +- EventHandler.cpp | 17 +++++++++++++++++ EventHandler.h | 13 +++++++++++++ Geometry.h | 4 ++++ Window.cpp | 20 +++++++++++++++++--- Window.h | 7 +++++++ main.cpp | 4 ++-- 7 files changed, 61 insertions(+), 6 deletions(-) create mode 100644 EventHandler.cpp create mode 100644 EventHandler.h diff --git a/CMakeLists.txt b/CMakeLists.txt index e21fe9d..01c7ea1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,6 @@ project(WinApi) set(CMAKE_CXX_STANDARD 14) -add_executable(WinApi WIN32 main.cpp d3dx12.h DXWindow.cpp DXWindow.h Logger.cpp Logger.h utils.cpp utils.h Window.cpp Window.h Timer.cpp Timer.h IDrawable.h Geometry.h) +add_executable(WinApi WIN32 main.cpp d3dx12.h DXWindow.cpp DXWindow.h Logger.cpp Logger.h utils.cpp utils.h Window.cpp Window.h Timer.cpp Timer.h IDrawable.h Geometry.h EventHandler.cpp EventHandler.h) target_link_libraries(WinApi d3d12.lib dxgi.lib dxguid.lib d3dcompiler.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib) \ No newline at end of file diff --git a/EventHandler.cpp b/EventHandler.cpp new file mode 100644 index 0000000..5e478d7 --- /dev/null +++ b/EventHandler.cpp @@ -0,0 +1,17 @@ +// +// Created by Epagris on 2020. 03. 01.. +// + +#include "EventHandler.h" + +eg3d::EventHandler::EventHandler() { + +} + +int eg3d::EventHandler::processEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { + // TODO eseménykezelés megvalósítása + + // switch()..... + + return 0; +} diff --git a/EventHandler.h b/EventHandler.h new file mode 100644 index 0000000..18d6bdc --- /dev/null +++ b/EventHandler.h @@ -0,0 +1,13 @@ +#pragma once + +#include + +namespace eg3d { + + class EventHandler { + public: + EventHandler(); // konstr. + int processEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); // esemény feldolgozása (0 -> feldolgozva, 1 -> nincs feldolgozva) + }; + +} \ No newline at end of file diff --git a/Geometry.h b/Geometry.h index 447564f..f5da651 100644 --- a/Geometry.h +++ b/Geometry.h @@ -93,6 +93,10 @@ namespace eg3d { return mTopology; } + void loadFromFile(const std::string& fileName) { + // TODO Epagrisnak: Assimpot le kell fordítani mindenkinek! + } + // input assembler beállítása void setupInputAssembler(ComPtr commandList) const { commandList->IASetVertexBuffers(0, 1, &mVertexBufferView); diff --git a/Window.cpp b/Window.cpp index 688463c..97372c4 100644 --- a/Window.cpp +++ b/Window.cpp @@ -6,7 +6,7 @@ namespace eg3d { const char * eg3d::Window::sWndClassName = "eg3d_winclass"; Window * Window::pMainWindow = nullptr; - Window::Window(bool show, WinFn pWindowFunction) : pWindowFunction(pWindowFunction == nullptr ? smWindowFunc : pWindowFunction) // ha nullptr van megadva, akkor visszaáll az eredeti függvényre + Window::Window(bool show, WinFn pWindowFunction) : pWindowFunction(pWindowFunction == nullptr ? smWindowFunc : pWindowFunction), pmEventHandler(nullptr) // ha nullptr van megadva, akkor visszaáll az eredeti függvényre { initializeWndClass(this->pWindowFunction); // window class inicializálása create(); // ablak létrehozása @@ -117,13 +117,19 @@ namespace eg3d { LRESULT Window::smWindowFunc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { + Window * pWindow = static_cast((void *)GetWindowLongPtrA(hwnd, GWLP_USERDATA)); // ablakhoz rendelt eseménykezelő elkérése + switch (message) { case WM_DESTROY: PostQuitMessage(0); break; - default: - return DefWindowProc(hwnd, message, wParam, lParam); + default: // minden egyéb esemény kezelése + if (pWindow-> != nullptr) { // ha meg van adva eseménykezelő + if (pEH->processEvent(hwnd, message, wParam, lParam) != 0) { // ha nem lett lekezelve az esemény + return DefWindowProc(hwnd, message, wParam, lParam); // ...akkor rábízzuk a rendszerre + } + } } return 0; @@ -159,4 +165,12 @@ namespace eg3d { void Window::setThisAsMainWindow() { pMainWindow = this; } + + void Window::setEventHandler(EventHandler *pEH) { + pmEventHandler = pEH; + } + + EventHandler *Window::getEventHandler() const { + return pmEventHandler; + } } diff --git a/Window.h b/Window.h index 68e7a79..ffe454d 100644 --- a/Window.h +++ b/Window.h @@ -4,6 +4,7 @@ #include #include "utils.h" +#include "EventHandler.h" namespace eg3d { @@ -17,6 +18,9 @@ namespace eg3d { ////////////// static LRESULT CALLBACK smWindowFunc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); // window process, mely az ablakhoz lesz kötve + // TODO Epagrisnak: ezt majd még átírom + EventHandler* pmEventHandler; // eseményfeldolgozó osztály pointere + protected: void create(); // ablak létrehozása HWND mHWND; // ablak-handler @@ -44,6 +48,9 @@ namespace eg3d { double getAspectRatio() const; // lekéri a képarányt void setThisAsMainWindow(); // ezt az ablakot állítja be főablaknak + + void setEventHandler(EventHandler* pEH); // event handler beállítása + EventHandler * getEventHandler() const; // event handler lekérése }; } diff --git a/main.cpp b/main.cpp index af35c09..6bf69e4 100644 --- a/main.cpp +++ b/main.cpp @@ -29,13 +29,14 @@ int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszA eg3d::DXWindow win; // megjelenĂ­tĂ©s be, alapĂ©rtelmezett window procedure használata win.setTitle("Keretszöveg"); // keretszöveg beállĂ­tása + // TODO esemĂ©nykezelĹ‘ lĂ©trehozása Ă©s ablakhoz rendelĂ©se + // FPS-mĂ©rĹ‘ callback-fĂĽggvĂ©ny regisztrálása TimerCallbackData timerCBData; timerCBData.callBackFn = CB_FPSaux; timerCBData.ptr = nullptr; gTmr1s.reg(timerCBData); - // TODO geometria Ă©s pool lĂ©trehozása std::vector vertices = { // vertexek { -0.5f, -0.5f, 0.1f, 1.0f, 0.0f, 0.0f }, { 0.5f, -0.5f, 0.1f , 0.0f, 1.0f, 0.0f }, @@ -80,7 +81,6 @@ int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszA gFrames++; // kĂ©pkockaszám lĂ©ptetĂ©se } - // TODO egy másodperces periĂłdusidejű Ăłra lĂ©ptetĂ©se gTmr1s.tick(); }