mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
[GcodePreview]Fix background on dark theme (#29837)
This commit is contained in:
@@ -29,6 +29,14 @@ namespace Microsoft.PowerToys.PreviewHandler.Gcode
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private bool _infoBarAdded;
|
private bool _infoBarAdded;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="GcodePreviewHandlerControl"/> class.
|
||||||
|
/// </summary>
|
||||||
|
public GcodePreviewHandlerControl()
|
||||||
|
{
|
||||||
|
SetBackgroundColor(Settings.BackgroundColor);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Start the preview on the Control.
|
/// Start the preview on the Control.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -124,7 +132,7 @@ namespace Microsoft.PowerToys.PreviewHandler.Gcode
|
|||||||
{
|
{
|
||||||
_pictureBox = new PictureBox();
|
_pictureBox = new PictureBox();
|
||||||
_pictureBox.BackgroundImage = image;
|
_pictureBox.BackgroundImage = image;
|
||||||
_pictureBox.BackgroundImageLayout = ImageLayout.Center;
|
_pictureBox.BackgroundImageLayout = Width >= image.Width && Height >= image.Height ? ImageLayout.Center : ImageLayout.Zoom;
|
||||||
_pictureBox.Dock = DockStyle.Fill;
|
_pictureBox.Dock = DockStyle.Fill;
|
||||||
Controls.Add(_pictureBox);
|
Controls.Add(_pictureBox);
|
||||||
}
|
}
|
||||||
|
|||||||
38
src/modules/previewpane/GcodePreviewHandler/Settings.cs
Normal file
38
src/modules/previewpane/GcodePreviewHandler/Settings.cs
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation
|
||||||
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||||
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
|
namespace Microsoft.PowerToys.PreviewHandler.Gcode
|
||||||
|
{
|
||||||
|
internal sealed class Settings
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the color of the window background.
|
||||||
|
/// Even though this is not a setting yet, it's retrieved from a "Settings" class to be aligned with other preview handlers that contain this setting.
|
||||||
|
/// It's possible it can be converted into a setting in the future.
|
||||||
|
/// </summary>
|
||||||
|
public static Color BackgroundColor
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (GetTheme() == "dark")
|
||||||
|
{
|
||||||
|
return Color.FromArgb(30, 30, 30); // #1e1e1e
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return Color.White;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the theme.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Theme that should be used.</returns>
|
||||||
|
public static string GetTheme()
|
||||||
|
{
|
||||||
|
return Common.UI.ThemeManager.GetWindowsBaseColor().ToLowerInvariant();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
#include "pch.h"
|
#include "pch.h"
|
||||||
#include "GcodePreviewHandler.h"
|
#include "GcodePreviewHandler.h"
|
||||||
|
#include "../powerpreview/powerpreviewConstants.h"
|
||||||
|
|
||||||
#include <shellapi.h>
|
#include <shellapi.h>
|
||||||
#include <Shlwapi.h>
|
#include <Shlwapi.h>
|
||||||
@@ -9,6 +10,7 @@
|
|||||||
#include <common/logger/logger.h>
|
#include <common/logger/logger.h>
|
||||||
#include <common/SettingsAPI/settings_helpers.h>
|
#include <common/SettingsAPI/settings_helpers.h>
|
||||||
#include <common/utils/process_path.h>
|
#include <common/utils/process_path.h>
|
||||||
|
#include <common/Themes/windows_colors.h>
|
||||||
|
|
||||||
extern HINSTANCE g_hInst;
|
extern HINSTANCE g_hInst;
|
||||||
extern long g_cDllRef;
|
extern long g_cDllRef;
|
||||||
@@ -202,6 +204,8 @@ IFACEMETHODIMP GcodePreviewHandler::Unload()
|
|||||||
|
|
||||||
IFACEMETHODIMP GcodePreviewHandler::SetBackgroundColor(COLORREF color)
|
IFACEMETHODIMP GcodePreviewHandler::SetBackgroundColor(COLORREF color)
|
||||||
{
|
{
|
||||||
|
HBRUSH brush = CreateSolidBrush(WindowsColors::is_dark_mode() ? powerpreviewConstants::DARK_THEME_COLOR : powerpreviewConstants::LIGHT_THEME_COLOR);
|
||||||
|
SetClassLongPtr(m_hwndParent, GCLP_HBRBACKGROUND, reinterpret_cast<LONG_PTR>(brush));
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -102,6 +102,9 @@
|
|||||||
<ProjectReference Include="..\..\..\common\SettingsAPI\SettingsAPI.vcxproj">
|
<ProjectReference Include="..\..\..\common\SettingsAPI\SettingsAPI.vcxproj">
|
||||||
<Project>{6955446d-23f7-4023-9bb3-8657f904af99}</Project>
|
<Project>{6955446d-23f7-4023-9bb3-8657f904af99}</Project>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
|
<ProjectReference Include="..\..\..\common\Themes\Themes.vcxproj">
|
||||||
|
<Project>{98537082-0fdb-40de-abd8-0dc5a4269bab}</Project>
|
||||||
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="..\..\..\..\deps\spdlog.props" />
|
<Import Project="..\..\..\..\deps\spdlog.props" />
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
|
|||||||
Reference in New Issue
Block a user