blob: c5397e97b80d3aa2f184109deb6365d6890a4602 (
plain)
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
|
/* [=]===^=[ framebuffer_callback ]=================================================================^===[=] */
static void framebuffer_callback(int32_t width, int32_t height) {
state.screen_width = width;
state.screen_height = height;
state.viewport.x = 0;
state.viewport.y = 0;
state.viewport.w = width;
state.viewport.h = height;
float current_aspect = (float)width / (float)height;
if(current_aspect > aspect_ratio) { // Window is wider than the desired aspect ratio
float new_width = height * aspect_ratio; // Compute new width based on the height and the desired aspect ratio
state.viewport.x = (width - new_width) / 2;
state.viewport.w = new_width;
} else if(current_aspect < aspect_ratio) { // Window is taller than the desired aspect ratio
float new_height = width / aspect_ratio; // Compute new height based on the width and the desired aspect ratio
state.viewport.y = (height - new_height) / 2;
state.viewport.h = new_height;
}
}
/* [=]===^=[ key_callback ]=================================================================^===[=] */
static void key_callback(uint32_t key, uint32_t action, uint32_t mods) {
if(key == MKS_KEY_ESCAPE) {
if(action == MKS_PRESSED) {
mkfw_set_should_close(true);
}
}
if(action == MKS_RELEASED) {
switch(key) {
// Handle shader CRT emulation toggle
case MKS_KEY_F12: {
state.toggle_crt_emulation = !state.toggle_crt_emulation;
} break;
// Handle fullscreen toggle
case MKS_KEY_F11: {
if(!keyboard_state[MKS_KEY_SHIFT]) {
if(state.fullscreen) {
mkfw_fullscreen(false);
state.fullscreen = false;
} else {
mkfw_fullscreen(true);
state.fullscreen = true;
}
} else if(keyboard_state[MKS_KEY_SHIFT]) {
#ifdef PROFILER
state.overlay = !state.overlay;
#endif
}
} break;
default: break;
}
}
}
/* [=]===^=[ mouse_move_callback ]=================================================================^===[=] */
static void mouse_move_callback(int32_t x, int32_t y) {
state.mouse_dx += x;
state.mouse_dy += y;
}
/* [=]===^=[ mouse_button_callback ]=================================================================^===[=] */
static void mouse_button_callback(uint8_t button, int action) {
// printf("mouse_button\n");
}
|