MCPcopy Create free account
hub / github.com/DiscordMessenger/dm / DrawButton

Method DrawButton

src/windows/GuildHeader.cpp:171–236  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

169}
170
171void GuildHeader::DrawButton(HDC hdc, Button& button)
172{
173 int iconSize = ScaleByDPI(16);
174 int sizeX = button.m_rect.right - button.m_rect.left;
175 int sizeY = button.m_rect.bottom - button.m_rect.top;
176 int iconX = button.m_rect.left + sizeX / 2 - iconSize / 2;
177 int iconY = button.m_rect.top + sizeY / 2 - iconSize / 2;
178
179 POINT oldPt;
180 COLORREF oldPen = ri::SetDCPenColor(hdc, 0);
181 HGDIOBJ oldObj = SelectObject(hdc, ri::GetDCPen());
182 MoveToEx(hdc, 0, 0, &oldPt);
183
184 const int clr = GUILD_HEADER_COLOR_2;
185 COLORREF clrA = LerpColor(RGB(255, 255, 255), GetSysColor(clr), 1, 2);
186 COLORREF clrB = LerpColor(RGB(0, 0, 0), GetSysColor(clr), 1, 2);
187
188 RECT exp = { iconX - 4, iconY - 4, iconX + 4 + iconSize, iconY + 4 + iconSize };
189 exp.left = std::max(exp.left, button.m_rect.left);
190 exp.top = std::max(exp.top, button.m_rect.top);
191 exp.right = std::min(exp.right, button.m_rect.right);
192 exp.bottom = std::min(exp.bottom, button.m_rect.bottom);
193
194 if (IsPlacementGuildType(button.m_placement)) {
195 HRGN rgn = CreateRectRgnIndirect(&exp);
196 SelectClipRgn(hdc, rgn);
197 FillGradient(hdc, &m_rectLeftFull, GUILD_HEADER_COLOR, GUILD_HEADER_COLOR_2, false);
198 SelectClipRgn(hdc, NULL);
199 DeleteRgn(rgn);
200 }
201 else {
202 FillRect(hdc, &exp, ri::GetSysColorBrush(clr));
203 }
204
205 if (button.m_held) {
206 iconX++, iconY++;
207 std::swap(clrA, clrB);
208 }
209
210 if (button.m_hot || button.m_held) {
211 ri::SetDCPenColor(hdc, clrA);
212 MoveToEx(hdc, exp.left, exp.top, NULL);
213 LineTo (hdc, exp.right, exp.top);
214 MoveToEx(hdc, exp.left, exp.top, NULL);
215 LineTo (hdc, exp.left, exp.bottom);
216 ri::SetDCPenColor(hdc, clrB);
217 MoveToEx(hdc, exp.right - 1, exp.bottom - 1, NULL);
218 LineTo (hdc, exp.right - 1, exp.top - 1);
219 MoveToEx(hdc, exp.right - 1, exp.bottom - 1, NULL);
220 LineTo (hdc, exp.left - 1, exp.bottom - 1);
221 }
222
223 HICON hicon = GetIcon(button.m_iconID, iconSize);
224 DrawIconInvert(
225 hdc,
226 hicon,
227 iconX,
228 iconY,

Callers 1

WndProcMethod · 0.80

Calls 6

ScaleByDPIFunction · 0.85
LerpColorFunction · 0.85
FillGradientFunction · 0.85
DrawIconInvertFunction · 0.85
IsIconMostlyBlackFunction · 0.85
swapFunction · 0.50

Tested by

no test coverage detected