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

Method Measure

src/windows/MessageList.cpp:130–260  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

128}
129
130void RichEmbedItem::Measure(HDC hdc, RECT& messageRect, bool isCompact)
131{
132 const int borderSize = ScaleByDPI(10);
133 SIZE sz { 0, 0 };
134
135 RECT rcItem = messageRect;
136 rcItem.left += borderSize;
137 rcItem.top += borderSize;
138 rcItem.right -= borderSize * 2;
139 rcItem.bottom -= borderSize * 2;
140 rcItem.right -= ScaleByDPI(20);
141 rcItem.bottom -= ScaleByDPI(20);
142 if (!isCompact)
143 rcItem.right -= ScaleByDPI(PROFILE_PICTURE_SIZE_DEF + 12);
144
145 const int maxBoxWidth = ScaleByDPI(500);
146 int width = rcItem.right - rcItem.left;
147 if (width > maxBoxWidth) {
148 width = maxBoxWidth;
149 rcItem.right = rcItem.left + width;
150 }
151
152 HGDIOBJ oldObj = SelectObject(hdc, GetStockFont(ANSI_VAR_FONT));
153
154 // TODO: avoid repeating myself
155 RECT rcMeasure;
156
157 // Calculate the provider.
158 if (!m_providerName.Empty()) {
159 SelectObject(hdc, g_ReplyTextFont);
160 RECT rcMeasure = rcItem;
161 DrawText(hdc, m_providerName.GetWrapped(), -1, &rcMeasure, DT_CALCRECT | DT_SINGLELINE | ri::GetWordEllipsisFlag());
162 m_providerSize.cx = rcMeasure.right - rcMeasure.left;
163 m_providerSize.cy = rcMeasure.bottom - rcMeasure.top;
164 }
165 else m_providerSize = sz;
166
167 // Calculate the author.
168 if (!m_authorName.Empty()) {
169 SelectObject(hdc, g_DateTextFont);
170 rcMeasure = rcItem;
171 DrawText(hdc, m_authorName.GetWrapped(), -1, &rcMeasure, DT_CALCRECT | DT_SINGLELINE | ri::GetWordEllipsisFlag());
172 m_authorSize.cx = rcMeasure.right - rcMeasure.left;
173 m_authorSize.cy = rcMeasure.bottom - rcMeasure.top;
174 }
175 else m_authorSize = sz;
176
177 // Calculate the title.
178 if (!m_title.Empty()) {
179 SelectObject(hdc, g_AuthorTextFont);
180 rcMeasure = rcItem;
181 DrawText(hdc, m_title.GetWrapped(), -1, &rcMeasure, DT_CALCRECT | DT_SINGLELINE | ri::GetWordEllipsisFlag());
182 m_titleSize.cx = rcMeasure.right - rcMeasure.left;
183 m_titleSize.cy = rcMeasure.bottom - rcMeasure.top;
184 }
185 else m_titleSize = sz;
186
187 // Calculate the description.

Callers 2

DrawMessageMethod · 0.80

Calls 6

ScaleByDPIFunction · 0.85
GetLocalSettingsFunction · 0.85
EnsureMaximumSizeFunction · 0.85
GetWrappedMethod · 0.80
ShowEmbedImagesMethod · 0.80
EmptyMethod · 0.45

Tested by

no test coverage detected