diff --git a/Editor/App.cpp b/Editor/App.cpp index 09dd0a8bb..28d1ab571 100644 --- a/Editor/App.cpp +++ b/Editor/App.cpp @@ -77,6 +77,9 @@ void App::SetWindow(CoreWindow^ window) DisplayInformation::DisplayContentsInvalidated += ref new TypedEventHandler(this, &App::OnDisplayContentsInvalidated); + window->KeyDown += ref new TypedEventHandler(this, &App::OnKeyDown); + window->CharacterReceived += ref new TypedEventHandler(this, &App::OnCharacterReceived); + editor.SetWindow(wiPlatform::window_type(window)); } @@ -169,10 +172,7 @@ void App::OnWindowClosed(CoreWindow^ sender, CoreWindowEventArgs^ args) void App::OnDpiChanged(DisplayInformation^ sender, Object^ args) { - // Note: The value for LogicalDpi retrieved here may not match the effective DPI of the app - // if it is being scaled for high resolution devices. Once the DPI is set on DeviceResources, - // you should always retrieve it using the GetDpi method. - // See DeviceResources.cpp for more details. + wiPlatform::GetWindowState().dpi = (int)sender->LogicalDpi; } void App::OnOrientationChanged(DisplayInformation^ sender, Object^ args) @@ -181,4 +181,36 @@ void App::OnOrientationChanged(DisplayInformation^ sender, Object^ args) void App::OnDisplayContentsInvalidated(DisplayInformation^ sender, Object^ args) { -} \ No newline at end of file +} + +// Input event handlers +void App::OnKeyDown(CoreWindow^ sender, KeyEventArgs^ key) +{ +} +void App::OnCharacterReceived(CoreWindow^ sender, CharacterReceivedEventArgs^ key) +{ + + switch (key->KeyCode) + { + case (unsigned int)VirtualKey::Back: + if (wiBackLog::isActive()) + wiBackLog::deletefromInput(); + wiTextInputField::DeleteFromInput(); + break; + + case (unsigned int)VirtualKey::Enter: + break; + + default: + { + const char c = (const char)key->KeyCode; + if (wiBackLog::isActive()) + { + wiBackLog::input(c); + } + wiTextInputField::AddInput(c); + } + break; + } + +} diff --git a/Editor/App.h b/Editor/App.h index 858673c09..5619c6390 100644 --- a/Editor/App.h +++ b/Editor/App.h @@ -34,6 +34,10 @@ namespace Template_UWP void OnOrientationChanged(Windows::Graphics::Display::DisplayInformation^ sender, Platform::Object^ args); void OnDisplayContentsInvalidated(Windows::Graphics::Display::DisplayInformation^ sender, Platform::Object^ args); + // Input handlers + void OnKeyDown(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ key); + void OnCharacterReceived(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::CharacterReceivedEventArgs^ key); + private: Editor editor; bool m_windowClosed; diff --git a/Editor/Editor.cpp b/Editor/Editor.cpp index c57474dac..6af9bb5f1 100644 --- a/Editor/Editor.cpp +++ b/Editor/Editor.cpp @@ -67,7 +67,7 @@ void EditorLoadingScreen::Load() WIFALIGN_CENTER, WIFALIGN_CENTER)); AddFont(&font); - sprite = wiSprite("../images/logo_small.png"); + sprite = wiSprite("images/logo_small.png"); sprite.anim.opa = 1; sprite.anim.repeatable = true; sprite.params.pos = XMFLOAT3(wiRenderer::GetDevice()->GetScreenWidth()*0.5f, wiRenderer::GetDevice()->GetScreenHeight()*0.5f - font.textHeight(), 0); @@ -610,14 +610,11 @@ void EditorComponent::Load() saveButton->OnClick([=](wiEventArgs args) { wiHelper::FileDialogParams params; - wiHelper::FileDialogResult result; params.type = wiHelper::FileDialogParams::SAVE; params.description = "Wicked Scene"; params.extensions.push_back("wiscene"); - wiHelper::FileDialog(params, result); + wiHelper::FileDialog(params, [this](std::string fileName) { - if (result.ok) { - string fileName = result.filenames.front(); if (fileName.substr(fileName.length() - 8).compare(".wiscene") != 0) { fileName += ".wiscene"; @@ -635,7 +632,7 @@ void EditorComponent::Load() { wiHelper::messageBox("Could not create " + fileName + "!"); } - } + }); }); GetGUI().AddWidget(saveButton); @@ -645,56 +642,48 @@ void EditorComponent::Load() modelButton->SetColor(wiColor(0, 89, 255, 180), wiWidget::WIDGETSTATE::IDLE); modelButton->SetColor(wiColor(112, 155, 255, 255), wiWidget::WIDGETSTATE::FOCUS); modelButton->OnClick([=](wiEventArgs args) { - thread([&] { + wiHelper::FileDialogParams params; + params.type = wiHelper::FileDialogParams::OPEN; + params.description = "Model formats (.wiscene, .obj, .gltf, .glb)"; + params.extensions.push_back("wiscene"); + params.extensions.push_back("obj"); + params.extensions.push_back("gltf"); + params.extensions.push_back("glb"); + wiHelper::FileDialog(params, [&](std::string fileName) { - wiHelper::FileDialogParams params; - wiHelper::FileDialogResult result; - params.type = wiHelper::FileDialogParams::OPEN; - params.description = "Model formats (.wiscene, .obj, .gltf, .glb)"; - params.extensions.push_back("wiscene"); - params.extensions.push_back("obj"); - params.extensions.push_back("gltf"); - params.extensions.push_back("glb"); - wiHelper::FileDialog(params, result); + main->loader->addLoadingFunction([=] { + string extension = wiHelper::toUpper(wiHelper::GetExtensionFromFileName(fileName)); - if (result.ok) - { - string fileName = result.filenames.front(); - - main->loader->addLoadingFunction([=] { - string extension = wiHelper::toUpper(wiHelper::GetExtensionFromFileName(fileName)); - - if (!extension.compare("WISCENE")) // engine-serialized - { - wiScene::LoadModel(fileName); - } - else if (!extension.compare("OBJ")) // wavefront-obj - { - Scene scene; - ImportModel_OBJ(fileName, scene); - wiScene::GetScene().Merge(scene); - } - else if (!extension.compare("GLTF")) // text-based gltf - { - Scene scene; - ImportModel_GLTF(fileName, scene); - wiScene::GetScene().Merge(scene); - } - else if (!extension.compare("GLB")) // binary gltf - { - Scene scene; - ImportModel_GLTF(fileName, scene); - wiScene::GetScene().Merge(scene); - } - }); - main->loader->onFinished([=] { - main->ActivatePath(this, 0.2f, wiColor::Black()); - weatherWnd->Update(); - }); - main->ActivatePath(main->loader.get(), 0.2f, wiColor::Black()); - ResetHistory(); - } - }).detach(); + if (!extension.compare("WISCENE")) // engine-serialized + { + wiScene::LoadModel(fileName); + } + else if (!extension.compare("OBJ")) // wavefront-obj + { + Scene scene; + ImportModel_OBJ(fileName, scene); + wiScene::GetScene().Merge(scene); + } + else if (!extension.compare("GLTF")) // text-based gltf + { + Scene scene; + ImportModel_GLTF(fileName, scene); + wiScene::GetScene().Merge(scene); + } + else if (!extension.compare("GLB")) // binary gltf + { + Scene scene; + ImportModel_GLTF(fileName, scene); + wiScene::GetScene().Merge(scene); + } + }); + main->loader->onFinished([=] { + main->ActivatePath(this, 0.2f, wiColor::Black()); + weatherWnd->Update(); + }); + main->ActivatePath(main->loader.get(), 0.2f, wiColor::Black()); + ResetHistory(); + }); }); GetGUI().AddWidget(modelButton); @@ -704,21 +693,13 @@ void EditorComponent::Load() scriptButton->SetColor(wiColor(255, 33, 140, 180), wiWidget::WIDGETSTATE::IDLE); scriptButton->SetColor(wiColor(255, 100, 140, 255), wiWidget::WIDGETSTATE::FOCUS); scriptButton->OnClick([=](wiEventArgs args) { - thread([&] { - - wiHelper::FileDialogParams params; - wiHelper::FileDialogResult result; - params.type = wiHelper::FileDialogParams::OPEN; - params.description = "Lua script"; - params.extensions.push_back("lua"); - wiHelper::FileDialog(params, result); - - if (result.ok) { - string fileName = result.filenames.front(); - wiLua::GetGlobal()->RunFile(fileName); - } - }).detach(); - + wiHelper::FileDialogParams params; + params.type = wiHelper::FileDialogParams::OPEN; + params.description = "Lua script"; + params.extensions.push_back("lua"); + wiHelper::FileDialog(params, [](std::string fileName) { + wiLua::GetGlobal()->RunFile(fileName); + }); }); GetGUI().AddWidget(scriptButton); @@ -821,7 +802,7 @@ void EditorComponent::Load() exitButton->SetColor(wiColor(190, 0, 0, 180), wiWidget::WIDGETSTATE::IDLE); exitButton->SetColor(wiColor(255, 0, 0, 255), wiWidget::WIDGETSTATE::FOCUS); exitButton->OnClick([this](wiEventArgs args) { - exit(0); + wiPlatform::Exit(); }); GetGUI().AddWidget(exitButton); @@ -856,7 +837,7 @@ void EditorComponent::Load() GetGUI().AddWidget(cinemaModeCheckBox); - sceneGraphView = new wiTreeList("Scene graph view (WIP)"); + sceneGraphView = new wiTreeList("Scene graph view"); sceneGraphView->OnSelect([this](wiEventArgs args) { translator.selected.clear(); diff --git a/Editor/Editor_UWP.vcxproj b/Editor/Editor_UWP.vcxproj index 07baa26d4..7fadec5e9 100644 --- a/Editor/Editor_UWP.vcxproj +++ b/Editor/Editor_UWP.vcxproj @@ -367,6 +367,11 @@ xcopy /Y /E /I $(SolutionDir)Editor\images $(OutDir)AppX\images Designer + + + {60da258f-e95f-4cf4-a46b-17d80644464b} + + diff --git a/Editor/LightWindow.cpp b/Editor/LightWindow.cpp index 795539cdb..17980721a 100644 --- a/Editor/LightWindow.cpp +++ b/Editor/LightWindow.cpp @@ -266,24 +266,20 @@ LightWindow::LightWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) else { wiHelper::FileDialogParams params; - wiHelper::FileDialogResult result; params.type = wiHelper::FileDialogParams::OPEN; params.description = "Texture"; params.extensions.push_back("dds"); params.extensions.push_back("png"); params.extensions.push_back("jpg"); params.extensions.push_back("tga"); - wiHelper::FileDialog(params, result); - - if (result.ok) { - std::string fileName = result.filenames.front(); + wiHelper::FileDialog(params, [this, light, i](std::string fileName) { light->lensFlareRimTextures[i] = wiResourceManager::Load(fileName); light->lensFlareNames[i] = fileName; fileName = wiHelper::GetFileNameFromPath(fileName); lensflare_Button[i]->SetText(fileName); - } + }); } - }); + }); lightWindow->AddWidget(lensflare_Button[i]); } diff --git a/Editor/MaterialWindow.cpp b/Editor/MaterialWindow.cpp index bb6023947..c2d054aa6 100644 --- a/Editor/MaterialWindow.cpp +++ b/Editor/MaterialWindow.cpp @@ -416,23 +416,19 @@ MaterialWindow::MaterialWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) else { wiHelper::FileDialogParams params; - wiHelper::FileDialogResult result; params.type = wiHelper::FileDialogParams::OPEN; params.description = "Texture"; params.extensions.push_back("dds"); params.extensions.push_back("png"); params.extensions.push_back("jpg"); params.extensions.push_back("tga"); - wiHelper::FileDialog(params, result); - - if (result.ok) { - string fileName = result.filenames.front(); + wiHelper::FileDialog(params, [this, material](std::string fileName) { material->baseColorMap = wiResourceManager::Load(fileName); material->baseColorMapName = fileName; material->SetDirty(); fileName = wiHelper::GetFileNameFromPath(fileName); texture_baseColor_Button->SetText(fileName); - } + }); } }); materialWindow->AddWidget(texture_baseColor_Button); @@ -478,23 +474,19 @@ MaterialWindow::MaterialWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) else { wiHelper::FileDialogParams params; - wiHelper::FileDialogResult result; params.type = wiHelper::FileDialogParams::OPEN; params.description = "Texture"; params.extensions.push_back("dds"); params.extensions.push_back("png"); params.extensions.push_back("jpg"); params.extensions.push_back("tga"); - wiHelper::FileDialog(params, result); - - if (result.ok) { - string fileName = result.filenames.front(); + wiHelper::FileDialog(params, [this, material](std::string fileName) { material->normalMap = wiResourceManager::Load(fileName); material->normalMapName = fileName; material->SetDirty(); fileName = wiHelper::GetFileNameFromPath(fileName); texture_normal_Button->SetText(fileName); - } + }); } }); materialWindow->AddWidget(texture_normal_Button); @@ -540,23 +532,19 @@ MaterialWindow::MaterialWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) else { wiHelper::FileDialogParams params; - wiHelper::FileDialogResult result; params.type = wiHelper::FileDialogParams::OPEN; params.description = "Texture"; params.extensions.push_back("dds"); params.extensions.push_back("png"); params.extensions.push_back("jpg"); params.extensions.push_back("tga"); - wiHelper::FileDialog(params, result); - - if (result.ok) { - string fileName = result.filenames.front(); + wiHelper::FileDialog(params, [this, material](std::string fileName) { material->surfaceMap = wiResourceManager::Load(fileName); material->surfaceMapName = fileName; material->SetDirty(); fileName = wiHelper::GetFileNameFromPath(fileName); texture_surface_Button->SetText(fileName); - } + }); } }); materialWindow->AddWidget(texture_surface_Button); @@ -602,25 +590,21 @@ MaterialWindow::MaterialWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) else { wiHelper::FileDialogParams params; - wiHelper::FileDialogResult result; params.type = wiHelper::FileDialogParams::OPEN; params.description = "Texture"; params.extensions.push_back("dds"); params.extensions.push_back("png"); params.extensions.push_back("jpg"); params.extensions.push_back("tga"); - wiHelper::FileDialog(params, result); - - if (result.ok) { - string fileName = result.filenames.front(); + wiHelper::FileDialog(params, [this, material](std::string fileName) { material->emissiveMap = wiResourceManager::Load(fileName); material->emissiveMapName = fileName; material->SetDirty(); fileName = wiHelper::GetFileNameFromPath(fileName); texture_emissive_Button->SetText(fileName); - } + }); } - }); + }); materialWindow->AddWidget(texture_emissive_Button); texture_emissive_uvset_Field = new wiTextInputField("uvset_emissive"); @@ -664,23 +648,19 @@ MaterialWindow::MaterialWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) else { wiHelper::FileDialogParams params; - wiHelper::FileDialogResult result; params.type = wiHelper::FileDialogParams::OPEN; params.description = "Texture"; params.extensions.push_back("dds"); params.extensions.push_back("png"); params.extensions.push_back("jpg"); params.extensions.push_back("tga"); - wiHelper::FileDialog(params, result); - - if (result.ok) { - string fileName = result.filenames.front(); + wiHelper::FileDialog(params, [this, material](std::string fileName) { material->displacementMap = wiResourceManager::Load(fileName); material->displacementMapName = fileName; material->SetDirty(); fileName = wiHelper::GetFileNameFromPath(fileName); texture_displacement_Button->SetText(fileName); - } + }); } }); materialWindow->AddWidget(texture_displacement_Button); @@ -727,23 +707,19 @@ MaterialWindow::MaterialWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) else { wiHelper::FileDialogParams params; - wiHelper::FileDialogResult result; params.type = wiHelper::FileDialogParams::OPEN; params.description = "Texture"; params.extensions.push_back("dds"); params.extensions.push_back("png"); params.extensions.push_back("jpg"); params.extensions.push_back("tga"); - wiHelper::FileDialog(params, result); - - if (result.ok) { - string fileName = result.filenames.front(); + wiHelper::FileDialog(params, [this, material](std::string fileName) { material->occlusionMap = wiResourceManager::Load(fileName); material->occlusionMapName = fileName; material->SetDirty(); fileName = wiHelper::GetFileNameFromPath(fileName); texture_occlusion_Button->SetText(fileName); - } + }); } }); materialWindow->AddWidget(texture_occlusion_Button); diff --git a/Editor/MeshWindow.cpp b/Editor/MeshWindow.cpp index 9930527c9..c980aaa8b 100644 --- a/Editor/MeshWindow.cpp +++ b/Editor/MeshWindow.cpp @@ -461,17 +461,13 @@ MeshWindow::MeshWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) heightmapButton->OnClick([=](wiEventArgs args) { wiHelper::FileDialogParams params; - wiHelper::FileDialogResult result; params.type = wiHelper::FileDialogParams::OPEN; params.description = "Texture"; params.extensions.push_back("dds"); params.extensions.push_back("png"); params.extensions.push_back("jpg"); params.extensions.push_back("tga"); - wiHelper::FileDialog(params, result); - - if (result.ok) { - string fileName = result.filenames.front(); + wiHelper::FileDialog(params, [=](std::string fileName) { if (this->rgb != nullptr) { @@ -483,7 +479,7 @@ MeshWindow::MeshWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) this->rgb = stbi_load(fileName.c_str(), &this->width, &this->height, &bpp, channelCount); generate_mesh(width, height, rgb, channelCount, dimYSlider->GetValue()); - } + }); }); terrainGenWindow->AddWidget(heightmapButton); diff --git a/Editor/Package.appxmanifest b/Editor/Package.appxmanifest index 56c6f5524..1e480d625 100644 --- a/Editor/Package.appxmanifest +++ b/Editor/Package.appxmanifest @@ -4,6 +4,7 @@ xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" + xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" IgnorableNamespaces="uap mp"> - + \ No newline at end of file diff --git a/Editor/PostprocessWindow.cpp b/Editor/PostprocessWindow.cpp index 2df261cb3..e1ecb1b72 100644 --- a/Editor/PostprocessWindow.cpp +++ b/Editor/PostprocessWindow.cpp @@ -217,26 +217,20 @@ PostprocessWindow::PostprocessWindow(EditorComponent* editor) : GUI(&editor->Get if (x == nullptr) { - thread([&] { - wiHelper::FileDialogParams params; - wiHelper::FileDialogResult result; - params.type = wiHelper::FileDialogParams::OPEN; - params.description = "Texture"; - params.extensions.push_back("dds"); - params.extensions.push_back("png"); - params.extensions.push_back("jpg"); - params.extensions.push_back("tga"); - wiHelper::FileDialog(params, result); - - if (result.ok) { - string fileName = result.filenames.front(); - editor->renderPath->setColorGradingTexture(wiResourceManager::Load(fileName)); - if (editor->renderPath->getColorGradingTexture() != nullptr) - { - colorGradingButton->SetText(fileName); - } + wiHelper::FileDialogParams params; + params.type = wiHelper::FileDialogParams::OPEN; + params.description = "Texture"; + params.extensions.push_back("dds"); + params.extensions.push_back("png"); + params.extensions.push_back("jpg"); + params.extensions.push_back("tga"); + wiHelper::FileDialog(params, [=](std::string fileName) { + editor->renderPath->setColorGradingTexture(wiResourceManager::Load(fileName)); + if (editor->renderPath->getColorGradingTexture() != nullptr) + { + colorGradingButton->SetText(fileName); } - }).detach(); + }); } else { diff --git a/Editor/SoundWindow.cpp b/Editor/SoundWindow.cpp index b9bc5d02b..e20fddbc0 100644 --- a/Editor/SoundWindow.cpp +++ b/Editor/SoundWindow.cpp @@ -69,19 +69,15 @@ SoundWindow::SoundWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) addButton->SetSize(XMFLOAT2(80, 30)); addButton->OnClick([=](wiEventArgs args) { wiHelper::FileDialogParams params; - wiHelper::FileDialogResult result; params.type = wiHelper::FileDialogParams::OPEN; params.description = "Sound"; params.extensions.push_back("wav"); - wiHelper::FileDialog(params, result); - - if (result.ok) { - string fileName = result.filenames.front(); + wiHelper::FileDialog(params, [=](std::string fileName) { Entity entity = GetScene().Entity_CreateSound("editorSound", fileName); editor->ClearSelected(); editor->AddSelected(entity); SetEntity(entity); - } + }); }); soundWindow->AddWidget(addButton); diff --git a/Editor/WeatherWindow.cpp b/Editor/WeatherWindow.cpp index 092ec5a04..c3da0428b 100644 --- a/Editor/WeatherWindow.cpp +++ b/Editor/WeatherWindow.cpp @@ -128,18 +128,15 @@ WeatherWindow::WeatherWindow(EditorComponent* editor) : GUI(&editor->GetGUI()) if (weather.skyMap == nullptr) { wiHelper::FileDialogParams params; - wiHelper::FileDialogResult result; params.type = wiHelper::FileDialogParams::OPEN; params.description = "Cubemap texture"; params.extensions.push_back("dds"); - wiHelper::FileDialog(params, result); - - if (result.ok) { - string fileName = result.filenames.front(); + wiHelper::FileDialog(params, [=](std::string fileName) { + auto& weather = GetWeather(); weather.skyMapName = fileName; weather.skyMap = wiResourceManager::Load(fileName); skyButton->SetText(fileName); - } + }); } else { diff --git a/Editor/images/logo_small.png b/Editor/images/logo_small.png new file mode 100644 index 000000000..9f69ce056 Binary files /dev/null and b/Editor/images/logo_small.png differ diff --git a/Editor/main.cpp b/Editor/main.cpp index 752e0924e..89821f496 100644 --- a/Editor/main.cpp +++ b/Editor/main.cpp @@ -211,32 +211,15 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) } } break; - case WM_KEYDOWN: - switch (wParam) - { - case VK_HOME: - wiBackLog::Toggle(); - break; - case VK_UP: - if (wiBackLog::isActive()) - wiBackLog::historyPrev(); - break; - case VK_DOWN: - if (wiBackLog::isActive()) - wiBackLog::historyNext(); - break; - case VK_NEXT: - if (wiBackLog::isActive()) - wiBackLog::Scroll(10); - break; - case VK_PRIOR: - if (wiBackLog::isActive()) - wiBackLog::Scroll(-10); - break; - default: - break; - } - break; + case WM_DPICHANGED: + { + int dpi_x = LOWORD(wParam); + int dpi_y = HIWORD(wParam); + assert(dpi_x == dpi_y); + RECT* size = (RECT*)lParam; + wiPlatform::GetWindowState().dpi = dpi_x; + } + break; case WM_HOTKEY: switch (wParam) { @@ -258,8 +241,6 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) wiTextInputField::DeleteFromInput(); break; case VK_RETURN: - if (wiBackLog::isActive()) - wiBackLog::acceptInput(); break; default: { diff --git a/Template_UWP/App.cpp b/Template_UWP/App.cpp index 2049de9a6..04edf8555 100644 --- a/Template_UWP/App.cpp +++ b/Template_UWP/App.cpp @@ -82,6 +82,9 @@ void App::SetWindow(CoreWindow^ window) DisplayInformation::DisplayContentsInvalidated += ref new TypedEventHandler(this, &App::OnDisplayContentsInvalidated); + window->KeyDown += ref new TypedEventHandler(this, &App::OnKeyDown); + window->CharacterReceived += ref new TypedEventHandler(this, &App::OnCharacterReceived); + main.SetWindow(wiPlatform::window_type(window)); } @@ -174,10 +177,7 @@ void App::OnWindowClosed(CoreWindow^ sender, CoreWindowEventArgs^ args) void App::OnDpiChanged(DisplayInformation^ sender, Object^ args) { - // Note: The value for LogicalDpi retrieved here may not match the effective DPI of the app - // if it is being scaled for high resolution devices. Once the DPI is set on DeviceResources, - // you should always retrieve it using the GetDpi method. - // See DeviceResources.cpp for more details. + wiPlatform::GetWindowState().dpi = (int)sender->LogicalDpi; } void App::OnOrientationChanged(DisplayInformation^ sender, Object^ args) @@ -186,4 +186,36 @@ void App::OnOrientationChanged(DisplayInformation^ sender, Object^ args) void App::OnDisplayContentsInvalidated(DisplayInformation^ sender, Object^ args) { +} + +// Input event handlers +void App::OnKeyDown(CoreWindow^ sender, KeyEventArgs^ key) +{ +} +void App::OnCharacterReceived(CoreWindow^ sender, CharacterReceivedEventArgs^ key) +{ + + switch (key->KeyCode) + { + case (unsigned int)VirtualKey::Back: + if (wiBackLog::isActive()) + wiBackLog::deletefromInput(); + wiTextInputField::DeleteFromInput(); + break; + + case (unsigned int)VirtualKey::Enter: + break; + + default: + { + const char c = (const char)key->KeyCode; + if (wiBackLog::isActive()) + { + wiBackLog::input(c); + } + wiTextInputField::AddInput(c); + } + break; + } + } \ No newline at end of file diff --git a/Template_UWP/App.h b/Template_UWP/App.h index 82f6fd305..9502124a6 100644 --- a/Template_UWP/App.h +++ b/Template_UWP/App.h @@ -33,6 +33,10 @@ namespace Template_UWP void OnOrientationChanged(Windows::Graphics::Display::DisplayInformation^ sender, Platform::Object^ args); void OnDisplayContentsInvalidated(Windows::Graphics::Display::DisplayInformation^ sender, Platform::Object^ args); + // Input handlers + void OnKeyDown(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ key); + void OnCharacterReceived(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::CharacterReceivedEventArgs^ key); + private: MainComponent main; bool m_windowClosed; diff --git a/Template_UWP/Template_UWP.vcxproj b/Template_UWP/Template_UWP.vcxproj index a4d81e9a4..8acc74199 100644 --- a/Template_UWP/Template_UWP.vcxproj +++ b/Template_UWP/Template_UWP.vcxproj @@ -399,6 +399,11 @@ xcopy /Y /E /I $(SolutionDir)WickedEngine\fonts $(OutDir)AppX\fonts Designer + + + {60da258f-e95f-4cf4-a46b-17d80644464b} + + diff --git a/Template_Windows/main.cpp b/Template_Windows/main.cpp index ed68523ae..b514726cf 100644 --- a/Template_Windows/main.cpp +++ b/Template_Windows/main.cpp @@ -172,32 +172,15 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) } } break; - case WM_KEYDOWN: - switch (wParam) - { - case VK_HOME: - wiBackLog::Toggle(); - break; - case VK_UP: - if (wiBackLog::isActive()) - wiBackLog::historyPrev(); - break; - case VK_DOWN: - if (wiBackLog::isActive()) - wiBackLog::historyNext(); - break; - case VK_NEXT: - if (wiBackLog::isActive()) - wiBackLog::Scroll(10); - break; - case VK_PRIOR: - if (wiBackLog::isActive()) - wiBackLog::Scroll(-10); - break; - default: - break; - } - break; + case WM_DPICHANGED: + { + int dpi_x = LOWORD(wParam); + int dpi_y = HIWORD(wParam); + assert(dpi_x == dpi_y); + RECT* size = (RECT*)lParam; + wiPlatform::GetWindowState().dpi = dpi_x; + } + break; case WM_CHAR: switch (wParam) { @@ -207,8 +190,6 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) wiTextInputField::DeleteFromInput(); break; case VK_RETURN: - if (wiBackLog::isActive()) - wiBackLog::acceptInput(); break; default: { diff --git a/Tests/main.cpp b/Tests/main.cpp index 1a5937ffa..d795904f0 100644 --- a/Tests/main.cpp +++ b/Tests/main.cpp @@ -165,32 +165,15 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) } } break; - case WM_KEYDOWN: - switch (wParam) - { - case VK_HOME: - wiBackLog::Toggle(); - break; - case VK_UP: - if (wiBackLog::isActive()) - wiBackLog::historyPrev(); - break; - case VK_DOWN: - if (wiBackLog::isActive()) - wiBackLog::historyNext(); - break; - case VK_NEXT: - if (wiBackLog::isActive()) - wiBackLog::Scroll(10); - break; - case VK_PRIOR: - if (wiBackLog::isActive()) - wiBackLog::Scroll(-10); - break; - default: - break; - } - break; + case WM_DPICHANGED: + { + int dpi_x = LOWORD(wParam); + int dpi_y = HIWORD(wParam); + assert(dpi_x == dpi_y); + RECT* size = (RECT*)lParam; + wiPlatform::GetWindowState().dpi = dpi_x; + } + break; case WM_CHAR: switch (wParam) { @@ -200,8 +183,6 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) wiTextInputField::DeleteFromInput(); break; case VK_RETURN: - if (wiBackLog::isActive()) - wiBackLog::acceptInput(); break; default: { diff --git a/WickedEngine/MainComponent.cpp b/WickedEngine/MainComponent.cpp index 7a1b7ab17..8efab7e3c 100644 --- a/WickedEngine/MainComponent.cpp +++ b/WickedEngine/MainComponent.cpp @@ -332,6 +332,7 @@ void MainComponent::Compose(CommandList cmd) void MainComponent::SetWindow(wiPlatform::window_type window) { - wiPlatform::GetWindow() = window; + wiPlatform::GetWindowState().window = window; + wiPlatform::InitDPI(); } diff --git a/WickedEngine/wiBackLog.cpp b/WickedEngine/wiBackLog.cpp index 6f79d81e3..ec9b083bf 100644 --- a/WickedEngine/wiBackLog.cpp +++ b/WickedEngine/wiBackLog.cpp @@ -8,6 +8,7 @@ #include "wiSpriteFont.h" #include "wiImage.h" #include "wiLua.h" +#include "wiInput.h" #include #include @@ -60,6 +61,35 @@ namespace wiBackLog } void Update() { + if (wiInput::Press(wiInput::KEYBOARD_BUTTON_HOME)) + { + Toggle(); + } + + if (isActive) + { + if (wiInput::Press(wiInput::KEYBOARD_BUTTON_UP)) + { + historyPrev(); + } + if (wiInput::Press(wiInput::KEYBOARD_BUTTON_DOWN)) + { + historyNext(); + } + if (wiInput::Press(wiInput::KEYBOARD_BUTTON_ENTER)) + { + acceptInput(); + } + if (wiInput::Down(wiInput::KEYBOARD_BUTTON_PAGEUP)) + { + Scroll(10); + } + if (wiInput::Down(wiInput::KEYBOARD_BUTTON_PAGEDOWN)) + { + Scroll(-10); + } + } + if (state == DEACTIVATING) pos -= speed; else if (state == ACTIVATING) diff --git a/WickedEngine/wiGraphicsDevice_DX11.cpp b/WickedEngine/wiGraphicsDevice_DX11.cpp index c9892abf8..5423340a7 100644 --- a/WickedEngine/wiGraphicsDevice_DX11.cpp +++ b/WickedEngine/wiGraphicsDevice_DX11.cpp @@ -1241,7 +1241,7 @@ GraphicsDevice_DX11::GraphicsDevice_DX11(wiPlatform::window_type window, bool fu std::stringstream ss(""); ss << "Failed to create the graphics device! ERROR: " << std::hex << hr; wiHelper::messageBox(ss.str(), "Error!"); - exit(1); + wiPlatform::Exit(); } ComPtr pDXGIDevice; @@ -1287,7 +1287,7 @@ GraphicsDevice_DX11::GraphicsDevice_DX11(wiPlatform::window_type window, bool fu if (FAILED(hr)) { wiHelper::messageBox("Failed to create a swapchain for the graphics device!", "Error!"); - exit(1); + wiPlatform::Exit(); } // Ensure that DXGI does not queue more than one frame at a time. This both reduces latency and @@ -1341,13 +1341,13 @@ void GraphicsDevice_DX11::CreateBackBufferResources() hr = swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), &backBuffer); if (FAILED(hr)) { wiHelper::messageBox("BackBuffer creation Failed!", "Error!"); - exit(1); + wiPlatform::Exit(); } hr = device->CreateRenderTargetView(backBuffer.Get(), nullptr, &renderTargetView); if (FAILED(hr)) { wiHelper::messageBox("Main Rendertarget creation Failed!", "Error!"); - exit(1); + wiPlatform::Exit(); } } diff --git a/WickedEngine/wiGraphicsDevice_DX12.cpp b/WickedEngine/wiGraphicsDevice_DX12.cpp index 6652edd9a..854c3b374 100644 --- a/WickedEngine/wiGraphicsDevice_DX12.cpp +++ b/WickedEngine/wiGraphicsDevice_DX12.cpp @@ -1577,7 +1577,7 @@ using namespace DX12_Internal; ss << "Failed to create the graphics device! ERROR: " << std::hex << hr; wiHelper::messageBox(ss.str(), "Error!"); assert(0); - exit(1); + wiPlatform::Exit(); } D3D12MA::ALLOCATOR_DESC allocatorDesc = {}; @@ -1647,7 +1647,7 @@ using namespace DX12_Internal; { wiHelper::messageBox("Failed to create a swapchain for the graphics device!", "Error!"); assert(0); - exit(1); + wiPlatform::Exit(); } hr = _swapChain.As(&swapChain); diff --git a/WickedEngine/wiHelper.cpp b/WickedEngine/wiHelper.cpp index f3a1fddf5..bf64a5ef8 100644 --- a/WickedEngine/wiHelper.cpp +++ b/WickedEngine/wiHelper.cpp @@ -5,6 +5,7 @@ #include "Utility/stb_image_write.h" +#include #include #include #include @@ -13,8 +14,13 @@ #include #include // string conversion +#ifdef PLATFORM_UWP +#include +#include +#else #include // openfile #include +#endif // PLATFORM_UWP using namespace std; @@ -343,71 +349,145 @@ namespace wiHelper return exists; } - void FileDialog(const FileDialogParams& params, FileDialogResult& result) + void FileDialog(const FileDialogParams& params, std::function onSuccess) { #ifdef _WIN32 #ifndef PLATFORM_UWP - char szFile[256]; + std::thread([=] { - OPENFILENAMEA ofn; - ZeroMemory(&ofn, sizeof(ofn)); - ofn.lStructSize = sizeof(ofn); - ofn.hwndOwner = nullptr; - ofn.lpstrFile = szFile; - // Set lpstrFile[0] to '\0' so that GetOpenFileName does not - // use the contents of szFile to initialize itself. - ofn.lpstrFile[0] = '\0'; - ofn.nMaxFile = sizeof(szFile); - ofn.lpstrFileTitle = NULL; - ofn.nMaxFileTitle = 0; - ofn.lpstrInitialDir = NULL; - ofn.nFilterIndex = 1; + char szFile[256]; - // Slightly convoluted way to create the filter. - // First string is description, ended by '\0' - // Second string is extensions, each separated by ';' and at the end of all, a '\0' - // Then the whole container string is closed with an other '\0' - // For example: "model files\0*.model;*.obj;\0" <-- this string literal has "model files" as description and two accepted extensions "model" and "obj" - std::vector filter; - filter.reserve(256); - { - for (auto& x : params.description) + OPENFILENAMEA ofn; + ZeroMemory(&ofn, sizeof(ofn)); + ofn.lStructSize = sizeof(ofn); + ofn.hwndOwner = nullptr; + ofn.lpstrFile = szFile; + // Set lpstrFile[0] to '\0' so that GetOpenFileName does not + // use the contents of szFile to initialize itself. + ofn.lpstrFile[0] = '\0'; + ofn.nMaxFile = sizeof(szFile); + ofn.lpstrFileTitle = NULL; + ofn.nMaxFileTitle = 0; + ofn.lpstrInitialDir = NULL; + ofn.nFilterIndex = 1; + + // Slightly convoluted way to create the filter. + // First string is description, ended by '\0' + // Second string is extensions, each separated by ';' and at the end of all, a '\0' + // Then the whole container string is closed with an other '\0' + // For example: "model files\0*.model;*.obj;\0" <-- this string literal has "model files" as description and two accepted extensions "model" and "obj" + std::vector filter; + filter.reserve(256); { - filter.push_back(x); - } - filter.push_back(0); - - for (auto& x : params.extensions) - { - filter.push_back('*'); - filter.push_back('.'); - for (auto& y : x) + for (auto& x : params.description) { - filter.push_back(y); + filter.push_back(x); } - filter.push_back(';'); + filter.push_back(0); + + for (auto& x : params.extensions) + { + filter.push_back('*'); + filter.push_back('.'); + for (auto& y : x) + { + filter.push_back(y); + } + filter.push_back(';'); + } + filter.push_back(0); + filter.push_back(0); } - filter.push_back(0); - filter.push_back(0); - } - ofn.lpstrFilter = filter.data(); + ofn.lpstrFilter = filter.data(); + + + BOOL ok = FALSE; + switch (params.type) + { + case FileDialogParams::OPEN: + ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; + ok = GetOpenFileNameA(&ofn) == TRUE; + break; + case FileDialogParams::SAVE: + ofn.Flags = OFN_OVERWRITEPROMPT; + ok = GetSaveFileNameA(&ofn) == TRUE; + break; + } + + if (ok) + { + onSuccess(ofn.lpstrFile); + } + + }).detach(); + +#else + + using namespace concurrency; + using namespace Platform; + using namespace Windows::Storage; + using namespace Windows::Storage::Pickers; + using namespace Windows::UI::Xaml; + using namespace Windows::UI::Xaml::Controls; + using namespace Windows::UI::Xaml::Navigation; switch (params.type) { case FileDialogParams::OPEN: - ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; - result.ok = GetOpenFileNameA(&ofn) == TRUE; - break; - case FileDialogParams::SAVE: - ofn.Flags = OFN_OVERWRITEPROMPT; - result.ok = GetSaveFileNameA(&ofn) == TRUE; - break; - } - - if (result.ok) { - result.filenames.push_back(ofn.lpstrFile); + FileOpenPicker^ picker = ref new FileOpenPicker(); + picker->ViewMode = PickerViewMode::List; + picker->SuggestedStartLocation = PickerLocationId::ComputerFolder; + + for (auto& x : params.extensions) + { + wstring wstr; + StringConvert(x, wstr); + wstr = L"." + wstr; + picker->FileTypeFilter->Append(ref new String(wstr.c_str())); + } + + create_task(picker->PickSingleFileAsync()).then([=](StorageFile^ file) { + + if (file) + { + wstring wstr = file->Path->Data(); + string str; + StringConvert(wstr, str); + onSuccess(str); + } + }); + } + break; + case FileDialogParams::SAVE: + { + FileSavePicker^ picker = ref new FileSavePicker(); + picker->SuggestedStartLocation = PickerLocationId::ComputerFolder; + + for (auto& x : params.extensions) + { + wstring wstr; + StringConvert(x, wstr); + wstr = L"." + wstr; + auto plainTextExtensions = ref new Platform::Collections::Vector(); + plainTextExtensions->Append(ref new String(wstr.c_str())); + StringConvert(params.description, wstr); + picker->FileTypeChoices->Insert(ref new String(wstr.c_str()), plainTextExtensions); + } + + create_task(picker->PickSaveFileAsync()).then([=](StorageFile^ file) { + + if (file) + { + wstring wstr = file->Path->Data(); + string str; + StringConvert(wstr, str); + onSuccess(str); + } + }); + } + break; } #endif // PLATFORM_UWP diff --git a/WickedEngine/wiHelper.h b/WickedEngine/wiHelper.h index ced5273af..c2308261b 100644 --- a/WickedEngine/wiHelper.h +++ b/WickedEngine/wiHelper.h @@ -4,6 +4,7 @@ #include #include +#include namespace wiHelper { @@ -78,12 +79,7 @@ namespace wiHelper std::string description; std::vector extensions; }; - struct FileDialogResult - { - bool ok = false; - std::vector filenames; - }; - void FileDialog(const FileDialogParams& params, FileDialogResult& result); + void FileDialog(const FileDialogParams& params, std::function onSuccess); void StringConvert(const std::string from, std::wstring& to); diff --git a/WickedEngine/wiPlatform.h b/WickedEngine/wiPlatform.h index 51e5db3b6..f1240e3c6 100644 --- a/WickedEngine/wiPlatform.h +++ b/WickedEngine/wiPlatform.h @@ -26,10 +26,20 @@ namespace wiPlatform #endif // PLATFORM_UWP #endif // _WIN32 + struct WindowState + { + window_type window; + int dpi = 96; + }; + inline WindowState& GetWindowState() + { + static WindowState state; + return state; + } + inline window_type& GetWindow() { - static window_type window; - return window; + return GetWindowState().window; } inline bool IsWindowActive() { @@ -43,20 +53,32 @@ namespace wiPlatform return true; #endif // _WIN32 } - inline int GetDPI() + inline void InitDPI() { #ifdef _WIN32 #ifndef PLATFORM_UWP - return (int)GetDpiForWindow(GetWindow()); + GetWindowState().dpi = (int)GetDpiForWindow(GetWindow()); #else - return (int)Windows::Graphics::Display::DisplayInformation::GetForCurrentView()->LogicalDpi; + GetWindowState().dpi = (int)Windows::Graphics::Display::DisplayInformation::GetForCurrentView()->LogicalDpi; #endif // PLATFORM_UWP -#else - return 96; #endif // _WIN32 } + inline int GetDPI() + { + return GetWindowState().dpi; + } inline float GetDPIScaling() { return (float)GetDPI() / 96.0f; } + inline void Exit() + { +#ifdef _WIN32 +#ifndef PLATFORM_UWP + PostQuitMessage(0); +#else + Windows::ApplicationModel::Core::CoreApplication::Exit(); +#endif // PLATFORM_UWP +#endif // _WIN32 + } } diff --git a/WickedEngine/wiScene_Serializers.cpp b/WickedEngine/wiScene_Serializers.cpp index 5f544f538..b0d7bda60 100644 --- a/WickedEngine/wiScene_Serializers.cpp +++ b/WickedEngine/wiScene_Serializers.cpp @@ -733,7 +733,10 @@ namespace wiScene if (archive.GetVersion() >= 32) { archive >> skyMapName; - skyMap = wiResourceManager::Load(dir + skyMapName); + if (!skyMapName.empty()) + { + skyMap = wiResourceManager::Load(dir + skyMapName); + } } if (archive.GetVersion() >= 40) { diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index 6d9da6dbb..8281121ba 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -9,7 +9,7 @@ namespace wiVersion // minor features, major updates const int minor = 41; // minor bug fixes, alterations, refactors, updates - const int revision = 8; + const int revision = 9; const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);