mirror of
https://github.com/seekrs/MacroLibX.git
synced 2026-01-11 22:53:34 +00:00
working input API
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/05 16:30:19 by maldavid #+# #+# */
|
||||
/* Updated: 2023/04/12 11:31:28 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/04/12 19:54:20 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -31,57 +31,6 @@ namespace mlx
|
||||
|
||||
while(SDL_PollEvent(&_event))
|
||||
{
|
||||
if(_event.window.event == SDL_WINDOWEVENT_CLOSE)
|
||||
_end = true;
|
||||
|
||||
switch(_event.type)
|
||||
{
|
||||
case SDL_KEYDOWN:
|
||||
{
|
||||
_keys[_event.key.keysym.scancode] = static_cast<uint8_t>(action::down);
|
||||
if(_events_hooks[0].hook)
|
||||
_events_hooks[0].hook(_event.key.keysym.scancode, _events_hooks[0].param);
|
||||
break;
|
||||
}
|
||||
|
||||
case SDL_KEYUP:
|
||||
{
|
||||
_keys[_event.key.keysym.scancode] = static_cast<uint8_t>(action::up);
|
||||
if(_events_hooks[1].hook)
|
||||
_events_hooks[1].hook(_event.key.keysym.scancode, _events_hooks[1].param);
|
||||
break;
|
||||
}
|
||||
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
{
|
||||
_mouse[_event.button.button] = static_cast<uint8_t>(action::down);
|
||||
if(_events_hooks[2].hook)
|
||||
_events_hooks[2].hook(_event.button.button, _events_hooks[2].param);
|
||||
break;
|
||||
}
|
||||
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
{
|
||||
_mouse[_event.button.button] = static_cast<uint8_t>(action::up);
|
||||
if(_events_hooks[3].hook)
|
||||
_events_hooks[3].hook(_event.button.button, _events_hooks[3].param);
|
||||
break;
|
||||
}
|
||||
|
||||
case SDL_WINDOWEVENT:
|
||||
{
|
||||
switch(_event.window.event)
|
||||
{
|
||||
//case
|
||||
|
||||
default : break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default: break;
|
||||
}
|
||||
|
||||
if(_event.type == SDL_MOUSEMOTION)
|
||||
{
|
||||
_x = _event.motion.x;
|
||||
@@ -90,6 +39,105 @@ namespace mlx
|
||||
_xRel = _event.motion.xrel;
|
||||
_yRel = _event.motion.yrel;
|
||||
}
|
||||
|
||||
uint32_t id = _event.window.windowID;
|
||||
if(!_events_hooks.count(id))
|
||||
continue;
|
||||
|
||||
switch(_event.type)
|
||||
{
|
||||
case SDL_KEYDOWN:
|
||||
{
|
||||
_keys[_event.key.keysym.scancode] = static_cast<uint8_t>(action::down);
|
||||
if(_events_hooks[id][0].hook)
|
||||
_events_hooks[id][0].hook(_event.key.keysym.scancode, _events_hooks[id][0].param);
|
||||
break;
|
||||
}
|
||||
|
||||
case SDL_KEYUP:
|
||||
{
|
||||
_keys[_event.key.keysym.scancode] = static_cast<uint8_t>(action::up);
|
||||
if(_events_hooks[id][1].hook)
|
||||
_events_hooks[id][1].hook(_event.key.keysym.scancode, _events_hooks[id][1].param);
|
||||
break;
|
||||
}
|
||||
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
{
|
||||
_mouse[_event.button.button] = static_cast<uint8_t>(action::down);
|
||||
if(_events_hooks[id][2].hook)
|
||||
_events_hooks[id][2].hook(_event.button.button, _events_hooks[id][2].param);
|
||||
break;
|
||||
}
|
||||
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
{
|
||||
_mouse[_event.button.button] = static_cast<uint8_t>(action::up);
|
||||
if(_events_hooks[id][3].hook)
|
||||
_events_hooks[id][3].hook(_event.button.button, _events_hooks[id][3].param);
|
||||
break;
|
||||
}
|
||||
|
||||
case SDL_WINDOWEVENT:
|
||||
{
|
||||
switch(_event.window.event)
|
||||
{
|
||||
case SDL_WINDOWEVENT_CLOSE:
|
||||
{
|
||||
if(_events_hooks[id][4].hook)
|
||||
_events_hooks[id][4].hook(0, _events_hooks[id][4].param);
|
||||
break;
|
||||
}
|
||||
case SDL_WINDOWEVENT_MOVED:
|
||||
{
|
||||
if(_events_hooks[id][4].hook)
|
||||
_events_hooks[id][4].hook(1, _events_hooks[id][4].param);
|
||||
break;
|
||||
}
|
||||
case SDL_WINDOWEVENT_MINIMIZED:
|
||||
{
|
||||
if(_events_hooks[id][4].hook)
|
||||
_events_hooks[id][4].hook(2, _events_hooks[id][4].param);
|
||||
break;
|
||||
}
|
||||
case SDL_WINDOWEVENT_MAXIMIZED:
|
||||
{
|
||||
if(_events_hooks[id][4].hook)
|
||||
_events_hooks[id][4].hook(3, _events_hooks[id][4].param);
|
||||
break;
|
||||
}
|
||||
case SDL_WINDOWEVENT_ENTER:
|
||||
{
|
||||
if(_events_hooks[id][4].hook)
|
||||
_events_hooks[id][4].hook(4, _events_hooks[id][4].param);
|
||||
break;
|
||||
}
|
||||
case SDL_WINDOWEVENT_FOCUS_GAINED:
|
||||
{
|
||||
if(_events_hooks[id][4].hook)
|
||||
_events_hooks[id][4].hook(4, _events_hooks[id][4].param);
|
||||
break;
|
||||
}
|
||||
case SDL_WINDOWEVENT_LEAVE:
|
||||
{
|
||||
if(_events_hooks[id][4].hook)
|
||||
_events_hooks[id][4].hook(5, _events_hooks[id][4].param);
|
||||
break;
|
||||
}
|
||||
case SDL_WINDOWEVENT_FOCUS_LOST:
|
||||
{
|
||||
if(_events_hooks[id][4].hook)
|
||||
_events_hooks[id][4].hook(4, _events_hooks[id][4].param);
|
||||
break;
|
||||
}
|
||||
|
||||
default : break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user