Skip to content

Commit

Permalink
Deploying to gh-pages from @ 78ff702 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
Meakk committed Nov 19, 2024
1 parent 6a0d340 commit 1e344a1
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 2 deletions.
4 changes: 2 additions & 2 deletions vtkext/private/module/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ if(NOT VTK_VERSION VERSION_GREATER_EQUAL 9.2.20220907)
set(classes ${classes} vtkF3DOrientationMarkerWidget)
endif()

if(WIN32 AND F3D_WINDOWS_GUI)
list(APPEND classes vtkF3DWin32OutputWindow)
if(WIN32)
list(APPEND classes vtkF3DWin32OutputWindow vtkF3DWGLRenderWindow)
endif()

if(ANDROID)
Expand Down
103 changes: 103 additions & 0 deletions vtkext/private/module/vtkF3DWGLRenderWindow.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#include <vtkObjectFactory.h>

#include "vtkF3DWGLRenderWindow.h"

#include <Windows.h>
#include <dwmapi.h>

#ifndef DWMWA_USE_IMMERSIVE_DARK_MODE
#define DWMWA_USE_IMMERSIVE_DARK_MODE 20
#endif

constexpr auto IMMERSIVE_DARK_MODE_SUPPORTED_SINCE = 19041;

namespace
{
/**
* Helper function to detect if the
* Windows Build Number is equal or greater to a number
*/
bool IsWindowsBuildNumberOrGreater(int buildNumber)
{
std::string value;
bool result = vtksys::SystemTools::ReadRegistryValue(
"HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows NT\\CurrentVersion;CurrentBuildNumber",
value);

if (result == true)
{
try
{
return std::stoi(value) >= buildNumber;
}
catch (const std::invalid_argument&)
{
}
}

return false;
}

/**
* Helper function to fetch a DWORD from windows registry.
*
* @param hKey A handle to an open registry key
* @param subKey The path of registry key relative to 'hKey'
* @param value The name of the registry value
* @param dWord Variable to store the result in
*/
bool ReadRegistryDWord(
HKEY hKey, const std::wstring& subKey, const std::wstring& value, DWORD& dWord)
{
DWORD dataSize = sizeof(DWORD);
LONG result = RegGetValueW(
hKey, subKey.c_str(), value.c_str(), RRF_RT_REG_DWORD, nullptr, &dWord, &dataSize);

return result == ERROR_SUCCESS;
}

/**
* Helper function to detect user theme
*/
bool IsWindowsInDarkMode()
{
std::wstring subKey(L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize");

DWORD value{};

if (::ReadRegistryDWord(HKEY_CURRENT_USER, subKey, L"AppsUseLightTheme", value))
{
return value == 0;
}

if (::ReadRegistryDWord(HKEY_CURRENT_USER, subKey, L"SystemUsesLightTheme", value))
{
return value == 0;
}

return false;
}
}

//------------------------------------------------------------------------------
vtkStandardNewMacro(vtkF3DWGLRenderWindow);

//------------------------------------------------------------------------------
vtkF3DWGLRenderWindow::vtkF3DWGLRenderWindow() = default;

//------------------------------------------------------------------------------
vtkF3DWGLRenderWindow::~vtkF3DWGLRenderWindow() = default;

//------------------------------------------------------------------------------
void vtkF3DWGLRenderWindow::WindowInitialize()
{
this->Superclass::WindowInitialize();

// set dark mode if necessary
if (::IsWindowsBuildNumberOrGreater(IMMERSIVE_DARK_MODE_SUPPORTED_SINCE))
{
HWND hwnd = this->WindowId;
BOOL useDarkMode = ::IsWindowsInDarkMode();
DwmSetWindowAttribute(hwnd, DWMWA_USE_IMMERSIVE_DARK_MODE, &useDarkMode, sizeof(useDarkMode));
}
}
30 changes: 30 additions & 0 deletions vtkext/private/module/vtkF3DWGLRenderWindow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* @class vtkF3DWGLRenderWindow
* @brief WGL context render window
*/

#ifndef vtkF3DWGLRenderWindow_h
#define vtkF3DWGLRenderWindow_h

#include "vtkWin32OpenGLRenderWindow.h"

class vtkF3DWGLRenderWindow : public vtkWin32OpenGLRenderWindow
{
public:
static vtkF3DWGLRenderWindow* New();
vtkTypeMacro(vtkF3DWGLRenderWindow, vtkWin32OpenGLRenderWindow);

/**
* Override to decorate with dark theme if needed.
*/
void WindowInitialize() override;

protected:
vtkF3DWGLRenderWindow();
~vtkF3DWGLRenderWindow() override;

private:
vtkF3DWGLRenderWindow(const vtkF3DWGLRenderWindow&) = delete;
void operator=(const vtkF3DWGLRenderWindow&) = delete;
};
#endif // vtkF3DWGLRenderWindow_h

0 comments on commit 1e344a1

Please sign in to comment.