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

Function MdDrawString

src/windows/TextInterface_Win32.cpp:158–274  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

156}
157
158void MdDrawString(DrawingContext* context, const Rect& rect, const String& str, int styleFlags)
159{
160 RECT rc = RectToNative(rect);
161 HDC hdc = context->m_hdc;
162
163 if (styleFlags & WORD_CEMOJI) {
164 // Parse the snowflake by hand because why not
165 Snowflake parsed = 0;
166 LPCTSTR wrapped = str.GetWrapped();
167 size_t size = str.GetSize();
168
169 for (size_t i = 0, colonsSeen = 0; i < size; i++) {
170 if (wrapped[i] == (TCHAR) ':')
171 colonsSeen++;
172
173 if (colonsSeen > 2)
174 break;
175
176 if (colonsSeen == 2) {
177 if (wrapped[i] >= (TCHAR) '0' && wrapped[i] <= (TCHAR) '9')
178 parsed = parsed * 10 + int(wrapped[i] - (TCHAR) '0');
179 }
180 }
181
182 int height = MdLineHeight(context, styleFlags);
183 if (styleFlags & WORD_HEADER1)
184 height = GetProfilePictureSize();
185
186 std::string nameRaw = "EMOJI_" + std::to_string(parsed);
187 std::string name = GetAvatarCache()->AddImagePlace(nameRaw, eImagePlace::EMOJIS, nameRaw, parsed, height);
188
189 bool hasAlpha = false;
190 HBITMAP hbm = GetAvatarCache()->GetImage(nameRaw, hasAlpha)->GetFirstFrame();
191
192 bool shouldResize = GetProfilePictureSize() != height;
193
194 if (shouldResize)
195 {
196 HBRUSH hbr = CreateSolidBrush(context->m_bkColor);
197 HBITMAP hnbm = ResizeWithBackgroundColor(hdc, hbm, hbr, hasAlpha, height, height, GetProfilePictureSize(), GetProfilePictureSize());
198 DrawBitmap(hdc, hnbm, rect.left, rect.top, NULL, CLR_NONE, height, height, false);
199 DeleteBitmap(hnbm);
200 DeleteBrush(hbr);
201 }
202 else
203 {
204 DrawBitmap(hdc, hbm, rect.left, rect.top, NULL, CLR_NONE, height, height, hasAlpha);
205 }
206 return;
207 }
208
209 if (styleFlags & WORD_MLCODE) {
210 rc.left += 4;
211 rc.top += 4;
212 rc.right -= 4;
213 rc.bottom -= 4;
214 }
215 COLORREF oldColor = CLR_NONE;

Callers 1

DrawMethod · 0.85

Calls 15

RectToNativeFunction · 0.85
MdLineHeightFunction · 0.85
GetProfilePictureSizeFunction · 0.85
GetAvatarCacheFunction · 0.85
DrawBitmapFunction · 0.85
LerpColorFunction · 0.85
MdDetermineFontFunction · 0.85
ScaleByDPIFunction · 0.85
GetWrappedMethod · 0.80
GetSizeMethod · 0.80
AddImagePlaceMethod · 0.80

Tested by

no test coverage detected