Borderless window support for the Win32 build. Default window position is now also centred.

This commit is contained in:
Saracen 2016-01-03 04:18:28 +00:00
parent 8b1dcbfe4d
commit 6eb4812317
6 changed files with 36 additions and 3 deletions

View File

@ -260,6 +260,13 @@ bool _OS::is_window_maximized() const {
return OS::get_singleton()->is_window_maximized(); return OS::get_singleton()->is_window_maximized();
} }
void _OS::set_borderless_window(bool p_borderless) {
OS::get_singleton()->set_borderless_window(p_borderless);
}
bool _OS::get_borderless_window() const {
return OS::get_singleton()->get_borderless_window();
}
void _OS::set_use_file_access_save_and_swap(bool p_enable) { void _OS::set_use_file_access_save_and_swap(bool p_enable) {
@ -865,6 +872,11 @@ void _OS::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_window_maximized", "enabled"),&_OS::set_window_maximized); ObjectTypeDB::bind_method(_MD("set_window_maximized", "enabled"),&_OS::set_window_maximized);
ObjectTypeDB::bind_method(_MD("is_window_maximized"),&_OS::is_window_maximized); ObjectTypeDB::bind_method(_MD("is_window_maximized"),&_OS::is_window_maximized);
ObjectTypeDB::bind_method(_MD("set_borderless_window", "borderless"), &_OS::set_borderless_window);
ObjectTypeDB::bind_method(_MD("get_borderless_window"), &_OS::get_borderless_window);
ObjectTypeDB::bind_method(_MD("set_multisamples", "multisamples"), &_OS::set_multisamples);
ObjectTypeDB::bind_method(_MD("get_multisamples"), &_OS::get_multisamples);
ObjectTypeDB::bind_method(_MD("set_screen_orientation","orientation"),&_OS::set_screen_orientation); ObjectTypeDB::bind_method(_MD("set_screen_orientation","orientation"),&_OS::set_screen_orientation);
ObjectTypeDB::bind_method(_MD("get_screen_orientation"),&_OS::get_screen_orientation); ObjectTypeDB::bind_method(_MD("get_screen_orientation"),&_OS::get_screen_orientation);

View File

@ -128,6 +128,8 @@ public:
virtual void set_window_maximized(bool p_enabled); virtual void set_window_maximized(bool p_enabled);
virtual bool is_window_maximized() const; virtual bool is_window_maximized() const;
virtual void set_borderless_window(bool p_borderless);
virtual bool get_borderless_window() const;
Error native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track); Error native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track);
bool native_video_is_playing(); bool native_video_is_playing();

View File

@ -75,8 +75,9 @@ public:
int width,height; int width,height;
bool fullscreen; bool fullscreen;
bool resizable; bool resizable;
bool borderless_window;
float get_aspect() const { return (float)width/(float)height; } float get_aspect() const { return (float)width/(float)height; }
VideoMode(int p_width=1024,int p_height=600,bool p_fullscreen=false, bool p_resizable = true) {width=p_width; height=p_height; fullscreen=p_fullscreen; resizable = p_resizable; } VideoMode(int p_width=1024,int p_height=600,bool p_fullscreen=false, bool p_resizable = true,bool p_borderless_window=false) { width=p_width; height=p_height; fullscreen=p_fullscreen; resizable = p_resizable; borderless_window=p_borderless_window; }
}; };
protected: protected:
friend class Main; friend class Main;
@ -172,6 +173,8 @@ public:
virtual void set_window_maximized(bool p_enabled) {} virtual void set_window_maximized(bool p_enabled) {}
virtual bool is_window_maximized() const { return true; } virtual bool is_window_maximized() const { return true; }
virtual void set_borderless_window(int p_borderless) {}
virtual bool get_borderless_window() { return 0; }

View File

