SpiecsEngine
 
Loading...
Searching...
No Matches

◆ OnMouseButtonPressed()

bool Spices::WorldPickIDQuerier::OnMouseButtonPressed ( MouseButtonPressedEvent & e)
private

Event OnKeyPressed.

Parameters
[in]eEvent Wrapper.
Returns
true if we need block the event.

The first frame, we will not get register pointer.

Get viewport.

Add pick.

@breif Sub pick.

@breif Single Select.

@breif Cancle Select.

The first frame, we will not get register pointer.

Get viewport.

Add pick.

@breif Sub pick.

@breif Single Select.

@breif Cancle Select.

Definition at line 27 of file WorldPickIDQuerier.cpp.

28 {
30
34 if (!SlateSystem::GetRegister()) return false;
35
39 if (!m_ViewPort.lock()) m_ViewPort = SlateSystem::GetRegister()->GetViewPort();
40
41 if (!m_ViewPort.lock()->IsHovered() || m_ViewPort.lock()->GetGizmo()->IsOver()) return false;
42
43 if (m_ViewPort.lock()->GetMousePosInViewport().first < 0 ||
44 m_ViewPort.lock()->GetMousePosInViewport().first > m_ViewPort.lock()->GetPanelSize().x ||
45 m_ViewPort.lock()->GetMousePosInViewport().second < 0 ||
46 m_ViewPort.lock()->GetMousePosInViewport().second > m_ViewPort.lock()->GetPanelSize().y
47 )
48 {
49 return false;
50 }
51
52 if (e.GetMouseButton() == Mouse::ButtonLeft)
53 {
58 {
59 auto pair = m_ViewPort.lock()->GetMousePosInViewport();
60
62 ->AccessRowResource("EntityID")
63 ->CopyImageTexelToBuffer(
64 pair.first,
65 pair.second,
66 reinterpret_cast<void*>(&m_WorldPickID[0])
67 );
68
69 Entity entity((entt::entity)m_WorldPickID[0], FrameInfo::Get().m_World.get());
70 std::string entityName = *entity.GetComponent<TagComponent>().GetTag().begin();
71
72 FrameInfo::Get().m_PickEntityID.push_back(static_cast<int>(m_WorldPickID[0]), entityName);
73
74 std::stringstream ss;
75 ss << "Select entity: " << entityName;
76
77 SPICES_CORE_TRACE(ss.str())
78 }
79
84 {
85 auto pair = m_ViewPort.lock()->GetMousePosInViewport();
86
88 ->AccessRowResource("EntityID")
89 ->CopyImageTexelToBuffer(
90 pair.first,
91 pair.second,
92 reinterpret_cast<void*>(&m_WorldPickID[0])
93 );
94
95 std::string* ptr = FrameInfo::Get().m_PickEntityID.find_value(static_cast<int>(m_WorldPickID[0]));
96 if (ptr)
97 {
98 std::stringstream ss;
99 ss << "Deselect entity: " << *ptr;
100
101 SPICES_CORE_TRACE(ss.str())
102
103 FrameInfo::Get().m_PickEntityID.erase(static_cast<int>(m_WorldPickID[0]));
104 }
105 }
106
110 else
111 {
113
114 auto pair = m_ViewPort.lock()->GetMousePosInViewport();
115
117 ->AccessRowResource("EntityID")
118 ->CopyImageTexelToBuffer(
119 pair.first,
120 pair.second,
121 reinterpret_cast<void*>(&m_WorldPickID[0])
122 );
123
124 Entity entity((entt::entity)m_WorldPickID[0], FrameInfo::Get().m_World.get());
125 std::string entityName = *entity.GetComponent<TagComponent>().GetTag().begin();
126
127 FrameInfo::Get().m_PickEntityID.push_back(static_cast<int>(m_WorldPickID[0]), entityName);
128
129 std::stringstream ss;
130 ss << "Select entity: " << entityName;
131
132 SPICES_CORE_TRACE(ss.str())
133 }
134 }
135
139 else if (e.GetMouseButton() == Mouse::ButtonRight)
140 {
142
143 SPICES_CORE_TRACE("Cancel all selected entity")
144 }
145
146 return false;
147 }
#define SPICES_PROFILE_ZONE
static FrameInfo & Get()
Get FrameInfo.
Definition FrameInfo.cpp:14
scl::linked_unordered_map< int, std::string > m_PickEntityID
Definition FrameInfo.h:82
static bool IsKeyPressed(const int &keycode)
Query If given Key is Pressed.
Definition Input.h:34
static std::shared_ptr< SlateRegister > GetRegister()
Get slate register.
Definition SlateSystem.h:67
static std::shared_ptr< RendererResourcePool > GetRendererResourcePool()
Get RendererResourcePool in use.
std::weak_ptr< ImguiViewport > m_ViewPort
viewport pointer.
float m_WorldPickID[4]
World Picked entity id (only use channel 0).
V * find_value(const K &key)
Find the value by key.
void clear()
Clear this container's data.
void push_back(const K &key, const V &value)
Add a element to this container.

References Spices::Mouse::ButtonLeft, Spices::Mouse::ButtonRight, Spices::FrameInfo::Get(), Spices::MouseButtonEvent::GetMouseButton(), Spices::Input::IsKeyPressed(), Spices::Key::LeftControl, Spices::Key::LeftShift, m_WorldPickID, Spices::Key::RightControl, and Spices::Key::RightShift.

Referenced by OnEvent().