Skip to content

Commit a885740

Browse files
committed
Add window translucency under Assorted Actions for cases when you want exactly match the underlying text content by moving the sampler window atop the other app.
1 parent 2d68777 commit a885740

4 files changed

Lines changed: 32 additions & 11 deletions

File tree

Common.ArrayRef.ixx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <initializer_list>
1010
#include <vector>
1111
#include <string>
12+
#include <cassert>
1213

1314
module Common.ArrayRef;
1415
export

MainWindow.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class MainWindow
7979
HRESULT SaveSelectedFontFile();
8080
HRESULT SaveUnpackedWoffFontFile();
8181
HRESULT ExportFontGlyphData();
82+
void SetWindowTranslucency(uint32_t alpha);
8283
HRESULT AutofitDrawableObjects(bool useMaximumWidth, bool useMaximumHeight);
8384
HRESULT SetNoLineWrapOnDrawableObjects();
8485
HRESULT GetSelectedDrawableObject(_Out_ uint32_t& selectedDrawableObject); // S_FALSE and ~0 if none.

MainWindow.ixx

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -405,16 +405,6 @@ INT_PTR MainWindow::InitializeMainDialog()
405405
DefWindowProc(hwnd_, WM_SETICON, ICON_BIG, LPARAM(LoadIcon(Application::g_hModule, MAKEINTRESOURCE(1))));
406406
SetWindowText(hwnd_, BUILD_TITLE_STRING);
407407

408-
#if 0 // todo::: delete
409-
SetWindowStyleEx(g_mainHwnd, GetWindowLong(g_mainHwnd, GWL_EXSTYLE) | WS_EX_LAYERED);
410-
SetLayeredWindowAttributes(
411-
g_mainHwnd,
412-
0,
413-
128,
414-
LWA_ALPHA
415-
);
416-
#endif
417-
418408
Edit_LimitText(GetWindowFromId(hwnd_, IdcLog), 1048576);
419409

420410
// Subclass the values edit box for a few reasons.
@@ -2099,6 +2089,30 @@ HRESULT MainWindow::ExportFontGlyphData()
20992089
}
21002090

21012091

2092+
void MainWindow::SetWindowTranslucency(uint32_t alpha)
2093+
{
2094+
#ifndef SetWindowExStyle
2095+
#define SetWindowExStyle(hwnd, value) ((DWORD)SetWindowLong(hwnd, GWL_EXSTYLE, value))
2096+
#endif
2097+
2098+
uint32_t previousExStyle = GetWindowExStyle(hwnd_);
2099+
if (alpha >= 255) // Opaque.
2100+
{
2101+
SetWindowExStyle(hwnd_, previousExStyle & ~WS_EX_LAYERED);
2102+
}
2103+
else // Translucent.
2104+
{
2105+
SetWindowExStyle(hwnd_, previousExStyle | WS_EX_LAYERED);
2106+
SetLayeredWindowAttributes(
2107+
hwnd_,
2108+
0,
2109+
alpha,
2110+
LWA_ALPHA
2111+
);
2112+
}
2113+
}
2114+
2115+
21022116
HRESULT MainWindow::AutofitDrawableObjects(bool useMaximumWidth, bool useMaximumHeight)
21032117
{
21042118
// Autofit all the selected objects to their actual contents, looping through and asking each
@@ -3008,7 +3022,10 @@ void MainWindow::OnAssortedActions(HWND anchorControl)
30083022
{0, u"-"},
30093023
{IdcAutofitDrawableObjects, u"Autofit drawable objects" },
30103024
{IdcAutofitDrawableObjectsUniformly, u"Autofit drawable objects uniformly" },
3011-
{IdcSetNoLineWrapOnDrawableObjects, u"Reduce drawable objects size with no wrap"}
3025+
{IdcSetNoLineWrapOnDrawableObjects, u"Reduce drawable objects size with no wrap"},
3026+
{0, u"-"},
3027+
{IdcSetWindowTranslucent, u"Make window translucent"},
3028+
{IdcSetWindowOpaque, u"Make window opaque"},
30123029
};
30133030

30143031
int menuId = TrackPopupMenu(make_array_ref(items, countof(items)), anchorControl, hwnd_);
@@ -3024,6 +3041,8 @@ void MainWindow::OnAssortedActions(HWND anchorControl)
30243041
case IdcAutofitDrawableObjects: AutofitDrawableObjects(/*useMaximumWidth*/false, /*useMaximumHeight*/false); break;
30253042
case IdcAutofitDrawableObjectsUniformly: AutofitDrawableObjects(/*useMaximumWidth*/true, /*useMaximumHeight*/true); break;
30263043
case IdcSetNoLineWrapOnDrawableObjects: SetNoLineWrapOnDrawableObjects(); break;
3044+
case IdcSetWindowTranslucent: SetWindowTranslucency(128); break;
3045+
case IdcSetWindowOpaque: SetWindowTranslucency(255); break;
30273046
}
30283047
}
30293048

resource.h

184 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)