@ -691,6 +691,8 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas
video_mode.fullscreen=globals->get("display/fullscreen"); video_mode.fullscreen=globals->get("display/fullscreen");
if (use_custom_res && globals->has("display/resizable")) if (use_custom_res && globals->has("display/resizable"))
video_mode.resizable=globals->get("display/resizable"); video_mode.resizable=globals->get("display/resizable");
if (use_custom_res && globals->has("display/borderless_window"))
video_mode.borderless_window = globals->get("display/borderless_window");
if (!force_res && use_custom_res && globals->has("display/test_width") && globals->has("display/test_height")) { if (!force_res && use_custom_res && globals->has("display/test_width") && globals->has("display/test_height")) {
int tw = globals->get("display/test_width"); int tw = globals->get("display/test_width");
@ -706,6 +708,7 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas
GLOBAL_DEF("display/height",video_mode.height); GLOBAL_DEF("display/height",video_mode.height);
GLOBAL_DEF("display/fullscreen",video_mode.fullscreen); GLOBAL_DEF("display/fullscreen",video_mode.fullscreen);
GLOBAL_DEF("display/resizable",video_mode.resizable); GLOBAL_DEF("display/resizable",video_mode.resizable);
GLOBAL_DEF("display/borderless_window", video_mode.borderless_window);
GLOBAL_DEF("display/test_width",0); GLOBAL_DEF("display/test_width",0);
GLOBAL_DEF("display/test_height",0); GLOBAL_DEF("display/test_height",0);
OS::get_singleton()->_pixel_snap=GLOBAL_DEF("display/use_2d_pixel_snap",false); OS::get_singleton()->_pixel_snap=GLOBAL_DEF("display/use_2d_pixel_snap",false);

View File

@ -177,6 +177,7 @@ void OS_Windows::initialize_core() {
//RedirectIOToConsole(); //RedirectIOToConsole();
maximized=false; maximized=false;
minimized=false; minimized=false;
borderless=false;
ThreadWindows::make_default(); ThreadWindows::make_default();
SemaphoreWindows::make_default(); SemaphoreWindows::make_default();
@ -884,7 +885,7 @@ void OS_Windows::initialize(const VideoMode& p_desired,int p_video_driver,int p_
DWORD dwExStyle; DWORD dwExStyle;
DWORD dwStyle; DWORD dwStyle;
if (video_mode.fullscreen) { if (video_mode.fullscreen||video_mode.borderless_window) {
dwExStyle=WS_EX_APPWINDOW; dwExStyle=WS_EX_APPWINDOW;
dwStyle=WS_POPUP; dwStyle=WS_POPUP;
@ -930,7 +931,7 @@ void OS_Windows::initialize(const VideoMode& p_desired,int p_video_driver,int p_
video_mode.fullscreen = false; video_mode.fullscreen = false;
} else { } else {
if (!(hWnd=CreateWindowExW(dwExStyle,L"Engine",L"", dwStyle|WS_CLIPSIBLINGS|WS_CLIPCHILDREN, 0, 0,WindowRect.right-WindowRect.left,WindowRect.bottom-WindowRect.top, NULL,NULL, hInstance,NULL))) { if (!(hWnd=CreateWindowExW(dwExStyle,L"Engine",L"", dwStyle|WS_CLIPSIBLINGS|WS_CLIPCHILDREN, (GetSystemMetrics(SM_CXSCREEN)-WindowRect.right)/2, (GetSystemMetrics(SM_CYSCREEN)-WindowRect.bottom)/2, WindowRect.right-WindowRect.left,WindowRect.bottom-WindowRect.top, NULL,NULL, hInstance,NULL))) {
MessageBoxW(NULL,L"Window Creation Error.",L"ERROR",MB_OK|MB_ICONEXCLAMATION); MessageBoxW(NULL,L"Window Creation Error.",L"ERROR",MB_OK|MB_ICONEXCLAMATION);
return; // Return FALSE return; // Return FALSE
} }
@ -1528,6 +1529,14 @@ bool OS_Windows::is_window_maximized() const{
} }
void OS_Windows::set_borderless_window(int p_borderless) {
video_mode.borderless_window = p_borderless;
}
bool OS_Windows::get_borderless_window() {
return video_mode.borderless_window;
}
void OS_Windows::print_error(const char* p_function, const char* p_file, int p_line, const char* p_code, const char* p_rationale, ErrorType p_type) { void OS_Windows::print_error(const char* p_function, const char* p_file, int p_line, const char* p_code, const char* p_rationale, ErrorType p_type) {
HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE); HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE);

View File

@ -179,6 +179,7 @@ protected:
Vector<MonitorInfo> monitor_info; Vector<MonitorInfo> monitor_info;
bool maximized; bool maximized;
bool minimized; bool minimized;
bool borderless;
static BOOL CALLBACK MonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData); static BOOL CALLBACK MonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData);
@ -223,6 +224,9 @@ public:
virtual void set_window_maximized(bool p_enabled); virtual void set_window_maximized(bool p_enabled);
virtual bool is_window_maximized() const; virtual bool is_window_maximized() const;
virtual void set_borderless_window(int p_borderless);
virtual bool get_borderless_window();
virtual MainLoop *get_main_loop() const; virtual MainLoop *get_main_loop() const;
virtual String get_name(); virtual String get_name();