From 40d3afdb58e8c8f575d947f6ed1121687c04f572 Mon Sep 17 00:00:00 2001 From: iProgramInCpp Date: Sun, 16 Jun 2024 21:59:25 +0300 Subject: [PATCH] * Add compact member list option. * Fix a misalignment bug in the message list. --- src/discord/LocalSettings.hpp | 6 +++ src/resource.h | 3 +- src/resource.rc | 3 +- src/windows/Main.cpp | 9 +++++ src/windows/MemberList.cpp | 74 +++++++++++++++++++++++++--------- src/windows/MessageList.cpp | 7 ++-- src/windows/OptionsDialog.cpp | 8 ++-- src/windows/WindowMessages.hpp | 1 + 8 files changed, 79 insertions(+), 32 deletions(-) diff --git a/src/discord/LocalSettings.hpp b/src/discord/LocalSettings.hpp index 21fb5b2..0a6b60e 100644 --- a/src/discord/LocalSettings.hpp +++ b/src/discord/LocalSettings.hpp @@ -145,6 +145,12 @@ class LocalSettings void SetUserScale(int userScale) { m_userScale = userScale; } + bool GetCompactMemberList() const { + return m_bCompactMemberList; + } + void SetCompactMemberList(bool b) { + m_bCompactMemberList = b; + } private: std::string m_token; diff --git a/src/resource.h b/src/resource.h index 1d953a3..49674d3 100644 --- a/src/resource.h +++ b/src/resource.h @@ -362,7 +362,7 @@ #define IDC_SAVE_WINDOW_SIZE 859 #define IDC_START_MAXIMIZED 860 #define IDC_QUICK_QUERY 861 -#define IDC_SCROLL_BAR_ON_GUILDS 861 +#define IDC_COMPACT_MEMBER_LIST 861 #define IDC_CHANNEL_LIST 862 #define IDC_QUICK_GROUP 863 #define IDC_EDIT_DISCORDAPI 864 @@ -391,7 +391,6 @@ #define IDC_COMBO_GUI_SCALE 890 #define IDC_NOTIFICATION_HINT 891 #define IDC_TOGGLE_XSUPERPROPS 892 -#define IDC_BUTTON1 893 #define IDC_NOTIFS_MARK_AS_READ 893 #define ID_FILE_PREFERENCES 1001 #define ID_FILE_STOPALLSPEECH 1002 diff --git a/src/resource.rc b/src/resource.rc index 49466e3..0967909 100644 --- a/src/resource.rc +++ b/src/resource.rc @@ -466,8 +466,7 @@ BEGIN EDITTEXT IDC_ACTIVE_IMAGE_EDIT,53,140,135,14,ES_AUTOHSCROLL | ES_READONLY LTEXT "Image:",IDC_STATIC,12,140,41,14,SS_CENTERIMAGE COMBOBOX IDC_MESSAGE_STYLE,73,109,175,128,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP - CONTROL "Show scroll bar on server list",IDC_SCROLL_BAR_ON_GUILDS, - "Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,218,236,10 + CONTROL "Compact member list",IDC_COMPACT_MEMBER_LIST,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,218,236,10 COMBOBOX IDC_COMBO_ALIGNMENT,53,158,195,78,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP LTEXT "Aligned to:",IDC_STATIC,12,158,41,12,SS_CENTERIMAGE GROUPBOX "Message List Watermark",IDC_STATIC,6,129,248,48 diff --git a/src/windows/Main.cpp b/src/windows/Main.cpp index 9fb2093..3e5628c 100644 --- a/src/windows/Main.cpp +++ b/src/windows/Main.cpp @@ -1186,6 +1186,15 @@ LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) } break; } + case WM_RECREATEMEMBERLIST: + { + RECT rc{}; + GetChildRect(hWnd, g_pMemberList->m_mainHwnd, &rc); + SAFE_DELETE(g_pMemberList); + g_pMemberList = MemberList::Create(hWnd, &rc); + WindowProc(hWnd, WM_UPDATEMEMBERLIST, 0, 0); + break; + } case WM_INITMENUPOPUP: { HMENU Menu = (HMENU)wParam; diff --git a/src/windows/MemberList.cpp b/src/windows/MemberList.cpp index bc0c4a5..550ee33 100644 --- a/src/windows/MemberList.cpp +++ b/src/windows/MemberList.cpp @@ -1,6 +1,7 @@ #include "MemberList.hpp" #include "ProfilePopout.hpp" #include "../discord/ProfileCache.hpp" +#include "../discord/LocalSettings.hpp" WNDCLASS MemberList::g_MemberListClass; #define GRPID_ONLINE (1) @@ -340,6 +341,14 @@ LRESULT MemberList::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) case WM_MEASUREITEM: { assert(pList); LPMEASUREITEMSTRUCT lpmis = (LPMEASUREITEMSTRUCT)lParam; + + if (GetLocalSettings()->GetCompactMemberList()) { + // adjust the default to be even + if (lpmis->itemHeight & 1) + lpmis->itemHeight++; + break; + } + lpmis->itemHeight = ScaleByDPI(PROFILE_PICTURE_SIZE_DEF + 12); break; } @@ -350,6 +359,8 @@ LRESULT MemberList::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) HDC hdc = lpdis->hDC; RECT rcItem = lpdis->rcItem; + bool compact = GetLocalSettings()->GetCompactMemberList(); + Snowflake user = pList->m_items[lpdis->itemID]; Profile* pf = GetProfileCache()->LookupProfile(user, "", "", "", false); @@ -380,37 +391,59 @@ LRESULT MemberList::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) statusTextColor = GetSysColor(COLOR_HIGHLIGHTTEXT); } - // draw profile picture frame - int sz = ScaleByDPI(PROFILE_PICTURE_SIZE_DEF + 12); - int szDraw = GetProfileBorderSize(); - DrawIconEx(hdc, rcItem.left, rcItem.top, g_ProfileBorderIcon, szDraw, szDraw, 0, NULL, DI_NORMAL | DI_COMPAT); - - // draw profile picture - bool hasAlpha = false; - HBITMAP hbm = GetAvatarCache()->GetBitmap(pf->m_avatarlnk, hasAlpha), hbmmask = NULL; - DrawBitmap(hdc, hbm, rcItem.left + ScaleByDPI(6), rcItem.top + ScaleByDPI(4), NULL, CLR_NONE, GetProfilePictureSize(), 0, hasAlpha); - - // draw status indicator - DrawActivityStatus(hdc, rcItem.left + ScaleByDPI(6), rcItem.top + ScaleByDPI(4), pf->m_activeStatus); - + int textOffset = 0; + if (!compact) + { + // draw profile picture frame + int sz = ScaleByDPI(PROFILE_PICTURE_SIZE_DEF + 12); + int szDraw = GetProfileBorderSize(); + DrawIconEx(hdc, rcItem.left, rcItem.top, g_ProfileBorderIcon, szDraw, szDraw, 0, NULL, DI_NORMAL | DI_COMPAT); + + // draw profile picture + bool hasAlpha = false; + HBITMAP hbm = GetAvatarCache()->GetBitmap(pf->m_avatarlnk, hasAlpha), hbmmask = NULL; + DrawBitmap(hdc, hbm, rcItem.left + ScaleByDPI(6), rcItem.top + ScaleByDPI(4), NULL, CLR_NONE, GetProfilePictureSize(), 0, hasAlpha); + + // draw status indicator + DrawActivityStatus(hdc, rcItem.left + ScaleByDPI(6), rcItem.top + ScaleByDPI(4), pf->m_activeStatus); + textOffset = sz; + } + else + { + // draw status indicator, shifted up by 1 pixel because the graphic is actually off-center + int statusIconSize = ScaleByDPI(16); + int profileSize = ScaleByDPI(PROFILE_PICTURE_SIZE_DEF); + DrawActivityStatus( + hdc, + rcItem.left - profileSize + statusIconSize, + rcItem.top - profileSize + statusIconSize + (rcItem.bottom - rcItem.top - statusIconSize) / 2 - ScaleByDPI(1), + pf->m_activeStatus + ); + textOffset = statusIconSize + ScaleByDPI(5); + } // compute data necessary to draw the text RECT rcText = rcItem; - rcText.left += sz; + rcText.left += textOffset; // note, off center from the rectangle because the profile picture is off-center too - rcText.bottom = rcText.top + sz - 4; + rcText.bottom = rcText.top + textOffset - 4; + + LPTSTR nameTstr = NULL, statTstr = NULL; std::string nameText = pf->GetName(pList->m_guild); - std::string statusText = pf->GetStatus(pList->m_guild); + nameTstr = ConvertCppStringToTString(nameText); - LPTSTR nameTstr = ConvertCppStringToTString(nameText); - LPTSTR statTstr = ConvertCppStringToTString(statusText); + if (!compact) { + std::string statusText = pf->GetStatus(pList->m_guild); + statTstr = ConvertCppStringToTString(statusText); + } COLORREF oldTextColor = SetTextColor(hdc, nameTextColor); COLORREF oldBkColor = SetBkColor (hdc, backgdColor); HGDIOBJ oldObj = SelectObject(hdc, g_AuthorTextFont); - if (statusText.empty()) { + if (compact || !*statTstr) { + rcText.top+=2; DrawText(hdc, nameTstr, -1, &rcText, DT_NOPREFIX | DT_VCENTER | DT_SINGLELINE); } else { @@ -431,7 +464,8 @@ LRESULT MemberList::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) SetBkColor(hdc, oldBkColor); free(nameTstr); - free(statTstr); + if (statTstr) + free(statTstr); break; } } diff --git a/src/windows/MessageList.cpp b/src/windows/MessageList.cpp index 6b8860e..7a4ff75 100644 --- a/src/windows/MessageList.cpp +++ b/src/windows/MessageList.cpp @@ -2683,8 +2683,6 @@ void MessageList::DrawMessage(HDC hdc, MessageItem& item, RECT& msgRect, RECT& c RECT embedRect = item.m_messageRect; auto& embedVec = item.m_embedData; size_t sz = embedVec.size(); - if (sz) - embedRect.bottom += ScaleByDPI(5); embedRect.right = msgRect.right - ScaleByDPI(10); embedRect.top = embedRect.bottom; @@ -2722,13 +2720,14 @@ void MessageList::DrawMessage(HDC hdc, MessageItem& item, RECT& msgRect, RECT& c embedRect.bottom = embedRect.top; } + if (sz) + embedRect.bottom += ScaleByDPI(5); + // draw available attachments, if any: RECT attachRect = embedRect; auto& attachVec = item.m_msg.m_attachments; auto& attachItemVec = item.m_attachmentData; sz = attachVec.size(); - if (sz != 0) - attachRect.bottom += ScaleByDPI(5) + ATTACHMENT_GAP; attachRect.right = msgRect.right - ScaleByDPI(10); attachRect.top = attachRect.bottom; diff --git a/src/windows/OptionsDialog.cpp b/src/windows/OptionsDialog.cpp index b480eaf..030b5fe 100644 --- a/src/windows/OptionsDialog.cpp +++ b/src/windows/OptionsDialog.cpp @@ -164,7 +164,7 @@ void WINAPI OnChildDialogInit(HWND hwndDlg) CheckDlgButton(hwndDlg, IDC_SAVE_WINDOW_SIZE, GetLocalSettings()->GetSaveWindowSize() ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(hwndDlg, IDC_START_MAXIMIZED, GetLocalSettings()->GetStartMaximized() ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(hwndDlg, IDC_DISABLE_FORMATTING, GetLocalSettings()->DisableFormatting() ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_SCROLL_BAR_ON_GUILDS, GetLocalSettings()->ShowScrollBarOnGuildList() ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hwndDlg, IDC_COMPACT_MEMBER_LIST, GetLocalSettings()->GetCompactMemberList() ? BST_CHECKED : BST_UNCHECKED); LPTSTR tstr = ConvertCppStringToTString(GetLocalSettings()->GetImageBackgroundFileName()); SetDlgItemText(hwndDlg, IDC_ACTIVE_IMAGE_EDIT, tstr); @@ -420,9 +420,9 @@ INT_PTR CALLBACK ChildDialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPa GetLocalSettings()->SetDisableFormatting(IsDlgButtonChecked(hWnd, IDC_DISABLE_FORMATTING)); SendMessage(g_Hwnd, WM_RECALCMSGLIST, 0, 0); break; - case IDC_SCROLL_BAR_ON_GUILDS: - GetLocalSettings()->SetShowScrollBarOnGuildList(IsDlgButtonChecked(hWnd, IDC_SCROLL_BAR_ON_GUILDS)); - SendMessage(g_Hwnd, WM_REPOSITIONEVERYTHING, 0, 0); + case IDC_COMPACT_MEMBER_LIST: + GetLocalSettings()->SetCompactMemberList(IsDlgButtonChecked(hWnd, IDC_COMPACT_MEMBER_LIST)); + SendMessage(g_Hwnd, WM_RECREATEMEMBERLIST, 0, 0); break; case IDC_SAVE_WINDOW_SIZE: GetLocalSettings()->SetSaveWindowSize(IsDlgButtonChecked(hWnd, IDC_SAVE_WINDOW_SIZE)); diff --git a/src/windows/WindowMessages.hpp b/src/windows/WindowMessages.hpp index ad46be1..6c85d53 100644 --- a/src/windows/WindowMessages.hpp +++ b/src/windows/WindowMessages.hpp @@ -64,6 +64,7 @@ enum eWmUserMsgs WM_REPOSITIONEVERYTHING, WM_NOTIFMANAGERCALLBACK, WM_POSTINIT, + WM_RECREATEMEMBERLIST, WM_UPDATETEXTSIZE = WM_APP, // used by the MessageEditor };