diff --git a/src/modules/previewpane/GcodePreviewHandler/GcodePreviewHandlerControl.cs b/src/modules/previewpane/GcodePreviewHandler/GcodePreviewHandlerControl.cs index 7ddec18b64..63d9828d38 100644 --- a/src/modules/previewpane/GcodePreviewHandler/GcodePreviewHandlerControl.cs +++ b/src/modules/previewpane/GcodePreviewHandler/GcodePreviewHandlerControl.cs @@ -29,6 +29,14 @@ namespace Microsoft.PowerToys.PreviewHandler.Gcode /// private bool _infoBarAdded; + /// + /// Initializes a new instance of the class. + /// + public GcodePreviewHandlerControl() + { + SetBackgroundColor(Settings.BackgroundColor); + } + /// /// Start the preview on the Control. /// @@ -124,7 +132,7 @@ namespace Microsoft.PowerToys.PreviewHandler.Gcode { _pictureBox = new PictureBox(); _pictureBox.BackgroundImage = image; - _pictureBox.BackgroundImageLayout = ImageLayout.Center; + _pictureBox.BackgroundImageLayout = Width >= image.Width && Height >= image.Height ? ImageLayout.Center : ImageLayout.Zoom; _pictureBox.Dock = DockStyle.Fill; Controls.Add(_pictureBox); } diff --git a/src/modules/previewpane/GcodePreviewHandler/Settings.cs b/src/modules/previewpane/GcodePreviewHandler/Settings.cs new file mode 100644 index 0000000000..0bfdd62ad4 --- /dev/null +++ b/src/modules/previewpane/GcodePreviewHandler/Settings.cs @@ -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 + { + /// + /// 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. + /// + public static Color BackgroundColor + { + get + { + if (GetTheme() == "dark") + { + return Color.FromArgb(30, 30, 30); // #1e1e1e + } + else + { + return Color.White; + } + } + } + + /// + /// Returns the theme. + /// + /// Theme that should be used. + public static string GetTheme() + { + return Common.UI.ThemeManager.GetWindowsBaseColor().ToLowerInvariant(); + } + } +} diff --git a/src/modules/previewpane/GcodePreviewHandlerCpp/GcodePreviewHandler.cpp b/src/modules/previewpane/GcodePreviewHandlerCpp/GcodePreviewHandler.cpp index 8903d9908c..3fc60d750b 100644 --- a/src/modules/previewpane/GcodePreviewHandlerCpp/GcodePreviewHandler.cpp +++ b/src/modules/previewpane/GcodePreviewHandlerCpp/GcodePreviewHandler.cpp @@ -1,5 +1,6 @@ #include "pch.h" #include "GcodePreviewHandler.h" +#include "../powerpreview/powerpreviewConstants.h" #include #include @@ -9,6 +10,7 @@ #include #include #include +#include extern HINSTANCE g_hInst; extern long g_cDllRef; @@ -202,6 +204,8 @@ IFACEMETHODIMP GcodePreviewHandler::Unload() 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(brush)); return S_OK; } diff --git a/src/modules/previewpane/GcodePreviewHandlerCpp/GcodePreviewHandlerCpp.vcxproj b/src/modules/previewpane/GcodePreviewHandlerCpp/GcodePreviewHandlerCpp.vcxproj index 7ff68885e4..094c55e6cb 100644 --- a/src/modules/previewpane/GcodePreviewHandlerCpp/GcodePreviewHandlerCpp.vcxproj +++ b/src/modules/previewpane/GcodePreviewHandlerCpp/GcodePreviewHandlerCpp.vcxproj @@ -102,6 +102,9 @@ {6955446d-23f7-4023-9bb3-8657f904af99} + + {98537082-0fdb-40de-abd8-0dc5a4269bab} +