wip
This commit is contained in:
@@ -110,11 +110,9 @@ else()
|
||||
endif()
|
||||
|
||||
if (WIN32)
|
||||
set(PLATFORM "Windows")
|
||||
add_compile_definitions(WIN32=1)
|
||||
add_compile_definitions(_HAS_EXCEPTIONS=0)
|
||||
elseif (UNIX)
|
||||
set(PLATFORM "SDL2")
|
||||
add_compile_definitions(SDL2=1)
|
||||
add_compile_definitions(_GLIBCXX_USE_CXX11_ABI=1)
|
||||
endif()
|
||||
|
||||
+14
-14
@@ -376,7 +376,20 @@ void Editor::SaveWindowSize()
|
||||
{
|
||||
if (window != nullptr)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
#ifdef SDL2
|
||||
if (!(SDL_GetWindowFlags(window) & SDL_WINDOW_MAXIMIZED))
|
||||
{
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
SDL_GetWindowSize(window, &width, &height);
|
||||
if (width > 0 && height > 0)
|
||||
{
|
||||
config.Set("width", width);
|
||||
config.Set("height", height);
|
||||
config.Commit();
|
||||
}
|
||||
}
|
||||
#elif defined(_WIN32)
|
||||
WINDOWPLACEMENT placement = {};
|
||||
placement.length = sizeof(WINDOWPLACEMENT);
|
||||
if (GetWindowPlacement(window, &placement) && placement.showCmd != SW_SHOWMAXIMIZED)
|
||||
@@ -392,19 +405,6 @@ void Editor::SaveWindowSize()
|
||||
config.Commit();
|
||||
}
|
||||
}
|
||||
#elif defined(SDL2)
|
||||
if (!(SDL_GetWindowFlags(window) & SDL_WINDOW_MAXIMIZED))
|
||||
{
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
SDL_GetWindowSize(window, &width, &height);
|
||||
if (width > 0 && height > 0)
|
||||
{
|
||||
config.Set("width", width);
|
||||
config.Set("height", height);
|
||||
config.Commit();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
#include "ImGui/imgui.h"
|
||||
#include "ImGui/imgui_internal.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "ImGui/imgui_impl_win32.h"
|
||||
#elif defined(SDL2)
|
||||
#ifdef SDL2
|
||||
#include "ImGui/imgui_impl_sdl.h"
|
||||
#elif defined(_WIN32)
|
||||
#include "ImGui/imgui_impl_win32.h"
|
||||
#endif
|
||||
|
||||
#include <fstream>
|
||||
@@ -97,10 +97,10 @@ Example_ImGui::~Example_ImGui()
|
||||
{
|
||||
// Cleanup
|
||||
//ImGui_ImplDX11_Shutdown();
|
||||
#ifdef _WIN32
|
||||
ImGui_ImplWin32_Shutdown();
|
||||
#elif defined(SDL2)
|
||||
#ifdef SDL2
|
||||
ImGui_ImplSDL2_Shutdown();
|
||||
#elif defined(_WIN32)
|
||||
ImGui_ImplWin32_Shutdown();
|
||||
#endif
|
||||
ImGui::DestroyContext();
|
||||
}
|
||||
@@ -129,10 +129,11 @@ void Example_ImGui::Initialize()
|
||||
ImGui::StyleColorsDark();
|
||||
//ImGui::StyleColorsClassic();
|
||||
|
||||
#ifdef _WIN32
|
||||
ImGui_ImplWin32_Init(window);
|
||||
#elif defined(SDL2)
|
||||
#ifdef SDL2
|
||||
//FIXME: add DX12 on windows
|
||||
ImGui_ImplSDL2_InitForVulkan(window);
|
||||
#elif defined(_WIN32)
|
||||
ImGui_ImplWin32_Init(window);
|
||||
#endif
|
||||
|
||||
IM_ASSERT(io.BackendRendererUserData == NULL && "Already initialized a renderer backend!");
|
||||
@@ -374,10 +375,10 @@ void Example_ImGuiRenderer::Update(float dt)
|
||||
ImGui_Impl_CreateDeviceObjects();
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
ImGui_ImplWin32_NewFrame();
|
||||
#elif defined(SDL2)
|
||||
#ifdef SDL2
|
||||
ImGui_ImplSDL2_NewFrame();
|
||||
#elif defined(_WIN32)
|
||||
ImGui_ImplWin32_NewFrame();
|
||||
#endif
|
||||
ImGui::NewFrame();
|
||||
|
||||
|
||||
@@ -25,7 +25,19 @@ set(IMGUI_FILES
|
||||
ImGui/IconsMaterialDesign.h
|
||||
)
|
||||
|
||||
if (WIN32)
|
||||
if(SDL2)
|
||||
list(APPEND SOURCE_FILES
|
||||
main_SDL2.cpp
|
||||
)
|
||||
list(APPEND IMGUI_FILES
|
||||
ImGui/imgui_impl_sdl.cpp
|
||||
ImGui/imgui_impl_sdl.h
|
||||
)
|
||||
add_library(Example_ImGui_Docking_Lib OBJECT ${IMGUI_FILES})
|
||||
find_package(SDL2 REQUIRED)
|
||||
target_link_libraries(Example_ImGui_Docking_Lib PRIVATE SDL2::SDL2)
|
||||
add_executable(Example_ImGui_Docking ${SOURCE_FILES})
|
||||
elseif(WIN32)
|
||||
list(APPEND SOURCE_FILES
|
||||
main_Windows.cpp
|
||||
main_Windows.h
|
||||
@@ -38,48 +50,31 @@ if (WIN32)
|
||||
add_library(Example_ImGui_Docking_Lib OBJECT ${IMGUI_FILES})
|
||||
|
||||
add_executable(Example_ImGui_Docking WIN32 ${SOURCE_FILES})
|
||||
endif()
|
||||
|
||||
target_link_libraries(Example_ImGui_Docking
|
||||
PUBLIC
|
||||
WickedEngine
|
||||
target_link_libraries(Example_ImGui_Docking
|
||||
PUBLIC
|
||||
WickedEngine
|
||||
$<UNIX:Threads::Threads>
|
||||
|
||||
PRIVATE
|
||||
Example_ImGui_Docking_Lib
|
||||
)
|
||||
PRIVATE
|
||||
Example_ImGui_Docking_Lib
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
set(LIB_DXCOMPILER "dxcompiler.dll")
|
||||
else()
|
||||
list(APPEND SOURCE_FILES
|
||||
main_SDL2.cpp
|
||||
)
|
||||
list(APPEND IMGUI_FILES
|
||||
ImGui/imgui_impl_sdl.cpp
|
||||
ImGui/imgui_impl_sdl.h
|
||||
)
|
||||
add_library(Example_ImGui_Docking_Lib OBJECT ${IMGUI_FILES})
|
||||
find_package(SDL2 REQUIRED)
|
||||
target_link_libraries(Example_ImGui_Docking_Lib PRIVATE SDL2::SDL2)
|
||||
add_executable(Example_ImGui_Docking ${SOURCE_FILES})
|
||||
|
||||
target_link_libraries(Example_ImGui_Docking
|
||||
PUBLIC
|
||||
WickedEngine
|
||||
Threads::Threads
|
||||
|
||||
PRIVATE
|
||||
Example_ImGui_Docking_Lib
|
||||
)
|
||||
|
||||
# Copy shaders and font to build and source folders just to be safe:
|
||||
add_custom_command(
|
||||
TARGET Example_ImGui_Docking POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/ImGuiPS.hlsl ${CMAKE_CURRENT_BINARY_DIR}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/ImGuiVS.hlsl ${CMAKE_CURRENT_BINARY_DIR}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/Roboto-Medium.ttf ${CMAKE_CURRENT_BINARY_DIR}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/MaterialIcons-Regular.ttf ${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
|
||||
set(LIB_DXCOMPILER "libdxcompiler.so")
|
||||
endif ()
|
||||
endif()
|
||||
|
||||
# Copy shaders and font to build and source folders just to be safe:
|
||||
add_custom_command(
|
||||
TARGET Example_ImGui_Docking POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/ImGuiPS.hlsl ${CMAKE_CURRENT_BINARY_DIR}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/ImGuiVS.hlsl ${CMAKE_CURRENT_BINARY_DIR}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/Roboto-Medium.ttf ${CMAKE_CURRENT_BINARY_DIR}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/MaterialIcons-Regular.ttf ${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
|
||||
if(WICKED_ENABLE_IPO)
|
||||
set_target_properties(Example_ImGui_Docking PROPERTIES
|
||||
|
||||
@@ -12,10 +12,10 @@
|
||||
#endif
|
||||
#include "ImGui/imgui_internal.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "ImGui/imgui_impl_win32.h"
|
||||
#elif defined(SDL2)
|
||||
#ifdef SDL2
|
||||
#include "ImGui/imgui_impl_sdl.h"
|
||||
#elif defined(_WIN32)
|
||||
#include "ImGui/imgui_impl_win32.h"
|
||||
#endif
|
||||
#include "ImGui/ImGuizmo.h"
|
||||
#ifdef INCLUDEICONFONT
|
||||
@@ -129,10 +129,10 @@ Example_ImGui::~Example_ImGui()
|
||||
{
|
||||
// Cleanup
|
||||
//ImGui_ImplDX11_Shutdown();
|
||||
#ifdef _WIN32
|
||||
ImGui_ImplWin32_Shutdown();
|
||||
#elif defined(SDL2)
|
||||
#ifdef SDL2
|
||||
ImGui_ImplSDL2_Shutdown();
|
||||
#elif defined(_WIN32)
|
||||
ImGui_ImplWin32_Shutdown();
|
||||
#endif
|
||||
ImGui::DestroyContext();
|
||||
}
|
||||
@@ -468,11 +468,11 @@ void Example_ImGuiRenderer::Update(float dt)
|
||||
ImGui_Impl_CreateDeviceObjects();
|
||||
}
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
ImGui_ImplWin32_NewFrame();
|
||||
#elif defined(SDL2)
|
||||
|
||||
#ifdef SDL2
|
||||
ImGui_ImplSDL2_NewFrame();
|
||||
#elif defined(_WIN32)
|
||||
ImGui_ImplWin32_NewFrame();
|
||||
#endif
|
||||
ImGui::NewFrame();
|
||||
|
||||
@@ -692,7 +692,7 @@ void Example_ImGuiRenderer::Update(float dt)
|
||||
bool bUseChild = false;
|
||||
if (use_fixed_height > 0) bUseChild = true;
|
||||
if(bUseChild) ImGui::BeginChild("##objectsc", ImVec2(0.0f, use_fixed_height), false, ImGuiWindowFlags_None); //ImGuiWindowFlags_AlwaysVerticalScrollbar
|
||||
|
||||
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
Entity e = scene.objects.GetEntity(i);
|
||||
@@ -1040,7 +1040,7 @@ void Example_ImGuiRenderer::Update(float dt)
|
||||
ImGui::EndTabBar();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (ImGui::CollapsingHeader(ICON_MD_SETTINGS " Settings", ImGuiTreeNodeFlags_None)) //ImGuiTreeNodeFlags_DefaultOpen
|
||||
{
|
||||
ImGui::SetCursorPos(ImGui::GetCursorPos() + ImVec2(0.0f, 3.0f));
|
||||
@@ -1401,7 +1401,7 @@ void Example_ImGuiRenderer::Update(float dt)
|
||||
if (ImGui::Selectable(lua_history[i].c_str(), is_selected)) {
|
||||
#ifdef _WIN32
|
||||
strcpy_s(lua, lua_history[i].c_str());
|
||||
#elif __linux__
|
||||
#elif __linux__
|
||||
strcpy(lua, lua_history[i].c_str());
|
||||
#endif
|
||||
bSetKeyBoardFocus = true;
|
||||
@@ -1500,7 +1500,7 @@ void Example_ImGuiRenderer::Update(float dt)
|
||||
}
|
||||
|
||||
float movespeed = CAMERAMOVESPEED;
|
||||
|
||||
|
||||
if (imgui_io.KeyShift)
|
||||
{
|
||||
movespeed *= 3.0; //Speed up camera.
|
||||
|
||||
@@ -32,16 +32,19 @@ else()
|
||||
message(STATUS "Building WickedEngine as a static library")
|
||||
endif()
|
||||
|
||||
if (WIN32)
|
||||
if (MSVC)
|
||||
add_compile_options(
|
||||
/bigobj
|
||||
)
|
||||
endif()
|
||||
else ()
|
||||
|
||||
if (MSVC)
|
||||
add_compile_options(
|
||||
/bigobj
|
||||
)
|
||||
endif()
|
||||
|
||||
if(SDL2)
|
||||
find_package(SDL2 REQUIRED)
|
||||
find_package(OpenImageDenoise "${MIN_OpenImageDenoise_VERSION}" QUIET)
|
||||
find_package(Threads REQUIRED)
|
||||
if(UNIX)
|
||||
find_package(Threads REQUIRED)
|
||||
endif()
|
||||
if(NOT ${OpenImageDenoise_FOUND})
|
||||
message("OpenImageDenoise>=${MIN_OpenImageDenoise_VERSION} not found, it will be disabled.")
|
||||
else()
|
||||
|
||||
+30
-29
@@ -15,6 +15,7 @@ static constexpr T AlignTo(T value, T alignment)
|
||||
return ((value + alignment - T(1)) / alignment) * alignment;
|
||||
}
|
||||
|
||||
//FIXME: Use FAudio on Windows SDL?
|
||||
#ifdef _WIN32
|
||||
|
||||
#include <wrl/client.h> // ComPtr
|
||||
@@ -454,7 +455,7 @@ namespace wi::audio
|
||||
}
|
||||
|
||||
instanceinternal->sourceVoice->GetVoiceDetails(&instanceinternal->voiceDetails);
|
||||
|
||||
|
||||
instanceinternal->outputMatrix.resize(size_t(instanceinternal->voiceDetails.InputChannels) * size_t(instanceinternal->audio->masteringVoiceDetails.InputChannels));
|
||||
instanceinternal->channelAzimuths.resize(instanceinternal->voiceDetails.InputChannels);
|
||||
for (size_t i = 0; i < instanceinternal->channelAzimuths.size(); ++i)
|
||||
@@ -678,7 +679,7 @@ namespace wi::audio
|
||||
settings.pMatrixCoefficients
|
||||
));
|
||||
|
||||
|
||||
|
||||
XAUDIO2_FILTER_PARAMETERS FilterParametersDirect = { LowPassFilter, 2.0f * sinf(X3DAUDIO_PI / 6.0f * settings.LPFDirectCoefficient), 1.0f };
|
||||
xaudio_check(instanceinternal->sourceVoice->SetOutputFilterParameters(instanceinternal->audio->submixVoices[instance->type], &FilterParametersDirect));
|
||||
|
||||
@@ -778,10 +779,10 @@ namespace wi::audio
|
||||
}
|
||||
|
||||
res = FAudio_CreateMasteringVoice(
|
||||
audioEngine,
|
||||
&masteringVoice,
|
||||
FAUDIO_DEFAULT_CHANNELS,
|
||||
FAUDIO_DEFAULT_SAMPLERATE,
|
||||
audioEngine,
|
||||
&masteringVoice,
|
||||
FAUDIO_DEFAULT_CHANNELS,
|
||||
FAUDIO_DEFAULT_SAMPLERATE,
|
||||
0, 0, NULL);
|
||||
if (res != 0)
|
||||
{
|
||||
@@ -790,15 +791,15 @@ namespace wi::audio
|
||||
wi::backlog::post(ss.str(), wi::backlog::LogLevel::Error);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
FAudioVoice_GetVoiceDetails(masteringVoice, &masteringVoiceDetails);
|
||||
|
||||
for (int i=0; i<SUBMIX_TYPE_COUNT; ++i){
|
||||
res = FAudio_CreateSubmixVoice(
|
||||
audioEngine,
|
||||
&submixVoices[i],
|
||||
masteringVoiceDetails.InputChannels,
|
||||
masteringVoiceDetails.InputSampleRate,
|
||||
audioEngine,
|
||||
&submixVoices[i],
|
||||
masteringVoiceDetails.InputChannels,
|
||||
masteringVoiceDetails.InputSampleRate,
|
||||
0, 0, NULL, NULL);
|
||||
if (res != 0)
|
||||
{
|
||||
@@ -834,15 +835,15 @@ namespace wi::audio
|
||||
|
||||
FAudioEffectDescriptor effects[] = { { reverbEffect, 1, 1 } };
|
||||
FAudioEffectChain effectChain = { arraysize(effects), effects };
|
||||
|
||||
|
||||
res = FAudio_CreateSubmixVoice(
|
||||
audioEngine,
|
||||
&reverbSubmix,
|
||||
1,
|
||||
masteringVoiceDetails.InputSampleRate,
|
||||
0,
|
||||
0,
|
||||
nullptr,
|
||||
audioEngine,
|
||||
&reverbSubmix,
|
||||
1,
|
||||
masteringVoiceDetails.InputSampleRate,
|
||||
0,
|
||||
0,
|
||||
nullptr,
|
||||
&effectChain
|
||||
);
|
||||
if (res != 0)
|
||||
@@ -966,7 +967,7 @@ namespace wi::audio
|
||||
|
||||
}
|
||||
|
||||
bool CreateSound(const std::string& filename, Sound* sound) {
|
||||
bool CreateSound(const std::string& filename, Sound* sound) {
|
||||
wi::vector<uint8_t> filedata;
|
||||
bool success = wi::helper::FileRead(filename, filedata);
|
||||
if (!success)
|
||||
@@ -1072,7 +1073,7 @@ namespace wi::audio
|
||||
instance->IsEnableReverb() ? (uint32_t)arraysize(SFXSend) : 1,
|
||||
SFXSend
|
||||
};
|
||||
|
||||
|
||||
res = FAudio_CreateSourceVoice(instanceinternal->audio->audioEngine, &instanceinternal->sourceVoice, &soundinternal->wfx,
|
||||
0, FAUDIO_DEFAULT_FREQ_RATIO, NULL, &SFXSendList, NULL);
|
||||
if(res != 0){
|
||||
@@ -1225,10 +1226,10 @@ namespace wi::audio
|
||||
uint32_t res = FAudioVoice_SetVolume(audio_internal->submixVoices[type], volume, FAUDIO_COMMIT_NOW);
|
||||
assert(res == 0);
|
||||
}
|
||||
float GetSubmixVolume(SUBMIX_TYPE type) {
|
||||
float GetSubmixVolume(SUBMIX_TYPE type) {
|
||||
float volume;
|
||||
FAudioVoice_GetVolume(audio_internal->submixVoices[type], &volume);
|
||||
return volume;
|
||||
return volume;
|
||||
}
|
||||
|
||||
void Update3D(SoundInstance* instance, const SoundInstance3D& instance3D) {
|
||||
@@ -1238,13 +1239,13 @@ namespace wi::audio
|
||||
listener.Position = (F3DAUDIO_VECTOR){ instance3D.listenerPos.x, instance3D.listenerPos.y, instance3D.listenerPos.z };
|
||||
listener.OrientFront = (F3DAUDIO_VECTOR){ instance3D.listenerFront.x, instance3D.listenerFront.y, instance3D.listenerFront.z };
|
||||
listener.OrientTop = (F3DAUDIO_VECTOR){ instance3D.listenerUp.x, instance3D.listenerUp.y, instance3D.listenerUp.z };
|
||||
listener.Velocity = (F3DAUDIO_VECTOR){ instance3D.listenerVelocity.x, instance3D.listenerVelocity.y, instance3D.listenerVelocity.z };
|
||||
listener.Velocity = (F3DAUDIO_VECTOR){ instance3D.listenerVelocity.x, instance3D.listenerVelocity.y, instance3D.listenerVelocity.z };
|
||||
|
||||
F3DAUDIO_EMITTER emitter = {};
|
||||
emitter.Position = (F3DAUDIO_VECTOR){ instance3D.emitterPos.x, instance3D.emitterPos.y, instance3D.emitterPos.z };
|
||||
emitter.OrientFront = (F3DAUDIO_VECTOR){ instance3D.emitterFront.x, instance3D.emitterFront.y, instance3D.emitterFront.z };
|
||||
emitter.OrientTop = (F3DAUDIO_VECTOR){ instance3D.emitterUp.x, instance3D.emitterUp.y, instance3D.emitterUp.z };
|
||||
emitter.Velocity = (F3DAUDIO_VECTOR){ instance3D.emitterVelocity.x, instance3D.emitterVelocity.y, instance3D.emitterVelocity.z };
|
||||
emitter.Velocity = (F3DAUDIO_VECTOR){ instance3D.emitterVelocity.x, instance3D.emitterVelocity.y, instance3D.emitterVelocity.z };
|
||||
emitter.InnerRadius = instance3D.emitterRadius;
|
||||
emitter.InnerRadiusAngle = F3DAUDIO_PI / 4.0f;
|
||||
emitter.ChannelCount = instanceinternal->voiceDetails.InputChannels;
|
||||
@@ -1277,11 +1278,11 @@ namespace wi::audio
|
||||
assert(res == 0);
|
||||
|
||||
res = FAudioVoice_SetOutputMatrix(
|
||||
instanceinternal->sourceVoice,
|
||||
instanceinternal->sourceVoice,
|
||||
instanceinternal->audio->submixVoices[instance->type],
|
||||
settings.SrcChannelCount,
|
||||
settings.DstChannelCount,
|
||||
settings.pMatrixCoefficients,
|
||||
settings.SrcChannelCount,
|
||||
settings.DstChannelCount,
|
||||
settings.pMatrixCoefficients,
|
||||
FAUDIO_COMMIT_NOW);
|
||||
assert(res == 0);
|
||||
|
||||
|
||||
@@ -101,9 +101,7 @@ namespace wi::helper
|
||||
StringConvert(msg, wmsg);
|
||||
StringConvert(caption, wcaption);
|
||||
MessageBox(GetActiveWindow(), wmsg.c_str(), wcaption.c_str(), 0);
|
||||
#endif // PLATFORM_WINDOWS_DESKTOP
|
||||
|
||||
#ifdef SDL2
|
||||
#elif defined(SDL2)
|
||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, caption.c_str(), msg.c_str(), NULL);
|
||||
#endif // SDL2
|
||||
}
|
||||
@@ -151,9 +149,7 @@ namespace wi::helper
|
||||
case IDIGNORE: return MessageBoxResult::Ignore;
|
||||
default: return MessageBoxResult::Cancel;
|
||||
}
|
||||
#endif // PLATFORM_WINDOWS_DESKTOP
|
||||
|
||||
#ifdef SDL2
|
||||
#elif defined(SDL2)
|
||||
const SDL_MessageBoxButtonData buttons_data[] = {
|
||||
{ SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT, 0, "Yes" },
|
||||
{ 0, 1, "No" },
|
||||
|
||||
+44
-50
@@ -46,22 +46,6 @@ namespace wi::input
|
||||
CURSOR cursor_current = CURSOR_COUNT; // something that's not default, because at least once code should change it to default
|
||||
CURSOR cursor_next = CURSOR_DEFAULT;
|
||||
|
||||
#ifdef _WIN32
|
||||
static const HCURSOR cursor_table_original[] = {
|
||||
::LoadCursor(nullptr, IDC_ARROW),
|
||||
::LoadCursor(nullptr, IDC_IBEAM),
|
||||
::LoadCursor(nullptr, IDC_SIZEALL),
|
||||
::LoadCursor(nullptr, IDC_SIZENS),
|
||||
::LoadCursor(nullptr, IDC_SIZEWE),
|
||||
::LoadCursor(nullptr, IDC_SIZENESW),
|
||||
::LoadCursor(nullptr, IDC_SIZENWSE),
|
||||
::LoadCursor(nullptr, IDC_HAND),
|
||||
::LoadCursor(nullptr, IDC_NO),
|
||||
::LoadCursor(nullptr, IDC_CROSS),
|
||||
};
|
||||
static HCURSOR cursor_table[arraysize(cursor_table_original)] = {};
|
||||
#endif // _WIN32
|
||||
|
||||
#ifdef SDL2
|
||||
static SDL_Cursor* cursor_table_original[] = {
|
||||
SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW),
|
||||
@@ -76,12 +60,27 @@ namespace wi::input
|
||||
SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_CROSSHAIR),
|
||||
};
|
||||
static SDL_Cursor* cursor_table[arraysize(cursor_table_original)] = {};
|
||||
#endif // SDL2
|
||||
#elif defined(_WIN32)
|
||||
static const HCURSOR cursor_table_original[] = {
|
||||
::LoadCursor(nullptr, IDC_ARROW),
|
||||
::LoadCursor(nullptr, IDC_IBEAM),
|
||||
::LoadCursor(nullptr, IDC_SIZEALL),
|
||||
::LoadCursor(nullptr, IDC_SIZENS),
|
||||
::LoadCursor(nullptr, IDC_SIZEWE),
|
||||
::LoadCursor(nullptr, IDC_SIZENESW),
|
||||
::LoadCursor(nullptr, IDC_SIZENWSE),
|
||||
::LoadCursor(nullptr, IDC_HAND),
|
||||
::LoadCursor(nullptr, IDC_NO),
|
||||
::LoadCursor(nullptr, IDC_CROSS),
|
||||
};
|
||||
static HCURSOR cursor_table[arraysize(cursor_table_original)] = {};
|
||||
#endif
|
||||
|
||||
|
||||
const KeyboardState& GetKeyboardState() { return keyboard; }
|
||||
const MouseState& GetMouseState() { return mouse; }
|
||||
|
||||
struct Input
|
||||
struct Input
|
||||
{
|
||||
BUTTON button = BUTTON_NONE;
|
||||
int playerIndex = 0;
|
||||
@@ -154,9 +153,12 @@ namespace wi::input
|
||||
wi::input::ps5::Update();
|
||||
#endif // PLATFORM_PS5
|
||||
|
||||
#if defined(_WIN32) && !defined(PLATFORM_XBOX)
|
||||
#ifdef SDL2
|
||||
wi::input::sdlinput::GetMouseState(&mouse);
|
||||
wi::input::sdlinput::GetKeyboardState(&keyboard);
|
||||
#elif defined(_WIN32) && !defined(PLATFORM_XBOX)
|
||||
wi::input::rawinput::GetMouseState(&mouse); // currently only the relative data can be used from this
|
||||
wi::input::rawinput::GetKeyboardState(&keyboard);
|
||||
wi::input::rawinput::GetKeyboardState(&keyboard);
|
||||
|
||||
// apparently checking the mouse here instead of Down() avoids missing the button presses (review!)
|
||||
mouse.left_button_press |= KEY_DOWN(VK_LBUTTON);
|
||||
@@ -169,10 +171,6 @@ namespace wi::input
|
||||
ScreenToClient(window, &p);
|
||||
mouse.position.x = (float)p.x;
|
||||
mouse.position.y = (float)p.y;
|
||||
|
||||
#elif defined(SDL2)
|
||||
wi::input::sdlinput::GetMouseState(&mouse);
|
||||
wi::input::sdlinput::GetKeyboardState(&keyboard);
|
||||
#endif
|
||||
|
||||
if (pen_override)
|
||||
@@ -389,14 +387,11 @@ namespace wi::input
|
||||
// Cursor update:
|
||||
if(cursor_next != cursor_current || cursor_next != CURSOR_DEFAULT)
|
||||
{
|
||||
#ifdef PLATFORM_WINDOWS_DESKTOP
|
||||
::SetCursor(cursor_table[cursor_next]);
|
||||
#endif // PLATFORM_WINDOWS_DESKTOP
|
||||
|
||||
#ifdef SDL2
|
||||
SDL_SetCursor(cursor_table[cursor_next] ? cursor_table[cursor_next] : cursor_table[CURSOR_DEFAULT]);
|
||||
#endif // SDL2
|
||||
|
||||
#elif defined(PLATFORM_WINDOWS_DESKTOP)
|
||||
::SetCursor(cursor_table[cursor_next]);
|
||||
#endif
|
||||
cursor_current = cursor_next;
|
||||
}
|
||||
cursor_next = CURSOR_DEFAULT;
|
||||
@@ -473,15 +468,15 @@ namespace wi::input
|
||||
switch (button)
|
||||
{
|
||||
case wi::input::MOUSE_BUTTON_LEFT:
|
||||
if (mouse.left_button_press)
|
||||
if (mouse.left_button_press)
|
||||
return true;
|
||||
return false;
|
||||
case wi::input::MOUSE_BUTTON_RIGHT:
|
||||
if (mouse.right_button_press)
|
||||
if (mouse.right_button_press)
|
||||
return true;
|
||||
return false;
|
||||
case wi::input::MOUSE_BUTTON_MIDDLE:
|
||||
if (mouse.middle_button_press)
|
||||
if (mouse.middle_button_press)
|
||||
return true;
|
||||
return false;
|
||||
#ifdef _WIN32
|
||||
@@ -506,7 +501,7 @@ namespace wi::input
|
||||
case wi::input::KEYBOARD_BUTTON_LSHIFT:
|
||||
keycode = VK_LSHIFT;
|
||||
break;
|
||||
case wi::input::KEYBOARD_BUTTON_F1:
|
||||
case wi::input::KEYBOARD_BUTTON_F1:
|
||||
keycode = VK_F1;
|
||||
break;
|
||||
case wi::input::KEYBOARD_BUTTON_F2:
|
||||
@@ -635,10 +630,10 @@ namespace wi::input
|
||||
#endif // _WIN32
|
||||
default: break;
|
||||
}
|
||||
#if defined(_WIN32) && !defined(PLATFORM_XBOX)
|
||||
return KEY_DOWN(keycode) || KEY_TOGGLE(keycode);
|
||||
#elif defined(SDL2)
|
||||
#ifdef SDL2
|
||||
return keyboard.buttons[keycode] == 1;
|
||||
#elif defined(_WIN32) && !defined(PLATFORM_XBOX)
|
||||
return KEY_DOWN(keycode) || KEY_TOGGLE(keycode);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -712,20 +707,22 @@ namespace wi::input
|
||||
const uint32_t posX = canvas.LogicalToPhysical(props.x);
|
||||
const uint32_t posY = canvas.LogicalToPhysical(props.y);
|
||||
|
||||
#if defined(PLATFORM_WINDOWS_DESKTOP)
|
||||
#ifdef SDL2
|
||||
SDL_WarpMouseInWindow(window, posX, posY);
|
||||
#elif defined(PLATFORM_WINDOWS_DESKTOP)
|
||||
HWND hWnd = window;
|
||||
POINT p;
|
||||
p.x = (LONG)(posX);
|
||||
p.y = (LONG)(posY);
|
||||
ClientToScreen(hWnd, &p);
|
||||
SetCursorPos(p.x, p.y);
|
||||
#elif defined(SDL2)
|
||||
SDL_WarpMouseInWindow(window, posX, posY);
|
||||
#endif // SDL2
|
||||
}
|
||||
void HidePointer(bool value)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
#ifdef SDL2
|
||||
SDL_SetRelativeMouseMode(value ? SDL_TRUE : SDL_FALSE);
|
||||
#elif defined(_WIN32)
|
||||
if (value)
|
||||
{
|
||||
while (ShowCursor(false) >= 0) {};
|
||||
@@ -734,8 +731,6 @@ namespace wi::input
|
||||
{
|
||||
while (ShowCursor(true) < 0) {};
|
||||
}
|
||||
#elif defined(SDL2)
|
||||
SDL_SetRelativeMouseMode(value ? SDL_TRUE : SDL_FALSE);
|
||||
#endif // _WIN32
|
||||
}
|
||||
|
||||
@@ -824,12 +819,6 @@ namespace wi::input
|
||||
|
||||
void SetCursorFromFile(CURSOR cursor, const char* filename)
|
||||
{
|
||||
#ifdef PLATFORM_WINDOWS_DESKTOP
|
||||
wchar_t wfilename[1024] = {};
|
||||
wi::helper::StringConvert(filename, wfilename, arraysize(wfilename));
|
||||
cursor_table[cursor] = LoadCursorFromFile(wfilename);
|
||||
#endif // PLATFORM_WINDOWS_DESKTOP
|
||||
|
||||
#ifdef SDL2
|
||||
// In SDL extract the raw color data from win32 .CUR file and use SDL to create cursor:
|
||||
wi::vector<uint8_t> data;
|
||||
@@ -877,7 +866,12 @@ namespace wi::input
|
||||
SDL_FreeSurface(surface);
|
||||
}
|
||||
}
|
||||
#endif // SDL2
|
||||
#elif defined(PLATFORM_WINDOWS_DESKTOP)
|
||||
wchar_t wfilename[1024] = {};
|
||||
wi::helper::StringConvert(filename, wfilename, arraysize(wfilename));
|
||||
cursor_table[cursor] = LoadCursorFromFile(wfilename);
|
||||
#endif // PLATFORM_WINDOWS_DESKTOP
|
||||
|
||||
|
||||
// refresh in case we set the current one:
|
||||
cursor_next = cursor_current;
|
||||
|
||||
@@ -38,27 +38,26 @@ typedef void* HMODULE;
|
||||
|
||||
namespace wi::platform
|
||||
{
|
||||
#ifdef _WIN32
|
||||
using window_type = HWND;
|
||||
using error_type = HRESULT;
|
||||
#elif defined(SDL2)
|
||||
#ifdef SDL2
|
||||
using window_type = SDL_Window*;
|
||||
using error_type = int;
|
||||
#elif defined(_WIN32)
|
||||
using window_type = HWND;
|
||||
using error_type = HRESULT;
|
||||
#else
|
||||
using window_type = void*;
|
||||
using error_type = int;
|
||||
#endif // _WIN32
|
||||
#endif
|
||||
|
||||
inline void Exit()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
PostQuitMessage(0);
|
||||
#endif // _WIN32
|
||||
#ifdef SDL2
|
||||
SDL_Event quit_event;
|
||||
quit_event.type = SDL_QUIT;
|
||||
SDL_PushEvent(&quit_event);
|
||||
#endif
|
||||
#elif defined(_WIN32)
|
||||
PostQuitMessage(0);
|
||||
#endif // _WIN32
|
||||
}
|
||||
|
||||
struct WindowProperties
|
||||
|
||||
Reference in New Issue
Block a user