Kernel: Input callbacks use the new BAN::Function
This commit is contained in:
parent
3561257286
commit
1545850be3
|
@ -1,5 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <BAN/Function.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
namespace Input
|
namespace Input
|
||||||
|
@ -57,9 +58,9 @@ namespace Input
|
||||||
void update();
|
void update();
|
||||||
bool is_key_down(Key);
|
bool is_key_down(Key);
|
||||||
|
|
||||||
void register_key_event_callback(void (*callback)(KeyEvent));
|
void register_key_event_callback(const BAN::Function<void(KeyEvent)>&);
|
||||||
void register_mouse_button_event_callback(void (*callback)(MouseButtonEvent));
|
void register_mouse_button_event_callback(const BAN::Function<void(MouseButtonEvent)>&);
|
||||||
void register_mouse_move_event_callback(void (*callback)(MouseMoveEvent));
|
void register_mouse_move_event_callback(const BAN::Function<void(MouseMoveEvent)>&);
|
||||||
|
|
||||||
const char* key_event_to_utf8(KeyEvent);
|
const char* key_event_to_utf8(KeyEvent);
|
||||||
|
|
||||||
|
|
|
@ -106,9 +106,9 @@ namespace Input
|
||||||
static uint8_t s_led_states = 0b000;
|
static uint8_t s_led_states = 0b000;
|
||||||
static uint8_t s_modifiers = 0x00;
|
static uint8_t s_modifiers = 0x00;
|
||||||
|
|
||||||
static void (*s_key_event_callback)(KeyEvent) = nullptr;
|
static BAN::Function<void(KeyEvent)> s_key_event_callback;
|
||||||
static void (*s_mouse_button_event_callback)(MouseButtonEvent) = nullptr;
|
static BAN::Function<void(MouseButtonEvent)> s_mouse_button_event_callback;
|
||||||
static void (*s_mouse_move_event_callback)(MouseMoveEvent) = nullptr;
|
static BAN::Function<void(MouseMoveEvent)> s_mouse_move_event_callback;
|
||||||
|
|
||||||
static const char* s_key_to_utf8_lower[]
|
static const char* s_key_to_utf8_lower[]
|
||||||
{
|
{
|
||||||
|
@ -385,21 +385,21 @@ namespace Input
|
||||||
|
|
||||||
while (!s_key_event_queue.Empty())
|
while (!s_key_event_queue.Empty())
|
||||||
{
|
{
|
||||||
if (s_key_event_callback)
|
if (s_key_event_callback.HasFunction())
|
||||||
s_key_event_callback(s_key_event_queue.Front());
|
s_key_event_callback(s_key_event_queue.Front());
|
||||||
s_key_event_queue.Pop();
|
s_key_event_queue.Pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!s_mouse_button_event_queue.Empty())
|
while (!s_mouse_button_event_queue.Empty())
|
||||||
{
|
{
|
||||||
if (s_mouse_button_event_callback)
|
if (s_mouse_button_event_callback.HasFunction())
|
||||||
s_mouse_button_event_callback(s_mouse_button_event_queue.Front());
|
s_mouse_button_event_callback(s_mouse_button_event_queue.Front());
|
||||||
s_mouse_button_event_queue.Pop();
|
s_mouse_button_event_queue.Pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!s_mouse_move_event_queue.Empty())
|
while (!s_mouse_move_event_queue.Empty())
|
||||||
{
|
{
|
||||||
if (s_mouse_move_event_callback)
|
if (s_mouse_move_event_callback.HasFunction())
|
||||||
s_mouse_move_event_callback(s_mouse_move_event_queue.Front());
|
s_mouse_move_event_callback(s_mouse_move_event_queue.Front());
|
||||||
s_mouse_move_event_queue.Pop();
|
s_mouse_move_event_queue.Pop();
|
||||||
}
|
}
|
||||||
|
@ -663,17 +663,17 @@ namespace Input
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void register_key_event_callback(void (*callback)(KeyEvent))
|
void register_key_event_callback(const BAN::Function<void(KeyEvent)>& callback)
|
||||||
{
|
{
|
||||||
s_key_event_callback = callback;
|
s_key_event_callback = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
void register_mouse_button_event_callback(void (*callback)(MouseButtonEvent))
|
void register_mouse_button_event_callback(const BAN::Function<void(MouseButtonEvent)>& callback)
|
||||||
{
|
{
|
||||||
s_mouse_button_event_callback = callback;
|
s_mouse_button_event_callback = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
void register_mouse_move_event_callback(void (*callback)(MouseMoveEvent))
|
void register_mouse_move_event_callback(const BAN::Function<void(MouseMoveEvent)>& callback)
|
||||||
{
|
{
|
||||||
s_mouse_move_event_callback = callback;
|
s_mouse_move_event_callback = callback;
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,9 +48,9 @@ namespace Kernel
|
||||||
|
|
||||||
Shell::Shell()
|
Shell::Shell()
|
||||||
{
|
{
|
||||||
Input::register_key_event_callback([](Input::KeyEvent event) { Shell::Get().KeyEventCallback(event); });
|
|
||||||
Input::register_mouse_move_event_callback([](Input::MouseMoveEvent event) { Shell::Get().MouseMoveEventCallback(event); });
|
|
||||||
SetPrompt("\\[\e[32m\\]user\\[\e[m\\]# "_sv);
|
SetPrompt("\\[\e[32m\\]user\\[\e[m\\]# "_sv);
|
||||||
|
Input::register_key_event_callback({ &Shell::KeyEventCallback, this });
|
||||||
|
Input::register_mouse_move_event_callback({ &Shell::MouseMoveEventCallback, this });
|
||||||
MUST(m_buffer.PushBack(""_sv));
|
MUST(m_buffer.PushBack(""_sv));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue