new editor settings customization of where to run the game from the editor

This commit is contained in:
Juan Linietsky 2015-08-30 23:36:46 -03:00
parent 2d8866574d
commit cf57a654d7
7 changed files with 140 additions and 10 deletions

View file

@ -155,7 +155,7 @@ public:
virtual int get_screen_count() const{ return 1; } virtual int get_screen_count() const{ return 1; }
virtual int get_current_screen() const { return 0; } virtual int get_current_screen() const { return 0; }
virtual void set_current_screen(int p_screen) { } virtual void set_current_screen(int p_screen) { }
virtual Point2 get_screen_position(int p_screen=0) { return Point2(); } virtual Point2 get_screen_position(int p_screen=0) const { return Point2(); }
virtual Size2 get_screen_size(int p_screen=0) const { return get_window_size(); } virtual Size2 get_screen_size(int p_screen=0) const { return get_window_size(); }
virtual Point2 get_window_position() const { return Vector2(); } virtual Point2 get_window_position() const { return Vector2(); }
virtual void set_window_position(const Point2& p_position) {} virtual void set_window_position(const Point2& p_position) {}

View file

@ -94,11 +94,15 @@ static FileAccessNetworkClient *file_access_network_client=NULL;
static TranslationServer *translation_server = NULL; static TranslationServer *translation_server = NULL;
static OS::VideoMode video_mode; static OS::VideoMode video_mode;
static bool init_maximized=false;
static bool init_fullscreen=false;
static bool init_use_custom_pos=false;
static Vector2 init_custom_pos;
static int video_driver_idx=-1; static int video_driver_idx=-1;
static int audio_driver_idx=-1; static int audio_driver_idx=-1;
static String locale; static String locale;
static bool init_maximized=false;
static int init_screen=-1; static int init_screen=-1;
static String unescape_cmdline(const String& p_str) { static String unescape_cmdline(const String& p_str) {
@ -136,8 +140,10 @@ void Main::print_help(const char* p_binary) {
} }
OS::get_singleton()->print(")\n"); OS::get_singleton()->print(")\n");
OS::get_singleton()->print("\t-r WIDTHxHEIGHT\t : Request Screen Resolution\n"); OS::get_singleton()->print("\t-r WIDTHxHEIGHT\t : Request Window Resolution\n");
OS::get_singleton()->print("\t-p XxY\t : Request Window Position\n");
OS::get_singleton()->print("\t-f\t\t : Request Fullscreen\n"); OS::get_singleton()->print("\t-f\t\t : Request Fullscreen\n");
OS::get_singleton()->print("\t-mx\t\t Request Maximized\n");
OS::get_singleton()->print("\t-vd DRIVER\t : Video Driver ("); OS::get_singleton()->print("\t-vd DRIVER\t : Video Driver (");
for (int i=0;i<OS::get_singleton()->get_video_driver_count();i++) { for (int i=0;i<OS::get_singleton()->get_video_driver_count();i++) {
@ -311,7 +317,37 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas
} }
} else if (I->get()=="-p") { // position
if (I->next()) {
String vm=I->next()->get();
if (vm.find("x")==-1) { // invalid parameter format
goto error;
}
int x=vm.get_slice("x",0).to_int();
int y=vm.get_slice("x",1).to_int();
init_custom_pos=Point2(x,y);
init_use_custom_pos=true;
force_res=true;
N=I->next()->next();
} else {
goto error;
}
} else if (I->get()=="-mx") { // video driver
init_maximized=true;
} else if (I->get()=="-vd") { // video driver } else if (I->get()=="-vd") { // video driver
if (I->next()) { if (I->next()) {
@ -383,7 +419,8 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas
} else if (I->get()=="-f") { // fullscreen } else if (I->get()=="-f") { // fullscreen
video_mode.fullscreen=true; //video_mode.fullscreen=false;
init_fullscreen=true;
} else if (I->get()=="-e" || I->get()=="-editor") { // fonud editor } else if (I->get()=="-e" || I->get()=="-editor") { // fonud editor
editor=true; editor=true;
@ -785,6 +822,14 @@ Error Main::setup2() {
OS::get_singleton()->initialize(video_mode,video_driver_idx,audio_driver_idx); OS::get_singleton()->initialize(video_mode,video_driver_idx,audio_driver_idx);
if (init_use_custom_pos) {
OS::get_singleton()->set_window_position(init_custom_pos);
}
if (init_maximized) {
OS::get_singleton()->set_window_maximized(true);
} else if (init_fullscreen) {
OS::get_singleton()->set_window_fullscreen(true);
}
register_core_singletons(); register_core_singletons();

View file

@ -170,7 +170,7 @@ public:
virtual int get_screen_count() const; virtual int get_screen_count() const;
virtual int get_current_screen() const; virtual int get_current_screen() const;
virtual void set_current_screen(int p_screen); virtual void set_current_screen(int p_screen);
virtual Point2 get_screen_position(int p_screen=0); virtual Point2 get_screen_position(int p_screen=0) const;
virtual Point2 get_window_position() const; virtual Point2 get_window_position() const;
virtual void set_window_position(const Point2& p_position); virtual void set_window_position(const Point2& p_position);
virtual void set_window_size(const Size2 p_size); virtual void set_window_size(const Size2 p_size);

View file

@ -1279,7 +1279,7 @@ void OS_OSX::set_current_screen(int p_screen) {
current_screen = p_screen; current_screen = p_screen;
}; };
Point2 OS_OSX::get_screen_position(int p_screen) { Point2 OS_OSX::get_screen_position(int p_screen) const {
ERR_FAIL_INDEX_V(p_screen, screens.size(), Point2()); ERR_FAIL_INDEX_V(p_screen, screens.size(), Point2());
return screens[p_screen].pos; return screens[p_screen].pos;

View file

@ -441,6 +441,7 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi
net_wm_icon = XInternAtom(x11_display, "_NET_WM_ICON", False); net_wm_icon = XInternAtom(x11_display, "_NET_WM_ICON", False);
//printf("got map notify\n"); //printf("got map notify\n");
} }
@ -671,17 +672,24 @@ void OS_X11::set_current_screen(int p_screen) {
} }
Point2 OS_X11::get_screen_position(int p_screen) const { Point2 OS_X11::get_screen_position(int p_screen) const {
// Using Xinerama Extension // Using Xinerama Extension
int event_base, error_base; int event_base, error_base;
const Bool ext_okay = XineramaQueryExtension(x11_display, &event_base, &error_base); const Bool ext_okay = XineramaQueryExtension(x11_display, &event_base, &error_base);
if( !ext_okay ) return Point2i(0,0); if( !ext_okay ) {
return Point2i(0,0);
}
int count; int count;
XineramaScreenInfo* xsi = XineramaQueryScreens(x11_display, &count); XineramaScreenInfo* xsi = XineramaQueryScreens(x11_display, &count);
if( p_screen >= count ) return Point2i(0,0); if( p_screen >= count ) {
return Point2i(0,0);
}
Point2i position = Point2i(xsi[p_screen].x_org, xsi[p_screen].y_org); Point2i position = Point2i(xsi[p_screen].x_org, xsi[p_screen].y_org);
XFree(xsi); XFree(xsi);
return position; return position;
} }
@ -715,6 +723,7 @@ Point2 OS_X11::get_window_position() const {
void OS_X11::set_window_position(const Point2& p_position) { void OS_X11::set_window_position(const Point2& p_position) {
// Using EWMH -- Extended Window Manager Hints // Using EWMH -- Extended Window Manager Hints
// to get the size of the decoration // to get the size of the decoration
#if 0
Atom property = XInternAtom(x11_display,"_NET_FRAME_EXTENTS", True); Atom property = XInternAtom(x11_display,"_NET_FRAME_EXTENTS", True);
Atom type; Atom type;
int format; int format;
@ -757,6 +766,9 @@ void OS_X11::set_window_position(const Point2& p_position) {
top -= screen_position.y; top -= screen_position.y;
XMoveWindow(x11_display,x11_window,p_position.x - left,p_position.y - top); XMoveWindow(x11_display,x11_window,p_position.x - left,p_position.y - top);
#else
XMoveWindow(x11_display,x11_window,p_position.x,p_position.y);
#endif
} }
Size2 OS_X11::get_window_size() const { Size2 OS_X11::get_window_size() const {

View file

@ -28,7 +28,7 @@
/*************************************************************************/ /*************************************************************************/
#include "editor_run.h" #include "editor_run.h"
#include "globals.h" #include "globals.h"
#include "editor_settings.h"
EditorRun::Status EditorRun::get_status() const { EditorRun::Status EditorRun::get_status() const {
@ -61,6 +61,70 @@ Error EditorRun::run(const String& p_scene,const String p_custom_args,const List
} }
} }
int screen = EditorSettings::get_singleton()->get("game_window_placement/screen");
if (screen==0) {
screen=OS::get_singleton()->get_current_screen();
} else {
screen--;
}
Rect2 screen_rect;
screen_rect.pos=OS::get_singleton()->get_screen_position(screen);
screen_rect.size=OS::get_singleton()->get_screen_size(screen);
Size2 desired_size;
desired_size.x=Globals::get_singleton()->get("display/width");
desired_size.y=Globals::get_singleton()->get("display/height");
Size2 test_size;
test_size.x=Globals::get_singleton()->get("display/test_width");
test_size.y=Globals::get_singleton()->get("display/test_height");
if (test_size.x>0 && test_size.y>0) {
desired_size=test_size;
}
int window_placement=EditorSettings::get_singleton()->get("game_window_placement/rect");
switch(window_placement) {
case 0: { // default
args.push_back("-p");
args.push_back(itos(screen_rect.pos.x)+"x"+itos(screen_rect.pos.y));
} break;
case 1: { // centered
Vector2 pos=screen_rect.pos+((screen_rect.size-desired_size)/2).floor();
args.push_back("-p");
args.push_back(itos(pos.x)+"x"+itos(pos.y));
} break;
case 2: { // custom pos
Vector2 pos = EditorSettings::get_singleton()->get("game_window_placement/rect_custom_position");
pos+=screen_rect.pos;
args.push_back("-p");
args.push_back(itos(pos.x)+"x"+itos(pos.y));
} break;
case 3: { // force maximized
Vector2 pos=screen_rect.pos;
args.push_back("-p");
args.push_back(itos(pos.x)+"x"+itos(pos.y));
args.push_back("-mx");
} break;
case 4: { // force fullscreen
Vector2 pos=screen_rect.pos;
args.push_back("-p");
args.push_back(itos(pos.x)+"x"+itos(pos.y));
args.push_back("-f");
} break;
}
if (p_breakpoints.size()) { if (p_breakpoints.size()) {
args.push_back("-bp"); args.push_back("-bp");

View file

@ -496,6 +496,15 @@ void EditorSettings::_load_defaults() {
set("2d_editor/bone_selected_color",Color(0.9,0.45,0.45,0.9)); set("2d_editor/bone_selected_color",Color(0.9,0.45,0.45,0.9));
set("2d_editor/bone_ik_color",Color(0.9,0.9,0.45,0.9)); set("2d_editor/bone_ik_color",Color(0.9,0.9,0.45,0.9));
set("game_window_placement/rect",0);
hints["game_window_placement/rect"]=PropertyInfo(Variant::INT,"game_window_placement/rect",PROPERTY_HINT_ENUM,"Default,Centered,Custom Position,Force Maximized,Force Full Screen");
String screen_hints="Default (Same as Editor)";
for(int i=0;i<OS::get_singleton()->get_screen_count();i++) {
screen_hints+=",Monitor "+itos(i+1);
}
set("game_window_placement/rect_custom_position",Vector2());
set("game_window_placement/screen",0);
hints["game_window_placement/screen"]=PropertyInfo(Variant::INT,"game_window_placement/screen",PROPERTY_HINT_ENUM,screen_hints);
set("on_save/compress_binary_resources",true); set("on_save/compress_binary_resources",true);
set("on_save/save_modified_external_resources",true); set("on_save/save_modified_external_resources",true);