@@ -31,25 +31,30 @@ namespace CppUtils::UnitTest::Terminal::Mouse
3131 CppUtils::Terminal::PrimitiveStyle::Outline,
3232 CppUtils::Terminal::CharAttributes{});
3333
34- if (event->position.x() < size.width() and event->position.y() < size.height())
34+ if (const auto origin = canvas.getAbsolutePosition();
35+ event->position.x() >= origin.x() and event->position.y() >= origin.y())
3536 {
36- auto c = ' ' ;
37- switch (event->button )
37+ const auto relativePosition = event->position - origin ;
38+ if (relativePosition.x() < size.width() and relativePosition.y() < size.height() )
3839 {
39- case CppUtils::Terminal::Mouse::Button::Left: c = 'L'; break;
40- case CppUtils::Terminal::Mouse::Button::Middle: c = 'M'; break;
41- case CppUtils::Terminal::Mouse::Button::Right: c = 'R'; break;
42- case CppUtils::Terminal::Mouse::Button::ScrollUp: c = '^'; break;
43- case CppUtils::Terminal::Mouse::Button::ScrollDown: c = 'v'; break;
44- default: c = '.'; break;
45- }
40+ auto c = ' ';
41+ switch (event->button)
42+ {
43+ case CppUtils::Terminal::Mouse::Button::Left: c = 'L'; break;
44+ case CppUtils::Terminal::Mouse::Button::Middle: c = 'M'; break;
45+ case CppUtils::Terminal::Mouse::Button::Right: c = 'R'; break;
46+ case CppUtils::Terminal::Mouse::Button::ScrollUp: c = '^'; break;
47+ case CppUtils::Terminal::Mouse::Button::ScrollDown: c = 'v'; break;
48+ default: c = '.'; break;
49+ }
4650
47- c = event->pressed ? static_cast<char>(std::toupper(c)) : static_cast<char>(std::tolower(c));
48- canvas.setChar(event->position , CppUtils::Terminal::CharAttributes{c});
51+ c = event->pressed ? static_cast<char>(std::toupper(c)) : static_cast<char>(std::tolower(c));
52+ canvas.setChar(relativePosition , CppUtils::Terminal::CharAttributes{c});
4953
50- canvas.printText({1, 1}, std::format("Position: {}, {}", event->position.x(), event->position.y()));
51- canvas.printText({1, 2}, std::format("Button: {} Pressed: {}", (int)event->button, event->pressed));
52- canvas.printText({1, 3}, std::format("Modifiers: {}{}{}", event->ctrl ? "C" : "", event->alt ? "A" : "", event->shift ? "S" : ""));
54+ canvas.printText({1, 1}, std::format("Position: {}, {}", event->position.x(), event->position.y()));
55+ canvas.printText({1, 2}, std::format("Button: {} Pressed: {}", (int)event->button, event->pressed));
56+ canvas.printText({1, 3}, std::format("Modifiers: {}{}{}", event->ctrl ? "C" : "", event->alt ? "A" : "", event->shift ? "S" : ""));
57+ }
5358 }
5459 canvas.print();
5560 }
0 commit comments