-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmini_gui.h
114 lines (96 loc) · 2.91 KB
/
mini_gui.h
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#ifndef MINI_GUI_H
#define MINI_GUI_H
#ifdef __cplusplus
extern "C" {
#endif
// Dummy declaration.
struct mini_gui;
/**
* @brief A rectangle. Top-left is (X,Y), bottom-right is (X+W,Y+H);
*/
struct rect {
unsigned short x;
unsigned short y;
unsigned short width;
unsigned short height;
};
/**
* @brief A refresh method prototype. Is invoked by MG
* whenever a whole screen refresh should be done.
* @note When called, MG cursor will always be at (0,0).
*/
typedef void(*mini_gui_refresh_method_t)(struct mini_gui*);
/**
* @brief Initiate a mini-gui object.
* @param log_filename A filename to write log outputs
* @param refresh_callback A refresh callback method.
* Is invoked whenever a reshresh should be done.
* @returns a MG object, or NULL in case of an error.
*/
struct mini_gui* mini_gui_init(const char* log_filename, mini_gui_refresh_method_t refresh_callback);
/**
* @brief Clear all allocated memory for MG.
*/
void mini_gui_destroy(struct mini_gui* mg);
/**
* @brief Sets the window to a fixed size.
* @param mg The MG object
* @param size A rectangle; the fixed window size
*/
void mini_gui_set_screen_size(struct mini_gui* mg, struct rect size);
/**
* @brief Set the MG object to skip all screen drawing & sleeping.
* @note The log will still be updated.
*/
void mini_gui_skip_drawing(struct mini_gui* mg);
/**
* @brief Returns a rectangle with the screen size
* @param mg The MG object
*/
struct rect mini_gui_get_screen_size(struct mini_gui* mg);
/**
* @brief Moves the cursor to a specific location within the terminal
* @param mg The MG object
* @param x The X location in the terminal
* @param y The Y location in the terminal
*/
void mini_gui_move(struct mini_gui* mg, unsigned short x, unsigned short y);
/**
* @brief Print a formatted string to the terminal
* @param mg The MG object
* @param fmt The formatted string
* @param ... Any additional arguments
*/
void mini_gui_print(struct mini_gui* mg, const char* fmt, ...);
/**
* @brief Print a formatted string within area
* @param mg The MG object
* @param rect A rectangle, a position within screen
* @param fmt The formatted string
* @param ... Any additional arguments
*/
void mini_gui_print_rect(struct mini_gui* mg, struct rect rect, const char* fmt, ...);
/**
* @brief Clears an area in the screen (rectangle)
* @param mg The MG object
* @param rect A rectangle, a position within screen
*/
void mini_gui_clear_rect(struct mini_gui* mg, struct rect rect);
/**
* @brief Adds a string to the logfile
* @param mg The MG object
* @param fmt The formatted string
* @param ... Any additional arguments
*/
void mini_gui_log(struct mini_gui* mg, const char* fmt, ...);
/**
* @brief Sleeps for X milliseconds
* @param mg The MG object
* @param milliseconds MS to sleep
* @note Will not sleep in case the 'skip drawing' attribute was set
*/
void mini_gui_sleep(struct mini_gui* mg, int milliseconds);
#ifdef __cplusplus
}
#endif
#endif