@@ -30,14 +30,16 @@ LRESULT CALLBACK BoundsToolWndProc(HWND window, UINT message, WPARAM wparam, LPA
30
30
auto toolState = GetWindowParam<BoundsToolState*>(window);
31
31
if (!toolState)
32
32
break ;
33
- const POINT cursorPos = convert::FromSystemToRelativeForDirect2D (window, toolState->commonState ->cursorPosSystemSpace );
33
+ const POINT cursorPos = convert::FromSystemToWindow (window, toolState->commonState ->cursorPosSystemSpace );
34
34
35
35
D2D_POINT_2F newRegionStart = { .x = static_cast <float >(cursorPos.x ), .y = static_cast <float >(cursorPos.y ) };
36
36
toolState->perScreen [window].currentRegionStart = newRegionStart;
37
37
break ;
38
38
}
39
39
case WM_CURSOR_LEFT_MONITOR:
40
40
{
41
+ for (; ShowCursor (true ) < 0 ;)
42
+ ;
41
43
auto toolState = GetWindowParam<BoundsToolState*>(window);
42
44
if (!toolState)
43
45
break ;
@@ -59,12 +61,12 @@ LRESULT CALLBACK BoundsToolWndProc(HWND window, UINT message, WPARAM wparam, LPA
59
61
60
62
if (const bool shiftPress = GetKeyState (VK_SHIFT) & 0x8000 ; shiftPress)
61
63
{
62
- const auto cursorPos = convert::FromSystemToRelativeForDirect2D (window, toolState->commonState ->cursorPosSystemSpace );
64
+ const auto cursorPos = convert::FromSystemToWindow (window, toolState->commonState ->cursorPosSystemSpace );
63
65
64
66
D2D1_RECT_F rect;
65
67
std::tie (rect.left , rect.right ) = std::minmax (static_cast <float >(cursorPos.x ), toolState->perScreen [window].currentRegionStart ->x );
66
68
std::tie (rect.top , rect.bottom ) = std::minmax (static_cast <float >(cursorPos.y ), toolState->perScreen [window].currentRegionStart ->y );
67
- toolState->perScreen [window].measurements .push_back (rect);
69
+ toolState->perScreen [window].measurements .push_back (Measurement{ rect } );
68
70
}
69
71
70
72
toolState->perScreen [window].currentRegionStart = std::nullopt;
@@ -97,45 +99,42 @@ LRESULT CALLBACK BoundsToolWndProc(HWND window, UINT message, WPARAM wparam, LPA
97
99
98
100
namespace
99
101
{
100
- void DrawMeasurement (const D2D1_RECT_F rect ,
102
+ void DrawMeasurement (const Measurement& measurement ,
101
103
const bool alignTextBoxToCenter,
102
104
const CommonState& commonState,
103
105
HWND window,
104
- const D2DState& d2dState)
106
+ const D2DState& d2dState,
107
+ float mouseX,
108
+ float mouseY)
105
109
{
106
110
const bool screenQuadrantAware = !alignTextBoxToCenter;
107
- const auto prevMode = d2dState.rt ->GetAntialiasMode ();
108
- d2dState.rt ->SetAntialiasMode (D2D1_ANTIALIAS_MODE_ALIASED);
109
- d2dState.rt ->DrawRectangle (rect, d2dState.solidBrushes [Brush::line].get ());
110
- d2dState.rt ->SetAntialiasMode (prevMode);
111
+ d2dState.ToggleAliasedLinesMode (true );
112
+ d2dState.dxgiWindowState .rt ->DrawRectangle (measurement.rect , d2dState.solidBrushes [Brush::line].get ());
113
+ d2dState.ToggleAliasedLinesMode (false );
111
114
112
115
OverlayBoxText text;
113
- const auto width = std::abs (rect.right - rect.left + 1 );
114
- const auto height = std::abs (rect.top - rect.bottom + 1 );
115
- const uint32_t textLen = swprintf_s (text.buffer .data (),
116
- text.buffer .size (),
117
- L" %.0f × %.0f" ,
118
- width,
119
- height);
120
- std::optional<size_t > crossSymbolPos = wcschr (text.buffer .data (), L' ' ) - text.buffer .data () + 1 ;
116
+ const auto [crossSymbolPos, measureStringBufLen] =
117
+ measurement.Print (text.buffer .data (),
118
+ text.buffer .size (),
119
+ true ,
120
+ true ,
121
+ commonState.units );
121
122
122
123
commonState.overlayBoxText .Access ([&](OverlayBoxText& v) {
123
124
v = text;
124
125
});
125
126
126
- float cornerX = rect.right ;
127
- float cornerY = rect.bottom ;
128
127
if (alignTextBoxToCenter)
129
128
{
130
- cornerX = rect.left + width / 2 ;
131
- cornerY = rect.top + height / 2 ;
129
+ mouseX = measurement. rect .left + measurement. Width (Measurement::Unit::Pixel) / 2 ;
130
+ mouseY = measurement. rect .top + measurement. Height (Measurement::Unit::Pixel) / 2 ;
132
131
}
133
132
134
133
d2dState.DrawTextBox (text.buffer .data (),
135
- textLen ,
134
+ measureStringBufLen ,
136
135
crossSymbolPos,
137
- cornerX ,
138
- cornerY ,
136
+ mouseX ,
137
+ mouseY ,
139
138
screenQuadrantAware,
140
139
window);
141
140
}
@@ -150,20 +149,21 @@ void DrawBoundsToolTick(const CommonState& commonState,
150
149
if (it == end (toolState.perScreen ))
151
150
return ;
152
151
153
- d2dState.rt ->Clear ();
152
+ d2dState.dxgiWindowState . rt ->Clear ();
154
153
155
154
const auto & perScreen = it->second ;
156
155
for (const auto & measure : perScreen.measurements )
157
- DrawMeasurement (measure, true , commonState, window, d2dState);
156
+ DrawMeasurement (measure, true , commonState, window, d2dState, measure. rect . right , measure. rect . bottom );
158
157
159
158
if (!perScreen.currentRegionStart .has_value ())
160
159
return ;
161
160
162
- const auto cursorPos = convert::FromSystemToRelativeForDirect2D (window, commonState.cursorPosSystemSpace );
161
+ const auto cursorPos = convert::FromSystemToWindow (window, commonState.cursorPosSystemSpace );
163
162
164
- const D2D1_RECT_F rect{ .left = perScreen.currentRegionStart ->x ,
165
- .top = perScreen.currentRegionStart ->y ,
166
- .right = static_cast <float >(cursorPos.x ),
167
- .bottom = static_cast <float >(cursorPos.y ) };
168
- DrawMeasurement (rect, false , commonState, window, d2dState);
163
+ D2D1_RECT_F rect;
164
+ const float cursorX = static_cast <float >(cursorPos.x );
165
+ const float cursorY = static_cast <float >(cursorPos.y );
166
+ std::tie (rect.left , rect.right ) = std::minmax (cursorX, perScreen.currentRegionStart ->x );
167
+ std::tie (rect.top , rect.bottom ) = std::minmax (cursorY, perScreen.currentRegionStart ->y );
168
+ DrawMeasurement (Measurement{ rect }, false , commonState, window, d2dState, cursorX, cursorY);
169
169
}
0 commit comments