This repository was archived by the owner on Jan 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfs_controller.cpp
96 lines (70 loc) · 2.86 KB
/
fs_controller.cpp
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
/*************************************************************************/
/* fs_controller.cpp */
/*************************************************************************/
#include "fs_controller.h"
FSController *FSController::singleton = NULL;
FSController *FSController::get_singleton() {
return singleton;
};
void FSController::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_screen_mode_list", "screen"), &FSController::get_screen_mode_list, DEFVAL(-1));
ClassDB::bind_method(D_METHOD("change_mode_windowed", "size", "position", "screen"), &FSController::change_mode_windowed, DEFVAL(0));
ClassDB::bind_method(D_METHOD("change_mode_borderless_fullscreen", "screen"), &FSController::change_mode_borderless_fullscreen, DEFVAL(0));
ClassDB::bind_method(D_METHOD("change_mode_exclusive_fullscreen", "mode", "screen"), &FSController::change_mode_exclusive_fullscreen, DEFVAL(0));
};
void FSController::_notification(int p_what) {
switch (p_what) {
case MainLoop::NOTIFICATION_WM_FOCUS_OUT: {
native_hnd.deactivate_video_mode();
} break;
case MainLoop::NOTIFICATION_WM_FOCUS_IN: {
native_hnd.activate_video_mode();
} break;
default: {
//NOP
};
}
};
Array FSController::get_screen_mode_list(int p_screen) const {
if (p_screen == -1) {
p_screen = OS::get_singleton()->get_current_screen();
}
Array vmarr;
List<Vector3> vmlist;
native_hnd.get_screen_mode_list_native(&vmlist, p_screen);
for (List<Vector3>::Element *E = vmlist.front(); E; E = E->next()) {
vmarr.push_back(E->get());
}
return vmarr;
};
void FSController::change_mode_windowed(const Vector2 &p_mode, const Point2 &p_position, int p_screen) {
OS::get_singleton()->set_window_resizable(true);
native_hnd.restore_video_mode();
OS::get_singleton()->set_window_fullscreen(false);
OS::get_singleton()->set_current_screen(p_screen);
OS::get_singleton()->set_window_size(Vector2(p_mode.x, p_mode.y));
OS::get_singleton()->set_window_resizable(false);
};
void FSController::change_mode_borderless_fullscreen(int p_screen) {
OS::get_singleton()->set_window_resizable(true);
native_hnd.restore_video_mode();
OS::get_singleton()->set_window_fullscreen(false);
OS::get_singleton()->set_current_screen(p_screen);
OS::get_singleton()->set_window_fullscreen(true);
OS::get_singleton()->set_window_resizable(false);
};
void FSController::change_mode_exclusive_fullscreen(const Vector3 &p_mode, int p_screen) {
OS::get_singleton()->set_window_resizable(true);
OS::get_singleton()->set_window_fullscreen(false);
OS::get_singleton()->set_current_screen(p_screen);
native_hnd.set_video_mode(p_mode);
OS::get_singleton()->set_window_fullscreen(true);
OS::get_singleton()->set_window_resizable(false);
};
FSController::FSController() {
singleton = this;
};
FSController::~FSController() {
native_hnd.restore_video_mode();
singleton = NULL;
};