aboutsummaryrefslogtreecommitdiff
path: root/src/ui/events/MouseEventArgs.cpp
blob: 39424c6525dae6fd944f22d35270dc3f67a4bb67 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include "cru/ui/events/MouseEventArgs.hpp"

#include "cru/ui/controls/Control.hpp"
#include "cru/ui/host/WindowHost.hpp"
#include "cru/ui/render/RenderObject.hpp"

namespace cru::ui::events {
Point MouseEventArgs::GetPoint(render::RenderObject* render_object) const {
  return GetPoint() - render_object->GetTotalOffset();
}

Point MouseEventArgs::GetPointToContent(
    render::RenderObject* render_object) const {
  return render_object->FromRootToContent(GetPoint());
}

Point MouseEventArgs::GetPointOfScreen() const {
  auto sender = GetSender();
  if (auto control = dynamic_cast<controls::Control*>(sender)) {
    if (auto host = control->GetWindowHost())
      return GetPoint() + control->GetWindowHost()
                              ->GetNativeWindow()
                              ->GetClientRect()
                              .GetLeftTop();
  }
  return GetPoint();
}
}  // namespace cru::ui::events