KTech 1.1.0
C++ 2D terminal game engine library
Loading...
Searching...
No Matches
callbackgroup.hpp
1/*
2 KTech, Kaup's C++ 2D terminal game engine library.
3 Copyright (C) 2023-2025 Ethan Kaufman (AKA Kaup)
4
5 This file is part of KTech.
6
7 KTech is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 any later version.
11
12 KTech is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with KTech. If not, see <https://www.gnu.org/licenses/>.
19*/
20
21#pragma once
22
23#include "input.hpp"
24
33{
34public:
35 CallbackGroup(Engine& engine, bool enabled = true);
37
38 void RegisterCallback(const std::string& stringKey, const std::function<bool()>& callback);
39 void RegisterRangedCallback(char start, char end, const std::function<bool()>& callback);
40
41 void Enable();
42 void Disable();
43
44private:
45 enum class Status : uint8_t
46 {
47 disabled,
48 enabled
49 };
50
51 Engine& engine;
52 std::vector<std::shared_ptr<Callback>> m_callbacks;
53 Status m_status;
54 bool m_synced = false;
55
56 void Update();
57
58 friend Input;
59};
Complete engine containing all engine components.
Definition engine.hpp:41
Input callbacks creator and manager.
Definition callbackgroup.hpp:33
~CallbackGroup()
Remove CallbackGroup and its callback functions from Input.
Definition callbackgroup.cpp:43
void Disable()
Disable registered callback functions.
Definition callbackgroup.cpp:137
void RegisterCallback(const std::string &stringKey, const std::function< bool()> &callback)
Register a function to be called back when an input is received.
Definition callbackgroup.cpp:70
void RegisterRangedCallback(char start, char end, const std::function< bool()> &callback)
Register a function to be called back when an input within a characters range is received.
Definition callbackgroup.cpp:106
void Enable()
Enable registered callback functions.
Definition callbackgroup.cpp:124
CallbackGroup(Engine &engine, bool enabled=true)
Register a new CallbackGroup at Input.
Definition callbackgroup.cpp:32
Engine component responsible for distributing user input.
Definition input.hpp:44