Rewritten GuildView and a new user panel
This commit is contained in:
+7
-14
@@ -187,13 +187,6 @@ BOOL IsStartMsg(ChatWnd *cwnd, int i) {
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BOOL ShouldGoUp(ChatWnd *cwnd, int i) {
|
|
||||||
if (i > 0) {
|
|
||||||
return (IsStartMsg(cwnd, i - 1) && !IsStartMsg(cwnd, i));
|
|
||||||
} else {
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
LRESULT CALLBACK ChatWndProc(HWND hwnd, UINT uMsg, WPARAM wParam,
|
LRESULT CALLBACK ChatWndProc(HWND hwnd, UINT uMsg, WPARAM wParam,
|
||||||
LPARAM lParam) {
|
LPARAM lParam) {
|
||||||
@@ -225,12 +218,12 @@ LRESULT CALLBACK ChatWndProc(HWND hwnd, UINT uMsg, WPARAM wParam,
|
|||||||
SetBrushOrgEx(hdc, 0, 0, NULL);
|
SetBrushOrgEx(hdc, 0, 0, NULL);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int TextContentHeight;
|
unsigned int TextContentHeight;
|
||||||
int UnpaddedMessageHeight;
|
unsigned int UnpaddedMessageHeight;
|
||||||
int ClampedUnpaddedMessageHeight;
|
unsigned int ClampedUnpaddedMessageHeight;
|
||||||
int UnclampedTotalMessageHeight;
|
unsigned int UnclampedTotalMessageHeight;
|
||||||
int TotalMessageHeight;
|
unsigned int TotalMessageHeight;
|
||||||
int MessageHeightForUse;
|
unsigned int MessageHeightForUse;
|
||||||
BOOL StartMsg;
|
BOOL StartMsg;
|
||||||
BOOL PushBack;
|
BOOL PushBack;
|
||||||
} MessageDetails;
|
} MessageDetails;
|
||||||
@@ -258,7 +251,7 @@ LRESULT CALLBACK ChatWndProc(HWND hwnd, UINT uMsg, WPARAM wParam,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (msgdet[i].PushBack) {
|
if (msgdet[i].PushBack) {
|
||||||
|
// 15 is for the username field
|
||||||
msgdet[i].UnpaddedMessageHeight =
|
msgdet[i].UnpaddedMessageHeight =
|
||||||
15 + msgdet[i].TextContentHeight;
|
15 + msgdet[i].TextContentHeight;
|
||||||
|
|
||||||
|
|||||||
+139
-105
@@ -30,7 +30,8 @@ void GuildView_SetIcon(HWND hwnd, HDC icon, char *id) {
|
|||||||
GuildWnd *guildwnd = GetGuildControlDetails(hwnd);
|
GuildWnd *guildwnd = GetGuildControlDetails(hwnd);
|
||||||
for (int i = 0; i < guildwnd->uigldcnt; i++) {
|
for (int i = 0; i < guildwnd->uigldcnt; i++) {
|
||||||
if (strcmp(guildwnd->uiglds[i].id, id) == 0) {
|
if (strcmp(guildwnd->uiglds[i].id, id) == 0) {
|
||||||
guildwnds->uiglds[i].icon = icon;
|
guildwnd->uiglds[i].icon = icon;
|
||||||
|
InvalidateRect(hwnd, NULL, TRUE);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -40,6 +41,7 @@ void GuildView_SetMentionCount(HWND hwnd, char *id, int cnt) {
|
|||||||
for (int i = 0; i < guildwnd->uigldcnt; i++) {
|
for (int i = 0; i < guildwnd->uigldcnt; i++) {
|
||||||
if (strcmp(guildwnd->uiglds[i].id, id) == 0) {
|
if (strcmp(guildwnd->uiglds[i].id, id) == 0) {
|
||||||
guildwnds->uiglds[i].MentionCount = cnt;
|
guildwnds->uiglds[i].MentionCount = cnt;
|
||||||
|
InvalidateRect(hwnd, NULL, TRUE);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -47,7 +49,8 @@ void GuildView_SetMentionCount(HWND hwnd, char *id, int cnt) {
|
|||||||
}
|
}
|
||||||
void GuildView_SetDMsIcon(HWND hwnd, HDC icon) {
|
void GuildView_SetDMsIcon(HWND hwnd, HDC icon) {
|
||||||
GuildWnd *guildwnd = GetGuildControlDetails(hwnd);
|
GuildWnd *guildwnd = GetGuildControlDetails(hwnd);
|
||||||
guildwnds->dmsicon = icon;
|
guildwnd->dmsicon = icon;
|
||||||
|
InvalidateRect(hwnd, NULL, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
LRESULT CALLBACK GuildWndProc(HWND hwnd, UINT uMsg, WPARAM wParam,
|
LRESULT CALLBACK GuildWndProc(HWND hwnd, UINT uMsg, WPARAM wParam,
|
||||||
@@ -60,6 +63,12 @@ LRESULT CALLBACK GuildWndProc(HWND hwnd, UINT uMsg, WPARAM wParam,
|
|||||||
guildwnds[guildwndcount - 1].uiglds = NULL;
|
guildwnds[guildwndcount - 1].uiglds = NULL;
|
||||||
guildwnds[guildwndcount - 1].hWnd = hwnd;
|
guildwnds[guildwndcount - 1].hWnd = hwnd;
|
||||||
guildwnds[guildwndcount - 1].scrollOffset = 0;
|
guildwnds[guildwndcount - 1].scrollOffset = 0;
|
||||||
|
guildwnds[guildwndcount - 1].GuildSize = 48;
|
||||||
|
guildwnds[guildwndcount - 1].selIndex = -2;
|
||||||
|
SetWindowLongPtr(hwnd, GWL_STYLE,
|
||||||
|
GetWindowLongPtr(hwnd, GWL_STYLE) | WS_VSCROLL);
|
||||||
|
SetWindowPos(hwnd, NULL, 0, 0, 0, 0,
|
||||||
|
SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
|
||||||
return 0;
|
return 0;
|
||||||
break;
|
break;
|
||||||
case WM_PAINT: {
|
case WM_PAINT: {
|
||||||
@@ -69,132 +78,157 @@ LRESULT CALLBACK GuildWndProc(HWND hwnd, UINT uMsg, WPARAM wParam,
|
|||||||
PAINTSTRUCT ps;
|
PAINTSTRUCT ps;
|
||||||
HDC hdc = BeginPaint(hwnd, &ps);
|
HDC hdc = BeginPaint(hwnd, &ps);
|
||||||
FillRect(hdc, &ctlrect, (HBRUSH)(COLOR_3DFACE + 1));
|
FillRect(hdc, &ctlrect, (HBRUSH)(COLOR_3DFACE + 1));
|
||||||
|
int starty;
|
||||||
|
int x =
|
||||||
|
(ctlrect.right - ctlrect.left) /
|
||||||
|
2 -
|
||||||
|
gwnd->GuildSize / 2;
|
||||||
SetStretchBltMode(hdc, HALFTONE);
|
SetStretchBltMode(hdc, HALFTONE);
|
||||||
RECT rc = ctlrect;
|
int dmregy = 8 + gwnd->GuildSize + 8 + 10;
|
||||||
int ctlw = ctlrect.right - ctlrect.left;
|
int hry = 8 + gwnd->GuildSize + 8;
|
||||||
int guildsize = ctlw - 16;
|
int dmregstarty = 8;
|
||||||
|
|
||||||
rc.left += 8;
|
HBITMAP hdmsbmp = GetCurrentObject(gwnd->dmsicon, OBJ_BITMAP);
|
||||||
rc.right = rc.left + guildsize;
|
BITMAP dmsbmp;
|
||||||
rc.top += 8;
|
GetObject(hdmsbmp, sizeof(BITMAP), &dmsbmp);
|
||||||
rc.bottom = rc.top + guildsize;
|
|
||||||
|
|
||||||
if (gwnd->dmsicon) {
|
StretchBlt(hdc, x, dmregstarty-gwnd->scrollOffset,
|
||||||
|
gwnd->GuildSize, gwnd->GuildSize, gwnd->dmsicon, 0, 0, dmsbmp.bmWidth, dmsbmp.bmHeight,
|
||||||
|
SRCCOPY);
|
||||||
|
COLORREF hrup = GetSysColor(COLOR_3DHILIGHT);
|
||||||
|
COLORREF hrdown = GetSysColor(COLOR_3DSHADOW);
|
||||||
|
HPEN penhrup = CreatePen(PS_SOLID, 1, hrup);
|
||||||
|
HPEN penhrdown = CreatePen(PS_SOLID, 1, hrdown);
|
||||||
|
HPEN oldPen = SelectPen(hdc, penhrdown);
|
||||||
|
|
||||||
BITMAP bmpInfo;
|
MoveToEx(hdc, x, hry, NULL);
|
||||||
HBITMAP hSrcBmp =
|
LineTo(hdc, x + gwnd->GuildSize, hry);
|
||||||
(HBITMAP)GetCurrentObject(gwnd->dmsicon, OBJ_BITMAP);
|
|
||||||
GetObject(hSrcBmp, sizeof(BITMAP), &bmpInfo);
|
|
||||||
|
|
||||||
StretchBlt(hdc, rc.left, rc.top, guildsize, guildsize,
|
SelectPen(hdc, penhrup);
|
||||||
gwnd->dmsicon, 0, 0, bmpInfo.bmWidth, bmpInfo.bmHeight,
|
|
||||||
SRCCOPY);
|
|
||||||
} else {
|
|
||||||
FillRect(hdc, &rc, (HBRUSH)(COLOR_3DSHADOW + 1));
|
|
||||||
}
|
|
||||||
HPEN hPenDark = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_BTNSHADOW));
|
|
||||||
HPEN hPenLight =
|
|
||||||
CreatePen(PS_SOLID, 1, GetSysColor(COLOR_BTNHIGHLIGHT));
|
|
||||||
HPEN hOldPen;
|
|
||||||
|
|
||||||
hOldPen = SelectObject(hdc, hPenDark);
|
MoveToEx(hdc, x, hry+1, NULL);
|
||||||
MoveToEx(hdc, rc.left, rc.top + guildsize + 8, NULL);
|
LineTo(hdc, x + gwnd->GuildSize, hry + 1);
|
||||||
LineTo(hdc, rc.right, rc.top + guildsize + 8);
|
SelectPen(hdc,oldPen);
|
||||||
|
|
||||||
SelectObject(hdc, hPenLight);
|
|
||||||
MoveToEx(hdc, rc.left, rc.top + guildsize + 1 + 8, NULL);
|
|
||||||
LineTo(hdc, rc.right, rc.top + guildsize + 1 + 8);
|
|
||||||
|
|
||||||
SelectObject(hdc, hOldPen);
|
|
||||||
DeleteObject(hPenDark);
|
|
||||||
DeleteObject(hPenLight);
|
|
||||||
|
|
||||||
|
int gldstarty=dmregy-gwnd->scrollOffset;
|
||||||
for (int i = 0; i < gwnd->uigldcnt; i++) {
|
for (int i = 0; i < gwnd->uigldcnt; i++) {
|
||||||
RECT rc = ctlrect;
|
GUIGuild gld = gwnd->uiglds[i];
|
||||||
rc.left += 8;
|
if (gwnd->selIndex == i) {
|
||||||
rc.right = rc.left + guildsize;
|
RECT lprc;
|
||||||
rc.top += i * (guildsize + 8) + 8 + guildsize + 10 + 8;
|
lprc.left = 0;
|
||||||
rc.bottom = rc.top + guildsize;
|
lprc.right = ctlrect.right;
|
||||||
if (i == gwnd->selIndex) {
|
lprc.top = (gwnd->GuildSize + 8) * i + gldstarty-4;
|
||||||
RECT rcs = rc;
|
lprc.bottom = lprc.top + gwnd->GuildSize+8;
|
||||||
rcs.left = ctlrect.left;
|
FillRect(hdc, &lprc, (HBRUSH)(COLOR_HIGHLIGHT + 1));
|
||||||
rcs.right = ctlrect.right;
|
|
||||||
rcs.top -= 4;
|
|
||||||
rcs.bottom += 4;
|
|
||||||
FillRect(hdc, &rcs, (HBRUSH)(COLOR_HIGHLIGHT + 1));
|
|
||||||
}
|
}
|
||||||
if (gwnd->uiglds[i].icon) {
|
if (gld.icon) {
|
||||||
|
int srcw, srch;
|
||||||
BITMAP bmpInfo;
|
HBITMAP hbmp = GetCurrentObject(gld.icon, OBJ_BITMAP);
|
||||||
HBITMAP hSrcBmp =
|
BITMAP bmp;
|
||||||
(HBITMAP)GetCurrentObject(gwnd->uiglds[i].icon, OBJ_BITMAP);
|
GetObject(hbmp, sizeof(BITMAP), &bmp);
|
||||||
GetObject(hSrcBmp, sizeof(BITMAP), &bmpInfo);
|
srcw = bmp.bmWidth;
|
||||||
|
srch = bmp.bmHeight;
|
||||||
StretchBlt(hdc, rc.left, rc.top, guildsize, guildsize,
|
StretchBlt(hdc, x, (gwnd->GuildSize+8) * i + gldstarty, gwnd->GuildSize,
|
||||||
gwnd->uiglds[i].icon, 0, 0, bmpInfo.bmWidth,
|
gwnd->GuildSize, gld.icon, 0, 0, srcw, srch,
|
||||||
bmpInfo.bmHeight, SRCCOPY);
|
SRCCOPY);
|
||||||
} else {
|
} else {
|
||||||
FillRect(hdc, &rc, (HBRUSH)(COLOR_3DSHADOW + 1));
|
RECT lprc;
|
||||||
}
|
lprc.left = x;
|
||||||
if (gwnd->uiglds[i].MentionCount) {
|
lprc.right = x + gwnd->GuildSize;
|
||||||
HBRUSH indicatorbrush = CreateSolidBrush((COLORREF)0x000000FF);
|
lprc.top = (gwnd->GuildSize + 8) * i + gldstarty;
|
||||||
|
lprc.bottom = lprc.top + gwnd->GuildSize;
|
||||||
|
|
||||||
RECT rc = ctlrect;
|
FillRect(hdc, &lprc, (HBRUSH)(COLOR_3DSHADOW + 1));
|
||||||
rc.left += 8;
|
char *initials = malloc(2);
|
||||||
rc.right = rc.left + guildsize;
|
initials[0] = gld.title[0];
|
||||||
rc.top += i * (guildsize + 8) + 8 + guildsize + 10 + 8;
|
int sizeofinitials = 1;
|
||||||
rc.bottom = rc.top + guildsize;
|
for (char *c = gld.title + 1; *c; c++) {
|
||||||
|
if (*(c - 1) == ' ') {
|
||||||
rc.top = i * (guildsize + 8) + 8 + guildsize + 10 + 8 + guildsize - 16;
|
sizeofinitials++;
|
||||||
rc.left = rc.left + guildsize - 16;
|
initials=realloc(initials, sizeofinitials+1);
|
||||||
FillRect(hdc, &rc, indicatorbrush);
|
initials[sizeofinitials-1]=*c;
|
||||||
char unreadtxt[16];
|
}
|
||||||
wsprintf(unreadtxt,"%i",gwnd->uiglds[i].MentionCount);
|
}
|
||||||
DrawText(hdc,unreadtxt,strlen(unreadtxt),&rc,DT_SINGLELINE | DT_CENTER | DT_VCENTER);
|
SetBkMode(hdc, TRANSPARENT);
|
||||||
|
SetTextColor(hdc, RGB(255, 255, 255));
|
||||||
|
SetBkColor(hdc,TRANSPARENT);
|
||||||
|
DrawTextA(hdc,initials,sizeofinitials,&lprc,DT_SINGLELINE | DT_VCENTER | DT_CENTER);
|
||||||
|
free(initials);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EndPaint(hwnd, &ps);
|
EndPaint(hwnd, &ps);
|
||||||
|
|
||||||
|
|
||||||
|
// Set scroll stuff
|
||||||
|
|
||||||
|
int contentHeight = gwnd->uigldcnt * (gwnd->GuildSize+8)+dmregy;
|
||||||
|
|
||||||
|
RECT rc;
|
||||||
|
GetClientRect(hwnd, &rc);
|
||||||
|
|
||||||
|
SCROLLINFO si = {sizeof(si), SIF_RANGE | SIF_PAGE | SIF_POS,
|
||||||
|
0, contentHeight - 1,
|
||||||
|
rc.bottom, gwnd->scrollOffset};
|
||||||
|
|
||||||
|
SetScrollInfo(hwnd, SB_VERT, &si, TRUE);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case WM_VSCROLL:
|
||||||
|
{
|
||||||
|
GuildWnd *gwnd = GetGuildControlDetails(hwnd);
|
||||||
|
SCROLLINFO si = { sizeof(si), SIF_ALL };
|
||||||
|
GetScrollInfo(hwnd, SB_VERT, &si);
|
||||||
|
|
||||||
|
switch (LOWORD(wParam))
|
||||||
|
{
|
||||||
|
case SB_LINEUP: si.nPos -= 20; break;
|
||||||
|
case SB_LINEDOWN: si.nPos += 20; break;
|
||||||
|
case SB_PAGEUP: si.nPos -= si.nPage; break;
|
||||||
|
case SB_PAGEDOWN: si.nPos += si.nPage; break;
|
||||||
|
case SB_THUMBTRACK: si.nPos = si.nTrackPos; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
SetScrollInfo(hwnd, SB_VERT, &si, TRUE);
|
||||||
|
GetScrollInfo(hwnd, SB_VERT, &si);
|
||||||
|
|
||||||
|
gwnd->scrollOffset = si.nPos;
|
||||||
|
InvalidateRect(hwnd, NULL, FALSE);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
case WM_LBUTTONUP: {
|
case WM_LBUTTONUP: {
|
||||||
GuildWnd *gwnd = GetGuildControlDetails(hwnd);
|
GuildWnd *gwnd = GetGuildControlDetails(hwnd);
|
||||||
RECT ctlrect;
|
int x = GET_X_LPARAM(lParam);
|
||||||
GetClientRect(hwnd, &ctlrect);
|
int y = GET_Y_LPARAM(lParam)+gwnd->scrollOffset;
|
||||||
int ctlw = ctlrect.right - ctlrect.left;
|
|
||||||
int guildsize = ctlw - 16;
|
NMGUILDVIEW nm = {0};
|
||||||
if (GET_Y_LPARAM(lParam) < guildsize + 10 + 8) {
|
|
||||||
if (gwnd->selIndex != 1) {
|
nm.hdr.hwndFrom = hwnd;
|
||||||
gwnd->selIndex = -1;
|
nm.hdr.idFrom = GetDlgCtrlID(hwnd);
|
||||||
|
nm.hdr.code = GVN_ITEMCHANGED;
|
||||||
|
|
||||||
NMGUILDVIEW nm = {0};
|
if (y < 8 + gwnd->GuildSize && gwnd->selIndex != GUILDVIEW_DMS) {
|
||||||
nm.hdr.hwndFrom = hwnd;
|
gwnd->selIndex = GUILDVIEW_DMS;
|
||||||
nm.hdr.idFrom = GetDlgCtrlID(hwnd);
|
nm.index = GUILDVIEW_DMS;
|
||||||
nm.hdr.code = GVN_ITEMCLICK;
|
nm.guild = (GUIGuild){0};
|
||||||
nm.index = GUILDVIEW_DMS;
|
} else if (y > 8 + gwnd->GuildSize + 8 + 10) {
|
||||||
nm.guild = (GUIGuild){NULL};
|
nm.index = (y - 16 - 10 - gwnd->GuildSize) / (gwnd->GuildSize + 8);
|
||||||
nm.pt = (POINT){GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)};
|
if (nm.index == gwnd->selIndex) {
|
||||||
|
return 0;
|
||||||
SendMessage(GetParent(hwnd), WM_NOTIFY, (WPARAM)nm.hdr.idFrom,
|
|
||||||
(LPARAM)&nm);
|
|
||||||
InvalidateRect(hwnd, NULL, FALSE);
|
|
||||||
}
|
}
|
||||||
|
gwnd->selIndex=nm.index;
|
||||||
|
nm.guild = gwnd->uiglds[nm.index];
|
||||||
} else {
|
} else {
|
||||||
int index = (GET_Y_LPARAM(lParam) - 8 - guildsize - 10 - 8) /
|
return 0;
|
||||||
(guildsize + 8);
|
|
||||||
if (index != gwnd->selIndex) {
|
|
||||||
NMGUILDVIEW nm = {0};
|
|
||||||
nm.hdr.hwndFrom = hwnd;
|
|
||||||
nm.hdr.idFrom = GetDlgCtrlID(hwnd);
|
|
||||||
nm.hdr.code = GVN_ITEMCLICK;
|
|
||||||
nm.index = index;
|
|
||||||
nm.guild = gwnd->uiglds[index];
|
|
||||||
nm.pt = (POINT){GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)};
|
|
||||||
gwnd->selIndex = index;
|
|
||||||
SendMessage(GetParent(hwnd), WM_NOTIFY, (WPARAM)nm.hdr.idFrom,
|
|
||||||
(LPARAM)&nm);
|
|
||||||
InvalidateRect(hwnd, NULL, FALSE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
nm.pt.x = x;
|
||||||
|
nm.pt.y = y;
|
||||||
|
|
||||||
|
SendMessage(GetParent(hwnd), WM_NOTIFY, nm.hdr.idFrom, (LPARAM)&nm);
|
||||||
|
InvalidateRect(hwnd, NULL, true);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include "../hmap/hashmap.h"
|
#include "../hmap/hashmap.h"
|
||||||
|
|
||||||
#define GVN_ITEMCLICK (0U - 1800U)
|
#define GVN_ITEMCHANGED (0U - 1800U)
|
||||||
#define GUILDVIEW_MAGIC 0xACC0
|
#define GUILDVIEW_MAGIC 0xACC0
|
||||||
#define GUILDVIEW_DMS -1
|
#define GUILDVIEW_DMS -1
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -26,6 +26,7 @@ typedef struct {
|
|||||||
int contentHeight;
|
int contentHeight;
|
||||||
HDC dmsicon;
|
HDC dmsicon;
|
||||||
int selIndex;
|
int selIndex;
|
||||||
|
int GuildSize;
|
||||||
} GuildWnd;
|
} GuildWnd;
|
||||||
|
|
||||||
LRESULT CALLBACK GuildWndProc(HWND hwnd, UINT uMsg, WPARAM wParam,
|
LRESULT CALLBACK GuildWndProc(HWND hwnd, UINT uMsg, WPARAM wParam,
|
||||||
|
|||||||
+10
-1
@@ -32,6 +32,7 @@ static int ChannelCompare(const void *a, const void *b, void *udata) {
|
|||||||
static void ChannelFree(void *item) {}
|
static void ChannelFree(void *item) {}
|
||||||
extern void onDiscordGuildLoad(DiscordGuild *guild, char *id);
|
extern void onDiscordGuildLoad(DiscordGuild *guild, char *id);
|
||||||
extern void onDiscordUpdatedGuildReadState(DiscordGuild gld);
|
extern void onDiscordUpdatedGuildReadState(DiscordGuild gld);
|
||||||
|
extern void onDiscordReady(DiscordUser user, DiscordGuild *guilds, int guildscount);
|
||||||
int DiscordSendMessage(const char *channelID, const char *content) {
|
int DiscordSendMessage(const char *channelID, const char *content) {
|
||||||
cJSON *payload = cJSON_CreateObject();
|
cJSON *payload = cJSON_CreateObject();
|
||||||
cJSON *name = cJSON_CreateString(content);
|
cJSON *name = cJSON_CreateString(content);
|
||||||
@@ -313,7 +314,6 @@ void HandleREADY(cJSON *json) {
|
|||||||
|
|
||||||
onDiscordGuildLoad(g, id);
|
onDiscordGuildLoad(g, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
cJSON *readstates = cJSON_GetObjectItem(data, "read_state");
|
cJSON *readstates = cJSON_GetObjectItem(data, "read_state");
|
||||||
for (int i = 0; i < cJSON_GetArraySize(readstates); i++) {
|
for (int i = 0; i < cJSON_GetArraySize(readstates); i++) {
|
||||||
cJSON *readstate = cJSON_GetArrayItem(readstates, i);
|
cJSON *readstate = cJSON_GetArrayItem(readstates, i);
|
||||||
@@ -343,6 +343,15 @@ void HandleREADY(cJSON *json) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
cJSON *jsonusr = cJSON_GetObjectItem(data, "user");
|
||||||
|
DiscordUser curuser = {0};
|
||||||
|
curuser.Username = cJSON_GetObjectItem(jsonusr, "username")->valuestring;
|
||||||
|
cJSON *jsondispname = cJSON_GetObjectItem(jsonusr, "global_name");
|
||||||
|
curuser.DisplayName = jsondispname ? jsondispname->valuestring : NULL;
|
||||||
|
cJSON *jsonavatar = cJSON_GetObjectItem(jsonusr, "avatar");
|
||||||
|
curuser.avatar = jsonavatar ? jsonavatar->valuestring : NULL;
|
||||||
|
curuser.id = cJSON_GetObjectItem(jsonusr, "id")->valuestring;
|
||||||
|
onDiscordReady(curuser,NULL,0);
|
||||||
}
|
}
|
||||||
extern void onDiscordReceiveMessage(DiscordMessage msg);
|
extern void onDiscordReceiveMessage(DiscordMessage msg);
|
||||||
void HandleMessageCreate(cJSON *json) {
|
void HandleMessageCreate(cJSON *json) {
|
||||||
|
|||||||
@@ -29,6 +29,10 @@ static HWND hDMsList;
|
|||||||
static HWND hGSel;
|
static HWND hGSel;
|
||||||
static HWND hPfpArea;
|
static HWND hPfpArea;
|
||||||
static HWND hMemList;
|
static HWND hMemList;
|
||||||
|
|
||||||
|
static HWND hPfpAreaPfp;
|
||||||
|
static HWND hPfpAreaDispName;
|
||||||
|
static HWND hPfpAreaUserName;
|
||||||
static HIMAGELIST hSidePfps;
|
static HIMAGELIST hSidePfps;
|
||||||
HINSTANCE hInstance;
|
HINSTANCE hInstance;
|
||||||
SSL *GatewaySSL;
|
SSL *GatewaySSL;
|
||||||
@@ -127,6 +131,61 @@ void onDiscordGuildLoad(DiscordGuild *guild, char *id) {
|
|||||||
free(path);
|
free(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HBITMAP ResizeBitmap(HBITMAP hOrig, int w, int h) {
|
||||||
|
BITMAP bm;
|
||||||
|
GetObject(hOrig, sizeof(bm), &bm);
|
||||||
|
|
||||||
|
HDC hdcScreen = GetDC(NULL);
|
||||||
|
HDC hdcSrc = CreateCompatibleDC(hdcScreen);
|
||||||
|
HDC hdcDst = CreateCompatibleDC(hdcScreen);
|
||||||
|
HBITMAP hResized = CreateCompatibleBitmap(hdcScreen, w, h);
|
||||||
|
|
||||||
|
SelectObject(hdcSrc, hOrig);
|
||||||
|
SelectObject(hdcDst, hResized);
|
||||||
|
|
||||||
|
SetStretchBltMode(hdcDst, HALFTONE);
|
||||||
|
SetBrushOrgEx(hdcDst, 0, 0, NULL);
|
||||||
|
|
||||||
|
StretchBlt(hdcDst, 0, 0, w, h, hdcSrc, 0, 0, bm.bmWidth, bm.bmHeight,
|
||||||
|
SRCCOPY);
|
||||||
|
|
||||||
|
DeleteDC(hdcSrc);
|
||||||
|
DeleteDC(hdcDst);
|
||||||
|
ReleaseDC(NULL, hdcScreen);
|
||||||
|
DeleteObject(hOrig);
|
||||||
|
|
||||||
|
return hResized;
|
||||||
|
}
|
||||||
|
void onDiscordReady(DiscordUser user, DiscordGuild *guilds, int guildscount) {
|
||||||
|
if (user.avatar) {
|
||||||
|
char tempPath[MAX_PATH];
|
||||||
|
DWORD len = GetTempPathA(MAX_PATH, tempPath);
|
||||||
|
char *path = malloc(MAX_PATH + strlen(user.id) + 1);
|
||||||
|
wsprintfA(path, "%s%s.png", tempPath, user.avatar);
|
||||||
|
if (GetFileAttributesA(path) == INVALID_FILE_ATTRIBUTES) {
|
||||||
|
path = DiscordFetchTmpPfp(user.id,
|
||||||
|
user.avatar); // testing
|
||||||
|
}
|
||||||
|
|
||||||
|
RECT ClientRect;
|
||||||
|
GetClientRect(hPfpAreaPfp, &ClientRect);
|
||||||
|
int DestW = ClientRect.right - ClientRect.left;
|
||||||
|
int DestH = ClientRect.bottom - ClientRect.top;
|
||||||
|
|
||||||
|
SendMessage(hPfpAreaPfp, STM_SETIMAGE, IMAGE_BITMAP,
|
||||||
|
(LPARAM)ResizeBitmap(LoadPNGBitmap(path),DestW,DestH));
|
||||||
|
|
||||||
|
free(path);
|
||||||
|
}
|
||||||
|
if (user.DisplayName) {
|
||||||
|
SetWindowText(hPfpAreaDispName, user.DisplayName);
|
||||||
|
SetWindowText(hPfpAreaUserName, user.Username);
|
||||||
|
} else {
|
||||||
|
SetWindowText(hPfpAreaDispName, user.Username);
|
||||||
|
ShowWindow(hPfpAreaUserName, SW_HIDE);
|
||||||
|
}
|
||||||
|
}
|
||||||
void onDiscordUpdatedGuildReadState(DiscordGuild guild) {
|
void onDiscordUpdatedGuildReadState(DiscordGuild guild) {
|
||||||
GuildView_SetMentionCount(hGSel, guild.id, guild.MentionCount);
|
GuildView_SetMentionCount(hGSel, guild.id, guild.MentionCount);
|
||||||
}
|
}
|
||||||
@@ -162,7 +221,7 @@ LRESULT CALLBACK MsgBarSubclassProc(HWND hwnd, UINT msg, WPARAM wParam,
|
|||||||
if (!(GetKeyState(VK_SHIFT) &
|
if (!(GetKeyState(VK_SHIFT) &
|
||||||
0x8000)) // if no shift then do cool stuff
|
0x8000)) // if no shift then do cool stuff
|
||||||
{
|
{
|
||||||
char *msgcontent = malloc(GetWindowTextLength(hMsg) + 1);
|
char msgcontent[GetWindowTextLength(hMsg) + 1];
|
||||||
GetWindowText(hMsg, msgcontent, GetWindowTextLength(hMsg) + 1);
|
GetWindowText(hMsg, msgcontent, GetWindowTextLength(hMsg) + 1);
|
||||||
DiscordSendMessage(curChannel, msgcontent);
|
DiscordSendMessage(curChannel, msgcontent);
|
||||||
|
|
||||||
@@ -173,35 +232,17 @@ LRESULT CALLBACK MsgBarSubclassProc(HWND hwnd, UINT msg, WPARAM wParam,
|
|||||||
}
|
}
|
||||||
return CallWindowProc(msgoldwndproc, hwnd, msg, wParam, lParam);
|
return CallWindowProc(msgoldwndproc, hwnd, msg, wParam, lParam);
|
||||||
}
|
}
|
||||||
HBITMAP ResizeBitmap(HBITMAP hOrig, int w, int h) {
|
|
||||||
BITMAP bm;
|
|
||||||
GetObject(hOrig, sizeof(bm), &bm);
|
|
||||||
|
|
||||||
HDC hdcScreen = GetDC(NULL);
|
|
||||||
HDC hdcSrc = CreateCompatibleDC(hdcScreen);
|
|
||||||
HDC hdcDst = CreateCompatibleDC(hdcScreen);
|
|
||||||
HBITMAP hResized = CreateCompatibleBitmap(hdcScreen, w, h);
|
|
||||||
|
|
||||||
SelectObject(hdcSrc, hOrig);
|
|
||||||
SelectObject(hdcDst, hResized);
|
|
||||||
|
|
||||||
SetStretchBltMode(hdcDst, HALFTONE);
|
|
||||||
SetBrushOrgEx(hdcDst, 0, 0, NULL);
|
|
||||||
|
|
||||||
StretchBlt(hdcDst, 0, 0, w, h, hdcSrc, 0, 0, bm.bmWidth, bm.bmHeight,
|
|
||||||
SRCCOPY);
|
|
||||||
|
|
||||||
DeleteDC(hdcSrc);
|
|
||||||
DeleteDC(hdcDst);
|
|
||||||
ReleaseDC(NULL, hdcScreen);
|
|
||||||
DeleteObject(hOrig);
|
|
||||||
|
|
||||||
return hResized;
|
|
||||||
}
|
|
||||||
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
|
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
|
||||||
LPARAM lParam) {
|
LPARAM lParam) {
|
||||||
switch (uMsg) {
|
switch (uMsg) {
|
||||||
case WM_CREATE:
|
case WM_CREATE:
|
||||||
|
|
||||||
|
NONCLIENTMETRICS ncm = {sizeof(NONCLIENTMETRICS)};
|
||||||
|
SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(ncm), &ncm, 0);
|
||||||
|
HFONT SysFont = CreateFontIndirect(&ncm.lfMessageFont);
|
||||||
|
ncm.lfMessageFont.lfWeight = FW_BOLD;
|
||||||
|
HFONT BoldSysFont = CreateFontIndirect(&ncm.lfMessageFont);
|
||||||
|
|
||||||
InitHTTP();
|
InitHTTP();
|
||||||
OpenWebSocket("gateway.discord.gg", "/?encoding=json&v=9", &GatewaySSL);
|
OpenWebSocket("gateway.discord.gg", "/?encoding=json&v=9", &GatewaySSL);
|
||||||
|
|
||||||
@@ -213,7 +254,7 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
|
|||||||
WS_CHILD | WS_VISIBLE | LVS_LIST, // Window style
|
WS_CHILD | WS_VISIBLE | LVS_LIST, // Window style
|
||||||
|
|
||||||
// Size and position
|
// Size and position
|
||||||
0, 0, 75, rc.bottom - rc.top - 80,
|
0, 0, 90, rc.bottom - rc.top - 80,
|
||||||
|
|
||||||
hwnd, // Parent window
|
hwnd, // Parent window
|
||||||
(HMENU)102, // Menu
|
(HMENU)102, // Menu
|
||||||
@@ -225,10 +266,10 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
|
|||||||
hChTree = CreateWindowExA(WS_EX_CLIENTEDGE, WC_TREEVIEWA, NULL,
|
hChTree = CreateWindowExA(WS_EX_CLIENTEDGE, WC_TREEVIEWA, NULL,
|
||||||
WS_CHILD | WS_VISIBLE | TVS_HASLINES |
|
WS_CHILD | WS_VISIBLE | TVS_HASLINES |
|
||||||
TVS_LINESATROOT | TVS_HASBUTTONS,
|
TVS_LINESATROOT | TVS_HASBUTTONS,
|
||||||
75, 0, 128, rc.bottom - rc.top - 80, hwnd,
|
90, 0, 128, rc.bottom - rc.top - 80, hwnd,
|
||||||
(HMENU)103, hInstance, NULL);
|
(HMENU)103, hInstance, NULL);
|
||||||
hDMsList = CreateWindowExA(
|
hDMsList = CreateWindowExA(
|
||||||
WS_EX_CLIENTEDGE, WC_LISTVIEWA, NULL, WS_CHILD | WS_VISIBLE, 75, 0,
|
WS_EX_CLIENTEDGE, WC_LISTVIEWA, NULL, WS_CHILD | WS_VISIBLE, 90, 0,
|
||||||
128, rc.bottom - rc.top - 80, hwnd, (HMENU)103, hInstance, NULL);
|
128, rc.bottom - rc.top - 80, hwnd, (HMENU)103, hInstance, NULL);
|
||||||
ShowWindow(hDMsList, SW_HIDE);
|
ShowWindow(hDMsList, SW_HIDE);
|
||||||
hMsgList = CreateWindowEx(0, // Optional window styles.
|
hMsgList = CreateWindowEx(0, // Optional window styles.
|
||||||
@@ -237,7 +278,7 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
|
|||||||
WS_CHILD | WS_VISIBLE, // Window style
|
WS_CHILD | WS_VISIBLE, // Window style
|
||||||
|
|
||||||
// Size and position
|
// Size and position
|
||||||
75 + 128, 0, rc.right - 128 - 75,
|
75 + 128, 0, rc.right - 128 - 90,
|
||||||
rc.bottom - rc.top - 25,
|
rc.bottom - rc.top - 25,
|
||||||
|
|
||||||
hwnd, // Parent window
|
hwnd, // Parent window
|
||||||
@@ -245,20 +286,31 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
|
|||||||
hInstance, // Instance handle
|
hInstance, // Instance handle
|
||||||
NULL); // Additional application data
|
NULL); // Additional application data
|
||||||
|
|
||||||
hPfpArea = CreateWindowEx(
|
hPfpArea =
|
||||||
0, // Optional window styles.
|
CreateWindowEx(0, // Optional window styles.
|
||||||
"BUTTON", // Window class
|
"BUTTON", // Window class
|
||||||
"User Profile", // Window text
|
"User Profile", // Window text
|
||||||
ES_MULTILINE | WS_CHILD | WS_VISIBLE | BS_GROUPBOX, // Window style
|
WS_CHILD | WS_VISIBLE | BS_GROUPBOX, // Window style
|
||||||
|
|
||||||
// Size and position
|
// Size and position
|
||||||
0, rc.bottom - rc.top - 80, 128 + 75, 80,
|
0, rc.bottom - rc.top - 80, 128 + 89, 80,
|
||||||
|
|
||||||
hwnd, // Parent window
|
hwnd, // Parent window
|
||||||
NULL, // Menu
|
NULL, // Menu
|
||||||
hInstance, // Instance handle
|
hInstance, // Instance handle
|
||||||
NULL // Additional application data
|
NULL // Additional application data
|
||||||
);
|
);
|
||||||
|
hPfpAreaPfp = CreateWindowExA(
|
||||||
|
0, "STATIC", "", SS_BITMAP | WS_CHILD | WS_VISIBLE,
|
||||||
|
12, 24, 36, 36, hPfpArea, NULL, GetModuleHandle(NULL), NULL);
|
||||||
|
hPfpAreaDispName = CreateWindowExA(
|
||||||
|
0, "STATIC", "Display Name", WS_CHILD | WS_VISIBLE, 54, 24, 144, 16,
|
||||||
|
hPfpArea, NULL, GetModuleHandle(NULL), NULL);
|
||||||
|
SendMessage(hPfpAreaDispName, WM_SETFONT, (WPARAM)BoldSysFont, 0);
|
||||||
|
hPfpAreaUserName = CreateWindowExA(
|
||||||
|
0, "STATIC", "Username", WS_CHILD | WS_VISIBLE, 54, 38, 144, 16,
|
||||||
|
hPfpArea, NULL, GetModuleHandle(NULL), NULL);
|
||||||
|
SendMessage(hPfpAreaUserName, WM_SETFONT, (WPARAM)SysFont, 0);
|
||||||
SendMessage(hPfpArea, WM_SETFONT, (WPARAM)regfont, 0);
|
SendMessage(hPfpArea, WM_SETFONT, (WPARAM)regfont, 0);
|
||||||
hMsg = CreateWindowEx(WS_EX_CLIENTEDGE, // Optional window styles.
|
hMsg = CreateWindowEx(WS_EX_CLIENTEDGE, // Optional window styles.
|
||||||
"EDIT", // Window class
|
"EDIT", // Window class
|
||||||
@@ -267,8 +319,8 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
|
|||||||
WS_VISIBLE, // Window style
|
WS_VISIBLE, // Window style
|
||||||
|
|
||||||
// Size and position
|
// Size and position
|
||||||
128 + 75, rc.bottom - rc.top - 25,
|
128 + 89, rc.bottom - rc.top - 25,
|
||||||
rc.right - rc.left - 128 - 75 - 25, 25,
|
rc.right - rc.left - 128 - 89 - 25, 25,
|
||||||
|
|
||||||
hwnd, // Parent window
|
hwnd, // Parent window
|
||||||
(HMENU)104, // Menu
|
(HMENU)104, // Menu
|
||||||
@@ -300,11 +352,11 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
|
|||||||
int height = HIWORD(lParam);
|
int height = HIWORD(lParam);
|
||||||
SetWindowPos(hPfpArea, NULL, 0, height - 80, 0, 0,
|
SetWindowPos(hPfpArea, NULL, 0, height - 80, 0, 0,
|
||||||
SWP_NOSIZE | SWP_NOZORDER);
|
SWP_NOSIZE | SWP_NOZORDER);
|
||||||
SetWindowPos(hGSel, NULL, 0, 0, 75, height - 80, SWP_NOZORDER);
|
SetWindowPos(hGSel, NULL, 0, 0, 90, height - 80, SWP_NOZORDER);
|
||||||
SetWindowPos(hMsg, NULL, 128 + 75, height - 25, width - 128 - 75 - 25,
|
SetWindowPos(hMsg, NULL, 128 + 90, height - 25, width - 128 - 90 - 25,
|
||||||
25, SWP_NOZORDER);
|
25, SWP_NOZORDER);
|
||||||
SetWindowPos(hChTree, NULL, 75, 0, 128, height - 80, SWP_NOZORDER);
|
SetWindowPos(hChTree, NULL, 90, 0, 128, height - 80, SWP_NOZORDER);
|
||||||
SetWindowPos(hMsgList, NULL, 128 + 75, 0, width - 128 - 75, height - 25,
|
SetWindowPos(hMsgList, NULL, 128 + 90, 0, width - 128 - 90, height - 25,
|
||||||
SWP_NOZORDER);
|
SWP_NOZORDER);
|
||||||
SetWindowPos(hSend, NULL, width - 25, height - 25, 25, 25,
|
SetWindowPos(hSend, NULL, width - 25, height - 25, 25, 25,
|
||||||
SWP_NOZORDER | SWP_NOSIZE);
|
SWP_NOZORDER | SWP_NOSIZE);
|
||||||
@@ -340,13 +392,13 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
|
|||||||
char tempPath[MAX_PATH];
|
char tempPath[MAX_PATH];
|
||||||
DWORD len = GetTempPathA(MAX_PATH, tempPath);
|
DWORD len = GetTempPathA(MAX_PATH, tempPath);
|
||||||
char path[MAX_PATH +
|
char path[MAX_PATH +
|
||||||
strlen(dms[i].receipents[0].avatar) + 1];
|
strlen(dms[i].receipents[0].avatar) + 1];
|
||||||
wsprintfA(path, "%s%s.png", tempPath,
|
wsprintfA(path, "%s%s.png", tempPath,
|
||||||
dms[i].receipents[0].avatar);
|
dms[i].receipents[0].avatar);
|
||||||
|
|
||||||
if (GetFileAttributesA(path) ==
|
if (GetFileAttributesA(path) ==
|
||||||
INVALID_FILE_ATTRIBUTES) {
|
INVALID_FILE_ATTRIBUTES) {
|
||||||
char* path2 = DiscordFetchTmpPfp(
|
char *path2 = DiscordFetchTmpPfp(
|
||||||
dms[i].receipents[0].id,
|
dms[i].receipents[0].id,
|
||||||
dms[i].receipents[0].avatar); // testing
|
dms[i].receipents[0].avatar); // testing
|
||||||
ImageList_Add(
|
ImageList_Add(
|
||||||
@@ -377,6 +429,8 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
|
|||||||
tvInsert.item.stateMask = TVIS_EXPANDED;
|
tvInsert.item.stateMask = TVIS_EXPANDED;
|
||||||
tvInsert.item.iImage =
|
tvInsert.item.iImage =
|
||||||
dms[i].receipents[0].avatar ? pfpidx : 0;
|
dms[i].receipents[0].avatar ? pfpidx : 0;
|
||||||
|
tvInsert.item.iSelectedImage =
|
||||||
|
dms[i].receipents[0].avatar ? pfpidx : 0;
|
||||||
HTREEITEM lres = (HTREEITEM)SendMessage(
|
HTREEITEM lres = (HTREEITEM)SendMessage(
|
||||||
hChTree, TVM_INSERTITEM, 0, (LPARAM)&tvInsert);
|
hChTree, TVM_INSERTITEM, 0, (LPARAM)&tvInsert);
|
||||||
if (dms[i].receipents[0].avatar) {
|
if (dms[i].receipents[0].avatar) {
|
||||||
@@ -492,6 +546,7 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
|
|||||||
|
|
||||||
FillRect(hdc, &ps.rcPaint, (HBRUSH)(COLOR_BTNFACE + 1));
|
FillRect(hdc, &ps.rcPaint, (HBRUSH)(COLOR_BTNFACE + 1));
|
||||||
EndPaint(hwnd, &ps);
|
EndPaint(hwnd, &ps);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user