Drop useless comment marker
[TortoiseGit.git] / src / Utils / Windows10Colors.h
blobf2759d6c0dff069a2266249b944981e0f2594d24
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2020 - TortoiseSVN
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #pragma once
20 /**
21 * Functions to obtain Windows 10 accent colors and colors used to paint window frames.
24 #include <Windows.h>
25 #include <vector>
26 #include <wrl.h>
27 #include <windows.ui.viewmanagement.h>
29 class Win10Colors
31 public:
32 Win10Colors();
33 ~Win10Colors();
35 Win10Colors(const Win10Colors& t) = delete;
36 Win10Colors& operator=(const Win10Colors& t) = delete;
38 /**
39 * RGBA color. Red is in the LSB, Alpha in the MSB.
40 * You can use GetRValue() et al to access individual components.
42 typedef DWORD RGBA;
44 /// Accent color shades
45 struct AccentColor
47 /// foreground accent color
48 RGBA foreground;
49 /// background accent color
50 RGBA background;
51 /// Base accent color
52 RGBA accent;
53 /// Darkest shade.
54 RGBA darkest;
55 /// Darker shade.
56 RGBA darker;
57 /// Dark shade.
58 RGBA dark;
59 /// Light shade.
60 RGBA light;
61 /// Lighter shade.
62 RGBA lighter;
63 /// Lightest shade.
64 RGBA lightest;
67 static HRESULT GetAccentColor(AccentColor& color);
69 /// Dynamically loaded WindowsCreateStringReference, if available
70 static HRESULT WindowsCreateStringReference(PCWSTR sourceString, UINT32 length, HSTRING_HEADER* hstringHeader, HSTRING* string)
72 return instance.WindowsCreateStringReferenceImpl(sourceString, length, hstringHeader, string);
75 /// Dynamically loaded RoActivateInstance, if available
76 static HRESULT RoActivateInstance(HSTRING activatableClassId, IInspectable** newInstance)
78 return instance.RoActivateInstanceImpl(activatableClassId, newInstance);
81 protected:
82 /// Wrap WindowsCreateStringReference
83 inline HRESULT WindowsCreateStringReferenceImpl(PCWSTR sourceString, UINT32 length, HSTRING_HEADER* hstringHeader, HSTRING* string)
85 if (!pWindowsCreateStringReference)
86 return E_NOTIMPL;
87 return pWindowsCreateStringReference(sourceString, length, hstringHeader, string);
90 /// Wrap RoActivateInstance
91 inline HRESULT RoActivateInstanceImpl(HSTRING activatableClassId, IInspectable** inst)
93 if (!pRoActivateInstance)
94 return E_NOTIMPL;
95 return pRoActivateInstance(activatableClassId, inst);
98 static inline RGBA MakeRGBA(uint8_t R, uint8_t G, uint8_t B, uint8_t A)
100 return RGB(R, G, B) | (A << 24);
103 static inline RGBA ToRGBA(ABI::Windows::UI::Color color)
105 return MakeRGBA(color.R, color.G, color.B, color.A);
108 private:
109 static Win10Colors instance;
110 bool modules_loaded = false;
111 HMODULE winrt = 0;
112 HMODULE winrt_string = 0;
114 typedef HRESULT(STDAPICALLTYPE* pfnWindowsCreateStringReference)(
115 PCWSTR sourceString, UINT32 length, HSTRING_HEADER* hstringHeader, HSTRING* string);
116 pfnWindowsCreateStringReference pWindowsCreateStringReference = nullptr;
117 typedef HRESULT(WINAPI* pfnRoActivateInstance)(HSTRING activatableClassId, IInspectable** instance);
118 pfnRoActivateInstance pRoActivateInstance = nullptr;