3
3
4
4
#include < dwmapi.h>
5
5
6
+ #include < ScalingUtils.h>
7
+
6
8
namespace
7
9
{
8
10
size_t D2DRectUHash (D2D1_SIZE_U rect)
@@ -88,7 +90,7 @@ void FrameDrawer::Show()
88
90
Render ();
89
91
}
90
92
91
- void FrameDrawer::SetBorderRect (RECT windowRect, COLORREF color, int thickness, int radius)
93
+ void FrameDrawer::SetBorderRect (RECT windowRect, COLORREF color, int thickness, float radius)
92
94
{
93
95
auto newSceneRect = DrawableRect{
94
96
.borderColor = ConvertColor (color),
@@ -181,15 +183,27 @@ D2D1_COLOR_F FrameDrawer::ConvertColor(COLORREF color)
181
183
1 .f );
182
184
}
183
185
184
- D2D1_ROUNDED_RECT FrameDrawer::ConvertRect (RECT rect, int thickness, int radius)
186
+ D2D1_ROUNDED_RECT FrameDrawer::ConvertRect (RECT rect, int thickness, float radius)
185
187
{
186
- auto d2d1Rect = D2D1::RectF ((float )rect.left + thickness, (float )rect.top + thickness, (float )rect.right - thickness, (float )rect.bottom - thickness);
187
- return D2D1::RoundedRect (d2d1Rect, (float )radius, (float )radius);
188
+ float halfThickness = thickness / 2 .0f ;
189
+
190
+ // 1 is needed to eliminate the gap between border and window
191
+ auto d2d1Rect = D2D1::RectF ((float )rect.left + halfThickness + 1 ,
192
+ (float )rect.top + halfThickness + 1 ,
193
+ (float )rect.right - halfThickness - 1 ,
194
+ (float )rect.bottom - halfThickness - 1 );
195
+ return D2D1::RoundedRect (d2d1Rect, radius, radius);
188
196
}
189
197
190
198
D2D1_RECT_F FrameDrawer::ConvertRect (RECT rect, int thickness)
191
199
{
192
- return D2D1::RectF ((float )rect.left + thickness, (float )rect.top + thickness, (float )rect.right - thickness, (float )rect.bottom - thickness);
200
+ float halfThickness = thickness / 2 .0f ;
201
+
202
+ // 1 is needed to eliminate the gap between border and window
203
+ return D2D1::RectF ((float )rect.left + halfThickness + 1 ,
204
+ (float )rect.top + halfThickness + 1 ,
205
+ (float )rect.right - halfThickness - 1 ,
206
+ (float )rect.bottom - halfThickness - 1 );
193
207
}
194
208
195
209
void FrameDrawer::Render ()
@@ -207,11 +221,11 @@ void FrameDrawer::Render()
207
221
208
222
if (m_sceneRect.roundedRect )
209
223
{
210
- m_renderTarget->DrawRoundedRectangle (m_sceneRect.roundedRect .value (), m_borderBrush.get (), static_cast <float >(m_sceneRect.thickness * 2 ));
224
+ m_renderTarget->DrawRoundedRectangle (m_sceneRect.roundedRect .value (), m_borderBrush.get (), static_cast <float >(m_sceneRect.thickness ));
211
225
}
212
226
else if (m_sceneRect.rect )
213
227
{
214
- m_renderTarget->DrawRectangle (m_sceneRect.rect .value (), m_borderBrush.get (), static_cast <float >(m_sceneRect.thickness * 2 ));
228
+ m_renderTarget->DrawRectangle (m_sceneRect.rect .value (), m_borderBrush.get (), static_cast <float >(m_sceneRect.thickness ));
215
229
}
216
230
217
231
m_renderTarget->EndDraw ();
0 commit comments