Skip to content

Commit

Permalink
new editor settings customization of where to run the game from the e…
Browse files Browse the repository at this point in the history
…ditor
  • Loading branch information
reduz committed Aug 31, 2015
1 parent 2d88665 commit cf57a65
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 10 deletions.
2 changes: 1 addition & 1 deletion core/os/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ friend class Main;
virtual int get_screen_count() const{ return 1; }
virtual int get_current_screen() const { return 0; }
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 Point2 get_window_position() const { return Vector2(); }
virtual void set_window_position(const Point2& p_position) {}
Expand Down
53 changes: 49 additions & 4 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,15 @@ static FileAccessNetworkClient *file_access_network_client=NULL;
static TranslationServer *translation_server = NULL;

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 audio_driver_idx=-1;
static String locale;

static bool init_maximized=false;

static int init_screen=-1;

static String unescape_cmdline(const String& p_str) {
Expand Down Expand Up @@ -136,8 +140,10 @@ void Main::print_help(const char* p_binary) {
}
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-mx\t\t Request Maximized\n");
OS::get_singleton()->print("\t-vd DRIVER\t : Video Driver (");
for (int i=0;i<OS::get_singleton()->get_video_driver_count();i++) {

Expand Down Expand Up @@ -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

if (I->next()) {
Expand Down Expand Up @@ -383,7 +419,8 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas

} 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

editor=true;
Expand Down Expand Up @@ -785,6 +822,14 @@ Error Main::setup2() {


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();

Expand Down
2 changes: 1 addition & 1 deletion platform/osx/os_osx.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class OS_OSX : public OS_Unix {
virtual int get_screen_count() const;
virtual int get_current_screen() const;
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 void set_window_position(const Point2& p_position);
virtual void set_window_size(const Size2 p_size);
Expand Down
2 changes: 1 addition & 1 deletion platform/osx/os_osx.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1279,7 +1279,7 @@ static void keyboardLayoutChanged(CFNotificationCenterRef center, void *observer
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());
return screens[p_screen].pos;
Expand Down
16 changes: 14 additions & 2 deletions platform/x11/os_x11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);



//printf("got map notify\n");

}
Expand Down Expand Up @@ -671,17 +672,24 @@ void OS_X11::set_current_screen(int p_screen) {
}

Point2 OS_X11::get_screen_position(int p_screen) const {

// Using Xinerama Extension
int 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;
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);

XFree(xsi);

return position;
}

Expand Down Expand Up @@ -715,6 +723,7 @@ Point2 OS_X11::get_window_position() const {
void OS_X11::set_window_position(const Point2& p_position) {
// Using EWMH -- Extended Window Manager Hints
// to get the size of the decoration
#if 0
Atom property = XInternAtom(x11_display,"_NET_FRAME_EXTENTS", True);
Atom type;
int format;
Expand Down Expand Up @@ -757,6 +766,9 @@ void OS_X11::set_window_position(const Point2& p_position) {
top -= screen_position.y;

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 {
Expand Down
66 changes: 65 additions & 1 deletion tools/editor/editor_run.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
/*************************************************************************/
#include "editor_run.h"
#include "globals.h"

#include "editor_settings.h"

EditorRun::Status EditorRun::get_status() const {

Expand Down Expand Up @@ -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()) {

args.push_back("-bp");
Expand Down
9 changes: 9 additions & 0 deletions tools/editor/editor_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_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/save_modified_external_resources",true);
Expand Down

0 comments on commit cf57a65

Please sign in to comment.