From 6df7d5d509c835564cb040575c7e917ac7168b9e Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Sun, 6 Oct 2013 10:57:24 +0300 Subject: [PATCH] Add "Use D2D rendering" option to skin context menu --- Common/Gfx/CanvasD2D.h | 6 +++--- Library/ContextMenu.cpp | 17 ++++++++++++++++- Library/MeterWindow.cpp | 32 ++++++++++++++++++++++++-------- Library/MeterWindow.h | 4 ++++ Library/resource.h | 1 + 5 files changed, 48 insertions(+), 12 deletions(-) diff --git a/Common/Gfx/CanvasD2D.h b/Common/Gfx/CanvasD2D.h index a0a1668a..e403583f 100644 --- a/Common/Gfx/CanvasD2D.h +++ b/Common/Gfx/CanvasD2D.h @@ -38,6 +38,9 @@ namespace Gfx { class CanvasD2D : public Canvas { public: + static bool Initialize(); + static void Finalize(); + virtual void Resize(int w, int h); virtual bool BeginDraw(); @@ -81,9 +84,6 @@ private: ~CanvasD2D(); CanvasD2D(const CanvasD2D& other) {} - static bool Initialize(); - static void Finalize(); - bool BeginTargetDraw(); void EndTargetDraw(); diff --git a/Library/ContextMenu.cpp b/Library/ContextMenu.cpp index d422639e..84b34a36 100644 --- a/Library/ContextMenu.cpp +++ b/Library/ContextMenu.cpp @@ -18,6 +18,7 @@ #include "StdAfx.h" #include "../Common/MenuTemplate.h" +#include "../Common/Gfx/CanvasD2D.h" #include "ContextMenu.h" #include "Rainmeter.h" #include "Litestep.h" @@ -238,7 +239,8 @@ HMENU ContextMenu::CreateSkinMenu(MeterWindow* meterWindow, int index, HMENU men MENU_ITEM(IDM_SKIN_REMEMBERPOSITION, ID_STR_SAVEPOSITION), MENU_ITEM(IDM_SKIN_SNAPTOEDGES, ID_STR_SNAPTOEDGES), MENU_ITEM(IDM_SKIN_CLICKTHROUGH, ID_STR_CLICKTHROUGH), - MENU_ITEM(IDM_SKIN_KEEPONSCREEN, ID_STR_KEEPONSCREEN)), + MENU_ITEM(IDM_SKIN_KEEPONSCREEN, ID_STR_KEEPONSCREEN), + MENU_ITEM(IDM_SKIN_USED2D, ID_STR_USED2D)), MENU_SEPARATOR(), MENU_ITEM(IDM_SKIN_MANAGESKIN, ID_STR_MANAGESKIN), MENU_ITEM(IDM_SKIN_EDITSKIN, ID_STR_EDITSKIN), @@ -341,6 +343,19 @@ HMENU ContextMenu::CreateSkinMenu(MeterWindow* meterWindow, int index, HMENU men { CheckMenuItem(settingsMenu, IDM_SKIN_KEEPONSCREEN, MF_BYCOMMAND | MF_CHECKED); } + + if (Gfx::CanvasD2D::Initialize()) + { + if (meterWindow->GetUseD2D()) + { + CheckMenuItem(settingsMenu, IDM_SKIN_USED2D, MF_BYCOMMAND | MF_CHECKED); + } + } + else + { + DeleteMenu(settingsMenu, IDM_SKIN_USED2D, MF_BYCOMMAND); + } + Gfx::CanvasD2D::Finalize(); } // Add the name of the Skin to the menu diff --git a/Library/MeterWindow.cpp b/Library/MeterWindow.cpp index cc984bd9..3c472b01 100644 --- a/Library/MeterWindow.cpp +++ b/Library/MeterWindow.cpp @@ -121,6 +121,7 @@ MeterWindow::MeterWindow(const std::wstring& folderPath, const std::wstring& fil m_ClickThrough(false), m_KeepOnScreen(true), m_AutoSelectScreen(false), + m_UseD2D(true), m_Dragging(false), m_Dragged(false), m_BackgroundMode(BGMODE_IMAGE), @@ -1928,6 +1929,7 @@ void MeterWindow::ReadOptions() m_KeepOnScreen = parser.ReadBool(section, L"KeepOnScreen", true); addWriteFlag(OPTION_KEEPONSCREEN); + m_UseD2D = parser.ReadBool(section, L"UseD2D", true); m_SavePosition = parser.ReadBool(section, L"SavePosition", true); m_WindowStartHidden = parser.ReadBool(section, L"StartHidden", false); m_AutoSelectScreen = parser.ReadBool(section, L"AutoSelectScreen", false); @@ -2041,6 +2043,11 @@ void MeterWindow::WriteOptions(INT setting) _itow_s(m_WindowZPosition, buffer, 10); WritePrivateProfileString(section, L"AlwaysOnTop", buffer, iniFile); } + + if (setting & OPTION_USED2D) + { + WritePrivateProfileString(section, L"UseD2D", m_UseD2D ? L"1" : L"0", iniFile); + } } } @@ -2070,14 +2077,8 @@ bool MeterWindow::ReadSkin() // Read options from Rainmeter.ini. ReadOptions(); - // Temporarily read "__UseD2D" from skin for easy testing - bool useD2D = GetRainmeter().GetUseD2D(); - if (revision_beta) - { - useD2D = m_Parser.ReadBool(L"Rainmeter", L"__UseD2D", useD2D); - } - - m_Canvas = Gfx::Canvas::Create(useD2D ? Gfx::Renderer::PreferD2D : Gfx::Renderer::GDIP); + m_Canvas = Gfx::Canvas::Create( + m_UseD2D && GetRainmeter().GetUseD2D() ? Gfx::Renderer::PreferD2D : Gfx::Renderer::GDIP); m_Canvas->SetAccurateText(m_Parser.ReadBool(L"Rainmeter", L"AccurateText", false)); const auto d2dParams = m_Parser.ReadFloats(L"Rainmeter", L"__D2DParams"); @@ -3437,6 +3438,10 @@ LRESULT MeterWindow::OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam) SetKeepOnScreen(!m_KeepOnScreen); break; + case IDM_SKIN_USED2D: + SetUseD2D(!m_UseD2D); + break; + case IDM_SKIN_CLICKTHROUGH: SetClickThrough(!m_ClickThrough); break; @@ -3625,6 +3630,17 @@ void MeterWindow::SetKeepOnScreen(bool b) } } +/* +** Helper function for setting UseD2D +** +*/ +void MeterWindow::SetUseD2D(bool b) +{ + m_UseD2D = b; + WriteOptions(OPTION_USED2D); + Refresh(false); +} + /* ** Helper function for setting WindowDraggable ** diff --git a/Library/MeterWindow.h b/Library/MeterWindow.h index 399b557b..45fe76e2 100644 --- a/Library/MeterWindow.h +++ b/Library/MeterWindow.h @@ -188,6 +188,7 @@ public: bool GetClickThrough() { return m_ClickThrough; } bool GetKeepOnScreen() { return m_KeepOnScreen; } + bool GetUseD2D() { return m_UseD2D; } bool GetAutoSelectScreen() { return m_AutoSelectScreen; } bool GetWindowDraggable() { return m_WindowDraggable; } bool GetSavePosition() { return m_SavePosition; } @@ -276,6 +277,7 @@ private: OPTION_KEEPONSCREEN = 0x00000100, OPTION_AUTOSELECTSCREEN = 0x00000200, OPTION_ALWAYSONTOP = 0x00000400, + OPTION_USED2D = 0x00000800, OPTION_ALL = 0xFFFFFFFF }; @@ -300,6 +302,7 @@ private: void HandleButtons(POINT pos, BUTTONPROC proc, bool execute = true); void SetClickThrough(bool b); void SetKeepOnScreen(bool b); + void SetUseD2D(bool b); void SetWindowDraggable(bool b); void SetSavePosition(bool b); void SavePositionIfAppropriate(); @@ -386,6 +389,7 @@ private: bool m_DynamicWindowSize; bool m_ClickThrough; bool m_KeepOnScreen; + bool m_UseD2D; bool m_AutoSelectScreen; bool m_Dragging; bool m_Dragged; diff --git a/Library/resource.h b/Library/resource.h index 0d4d0484..89c60fdc 100644 --- a/Library/resource.h +++ b/Library/resource.h @@ -205,6 +205,7 @@ #define IDM_MANAGESKINSMENU_REFRESH 4057 #define IDM_MANAGESKINSMENU_EDIT 4058 #define IDM_COPY 4059 +#define IDM_SKIN_USED2D 4060 #define IDM_SKIN_CUSTOMCONTEXTMENU_FIRST 9000 #define IDM_SKIN_CUSTOMCONTEXTMENU_LAST 9014