New module: Platform - Split window management from Utility module (#128)
* New module: Platform - Split window management from Utility module Final touch * NDK/SDK: Bring back initialization of Utility
This commit is contained in:
committed by
Jérôme Leclercq
parent
41a1b5d493
commit
5aa072cee3
81
tests/Engine/Platform/EventHandler/MouseClickState.cpp
Normal file
81
tests/Engine/Platform/EventHandler/MouseClickState.cpp
Normal file
@@ -0,0 +1,81 @@
|
||||
#include "MouseClickState.hpp"
|
||||
|
||||
#include "StateContext.hpp"
|
||||
#include "StateFactory.hpp"
|
||||
|
||||
#include <Nazara/Renderer/RenderWindow.hpp>
|
||||
#include <NDK/StateMachine.hpp>
|
||||
|
||||
MouseClickState::MouseClickState(StateContext& context) :
|
||||
BaseState(context)
|
||||
{
|
||||
}
|
||||
|
||||
void MouseClickState::Enter(Ndk::StateMachine& fsm)
|
||||
{
|
||||
BaseState::Enter(fsm);
|
||||
|
||||
Nz::EventHandler& eventHandler = m_context.window.GetEventHandler();
|
||||
m_keyPressedSlot.Connect(eventHandler.OnKeyPressed, [&] (const Nz::EventHandler*, const Nz::WindowEvent::KeyEvent& key)
|
||||
{
|
||||
if (key.code == Nz::Keyboard::Key::M && key.shift)
|
||||
{
|
||||
fsm.ChangeState(StateFactory::Get(EventStatus::Menu));
|
||||
}
|
||||
});
|
||||
|
||||
m_mouseButtonDoubleClickedSlot.Connect(eventHandler.OnMouseButtonDoubleClicked, [&] (const Nz::EventHandler*, const Nz::WindowEvent::MouseButtonEvent& mouse)
|
||||
{
|
||||
ManageInput(MouseStatus::DoubleClick, mouse, fsm);
|
||||
});
|
||||
|
||||
m_mouseButtonPressedSlot.Connect(eventHandler.OnMouseButtonPressed, [&] (const Nz::EventHandler*, const Nz::WindowEvent::MouseButtonEvent& mouse)
|
||||
{
|
||||
ManageInput(MouseStatus::Pressed, mouse, fsm);
|
||||
});
|
||||
|
||||
m_mouseButtonReleasedSlot.Connect(eventHandler.OnMouseButtonReleased, [&] (const Nz::EventHandler*, const Nz::WindowEvent::MouseButtonEvent& mouse)
|
||||
{
|
||||
ManageInput(MouseStatus::Released, mouse, fsm);
|
||||
});
|
||||
}
|
||||
|
||||
void MouseClickState::DrawMenu()
|
||||
{
|
||||
m_text.SetContent("Click in the windows, this text should change !\nM for Menu");
|
||||
}
|
||||
|
||||
void MouseClickState::ManageInput(MouseStatus mouseStatus, const Nz::WindowEvent::MouseButtonEvent& mouse, Ndk::StateMachine& /*fsm*/)
|
||||
{
|
||||
Nz::String content;
|
||||
if (mouseStatus == MouseStatus::Pressed)
|
||||
content = "Pressed: ";
|
||||
else if (mouseStatus == MouseStatus::Released)
|
||||
content = "Released: ";
|
||||
else
|
||||
content = "Double clicked: ";
|
||||
|
||||
switch (mouse.button)
|
||||
{
|
||||
case Nz::Mouse::Left:
|
||||
content += "Left";
|
||||
break;
|
||||
case Nz::Mouse::Middle:
|
||||
content += "Middle";
|
||||
break;
|
||||
case Nz::Mouse::Right:
|
||||
content += "Right";
|
||||
break;
|
||||
case Nz::Mouse::XButton1:
|
||||
content += "XButton1";
|
||||
break;
|
||||
case Nz::Mouse::XButton2:
|
||||
content += "XButton2";
|
||||
break;
|
||||
default:
|
||||
content += "Unknown";
|
||||
break;
|
||||
}
|
||||
|
||||
m_text.SetContent(content + "\nM for Menu");
|
||||
}
|
||||
Reference in New Issue
Block a user