-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtifc.c
179 lines (145 loc) · 4.43 KB
/
tifc.c
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#include "tifc.h"
#include "display.h"
#include "frame.h"
#include "grid.h"
#include "layout.h"
#include "panel.h"
#include "ui.h"
#include <locale.h>
tifc_t tifc_init(void)
{
setlocale(LC_ALL, "");
input_enable_mouse();
tifc_t tifc = {
.input = input_init(),
.mode = TIFC_CANVAS_MODE,
.ui = ui_init(),
.canvas = canvas_init(),
};
canvas_load_objects(&tifc.canvas);
return tifc;
}
void tifc_deinit(tifc_t *const tifc)
{
input_disable_mouse();
canvas_deinit(&tifc->canvas);
input_deinit(&tifc->input);
}
void tifc_canvas_mode(tifc_t *const tifc)
{
tifc->mode = TIFC_CANVAS_MODE;
}
void tifc_ui_mode(tifc_t* const tifc)
{
tifc->mode = TIFC_UI_MODE;
}
input_hooks_t* tifc_mode_current_hooks(tifc_t *const tifc)
{
switch (tifc->mode)
{
case TIFC_CANVAS_MODE: return &tifc->canvas.hooks;
case TIFC_UI_MODE: return &tifc->ui.hooks;
}
return 0;
}
void tifc_render(tifc_t *const tifc)
{
display_clear(&tifc->display);
//canvas_render(&tifc->canvas, &tifc->display);
// ...
ui_render(&tifc->ui, &tifc->display);
display_render(&tifc->display);
}
void tifc_create_ui_layout(tifc_t *const tifc)
{
panel_opts_t *opts = &(panel_opts_t)
{
.title = "top",
.layout = {
.align = LAYOUT_ALIGN_TOP,
.size_method = LAYOUT_SIZE_RELATIVE,
.size = {.y = 50},
},
.columns = 4,
.column_layout = (grid_layout_t[]){
[0] = {.size = 3},
[1] = {.size = 50, .size_method = LAYOUT_SIZE_RELATIVE },
[2] = {.size = 50, .size_method = LAYOUT_SIZE_RELATIVE },
[3] = {.size = 100, .size_method = LAYOUT_SIZE_RELATIVE },
},
.rows = 3,
.row_layout = (grid_layout_t[]){
[0] = {.size = 3},
[1] = {.size = 35, .size_method = LAYOUT_SIZE_RELATIVE },
[2] = {.size = 100, .size_method = LAYOUT_SIZE_RELATIVE },
}
};
panel_t * panel = ui_add_panel(&tifc->ui, opts);
grid_span_t span;
span = (grid_span_t){{0, 0}, {0, 0}};
grid_add_area(&panel->grid, span, TEXT_ALIGN_LEFT);
span = (grid_span_t){{1, 1}, {0, 0}};
grid_add_area(&panel->grid, span, TEXT_ALIGN_LEFT);
span = (grid_span_t){{2, 2}, {0, 0}};
grid_add_area(&panel->grid, span, TEXT_ALIGN_LEFT);
span = (grid_span_t){{3, 3}, {0, 0}};
grid_add_area(&panel->grid, span, TEXT_ALIGN_LEFT);
span = (grid_span_t){{0, 0}, {1, 1}};
grid_add_area(&panel->grid, span, TEXT_ALIGN_LEFT);
span = (grid_span_t){{1, 1}, {1, 1}};
grid_add_area(&panel->grid, span, TEXT_ALIGN_LEFT);
span = (grid_span_t){{2, 2}, {1, 1}};
grid_add_area(&panel->grid, span, TEXT_ALIGN_LEFT);
span = (grid_span_t){{3, 3}, {1, 1}};
grid_add_area(&panel->grid, span, TEXT_ALIGN_LEFT);
span = (grid_span_t){{0, 0}, {2, 2}};
grid_add_area(&panel->grid, span, TEXT_ALIGN_LEFT);
span = (grid_span_t){{1, 1}, {2, 2}};
grid_add_area(&panel->grid, span, TEXT_ALIGN_LEFT);
span = (grid_span_t){{2, 2}, {2, 2}};
grid_add_area(&panel->grid, span, TEXT_ALIGN_LEFT);
span = (grid_span_t){{3, 3}, {2, 2}};
grid_add_area(&panel->grid, span, TEXT_ALIGN_LEFT);
opts->title = "left";
opts->layout.align = LAYOUT_ALIGN_LEFT;
opts->layout.size.x = 50;
(void) ui_add_panel(&tifc->ui, opts);
opts->title = "right-top";
opts->layout.align = LAYOUT_ALIGN_TOP;
opts->layout.size.y = 50;
(void) ui_add_panel(&tifc->ui, opts);
opts->title = "right-bot";
opts->layout.align = LAYOUT_ALIGN_BOT;
opts->layout.size.y = 100;
(void) ui_add_panel(&tifc->ui, opts);
ui_recalculate_layout(&tifc->ui, &tifc->display);
}
int tifc_event_loop(void)
{
tifc_t tifc = tifc_init();
resize_hook_with_data_t resize_hook = {
.data = &tifc.ui,
.hook = ui_resize_hook,
};
display_set_resize_handler(&tifc.display, resize_hook);
tifc_create_ui_layout(&tifc);
int exit_status = 0;
while (1)
{
// input_display_overlay(&tifc.input, (disp_pos_t){.x = 0, .y = 3});
tifc_render(&tifc);
input_hooks_t *hooks = tifc_mode_current_hooks(&tifc);
exit_status = input_handle_events(&tifc.input, hooks, &tifc);
if (0 != exit_status)
{
display_erase();
break;
}
}
tifc_deinit(&tifc);
return exit_status;
}
int main(void)
{
return tifc_event_loop();
}