ConsoleLib.h->ConsoleLib.hpp ConsoleLib::initConsole()->ConsoleLib::init()
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
#ifndef CONSOLELIB_H
|
||||
#define CONSOLELIB_H
|
||||
|
||||
#include <array>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <string_view>
|
||||
|
||||
// SDL 风格的按键码:ASCII 字符直接使用其 ASCII 值,特殊键从 128 开始。
|
||||
enum Keycode : uint16_t {
|
||||
KEY_UNKNOWN = 0,
|
||||
|
||||
KEY_BACKSPACE = 8,
|
||||
KEY_TAB = 9,
|
||||
KEY_RETURN = 13,
|
||||
KEY_ESCAPE = 27,
|
||||
KEY_SPACE = 32,
|
||||
|
||||
KEY_0 = '0',
|
||||
KEY_1 = '1',
|
||||
KEY_2 = '2',
|
||||
KEY_3 = '3',
|
||||
KEY_4 = '4',
|
||||
KEY_5 = '5',
|
||||
KEY_6 = '6',
|
||||
KEY_7 = '7',
|
||||
KEY_8 = '8',
|
||||
KEY_9 = '9',
|
||||
|
||||
KEY_a = 'a',
|
||||
KEY_b = 'b',
|
||||
KEY_c = 'c',
|
||||
KEY_d = 'd',
|
||||
KEY_e = 'e',
|
||||
KEY_f = 'f',
|
||||
KEY_g = 'g',
|
||||
KEY_h = 'h',
|
||||
KEY_i = 'i',
|
||||
KEY_j = 'j',
|
||||
KEY_k = 'k',
|
||||
KEY_l = 'l',
|
||||
KEY_m = 'm',
|
||||
KEY_n = 'n',
|
||||
KEY_o = 'o',
|
||||
KEY_p = 'p',
|
||||
KEY_q = 'q',
|
||||
KEY_r = 'r',
|
||||
KEY_s = 's',
|
||||
KEY_t = 't',
|
||||
KEY_u = 'u',
|
||||
KEY_v = 'v',
|
||||
KEY_w = 'w',
|
||||
KEY_x = 'x',
|
||||
KEY_y = 'y',
|
||||
KEY_z = 'z',
|
||||
|
||||
KEY_DELETE = 127,
|
||||
|
||||
KEY_UP = 128,
|
||||
KEY_DOWN,
|
||||
KEY_LEFT,
|
||||
KEY_RIGHT,
|
||||
KEY_HOME,
|
||||
KEY_END,
|
||||
KEY_F1,
|
||||
KEY_F2,
|
||||
KEY_F3,
|
||||
KEY_F4,
|
||||
|
||||
KEY_COUNT
|
||||
};
|
||||
|
||||
constexpr size_t KEYCODE_COUNT = static_cast<size_t>(KEY_COUNT);
|
||||
constexpr size_t ASCII_TABLE_SIZE = 128;
|
||||
constexpr uint8_t DEFAULT_CONSOLE_INPUT_FREQUENCY = 50;
|
||||
typedef std::uint32_t Color;
|
||||
|
||||
namespace ConsoleLib {
|
||||
void init();
|
||||
void stopInputThread();
|
||||
void restoreConsoleMode();
|
||||
|
||||
void RawPrint(std::string_view text);
|
||||
void printToConsole(std::string_view data);
|
||||
void printToConsole(std::string_view data, Color color);
|
||||
void clearConsole();
|
||||
|
||||
char getinput();
|
||||
|
||||
// 按 Keycode 返回按键状态,并清空内部记录。
|
||||
std::array<bool, KEYCODE_COUNT>& getConsoleKeyInput();
|
||||
bool isKeyPressed(Keycode key);
|
||||
|
||||
void sleep_ms(unsigned int ms);
|
||||
void setInputFrequency(std::uint8_t frequency);
|
||||
std::uint8_t getInputFrequency();
|
||||
|
||||
void quit(int exitCode);
|
||||
} // namespace ConsoleLib
|
||||
|
||||
#endif // CONSOLELIB_H
|
||||
Reference in New Issue
Block a user