This repository was archived by the owner on Mar 1, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathsomething_console.hpp
More file actions
66 lines (50 loc) · 1.43 KB
/
something_console.hpp
File metadata and controls
66 lines (50 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#ifndef SOMETHING_CONSOLE_HPP_
#define SOMETHING_CONSOLE_HPP_
#include "something_select_popup.hpp"
#include "something_edit_field.hpp"
struct Game;
struct Console
{
struct History
{
char entries[CONSOLE_HISTORY_CAPACITY][CONSOLE_COLUMNS];
size_t entry_sizes[CONSOLE_HISTORY_CAPACITY];
int end;
int count;
int cursor;
void push(String_View entry);
void up();
void down();
String_View current();
};
bool enabled;
float slide_position;
char rows[CONSOLE_ROWS][CONSOLE_COLUMNS];
size_t rows_count[CONSOLE_ROWS];
size_t begin;
size_t count;
size_t scroll;
History history;
Edit_Field edit_field;
bool completion_popup_enabled;
Select_Popup completion_popup;
void render(SDL_Renderer *renderer, Bitmap_Font *font);
void update(float dt);
void toggle();
void start_autocompletion();
template <typename ... Types>
void println(Types... args)
{
const size_t index = (begin + count) % CONSOLE_ROWS;
String_Buffer sbuffer = {CONSOLE_COLUMNS, rows[index], rows_count[index]};
sprintln(&sbuffer, args...);
rows_count[index] = sbuffer.size;
if (count < (int) CONSOLE_ROWS) {
count += 1;
} else {
begin = (begin + 1) % CONSOLE_ROWS;
}
}
void handle_event(SDL_Event *event, Game *game);
};
#endif // SOMETHING_CONSOLE_HPP_