@@ -39,13 +39,11 @@ cam_capture_source::cam_capture_source(HWND hwnd, const cam::rect<int> & /*view*
3939 , src_rect_()
4040 , annotations_()
4141 , stopwatch_(std::make_unique<cam::stop_watch>())
42+ , virtual_screen_info_(cam::get_virtual_screen_info())
4243{
4344 if (hwnd == nullptr )
4445 {
45- src_rect_.left_ = ::GetSystemMetrics (SM_XVIRTUALSCREEN);
46- src_rect_.top_ = ::GetSystemMetrics (SM_YVIRTUALSCREEN);
47- src_rect_.right_ = src_rect_.left_ + ::GetSystemMetrics (SM_CXVIRTUALSCREEN);
48- src_rect_.bottom_ = src_rect_.top_ + ::GetSystemMetrics (SM_CYVIRTUALSCREEN);
46+ src_rect_ = virtual_screen_info_.size ;
4947 }
5048 else
5149 {
@@ -137,12 +135,11 @@ void cam_capture_source::_draw_annotations(const cam::rect<int> &capture_rect)
137135 {
138136 POINT pt;
139137 ::GetCursorPos (&pt);
138+ const auto mouse_point = _translate_from_virtual (pt);
140139
141140 Gdiplus::Graphics canvas (memory_dc_);
142141 canvas.SetSmoothingMode (Gdiplus::SmoothingMode::SmoothingModeAntiAlias);
143142
144- point<int > mouse_point (pt.x , pt.y );
145-
146143 const auto mouse_event_count = mouse_hook::get ().get_mouse_events_count ();
147144 if (mouse_event_count > 0 )
148145 {
@@ -184,3 +181,14 @@ void cam_capture_source::_draw_annotations(const cam::rect<int> &capture_rect)
184181 annotation->draw (canvas, draw_data);
185182 }
186183}
184+
185+ auto cam_capture_source::_translate_from_virtual (const POINT &mouse_position) -> point<int>
186+ {
187+ // virtual dataspace can be negative, but the target dataspace is always positive.
188+ const auto screen_rect = virtual_screen_info_.size ;
189+ auto result = point<int >(mouse_position.x , mouse_position.y );
190+ result.x (result.x () - screen_rect.left ());
191+ result.y (result.y () - screen_rect.top ());
192+
193+ return result;
194+ }
0 commit comments