From 0da24446078c971195c41cabeff5656f68289148 Mon Sep 17 00:00:00 2001 From: Tanner Date: Tue, 24 Sep 2024 13:33:21 -0600 Subject: [PATCH] Tools > Keyboard shortcuts: render hotkeys in treeview Relates to #474 . The treeview now displays all menu items and their associated hotkeys! Next up, actually letting the user edit them... --- Classes/pdTreeSupport.cls | 2 +- Forms/Tools_Hotkeys.frm | 27 +++++++++++++++++++++++++-- PhotoDemon.vbp | 2 +- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/Classes/pdTreeSupport.cls b/Classes/pdTreeSupport.cls index b687ebbaf..c6f5d612b 100644 --- a/Classes/pdTreeSupport.cls +++ b/Classes/pdTreeSupport.cls @@ -1148,7 +1148,7 @@ Friend Sub CalculateRenderMetrics() 'Always add an extra offset in case we need to render a caret to the left .captionRect.Left = m_ListRectF.Left + m_OffsetPerLevel * (.numParents + 1) - .captionRect.Width = m_ListRectF.Width - .ItemRect.Left + .captionRect.Width = m_ListRectF.Width - .captionRect.Left .captionRect.Top = curOffsetYincCollapse .captionRect.Height = m_DefaultHeight - 1 diff --git a/Forms/Tools_Hotkeys.frm b/Forms/Tools_Hotkeys.frm index 5d1cd5f7e..be41ca84d 100644 --- a/Forms/Tools_Hotkeys.frm +++ b/Forms/Tools_Hotkeys.frm @@ -98,7 +98,7 @@ Private Const BLOCKHEIGHT As Long = 32 'Two font objects; one for menus that are allowed to have hotkeys, and one for menus that are not ' (e.g. top-level menus or parent-only menus). -Private m_FontAllowed As pdFont, m_FontDisallowed As pdFont +Private m_FontAllowed As pdFont, m_FontDisallowed As pdFont, m_FontHotkey As pdFont 'All rendering is suspended until the form is loaded Private m_RenderingOK As Boolean @@ -210,6 +210,12 @@ Private Sub Form_Load() m_FontDisallowed.CreateFontObject m_FontDisallowed.SetTextAlignment vbLeftJustify + Set m_FontHotkey = New pdFont + m_FontHotkey.SetFontBold False + m_FontHotkey.SetFontSize 12 + m_FontHotkey.CreateFontObject + m_FontHotkey.SetTextAlignment vbLeftJustify + 'Apply custom themes Interface.ApplyThemeAndTranslations Me @@ -270,14 +276,21 @@ Private Sub tvMenus_DrawListEntry(ByVal bufferDC As Long, ByVal itemIndex As Lon offsetX = tmpRectF.Left offsetY = tmpRectF.Top + Interface.FixDPI(1) + 'Hotkeys get a fixed (at 96-dpi) 192 pixels to display their key combo. If menu text overflows this boundary, + ' it will be truncated with ellipses. + Dim leftOffsetHotkey As Long + leftOffsetHotkey = tmpRectF.Left + tmpRectF.Width - (Interface.FixDPI(192)) + 'If this item has been selected, draw the background with the system's current selection color Dim curFont As pdFont If m_Items(itemIndex).hk_HasChildren Then Set curFont = m_FontDisallowed Else Set curFont = m_FontAllowed If itemIsSelected Then curFont.SetFontColor g_Themer.GetGenericUIColor(UI_TextClickableSelected) + m_FontHotkey.SetFontColor g_Themer.GetGenericUIColor(UI_TextClickableSelected) Else curFont.SetFontColor g_Themer.GetGenericUIColor(UI_TextClickableUnselected, , , itemIsHovered) + m_FontHotkey.SetFontColor g_Themer.GetGenericUIColor(UI_TextClickableUnselected, , , itemIsHovered) End If 'Prepare the rendering text @@ -287,10 +300,20 @@ Private Sub tvMenus_DrawListEntry(ByVal bufferDC As Long, ByVal itemIndex As Lon 'Render the text If (LenB(drawString) <> 0) Then curFont.AttachToDC bufferDC - curFont.FastRenderText offsetX, offsetY + Interface.FixDPI(4), drawString + curFont.FastRenderTextWithClipping offsetX, offsetY + Interface.FixDPI(4), leftOffsetHotkey - tmpRectF.Left, tmpRectF.Height, drawString, True, False, False curFont.ReleaseFromDC End If + 'Next, solve for the on-screen size of the hotkey text + If (m_Items(itemIndex).hk_KeyCode <> 0) Then + + 'Right-align the hotkey text in the drop-down area, with a little padding + m_FontHotkey.AttachToDC bufferDC + m_FontHotkey.FastRenderText leftOffsetHotkey, offsetY + Interface.FixDPI(4), m_Items(itemIndex).hk_HotkeyText + m_FontHotkey.ReleaseFromDC + + End If + 'Still TODO: ' - figure out where to position hotkey text/input area diff --git a/PhotoDemon.vbp b/PhotoDemon.vbp index 1d6430bb8..37d43a426 100644 --- a/PhotoDemon.vbp +++ b/PhotoDemon.vbp @@ -534,7 +534,7 @@ Description="PhotoDemon Photo Editor" CompatibleMode="0" MajorVer=2024 MinorVer=8 -RevisionVer=86 +RevisionVer=87 AutoIncrementVer=1 ServerSupportFiles=0 VersionComments="Copyright 2000-2024 Tanner Helland - photodemon.org"