Skip to content

Commit

Permalink
* Add compact member list option.
Browse files Browse the repository at this point in the history
* Fix a misalignment bug in the message list.
  • Loading branch information
iProgramMC committed Jun 16, 2024
1 parent 0248d51 commit 40d3afd
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 32 deletions.
6 changes: 6 additions & 0 deletions src/discord/LocalSettings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions src/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/resource.rc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions src/windows/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
74 changes: 54 additions & 20 deletions src/windows/MemberList.cpp
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);

Expand Down Expand Up @@ -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 {
Expand All @@ -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;
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/windows/MessageList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/windows/OptionsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand Down
1 change: 1 addition & 0 deletions src/windows/WindowMessages.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ enum eWmUserMsgs
WM_REPOSITIONEVERYTHING,
WM_NOTIFMANAGERCALLBACK,
WM_POSTINIT,
WM_RECREATEMEMBERLIST,

WM_UPDATETEXTSIZE = WM_APP, // used by the MessageEditor
};

0 comments on commit 40d3afd

Please sign in to comment.