This commit is contained in:
2025-05-13 02:46:21 +03:00
parent 143e16692e
commit 86914b7fcc
610 changed files with 92343 additions and 2 deletions
+61
View File
@@ -0,0 +1,61 @@
#include "IInputSystem.h"
#include "IInputListener.h"
namespace LifeCore
{
bool IInputSystem::IsListening(IInputListener* listener){
for(auto val : listeners)
if(val == listener)
return true;
return false;
}
bool IInputSystem::RemoveListener(IInputListener* listener){
auto it = listeners.begin();
for(it = listeners.begin(); it != listeners.end(); ++it){
if(*it == listener)
break;
}
if(it == listeners.end())
return false;
listeners.erase(it);
if(listener->GetInputSystem() == this){
listener->SetInputSystem(nullptr);
}
return true;
}
void IInputSystem::AddListener(IInputListener* listener){
if(IsListening(listener))
return;
listeners.push_back(listener);
if(listener->GetInputSystem() != this)
listener->SetInputSystem(this);
}
bool IInputSystem::KeyPressed(Key key){
return keyboard_keys[static_cast<size_t>(key)];
}
void IInputSystem::OnKeyPress(Key key, unsigned int text, const std::string& str){
keyboard_keys[static_cast<size_t>(key)] = true;
for(auto listener : listeners)
listener->KeyDown(key, text, str);
}
void IInputSystem::OnKeyRelease(Key key, unsigned int text, const std::string& str){
keyboard_keys[static_cast<size_t>(key)] = false;
for(auto listener : listeners)
listener->KeyUp(key, text, str);
}
void IInputSystem::OnMouseMove(int absX, int relX, int absY, int relY){
for(auto listener : listeners)
listener->MouseMove(absX, relX, absY, relY);
}
void IInputSystem::OnMousePress(MouseKey button){
for(auto listener : listeners)
listener->MousePressed(button);
}
void IInputSystem::OnMouseRelease(MouseKey button){
for(auto listener : listeners)
listener->MouseReleased(button);
}
}