Compare commits

..

6 Commits

Author SHA1 Message Date
Attila Uygun b292f423ba mouse events 2023-08-10 12:50:38 +02:00
Attila Uygun 2985fed3d4 tmp 2023-08-10 11:06:32 +02:00
Attila Uygun 6619cd368b tmp 2023-08-10 10:40:31 +02:00
Attila Uygun ba1e5cc681 win log 2023-08-10 10:39:54 +02:00
Attila Uygun f8df7d86f6 tmp 2023-08-10 10:39:53 +02:00
Attila Uygun 6e952e511e Add Platform::CreateMainWindow 2023-08-10 10:03:28 +02:00
4 changed files with 47 additions and 11 deletions

View File

@ -26,7 +26,9 @@ AudioMixer::AudioMixer()
#elif defined(__linux__) #elif defined(__linux__)
audio_sink_{std::make_unique<AudioSinkAlsa>(this)} { audio_sink_{std::make_unique<AudioSinkAlsa>(this)} {
#elif defined(_WIN32) #elif defined(_WIN32)
audio_sink_{std::make_unique<AudioSinkNull>()} { // TODO: Implement AudioSinkWindows
audio_sink_{std::make_unique<AudioSinkNull>()},
audio_enabled_(false) {
#endif #endif
bool res = audio_sink_->Initialize(); bool res = audio_sink_->Initialize();
CHECK(res) << "Failed to initialize audio sink."; CHECK(res) << "Failed to initialize audio sink.";

View File

@ -487,7 +487,8 @@ bool Engine::IsMobile() const {
} }
void Engine::OnWindowCreated() { void Engine::OnWindowCreated() {
renderer_->Initialize(platform_); if (renderer_)
renderer_->Initialize(platform_);
} }
void Engine::OnWindowDestroyed() { void Engine::OnWindowDestroyed() {

View File

@ -106,8 +106,9 @@ void Platform::Update() {
case ClientMessage: { case ClientMessage: {
// WM_DELETE_WINDOW is the only registered type for now. // WM_DELETE_WINDOW is the only registered type for now.
observer_->OnWindowDestroyed(); observer_->OnWindowDestroyed();
DestroyWindow();
should_exit_ = true; should_exit_ = true;
break; return;
} }
case ConfigureNotify: { case ConfigureNotify: {
XConfigureEvent xce = e.xconfigure; XConfigureEvent xce = e.xconfigure;

View File

@ -6,8 +6,8 @@
// #include <memory> // #include <memory>
// //
#include "base/log.h" #include "base/log.h"
// #include "base/vecmath.h" #include "base/vecmath.h"
// #include "engine/input_event.h" #include "engine/input_event.h"
#include "engine/platform/platform_observer.h" #include "engine/platform/platform_observer.h"
using namespace base; using namespace base;
@ -20,9 +20,22 @@ Platform::Platform(HINSTANCE instance, int cmd_show)
: instance_(instance), cmd_show_(cmd_show) { : instance_(instance), cmd_show_(cmd_show) {
LOG(0) << "Initializing platform."; LOG(0) << "Initializing platform.";
root_path_ = "./"; root_path_ = ".\\";
data_path_ = "./"; data_path_ = ".\\";
shared_data_path_ = "./"; shared_data_path_ = ".\\";
char dest[MAX_PATH];
memset(dest, 0, sizeof(dest));
if (GetModuleFileNameA(NULL, dest, MAX_PATH) > 0) {
std::string path = dest;
std::size_t last_slash_pos = path.find_last_of('\\');
if (last_slash_pos != std::string::npos)
path = path.substr(0, last_slash_pos + 1);
root_path_ = path;
data_path_ = path;
shared_data_path_ = path;
}
LOG(0) << "Root path: " << root_path_.c_str(); LOG(0) << "Root path: " << root_path_.c_str();
LOG(0) << "Data path: " << data_path_.c_str(); LOG(0) << "Data path: " << data_path_.c_str();
@ -56,12 +69,9 @@ void Platform::CreateMainWindow() {
Platform::~Platform() { Platform::~Platform() {
LOG(0) << "Shutting down platform."; LOG(0) << "Shutting down platform.";
DestroyWindow(wnd_);
} }
void Platform::Update() { void Platform::Update() {
DCHECK(!should_exit_);
MSG msg; MSG msg;
while (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE)) { while (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE)) {
if (msg.message == WM_QUIT) { if (msg.message == WM_QUIT) {
@ -112,6 +122,28 @@ LRESULT CALLBACK Platform::WndProc(HWND wnd,
platform->observer_->OnWindowDestroyed(); platform->observer_->OnWindowDestroyed();
PostQuitMessage(0); PostQuitMessage(0);
break; break;
case WM_MOUSEMOVE: {
Vector2f v(MAKEPOINTS(lparam).x, MAKEPOINTS(lparam).y);
auto input_event =
std::make_unique<InputEvent>(InputEvent::kDrag, 0, v);
platform->observer_->AddInputEvent(std::move(input_event));
} break;
case WM_LBUTTONDOWN: {
Vector2f v(MAKEPOINTS(lparam).x, MAKEPOINTS(lparam).y);
auto input_event =
std::make_unique<InputEvent>(InputEvent::kDragStart, 0, v);
platform->observer_->AddInputEvent(std::move(input_event));
} break;
case WM_LBUTTONUP: {
Vector2f v(MAKEPOINTS(lparam).x, MAKEPOINTS(lparam).y);
auto input_event =
std::make_unique<InputEvent>(InputEvent::kDragEnd, 0, v);
platform->observer_->AddInputEvent(std::move(input_event));
} break;
default: default:
return DefWindowProc(wnd, message, wparam, lparam); return DefWindowProc(wnd, message, wparam, lparam);
} }