From 97d290e466bfdf1bb0fa68d828c3a3cb13f138de Mon Sep 17 00:00:00 2001 From: hurikhan Date: Sat, 10 Jan 2015 15:47:34 +0800 Subject: x11-fullscreen support through GDScript( OS.set_fullscreen(bool) ) --- core/bind/core_bind.cpp | 12 ++++++++++++ core/bind/core_bind.h | 4 ++++ core/os/os.h | 4 ++++ platform/x11/os_x11.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ platform/x11/os_x11.h | 3 +++ 5 files changed, 72 insertions(+) diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index 0c5d21b4f6..0d24486e90 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -176,6 +176,14 @@ bool _OS::is_video_mode_fullscreen(int p_screen) const { } +void _OS::set_fullscreen(bool p_fullscreen) { + OS::get_singleton()->set_fullscreen(p_fullscreen); +} + +bool _OS::is_fullscreen() const { + return OS::get_singleton()->is_fullscreen(); +} + void _OS::set_use_file_access_save_and_swap(bool p_enable) { FileAccess::set_backup_save(p_enable); @@ -632,6 +640,10 @@ void _OS::_bind_methods() { ObjectTypeDB::bind_method(_MD("is_video_mode_resizable","screen"),&_OS::is_video_mode_resizable,DEFVAL(0)); ObjectTypeDB::bind_method(_MD("get_fullscreen_mode_list","screen"),&_OS::get_fullscreen_mode_list,DEFVAL(0)); + //MSC + ObjectTypeDB::bind_method(_MD("set_fullscreen","fullscreen"),&_OS::set_fullscreen); + ObjectTypeDB::bind_method(_MD("is_fullscreen"),&_OS::is_fullscreen); + ObjectTypeDB::bind_method(_MD("set_iterations_per_second","iterations_per_second"),&_OS::set_iterations_per_second); ObjectTypeDB::bind_method(_MD("get_iterations_per_second"),&_OS::get_iterations_per_second); ObjectTypeDB::bind_method(_MD("set_target_fps","target_fps"),&_OS::set_target_fps); diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index 12a4ae86eb..97aff87bca 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -108,6 +108,10 @@ public: bool is_video_mode_resizable(int p_screen=0) const; Array get_fullscreen_mode_list(int p_screen=0) const; + //MSC + void set_fullscreen(bool p_fullscreen); + bool is_fullscreen() const; + Error native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track); bool native_video_is_playing(); void native_video_pause(); diff --git a/core/os/os.h b/core/os/os.h index d4deff2f5e..e8de28e86a 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -149,6 +149,10 @@ public: virtual void set_video_mode(const VideoMode& p_video_mode,int p_screen=0)=0; virtual VideoMode get_video_mode(int p_screen=0) const=0; virtual void get_fullscreen_mode_list(List *p_list,int p_screen=0) const=0; + + //MSC + virtual void set_fullscreen(bool fullscreen)=0; + virtual bool is_fullscreen() const=0; virtual void set_iterations_per_second(int p_ips); virtual int get_iterations_per_second() const; diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index aa9e4c63c9..bf0bef15db 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -521,6 +521,55 @@ void OS_X11::get_fullscreen_mode_list(List *p_list,int p_screen) cons } +void OS_X11::set_fullscreen(bool p_fullscreen) { + + long wm_action; + + if(p_fullscreen) { + current_videomode.fullscreen = True; + wm_action = 1; + } else { + current_videomode.fullscreen = False; + wm_action = 0; + } + + /* + // MSC: Disabled until I can test it with lxde + // + // needed for lxde/openbox, possibly others + Hints hints; + Atom property; + hints.flags = 2; + hints.decorations = 0; + property = XInternAtom(x11_display, "_MOTIF_WM_HINTS", True); + XChangeProperty(x11_display, x11_window, property, property, 32, PropModeReplace, (unsigned char *)&hints, 5); + XMapRaised(x11_display, x11_window); + XWindowAttributes xwa; + XGetWindowAttributes(x11_display, DefaultRootWindow(x11_display), &xwa); + XMoveResizeWindow(x11_display, x11_window, 0, 0, xwa.width, xwa.height); + */ + + // code for netwm-compliants + XEvent xev; + Atom wm_state = XInternAtom(x11_display, "_NET_WM_STATE", False); + Atom wm_fullscreen = XInternAtom(x11_display, "_NET_WM_STATE_FULLSCREEN", False); + + memset(&xev, 0, sizeof(xev)); + xev.type = ClientMessage; + xev.xclient.window = x11_window; + xev.xclient.message_type = wm_state; + xev.xclient.format = 32; + xev.xclient.data.l[0] = wm_action; + xev.xclient.data.l[1] = wm_fullscreen; + xev.xclient.data.l[2] = 0; + + XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureNotifyMask, &xev); + + visual_server->init(); +} + +bool OS_X11::is_fullscreen() const { +} InputModifierState OS_X11::get_key_modifier_state(unsigned int p_x11_state) { diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h index dd2476ec1b..e92bd6e081 100644 --- a/platform/x11/os_x11.h +++ b/platform/x11/os_x11.h @@ -213,6 +213,9 @@ public: virtual VideoMode get_video_mode(int p_screen=0) const; virtual void get_fullscreen_mode_list(List *p_list,int p_screen=0) const; + virtual void set_fullscreen(bool p_fullscreen); + virtual bool is_fullscreen() const; + virtual void move_window_to_foreground(); void run(); -- cgit v1.2.3 From cd90215ceca03b456aad761da935c92058b0da6a Mon Sep 17 00:00:00 2001 From: hurikhan Date: Sat, 10 Jan 2015 16:01:01 +0800 Subject: Make GDScript-Function ( bool OS.is_fullscreen() ) work --- platform/x11/os_x11.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index bf0bef15db..79051b2ac5 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -569,6 +569,7 @@ void OS_X11::set_fullscreen(bool p_fullscreen) { } bool OS_X11::is_fullscreen() const { + return current_videomode.fullscreen; } InputModifierState OS_X11::get_key_modifier_state(unsigned int p_x11_state) { -- cgit v1.2.3 From 0d2ec19082e9ebff07ab1ab8e365e2db9ee3268b Mon Sep 17 00:00:00 2001 From: hurikhan Date: Sat, 10 Jan 2015 18:38:30 +0800 Subject: API change to set_fullscreen(enabled,screen) --- core/bind/core_bind.cpp | 6 +++--- core/bind/core_bind.h | 2 +- core/os/os.h | 2 +- platform/x11/os_x11.cpp | 4 ++-- platform/x11/os_x11.h | 6 +++--- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index 0d24486e90..62d93745a0 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -176,8 +176,8 @@ bool _OS::is_video_mode_fullscreen(int p_screen) const { } -void _OS::set_fullscreen(bool p_fullscreen) { - OS::get_singleton()->set_fullscreen(p_fullscreen); +void _OS::set_fullscreen(bool p_enabled,int p_screen) { + OS::get_singleton()->set_fullscreen(p_enabled, p_screen); } bool _OS::is_fullscreen() const { @@ -641,7 +641,7 @@ void _OS::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_fullscreen_mode_list","screen"),&_OS::get_fullscreen_mode_list,DEFVAL(0)); //MSC - ObjectTypeDB::bind_method(_MD("set_fullscreen","fullscreen"),&_OS::set_fullscreen); + ObjectTypeDB::bind_method(_MD("set_fullscreen","enabled","screen"),&_OS::set_fullscreen,DEFVAL(0)); ObjectTypeDB::bind_method(_MD("is_fullscreen"),&_OS::is_fullscreen); ObjectTypeDB::bind_method(_MD("set_iterations_per_second","iterations_per_second"),&_OS::set_iterations_per_second); diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index 97aff87bca..fedd03c3a9 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -109,7 +109,7 @@ public: Array get_fullscreen_mode_list(int p_screen=0) const; //MSC - void set_fullscreen(bool p_fullscreen); + void set_fullscreen(bool p_enabled, int p_screen=0); bool is_fullscreen() const; Error native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track); diff --git a/core/os/os.h b/core/os/os.h index e8de28e86a..b86b122623 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -151,7 +151,7 @@ public: virtual void get_fullscreen_mode_list(List *p_list,int p_screen=0) const=0; //MSC - virtual void set_fullscreen(bool fullscreen)=0; + virtual void set_fullscreen(bool p_enabled,int p_screen=0)=0; virtual bool is_fullscreen() const=0; virtual void set_iterations_per_second(int p_ips); diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index 79051b2ac5..6dd2d7426f 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -521,11 +521,11 @@ void OS_X11::get_fullscreen_mode_list(List *p_list,int p_screen) cons } -void OS_X11::set_fullscreen(bool p_fullscreen) { +void OS_X11::set_fullscreen(bool p_enabled,int p_screen) { long wm_action; - if(p_fullscreen) { + if(p_enabled) { current_videomode.fullscreen = True; wm_action = 1; } else { diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h index e92bd6e081..f382e21edc 100644 --- a/platform/x11/os_x11.h +++ b/platform/x11/os_x11.h @@ -166,8 +166,8 @@ protected: virtual const char * get_video_driver_name(int p_driver) const; virtual VideoMode get_default_video_mode() const; - virtual int get_audio_driver_count() const; - virtual const char * get_audio_driver_name(int p_driver) const; + virtual int get_audio_driver_count() const; + virtual const char * get_audio_driver_name(int p_driver) const; virtual void initialize(const VideoMode& p_desired,int p_video_driver,int p_audio_driver); virtual void finalize(); @@ -213,7 +213,7 @@ public: virtual VideoMode get_video_mode(int p_screen=0) const; virtual void get_fullscreen_mode_list(List *p_list,int p_screen=0) const; - virtual void set_fullscreen(bool p_fullscreen); + virtual void set_fullscreen(bool p_enabled,int p_screen=0); virtual bool is_fullscreen() const; virtual void move_window_to_foreground(); -- cgit v1.2.3 From 5d9de48d8d35961835135a7310840cdc9cbacb63 Mon Sep 17 00:00:00 2001 From: hurikhan Date: Sat, 10 Jan 2015 21:50:31 +0800 Subject: Make fullscreen-switching is working with LXDE/Openbox --- platform/x11/os_x11.cpp | 90 +++++++++++++++++++++++-------------------------- platform/x11/os_x11.h | 4 +++ 2 files changed, 46 insertions(+), 48 deletions(-) diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index 6dd2d7426f..707868ccb0 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -182,33 +182,8 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi // borderless fullscreen window mode if (current_videomode.fullscreen) { - // needed for lxde/openbox, possibly others - Hints hints; - Atom property; - hints.flags = 2; - hints.decorations = 0; - property = XInternAtom(x11_display, "_MOTIF_WM_HINTS", True); - XChangeProperty(x11_display, x11_window, property, property, 32, PropModeReplace, (unsigned char *)&hints, 5); - XMapRaised(x11_display, x11_window); - XWindowAttributes xwa; - XGetWindowAttributes(x11_display, DefaultRootWindow(x11_display), &xwa); - XMoveResizeWindow(x11_display, x11_window, 0, 0, xwa.width, xwa.height); - - // code for netwm-compliants - XEvent xev; - Atom wm_state = XInternAtom(x11_display, "_NET_WM_STATE", False); - Atom fullscreen = XInternAtom(x11_display, "_NET_WM_STATE_FULLSCREEN", False); - - memset(&xev, 0, sizeof(xev)); - xev.type = ClientMessage; - xev.xclient.window = x11_window; - xev.xclient.message_type = wm_state; - xev.xclient.format = 32; - xev.xclient.data.l[0] = 1; - xev.xclient.data.l[1] = fullscreen; - xev.xclient.data.l[2] = 0; - - XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureNotifyMask, &xev); + set_wm_border(false); + set_wm_fullscreen(true); } // disable resizeable window @@ -521,34 +496,19 @@ void OS_X11::get_fullscreen_mode_list(List *p_list,int p_screen) cons } -void OS_X11::set_fullscreen(bool p_enabled,int p_screen) { - - long wm_action; - - if(p_enabled) { - current_videomode.fullscreen = True; - wm_action = 1; - } else { - current_videomode.fullscreen = False; - wm_action = 0; - } - - /* - // MSC: Disabled until I can test it with lxde - // +void OS_X11::set_wm_border(bool p_enabled) { // needed for lxde/openbox, possibly others Hints hints; Atom property; hints.flags = 2; - hints.decorations = 0; + hints.decorations = p_enabled ? 1L : 0L;; property = XInternAtom(x11_display, "_MOTIF_WM_HINTS", True); XChangeProperty(x11_display, x11_window, property, property, 32, PropModeReplace, (unsigned char *)&hints, 5); XMapRaised(x11_display, x11_window); - XWindowAttributes xwa; - XGetWindowAttributes(x11_display, DefaultRootWindow(x11_display), &xwa); - XMoveResizeWindow(x11_display, x11_window, 0, 0, xwa.width, xwa.height); - */ + XMoveResizeWindow(x11_display, x11_window, 0, 0, current_videomode.width, current_videomode.height); +} +void OS_X11::set_wm_fullscreen(bool p_enabled) { // code for netwm-compliants XEvent xev; Atom wm_state = XInternAtom(x11_display, "_NET_WM_STATE", False); @@ -559,11 +519,45 @@ void OS_X11::set_fullscreen(bool p_enabled,int p_screen) { xev.xclient.window = x11_window; xev.xclient.message_type = wm_state; xev.xclient.format = 32; - xev.xclient.data.l[0] = wm_action; + xev.xclient.data.l[0] = p_enabled ? 1L : 0L; xev.xclient.data.l[1] = wm_fullscreen; xev.xclient.data.l[2] = 0; XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureNotifyMask, &xev); +} + +void OS_X11::set_fullscreen(bool p_enabled,int p_screen) { + + long wm_action; + long wm_decoration; + + if(p_enabled) { + wm_action = 1L; + wm_decoration = 0L; // Removes all decorations + + pre_videomode = current_videomode; + + // Get Desktop resolutuion + XWindowAttributes xwa; + XGetWindowAttributes(x11_display, DefaultRootWindow(x11_display), &xwa); + + current_videomode.fullscreen = True; + current_videomode.width = xwa.width; + current_videomode.height = xwa.height; + + set_wm_border(false); + set_wm_fullscreen(true); + } else { + wm_action = 0L; + wm_decoration = 1L; // MWM_DECORE_ALL (1L << 0) + + current_videomode.fullscreen = False; + current_videomode.width = pre_videomode.width; + current_videomode.height = pre_videomode.height; + + set_wm_fullscreen(false); + set_wm_border(true); + } visual_server->init(); } diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h index f382e21edc..11842ace83 100644 --- a/platform/x11/os_x11.h +++ b/platform/x11/os_x11.h @@ -73,6 +73,7 @@ class OS_X11 : public OS_Unix { Rasterizer *rasterizer; VisualServer *visual_server; VideoMode current_videomode; + VideoMode pre_videomode; List args; Window x11_window; MainLoop *main_loop; @@ -159,6 +160,8 @@ class OS_X11 : public OS_Unix { int joystick_count; Joystick joysticks[JOYSTICKS_MAX]; + void set_wm_border(bool p_enabled); + void set_wm_fullscreen(bool p_enabled); protected: @@ -178,6 +181,7 @@ protected: void process_joysticks(); void close_joystick(int p_id = -1); + public: virtual String get_name(); -- cgit v1.2.3 From a8e3c5c0b7fb202bcceb06b9373b5b6a4ff8f9b8 Mon Sep 17 00:00:00 2001 From: hurikhan Date: Sun, 11 Jan 2015 01:07:23 +0800 Subject: First attempt of restoring the window at the old position --- core/os/os.h | 5 +++-- main/main.cpp | 7 ++++++- platform/x11/os_x11.cpp | 40 +++++++++++++++++++++++++++++----------- 3 files changed, 38 insertions(+), 14 deletions(-) diff --git a/core/os/os.h b/core/os/os.h index b86b122623..9de2e3556b 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -69,11 +69,12 @@ public: }; struct VideoMode { - int width,height; + int x,y,width,height; bool fullscreen; bool resizable; float get_aspect() const { return (float)width/(float)height; } - VideoMode(int p_width=640,int p_height=480,bool p_fullscreen=false, bool p_resizable = true) { width=p_width; height=p_height; fullscreen=p_fullscreen; resizable = p_resizable; } + VideoMode(int p_x=0, int p_y=0,int p_width=640,int p_height=480,bool p_fullscreen=false, bool p_resizable = true) + { x=p_x; y=p_y; width=p_width; height=p_height; fullscreen=p_fullscreen; resizable = p_resizable; } }; protected: friend class Main; diff --git a/main/main.cpp b/main/main.cpp index f0e376a045..b6638a3ad0 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -609,6 +609,10 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas if (video_driver=="") // specified in engine.cfg video_driver=_GLOBAL_DEF("display/driver",Variant((const char*)OS::get_singleton()->get_video_driver_name(0))); + if (!force_res && use_custom_res && globals->has("display/x")) + video_mode.width=globals->get("display/y"); + if (!force_res && use_custom_res && globals->has("display/width")) + video_mode.width=globals->get("display/width"); if (!force_res && use_custom_res && globals->has("display/width")) video_mode.width=globals->get("display/width"); if (!force_res &&use_custom_res && globals->has("display/height")) @@ -627,7 +631,8 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas } } - + GLOBAL_DEF("display/x",video_mode.x); + GLOBAL_DEF("display/y",video_mode.y); GLOBAL_DEF("display/width",video_mode.width); GLOBAL_DEF("display/height",video_mode.height); GLOBAL_DEF("display/fullscreen",video_mode.fullscreen); diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index 707868ccb0..9e02f54dd4 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -71,7 +71,7 @@ const char * OS_X11::get_video_driver_name(int p_driver) const { } OS::VideoMode OS_X11::get_default_video_mode() const { - return OS::VideoMode(800,600,false); + return OS::VideoMode(0,0,800,600,false); } int OS_X11::get_audio_driver_count() const { @@ -163,6 +163,18 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi // maybe contextgl wants to be in charge of creating the window //print_line("def videomode "+itos(current_videomode.width)+","+itos(current_videomode.height)); #if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED) + if( current_videomode.x > current_videomode.width || + current_videomode.y > current_videomode.height || + current_videomode.width==0 || + current_videomode.height==0) { + + current_videomode.x = 0; + current_videomode.y = 0; + current_videomode.width = 640; + current_videomode.height = 480; + } + + context_gl = memnew( ContextGL_X11( x11_display, x11_window,current_videomode, false ) ); context_gl->initialize(); @@ -505,7 +517,7 @@ void OS_X11::set_wm_border(bool p_enabled) { property = XInternAtom(x11_display, "_MOTIF_WM_HINTS", True); XChangeProperty(x11_display, x11_window, property, property, 32, PropModeReplace, (unsigned char *)&hints, 5); XMapRaised(x11_display, x11_window); - XMoveResizeWindow(x11_display, x11_window, 0, 0, current_videomode.width, current_videomode.height); + XMoveResizeWindow(x11_display, x11_window, current_videomode.x, current_videomode.y, current_videomode.width, current_videomode.height); } void OS_X11::set_wm_fullscreen(bool p_enabled) { @@ -528,17 +540,24 @@ void OS_X11::set_wm_fullscreen(bool p_enabled) { void OS_X11::set_fullscreen(bool p_enabled,int p_screen) { - long wm_action; - long wm_decoration; - if(p_enabled) { - wm_action = 1L; - wm_decoration = 0L; // Removes all decorations + XWindowAttributes xwa; + XGetWindowAttributes(x11_display, x11_window, &xwa); + + print_line(itos(xwa.x)); + print_line(itos(xwa.y)); + print_line(itos(xwa.width)); + print_line(itos(xwa.height)); + + current_videomode.x = xwa.x; + current_videomode.y = xwa.y; + current_videomode.width = xwa.width; + current_videomode.height = xwa.height; + pre_videomode = current_videomode; // Get Desktop resolutuion - XWindowAttributes xwa; XGetWindowAttributes(x11_display, DefaultRootWindow(x11_display), &xwa); current_videomode.fullscreen = True; @@ -548,10 +567,9 @@ void OS_X11::set_fullscreen(bool p_enabled,int p_screen) { set_wm_border(false); set_wm_fullscreen(true); } else { - wm_action = 0L; - wm_decoration = 1L; // MWM_DECORE_ALL (1L << 0) - current_videomode.fullscreen = False; + current_videomode.x = pre_videomode.x; + current_videomode.y = pre_videomode.y; current_videomode.width = pre_videomode.width; current_videomode.height = pre_videomode.height; -- cgit v1.2.3 From ac558c15eaeb45b3e7ae2604e26ca1dffb60b779 Mon Sep 17 00:00:00 2001 From: hurikhan Date: Sun, 11 Jan 2015 15:47:27 +0800 Subject: get_window_position() + set_window_position() added --- core/bind/core_bind.cpp | 10 ++++++ core/bind/core_bind.h | 2 ++ core/os/os.h | 7 ++-- main/main.cpp | 6 ---- platform/x11/os_x11.cpp | 86 ++++++++++++++++++++++++++++++++----------------- platform/x11/os_x11.h | 2 ++ 6 files changed, 74 insertions(+), 39 deletions(-) diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index 62d93745a0..3109b8bc84 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -176,6 +176,14 @@ bool _OS::is_video_mode_fullscreen(int p_screen) const { } +Point2 _OS::get_window_position() const { + return OS::get_singleton()->get_window_position(); +} + +void _OS::set_window_position(const Point2& p_position) { + OS::get_singleton()->set_window_position(p_position); +} + void _OS::set_fullscreen(bool p_enabled,int p_screen) { OS::get_singleton()->set_fullscreen(p_enabled, p_screen); } @@ -641,6 +649,8 @@ void _OS::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_fullscreen_mode_list","screen"),&_OS::get_fullscreen_mode_list,DEFVAL(0)); //MSC + ObjectTypeDB::bind_method(_MD("get_window_position"),&_OS::get_window_position); + ObjectTypeDB::bind_method(_MD("set_window_position"),&_OS::set_window_position); ObjectTypeDB::bind_method(_MD("set_fullscreen","enabled","screen"),&_OS::set_fullscreen,DEFVAL(0)); ObjectTypeDB::bind_method(_MD("is_fullscreen"),&_OS::is_fullscreen); diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index fedd03c3a9..92056aa0d6 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -109,6 +109,8 @@ public: Array get_fullscreen_mode_list(int p_screen=0) const; //MSC + virtual Point2 get_window_position() const; + virtual void set_window_position(const Point2& p_position); void set_fullscreen(bool p_enabled, int p_screen=0); bool is_fullscreen() const; diff --git a/core/os/os.h b/core/os/os.h index 9de2e3556b..9089e7de76 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -69,12 +69,11 @@ public: }; struct VideoMode { - int x,y,width,height; + int width,height; bool fullscreen; bool resizable; float get_aspect() const { return (float)width/(float)height; } - VideoMode(int p_x=0, int p_y=0,int p_width=640,int p_height=480,bool p_fullscreen=false, bool p_resizable = true) - { x=p_x; y=p_y; width=p_width; height=p_height; fullscreen=p_fullscreen; resizable = p_resizable; } + VideoMode(int p_width=640,int p_height=480,bool p_fullscreen=false, bool p_resizable = true) {width=p_width; height=p_height; fullscreen=p_fullscreen; resizable = p_resizable; } }; protected: friend class Main; @@ -152,6 +151,8 @@ public: virtual void get_fullscreen_mode_list(List *p_list,int p_screen=0) const=0; //MSC + virtual Point2 get_window_position() const=0; + virtual void set_window_position(const Point2& p_position)=0; virtual void set_fullscreen(bool p_enabled,int p_screen=0)=0; virtual bool is_fullscreen() const=0; diff --git a/main/main.cpp b/main/main.cpp index b6638a3ad0..27d7d97e85 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -609,10 +609,6 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas if (video_driver=="") // specified in engine.cfg video_driver=_GLOBAL_DEF("display/driver",Variant((const char*)OS::get_singleton()->get_video_driver_name(0))); - if (!force_res && use_custom_res && globals->has("display/x")) - video_mode.width=globals->get("display/y"); - if (!force_res && use_custom_res && globals->has("display/width")) - video_mode.width=globals->get("display/width"); if (!force_res && use_custom_res && globals->has("display/width")) video_mode.width=globals->get("display/width"); if (!force_res &&use_custom_res && globals->has("display/height")) @@ -631,8 +627,6 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas } } - GLOBAL_DEF("display/x",video_mode.x); - GLOBAL_DEF("display/y",video_mode.y); GLOBAL_DEF("display/width",video_mode.width); GLOBAL_DEF("display/height",video_mode.height); GLOBAL_DEF("display/fullscreen",video_mode.fullscreen); diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index 5a05455918..502d510f5b 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -70,7 +70,7 @@ const char * OS_X11::get_video_driver_name(int p_driver) const { } OS::VideoMode OS_X11::get_default_video_mode() const { - return OS::VideoMode(0,0,800,600,false); + return OS::VideoMode(800,600,false); } int OS_X11::get_audio_driver_count() const { @@ -162,17 +162,6 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi // maybe contextgl wants to be in charge of creating the window //print_line("def videomode "+itos(current_videomode.width)+","+itos(current_videomode.height)); #if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED) - if( current_videomode.x > current_videomode.width || - current_videomode.y > current_videomode.height || - current_videomode.width==0 || - current_videomode.height==0) { - - current_videomode.x = 0; - current_videomode.y = 0; - current_videomode.width = 640; - current_videomode.height = 480; - } - context_gl = memnew( ContextGL_X11( x11_display, x11_window,current_videomode, false ) ); context_gl->initialize(); @@ -516,7 +505,7 @@ void OS_X11::set_wm_border(bool p_enabled) { property = XInternAtom(x11_display, "_MOTIF_WM_HINTS", True); XChangeProperty(x11_display, x11_window, property, property, 32, PropModeReplace, (unsigned char *)&hints, 5); XMapRaised(x11_display, x11_window); - XMoveResizeWindow(x11_display, x11_window, current_videomode.x, current_videomode.y, current_videomode.width, current_videomode.height); + XMoveResizeWindow(x11_display, x11_window, 0, 0, current_videomode.width, current_videomode.height); } void OS_X11::set_wm_fullscreen(bool p_enabled) { @@ -537,26 +526,65 @@ void OS_X11::set_wm_fullscreen(bool p_enabled) { XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureNotifyMask, &xev); } -void OS_X11::set_fullscreen(bool p_enabled,int p_screen) { +Point2 OS_X11::get_window_position() const { + int x,y; + XWindowAttributes xwa; + Window child; + XTranslateCoordinates( x11_display, x11_window, DefaultRootWindow(x11_display), 0, 0, &x, &y, &child); + XGetWindowAttributes(x11_display, x11_window, &xwa); - if(p_enabled) { - XWindowAttributes xwa; - XGetWindowAttributes(x11_display, x11_window, &xwa); + return Point2i(x,y); +} - print_line(itos(xwa.x)); - print_line(itos(xwa.y)); - print_line(itos(xwa.width)); - print_line(itos(xwa.height)); - - current_videomode.x = xwa.x; - current_videomode.y = xwa.y; - current_videomode.width = xwa.width; - current_videomode.height = xwa.height; - +void OS_X11::set_window_position(const Point2& p_position) { + // _NET_FRAME_EXTENTS + Atom property = XInternAtom(x11_display,"_NET_FRAME_EXTENTS", True); + Atom type; + int format; + unsigned long len; + unsigned long remaining; + unsigned char *data = NULL; + //long *extends; + int result; + + result = XGetWindowProperty( + x11_display, + x11_window, + property, + 0, + 32, + False, + AnyPropertyType, + &type, + &format, + &len, + &remaining, + &data + ); + + long left = 0L; + long top = 0L; + + if( result == Success ) { + long *extends = (long *) data; + + left = extends[0]; + top = extends[2]; + + XFree(data); + data = NULL; + } + + XMoveWindow(x11_display,x11_window,p_position.x - left,p_position.y - top); +} + +void OS_X11::set_fullscreen(bool p_enabled,int p_screen) { + + if(p_enabled) { pre_videomode = current_videomode; - // Get Desktop resolutuion + XWindowAttributes xwa; XGetWindowAttributes(x11_display, DefaultRootWindow(x11_display), &xwa); current_videomode.fullscreen = True; @@ -567,8 +595,6 @@ void OS_X11::set_fullscreen(bool p_enabled,int p_screen) { set_wm_fullscreen(true); } else { current_videomode.fullscreen = False; - current_videomode.x = pre_videomode.x; - current_videomode.y = pre_videomode.y; current_videomode.width = pre_videomode.width; current_videomode.height = pre_videomode.height; diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h index 11842ace83..ad7364f999 100644 --- a/platform/x11/os_x11.h +++ b/platform/x11/os_x11.h @@ -217,6 +217,8 @@ public: virtual VideoMode get_video_mode(int p_screen=0) const; virtual void get_fullscreen_mode_list(List *p_list,int p_screen=0) const; + virtual Point2 get_window_position() const; + virtual void set_window_position(const Point2& p_position); virtual void set_fullscreen(bool p_enabled,int p_screen=0); virtual bool is_fullscreen() const; -- cgit v1.2.3 From 466e251abecf3686f0caac40ab886155e43cc0a6 Mon Sep 17 00:00:00 2001 From: hurikhan Date: Sun, 11 Jan 2015 17:36:56 +0800 Subject: get_window_size() + set_window_size() added --- core/bind/core_bind.cpp | 11 ++++++++++- core/bind/core_bind.h | 3 ++- core/os/os.h | 3 ++- platform/x11/os_x11.cpp | 18 +++++++++++++++++- platform/x11/os_x11.h | 2 ++ 5 files changed, 33 insertions(+), 4 deletions(-) diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index 3109b8bc84..2b4e2e1239 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -184,6 +184,14 @@ void _OS::set_window_position(const Point2& p_position) { OS::get_singleton()->set_window_position(p_position); } +Size2 _OS::get_window_size() const { + return OS::get_singleton()->get_window_size(); +} + +void _OS::set_window_size(const Size2& p_size) { + OS::get_singleton()->set_window_size(p_size); +} + void _OS::set_fullscreen(bool p_enabled,int p_screen) { OS::get_singleton()->set_fullscreen(p_enabled, p_screen); } @@ -648,9 +656,10 @@ void _OS::_bind_methods() { ObjectTypeDB::bind_method(_MD("is_video_mode_resizable","screen"),&_OS::is_video_mode_resizable,DEFVAL(0)); ObjectTypeDB::bind_method(_MD("get_fullscreen_mode_list","screen"),&_OS::get_fullscreen_mode_list,DEFVAL(0)); - //MSC ObjectTypeDB::bind_method(_MD("get_window_position"),&_OS::get_window_position); ObjectTypeDB::bind_method(_MD("set_window_position"),&_OS::set_window_position); + ObjectTypeDB::bind_method(_MD("get_window_size"),&_OS::get_window_size); + ObjectTypeDB::bind_method(_MD("set_window_size"),&_OS::set_window_size); ObjectTypeDB::bind_method(_MD("set_fullscreen","enabled","screen"),&_OS::set_fullscreen,DEFVAL(0)); ObjectTypeDB::bind_method(_MD("is_fullscreen"),&_OS::is_fullscreen); diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index 92056aa0d6..e60bb5e66a 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -108,9 +108,10 @@ public: bool is_video_mode_resizable(int p_screen=0) const; Array get_fullscreen_mode_list(int p_screen=0) const; - //MSC virtual Point2 get_window_position() const; virtual void set_window_position(const Point2& p_position); + virtual Size2 get_window_size() const; + virtual void set_window_size(const Size2& p_size); void set_fullscreen(bool p_enabled, int p_screen=0); bool is_fullscreen() const; diff --git a/core/os/os.h b/core/os/os.h index 9089e7de76..7e9fdcc579 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -150,9 +150,10 @@ public: virtual VideoMode get_video_mode(int p_screen=0) const=0; virtual void get_fullscreen_mode_list(List *p_list,int p_screen=0) const=0; - //MSC virtual Point2 get_window_position() const=0; virtual void set_window_position(const Point2& p_position)=0; + virtual Size2 get_window_size() const=0; + virtual void set_window_size(const Size2 p_size)=0; virtual void set_fullscreen(bool p_enabled,int p_screen=0)=0; virtual bool is_fullscreen() const=0; diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index 502d510f5b..f21ea4c9a2 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -537,8 +537,11 @@ Point2 OS_X11::get_window_position() const { } void OS_X11::set_window_position(const Point2& p_position) { - // _NET_FRAME_EXTENTS + if( current_videomode.fullscreen ) + return; + + // _NET_FRAME_EXTENTS Atom property = XInternAtom(x11_display,"_NET_FRAME_EXTENTS", True); Atom type; int format; @@ -579,6 +582,19 @@ void OS_X11::set_window_position(const Point2& p_position) { XMoveWindow(x11_display,x11_window,p_position.x - left,p_position.y - top); } +Size2 OS_X11::get_window_size() const { + XWindowAttributes xwa; + XGetWindowAttributes(x11_display, x11_window, &xwa); + return Size2i(xwa.width, xwa.height); +} + +void OS_X11::set_window_size(const Size2 p_size) { + if( current_videomode.fullscreen ) + return; + + XResizeWindow(x11_display, x11_window, p_size.x, p_size.y); +} + void OS_X11::set_fullscreen(bool p_enabled,int p_screen) { if(p_enabled) { diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h index ad7364f999..1cedea4223 100644 --- a/platform/x11/os_x11.h +++ b/platform/x11/os_x11.h @@ -219,6 +219,8 @@ public: virtual Point2 get_window_position() const; virtual void set_window_position(const Point2& p_position); + virtual Size2 get_window_size() const; + virtual void set_window_size(const Size2 p_size); virtual void set_fullscreen(bool p_enabled,int p_screen=0); virtual bool is_fullscreen() const; -- cgit v1.2.3 From 3c8b047b111cf20b3823851e298ce42bdf941871 Mon Sep 17 00:00:00 2001 From: hurikhan Date: Sun, 11 Jan 2015 18:52:42 +0800 Subject: get_screen_count() added --- core/bind/core_bind.cpp | 5 +++++ core/bind/core_bind.h | 1 + core/os/os.h | 1 + platform/x11/os_x11.cpp | 7 +++++++ platform/x11/os_x11.h | 1 + 5 files changed, 15 insertions(+) diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index 2b4e2e1239..3f86efc879 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -176,6 +176,10 @@ bool _OS::is_video_mode_fullscreen(int p_screen) const { } +int _OS::get_screen_count() const { + return OS::get_singleton()->get_screen_count(); +} + Point2 _OS::get_window_position() const { return OS::get_singleton()->get_window_position(); } @@ -656,6 +660,7 @@ void _OS::_bind_methods() { ObjectTypeDB::bind_method(_MD("is_video_mode_resizable","screen"),&_OS::is_video_mode_resizable,DEFVAL(0)); ObjectTypeDB::bind_method(_MD("get_fullscreen_mode_list","screen"),&_OS::get_fullscreen_mode_list,DEFVAL(0)); + ObjectTypeDB::bind_method(_MD("get_screen_count"),&_OS::get_screen_count); ObjectTypeDB::bind_method(_MD("get_window_position"),&_OS::get_window_position); ObjectTypeDB::bind_method(_MD("set_window_position"),&_OS::set_window_position); ObjectTypeDB::bind_method(_MD("get_window_size"),&_OS::get_window_size); diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index e60bb5e66a..cb9a5da479 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -108,6 +108,7 @@ public: bool is_video_mode_resizable(int p_screen=0) const; Array get_fullscreen_mode_list(int p_screen=0) const; + virtual int get_screen_count() const; virtual Point2 get_window_position() const; virtual void set_window_position(const Point2& p_position); virtual Size2 get_window_size() const; diff --git a/core/os/os.h b/core/os/os.h index 7e9fdcc579..68769e7ad4 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -150,6 +150,7 @@ public: virtual VideoMode get_video_mode(int p_screen=0) const=0; virtual void get_fullscreen_mode_list(List *p_list,int p_screen=0) const=0; + virtual int get_screen_count() const=0; virtual Point2 get_window_position() const=0; virtual void set_window_position(const Point2& p_position)=0; virtual Size2 get_window_size() const=0; diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index f21ea4c9a2..c37358139c 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -526,6 +526,10 @@ void OS_X11::set_wm_fullscreen(bool p_enabled) { XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureNotifyMask, &xev); } +int OS_X11::get_screen_count() const { + return XScreenCount(x11_display); +} + Point2 OS_X11::get_window_position() const { int x,y; XWindowAttributes xwa; @@ -597,6 +601,9 @@ void OS_X11::set_window_size(const Size2 p_size) { void OS_X11::set_fullscreen(bool p_enabled,int p_screen) { + if(p_enabled && current_videomode.fullscreen) + return; + if(p_enabled) { pre_videomode = current_videomode; diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h index 1cedea4223..f55b7dc0e3 100644 --- a/platform/x11/os_x11.h +++ b/platform/x11/os_x11.h @@ -217,6 +217,7 @@ public: virtual VideoMode get_video_mode(int p_screen=0) const; virtual void get_fullscreen_mode_list(List *p_list,int p_screen=0) const; + virtual int get_screen_count() const; virtual Point2 get_window_position() const; virtual void set_window_position(const Point2& p_position); virtual Size2 get_window_size() const; -- cgit v1.2.3 From f9d0de0d2a82456f3553499fcbc1c487b59fed1c Mon Sep 17 00:00:00 2001 From: hurikhan Date: Sun, 11 Jan 2015 19:35:53 +0800 Subject: get_screen_size() added --- core/bind/core_bind.cpp | 5 +++++ core/bind/core_bind.h | 1 + core/os/os.h | 1 + platform/x11/os_x11.cpp | 8 ++++++++ platform/x11/os_x11.h | 1 + 5 files changed, 16 insertions(+) diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index 3f86efc879..47bfba1cbb 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -180,6 +180,10 @@ int _OS::get_screen_count() const { return OS::get_singleton()->get_screen_count(); } +Size2 _OS::get_screen_size(int p_screen) const { + return OS::get_singleton()->get_screen_size(p_screen); +} + Point2 _OS::get_window_position() const { return OS::get_singleton()->get_window_position(); } @@ -661,6 +665,7 @@ void _OS::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_fullscreen_mode_list","screen"),&_OS::get_fullscreen_mode_list,DEFVAL(0)); ObjectTypeDB::bind_method(_MD("get_screen_count"),&_OS::get_screen_count); + ObjectTypeDB::bind_method(_MD("get_screen_size"),&_OS::get_screen_size,DEFVAL(0)); ObjectTypeDB::bind_method(_MD("get_window_position"),&_OS::get_window_position); ObjectTypeDB::bind_method(_MD("set_window_position"),&_OS::set_window_position); ObjectTypeDB::bind_method(_MD("get_window_size"),&_OS::get_window_size); diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index cb9a5da479..2a87f85ec7 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -109,6 +109,7 @@ public: Array get_fullscreen_mode_list(int p_screen=0) const; virtual int get_screen_count() const; + virtual Size2 get_screen_size(int p_screen=0) const; virtual Point2 get_window_position() const; virtual void set_window_position(const Point2& p_position); virtual Size2 get_window_size() const; diff --git a/core/os/os.h b/core/os/os.h index 68769e7ad4..edb5d57c5f 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -151,6 +151,7 @@ public: virtual void get_fullscreen_mode_list(List *p_list,int p_screen=0) const=0; virtual int get_screen_count() const=0; + virtual Size2 get_screen_size(int p_screen=0) const=0; virtual Point2 get_window_position() const=0; virtual void set_window_position(const Point2& p_position)=0; virtual Size2 get_window_size() const=0; diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index c37358139c..063fb17c26 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -530,6 +530,14 @@ int OS_X11::get_screen_count() const { return XScreenCount(x11_display); } +Size2 OS_X11::get_screen_size(int p_screen) const { + Window root = XRootWindow(x11_display, p_screen); + XWindowAttributes xwa; + XGetWindowAttributes(x11_display, root, &xwa); + return Size2i(xwa.width, xwa.height); +} + + Point2 OS_X11::get_window_position() const { int x,y; XWindowAttributes xwa; diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h index f55b7dc0e3..a38d511003 100644 --- a/platform/x11/os_x11.h +++ b/platform/x11/os_x11.h @@ -218,6 +218,7 @@ public: virtual void get_fullscreen_mode_list(List *p_list,int p_screen=0) const; virtual int get_screen_count() const; + virtual Size2 get_screen_size(int p_screen=0) const; virtual Point2 get_window_position() const; virtual void set_window_position(const Point2& p_position); virtual Size2 get_window_size() const; -- cgit v1.2.3 From 107d2a373a4a66bc237cc47128f815c2624c35bb Mon Sep 17 00:00:00 2001 From: hurikhan Date: Sun, 11 Jan 2015 20:30:57 +0800 Subject: Demo misc/window_management added --- demos/misc/window_management/control.gd | 39 +++++++++++++++++++++ demos/misc/window_management/engine.cfg | 5 +++ demos/misc/window_management/icon.png | Bin 0 -> 3639 bytes demos/misc/window_management/icon.png.flags | 1 + demos/misc/window_management/window_management.scn | Bin 0 -> 3276 bytes 5 files changed, 45 insertions(+) create mode 100644 demos/misc/window_management/control.gd create mode 100644 demos/misc/window_management/engine.cfg create mode 100644 demos/misc/window_management/icon.png create mode 100644 demos/misc/window_management/icon.png.flags create mode 100644 demos/misc/window_management/window_management.scn diff --git a/demos/misc/window_management/control.gd b/demos/misc/window_management/control.gd new file mode 100644 index 0000000000..3e74f24e42 --- /dev/null +++ b/demos/misc/window_management/control.gd @@ -0,0 +1,39 @@ + +extends Control + +func _fixed_process(delta): + if(OS.is_fullscreen()): + get_node("Label_Fullscreen").set_text("Mode:\nFullscreen") + else: + get_node("Label_Fullscreen").set_text("Mode:\nWindowed") + + get_node("Label_Position").set_text( str("Position:\n", OS.get_window_position() ) ) + + get_node("Label_Size").set_text(str("Size:\n", OS.get_window_size() ) ) + + get_node("Label_Screen_Count").set_text( str("Screens:\n", OS.get_screen_count() ) ) + + get_node("Label_Screen0_Resolution").set_text( str("Screen0 Resolution:\n", OS.get_screen_size() ) ) + + if(OS.get_screen_count() > 1): + get_node("Label_Screen1_Resolution").show() + get_node("Label_Screen1_Resolution").set_text( str("Screen0 Resolution:\n", OS.get_screen_size(1) ) ) + + +func _ready(): + set_fixed_process(true) + + +func _on_Fullscreen_toggled( pressed ): + if(pressed): + OS.set_fullscreen(true) + else: + OS.set_fullscreen(false) + + +func _on_Button_MoveTo_pressed(): + OS.set_window_position( Vector2(100,100) ) + + +func _on_Button_Resize_pressed(): + OS.set_window_size( Vector2(1024,768) ) diff --git a/demos/misc/window_management/engine.cfg b/demos/misc/window_management/engine.cfg new file mode 100644 index 0000000000..7b6dddce96 --- /dev/null +++ b/demos/misc/window_management/engine.cfg @@ -0,0 +1,5 @@ +[application] + +name="window_management" +main_scene="res://window_management.scn" +icon="icon.png" diff --git a/demos/misc/window_management/icon.png b/demos/misc/window_management/icon.png new file mode 100644 index 0000000000..0c422e37b0 Binary files /dev/null and b/demos/misc/window_management/icon.png differ diff --git a/demos/misc/window_management/icon.png.flags b/demos/misc/window_management/icon.png.flags new file mode 100644 index 0000000000..5130fd1aab --- /dev/null +++ b/demos/misc/window_management/icon.png.flags @@ -0,0 +1 @@ +gen_mipmaps=false diff --git a/demos/misc/window_management/window_management.scn b/demos/misc/window_management/window_management.scn new file mode 100644 index 0000000000..6eaf62ff9f Binary files /dev/null and b/demos/misc/window_management/window_management.scn differ -- cgit v1.2.3 From 16cf16da7e09909e3ebc668851205db823800866 Mon Sep 17 00:00:00 2001 From: hurikhan Date: Sun, 11 Jan 2015 22:02:18 +0800 Subject: Update README.md --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index 3456290f74..57068bf39c 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,21 @@ +### x11-window-management branch + +#### New GDScript Methods for the OS Class: +* int OS.get_screen_count() +* Vector2 OS.get_screen_size(int screen=0) +* Vector2 OS.get_window_position() +* void OS.set_window_position(Vector2 position) +* Vector2 OS.get_window_size() +* void OS.set_window_size(Vector2 size) +* void OS.set_fullscreen(bool enabled, int screen=0) +* bool OS.is_fullscreen() + +#### Demo +A demo/test is available at "demos/misc/window-management" + +#### Warning +Just only works for X11. It breaks other platforms at the moment. + ![GODOT](/logo.png) ### The Engine -- cgit v1.2.3 From c0d363266755de3ac87f61600f23921d881d99e2 Mon Sep 17 00:00:00 2001 From: hurikhan Date: Tue, 13 Jan 2015 15:44:39 +0800 Subject: introduced the scons experimental_wm_api switch: ================================================ Usage: scons p=x11 experimental_wm_api=yes --- core/bind/core_bind.cpp | 4 ++++ core/bind/core_bind.h | 2 ++ core/os/os.h | 4 +++- platform/x11/detect.py | 4 ++++ platform/x11/os_x11.cpp | 32 ++++++++++++++++++++++++++++++++ platform/x11/os_x11.h | 7 +++++-- 6 files changed, 50 insertions(+), 3 deletions(-) diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index 47bfba1cbb..b8fc63dc43 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -176,6 +176,7 @@ bool _OS::is_video_mode_fullscreen(int p_screen) const { } +#ifdef EXPERIMENTAL_WM_API int _OS::get_screen_count() const { return OS::get_singleton()->get_screen_count(); } @@ -207,6 +208,7 @@ void _OS::set_fullscreen(bool p_enabled,int p_screen) { bool _OS::is_fullscreen() const { return OS::get_singleton()->is_fullscreen(); } +#endif void _OS::set_use_file_access_save_and_swap(bool p_enable) { @@ -664,6 +666,7 @@ void _OS::_bind_methods() { ObjectTypeDB::bind_method(_MD("is_video_mode_resizable","screen"),&_OS::is_video_mode_resizable,DEFVAL(0)); ObjectTypeDB::bind_method(_MD("get_fullscreen_mode_list","screen"),&_OS::get_fullscreen_mode_list,DEFVAL(0)); +#ifdef EXPERIMENTAL_WM_API ObjectTypeDB::bind_method(_MD("get_screen_count"),&_OS::get_screen_count); ObjectTypeDB::bind_method(_MD("get_screen_size"),&_OS::get_screen_size,DEFVAL(0)); ObjectTypeDB::bind_method(_MD("get_window_position"),&_OS::get_window_position); @@ -672,6 +675,7 @@ void _OS::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_window_size"),&_OS::set_window_size); ObjectTypeDB::bind_method(_MD("set_fullscreen","enabled","screen"),&_OS::set_fullscreen,DEFVAL(0)); ObjectTypeDB::bind_method(_MD("is_fullscreen"),&_OS::is_fullscreen); +#endif ObjectTypeDB::bind_method(_MD("set_iterations_per_second","iterations_per_second"),&_OS::set_iterations_per_second); ObjectTypeDB::bind_method(_MD("get_iterations_per_second"),&_OS::get_iterations_per_second); diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index 2a87f85ec7..62f9913556 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -108,6 +108,7 @@ public: bool is_video_mode_resizable(int p_screen=0) const; Array get_fullscreen_mode_list(int p_screen=0) const; +#ifdef EXPERIMENTAL_WM_API virtual int get_screen_count() const; virtual Size2 get_screen_size(int p_screen=0) const; virtual Point2 get_window_position() const; @@ -116,6 +117,7 @@ public: virtual void set_window_size(const Size2& p_size); void set_fullscreen(bool p_enabled, int p_screen=0); bool is_fullscreen() const; +#endif Error native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track); bool native_video_is_playing(); diff --git a/core/os/os.h b/core/os/os.h index edb5d57c5f..c2534287bc 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -150,6 +150,7 @@ public: virtual VideoMode get_video_mode(int p_screen=0) const=0; virtual void get_fullscreen_mode_list(List *p_list,int p_screen=0) const=0; +#ifdef EXPERIMENTAL_WM_API virtual int get_screen_count() const=0; virtual Size2 get_screen_size(int p_screen=0) const=0; virtual Point2 get_window_position() const=0; @@ -158,7 +159,8 @@ public: virtual void set_window_size(const Size2 p_size)=0; virtual void set_fullscreen(bool p_enabled,int p_screen=0)=0; virtual bool is_fullscreen() const=0; - +#endif + virtual void set_iterations_per_second(int p_ips); virtual int get_iterations_per_second() const; diff --git a/platform/x11/detect.py b/platform/x11/detect.py index 621a0c66a0..954e5270e8 100644 --- a/platform/x11/detect.py +++ b/platform/x11/detect.py @@ -47,6 +47,7 @@ def get_opts(): return [ ('use_llvm','Use llvm compiler','no'), ('use_sanitizer','Use llvm compiler sanitize address','no'), + ('experimental_wm_api', 'Use experimental window management API','no'), ] def get_flags(): @@ -148,3 +149,6 @@ def configure(env): env.Append( BUILDERS = { 'GLSL120GLES' : env.Builder(action = methods.build_gles2_headers, suffix = 'glsl.h',src_suffix = '.glsl') } ) #env.Append( BUILDERS = { 'HLSL9' : env.Builder(action = methods.build_hlsl_dx9_headers, suffix = 'hlsl.h',src_suffix = '.hlsl') } ) + if(env["experimental_wm_api"]=="yes"): + env.Append(CPPFLAGS=['-DEXPERIMENTAL_WM_API']) + diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index 063fb17c26..e20d0731e1 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -182,8 +182,38 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi // borderless fullscreen window mode if (current_videomode.fullscreen) { +#ifndef EXPERIMENTAL_WM_API + // needed for lxde/openbox, possibly others + Hints hints; + Atom property; + hints.flags = 2; + hints.decorations = 0; + property = XInternAtom(x11_display, "_MOTIF_WM_HINTS", True); + XChangeProperty(x11_display, x11_window, property, property, 32, PropModeReplace, (unsigned char *)&hints, 5); + XMapRaised(x11_display, x11_window); + XWindowAttributes xwa; + XGetWindowAttributes(x11_display, DefaultRootWindow(x11_display), &xwa); + XMoveResizeWindow(x11_display, x11_window, 0, 0, xwa.width, xwa.height); + + // code for netwm-compliants + XEvent xev; + Atom wm_state = XInternAtom(x11_display, "_NET_WM_STATE", False); + Atom fullscreen = XInternAtom(x11_display, "_NET_WM_STATE_FULLSCREEN", False); + + memset(&xev, 0, sizeof(xev)); + xev.type = ClientMessage; + xev.xclient.window = x11_window; + xev.xclient.message_type = wm_state; + xev.xclient.format = 32; + xev.xclient.data.l[0] = 1; + xev.xclient.data.l[1] = fullscreen; + xev.xclient.data.l[2] = 0; + + XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureNotifyMask, &xev); +#else set_wm_border(false); set_wm_fullscreen(true); +#endif } // disable resizeable window @@ -496,6 +526,7 @@ void OS_X11::get_fullscreen_mode_list(List *p_list,int p_screen) cons } +#ifdef EXPERIMENTAL_WM_API void OS_X11::set_wm_border(bool p_enabled) { // needed for lxde/openbox, possibly others Hints hints; @@ -639,6 +670,7 @@ void OS_X11::set_fullscreen(bool p_enabled,int p_screen) { bool OS_X11::is_fullscreen() const { return current_videomode.fullscreen; } +#endif InputModifierState OS_X11::get_key_modifier_state(unsigned int p_x11_state) { diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h index a38d511003..4aca996fdc 100644 --- a/platform/x11/os_x11.h +++ b/platform/x11/os_x11.h @@ -73,7 +73,6 @@ class OS_X11 : public OS_Unix { Rasterizer *rasterizer; VisualServer *visual_server; VideoMode current_videomode; - VideoMode pre_videomode; List args; Window x11_window; MainLoop *main_loop; @@ -160,8 +159,11 @@ class OS_X11 : public OS_Unix { int joystick_count; Joystick joysticks[JOYSTICKS_MAX]; +#ifdef EXPERIMENTAL_WM_API + VideoMode pre_videomode; void set_wm_border(bool p_enabled); void set_wm_fullscreen(bool p_enabled); +#endif protected: @@ -217,6 +219,7 @@ public: virtual VideoMode get_video_mode(int p_screen=0) const; virtual void get_fullscreen_mode_list(List *p_list,int p_screen=0) const; +#ifdef EXPERIMENTAL_WM_API virtual int get_screen_count() const; virtual Size2 get_screen_size(int p_screen=0) const; virtual Point2 get_window_position() const; @@ -225,7 +228,7 @@ public: virtual void set_window_size(const Size2 p_size); virtual void set_fullscreen(bool p_enabled,int p_screen=0); virtual bool is_fullscreen() const; - +#endif virtual void move_window_to_foreground(); void run(); -- cgit v1.2.3 From ce7c7a862ebe37fada7708c342c07d70fa80465a Mon Sep 17 00:00:00 2001 From: hurikhan Date: Tue, 13 Jan 2015 17:25:50 +0800 Subject: get_screen_position() added --- core/bind/core_bind.cpp | 5 +++++ core/bind/core_bind.h | 1 + core/os/os.h | 1 + demos/misc/window_management/control.gd | 11 ++++++++--- demos/misc/window_management/window_management.scn | Bin 3276 -> 3582 bytes platform/x11/os_x11.cpp | 12 ++++++++++++ platform/x11/os_x11.h | 1 + 7 files changed, 28 insertions(+), 3 deletions(-) diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index b8fc63dc43..a2aca7e11f 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -181,6 +181,10 @@ int _OS::get_screen_count() const { return OS::get_singleton()->get_screen_count(); } +Point2 _OS::get_screen_position(int p_screen) const { + return OS::get_singleton()->get_screen_position(p_screen); +} + Size2 _OS::get_screen_size(int p_screen) const { return OS::get_singleton()->get_screen_size(p_screen); } @@ -668,6 +672,7 @@ void _OS::_bind_methods() { #ifdef EXPERIMENTAL_WM_API ObjectTypeDB::bind_method(_MD("get_screen_count"),&_OS::get_screen_count); + ObjectTypeDB::bind_method(_MD("get_screen_position"),&_OS::get_screen_position,DEFVAL(0)); ObjectTypeDB::bind_method(_MD("get_screen_size"),&_OS::get_screen_size,DEFVAL(0)); ObjectTypeDB::bind_method(_MD("get_window_position"),&_OS::get_window_position); ObjectTypeDB::bind_method(_MD("set_window_position"),&_OS::set_window_position); diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index 62f9913556..9d9f25691e 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -110,6 +110,7 @@ public: #ifdef EXPERIMENTAL_WM_API virtual int get_screen_count() const; + virtual Point2 get_screen_position(int p_screen=0) const; virtual Size2 get_screen_size(int p_screen=0) const; virtual Point2 get_window_position() const; virtual void set_window_position(const Point2& p_position); diff --git a/core/os/os.h b/core/os/os.h index c2534287bc..1ef05e45c8 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -152,6 +152,7 @@ public: #ifdef EXPERIMENTAL_WM_API virtual int get_screen_count() const=0; + virtual Point2 get_screen_position(int p_screen=0) const=0; virtual Size2 get_screen_size(int p_screen=0) const=0; virtual Point2 get_window_position() const=0; virtual void set_window_position(const Point2& p_position)=0; diff --git a/demos/misc/window_management/control.gd b/demos/misc/window_management/control.gd index 3e74f24e42..ad15a74731 100644 --- a/demos/misc/window_management/control.gd +++ b/demos/misc/window_management/control.gd @@ -15,11 +15,16 @@ func _fixed_process(delta): get_node("Label_Screen0_Resolution").set_text( str("Screen0 Resolution:\n", OS.get_screen_size() ) ) + get_node("Label_Screen0_Position").set_text(str("Screen0 Position:\n",OS.get_screen_position())) + if(OS.get_screen_count() > 1): get_node("Label_Screen1_Resolution").show() - get_node("Label_Screen1_Resolution").set_text( str("Screen0 Resolution:\n", OS.get_screen_size(1) ) ) - - + get_node("Label_Screen1_Resolution").set_text( str("Screen1 Resolution:\n", OS.get_screen_size(1) ) ) + get_node("Label_Screen1_Position").show() + get_node("Label_Screen1_Position").set_text( str("Screen1 Position:\n", OS.get_screen_size(1) ) ) + else: + get_node("Label_Screen1_Resolution").hide() + get_node("Label_Screen1_Position").hide() func _ready(): set_fixed_process(true) diff --git a/demos/misc/window_management/window_management.scn b/demos/misc/window_management/window_management.scn index 6eaf62ff9f..3a6426f3ee 100644 Binary files a/demos/misc/window_management/window_management.scn and b/demos/misc/window_management/window_management.scn differ diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index e20d0731e1..01d62f333d 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -561,7 +561,19 @@ int OS_X11::get_screen_count() const { return XScreenCount(x11_display); } +Point2 OS_X11::get_screen_position(int p_screen) const { + if( p_screen >= XScreenCount(x11_display) ) + return Point2i(0,0); + + Window root = XRootWindow(x11_display, p_screen); + XWindowAttributes xwa; + XGetWindowAttributes(x11_display, root, &xwa); + return Point2i(xwa.x, xwa.y); +} + Size2 OS_X11::get_screen_size(int p_screen) const { + if( p_screen >= XScreenCount(x11_display) ) + return Size2i(0,0); Window root = XRootWindow(x11_display, p_screen); XWindowAttributes xwa; XGetWindowAttributes(x11_display, root, &xwa); diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h index 4aca996fdc..ca35bf2c0a 100644 --- a/platform/x11/os_x11.h +++ b/platform/x11/os_x11.h @@ -221,6 +221,7 @@ public: #ifdef EXPERIMENTAL_WM_API virtual int get_screen_count() const; + virtual Point2 get_screen_position(int p_screen=0) const; virtual Size2 get_screen_size(int p_screen=0) const; virtual Point2 get_window_position() const; virtual void set_window_position(const Point2& p_position); -- cgit v1.2.3 From f55c0e928580de63af55ac22f045bb4380a1df2e Mon Sep 17 00:00:00 2001 From: hurikhan Date: Tue, 13 Jan 2015 21:01:24 +0800 Subject: Using Xinerama extension for getting screen info --- demos/misc/window_management/control.gd | 2 +- platform/x11/detect.py | 6 +++++ platform/x11/os_x11.cpp | 42 ++++++++++++++++++++++----------- 3 files changed, 35 insertions(+), 15 deletions(-) diff --git a/demos/misc/window_management/control.gd b/demos/misc/window_management/control.gd index ad15a74731..34df5dd92c 100644 --- a/demos/misc/window_management/control.gd +++ b/demos/misc/window_management/control.gd @@ -21,7 +21,7 @@ func _fixed_process(delta): get_node("Label_Screen1_Resolution").show() get_node("Label_Screen1_Resolution").set_text( str("Screen1 Resolution:\n", OS.get_screen_size(1) ) ) get_node("Label_Screen1_Position").show() - get_node("Label_Screen1_Position").set_text( str("Screen1 Position:\n", OS.get_screen_size(1) ) ) + get_node("Label_Screen1_Position").set_text( str("Screen1 Position:\n", OS.get_screen_position(1) ) ) else: get_node("Label_Screen1_Resolution").hide() get_node("Label_Screen1_Position").hide() diff --git a/platform/x11/detect.py b/platform/x11/detect.py index 954e5270e8..1eb615893b 100644 --- a/platform/x11/detect.py +++ b/platform/x11/detect.py @@ -38,6 +38,11 @@ def can_build(): if (x11_error): print("xcursor not found.. x11 disabled.") return False + + x11_error=os.system("pkg-config xinerama --modversion > /dev/null ") + if (x11_error): + print("xinerama not found.. x11 disabled.") + return False return True # X11 enabled @@ -151,4 +156,5 @@ def configure(env): if(env["experimental_wm_api"]=="yes"): env.Append(CPPFLAGS=['-DEXPERIMENTAL_WM_API']) + env.ParseConfig('pkg-config xinerama --cflags --libs') diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index 01d62f333d..533e57d5c7 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -36,6 +36,9 @@ #include "servers/physics/physics_server_sw.h" #include "X11/Xutil.h" +#ifdef EXPERIMENTAL_WM_API +#include "X11/extensions/Xinerama.h" +#endif #include "main/main.h" @@ -558,26 +561,37 @@ void OS_X11::set_wm_fullscreen(bool p_enabled) { } int OS_X11::get_screen_count() const { - return XScreenCount(x11_display); + int event_base, error_base; + const Bool ext_okay = XineramaQueryExtension(x11_display, &event_base, &error_base); + if( !ext_okay ) return 0; + int count; + XineramaScreenInfo* xsi = XineramaQueryScreens(x11_display, &count); + XFree(xsi); + return count; } Point2 OS_X11::get_screen_position(int p_screen) const { - if( p_screen >= XScreenCount(x11_display) ) - return Point2i(0,0); - - Window root = XRootWindow(x11_display, p_screen); - XWindowAttributes xwa; - XGetWindowAttributes(x11_display, root, &xwa); - return Point2i(xwa.x, xwa.y); + int event_base, error_base; + const Bool ext_okay = XineramaQueryExtension(x11_display, &event_base, &error_base); + if( !ext_okay ) return Point2i(0,0); + int count; + XineramaScreenInfo* xsi = XineramaQueryScreens(x11_display, &count); + 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; } Size2 OS_X11::get_screen_size(int p_screen) const { - if( p_screen >= XScreenCount(x11_display) ) - return Size2i(0,0); - Window root = XRootWindow(x11_display, p_screen); - XWindowAttributes xwa; - XGetWindowAttributes(x11_display, root, &xwa); - return Size2i(xwa.width, xwa.height); + int event_base, error_base; + const Bool ext_okay = XineramaQueryExtension(x11_display, &event_base, &error_base); + if( !ext_okay ) return Size2i(0,0); + int count; + XineramaScreenInfo* xsi = XineramaQueryScreens(x11_display, &count); + if( p_screen >= count ) return Size2i(0,0); + Size2i size = Point2i(xsi[p_screen].width, xsi[p_screen].height); + XFree(xsi); + return size; } -- cgit v1.2.3 From 790d8ecbb9a0a0ac67520b84fc621c34f910d817 Mon Sep 17 00:00:00 2001 From: hurikhan Date: Wed, 14 Jan 2015 12:02:59 +0800 Subject: get_screen() + set_screen() added --- core/bind/core_bind.cpp | 16 ++++- core/bind/core_bind.h | 4 +- core/os/os.h | 4 +- demos/misc/window_management/control.gd | 27 +++++++- demos/misc/window_management/engine.cfg | 4 ++ demos/misc/window_management/window_management.scn | Bin 3582 -> 3787 bytes platform/x11/os_x11.cpp | 71 ++++++++++++++++----- platform/x11/os_x11.h | 7 +- 8 files changed, 109 insertions(+), 24 deletions(-) diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index a2aca7e11f..48cd43ccdc 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -181,6 +181,14 @@ int _OS::get_screen_count() const { return OS::get_singleton()->get_screen_count(); } +int _OS::get_screen() const { + return OS::get_singleton()->get_screen(); +} + +void _OS::set_screen(int p_screen) { + OS::get_singleton()->set_screen(p_screen); +} + Point2 _OS::get_screen_position(int p_screen) const { return OS::get_singleton()->get_screen_position(p_screen); } @@ -205,8 +213,8 @@ void _OS::set_window_size(const Size2& p_size) { OS::get_singleton()->set_window_size(p_size); } -void _OS::set_fullscreen(bool p_enabled,int p_screen) { - OS::get_singleton()->set_fullscreen(p_enabled, p_screen); +void _OS::set_fullscreen(bool p_enabled) { + OS::get_singleton()->set_fullscreen(p_enabled); } bool _OS::is_fullscreen() const { @@ -672,13 +680,15 @@ void _OS::_bind_methods() { #ifdef EXPERIMENTAL_WM_API ObjectTypeDB::bind_method(_MD("get_screen_count"),&_OS::get_screen_count); + ObjectTypeDB::bind_method(_MD("get_screen"),&_OS::get_screen); + ObjectTypeDB::bind_method(_MD("set_screen"),&_OS::set_screen); ObjectTypeDB::bind_method(_MD("get_screen_position"),&_OS::get_screen_position,DEFVAL(0)); ObjectTypeDB::bind_method(_MD("get_screen_size"),&_OS::get_screen_size,DEFVAL(0)); ObjectTypeDB::bind_method(_MD("get_window_position"),&_OS::get_window_position); ObjectTypeDB::bind_method(_MD("set_window_position"),&_OS::set_window_position); ObjectTypeDB::bind_method(_MD("get_window_size"),&_OS::get_window_size); ObjectTypeDB::bind_method(_MD("set_window_size"),&_OS::set_window_size); - ObjectTypeDB::bind_method(_MD("set_fullscreen","enabled","screen"),&_OS::set_fullscreen,DEFVAL(0)); + ObjectTypeDB::bind_method(_MD("set_fullscreen","enabled"),&_OS::set_fullscreen); ObjectTypeDB::bind_method(_MD("is_fullscreen"),&_OS::is_fullscreen); #endif diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index 9d9f25691e..99ecb765c7 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -110,13 +110,15 @@ public: #ifdef EXPERIMENTAL_WM_API virtual int get_screen_count() const; + virtual int get_screen() const; + virtual void set_screen(int p_screen); virtual Point2 get_screen_position(int p_screen=0) const; virtual Size2 get_screen_size(int p_screen=0) const; virtual Point2 get_window_position() const; virtual void set_window_position(const Point2& p_position); virtual Size2 get_window_size() const; virtual void set_window_size(const Size2& p_size); - void set_fullscreen(bool p_enabled, int p_screen=0); + void set_fullscreen(bool p_enabled); bool is_fullscreen() const; #endif diff --git a/core/os/os.h b/core/os/os.h index 1ef05e45c8..2d4e937974 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -152,13 +152,15 @@ public: #ifdef EXPERIMENTAL_WM_API virtual int get_screen_count() const=0; + virtual int get_screen() const=0; + virtual void set_screen(int p_screen)=0; virtual Point2 get_screen_position(int p_screen=0) const=0; virtual Size2 get_screen_size(int p_screen=0) const=0; virtual Point2 get_window_position() const=0; virtual void set_window_position(const Point2& p_position)=0; virtual Size2 get_window_size() const=0; virtual void set_window_size(const Size2 p_size)=0; - virtual void set_fullscreen(bool p_enabled,int p_screen=0)=0; + virtual void set_fullscreen(bool p_enabled)=0; virtual bool is_fullscreen() const=0; #endif diff --git a/demos/misc/window_management/control.gd b/demos/misc/window_management/control.gd index 34df5dd92c..ce17db6b00 100644 --- a/demos/misc/window_management/control.gd +++ b/demos/misc/window_management/control.gd @@ -13,18 +13,35 @@ func _fixed_process(delta): get_node("Label_Screen_Count").set_text( str("Screens:\n", OS.get_screen_count() ) ) + get_node("Label_Screen_Current").set_text( str("Current:\n", OS.get_screen() ) ) + get_node("Label_Screen0_Resolution").set_text( str("Screen0 Resolution:\n", OS.get_screen_size() ) ) get_node("Label_Screen0_Position").set_text(str("Screen0 Position:\n",OS.get_screen_position())) if(OS.get_screen_count() > 1): + get_node("Button_Screen1").show() get_node("Label_Screen1_Resolution").show() - get_node("Label_Screen1_Resolution").set_text( str("Screen1 Resolution:\n", OS.get_screen_size(1) ) ) get_node("Label_Screen1_Position").show() + get_node("Label_Screen1_Resolution").set_text( str("Screen1 Resolution:\n", OS.get_screen_size(1) ) ) get_node("Label_Screen1_Position").set_text( str("Screen1 Position:\n", OS.get_screen_position(1) ) ) else: + get_node("Button_Screen1").hide() get_node("Label_Screen1_Resolution").hide() get_node("Label_Screen1_Position").hide() + + if( Input.is_action_pressed("ui_right")): + OS.set_screen(1) + + if( Input.is_action_pressed("ui_left")): + OS.set_screen(0) + + if( Input.is_action_pressed("ui_up")): + OS.set_fullscreen(true) + + if( Input.is_action_pressed("ui_down")): + OS.set_fullscreen(false) + func _ready(): set_fixed_process(true) @@ -42,3 +59,11 @@ func _on_Button_MoveTo_pressed(): func _on_Button_Resize_pressed(): OS.set_window_size( Vector2(1024,768) ) + + +func _on_Button_Screen0_pressed(): + OS.set_screen(0) + + +func _on_Button_Screen1_pressed(): + OS.set_screen(1) diff --git a/demos/misc/window_management/engine.cfg b/demos/misc/window_management/engine.cfg index 7b6dddce96..44ad30ea14 100644 --- a/demos/misc/window_management/engine.cfg +++ b/demos/misc/window_management/engine.cfg @@ -3,3 +3,7 @@ name="window_management" main_scene="res://window_management.scn" icon="icon.png" + +[display] + +fullscreen=true diff --git a/demos/misc/window_management/window_management.scn b/demos/misc/window_management/window_management.scn index 3a6426f3ee..9d55174dce 100644 Binary files a/demos/misc/window_management/window_management.scn and b/demos/misc/window_management/window_management.scn differ diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index 533e57d5c7..0ed8c80162 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -214,6 +214,10 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureNotifyMask, &xev); #else + old_window_position.x = 0; + old_window_position.y = 0; + old_window_size.width = 800; + old_window_size.height = 600; set_wm_border(false); set_wm_fullscreen(true); #endif @@ -539,7 +543,7 @@ void OS_X11::set_wm_border(bool p_enabled) { property = XInternAtom(x11_display, "_MOTIF_WM_HINTS", True); XChangeProperty(x11_display, x11_window, property, property, 32, PropModeReplace, (unsigned char *)&hints, 5); XMapRaised(x11_display, x11_window); - XMoveResizeWindow(x11_display, x11_window, 0, 0, current_videomode.width, current_videomode.height); + //XMoveResizeWindow(x11_display, x11_window, 0, 0, 800, 800); } void OS_X11::set_wm_fullscreen(bool p_enabled) { @@ -564,19 +568,55 @@ int OS_X11::get_screen_count() const { int event_base, error_base; const Bool ext_okay = XineramaQueryExtension(x11_display, &event_base, &error_base); if( !ext_okay ) return 0; + int count; XineramaScreenInfo* xsi = XineramaQueryScreens(x11_display, &count); XFree(xsi); return count; } +int OS_X11::get_screen() const { + int x,y; + Window child; + XTranslateCoordinates( x11_display, x11_window, DefaultRootWindow(x11_display), 0, 0, &x, &y, &child); + + int count = get_screen_count(); + for(int i=0; i= pos.x && x = pos.y && y < pos.y + size.height) ) + return i; + } + return 0; +} + +void OS_X11::set_screen(int p_screen) { + int count = get_screen_count(); + if(p_screen >= count) return; + + if( current_videomode.fullscreen ) { + Point2i position = get_screen_position(p_screen); + Size2i size = get_screen_size(p_screen); + + XMoveResizeWindow(x11_display, x11_window, position.x, position.y, size.x, size.y); + } + else { + if( p_screen != get_screen() ) { + Point2i position = get_screen_position(p_screen); + XMoveWindow(x11_display, x11_window, position.x, position.y); + } + } +} + Point2 OS_X11::get_screen_position(int p_screen) const { int event_base, error_base; const Bool ext_okay = XineramaQueryExtension(x11_display, &event_base, &error_base); if( !ext_okay ) return Point2i(0,0); + int count; XineramaScreenInfo* xsi = XineramaQueryScreens(x11_display, &count); 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; @@ -586,9 +626,11 @@ Size2 OS_X11::get_screen_size(int p_screen) const { int event_base, error_base; const Bool ext_okay = XineramaQueryExtension(x11_display, &event_base, &error_base); if( !ext_okay ) return Size2i(0,0); + int count; XineramaScreenInfo* xsi = XineramaQueryScreens(x11_display, &count); if( p_screen >= count ) return Size2i(0,0); + Size2i size = Point2i(xsi[p_screen].width, xsi[p_screen].height); XFree(xsi); return size; @@ -597,11 +639,8 @@ Size2 OS_X11::get_screen_size(int p_screen) const { Point2 OS_X11::get_window_position() const { int x,y; - XWindowAttributes xwa; Window child; XTranslateCoordinates( x11_display, x11_window, DefaultRootWindow(x11_display), 0, 0, &x, &y, &child); - XGetWindowAttributes(x11_display, x11_window, &xwa); - return Point2i(x,y); } @@ -664,30 +703,30 @@ void OS_X11::set_window_size(const Size2 p_size) { XResizeWindow(x11_display, x11_window, p_size.x, p_size.y); } -void OS_X11::set_fullscreen(bool p_enabled,int p_screen) { +void OS_X11::set_fullscreen(bool p_enabled) { if(p_enabled && current_videomode.fullscreen) return; if(p_enabled) { - pre_videomode = current_videomode; + old_window_size = get_window_size(); + old_window_position = get_window_position(); - XWindowAttributes xwa; - XGetWindowAttributes(x11_display, DefaultRootWindow(x11_display), &xwa); - - current_videomode.fullscreen = True; - current_videomode.width = xwa.width; - current_videomode.height = xwa.height; + int screen = get_screen(); + Size2i size = get_screen_size(screen); + Point2i position = get_screen_position(screen); set_wm_border(false); set_wm_fullscreen(true); - } else { - current_videomode.fullscreen = False; - current_videomode.width = pre_videomode.width; - current_videomode.height = pre_videomode.height; + XMoveResizeWindow(x11_display, x11_window, position.x, position.y, size.x, size.y); + current_videomode.fullscreen = True; + } else { set_wm_fullscreen(false); set_wm_border(true); + XMoveResizeWindow(x11_display, x11_window, old_window_position.x, old_window_position.y, old_window_size.width, old_window_size.height); + + current_videomode.fullscreen = False; } visual_server->init(); diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h index ca35bf2c0a..bb0fd38387 100644 --- a/platform/x11/os_x11.h +++ b/platform/x11/os_x11.h @@ -160,7 +160,8 @@ class OS_X11 : public OS_Unix { Joystick joysticks[JOYSTICKS_MAX]; #ifdef EXPERIMENTAL_WM_API - VideoMode pre_videomode; + Point2i old_window_position; + Size2i old_window_size; void set_wm_border(bool p_enabled); void set_wm_fullscreen(bool p_enabled); #endif @@ -221,13 +222,15 @@ public: #ifdef EXPERIMENTAL_WM_API virtual int get_screen_count() const; + virtual int get_screen() const; + virtual void set_screen(int p_screen); virtual Point2 get_screen_position(int p_screen=0) const; virtual Size2 get_screen_size(int p_screen=0) const; virtual Point2 get_window_position() const; virtual void set_window_position(const Point2& p_position); virtual Size2 get_window_size() const; virtual void set_window_size(const Size2 p_size); - virtual void set_fullscreen(bool p_enabled,int p_screen=0); + virtual void set_fullscreen(bool p_enabled); virtual bool is_fullscreen() const; #endif virtual void move_window_to_foreground(); -- cgit v1.2.3 From 7222e195e549cc9a08c06fb30fb4d3d9051c818e Mon Sep 17 00:00:00 2001 From: hurikhan Date: Wed, 14 Jan 2015 13:19:27 +0800 Subject: minor cleanup --- platform/x11/os_x11.cpp | 24 ++++++++++++++---------- platform/x11/os_x11.h | 6 ++++-- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index 0ed8c80162..d395e99210 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -214,10 +214,10 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureNotifyMask, &xev); #else - old_window_position.x = 0; - old_window_position.y = 0; - old_window_size.width = 800; - old_window_size.height = 600; + window_data.position.x = 0; + window_data.position.y = 0; + window_data.size.width = 800; + window_data.size.height = 600; set_wm_border(false); set_wm_fullscreen(true); #endif @@ -709,8 +709,8 @@ void OS_X11::set_fullscreen(bool p_enabled) { return; if(p_enabled) { - old_window_size = get_window_size(); - old_window_position = get_window_position(); + window_data.size = get_window_size(); + window_data.position = get_window_position(); int screen = get_screen(); Size2i size = get_screen_size(screen); @@ -724,7 +724,11 @@ void OS_X11::set_fullscreen(bool p_enabled) { } else { set_wm_fullscreen(false); set_wm_border(true); - XMoveResizeWindow(x11_display, x11_window, old_window_position.x, old_window_position.y, old_window_size.width, old_window_size.height); + XMoveResizeWindow(x11_display, x11_window, + window_data.position.x, + window_data.position.y, + window_data.size.width, + window_data.size.height); current_videomode.fullscreen = False; } @@ -1072,7 +1076,7 @@ void OS_X11::process_xevents() { if (mouse_mode==MOUSE_MODE_CAPTURED) { #if 1 - Vector2 c = Point2i(current_videomode.width/2,current_videomode.height/2); + //Vector2 c = Point2i(current_videomode.width/2,current_videomode.height/2); if (pos==Point2i(current_videomode.width/2,current_videomode.height/2)) { //this sucks, it's a hack, etc and is a little inaccurate, etc. //but nothing I can do, X11 sucks. @@ -1081,9 +1085,9 @@ void OS_X11::process_xevents() { break; } - Point2i ncenter = pos; + Point2i new_center = pos; pos = last_mouse_pos + ( pos-center ); - center=ncenter; + center=new_center; do_mouse_warp=true; #else //Dear X11, thanks for making my life miserable diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h index bb0fd38387..72d212c131 100644 --- a/platform/x11/os_x11.h +++ b/platform/x11/os_x11.h @@ -160,8 +160,10 @@ class OS_X11 : public OS_Unix { Joystick joysticks[JOYSTICKS_MAX]; #ifdef EXPERIMENTAL_WM_API - Point2i old_window_position; - Size2i old_window_size; + struct { + Point2i position; + Size2i size; + } window_data; void set_wm_border(bool p_enabled); void set_wm_fullscreen(bool p_enabled); #endif -- cgit v1.2.3 From 2203ba5fe3f7cdca078dd557ec532b7f335d3670 Mon Sep 17 00:00:00 2001 From: hurikhan Date: Wed, 14 Jan 2015 13:27:03 +0800 Subject: don't start demo in fullscreen mode --- demos/misc/window_management/engine.cfg | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/demos/misc/window_management/engine.cfg b/demos/misc/window_management/engine.cfg index 44ad30ea14..bdc8ec3ed7 100644 --- a/demos/misc/window_management/engine.cfg +++ b/demos/misc/window_management/engine.cfg @@ -6,4 +6,5 @@ icon="icon.png" [display] -fullscreen=true +fullscreen=false +resizable=false -- cgit v1.2.3 From 1576dc5215c107e6966ceace2f3979ff12f2dd62 Mon Sep 17 00:00:00 2001 From: MSC Date: Wed, 14 Jan 2015 13:49:10 +0800 Subject: Update README.md --- README.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 57068bf39c..35841c8b29 100644 --- a/README.md +++ b/README.md @@ -2,19 +2,22 @@ #### New GDScript Methods for the OS Class: * int OS.get_screen_count() +* int OS.get_screen() +* void OS.set_screen(int screen) +* Vector2 OS.get_screen_position(int screen=0) * Vector2 OS.get_screen_size(int screen=0) * Vector2 OS.get_window_position() * void OS.set_window_position(Vector2 position) * Vector2 OS.get_window_size() * void OS.set_window_size(Vector2 size) -* void OS.set_fullscreen(bool enabled, int screen=0) +* void OS.set_fullscreen(bool enabled) * bool OS.is_fullscreen() #### Demo A demo/test is available at "demos/misc/window-management" -#### Warning -Just only works for X11. It breaks other platforms at the moment. +#### Scons Commandline +'''scons p=x11 experimental_wm_api=yes''' ![GODOT](/logo.png) -- cgit v1.2.3 From 07b8d9136a6ccea1587d27ca30db1ec10aca0ed1 Mon Sep 17 00:00:00 2001 From: hurikhan Date: Wed, 14 Jan 2015 15:44:47 +0800 Subject: demo window set to resizeable (need a bugfix her) --- demos/misc/window_management/engine.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demos/misc/window_management/engine.cfg b/demos/misc/window_management/engine.cfg index bdc8ec3ed7..2accafe43e 100644 --- a/demos/misc/window_management/engine.cfg +++ b/demos/misc/window_management/engine.cfg @@ -7,4 +7,4 @@ icon="icon.png" [display] fullscreen=false -resizable=false +resizable=true -- cgit v1.2.3 From d269344bbd19d9653fff3c2a230261b8fa00d7f6 Mon Sep 17 00:00:00 2001 From: hurikhan Date: Thu, 15 Jan 2015 22:50:23 +0900 Subject: WIP -- set_resizable() + is_resizable added --- core/bind/core_bind.cpp | 11 +++- core/bind/core_bind.h | 2 + core/os/os.h | 2 + demos/misc/window_management/control.gd | 28 +++++++++- demos/misc/window_management/window_management.scn | Bin 3787 -> 3897 bytes platform/x11/os_x11.cpp | 57 ++++++++++++++++----- platform/x11/os_x11.h | 9 +++- 7 files changed, 91 insertions(+), 18 deletions(-) diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index 48cd43ccdc..1fb6f96e71 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -220,6 +220,14 @@ void _OS::set_fullscreen(bool p_enabled) { bool _OS::is_fullscreen() const { return OS::get_singleton()->is_fullscreen(); } + +void _OS::set_resizable(bool p_enabled) { + OS::get_singleton()->set_resizable(p_enabled); +} + +bool _OS::is_resizable() const { + return OS::get_singleton()->is_resizable(); +} #endif void _OS::set_use_file_access_save_and_swap(bool p_enable) { @@ -232,7 +240,6 @@ bool _OS::is_video_mode_resizable(int p_screen) const { OS::VideoMode vm; vm = OS::get_singleton()->get_video_mode(p_screen); return vm.resizable; - } Array _OS::get_fullscreen_mode_list(int p_screen) const { @@ -690,6 +697,8 @@ void _OS::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_window_size"),&_OS::set_window_size); ObjectTypeDB::bind_method(_MD("set_fullscreen","enabled"),&_OS::set_fullscreen); ObjectTypeDB::bind_method(_MD("is_fullscreen"),&_OS::is_fullscreen); + ObjectTypeDB::bind_method(_MD("set_resizable","enabled"),&_OS::set_resizable); + ObjectTypeDB::bind_method(_MD("is_resizable"),&_OS::is_resizable); #endif ObjectTypeDB::bind_method(_MD("set_iterations_per_second","iterations_per_second"),&_OS::set_iterations_per_second); diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index 99ecb765c7..7ffd7e9e7c 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -120,6 +120,8 @@ public: virtual void set_window_size(const Size2& p_size); void set_fullscreen(bool p_enabled); bool is_fullscreen() const; + void set_resizable(bool p_enabled); + bool is_resizable() const; #endif Error native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track); diff --git a/core/os/os.h b/core/os/os.h index 2d4e937974..f1a9de1edf 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -162,6 +162,8 @@ public: virtual void set_window_size(const Size2 p_size)=0; virtual void set_fullscreen(bool p_enabled)=0; virtual bool is_fullscreen() const=0; + virtual void set_resizable(bool p_enabled)=0; + virtual bool is_resizable() const=0; #endif virtual void set_iterations_per_second(int p_ips); diff --git a/demos/misc/window_management/control.gd b/demos/misc/window_management/control.gd index ce17db6b00..c867bd21db 100644 --- a/demos/misc/window_management/control.gd +++ b/demos/misc/window_management/control.gd @@ -2,10 +2,18 @@ extends Control func _fixed_process(delta): + + var modetext = "Mode:\n" + if(OS.is_fullscreen()): - get_node("Label_Fullscreen").set_text("Mode:\nFullscreen") + modetext += "Fullscreen\n" else: - get_node("Label_Fullscreen").set_text("Mode:\nWindowed") + modetext += "Windowed\n" + + if(!OS.is_resizable()): + modetext += "FixedSize\n" + + get_node("Label_Mode").set_text(modetext) get_node("Label_Position").set_text( str("Position:\n", OS.get_window_position() ) ) @@ -19,6 +27,7 @@ func _fixed_process(delta): get_node("Label_Screen0_Position").set_text(str("Screen0 Position:\n",OS.get_screen_position())) + if(OS.get_screen_count() > 1): get_node("Button_Screen1").show() get_node("Label_Screen1_Resolution").show() @@ -42,6 +51,9 @@ func _fixed_process(delta): if( Input.is_action_pressed("ui_down")): OS.set_fullscreen(false) + get_node("Button_FixedSize").set_pressed( !OS.is_resizable() ) + + func _ready(): set_fixed_process(true) @@ -67,3 +79,15 @@ func _on_Button_Screen0_pressed(): func _on_Button_Screen1_pressed(): OS.set_screen(1) + + + + + +func _on_Button_FixedSize_pressed(): + if(OS.is_resizable()): + OS.set_resizable(false) + else: + OS.set_resizable(true) + + diff --git a/demos/misc/window_management/window_management.scn b/demos/misc/window_management/window_management.scn index 9d55174dce..befc177b5e 100644 Binary files a/demos/misc/window_management/window_management.scn and b/demos/misc/window_management/window_management.scn differ diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index d395e99210..f33c2556ba 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -223,7 +223,7 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi #endif } - // disable resizeable window + // disable resizable window if (!current_videomode.resizable) { XSizeHints *xsh; xsh = XAllocSizeHints(); @@ -239,7 +239,9 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi xsh->min_height = xwa.height; xsh->max_height = xwa.height; XSetWMNormalHints(x11_display, x11_window, xsh); + XFree(xsh); } + current_videomode.resizable; AudioDriverManagerSW::get_driver(p_audio_driver)->set_singleton(); @@ -277,19 +279,19 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi XChangeWindowAttributes(x11_display, x11_window,CWEventMask,&new_attr); - XClassHint* classHint; + XClassHint* classHint; - /* set the titlebar name */ - XStoreName(x11_display, x11_window, "Godot"); + /* set the titlebar name */ + XStoreName(x11_display, x11_window, "Godot"); - /* set the name and class hints for the window manager to use */ - classHint = XAllocClassHint(); - if (classHint) { - classHint->res_name = "Godot"; - classHint->res_class = "Godot"; - } - XSetClassHint(x11_display, x11_window, classHint); - XFree(classHint); + /* set the name and class hints for the window manager to use */ + classHint = XAllocClassHint(); + if (classHint) { + classHint->res_name = "Godot"; + classHint->res_class = "Godot"; + } + XSetClassHint(x11_display, x11_window, classHint); + XFree(classHint); wm_delete = XInternAtom(x11_display, "WM_DELETE_WINDOW", true); XSetWMProtocols(x11_display, x11_window, &wm_delete, 1); @@ -708,6 +710,9 @@ void OS_X11::set_fullscreen(bool p_enabled) { if(p_enabled && current_videomode.fullscreen) return; + if(!current_videomode.resizable) + set_resizable(true); + if(p_enabled) { window_data.size = get_window_size(); window_data.position = get_window_position(); @@ -734,11 +739,37 @@ void OS_X11::set_fullscreen(bool p_enabled) { } visual_server->init(); + } bool OS_X11::is_fullscreen() const { return current_videomode.fullscreen; } + +void OS_X11::set_resizable(bool p_enabled) { + + if(!current_videomode.fullscreen) { + XSizeHints *xsh; + xsh = XAllocSizeHints(); + xsh->flags = p_enabled ? 0L : PMinSize | PMaxSize; + if(!p_enabled) { + XWindowAttributes xwa; + XGetWindowAttributes(x11_display,x11_window,&xwa); + xsh->min_width = xwa.width; + xsh->max_width = xwa.width; + xsh->min_height = xwa.height; + xsh->max_height = xwa.height; + printf("%d %d\n", xwa.width, xwa.height); + } + XSetWMNormalHints(x11_display, x11_window, xsh); + XFree(xsh); + current_videomode.resizable = p_enabled; + } +} + +bool OS_X11::is_resizable() const { + return current_videomode.resizable; +} #endif InputModifierState OS_X11::get_key_modifier_state(unsigned int p_x11_state) { @@ -1688,6 +1719,4 @@ OS_X11::OS_X11() { minimized = false; xim_style=NULL; mouse_mode=MOUSE_MODE_VISIBLE; - - }; diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h index 72d212c131..d286efe7b8 100644 --- a/platform/x11/os_x11.h +++ b/platform/x11/os_x11.h @@ -160,10 +160,15 @@ class OS_X11 : public OS_Unix { Joystick joysticks[JOYSTICKS_MAX]; #ifdef EXPERIMENTAL_WM_API + // This struct saves the values of the window before going fullscreen + // to be able to restore the same state after leaving fullscreen struct { + bool resizable; Point2i position; Size2i size; - } window_data; + } window_data; + + bool maximized; void set_wm_border(bool p_enabled); void set_wm_fullscreen(bool p_enabled); #endif @@ -234,6 +239,8 @@ public: virtual void set_window_size(const Size2 p_size); virtual void set_fullscreen(bool p_enabled); virtual bool is_fullscreen() const; + virtual void set_resizable(bool p_enabled); + virtual bool is_resizable() const; #endif virtual void move_window_to_foreground(); -- cgit v1.2.3 From d42fa511a51db582849470316dfd1f0eee459350 Mon Sep 17 00:00:00 2001 From: hurikhan Date: Fri, 16 Jan 2015 13:49:46 +0900 Subject: rearrange the demo --- demos/misc/window_management/control.gd | 4 +--- demos/misc/window_management/window_management.scn | Bin 3897 -> 3931 bytes 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/demos/misc/window_management/control.gd b/demos/misc/window_management/control.gd index c867bd21db..043db8d489 100644 --- a/demos/misc/window_management/control.gd +++ b/demos/misc/window_management/control.gd @@ -19,9 +19,7 @@ func _fixed_process(delta): get_node("Label_Size").set_text(str("Size:\n", OS.get_window_size() ) ) - get_node("Label_Screen_Count").set_text( str("Screens:\n", OS.get_screen_count() ) ) - - get_node("Label_Screen_Current").set_text( str("Current:\n", OS.get_screen() ) ) + get_node("Label_Screen_Info").set_text( str("Screens:\n", OS.get_screen_count(),"\n\nCurrent:\n", OS.get_screen() ) ) get_node("Label_Screen0_Resolution").set_text( str("Screen0 Resolution:\n", OS.get_screen_size() ) ) diff --git a/demos/misc/window_management/window_management.scn b/demos/misc/window_management/window_management.scn index befc177b5e..a83897f9a0 100644 Binary files a/demos/misc/window_management/window_management.scn and b/demos/misc/window_management/window_management.scn differ -- cgit v1.2.3 From f1b9953d0b321a5564109e11b5326efa4624c70c Mon Sep 17 00:00:00 2001 From: hurikhan Date: Fri, 16 Jan 2015 14:44:41 +0900 Subject: fixing the warnings in os_x11.cpp --- platform/x11/os_x11.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index f33c2556ba..c6fdc24768 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -59,7 +59,7 @@ #include -#include "os/pc_joystick_map.h" +//#include "os/pc_joystick_map.h" #undef CursorShape @@ -120,10 +120,10 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi if (xim == NULL) { WARN_PRINT("XOpenIM failed"); - xim_style=NULL; + xim_style=0L; } else { ::XIMStyles *xim_styles=NULL; - xim_style=0; + xim_style=0L; char *imvalret=NULL; imvalret = XGetIMValues(xim, XNQueryInputStyle, &xim_styles, NULL); if (imvalret != NULL || xim_styles == NULL) { @@ -131,7 +131,7 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi } if (xim_styles) { - xim_style = 0; + xim_style = 0L; for (int i=0;icount_styles;i++) { if (xim_styles->supported_styles[i] == @@ -241,7 +241,6 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi XSetWMNormalHints(x11_display, x11_window, xsh); XFree(xsh); } - current_videomode.resizable; AudioDriverManagerSW::get_driver(p_audio_driver)->set_singleton(); @@ -287,8 +286,9 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi /* set the name and class hints for the window manager to use */ classHint = XAllocClassHint(); if (classHint) { - classHint->res_name = "Godot"; - classHint->res_class = "Godot"; + char wmclass[] = "Godot"; + classHint->res_name = wmclass; + classHint->res_class = wmclass; } XSetClassHint(x11_display, x11_window, classHint); XFree(classHint); @@ -845,11 +845,9 @@ void OS_X11::handle_key_event(XKeyEvent *p_event, bool p_echo) { KeySym keysym_keycode=0; // keysym used to find a keycode KeySym keysym_unicode=0; // keysym used to find unicode - int nbytes=0; // bytes the string takes - // XLookupString returns keysyms usable as nice scancodes/ char str[256+1]; - nbytes=XLookupString(xkeyevent, str, 256, &keysym_keycode, NULL); + XLookupString(xkeyevent, str, 256, &keysym_keycode, NULL); // Meanwhile, XLookupString returns keysyms useful for unicode. @@ -946,7 +944,7 @@ void OS_X11::handle_key_event(XKeyEvent *p_event, bool p_echo) { ::Time tresh=ABS(peek_event.xkey.time-xkeyevent->time); if (peek_event.type == KeyPress && tresh<5 ) { KeySym rk; - nbytes=XLookupString((XKeyEvent*)&peek_event, str, 256, &rk, NULL); + XLookupString((XKeyEvent*)&peek_event, str, 256, &rk, NULL); if (rk==keysym_keycode) { XEvent event; XNextEvent(x11_display, &event); //erase next event @@ -1605,6 +1603,7 @@ void OS_X11::process_joysticks() { #endif }; + void OS_X11::set_cursor_shape(CursorShape p_shape) { ERR_FAIL_INDEX(p_shape,CURSOR_MAX); @@ -1717,6 +1716,7 @@ OS_X11::OS_X11() { #endif minimized = false; - xim_style=NULL; + xim_style=0L; mouse_mode=MOUSE_MODE_VISIBLE; }; + -- cgit v1.2.3 From 716971655eb9ab7909447e2f5d4911b6f45164bb Mon Sep 17 00:00:00 2001 From: hurikhan Date: Sat, 17 Jan 2015 00:18:45 +0900 Subject: added the following methods: * set_minimized(bool) * bool is_minimized() * set_maximized(bool) * bool is_maximized() --- core/bind/core_bind.cpp | 22 +++- core/bind/core_bind.h | 12 +- core/os/os.h | 4 + demos/misc/window_management/control.gd | 33 +++-- demos/misc/window_management/window_management.scn | Bin 3931 -> 4111 bytes platform/x11/os_x11.cpp | 137 ++++++++++++++++++++- platform/x11/os_x11.h | 4 + 7 files changed, 194 insertions(+), 18 deletions(-) diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index 1fb6f96e71..6919c70a5f 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -228,6 +228,22 @@ void _OS::set_resizable(bool p_enabled) { bool _OS::is_resizable() const { return OS::get_singleton()->is_resizable(); } + +void _OS::set_minimized(bool p_enabled) { + OS::get_singleton()->set_minimized(p_enabled); +} + +bool _OS::is_minimized() const { + return OS::get_singleton()->is_minimized(); +} + +void _OS::set_maximized(bool p_enabled) { + OS::get_singleton()->set_maximized(p_enabled); +} + +bool _OS::is_maximized() const { + return OS::get_singleton()->is_maximized(); +} #endif void _OS::set_use_file_access_save_and_swap(bool p_enable) { @@ -698,7 +714,11 @@ void _OS::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_fullscreen","enabled"),&_OS::set_fullscreen); ObjectTypeDB::bind_method(_MD("is_fullscreen"),&_OS::is_fullscreen); ObjectTypeDB::bind_method(_MD("set_resizable","enabled"),&_OS::set_resizable); - ObjectTypeDB::bind_method(_MD("is_resizable"),&_OS::is_resizable); + ObjectTypeDB::bind_method(_MD("is_resizable"),&_OS::is_resizable); + ObjectTypeDB::bind_method(_MD("set_minimized", "enabled"),&_OS::set_minimized); + ObjectTypeDB::bind_method(_MD("is_minimized"),&_OS::is_minimized); + ObjectTypeDB::bind_method(_MD("set_maximized", "enabled"),&_OS::set_maximized); + ObjectTypeDB::bind_method(_MD("is_maximized"),&_OS::is_maximized); #endif ObjectTypeDB::bind_method(_MD("set_iterations_per_second","iterations_per_second"),&_OS::set_iterations_per_second); diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index 7ffd7e9e7c..b6f4f8eef4 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -118,10 +118,14 @@ public: virtual void set_window_position(const Point2& p_position); virtual Size2 get_window_size() const; virtual void set_window_size(const Size2& p_size); - void set_fullscreen(bool p_enabled); - bool is_fullscreen() const; - void set_resizable(bool p_enabled); - bool is_resizable() const; + virtual void set_fullscreen(bool p_enabled); + virtual bool is_fullscreen() const; + virtual void set_resizable(bool p_enabled); + virtual bool is_resizable() const; + virtual void set_minimized(bool p_enabled); + virtual bool is_minimized() const; + virtual void set_maximized(bool p_enabled); + virtual bool is_maximized() const; #endif Error native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track); diff --git a/core/os/os.h b/core/os/os.h index f1a9de1edf..c04a91e302 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -164,6 +164,10 @@ public: virtual bool is_fullscreen() const=0; virtual void set_resizable(bool p_enabled)=0; virtual bool is_resizable() const=0; + virtual void set_minimized(bool p_enabled)=0; + virtual bool is_minimized() const=0; + virtual void set_maximized(bool p_enabled)=0; + virtual bool is_maximized() const=0; #endif virtual void set_iterations_per_second(int p_ips); diff --git a/demos/misc/window_management/control.gd b/demos/misc/window_management/control.gd index 043db8d489..fd746cf036 100644 --- a/demos/misc/window_management/control.gd +++ b/demos/misc/window_management/control.gd @@ -13,17 +13,25 @@ func _fixed_process(delta): if(!OS.is_resizable()): modetext += "FixedSize\n" + if(OS.is_minimized()): + modetext += "Minimized\n" + + if(OS.is_maximized()): + modetext += "Maximized\n" + get_node("Label_Mode").set_text(modetext) get_node("Label_Position").set_text( str("Position:\n", OS.get_window_position() ) ) get_node("Label_Size").set_text(str("Size:\n", OS.get_window_size() ) ) - get_node("Label_Screen_Info").set_text( str("Screens:\n", OS.get_screen_count(),"\n\nCurrent:\n", OS.get_screen() ) ) + get_node("Label_Screen_Count").set_text( str("Screens:\n", OS.get_screen_count() ) ) + + get_node("Label_Screen_Current").set_text( str("Current:\n", OS.get_screen() ) ) get_node("Label_Screen0_Resolution").set_text( str("Screen0 Resolution:\n", OS.get_screen_size() ) ) - get_node("Label_Screen0_Position").set_text(str("Screen0 Position:\n",OS.get_screen_position())) + get_node("Label_Screen0_Position").set_text(str("Screen0 Position:\n",OS.get_screen_position() ) ) if(OS.get_screen_count() > 1): @@ -50,8 +58,9 @@ func _fixed_process(delta): OS.set_fullscreen(false) get_node("Button_FixedSize").set_pressed( !OS.is_resizable() ) - - + get_node("Button_Minimized").set_pressed( OS.is_minimized() ) + get_node("Button_Maximized").set_pressed( OS.is_maximized() ) + func _ready(): set_fixed_process(true) @@ -79,9 +88,6 @@ func _on_Button_Screen1_pressed(): OS.set_screen(1) - - - func _on_Button_FixedSize_pressed(): if(OS.is_resizable()): OS.set_resizable(false) @@ -89,3 +95,16 @@ func _on_Button_FixedSize_pressed(): OS.set_resizable(true) + +func _on_Button_Minimized_pressed(): + if(OS.is_minimized()): + OS.set_minimized(false) + else: + OS.set_minimized(true) + + +func _on_Button_Maximized_pressed(): + if(OS.is_maximized()): + OS.set_maximized(false) + else: + OS.set_maximized(true) diff --git a/demos/misc/window_management/window_management.scn b/demos/misc/window_management/window_management.scn index a83897f9a0..635f6f6f28 100644 Binary files a/demos/misc/window_management/window_management.scn and b/demos/misc/window_management/window_management.scn differ diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index c6fdc24768..ef92d190c9 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -37,7 +37,16 @@ #include "X11/Xutil.h" #ifdef EXPERIMENTAL_WM_API +#include "X11/Xatom.h" #include "X11/extensions/Xinerama.h" +// ICCCM +#define WM_NormalState 1L // window normal state +#define WM_IconicState 3L // window minimized + +// EWMH +#define _NET_WM_STATE_REMOVE 0L // remove/unset property +#define _NET_WM_STATE_ADD 1L // add/set property +#define _NET_WM_STATE_TOGGLE 2L // toggle property #endif #include "main/main.h" @@ -214,6 +223,8 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureNotifyMask, &xev); #else + minimized = false; + minimized = false; window_data.position.x = 0; window_data.position.y = 0; window_data.size.width = 800; @@ -549,7 +560,7 @@ void OS_X11::set_wm_border(bool p_enabled) { } void OS_X11::set_wm_fullscreen(bool p_enabled) { - // code for netwm-compliants + // Using EWMH -- Extened Window Manager Hints XEvent xev; Atom wm_state = XInternAtom(x11_display, "_NET_WM_STATE", False); Atom wm_fullscreen = XInternAtom(x11_display, "_NET_WM_STATE_FULLSCREEN", False); @@ -559,7 +570,7 @@ void OS_X11::set_wm_fullscreen(bool p_enabled) { xev.xclient.window = x11_window; xev.xclient.message_type = wm_state; xev.xclient.format = 32; - xev.xclient.data.l[0] = p_enabled ? 1L : 0L; + xev.xclient.data.l[0] = p_enabled ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE; xev.xclient.data.l[1] = wm_fullscreen; xev.xclient.data.l[2] = 0; @@ -567,6 +578,7 @@ void OS_X11::set_wm_fullscreen(bool p_enabled) { } int OS_X11::get_screen_count() const { + // Using Xinerama Extension int event_base, error_base; const Bool ext_okay = XineramaQueryExtension(x11_display, &event_base, &error_base); if( !ext_okay ) return 0; @@ -611,6 +623,7 @@ void OS_X11::set_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); @@ -625,6 +638,7 @@ Point2 OS_X11::get_screen_position(int p_screen) const { } Size2 OS_X11::get_screen_size(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 Size2i(0,0); @@ -651,14 +665,14 @@ void OS_X11::set_window_position(const Point2& p_position) { if( current_videomode.fullscreen ) return; - // _NET_FRAME_EXTENTS + // Using EWMH -- Extended Window Manager Hints + // to get the size of the decoration Atom property = XInternAtom(x11_display,"_NET_FRAME_EXTENTS", True); Atom type; int format; unsigned long len; unsigned long remaining; unsigned char *data = NULL; - //long *extends; int result; result = XGetWindowProperty( @@ -759,7 +773,6 @@ void OS_X11::set_resizable(bool p_enabled) { xsh->max_width = xwa.width; xsh->min_height = xwa.height; xsh->max_height = xwa.height; - printf("%d %d\n", xwa.width, xwa.height); } XSetWMNormalHints(x11_display, x11_window, xsh); XFree(xsh); @@ -770,6 +783,119 @@ void OS_X11::set_resizable(bool p_enabled) { bool OS_X11::is_resizable() const { return current_videomode.resizable; } + +void OS_X11::set_minimized(bool p_enabled) { + // Using ICCCM -- Inter-Client Communication Conventions Manual + XEvent xev; + Atom wm_change = XInternAtom(x11_display, "WM_CHANGE_STATE", False); + + memset(&xev, 0, sizeof(xev)); + xev.type = ClientMessage; + xev.xclient.window = x11_window; + xev.xclient.message_type = wm_change; + xev.xclient.format = 32; + xev.xclient.data.l[0] = p_enabled ? WM_IconicState : WM_NormalState; + + XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureNotifyMask, &xev); +} + +bool OS_X11::is_minimized() const { + // Using ICCCM -- Inter-Client Communication Conventions Manual + Atom property = XInternAtom(x11_display,"WM_STATE", True); + Atom type; + int format; + unsigned long len; + unsigned long remaining; + unsigned char *data = NULL; + + int result = XGetWindowProperty( + x11_display, + x11_window, + property, + 0, + 32, + False, + AnyPropertyType, + &type, + &format, + &len, + &remaining, + &data + ); + + if( result == Success ) { + long *state = (long *) data; + if( state[0] == 3L ) + return true; + } + return false; +} + +void OS_X11::set_maximized(bool p_enabled) { + // Using EWMH -- Extended Window Manager Hints + XEvent xev; + Atom wm_state = XInternAtom(x11_display, "_NET_WM_STATE", False); + Atom wm_max_horz = XInternAtom(x11_display, "_NET_WM_STATE_MAXIMIZED_HORZ", False); + Atom wm_max_vert = XInternAtom(x11_display, "_NET_WM_STATE_MAXIMIZED_VERT", False); + + memset(&xev, 0, sizeof(xev)); + xev.type = ClientMessage; + xev.xclient.window = x11_window; + xev.xclient.message_type = wm_state; + xev.xclient.format = 32; + xev.xclient.data.l[0] = p_enabled ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE; + xev.xclient.data.l[1] = wm_max_horz; + xev.xclient.data.l[2] = wm_max_vert; + + XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureNotifyMask, &xev); + + maximized = p_enabled; +} + +bool OS_X11::is_maximized() const { + // Using EWMH -- Extended Window Manager Hints + Atom property = XInternAtom(x11_display,"_NET_WM_STATE",False ); + Atom type; + int format; + unsigned long len; + unsigned long remaining; + unsigned char *data = NULL; + + int result = XGetWindowProperty( + x11_display, + x11_window, + property, + 0, + 1024, + False, + XA_ATOM, + &type, + &format, + &len, + &remaining, + &data + ); + + if(result == Success) { + Atom *atoms = (Atom*) data; + Atom wm_max_horz = XInternAtom(x11_display, "_NET_WM_STATE_MAXIMIZED_HORZ", False); + Atom wm_max_vert = XInternAtom(x11_display, "_NET_WM_STATE_MAXIMIZED_VERT", False); + bool found_wm_max_horz = false; + bool found_wm_max_vert = false; + + for( unsigned int i=0; i < len; i++ ) { + if( atoms[i] == wm_max_horz ) + found_wm_max_horz = true; + if( atoms[i] == wm_max_vert ) + found_wm_max_vert = true; + + if( found_wm_max_horz && found_wm_max_vert ) + return true; + } + } + + return false; +} #endif InputModifierState OS_X11::get_key_modifier_state(unsigned int p_x11_state) { @@ -1719,4 +1845,3 @@ OS_X11::OS_X11() { xim_style=0L; mouse_mode=MOUSE_MODE_VISIBLE; }; - diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h index d286efe7b8..557052ab69 100644 --- a/platform/x11/os_x11.h +++ b/platform/x11/os_x11.h @@ -241,6 +241,10 @@ public: virtual bool is_fullscreen() const; virtual void set_resizable(bool p_enabled); virtual bool is_resizable() const; + virtual void set_minimized(bool p_enabled); + virtual bool is_minimized() const; + virtual void set_maximized(bool p_enabled); + virtual bool is_maximized() const; #endif virtual void move_window_to_foreground(); -- cgit v1.2.3 From 6185949f6a4f6eae78d8afca2dd787dbf063d675 Mon Sep 17 00:00:00 2001 From: hurikhan Date: Sat, 17 Jan 2015 02:36:07 +0900 Subject: Make it set_minimized() + set_maximized() work in both worlds: Unity and LXDE --- platform/x11/os_x11.cpp | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index ef92d190c9..fd2470a37a 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -552,7 +552,7 @@ void OS_X11::set_wm_border(bool p_enabled) { Hints hints; Atom property; hints.flags = 2; - hints.decorations = p_enabled ? 1L : 0L;; + hints.decorations = p_enabled ? 1L : 0L; property = XInternAtom(x11_display, "_MOTIF_WM_HINTS", True); XChangeProperty(x11_display, x11_window, property, property, 32, PropModeReplace, (unsigned char *)&hints, 5); XMapRaised(x11_display, x11_window); @@ -700,7 +700,6 @@ void OS_X11::set_window_position(const Point2& p_position) { top = extends[2]; XFree(data); - data = NULL; } XMoveWindow(x11_display,x11_window,p_position.x - left,p_position.y - top); @@ -785,6 +784,10 @@ bool OS_X11::is_resizable() const { } void OS_X11::set_minimized(bool p_enabled) { + + if( is_fullscreen() ) + set_fullscreen(false); + // Using ICCCM -- Inter-Client Communication Conventions Manual XEvent xev; Atom wm_change = XInternAtom(x11_display, "WM_CHANGE_STATE", False); @@ -797,6 +800,20 @@ void OS_X11::set_minimized(bool p_enabled) { xev.xclient.data.l[0] = p_enabled ? WM_IconicState : WM_NormalState; XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureNotifyMask, &xev); + + //XEvent xev; + Atom wm_state = XInternAtom(x11_display, "_NET_WM_STATE", False); + Atom wm_hidden = XInternAtom(x11_display, "_NET_WM_STATE_HIDDEN", False); + + memset(&xev, 0, sizeof(xev)); + xev.type = ClientMessage; + xev.xclient.window = x11_window; + xev.xclient.message_type = wm_state; + xev.xclient.format = 32; + xev.xclient.data.l[0] = _NET_WM_STATE_ADD; + xev.xclient.data.l[1] = wm_hidden; + + XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureRedirectMask | SubstructureNotifyMask, &xev); } bool OS_X11::is_minimized() const { @@ -825,7 +842,7 @@ bool OS_X11::is_minimized() const { if( result == Success ) { long *state = (long *) data; - if( state[0] == 3L ) + if( state[0] == WM_IconicState ) return true; } return false; @@ -847,7 +864,7 @@ void OS_X11::set_maximized(bool p_enabled) { xev.xclient.data.l[1] = wm_max_horz; xev.xclient.data.l[2] = wm_max_vert; - XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureNotifyMask, &xev); + XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureRedirectMask | SubstructureNotifyMask, &xev); maximized = p_enabled; } @@ -892,6 +909,7 @@ bool OS_X11::is_maximized() const { if( found_wm_max_horz && found_wm_max_vert ) return true; } + XFree(atoms); } return false; -- cgit v1.2.3 From f1dc00e380439078c93d00af2f85d138a9400b2e Mon Sep 17 00:00:00 2001 From: hurikhan Date: Sat, 17 Jan 2015 19:43:12 +0900 Subject: * cleanup window state handling * first attemps in handling ALT+TABa (WIP) --- demos/misc/window_management/control.gd | 28 ++++++---- demos/misc/window_management/window_management.scn | Bin 4111 -> 4052 bytes platform/x11/os_x11.cpp | 62 ++++++++++----------- 3 files changed, 47 insertions(+), 43 deletions(-) diff --git a/demos/misc/window_management/control.gd b/demos/misc/window_management/control.gd index fd746cf036..4929b1376c 100644 --- a/demos/misc/window_management/control.gd +++ b/demos/misc/window_management/control.gd @@ -25,9 +25,9 @@ func _fixed_process(delta): get_node("Label_Size").set_text(str("Size:\n", OS.get_window_size() ) ) - get_node("Label_Screen_Count").set_text( str("Screens:\n", OS.get_screen_count() ) ) + get_node("Label_Screen_Count").set_text( str("Screen_Count:\n", OS.get_screen_count() ) ) - get_node("Label_Screen_Current").set_text( str("Current:\n", OS.get_screen() ) ) + get_node("Label_Screen_Current").set_text( str("Screen:\n", OS.get_screen() ) ) get_node("Label_Screen0_Resolution").set_text( str("Screen0 Resolution:\n", OS.get_screen_size() ) ) @@ -35,12 +35,14 @@ func _fixed_process(delta): if(OS.get_screen_count() > 1): + get_node("Button_Screen0").show() get_node("Button_Screen1").show() get_node("Label_Screen1_Resolution").show() get_node("Label_Screen1_Position").show() get_node("Label_Screen1_Resolution").set_text( str("Screen1 Resolution:\n", OS.get_screen_size(1) ) ) get_node("Label_Screen1_Position").set_text( str("Screen1 Position:\n", OS.get_screen_position(1) ) ) else: + get_node("Button_Screen0").hide() get_node("Button_Screen1").hide() get_node("Label_Screen1_Resolution").hide() get_node("Label_Screen1_Position").hide() @@ -57,19 +59,14 @@ func _fixed_process(delta): if( Input.is_action_pressed("ui_down")): OS.set_fullscreen(false) + get_node("Button_Fullscreen").set_pressed( OS.is_fullscreen() ) get_node("Button_FixedSize").set_pressed( !OS.is_resizable() ) get_node("Button_Minimized").set_pressed( OS.is_minimized() ) get_node("Button_Maximized").set_pressed( OS.is_maximized() ) - -func _ready(): - set_fixed_process(true) -func _on_Fullscreen_toggled( pressed ): - if(pressed): - OS.set_fullscreen(true) - else: - OS.set_fullscreen(false) +func _ready(): + set_fixed_process(true) func _on_Button_MoveTo_pressed(): @@ -88,12 +85,18 @@ func _on_Button_Screen1_pressed(): OS.set_screen(1) +func _on_Button_Fullscreen_pressed(): + if(OS.is_fullscreen()): + OS.set_fullscreen(false) + else: + OS.set_fullscreen(true) + + func _on_Button_FixedSize_pressed(): if(OS.is_resizable()): OS.set_resizable(false) else: OS.set_resizable(true) - func _on_Button_Minimized_pressed(): @@ -108,3 +111,6 @@ func _on_Button_Maximized_pressed(): OS.set_maximized(false) else: OS.set_maximized(true) + + + diff --git a/demos/misc/window_management/window_management.scn b/demos/misc/window_management/window_management.scn index 635f6f6f28..3d62d4ecc1 100644 Binary files a/demos/misc/window_management/window_management.scn and b/demos/misc/window_management/window_management.scn differ diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index fd2470a37a..d4328d9da3 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -229,7 +229,7 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi window_data.position.y = 0; window_data.size.width = 800; window_data.size.height = 600; - set_wm_border(false); + //set_wm_border(false); set_wm_fullscreen(true); #endif } @@ -574,7 +574,7 @@ void OS_X11::set_wm_fullscreen(bool p_enabled) { xev.xclient.data.l[1] = wm_fullscreen; xev.xclient.data.l[2] = 0; - XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureNotifyMask, &xev); + XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureRedirectMask | SubstructureNotifyMask, &xev); } int OS_X11::get_screen_count() const { @@ -661,10 +661,6 @@ Point2 OS_X11::get_window_position() const { } void OS_X11::set_window_position(const Point2& p_position) { - - if( current_videomode.fullscreen ) - return; - // Using EWMH -- Extended Window Manager Hints // to get the size of the decoration Atom property = XInternAtom(x11_display,"_NET_FRAME_EXTENTS", True); @@ -712,14 +708,12 @@ Size2 OS_X11::get_window_size() const { } void OS_X11::set_window_size(const Size2 p_size) { - if( current_videomode.fullscreen ) - return; - XResizeWindow(x11_display, x11_window, p_size.x, p_size.y); } void OS_X11::set_fullscreen(bool p_enabled) { +#if 0 if(p_enabled && current_videomode.fullscreen) return; @@ -750,6 +744,9 @@ void OS_X11::set_fullscreen(bool p_enabled) { current_videomode.fullscreen = False; } +#endif + set_wm_fullscreen(p_enabled); + current_videomode.fullscreen = p_enabled; visual_server->init(); @@ -760,23 +757,20 @@ bool OS_X11::is_fullscreen() const { } void OS_X11::set_resizable(bool p_enabled) { - - if(!current_videomode.fullscreen) { - XSizeHints *xsh; - xsh = XAllocSizeHints(); - xsh->flags = p_enabled ? 0L : PMinSize | PMaxSize; - if(!p_enabled) { - XWindowAttributes xwa; - XGetWindowAttributes(x11_display,x11_window,&xwa); - xsh->min_width = xwa.width; - xsh->max_width = xwa.width; - xsh->min_height = xwa.height; - xsh->max_height = xwa.height; - } - XSetWMNormalHints(x11_display, x11_window, xsh); - XFree(xsh); - current_videomode.resizable = p_enabled; + XSizeHints *xsh; + xsh = XAllocSizeHints(); + xsh->flags = p_enabled ? 0L : PMinSize | PMaxSize; + if(!p_enabled) { + XWindowAttributes xwa; + XGetWindowAttributes(x11_display,x11_window,&xwa); + xsh->min_width = xwa.width; + xsh->max_width = xwa.width; + xsh->min_height = xwa.height; + xsh->max_height = xwa.height; } + XSetWMNormalHints(x11_display, x11_window, xsh); + XFree(xsh); + current_videomode.resizable = p_enabled; } bool OS_X11::is_resizable() const { @@ -784,10 +778,6 @@ bool OS_X11::is_resizable() const { } void OS_X11::set_minimized(bool p_enabled) { - - if( is_fullscreen() ) - set_fullscreen(false); - // Using ICCCM -- Inter-Client Communication Conventions Manual XEvent xev; Atom wm_change = XInternAtom(x11_display, "WM_CHANGE_STATE", False); @@ -799,7 +789,7 @@ void OS_X11::set_minimized(bool p_enabled) { xev.xclient.format = 32; xev.xclient.data.l[0] = p_enabled ? WM_IconicState : WM_NormalState; - XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureNotifyMask, &xev); + XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureRedirectMask | SubstructureNotifyMask, &xev); //XEvent xev; Atom wm_state = XInternAtom(x11_display, "_NET_WM_STATE", False); @@ -1152,13 +1142,16 @@ void OS_X11::process_xevents() { break; case VisibilityNotify: { - XVisibilityEvent * visibility = (XVisibilityEvent *)&event; minimized = (visibility->state == VisibilityFullyObscured); - } break; case FocusIn: + if(current_videomode.fullscreen) { + set_minimized(false); + set_wm_fullscreen(true); + visual_server->init(); + } main_loop->notification(MainLoop::NOTIFICATION_WM_FOCUS_IN); if (mouse_mode==MOUSE_MODE_CAPTURED) { XGrabPointer(x11_display, x11_window, True, @@ -1169,6 +1162,11 @@ void OS_X11::process_xevents() { break; case FocusOut: + if(current_videomode.fullscreen) { + set_wm_fullscreen(false); + set_minimized(true); + visual_server->init(); + } main_loop->notification(MainLoop::NOTIFICATION_WM_FOCUS_OUT); if (mouse_mode==MOUSE_MODE_CAPTURED) { //dear X11, I try, I really try, but you never work, you do whathever you want. -- cgit v1.2.3 From dfb5a1d5e1318d91f26c0f7663afe861005104c8 Mon Sep 17 00:00:00 2001 From: hurikhan Date: Sun, 18 Jan 2015 00:28:04 +0900 Subject: * multi_screen testing + bugfixes * ALT-TAB is working * tested on Ubuntu 14.10 Unity + LXDE * minor cleanup --- demos/misc/window_management/engine.cfg | 2 + demos/misc/window_management/window_management.scn | Bin 4052 -> 4030 bytes platform/x11/os_x11.cpp | 48 ++++++++++++++------- platform/x11/os_x11.h | 10 +---- 4 files changed, 35 insertions(+), 25 deletions(-) diff --git a/demos/misc/window_management/engine.cfg b/demos/misc/window_management/engine.cfg index 2accafe43e..6ce3d51aee 100644 --- a/demos/misc/window_management/engine.cfg +++ b/demos/misc/window_management/engine.cfg @@ -8,3 +8,5 @@ icon="icon.png" fullscreen=false resizable=true +width=800 +height=600 diff --git a/demos/misc/window_management/window_management.scn b/demos/misc/window_management/window_management.scn index 3d62d4ecc1..baf03bdfd1 100644 Binary files a/demos/misc/window_management/window_management.scn and b/demos/misc/window_management/window_management.scn differ diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index d4328d9da3..d711cea42e 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -42,7 +42,6 @@ // ICCCM #define WM_NormalState 1L // window normal state #define WM_IconicState 3L // window minimized - // EWMH #define _NET_WM_STATE_REMOVE 0L // remove/unset property #define _NET_WM_STATE_ADD 1L // add/set property @@ -192,9 +191,9 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi visual_server =memnew(VisualServerWrapMT(visual_server,get_render_thread_mode()==RENDER_SEPARATE_THREAD)); } +#ifndef EXPERIMENTAL_WM_API // borderless fullscreen window mode if (current_videomode.fullscreen) { -#ifndef EXPERIMENTAL_WM_API // needed for lxde/openbox, possibly others Hints hints; Atom property; @@ -222,16 +221,6 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi xev.xclient.data.l[2] = 0; XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureNotifyMask, &xev); -#else - minimized = false; - minimized = false; - window_data.position.x = 0; - window_data.position.y = 0; - window_data.size.width = 800; - window_data.size.height = 600; - //set_wm_border(false); - set_wm_fullscreen(true); -#endif } // disable resizable window @@ -252,6 +241,21 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi XSetWMNormalHints(x11_display, x11_window, xsh); XFree(xsh); } +#else + if (current_videomode.fullscreen) { + minimized = false; + maximized = false; + //set_wm_border(false); + set_wm_fullscreen(true); + } + if (!current_videomode.resizable) { + int screen = get_screen(); + Size2i screen_size = get_screen_size(screen); + set_window_size(screen_size); + set_resizable(false); + } +#endif + AudioDriverManagerSW::get_driver(p_audio_driver)->set_singleton(); @@ -519,7 +523,6 @@ OS::MouseMode OS_X11::get_mouse_mode() const { int OS_X11::get_mouse_button_state() const { - return last_button_state; } @@ -547,6 +550,8 @@ void OS_X11::get_fullscreen_mode_list(List *p_list,int p_screen) cons } #ifdef EXPERIMENTAL_WM_API +#if 0 +// Just now not needed. Can be used for a possible OS.set_border(bool) method void OS_X11::set_wm_border(bool p_enabled) { // needed for lxde/openbox, possibly others Hints hints; @@ -558,6 +563,7 @@ void OS_X11::set_wm_border(bool p_enabled) { XMapRaised(x11_display, x11_window); //XMoveResizeWindow(x11_display, x11_window, 0, 0, 800, 800); } +#endif void OS_X11::set_wm_fullscreen(bool p_enabled) { // Using EWMH -- Extened Window Manager Hints @@ -657,7 +663,11 @@ Point2 OS_X11::get_window_position() const { int x,y; Window child; XTranslateCoordinates( x11_display, x11_window, DefaultRootWindow(x11_display), 0, 0, &x, &y, &child); - return Point2i(x,y); + + int screen = get_screen(); + Point2i screen_position = get_screen_position(screen); + + return Point2i(x-screen_position.x, y-screen_position.y); } void OS_X11::set_window_position(const Point2& p_position) { @@ -698,6 +708,12 @@ void OS_X11::set_window_position(const Point2& p_position) { XFree(data); } + int screen = get_screen(); + Point2i screen_position = get_screen_position(screen); + + left -= screen_position.x; + top -= screen_position.y; + XMoveWindow(x11_display,x11_window,p_position.x - left,p_position.y - top); } @@ -1146,9 +1162,9 @@ void OS_X11::process_xevents() { minimized = (visibility->state == VisibilityFullyObscured); } break; - case FocusIn: + case FocusIn: + minimized = false; if(current_videomode.fullscreen) { - set_minimized(false); set_wm_fullscreen(true); visual_server->init(); } diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h index 557052ab69..b47c5db069 100644 --- a/platform/x11/os_x11.h +++ b/platform/x11/os_x11.h @@ -160,16 +160,8 @@ class OS_X11 : public OS_Unix { Joystick joysticks[JOYSTICKS_MAX]; #ifdef EXPERIMENTAL_WM_API - // This struct saves the values of the window before going fullscreen - // to be able to restore the same state after leaving fullscreen - struct { - bool resizable; - Point2i position; - Size2i size; - } window_data; - bool maximized; - void set_wm_border(bool p_enabled); + //void set_wm_border(bool p_enabled); void set_wm_fullscreen(bool p_enabled); #endif -- cgit v1.2.3 From 94d94a08558c83fb6e447c3e1ed858cf39c0e1ba Mon Sep 17 00:00:00 2001 From: hurikhan Date: Thu, 22 Jan 2015 01:14:50 +0900 Subject: * fix compilation without scons experimental_wm_api=yes * Extended the demo with an addional MouseGrab Test --- demos/misc/window_management/control.gd | 6 ++++-- demos/misc/window_management/engine.cfg | 7 +++++++ demos/misc/window_management/window_management.scn | Bin 4030 -> 4268 bytes platform/x11/os_x11.cpp | 10 +++++----- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/demos/misc/window_management/control.gd b/demos/misc/window_management/control.gd index 4929b1376c..6dc9282149 100644 --- a/demos/misc/window_management/control.gd +++ b/demos/misc/window_management/control.gd @@ -33,7 +33,6 @@ func _fixed_process(delta): get_node("Label_Screen0_Position").set_text(str("Screen0 Position:\n",OS.get_screen_position() ) ) - if(OS.get_screen_count() > 1): get_node("Button_Screen0").show() get_node("Button_Screen1").show() @@ -63,6 +62,7 @@ func _fixed_process(delta): get_node("Button_FixedSize").set_pressed( !OS.is_resizable() ) get_node("Button_Minimized").set_pressed( OS.is_minimized() ) get_node("Button_Maximized").set_pressed( OS.is_maximized() ) + get_node("Button_Mouse_Grab").set_pressed( Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED ) func _ready(): @@ -113,4 +113,6 @@ func _on_Button_Maximized_pressed(): OS.set_maximized(true) - +func _on_Button_Mouse_Grab_pressed(): + var observer = get_node("../Observer") + observer.state = observer.STATE_GRAB diff --git a/demos/misc/window_management/engine.cfg b/demos/misc/window_management/engine.cfg index 6ce3d51aee..c53bd45fb7 100644 --- a/demos/misc/window_management/engine.cfg +++ b/demos/misc/window_management/engine.cfg @@ -10,3 +10,10 @@ fullscreen=false resizable=true width=800 height=600 + +[input] + +move_forward=[key(W)] +move_backwards=[key(S)] +move_left=[key(A)] +move_right=[key(D)] diff --git a/demos/misc/window_management/window_management.scn b/demos/misc/window_management/window_management.scn index baf03bdfd1..40e6e64cef 100644 Binary files a/demos/misc/window_management/window_management.scn and b/demos/misc/window_management/window_management.scn differ diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index d711cea42e..fa3701aeef 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -177,11 +177,7 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi context_gl = memnew( ContextGL_X11( x11_display, x11_window,current_videomode, false ) ); context_gl->initialize(); - if (true) { - rasterizer = memnew( RasterizerGLES2 ); - } else { - //rasterizer = memnew( RasterizerGLES1 ); - }; + rasterizer = memnew( RasterizerGLES2 ); #endif visual_server = memnew( VisualServerRaster(rasterizer) ); @@ -1164,10 +1160,12 @@ void OS_X11::process_xevents() { case FocusIn: minimized = false; +#ifdef EXPERIMENTAL_WM_API if(current_videomode.fullscreen) { set_wm_fullscreen(true); visual_server->init(); } +#endif main_loop->notification(MainLoop::NOTIFICATION_WM_FOCUS_IN); if (mouse_mode==MOUSE_MODE_CAPTURED) { XGrabPointer(x11_display, x11_window, True, @@ -1178,11 +1176,13 @@ void OS_X11::process_xevents() { break; case FocusOut: +#ifdef EXPERIMENTAL_WM_API if(current_videomode.fullscreen) { set_wm_fullscreen(false); set_minimized(true); visual_server->init(); } +#endif main_loop->notification(MainLoop::NOTIFICATION_WM_FOCUS_OUT); if (mouse_mode==MOUSE_MODE_CAPTURED) { //dear X11, I try, I really try, but you never work, you do whathever you want. -- cgit v1.2.3 From 2204914abfc939e16cc595a6b175ff74b6552a6c Mon Sep 17 00:00:00 2001 From: hurikhan Date: Thu, 22 Jan 2015 01:54:17 +0900 Subject: * observer scene for the demo --- demos/misc/window_management/observer/observer.gd | 78 ++++++++++++++++ demos/misc/window_management/observer/observer.scn | Bin 0 -> 1786 bytes .../window_management/observer/observer_hud.gd | 98 +++++++++++++++++++++ 3 files changed, 176 insertions(+) create mode 100644 demos/misc/window_management/observer/observer.gd create mode 100644 demos/misc/window_management/observer/observer.scn create mode 100644 demos/misc/window_management/observer/observer_hud.gd diff --git a/demos/misc/window_management/observer/observer.gd b/demos/misc/window_management/observer/observer.gd new file mode 100644 index 0000000000..7bec0f5301 --- /dev/null +++ b/demos/misc/window_management/observer/observer.gd @@ -0,0 +1,78 @@ + +extends Spatial + +var r_pos = Vector2() +var state + +const STATE_MENU=0 +const STATE_GRAB=1 + +func direction(vector): + var v = get_node("Camera").get_global_transform().basis * vector + v = v.normalized() + + return v + + +func impulse(event, action): + if(event.is_action(action) && event.is_pressed() && !event.is_echo()): + return true + else: + return false + + +func _fixed_process(delta): + + if(state != STATE_GRAB): + return + + if(Input.get_mouse_mode() != Input.MOUSE_MODE_CAPTURED): + Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) + + var dir = Vector3() + var cam = get_global_transform() + var org = get_translation() + + if (Input.is_action_pressed("move_forward")): + dir += direction(Vector3(0,0,-1)) + if (Input.is_action_pressed("move_backwards")): + dir += direction(Vector3(0,0,1)) + if (Input.is_action_pressed("move_left")): + dir += direction(Vector3(-1,0,0)) + if (Input.is_action_pressed("move_right")): + dir += direction(Vector3(1,0,0)) + + dir = dir.normalized() + + move(dir * 10 * delta) + var d = delta * 0.1 + + var yaw = get_transform().rotated(Vector3(0,1,0), d * r_pos.x) + set_transform(yaw) + + var cam = get_node("Camera") + var pitch = cam.get_transform().rotated(Vector3(1,0,0), d * r_pos.y) + cam.set_transform(pitch) + + r_pos.x = 0.0 + r_pos.y = 0.0 + + +func _input( event ): + if(event.type == InputEvent.MOUSE_MOTION): + r_pos = event.relative_pos + + if(impulse(event, "ui_cancel")): + if(state == STATE_GRAB): + Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) + state = STATE_MENU + else: + Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) + state = STATE_GRAB + + +func _ready(): + set_fixed_process(true) + set_process_input(true) + + state = STATE_MENU diff --git a/demos/misc/window_management/observer/observer.scn b/demos/misc/window_management/observer/observer.scn new file mode 100644 index 0000000000..da29ad62b8 Binary files /dev/null and b/demos/misc/window_management/observer/observer.scn differ diff --git a/demos/misc/window_management/observer/observer_hud.gd b/demos/misc/window_management/observer/observer_hud.gd new file mode 100644 index 0000000000..24e81b02ba --- /dev/null +++ b/demos/misc/window_management/observer/observer_hud.gd @@ -0,0 +1,98 @@ +var parent + +func printdebug(): + + var s + + if(parent.state == parent.STATE_GAME): + s = str( "TIME_FPS: ", Performance.get_monitor(Performance.TIME_FPS), "\n") + s += str("OBJECT_COUNT: ", Performance.get_monitor(Performance.OBJECT_COUNT), "\n") + s += str("OBJECT_RESOURCE_COUNT : ", Performance.get_monitor(Performance.OBJECT_RESOURCE_COUNT), "\n") + s += str("OBJECT_NODE_COUNT : ", Performance.get_monitor(Performance.OBJECT_NODE_COUNT), "\n") + s += str("RENDER_OBJECTS_IN_FRAME : ", Performance.get_monitor(Performance.RENDER_OBJECTS_IN_FRAME), "\n") + s += str("RENDER_VERTICES_IN_FRAME : ", Performance.get_monitor(Performance.RENDER_VERTICES_IN_FRAME), "\n") + s += str("RENDER_DRAW_CALLS_IN_FRAME : ", Performance.get_monitor(Performance.RENDER_DRAW_CALLS_IN_FRAME), "\n") + s += str("RENDER_VERTICES_IN_FRAME : ", Performance.get_monitor(Performance.RENDER_VERTICES_IN_FRAME), "\n") + # s += str("RENDER_USAGE_VIDEO_MEM_TOTAL : ", Performance.get_monitor(Performance.RENDER_USAGE_VIDEO_MEM_TOTAL), "\n") + # s += str("RENDER_VIDEO_MEM_USED : ", Performance.get_monitor(Performance.RENDER_VIDEO_MEM_USED), "\n") + # s += str("RENDER_TEXTURE_MEM_USED : ", Performance.get_monitor(Performance.RENDER_TEXTURE_MEM_USED), "\n") + # s += str("RENDER_VERTEX_MEM_USED : ", Performance.get_monitor(Performance.RENDER_VERTEX_MEM_USED), "\n") + s += str("CUBES: ", get_node("/root/World").world.size(), "\n") + else: + s = "" + + get_node("Label_Debug").set_text(s) + + +func _fixed_process(delta): + parent = get_parent() + + printdebug() + + if( parent.state == parent.STATE_MENU ): + get_node("Menu").show() + else: + get_node("Menu").hide() + + + +func _ready(): + set_fixed_process(true) + + +func _on_Fullscreen_toggled( pressed ): + if( pressed ): + OS.set_fullscreen(true) + else: + OS.set_fullscreen(false) + + +func _on_DebugInfo_toggled( pressed ): + if( pressed ): + get_node("Label_Debug").show() + else: + get_node("Label_Debug").hide() + + +func _on_Save_pressed(): + var file_dialog = get_node("Menu/SaveDialog") + file_dialog.clear_filters() + file_dialog.add_filter("*.json") + file_dialog.set_mode(3) + file_dialog.show() + file_dialog._update_file_list() + + +func _on_SaveDialog_file_selected( path ): + get_node("/root/World").save_world( path ) + + +func _on_Load_pressed(): + var file_dialog = get_node("Menu/LoadDialog") + file_dialog.clear_filters() + file_dialog.add_filter("*.json") + file_dialog.set_mode(0) + file_dialog.show() + file_dialog._update_file_list() + + +func _on_LoadDialog_file_selected( path ): + get_node("/root/World").load_world( path ) + + +func _on_Server_toggled( pressed ): + if pressed: + get_node("/root/World/Server").start() + get_node("Menu/Client").hide() + else: + get_node("/root/World/Server").stop() + get_node("Menu/Client").show() + + +func _on_Client_toggled( pressed ): + if pressed: + get_node("/root/World/Client").start() + get_node("Menu/Server").hide() + else: + get_node("/root/World/Client").stop() + get_node("Menu/Server").show() \ No newline at end of file -- cgit v1.2.3 From 03c453ac7dc2b22bfb864e563b7f3b8424bbcff4 Mon Sep 17 00:00:00 2001 From: hurikhan Date: Thu, 22 Jan 2015 05:35:39 +0900 Subject: * Cleanup for PR * Demo shows a Dialog with not implemented methods at startup --- README.md | 21 ----- demos/misc/window_management/control.gd | 68 +++++++++++++- demos/misc/window_management/observer/observer.gd | 1 + .../window_management/observer/observer_hud.gd | 98 --------------------- demos/misc/window_management/window_management.scn | Bin 4268 -> 4744 bytes main/main.cpp | 1 + 6 files changed, 69 insertions(+), 120 deletions(-) delete mode 100644 demos/misc/window_management/observer/observer_hud.gd diff --git a/README.md b/README.md index 35841c8b29..3456290f74 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,3 @@ -### x11-window-management branch - -#### New GDScript Methods for the OS Class: -* int OS.get_screen_count() -* int OS.get_screen() -* void OS.set_screen(int screen) -* Vector2 OS.get_screen_position(int screen=0) -* Vector2 OS.get_screen_size(int screen=0) -* Vector2 OS.get_window_position() -* void OS.set_window_position(Vector2 position) -* Vector2 OS.get_window_size() -* void OS.set_window_size(Vector2 size) -* void OS.set_fullscreen(bool enabled) -* bool OS.is_fullscreen() - -#### Demo -A demo/test is available at "demos/misc/window-management" - -#### Scons Commandline -'''scons p=x11 experimental_wm_api=yes''' - ![GODOT](/logo.png) ### The Engine diff --git a/demos/misc/window_management/control.gd b/demos/misc/window_management/control.gd index 6dc9282149..d329237aed 100644 --- a/demos/misc/window_management/control.gd +++ b/demos/misc/window_management/control.gd @@ -19,6 +19,9 @@ func _fixed_process(delta): if(OS.is_maximized()): modetext += "Maximized\n" + if(Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED): + modetext += "MouseGrab\n" + get_node("Label_Mode").set_text(modetext) get_node("Label_Position").set_text( str("Position:\n", OS.get_window_position() ) ) @@ -65,8 +68,71 @@ func _fixed_process(delta): get_node("Button_Mouse_Grab").set_pressed( Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED ) +func check_wm_api(): + var s = "" + if( !OS.has_method("get_screen_count") ): + s += " - get_screen_count()\n" + + if( !OS.has_method("get_screen") ): + s += " - get_screen()\n" + + if( !OS.has_method("set_screen") ): + s += " - set_screen()\n" + + if( !OS.has_method("get_screen_position") ): + s += " - get_screen_position()\n" + + if( !OS.has_method("get_screen_size") ): + s += " - get_screen_size()\n" + + if( !OS.has_method("get_window_position") ): + s += " - get_window_position()\n" + + if( !OS.has_method("set_window_position") ): + s += " - set_window_position()\n" + + if( !OS.has_method("get_window_size") ): + s += " - get_window_size()\n" + + if( !OS.has_method("set_window_size") ): + s += " - set_window_size()\n" + + if( !OS.has_method("set_fullscreen") ): + s += " - set_fullscreen()\n" + + if( !OS.has_method("is_fullscreen") ): + s += " - is_fullscreen()\n" + + if( !OS.has_method("set_resizable") ): + s += " - set_resizable()\n" + + if( !OS.has_method("is_resizable") ): + s += " - is_resizable()\n" + + if( !OS.has_method("set_minimized") ): + s += " - set_minimized()\n" + + if( !OS.has_method("is_minimized") ): + s += " - is_minimized()\n" + + if( !OS.has_method("set_maximized") ): + s += " - set_maximized()\n" + + if( !OS.has_method("is_maximized") ): + s += " - is_maximized()\n" + + if( s.length() == 0 ): + return true + else: + var text = get_node("ImplementationDialog/Text").get_text() + get_node("ImplementationDialog/Text").set_text( text + s ) + get_node("ImplementationDialog").show() + return false + + func _ready(): - set_fixed_process(true) + if( check_wm_api() ): + set_fixed_process(true) func _on_Button_MoveTo_pressed(): diff --git a/demos/misc/window_management/observer/observer.gd b/demos/misc/window_management/observer/observer.gd index 7bec0f5301..d27912a670 100644 --- a/demos/misc/window_management/observer/observer.gd +++ b/demos/misc/window_management/observer/observer.gd @@ -76,3 +76,4 @@ func _ready(): set_process_input(true) state = STATE_MENU + diff --git a/demos/misc/window_management/observer/observer_hud.gd b/demos/misc/window_management/observer/observer_hud.gd deleted file mode 100644 index 24e81b02ba..0000000000 --- a/demos/misc/window_management/observer/observer_hud.gd +++ /dev/null @@ -1,98 +0,0 @@ -var parent - -func printdebug(): - - var s - - if(parent.state == parent.STATE_GAME): - s = str( "TIME_FPS: ", Performance.get_monitor(Performance.TIME_FPS), "\n") - s += str("OBJECT_COUNT: ", Performance.get_monitor(Performance.OBJECT_COUNT), "\n") - s += str("OBJECT_RESOURCE_COUNT : ", Performance.get_monitor(Performance.OBJECT_RESOURCE_COUNT), "\n") - s += str("OBJECT_NODE_COUNT : ", Performance.get_monitor(Performance.OBJECT_NODE_COUNT), "\n") - s += str("RENDER_OBJECTS_IN_FRAME : ", Performance.get_monitor(Performance.RENDER_OBJECTS_IN_FRAME), "\n") - s += str("RENDER_VERTICES_IN_FRAME : ", Performance.get_monitor(Performance.RENDER_VERTICES_IN_FRAME), "\n") - s += str("RENDER_DRAW_CALLS_IN_FRAME : ", Performance.get_monitor(Performance.RENDER_DRAW_CALLS_IN_FRAME), "\n") - s += str("RENDER_VERTICES_IN_FRAME : ", Performance.get_monitor(Performance.RENDER_VERTICES_IN_FRAME), "\n") - # s += str("RENDER_USAGE_VIDEO_MEM_TOTAL : ", Performance.get_monitor(Performance.RENDER_USAGE_VIDEO_MEM_TOTAL), "\n") - # s += str("RENDER_VIDEO_MEM_USED : ", Performance.get_monitor(Performance.RENDER_VIDEO_MEM_USED), "\n") - # s += str("RENDER_TEXTURE_MEM_USED : ", Performance.get_monitor(Performance.RENDER_TEXTURE_MEM_USED), "\n") - # s += str("RENDER_VERTEX_MEM_USED : ", Performance.get_monitor(Performance.RENDER_VERTEX_MEM_USED), "\n") - s += str("CUBES: ", get_node("/root/World").world.size(), "\n") - else: - s = "" - - get_node("Label_Debug").set_text(s) - - -func _fixed_process(delta): - parent = get_parent() - - printdebug() - - if( parent.state == parent.STATE_MENU ): - get_node("Menu").show() - else: - get_node("Menu").hide() - - - -func _ready(): - set_fixed_process(true) - - -func _on_Fullscreen_toggled( pressed ): - if( pressed ): - OS.set_fullscreen(true) - else: - OS.set_fullscreen(false) - - -func _on_DebugInfo_toggled( pressed ): - if( pressed ): - get_node("Label_Debug").show() - else: - get_node("Label_Debug").hide() - - -func _on_Save_pressed(): - var file_dialog = get_node("Menu/SaveDialog") - file_dialog.clear_filters() - file_dialog.add_filter("*.json") - file_dialog.set_mode(3) - file_dialog.show() - file_dialog._update_file_list() - - -func _on_SaveDialog_file_selected( path ): - get_node("/root/World").save_world( path ) - - -func _on_Load_pressed(): - var file_dialog = get_node("Menu/LoadDialog") - file_dialog.clear_filters() - file_dialog.add_filter("*.json") - file_dialog.set_mode(0) - file_dialog.show() - file_dialog._update_file_list() - - -func _on_LoadDialog_file_selected( path ): - get_node("/root/World").load_world( path ) - - -func _on_Server_toggled( pressed ): - if pressed: - get_node("/root/World/Server").start() - get_node("Menu/Client").hide() - else: - get_node("/root/World/Server").stop() - get_node("Menu/Client").show() - - -func _on_Client_toggled( pressed ): - if pressed: - get_node("/root/World/Client").start() - get_node("Menu/Server").hide() - else: - get_node("/root/World/Client").stop() - get_node("Menu/Server").show() \ No newline at end of file diff --git a/demos/misc/window_management/window_management.scn b/demos/misc/window_management/window_management.scn index 40e6e64cef..bf7a0871e7 100644 Binary files a/demos/misc/window_management/window_management.scn and b/demos/misc/window_management/window_management.scn differ diff --git a/main/main.cpp b/main/main.cpp index 27d7d97e85..f0e376a045 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -627,6 +627,7 @@ Error Main::setup(const char *execpath,int argc, char *argv[],bool p_second_phas } } + GLOBAL_DEF("display/width",video_mode.width); GLOBAL_DEF("display/height",video_mode.height); GLOBAL_DEF("display/fullscreen",video_mode.fullscreen); -- cgit v1.2.3 From 2db55ef6fc9ce73ecec35d2241d2faa4082f0441 Mon Sep 17 00:00:00 2001 From: fry- Date: Mon, 2 Feb 2015 23:08:57 +0100 Subject: added a demo for 2D fog of war --- demos/2d/fog_of_war/.fscache | 11 +++++ demos/2d/fog_of_war/engine.cfg | 12 ++++++ demos/2d/fog_of_war/floor.png | Bin 0 -> 572 bytes demos/2d/fog_of_war/fog.gd | 86 +++++++++++++++++++++++++++++++++++++ demos/2d/fog_of_war/fog.png | Bin 0 -> 31448 bytes demos/2d/fog_of_war/fog.scn | Bin 0 -> 3714 bytes demos/2d/fog_of_war/fog.xml | 29 +++++++++++++ demos/2d/fog_of_war/icon.png | Bin 0 -> 3639 bytes demos/2d/fog_of_war/icon.png.flags | 1 + demos/2d/fog_of_war/tile_edit.scn | Bin 0 -> 1443 bytes demos/2d/fog_of_war/troll.gd | 43 +++++++++++++++++++ demos/2d/fog_of_war/troll.png | Bin 0 -> 7246 bytes demos/2d/fog_of_war/troll.scn | Bin 0 -> 1839 bytes 13 files changed, 182 insertions(+) create mode 100644 demos/2d/fog_of_war/.fscache create mode 100644 demos/2d/fog_of_war/engine.cfg create mode 100644 demos/2d/fog_of_war/floor.png create mode 100644 demos/2d/fog_of_war/fog.gd create mode 100644 demos/2d/fog_of_war/fog.png create mode 100644 demos/2d/fog_of_war/fog.scn create mode 100644 demos/2d/fog_of_war/fog.xml create mode 100644 demos/2d/fog_of_war/icon.png create mode 100644 demos/2d/fog_of_war/icon.png.flags create mode 100644 demos/2d/fog_of_war/tile_edit.scn create mode 100644 demos/2d/fog_of_war/troll.gd create mode 100644 demos/2d/fog_of_war/troll.png create mode 100644 demos/2d/fog_of_war/troll.scn diff --git a/demos/2d/fog_of_war/.fscache b/demos/2d/fog_of_war/.fscache new file mode 100644 index 0000000000..ba5e3995f3 --- /dev/null +++ b/demos/2d/fog_of_war/.fscache @@ -0,0 +1,11 @@ +::res://::1422910453 +floor.png::ImageTexture::1422910453:: +fog.gd::GDScript::1422910025:: +fog.png::ImageTexture::1422908128:: +fog.scn::PackedScene::1422909435:: +fog.xml::TileSet::1422909324:: +icon.png::ImageTexture::1422811193:: +tile_edit.scn::PackedScene::1422909313:: +troll.gd::GDScript::1422909940:: +troll.png::ImageTexture::1418669358:: +troll.scn::PackedScene::1418669358:: diff --git a/demos/2d/fog_of_war/engine.cfg b/demos/2d/fog_of_war/engine.cfg new file mode 100644 index 0000000000..5c4307b5bc --- /dev/null +++ b/demos/2d/fog_of_war/engine.cfg @@ -0,0 +1,12 @@ +[application] + +name="Fog of War" +main_scene="res://fog.scn" +icon="icon.png" + +[input] + +move_up=[key(Up)] +move_bottom=[key(Down)] +move_left=[key(Left)] +move_right=[key(Right)] diff --git a/demos/2d/fog_of_war/floor.png b/demos/2d/fog_of_war/floor.png new file mode 100644 index 0000000000..07b4f8c98f Binary files /dev/null and b/demos/2d/fog_of_war/floor.png differ diff --git a/demos/2d/fog_of_war/fog.gd b/demos/2d/fog_of_war/fog.gd new file mode 100644 index 0000000000..9da5680e4d --- /dev/null +++ b/demos/2d/fog_of_war/fog.gd @@ -0,0 +1,86 @@ + +extends TileMap + +# member variables here, example: +# var a=2 +# var b="textvar" + +# boundarys for the fog rectangle +var x_min = -20 # left start tile +var x_max = 20 # right end tile +var y_min = -20 # top start tile +var y_max = 20 # bottom end tile + +var position # players position + +# iteration variables +var x +var y + +# variable to check if player moved +var x_old +var y_old + +# array to build up the visible area like a square +# first value determines the width/height of the tip +# here it would be 2*2 + 1 = 5 tiles wide/high +# second value determines the total squares size +# here it would be 5*2 + 1 = 10 tiles wide/high +var l = range(2,5) + +# process that runs in realtime +func _fixed_process(delta): + position = get_node("../troll").get_pos() + + # calculate the corresponding tile + # from the players position + x = int(position.x/get_cell_size().x) + # switching from positive to negative tile positions + # causes problems because of rounding problems + if position.x < 0: + x -= 1 # correct negative values + + y = int(position.y/get_cell_size().y) + if position.y < 0: + y -= 1 + + # check if the player moved one tile further + if (x_old != x) or (y_old != y): + + # create the transparent part (visited area) + var end = l.size()-1 + var start = 0 + for steps in range(l.size()): + for m in range(x-l[end]-1,x+l[end]+2): + for n in range(y-l[start]-1,y+l[start]+2): + if get_cell(m,n) != 0: + set_cell(m,n,1,0,0) + end -= 1 + start += 1 + + # create the actual and active visible part + var end = l.size()-1 + var start = 0 + for steps in range(l.size()): + for m in range(x-l[end],x+l[end]+1): + for n in range(y-l[start],y+l[start]+1): + set_cell(m,n,-1) + end -= 1 + start += 1 + + x_old = x + y_old = y + + pass + +func _ready(): + # Initalization here + + # create a square filled with the 100% opaque fog + for x in range(x_min,x_max): + for y in range(y_min,y_max): + set_cell(x,y,0,0,0) + set_fixed_process(true) + pass + + diff --git a/demos/2d/fog_of_war/fog.png b/demos/2d/fog_of_war/fog.png new file mode 100644 index 0000000000..56980c298d Binary files /dev/null and b/demos/2d/fog_of_war/fog.png differ diff --git a/demos/2d/fog_of_war/fog.scn b/demos/2d/fog_of_war/fog.scn new file mode 100644 index 0000000000..4987f1ead5 Binary files /dev/null and b/demos/2d/fog_of_war/fog.scn differ diff --git a/demos/2d/fog_of_war/fog.xml b/demos/2d/fog_of_war/fog.xml new file mode 100644 index 0000000000..ed08d84a1f --- /dev/null +++ b/demos/2d/fog_of_war/fog.xml @@ -0,0 +1,29 @@ + + + + + + "fog opaque" + + -48, -48 + 0, 0 + 0, 0, 144, 144 + + + "fog transparent" + + -48, -48 + 0, 0 + 144, 0, 144, 144 + + + "floor" + + 0, 0 + 0, 0 + 0, 0, 0, 0 + + + + + \ No newline at end of file diff --git a/demos/2d/fog_of_war/icon.png b/demos/2d/fog_of_war/icon.png new file mode 100644 index 0000000000..0c422e37b0 Binary files /dev/null and b/demos/2d/fog_of_war/icon.png differ diff --git a/demos/2d/fog_of_war/icon.png.flags b/demos/2d/fog_of_war/icon.png.flags new file mode 100644 index 0000000000..dbef2209e8 --- /dev/null +++ b/demos/2d/fog_of_war/icon.png.flags @@ -0,0 +1 @@ +gen_mipmaps=true diff --git a/demos/2d/fog_of_war/tile_edit.scn b/demos/2d/fog_of_war/tile_edit.scn new file mode 100644 index 0000000000..aaca19d370 Binary files /dev/null and b/demos/2d/fog_of_war/tile_edit.scn differ diff --git a/demos/2d/fog_of_war/troll.gd b/demos/2d/fog_of_war/troll.gd new file mode 100644 index 0000000000..d118d3a2ba --- /dev/null +++ b/demos/2d/fog_of_war/troll.gd @@ -0,0 +1,43 @@ + +extends KinematicBody2D + +# This is a simple collision demo showing how +# the kinematic cotroller works. +# move() will allow to move the node, and will +# always move it to a non-colliding spot, +# as long as it starts from a non-colliding spot too. + + +#pixels / second +const MOTION_SPEED=160 + +func _fixed_process(delta): + + var motion = Vector2() + + if (Input.is_action_pressed("move_up")): + motion+=Vector2(0,-1) + if (Input.is_action_pressed("move_bottom")): + motion+=Vector2(0,1) + if (Input.is_action_pressed("move_left")): + motion+=Vector2(-1,0) + if (Input.is_action_pressed("move_right")): + motion+=Vector2(1,0) + + motion = motion.normalized() * MOTION_SPEED * delta + motion = move(motion) + + #make character slide nicely through the world + var slide_attempts = 4 + while(is_colliding() and slide_attempts>0): + motion = get_collision_normal().slide(motion) + motion=move(motion) + slide_attempts-=1 + + +func _ready(): + # Initalization here + set_fixed_process(true) + pass + + diff --git a/demos/2d/fog_of_war/troll.png b/demos/2d/fog_of_war/troll.png new file mode 100644 index 0000000000..69f195d034 Binary files /dev/null and b/demos/2d/fog_of_war/troll.png differ diff --git a/demos/2d/fog_of_war/troll.scn b/demos/2d/fog_of_war/troll.scn new file mode 100644 index 0000000000..f5d87c3631 Binary files /dev/null and b/demos/2d/fog_of_war/troll.scn differ -- cgit v1.2.3 From c21227a6368a7ff26bb1872b803ad7409684da7a Mon Sep 17 00:00:00 2001 From: fry- Date: Mon, 2 Feb 2015 23:29:19 +0100 Subject: added preview picture --- demos/2d/fog_of_war/icon.png | Bin 3639 -> 8681 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/demos/2d/fog_of_war/icon.png b/demos/2d/fog_of_war/icon.png index 0c422e37b0..a483390048 100644 Binary files a/demos/2d/fog_of_war/icon.png and b/demos/2d/fog_of_war/icon.png differ -- cgit v1.2.3 From df7d26ff5b89ce9852813abd370d1357aab1501b Mon Sep 17 00:00:00 2001 From: hurikhan Date: Thu, 12 Feb 2015 15:58:00 +0100 Subject: cleanup + MouseGrab --- demos/misc/window_management/control.gd | 2 + demos/misc/window_management/window_management.scn | Bin 4744 -> 4850 bytes platform/x11/os_x11.cpp | 81 +++++++++------------ platform/x11/os_x11.h | 1 + 4 files changed, 36 insertions(+), 48 deletions(-) diff --git a/demos/misc/window_management/control.gd b/demos/misc/window_management/control.gd index d329237aed..50fc3a3765 100644 --- a/demos/misc/window_management/control.gd +++ b/demos/misc/window_management/control.gd @@ -28,6 +28,8 @@ func _fixed_process(delta): get_node("Label_Size").set_text(str("Size:\n", OS.get_window_size() ) ) + get_node("Label_MousePosition").set_text(str("Mouse Position:\n", Input.get_mouse_pos() ) ) + get_node("Label_Screen_Count").set_text( str("Screen_Count:\n", OS.get_screen_count() ) ) get_node("Label_Screen_Current").set_text( str("Screen:\n", OS.get_screen() ) ) diff --git a/demos/misc/window_management/window_management.scn b/demos/misc/window_management/window_management.scn index bf7a0871e7..14d0da0415 100644 Binary files a/demos/misc/window_management/window_management.scn and b/demos/misc/window_management/window_management.scn differ diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index fa3701aeef..9fb2a4c64d 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -238,9 +238,11 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi XFree(xsh); } #else + capture_idle = 0; + minimized = false; + maximized = false; + if (current_videomode.fullscreen) { - minimized = false; - maximized = false; //set_wm_border(false); set_wm_fullscreen(true); } @@ -494,8 +496,9 @@ void OS_X11::set_mouse_mode(MouseMode p_mode) { center.y = current_videomode.height/2; XWarpPointer(x11_display, None, x11_window, 0,0,0,0, (int)center.x, (int)center.y); - } + input->set_mouse_pos(center); + } } void OS_X11::warp_mouse_pos(const Point2& p_to) { @@ -724,44 +727,10 @@ void OS_X11::set_window_size(const Size2 p_size) { } void OS_X11::set_fullscreen(bool p_enabled) { - -#if 0 - if(p_enabled && current_videomode.fullscreen) - return; - - if(!current_videomode.resizable) - set_resizable(true); - - if(p_enabled) { - window_data.size = get_window_size(); - window_data.position = get_window_position(); - - int screen = get_screen(); - Size2i size = get_screen_size(screen); - Point2i position = get_screen_position(screen); - - set_wm_border(false); - set_wm_fullscreen(true); - XMoveResizeWindow(x11_display, x11_window, position.x, position.y, size.x, size.y); - - current_videomode.fullscreen = True; - } else { - set_wm_fullscreen(false); - set_wm_border(true); - XMoveResizeWindow(x11_display, x11_window, - window_data.position.x, - window_data.position.y, - window_data.size.width, - window_data.size.height); - - current_videomode.fullscreen = False; - } -#endif set_wm_fullscreen(p_enabled); current_videomode.fullscreen = p_enabled; visual_server->init(); - } bool OS_X11::is_fullscreen() const { @@ -1209,7 +1178,7 @@ void OS_X11::process_xevents() { event.xbutton.x=last_mouse_pos.x; event.xbutton.y=last_mouse_pos.y; } - + InputEvent mouse_event; mouse_event.ID=++event_id; mouse_event.type = InputEvent::MOUSE_BUTTON; @@ -1244,7 +1213,7 @@ void OS_X11::process_xevents() { last_click_ms+=diff; last_click_pos = Point2(event.xbutton.x,event.xbutton.y); } - } + } input->parse_input_event( mouse_event); @@ -1254,11 +1223,10 @@ void OS_X11::process_xevents() { last_timestamp=event.xmotion.time; - + // Motion is also simple. // A little hack is in order // to be able to send relative motion events. - Point2i pos( event.xmotion.x, event.xmotion.y ); if (mouse_mode==MOUSE_MODE_CAPTURED) { @@ -1273,7 +1241,7 @@ void OS_X11::process_xevents() { } Point2i new_center = pos; - pos = last_mouse_pos + ( pos-center ); + pos = last_mouse_pos + ( pos - center ); center=new_center; do_mouse_warp=true; #else @@ -1287,9 +1255,7 @@ void OS_X11::process_xevents() { XWarpPointer(x11_display, None, x11_window, 0,0,0,0, (int)center.x, (int)center.y); #endif - } - if (!last_mouse_pos_valid) { @@ -1298,7 +1264,14 @@ void OS_X11::process_xevents() { } Point2i rel = pos - last_mouse_pos; - + +#ifdef EXPERIMENTAL_WM_API + if (mouse_mode==MOUSE_MODE_CAPTURED) { + pos.x = current_videomode.width / 2; + pos.y = current_videomode.height / 2; + } +#endif + InputEvent motion_event; motion_event.ID=++event_id; motion_event.type=InputEvent::MOUSE_MOTION; @@ -1309,7 +1282,7 @@ void OS_X11::process_xevents() { motion_event.mouse_motion.x=pos.x; motion_event.mouse_motion.y=pos.y; input->set_mouse_pos(pos); - motion_event.mouse_motion.global_x=pos.x; + motion_event.mouse_motion.global_x=pos.y; motion_event.mouse_motion.global_y=pos.y; motion_event.mouse_motion.speed_x=input->get_mouse_speed().x; motion_event.mouse_motion.speed_y=input->get_mouse_speed().y; @@ -1318,6 +1291,8 @@ void OS_X11::process_xevents() { motion_event.mouse_motion.relative_y=rel.y; last_mouse_pos=pos; + + // printf("rel: %d,%d\n", rel.x, rel.y ); input->parse_input_event( motion_event); @@ -1392,8 +1367,18 @@ void OS_X11::process_xevents() { if (do_mouse_warp) { XWarpPointer(x11_display, None, x11_window, - 0,0,0,0, (int)current_videomode.width/2, (int)current_videomode.height/2); - + 0,0,0,0, (int)current_videomode.width/2, (int)current_videomode.height/2); + + /* + Window root, child; + int root_x, root_y; + int win_x, win_y; + unsigned int mask; + XQueryPointer( x11_display, x11_window, &root, &child, &root_x, &root_y, &win_x, &win_y, &mask ); + + printf("Root: %d,%d\n", root_x, root_y); + printf("Win: %d,%d\n", win_x, win_y); + */ } } diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h index b47c5db069..7518c93562 100644 --- a/platform/x11/os_x11.h +++ b/platform/x11/os_x11.h @@ -160,6 +160,7 @@ class OS_X11 : public OS_Unix { Joystick joysticks[JOYSTICKS_MAX]; #ifdef EXPERIMENTAL_WM_API + unsigned int capture_idle; bool maximized; //void set_wm_border(bool p_enabled); void set_wm_fullscreen(bool p_enabled); -- cgit v1.2.3 From e2c8aecb3d65cacb7695316257ecd0ec90c91871 Mon Sep 17 00:00:00 2001 From: Carl Olsson Date: Sun, 15 Feb 2015 18:00:55 +1000 Subject: Better 2D Snapping Consolidated duplicate snapping functions into CanvasItemEditor. Allow non-square grids. Add grid origin offsets. Allow seperate toggling of grid display. Add rotation snapping. Add offset snapping. --- tools/editor/plugins/canvas_item_editor_plugin.cpp | 427 +++++++++++++-------- tools/editor/plugins/canvas_item_editor_plugin.h | 22 +- .../plugins/collision_polygon_2d_editor_plugin.cpp | 15 +- .../plugins/collision_polygon_2d_editor_plugin.h | 1 - .../plugins/collision_polygon_editor_plugin.cpp | 17 +- .../plugins/collision_polygon_editor_plugin.h | 1 - .../plugins/navigation_polygon_editor_plugin.cpp | 15 +- .../plugins/navigation_polygon_editor_plugin.h | 1 - tools/editor/plugins/path_2d_editor_plugin.cpp | 31 +- tools/editor/plugins/path_2d_editor_plugin.h | 1 - tools/editor/plugins/polygon_2d_editor_plugin.cpp | 15 +- tools/editor/plugins/polygon_2d_editor_plugin.h | 1 - tools/editor/plugins/tile_map_editor_plugin.h | 1 - 13 files changed, 294 insertions(+), 254 deletions(-) diff --git a/tools/editor/plugins/canvas_item_editor_plugin.cpp b/tools/editor/plugins/canvas_item_editor_plugin.cpp index 514f4b6525..22ab69df60 100644 --- a/tools/editor/plugins/canvas_item_editor_plugin.cpp +++ b/tools/editor/plugins/canvas_item_editor_plugin.cpp @@ -36,6 +36,110 @@ #include "globals.h" #include "os/input.h" #include "tools/editor/editor_settings.h" +#include "scene/gui/grid_container.h" + +class SnapDialog : public ConfirmationDialog { + + OBJ_TYPE(SnapDialog,ConfirmationDialog); + +protected: + friend class CanvasItemEditor; + SpinBox *grid_offset_x; + SpinBox *grid_offset_y; + SpinBox *grid_step_x; + SpinBox *grid_step_y; + SpinBox *rotation_offset; + SpinBox *rotation_step; + +public: + SnapDialog() : ConfirmationDialog() { + const int SPIN_BOX_GRID_RANGE = 256; + const int SPIN_BOX_ROTATION_RANGE = 360; + Label *label; + VBoxContainer *container; + GridContainer *child_container; + + set_title("Configure Snap"); + get_ok()->set_text("Close"); + container = memnew(VBoxContainer); + add_child(container); + + child_container = memnew(GridContainer); + child_container->set_columns(3); + container->add_child(child_container); + + label = memnew(Label); + label->set_text("Grid Offset:"); + child_container->add_child(label); + grid_offset_x=memnew(SpinBox); + grid_offset_x->set_min(-SPIN_BOX_GRID_RANGE); + grid_offset_x->set_max(SPIN_BOX_GRID_RANGE); + grid_offset_x->set_suffix("px"); + child_container->add_child(grid_offset_x); + grid_offset_y=memnew(SpinBox); + grid_offset_y->set_min(-SPIN_BOX_GRID_RANGE); + grid_offset_y->set_max(SPIN_BOX_GRID_RANGE); + grid_offset_y->set_suffix("px"); + child_container->add_child(grid_offset_y); + + label = memnew(Label); + label->set_text("Grid Step:"); + child_container->add_child(label); + grid_step_x=memnew(SpinBox); + grid_step_x->set_min(-SPIN_BOX_GRID_RANGE); + grid_step_x->set_max(SPIN_BOX_GRID_RANGE); + grid_step_x->set_suffix("px"); + child_container->add_child(grid_step_x); + grid_step_y=memnew(SpinBox); + grid_step_y->set_min(-SPIN_BOX_GRID_RANGE); + grid_step_y->set_max(SPIN_BOX_GRID_RANGE); + grid_step_y->set_suffix("px"); + child_container->add_child(grid_step_y); + + container->add_child(memnew(HSeparator)); + + child_container = memnew(GridContainer); + child_container->set_columns(2); + container->add_child(child_container); + + label = memnew(Label); + label->set_text("Rotation Offset:"); + child_container->add_child(label); + rotation_offset=memnew(SpinBox); + rotation_offset->set_min(-SPIN_BOX_ROTATION_RANGE); + rotation_offset->set_max(SPIN_BOX_ROTATION_RANGE); + rotation_offset->set_suffix("deg"); + child_container->add_child(rotation_offset); + + label = memnew(Label); + label->set_text("Rotation Step:"); + child_container->add_child(label); + rotation_step=memnew(SpinBox); + rotation_step->set_min(-SPIN_BOX_ROTATION_RANGE); + rotation_step->set_max(SPIN_BOX_ROTATION_RANGE); + rotation_step->set_suffix("deg"); + child_container->add_child(rotation_step); + } + + void set_fields(const Point2 p_grid_offset, const Size2 p_grid_step, const float p_rotation_offset, const float p_rotation_step) { + grid_offset_x->set_val(p_grid_offset.x); + grid_offset_y->set_val(p_grid_offset.y); + grid_step_x->set_val(p_grid_step.x); + grid_step_y->set_val(p_grid_step.y); + rotation_offset->set_val(p_rotation_offset * (180 / Math_PI)); + rotation_step->set_val(p_rotation_step * (180 / Math_PI)); + } + + void get_fields(Point2 &p_grid_offset, Size2 &p_grid_step, float &p_rotation_offset, float &p_rotation_step) { + p_grid_offset.x = grid_offset_x->get_val(); + p_grid_offset.y = grid_offset_y->get_val(); + p_grid_step.x = grid_step_x->get_val(); + p_grid_step.y = grid_step_y->get_val(); + p_rotation_offset = rotation_offset->get_val() / (180 / Math_PI); + p_rotation_step = rotation_step->get_val() / (180 / Math_PI); + } +}; + void CanvasItemEditor::_unhandled_key_input(const InputEvent& p_ev) { if (!is_visible()) @@ -75,9 +179,24 @@ Object *CanvasItemEditor::_get_editor_data(Object *p_what) { return memnew( CanvasItemEditorSelectedItem ); } -bool CanvasItemEditor::is_snap_active() const { +inline float _snap_scalar(float p_offset, float p_step, bool p_snap_to_offset, float p_target, float p_start) { + float offset = p_snap_to_offset ? p_start : p_offset; + return p_step != 0 ? Math::stepify(p_target - offset, p_step) + offset : p_target; +} + +Vector2 CanvasItemEditor::snap_point(Vector2 p_target, Vector2 p_start) const { + if (snap_grid) { + p_target.x = _snap_scalar(snap_offset.x, snap_step.x, snap_to_offset, p_target.x, p_start.x); + p_target.y = _snap_scalar(snap_offset.y, snap_step.y, snap_to_offset, p_target.y, p_start.y); + } + if (snap_pixel) + p_target = p_target.snapped(Size2(1, 1)); + + return p_target; +} - return edit_menu->get_popup()->is_item_checked(edit_menu->get_popup()->get_item_index(SNAP_USE)); +float CanvasItemEditor::snap_angle(float p_target, float p_start) const { + return snap_rotation ? _snap_scalar(snap_rotation_offset, snap_rotation_step, snap_to_offset, p_target, p_start) : p_target; } Dictionary CanvasItemEditor::get_state() const { @@ -86,9 +205,15 @@ Dictionary CanvasItemEditor::get_state() const { state["zoom"]=zoom; state["ofs"]=Point2(h_scroll->get_val(),v_scroll->get_val()); // state["ofs"]=-transform.get_origin(); - state["use_snap"]=is_snap_active(); - state["snap"]=snap; - state["pixel_snap"]=pixel_snap; + state["snap_offset"]=snap_offset; + state["snap_step"]=snap_step; + state["snap_rotation_offset"]=snap_rotation_offset; + state["snap_rotation_step"]=snap_rotation_step; + state["snap_grid"]=snap_grid; + state["snap_show_grid"]=snap_show_grid; + state["snap_rotation"]=snap_rotation; + state["snap_to_offset"]=snap_to_offset; + state["snap_pixel"]=snap_pixel; return state; } void CanvasItemEditor::set_state(const Dictionary& p_state){ @@ -105,19 +230,50 @@ void CanvasItemEditor::set_state(const Dictionary& p_state){ v_scroll->set_val(ofs.y); } - if (state.has("use_snap")) { + if (state.has("snap_step")) { + snap_step=state["snap_step"]; + } + + if (state.has("snap_offset")) { + snap_offset=state["snap_offset"]; + } + + if (state.has("snap_rotation_step")) { + snap_rotation_step=state["snap_rotation_step"]; + } + + if (state.has("snap_rotation_offset")) { + snap_rotation_offset=state["snap_rotation_offset"]; + } + + if (state.has("snap_grid")) { + snap_grid=state["snap_grid"]; int idx = edit_menu->get_popup()->get_item_index(SNAP_USE); - edit_menu->get_popup()->set_item_checked(idx,state["use_snap"]); + edit_menu->get_popup()->set_item_checked(idx,snap_grid); + } + + if (state.has("snap_show_grid")) { + snap_show_grid=state["snap_show_grid"]; + int idx = edit_menu->get_popup()->get_item_index(SNAP_SHOW_GRID); + edit_menu->get_popup()->set_item_checked(idx,snap_show_grid); + } + + if (state.has("snap_rotation")) { + snap_rotation=state["snap_rotation"]; + int idx = edit_menu->get_popup()->get_item_index(SNAP_USE_ROTATION); + edit_menu->get_popup()->set_item_checked(idx,snap_rotation); } - if (state.has("snap")) { - snap=state["snap"]; + if (state.has("snap_to_offset")) { + snap_to_offset=state["snap_to_offset"]; + int idx = edit_menu->get_popup()->get_item_index(SNAP_TO_OFFSET); + edit_menu->get_popup()->set_item_checked(idx,snap_to_offset); } - if (state.has("pixel_snap")) { - pixel_snap=state["pixel_snap"]; + if (state.has("snap_pixel")) { + snap_pixel=state["snap_pixel"]; int idx = edit_menu->get_popup()->get_item_index(SNAP_USE_PIXEL); - edit_menu->get_popup()->set_item_checked(idx,pixel_snap); + edit_menu->get_popup()->set_item_checked(idx,snap_pixel); } } @@ -286,9 +442,7 @@ void CanvasItemEditor::_key_move(const Vector2& p_dir, bool p_snap, KeyMoveMODE for(List::Element *E=selection.front();E;E=E->next()) { CanvasItem *canvas_item = E->get()->cast_to(); - if (!canvas_item) - continue; - if (!canvas_item->is_visible()) + if (!canvas_item || !canvas_item->is_visible()) continue; CanvasItemEditorSelectedItem *se=editor_selection->get_node_editor_data(canvas_item); if (!se) @@ -300,7 +454,7 @@ void CanvasItemEditor::_key_move(const Vector2& p_dir, bool p_snap, KeyMoveMODE Vector2 drag = p_dir; if (p_snap) - drag*=snap; + drag*=snap_step; undo_redo->add_undo_method(canvas_item,"edit_set_state",canvas_item->edit_get_state()); @@ -347,9 +501,7 @@ Point2 CanvasItemEditor::_find_topleftmost_point() { for(List::Element *E=selection.front();E;E=E->next()) { CanvasItem *canvas_item = E->get()->cast_to(); - if (!canvas_item) - continue; - if (!canvas_item->is_visible()) + if (!canvas_item || !canvas_item->is_visible()) continue; @@ -377,9 +529,7 @@ int CanvasItemEditor::get_item_count() { for(List::Element *E=selection.front();E;E=E->next()) { CanvasItem *canvas_item = E->get()->cast_to(); - if (!canvas_item) - continue; - if (!canvas_item->is_visible()) + if (!canvas_item || !canvas_item->is_visible()) continue; ic++; @@ -398,9 +548,7 @@ CanvasItem *CanvasItemEditor::get_single_item() { for(Map::Element *E=selection.front();E;E=E->next()) { CanvasItem *canvas_item = E->key()->cast_to(); - if (!canvas_item) - continue; - if (!canvas_item->is_visible()) + if (!canvas_item || !canvas_item->is_visible()) continue; if (single_item) @@ -554,6 +702,11 @@ void CanvasItemEditor::_append_canvas_item(CanvasItem *c) { } +void CanvasItemEditor::_snap_changed() { + ((SnapDialog *)snap_dialog)->get_fields(snap_offset, snap_step, snap_rotation_offset, snap_rotation_step); + viewport->update(); +} + void CanvasItemEditor::_dialog_value_changed(double) { if (updating_value_dialog) @@ -561,11 +714,6 @@ void CanvasItemEditor::_dialog_value_changed(double) { switch(last_option) { - case SNAP_CONFIGURE: { - - snap=dialog_val->get_val(); - viewport->update(); - } break; case ZOOM_SET: { zoom=dialog_val->get_val()/100.0; @@ -661,9 +809,7 @@ void CanvasItemEditor::_viewport_input_event(const InputEvent& p_event) { for(List::Element *E=selection.front();E;E=E->next()) { CanvasItem *canvas_item = E->get()->cast_to(); - if (!canvas_item) - continue; - if (!canvas_item->is_visible()) + if (!canvas_item || !canvas_item->is_visible()) continue; CanvasItemEditorSelectedItem *se=editor_selection->get_node_editor_data(canvas_item); @@ -735,9 +881,7 @@ void CanvasItemEditor::_viewport_input_event(const InputEvent& p_event) { for(List::Element *E=selection.front();E;E=E->next()) { CanvasItem *canvas_item = E->get()->cast_to(); - if (!canvas_item) - continue; - if (!canvas_item->is_visible()) + if (!canvas_item || !canvas_item->is_visible()) continue; CanvasItemEditorSelectedItem *se=editor_selection->get_node_editor_data(canvas_item); if (!se) @@ -943,9 +1087,7 @@ void CanvasItemEditor::_viewport_input_event(const InputEvent& p_event) { for(List::Element *E=selection.front();E;E=E->next()) { CanvasItem *canvas_item = E->get()->cast_to(); - if (!canvas_item) - continue; - if (!canvas_item->is_visible()) + if (!canvas_item || !canvas_item->is_visible()) continue; CanvasItemEditorSelectedItem *se=editor_selection->get_node_editor_data(canvas_item); if (!se) @@ -1068,9 +1210,7 @@ void CanvasItemEditor::_viewport_input_event(const InputEvent& p_event) { for(List::Element *E=selection.front();E;E=E->next()) { CanvasItem *canvas_item = E->get()->cast_to(); - if (!canvas_item) - continue; - if (!canvas_item->is_visible()) + if (!canvas_item || !canvas_item->is_visible()) continue; CanvasItemEditorSelectedItem *se=editor_selection->get_node_editor_data(canvas_item); if (!se) @@ -1126,9 +1266,7 @@ void CanvasItemEditor::_viewport_input_event(const InputEvent& p_event) { for(List::Element *E=selection.front();E;E=E->next()) { CanvasItem *canvas_item = E->get()->cast_to(); - if (!canvas_item) - continue; - if (!canvas_item->is_visible()) + if (!canvas_item || !canvas_item->is_visible()) continue; CanvasItemEditorSelectedItem *se=editor_selection->get_node_editor_data(canvas_item); if (!se) @@ -1153,39 +1291,21 @@ void CanvasItemEditor::_viewport_input_event(const InputEvent& p_event) { if (drag==DRAG_ROTATE) { Vector2 center = canvas_item->get_global_transform_with_canvas().get_origin(); - - Matrix32 rot; - rot.elements[1] = (dfrom - center).normalized(); - rot.elements[0] = rot.elements[1].tangent(); - float ang = rot.xform_inv(dto-center).atan2(); - canvas_item->edit_rotate(ang); - display_rotate_to = dto; - display_rotate_from = center; + if (Node2D *node = canvas_item->cast_to()) { + Matrix32 rot; + rot.elements[1] = (dfrom - center).normalized(); + rot.elements[0] = rot.elements[1].tangent(); + node->set_rot(snap_angle(rot.xform_inv(dto-center).atan2(), node->get_rot())); + display_rotate_to = dto; + display_rotate_from = center; + viewport->update(); + } continue; } - if (pixel_snap || (is_snap_active() && snap>0)) { - - if (drag!=DRAG_ALL) { - dfrom=drag_point_from; - dto=snapify(dto); - } else { - - Vector2 newpos = drag_point_from + (dto-dfrom); - Vector2 disp; - if (!is_snap_active() || snap<1) { - - disp.x = Math::fposmod(newpos.x,1); - disp.y = Math::fposmod(newpos.y,1); - - } else { - disp.x = Math::fposmod(newpos.x,snap); - disp.y = Math::fposmod(newpos.y,snap); - } - dto-=disp; - } - } + dfrom = drag_point_from; + dto = snap_point(dto - (drag == DRAG_ALL ? drag_from - drag_point_from : Vector2(0, 0)), drag_point_from); Vector2 drag_vector = canvas_item->get_global_transform_with_canvas().affine_inverse().xform(dto) - @@ -1293,8 +1413,6 @@ void CanvasItemEditor::_viewport_input_event(const InputEvent& p_event) { - - if (!dragging_bone) { local_rect.pos=begin; @@ -1477,32 +1595,32 @@ void CanvasItemEditor::_viewport_draw() { _update_scrollbars(); RID ci=viewport->get_canvas_item(); - if (snap>0 && is_snap_active() && true ) { - + if (snap_show_grid) { Size2 s = viewport->get_size(); - int last_cell; Matrix32 xform = transform.affine_inverse(); - for(int i=0;idraw_line(Point2(i,0),Point2(i,s.height),Color(0.3,0.7,1,0.3)); last_cell=cell; - if (last_cell!=cell) - viewport->draw_line(Point2(i,0),Point2(i,s.height),Color(0.3,0.7,1,0.3)); - last_cell=cell; + } } - for(int i=0;idraw_line(Point2(0,i),Point2(s.width,i),Color(0.3,0.7,1,0.3)); last_cell=cell; - if (last_cell!=cell) - viewport->draw_line(Point2(0,i),Point2(s.width,i),Color(0.3,0.7,1,0.3)); - last_cell=cell; + } } - } if (viewport->has_focus()) { @@ -1530,9 +1648,7 @@ void CanvasItemEditor::_viewport_draw() { CanvasItem *canvas_item = E->key()->cast_to(); - if (!canvas_item) - continue; - if (!canvas_item->is_visible()) + if (!canvas_item || !canvas_item->is_visible()) continue; CanvasItemEditorSelectedItem *se=editor_selection->get_node_editor_data(canvas_item); if (!se) @@ -1749,9 +1865,7 @@ void CanvasItemEditor::_notification(int p_what) { for(List::Element *E=selection.front();E;E=E->next()) { CanvasItem *canvas_item = E->get()->cast_to(); - if (!canvas_item) - continue; - if (!canvas_item->is_visible()) + if (!canvas_item || !canvas_item->is_visible()) continue; CanvasItemEditorSelectedItem *se=editor_selection->get_node_editor_data(canvas_item); @@ -1996,59 +2110,40 @@ void CanvasItemEditor::_update_scroll(float) { } -Point2 CanvasItemEditor::snapify(const Point2& p_pos) const { - - bool active=is_snap_active(); - - Vector2 pos = p_pos; - - if (!active || snap<1) { - - if (pixel_snap) { - - pos.x=Math::stepify(pos.x,1); - pos.y=Math::stepify(pos.y,1); - } - - return pos; - } - - - pos.x=Math::stepify(pos.x,snap); - pos.y=Math::stepify(pos.y,snap); - return pos; - - -} - - void CanvasItemEditor::_popup_callback(int p_op) { last_option=MenuOption(p_op); switch(p_op) { case SNAP_USE: { - + snap_grid = !snap_grid; int idx = edit_menu->get_popup()->get_item_index(SNAP_USE); - edit_menu->get_popup()->set_item_checked( idx,!edit_menu->get_popup()->is_item_checked(0)); + edit_menu->get_popup()->set_item_checked(idx,snap_grid); + } break; + case SNAP_SHOW_GRID: { + snap_show_grid = !snap_show_grid; + int idx = edit_menu->get_popup()->get_item_index(SNAP_SHOW_GRID); + edit_menu->get_popup()->set_item_checked(idx,snap_show_grid); viewport->update(); } break; + case SNAP_USE_ROTATION: { + snap_rotation = !snap_rotation; + int idx = edit_menu->get_popup()->get_item_index(SNAP_USE_ROTATION); + edit_menu->get_popup()->set_item_checked(idx,snap_rotation); + } break; + case SNAP_TO_OFFSET: { + snap_to_offset = !snap_to_offset; + int idx = edit_menu->get_popup()->get_item_index(SNAP_TO_OFFSET); + edit_menu->get_popup()->set_item_checked(idx,snap_to_offset); + } break; case SNAP_USE_PIXEL: { - pixel_snap = ! pixel_snap; + snap_pixel = !snap_pixel; int idx = edit_menu->get_popup()->get_item_index(SNAP_USE_PIXEL); - edit_menu->get_popup()->set_item_checked(idx,pixel_snap); + edit_menu->get_popup()->set_item_checked(idx,snap_pixel); } break; case SNAP_CONFIGURE: { - updating_value_dialog=true; - - dialog_label->set_text("Snap (Pixels):"); - dialog_val->set_min(1); - dialog_val->set_step(1); - dialog_val->set_max(4096); - dialog_val->set_val(snap); - value_dialog->popup_centered(Size2(200,85)); - updating_value_dialog=false; - + ((SnapDialog *)snap_dialog)->set_fields(snap_offset, snap_step, snap_rotation_offset, snap_rotation_step); + snap_dialog->popup_centered(Size2(200,160)); } break; case ZOOM_IN: { zoom=zoom*(1.0/0.5); @@ -2092,9 +2187,7 @@ void CanvasItemEditor::_popup_callback(int p_op) { for(List::Element *E=selection.front();E;E=E->next()) { CanvasItem *canvas_item = E->get()->cast_to(); - if (!canvas_item) - continue; - if (!canvas_item->is_visible()) + if (!canvas_item || !canvas_item->is_visible()) continue; canvas_item->set_meta("_edit_lock_",true); @@ -2109,9 +2202,7 @@ void CanvasItemEditor::_popup_callback(int p_op) { for(List::Element *E=selection.front();E;E=E->next()) { CanvasItem *canvas_item = E->get()->cast_to(); - if (!canvas_item) - continue; - if (!canvas_item->is_visible()) + if (!canvas_item || !canvas_item->is_visible()) continue; @@ -2129,9 +2220,7 @@ void CanvasItemEditor::_popup_callback(int p_op) { for(List::Element *E=selection.front();E;E=E->next()) { CanvasItem *canvas_item = E->get()->cast_to(); - if (!canvas_item) - continue; - if (!canvas_item->is_visible()) + if (!canvas_item || !canvas_item->is_visible()) continue; canvas_item->set_meta("_edit_group_",true); @@ -2146,9 +2235,7 @@ void CanvasItemEditor::_popup_callback(int p_op) { for(List::Element *E=selection.front();E;E=E->next()) { CanvasItem *canvas_item = E->get()->cast_to(); - if (!canvas_item) - continue; - if (!canvas_item->is_visible()) + if (!canvas_item || !canvas_item->is_visible()) continue; canvas_item->set_meta("_edit_group_",Variant()); @@ -2166,9 +2253,7 @@ void CanvasItemEditor::_popup_callback(int p_op) { for(List::Element *E=selection.front();E;E=E->next()) { CanvasItem *canvas_item = E->get()->cast_to(); - if (!canvas_item) - continue; - if (!canvas_item->is_visible()) + if (!canvas_item || !canvas_item->is_visible()) continue; @@ -2236,9 +2321,7 @@ void CanvasItemEditor::_popup_callback(int p_op) { for(Map::Element *E=selection.front();E;E=E->next()) { CanvasItem *canvas_item = E->key()->cast_to(); - if (!canvas_item) - continue; - if (!canvas_item->is_visible()) + if (!canvas_item || !canvas_item->is_visible()) continue; if (canvas_item->cast_to()) { @@ -2348,9 +2431,7 @@ void CanvasItemEditor::_popup_callback(int p_op) { for(Map::Element *E=selection.front();E;E=E->next()) { CanvasItem *canvas_item = E->key()->cast_to(); - if (!canvas_item) - continue; - if (!canvas_item->is_visible()) + if (!canvas_item || !canvas_item->is_visible()) continue; @@ -2400,9 +2481,7 @@ void CanvasItemEditor::_popup_callback(int p_op) { for(Map::Element *E=selection.front();E;E=E->next()) { CanvasItem *canvas_item = E->key()->cast_to(); - if (!canvas_item) - continue; - if (!canvas_item->is_visible()) + if (!canvas_item || !canvas_item->is_visible()) continue; if (canvas_item->cast_to()) { @@ -2528,9 +2607,7 @@ void CanvasItemEditor::_popup_callback(int p_op) { for(List::Element *E=selection.front();E;E=E->next()) { CanvasItem *canvas_item = E->get()->cast_to(); - if (!canvas_item) - continue; - if (!canvas_item->is_visible()) + if (!canvas_item || !canvas_item->is_visible()) continue; @@ -2604,6 +2681,7 @@ void CanvasItemEditor::_bind_methods() { ObjectTypeDB::bind_method("_unhandled_key_input",&CanvasItemEditor::_unhandled_key_input); ObjectTypeDB::bind_method("_viewport_draw",&CanvasItemEditor::_viewport_draw); ObjectTypeDB::bind_method("_viewport_input_event",&CanvasItemEditor::_viewport_input_event); + ObjectTypeDB::bind_method("_snap_changed",&CanvasItemEditor::_snap_changed); ADD_SIGNAL( MethodInfo("item_lock_status_changed") ); ADD_SIGNAL( MethodInfo("item_group_status_changed") ); @@ -2809,6 +2887,9 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { PopupMenu *p; p = edit_menu->get_popup(); p->add_check_item("Use Snap",SNAP_USE); + p->add_check_item("Show Grid",SNAP_SHOW_GRID); + p->add_check_item("Use Rotation Snap",SNAP_USE_ROTATION); + p->add_check_item("Offset Snap",SNAP_TO_OFFSET); p->add_item("Configure Snap..",SNAP_CONFIGURE); p->add_separator(); p->add_check_item("Use Pixel Snap",SNAP_USE_PIXEL); @@ -2899,6 +2980,10 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { p->add_item("Paste Pose",ANIM_PASTE_POSE); p->add_item("Clear Pose",ANIM_CLEAR_POSE,KEY_MASK_SHIFT|KEY_K); + snap_dialog = memnew(SnapDialog); + snap_dialog->connect("confirmed",this,"_snap_changed"); + add_child(snap_dialog); + value_dialog = memnew( AcceptDialog ); value_dialog->set_title("Set a Value"); value_dialog->get_ok()->set_text("Close"); @@ -2923,7 +3008,14 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { key_scale=false; zoom=1; - snap=10; + snap_offset=Vector2(0, 0); + snap_step=Vector2(10, 10); + snap_rotation_offset=0; + snap_rotation_step=15 / (180 / Math_PI); + snap_grid=false; + snap_show_grid=false; + snap_rotation=false; + snap_pixel=false; updating_value_dialog=false; box_selecting=false; //zoom=0.5; @@ -2931,7 +3023,6 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { editor->get_animation_editor()->connect("keying_changed",this,"_keying_changed"); set_process_unhandled_key_input(true); can_move_pivot=false; - pixel_snap=false; drag=DRAG_NONE; } diff --git a/tools/editor/plugins/canvas_item_editor_plugin.h b/tools/editor/plugins/canvas_item_editor_plugin.h index 6648d486e8..f2c3370fa5 100644 --- a/tools/editor/plugins/canvas_item_editor_plugin.h +++ b/tools/editor/plugins/canvas_item_editor_plugin.h @@ -75,6 +75,9 @@ class CanvasItemEditor : public VBoxContainer { enum MenuOption { SNAP_USE, + SNAP_SHOW_GRID, + SNAP_USE_ROTATION, + SNAP_TO_OFFSET, SNAP_CONFIGURE, SNAP_USE_PIXEL, ZOOM_IN, @@ -143,8 +146,15 @@ class CanvasItemEditor : public VBoxContainer { Matrix32 transform; float zoom; - int snap; - bool pixel_snap; + Vector2 snap_offset; + Vector2 snap_step; + float snap_rotation_step; + float snap_rotation_offset; + bool snap_grid; + bool snap_show_grid; + bool snap_rotation; + bool snap_to_offset; + bool snap_pixel; bool box_selecting; Point2 box_selecting_to; bool key_pos; @@ -247,6 +257,8 @@ class CanvasItemEditor : public VBoxContainer { CanvasItem* _select_canvas_item_at_pos(const Point2 &p_pos,Node* p_node,const Matrix32& p_parent_xform,const Matrix32& p_canvas_xform); void _find_canvas_items_at_rect(const Rect2& p_rect,Node* p_node,const Matrix32& p_parent_xform,const Matrix32& p_canvas_xform,List *r_items); + ConfirmationDialog *snap_dialog; + AcceptDialog *value_dialog; Label *dialog_label; SpinBox *dialog_val; @@ -261,7 +273,6 @@ class CanvasItemEditor : public VBoxContainer { DragType _find_drag_type(const Matrix32& p_xform, const Rect2& p_local_rect, const Point2& p_click, Vector2& r_point); - Point2 snapify(const Point2& p_pos) const; void _popup_callback(int p_op); bool updating_scroll; void _update_scroll(float); @@ -271,6 +282,7 @@ class CanvasItemEditor : public VBoxContainer { void _append_canvas_item(CanvasItem *p_item); void _dialog_value_changed(double); + void _snap_changed(); UndoRedo *undo_redo; Point2 _find_topleftmost_point(); @@ -334,8 +346,8 @@ protected: static CanvasItemEditor *singleton; public: - bool is_snap_active() const; - int get_snap() const { return snap; } + Vector2 snap_point(Vector2 p_target, Vector2 p_start = Vector2(0, 0)) const; + float snap_angle(float p_target, float p_start = 0) const; Matrix32 get_canvas_transform() const { return transform; } diff --git a/tools/editor/plugins/collision_polygon_2d_editor_plugin.cpp b/tools/editor/plugins/collision_polygon_2d_editor_plugin.cpp index ed228e9a1c..4c3315ad53 100644 --- a/tools/editor/plugins/collision_polygon_2d_editor_plugin.cpp +++ b/tools/editor/plugins/collision_polygon_2d_editor_plugin.cpp @@ -34,17 +34,6 @@ void CollisionPolygon2DEditor::_node_removed(Node *p_node) { } -Vector2 CollisionPolygon2DEditor::snap_point(const Vector2& p_point) const { - - if (canvas_item_editor->is_snap_active()) { - - return p_point.snapped(Vector2(1,1)*canvas_item_editor->get_snap()); - - } else { - return p_point; - } -} - void CollisionPolygon2DEditor::_menu_option(int p_option) { switch(p_option) { @@ -98,7 +87,7 @@ bool CollisionPolygon2DEditor::forward_input_event(const InputEvent& p_event) { Vector2 gpoint = Point2(mb.x,mb.y); Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint); - cpoint=snap_point(cpoint); + cpoint=canvas_item_editor->snap_point(cpoint); cpoint = node->get_global_transform().affine_inverse().xform(cpoint); Vector poly = node->get_polygon(); @@ -301,7 +290,7 @@ bool CollisionPolygon2DEditor::forward_input_event(const InputEvent& p_event) { Vector2 gpoint = Point2(mm.x,mm.y); Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint); - cpoint=snap_point(cpoint); + cpoint=canvas_item_editor->snap_point(cpoint); edited_point_pos = node->get_global_transform().affine_inverse().xform(cpoint); canvas_item_editor->get_viewport_control()->update(); diff --git a/tools/editor/plugins/collision_polygon_2d_editor_plugin.h b/tools/editor/plugins/collision_polygon_2d_editor_plugin.h index 052019b6c5..f34405b355 100644 --- a/tools/editor/plugins/collision_polygon_2d_editor_plugin.h +++ b/tools/editor/plugins/collision_polygon_2d_editor_plugin.h @@ -53,7 +53,6 @@ protected: static void _bind_methods(); public: - Vector2 snap_point(const Vector2& p_point) const; bool forward_input_event(const InputEvent& p_event); void edit(Node *p_collision_polygon); CollisionPolygon2DEditor(EditorNode *p_editor); diff --git a/tools/editor/plugins/collision_polygon_editor_plugin.cpp b/tools/editor/plugins/collision_polygon_editor_plugin.cpp index a6f2085a19..126328bac3 100644 --- a/tools/editor/plugins/collision_polygon_editor_plugin.cpp +++ b/tools/editor/plugins/collision_polygon_editor_plugin.cpp @@ -70,19 +70,6 @@ void CollisionPolygonEditor::_node_removed(Node *p_node) { } -Vector2 CollisionPolygonEditor::snap_point(const Vector2& p_point) const { - - return p_point; - - if (CanvasItemEditor::get_singleton()->is_snap_active()) { - - return p_point.snapped(Vector2(1,1)*CanvasItemEditor::get_singleton()->get_snap()); - - } else { - return p_point; - } -} - void CollisionPolygonEditor::_menu_option(int p_option) { switch(p_option) { @@ -150,7 +137,7 @@ bool CollisionPolygonEditor::forward_spatial_input_event(Camera* p_camera,const Vector2 cpoint(spoint.x,spoint.y); - cpoint=snap_point(cpoint); + cpoint=CanvasItemEditor::get_singleton()->snap_point(cpoint); Vector poly = node->get_polygon(); @@ -364,7 +351,7 @@ bool CollisionPolygonEditor::forward_spatial_input_event(Camera* p_camera,const Vector2 cpoint(spoint.x,spoint.y); - cpoint=snap_point(cpoint); + cpoint=CanvasItemEditor::get_singleton()->snap_point(cpoint); edited_point_pos = cpoint; _polygon_draw(); diff --git a/tools/editor/plugins/collision_polygon_editor_plugin.h b/tools/editor/plugins/collision_polygon_editor_plugin.h index 54b0706149..1c12ee0041 100644 --- a/tools/editor/plugins/collision_polygon_editor_plugin.h +++ b/tools/editor/plugins/collision_polygon_editor_plugin.h @@ -90,7 +90,6 @@ protected: static void _bind_methods(); public: - Vector2 snap_point(const Vector2& p_point) const; virtual bool forward_spatial_input_event(Camera* p_camera,const InputEvent& p_event); void edit(Node *p_collision_polygon); CollisionPolygonEditor(EditorNode *p_editor); diff --git a/tools/editor/plugins/navigation_polygon_editor_plugin.cpp b/tools/editor/plugins/navigation_polygon_editor_plugin.cpp index 599d18c8bb..2a32a2216a 100644 --- a/tools/editor/plugins/navigation_polygon_editor_plugin.cpp +++ b/tools/editor/plugins/navigation_polygon_editor_plugin.cpp @@ -42,17 +42,6 @@ void NavigationPolygonEditor::_create_nav() { undo_redo->commit_action(); } -Vector2 NavigationPolygonEditor::snap_point(const Vector2& p_point) const { - - if (canvas_item_editor->is_snap_active()) { - - return p_point.snapped(Vector2(1,1)*canvas_item_editor->get_snap()); - - } else { - return p_point; - } -} - void NavigationPolygonEditor::_menu_option(int p_option) { switch(p_option) { @@ -122,7 +111,7 @@ bool NavigationPolygonEditor::forward_input_event(const InputEvent& p_event) { Vector2 gpoint = Point2(mb.x,mb.y); Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint); - cpoint=snap_point(cpoint); + cpoint=canvas_item_editor->snap_point(cpoint); cpoint = node->get_global_transform().affine_inverse().xform(cpoint); @@ -370,7 +359,7 @@ bool NavigationPolygonEditor::forward_input_event(const InputEvent& p_event) { Vector2 gpoint = Point2(mm.x,mm.y); Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint); - cpoint=snap_point(cpoint); + cpoint=canvas_item_editor->snap_point(cpoint); edited_point_pos = node->get_global_transform().affine_inverse().xform(cpoint); canvas_item_editor->get_viewport_control()->update(); diff --git a/tools/editor/plugins/navigation_polygon_editor_plugin.h b/tools/editor/plugins/navigation_polygon_editor_plugin.h index a86d28c8a8..f742cb011d 100644 --- a/tools/editor/plugins/navigation_polygon_editor_plugin.h +++ b/tools/editor/plugins/navigation_polygon_editor_plugin.h @@ -59,7 +59,6 @@ protected: static void _bind_methods(); public: - Vector2 snap_point(const Vector2& p_point) const; bool forward_input_event(const InputEvent& p_event); void edit(Node *p_collision_polygon); NavigationPolygonEditor(EditorNode *p_editor); diff --git a/tools/editor/plugins/path_2d_editor_plugin.cpp b/tools/editor/plugins/path_2d_editor_plugin.cpp index 49239343a5..a38ec5bb7a 100644 --- a/tools/editor/plugins/path_2d_editor_plugin.cpp +++ b/tools/editor/plugins/path_2d_editor_plugin.cpp @@ -62,17 +62,6 @@ void Path2DEditor::_node_removed(Node *p_node) { } -Vector2 Path2DEditor::snap_point(const Vector2& p_point) const { - - if (canvas_item_editor->is_snap_active()) { - - return p_point.snapped(Vector2(1,1)*canvas_item_editor->get_snap()); - - } else { - return p_point; - } -} - bool Path2DEditor::forward_input_event(const InputEvent& p_event) { if (!node) @@ -93,8 +82,8 @@ bool Path2DEditor::forward_input_event(const InputEvent& p_event) { Matrix32 xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); Vector2 gpoint = Point2(mb.x,mb.y); - Vector2 cpoint = !mb.mod.alt? snap_point(xform.affine_inverse().xform(gpoint)) - : node->get_global_transform().affine_inverse().xform( snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint)) ); + Vector2 cpoint = !mb.mod.alt? canvas_item_editor->snap_point(xform.affine_inverse().xform(gpoint)) + : node->get_global_transform().affine_inverse().xform( canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint)) ); //first check if a point is to be added (segment split) real_t grab_treshold=EDITOR_DEF("poly_editor/point_grab_radius",8); @@ -250,9 +239,9 @@ bool Path2DEditor::forward_input_event(const InputEvent& p_event) { if (!wip_active) { wip.clear(); - wip.push_back( snap_point(cpoint) ); + wip.push_back( canvas_item_editor->snap_point(cpoint) ); wip_active=true; - edited_point_pos=snap_point(cpoint); + edited_point_pos=canvas_item_editor->snap_point(cpoint); canvas_item_editor->update(); edited_point=1; return true; @@ -265,7 +254,7 @@ bool Path2DEditor::forward_input_event(const InputEvent& p_event) { return true; } else { - wip.push_back( snap_point(cpoint) ); + wip.push_back( canvas_item_editor->snap_point(cpoint) ); edited_point=wip.size(); canvas_item_editor->update(); return true; @@ -327,9 +316,9 @@ bool Path2DEditor::forward_input_event(const InputEvent& p_event) { if (closest_idx>=0) { pre_move_edit=poly; - poly.insert(closest_idx+1,snap_point(xform.affine_inverse().xform(closest_pos))); + poly.insert(closest_idx+1,canvas_item_editor->snap_point(xform.affine_inverse().xform(closest_pos))); edited_point=closest_idx+1; - edited_point_pos=snap_point(xform.affine_inverse().xform(closest_pos)); + edited_point_pos=canvas_item_editor->snap_point(xform.affine_inverse().xform(closest_pos)); node->set_polygon(poly); canvas_item_editor->update(); return true; @@ -434,8 +423,8 @@ bool Path2DEditor::forward_input_event(const InputEvent& p_event) { Matrix32 xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); Vector2 gpoint = Point2(mm.x,mm.y); - Vector2 cpoint = !mm.mod.alt? snap_point(xform.affine_inverse().xform(gpoint)) - : node->get_global_transform().affine_inverse().xform( snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint)) ); + Vector2 cpoint = !mm.mod.alt? canvas_item_editor->snap_point(xform.affine_inverse().xform(gpoint)) + : node->get_global_transform().affine_inverse().xform( canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint)) ); Ref curve = node->get_curve(); @@ -471,7 +460,7 @@ bool Path2DEditor::forward_input_event(const InputEvent& p_event) { Matrix32 xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); Vector2 gpoint = Point2(mm.x,mm.y); - edited_point_pos = snap_point(xform.affine_inverse().xform(gpoint)); + edited_point_pos = canvas_item_editor->snap_point(xform.affine_inverse().xform(gpoint)); canvas_item_editor->update(); } diff --git a/tools/editor/plugins/path_2d_editor_plugin.h b/tools/editor/plugins/path_2d_editor_plugin.h index 73de2cc838..6ff69b96a2 100644 --- a/tools/editor/plugins/path_2d_editor_plugin.h +++ b/tools/editor/plugins/path_2d_editor_plugin.h @@ -94,7 +94,6 @@ protected: static void _bind_methods(); public: - Vector2 snap_point(const Vector2& p_point) const; bool forward_input_event(const InputEvent& p_event); void edit(Node *p_path2d); Path2DEditor(EditorNode *p_editor); diff --git a/tools/editor/plugins/polygon_2d_editor_plugin.cpp b/tools/editor/plugins/polygon_2d_editor_plugin.cpp index 27e539d50b..3858bf2c68 100644 --- a/tools/editor/plugins/polygon_2d_editor_plugin.cpp +++ b/tools/editor/plugins/polygon_2d_editor_plugin.cpp @@ -69,17 +69,6 @@ void Polygon2DEditor::_node_removed(Node *p_node) { } -Vector2 Polygon2DEditor::snap_point(const Vector2& p_point) const { - - if (canvas_item_editor->is_snap_active()) { - - return p_point.snapped(Vector2(1,1)*canvas_item_editor->get_snap()); - - } else { - return p_point; - } -} - void Polygon2DEditor::_menu_option(int p_option) { switch(p_option) { @@ -201,7 +190,7 @@ bool Polygon2DEditor::forward_input_event(const InputEvent& p_event) { Vector2 gpoint = Point2(mb.x,mb.y); Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint); - cpoint=snap_point(cpoint); + cpoint=canvas_item_editor->snap_point(cpoint); cpoint = node->get_global_transform().affine_inverse().xform(cpoint); @@ -405,7 +394,7 @@ bool Polygon2DEditor::forward_input_event(const InputEvent& p_event) { Vector2 gpoint = Point2(mm.x,mm.y); Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint); - cpoint=snap_point(cpoint); + cpoint=canvas_item_editor->snap_point(cpoint); edited_point_pos = node->get_global_transform().affine_inverse().xform(cpoint); canvas_item_editor->get_viewport_control()->update(); diff --git a/tools/editor/plugins/polygon_2d_editor_plugin.h b/tools/editor/plugins/polygon_2d_editor_plugin.h index 88d1c20493..8f807cb7e8 100644 --- a/tools/editor/plugins/polygon_2d_editor_plugin.h +++ b/tools/editor/plugins/polygon_2d_editor_plugin.h @@ -92,7 +92,6 @@ protected: static void _bind_methods(); public: - Vector2 snap_point(const Vector2& p_point) const; bool forward_input_event(const InputEvent& p_event); void edit(Node *p_collision_polygon); Polygon2DEditor(EditorNode *p_editor); diff --git a/tools/editor/plugins/tile_map_editor_plugin.h b/tools/editor/plugins/tile_map_editor_plugin.h index f3c590e228..4fd252516a 100644 --- a/tools/editor/plugins/tile_map_editor_plugin.h +++ b/tools/editor/plugins/tile_map_editor_plugin.h @@ -109,7 +109,6 @@ protected: public: HBoxContainer *get_canvas_item_editor_hb() const { return canvas_item_editor_hb; } - Vector2 snap_point(const Vector2& p_point) const; bool forward_input_event(const InputEvent& p_event); void edit(Node *p_tile_map); TileMapEditor(EditorNode *p_editor); -- cgit v1.2.3 From f5d2e1f42cca1c5b078073133fccda63c556a0da Mon Sep 17 00:00:00 2001 From: hurikhan Date: Sun, 15 Feb 2015 18:26:49 +0800 Subject: Renamed EXPERIMENTAL_WM_API to NEW_WM_API --- core/bind/core_bind.cpp | 4 ++-- core/bind/core_bind.h | 2 +- core/os/os.h | 2 +- platform/x11/detect.py | 6 +++--- platform/x11/os_x11.cpp | 12 ++++++------ platform/x11/os_x11.h | 4 ++-- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index 39c5761d67..858f5cec27 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -176,7 +176,7 @@ bool _OS::is_video_mode_fullscreen(int p_screen) const { } -#ifdef EXPERIMENTAL_WM_API +#ifdef NEW_WM_API int _OS::get_screen_count() const { return OS::get_singleton()->get_screen_count(); } @@ -706,7 +706,7 @@ void _OS::_bind_methods() { ObjectTypeDB::bind_method(_MD("is_video_mode_resizable","screen"),&_OS::is_video_mode_resizable,DEFVAL(0)); ObjectTypeDB::bind_method(_MD("get_fullscreen_mode_list","screen"),&_OS::get_fullscreen_mode_list,DEFVAL(0)); -#ifdef EXPERIMENTAL_WM_API +#ifdef NEW_WM_API ObjectTypeDB::bind_method(_MD("get_screen_count"),&_OS::get_screen_count); ObjectTypeDB::bind_method(_MD("get_screen"),&_OS::get_screen); ObjectTypeDB::bind_method(_MD("set_screen"),&_OS::set_screen); diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index e77ed9e40f..1a80e35221 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -108,7 +108,7 @@ public: bool is_video_mode_resizable(int p_screen=0) const; Array get_fullscreen_mode_list(int p_screen=0) const; -#ifdef EXPERIMENTAL_WM_API +#ifdef NEW_WM_API virtual int get_screen_count() const; virtual int get_screen() const; virtual void set_screen(int p_screen); diff --git a/core/os/os.h b/core/os/os.h index c04a91e302..6301bd495f 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -150,7 +150,7 @@ public: virtual VideoMode get_video_mode(int p_screen=0) const=0; virtual void get_fullscreen_mode_list(List *p_list,int p_screen=0) const=0; -#ifdef EXPERIMENTAL_WM_API +#ifdef NEW_WM_API virtual int get_screen_count() const=0; virtual int get_screen() const=0; virtual void set_screen(int p_screen)=0; diff --git a/platform/x11/detect.py b/platform/x11/detect.py index 0601c59981..2519dd6fdf 100644 --- a/platform/x11/detect.py +++ b/platform/x11/detect.py @@ -53,7 +53,7 @@ def get_opts(): ('use_llvm','Use llvm compiler','no'), ('use_sanitizer','Use llvm compiler sanitize address','no'), ('pulseaudio','Detect & Use pulseaudio','yes'), - ('experimental_wm_api', 'Use experimental window management API','no'), + ('new_wm_api', 'Use experimental window management API','no'), ] def get_flags(): @@ -153,7 +153,7 @@ def configure(env): env.Append( BUILDERS = { 'GLSL120GLES' : env.Builder(action = methods.build_gles2_headers, suffix = 'glsl.h',src_suffix = '.glsl') } ) #env.Append( BUILDERS = { 'HLSL9' : env.Builder(action = methods.build_hlsl_dx9_headers, suffix = 'hlsl.h',src_suffix = '.hlsl') } ) - if(env["experimental_wm_api"]=="yes"): - env.Append(CPPFLAGS=['-DEXPERIMENTAL_WM_API']) + if(env["new_wm_api"]=="yes"): + env.Append(CPPFLAGS=['-DNEW_WM_API']) env.ParseConfig('pkg-config xinerama --cflags --libs') diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index 4c86f5a82f..8def564562 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -36,7 +36,7 @@ #include "servers/physics/physics_server_sw.h" #include "X11/Xutil.h" -#ifdef EXPERIMENTAL_WM_API +#ifdef NEW_WM_API #include "X11/Xatom.h" #include "X11/extensions/Xinerama.h" // ICCCM @@ -187,7 +187,7 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi visual_server =memnew(VisualServerWrapMT(visual_server,get_render_thread_mode()==RENDER_SEPARATE_THREAD)); } -#ifndef EXPERIMENTAL_WM_API +#ifndef NEW_WM_API // borderless fullscreen window mode if (current_videomode.fullscreen) { // needed for lxde/openbox, possibly others @@ -552,7 +552,7 @@ void OS_X11::get_fullscreen_mode_list(List *p_list,int p_screen) cons } -#ifdef EXPERIMENTAL_WM_API +#ifdef NEW_WM_API #if 0 // Just now not needed. Can be used for a possible OS.set_border(bool) method void OS_X11::set_wm_border(bool p_enabled) { @@ -1133,7 +1133,7 @@ void OS_X11::process_xevents() { case FocusIn: minimized = false; -#ifdef EXPERIMENTAL_WM_API +#ifdef NEW_WM_API if(current_videomode.fullscreen) { set_wm_fullscreen(true); visual_server->init(); @@ -1149,7 +1149,7 @@ void OS_X11::process_xevents() { break; case FocusOut: -#ifdef EXPERIMENTAL_WM_API +#ifdef NEW_WM_API if(current_videomode.fullscreen) { set_wm_fullscreen(false); set_minimized(true); @@ -1269,7 +1269,7 @@ void OS_X11::process_xevents() { Point2i rel = pos - last_mouse_pos; -#ifdef EXPERIMENTAL_WM_API +#ifdef NEW_WM_API if (mouse_mode==MOUSE_MODE_CAPTURED) { pos.x = current_videomode.width / 2; pos.y = current_videomode.height / 2; diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h index 7518c93562..ffa1ce00b3 100644 --- a/platform/x11/os_x11.h +++ b/platform/x11/os_x11.h @@ -159,7 +159,7 @@ class OS_X11 : public OS_Unix { int joystick_count; Joystick joysticks[JOYSTICKS_MAX]; -#ifdef EXPERIMENTAL_WM_API +#ifdef NEW_WM_API unsigned int capture_idle; bool maximized; //void set_wm_border(bool p_enabled); @@ -220,7 +220,7 @@ public: virtual VideoMode get_video_mode(int p_screen=0) const; virtual void get_fullscreen_mode_list(List *p_list,int p_screen=0) const; -#ifdef EXPERIMENTAL_WM_API +#ifdef NEW_WM_API virtual int get_screen_count() const; virtual int get_screen() const; virtual void set_screen(int p_screen); -- cgit v1.2.3 From fba2d121b4f590d2c4f4ee1dd0eb4e2d712181d2 Mon Sep 17 00:00:00 2001 From: "Bil Bas (Spooner)" Date: Mon, 16 Feb 2015 20:59:16 +0000 Subject: Corrected behaviour of File.READ_WRITE mode (fixes #378) --- drivers/unix/file_access_unix.cpp | 2 +- drivers/windows/file_access_windows.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/unix/file_access_unix.cpp b/drivers/unix/file_access_unix.cpp index 7f85526852..2f91eee90e 100644 --- a/drivers/unix/file_access_unix.cpp +++ b/drivers/unix/file_access_unix.cpp @@ -74,7 +74,7 @@ Error FileAccessUnix::_open(const String& p_path, int p_mode_flags) { else if (p_mode_flags==WRITE) mode_string="wb"; else if (p_mode_flags==READ_WRITE) - mode_string="wb+"; + mode_string="rb+"; else return ERR_INVALID_PARAMETER; diff --git a/drivers/windows/file_access_windows.cpp b/drivers/windows/file_access_windows.cpp index a6073cbb29..50e2b1d9e6 100644 --- a/drivers/windows/file_access_windows.cpp +++ b/drivers/windows/file_access_windows.cpp @@ -65,7 +65,7 @@ Error FileAccessWindows::_open(const String& p_filename, int p_mode_flags) { else if (p_mode_flags==WRITE) mode_string=L"wb"; else if (p_mode_flags==READ_WRITE) - mode_string=L"wb+"; + mode_string=L"rb+"; else return ERR_INVALID_PARAMETER; -- cgit v1.2.3 From 56402900ff002c68734cc1de0f53b78f23154f77 Mon Sep 17 00:00:00 2001 From: Felix Laurie von Massenbach Date: Tue, 17 Feb 2015 02:51:17 +0000 Subject: View > Settings isn't a check item. --- tools/editor/plugins/spatial_editor_plugin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/editor/plugins/spatial_editor_plugin.cpp b/tools/editor/plugins/spatial_editor_plugin.cpp index 87bd8105af..b7c2281a09 100644 --- a/tools/editor/plugins/spatial_editor_plugin.cpp +++ b/tools/editor/plugins/spatial_editor_plugin.cpp @@ -3666,7 +3666,7 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { p->add_check_item("View Origin",MENU_VIEW_ORIGIN); p->add_check_item("View Grid",MENU_VIEW_GRID); p->add_separator(); - p->add_check_item("Settings",MENU_VIEW_CAMERA_SETTINGS ); + p->add_item("Settings",MENU_VIEW_CAMERA_SETTINGS); p->set_item_checked( p->get_item_index(MENU_VIEW_USE_DEFAULT_LIGHT), true ); -- cgit v1.2.3 From 0e1f34b49da3066bed94b316f22e6dd805509bf3 Mon Sep 17 00:00:00 2001 From: ElectricSolstice Date: Mon, 16 Feb 2015 18:58:41 -0800 Subject: Changed code to remove gcc -Wparentheses warnings. --- core/math/geometry.h | 4 ++-- drivers/etc1/rg_etc1.cpp | 2 +- drivers/trex/trex.c | 2 +- drivers/vorbis/codebook.c | 2 +- drivers/vorbis/floor1.c | 2 +- servers/visual/rasterizer.cpp | 2 +- tools/editor/plugins/script_editor_plugin.cpp | 8 +++++--- 7 files changed, 12 insertions(+), 10 deletions(-) diff --git a/core/math/geometry.h b/core/math/geometry.h index 7e0cc01a22..4ad4db8523 100644 --- a/core/math/geometry.h +++ b/core/math/geometry.h @@ -519,9 +519,9 @@ public: bool s_ab = (b.x-a.x)*as_y-(b.y-a.y)*as_x > 0; - if((c.x-a.x)*as_y-(c.y-a.y)*as_x > 0 == s_ab) return false; + if(((c.x-a.x)*as_y-(c.y-a.y)*as_x > 0) == s_ab) return false; - if((c.x-b.x)*(s.y-b.y)-(c.y-b.y)*(s.x-b.x) > 0 != s_ab) return false; + if(((c.x-b.x)*(s.y-b.y)-(c.y-b.y)*(s.x-b.x) > 0) != s_ab) return false; return true; } diff --git a/drivers/etc1/rg_etc1.cpp b/drivers/etc1/rg_etc1.cpp index cad9af8830..63877e6d12 100644 --- a/drivers/etc1/rg_etc1.cpp +++ b/drivers/etc1/rg_etc1.cpp @@ -2367,7 +2367,7 @@ found_perfect_match: int dr = best_results[1].m_block_color_unscaled.r - best_results[0].m_block_color_unscaled.r; int dg = best_results[1].m_block_color_unscaled.g - best_results[0].m_block_color_unscaled.g; int db = best_results[1].m_block_color_unscaled.b - best_results[0].m_block_color_unscaled.b; - RG_ETC1_ASSERT(best_use_color4 || (rg_etc1::minimum(dr, dg, db) >= cETC1ColorDeltaMin) && (rg_etc1::maximum(dr, dg, db) <= cETC1ColorDeltaMax)); + RG_ETC1_ASSERT(best_use_color4 || ((rg_etc1::minimum(dr, dg, db) >= cETC1ColorDeltaMin) && (rg_etc1::maximum(dr, dg, db) <= cETC1ColorDeltaMax))); if (best_use_color4) { diff --git a/drivers/trex/trex.c b/drivers/trex/trex.c index e63a248e9e..b3668c3a11 100644 --- a/drivers/trex/trex.c +++ b/drivers/trex/trex.c @@ -489,7 +489,7 @@ static const TRexChar *trex_matchnode(TRex* exp,TRexNode *node,const TRexChar *s return cur; } case OP_WB: - if(str == exp->_bol && !isspace(*str) + if((str == exp->_bol && !isspace(*str)) || (str == exp->_eol && !isspace(*(str-1))) || (!isspace(*str) && isspace(*(str+1))) || (isspace(*str) && !isspace(*(str+1))) ) { diff --git a/drivers/vorbis/codebook.c b/drivers/vorbis/codebook.c index 759d7b4254..8a928cebb9 100644 --- a/drivers/vorbis/codebook.c +++ b/drivers/vorbis/codebook.c @@ -248,7 +248,7 @@ static_codebook *vorbis_staticbook_unpack(oggpack_buffer *opb){ } /* quantized values */ - if((quantvals*s->q_quant+7>>3)>opb->storage-oggpack_bytes(opb)) + if(((quantvals*s->q_quant+7)>>3)>opb->storage-oggpack_bytes(opb)) goto _eofout; s->quantlist=_ogg_malloc(sizeof(*s->quantlist)*quantvals); for(i=0;iloneighbor[i-2]]&=0x7fff; fit_value[look->hineighbor[i-2]]&=0x7fff; diff --git a/servers/visual/rasterizer.cpp b/servers/visual/rasterizer.cpp index c3dcd83a31..5088000022 100644 --- a/servers/visual/rasterizer.cpp +++ b/servers/visual/rasterizer.cpp @@ -91,7 +91,7 @@ RID Rasterizer::_create_shader(const FixedMaterialShaderKey& p_key) { scode+="uniform float fmp_normal;\n"; scode+="uniform texture fmp_normal_tex;\n"; String uv_str; - if ((p_key.texcoord_mask>>(VS::FIXED_MATERIAL_PARAM_NORMAL*2))&0x3==VS::FIXED_MATERIAL_TEXCOORD_SPHERE) { + if (((p_key.texcoord_mask>>(VS::FIXED_MATERIAL_PARAM_NORMAL*2))&0x3)==VS::FIXED_MATERIAL_TEXCOORD_SPHERE) { uv_str="uv"; //sorry not supported } else { uv_str=_TEXUVSTR(VS::FIXED_MATERIAL_PARAM_NORMAL); diff --git a/tools/editor/plugins/script_editor_plugin.cpp b/tools/editor/plugins/script_editor_plugin.cpp index 1349d5ccab..a6ce6d3ef2 100644 --- a/tools/editor/plugins/script_editor_plugin.cpp +++ b/tools/editor/plugins/script_editor_plugin.cpp @@ -630,11 +630,13 @@ bool ScriptEditor::_test_script_times_on_disk() { - if (!all_ok) - if (bool(EDITOR_DEF("text_editor/auto_reload_changed_scripts",false))) + if (!all_ok) { + if (bool(EDITOR_DEF("text_editor/auto_reload_changed_scripts",false))) { script_editor->_reload_scripts(); - else + } else { disk_changed->call_deferred("popup_centered_ratio",0.5); + } + } return all_ok; } -- cgit v1.2.3 From db2381de7afffc932d051ec9fc853bfe06645060 Mon Sep 17 00:00:00 2001 From: "Bil Bas (Spooner)" Date: Thu, 19 Feb 2015 15:45:49 +0000 Subject: Correctly halt on error in sprintf parsing (fixes #1393) --- bin/tests/test_string.cpp | 137 +++++++++++++++++++++-------------------- core/ustring.cpp | 54 ++++++---------- core/ustring.h | 2 +- core/variant_op.cpp | 16 +++-- modules/gdscript/gd_script.cpp | 2 +- 5 files changed, 101 insertions(+), 110 deletions(-) diff --git a/bin/tests/test_string.cpp b/bin/tests/test_string.cpp index 4aaddd8ac1..2a048f2f67 100644 --- a/bin/tests/test_string.cpp +++ b/bin/tests/test_string.cpp @@ -519,12 +519,13 @@ bool test_28() { char output_format[] = "\tTest:\t%ls => %ls (%s)\n"; String format, output; Array args; + bool error; // %% format = "fish %% frog"; args.clear(); - output = format.sprintf(args); - success = (output == String("fish % frog")); + output = format.sprintf(args, &error); + success = (output == String("fish % frog") && !error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); if (!success) state = false; @@ -534,8 +535,8 @@ bool test_28() { format = "fish %d frog"; args.clear(); args.push_back(5); - output = format.sprintf(args); - success = (output == String("fish 5 frog")); + output = format.sprintf(args, &error); + success = (output == String("fish 5 frog") && !error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); if (!success) state = false; @@ -543,8 +544,8 @@ bool test_28() { format = "fish %05d frog"; args.clear(); args.push_back(5); - output = format.sprintf(args); - success = (output == String("fish 00005 frog")); + output = format.sprintf(args, &error); + success = (output == String("fish 00005 frog") && !error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); if (!success) state = false; @@ -552,8 +553,8 @@ bool test_28() { format = "fish %5d frog"; args.clear(); args.push_back(5); - output = format.sprintf(args); - success = (output == String("fish 5 frog")); + output = format.sprintf(args, &error); + success = (output == String("fish 5 frog") && !error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); if (!success) state = false; @@ -561,8 +562,8 @@ bool test_28() { format = "fish %-5d frog"; args.clear(); args.push_back(5); - output = format.sprintf(args); - success = (output == String("fish 5 frog")); + output = format.sprintf(args, &error); + success = (output == String("fish 5 frog") && !error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); if (!success) state = false; @@ -570,8 +571,8 @@ bool test_28() { format = "fish %+d frog"; args.clear(); args.push_back(5); - output = format.sprintf(args); - success = (output == String("fish +5 frog")); + output = format.sprintf(args, &error); + success = (output == String("fish +5 frog") && !error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); if (!success) state = false; @@ -579,8 +580,8 @@ bool test_28() { format = "fish %d frog"; args.clear(); args.push_back(-5); - output = format.sprintf(args); - success = (output == String("fish -5 frog")); + output = format.sprintf(args, &error); + success = (output == String("fish -5 frog") && !error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); if (!success) state = false; @@ -588,8 +589,8 @@ bool test_28() { format = "fish %x frog"; args.clear(); args.push_back(45); - output = format.sprintf(args); - success = (output == String("fish 2d frog")); + output = format.sprintf(args, &error); + success = (output == String("fish 2d frog") && !error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); if (!success) state = false; @@ -597,8 +598,8 @@ bool test_28() { format = "fish %X frog"; args.clear(); args.push_back(45); - output = format.sprintf(args); - success = (output == String("fish 2D frog")); + output = format.sprintf(args, &error); + success = (output == String("fish 2D frog") && !error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); if (!success) state = false; @@ -606,8 +607,8 @@ bool test_28() { format = "fish %o frog"; args.clear(); args.push_back(99); - output = format.sprintf(args); - success = (output == String("fish 143 frog")); + output = format.sprintf(args, &error); + success = (output == String("fish 143 frog") && !error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); if (!success) state = false; @@ -617,8 +618,8 @@ bool test_28() { format = "fish %f frog"; args.clear(); args.push_back(99.99); - output = format.sprintf(args); - success = (output == String("fish 99.990000 frog")); + output = format.sprintf(args, &error); + success = (output == String("fish 99.990000 frog") && !error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); if (!success) state = false; @@ -626,8 +627,8 @@ bool test_28() { format = "fish %11f frog"; args.clear(); args.push_back(99.99); - output = format.sprintf(args); - success = (output == String("fish 99.990000 frog")); + output = format.sprintf(args, &error); + success = (output == String("fish 99.990000 frog") && !error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); if (!success) state = false; @@ -635,8 +636,8 @@ bool test_28() { format = "fish %-11f frog"; args.clear(); args.push_back(99.99); - output = format.sprintf(args); - success = (output == String("fish 99.990000 frog")); + output = format.sprintf(args, &error); + success = (output == String("fish 99.990000 frog") && !error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); if (!success) state = false; @@ -644,8 +645,8 @@ bool test_28() { format = "fish %f frog"; args.clear(); args.push_back(99); - output = format.sprintf(args); - success = (output == String("fish 99.000000 frog")); + output = format.sprintf(args, &error); + success = (output == String("fish 99.000000 frog") && !error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); if (!success) state = false; @@ -653,8 +654,8 @@ bool test_28() { format = "fish %+f frog"; args.clear(); args.push_back(99.99); - output = format.sprintf(args); - success = (output == String("fish +99.990000 frog")); + output = format.sprintf(args, &error); + success = (output == String("fish +99.990000 frog") && !error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); if (!success) state = false; @@ -662,8 +663,8 @@ bool test_28() { format = "fish %.1f frog"; args.clear(); args.push_back(99.99); - output = format.sprintf(args); - success = (output == String("fish 100.0 frog")); + output = format.sprintf(args, &error); + success = (output == String("fish 100.0 frog") && !error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); if (!success) state = false; @@ -671,8 +672,8 @@ bool test_28() { format = "fish %.12f frog"; args.clear(); args.push_back(99.99); - output = format.sprintf(args); - success = (output == String("fish 99.990000000000 frog")); + output = format.sprintf(args, &error); + success = (output == String("fish 99.990000000000 frog") && !error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); if (!success) state = false; @@ -680,8 +681,8 @@ bool test_28() { format = "fish %.f frog"; args.clear(); args.push_back(99.99); - output = format.sprintf(args); - success = (output == String("fish 100 frog")); + output = format.sprintf(args, &error); + success = (output == String("fish 100 frog") && !error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); if (!success) state = false; @@ -691,8 +692,8 @@ bool test_28() { format = "fish %s frog"; args.clear(); args.push_back("cheese"); - output = format.sprintf(args); - success = (output == String("fish cheese frog")); + output = format.sprintf(args, &error); + success = (output == String("fish cheese frog") && !error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); if (!success) state = false; @@ -700,8 +701,8 @@ bool test_28() { format = "fish %10s frog"; args.clear(); args.push_back("cheese"); - output = format.sprintf(args); - success = (output == String("fish cheese frog")); + output = format.sprintf(args, &error); + success = (output == String("fish cheese frog") && !error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); if (!success) state = false; @@ -709,8 +710,8 @@ bool test_28() { format = "fish %-10s frog"; args.clear(); args.push_back("cheese"); - output = format.sprintf(args); - success = (output == String("fish cheese frog")); + output = format.sprintf(args, &error); + success = (output == String("fish cheese frog") && !error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); if (!success) state = false; @@ -720,8 +721,8 @@ bool test_28() { format = "fish %c frog"; args.clear(); args.push_back("A"); - output = format.sprintf(args); - success = (output == String("fish A frog")); + output = format.sprintf(args, &error); + success = (output == String("fish A frog") && !error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); if (!success) state = false; @@ -729,8 +730,8 @@ bool test_28() { format = "fish %c frog"; args.clear(); args.push_back(65); - output = format.sprintf(args); - success = (output == String("fish A frog")); + output = format.sprintf(args, &error); + success = (output == String("fish A frog") && !error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); if (!success) state = false; @@ -741,8 +742,8 @@ bool test_28() { args.clear(); args.push_back(10); args.push_back("cheese"); - output = format.sprintf(args); - success = (output == String("fish cheese frog")); + output = format.sprintf(args, &error); + success = (output == String("fish cheese frog") && !error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); if (!success) state = false; @@ -751,8 +752,8 @@ bool test_28() { args.clear(); args.push_back(10); args.push_back(99); - output = format.sprintf(args); - success = (output == String("fish 99 frog")); + output = format.sprintf(args, &error); + success = (output == String("fish 99 frog") && !error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); if (!success) state = false; @@ -762,8 +763,8 @@ bool test_28() { args.push_back(10); args.push_back(3); args.push_back(99.99); - output = format.sprintf(args); - success = (output == String("fish 99.990 frog")); + output = format.sprintf(args, &error); + success = (output == String("fish 99.990 frog") && !error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); if (!success) state = false; @@ -773,8 +774,8 @@ bool test_28() { format = "fish %s %s frog"; args.clear(); args.push_back("cheese"); - output = format.sprintf(args); - success = (output == ""); + output = format.sprintf(args, &error); + success = (output == "not enough arguments for format string" && error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); if (!success) state = false; @@ -783,8 +784,8 @@ bool test_28() { args.clear(); args.push_back("hello"); args.push_back("cheese"); - output = format.sprintf(args); - success = (output == ""); + output = format.sprintf(args, &error); + success = (output == "not all arguments converted during string formatting" && error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); if (!success) state = false; @@ -792,8 +793,8 @@ bool test_28() { format = "fish %10"; args.clear(); args.push_back("cheese"); - output = format.sprintf(args); - success = (output == ""); + output = format.sprintf(args, &error); + success = (output == "incomplete format" && error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); if (!success) state = false; @@ -801,8 +802,8 @@ bool test_28() { format = "fish %&f frog"; args.clear(); args.push_back("cheese"); - output = format.sprintf(args); - success = (output == ""); + output = format.sprintf(args, &error); + success = (output == "unsupported format character" && error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); if (!success) state = false; @@ -810,8 +811,8 @@ bool test_28() { format = "fish %2.2.2f frog"; args.clear(); args.push_back(99.99); - output = format.sprintf(args); - success = (output == ""); + output = format.sprintf(args, &error); + success = (output == "too many decimal points in format" && error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); if (!success) state = false; @@ -820,8 +821,8 @@ bool test_28() { args.clear(); args.push_back("cheese"); args.push_back(99.99); - output = format.sprintf(args); - success = (output == ""); + output = format.sprintf(args, &error); + success = (output == "* wants number" && error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); if (!success) state = false; @@ -829,8 +830,8 @@ bool test_28() { format = "fish %c frog"; args.clear(); args.push_back("sc"); - output = format.sprintf(args); - success = (output == ""); + output = format.sprintf(args, &error); + success = (output == "%c requires number or single-character string" && error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); if (!success) state = false; @@ -838,8 +839,8 @@ bool test_28() { format = "fish %c frog"; args.clear(); args.push_back(Array()); - output = format.sprintf(args); - success = (output == ""); + output = format.sprintf(args, &error); + success = (output == "%c requires number or single-character string" && error); OS::get_singleton()->print(output_format, format.c_str(), output.c_str(), success ? "OK" : "FAIL"); if (!success) state = false; diff --git a/core/ustring.cpp b/core/ustring.cpp index 476ab3f936..09d3d95b68 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -3550,8 +3550,8 @@ String String::lpad(int min_length, const String& character) const { // sprintf is implemented in GDScript via: // "fish %s pie" % "frog" // "fish %s %d pie" % ["frog", 12] -String String::sprintf(const Array& values) const { - +// In case of an error, the string returned is the error description and "error" is true. +String String::sprintf(const Array& values, bool* error) const { String formatted; CharType* self = (CharType*)c_str(); int num_items = values.size(); @@ -3564,6 +3564,7 @@ String String::sprintf(const Array& values) const { bool left_justified; bool show_sign; + *error = true; for (; *self; self++) { const CharType c = *self; @@ -3580,13 +3581,11 @@ String String::sprintf(const Array& values) const { case 'x': // Hexadecimal (lowercase) case 'X': { // Hexadecimal (uppercase) if (value_index >= values.size()) { - ERR_EXPLAIN("not enough arguments for format string"); - ERR_FAIL_V(""); + return "not enough arguments for format string"; } if (!values[value_index].is_num()) { - ERR_EXPLAIN("a number is required"); - ERR_FAIL_V(""); + return "a number is required"; } int64_t value = values[value_index]; @@ -3622,13 +3621,11 @@ String String::sprintf(const Array& values) const { } case 'f': { // Float if (value_index >= values.size()) { - ERR_EXPLAIN("not enough arguments for format string"); - ERR_FAIL_V(""); + return "not enough arguments for format string"; } if (!values[value_index].is_num()) { - ERR_EXPLAIN("a number is required"); - ERR_FAIL_V(""); + return "a number is required"; } double value = values[value_index]; @@ -3657,8 +3654,7 @@ String String::sprintf(const Array& values) const { } case 's': { // String if (value_index >= values.size()) { - ERR_EXPLAIN("not enough arguments for format string"); - ERR_FAIL_V(""); + return "not enough arguments for format string"; } String str = values[value_index]; @@ -3676,8 +3672,7 @@ String String::sprintf(const Array& values) const { } case 'c': { if (value_index >= values.size()) { - ERR_EXPLAIN("not enough arguments for format string"); - ERR_FAIL_V(""); + return "not enough arguments for format string"; } // Convert to character. @@ -3685,22 +3680,18 @@ String String::sprintf(const Array& values) const { if (values[value_index].is_num()) { int value = values[value_index]; if (value < 0) { - ERR_EXPLAIN("unsigned byte integer is lower than maximum") - ERR_FAIL_V(""); + return "unsigned byte integer is lower than maximum"; } else if (value > 255) { - ERR_EXPLAIN("unsigned byte integer is greater than maximum") - ERR_FAIL_V(""); + return "unsigned byte integer is greater than maximum"; } str = chr(values[value_index]); } else if (values[value_index].get_type() == Variant::STRING) { str = values[value_index]; if (str.length() != 1) { - ERR_EXPLAIN("%c requires number or single-character string"); - ERR_FAIL_V(""); + return "%c requires number or single-character string"; } } else { - ERR_EXPLAIN("%c requires number or single-character string"); - ERR_FAIL_V(""); + return "%c requires number or single-character string"; } // Padding. @@ -3741,8 +3732,7 @@ String String::sprintf(const Array& values) const { } case '.': { // Float separtor. if (in_decimals) { - ERR_EXPLAIN("too many decimal points in format"); - ERR_FAIL_V(""); + return "too many decimal points in format"; } in_decimals = true; min_decimals = 0; // We want to add the value manually. @@ -3751,13 +3741,11 @@ String String::sprintf(const Array& values) const { case '*': { // Dyanmic width, based on value. if (value_index >= values.size()) { - ERR_EXPLAIN("not enough arguments for format string"); - ERR_FAIL_V(""); + return "not enough arguments for format string"; } if (!values[value_index].is_num()) { - ERR_EXPLAIN("* wants number"); - ERR_FAIL_V(""); + return "* wants number"; } int size = values[value_index]; @@ -3773,8 +3761,7 @@ String String::sprintf(const Array& values) const { } default: { - ERR_EXPLAIN("unsupported format character"); - ERR_FAIL_V(""); + return "unsupported format character"; } } } else { // Not in format string. @@ -3796,14 +3783,13 @@ String String::sprintf(const Array& values) const { } if (in_format) { - ERR_EXPLAIN("incomplete format"); - ERR_FAIL_V(""); + return "incomplete format"; } if (value_index != values.size()) { - ERR_EXPLAIN("not all arguments converted during string formatting"); - ERR_FAIL_V(""); + return "not all arguments converted during string formatting"; } + *error = false; return formatted; } diff --git a/core/ustring.h b/core/ustring.h index af5ffb7c35..d4b854ea76 100644 --- a/core/ustring.h +++ b/core/ustring.h @@ -130,7 +130,7 @@ public: String pad_zeros(int p_digits) const; String lpad(int min_length,const String& character=" ") const; String rpad(int min_length,const String& character=" ") const; - String sprintf(const Array& values) const; + String sprintf(const Array& values, bool* error) const; static String num(double p_num,int p_decimals=-1); static String num_scientific(double p_num); static String num_real(double p_num); diff --git a/core/variant_op.cpp b/core/variant_op.cpp index 21bbc8c7ee..10b9a67da2 100644 --- a/core/variant_op.cpp +++ b/core/variant_op.cpp @@ -738,18 +738,22 @@ void Variant::evaluate(const Operator& p_op, const Variant& p_a, const Variant& _RETURN( p_a._data._int % p_b._data._int ); } else if (p_a.type==STRING) { - const String *str=reinterpret_cast(p_a._data._mem); + const String* format=reinterpret_cast(p_a._data._mem); + String result; + bool error; if (p_b.type==ARRAY) { // e.g. "frog %s %d" % ["fish", 12] - const Array *arr=reinterpret_cast(p_b._data._mem); - _RETURN(str->sprintf(*arr)); + const Array* args=reinterpret_cast(p_b._data._mem); + result=format->sprintf(*args, &error); } else { // e.g. "frog %d" % 12 - Array arr; - arr.push_back(p_b); - _RETURN(str->sprintf(arr)); + Array args; + args.push_back(p_b); + result=format->sprintf(args, &error); } + r_valid = !error; + _RETURN(result); } r_valid=false; diff --git a/modules/gdscript/gd_script.cpp b/modules/gdscript/gd_script.cpp index 0aa115ffbc..2a1e7a18df 100644 --- a/modules/gdscript/gd_script.cpp +++ b/modules/gdscript/gd_script.cpp @@ -337,7 +337,7 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a Variant::evaluate(op,*a,*b,*dst,valid); if (!valid) { - if (false && dst->get_type()==Variant::STRING) { + if (dst->get_type()==Variant::STRING) { //return a string when invalid with the error err_text=*dst; } else { -- cgit v1.2.3 From 748311ec42b6818f5481ad4ac4152f40ff1a8a6f Mon Sep 17 00:00:00 2001 From: "Bil Bas (Spooner)" Date: Thu, 19 Feb 2015 16:59:37 +0000 Subject: Added info about operator after bespoke error message. --- modules/gdscript/gd_script.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/gdscript/gd_script.cpp b/modules/gdscript/gd_script.cpp index 2a1e7a18df..bf4e9b8d8a 100644 --- a/modules/gdscript/gd_script.cpp +++ b/modules/gdscript/gd_script.cpp @@ -340,6 +340,7 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a if (dst->get_type()==Variant::STRING) { //return a string when invalid with the error err_text=*dst; + err_text += " in operator '"+Variant::get_operator_name(op)+"'."; } else { err_text="Invalid operands '"+Variant::get_type_name(a->get_type())+"' and '"+Variant::get_type_name(b->get_type())+"' in operator '"+Variant::get_operator_name(op)+"'."; } -- cgit v1.2.3 From 11a5949ec4f3231f5a7c054a6ebb102b705ad20f Mon Sep 17 00:00:00 2001 From: ElectricSolstice Date: Thu, 19 Feb 2015 16:34:04 -0800 Subject: Fixed issue 1377 about script editor parenthesis matching. --- scene/gui/text_edit.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 8855627bb4..a0d5af2efc 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -498,7 +498,29 @@ void TextEdit::_notification(int p_what) { for(int j=from;j=0;j--) { CharType cc = text[i][j]; - if (cc==c) + //ignore any brackets inside a string + if (cc== '"' | cc == '\'') { + CharType quotation = cc; + do { + j--; + if (!(j>=0)) { + break; + } + cc=text[i][j]; + //skip over escaped quotation marks inside strings + if (cc==quotation) { + bool escaped = false; + while (j-1>=0 && text[i][j-1]=='\\') { + escaped=!escaped; + j--; + } + if (escaped) { + j--; + cc='\\'; + continue; + } + } + } while (cc!= quotation); + } else if (cc==c) stack++; else if (cc==closec) stack--; -- cgit v1.2.3 From 8f5bf2a2ef96ea2d189d09a8cdd8d0a15deceb00 Mon Sep 17 00:00:00 2001 From: Nathan Warden Date: Thu, 19 Feb 2015 19:35:04 -0500 Subject: Camelcased script variables will now capitalize in the inspector. --- core/ustring.cpp | 25 ++++++++++++++++++++++++- core/ustring.h | 3 +-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/core/ustring.cpp b/core/ustring.cpp index 476ab3f936..8ad1d434d4 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -482,7 +482,7 @@ void String::erase(int p_pos, int p_chars) { String String::capitalize() const { - String aux=this->replace("_"," ").to_lower(); + String aux=this->camelcase_to_underscore().replace("_"," ").to_lower(); String cap; for (int i=0;isize()-1; i++ ) { + bool isCapital = cstr[i] >= A && cstr[i] <= Z; + + if ( isCapital ) { + newString += "_" + this->substr(startIndex, i-startIndex); + startIndex = i; + } + } + + newString += "_" + this->substr(startIndex, this->size()-startIndex); + + return newString; +} + + int String::get_slice_count(String p_splitter) const{ if (empty()) diff --git a/core/ustring.h b/core/ustring.h index af5ffb7c35..c7da26a695 100644 --- a/core/ustring.h +++ b/core/ustring.h @@ -149,6 +149,7 @@ public: static double to_double(const CharType* p_str, const CharType **r_end=NULL); static int64_t to_int(const CharType* p_str,int p_len=-1); String capitalize() const; + String camelcase_to_underscore() const; int get_slice_count(String p_splitter) const; String get_slice(String p_splitter,int p_slice) const; @@ -225,8 +226,6 @@ public: String(const char *p_str); String(const CharType *p_str,int p_clip_to_len=-1); String(const StrRange& p_range); - - }; -- cgit v1.2.3 From 402db5bd79bf889fca33b89cb083feb24effc614 Mon Sep 17 00:00:00 2001 From: Carl Olsson Date: Fri, 20 Feb 2015 22:21:59 +1000 Subject: Renamed "snap to offset" to "snap relative". Better conveys meaning. --- tools/editor/plugins/canvas_item_editor_plugin.cpp | 30 +++++++++++----------- tools/editor/plugins/canvas_item_editor_plugin.h | 4 +-- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/tools/editor/plugins/canvas_item_editor_plugin.cpp b/tools/editor/plugins/canvas_item_editor_plugin.cpp index 22ab69df60..32d5641e68 100644 --- a/tools/editor/plugins/canvas_item_editor_plugin.cpp +++ b/tools/editor/plugins/canvas_item_editor_plugin.cpp @@ -179,15 +179,15 @@ Object *CanvasItemEditor::_get_editor_data(Object *p_what) { return memnew( CanvasItemEditorSelectedItem ); } -inline float _snap_scalar(float p_offset, float p_step, bool p_snap_to_offset, float p_target, float p_start) { - float offset = p_snap_to_offset ? p_start : p_offset; +inline float _snap_scalar(float p_offset, float p_step, bool p_snap_relative, float p_target, float p_start) { + float offset = p_snap_relative ? p_start : p_offset; return p_step != 0 ? Math::stepify(p_target - offset, p_step) + offset : p_target; } Vector2 CanvasItemEditor::snap_point(Vector2 p_target, Vector2 p_start) const { if (snap_grid) { - p_target.x = _snap_scalar(snap_offset.x, snap_step.x, snap_to_offset, p_target.x, p_start.x); - p_target.y = _snap_scalar(snap_offset.y, snap_step.y, snap_to_offset, p_target.y, p_start.y); + p_target.x = _snap_scalar(snap_offset.x, snap_step.x, snap_relative, p_target.x, p_start.x); + p_target.y = _snap_scalar(snap_offset.y, snap_step.y, snap_relative, p_target.y, p_start.y); } if (snap_pixel) p_target = p_target.snapped(Size2(1, 1)); @@ -196,7 +196,7 @@ Vector2 CanvasItemEditor::snap_point(Vector2 p_target, Vector2 p_start) const { } float CanvasItemEditor::snap_angle(float p_target, float p_start) const { - return snap_rotation ? _snap_scalar(snap_rotation_offset, snap_rotation_step, snap_to_offset, p_target, p_start) : p_target; + return snap_rotation ? _snap_scalar(snap_rotation_offset, snap_rotation_step, snap_relative, p_target, p_start) : p_target; } Dictionary CanvasItemEditor::get_state() const { @@ -212,7 +212,7 @@ Dictionary CanvasItemEditor::get_state() const { state["snap_grid"]=snap_grid; state["snap_show_grid"]=snap_show_grid; state["snap_rotation"]=snap_rotation; - state["snap_to_offset"]=snap_to_offset; + state["snap_relative"]=snap_relative; state["snap_pixel"]=snap_pixel; return state; } @@ -264,10 +264,10 @@ void CanvasItemEditor::set_state(const Dictionary& p_state){ edit_menu->get_popup()->set_item_checked(idx,snap_rotation); } - if (state.has("snap_to_offset")) { - snap_to_offset=state["snap_to_offset"]; - int idx = edit_menu->get_popup()->get_item_index(SNAP_TO_OFFSET); - edit_menu->get_popup()->set_item_checked(idx,snap_to_offset); + if (state.has("snap_relative")) { + snap_relative=state["snap_relative"]; + int idx = edit_menu->get_popup()->get_item_index(SNAP_RELATIVE); + edit_menu->get_popup()->set_item_checked(idx,snap_relative); } if (state.has("snap_pixel")) { @@ -2131,10 +2131,10 @@ void CanvasItemEditor::_popup_callback(int p_op) { int idx = edit_menu->get_popup()->get_item_index(SNAP_USE_ROTATION); edit_menu->get_popup()->set_item_checked(idx,snap_rotation); } break; - case SNAP_TO_OFFSET: { - snap_to_offset = !snap_to_offset; - int idx = edit_menu->get_popup()->get_item_index(SNAP_TO_OFFSET); - edit_menu->get_popup()->set_item_checked(idx,snap_to_offset); + case SNAP_RELATIVE: { + snap_relative = !snap_relative; + int idx = edit_menu->get_popup()->get_item_index(SNAP_RELATIVE); + edit_menu->get_popup()->set_item_checked(idx,snap_relative); } break; case SNAP_USE_PIXEL: { snap_pixel = !snap_pixel; @@ -2889,7 +2889,7 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { p->add_check_item("Use Snap",SNAP_USE); p->add_check_item("Show Grid",SNAP_SHOW_GRID); p->add_check_item("Use Rotation Snap",SNAP_USE_ROTATION); - p->add_check_item("Offset Snap",SNAP_TO_OFFSET); + p->add_check_item("Snap Relative",SNAP_RELATIVE); p->add_item("Configure Snap..",SNAP_CONFIGURE); p->add_separator(); p->add_check_item("Use Pixel Snap",SNAP_USE_PIXEL); diff --git a/tools/editor/plugins/canvas_item_editor_plugin.h b/tools/editor/plugins/canvas_item_editor_plugin.h index f2c3370fa5..f25296abdc 100644 --- a/tools/editor/plugins/canvas_item_editor_plugin.h +++ b/tools/editor/plugins/canvas_item_editor_plugin.h @@ -77,7 +77,7 @@ class CanvasItemEditor : public VBoxContainer { SNAP_USE, SNAP_SHOW_GRID, SNAP_USE_ROTATION, - SNAP_TO_OFFSET, + SNAP_RELATIVE, SNAP_CONFIGURE, SNAP_USE_PIXEL, ZOOM_IN, @@ -153,7 +153,7 @@ class CanvasItemEditor : public VBoxContainer { bool snap_grid; bool snap_show_grid; bool snap_rotation; - bool snap_to_offset; + bool snap_relative; bool snap_pixel; bool box_selecting; Point2 box_selecting_to; -- cgit v1.2.3 From 071b2ea4f205ea99346a5cf73afdd50f7ccc95ed Mon Sep 17 00:00:00 2001 From: Nathan Warden Date: Fri, 20 Feb 2015 13:05:21 -0500 Subject: Updated the internal documention for the GDScript class. --- doc/base/classes.xml | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/doc/base/classes.xml b/doc/base/classes.xml index 35de0106b5..7c5530682e 100644 --- a/doc/base/classes.xml +++ b/doc/base/classes.xml @@ -257,13 +257,14 @@ - + - + - + + Linear interpolates between two values by a normalized value. @@ -276,6 +277,7 @@ + Decreases time by a specified amount. @@ -421,6 +423,7 @@ + Returns a reference to the specified function @@ -475,6 +478,7 @@ + Print one or more arguments to the console with a tab between each argument. @@ -499,6 +503,24 @@ Print one or more arguments to strings in the best way possible to console. No newline is added at the end. + + + + + + + Converts the value of a variable to a String. + + + + + + + + + Converts the value of a String to a variable. + + @@ -544,6 +566,7 @@ + Hashes the variable passed and returns an integer. -- cgit v1.2.3 From bfad3923878aa9b485f90a37bc04944828e35f27 Mon Sep 17 00:00:00 2001 From: Nathan Warden Date: Fri, 20 Feb 2015 16:28:48 -0500 Subject: Updated the variable in the lerp function to be weight instead of percent. --- doc/base/classes.xml | 2 +- modules/gdscript/gd_functions.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/base/classes.xml b/doc/base/classes.xml index 7c5530682e..8271c5f7b6 100644 --- a/doc/base/classes.xml +++ b/doc/base/classes.xml @@ -261,7 +261,7 @@ - + Linear interpolates between two values by a normalized value. diff --git a/modules/gdscript/gd_functions.cpp b/modules/gdscript/gd_functions.cpp index b616d8f228..f37b2f645a 100644 --- a/modules/gdscript/gd_functions.cpp +++ b/modules/gdscript/gd_functions.cpp @@ -1101,7 +1101,7 @@ MethodInfo GDFunctions::get_info(Function p_func) { return mi; } break; case MATH_LERP: { - MethodInfo mi("lerp",PropertyInfo(Variant::REAL,"a"),PropertyInfo(Variant::REAL,"b"), PropertyInfo(Variant::REAL,"c")); + MethodInfo mi("lerp",PropertyInfo(Variant::REAL,"from"),PropertyInfo(Variant::REAL,"to"), PropertyInfo(Variant::REAL,"weight")); mi.return_val.type=Variant::REAL; return mi; } break; -- cgit v1.2.3 From 84905809a159e4f04b166f06a5807560c4c7d538 Mon Sep 17 00:00:00 2001 From: UsernameIsAReservedWord Date: Tue, 24 Feb 2015 22:28:51 +0100 Subject: fixes platform/windows/detect.py - fixes issue #1298 : under windows, too long `ar` command lines are split into several smaller command lines. - fixes issue #1285 : under linux, cross compiling with Mingw-w64 now generates actual 64bits EXE. - `MINGW32_PREFIX` and `MINGW64_PREFIX` environment variables are also available for Windows. - started to clean-up the remains of previous hacks and workarounds. - added some documentation into the script. --- platform/windows/detect.py | 208 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 162 insertions(+), 46 deletions(-) diff --git a/platform/windows/detect.py b/platform/windows/detect.py index 16dd695c59..b07882f552 100644 --- a/platform/windows/detect.py +++ b/platform/windows/detect.py @@ -1,4 +1,90 @@ - +# +# tested on | Windows native | Linux cross-compilation +# ------------------------+-------------------+--------------------------- +# MSVS C++ 2010 Express | WORKS | n/a +# Mingw-w64 | WORKS | WORKS +# Mingw-w32 | WORKS | WORKS +# MinGW | WORKS | untested +# +##### +# Notes about MSVS C++ : +# +# - MSVC2010-Express compiles to 32bits only. +# +##### +# Notes about Mingw-w64 and Mingw-w32 under Windows : +# +# - both can be installed using the official installer : +# http://mingw-w64.sourceforge.net/download.php#mingw-builds +# +# - if you want to compile both 32bits and 64bits, don't forget to +# run the installer twice to install them both. +# +# - install them into a path that does not contain spaces +# ( example : "C:/Mingw-w32", "C:/Mingw-w64" ) +# +# - if you want to compile faster using the "-j" option, don't forget +# to install the appropriate version of the Pywin32 python extension +# available from : http://sourceforge.net/projects/pywin32/files/ +# +# - before running scons, you must add into the environment path +# the path to the "/bin" directory of the Mingw version you want +# to use : +# +# set PATH=C:/Mingw-w32/bin;%PATH% +# +# - then, scons should be able to detect gcc. +# - Mingw-w32 only compiles 32bits. +# - Mingw-w64 only compiles 64bits. +# +# - it is possible to add them both at the same time into the PATH env, +# if you also define the MINGW32_PREFIX and MINGW64_PREFIX environment +# variables. +# For instance, you could store that set of commands into a .bat script +# that you would run just before scons : +# +# set PATH=C:\mingw-w64\bin;%PATH% +# set PATH=C:\mingw-w64\bin;%PATH% +# set MINGW32_PREFIX=C:\mingw-w64\bin\ +# set MINGW64_PREFIX=C:\mingw-w64\bin\ +# +##### +# Notes about Mingw, Mingw-w64 and Mingw-w32 under Linux : +# +# - default toolchain prefixes are : +# "i586-mingw32msvc-" for MinGW +# "i686-w64-mingw32-" for Mingw-w32 +# "x86_64-w64-mingw32-" for Mingw-w64 +# +# - if both MinGW and Mingw-w32 are installed on your system +# Mingw-w32 should take the priority over MinGW. +# +# - it is possible to manually override prefixes by defining +# the MINGW32_PREFIX and MINGW64_PREFIX environment variables. +# +##### +# Notes about Mingw under Windows : +# +# - this is the MinGW version from http://mingw.org/ +# - install it into a path that does not contain spaces +# ( example : "C:/MinGW" ) +# - several DirectX headers might be missing. You can copy them into +# the C:/MinGW/include" directory from this page : +# https://code.google.com/p/mingw-lib/source/browse/trunk/working/avcodec_to_widget_5/directx_include/ +# - before running scons, add the path to the "/bin" directory : +# set PATH=C:/MinGW/bin;%PATH% +# - scons should be able to detect gcc. +# + +##### +# TODO : +# +# - finish to cleanup this script to remove all the remains of previous hacks and workarounds +# - make it work with the Windows7 SDK that is supposed to enable 64bits compilation for MSVC2010-Express +# - confirm it works well with other Visual Studio versions. +# - update the wiki about the pywin32 extension required for the "-j" option under Windows. +# - update the wiki to document MINGW32_PREFIX and MINGW64_PREFIX +# import os @@ -13,50 +99,70 @@ def get_name(): def can_build(): - if (os.name=="nt"): #building natively on windows! if (os.getenv("VSINSTALLDIR")): return True else: - print("MSVC Not detected, attempting mingw.") + print("\nMSVC not detected, attempting Mingw.") + mingw32 = "" + mingw64 = "" + if ( os.getenv("MINGW32_PREFIX") ) : + mingw32 = os.getenv("MINGW32_PREFIX") + if ( os.getenv("MINGW64_PREFIX") ) : + mingw64 = os.getenv("MINGW64_PREFIX") + + test = "gcc --version > NUL 2>&1" + if os.system(test)!= 0 and os.system(mingw32+test)!=0 and os.system(mingw64+test)!=0 : + print("- could not detect gcc.") + print("Please, make sure a path to a Mingw /bin directory is accessible into the environment PATH.\n") + return False + else: + print("- gcc detected.") + return True - - if (os.name=="posix"): mingw = "i586-mingw32msvc-" - mingw64 = "i686-w64-mingw32-" + mingw64 = "x86_64-w64-mingw32-" + mingw32 = "i686-w64-mingw32-" + if (os.getenv("MINGW32_PREFIX")): - mingw=os.getenv("MINGW32_PREFIX") + mingw32=os.getenv("MINGW32_PREFIX") + mingw = mingw32 if (os.getenv("MINGW64_PREFIX")): mingw64=os.getenv("MINGW64_PREFIX") - - if os.system(mingw+"gcc --version >/dev/null") == 0 or os.system(mingw64+"gcc --version >/dev/null") ==0: + + test = "gcc --version >/dev/null" + if os.system(mingw+test) == 0 or os.system(mingw64+test) ==0 or os.system(mingw32+test) ==0 : return True - - return False def get_opts(): mingw="" + mingw32="" mingw64="" - if (os.name!="nt"): + if ( os.name == "posix" ): mingw = "i586-mingw32msvc-" - mingw64 = "i686-w64-mingw32-" - if (os.getenv("MINGW32_PREFIX")): - mingw=os.getenv("MINGW32_PREFIX") - if (os.getenv("MINGW64_PREFIX")): - mingw64=os.getenv("MINGW64_PREFIX") + mingw32 = "i686-w64-mingw32-" + mingw64 = "x86_64-w64-mingw32-" + + if os.system(mingw32+"gcc --version >/dev/null") != 0 : + mingw32 = mingw + + if (os.getenv("MINGW32_PREFIX")): + mingw32=os.getenv("MINGW32_PREFIX") + mingw = mingw32 + if (os.getenv("MINGW64_PREFIX")): + mingw64=os.getenv("MINGW64_PREFIX") return [ - ('mingw_prefix','Mingw Prefix',mingw), + ('mingw_prefix','Mingw Prefix',mingw32), ('mingw_prefix_64','Mingw Prefix 64 bits',mingw64), - ('mingw64_for_32','Use Mingw 64 for 32 Bits Build',"no"), ] def get_flags(): @@ -140,13 +246,13 @@ def configure(env): # http://www.scons.org/wiki/LongCmdLinesOnWin32 if (os.name=="nt"): import subprocess - def mySpawn(sh, escape, cmd, args, env): - newargs = ' '.join(args[1:]) - cmdline = cmd + " " + newargs + + def mySubProcess(cmdline,env): + #print "SPAWNED : " + cmdline startupinfo = subprocess.STARTUPINFO() startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW proc = subprocess.Popen(cmdline, stdin=subprocess.PIPE, stdout=subprocess.PIPE, - stderr=subprocess.PIPE, startupinfo=startupinfo, shell = False, env = env) + stderr=subprocess.PIPE, startupinfo=startupinfo, shell = False, env = env) data, err = proc.communicate() rv = proc.wait() if rv: @@ -154,35 +260,45 @@ def configure(env): print err print "=====" return rv + + def mySpawn(sh, escape, cmd, args, env): + + newargs = ' '.join(args[1:]) + cmdline = cmd + " " + newargs + + rv=0 + if len(cmdline) > 32000 and cmd.endswith("ar") : + cmdline = cmd + " " + args[1] + " " + args[2] + " " + for i in range(3,len(args)) : + rv = mySubProcess( cmdline + args[i], env ) + if rv : + break + else: + rv = mySubProcess( cmdline, env ) + + return rv + env['SPAWN'] = mySpawn #build using mingw if (os.name=="nt"): env['ENV']['TMP'] = os.environ['TMP'] #way to go scons, you can be so stupid sometimes else: - env["PROGSUFFIX"]=env["PROGSUFFIX"]+".exe" + env["PROGSUFFIX"]=env["PROGSUFFIX"]+".exe" # for linux cross-compilation mingw_prefix="" if (env["bits"]=="default"): env["bits"]="32" - use64=False if (env["bits"]=="32"): - - if (env["mingw64_for_32"]=="yes"): - env.Append(CCFLAGS=['-m32']) - env.Append(LINKFLAGS=['-m32']) - env.Append(LINKFLAGS=['-static-libgcc']) - env.Append(LINKFLAGS=['-static-libstdc++']) - mingw_prefix=env["mingw_prefix_64"]; - else: - mingw_prefix=env["mingw_prefix"]; - - + env.Append(LINKFLAGS=['-static']) + env.Append(LINKFLAGS=['-static-libgcc']) + env.Append(LINKFLAGS=['-static-libstdc++']) + mingw_prefix=env["mingw_prefix"]; else: - mingw_prefix=env["mingw_prefix_64"]; env.Append(LINKFLAGS=['-static']) + mingw_prefix=env["mingw_prefix_64"]; nulstr="" @@ -193,10 +309,10 @@ def configure(env): - if os.system(mingw_prefix+"gcc --version"+nulstr)!=0: - #not really super consistent but.. - print("Can't find Windows compiler: "+mingw_prefix) - sys.exit(255) + # if os.system(mingw_prefix+"gcc --version"+nulstr)!=0: + # #not really super consistent but.. + # print("Can't find Windows compiler: "+mingw_prefix) + # sys.exit(255) if (env["target"]=="release"): @@ -231,11 +347,11 @@ def configure(env): env.Append(CCFLAGS=['-DGLES2_ENABLED','-DGLEW_ENABLED']) env.Append(LIBS=['mingw32','opengl32', 'dsound', 'ole32', 'd3d9','winmm','gdi32','iphlpapi','wsock32','kernel32']) - if (env["bits"]=="32" and env["mingw64_for_32"]!="yes"): -# env.Append(LIBS=['gcc_s']) - #--with-arch=i686 - env.Append(CPPFLAGS=['-march=i686']) - env.Append(LINKFLAGS=['-march=i686']) + # if (env["bits"]=="32"): +# # env.Append(LIBS=['gcc_s']) + # #--with-arch=i686 + # env.Append(CPPFLAGS=['-march=i686']) + # env.Append(LINKFLAGS=['-march=i686']) -- cgit v1.2.3 From fde7f11a559065af87dc345d34694f64eaa45e91 Mon Sep 17 00:00:00 2001 From: UsernameIsAReservedWord Date: Tue, 24 Feb 2015 22:31:18 +0100 Subject: Update detect.py --- platform/windows/detect.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/windows/detect.py b/platform/windows/detect.py index b07882f552..94e0b9853b 100644 --- a/platform/windows/detect.py +++ b/platform/windows/detect.py @@ -45,7 +45,7 @@ # # set PATH=C:\mingw-w64\bin;%PATH% # set PATH=C:\mingw-w64\bin;%PATH% -# set MINGW32_PREFIX=C:\mingw-w64\bin\ +# set MINGW32_PREFIX=C:\mingw-w32\bin\ # set MINGW64_PREFIX=C:\mingw-w64\bin\ # ##### -- cgit v1.2.3 From b3976ec14c0239faeed564ca105b2d27f5ac5ad7 Mon Sep 17 00:00:00 2001 From: UsernameIsAReservedWord Date: Tue, 24 Feb 2015 22:38:49 +0100 Subject: Update detect.py --- platform/windows/detect.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/windows/detect.py b/platform/windows/detect.py index 94e0b9853b..efd2e79cae 100644 --- a/platform/windows/detect.py +++ b/platform/windows/detect.py @@ -43,7 +43,7 @@ # For instance, you could store that set of commands into a .bat script # that you would run just before scons : # -# set PATH=C:\mingw-w64\bin;%PATH% +# set PATH=C:\mingw-w32\bin;%PATH% # set PATH=C:\mingw-w64\bin;%PATH% # set MINGW32_PREFIX=C:\mingw-w32\bin\ # set MINGW64_PREFIX=C:\mingw-w64\bin\ -- cgit v1.2.3 From 144494600620dbaeee454fb454b84f2388d6fe25 Mon Sep 17 00:00:00 2001 From: cheece <666mon@gmail.com> Date: Tue, 24 Feb 2015 20:13:21 -0430 Subject: COLLADA load normals from morph target if the file has normals use them! --- tools/editor/io_plugins/editor_import_collada.cpp | 54 ++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/tools/editor/io_plugins/editor_import_collada.cpp b/tools/editor/io_plugins/editor_import_collada.cpp index 529ed3374b..36d412d66c 100644 --- a/tools/editor/io_plugins/editor_import_collada.cpp +++ b/tools/editor/io_plugins/editor_import_collada.cpp @@ -1354,8 +1354,60 @@ Error ColladaImport::_create_mesh_surfaces(Ref& p_mesh,const Map::Write(); DVector normals; DVector tangents; + if(md.vertices[vertex_src_id].sources.has("NORMAL")){ + //has normals + normals.resize(vlen); + std::cout << "has normals" << std::endl; + String normal_src_id = md.vertices[vertex_src_id].sources["NORMAL"]; + std::cout << "normals source: "<< normal_src_id.utf8().get_data() <array.size() != vertex_src->array.size(), ERR_INVALID_DATA); + int stride=m->stride; + if (stride==0) + stride=3; + + + //read normals from morph target + DVector::Write vertw = normals.write(); + + for(int m_i=0;m_iarray.size()/stride;m_i++) { + + int pos = m_i*stride; + Vector3 vtx( m->array[pos+0], m->array[pos+1], m->array[pos+2] ); + + #ifndef NO_UP_AXIS_SWAP + if (collada.state.up_axis==Vector3::AXIS_Z) { + + SWAP( vtx.z, vtx.y ); + vtx.z = -vtx.z; + + } + #endif + + Collada::Vertex vertex; + vertex.vertex=vtx; + vertex.fix_unit_scale(collada); + vtx=vertex.vertex; + + vtx = p_local_xform.xform(vtx); + + + if (vertex_map.has(m_i)) { //vertex may no longer be here, don't bother converting + + + for (Set ::Element *E=vertex_map[m_i].front() ; E; E=E->next() ) { + + vertw[E->get()]=vtx; + } + } + } + + }else{ + _generate_normals(index_array,vertices,normals);//no normals + } if (final_tangent_array.size() && final_uv_array.size()) { _generate_tangents_and_binormals(index_array,vertices,final_uv_array,normals,tangents); -- cgit v1.2.3 From e7024259e19c18411272ec7b8d2aabf16a93e926 Mon Sep 17 00:00:00 2001 From: "Bil Bas (Spooner)" Date: Wed, 25 Feb 2015 17:24:32 +0000 Subject: Fixed columns to have integer positions, so that they don't "jiggle" when moving the camera. --- demos/2d/isometric/dungeon.scn | Bin 4582 -> 4721 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/demos/2d/isometric/dungeon.scn b/demos/2d/isometric/dungeon.scn index 76532a44aa..58c530d5c5 100644 Binary files a/demos/2d/isometric/dungeon.scn and b/demos/2d/isometric/dungeon.scn differ -- cgit v1.2.3 From 69cf996ce60f9419922b0de4590b7ece7fa0a8be Mon Sep 17 00:00:00 2001 From: UsernameIsAReservedWord Date: Thu, 26 Feb 2015 19:27:32 +0100 Subject: should fixes #1284 I could reproduce the crash described in #1284 only with 32bits versions of godot. The test scene contains a Plane collision shape, and a kinematicsbody with a Sphere collision shape. The crash occurs into `CollisionSolverSW::solve_distance_plane()` on line 299 when `p_shape_A` is a `PlaneShapeSW` object and when `p_shape_B` is a `MotionShapeSW` object, because `int support_count;` is not initialized by default, and because `MotionShapeSW::get_supports()` does not change `support_count` once passed as referenced parameter, and if the default value of `support_count` is greater than the length of `supports[16]`. I don't know if it is the good way to fix it because i'm not skilled ennough with the physics server inner working, but this fix prevents the crash and the test-scene seems to work correctly. --- servers/physics/shape_sw.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/servers/physics/shape_sw.h b/servers/physics/shape_sw.h index cdb21556b8..bcf8fbdc8d 100644 --- a/servers/physics/shape_sw.h +++ b/servers/physics/shape_sw.h @@ -438,7 +438,7 @@ struct MotionShapeSW : public ShapeSW { } return support; } - virtual void get_supports(const Vector3& p_normal,int p_max,Vector3 *r_supports,int & r_amount) const {} + virtual void get_supports(const Vector3& p_normal,int p_max,Vector3 *r_supports,int & r_amount) const { r_amount=0; } bool intersect_segment(const Vector3& p_begin,const Vector3& p_end,Vector3 &r_result, Vector3 &r_normal) const { return false; } Vector3 get_moment_of_inertia(float p_mass) const { return Vector3(); } -- cgit v1.2.3 From 525f2fe995d71f5321f19cd0e4076fcad526c5b5 Mon Sep 17 00:00:00 2001 From: theuserbl Date: Fri, 27 Feb 2015 11:09:57 +0100 Subject: Update register_scene_types.cpp Makes ToolButton usable for GDScript --- scene/register_scene_types.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp index ff525203bf..a1c4aaf811 100644 --- a/scene/register_scene_types.cpp +++ b/scene/register_scene_types.cpp @@ -76,6 +76,7 @@ #include "scene/gui/reference_frame.h" #include "scene/gui/graph_node.h" #include "scene/gui/graph_edit.h" +#include "scene/gui/tool_button.h" #include "scene/resources/video_stream.h" #include "scene/2d/particles_2d.h" #include "scene/2d/path_2d.h" @@ -288,6 +289,7 @@ void register_scene_types() { ObjectTypeDB::register_type(); ObjectTypeDB::register_type(); ObjectTypeDB::register_type(); + ObjectTypeDB::register_type(); ObjectTypeDB::register_type(); ObjectTypeDB::register_type(); -- cgit v1.2.3 From e2c0caf41e8ae2c992c81ceed89a95a5c0d0cbfa Mon Sep 17 00:00:00 2001 From: theuserbl Date: Fri, 27 Feb 2015 11:19:55 +0100 Subject: Update global_constants.cpp Making KEY_MASK_CMD usable in GDScript --- core/global_constants.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/core/global_constants.cpp b/core/global_constants.cpp index ae4abc627d..fc48a105db 100644 --- a/core/global_constants.cpp +++ b/core/global_constants.cpp @@ -313,6 +313,7 @@ static _GlobalConstant _global_constants[]={ BIND_GLOBAL_CONSTANT( KEY_MASK_ALT ), BIND_GLOBAL_CONSTANT( KEY_MASK_META ), BIND_GLOBAL_CONSTANT( KEY_MASK_CTRL ), + BIND_GLOBAL_CONSTANT( KEY_MASK_CMD ), BIND_GLOBAL_CONSTANT( KEY_MASK_KPAD ), BIND_GLOBAL_CONSTANT( KEY_MASK_GROUP_SWITCH ), -- cgit v1.2.3 From e8e9f100e57d6b68915fc6df5ed153384b026371 Mon Sep 17 00:00:00 2001 From: Mariano Javier Suligoy Date: Sun, 1 Mar 2015 11:23:05 -0300 Subject: Add CheckBox control with theme edition and radio icon avaible. --- scene/gui/check_box.cpp | 76 ++++++++++++++++++++++ scene/gui/check_box.h | 58 +++++++++++++++++ scene/resources/default_theme/default_theme.cpp | 32 ++++++++- scene/resources/default_theme/radio_checked.png | Bin 0 -> 569 bytes scene/resources/default_theme/radio_unchecked.png | Bin 0 -> 421 bytes scene/resources/default_theme/theme_data.h | 10 +++ tools/editor/icons/icon_check_box.png | Bin 0 -> 344 bytes 7 files changed, 175 insertions(+), 1 deletion(-) create mode 100644 scene/gui/check_box.cpp create mode 100644 scene/gui/check_box.h create mode 100644 scene/resources/default_theme/radio_checked.png create mode 100644 scene/resources/default_theme/radio_unchecked.png create mode 100644 tools/editor/icons/icon_check_box.png diff --git a/scene/gui/check_box.cpp b/scene/gui/check_box.cpp new file mode 100644 index 0000000000..1f37833618 --- /dev/null +++ b/scene/gui/check_box.cpp @@ -0,0 +1,76 @@ +/*************************************************************************/ +/* check_button.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "check_box.h" + +#include "servers/visual_server.h" +#include "button_group.h" + +void CheckBox::_bind_methods() +{ + ObjectTypeDB::bind_method(_MD("set_pressed","pressed"),&CheckBox::toggled); +} + +bool CheckBox::is_radio() +{ + Node* parent = this; + do { + parent = parent->get_parent(); + if (dynamic_cast< ButtonGroup* >( parent)) + break; + } while (parent != nullptr); + + return (parent != nullptr); +} + +void CheckBox::update_icon(bool p_pressed) +{ + if (is_radio()) + set_icon(Control::get_icon(p_pressed ? "radio_checked" : "radio_unchecked")); + else + set_icon(Control::get_icon(p_pressed ? "checked" : "unchecked")); +} + +void CheckBox::toggled(bool p_pressed) +{ + update_icon(); + BaseButton::toggled(p_pressed); +} + +CheckBox::CheckBox() +{ + set_toggle_mode(true); + set_text_align(ALIGN_LEFT); + + update_icon(is_pressed()); + +} + +CheckBox::~CheckBox() +{ +} diff --git a/scene/gui/check_box.h b/scene/gui/check_box.h new file mode 100644 index 0000000000..1f0d1ed7ed --- /dev/null +++ b/scene/gui/check_box.h @@ -0,0 +1,58 @@ +/*************************************************************************/ +/* check_box.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#ifndef CHECK_BOX_H +#define CHECK_BOX_H + + +#include "scene/gui/button.h" +/** +@author Mariano Suligoy +*/ +class CheckBox : public Button { + + OBJ_TYPE( CheckBox, Button ); + + +protected: + static void _bind_methods(); + + bool is_radio(); + + void update_icon(bool p_pressed); + + +public: + void toggled(bool p_pressed); + + CheckBox(); + ~CheckBox(); + +}; + +#endif diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp index 4d1e9896db..ab0688af81 100644 --- a/scene/resources/default_theme/default_theme.cpp +++ b/scene/resources/default_theme/default_theme.cpp @@ -300,6 +300,36 @@ void make_default_theme() { t->set_constant("hseparation","MenuButton", 0 ); + // CheckBox + + Ref cbx_empty = memnew( StyleBoxEmpty ); + Ref cbx_focus = focus; + cbx_focus->set_default_margin(MARGIN_LEFT,4); + cbx_focus->set_default_margin(MARGIN_RIGHT,4); + cbx_focus->set_default_margin(MARGIN_TOP,4); + cbx_focus->set_default_margin(MARGIN_BOTTOM,5); + + t->set_stylebox("normal","CheckBox", cbx_empty ); + t->set_stylebox("pressed","CheckBox", cbx_empty ); + t->set_stylebox("disabled","CheckBox", cbx_empty ); + t->set_stylebox("hover","CheckBox", cbx_empty ); + t->set_stylebox("focus","CheckBox", cbx_focus ); + + t->set_icon("checked", "CheckBox", make_icon(checked_png)); + t->set_icon("unchecked", "CheckBox", make_icon(unchecked_png)); + t->set_icon("radio_checked", "CheckBox", make_icon(radio_checked_png)); + t->set_icon("radio_unchecked", "CheckBox", make_icon(radio_unchecked_png)); + + t->set_font("font","CheckBox", default_font ); + + t->set_color("font_color","CheckBox", control_font_color ); + t->set_color("font_color_pressed","CheckBox", control_font_color_pressed ); + t->set_color("font_color_hover","CheckBox", control_font_color_hover ); + t->set_color("font_color_disabled","CheckBox", control_font_color_disabled ); + + t->set_constant("hseparation","CheckBox",4); + t->set_constant("check_vadjust","CheckBox",0); + // CheckButton @@ -308,7 +338,7 @@ void make_default_theme() { cb_empty->set_default_margin(MARGIN_LEFT,6); cb_empty->set_default_margin(MARGIN_RIGHT,70); cb_empty->set_default_margin(MARGIN_TOP,4); - cb_empty->set_default_margin(MARGIN_BOTTOM,4); + cb_empty->set_default_margin(MARGIN_BOTTOM,4); t->set_stylebox("normal","CheckButton", cb_empty ); t->set_stylebox("pressed","CheckButton", cb_empty ); diff --git a/scene/resources/default_theme/radio_checked.png b/scene/resources/default_theme/radio_checked.png new file mode 100644 index 0000000000..ada8dde3c1 Binary files /dev/null and b/scene/resources/default_theme/radio_checked.png differ diff --git a/scene/resources/default_theme/radio_unchecked.png b/scene/resources/default_theme/radio_unchecked.png new file mode 100644 index 0000000000..018af99afd Binary files /dev/null and b/scene/resources/default_theme/radio_unchecked.png differ diff --git a/scene/resources/default_theme/theme_data.h b/scene/resources/default_theme/theme_data.h index e9a6d3dad6..78e210239d 100644 --- a/scene/resources/default_theme/theme_data.h +++ b/scene/resources/default_theme/theme_data.h @@ -264,6 +264,16 @@ static const unsigned char progress_fill_png[]={ }; +static const unsigned char radio_checked_png[]={ +0x89,0x50,0x4e,0x47,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0xd,0x49,0x48,0x44,0x52,0x0,0x0,0x0,0x10,0x0,0x0,0x0,0x10,0x8,0x6,0x0,0x0,0x0,0x1f,0xf3,0xff,0x61,0x0,0x0,0x0,0x6,0x62,0x4b,0x47,0x44,0x0,0xff,0x0,0xff,0x0,0xff,0xa0,0xbd,0xa7,0x93,0x0,0x0,0x0,0x9,0x70,0x48,0x59,0x73,0x0,0x0,0xb,0x13,0x0,0x0,0xb,0x13,0x1,0x0,0x9a,0x9c,0x18,0x0,0x0,0x0,0x7,0x74,0x49,0x4d,0x45,0x7,0xdf,0x3,0x1,0x4,0x19,0x36,0x83,0x13,0x8d,0xb2,0x0,0x0,0x0,0x1d,0x69,0x54,0x58,0x74,0x43,0x6f,0x6d,0x6d,0x65,0x6e,0x74,0x0,0x0,0x0,0x0,0x0,0x43,0x72,0x65,0x61,0x74,0x65,0x64,0x20,0x77,0x69,0x74,0x68,0x20,0x47,0x49,0x4d,0x50,0x64,0x2e,0x65,0x7,0x0,0x0,0x1,0x9d,0x49,0x44,0x41,0x54,0x38,0xcb,0xad,0x93,0x31,0x6b,0xdb,0x50,0x14,0x85,0x3f,0x59,0x8a,0x21,0xbb,0x17,0xd1,0x37,0xa4,0xa4,0xb5,0x10,0xb5,0x3,0xfa,0x7,0x5d,0x3a,0x74,0xf2,0x56,0x39,0x64,0x4d,0x97,0x42,0x9b,0xce,0x6d,0x7e,0x44,0xe3,0x8e,0xf5,0x60,0x4,0xc5,0x22,0x9b,0x27,0x63,0xe8,0xea,0xc5,0x43,0x4d,0x48,0x40,0x7a,0xe9,0xd0,0xe0,0xd4,0x68,0x32,0x18,0x3c,0x8,0x64,0xc3,0xed,0x50,0x59,0x34,0x71,0xa7,0x3a,0x7,0xde,0x72,0xef,0x79,0x87,0x7b,0xde,0x3d,0xf,0xb6,0x84,0x71,0xbf,0xe0,0x38,0xce,0x23,0xe0,0x2d,0xf0,0x12,0xa8,0xe6,0xe5,0x6b,0xa0,0xf,0x7c,0xd6,0x5a,0x4f,0xff,0x29,0x60,0x99,0x16,0xfb,0x4f,0xf6,0x8f,0x81,0x56,0xb3,0x79,0xb4,0x7b,0x78,0xf8,0xa,0xc3,0xf8,0xd3,0x16,0x11,0xba,0xdd,0x73,0xc2,0xf0,0x6b,0xa,0xbc,0x9b,0x4c,0x26,0xed,0x34,0x4d,0xef,0xa,0x38,0x8e,0x73,0xbc,0xb7,0xf7,0xf8,0xcb,0xd9,0xd9,0xa7,0xe2,0xe2,0x7d,0x88,0x8,0x27,0x27,0xef,0xb9,0xb9,0xf9,0xf9,0x5a,0x6b,0xdd,0x2e,0x4,0xf2,0xb1,0x7f,0xf4,0x7a,0xbd,0x5d,0xc3,0x30,0xc8,0xb2,0x8c,0xf1,0x78,0x4c,0x14,0x45,0x0,0xb8,0xae,0x8b,0xe7,0x79,0x94,0xcb,0x65,0x44,0x84,0x46,0xa3,0x91,0x2,0x4f,0xb5,0xd6,0x53,0x13,0xa0,0x52,0xa9,0x7c,0x6c,0x36,0x8f,0x9e,0x1f,0x1c,0xd4,0xc8,0xb2,0x8c,0x4e,0xa7,0x43,0xab,0xd5,0x62,0x30,0x18,0x30,0x1c,0xe,0x19,0x8d,0x46,0xac,0x56,0x2b,0xea,0xf5,0x3a,0x96,0x65,0x21,0x52,0xda,0xb9,0xba,0xba,0x5c,0xce,0x66,0xb3,0x6f,0xeb,0xf1,0x2f,0xe2,0x38,0x16,0xad,0xb5,0x4,0x41,0x20,0x4a,0x29,0x1,0xee,0x1c,0xa5,0x94,0x4,0x41,0x20,0x5a,0x6b,0x89,0xe3,0x58,0x1c,0xc7,0xb9,0x0,0x28,0xe5,0xf6,0xaa,0x6b,0xdf,0x51,0x14,0x91,0x24,0xc9,0x86,0xff,0x24,0x49,0xa,0x4b,0x39,0xb7,0xfa,0xb7,0xc0,0x7f,0x63,0x2d,0x70,0x2d,0x22,0xc5,0x83,0xd9,0xb6,0xbd,0x41,0xb4,0x6d,0x1b,0xd7,0x75,0x8b,0x6d,0xe4,0xd9,0x28,0x4,0xfa,0xdd,0xee,0x39,0x0,0x9e,0xe7,0xe1,0xfb,0x3e,0x4a,0x29,0x4c,0xd3,0xc4,0x34,0x4d,0x94,0x52,0xf8,0xbe,0x8f,0xe7,0x79,0x0,0xe4,0xdc,0xfe,0x83,0xac,0x71,0xeb,0x20,0x99,0xeb,0xe6,0x62,0xb1,0xf8,0x6e,0x18,0x4c,0xc3,0x30,0x7c,0x21,0x52,0xda,0xa9,0xd5,0x9e,0x6d,0x44,0xf9,0xf4,0xf4,0x43,0x3a,0x9f,0xcf,0xdf,0xdc,0xde,0xfe,0x6a,0x2f,0x97,0xcb,0x87,0xf9,0x4c,0x5b,0xe3,0x37,0x57,0xdf,0xd7,0x8,0xe6,0x62,0x7d,0xab,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82 +}; + + +static const unsigned char radio_unchecked_png[]={ +0x89,0x50,0x4e,0x47,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0xd,0x49,0x48,0x44,0x52,0x0,0x0,0x0,0x10,0x0,0x0,0x0,0x10,0x8,0x6,0x0,0x0,0x0,0x1f,0xf3,0xff,0x61,0x0,0x0,0x0,0x6,0x62,0x4b,0x47,0x44,0x0,0xff,0x0,0xff,0x0,0xff,0xa0,0xbd,0xa7,0x93,0x0,0x0,0x0,0x9,0x70,0x48,0x59,0x73,0x0,0x0,0xb,0x13,0x0,0x0,0xb,0x13,0x1,0x0,0x9a,0x9c,0x18,0x0,0x0,0x0,0x7,0x74,0x49,0x4d,0x45,0x7,0xdf,0x3,0x1,0x4,0x1b,0x6,0x97,0xfc,0xdf,0x9c,0x0,0x0,0x0,0x1d,0x69,0x54,0x58,0x74,0x43,0x6f,0x6d,0x6d,0x65,0x6e,0x74,0x0,0x0,0x0,0x0,0x0,0x43,0x72,0x65,0x61,0x74,0x65,0x64,0x20,0x77,0x69,0x74,0x68,0x20,0x47,0x49,0x4d,0x50,0x64,0x2e,0x65,0x7,0x0,0x0,0x1,0x9,0x49,0x44,0x41,0x54,0x38,0xcb,0xad,0x93,0xbd,0x72,0x82,0x40,0x14,0x85,0xf,0x68,0xa,0x9e,0x21,0x8d,0x8e,0x9,0xdb,0xc4,0xc7,0x48,0x41,0x43,0x2b,0xa3,0xad,0x69,0x32,0xc3,0xda,0xc7,0xa7,0x8,0x94,0xa1,0xd,0x68,0x4b,0xc3,0x5b,0xd8,0x5f,0x2d,0xe2,0x60,0xe8,0x99,0xa1,0xd8,0x82,0xc2,0x34,0x17,0x67,0x35,0x19,0x43,0x34,0xa7,0xbc,0x7b,0xee,0x37,0xf7,0x6f,0x81,0x2b,0x65,0x9c,0x6,0x84,0x10,0xb7,0x0,0x7c,0x0,0xe,0x0,0x9b,0xc3,0x6b,0x0,0x19,0x80,0x90,0x88,0x8a,0x1f,0x1,0xdd,0x4e,0x17,0x83,0xbb,0xc1,0x14,0x40,0xe0,0x79,0x13,0x6b,0x3c,0x1e,0x1d,0x81,0xe3,0x78,0x89,0xc5,0xe2,0x5d,0x1,0x90,0x79,0x9e,0x47,0x4a,0xa9,0x63,0x80,0x10,0x62,0xda,0xeb,0xf5,0xdf,0x82,0xe0,0xf5,0x6c,0xc9,0x52,0xce,0xb0,0xdd,0x7e,0x3c,0x11,0x51,0x74,0x0,0x70,0xd9,0x9b,0x34,0x4d,0xad,0x36,0x7d,0xbb,0xae,0xab,0x0,0xdc,0x13,0x51,0x61,0x72,0xcc,0xf7,0xbc,0x89,0xd5,0x76,0x70,0xec,0xf5,0x1,0xa0,0x1,0x38,0xa7,0x3d,0x9f,0x13,0x7b,0x1d,0x1d,0x60,0x5f,0xb0,0x41,0x5b,0x7,0x5c,0x2c,0x53,0xdb,0xf3,0x5f,0xb5,0xd6,0x1,0x59,0x1c,0x2f,0x5b,0x67,0xb2,0x37,0xd3,0x1,0x21,0x1f,0x49,0x2b,0xb1,0x37,0x3c,0x0,0xf8,0x3c,0xa5,0x94,0xb3,0x5f,0x93,0xd9,0x23,0x9b,0x93,0xee,0x34,0xf,0x55,0x55,0xad,0xc,0x3,0x45,0x92,0x24,0x8f,0xfb,0xbd,0x79,0x33,0x1c,0x3e,0x7c,0x2b,0x7b,0x3e,0x7f,0x51,0x65,0x59,0x3e,0xef,0x76,0x9f,0x51,0x5d,0xd7,0xff,0xf3,0x99,0xae,0xd6,0x17,0xf,0x97,0x66,0x8b,0x3d,0xf1,0x64,0x47,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82 +}; + + static const unsigned char reference_border_png[]={ 0x89,0x50,0x4e,0x47,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0xd,0x49,0x48,0x44,0x52,0x0,0x0,0x0,0x10,0x0,0x0,0x0,0x10,0x8,0x6,0x0,0x0,0x0,0x1f,0xf3,0xff,0x61,0x0,0x0,0x0,0x1,0x73,0x52,0x47,0x42,0x0,0xae,0xce,0x1c,0xe9,0x0,0x0,0x0,0x6,0x62,0x4b,0x47,0x44,0x0,0xff,0x0,0xff,0x0,0xff,0xa0,0xbd,0xa7,0x93,0x0,0x0,0x0,0x9,0x70,0x48,0x59,0x73,0x0,0x0,0xb,0x13,0x0,0x0,0xb,0x13,0x1,0x0,0x9a,0x9c,0x18,0x0,0x0,0x0,0x7,0x74,0x49,0x4d,0x45,0x7,0xdb,0x7,0x9,0x11,0x2b,0x1a,0xed,0xf3,0x18,0x82,0x0,0x0,0x0,0x5b,0x49,0x44,0x41,0x54,0x38,0xcb,0x63,0xfc,0xbf,0x7d,0xfb,0x7f,0x6,0x6,0x6,0x6,0x86,0xae,0x2e,0x6,0x92,0x40,0x59,0x19,0x84,0x86,0x1b,0x40,0x6,0xf8,0xbf,0x7d,0xfb,0x7f,0xc6,0xff,0x8e,0x8e,0xff,0x19,0xf7,0xef,0x67,0xfc,0x7f,0xf1,0x22,0x49,0x9a,0x19,0xf5,0xf5,0x19,0xfe,0x3b,0x3a,0xfe,0x67,0x41,0x17,0x24,0xca,0x66,0x24,0xcb,0x98,0x18,0x28,0x4,0xa3,0x6,0x8c,0x1a,0xc0,0xc0,0xc0,0xc0,0xc0,0x82,0x2b,0x85,0x91,0x94,0x21,0x28,0xcb,0x4c,0x14,0x66,0x67,0x0,0x0,0x2b,0x27,0xc7,0x5e,0xa8,0x15,0xe4,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82 }; diff --git a/tools/editor/icons/icon_check_box.png b/tools/editor/icons/icon_check_box.png new file mode 100644 index 0000000000..8a2b56cc3e Binary files /dev/null and b/tools/editor/icons/icon_check_box.png differ -- cgit v1.2.3 From 205ed6c9f5d6680608765dde17cbcabedfbbffa9 Mon Sep 17 00:00:00 2001 From: Mariano Javier Suligoy Date: Sun, 1 Mar 2015 16:45:13 -0300 Subject: Improve mechanism and fix radio icon rendering. --- scene/gui/check_box.cpp | 45 +++++++++++++------------ scene/gui/check_box.h | 7 ++-- scene/resources/default_theme/default_theme.cpp | 8 +++-- 3 files changed, 32 insertions(+), 28 deletions(-) diff --git a/scene/gui/check_box.cpp b/scene/gui/check_box.cpp index 1f37833618..ac156f5144 100644 --- a/scene/gui/check_box.cpp +++ b/scene/gui/check_box.cpp @@ -31,9 +31,27 @@ #include "servers/visual_server.h" #include "button_group.h" -void CheckBox::_bind_methods() -{ - ObjectTypeDB::bind_method(_MD("set_pressed","pressed"),&CheckBox::toggled); + +void CheckBox::_notification(int p_what) { + + if (p_what==NOTIFICATION_DRAW) { + + RID ci = get_canvas_item(); + + Ref on=Control::get_icon(is_radio() ? "radio_checked" : "checked"); + Ref off=Control::get_icon(is_radio() ? "radio_unchecked" : "unchecked"); + + Vector2 ofs; + ofs.x = 0; + ofs.y = int((get_size().height - on->get_height())/2); + + if (is_pressed()) + on->draw(ci,ofs); + else + off->draw(ci,ofs); + + + } } bool CheckBox::is_radio() @@ -41,34 +59,19 @@ bool CheckBox::is_radio() Node* parent = this; do { parent = parent->get_parent(); - if (dynamic_cast< ButtonGroup* >( parent)) + if (dynamic_cast< ButtonGroup* >(parent)) break; } while (parent != nullptr); return (parent != nullptr); } -void CheckBox::update_icon(bool p_pressed) -{ - if (is_radio()) - set_icon(Control::get_icon(p_pressed ? "radio_checked" : "radio_unchecked")); - else - set_icon(Control::get_icon(p_pressed ? "checked" : "unchecked")); -} - -void CheckBox::toggled(bool p_pressed) -{ - update_icon(); - BaseButton::toggled(p_pressed); -} - -CheckBox::CheckBox() +CheckBox::CheckBox(const String &p_text): + Button(p_text) { set_toggle_mode(true); set_text_align(ALIGN_LEFT); - update_icon(is_pressed()); - } CheckBox::~CheckBox() diff --git a/scene/gui/check_box.h b/scene/gui/check_box.h index 1f0d1ed7ed..171fd55351 100644 --- a/scene/gui/check_box.h +++ b/scene/gui/check_box.h @@ -40,17 +40,14 @@ class CheckBox : public Button { protected: - static void _bind_methods(); + void _notification(int p_what); bool is_radio(); - void update_icon(bool p_pressed); - public: - void toggled(bool p_pressed); - CheckBox(); + CheckBox(const String& p_text=String()); ~CheckBox(); }; diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp index ab0688af81..7d5981522e 100644 --- a/scene/resources/default_theme/default_theme.cpp +++ b/scene/resources/default_theme/default_theme.cpp @@ -303,9 +303,13 @@ void make_default_theme() { // CheckBox Ref cbx_empty = memnew( StyleBoxEmpty ); + cbx_empty->set_default_margin(MARGIN_LEFT,22); + cbx_empty->set_default_margin(MARGIN_RIGHT,4); + cbx_empty->set_default_margin(MARGIN_TOP,4); + cbx_empty->set_default_margin(MARGIN_BOTTOM,5); Ref cbx_focus = focus; cbx_focus->set_default_margin(MARGIN_LEFT,4); - cbx_focus->set_default_margin(MARGIN_RIGHT,4); + cbx_focus->set_default_margin(MARGIN_RIGHT,22); cbx_focus->set_default_margin(MARGIN_TOP,4); cbx_focus->set_default_margin(MARGIN_BOTTOM,5); @@ -570,7 +574,7 @@ void make_default_theme() { // Tree Ref tree_selected = make_stylebox( selection_png,4,4,4,4,8,0,8,0); - Ref tree_selected_oof = make_stylebox( selection_oof_png,4,4,4,4,8,0,8,0); + Ref tree_selected_oof = make_stylebox( selection_oof_png,4,4,4,4,8,0,8,0); t->set_stylebox("bg","Tree", make_stylebox( tree_bg_png,4,4,4,5) ); t->set_stylebox("bg_focus","Tree", focus ); -- cgit v1.2.3 From 63006f6f6f55573d55c14fcb9f7b6eeb6444aeb6 Mon Sep 17 00:00:00 2001 From: Mariano Javier Suligoy Date: Sun, 1 Mar 2015 21:07:50 -0300 Subject: Register CheckBox class to create it using editor. --- scene/gui/base_button.cpp | 5 +++-- scene/register_scene_types.cpp | 2 ++ tools/editor/plugins/theme_editor_plugin.cpp | 20 ++++++++++++++++++++ tools/editor/plugins/theme_editor_plugin.h | 2 ++ 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp index 0167687621..bbe15da1cc 100644 --- a/scene/gui/base_button.cpp +++ b/scene/gui/base_button.cpp @@ -279,12 +279,12 @@ void BaseButton::set_disabled(bool p_disabled) { set_focus_mode(FOCUS_NONE); else set_focus_mode(FOCUS_ALL); -}; +} bool BaseButton::is_disabled() const { return status.disabled; -}; +} void BaseButton::set_pressed(bool p_pressed) { @@ -391,6 +391,7 @@ void BaseButton::_bind_methods() { ADD_SIGNAL( MethodInfo("toggled", PropertyInfo( Variant::BOOL,"pressed") ) ); ADD_PROPERTY( PropertyInfo( Variant::BOOL, "disabled"), _SCS("set_disabled"), _SCS("is_disabled")); ADD_PROPERTY( PropertyInfo( Variant::BOOL, "toggle_mode"), _SCS("set_toggle_mode"), _SCS("is_toggle_mode")); + ADD_PROPERTY( PropertyInfo( Variant::BOOL, "is_pressed"), _SCS("set_pressed"), _SCS("is_pressed")); ADD_PROPERTY( PropertyInfo( Variant::BOOL, "click_on_press"), _SCS("set_click_on_press"), _SCS("get_click_on_press")); diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp index ff525203bf..02a9b60508 100644 --- a/scene/register_scene_types.cpp +++ b/scene/register_scene_types.cpp @@ -53,6 +53,7 @@ #include "scene/gui/color_picker.h" #include "scene/gui/texture_frame.h" #include "scene/gui/menu_button.h" +#include "scene/gui/check_box.h" #include "scene/gui/check_button.h" #include "scene/gui/tab_container.h" #include "scene/gui/panel_container.h" @@ -287,6 +288,7 @@ void register_scene_types() { ObjectTypeDB::register_type(); ObjectTypeDB::register_type(); ObjectTypeDB::register_type(); + ObjectTypeDB::register_type(); ObjectTypeDB::register_type(); ObjectTypeDB::register_type(); ObjectTypeDB::register_type(); diff --git a/tools/editor/plugins/theme_editor_plugin.cpp b/tools/editor/plugins/theme_editor_plugin.cpp index ccbd923118..bd6fb37b29 100644 --- a/tools/editor/plugins/theme_editor_plugin.cpp +++ b/tools/editor/plugins/theme_editor_plugin.cpp @@ -568,6 +568,26 @@ ThemeEditor::ThemeEditor() { CheckButton *cb = memnew( CheckButton ); cb->set_text("CheckButton"); first_vb->add_child(cb ); + CheckBox *cbx = memnew( CheckBox ); + cbx->set_text("CheckBox"); + first_vb->add_child(cbx ); + + /* TODO: This is not working properly, controls are overlapping*/ + /* + ButtonGroup *bg = memnew( ButtonGroup ); + bg->set_v_size_flags(SIZE_EXPAND_FILL); + VBoxContainer *gbvb = memnew( VBoxContainer ); + gbvb->set_v_size_flags(SIZE_EXPAND_FILL); + CheckBox *rbx1 = memnew( CheckBox ); + rbx1->set_text("CheckBox Radio1"); + rbx1->set_pressed(true); + gbvb->add_child(rbx1); + CheckBox *rbx2 = memnew( CheckBox ); + rbx2->set_text("CheckBox Radio2"); + gbvb->add_child(rbx2); + bg->add_child(gbvb); + first_vb->add_child(bg); + */ MenuButton* test_menu_button = memnew( MenuButton ); test_menu_button->set_text("MenuButton"); diff --git a/tools/editor/plugins/theme_editor_plugin.h b/tools/editor/plugins/theme_editor_plugin.h index 98156422ee..83432b9232 100644 --- a/tools/editor/plugins/theme_editor_plugin.h +++ b/tools/editor/plugins/theme_editor_plugin.h @@ -33,6 +33,8 @@ #include "scene/gui/texture_frame.h" #include "scene/gui/option_button.h" #include "scene/gui/file_dialog.h" +#include "scene/gui/check_box.h" +#include "scene/gui/button_group.h" #include "tools/editor/editor_node.h" -- cgit v1.2.3 From 31e6c6ca8fa84ff5e2c7e007a68eae1a54115f26 Mon Sep 17 00:00:00 2001 From: theuserbl Date: Thu, 5 Mar 2015 23:05:30 +0100 Subject: Changed *_scene() to *_tree() Changed _enter_scene and _exit_scene() to _enter_tree() and _exit_tree() in the time-example, because the *_scene no longer work. --- tools/script_plugins/time/time.gd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/script_plugins/time/time.gd b/tools/script_plugins/time/time.gd index 66b3e9ed04..2e56d89d4f 100644 --- a/tools/script_plugins/time/time.gd +++ b/tools/script_plugins/time/time.gd @@ -21,12 +21,12 @@ func _init(): timer.set_one_shot(false) timer.connect("timeout",self,"_timeout") -func _enter_scene(): +func _enter_tree(): label = Label.new() add_custom_control(CONTAINER_TOOLBAR,label) timer.start() -func _exit_scene(): +func _exit_tree(): timer.stop() label.free() label=null -- cgit v1.2.3 From ba74e45027f795238323c3667dfdb660608d7484 Mon Sep 17 00:00:00 2001 From: hurikhan Date: Sun, 8 Mar 2015 01:27:36 -0600 Subject: added Label_MouseGrab_KeyInfo --- demos/misc/window_management/control.gd | 3 +++ demos/misc/window_management/window_management.scn | Bin 4850 -> 5072 bytes 2 files changed, 3 insertions(+) diff --git a/demos/misc/window_management/control.gd b/demos/misc/window_management/control.gd index 50fc3a3765..7f805a1a21 100644 --- a/demos/misc/window_management/control.gd +++ b/demos/misc/window_management/control.gd @@ -21,6 +21,9 @@ func _fixed_process(delta): if(Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED): modetext += "MouseGrab\n" + get_node("Label_MouseGrab_KeyInfo").show() + else: + get_node("Label_MouseGrab_KeyInfo").hide() get_node("Label_Mode").set_text(modetext) diff --git a/demos/misc/window_management/window_management.scn b/demos/misc/window_management/window_management.scn index 14d0da0415..0cb7030ffc 100644 Binary files a/demos/misc/window_management/window_management.scn and b/demos/misc/window_management/window_management.scn differ -- cgit v1.2.3 From 5241626dee5aa7f91da7d7ac5476fb76e1d0b89e Mon Sep 17 00:00:00 2001 From: hurikhan Date: Sun, 8 Mar 2015 03:32:13 -0500 Subject: fixing a typo in the demo --- demos/misc/window_management/window_management.scn | Bin 5072 -> 5068 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/demos/misc/window_management/window_management.scn b/demos/misc/window_management/window_management.scn index 0cb7030ffc..9b963a0a15 100644 Binary files a/demos/misc/window_management/window_management.scn and b/demos/misc/window_management/window_management.scn differ -- cgit v1.2.3 From 52a4e8495c6b9324f3c61f85c3ed3708c3e93213 Mon Sep 17 00:00:00 2001 From: hurikhan Date: Sun, 8 Mar 2015 04:24:21 -0500 Subject: fix introduced bug --- platform/x11/os_x11.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index 8def564562..8196281732 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -1286,7 +1286,7 @@ void OS_X11::process_xevents() { motion_event.mouse_motion.x=pos.x; motion_event.mouse_motion.y=pos.y; input->set_mouse_pos(pos); - motion_event.mouse_motion.global_x=pos.y; + motion_event.mouse_motion.global_x=pos.x; motion_event.mouse_motion.global_y=pos.y; motion_event.mouse_motion.speed_x=input->get_mouse_speed().x; motion_event.mouse_motion.speed_y=input->get_mouse_speed().y; -- cgit v1.2.3 From 0bc7eb1d91212e5fcc799d1b790430a4c2468751 Mon Sep 17 00:00:00 2001 From: Mariano Javier Suligoy Date: Sun, 8 Mar 2015 10:39:27 -0300 Subject: Fix C++11 compilation --- scene/gui/check_box.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scene/gui/check_box.cpp b/scene/gui/check_box.cpp index ac156f5144..309152ba8f 100644 --- a/scene/gui/check_box.cpp +++ b/scene/gui/check_box.cpp @@ -61,9 +61,9 @@ bool CheckBox::is_radio() parent = parent->get_parent(); if (dynamic_cast< ButtonGroup* >(parent)) break; - } while (parent != nullptr); + } while (parent); - return (parent != nullptr); + return (parent != 0); } CheckBox::CheckBox(const String &p_text): -- cgit v1.2.3 From f7621810a2f072a5d77563b6018023c575f355bf Mon Sep 17 00:00:00 2001 From: hurikhan Date: Sun, 8 Mar 2015 09:26:58 -0500 Subject: removed up, down, left, right keys from the demo. were used before for fast multiscreen setup testing. --- demos/misc/window_management/control.gd | 12 ------------ demos/misc/window_management/window_management.scn | Bin 5068 -> 5087 bytes 2 files changed, 12 deletions(-) diff --git a/demos/misc/window_management/control.gd b/demos/misc/window_management/control.gd index 7f805a1a21..bca13c5a0c 100644 --- a/demos/misc/window_management/control.gd +++ b/demos/misc/window_management/control.gd @@ -54,18 +54,6 @@ func _fixed_process(delta): get_node("Label_Screen1_Resolution").hide() get_node("Label_Screen1_Position").hide() - if( Input.is_action_pressed("ui_right")): - OS.set_screen(1) - - if( Input.is_action_pressed("ui_left")): - OS.set_screen(0) - - if( Input.is_action_pressed("ui_up")): - OS.set_fullscreen(true) - - if( Input.is_action_pressed("ui_down")): - OS.set_fullscreen(false) - get_node("Button_Fullscreen").set_pressed( OS.is_fullscreen() ) get_node("Button_FixedSize").set_pressed( !OS.is_resizable() ) get_node("Button_Minimized").set_pressed( OS.is_minimized() ) diff --git a/demos/misc/window_management/window_management.scn b/demos/misc/window_management/window_management.scn index 9b963a0a15..b8b0ee210b 100644 Binary files a/demos/misc/window_management/window_management.scn and b/demos/misc/window_management/window_management.scn differ -- cgit v1.2.3 From 57380f9aba2352755273acb9dcd5f20351e668ce Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Tue, 10 Mar 2015 09:53:22 -0300 Subject: increase minimum range in property editor a bit --- tools/editor/property_editor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/editor/property_editor.cpp b/tools/editor/property_editor.cpp index fb4c134263..f760ab1cb5 100644 --- a/tools/editor/property_editor.cpp +++ b/tools/editor/property_editor.cpp @@ -2362,7 +2362,7 @@ void PropertyEditor::update_tree() { } else { if (p.type == Variant::REAL) { - item->set_range_config(1, -65536, 65535, 0.01); + item->set_range_config(1, -65536, 65535, 0.001); } else { item->set_range_config(1, -65536, 65535, 1); -- cgit v1.2.3 From a6f96f46b779a815b03974fece21728fe32e88d2 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Tue, 10 Mar 2015 21:05:49 -0300 Subject: small optimizations to isometric light demo should work faster, and even faster if exported.. as textures have been optimized. --- demos/2d/isometric_light/cubio.scn | Bin 6878 -> 6927 bytes demos/2d/isometric_light/export.cfg | 262 +++++++++++++++++++++++++++++ demos/2d/isometric_light/faceNormal.png | Bin 131067 -> 54844 bytes demos/2d/isometric_light/floor_shader.res | Bin 972 -> 1026 bytes demos/2d/isometric_light/light2.png | Bin 60871 -> 3500 bytes demos/2d/isometric_light/map.scn | Bin 8520 -> 8565 bytes demos/2d/isometric_light/tileset_scene.scn | Bin 4813 -> 4812 bytes demos/2d/isometric_light/torch.scn | Bin 4232 -> 4262 bytes demos/2d/isometric_light/torch_light.png | Bin 28516 -> 1262 bytes demos/2d/isometric_light/wall_shader.res | Bin 1628 -> 1684 bytes scene/2d/light_2d.cpp | 26 ++- scene/2d/light_2d.h | 4 + scene/resources/texture.cpp | 9 + scene/resources/texture.h | 2 + servers/visual/rasterizer.h | 2 + servers/visual/visual_server_raster.cpp | 10 ++ servers/visual/visual_server_raster.h | 1 + servers/visual/visual_server_wrap_mt.h | 1 + servers/visual_server.h | 1 + 19 files changed, 317 insertions(+), 1 deletion(-) create mode 100644 demos/2d/isometric_light/export.cfg diff --git a/demos/2d/isometric_light/cubio.scn b/demos/2d/isometric_light/cubio.scn index 29fa077389..c8ab7ddd4e 100644 Binary files a/demos/2d/isometric_light/cubio.scn and b/demos/2d/isometric_light/cubio.scn differ diff --git a/demos/2d/isometric_light/export.cfg b/demos/2d/isometric_light/export.cfg new file mode 100644 index 0000000000..578d4171b2 --- /dev/null +++ b/demos/2d/isometric_light/export.cfg @@ -0,0 +1,262 @@ +[convert_images] + +action="none" +compress_quality=0.7 +formats="png" +shrink=1 + +[export_filter] + +filter="" +type="resources" + +[image_group_files] + +files=["res://faceNormal.png", "normal", "res://faceColor.png", "normal", "res://faceMask.png", "normal"] + +[image_groups] + +normal={"atlas":false, "action":"compress_ram", "shrink":1, "lossy_quality":0.7} + +[platform:Android] + +apk_expansion/SALT="" +apk_expansion/enable=false +apk_expansion/public_key="" +command_line/extra_args="" +custom_package/debug="" +custom_package/release="" +keystore/release="" +keystore/release_password="" +keystore/release_user="" +one_click_deploy/clear_previous_install=true +package/icon="" +package/name="" +package/signed=true +package/unique_name="com.android.noname" +permissions/access_checkin_properties=false +permissions/access_coarse_location=false +permissions/access_fine_location=false +permissions/access_location_extra_commands=false +permissions/access_mock_location=false +permissions/access_network_state=false +permissions/access_surface_flinger=false +permissions/access_wifi_state=false +permissions/account_manager=false +permissions/add_voicemail=false +permissions/authenticate_accounts=false +permissions/battery_stats=false +permissions/bind_accessibility_service=false +permissions/bind_appwidget=false +permissions/bind_device_admin=false +permissions/bind_input_method=false +permissions/bind_nfc_service=false +permissions/bind_notification_listener_service=false +permissions/bind_print_service=false +permissions/bind_remoteviews=false +permissions/bind_text_service=false +permissions/bind_vpn_service=false +permissions/bind_wallpaper=false +permissions/bluetooth=false +permissions/bluetooth_admin=false +permissions/bluetooth_privileged=false +permissions/brick=false +permissions/broadcast_package_removed=false +permissions/broadcast_sms=false +permissions/broadcast_sticky=false +permissions/broadcast_wap_push=false +permissions/call_phone=false +permissions/call_privileged=false +permissions/camera=false +permissions/capture_audio_output=false +permissions/capture_secure_video_output=false +permissions/capture_video_output=false +permissions/change_component_enabled_state=false +permissions/change_configuration=false +permissions/change_network_state=false +permissions/change_wifi_multicast_state=false +permissions/change_wifi_state=false +permissions/clear_app_cache=false +permissions/clear_app_user_data=false +permissions/control_location_updates=false +permissions/delete_cache_files=false +permissions/delete_packages=false +permissions/device_power=false +permissions/diagnostic=false +permissions/disable_keyguard=false +permissions/dump=false +permissions/expand_status_bar=false +permissions/factory_test=false +permissions/flashlight=false +permissions/force_back=false +permissions/get_accounts=false +permissions/get_package_size=false +permissions/get_tasks=false +permissions/get_top_activity_info=false +permissions/global_search=false +permissions/hardware_test=false +permissions/inject_events=false +permissions/install_location_provider=false +permissions/install_packages=false +permissions/install_shortcut=false +permissions/internal_system_window=false +permissions/internet=false +permissions/kill_background_processes=false +permissions/location_hardware=false +permissions/manage_accounts=false +permissions/manage_app_tokens=false +permissions/manage_documents=false +permissions/master_clear=false +permissions/media_content_control=false +permissions/modify_audio_settings=false +permissions/modify_phone_state=false +permissions/mount_format_filesystems=false +permissions/mount_unmount_filesystems=false +permissions/nfc=false +permissions/persistent_activity=false +permissions/process_outgoing_calls=false +permissions/read_calendar=false +permissions/read_call_log=false +permissions/read_contacts=false +permissions/read_external_storage=false +permissions/read_frame_buffer=false +permissions/read_history_bookmarks=false +permissions/read_input_state=false +permissions/read_logs=false +permissions/read_phone_state=false +permissions/read_profile=false +permissions/read_sms=false +permissions/read_social_stream=false +permissions/read_sync_settings=false +permissions/read_sync_stats=false +permissions/read_user_dictionary=false +permissions/reboot=false +permissions/receive_boot_completed=false +permissions/receive_mms=false +permissions/receive_sms=false +permissions/receive_wap_push=false +permissions/record_audio=false +permissions/reorder_tasks=false +permissions/restart_packages=false +permissions/send_respond_via_message=false +permissions/send_sms=false +permissions/set_activity_watcher=false +permissions/set_alarm=false +permissions/set_always_finish=false +permissions/set_animation_scale=false +permissions/set_debug_app=false +permissions/set_orientation=false +permissions/set_pointer_speed=false +permissions/set_preferred_applications=false +permissions/set_process_limit=false +permissions/set_time=false +permissions/set_time_zone=false +permissions/set_wallpaper=false +permissions/set_wallpaper_hints=false +permissions/signal_persistent_processes=false +permissions/status_bar=false +permissions/subscribed_feeds_read=false +permissions/subscribed_feeds_write=false +permissions/system_alert_window=false +permissions/transmit_ir=false +permissions/uninstall_shortcut=false +permissions/update_device_stats=false +permissions/use_credentials=false +permissions/use_sip=false +permissions/vibrate=false +permissions/wake_lock=false +permissions/write_apn_settings=false +permissions/write_calendar=false +permissions/write_call_log=false +permissions/write_contacts=false +permissions/write_external_storage=false +permissions/write_gservices=false +permissions/write_history_bookmarks=false +permissions/write_profile=false +permissions/write_secure_settings=false +permissions/write_settings=false +permissions/write_sms=false +permissions/write_social_stream=false +permissions/write_sync_settings=false +permissions/write_user_dictionary=false +screen/orientation=0 +screen/support_large=true +screen/support_normal=true +screen/support_small=true +screen/support_xlarge=true +user_permissions/0="" +user_permissions/1="" +user_permissions/10="" +user_permissions/11="" +user_permissions/12="" +user_permissions/13="" +user_permissions/14="" +user_permissions/15="" +user_permissions/16="" +user_permissions/17="" +user_permissions/18="" +user_permissions/19="" +user_permissions/2="" +user_permissions/3="" +user_permissions/4="" +user_permissions/5="" +user_permissions/6="" +user_permissions/7="" +user_permissions/8="" +user_permissions/9="" +version/code=1 +version/name="1.0" + +[platform:BlackBerry 10] + +package/category="core.games" +package/custom_template="" +package/description="Game made with Godot Engine" +package/icon="" +package/name="" +package/unique_name="com.godot.noname" +release/author="Cert. Name" +release/author_id="Cert. ID" +version/code=1 +version/name="1.0" + +[platform:HTML5] + +browser/enable_run=false +custom_package/debug="" +custom_package/release="" +options/memory_size=3 + +[platform:Linux X11] + +binary/64_bits=true +custom_binary/debug="" +custom_binary/release="" +resources/pack_mode=1 + +[platform:Mac OSX] + +application/64_bits=false +application/copyright="" +application/icon="" +application/identifier="com.godot.macgame" +application/info="This Game is Nice" +application/name="" +application/short_version="1.0" +application/signature="godotmacgame" +application/version="1.0" +custom_package/debug="" +custom_package/release="" +display/high_res=false + +[platform:Windows Desktop] + +binary/64_bits=true +custom_binary/debug="" +custom_binary/release="" +resources/pack_mode=1 + +[script] + +action="compile" +encrypt_key="" diff --git a/demos/2d/isometric_light/faceNormal.png b/demos/2d/isometric_light/faceNormal.png index c6498dd1df..651f075fa1 100644 Binary files a/demos/2d/isometric_light/faceNormal.png and b/demos/2d/isometric_light/faceNormal.png differ diff --git a/demos/2d/isometric_light/floor_shader.res b/demos/2d/isometric_light/floor_shader.res index d4fac5b933..446c71d227 100644 Binary files a/demos/2d/isometric_light/floor_shader.res and b/demos/2d/isometric_light/floor_shader.res differ diff --git a/demos/2d/isometric_light/light2.png b/demos/2d/isometric_light/light2.png index dd035e9911..cd473251aa 100644 Binary files a/demos/2d/isometric_light/light2.png and b/demos/2d/isometric_light/light2.png differ diff --git a/demos/2d/isometric_light/map.scn b/demos/2d/isometric_light/map.scn index 10de40d4ac..fb2f3a2154 100644 Binary files a/demos/2d/isometric_light/map.scn and b/demos/2d/isometric_light/map.scn differ diff --git a/demos/2d/isometric_light/tileset_scene.scn b/demos/2d/isometric_light/tileset_scene.scn index e76a22c892..3d0773c9c5 100644 Binary files a/demos/2d/isometric_light/tileset_scene.scn and b/demos/2d/isometric_light/tileset_scene.scn differ diff --git a/demos/2d/isometric_light/torch.scn b/demos/2d/isometric_light/torch.scn index 2daa199e92..d1cb7fe7e6 100644 Binary files a/demos/2d/isometric_light/torch.scn and b/demos/2d/isometric_light/torch.scn differ diff --git a/demos/2d/isometric_light/torch_light.png b/demos/2d/isometric_light/torch_light.png index 60e5838043..a98113d36f 100644 Binary files a/demos/2d/isometric_light/torch_light.png and b/demos/2d/isometric_light/torch_light.png differ diff --git a/demos/2d/isometric_light/wall_shader.res b/demos/2d/isometric_light/wall_shader.res index a1318746a5..78c8fe57e1 100644 Binary files a/demos/2d/isometric_light/wall_shader.res and b/demos/2d/isometric_light/wall_shader.res differ diff --git a/scene/2d/light_2d.cpp b/scene/2d/light_2d.cpp index 5472e0b00e..8f6907798f 100644 --- a/scene/2d/light_2d.cpp +++ b/scene/2d/light_2d.cpp @@ -23,7 +23,7 @@ Rect2 Light2D::get_item_rect() const { Size2i s; - s = texture->get_size(); + s = texture->get_size()*scale; Point2i ofs=texture_offset; ofs-=s/2; @@ -63,6 +63,8 @@ void Light2D::set_texture_offset( const Vector2& p_offset) { texture_offset=p_offset; VS::get_singleton()->canvas_light_set_texture_offset(canvas_light,texture_offset); + item_rect_changed(); + } Vector2 Light2D::get_texture_offset() const { @@ -87,11 +89,27 @@ void Light2D::set_height( float p_height) { VS::get_singleton()->canvas_light_set_height(canvas_light,height); } + + float Light2D::get_height() const { return height; } +void Light2D::set_scale( float p_scale) { + + scale=p_scale; + VS::get_singleton()->canvas_light_set_scale(canvas_light,scale); + item_rect_changed(); + +} + + +float Light2D::get_scale() const { + + return scale; +} + void Light2D::set_z_range_min( int p_min_z) { z_min=p_min_z; @@ -242,6 +260,10 @@ void Light2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_height","height"),&Light2D::set_height); ObjectTypeDB::bind_method(_MD("get_height"),&Light2D::get_height); + ObjectTypeDB::bind_method(_MD("set_scale","scale"),&Light2D::set_scale); + ObjectTypeDB::bind_method(_MD("get_scale"),&Light2D::get_scale); + + ObjectTypeDB::bind_method(_MD("set_z_range_min","z"),&Light2D::set_z_range_min); ObjectTypeDB::bind_method(_MD("get_z_range_min"),&Light2D::get_z_range_min); @@ -276,6 +298,7 @@ void Light2D::_bind_methods() { ADD_PROPERTY( PropertyInfo(Variant::BOOL,"enabled"),_SCS("set_enabled"),_SCS("is_enabled")); ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"texture",PROPERTY_HINT_RESOURCE_TYPE,"Texture"),_SCS("set_texture"),_SCS("get_texture")); ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"offset"),_SCS("set_texture_offset"),_SCS("get_texture_offset")); + ADD_PROPERTY( PropertyInfo(Variant::REAL,"scale",PROPERTY_HINT_RANGE,"0.01,4096,0.01"),_SCS("set_scale"),_SCS("get_scale")); ADD_PROPERTY( PropertyInfo(Variant::COLOR,"color"),_SCS("set_color"),_SCS("get_color")); ADD_PROPERTY( PropertyInfo(Variant::BOOL,"subtract"),_SCS("set_subtract_mode"),_SCS("get_subtract_mode")); ADD_PROPERTY( PropertyInfo(Variant::REAL,"range/height"),_SCS("set_height"),_SCS("get_height")); @@ -299,6 +322,7 @@ Light2D::Light2D() { shadow=false; color=Color(1,1,1); height=0; + scale=1.0; z_min=-1024; z_max=1024; layer_min=0; diff --git a/scene/2d/light_2d.h b/scene/2d/light_2d.h index 26dc1f4d44..6eb6ad5237 100644 --- a/scene/2d/light_2d.h +++ b/scene/2d/light_2d.h @@ -12,6 +12,7 @@ private: bool shadow; Color color; float height; + float scale; int z_min; int z_max; int layer_min; @@ -50,6 +51,9 @@ public: void set_height( float p_height); float get_height() const; + void set_scale( float p_scale); + float get_scale() const; + void set_z_range_min( int p_min_z); int get_z_range_min() const; diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp index 2c1502288b..8d3cbadd06 100644 --- a/scene/resources/texture.cpp +++ b/scene/resources/texture.cpp @@ -321,6 +321,13 @@ void ImageTexture::premultiply_alpha() { } } +void ImageTexture::normal_to_xy() { + + Image img = get_data(); + img.normalmap_to_xy(); + create_from_image(img,flags); +} + bool ImageTexture::has_alpha() const { return ( format==Image::FORMAT_GRAYSCALE_ALPHA || format==Image::FORMAT_INDEXED_ALPHA || format==Image::FORMAT_RGBA ); @@ -405,9 +412,11 @@ void ImageTexture::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_lossy_storage_quality"),&ImageTexture::get_lossy_storage_quality); ObjectTypeDB::bind_method(_MD("fix_alpha_edges"),&ImageTexture::fix_alpha_edges); ObjectTypeDB::bind_method(_MD("premultiply_alpha"),&ImageTexture::premultiply_alpha); + ObjectTypeDB::bind_method(_MD("normal_to_xy"),&ImageTexture::normal_to_xy); ObjectTypeDB::bind_method(_MD("set_size_override","size"),&ImageTexture::set_size_override); ObjectTypeDB::set_method_flags(get_type_static(),_SCS("fix_alpha_edges"),METHOD_FLAGS_DEFAULT|METHOD_FLAG_EDITOR); ObjectTypeDB::set_method_flags(get_type_static(),_SCS("premultiply_alpha"),METHOD_FLAGS_DEFAULT|METHOD_FLAG_EDITOR); + ObjectTypeDB::set_method_flags(get_type_static(),_SCS("normal_to_xy"),METHOD_FLAGS_DEFAULT|METHOD_FLAG_EDITOR); ObjectTypeDB::bind_method(_MD("_reload_hook","rid"),&ImageTexture::_reload_hook); diff --git a/scene/resources/texture.h b/scene/resources/texture.h index c1122b005d..e853a4b05f 100644 --- a/scene/resources/texture.h +++ b/scene/resources/texture.h @@ -146,6 +146,8 @@ public: void fix_alpha_edges(); void premultiply_alpha(); + void normal_to_xy(); + void set_size_override(const Size2& p_size); diff --git a/servers/visual/rasterizer.h b/servers/visual/rasterizer.h index d2a1c48c46..869ab83d9a 100644 --- a/servers/visual/rasterizer.h +++ b/servers/visual/rasterizer.h @@ -577,6 +577,7 @@ public: Color color; Matrix32 xform; float height; + float scale; int z_min; int z_max; int layer_min; @@ -614,6 +615,7 @@ public: layer_min=0; layer_max=0; item_mask=1; + scale=1.0; item_shadow_mask=-1; subtract=false; texture_cache=NULL; diff --git a/servers/visual/visual_server_raster.cpp b/servers/visual/visual_server_raster.cpp index 1c16f51e89..2c81dfbb30 100644 --- a/servers/visual/visual_server_raster.cpp +++ b/servers/visual/visual_server_raster.cpp @@ -3899,6 +3899,15 @@ void VisualServerRaster::canvas_light_set_transform(RID p_light, const Matrix32& clight->xform=p_transform; } +void VisualServerRaster::canvas_light_set_scale(RID p_light, float p_scale) { + + Rasterizer::CanvasLight *clight = canvas_light_owner.get(p_light); + ERR_FAIL_COND(!clight); + clight->scale=p_scale; + +} + + void VisualServerRaster::canvas_light_set_texture(RID p_light, RID p_texture){ Rasterizer::CanvasLight *clight = canvas_light_owner.get(p_light); @@ -6937,6 +6946,7 @@ void VisualServerRaster::_draw_viewport(Viewport *p_viewport,int p_ofs_x, int p_ if (cl->enabled && cl->texture.is_valid()) { //not super efficient.. Size2 tsize(rasterizer->texture_get_width(cl->texture),rasterizer->texture_get_height(cl->texture)); + tsize*=cl->scale; Vector2 offset=tsize/2.0; cl->rect_cache=Rect2(-offset+cl->texture_offset,tsize); cl->xform_cache=xf * cl->xform; diff --git a/servers/visual/visual_server_raster.h b/servers/visual/visual_server_raster.h index 7d7bbe1d71..1622871d45 100644 --- a/servers/visual/visual_server_raster.h +++ b/servers/visual/visual_server_raster.h @@ -1157,6 +1157,7 @@ public: virtual void canvas_light_attach_to_canvas(RID p_light,RID p_canvas); virtual void canvas_light_set_enabled(RID p_light, bool p_enabled); virtual void canvas_light_set_transform(RID p_light, const Matrix32& p_transform); + virtual void canvas_light_set_scale(RID p_light, float p_scale); virtual void canvas_light_set_texture(RID p_light, RID p_texture); virtual void canvas_light_set_texture_offset(RID p_light, const Vector2& p_offset); virtual void canvas_light_set_color(RID p_light, const Color& p_color); diff --git a/servers/visual/visual_server_wrap_mt.h b/servers/visual/visual_server_wrap_mt.h index bccb096e1b..4022503697 100644 --- a/servers/visual/visual_server_wrap_mt.h +++ b/servers/visual/visual_server_wrap_mt.h @@ -1151,6 +1151,7 @@ public: FUNC2(canvas_light_attach_to_canvas,RID,RID); FUNC2(canvas_light_set_enabled,RID,bool); FUNC2(canvas_light_set_transform,RID,const Matrix32&); + FUNC2(canvas_light_set_scale,RID,float); FUNC2(canvas_light_set_texture,RID,RID); FUNC2(canvas_light_set_texture_offset,RID,const Vector2&); FUNC2(canvas_light_set_color,RID,const Color&); diff --git a/servers/visual_server.h b/servers/visual_server.h index 9404ea040c..8f1a0d1529 100644 --- a/servers/visual_server.h +++ b/servers/visual_server.h @@ -1005,6 +1005,7 @@ public: virtual RID canvas_light_create()=0; virtual void canvas_light_attach_to_canvas(RID p_light,RID p_canvas)=0; virtual void canvas_light_set_enabled(RID p_light, bool p_enabled)=0; + virtual void canvas_light_set_scale(RID p_light, float p_scale)=0; virtual void canvas_light_set_transform(RID p_light, const Matrix32& p_transform)=0; virtual void canvas_light_set_texture(RID p_light, RID p_texture)=0; virtual void canvas_light_set_texture_offset(RID p_light, const Vector2& p_offset)=0; -- cgit v1.2.3 From 9f88a40e9fa1045f60ac5b6ca36de945562d6b65 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Wed, 11 Mar 2015 01:44:52 -0300 Subject: simple shader effects library for 2D ready to use in any project --- demos/2d/sprite_shaders/cubio.png | Bin 0 -> 26579 bytes demos/2d/sprite_shaders/engine.cfg | 4 ++++ demos/2d/sprite_shaders/sprite_shaders.scn | Bin 0 -> 4087 bytes 3 files changed, 4 insertions(+) create mode 100644 demos/2d/sprite_shaders/cubio.png create mode 100644 demos/2d/sprite_shaders/engine.cfg create mode 100644 demos/2d/sprite_shaders/sprite_shaders.scn diff --git a/demos/2d/sprite_shaders/cubio.png b/demos/2d/sprite_shaders/cubio.png new file mode 100644 index 0000000000..6f76220225 Binary files /dev/null and b/demos/2d/sprite_shaders/cubio.png differ diff --git a/demos/2d/sprite_shaders/engine.cfg b/demos/2d/sprite_shaders/engine.cfg new file mode 100644 index 0000000000..09f9a59566 --- /dev/null +++ b/demos/2d/sprite_shaders/engine.cfg @@ -0,0 +1,4 @@ +[application] + +name="2D Shaders for Sprites" +main_scene="res://sprite_shaders.scn" diff --git a/demos/2d/sprite_shaders/sprite_shaders.scn b/demos/2d/sprite_shaders/sprite_shaders.scn new file mode 100644 index 0000000000..84f81dde12 Binary files /dev/null and b/demos/2d/sprite_shaders/sprite_shaders.scn differ -- cgit v1.2.3 From 650e13f3cd68c9b45879a905548c34e9fb5bb46f Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Thu, 12 Mar 2015 01:05:50 -0300 Subject: back buffer copy node, to improve on texscreen() back buffer copy node and respective demo --- demos/2d/isometric_light/engine.cfg | 4 ++ demos/2d/sprite_shaders/sprite_shaders.scn | Bin 4087 -> 4079 bytes demos/2d/texscreen/bubble.png | Bin 0 -> 18619 bytes demos/2d/texscreen/bubbles.gd | 17 ++++++ demos/2d/texscreen/bubbles.scn | Bin 0 -> 1456 bytes demos/2d/texscreen/burano.png | Bin 0 -> 974437 bytes demos/2d/texscreen/engine.cfg | 4 ++ demos/2d/texscreen/lens.gd | 37 +++++++++++++ demos/2d/texscreen/lens.scn | Bin 0 -> 1805 bytes drivers/gles2/rasterizer_gles2.cpp | 62 +++++++++++++++++++--- scene/2d/back_buffer_copy.cpp | 75 +++++++++++++++++++++++++++ scene/2d/back_buffer_copy.h | 41 +++++++++++++++ scene/2d/canvas_item.cpp | 1 - scene/register_scene_types.cpp | 2 + servers/visual/rasterizer.h | 10 +++- servers/visual/visual_server_raster.cpp | 27 +++++++++- servers/visual/visual_server_raster.h | 1 + servers/visual/visual_server_wrap_mt.h | 2 + servers/visual_server.h | 1 + tools/editor/icons/icon_back_buffer_copy.png | Bin 0 -> 204 bytes 20 files changed, 272 insertions(+), 12 deletions(-) create mode 100644 demos/2d/texscreen/bubble.png create mode 100644 demos/2d/texscreen/bubbles.gd create mode 100644 demos/2d/texscreen/bubbles.scn create mode 100644 demos/2d/texscreen/burano.png create mode 100644 demos/2d/texscreen/engine.cfg create mode 100644 demos/2d/texscreen/lens.gd create mode 100644 demos/2d/texscreen/lens.scn create mode 100644 scene/2d/back_buffer_copy.cpp create mode 100644 scene/2d/back_buffer_copy.h create mode 100644 tools/editor/icons/icon_back_buffer_copy.png diff --git a/demos/2d/isometric_light/engine.cfg b/demos/2d/isometric_light/engine.cfg index bd65a38921..0d9e432d5d 100644 --- a/demos/2d/isometric_light/engine.cfg +++ b/demos/2d/isometric_light/engine.cfg @@ -9,6 +9,10 @@ down=[key(S), key(Down)] left=[key(Left), key(A)] right=[key(Right), key(D)] +[rasterizer] + +shadow_filter=0 + [render] default_clear_color=#ff000000 diff --git a/demos/2d/sprite_shaders/sprite_shaders.scn b/demos/2d/sprite_shaders/sprite_shaders.scn index 84f81dde12..7c36f2137c 100644 Binary files a/demos/2d/sprite_shaders/sprite_shaders.scn and b/demos/2d/sprite_shaders/sprite_shaders.scn differ diff --git a/demos/2d/texscreen/bubble.png b/demos/2d/texscreen/bubble.png new file mode 100644 index 0000000000..021abba601 Binary files /dev/null and b/demos/2d/texscreen/bubble.png differ diff --git a/demos/2d/texscreen/bubbles.gd b/demos/2d/texscreen/bubbles.gd new file mode 100644 index 0000000000..2ee227a928 --- /dev/null +++ b/demos/2d/texscreen/bubbles.gd @@ -0,0 +1,17 @@ + +extends Control + +# member variables here, example: +# var a=2 +# var b="textvar" + +const MAX_BUBBLES=10 + +func _ready(): + # Initialization here + for i in range(MAX_BUBBLES): + var bubble = preload("res://lens.scn").instance() + add_child(bubble) + pass + + diff --git a/demos/2d/texscreen/bubbles.scn b/demos/2d/texscreen/bubbles.scn new file mode 100644 index 0000000000..779cba6930 Binary files /dev/null and b/demos/2d/texscreen/bubbles.scn differ diff --git a/demos/2d/texscreen/burano.png b/demos/2d/texscreen/burano.png new file mode 100644 index 0000000000..6eec09d585 Binary files /dev/null and b/demos/2d/texscreen/burano.png differ diff --git a/demos/2d/texscreen/engine.cfg b/demos/2d/texscreen/engine.cfg new file mode 100644 index 0000000000..58193c8c4a --- /dev/null +++ b/demos/2d/texscreen/engine.cfg @@ -0,0 +1,4 @@ +[application] + +name="Glass Bubbles (Texscreen)" +main_scene="res://bubbles.scn" diff --git a/demos/2d/texscreen/lens.gd b/demos/2d/texscreen/lens.gd new file mode 100644 index 0000000000..2ccbfba497 --- /dev/null +++ b/demos/2d/texscreen/lens.gd @@ -0,0 +1,37 @@ + +extends BackBufferCopy + +# member variables here, example: +# var a=2 +# var b="textvar" +const MOTION_SPEED=150 + +var vsize; +var dir; + +func _process(delta): + var pos = get_pos() + dir * delta * MOTION_SPEED + + if (pos.x<0): + dir.x=abs(dir.x) + elif (pos.x>vsize.x): + dir.x=-abs(dir.x) + + if (pos.y<0): + dir.y=abs(dir.y) + elif (pos.y>vsize.y): + dir.y=-abs(dir.y) + + set_pos(pos) + +func _ready(): + vsize = get_viewport_rect().size + var pos = vsize * Vector2(randf(),randf()); + set_pos(pos); + dir = Vector2(randf()*2.0-1,randf()*2.0-1).normalized() + set_process(true) + + # Initialization here + pass + + diff --git a/demos/2d/texscreen/lens.scn b/demos/2d/texscreen/lens.scn new file mode 100644 index 0000000000..5c6f8b7af8 Binary files /dev/null and b/demos/2d/texscreen/lens.scn differ diff --git a/drivers/gles2/rasterizer_gles2.cpp b/drivers/gles2/rasterizer_gles2.cpp index b6444b2978..49fae098a8 100644 --- a/drivers/gles2/rasterizer_gles2.cpp +++ b/drivers/gles2/rasterizer_gles2.cpp @@ -989,8 +989,14 @@ void RasterizerGLES2::texture_set_data(RID p_texture,const Image& p_image,VS::Cu if (texture->flags&VS::TEXTURE_FLAG_MIPMAPS && !texture->ignore_mipmaps) glTexParameteri(texture->target,GL_TEXTURE_MIN_FILTER,use_fast_texture_filter?GL_LINEAR_MIPMAP_NEAREST:GL_LINEAR_MIPMAP_LINEAR); - else - glTexParameteri(texture->target,GL_TEXTURE_MIN_FILTER,GL_LINEAR); + else { + if (texture->flags&VS::TEXTURE_FLAG_FILTER) { + glTexParameteri(texture->target,GL_TEXTURE_MIN_FILTER,GL_LINEAR); + } else { + glTexParameteri(texture->target,GL_TEXTURE_MIN_FILTER,GL_NEAREST); + + } + } if (texture->flags&VS::TEXTURE_FLAG_FILTER) { @@ -1283,8 +1289,14 @@ void RasterizerGLES2::texture_set_flags(RID p_texture,uint32_t p_flags) { if (texture->flags&VS::TEXTURE_FLAG_MIPMAPS && !texture->ignore_mipmaps) glTexParameteri(texture->target,GL_TEXTURE_MIN_FILTER,use_fast_texture_filter?GL_LINEAR_MIPMAP_NEAREST:GL_LINEAR_MIPMAP_LINEAR); - else - glTexParameteri(texture->target,GL_TEXTURE_MIN_FILTER,GL_LINEAR); + else{ + if (texture->flags&VS::TEXTURE_FLAG_FILTER) { + glTexParameteri(texture->target,GL_TEXTURE_MIN_FILTER,GL_LINEAR); + } else { + glTexParameteri(texture->target,GL_TEXTURE_MIN_FILTER,GL_NEAREST); + + } + } if (texture->flags&VS::TEXTURE_FLAG_FILTER) { @@ -8554,7 +8566,7 @@ RID RasterizerGLES2::canvas_light_shadow_buffer_create(int p_width) { //printf("errnum: %x\n",status); #ifdef GLEW_ENABLED if (read_depth_supported) { - glDrawBuffer(GL_BACK); + //glDrawBuffer(GL_BACK); } #endif glBindFramebuffer(GL_FRAMEBUFFER, base_framebuffer); @@ -8563,7 +8575,7 @@ RID RasterizerGLES2::canvas_light_shadow_buffer_create(int p_width) { #ifdef GLEW_ENABLED if (read_depth_supported) { - glDrawBuffer(GL_BACK); + //glDrawBuffer(GL_BACK); } #endif @@ -9138,6 +9150,40 @@ void RasterizerGLES2::canvas_render_items(CanvasItem *p_item_list,int p_z,const } } + if (ci->copy_back_buffer && framebuffer.active && framebuffer.scale==1) { + + Rect2 rect; + int x,y,w,h; + + if (ci->copy_back_buffer->full) { + + x = viewport.x; + y = window_size.height-(viewport.height+viewport.y); + w = viewport.width; + h = viewport.height; + } else { + x = viewport.x+ci->copy_back_buffer->screen_rect.pos.x; + y = window_size.height-(viewport.y+ci->copy_back_buffer->screen_rect.pos.y+ci->copy_back_buffer->screen_rect.size.y); + w = ci->copy_back_buffer->screen_rect.size.x; + h = ci->copy_back_buffer->screen_rect.size.y; + } + glActiveTexture(GL_TEXTURE0+max_texture_units-1); + glBindTexture(GL_TEXTURE_2D,framebuffer.sample_color); + +#ifdef GLEW_ENABLED + glReadBuffer(GL_COLOR_ATTACHMENT0); +#endif + glCopyTexSubImage2D(GL_TEXTURE_2D,0,x,y,x,y,w,h); +// if (current_clip) { +// // print_line(" a clip "); +// } + + canvas_texscreen_used=true; + glActiveTexture(GL_TEXTURE0); + } + + + //begin rect CanvasItem *material_owner = ci->material_owner?ci->material_owner:ci; @@ -9904,7 +9950,7 @@ bool RasterizerGLES2::ShadowBuffer::init(int p_size,bool p_use_depth) { //printf("errnum: %x\n",status); #ifdef GLEW_ENABLED if (p_use_depth) { - glDrawBuffer(GL_BACK); + //glDrawBuffer(GL_BACK); } #endif glBindFramebuffer(GL_FRAMEBUFFER, 0); @@ -9913,7 +9959,7 @@ bool RasterizerGLES2::ShadowBuffer::init(int p_size,bool p_use_depth) { #ifdef GLEW_ENABLED if (p_use_depth) { - glDrawBuffer(GL_BACK); + //glDrawBuffer(GL_BACK); } #endif diff --git a/scene/2d/back_buffer_copy.cpp b/scene/2d/back_buffer_copy.cpp new file mode 100644 index 0000000000..245b3ba7eb --- /dev/null +++ b/scene/2d/back_buffer_copy.cpp @@ -0,0 +1,75 @@ +#include "back_buffer_copy.h" + +void BackBufferCopy::_update_copy_mode() { + + switch(copy_mode) { + + case COPY_MODE_DISALED: { + + VS::get_singleton()->canvas_item_set_copy_to_backbuffer(get_canvas_item(),false,Rect2()); + } break; + case COPY_MODE_RECT: { + + VS::get_singleton()->canvas_item_set_copy_to_backbuffer(get_canvas_item(),true,rect); + } break; + case COPY_MODE_VIEWPORT: { + + VS::get_singleton()->canvas_item_set_copy_to_backbuffer(get_canvas_item(),true,Rect2()); + + } break; + + } +} + +Rect2 BackBufferCopy::get_item_rect() const { + + return rect; +} + +void BackBufferCopy::set_rect(const Rect2& p_rect) { + + rect=p_rect; + _update_copy_mode(); +} + +Rect2 BackBufferCopy::get_rect() const{ + return rect; +} + +void BackBufferCopy::set_copy_mode(CopyMode p_mode){ + + copy_mode=p_mode; + _update_copy_mode(); +} +BackBufferCopy::CopyMode BackBufferCopy::get_copy_mode() const{ + + return copy_mode; +} + + +void BackBufferCopy::_bind_methods() { + + ObjectTypeDB::bind_method(_MD("set_rect","rect"),&BackBufferCopy::set_rect); + ObjectTypeDB::bind_method(_MD("get_rect"),&BackBufferCopy::get_rect); + + ObjectTypeDB::bind_method(_MD("set_copy_mode","copy_mode"),&BackBufferCopy::set_copy_mode); + ObjectTypeDB::bind_method(_MD("get_copy_mode"),&BackBufferCopy::get_copy_mode); + + ADD_PROPERTY( PropertyInfo(Variant::INT,"copy_mode",PROPERTY_HINT_ENUM,"Disabled,Rect,Viewport"),_SCS("set_copy_mode"),_SCS("get_copy_mode")); + ADD_PROPERTY( PropertyInfo(Variant::RECT2,"rect"),_SCS("set_rect"),_SCS("get_rect")); + + BIND_CONSTANT( COPY_MODE_DISALED ); + BIND_CONSTANT( COPY_MODE_RECT ); + BIND_CONSTANT( COPY_MODE_VIEWPORT ); + +} + +BackBufferCopy::BackBufferCopy(){ + + rect=Rect2(-100,-100,200,200); + copy_mode=COPY_MODE_RECT; + _update_copy_mode(); +} +BackBufferCopy::~BackBufferCopy(){ + +} diff --git a/scene/2d/back_buffer_copy.h b/scene/2d/back_buffer_copy.h new file mode 100644 index 0000000000..d6777a8d23 --- /dev/null +++ b/scene/2d/back_buffer_copy.h @@ -0,0 +1,41 @@ +#ifndef BACKBUFFERCOPY_H +#define BACKBUFFERCOPY_H + +#include "scene/2d/node_2d.h" + +class BackBufferCopy : public Node2D { + OBJ_TYPE( BackBufferCopy,Node2D); +public: + enum CopyMode { + COPY_MODE_DISALED, + COPY_MODE_RECT, + COPY_MODE_VIEWPORT + }; +private: + + Rect2 rect; + CopyMode copy_mode; + + void _update_copy_mode(); + +protected: + + static void _bind_methods(); + +public: + + void set_rect(const Rect2& p_rect); + Rect2 get_rect() const; + + void set_copy_mode(CopyMode p_mode); + CopyMode get_copy_mode() const; + + Rect2 BackBufferCopy::get_item_rect() const; + + BackBufferCopy(); + ~BackBufferCopy(); +}; + +VARIANT_ENUM_CAST(BackBufferCopy::CopyMode); + +#endif // BACKBUFFERCOPY_H diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp index 1002713740..436b77a1ac 100644 --- a/scene/2d/canvas_item.cpp +++ b/scene/2d/canvas_item.cpp @@ -44,7 +44,6 @@ bool CanvasItemMaterial::_set(const StringName& p_name, const Variant& p_value) return true; } else if (p_name==SceneStringNames::get_singleton()->shader_unshaded) { set_unshaded(p_value); - print_line("set unshaded"); return true; } else { diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp index f90db42614..5d5e7595d7 100644 --- a/scene/register_scene_types.cpp +++ b/scene/register_scene_types.cpp @@ -86,6 +86,7 @@ #include "scene/2d/sprite.h" #include "scene/2d/animated_sprite.h" #include "scene/2d/polygon_2d.h" +#include "scene/2d/back_buffer_copy.h" #include "scene/2d/visibility_notifier_2d.h" @@ -481,6 +482,7 @@ void register_scene_types() { ObjectTypeDB::register_type(); ObjectTypeDB::register_type(); ObjectTypeDB::register_type(); + ObjectTypeDB::register_type(); ObjectTypeDB::set_type_enabled("CollisionShape2D",false); ObjectTypeDB::set_type_enabled("CollisionPolygon2D",false); diff --git a/servers/visual/rasterizer.h b/servers/visual/rasterizer.h index 869ab83d9a..2abe33449e 100644 --- a/servers/visual/rasterizer.h +++ b/servers/visual/rasterizer.h @@ -769,6 +769,12 @@ public: mutable Rect2 rect; CanvasItem*next; CanvasItemMaterial* material; + struct CopyBackBuffer { + Rect2 rect; + Rect2 screen_rect; + bool full; + }; + CopyBackBuffer *copy_back_buffer; float final_opacity; @@ -904,8 +910,8 @@ public: } void clear() { for (int i=0;icopy_back_buffer!=NULL) !=p_enable) { + if (p_enable) { + canvas_item->copy_back_buffer = memnew( Rasterizer::CanvasItem::CopyBackBuffer ); + } else { + memdelete(canvas_item->copy_back_buffer); + canvas_item->copy_back_buffer=NULL; + } + } + + if (p_enable) { + canvas_item->copy_back_buffer->rect=p_rect; + canvas_item->copy_back_buffer->full=p_rect==Rect2(); + } + +} + void VisualServerRaster::canvas_item_set_use_parent_material(RID p_item, bool p_enable) { VS_CHANGED; @@ -6766,8 +6787,12 @@ void VisualServerRaster::_render_canvas_item(CanvasItem *p_canvas_item,const Mat _render_canvas_item(child_items[i],xform,p_clip_rect,opacity,p_z,z_list,z_last_list,(CanvasItem*)ci->final_clip_owner,p_material_owner); } + if (ci->copy_back_buffer) { + + ci->copy_back_buffer->screen_rect = xform.xform(ci->copy_back_buffer->rect).clip(p_clip_rect); + } - if ((!ci->commands.empty() && p_clip_rect.intersects(global_rect)) || ci->vp_render) { + if ((!ci->commands.empty() && p_clip_rect.intersects(global_rect)) || ci->vp_render || ci->copy_back_buffer) { //something to draw? ci->final_transform=xform; ci->final_opacity=opacity * ci->self_opacity; diff --git a/servers/visual/visual_server_raster.h b/servers/visual/visual_server_raster.h index 1622871d45..5c0d48645e 100644 --- a/servers/visual/visual_server_raster.h +++ b/servers/visual/visual_server_raster.h @@ -1149,6 +1149,7 @@ public: virtual void canvas_item_set_sort_children_by_y(RID p_item, bool p_enable); virtual void canvas_item_set_z(RID p_item, int p_z); virtual void canvas_item_set_z_as_relative_to_parent(RID p_item, bool p_enable); + virtual void canvas_item_set_copy_to_backbuffer(RID p_item, bool p_enable,const Rect2& p_rect); virtual void canvas_item_set_material(RID p_item, RID p_material); virtual void canvas_item_set_use_parent_material(RID p_item, bool p_enable); diff --git a/servers/visual/visual_server_wrap_mt.h b/servers/visual/visual_server_wrap_mt.h index 4022503697..6848075824 100644 --- a/servers/visual/visual_server_wrap_mt.h +++ b/servers/visual/visual_server_wrap_mt.h @@ -1138,6 +1138,8 @@ public: FUNC2(canvas_item_set_sort_children_by_y,RID,bool); FUNC2(canvas_item_set_z,RID,int); FUNC2(canvas_item_set_z_as_relative_to_parent,RID,bool); + FUNC3(canvas_item_set_copy_to_backbuffer,RID,bool,const Rect2&); + FUNC2(canvas_item_set_material,RID, RID ); diff --git a/servers/visual_server.h b/servers/visual_server.h index 8f1a0d1529..f4896f984e 100644 --- a/servers/visual_server.h +++ b/servers/visual_server.h @@ -994,6 +994,7 @@ public: virtual void canvas_item_set_sort_children_by_y(RID p_item, bool p_enable)=0; virtual void canvas_item_set_z(RID p_item, int p_z)=0; virtual void canvas_item_set_z_as_relative_to_parent(RID p_item, bool p_enable)=0; + virtual void canvas_item_set_copy_to_backbuffer(RID p_item, bool p_enable,const Rect2& p_rect)=0; virtual void canvas_item_clear(RID p_item)=0; virtual void canvas_item_raise(RID p_item)=0; diff --git a/tools/editor/icons/icon_back_buffer_copy.png b/tools/editor/icons/icon_back_buffer_copy.png new file mode 100644 index 0000000000..b27eb39108 Binary files /dev/null and b/tools/editor/icons/icon_back_buffer_copy.png differ -- cgit v1.2.3 From 86eedaec217a0db2325753cf682992114f9943b0 Mon Sep 17 00:00:00 2001 From: marynate Date: Thu, 12 Mar 2015 14:23:36 +0800 Subject: Fix compile error in back_buffer_copy.h --- scene/2d/back_buffer_copy.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scene/2d/back_buffer_copy.h b/scene/2d/back_buffer_copy.h index d6777a8d23..3a86ffa309 100644 --- a/scene/2d/back_buffer_copy.h +++ b/scene/2d/back_buffer_copy.h @@ -30,7 +30,7 @@ public: void set_copy_mode(CopyMode p_mode); CopyMode get_copy_mode() const; - Rect2 BackBufferCopy::get_item_rect() const; + Rect2 get_item_rect() const; BackBufferCopy(); ~BackBufferCopy(); -- cgit v1.2.3 From 7cdd3c86c4661953e7d765d5a9cd2cc18d7ec27f Mon Sep 17 00:00:00 2001 From: sanikoyes Date: Sat, 14 Mar 2015 10:40:58 +0800 Subject: Add missing particles_2d macro bind --- scene/2d/particles_2d.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scene/2d/particles_2d.cpp b/scene/2d/particles_2d.cpp index 6e2cf5954b..c9dd92ff3d 100644 --- a/scene/2d/particles_2d.cpp +++ b/scene/2d/particles_2d.cpp @@ -1077,13 +1077,18 @@ void Particles2D::_bind_methods() { BIND_CONSTANT( PARAM_SPREAD ); BIND_CONSTANT( PARAM_LINEAR_VELOCITY ); BIND_CONSTANT( PARAM_SPIN_VELOCITY ); + BIND_CONSTANT( PARAM_ORBIT_VELOCITY ); BIND_CONSTANT( PARAM_GRAVITY_DIRECTION ); BIND_CONSTANT( PARAM_GRAVITY_STRENGTH ); BIND_CONSTANT( PARAM_RADIAL_ACCEL ); BIND_CONSTANT( PARAM_TANGENTIAL_ACCEL ); + BIND_CONSTANT( PARAM_DAMPING ); + BIND_CONSTANT( PARAM_INITIAL_ANGLE ); BIND_CONSTANT( PARAM_INITIAL_SIZE ); BIND_CONSTANT( PARAM_FINAL_SIZE ); BIND_CONSTANT( PARAM_HUE_VARIATION ); + BIND_CONSTANT( PARAM_ANIM_SPEED_SCALE ); + BIND_CONSTANT( PARAM_ANIM_INITIAL_POS ); BIND_CONSTANT( PARAM_MAX ); BIND_CONSTANT( MAX_COLOR_PHASES ); -- cgit v1.2.3 From e646fc5b5d55869a7d497e69f1e513c226e6e75d Mon Sep 17 00:00:00 2001 From: Roman Nekrassow Date: Sat, 14 Mar 2015 12:35:18 +0100 Subject: [Fix] make_dir_recursive on Windows function normally tries to create c: which isn't possible, because the access is denied, handling ERROR_ACCESS_DENIED as ERR_ALREADY_EXISTS lets the function skip the creation of c: . --- drivers/windows/dir_access_windows.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/windows/dir_access_windows.cpp b/drivers/windows/dir_access_windows.cpp index d1e9766105..aa96faac1b 100644 --- a/drivers/windows/dir_access_windows.cpp +++ b/drivers/windows/dir_access_windows.cpp @@ -270,7 +270,7 @@ Error DirAccessWindows::make_dir(String p_dir) { return OK; }; - if (err == ERROR_ALREADY_EXISTS) { + if (err == ERROR_ALREADY_EXISTS || err == ERROR_ACCESS_DENIED) { return ERR_ALREADY_EXISTS; }; -- cgit v1.2.3 From 1200689245aea59a1620145a3f85cc4bd76b561f Mon Sep 17 00:00:00 2001 From: Matthew Hughes Date: Sun, 15 Mar 2015 09:43:13 -0500 Subject: Update file_access_windows.cpp for mingw cross-compile Cross compiling on linux failed on this file. Changing case of the windows.h and shlwapi.h allows mingw to find these headers but setting WINVER 0x0500 is needed for the compiler to find ReplaceFileW --- drivers/windows/file_access_windows.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/windows/file_access_windows.cpp b/drivers/windows/file_access_windows.cpp index e24685432c..562ddd02e2 100644 --- a/drivers/windows/file_access_windows.cpp +++ b/drivers/windows/file_access_windows.cpp @@ -28,8 +28,10 @@ /*************************************************************************/ #ifdef WINDOWS_ENABLED -#include -#include "Shlwapi.h" +#define WINVER 0x0500 + +#include +#include "shlwapi.h" #include "file_access_windows.h" -- cgit v1.2.3 From 2d4cad705728c0b9d531bf6088513830f6e08bcc Mon Sep 17 00:00:00 2001 From: Alex Bonfim Date: Sun, 15 Mar 2015 23:17:48 -0300 Subject: Fix for InputEvent::set_as_action --- core/variant_call.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/core/variant_call.cpp b/core/variant_call.cpp index 50a60390e5..c6b498ff28 100644 --- a/core/variant_call.cpp +++ b/core/variant_call.cpp @@ -511,7 +511,7 @@ static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Var VCALL_LOCALMEM1(ColorArray,append_array); #define VCALL_PTR0(m_type,m_method)\ -static void _call_##m_type##m_method(Variant& r_ret,Variant& p_self,const Variant** p_args) { reinterpret_cast(p_self._data._ptr)->m_method(); } +static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Variant** p_args) { reinterpret_cast(p_self._data._ptr)->m_method(); } #define VCALL_PTR0R(m_type,m_method)\ static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Variant** p_args) { r_ret=reinterpret_cast(p_self._data._ptr)->m_method(); } #define VCALL_PTR1(m_type,m_method)\ @@ -519,7 +519,7 @@ static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Var #define VCALL_PTR1R(m_type,m_method)\ static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Variant** p_args) { r_ret=reinterpret_cast(p_self._data._ptr)->m_method(*p_args[0]); } #define VCALL_PTR2(m_type,m_method)\ -static void _call_##m_type##m_method(Variant& r_ret,Variant& p_self,const Variant** p_args) { reinterpret_cast(p_self._data._ptr)->m_method(*p_args[0],*p_args[1]); } +static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Variant** p_args) { reinterpret_cast(p_self._data._ptr)->m_method(*p_args[0],*p_args[1]); } #define VCALL_PTR2R(m_type,m_method)\ static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Variant** p_args) { r_ret=reinterpret_cast(p_self._data._ptr)->m_method(*p_args[0],*p_args[1]); } #define VCALL_PTR3(m_type,m_method)\ @@ -531,7 +531,7 @@ static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Var #define VCALL_PTR4R(m_type,m_method)\ static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Variant** p_args) { r_ret=reinterpret_cast(p_self._data._ptr)->m_method(*p_args[0],*p_args[1],*p_args[2],*p_args[3]); } #define VCALL_PTR5(m_type,m_method)\ -static void _call_##m_type##m_method(Variant& r_ret,Variant& p_self,const Variant** p_args) { reinterpret_cast(p_self._data._ptr)->m_method(*p_args[0],*p_args[1],*p_args[2],*p_args[3],*p_args[4]); } +static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Variant** p_args) { reinterpret_cast(p_self._data._ptr)->m_method(*p_args[0],*p_args[1],*p_args[2],*p_args[3],*p_args[4]); } #define VCALL_PTR5R(m_type,m_method)\ static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Variant** p_args) { r_ret=reinterpret_cast(p_self._data._ptr)->m_method(*p_args[0],*p_args[1],*p_args[2],*p_args[3],*p_args[4]); } @@ -685,7 +685,7 @@ static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Var VCALL_PTR0R( InputEvent, is_pressed ); VCALL_PTR1R( InputEvent, is_action ); VCALL_PTR0R( InputEvent, is_echo ); - //VCALL_PTR2( InputEvent, set_as_action ); + VCALL_PTR2( InputEvent, set_as_action ); struct ConstructData { @@ -1496,7 +1496,7 @@ _VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_SCS(#m_method),VCALL(m_cl ADDFUNC0(INPUT_EVENT,BOOL,InputEvent,is_pressed,varray()); ADDFUNC1(INPUT_EVENT,BOOL,InputEvent,is_action,STRING,"action",varray()); ADDFUNC0(INPUT_EVENT,BOOL,InputEvent,is_echo,varray()); - //ADDFUNC2(INPUT_EVENT,NIL,InputEvent,set_as_action,STRING,"action",BOOL,"pressed",varray()); + ADDFUNC2(INPUT_EVENT,NIL,InputEvent,set_as_action,STRING,"action",BOOL,"pressed",varray()); /* REGISTER CONSTRUCTORS */ -- cgit v1.2.3 From 53e1694e1e2b76026d862e84c1de88f62601cbc3 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Mon, 16 Mar 2015 00:47:37 -0300 Subject: New option to send canvas to render buffer allows to use 3D environment effects for post processing such as Glow, Bloom, HDR, etc. in 2D. --- demos/2d/hdr/beach_cave.gd | 26 +++++++++ demos/2d/hdr/beach_cave.scn | Bin 0 -> 2972 bytes demos/2d/hdr/engine.cfg | 13 +++++ demos/2d/hdr/ocean_beach.png | Bin 0 -> 443558 bytes demos/2d/hdr/ocean_beach.png.flags | 1 + demos/2d/hdr/ocean_cave.png | Bin 0 -> 745215 bytes demos/2d/hdr/ocean_cave.png.flags | 1 + demos/2d/isometric_light/map.scn | Bin 8565 -> 8535 bytes demos/2d/platformer/stage.xml | 35 ++++++------ drivers/gles2/rasterizer_gles2.cpp | 50 +++++++++++------ drivers/gles2/rasterizer_gles2.h | 4 ++ platform/windows/os_windows.cpp | 1 + scene/gui/text_edit.cpp | 4 +- scene/resources/environment.cpp | 7 ++- scene/resources/environment.h | 6 +- servers/visual/rasterizer.h | 1 + servers/visual/visual_server_raster.cpp | 96 ++++++++++++++++++++++++++++++-- servers/visual/visual_server_raster.h | 8 ++- servers/visual/visual_server_wrap_mt.h | 1 + servers/visual_server.h | 5 +- tools/editor/editor_node.cpp | 5 ++ tools/editor/property_editor.cpp | 24 ++++++++ 22 files changed, 238 insertions(+), 50 deletions(-) create mode 100644 demos/2d/hdr/beach_cave.gd create mode 100644 demos/2d/hdr/beach_cave.scn create mode 100644 demos/2d/hdr/engine.cfg create mode 100644 demos/2d/hdr/ocean_beach.png create mode 100644 demos/2d/hdr/ocean_beach.png.flags create mode 100644 demos/2d/hdr/ocean_cave.png create mode 100644 demos/2d/hdr/ocean_cave.png.flags diff --git a/demos/2d/hdr/beach_cave.gd b/demos/2d/hdr/beach_cave.gd new file mode 100644 index 0000000000..9dffbc4662 --- /dev/null +++ b/demos/2d/hdr/beach_cave.gd @@ -0,0 +1,26 @@ + +extends Node2D + +# member variables here, example: +# var a=2 +# var b="textvar" +const CAVE_LIMIT=1000 + +func _input(ev): + if (ev.type==InputEvent.MOUSE_MOTION and ev.button_mask&1): + var rel_x = ev.relative_x + var cavepos = get_node("cave").get_pos() + cavepos.x+=rel_x + if (cavepos.x<-CAVE_LIMIT): + cavepos.x=-CAVE_LIMIT + elif (cavepos.x>0): + cavepos.x=0 + get_node("cave").set_pos(cavepos) + + +func _ready(): + set_process_input(true) + # Initialization here + pass + + diff --git a/demos/2d/hdr/beach_cave.scn b/demos/2d/hdr/beach_cave.scn new file mode 100644 index 0000000000..4147a130ad Binary files /dev/null and b/demos/2d/hdr/beach_cave.scn differ diff --git a/demos/2d/hdr/engine.cfg b/demos/2d/hdr/engine.cfg new file mode 100644 index 0000000000..3d8b4222d5 --- /dev/null +++ b/demos/2d/hdr/engine.cfg @@ -0,0 +1,13 @@ +[application] + +name="HDR for 2D" +main_scene="res://beach_cave.scn" + +[display] + +width=1080 +height=720 + +[rasterizer] + +blur_buffer_size=128 diff --git a/demos/2d/hdr/ocean_beach.png b/demos/2d/hdr/ocean_beach.png new file mode 100644 index 0000000000..a873d4f61d Binary files /dev/null and b/demos/2d/hdr/ocean_beach.png differ diff --git a/demos/2d/hdr/ocean_beach.png.flags b/demos/2d/hdr/ocean_beach.png.flags new file mode 100644 index 0000000000..82127bd7d5 --- /dev/null +++ b/demos/2d/hdr/ocean_beach.png.flags @@ -0,0 +1 @@ +tolinear=true diff --git a/demos/2d/hdr/ocean_cave.png b/demos/2d/hdr/ocean_cave.png new file mode 100644 index 0000000000..8875499df3 Binary files /dev/null and b/demos/2d/hdr/ocean_cave.png differ diff --git a/demos/2d/hdr/ocean_cave.png.flags b/demos/2d/hdr/ocean_cave.png.flags new file mode 100644 index 0000000000..82127bd7d5 --- /dev/null +++ b/demos/2d/hdr/ocean_cave.png.flags @@ -0,0 +1 @@ +tolinear=true diff --git a/demos/2d/isometric_light/map.scn b/demos/2d/isometric_light/map.scn index fb2f3a2154..c939a4b392 100644 Binary files a/demos/2d/isometric_light/map.scn and b/demos/2d/isometric_light/map.scn differ diff --git a/demos/2d/platformer/stage.xml b/demos/2d/platformer/stage.xml index 35517f747d..610057183b 100644 --- a/demos/2d/platformer/stage.xml +++ b/demos/2d/platformer/stage.xml @@ -2,16 +2,16 @@ - - + + + - "names" - + "stage" "Node" "_import_path" @@ -21,6 +21,7 @@ "visibility/visible" "visibility/opacity" "visibility/self_opacity" + "visibility/light_mask" "transform/pos" "transform/rot" "transform/scale" @@ -32,7 +33,9 @@ "cell/quadrant_size" "cell/custom_transform" "cell/half_offset" - "collision/body_mode" + "cell/tile_origin" + "cell/y_sort" + "collision/use_kinematic" "collision/friction" "collision/bounce" "collision/layers" @@ -172,10 +175,10 @@ 0.814506 "use_snap" False + "snap_vec" + 10, 10 "ofs" - -121.031, 464.121 - "snap" - 10 + 177.488, 709.633 "3D" @@ -278,10 +281,11 @@ 0 "__editor_plugin_screen__" - "2D" + "3D" True 1 + 1 0, 0 0 1, 1 @@ -291,7 +295,7 @@ 8 1, 0, 0, 1, 0, 0 2 - 1 + False 0, 2, 70, 536870914, 71, 10, 72, 10, 73, 10, 74, 10, 75, 10, 76, 10, 77, 10, 78, 10, 65536, 2, 65606, 536870914, 65607, 10, 65608, 10, 65609, 10, 65610, 10, 65611, 10, 65612, 10, 65613, 10, 65614, 10, 131072, 2, 131142, 536870914, 131143, 10, 131144, 10, 131145, 10, 131146, 10, 131147, 10, 131148, 10, 131149, 10, 131150, 10, 196608, 2, 196626, 9, 196678, 536870914, 196679, 10, 196680, 10, 196681, 10, 196682, 10, 196683, 10, 196684, 10, 196685, 10, 196686, 10, 262144, 2, 262162, 8, 262214, 536870914, 262215, 10, 262216, 10, 262217, 10, 262218, 10, 262219, 10, 262220, 10, 262221, 10, 262222, 10, 327680, 2, 327697, 536870921, 327698, 7, 327733, 9, 327750, 536870914, 327751, 10, 327752, 10, 327753, 10, 327754, 10, 327755, 10, 327756, 10, 327757, 10, 327758, 10, 393216, 2, 393233, 536870920, 393234, 7, 393257, 9, 393269, 7, 393286, 536870914, 393287, 10, 393288, 10, 393289, 10, 393290, 10, 393291, 10, 393292, 10, 393293, 10, 393294, 10, 458752, 2, 458769, 7, 458770, 8, 458790, 9, 458793, 8, 458805, 8, 458822, 536870914, 458823, 10, 458824, 10, 458825, 10, 458826, 10, 458827, 10, 458828, 10, 458829, 10, 458830, 10, 524288, 4, 524289, 1, 524304, 536870913, 524305, 536870918, 524306, 6, 524307, 5, 524308, 1, 524326, 8, 524329, 7, 524341, 7, 524358, 536870914, 524359, 10, 524360, 10, 524361, 10, 524362, 10, 524363, 10, 524364, 10, 524365, 10, 524366, 10, 589824, 10, 589825, 13, 589840, 536870914, 589841, 10, 589842, 10, 589843, 10, 589844, 2, 589862, 7, 589865, 7, 589876, 536870913, 589877, 6, 589878, 1, 589894, 536870914, 589895, 10, 589896, 10, 589897, 10, 589898, 10, 589899, 10, 589900, 10, 589901, 10, 589902, 10, 655360, 2, 655376, 536870914, 655377, 10, 655378, 10, 655379, 10, 655380, 2, 655398, 7, 655401, 8, 655412, 536870925, 655413, 11, 655414, 13, 655430, 536870914, 655431, 10, 655432, 10, 655433, 10, 655434, 10, 655435, 10, 655436, 10, 655437, 10, 655438, 10, 720896, 2, 720912, 536870914, 720913, 10, 720914, 10, 720915, 10, 720916, 2, 720934, 8, 720937, 7, 720958, 536870913, 720959, 5, 720960, 536870917, 720961, 5, 720962, 5, 720963, 536870917, 720964, 5, 720965, 0, 720966, 536870916, 720967, 10, 720968, 10, 720969, 10, 720970, 10, 720971, 10, 720972, 10, 720973, 10, 720974, 10, 786432, 2, 786437, 9, 786448, 536870914, 786449, 10, 786450, 10, 786451, 10, 786452, 2, 786464, 536870913, 786465, 1, 786470, 7, 786473, 7, 786474, 536870924, 786475, 1, 786494, 536870914, 786495, 10, 786496, 10, 786497, 10, 786498, 10, 786499, 10, 786500, 10, 786501, 10, 786502, 10, 786503, 10, 786504, 10, 786505, 10, 786506, 10, 786507, 10, 786508, 10, 786509, 10, 851968, 2, 851973, 7, 851984, 536870914, 851985, 10, 851986, 10, 851987, 10, 851988, 2, 851996, 536870913, 851997, 1, 852000, 536870914, 852001, 3, 852006, 7, 852009, 536870913, 852011, 2, 852030, 536870914, 852031, 10, 852032, 10, 852033, 10, 852034, 10, 852035, 10, 852036, 10, 852037, 10, 852038, 10, 852039, 10, 852040, 10, 852041, 10, 852042, 10, 852043, 10, 852044, 10, 852045, 10, 917504, 2, 917506, 9, 917509, 7, 917512, 536870921, 917520, 536870925, 917521, 11, 917522, 11, 917523, 11, 917524, 13, 917532, 536870925, 917533, 13, 917536, 536870914, 917537, 4, 917538, 1, 917540, 536870913, 917541, 0, 917542, 1, 917545, 536870914, 917546, 10, 917547, 4, 917548, 1, 917566, 536870914, 917567, 10, 917568, 10, 917569, 10, 917570, 10, 917571, 10, 917572, 10, 917573, 10, 917574, 10, 917575, 10, 917576, 10, 917577, 10, 917578, 10, 917579, 10, 917580, 10, 917581, 10, 983040, 2, 983042, 7, 983045, 7, 983048, 536870920, 983050, 536870913, 983051, 1, 983064, 536870913, 983065, 1, 983072, 536870914, 983073, 10, 983074, 4, 983075, 0, 983076, 536870916, 983077, 10, 983078, 4, 983079, 536870912, 983080, 536870912, 983081, 536870916, 983082, 10, 983083, 10, 983084, 2, 983095, 9, 983102, 536870914, 983103, 10, 983104, 10, 983105, 10, 983106, 10, 983107, 10, 983108, 10, 983109, 10, 983110, 10, 983111, 10, 983112, 10, 983113, 10, 983114, 10, 983115, 10, 983116, 10, 983117, 10, 1048576, 2, 1048578, 8, 1048581, 8, 1048584, 536870919, 1048586, 536870925, 1048587, 13, 1048600, 536870925, 1048601, 13, 1048604, 9, 1048608, 536870925, 1048609, 536870923, 1048610, 536870923, 1048611, 536870923, 1048612, 10, 1048613, 10, 1048614, 10, 1048615, 10, 1048616, 10, 1048617, 10, 1048618, 10, 1048619, 10, 1048620, 4, 1048621, 1, 1048630, 536870921, 1048631, 8, 1048638, 536870914, 1048639, 10, 1048640, 10, 1048641, 10, 1048642, 10, 1048643, 10, 1048644, 10, 1048645, 10, 1048646, 10, 1048647, 10, 1048648, 10, 1048649, 10, 1048650, 10, 1048651, 10, 1048652, 10, 1048653, 10, 1114112, 4, 1114113, 0, 1114114, 6, 1114115, 0, 1114116, 0, 1114117, 6, 1114118, 1, 1114120, 536870920, 1114128, 536870913, 1114129, 5, 1114130, 536870917, 1114131, 5, 1114132, 0, 1114133, 1, 1114140, 7, 1114141, 536870921, 1114148, 536870914, 1114149, 10, 1114150, 10, 1114151, 10, 1114152, 10, 1114153, 10, 1114154, 10, 1114155, 10, 1114156, 10, 1114157, 2, 1114166, 536870920, 1114167, 8, 1114174, 536870914, 1114175, 10, 1114176, 10, 1114177, 10, 1114178, 10, 1114179, 10, 1114180, 10, 1114181, 10, 1114182, 10, 1114183, 10, 1114184, 10, 1114185, 10, 1114186, 10, 1114187, 10, 1114188, 10, 1179648, 10, 1179649, 10, 1179650, 10, 1179651, 10, 1179652, 10, 1179653, 10, 1179654, 2, 1179656, 536870919, 1179663, 536870915, 1179665, 10, 1179666, 10, 1179667, 10, 1179668, 10, 1179669, 4, 1179670, 12, 1179675, 9, 1179676, 8, 1179677, 8, 1179684, 536870914, 1179685, 10, 1179686, 10, 1179687, 10, 1179688, 10, 1179689, 10, 1179690, 10, 1179691, 10, 1179692, 10, 1179693, 4, 1179694, 1, 1179701, 9, 1179702, 536870919, 1179703, 7, 1179710, 536870914, 1179711, 10, 1179712, 10, 1179713, 10, 1179714, 10, 1179715, 10, 1179716, 10, 1179717, 10, 1179718, 10, 1179719, 10, 1179720, 10, 1179721, 10, 1179722, 10, 1245184, 10, 1245185, 10, 1245186, 10, 1245187, 10, 1245188, 10, 1245189, 10, 1245190, 2, 1245192, 536870919, 1245199, 536870913, 1245200, 536870916, 1245201, 10, 1245202, 10, 1245203, 10, 1245204, 10, 1245205, 10, 1245207, 1, 1245211, 7, 1245212, 7, 1245213, 536870920, 1245220, 536870914, 1245221, 10, 1245222, 10, 1245223, 10, 1245224, 10, 1245225, 10, 1245226, 10, 1245227, 10, 1245228, 10, 1245229, 10, 1245230, 2, 1245237, 8, 1245238, 536870919, 1245239, 8, 1245240, 536870921, 1245246, 536870914, 1245247, 10, 1245248, 10, 1245249, 10, 1245250, 10, 1245251, 10, 1245252, 10, 1245253, 10, 1245254, 10, 1245255, 10, 1245256, 10, 1245257, 10, 1245258, 10, 1310720, 10, 1310721, 10, 1310722, 10, 1310723, 10, 1310724, 10, 1310725, 10, 1310726, 2, 1310728, 536870920, 1310730, 536870913, 1310731, 1, 1310734, 536870913, 1310735, 536870916, 1310736, 10, 1310737, 10, 1310738, 10, 1310739, 10, 1310740, 10, 1310741, 10, 1310742, 10, 1310743, 4, 1310744, 1, 1310747, 8, 1310748, 7, 1310749, 536870919, 1310756, 536870914, 1310757, 10, 1310758, 10, 1310759, 10, 1310760, 10, 1310761, 10, 1310762, 10, 1310763, 10, 1310764, 10, 1310765, 10, 1310766, 4, 1310767, 5, 1310768, 12, 1310773, 7, 1310774, 536870919, 1310775, 7, 1310776, 536870919, 1310782, 536870914, 1310783, 10, 1310784, 10, 1310785, 10, 1310786, 10, 1310787, 10, 1310788, 10, 1310789, 10, 1310790, 10, 1310791, 10, 1310792, 10, 1310793, 10, 1376256, 10, 1376257, 10, 1376258, 10, 1376259, 10, 1376260, 10, 1376261, 10, 1376262, 4, 1376263, 0, 1376264, 0, 1376265, 0, 1376266, 536870916, 1376267, 4, 1376268, 0, 1376269, 0, 1376270, 536870916, 1376271, 10, 1376272, 10, 1376273, 10, 1376274, 10, 1376275, 10, 1376276, 10, 1376277, 10, 1376278, 10, 1376279, 10, 1376280, 4, 1376281, 12, 1376283, 8, 1376284, 8, 1376285, 536870920, 1376287, 536870924, 1376288, 0, 1376289, 5, 1376290, 536870917, 1376291, 0, 1376292, 536870916, 1376293, 10, 1376294, 10, 1376295, 10, 1376296, 10, 1376297, 10, 1376298, 10, 1376299, 10, 1376300, 10, 1376301, 10, 1376302, 10, 1376303, 10, 1376305, 12, 1376309, 7, 1376310, 536870920, 1376311, 7, 1376312, 536870920, 1376318, 536870914, 1376319, 10, 1376320, 10, 1376321, 10, 1376322, 10, 1376323, 10, 1376324, 10, 1376325, 10, 1376326, 10, 1376327, 10, 1376328, 10, 1441792, 10, 1441793, 10, 1441794, 10, 1441795, 10, 1441796, 10, 1441797, 10, 1441798, 10, 1441799, 10, 1441800, 10, 1441801, 10, 1441802, 10, 1441803, 10, 1441804, 10, 1441805, 10, 1441806, 10, 1441807, 10, 1441808, 10, 1441809, 10, 1441810, 10, 1441811, 10, 1441812, 10, 1441813, 10, 1441814, 10, 1441815, 10, 1441816, 10, 1441818, 0, 1441819, 6, 1441820, 6, 1441821, 536870918, 1441822, 5, 1441824, 10, 1441825, 10, 1441826, 10, 1441827, 10, 1441828, 10, 1441829, 10, 1441830, 10, 1441831, 10, 1441832, 10, 1441833, 10, 1441834, 10, 1441835, 10, 1441836, 10, 1441837, 10, 1441838, 10, 1441839, 10, 1441840, 10, 1441842, 0, 1441843, 0, 1441844, 0, 1441845, 6, 1441846, 536870918, 1441847, 6, 1441848, 536870918, 1441849, 0, 1441850, 5, 1441851, 536870917, 1441852, 5, 1441853, 0, 1441854, 536870916, 1441855, 10, 1441856, 10, 1441857, 10, 1441858, 10, 1441859, 10, 1441860, 10, 1441861, 10, 1441862, 10, 1441863, 10, 1507328, 10, 1507329, 10, 1507330, 10, 1507331, 10, 1507332, 10, 1507333, 10, 1507334, 10, 1507335, 10, 1507336, 10, 1507337, 10, 1507338, 10, 1507339, 10, 1507340, 10, 1507341, 10, 1507342, 10, 1507343, 10, 1507344, 10, 1507345, 10, 1507346, 10, 1507347, 10, 1507348, 10, 1507349, 10, 1507350, 10, 1507351, 10, 1507352, 10, 1507353, 10, 1507354, 10, 1507355, 10, 1507356, 10, 1507357, 10, 1507358, 10, 1507359, 10, 1507360, 10, 1507361, 10, 1507362, 10, 1507363, 10, 1507364, 10, 1507365, 10, 1507366, 10, 1507367, 10, 1507368, 10, 1507369, 10, 1507370, 10, 1507371, 10, 1507372, 10, 1507373, 10, 1507374, 10, 1507375, 10, 1507376, 10, 1507377, 10, 1507378, 10, 1507379, 10, 1507380, 10, 1507381, 10, 1507382, 10, 1507383, 10, 1507384, 10, 1507385, 10, 1507386, 10, 1507387, 10, 1507388, 10, 1507389, 10, 1507390, 10, 1507391, 10, 1507392, 10, 1507393, 10, 1507394, 10, 1507395, 10, 1507396, 10, 1507397, 10, 1507398, 10, 1507399, 10, 1572864, 10, 1572865, 10, 1572866, 10, 1572867, 10, 1572868, 10, 1572869, 10, 1572870, 10, 1572871, 10, 1572872, 10, 1572873, 10, 1572874, 10, 1572875, 10, 1572876, 10, 1572877, 10, 1572878, 10, 1572879, 10, 1572880, 10, 1572881, 10, 1572882, 10, 1572883, 10, 1572884, 10, 1572885, 10, 1572886, 10, 1572887, 10, 1572888, 10, 1572889, 10, 1572890, 10, 1572891, 10, 1572892, 10, 1572893, 10, 1572894, 10, 1572895, 10, 1572896, 10, 1572897, 10, 1572898, 10, 1572899, 10, 1572900, 10, 1572901, 10, 1572902, 10, 1572903, 10, 1572904, 10, 1572905, 10, 1572906, 10, 1572907, 10, 1572908, 10, 1572909, 10, 1572910, 10, 1572911, 10, 1572912, 10, 1572913, 10, 1572914, 10, 1572915, 10, 1572916, 10, 1572917, 10, 1572918, 10, 1572919, 10, 1572920, 10, 1572921, 10, 1572922, 10, 1572923, 10, 1572924, 10, 1572925, 10, 1572926, 10, 1572927, 10, 1572928, 10, 1572929, 10, 1572930, 10, 1572931, 10, 1572932, 10, 1572933, 10, 1572934, 10, 1572935, 10, 1638400, 10, 1638401, 10, 1638402, 10, 1638403, 10, 1638404, 10, 1638405, 10, 1638406, 10, 1638407, 10, 1638408, 10, 1638409, 10, 1638410, 10, 1638411, 10, 1638412, 10, 1638413, 10, 1638414, 10, 1638415, 10, 1638416, 10, 1638417, 10, 1638418, 10, 1638419, 10, 1638420, 10, 1638421, 10, 1638422, 10, 1638423, 10, 1638424, 10, 1638425, 10, 1638426, 10, 1638427, 10, 1638428, 10, 1638429, 10, 1638430, 10, 1638431, 10, 1638432, 10, 1638433, 10, 1638434, 10, 1638435, 10, 1638436, 10, 1638437, 10, 1638438, 10, 1638439, 10, 1638440, 10, 1638441, 10, 1638442, 10, 1638443, 10, 1638444, 10, 1638445, 10, 1638446, 10, 1638447, 10, 1638448, 10, 1638449, 10, 1638450, 10, 1638451, 10, 1638452, 10, 1638453, 10, 1638454, 10, 1638455, 10, 1638456, 10, 1638457, 10, 1638458, 10, 1638459, 10, 1638460, 10, 1638461, 10, 1638462, 10, 1638463, 10, 1638464, 10, 1638465, 10, 1638466, 10, 1638467, 10, 1638468, 10, 1638469, 10, 1638470, 10, 1638471, 10, 1703952, 10, 1703953, 10, 1703954, 10, 1703955, 10, 1703956, 10, 1703957, 10, 1703958, 10, 1703959, 10, 1703960, 10, 1703961, 10, 1703962, 10, 1703963, 10, 1703964, 10, 1703965, 10, 1703966, 10, 1703967, 10, 1703968, 10, 1703969, 10, 1703970, 10, 1703971, 10, 1703972, 10, 1703973, 10, 1703974, 10, 1703975, 10, 1703976, 10, 1703977, 10, 1703978, 10, 1703979, 10, 1703980, 10, 1703981, 10, 1703982, 10, 1703983, 10, 1703984, 10, 1703985, 10, 1703986, 10, 1703987, 10, 1703988, 10, 1703989, 10, 1703990, 10, 1703991, 10, 1703992, 10, 1703993, 10, 1703994, 10, 1703995, 10, 1703996, 10, 1703997, 10, 1703998, 10, 1703999, 10, 1704000, 10, 1704001, 10, 1704002, 10, 1704003, 10, 1704004, 10, 1704005, 10, 1704006, 10, 1704007, 10, 1769488, 10, 1769489, 10, 1769490, 10, 1769491, 10, 1769492, 10, 1769493, 10, 1769494, 10, 1769495, 10, 1769496, 10, 1769497, 10, 1769498, 10, 1769499, 10, 1769500, 10, 1769501, 10, 1769502, 10, 1769503, 10, 1769504, 10, 1769505, 10, 1769506, 10, 1769507, 10, 1769508, 10, 1769509, 10, 1769510, 10, 1769511, 10, 1769512, 10, 1769513, 10, 1769514, 10, 1769515, 10, 1769516, 10, 1769517, 10, 1769518, 10, 1769519, 10, 1769520, 10, 1769521, 10, 1769522, 10, 1769523, 10, 1769524, 10, 1769525, 10, 1769526, 10, 1769527, 10, 1769528, 10, 1769529, 10, 1769530, 10, 1769531, 10, 1769532, 10, 1769533, 10, 1769534, 10, 1769535, 10, 1769536, 10, 1769537, 10, 1769538, 10, 1769539, 10, 1769540, 10, 1769541, 10 "_edit_lock_" @@ -483,12 +487,10 @@ "3D" - "deflight_rot_y" - 0.628319 - "zfar" - 500 "fov" 45 + "zfar" + 500 "viewports" @@ -556,6 +558,8 @@ 0, 0, 0 + "deflight_rot_y" + 0.628319 "default_light" True "viewport_mode" @@ -806,7 +810,6 @@ "2D" - False 2 834.664, 1309.6 @@ -1000,7 +1003,7 @@ -1 "nodes" - -1, -1, 1, 0, -1, 2, 2, 0, 3, 1, 0, 0, 0, 5, 4, -1, 21, 2, 0, 6, 2, 7, 3, 8, 3, 9, 4, 10, 5, 11, 6, 12, 7, 13, 2, 14, 7, 15, 8, 16, 9, 17, 10, 18, 11, 19, 12, 20, 7, 21, 3, 22, 5, 23, 13, 24, 14, 3, 15, 0, 0, 0, 1, 25, -1, 2, 2, 0, 3, 16, 0, 2, 0, 27, 26, 17, 3, 2, 0, 9, 18, 3, 19, 0, 2, 0, 27, 28, 17, 3, 2, 0, 9, 20, 3, 19, 0, 2, 0, 27, 29, 17, 3, 2, 0, 9, 21, 3, 19, 0, 2, 0, 27, 30, 17, 3, 2, 0, 9, 22, 3, 19, 0, 2, 0, 27, 31, 17, 3, 2, 0, 9, 23, 3, 19, 0, 2, 0, 27, 32, 17, 3, 2, 0, 9, 24, 3, 19, 0, 2, 0, 27, 33, 17, 3, 2, 0, 9, 25, 3, 19, 0, 2, 0, 27, 34, 17, 3, 2, 0, 9, 26, 3, 19, 0, 2, 0, 27, 35, 17, 3, 2, 0, 9, 27, 3, 19, 0, 2, 0, 27, 36, 17, 3, 2, 0, 9, 28, 3, 19, 0, 2, 0, 27, 37, 17, 3, 2, 0, 9, 29, 3, 19, 0, 2, 0, 27, 38, 17, 3, 2, 0, 9, 30, 3, 19, 0, 2, 0, 27, 39, 17, 3, 2, 0, 9, 31, 3, 19, 0, 2, 0, 27, 40, 17, 3, 2, 0, 9, 32, 3, 19, 0, 2, 0, 27, 41, 17, 3, 2, 0, 9, 33, 3, 19, 0, 2, 0, 27, 42, 17, 3, 2, 0, 9, 34, 3, 19, 0, 2, 0, 27, 43, 17, 3, 2, 0, 9, 35, 3, 19, 0, 2, 0, 27, 44, 17, 3, 2, 0, 9, 36, 3, 19, 0, 2, 0, 27, 45, 17, 3, 2, 0, 9, 37, 3, 19, 0, 2, 0, 27, 46, 17, 3, 2, 0, 9, 38, 3, 19, 0, 2, 0, 27, 47, 17, 3, 2, 0, 9, 39, 3, 19, 0, 2, 0, 27, 48, 17, 3, 2, 0, 9, 40, 3, 19, 0, 2, 0, 27, 49, 17, 3, 2, 0, 9, 41, 3, 19, 0, 2, 0, 27, 50, 17, 3, 2, 0, 9, 42, 3, 19, 0, 2, 0, 27, 51, 17, 3, 2, 0, 9, 43, 3, 19, 0, 2, 0, 27, 52, 17, 3, 2, 0, 9, 44, 3, 19, 0, 2, 0, 27, 53, 17, 3, 2, 0, 9, 45, 3, 19, 0, 2, 0, 27, 54, 17, 3, 2, 0, 9, 46, 3, 19, 0, 2, 0, 27, 55, 17, 3, 2, 0, 9, 47, 3, 19, 0, 2, 0, 27, 56, 17, 3, 2, 0, 9, 48, 3, 19, 0, 2, 0, 27, 57, 17, 3, 2, 0, 9, 49, 3, 19, 0, 2, 0, 27, 58, 17, 3, 2, 0, 9, 50, 3, 19, 0, 2, 0, 27, 59, 17, 3, 2, 0, 9, 51, 3, 19, 0, 2, 0, 27, 60, 17, 3, 2, 0, 9, 52, 3, 19, 0, 2, 0, 27, 61, 17, 3, 2, 0, 9, 53, 3, 19, 0, 2, 0, 27, 62, 17, 3, 2, 0, 9, 54, 3, 19, 0, 2, 0, 27, 63, 17, 3, 2, 0, 9, 55, 3, 19, 0, 2, 0, 27, 64, 17, 3, 2, 0, 9, 56, 3, 19, 0, 2, 0, 27, 65, 17, 3, 2, 0, 9, 57, 3, 19, 0, 2, 0, 27, 66, 17, 3, 2, 0, 9, 58, 3, 19, 0, 2, 0, 27, 67, 17, 3, 2, 0, 9, 59, 3, 19, 0, 2, 0, 27, 68, 17, 3, 2, 0, 9, 60, 3, 19, 0, 0, 0, 70, 69, 61, 3, 2, 0, 9, 62, 3, 63, 0, 0, 0, 1, 71, -1, 1, 2, 0, 0, 46, 0, 73, 72, 64, 5, 2, 0, 9, 65, 3, 66, 74, 67, 75, 68, 0, 46, 0, 73, 76, 64, 5, 2, 0, 9, 69, 3, 66, 74, 70, 75, 71, 0, 46, 0, 73, 77, 64, 5, 2, 0, 9, 72, 3, 66, 74, 73, 75, 71, 0, 46, 0, 73, 78, 74, 3, 2, 0, 9, 75, 3, 76, 0, 0, 0, 80, 79, -1, 7, 2, 0, 81, 77, 82, 78, 83, 2, 84, 79, 85, 2, 86, 78, 0, 0, 0, 1, 87, -1, 1, 2, 0, 0, 52, 0, 70, 88, 80, 3, 2, 0, 9, 81, 3, 82, 0, 52, 0, 70, 89, 80, 3, 2, 0, 9, 83, 3, 82, 0, 52, 0, 70, 90, 80, 3, 2, 0, 9, 84, 3, 82, 0, 52, 0, 70, 91, 80, 3, 2, 0, 9, 85, 3, 82, 0, 52, 0, 70, 92, 80, 3, 2, 0, 9, 86, 3, 82, 0, 52, 0, 70, 93, 80, 3, 2, 0, 9, 87, 3, 82, 0, 52, 0, 70, 94, 80, 3, 2, 0, 9, 88, 3, 82, 0, 52, 0, 70, 95, 80, 3, 2, 0, 9, 89, 3, 82, 0, 52, 0, 70, 96, 80, 3, 2, 0, 9, 90, 3, 82, 0, 52, 0, 70, 97, 80, 3, 2, 0, 9, 91, 3, 82, 0, 52, 0, 70, 98, 80, 3, 2, 0, 9, 92, 3, 82, 0, 0, 0, 100, 99, 93, 2, 2, 0, 3, 94, 0, 0, 0, 101, 101, -1, 29, 2, 0, 6, 2, 7, 3, 8, 3, 102, 95, 103, 96, 104, 97, 105, 98, 106, 0, 107, 0, 108, 0, 109, 0, 110, 2, 111, 2, 112, 12, 113, 3, 114, 5, 115, 99, 116, 3, 117, 100, 118, 5, 119, 78, 120, 78, 121, 101, 122, 7, 123, 7, 124, 2, 125, 78, 126, 102, 0 + -1, -1, 1, 0, -1, 2, 2, 0, 3, 1, 0, 0, 0, 5, 4, -1, 24, 2, 0, 6, 2, 7, 3, 8, 3, 9, 4, 10, 5, 11, 6, 12, 7, 13, 8, 14, 2, 15, 8, 16, 9, 17, 10, 18, 11, 19, 12, 20, 13, 21, 8, 22, 14, 23, 14, 24, 3, 25, 6, 26, 4, 27, 15, 3, 16, 0, 0, 0, 1, 28, -1, 2, 2, 0, 3, 17, 0, 2, 0, 30, 29, 18, 3, 2, 0, 10, 19, 3, 20, 0, 2, 0, 30, 31, 18, 3, 2, 0, 10, 21, 3, 20, 0, 2, 0, 30, 32, 18, 3, 2, 0, 10, 22, 3, 20, 0, 2, 0, 30, 33, 18, 3, 2, 0, 10, 23, 3, 20, 0, 2, 0, 30, 34, 18, 3, 2, 0, 10, 24, 3, 20, 0, 2, 0, 30, 35, 18, 3, 2, 0, 10, 25, 3, 20, 0, 2, 0, 30, 36, 18, 3, 2, 0, 10, 26, 3, 20, 0, 2, 0, 30, 37, 18, 3, 2, 0, 10, 27, 3, 20, 0, 2, 0, 30, 38, 18, 3, 2, 0, 10, 28, 3, 20, 0, 2, 0, 30, 39, 18, 3, 2, 0, 10, 29, 3, 20, 0, 2, 0, 30, 40, 18, 3, 2, 0, 10, 30, 3, 20, 0, 2, 0, 30, 41, 18, 3, 2, 0, 10, 31, 3, 20, 0, 2, 0, 30, 42, 18, 3, 2, 0, 10, 32, 3, 20, 0, 2, 0, 30, 43, 18, 3, 2, 0, 10, 33, 3, 20, 0, 2, 0, 30, 44, 18, 3, 2, 0, 10, 34, 3, 20, 0, 2, 0, 30, 45, 18, 3, 2, 0, 10, 35, 3, 20, 0, 2, 0, 30, 46, 18, 3, 2, 0, 10, 36, 3, 20, 0, 2, 0, 30, 47, 18, 3, 2, 0, 10, 37, 3, 20, 0, 2, 0, 30, 48, 18, 3, 2, 0, 10, 38, 3, 20, 0, 2, 0, 30, 49, 18, 3, 2, 0, 10, 39, 3, 20, 0, 2, 0, 30, 50, 18, 3, 2, 0, 10, 40, 3, 20, 0, 2, 0, 30, 51, 18, 3, 2, 0, 10, 41, 3, 20, 0, 2, 0, 30, 52, 18, 3, 2, 0, 10, 42, 3, 20, 0, 2, 0, 30, 53, 18, 3, 2, 0, 10, 43, 3, 20, 0, 2, 0, 30, 54, 18, 3, 2, 0, 10, 44, 3, 20, 0, 2, 0, 30, 55, 18, 3, 2, 0, 10, 45, 3, 20, 0, 2, 0, 30, 56, 18, 3, 2, 0, 10, 46, 3, 20, 0, 2, 0, 30, 57, 18, 3, 2, 0, 10, 47, 3, 20, 0, 2, 0, 30, 58, 18, 3, 2, 0, 10, 48, 3, 20, 0, 2, 0, 30, 59, 18, 3, 2, 0, 10, 49, 3, 20, 0, 2, 0, 30, 60, 18, 3, 2, 0, 10, 50, 3, 20, 0, 2, 0, 30, 61, 18, 3, 2, 0, 10, 51, 3, 20, 0, 2, 0, 30, 62, 18, 3, 2, 0, 10, 52, 3, 20, 0, 2, 0, 30, 63, 18, 3, 2, 0, 10, 53, 3, 20, 0, 2, 0, 30, 64, 18, 3, 2, 0, 10, 54, 3, 20, 0, 2, 0, 30, 65, 18, 3, 2, 0, 10, 55, 3, 20, 0, 2, 0, 30, 66, 18, 3, 2, 0, 10, 56, 3, 20, 0, 2, 0, 30, 67, 18, 3, 2, 0, 10, 57, 3, 20, 0, 2, 0, 30, 68, 18, 3, 2, 0, 10, 58, 3, 20, 0, 2, 0, 30, 69, 18, 3, 2, 0, 10, 59, 3, 20, 0, 2, 0, 30, 70, 18, 3, 2, 0, 10, 60, 3, 20, 0, 2, 0, 30, 71, 18, 3, 2, 0, 10, 61, 3, 20, 0, 0, 0, 73, 72, 62, 3, 2, 0, 10, 63, 3, 64, 0, 0, 0, 1, 74, -1, 1, 2, 0, 0, 46, 0, 76, 75, 65, 5, 2, 0, 10, 66, 3, 67, 77, 68, 78, 69, 0, 46, 0, 76, 79, 65, 5, 2, 0, 10, 70, 3, 67, 77, 71, 78, 72, 0, 46, 0, 76, 80, 65, 5, 2, 0, 10, 73, 3, 67, 77, 74, 78, 72, 0, 46, 0, 76, 81, 75, 3, 2, 0, 10, 76, 3, 77, 0, 0, 0, 83, 82, -1, 7, 2, 0, 84, 78, 85, 14, 86, 2, 87, 79, 88, 2, 89, 14, 0, 0, 0, 1, 90, -1, 1, 2, 0, 0, 52, 0, 73, 91, 80, 3, 2, 0, 10, 81, 3, 82, 0, 52, 0, 73, 92, 80, 3, 2, 0, 10, 83, 3, 82, 0, 52, 0, 73, 93, 80, 3, 2, 0, 10, 84, 3, 82, 0, 52, 0, 73, 94, 80, 3, 2, 0, 10, 85, 3, 82, 0, 52, 0, 73, 95, 80, 3, 2, 0, 10, 86, 3, 82, 0, 52, 0, 73, 96, 80, 3, 2, 0, 10, 87, 3, 82, 0, 52, 0, 73, 97, 80, 3, 2, 0, 10, 88, 3, 82, 0, 52, 0, 73, 98, 80, 3, 2, 0, 10, 89, 3, 82, 0, 52, 0, 73, 99, 80, 3, 2, 0, 10, 90, 3, 82, 0, 52, 0, 73, 100, 80, 3, 2, 0, 10, 91, 3, 82, 0, 52, 0, 73, 101, 80, 3, 2, 0, 10, 92, 3, 82, 0, 0, 0, 103, 102, 93, 2, 2, 0, 3, 94, 0, 0, 0, 104, 104, -1, 30, 2, 0, 6, 2, 7, 3, 8, 3, 9, 4, 105, 95, 106, 96, 107, 97, 108, 98, 109, 0, 110, 0, 111, 0, 112, 0, 113, 2, 114, 2, 115, 13, 116, 3, 117, 6, 118, 99, 119, 3, 120, 100, 121, 6, 122, 14, 123, 14, 124, 101, 125, 8, 126, 8, 127, 2, 128, 14, 129, 102, 0 "conns" diff --git a/drivers/gles2/rasterizer_gles2.cpp b/drivers/gles2/rasterizer_gles2.cpp index 49fae098a8..a21b0775e9 100644 --- a/drivers/gles2/rasterizer_gles2.cpp +++ b/drivers/gles2/rasterizer_gles2.cpp @@ -4288,7 +4288,7 @@ void RasterizerGLES2::capture_viewport(Image* r_capture) { void RasterizerGLES2::clear_viewport(const Color& p_color) { - if (current_rt) { + if (current_rt || using_canvas_bg) { glScissor( 0, 0, viewport.width, viewport.height ); } else { @@ -6944,7 +6944,7 @@ void RasterizerGLES2::_draw_tex_bg() { RID texture; - if (current_env->bg_mode==VS::ENV_BG_TEXTURE || current_env->bg_mode==VS::ENV_BG_TEXTURE_RGBE) { + if (current_env->bg_mode==VS::ENV_BG_TEXTURE) { texture=current_env->bg_param[VS::ENV_BG_PARAM_TEXTURE]; } else { texture=current_env->bg_param[VS::ENV_BG_PARAM_CUBEMAP]; @@ -6961,25 +6961,20 @@ void RasterizerGLES2::_draw_tex_bg() { copy_shader.set_conditional(CopyShaderGLES2::USE_ENERGY,true); - if (current_env->bg_mode==VS::ENV_BG_TEXTURE || current_env->bg_mode==VS::ENV_BG_TEXTURE_RGBE) { + if (current_env->bg_mode==VS::ENV_BG_TEXTURE) { copy_shader.set_conditional(CopyShaderGLES2::USE_CUBEMAP,false); } else { copy_shader.set_conditional(CopyShaderGLES2::USE_CUBEMAP,true); } - if (current_env->bg_mode==VS::ENV_BG_CUBEMAP_RGBE || current_env->bg_mode==VS::ENV_BG_TEXTURE_RGBE) { - copy_shader.set_conditional(CopyShaderGLES2::USE_RGBE,true); - } else { - copy_shader.set_conditional(CopyShaderGLES2::USE_RGBE,false); - } copy_shader.set_conditional(CopyShaderGLES2::USE_CUSTOM_ALPHA,true); copy_shader.bind(); - if (current_env->bg_mode==VS::ENV_BG_TEXTURE || current_env->bg_mode==VS::ENV_BG_TEXTURE_RGBE) { + if (current_env->bg_mode==VS::ENV_BG_TEXTURE) { glUniform1i( copy_shader.get_uniform_location(CopyShaderGLES2::SOURCE),0); } else { glUniform1i( copy_shader.get_uniform_location(CopyShaderGLES2::SOURCE_CUBE),0); @@ -7006,7 +7001,7 @@ void RasterizerGLES2::_draw_tex_bg() { Vector3( 0, 0, 0) }; - if (current_env->bg_mode==VS::ENV_BG_TEXTURE || current_env->bg_mode==VS::ENV_BG_TEXTURE_RGBE) { + if (current_env->bg_mode==VS::ENV_BG_TEXTURE) { //regular texture //adjust aspect @@ -7076,7 +7071,7 @@ void RasterizerGLES2::end_scene() { if (framebuffer.active) { //detect when to use the framebuffer object - if (texscreen_used || framebuffer.scale!=1) { + if (using_canvas_bg || texscreen_used || framebuffer.scale!=1) { use_fb=true; } else if (current_env) { use_fb=false; @@ -7128,6 +7123,7 @@ void RasterizerGLES2::end_scene() { switch(current_env->bg_mode) { + case VS::ENV_BG_CANVAS: case VS::ENV_BG_KEEP: { //copy from framebuffer if framebuffer glClear(GL_DEPTH_BUFFER_BIT); @@ -7140,7 +7136,7 @@ void RasterizerGLES2::end_scene() { bgcolor = current_env->bg_param[VS::ENV_BG_PARAM_COLOR]; else bgcolor = Globals::get_singleton()->get("render/default_clear_color"); - bgcolor = _convert_color(bgcolor); + bgcolor = _convert_color(bgcolor); float a = use_fb ? float(current_env->bg_param[VS::ENV_BG_PARAM_GLOW]) : 1.0; glClearColor(bgcolor.r,bgcolor.g,bgcolor.b,a); _glClearDepth(1.0); @@ -7148,9 +7144,7 @@ void RasterizerGLES2::end_scene() { } break; case VS::ENV_BG_TEXTURE: - case VS::ENV_BG_CUBEMAP: - case VS::ENV_BG_TEXTURE_RGBE: - case VS::ENV_BG_CUBEMAP_RGBE: { + case VS::ENV_BG_CUBEMAP: { glClear(GL_DEPTH_BUFFER_BIT); @@ -7369,8 +7363,12 @@ void RasterizerGLES2::end_scene() { _debug_shadows(); } // _debug_luminances(); - _debug_samplers(); +// _debug_samplers(); + if (using_canvas_bg) { + using_canvas_bg=false; + glColorMask(1,1,1,1); //don't touch alpha + } } void RasterizerGLES2::end_shadow_map() { @@ -7839,8 +7837,26 @@ void RasterizerGLES2::flush_frame() { /* CANVAS API */ +void RasterizerGLES2::begin_canvas_bg() { + + if (framebuffer.active) { + using_canvas_bg=true; + glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.fbo); + glViewport( 0,0,viewport.width , viewport.height ); + } else { + using_canvas_bg=false; + } + +} + void RasterizerGLES2::canvas_begin() { + + if (using_canvas_bg) { + glBindFramebuffer(GL_FRAMEBUFFER, framebuffer.fbo); + glColorMask(1,1,1,0); //don't touch alpha + } + glDisable(GL_CULL_FACE); glDisable(GL_DEPTH_TEST); glDisable(GL_SCISSOR_TEST); @@ -10567,7 +10583,7 @@ void RasterizerGLES2::init() { glBindBuffer(GL_ARRAY_BUFFER,0); //unbind - + using_canvas_bg=false; _update_framebuffer(); DEBUG_TEST_ERROR("Initializing"); } diff --git a/drivers/gles2/rasterizer_gles2.h b/drivers/gles2/rasterizer_gles2.h index f09714f50c..b7895ad82e 100644 --- a/drivers/gles2/rasterizer_gles2.h +++ b/drivers/gles2/rasterizer_gles2.h @@ -677,6 +677,7 @@ class RasterizerGLES2 : public Rasterizer { bg_param[VS::ENV_BG_PARAM_ENERGY]=1.0; bg_param[VS::ENV_BG_PARAM_SCALE]=1.0; bg_param[VS::ENV_BG_PARAM_GLOW]=0.0; + bg_param[VS::ENV_BG_PARAM_CANVAS_MAX_LAYER]=0; for(int i=0;i0) { completion_index=0; completion_current=completion_options[completion_index]; @@ -1354,7 +1354,7 @@ void TextEdit::_input_event(const InputEvent& p_input_event) { return; } - if (k.scancode==KEY_END) { + if (k.scancode==KEY_END && completion_indexdisable_environment=p_disable; + +} + void VisualServerRaster::viewport_attach_camera(RID p_viewport,RID p_camera) { VS_CHANGED; @@ -6267,6 +6278,20 @@ void VisualServerRaster::_process_sampled_light(const Transform& p_camera,Instan } +void VisualServerRaster::_render_no_camera(Viewport *p_viewport,Camera *p_camera, Scenario *p_scenario) { + RID environment; + if (p_scenario->environment.is_valid()) + environment=p_scenario->environment; + else + environment=p_scenario->fallback_environment; + + rasterizer->set_camera(Transform(),CameraMatrix()); + rasterizer->begin_scene(p_viewport->viewport_data,environment,p_scenario->debug); + rasterizer->set_viewport(viewport_rect); + rasterizer->end_scene(); +} + + void VisualServerRaster::_render_camera(Viewport *p_viewport,Camera *p_camera, Scenario *p_scenario) { @@ -6889,6 +6914,23 @@ void VisualServerRaster::_render_canvas(Canvas *p_canvas,const Matrix32 &p_trans } +void VisualServerRaster::_draw_viewport_camera(Viewport *p_viewport,bool p_ignore_camera) { + + + Camera *camera=NULL; + if (camera_owner.owns( p_viewport->camera )) + camera=camera_owner.get( p_viewport->camera ); + Scenario *scenario = scenario_owner.get( p_viewport->scenario ); + + _update_instances(); // check dirty instances before rendering + + if (p_ignore_camera) + _render_no_camera(p_viewport, camera,scenario ); + else + _render_camera(p_viewport, camera,scenario ); + +} + void VisualServerRaster::_draw_viewport(Viewport *p_viewport,int p_ofs_x, int p_ofs_y,int p_parent_w,int p_parent_h) { ViewportRect desired_rect=p_viewport->rect; @@ -6923,14 +6965,31 @@ void VisualServerRaster::_draw_viewport(Viewport *p_viewport,int p_ofs_x, int p_ /* Camera should always be BEFORE any other 3D */ - if (!p_viewport->hide_scenario && camera_owner.owns(p_viewport->camera) && scenario_owner.owns(p_viewport->scenario)) { + bool scenario_draw_canvas_bg=false; + int scenario_canvas_max_layer=0; - Camera *camera = camera_owner.get( p_viewport->camera ); - Scenario *scenario = scenario_owner.get( p_viewport->scenario ); + if (!p_viewport->hide_canvas && !p_viewport->disable_environment && scenario_owner.owns(p_viewport->scenario)) { - _update_instances(); // check dirty instances before rendering + Scenario *scenario=scenario_owner.get(p_viewport->scenario); + if (scenario->environment.is_valid()) { + if (rasterizer->is_environment(scenario->environment)) { + scenario_draw_canvas_bg=rasterizer->environment_get_background(scenario->environment)==VS::ENV_BG_CANVAS; + scenario_canvas_max_layer=rasterizer->environment_get_background_param(scenario->environment,VS::ENV_BG_PARAM_CANVAS_MAX_LAYER); + } + } + } + + bool can_draw_3d=!p_viewport->hide_scenario && camera_owner.owns(p_viewport->camera) && scenario_owner.owns(p_viewport->scenario); - _render_camera(p_viewport, camera,scenario ); + + if (scenario_draw_canvas_bg) { + + rasterizer->begin_canvas_bg(); + } + + if (!scenario_draw_canvas_bg && can_draw_3d) { + + _draw_viewport_camera(p_viewport,false); } else if (true /*|| !p_viewport->canvas_list.empty()*/){ @@ -6940,7 +6999,10 @@ void VisualServerRaster::_draw_viewport(Viewport *p_viewport,int p_ofs_x, int p_ rasterizer->clear_viewport(Color(0,0,0,0)); } else { - rasterizer->clear_viewport(clear_color); + Color cc=clear_color; + if (scenario_draw_canvas_bg) + cc.a=0; + rasterizer->clear_viewport(cc); } p_viewport->render_target_clear=false; } @@ -7040,6 +7102,16 @@ void VisualServerRaster::_draw_viewport(Viewport *p_viewport,int p_ofs_x, int p_ rasterizer->set_viewport(viewport_rect); //must reset viewport afterwards } + + + + if (scenario_draw_canvas_bg && canvas_map.front() && canvas_map.front()->key().layer>scenario_canvas_max_layer) { + + _draw_viewport_camera(p_viewport,!can_draw_3d); + scenario_draw_canvas_bg=false; + + } + for (Map::Element *E=canvas_map.front();E;E=E->next()) { @@ -7061,8 +7133,20 @@ void VisualServerRaster::_draw_viewport(Viewport *p_viewport,int p_ofs_x, int p_ _render_canvas( E->get()->canvas,xform,canvas_lights ); i++; + if (scenario_draw_canvas_bg && E->key().layer>=scenario_canvas_max_layer) { + _draw_viewport_camera(p_viewport,!can_draw_3d); + scenario_draw_canvas_bg=false; + } + + } + if (scenario_draw_canvas_bg) { + _draw_viewport_camera(p_viewport,!can_draw_3d); + scenario_draw_canvas_bg=false; + } + + //rasterizer->canvas_debug_viewport_shadows(lights_with_shadow); } diff --git a/servers/visual/visual_server_raster.h b/servers/visual/visual_server_raster.h index 5c0d48645e..b1970c55b3 100644 --- a/servers/visual/visual_server_raster.h +++ b/servers/visual/visual_server_raster.h @@ -489,6 +489,8 @@ class VisualServerRaster : public VisualServer { bool render_target_vflip; bool render_target_clear_on_new_frame; bool render_target_clear; + bool disable_environment; + Image capture; bool rendered_in_prev_frame; @@ -515,7 +517,7 @@ class VisualServerRaster : public VisualServer { SelfList update_list; - Viewport() : update_list(this) { transparent_bg=false; render_target_update_mode=RENDER_TARGET_UPDATE_WHEN_VISIBLE; queue_capture=false; rendered_in_prev_frame=false; render_target_vflip=false; render_target_clear_on_new_frame=true; render_target_clear=true;} + Viewport() : update_list(this) { transparent_bg=false; render_target_update_mode=RENDER_TARGET_UPDATE_WHEN_VISIBLE; queue_capture=false; rendered_in_prev_frame=false; render_target_vflip=false; render_target_clear_on_new_frame=true; render_target_clear=true; disable_environment=false; } }; SelfList::List viewport_update_list; @@ -626,6 +628,7 @@ class VisualServerRaster : public VisualServer { void _cull_room(Camera *p_camera, Instance *p_room,Instance *p_from_portal=NULL); void _process_sampled_light(const Transform &p_camera, Instance *p_sampled_light, bool p_linear_colorspace); + void _render_no_camera(Viewport *p_viewport,Camera *p_camera, Scenario *p_scenario); void _render_camera(Viewport *p_viewport,Camera *p_camera, Scenario *p_scenario); static void _render_canvas_item_viewport(VisualServer* p_self,void *p_vp,const Rect2& p_rect); void _render_canvas_item_tree(CanvasItem *p_canvas_item, const Matrix32& p_transform, const Rect2& p_clip_rect, const Color &p_modulate, Rasterizer::CanvasLight *p_lights); @@ -643,6 +646,7 @@ class VisualServerRaster : public VisualServer { int changes; bool draw_extra_frame; + void _draw_viewport_camera(Viewport *p_viewport, bool p_ignore_camera); void _draw_viewport(Viewport *p_viewport,int p_ofs_x, int p_ofs_y,int p_parent_w,int p_parent_h); void _draw_viewports(); void _draw_cursors_and_margins(); @@ -983,6 +987,7 @@ public: virtual void viewport_render_target_clear(RID p_viewport); virtual void viewport_set_render_target_to_screen_rect(RID p_viewport,const Rect2& p_rect); + virtual void viewport_queue_screen_capture(RID p_viewport); virtual Image viewport_get_screen_capture(RID p_viewport) const; @@ -991,6 +996,7 @@ public: virtual void viewport_set_hide_scenario(RID p_viewport,bool p_hide); virtual void viewport_set_hide_canvas(RID p_viewport,bool p_hide); + virtual void viewport_set_disable_environment(RID p_viewport,bool p_disable); virtual void viewport_attach_camera(RID p_viewport,RID p_camera); virtual void viewport_set_scenario(RID p_viewport,RID p_scenario); diff --git a/servers/visual/visual_server_wrap_mt.h b/servers/visual/visual_server_wrap_mt.h index 6848075824..562b9ffeb0 100644 --- a/servers/visual/visual_server_wrap_mt.h +++ b/servers/visual/visual_server_wrap_mt.h @@ -982,6 +982,7 @@ public: FUNC2(viewport_set_hide_canvas,RID,bool ); FUNC2(viewport_attach_camera,RID,RID ); FUNC2(viewport_set_scenario,RID,RID ); + FUNC2(viewport_set_disable_environment,RID,bool ); FUNC1RC(RID,viewport_get_attached_camera,RID); FUNC1RC(RID,viewport_get_scenario,RID ); diff --git a/servers/visual_server.h b/servers/visual_server.h index f4896f984e..c748839d1e 100644 --- a/servers/visual_server.h +++ b/servers/visual_server.h @@ -704,6 +704,7 @@ public: virtual void viewport_set_hide_scenario(RID p_viewport,bool p_hide)=0; virtual void viewport_set_hide_canvas(RID p_viewport,bool p_hide)=0; + virtual void viewport_set_disable_environment(RID p_viewport,bool p_disable)=0; virtual void viewport_attach_camera(RID p_viewport,RID p_camera)=0; virtual void viewport_set_scenario(RID p_viewport,RID p_scenario)=0; @@ -734,8 +735,7 @@ public: ENV_BG_COLOR, ENV_BG_TEXTURE, ENV_BG_CUBEMAP, - ENV_BG_TEXTURE_RGBE, - ENV_BG_CUBEMAP_RGBE, + ENV_BG_CANVAS, ENV_BG_MAX }; @@ -744,6 +744,7 @@ public: enum EnvironmentBGParam { + ENV_BG_PARAM_CANVAS_MAX_LAYER, ENV_BG_PARAM_COLOR, ENV_BG_PARAM_TEXTURE, ENV_BG_PARAM_CUBEMAP, diff --git a/tools/editor/editor_node.cpp b/tools/editor/editor_node.cpp index 3d42867d9a..5e571373ea 100644 --- a/tools/editor/editor_node.cpp +++ b/tools/editor/editor_node.cpp @@ -218,6 +218,7 @@ void EditorNode::_notification(int p_what) { } if (p_what==NOTIFICATION_ENTER_TREE) { + //MessageQueue::get_singleton()->push_call(this,"_get_scene_metadata"); get_tree()->set_editor_hint(true); get_tree()->get_root()->set_as_audio_listener(false); @@ -231,6 +232,8 @@ void EditorNode::_notification(int p_what) { VisualServer::get_singleton()->viewport_set_hide_scenario(get_scene_root()->get_viewport(),true); VisualServer::get_singleton()->viewport_set_hide_canvas(get_scene_root()->get_viewport(),true); + VisualServer::get_singleton()->viewport_set_disable_environment(get_viewport()->get_viewport_rid(),true); + _editor_select(1); if (defer_load_scene!="") { @@ -3412,6 +3415,8 @@ EditorNode::EditorNode() { scene_root = memnew( Viewport ); + + //scene_root_base->add_child(scene_root); scene_root->set_meta("_editor_disable_input",true); VisualServer::get_singleton()->viewport_set_hide_scenario(scene_root->get_viewport(),true); diff --git a/tools/editor/property_editor.cpp b/tools/editor/property_editor.cpp index f760ab1cb5..078a177ca1 100644 --- a/tools/editor/property_editor.cpp +++ b/tools/editor/property_editor.cpp @@ -651,6 +651,8 @@ bool CustomPropertyEditor::edit(Object* p_owner,const String& p_name,Variant::Ty if (!RES(v).is_null()) { + + menu->add_icon_item(get_icon("EditResource","EditorIcons"),"Edit",OBJ_MENU_EDIT); menu->add_icon_item(get_icon("Del","EditorIcons"),"Clear",OBJ_MENU_CLEAR); menu->add_icon_item(get_icon("Duplicate","EditorIcons"),"Make Unique",OBJ_MENU_MAKE_UNIQUE); @@ -659,6 +661,13 @@ bool CustomPropertyEditor::edit(Object* p_owner,const String& p_name,Variant::Ty menu->add_separator(); menu->add_icon_item(get_icon("Reload","EditorIcons"),"Re-Import",OBJ_MENU_REIMPORT); } + /*if (r.is_valid() && r->get_path().is_resource_file()) { + menu->set_item_tooltip(1,r->get_path()); + } else if (r.is_valid()) { + menu->set_item_tooltip(1,r->get_name()+" ("+r->get_type()+")"); + }*/ + } else { + } @@ -1858,6 +1867,14 @@ void PropertyEditor::set_item_text(TreeItem *p_item, int p_type, const String& p p_item->set_text(1,"<"+res->get_type()+">"); }; + + if (res.is_valid() && res->get_path().is_resource_file()) { + p_item->set_tooltip(1,res->get_path()); + } else if (res.is_valid()) { + p_item->set_tooltip(1,res->get_name()+" ("+res->get_type()+")"); + } + + if (has_icon(res->get_type(),"EditorIcons")) { p_item->set_icon(0,get_icon(res->get_type(),"EditorIcons")); @@ -2584,6 +2601,13 @@ void PropertyEditor::update_tree() { if (has_icon(res->get_type(),"EditorIcons")) { type=res->get_type(); } + + if (res.is_valid() && res->get_path().is_resource_file()) { + item->set_tooltip(1,res->get_path()); + } else if (res.is_valid()) { + item->set_tooltip(1,res->get_name()+" ("+res->get_type()+")"); + } + } -- cgit v1.2.3 From a969e2e6f17d6810771e9c9c31551d57e5d1efdb Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Tue, 17 Mar 2015 00:45:25 -0300 Subject: Area2D can now detect overlap with other areas this should make everything simpler, specially for newcomers to Godot --- scene/2d/area_2d.cpp | 235 +++++++++++++++++++++++++--- scene/2d/area_2d.h | 35 +++++ scene/scene_string_names.cpp | 6 + scene/scene_string_names.h | 7 + servers/physics_2d/area_2d_sw.cpp | 71 ++++++++- servers/physics_2d/area_2d_sw.h | 34 ++++ servers/physics_2d/area_pair_2d_sw.cpp | 69 ++++++++ servers/physics_2d/area_pair_2d_sw.h | 18 +++ servers/physics_2d/physics_2d_server_sw.cpp | 18 +++ servers/physics_2d/physics_2d_server_sw.h | 3 +- servers/physics_2d/space_2d_sw.cpp | 15 +- servers/physics_2d_server.h | 3 + tools/editor/connections_dialog.cpp | 11 +- 13 files changed, 500 insertions(+), 25 deletions(-) diff --git a/scene/2d/area_2d.cpp b/scene/2d/area_2d.cpp index fce21f6001..b972ddfa3c 100644 --- a/scene/2d/area_2d.cpp +++ b/scene/2d/area_2d.cpp @@ -216,6 +216,119 @@ void Area2D::_body_inout(int p_status,const RID& p_body, int p_instance, int p_b } + +void Area2D::_area_enter_tree(ObjectID p_id) { + + Object *obj = ObjectDB::get_instance(p_id); + Node *node = obj ? obj->cast_to() : NULL; + ERR_FAIL_COND(!node); + + Map::Element *E=area_map.find(p_id); + ERR_FAIL_COND(!E); + ERR_FAIL_COND(E->get().in_tree); + + E->get().in_tree=true; + emit_signal(SceneStringNames::get_singleton()->area_enter,node); + for(int i=0;iget().shapes.size();i++) { + + emit_signal(SceneStringNames::get_singleton()->area_enter_shape,p_id,node,E->get().shapes[i].area_shape,E->get().shapes[i].self_shape); + } + +} + +void Area2D::_area_exit_tree(ObjectID p_id) { + + Object *obj = ObjectDB::get_instance(p_id); + Node *node = obj ? obj->cast_to() : NULL; + ERR_FAIL_COND(!node); + Map::Element *E=area_map.find(p_id); + ERR_FAIL_COND(!E); + ERR_FAIL_COND(!E->get().in_tree); + E->get().in_tree=false; + emit_signal(SceneStringNames::get_singleton()->area_exit,node); + for(int i=0;iget().shapes.size();i++) { + + emit_signal(SceneStringNames::get_singleton()->area_exit_shape,p_id,node,E->get().shapes[i].area_shape,E->get().shapes[i].self_shape); + } + +} + +void Area2D::_area_inout(int p_status,const RID& p_area, int p_instance, int p_area_shape,int p_self_shape) { + + bool area_in = p_status==Physics2DServer::AREA_BODY_ADDED; + ObjectID objid=p_instance; + + Object *obj = ObjectDB::get_instance(objid); + Node *node = obj ? obj->cast_to() : NULL; + + Map::Element *E=area_map.find(objid); + + ERR_FAIL_COND(!area_in && !E); + + locked=true; + + if (area_in) { + if (!E) { + + E = area_map.insert(objid,AreaState()); + E->get().rc=0; + E->get().in_tree=node && node->is_inside_tree(); + if (node) { + node->connect(SceneStringNames::get_singleton()->enter_tree,this,SceneStringNames::get_singleton()->_area_enter_tree,make_binds(objid)); + node->connect(SceneStringNames::get_singleton()->exit_tree,this,SceneStringNames::get_singleton()->_area_exit_tree,make_binds(objid)); + if (E->get().in_tree) { + emit_signal(SceneStringNames::get_singleton()->area_enter,node); + } + } + + } + E->get().rc++; + if (node) + E->get().shapes.insert(AreaShapePair(p_area_shape,p_self_shape)); + + + if (!node || E->get().in_tree) { + emit_signal(SceneStringNames::get_singleton()->area_enter_shape,objid,node,p_area_shape,p_self_shape); + } + + } else { + + E->get().rc--; + + if (node) + E->get().shapes.erase(AreaShapePair(p_area_shape,p_self_shape)); + + bool eraseit=false; + + if (E->get().rc==0) { + + if (node) { + node->disconnect(SceneStringNames::get_singleton()->enter_tree,this,SceneStringNames::get_singleton()->_area_enter_tree); + node->disconnect(SceneStringNames::get_singleton()->exit_tree,this,SceneStringNames::get_singleton()->_area_exit_tree); + if (E->get().in_tree) + emit_signal(SceneStringNames::get_singleton()->area_exit,obj); + + } + + eraseit=true; + + } + if (!node || E->get().in_tree) { + emit_signal(SceneStringNames::get_singleton()->area_exit_shape,objid,obj,p_area_shape,p_self_shape); + } + + if (eraseit) + area_map.erase(E); + + } + + locked=false; + + +} + + + void Area2D::_clear_monitoring() { if (locked) { @@ -223,27 +336,56 @@ void Area2D::_clear_monitoring() { } ERR_FAIL_COND(locked); - Map bmcopy = body_map; - body_map.clear(); - //disconnect all monitored stuff + { + Map bmcopy = body_map; + body_map.clear(); + //disconnect all monitored stuff - for (Map::Element *E=bmcopy.front();E;E=E->next()) { + for (Map::Element *E=bmcopy.front();E;E=E->next()) { - Object *obj = ObjectDB::get_instance(E->key()); - Node *node = obj ? obj->cast_to() : NULL; - ERR_CONTINUE(!node); - if (!E->get().in_tree) - continue; + Object *obj = ObjectDB::get_instance(E->key()); + Node *node = obj ? obj->cast_to() : NULL; + ERR_CONTINUE(!node); + if (!E->get().in_tree) + continue; - for(int i=0;iget().shapes.size();i++) { + for(int i=0;iget().shapes.size();i++) { - emit_signal(SceneStringNames::get_singleton()->body_exit_shape,E->key(),node,E->get().shapes[i].body_shape,E->get().shapes[i].area_shape); + emit_signal(SceneStringNames::get_singleton()->body_exit_shape,E->key(),node,E->get().shapes[i].body_shape,E->get().shapes[i].area_shape); + } + + emit_signal(SceneStringNames::get_singleton()->body_exit,obj); + + node->disconnect(SceneStringNames::get_singleton()->enter_tree,this,SceneStringNames::get_singleton()->_body_enter_tree); + node->disconnect(SceneStringNames::get_singleton()->exit_tree,this,SceneStringNames::get_singleton()->_body_exit_tree); } - emit_signal(SceneStringNames::get_singleton()->body_exit,obj); + } + + { - node->disconnect(SceneStringNames::get_singleton()->enter_tree,this,SceneStringNames::get_singleton()->_body_enter_tree); - node->disconnect(SceneStringNames::get_singleton()->exit_tree,this,SceneStringNames::get_singleton()->_body_exit_tree); + Map bmcopy = area_map; + area_map.clear(); + //disconnect all monitored stuff + + for (Map::Element *E=bmcopy.front();E;E=E->next()) { + + Object *obj = ObjectDB::get_instance(E->key()); + Node *node = obj ? obj->cast_to() : NULL; + ERR_CONTINUE(!node); + if (!E->get().in_tree) + continue; + + for(int i=0;iget().shapes.size();i++) { + + emit_signal(SceneStringNames::get_singleton()->area_exit_shape,E->key(),node,E->get().shapes[i].area_shape,E->get().shapes[i].self_shape); + } + + emit_signal(SceneStringNames::get_singleton()->area_exit,obj); + + node->disconnect(SceneStringNames::get_singleton()->enter_tree,this,SceneStringNames::get_singleton()->_area_enter_tree); + node->disconnect(SceneStringNames::get_singleton()->exit_tree,this,SceneStringNames::get_singleton()->_area_exit_tree); + } } } @@ -276,8 +418,10 @@ void Area2D::set_enable_monitoring(bool p_enable) { if (monitoring) { Physics2DServer::get_singleton()->area_set_monitor_callback(get_rid(),this,"_body_inout"); + Physics2DServer::get_singleton()->area_set_area_monitor_callback(get_rid(),this,"_area_inout"); } else { Physics2DServer::get_singleton()->area_set_monitor_callback(get_rid(),NULL,StringName()); + Physics2DServer::get_singleton()->area_set_area_monitor_callback(get_rid(),NULL,StringName()); _clear_monitoring(); } @@ -288,6 +432,26 @@ bool Area2D::is_monitoring_enabled() const { return monitoring; } +void Area2D::set_monitorable(bool p_enable) { + + if (locked) { + ERR_EXPLAIN("This function can't be used during the in/out signal."); + } + ERR_FAIL_COND(locked); + + if (p_enable==monitorable) + return; + + monitorable=p_enable; + + Physics2DServer::get_singleton()->area_set_monitorable(get_rid(),monitorable); +} + +bool Area2D::is_monitorable() const { + + return monitorable; +} + Array Area2D::get_overlapping_bodies() const { ERR_FAIL_COND_V(!monitoring,Array()); @@ -307,12 +471,33 @@ Array Area2D::get_overlapping_bodies() const { return ret; } +Array Area2D::get_overlapping_areas() const { + + ERR_FAIL_COND_V(!monitoring,Array()); + Array ret; + ret.resize(area_map.size()); + int idx=0; + for (const Map::Element *E=area_map.front();E;E=E->next()) { + Object *obj = ObjectDB::get_instance(E->key()); + if (!obj) { + ret.resize( ret.size() -1 ); //ops + } else { + ret[idx++]=obj; + } + + } + + return ret; +} void Area2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("_body_enter_tree","id"),&Area2D::_body_enter_tree); ObjectTypeDB::bind_method(_MD("_body_exit_tree","id"),&Area2D::_body_exit_tree); + ObjectTypeDB::bind_method(_MD("_area_enter_tree","id"),&Area2D::_area_enter_tree); + ObjectTypeDB::bind_method(_MD("_area_exit_tree","id"),&Area2D::_area_exit_tree); + ObjectTypeDB::bind_method(_MD("set_space_override_mode","enable"),&Area2D::set_space_override_mode); ObjectTypeDB::bind_method(_MD("get_space_override_mode"),&Area2D::get_space_override_mode); @@ -337,15 +522,26 @@ void Area2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_enable_monitoring","enable"),&Area2D::set_enable_monitoring); ObjectTypeDB::bind_method(_MD("is_monitoring_enabled"),&Area2D::is_monitoring_enabled); + ObjectTypeDB::bind_method(_MD("set_monitorable","enable"),&Area2D::set_monitorable); + ObjectTypeDB::bind_method(_MD("is_monitorable"),&Area2D::is_monitorable); + ObjectTypeDB::bind_method(_MD("get_overlapping_bodies"),&Area2D::get_overlapping_bodies); + ObjectTypeDB::bind_method(_MD("get_overlapping_areas"),&Area2D::get_overlapping_areas); ObjectTypeDB::bind_method(_MD("_body_inout"),&Area2D::_body_inout); + ObjectTypeDB::bind_method(_MD("_area_inout"),&Area2D::_area_inout); + + + ADD_SIGNAL( MethodInfo("body_enter_shape",PropertyInfo(Variant::INT,"body_id"),PropertyInfo(Variant::OBJECT,"body",PROPERTY_HINT_RESOURCE_TYPE,"PhysicsBody2D"),PropertyInfo(Variant::INT,"body_shape"),PropertyInfo(Variant::INT,"area_shape"))); + ADD_SIGNAL( MethodInfo("body_exit_shape",PropertyInfo(Variant::INT,"body_id"),PropertyInfo(Variant::OBJECT,"body",PROPERTY_HINT_RESOURCE_TYPE,"PhysicsBody2D"),PropertyInfo(Variant::INT,"body_shape"),PropertyInfo(Variant::INT,"area_shape"))); + ADD_SIGNAL( MethodInfo("body_enter:",PropertyInfo(Variant::OBJECT,"body",PROPERTY_HINT_RESOURCE_TYPE,"PhysicsBody2D"))); + ADD_SIGNAL( MethodInfo("body_exit",PropertyInfo(Variant::OBJECT,"body",PROPERTY_HINT_RESOURCE_TYPE,"PhysicsBody2D"))); + ADD_SIGNAL( MethodInfo("area_enter_shape",PropertyInfo(Variant::INT,"area_id"),PropertyInfo(Variant::OBJECT,"area",PROPERTY_HINT_RESOURCE_TYPE,"Area2D"),PropertyInfo(Variant::INT,"area_shape"),PropertyInfo(Variant::INT,"area_shape"))); + ADD_SIGNAL( MethodInfo("area_exit_shape",PropertyInfo(Variant::INT,"area_id"),PropertyInfo(Variant::OBJECT,"area",PROPERTY_HINT_RESOURCE_TYPE,"Area2D"),PropertyInfo(Variant::INT,"area_shape"),PropertyInfo(Variant::INT,"area_shape"))); + ADD_SIGNAL( MethodInfo("area_enter",PropertyInfo(Variant::OBJECT,"area",PROPERTY_HINT_RESOURCE_TYPE,"Area2D"))); + ADD_SIGNAL( MethodInfo("area_exit",PropertyInfo(Variant::OBJECT,"area",PROPERTY_HINT_RESOURCE_TYPE,"Area2D"))); - ADD_SIGNAL( MethodInfo("body_enter_shape",PropertyInfo(Variant::INT,"body_id"),PropertyInfo(Variant::OBJECT,"body"),PropertyInfo(Variant::INT,"body_shape"),PropertyInfo(Variant::INT,"area_shape"))); - ADD_SIGNAL( MethodInfo("body_exit_shape",PropertyInfo(Variant::INT,"body_id"),PropertyInfo(Variant::OBJECT,"body"),PropertyInfo(Variant::INT,"body_shape"),PropertyInfo(Variant::INT,"area_shape"))); - ADD_SIGNAL( MethodInfo("body_enter",PropertyInfo(Variant::OBJECT,"body"))); - ADD_SIGNAL( MethodInfo("body_exit",PropertyInfo(Variant::OBJECT,"body"))); ADD_PROPERTYNZ( PropertyInfo(Variant::INT,"space_override",PROPERTY_HINT_ENUM,"Disabled,Combine,Replace"),_SCS("set_space_override_mode"),_SCS("get_space_override_mode")); ADD_PROPERTY( PropertyInfo(Variant::BOOL,"gravity_point"),_SCS("set_gravity_is_point"),_SCS("is_gravity_a_point")); @@ -355,6 +551,7 @@ void Area2D::_bind_methods() { ADD_PROPERTY( PropertyInfo(Variant::REAL,"angular_damp",PROPERTY_HINT_RANGE,"0,1024,0.001"),_SCS("set_angular_damp"),_SCS("get_angular_damp")); ADD_PROPERTYNZ( PropertyInfo(Variant::INT,"priority",PROPERTY_HINT_RANGE,"0,128,1"),_SCS("set_priority"),_SCS("get_priority")); ADD_PROPERTY( PropertyInfo(Variant::BOOL,"monitoring"),_SCS("set_enable_monitoring"),_SCS("is_monitoring_enabled")); + ADD_PROPERTY( PropertyInfo(Variant::BOOL,"monitorable"),_SCS("set_monitorable"),_SCS("is_monitorable")); } @@ -369,7 +566,9 @@ Area2D::Area2D() : CollisionObject2D(Physics2DServer::get_singleton()->area_crea locked=false; priority=0; monitoring=false; + monitorable=false; set_enable_monitoring(true); + set_monitorable(true); } diff --git a/scene/2d/area_2d.h b/scene/2d/area_2d.h index f770e88a19..bd00f56ae1 100644 --- a/scene/2d/area_2d.h +++ b/scene/2d/area_2d.h @@ -53,6 +53,7 @@ private: real_t angular_damp; int priority; bool monitoring; + bool monitorable; bool locked; void _body_inout(int p_status,const RID& p_body, int p_instance, int p_body_shape,int p_area_shape); @@ -84,6 +85,36 @@ private: Map body_map; + + + void _area_inout(int p_status,const RID& p_area, int p_instance, int p_area_shape,int p_self_shape); + + void _area_enter_tree(ObjectID p_id); + void _area_exit_tree(ObjectID p_id); + + struct AreaShapePair { + + int area_shape; + int self_shape; + bool operator<(const AreaShapePair& p_sp) const { + if (area_shape==p_sp.area_shape) + return self_shape < p_sp.self_shape; + else + return area_shape < p_sp.area_shape; + } + + AreaShapePair() {} + AreaShapePair(int p_bs, int p_as) { area_shape=p_bs; self_shape=p_as; } + }; + + struct AreaState { + + int rc; + bool in_tree; + VSet shapes; + }; + + Map area_map; void _clear_monitoring(); @@ -117,7 +148,11 @@ public: void set_enable_monitoring(bool p_enable); bool is_monitoring_enabled() const; + void set_monitorable(bool p_enable); + bool is_monitorable() const; + Array get_overlapping_bodies() const; //function for script + Array get_overlapping_areas() const; //function for script Area2D(); diff --git a/scene/scene_string_names.cpp b/scene/scene_string_names.cpp index c30ff0044e..d4159f0946 100644 --- a/scene/scene_string_names.cpp +++ b/scene/scene_string_names.cpp @@ -64,6 +64,9 @@ SceneStringNames::SceneStringNames() { body_exit_shape = StaticCString::create("body_exit_shape"); body_exit = StaticCString::create("body_exit"); + area_enter_shape = StaticCString::create("area_enter_shape"); + area_exit_shape = StaticCString::create("area_exit_shape"); + idle=StaticCString::create("idle"); iteration=StaticCString::create("iteration"); @@ -103,6 +106,9 @@ SceneStringNames::SceneStringNames() { _body_enter_tree = StaticCString::create("_body_enter_tree"); _body_exit_tree = StaticCString::create("_body_exit_tree"); + _area_enter_tree = StaticCString::create("_area_enter_tree"); + _area_exit_tree = StaticCString::create("_area_exit_tree"); + _input_event=StaticCString::create("_input_event"); changed=StaticCString::create("changed"); diff --git a/scene/scene_string_names.h b/scene/scene_string_names.h index 184cbe347b..aa29ef57dc 100644 --- a/scene/scene_string_names.h +++ b/scene/scene_string_names.h @@ -83,6 +83,10 @@ public: StringName body_exit_shape; StringName body_exit; + StringName area_enter_shape; + StringName area_exit_shape; + + StringName _get_gizmo_geometry; StringName _can_gizmo_scale; @@ -124,6 +128,9 @@ public: StringName _body_enter_tree; StringName _body_exit_tree; + StringName _area_enter_tree; + StringName _area_exit_tree; + StringName changed; StringName _shader_changed; diff --git a/servers/physics_2d/area_2d_sw.cpp b/servers/physics_2d/area_2d_sw.cpp index 2e911288ae..65f3b80dd3 100644 --- a/servers/physics_2d/area_2d_sw.cpp +++ b/servers/physics_2d/area_2d_sw.cpp @@ -31,6 +31,7 @@ #include "body_2d_sw.h" Area2DSW::BodyKey::BodyKey(Body2DSW *p_body, uint32_t p_body_shape,uint32_t p_area_shape) { rid=p_body->get_self(); instance_id=p_body->get_instance_id(); body_shape=p_body_shape; area_shape=p_area_shape; } +Area2DSW::BodyKey::BodyKey(Area2DSW *p_body, uint32_t p_body_shape,uint32_t p_area_shape) { rid=p_body->get_self(); instance_id=p_body->get_instance_id(); body_shape=p_body_shape; area_shape=p_area_shape; } void Area2DSW::_shapes_changed() { @@ -57,6 +58,7 @@ void Area2DSW::set_space(Space2DSW *p_space) { } monitored_bodies.clear(); + monitored_areas.clear(); _set_space(p_space); } @@ -76,11 +78,31 @@ void Area2DSW::set_monitor_callback(ObjectID p_id, const StringName& p_method) { monitor_callback_method=p_method; monitored_bodies.clear(); + monitored_areas.clear(); _shape_changed(); } +void Area2DSW::set_area_monitor_callback(ObjectID p_id, const StringName& p_method) { + + + if (p_id==area_monitor_callback_id) { + area_monitor_callback_method=p_method; + return; + } + + _unregister_shapes(); + + area_monitor_callback_id=p_id; + area_monitor_callback_method=p_method; + + monitored_bodies.clear(); + monitored_areas.clear(); + + _shape_changed(); + +} void Area2DSW::set_space_override_mode(Physics2DServer::AreaSpaceOverrideMode p_mode) { @@ -134,6 +156,15 @@ void Area2DSW::_queue_monitor_update() { } +void Area2DSW::set_monitorable(bool p_monitorable) { + + if (monitorable==p_monitorable) + return; + + monitorable=p_monitorable; + _set_static(!monitorable); +} + void Area2DSW::call_queries() { if (monitor_callback_id && !monitored_bodies.empty()) { @@ -170,13 +201,49 @@ void Area2DSW::call_queries() { monitored_bodies.clear(); + if (area_monitor_callback_id && !monitored_areas.empty()) { + + + Variant res[5]; + Variant *resptr[5]; + for(int i=0;i<5;i++) + resptr[i]=&res[i]; + + Object *obj = ObjectDB::get_instance(area_monitor_callback_id); + if (!obj) { + monitored_areas.clear(); + area_monitor_callback_id=0; + return; + } + + + + for (Map::Element *E=monitored_areas.front();E;E=E->next()) { + + if (E->get().state==0) + continue; //nothing happened + + res[0]=E->get().state>0 ? Physics2DServer::AREA_BODY_ADDED : Physics2DServer::AREA_BODY_REMOVED; + res[1]=E->key().rid; + res[2]=E->key().instance_id; + res[3]=E->key().body_shape; + res[4]=E->key().area_shape; + + + Variant::CallError ce; + obj->call(area_monitor_callback_method,(const Variant**)resptr,5,ce); + } + } + + monitored_areas.clear(); + //get_space()->area_remove_from_monitor_query_list(&monitor_query_list); } Area2DSW::Area2DSW() : CollisionObject2DSW(TYPE_AREA), monitor_query_list(this), moved_list(this) { - _set_static(true); //areas are never active + _set_static(true); //areas are not active by default space_override_mode=Physics2DServer::AREA_SPACE_OVERRIDE_DISABLED; gravity=9.80665; gravity_vector=Vector2(0,-1); @@ -187,6 +254,8 @@ Area2DSW::Area2DSW() : CollisionObject2DSW(TYPE_AREA), monitor_query_list(this), linear_damp=0.1; priority=0; monitor_callback_id=0; + area_monitor_callback_id=0; + monitorable=false; } diff --git a/servers/physics_2d/area_2d_sw.h b/servers/physics_2d/area_2d_sw.h index d94b2f9ccf..26b7b2516c 100644 --- a/servers/physics_2d/area_2d_sw.h +++ b/servers/physics_2d/area_2d_sw.h @@ -50,10 +50,14 @@ class Area2DSW : public CollisionObject2DSW{ float linear_damp; float angular_damp; int priority; + bool monitorable; ObjectID monitor_callback_id; StringName monitor_callback_method; + ObjectID area_monitor_callback_id; + StringName area_monitor_callback_method; + SelfList monitor_query_list; SelfList moved_list; @@ -80,6 +84,7 @@ class Area2DSW : public CollisionObject2DSW{ _FORCE_INLINE_ BodyKey() {} BodyKey(Body2DSW *p_body, uint32_t p_body_shape,uint32_t p_area_shape); + BodyKey(Area2DSW *p_body, uint32_t p_body_shape,uint32_t p_area_shape); }; struct BodyState { @@ -91,6 +96,7 @@ class Area2DSW : public CollisionObject2DSW{ }; Map monitored_bodies; + Map monitored_areas; //virtual void shape_changed_notify(Shape2DSW *p_shape); //virtual void shape_deleted_notify(Shape2DSW *p_shape); @@ -108,9 +114,16 @@ public: void set_monitor_callback(ObjectID p_id, const StringName& p_method); _FORCE_INLINE_ bool has_monitor_callback() const { return monitor_callback_id; } + void set_area_monitor_callback(ObjectID p_id, const StringName& p_method); + _FORCE_INLINE_ bool has_area_monitor_callback() const { return area_monitor_callback_id; } + + _FORCE_INLINE_ void add_body_to_query(Body2DSW *p_body, uint32_t p_body_shape,uint32_t p_area_shape); _FORCE_INLINE_ void remove_body_from_query(Body2DSW *p_body, uint32_t p_body_shape,uint32_t p_area_shape); + _FORCE_INLINE_ void add_area_to_query(Area2DSW *p_area, uint32_t p_area_shape,uint32_t p_self_shape); + _FORCE_INLINE_ void remove_area_from_query(Area2DSW *p_area, uint32_t p_area_shape,uint32_t p_self_shape); + void set_param(Physics2DServer::AreaParameter p_param, const Variant& p_value); Variant get_param(Physics2DServer::AreaParameter p_param) const; @@ -142,6 +155,9 @@ public: _FORCE_INLINE_ void remove_constraint( Constraint2DSW* p_constraint) { constraints.erase(p_constraint); } _FORCE_INLINE_ const Set& get_constraints() const { return constraints; } + void set_monitorable(bool p_monitorable); + _FORCE_INLINE_ bool is_monitorable() const { return monitorable; } + void set_transform(const Matrix32& p_transform); void set_space(Space2DSW *p_space); @@ -168,6 +184,24 @@ void Area2DSW::remove_body_from_query(Body2DSW *p_body, uint32_t p_body_shape,ui _queue_monitor_update(); } +void Area2DSW::add_area_to_query(Area2DSW *p_area, uint32_t p_area_shape,uint32_t p_self_shape) { + + + BodyKey bk(p_area,p_area_shape,p_self_shape); + monitored_areas[bk].inc(); + if (!monitor_query_list.in_list()) + _queue_monitor_update(); + + +} +void Area2DSW::remove_area_from_query(Area2DSW *p_area, uint32_t p_area_shape,uint32_t p_self_shape) { + + + BodyKey bk(p_area,p_area_shape,p_self_shape); + monitored_areas[bk].dec(); + if (!monitor_query_list.in_list()) + _queue_monitor_update(); +} diff --git a/servers/physics_2d/area_pair_2d_sw.cpp b/servers/physics_2d/area_pair_2d_sw.cpp index 1c7f73db5e..ed2e34c972 100644 --- a/servers/physics_2d/area_pair_2d_sw.cpp +++ b/servers/physics_2d/area_pair_2d_sw.cpp @@ -94,3 +94,72 @@ AreaPair2DSW::~AreaPair2DSW() { body->remove_constraint(this); area->remove_constraint(this); } + + +////////////////////////////////// + + + +bool Area2Pair2DSW::setup(float p_step) { + + bool result = CollisionSolver2DSW::solve(area_a->get_shape(shape_a),area_a->get_transform() * area_a->get_shape_transform(shape_a),Vector2(),area_b->get_shape(shape_b),area_b->get_transform() * area_b->get_shape_transform(shape_b),Vector2(),NULL,this); + + if (result!=colliding) { + + if (result) { + + if (area_b->has_area_monitor_callback() && area_a->is_monitorable()) + area_b->add_area_to_query(area_a,shape_a,shape_b); + + if (area_a->has_area_monitor_callback() && area_b->is_monitorable()) + area_a->add_area_to_query(area_b,shape_b,shape_a); + + } else { + + if (area_b->has_area_monitor_callback() && area_a->is_monitorable()) + area_b->remove_area_from_query(area_a,shape_a,shape_b); + + if (area_a->has_area_monitor_callback() && area_b->is_monitorable()) + area_a->remove_area_from_query(area_b,shape_b,shape_a); + } + + colliding=result; + + } + + return false; //never do any post solving +} + +void Area2Pair2DSW::solve(float p_step) { + + +} + + +Area2Pair2DSW::Area2Pair2DSW(Area2DSW *p_area_a,int p_shape_a, Area2DSW *p_area_b,int p_shape_b) { + + + area_a=p_area_a; + area_b=p_area_b; + shape_a=p_shape_a; + shape_b=p_shape_b; + colliding=false; + area_a->add_constraint(this); + area_b->add_constraint(this); + +} + +Area2Pair2DSW::~Area2Pair2DSW() { + + if (colliding) { + + if (area_b->has_area_monitor_callback() && area_a->is_monitorable()) + area_b->remove_area_from_query(area_a,shape_a,shape_b); + + if (area_a->has_area_monitor_callback() && area_b->is_monitorable()) + area_a->remove_area_from_query(area_b,shape_b,shape_a); + } + + area_a->remove_constraint(this); + area_b->remove_constraint(this); +} diff --git a/servers/physics_2d/area_pair_2d_sw.h b/servers/physics_2d/area_pair_2d_sw.h index 5dad8c7a12..575490b109 100644 --- a/servers/physics_2d/area_pair_2d_sw.h +++ b/servers/physics_2d/area_pair_2d_sw.h @@ -49,5 +49,23 @@ public: ~AreaPair2DSW(); }; + +class Area2Pair2DSW : public Constraint2DSW { + + Area2DSW *area_a; + Area2DSW *area_b; + int shape_a; + int shape_b; + bool colliding; +public: + + bool setup(float p_step); + void solve(float p_step); + + Area2Pair2DSW(Area2DSW *p_area_a,int p_shape_a, Area2DSW *p_area_b,int p_shape_b); + ~Area2Pair2DSW(); +}; + + #endif // AREA_PAIR_2D_SW_H diff --git a/servers/physics_2d/physics_2d_server_sw.cpp b/servers/physics_2d/physics_2d_server_sw.cpp index be49955055..0a02a9568a 100644 --- a/servers/physics_2d/physics_2d_server_sw.cpp +++ b/servers/physics_2d/physics_2d_server_sw.cpp @@ -463,6 +463,16 @@ Matrix32 Physics2DServerSW::area_get_transform(RID p_area) const { return area->get_transform(); }; +void Physics2DServerSW::area_set_monitorable(RID p_area,bool p_monitorable) { + + Area2DSW *area = area_owner.get(p_area); + ERR_FAIL_COND(!area); + + area->set_monitorable(p_monitorable); + +} + + void Physics2DServerSW::area_set_monitor_callback(RID p_area,Object *p_receiver,const StringName& p_method) { Area2DSW *area = area_owner.get(p_area); @@ -473,6 +483,14 @@ void Physics2DServerSW::area_set_monitor_callback(RID p_area,Object *p_receiver, } +void Physics2DServerSW::area_set_area_monitor_callback(RID p_area,Object *p_receiver,const StringName& p_method) { + + + Area2DSW *area = area_owner.get(p_area); + ERR_FAIL_COND(!area); + + area->set_area_monitor_callback(p_receiver?p_receiver->get_instance_ID():0,p_method); +} /* BODY API */ diff --git a/servers/physics_2d/physics_2d_server_sw.h b/servers/physics_2d/physics_2d_server_sw.h index e9c499aaff..eba5845e5b 100644 --- a/servers/physics_2d/physics_2d_server_sw.h +++ b/servers/physics_2d/physics_2d_server_sw.h @@ -133,9 +133,10 @@ public: virtual Variant area_get_param(RID p_parea,AreaParameter p_param) const; virtual Matrix32 area_get_transform(RID p_area) const; + virtual void area_set_monitorable(RID p_area,bool p_monitorable); virtual void area_set_monitor_callback(RID p_area,Object *p_receiver,const StringName& p_method); - + virtual void area_set_area_monitor_callback(RID p_area,Object *p_receiver,const StringName& p_method); /* BODY API */ diff --git a/servers/physics_2d/space_2d_sw.cpp b/servers/physics_2d/space_2d_sw.cpp index f2ed74ffbf..9523e8bf8a 100644 --- a/servers/physics_2d/space_2d_sw.cpp +++ b/servers/physics_2d/space_2d_sw.cpp @@ -527,13 +527,20 @@ void* Space2DSW::_broadphase_pair(CollisionObject2DSW *A,int p_subindex_A,Collis if (type_A==CollisionObject2DSW::TYPE_AREA) { - ERR_FAIL_COND_V(type_B!=CollisionObject2DSW::TYPE_BODY,NULL); Area2DSW *area=static_cast(A); - Body2DSW *body=static_cast(B); + if (type_B==CollisionObject2DSW::TYPE_AREA) { + + Area2DSW *area_b=static_cast(B); + Area2Pair2DSW *area2_pair = memnew(Area2Pair2DSW(area_b,p_subindex_B,area,p_subindex_A) ); + return area2_pair; + } else { + + Body2DSW *body=static_cast(B); + AreaPair2DSW *area_pair = memnew(AreaPair2DSW(body,p_subindex_B,area,p_subindex_A) ); + return area_pair; + } - AreaPair2DSW *area_pair = memnew(AreaPair2DSW(body,p_subindex_B,area,p_subindex_A) ); - return area_pair; } else { diff --git a/servers/physics_2d_server.h b/servers/physics_2d_server.h index 765cebf45f..1fb47fc1d9 100644 --- a/servers/physics_2d_server.h +++ b/servers/physics_2d_server.h @@ -341,7 +341,10 @@ public: virtual Variant area_get_param(RID p_parea,AreaParameter p_param) const=0; virtual Matrix32 area_get_transform(RID p_area) const=0; + virtual void area_set_monitorable(RID p_area,bool p_monitorable)=0; + virtual void area_set_monitor_callback(RID p_area,Object *p_receiver,const StringName& p_method)=0; + virtual void area_set_area_monitor_callback(RID p_area,Object *p_receiver,const StringName& p_method)=0; /* BODY API */ diff --git a/tools/editor/connections_dialog.cpp b/tools/editor/connections_dialog.cpp index d7158eb7e9..cf4b21510a 100644 --- a/tools/editor/connections_dialog.cpp +++ b/tools/editor/connections_dialog.cpp @@ -607,6 +607,14 @@ void ConnectionsDialog::_remove_confirm() { } */ + +struct _ConnectionsDialogMethodInfoSort { + + _FORCE_INLINE_ bool operator()(const MethodInfo& a, const MethodInfo& b) const { + return a.name < b.name; + } +}; + void ConnectionsDialog::update_tree() { if (!is_visible()) @@ -623,7 +631,8 @@ void ConnectionsDialog::update_tree() { node->get_signal_list(&node_signals); - + //node_signals.sort_custom<_ConnectionsDialogMethodInfoSort>(); + for(List::Element *E=node_signals.front();E;E=E->next()) { -- cgit v1.2.3 From 4cac1e0cb6406609b915797ca41ad125f9b3da08 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Tue, 17 Mar 2015 09:25:35 -0300 Subject: add functions to test overlap with another body or area --- scene/2d/area_2d.cpp | 26 ++++++++++++++++++++++++++ scene/2d/area_2d.h | 2 ++ 2 files changed, 28 insertions(+) diff --git a/scene/2d/area_2d.cpp b/scene/2d/area_2d.cpp index b972ddfa3c..03702d8a13 100644 --- a/scene/2d/area_2d.cpp +++ b/scene/2d/area_2d.cpp @@ -490,6 +490,29 @@ Array Area2D::get_overlapping_areas() const { return ret; } +bool Area2D::overlaps_area(Node* p_area) const { + + ERR_FAIL_NULL_V(p_area,false); + const Map::Element *E=area_map.find(p_area->get_instance_ID()); + if (!E) + return false; + return E->get().in_tree; + + + +} + +bool Area2D::overlaps_body(Node* p_body) const{ + + ERR_FAIL_NULL_V(p_body,false); + const Map::Element *E=body_map.find(p_body->get_instance_ID()); + if (!E) + return false; + return E->get().in_tree; + +} + + void Area2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("_body_enter_tree","id"),&Area2D::_body_enter_tree); @@ -528,6 +551,9 @@ void Area2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_overlapping_bodies"),&Area2D::get_overlapping_bodies); ObjectTypeDB::bind_method(_MD("get_overlapping_areas"),&Area2D::get_overlapping_areas); + ObjectTypeDB::bind_method(_MD("overlaps_body:PhysicsBody2D","body"),&Area2D::overlaps_body); + ObjectTypeDB::bind_method(_MD("overlaps_area:Area2D","area"),&Area2D::overlaps_area); + ObjectTypeDB::bind_method(_MD("_body_inout"),&Area2D::_body_inout); ObjectTypeDB::bind_method(_MD("_area_inout"),&Area2D::_area_inout); diff --git a/scene/2d/area_2d.h b/scene/2d/area_2d.h index bd00f56ae1..6a6c757e0c 100644 --- a/scene/2d/area_2d.h +++ b/scene/2d/area_2d.h @@ -154,6 +154,8 @@ public: Array get_overlapping_bodies() const; //function for script Array get_overlapping_areas() const; //function for script + bool overlaps_area(Node* p_area) const; + bool overlaps_body(Node* p_body) const; Area2D(); ~Area2D(); -- cgit v1.2.3 From 9dd0d8277d0c2336bbd61b1afff51a0ce6e11717 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Wed, 18 Mar 2015 21:03:11 -0300 Subject: add overlap test function, remove a semicolon --- scene/2d/area_2d.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scene/2d/area_2d.cpp b/scene/2d/area_2d.cpp index 03702d8a13..a5c455ce64 100644 --- a/scene/2d/area_2d.cpp +++ b/scene/2d/area_2d.cpp @@ -560,7 +560,7 @@ void Area2D::_bind_methods() { ADD_SIGNAL( MethodInfo("body_enter_shape",PropertyInfo(Variant::INT,"body_id"),PropertyInfo(Variant::OBJECT,"body",PROPERTY_HINT_RESOURCE_TYPE,"PhysicsBody2D"),PropertyInfo(Variant::INT,"body_shape"),PropertyInfo(Variant::INT,"area_shape"))); ADD_SIGNAL( MethodInfo("body_exit_shape",PropertyInfo(Variant::INT,"body_id"),PropertyInfo(Variant::OBJECT,"body",PROPERTY_HINT_RESOURCE_TYPE,"PhysicsBody2D"),PropertyInfo(Variant::INT,"body_shape"),PropertyInfo(Variant::INT,"area_shape"))); - ADD_SIGNAL( MethodInfo("body_enter:",PropertyInfo(Variant::OBJECT,"body",PROPERTY_HINT_RESOURCE_TYPE,"PhysicsBody2D"))); + ADD_SIGNAL( MethodInfo("body_enter",PropertyInfo(Variant::OBJECT,"body",PROPERTY_HINT_RESOURCE_TYPE,"PhysicsBody2D"))); ADD_SIGNAL( MethodInfo("body_exit",PropertyInfo(Variant::OBJECT,"body",PROPERTY_HINT_RESOURCE_TYPE,"PhysicsBody2D"))); ADD_SIGNAL( MethodInfo("area_enter_shape",PropertyInfo(Variant::INT,"area_id"),PropertyInfo(Variant::OBJECT,"area",PROPERTY_HINT_RESOURCE_TYPE,"Area2D"),PropertyInfo(Variant::INT,"area_shape"),PropertyInfo(Variant::INT,"area_shape"))); -- cgit v1.2.3 From 90a84b4ddb64f4adc024766435f3fc75605f9aab Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Fri, 20 Mar 2015 00:26:01 -0300 Subject: wip distance field font import font import may not work if using distance field, this is WIP --- .../io_plugins/editor_font_import_plugin.cpp | 347 ++++++++++++++++++--- 1 file changed, 297 insertions(+), 50 deletions(-) diff --git a/tools/editor/io_plugins/editor_font_import_plugin.cpp b/tools/editor/io_plugins/editor_font_import_plugin.cpp index 1fd7d26f8b..05a42218a2 100644 --- a/tools/editor/io_plugins/editor_font_import_plugin.cpp +++ b/tools/editor/io_plugins/editor_font_import_plugin.cpp @@ -47,6 +47,12 @@ class _EditorFontImportOptions : public Object { OBJ_TYPE(_EditorFontImportOptions,Object); public: + enum FontMode { + + FONT_BITMAP, + FONT_DISTANCE_FIELD + }; + enum ColorType { COLOR_WHITE, COLOR_CUSTOM, @@ -69,6 +75,9 @@ public: CHARSET_CUSTOM_LATIN }; + + FontMode font_mode; + CharacterSet character_set; String custom_file; @@ -91,7 +100,6 @@ public: bool color_use_monochrome; String gradient_image; - bool disable_filter; bool round_advance; @@ -100,7 +108,10 @@ public: bool _set(const StringName& p_name, const Variant& p_value) { String n = p_name; - if (n=="extra_space/char") + if (n=="mode/mode") { + font_mode=FontMode(int(p_value)); + _change_notify(); + } else if (n=="extra_space/char") char_extra_spacing=p_value; else if (n=="extra_space/space") space_extra_spacing=p_value; @@ -169,7 +180,9 @@ public: bool _get(const StringName& p_name,Variant &r_ret) const{ String n = p_name; - if (n=="extra_space/char") + if (n=="mode/mode") + r_ret=font_mode; + else if (n=="extra_space/char") r_ret=char_extra_spacing; else if (n=="extra_space/space") r_ret=space_extra_spacing; @@ -231,6 +244,9 @@ public: void _get_property_list( List *p_list) const{ + + p_list->push_back(PropertyInfo(Variant::INT,"mode/mode",PROPERTY_HINT_ENUM,"Bitmap,Distance Field")); + p_list->push_back(PropertyInfo(Variant::INT,"extra_space/char",PROPERTY_HINT_RANGE,"-64,64,1")); p_list->push_back(PropertyInfo(Variant::INT,"extra_space/space",PROPERTY_HINT_RANGE,"-64,64,1")); p_list->push_back(PropertyInfo(Variant::INT,"extra_space/top",PROPERTY_HINT_RANGE,"-64,64,1")); @@ -240,35 +256,45 @@ public: if (character_set>=CHARSET_CUSTOM) p_list->push_back(PropertyInfo(Variant::STRING,"character_set/custom",PROPERTY_HINT_FILE)); - p_list->push_back(PropertyInfo(Variant::BOOL,"shadow/enabled")); - if (shadow) { - p_list->push_back(PropertyInfo(Variant::INT,"shadow/radius",PROPERTY_HINT_RANGE,"-64,64,1")); - p_list->push_back(PropertyInfo(Variant::VECTOR2,"shadow/offset")); - p_list->push_back(PropertyInfo(Variant::COLOR,"shadow/color")); - p_list->push_back(PropertyInfo(Variant::REAL,"shadow/transition",PROPERTY_HINT_EXP_EASING)); - } + int usage = PROPERTY_USAGE_DEFAULT; - p_list->push_back(PropertyInfo(Variant::BOOL,"shadow2/enabled")); - if (shadow2) { - p_list->push_back(PropertyInfo(Variant::INT,"shadow2/radius",PROPERTY_HINT_RANGE,"-64,64,1")); - p_list->push_back(PropertyInfo(Variant::VECTOR2,"shadow2/offset")); - p_list->push_back(PropertyInfo(Variant::COLOR,"shadow2/color")); - p_list->push_back(PropertyInfo(Variant::REAL,"shadow2/transition",PROPERTY_HINT_EXP_EASING)); + if (font_mode==FONT_DISTANCE_FIELD) { + usage = PROPERTY_USAGE_NOEDITOR; } - p_list->push_back(PropertyInfo(Variant::INT,"color/mode",PROPERTY_HINT_ENUM,"White,Color,Gradient,Gradient Image")); - if (color_type==COLOR_CUSTOM) { - p_list->push_back(PropertyInfo(Variant::COLOR,"color/color")); + { + p_list->push_back(PropertyInfo(Variant::BOOL,"shadow/enabled",PROPERTY_HINT_NONE,"",usage)); + if (shadow) { + p_list->push_back(PropertyInfo(Variant::INT,"shadow/radius",PROPERTY_HINT_RANGE,"-64,64,1",usage)); + p_list->push_back(PropertyInfo(Variant::VECTOR2,"shadow/offset",PROPERTY_HINT_NONE,"",usage)); + p_list->push_back(PropertyInfo(Variant::COLOR,"shadow/color",PROPERTY_HINT_NONE,"",usage)); + p_list->push_back(PropertyInfo(Variant::REAL,"shadow/transition",PROPERTY_HINT_EXP_EASING,"",usage)); + } + + p_list->push_back(PropertyInfo(Variant::BOOL,"shadow2/enabled",PROPERTY_HINT_NONE,"",usage)); + if (shadow2) { + p_list->push_back(PropertyInfo(Variant::INT,"shadow2/radius",PROPERTY_HINT_RANGE,"-64,64,1",usage)); + p_list->push_back(PropertyInfo(Variant::VECTOR2,"shadow2/offset",PROPERTY_HINT_NONE,"",usage)); + p_list->push_back(PropertyInfo(Variant::COLOR,"shadow2/color",PROPERTY_HINT_NONE,"",usage)); + p_list->push_back(PropertyInfo(Variant::REAL,"shadow2/transition",PROPERTY_HINT_EXP_EASING,"",usage)); + } + + p_list->push_back(PropertyInfo(Variant::INT,"color/mode",PROPERTY_HINT_ENUM,"White,Color,Gradient,Gradient Image",usage)); + if (color_type==COLOR_CUSTOM) { + p_list->push_back(PropertyInfo(Variant::COLOR,"color/color",PROPERTY_HINT_NONE,"",usage)); + + } + if (color_type==COLOR_GRADIENT_RANGE) { + p_list->push_back(PropertyInfo(Variant::COLOR,"color/begin",PROPERTY_HINT_NONE,"",usage)); + p_list->push_back(PropertyInfo(Variant::COLOR,"color/end",PROPERTY_HINT_NONE,"",usage)); + } + if (color_type==COLOR_GRADIENT_IMAGE) { + p_list->push_back(PropertyInfo(Variant::STRING,"color/image",PROPERTY_HINT_FILE,"",usage)); + } + p_list->push_back(PropertyInfo(Variant::BOOL,"color/monochrome",PROPERTY_HINT_NONE,"",usage)); } - if (color_type==COLOR_GRADIENT_RANGE) { - p_list->push_back(PropertyInfo(Variant::COLOR,"color/begin")); - p_list->push_back(PropertyInfo(Variant::COLOR,"color/end")); - } - if (color_type==COLOR_GRADIENT_IMAGE) { - p_list->push_back(PropertyInfo(Variant::STRING,"color/image",PROPERTY_HINT_FILE)); - } - p_list->push_back(PropertyInfo(Variant::BOOL,"color/monochrome")); + p_list->push_back(PropertyInfo(Variant::BOOL,"advanced/round_advance")); p_list->push_back(PropertyInfo(Variant::BOOL,"advanced/disable_filter")); @@ -307,6 +333,7 @@ public: gradient_end=Color(0.5,0.5,0.5,1); color_use_monochrome=false; + font_mode=FONT_BITMAP; round_advance=true; disable_filter=false; @@ -314,6 +341,8 @@ public: _EditorFontImportOptions() { + font_mode=FONT_BITMAP; + char_extra_spacing=0; top_extra_spacing=0; bottom_extra_spacing=0; @@ -706,6 +735,137 @@ struct _EditorKerningKey { }; + +static unsigned char get_SDF_radial( + unsigned char *fontmap, + int w, int h, + int x, int y, + int max_radius ) +{ + // hideous brute force method + float d2 = max_radius*max_radius+1.0; + unsigned char v = fontmap[x+y*w]; + for( int radius = 1; (radius <= max_radius) && (radius*radius < d2); ++radius ) + { + int line, lo, hi; + // north + line = y - radius; + if( (line >= 0) && (line < h) ) + { + lo = x - radius; + hi = x + radius; + if( lo < 0 ) { lo = 0; } + if( hi >= w ) { hi = w-1; } + int idx = line * w + lo; + for( int i = lo; i <= hi; ++i ) + { + // check this pixel + if( fontmap[idx] != v ) + { + float nx = i - x; + float ny = line - y; + float nd2 = nx*nx+ny*ny; + if( nd2 < d2 ) + { + d2 = nd2; + } + } + // move on + ++idx; + } + } + // south + line = y + radius; + if( (line >= 0) && (line < h) ) + { + lo = x - radius; + hi = x + radius; + if( lo < 0 ) { lo = 0; } + if( hi >= w ) { hi = w-1; } + int idx = line * w + lo; + for( int i = lo; i <= hi; ++i ) + { + // check this pixel + if( fontmap[idx] != v ) + { + float nx = i - x; + float ny = line - y; + float nd2 = nx*nx+ny*ny; + if( nd2 < d2 ) + { + d2 = nd2; + } + } + // move on + ++idx; + } + } + // west + line = x - radius; + if( (line >= 0) && (line < w) ) + { + lo = y - radius + 1; + hi = y + radius - 1; + if( lo < 0 ) { lo = 0; } + if( hi >= h ) { hi = h-1; } + int idx = lo * w + line; + for( int i = lo; i <= hi; ++i ) + { + // check this pixel + if( fontmap[idx] != v ) + { + float nx = line - x; + float ny = i - y; + float nd2 = nx*nx+ny*ny; + if( nd2 < d2 ) + { + d2 = nd2; + } + } + // move on + idx += w; + } + } + // east + line = x + radius; + if( (line >= 0) && (line < w) ) + { + lo = y - radius + 1; + hi = y + radius - 1; + if( lo < 0 ) { lo = 0; } + if( hi >= h ) { hi = h-1; } + int idx = lo * w + line; + for( int i = lo; i <= hi; ++i ) + { + // check this pixel + if( fontmap[idx] != v ) + { + float nx = line - x; + float ny = i - y; + float nd2 = nx*nx+ny*ny; + if( nd2 < d2 ) + { + d2 = nd2; + } + } + // move on + idx += w; + } + } + } + d2 = sqrtf( d2 ); + if( v==0 ) + { + d2 = -d2; + } + d2 *= 127.5 / max_radius; + d2 += 127.5; + if( d2 < 0.0 ) d2 = 0.0; + if( d2 > 255.0 ) d2 = 255.0; + return (unsigned char)(d2 + 0.5); +} + + Ref EditorFontImportPlugin::generate_font(const Ref& p_from, const String &p_existing) { Ref from = p_from; @@ -754,7 +914,11 @@ Ref EditorFontImportPlugin::generate_font(const Refget_option("mode/mode"); + + int scaler=(font_mode==_EditorFontImportOptions::FONT_DISTANCE_FIELD)?16:1; + + error = FT_Set_Pixel_Sizes(face,0,size*scaler); FT_GlyphSlot slot = face->glyph; @@ -822,7 +986,7 @@ Ref EditorFontImportPlugin::generate_font(const Refglyph, ft_render_mode_normal ); + else error = FT_Render_Glyph( face->glyph, font_mode==_EditorFontImportOptions::FONT_BITMAP?ft_render_mode_normal:ft_render_mode_mono ); if (error) { skip=true; } else if (!skip) { @@ -847,28 +1011,35 @@ Ref EditorFontImportPlugin::generate_font(const Refbitmap.resize( slot->bitmap.width*slot->bitmap.rows ); - fdata->width=slot->bitmap.width; - fdata->height=slot->bitmap.rows; - fdata->character=charcode; - fdata->glyph=FT_Get_Char_Index(face,charcode); - if (charcode=='x') - xsize=slot->bitmap.width; - if (charcode<127) { - if (slot->bitmap_top>max_up) { - - max_up=slot->bitmap_top; - } + int w = slot->bitmap.width; + int h = slot->bitmap.rows; + int p = slot->bitmap.pitch; + print_line("pitch "+itos(slot->bitmap.pitch)); + if (font_mode==_EditorFontImportOptions::FONT_DISTANCE_FIELD) { - if ( (slot->bitmap_top - fdata->height)bitmap_top - fdata->height; - } + fdata->width=sdfw; + fdata->height=sdfh; + } else { + fdata->width=w; + fdata->height=h; } + fdata->character=charcode; + fdata->glyph=FT_Get_Char_Index(face,charcode); + if (charcode=='x') + xsize=w/scaler; + + fdata->valign=slot->bitmap_top; fdata->halign=slot->bitmap_left; @@ -878,12 +1049,87 @@ Ref EditorFontImportPlugin::generate_font(const Refadvance=slot->advance.x/float(1<<6); + fdata->advance/=scaler; + + if (font_mode==_EditorFontImportOptions::FONT_DISTANCE_FIELD) { + + fdata->halign = fdata->halign / scaler - 1.5; + fdata->valign = fdata->valign / scaler + 1.5; + fdata->advance/=scaler; + + } + fdata->advance+=font_spacing; - for (int i=0;ibitmap.width;i++) { - for (int j=0;jbitmap.rows;j++) { - fdata->bitmap[j*slot->bitmap.width+i]=slot->bitmap.buffer[j*slot->bitmap.width+i]; + if (charcode<127) { + int top = fdata->valign; + int hmax = h/scaler; + + if (top>max_up) { + + max_up=top; + } + + + if ( (top - hmax)bitmap.buffer; + for( int j = 0; j < h; ++j ) { + for( int i = 0; i < w; ++i ) { + smooth_buf[scaler*2+i+(j+scaler*2)*sw] = 255 * ((buf[j*p+(i>>3)] >> (7 - (i & 7))) & 1); + } + } + + // do the SDF + int sdfw = fdata->width; + int sdfh = fdata->height; + + fdata->bitmap.resize( sdfw*sdfh ); + + for( int j = 0; j < sdfh; ++j ) { + for( int i = 0; i < sdfw; ++i ) { + int pd_idx = j*sdfw+i; + + //fdata->bitmap[j*slot->bitmap.width+i]=slot->bitmap.buffer[j*slot->bitmap.width+i]; + + fdata->bitmap[pd_idx] = + //get_SDF + get_SDF_radial + ( smooth_buf, sw, sh, + i*scaler + (scaler >>1), j*scaler + (scaler >>1), + 2*scaler ); + + } + } + + delete [] smooth_buf; + + } else { + fdata->bitmap.resize( slot->bitmap.width*slot->bitmap.rows ); + for (int i=0;ibitmap.width;i++) { + for (int j=0;jbitmap.rows;j++) { + + fdata->bitmap[j*slot->bitmap.width+i]=slot->bitmap.buffer[j*slot->bitmap.width+i]; + } } } @@ -907,6 +1153,7 @@ Ref EditorFontImportPlugin::generate_font(const Refglyph, ft_render_mode_normal )) { spd->advance = slot->advance.x>>6; //round to nearest or store as float + spd->advance/=scaler; spd->advance+=font_spacing; } else { @@ -955,7 +1202,7 @@ Ref EditorFontImportPlugin::generate_font(const Ref EditorFontImportPlugin::generate_font(const Ref::Write w = pixels.write(); - print_line("val: "+itos(font_data_list[i]->valign)); + //print_line("val: "+itos(font_data_list[i]->valign)); for(int y=0;yvalign,0,height-1); @@ -1251,7 +1498,7 @@ Ref EditorFontImportPlugin::generate_font(const Ref atlast = memnew( ImageTexture ); atlast->create_from_image(atlas); -- cgit v1.2.3 From acc6f3b285f058104fd6431bed2c4cfe4dc05a58 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sat, 21 Mar 2015 00:43:33 -0300 Subject: signed distance field font support --- drivers/gles2/rasterizer_gles2.cpp | 12 ++++++++++++ drivers/gles2/shaders/canvas.glsl | 10 +++++++++- scene/gui/label.cpp | 4 +++- scene/resources/font.cpp | 17 +++++++++++++++++ scene/resources/font.h | 4 ++++ servers/visual/rasterizer.h | 3 ++- servers/visual/visual_server_raster.cpp | 8 ++++++++ servers/visual/visual_server_raster.h | 1 + servers/visual/visual_server_wrap_mt.h | 1 + servers/visual_server.h | 1 + tools/editor/io_plugins/editor_font_import_plugin.cpp | 12 ++++++------ 11 files changed, 64 insertions(+), 9 deletions(-) diff --git a/drivers/gles2/rasterizer_gles2.cpp b/drivers/gles2/rasterizer_gles2.cpp index a21b0775e9..05c977f344 100644 --- a/drivers/gles2/rasterizer_gles2.cpp +++ b/drivers/gles2/rasterizer_gles2.cpp @@ -9127,8 +9127,10 @@ void RasterizerGLES2::canvas_render_items(CanvasItem *p_item_list,int p_z,const canvas_use_modulate=p_modulate!=Color(1,1,1,1); canvas_modulate=p_modulate; canvas_shader.set_conditional(CanvasShaderGLES2::USE_MODULATE,canvas_use_modulate); + canvas_shader.set_conditional(CanvasShaderGLES2::USE_DISTANCE_FIELD,false); bool reset_modulate=false; + bool prev_distance_field=false; while(p_item_list) { @@ -9144,12 +9146,22 @@ void RasterizerGLES2::canvas_render_items(CanvasItem *p_item_list,int p_z,const canvas_use_modulate=p_modulate!=Color(1,1,1,1); canvas_modulate=p_modulate; canvas_shader.set_conditional(CanvasShaderGLES2::USE_MODULATE,canvas_use_modulate); + canvas_shader.set_conditional(CanvasShaderGLES2::USE_DISTANCE_FIELD,false); + prev_distance_field=false; rebind_shader=true; reset_modulate=true; } + if (prev_distance_field!=ci->distance_field) { + + canvas_shader.set_conditional(CanvasShaderGLES2::USE_DISTANCE_FIELD,ci->distance_field); + prev_distance_field=ci->distance_field; + rebind_shader=true; + } + + if (current_clip!=ci->final_clip_owner) { current_clip=ci->final_clip_owner; diff --git a/drivers/gles2/shaders/canvas.glsl b/drivers/gles2/shaders/canvas.glsl index 0e19736fd5..e6d2569977 100644 --- a/drivers/gles2/shaders/canvas.glsl +++ b/drivers/gles2/shaders/canvas.glsl @@ -191,8 +191,16 @@ void main() { vec3 normal = vec3(0.0,0.0,1.0); #endif - +#ifdef USE_DISTANCE_FIELD + const float smoothing = 1.0/32.0; + float distance = texture2D(texture, uv_interp).a; + color.a = smoothstep(0.5 - smoothing, 0.5 + smoothing, distance); +#else color *= texture2D( texture, uv_interp ); + +#endif + + #if defined(ENABLE_SCREEN_UV) vec2 screen_uv = gl_FragCoord.xy*screen_uv_mult; #endif diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp index d2e1e7f0b9..892e4c9bc7 100644 --- a/scene/gui/label.cpp +++ b/scene/gui/label.cpp @@ -72,6 +72,7 @@ void Label::_notification(int p_what) { if (clip && !autowrap) VisualServer::get_singleton()->canvas_item_set_clip(get_canvas_item(),true); + if (word_cache_dirty) regenerate_word_cache(); @@ -87,7 +88,8 @@ void Label::_notification(int p_what) { bool use_outlinde = get_constant("shadow_as_outline"); Point2 shadow_ofs(get_constant("shadow_offset_x"),get_constant("shadow_offset_y")); - + VisualServer::get_singleton()->canvas_item_set_distance_field_mode(get_canvas_item(),font.is_valid() && font->is_distance_field_hint()); + int font_h = font->get_height(); int line_from=(int)get_val(); // + p_exposed.pos.y / font_h; int lines_visible = size.y/font_h; diff --git a/scene/resources/font.cpp b/scene/resources/font.cpp index 49ee3ee017..24d413ed60 100644 --- a/scene/resources/font.cpp +++ b/scene/resources/font.cpp @@ -398,6 +398,17 @@ int Font::get_kerning_pair(CharType p_A,CharType p_B) const { return 0; } +void Font::set_distance_field_hint(bool p_distance_field) { + + distance_field_hint=p_distance_field; + emit_changed(); +} + +bool Font::is_distance_field_hint() const{ + + return distance_field_hint; +} + void Font::clear() { @@ -406,6 +417,7 @@ void Font::clear() { char_map.clear(); textures.clear(); kerning_map.clear(); + distance_field_hint=false; } Size2 Font::get_string_size(const String& p_string) const { @@ -514,6 +526,9 @@ void Font::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_char_size","char","next"),&Font::get_char_size,DEFVAL(0)); ObjectTypeDB::bind_method(_MD("get_string_size","string"),&Font::get_string_size); + ObjectTypeDB::bind_method(_MD("set_distance_field_hint","enable"),&Font::set_distance_field_hint); + ObjectTypeDB::bind_method(_MD("is_distance_field_hint"),&Font::is_distance_field_hint); + ObjectTypeDB::bind_method(_MD("clear"),&Font::clear); ObjectTypeDB::bind_method(_MD("draw","canvas_item","pos","string","modulate","clip_w"),&Font::draw,DEFVAL(Color(1,1,1)),DEFVAL(-1)); @@ -535,12 +550,14 @@ void Font::_bind_methods() { ADD_PROPERTY( PropertyInfo( Variant::REAL, "height", PROPERTY_HINT_RANGE,"-1024,1024,1" ), _SCS("set_height"), _SCS("get_height") ); ADD_PROPERTY( PropertyInfo( Variant::REAL, "ascent", PROPERTY_HINT_RANGE,"-1024,1024,1" ), _SCS("set_ascent"), _SCS("get_ascent") ); + ADD_PROPERTY( PropertyInfo( Variant::BOOL, "distance_field" ), _SCS("set_distance_field_hint"), _SCS("is_distance_field_hint") ); } Font::Font() { clear(); + } diff --git a/scene/resources/font.h b/scene/resources/font.h index a64ec1ef7a..498bc6863a 100644 --- a/scene/resources/font.h +++ b/scene/resources/font.h @@ -75,6 +75,7 @@ private: float height; float ascent; + bool distance_field_hint; void _set_chars(const DVector& p_chars); DVector _get_chars() const; @@ -116,6 +117,9 @@ public: Size2 get_string_size(const String& p_string) const; void clear(); + + void set_distance_field_hint(bool p_distance_field); + bool is_distance_field_hint() const; void draw(RID p_canvas_item, const Point2& p_pos, const String& p_text,const Color& p_modulate=Color(1,1,1),int p_clip_w=-1) const; void draw_halign(RID p_canvas_item, const Point2& p_pos, HAlign p_align,float p_width,const String& p_text,const Color& p_modulate=Color(1,1,1)) const; diff --git a/servers/visual/rasterizer.h b/servers/visual/rasterizer.h index 8c89ddd5b7..ebc210fe3d 100644 --- a/servers/visual/rasterizer.h +++ b/servers/visual/rasterizer.h @@ -783,6 +783,7 @@ public: CanvasItem* final_clip_owner; CanvasItem* material_owner; ViewportRender *vp_render; + bool distance_field; Rect2 global_rect_cache; @@ -910,7 +911,7 @@ public: } void clear() { for (int i=0;iclip=p_clip; } +void VisualServerRaster::canvas_item_set_distance_field_mode(RID p_item, bool p_distance_field) { + VS_CHANGED; + CanvasItem *canvas_item = canvas_item_owner.get( p_item ); + ERR_FAIL_COND(!canvas_item); + + canvas_item->distance_field=p_distance_field; +} + void VisualServerRaster::canvas_item_set_transform(RID p_item, const Matrix32& p_transform) { diff --git a/servers/visual/visual_server_raster.h b/servers/visual/visual_server_raster.h index b1970c55b3..72af793278 100644 --- a/servers/visual/visual_server_raster.h +++ b/servers/visual/visual_server_raster.h @@ -1128,6 +1128,7 @@ public: //virtual void canvas_item_set_rect(RID p_item, const Rect2& p_rect); virtual void canvas_item_set_transform(RID p_item, const Matrix32& p_transform); virtual void canvas_item_set_clip(RID p_item, bool p_clip); + virtual void canvas_item_set_distance_field_mode(RID p_item, bool p_enable); virtual void canvas_item_set_custom_rect(RID p_item, bool p_custom_rect,const Rect2& p_rect=Rect2()); virtual void canvas_item_set_opacity(RID p_item, float p_opacity); virtual float canvas_item_get_opacity(RID p_item, float p_opacity) const; diff --git a/servers/visual/visual_server_wrap_mt.h b/servers/visual/visual_server_wrap_mt.h index 562b9ffeb0..ded4c6fc00 100644 --- a/servers/visual/visual_server_wrap_mt.h +++ b/servers/visual/visual_server_wrap_mt.h @@ -1109,6 +1109,7 @@ public: //FUNC(canvas_item_set_rect,RID, const Rect2& p_rect); FUNC2(canvas_item_set_transform,RID, const Matrix32& ); FUNC2(canvas_item_set_clip,RID, bool ); + FUNC2(canvas_item_set_distance_field_mode,RID, bool ); FUNC3(canvas_item_set_custom_rect,RID, bool ,const Rect2&); FUNC2(canvas_item_set_opacity,RID, float ); FUNC2RC(float,canvas_item_get_opacity,RID, float ); diff --git a/servers/visual_server.h b/servers/visual_server.h index c748839d1e..b6d354454e 100644 --- a/servers/visual_server.h +++ b/servers/visual_server.h @@ -969,6 +969,7 @@ public: virtual void canvas_item_set_transform(RID p_item, const Matrix32& p_transform)=0; virtual void canvas_item_set_clip(RID p_item, bool p_clip)=0; + virtual void canvas_item_set_distance_field_mode(RID p_item, bool p_enable)=0; virtual void canvas_item_set_custom_rect(RID p_item, bool p_custom_rect,const Rect2& p_rect=Rect2())=0; virtual void canvas_item_set_opacity(RID p_item, float p_opacity)=0; virtual float canvas_item_get_opacity(RID p_item, float p_opacity) const=0; diff --git a/tools/editor/io_plugins/editor_font_import_plugin.cpp b/tools/editor/io_plugins/editor_font_import_plugin.cpp index 05a42218a2..0562153199 100644 --- a/tools/editor/io_plugins/editor_font_import_plugin.cpp +++ b/tools/editor/io_plugins/editor_font_import_plugin.cpp @@ -984,7 +984,7 @@ Ref EditorFontImportPlugin::generate_font(const Refglyph, font_mode==_EditorFontImportOptions::FONT_BITMAP?ft_render_mode_normal:ft_render_mode_mono ); if (error) { @@ -1016,7 +1016,8 @@ Ref EditorFontImportPlugin::generate_font(const Refbitmap.width; int h = slot->bitmap.rows; int p = slot->bitmap.pitch; - print_line("pitch "+itos(slot->bitmap.pitch)); + + print_line("W: "+itos(w)+" P: "+itos(slot->bitmap.pitch)); if (font_mode==_EditorFontImportOptions::FONT_DISTANCE_FIELD) { @@ -1049,8 +1050,6 @@ Ref EditorFontImportPlugin::generate_font(const Refadvance=slot->advance.x/float(1<<6); - fdata->advance/=scaler; - if (font_mode==_EditorFontImportOptions::FONT_DISTANCE_FIELD) { fdata->halign = fdata->halign / scaler - 1.5; @@ -1150,7 +1149,7 @@ Ref EditorFontImportPlugin::generate_font(const Refofs_x=0; spd->ofs_y=0; - if (!FT_Load_Char( face, ' ', FT_LOAD_RENDER ) && !FT_Render_Glyph( face->glyph, ft_render_mode_normal )) { + if (!FT_Load_Char( face, ' ', FT_LOAD_RENDER ) && !FT_Render_Glyph( face->glyph, font_mode==_EditorFontImportOptions::FONT_BITMAP?ft_render_mode_normal:ft_render_mode_mono )) { spd->advance = slot->advance.x>>6; //round to nearest or store as float spd->advance/=scaler; @@ -1498,7 +1497,7 @@ Ref EditorFontImportPlugin::generate_font(const Ref atlast = memnew( ImageTexture ); atlast->create_from_image(atlas); @@ -1531,6 +1530,7 @@ Ref EditorFontImportPlugin::generate_font(const Refclear(); font->set_height(height+bottom_space+top_space); font->set_ascent(ascent+top_space); + font->set_distance_field_hint(font_mode==_EditorFontImportOptions::FONT_DISTANCE_FIELD); //register texures { -- cgit v1.2.3 From 40496dd76ae53c93ef5ea7e56671682a7cae9def Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sat, 21 Mar 2015 10:15:30 -0300 Subject: signed distance field fonts demo --- demos/2d/sdf_font/KaushanScript-Regular.otf | Bin 0 -> 89168 bytes demos/2d/sdf_font/engine.cfg | 4 ++++ demos/2d/sdf_font/font.fnt | Bin 0 -> 180332 bytes demos/2d/sdf_font/sdf.scn | Bin 0 -> 2415 bytes 4 files changed, 4 insertions(+) create mode 100644 demos/2d/sdf_font/KaushanScript-Regular.otf create mode 100644 demos/2d/sdf_font/engine.cfg create mode 100644 demos/2d/sdf_font/font.fnt create mode 100644 demos/2d/sdf_font/sdf.scn diff --git a/demos/2d/sdf_font/KaushanScript-Regular.otf b/demos/2d/sdf_font/KaushanScript-Regular.otf new file mode 100644 index 0000000000..bd29502100 Binary files /dev/null and b/demos/2d/sdf_font/KaushanScript-Regular.otf differ diff --git a/demos/2d/sdf_font/engine.cfg b/demos/2d/sdf_font/engine.cfg new file mode 100644 index 0000000000..bdf26ce741 --- /dev/null +++ b/demos/2d/sdf_font/engine.cfg @@ -0,0 +1,4 @@ +[application] + +name="Signed Distance Field Font" +main_scene="res://sdf.scn" diff --git a/demos/2d/sdf_font/font.fnt b/demos/2d/sdf_font/font.fnt new file mode 100644 index 0000000000..c2b6b0177d Binary files /dev/null and b/demos/2d/sdf_font/font.fnt differ diff --git a/demos/2d/sdf_font/sdf.scn b/demos/2d/sdf_font/sdf.scn new file mode 100644 index 0000000000..89d6245bf0 Binary files /dev/null and b/demos/2d/sdf_font/sdf.scn differ -- cgit v1.2.3 From db0a71fc58137da99137e9fbea3ee982679c9afd Mon Sep 17 00:00:00 2001 From: rollenrolm Date: Sat, 21 Mar 2015 18:33:32 +0100 Subject: New option to show/hide hidden files --- core/io/file_access_pack.cpp | 4 ++++ core/io/file_access_pack.h | 1 + core/os/dir_access.h | 1 + drivers/unix/dir_access_unix.cpp | 6 ++++++ drivers/unix/dir_access_unix.h | 2 ++ drivers/windows/dir_access_windows.cpp | 9 +++++++++ drivers/windows/dir_access_windows.h | 1 + platform/android/dir_access_android.cpp | 3 +++ platform/android/dir_access_android.h | 1 + platform/android/dir_access_jandroid.cpp | 3 +++ scene/gui/file_dialog.cpp | 19 ++++++++++++++----- tools/editor/editor_dir_dialog.cpp | 22 +++++++++++++++++----- tools/editor/editor_settings.cpp | 1 + 13 files changed, 63 insertions(+), 10 deletions(-) diff --git a/core/io/file_access_pack.cpp b/core/io/file_access_pack.cpp index 6e03819aac..afbd7e3d46 100644 --- a/core/io/file_access_pack.cpp +++ b/core/io/file_access_pack.cpp @@ -362,6 +362,10 @@ bool DirAccessPack::current_is_dir() const{ return cdir; } +bool DirAccessPack::current_is_hidden() const{ + + return false; +} void DirAccessPack::list_dir_end() { list_dirs.clear(); diff --git a/core/io/file_access_pack.h b/core/io/file_access_pack.h index 5fcc79aaf4..2d0cf5b32e 100644 --- a/core/io/file_access_pack.h +++ b/core/io/file_access_pack.h @@ -208,6 +208,7 @@ public: virtual bool list_dir_begin(); virtual String get_next(); virtual bool current_is_dir() const; + virtual bool current_is_hidden() const; virtual void list_dir_end(); virtual int get_drive_count(); diff --git a/core/os/dir_access.h b/core/os/dir_access.h index d8672218bd..dc56f2308e 100644 --- a/core/os/dir_access.h +++ b/core/os/dir_access.h @@ -78,6 +78,7 @@ public: virtual String get_next(bool* p_is_dir); // compatibility virtual String get_next()=0; virtual bool current_is_dir() const=0; + virtual bool current_is_hidden() const=0; virtual void list_dir_end()=0; ///< diff --git a/drivers/unix/dir_access_unix.cpp b/drivers/unix/dir_access_unix.cpp index 452d791d96..5f51865432 100644 --- a/drivers/unix/dir_access_unix.cpp +++ b/drivers/unix/dir_access_unix.cpp @@ -161,6 +161,7 @@ String DirAccessUnix::get_next() { } + _cishidden=(fname!="." && fname!=".." && fname.begins_with(".")); @@ -173,6 +174,11 @@ bool DirAccessUnix::current_is_dir() const { return _cisdir; } +bool DirAccessUnix::current_is_hidden() const { + + return _cishidden; +} + void DirAccessUnix::list_dir_end() { diff --git a/drivers/unix/dir_access_unix.h b/drivers/unix/dir_access_unix.h index 119cb5c3f4..f6089ccfe1 100644 --- a/drivers/unix/dir_access_unix.h +++ b/drivers/unix/dir_access_unix.h @@ -50,12 +50,14 @@ class DirAccessUnix : public DirAccess { String current_dir; bool _cisdir; + bool _cishidden; public: virtual bool list_dir_begin(); ///< This starts dir listing virtual String get_next(); virtual bool current_is_dir() const; + virtual bool current_is_hidden() const; virtual void list_dir_end(); ///< diff --git a/drivers/windows/dir_access_windows.cpp b/drivers/windows/dir_access_windows.cpp index d1e9766105..64df801b12 100644 --- a/drivers/windows/dir_access_windows.cpp +++ b/drivers/windows/dir_access_windows.cpp @@ -68,6 +68,7 @@ struct DirAccessWindowsPrivate { bool DirAccessWindows::list_dir_begin() { _cisdir=false; + _cishidden=false; if (unicode) { list_dir_end(); @@ -95,6 +96,8 @@ String DirAccessWindows::get_next() { if (unicode) { _cisdir=(p->fu.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY); + _cishidden=(p->fu.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN); + String name=p->fu.cFileName; if (FindNextFileW(p->h, &p->fu) == 0) { @@ -108,6 +111,7 @@ String DirAccessWindows::get_next() { #ifndef WINRT_ENABLED _cisdir=(p->fu.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY); + _cishidden=(p->fu.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN); String name=p->f.cFileName; @@ -128,6 +132,11 @@ bool DirAccessWindows::current_is_dir() const { return _cisdir; } +bool DirAccessWindows::current_is_hidden() const { + + return _cishidden; +} + void DirAccessWindows::list_dir_end() { if (p->h!=INVALID_HANDLE_VALUE) { diff --git a/drivers/windows/dir_access_windows.h b/drivers/windows/dir_access_windows.h index 36530ba9b3..906ce0d064 100644 --- a/drivers/windows/dir_access_windows.h +++ b/drivers/windows/dir_access_windows.h @@ -58,6 +58,7 @@ class DirAccessWindows : public DirAccess { bool unicode; bool _cisdir; + bool _cishidden; public: diff --git a/platform/android/dir_access_android.cpp b/platform/android/dir_access_android.cpp index 60bde61fc4..80311e5a08 100644 --- a/platform/android/dir_access_android.cpp +++ b/platform/android/dir_access_android.cpp @@ -79,6 +79,9 @@ bool DirAccessAndroid::current_is_dir() const{ return false; } +bool DirAccessAndroid::current_is_hidden() const{ + return current!="." && current!=".." && current.begins_with("."); +} void DirAccessAndroid::list_dir_end(){ if (aad==NULL) diff --git a/platform/android/dir_access_android.h b/platform/android/dir_access_android.h index a6aead6eb3..57683542fa 100644 --- a/platform/android/dir_access_android.h +++ b/platform/android/dir_access_android.h @@ -52,6 +52,7 @@ public: virtual bool list_dir_begin(); ///< This starts dir listing virtual String get_next(); virtual bool current_is_dir() const; + virtual bool current_is_hidden() const; virtual void list_dir_end(); ///< virtual int get_drive_count(); diff --git a/platform/android/dir_access_jandroid.cpp b/platform/android/dir_access_jandroid.cpp index f32e16e7d8..fda4ca7357 100644 --- a/platform/android/dir_access_jandroid.cpp +++ b/platform/android/dir_access_jandroid.cpp @@ -105,6 +105,9 @@ bool DirAccessJAndroid::current_is_dir() const{ return true; } +bool DirAccessAndroid::current_is_hidden() const{ + return current!="." && current!=".." && current.begins_with("."); +} void DirAccessJAndroid::list_dir_end(){ if (id==0) diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp index fbcfdb69bb..47f862a58d 100644 --- a/scene/gui/file_dialog.cpp +++ b/scene/gui/file_dialog.cpp @@ -29,6 +29,8 @@ #include "file_dialog.h" #include "scene/gui/label.h" #include "print_string.h" +#include "os/keyboard.h" +#include "tools/editor/editor_settings.h" FileDialog::GetIconFunc FileDialog::get_icon_func=NULL; @@ -278,13 +280,20 @@ void FileDialog::update_file_list() { List dirs; bool isdir; + bool ishidden; + bool show_hidden = EditorSettings::get_singleton()->get("file_dialog/show_hidden_files"); String item; + while ((item=dir_access->get_next(&isdir))!="") { - - if (!isdir) - files.push_back(item); - else - dirs.push_back(item); + + ishidden = dir_access->current_is_hidden(); + + if (show_hidden || !ishidden) { + if (!isdir) + files.push_back(item); + else + dirs.push_back(item); + } } dirs.sort_custom(); diff --git a/tools/editor/editor_dir_dialog.cpp b/tools/editor/editor_dir_dialog.cpp index eee4125e93..eec452ab7f 100644 --- a/tools/editor/editor_dir_dialog.cpp +++ b/tools/editor/editor_dir_dialog.cpp @@ -28,6 +28,9 @@ /*************************************************************************/ #include "editor_dir_dialog.h" #include "os/os.h" +#include "os/keyboard.h" +#include "tools/editor/editor_settings.h" + void EditorDirDialog::_update_dir(TreeItem* p_item) { @@ -39,12 +42,21 @@ void EditorDirDialog::_update_dir(TreeItem* p_item) { da->change_dir(cdir); da->list_dir_begin(); String p=da->get_next(); + + bool ishidden; + bool show_hidden = EditorSettings::get_singleton()->get("file_dialog/show_hidden_files"); + while(p!="") { - if (da->current_is_dir() && !p.begins_with(".")) { - TreeItem *ti = tree->create_item(p_item); - ti->set_text(0,p); - ti->set_icon(0,get_icon("Folder","EditorIcons")); - ti->set_collapsed(true); + + ishidden = da->current_is_hidden(); + + if (show_hidden || !ishidden) { + if (da->current_is_dir() && !p.begins_with(".")) { + TreeItem *ti = tree->create_item(p_item); + ti->set_text(0,p); + ti->set_icon(0,get_icon("Folder","EditorIcons")); + ti->set_collapsed(true); + } } p=da->get_next(); diff --git a/tools/editor/editor_settings.cpp b/tools/editor/editor_settings.cpp index 24699ac87f..deb5d86a2e 100644 --- a/tools/editor/editor_settings.cpp +++ b/tools/editor/editor_settings.cpp @@ -446,6 +446,7 @@ void EditorSettings::_load_defaults() { set("text_editor/create_signal_callbacks",true); + set("file_dialog/show_hidden_files", false); set("animation/autorename_animation_tracks",true); set("animation/confirm_insert_track",true); -- cgit v1.2.3 From 4d30bb72412506871e8567dc736f9920a57d527a Mon Sep 17 00:00:00 2001 From: rollenrolm Date: Sat, 21 Mar 2015 21:47:21 +0100 Subject: Fix issue #931: display current view name into editor's 3d scene viewports --- tools/editor/plugins/spatial_editor_plugin.cpp | 69 +++++++++++++++++++++----- tools/editor/plugins/spatial_editor_plugin.h | 2 + 2 files changed, 58 insertions(+), 13 deletions(-) diff --git a/tools/editor/plugins/spatial_editor_plugin.cpp b/tools/editor/plugins/spatial_editor_plugin.cpp index 87bd8105af..8f14c567c3 100644 --- a/tools/editor/plugins/spatial_editor_plugin.cpp +++ b/tools/editor/plugins/spatial_editor_plugin.cpp @@ -477,6 +477,16 @@ void SpatialEditorViewport::_select_region() { } +void SpatialEditorViewport::_update_name() { + + String ortho = orthogonal?"Orthogonal":"Perspective"; + + if (name!="") + view_menu->set_text("[ "+name+" "+ortho+" ]"); + else + view_menu->set_text("[ "+ortho+" ]"); +} + void SpatialEditorViewport::_compute_edit(const Point2& p_point) { @@ -832,6 +842,8 @@ void SpatialEditorViewport::_sinput(const InputEvent &p_event) { _edit.plane=TRANSFORM_X_AXIS; set_message("View Plane Transform.",2); + name=""; + _update_name(); } break; case TRANSFORM_X_AXIS: { @@ -1460,6 +1472,8 @@ void SpatialEditorViewport::_sinput(const InputEvent &p_event) { cursor.x_rot=Math_PI/2.0; if (cursor.x_rot<-Math_PI/2.0) cursor.x_rot=-Math_PI/2.0; + name=""; + _update_name(); } break; default: {} @@ -1484,9 +1498,14 @@ void SpatialEditorViewport::_sinput(const InputEvent &p_event) { if (k.mod.shift) { cursor.x_rot=-Math_PI/2.0; set_message("Bottom View.",2); + name="Bottom"; + _update_name(); + } else { cursor.x_rot=Math_PI/2.0; set_message("Top View.",2); + name="Top"; + _update_name(); } } break; case KEY_KP_1: { @@ -1495,10 +1514,14 @@ void SpatialEditorViewport::_sinput(const InputEvent &p_event) { if (k.mod.shift) { cursor.y_rot=Math_PI; set_message("Rear View.",2); + name="Rear"; + _update_name(); } else { cursor.y_rot=0; set_message("Front View.",2); + name="Front"; + _update_name(); } } break; @@ -1508,9 +1531,13 @@ void SpatialEditorViewport::_sinput(const InputEvent &p_event) { if (k.mod.shift) { cursor.y_rot=Math_PI/2.0; set_message("Left View.",2); + name="Left"; + _update_name(); } else { cursor.y_rot=-Math_PI/2.0; set_message("Right View.",2); + name="Right"; + _update_name(); } } break; @@ -1518,6 +1545,7 @@ void SpatialEditorViewport::_sinput(const InputEvent &p_event) { orthogonal = !orthogonal; _menu_option(orthogonal?VIEW_PERSPECTIVE:VIEW_ORTHOGONAL); + _update_name(); } break; @@ -1831,35 +1859,47 @@ void SpatialEditorViewport::_menu_option(int p_option) { cursor.x_rot=Math_PI/2.0; cursor.y_rot=0; + name="Top"; + _update_name(); } break; case VIEW_BOTTOM: { cursor.x_rot=-Math_PI/2.0; cursor.y_rot=0; + name="Bottom"; + _update_name(); } break; case VIEW_LEFT: { cursor.y_rot=Math_PI/2.0; cursor.x_rot=0; + name="Left"; + _update_name(); } break; case VIEW_RIGHT: { cursor.y_rot=-Math_PI/2.0; cursor.x_rot=0; + name="Right"; + _update_name(); } break; case VIEW_FRONT: { cursor.y_rot=0; cursor.x_rot=0; + name="Front"; + _update_name(); } break; case VIEW_REAR: { cursor.y_rot=Math_PI; cursor.x_rot=0; + name="Rear"; + _update_name(); } break; case VIEW_CENTER_TO_SELECTION: { @@ -1941,6 +1981,7 @@ void SpatialEditorViewport::_menu_option(int p_option) { view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(VIEW_ORTHOGONAL), false ); orthogonal=false; call_deferred("update_transform_gizmo_view"); + _update_name(); } break; case VIEW_ORTHOGONAL: { @@ -1949,6 +1990,7 @@ void SpatialEditorViewport::_menu_option(int p_option) { view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(VIEW_ORTHOGONAL), true ); orthogonal=true; call_deferred("update_transform_gizmo_view"); + _update_name(); } break; case VIEW_AUDIO_LISTENER: { @@ -2147,15 +2189,13 @@ void SpatialEditorViewport::reset() { message_time=0; message=""; last_message=""; + name="Top"; cursor.x_rot=0; cursor.y_rot=0; cursor.distance=4; cursor.region_select=false; - - - - + _update_name(); } SpatialEditorViewport::SpatialEditorViewport(SpatialEditor *p_spatial_editor, EditorNode *p_editor, int p_index) { @@ -2189,18 +2229,17 @@ SpatialEditorViewport::SpatialEditorViewport(SpatialEditor *p_spatial_editor, Ed view_menu = memnew( MenuButton ); surface->add_child(view_menu); view_menu->set_pos( Point2(4,4)); - view_menu->set_text("[view]"); view_menu->set_self_opacity(0.5); - view_menu->get_popup()->add_item("Top",VIEW_TOP); - view_menu->get_popup()->add_item("Bottom",VIEW_BOTTOM); - view_menu->get_popup()->add_item("Left",VIEW_LEFT); - view_menu->get_popup()->add_item("Right",VIEW_RIGHT); - view_menu->get_popup()->add_item("Front",VIEW_FRONT); - view_menu->get_popup()->add_item("Rear",VIEW_REAR); + view_menu->get_popup()->add_item("Top (Num7)",VIEW_TOP); + view_menu->get_popup()->add_item("Bottom (Shift+Num7)",VIEW_BOTTOM); + view_menu->get_popup()->add_item("Left (Num3)",VIEW_LEFT); + view_menu->get_popup()->add_item("Right (Shift+Num3)",VIEW_RIGHT); + view_menu->get_popup()->add_item("Front (Num1)",VIEW_FRONT); + view_menu->get_popup()->add_item("Rear (Shift+Num1)",VIEW_REAR); view_menu->get_popup()->add_separator(); - view_menu->get_popup()->add_check_item("Perspective",VIEW_PERSPECTIVE); - view_menu->get_popup()->add_check_item("Orthogonal",VIEW_ORTHOGONAL); + view_menu->get_popup()->add_check_item("Perspective (Num5)",VIEW_PERSPECTIVE); + view_menu->get_popup()->add_check_item("Orthogonal (Num5)",VIEW_ORTHOGONAL); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_PERSPECTIVE),true); view_menu->get_popup()->add_separator(); view_menu->get_popup()->add_check_item("Environment",VIEW_ENVIRONMENT); @@ -2233,6 +2272,10 @@ SpatialEditorViewport::SpatialEditorViewport(SpatialEditor *p_spatial_editor, Ed viewport->set_as_audio_listener(true); } + + name="Top"; + _update_name(); + EditorSettings::get_singleton()->connect("settings_changed",this,"update_transform_gizmo_view"); } diff --git a/tools/editor/plugins/spatial_editor_plugin.h b/tools/editor/plugins/spatial_editor_plugin.h index 646a4d2d86..4d594d1921 100644 --- a/tools/editor/plugins/spatial_editor_plugin.h +++ b/tools/editor/plugins/spatial_editor_plugin.h @@ -92,6 +92,7 @@ public: }; private: int index; + String name; void _menu_option(int p_option); Size2 prev_size; @@ -110,6 +111,7 @@ private: bool orthogonal; float gizmo_scale; + void _update_name(); void _compute_edit(const Point2& p_point); void _clear_selected(); void _select_clicked(bool p_append,bool p_single); -- cgit v1.2.3 From c6c72a3c37a44964ec8e6b3353f78635bf588eab Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sun, 22 Mar 2015 01:46:18 -0300 Subject: input events on Area2D is now supported also added a demo showing how this works --- demos/2d/area_input/box_area.png | Bin 0 -> 1246 bytes demos/2d/area_input/circle_area.png | Bin 0 -> 3030 bytes demos/2d/area_input/engine.cfg | 4 ++ demos/2d/area_input/input.gd | 20 ++++++++ demos/2d/area_input/input.scn | Bin 0 -> 2886 bytes scene/2d/canvas_item.cpp | 62 ++++++++++++++++++++++ scene/2d/canvas_item.h | 1 + scene/2d/collision_object_2d.cpp | 71 ++++++++++++++++++++++++++ scene/2d/collision_object_2d.h | 12 +++++ scene/2d/physics_body_2d.cpp | 1 + scene/main/viewport.cpp | 65 +++++++++++++++++++++-- scene/main/viewport.h | 1 + scene/resources/font.cpp | 4 ++ servers/physics/space_sw.cpp | 2 +- servers/physics_2d/collision_object_2d_sw.cpp | 1 + servers/physics_2d/collision_object_2d_sw.h | 4 ++ servers/physics_2d/physics_2d_server_sw.cpp | 15 ++++++ servers/physics_2d/physics_2d_server_sw.h | 5 ++ servers/physics_2d/shape_2d_sw.cpp | 63 +++++++++++++++++++++++ servers/physics_2d/shape_2d_sw.h | 10 ++++ servers/physics_2d/space_2d_sw.cpp | 51 ++++++++++++++++++ servers/physics_2d/space_2d_sw.h | 1 + servers/physics_2d_server.h | 5 ++ 23 files changed, 392 insertions(+), 6 deletions(-) create mode 100644 demos/2d/area_input/box_area.png create mode 100644 demos/2d/area_input/circle_area.png create mode 100644 demos/2d/area_input/engine.cfg create mode 100644 demos/2d/area_input/input.gd create mode 100644 demos/2d/area_input/input.scn diff --git a/demos/2d/area_input/box_area.png b/demos/2d/area_input/box_area.png new file mode 100644 index 0000000000..ba7c37f7de Binary files /dev/null and b/demos/2d/area_input/box_area.png differ diff --git a/demos/2d/area_input/circle_area.png b/demos/2d/area_input/circle_area.png new file mode 100644 index 0000000000..3cc24c8a0c Binary files /dev/null and b/demos/2d/area_input/circle_area.png differ diff --git a/demos/2d/area_input/engine.cfg b/demos/2d/area_input/engine.cfg new file mode 100644 index 0000000000..3227e9278f --- /dev/null +++ b/demos/2d/area_input/engine.cfg @@ -0,0 +1,4 @@ +[application] + +name="Area 2D Input Events" +main_scene="res://input.scn" diff --git a/demos/2d/area_input/input.gd b/demos/2d/area_input/input.gd new file mode 100644 index 0000000000..acecd095ed --- /dev/null +++ b/demos/2d/area_input/input.gd @@ -0,0 +1,20 @@ + +extends Area2D + +# member variables here, example: +# var a=2 +# var b="textvar" + +#virtual from CollisionObject2D (also available as signal) +func _input_event(viewport, event, shape_idx): + #convert event to local coordinates + if (event.type==InputEvent.MOUSE_MOTION): + event = make_input_local( event ) + get_node("label").set_text(str(event.pos)) + +#virtual from CollisionObject2D (also available as signal) +func _mouse_exit(): + get_node("label").set_text("") + + + diff --git a/demos/2d/area_input/input.scn b/demos/2d/area_input/input.scn new file mode 100644 index 0000000000..0bb3a18834 Binary files /dev/null and b/demos/2d/area_input/input.scn differ diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp index 436b77a1ac..c3ff03d8f4 100644 --- a/scene/2d/canvas_item.cpp +++ b/scene/2d/canvas_item.cpp @@ -943,7 +943,67 @@ Ref CanvasItem::get_material() const{ } +InputEvent CanvasItem::make_input_local(const InputEvent& p_event) const { + ERR_FAIL_COND_V(!is_inside_tree(),p_event); + + InputEvent ev = p_event; + + Matrix32 local_matrix = (get_canvas_transform() * get_global_transform()).affine_inverse(); + + switch(ev.type) { + + case InputEvent::MOUSE_BUTTON: { + + Vector2 g = local_matrix.xform(Vector2(ev.mouse_button.global_x,ev.mouse_button.global_y)); + Vector2 l = local_matrix.xform(Vector2(ev.mouse_button.x,ev.mouse_button.y)); + ev.mouse_button.x=l.x; + ev.mouse_button.y=l.y; + ev.mouse_button.global_x=g.x; + ev.mouse_button.global_y=g.y; + + } break; + case InputEvent::MOUSE_MOTION: { + + Vector2 g = local_matrix.xform(Vector2(ev.mouse_motion.global_x,ev.mouse_motion.global_y)); + Vector2 l = local_matrix.xform(Vector2(ev.mouse_motion.x,ev.mouse_motion.y)); + Vector2 r = local_matrix.basis_xform(Vector2(ev.mouse_motion.relative_x,ev.mouse_motion.relative_y)); + Vector2 s = local_matrix.basis_xform(Vector2(ev.mouse_motion.speed_x,ev.mouse_motion.speed_y)); + ev.mouse_motion.x=l.x; + ev.mouse_motion.y=l.y; + ev.mouse_motion.global_x=g.x; + ev.mouse_motion.global_y=g.y; + ev.mouse_motion.relative_x=r.x; + ev.mouse_motion.relative_y=r.y; + ev.mouse_motion.speed_x=s.x; + ev.mouse_motion.speed_y=s.y; + + } break; + case InputEvent::SCREEN_TOUCH: { + + + Vector2 t = local_matrix.xform(Vector2(ev.screen_touch.x,ev.screen_touch.y)); + ev.screen_touch.x=t.x; + ev.screen_touch.y=t.y; + + } break; + case InputEvent::SCREEN_DRAG: { + + + Vector2 t = local_matrix.xform(Vector2(ev.screen_drag.x,ev.screen_drag.y)); + Vector2 r = local_matrix.basis_xform(Vector2(ev.screen_drag.relative_x,ev.screen_drag.relative_y)); + Vector2 s = local_matrix.basis_xform(Vector2(ev.screen_drag.speed_x,ev.screen_drag.speed_y)); + ev.screen_drag.x=t.x; + ev.screen_drag.y=t.y; + ev.screen_drag.relative_x=r.x; + ev.screen_drag.relative_y=r.y; + ev.screen_drag.speed_x=s.x; + ev.screen_drag.speed_y=s.y; + } break; + } + + return ev; +} void CanvasItem::_bind_methods() { @@ -1021,6 +1081,8 @@ void CanvasItem::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_use_parent_material","enable"),&CanvasItem::set_use_parent_material); ObjectTypeDB::bind_method(_MD("get_use_parent_material"),&CanvasItem::get_use_parent_material); + ObjectTypeDB::bind_method(_MD("make_input_local","event"),&CanvasItem::make_input_local); + BIND_VMETHOD(MethodInfo("_draw")); ADD_PROPERTY( PropertyInfo(Variant::BOOL,"visibility/visible"), _SCS("_set_visible_"),_SCS("_is_visible_") ); diff --git a/scene/2d/canvas_item.h b/scene/2d/canvas_item.h index 0c7be261ab..c43642a8ec 100644 --- a/scene/2d/canvas_item.h +++ b/scene/2d/canvas_item.h @@ -249,6 +249,7 @@ public: void set_use_parent_material(bool p_use_parent_material); bool get_use_parent_material() const; + InputEvent make_input_local(const InputEvent& pevent) const; CanvasItem(); ~CanvasItem(); diff --git a/scene/2d/collision_object_2d.cpp b/scene/2d/collision_object_2d.cpp index 3b859d9366..a883fee103 100644 --- a/scene/2d/collision_object_2d.cpp +++ b/scene/2d/collision_object_2d.cpp @@ -28,6 +28,7 @@ /*************************************************************************/ #include "collision_object_2d.h" #include "servers/physics_2d_server.h" +#include "scene/scene_string_names.h" void CollisionObject2D::_update_shapes_from_children() { @@ -58,9 +59,15 @@ void CollisionObject2D::_notification(int p_what) { } else Physics2DServer::get_singleton()->body_set_space(rid,space); + _update_pickable(); + //get space } + case NOTIFICATION_VISIBILITY_CHANGED: { + + _update_pickable(); + } break; case NOTIFICATION_TRANSFORM_CHANGED: { if (area) @@ -166,6 +173,57 @@ void CollisionObject2D::_get_property_list( List *p_list) const { } } + +void CollisionObject2D::set_pickable(bool p_enabled) { + + if (pickable==p_enabled) + return; + + pickable=p_enabled; + _update_pickable(); +} + +bool CollisionObject2D::is_pickable() const { + + return pickable; +} + +void CollisionObject2D::_input_event(Node *p_viewport, const InputEvent& p_input_event, int p_shape) { + + if (get_script_instance()) { + get_script_instance()->call(SceneStringNames::get_singleton()->_input_event,p_viewport,p_input_event,p_shape); + } + emit_signal(SceneStringNames::get_singleton()->input_event,p_viewport,p_input_event,p_shape); +} + +void CollisionObject2D::_mouse_enter() { + + if (get_script_instance()) { + get_script_instance()->call(SceneStringNames::get_singleton()->_mouse_enter); + } + emit_signal(SceneStringNames::get_singleton()->mouse_enter); +} + + +void CollisionObject2D::_mouse_exit() { + + if (get_script_instance()) { + get_script_instance()->call(SceneStringNames::get_singleton()->_mouse_exit); + } + emit_signal(SceneStringNames::get_singleton()->mouse_exit); + +} + +void CollisionObject2D::_update_pickable() { + if (!is_inside_tree()) + return; + bool pickable = this->pickable && is_inside_tree() && is_visible(); + if (area) + Physics2DServer::get_singleton()->area_set_pickable(rid,pickable); + else + Physics2DServer::get_singleton()->body_set_pickable(rid,pickable); +} + void CollisionObject2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("add_shape","shape:Shape2D","transform"),&CollisionObject2D::add_shape,DEFVAL(Matrix32())); @@ -180,6 +238,17 @@ void CollisionObject2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("clear_shapes"),&CollisionObject2D::clear_shapes); ObjectTypeDB::bind_method(_MD("get_rid"),&CollisionObject2D::get_rid); + ObjectTypeDB::bind_method(_MD("set_pickable","enabled"),&CollisionObject2D::set_pickable); + ObjectTypeDB::bind_method(_MD("is_pickable"),&CollisionObject2D::is_pickable); + + BIND_VMETHOD( MethodInfo("_input_event",PropertyInfo(Variant::OBJECT,"viewport"),PropertyInfo(Variant::INPUT_EVENT,"event"),PropertyInfo(Variant::INT,"shape_idx"))); + + ADD_SIGNAL( MethodInfo("input_event",PropertyInfo(Variant::OBJECT,"viewport"),PropertyInfo(Variant::INPUT_EVENT,"event"),PropertyInfo(Variant::INT,"shape_idx"))); + ADD_SIGNAL( MethodInfo("mouse_enter")); + ADD_SIGNAL( MethodInfo("mouse_exit")); + + ADD_PROPERTY( PropertyInfo(Variant::BOOL,"input/pickable"),_SCS("set_pickable"),_SCS("is_pickable")); + } @@ -262,7 +331,9 @@ CollisionObject2D::CollisionObject2D(RID p_rid, bool p_area) { rid=p_rid; area=p_area; + pickable=true; if (p_area) { + Physics2DServer::get_singleton()->area_attach_object_instance_ID(rid,get_instance_ID()); } else { Physics2DServer::get_singleton()->body_attach_object_instance_ID(rid,get_instance_ID()); diff --git a/scene/2d/collision_object_2d.h b/scene/2d/collision_object_2d.h index 4a529ce062..393973ce90 100644 --- a/scene/2d/collision_object_2d.h +++ b/scene/2d/collision_object_2d.h @@ -38,6 +38,7 @@ class CollisionObject2D : public Node2D { bool area; RID rid; + bool pickable; struct ShapeData { Matrix32 xform; @@ -66,9 +67,17 @@ protected: bool _get(const StringName& p_name,Variant &r_ret) const; void _get_property_list( List *p_list) const; static void _bind_methods(); + + void _update_pickable(); +friend class Viewport; + void _input_event(Node *p_viewport, const InputEvent& p_input_event, int p_shape); + void _mouse_enter(); + void _mouse_exit(); + public: + void add_shape(const Ref& p_shape, const Matrix32& p_transform=Matrix32()); int get_shape_count() const; void set_shape(int p_shape_idx, const Ref& p_shape); @@ -80,6 +89,9 @@ public: void remove_shape(int p_shape_idx); void clear_shapes(); + void set_pickable(bool p_enabled); + bool is_pickable() const; + _FORCE_INLINE_ RID get_rid() const { return rid; } CollisionObject2D(); diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp index 6f18325212..22dd0f01d0 100644 --- a/scene/2d/physics_body_2d.cpp +++ b/scene/2d/physics_body_2d.cpp @@ -98,6 +98,7 @@ PhysicsBody2D::PhysicsBody2D(Physics2DServer::BodyMode p_mode) : CollisionObject mask=1; set_one_way_collision_max_depth(0); + set_pickable(false); } diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 02e009866f..18b8b46d90 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -30,7 +30,7 @@ #include "os/os.h" #include "scene/3d/spatial.h" #include "os/input.h" - +#include "servers/physics_2d_server.h" //#include "scene/3d/camera.h" #include "servers/spatial_sound_server.h" @@ -40,7 +40,7 @@ #include "scene/3d/spatial_indexer.h" #include "scene/3d/collision_object.h" - +#include "scene/2d/collision_object_2d.h" int RenderTargetTexture::get_width() const { @@ -355,11 +355,12 @@ void Viewport::_notification(int p_what) { case NOTIFICATION_FIXED_PROCESS: { if (physics_object_picking) { -#ifndef _3D_DISABLED + Vector2 last_pos(1e20,1e20); CollisionObject *last_object; ObjectID last_id=0; PhysicsDirectSpaceState::RayResult result; + Physics2DDirectSpaceState *ss2d=Physics2DServer::get_singleton()->space_get_direct_state(find_world_2d()->get_space()); bool motion_tested=false; @@ -392,6 +393,60 @@ void Viewport::_notification(int p_what) { } + if (ss2d) { + //send to 2D + + + uint64_t frame = get_tree()->get_frame(); + + Vector2 point = get_canvas_transform().affine_inverse().xform(pos); + Physics2DDirectSpaceState::ShapeResult res[64]; + int rc = ss2d->intersect_point(point,res,64,Set(),0xFFFFFFFF,0xFFFFFFFF); + for(int i=0;icast_to(); + if (co) { + + Map::Element *E=physics_2d_mouseover.find(res[i].collider_id); + if (!E) { + E=physics_2d_mouseover.insert(res[i].collider_id,frame); + co->_mouse_enter(); + } else { + E->get()=frame; + } + + co->_input_event(this,ev,res[i].shape); + } + } + } + + List::Element*> to_erase; + + for (Map::Element*E=physics_2d_mouseover.front();E;E=E->next()) { + if (E->get()!=frame) { + Object *o=ObjectDB::get_instance(E->key()); + if (o) { + + CollisionObject2D *co=o->cast_to(); + if (co) { + co->_mouse_exit(); + } + } + to_erase.push_back(E); + } + } + + while(to_erase.size()) { + physics_2d_mouseover.erase(to_erase.front()->get()); + to_erase.pop_front(); + } + + } + + + +#ifndef _3D_DISABLED bool captured=false; if (physics_object_capture!=0) { @@ -499,9 +554,9 @@ void Viewport::_notification(int p_what) { _test_new_mouseover(new_collider); } - - } #endif + } + } } break; diff --git a/scene/main/viewport.h b/scene/main/viewport.h index d2a22401bd..14f4f68217 100644 --- a/scene/main/viewport.h +++ b/scene/main/viewport.h @@ -124,6 +124,7 @@ friend class RenderTargetTexture; ObjectID physics_object_over; Vector2 physics_last_mousepos; void _test_new_mouseover(ObjectID new_collider); + Map physics_2d_mouseover; void _update_rect(); diff --git a/scene/resources/font.cpp b/scene/resources/font.cpp index 24d413ed60..79316f0019 100644 --- a/scene/resources/font.cpp +++ b/scene/resources/font.cpp @@ -523,6 +523,10 @@ void Font::_bind_methods() { ObjectTypeDB::bind_method(_MD("add_texture","texture:Texture"),&Font::add_texture); ObjectTypeDB::bind_method(_MD("add_char","character","texture","rect","align","advance"),&Font::add_char,DEFVAL(Point2()),DEFVAL(-1)); + + ObjectTypeDB::bind_method(_MD("get_texture_count"),&Font::get_texture_count); + ObjectTypeDB::bind_method(_MD("get_texture:Texture","idx"),&Font::get_texture); + ObjectTypeDB::bind_method(_MD("get_char_size","char","next"),&Font::get_char_size,DEFVAL(0)); ObjectTypeDB::bind_method(_MD("get_string_size","string"),&Font::get_string_size); diff --git a/servers/physics/space_sw.cpp b/servers/physics/space_sw.cpp index 4e8b60b86b..3fc34889f2 100644 --- a/servers/physics/space_sw.cpp +++ b/servers/physics/space_sw.cpp @@ -77,7 +77,7 @@ bool PhysicsDirectSpaceStateSW::intersect_ray(const Vector3& p_from, const Vecto if (!_match_object_type_query(space->intersection_query_results[i],p_layer_mask,p_object_type_mask)) continue; - if (!(static_cast(space->intersection_query_results[i])->is_ray_pickable())) + if (!(static_cast(space->intersection_query_results[i])->is_ray_pickable())) continue; if (p_exclude.has( space->intersection_query_results[i]->get_self())) diff --git a/servers/physics_2d/collision_object_2d_sw.cpp b/servers/physics_2d/collision_object_2d_sw.cpp index d0443f8110..eefc598b39 100644 --- a/servers/physics_2d/collision_object_2d_sw.cpp +++ b/servers/physics_2d/collision_object_2d_sw.cpp @@ -228,4 +228,5 @@ CollisionObject2DSW::CollisionObject2DSW(Type p_type) { instance_id=0; user_mask=0; layer_mask=1; + pickable=true; } diff --git a/servers/physics_2d/collision_object_2d_sw.h b/servers/physics_2d/collision_object_2d_sw.h index 00ad361245..0c91237876 100644 --- a/servers/physics_2d/collision_object_2d_sw.h +++ b/servers/physics_2d/collision_object_2d_sw.h @@ -47,6 +47,7 @@ private: Type type; RID self; ObjectID instance_id; + bool pickable; struct Shape { @@ -129,6 +130,9 @@ public: _FORCE_INLINE_ bool is_static() const { return _static; } + void set_pickable(bool p_pickable) { pickable=p_pickable; } + _FORCE_INLINE_ bool is_pickable() const { return pickable; } + virtual ~CollisionObject2DSW() {} }; diff --git a/servers/physics_2d/physics_2d_server_sw.cpp b/servers/physics_2d/physics_2d_server_sw.cpp index 0a02a9568a..883acd0200 100644 --- a/servers/physics_2d/physics_2d_server_sw.cpp +++ b/servers/physics_2d/physics_2d_server_sw.cpp @@ -463,6 +463,14 @@ Matrix32 Physics2DServerSW::area_get_transform(RID p_area) const { return area->get_transform(); }; +void Physics2DServerSW::area_set_pickable(RID p_area,bool p_pickable) { + + Area2DSW *area = area_owner.get(p_area); + ERR_FAIL_COND(!area); + area->set_pickable(p_pickable); + +} + void Physics2DServerSW::area_set_monitorable(RID p_area,bool p_monitorable) { Area2DSW *area = area_owner.get(p_area); @@ -943,6 +951,13 @@ bool Physics2DServerSW::body_collide_shape(RID p_body, int p_body_shape, RID p_s } +void Physics2DServerSW::body_set_pickable(RID p_body,bool p_pickable) { + + Body2DSW *body = body_owner.get(p_body); + ERR_FAIL_COND(!body); + body->set_pickable(p_pickable); + +} /* JOINT API */ diff --git a/servers/physics_2d/physics_2d_server_sw.h b/servers/physics_2d/physics_2d_server_sw.h index eba5845e5b..58fc4eeb33 100644 --- a/servers/physics_2d/physics_2d_server_sw.h +++ b/servers/physics_2d/physics_2d_server_sw.h @@ -138,6 +138,9 @@ public: virtual void area_set_monitor_callback(RID p_area,Object *p_receiver,const StringName& p_method); virtual void area_set_area_monitor_callback(RID p_area,Object *p_receiver,const StringName& p_method); + virtual void area_set_pickable(RID p_area,bool p_pickable); + + /* BODY API */ // create a body of a given type @@ -218,6 +221,8 @@ public: virtual void body_set_force_integration_callback(RID p_body,Object *p_receiver,const StringName& p_method,const Variant& p_udata=Variant()); virtual bool body_collide_shape(RID p_body, int p_body_shape,RID p_shape, const Matrix32& p_shape_xform,const Vector2& p_motion,Vector2 *r_results,int p_result_max,int &r_result_count); + virtual void body_set_pickable(RID p_body,bool p_pickable); + /* JOINT API */ virtual void joint_set_param(RID p_joint, JointParam p_param, real_t p_value); diff --git a/servers/physics_2d/shape_2d_sw.cpp b/servers/physics_2d/shape_2d_sw.cpp index ed63870a12..9a4b52d563 100644 --- a/servers/physics_2d/shape_2d_sw.cpp +++ b/servers/physics_2d/shape_2d_sw.cpp @@ -106,6 +106,11 @@ void LineShape2DSW::get_supports(const Vector2& p_normal,Vector2 *r_supports,int r_amount=0; } +bool LineShape2DSW::contains_point(const Vector2& p_point) const { + + return normal.dot(p_point) < d; +} + bool LineShape2DSW::intersect_segment(const Vector2& p_begin,const Vector2& p_end,Vector2 &r_point, Vector2 &r_normal) const { Vector2 segment= p_begin - p_end; @@ -175,6 +180,11 @@ void RayShape2DSW::get_supports(const Vector2& p_normal,Vector2 *r_supports,int } +bool RayShape2DSW::contains_point(const Vector2& p_point) const { + + return false; +} + bool RayShape2DSW::intersect_segment(const Vector2& p_begin,const Vector2& p_end,Vector2 &r_point, Vector2 &r_normal) const { return false; //rays can't be intersected @@ -223,6 +233,11 @@ void SegmentShape2DSW::get_supports(const Vector2& p_normal,Vector2 *r_supports, } +bool SegmentShape2DSW::contains_point(const Vector2& p_point) const { + + return false; +} + bool SegmentShape2DSW::intersect_segment(const Vector2& p_begin,const Vector2& p_end,Vector2 &r_point, Vector2 &r_normal) const { if (!Geometry::segment_intersects_segment_2d(p_begin,p_end,a,b,&r_point)) @@ -288,6 +303,13 @@ void CircleShape2DSW::get_supports(const Vector2& p_normal,Vector2 *r_supports,i } + +bool CircleShape2DSW::contains_point(const Vector2& p_point) const { + + return p_point.length_squared() < radius*radius; +} + + bool CircleShape2DSW::intersect_segment(const Vector2& p_begin,const Vector2& p_end,Vector2 &r_point, Vector2 &r_normal) const { @@ -375,6 +397,11 @@ void RectangleShape2DSW::get_supports(const Vector2& p_normal,Vector2 *r_support } +bool RectangleShape2DSW::contains_point(const Vector2& p_point) const { + + return Math::abs(p_point.x)0) + out=true; + else + in=true; + } + + return (in && !out) || (!in && out); +} + + bool ConvexPolygonShape2DSW::intersect_segment(const Vector2& p_begin,const Vector2& p_end,Vector2 &r_point, Vector2 &r_normal) const { Vector2 n = (p_end-p_begin).normalized(); @@ -734,6 +791,12 @@ void ConcavePolygonShape2DSW::get_supports(const Vector2& p_normal,Vector2 *r_su } +bool ConcavePolygonShape2DSW::contains_point(const Vector2& p_point) const { + + return false; //sorry +} + + bool ConcavePolygonShape2DSW::intersect_segment(const Vector2& p_begin,const Vector2& p_end,Vector2 &r_point, Vector2 &r_normal) const{ uint32_t* stack = (uint32_t*)alloca(sizeof(int)*bvh_depth); diff --git a/servers/physics_2d/shape_2d_sw.h b/servers/physics_2d/shape_2d_sw.h index 931491efd5..05ea5b21cd 100644 --- a/servers/physics_2d/shape_2d_sw.h +++ b/servers/physics_2d/shape_2d_sw.h @@ -78,6 +78,8 @@ public: virtual bool is_concave() const { return false; } + virtual bool contains_point(const Vector2& p_point) const=0; + virtual void project_rangev(const Vector2& p_normal, const Matrix32& p_transform, real_t &r_min, real_t &r_max) const=0; virtual void project_range_castv(const Vector2& p_cast, const Vector2& p_normal, const Matrix32& p_transform, real_t &r_min, real_t &r_max) const=0; virtual Vector2 get_support(const Vector2& p_normal) const; @@ -171,6 +173,7 @@ public: virtual void project_rangev(const Vector2& p_normal, const Matrix32& p_transform, real_t &r_min, real_t &r_max) const { project_range(p_normal,p_transform,r_min,r_max); } virtual void get_supports(const Vector2& p_normal,Vector2 *r_supports,int & r_amount) const; + virtual bool contains_point(const Vector2& p_point) const; virtual bool intersect_segment(const Vector2& p_begin,const Vector2& p_end,Vector2 &r_point, Vector2 &r_normal) const; virtual real_t get_moment_of_inertia(float p_mass,const Vector2& p_scale) const; @@ -213,6 +216,7 @@ public: virtual void project_rangev(const Vector2& p_normal, const Matrix32& p_transform, real_t &r_min, real_t &r_max) const { project_range(p_normal,p_transform,r_min,r_max); } virtual void get_supports(const Vector2& p_normal,Vector2 *r_supports,int & r_amount) const; + virtual bool contains_point(const Vector2& p_point) const; virtual bool intersect_segment(const Vector2& p_begin,const Vector2& p_end,Vector2 &r_point, Vector2 &r_normal) const; virtual real_t get_moment_of_inertia(float p_mass,const Vector2& p_scale) const; @@ -260,6 +264,7 @@ public: virtual void project_rangev(const Vector2& p_normal, const Matrix32& p_transform, real_t &r_min, real_t &r_max) const { project_range(p_normal,p_transform,r_min,r_max); } virtual void get_supports(const Vector2& p_normal,Vector2 *r_supports,int & r_amount) const; + virtual bool contains_point(const Vector2& p_point) const; virtual bool intersect_segment(const Vector2& p_begin,const Vector2& p_end,Vector2 &r_point, Vector2 &r_normal) const; virtual real_t get_moment_of_inertia(float p_mass,const Vector2& p_scale) const; @@ -297,6 +302,7 @@ public: virtual void project_rangev(const Vector2& p_normal, const Matrix32& p_transform, real_t &r_min, real_t &r_max) const { project_range(p_normal,p_transform,r_min,r_max); } virtual void get_supports(const Vector2& p_normal,Vector2 *r_supports,int & r_amount) const; + virtual bool contains_point(const Vector2& p_point) const; virtual bool intersect_segment(const Vector2& p_begin,const Vector2& p_end,Vector2 &r_point, Vector2 &r_normal) const; virtual real_t get_moment_of_inertia(float p_mass,const Vector2& p_scale) const; @@ -336,6 +342,7 @@ public: virtual void project_rangev(const Vector2& p_normal, const Matrix32& p_transform, real_t &r_min, real_t &r_max) const { project_range(p_normal,p_transform,r_min,r_max); } virtual void get_supports(const Vector2& p_normal,Vector2 *r_supports,int & r_amount) const; + virtual bool contains_point(const Vector2& p_point) const; virtual bool intersect_segment(const Vector2& p_begin,const Vector2& p_end,Vector2 &r_point, Vector2 &r_normal) const; virtual real_t get_moment_of_inertia(float p_mass,const Vector2& p_scale) const; @@ -423,6 +430,7 @@ public: virtual void project_rangev(const Vector2& p_normal, const Matrix32& p_transform, real_t &r_min, real_t &r_max) const { project_range(p_normal,p_transform,r_min,r_max); } virtual void get_supports(const Vector2& p_normal,Vector2 *r_supports,int & r_amount) const; + virtual bool contains_point(const Vector2& p_point) const; virtual bool intersect_segment(const Vector2& p_begin,const Vector2& p_end,Vector2 &r_point, Vector2 &r_normal) const; virtual real_t get_moment_of_inertia(float p_mass,const Vector2& p_scale) const; @@ -485,6 +493,7 @@ public: virtual void project_rangev(const Vector2& p_normal, const Matrix32& p_transform, real_t &r_min, real_t &r_max) const { project_range(p_normal,p_transform,r_min,r_max); } virtual void get_supports(const Vector2& p_normal,Vector2 *r_supports,int & r_amount) const; + virtual bool contains_point(const Vector2& p_point) const; virtual bool intersect_segment(const Vector2& p_begin,const Vector2& p_end,Vector2 &r_point, Vector2 &r_normal) const; virtual real_t get_moment_of_inertia(float p_mass,const Vector2& p_scale) const; @@ -572,6 +581,7 @@ public: virtual void project_range(const Vector2& p_normal, const Matrix32& p_transform, real_t &r_min, real_t &r_max) const { /*project_range(p_normal,p_transform,r_min,r_max);*/ } virtual void get_supports(const Vector2& p_normal,Vector2 *r_supports,int & r_amount) const; + virtual bool contains_point(const Vector2& p_point) const; virtual bool intersect_segment(const Vector2& p_begin,const Vector2& p_end,Vector2 &r_point, Vector2 &r_normal) const; virtual real_t get_moment_of_inertia(float p_mass,const Vector2& p_scale) const { return 0; } diff --git a/servers/physics_2d/space_2d_sw.cpp b/servers/physics_2d/space_2d_sw.cpp index 9523e8bf8a..5aaf9a7613 100644 --- a/servers/physics_2d/space_2d_sw.cpp +++ b/servers/physics_2d/space_2d_sw.cpp @@ -45,6 +45,57 @@ _FORCE_INLINE_ static bool _match_object_type_query(CollisionObject2DSW *p_objec } + +int Physics2DDirectSpaceStateSW::intersect_point(const Vector2& p_point,ShapeResult *r_results,int p_result_max,const Set& p_exclude,uint32_t p_layer_mask,uint32_t p_object_type_mask) { + + if (p_result_max<=0) + return 0; + + Rect2 aabb; + aabb.pos=p_point-Vector2(0.00001,0.00001); + aabb.size=Vector2(0.00002,0.00002); + + int amount = space->broadphase->cull_aabb(aabb,space->intersection_query_results,Space2DSW::INTERSECTION_QUERY_MAX,space->intersection_query_subindex_results); + + int cc=0; + + for(int i=0;iintersection_query_results[i],p_layer_mask,p_object_type_mask)) + continue; + + if (p_exclude.has( space->intersection_query_results[i]->get_self())) + continue; + + const CollisionObject2DSW *col_obj=space->intersection_query_results[i]; + + if (!col_obj->is_pickable()) + continue; + + int shape_idx=space->intersection_query_subindex_results[i]; + + Shape2DSW * shape = col_obj->get_shape(shape_idx); + + Vector2 local_point = (col_obj->get_transform() * col_obj->get_shape_transform(shape_idx)).affine_inverse().xform(p_point); + + if (!shape->contains_point(local_point)) + continue; + + r_results[cc].collider_id=col_obj->get_instance_id(); + if (r_results[cc].collider_id!=0) + r_results[cc].collider=ObjectDB::get_instance(r_results[cc].collider_id); + r_results[cc].rid=col_obj->get_self(); + r_results[cc].shape=shape_idx; + r_results[cc].metadata=col_obj->get_shape_metadata(shape_idx); + + cc++; + } + + return cc; + + +} + bool Physics2DDirectSpaceStateSW::intersect_ray(const Vector2& p_from, const Vector2& p_to,RayResult &r_result,const Set& p_exclude,uint32_t p_layer_mask,uint32_t p_object_type_mask) { diff --git a/servers/physics_2d/space_2d_sw.h b/servers/physics_2d/space_2d_sw.h index 7977b19063..05b55fe807 100644 --- a/servers/physics_2d/space_2d_sw.h +++ b/servers/physics_2d/space_2d_sw.h @@ -46,6 +46,7 @@ public: Space2DSW *space; + virtual int intersect_point(const Vector2& p_point,ShapeResult *r_results,int p_result_max,const Set& p_exclude=Set(),uint32_t p_layer_mask=0xFFFFFFFF,uint32_t p_object_type_mask=TYPE_MASK_COLLISION); virtual bool intersect_ray(const Vector2& p_from, const Vector2& p_to,RayResult &r_result,const Set& p_exclude=Set(),uint32_t p_layer_mask=0xFFFFFFFF,uint32_t p_object_type_mask=TYPE_MASK_COLLISION); virtual int intersect_shape(const RID& p_shape, const Matrix32& p_xform,const Vector2& p_motion,float p_margin,ShapeResult *r_results,int p_result_max,const Set& p_exclude=Set(),uint32_t p_layer_mask=0xFFFFFFFF,uint32_t p_object_type_mask=TYPE_MASK_COLLISION); virtual bool cast_motion(const RID& p_shape, const Matrix32& p_xform,const Vector2& p_motion,float p_margin,float &p_closest_safe,float &p_closest_unsafe, const Set& p_exclude=Set(),uint32_t p_layer_mask=0xFFFFFFFF,uint32_t p_object_type_mask=TYPE_MASK_COLLISION); diff --git a/servers/physics_2d_server.h b/servers/physics_2d_server.h index 1fb47fc1d9..657e5ce441 100644 --- a/servers/physics_2d_server.h +++ b/servers/physics_2d_server.h @@ -181,6 +181,8 @@ public: }; + virtual int intersect_point(const Vector2& p_point,ShapeResult *r_results,int p_result_max,const Set& p_exclude=Set(),uint32_t p_layer_mask=0xFFFFFFFF,uint32_t p_object_type_mask=TYPE_MASK_COLLISION)=0; + virtual int intersect_shape(const RID& p_shape, const Matrix32& p_xform,const Vector2& p_motion,float p_margin,ShapeResult *r_results,int p_result_max,const Set& p_exclude=Set(),uint32_t p_layer_mask=0xFFFFFFFF,uint32_t p_object_type_mask=TYPE_MASK_COLLISION)=0; virtual bool cast_motion(const RID& p_shape, const Matrix32& p_xform,const Vector2& p_motion,float p_margin,float &p_closest_safe,float &p_closest_unsafe, const Set& p_exclude=Set(),uint32_t p_layer_mask=0xFFFFFFFF,uint32_t p_object_type_mask=TYPE_MASK_COLLISION)=0; @@ -342,6 +344,7 @@ public: virtual Matrix32 area_get_transform(RID p_area) const=0; virtual void area_set_monitorable(RID p_area,bool p_monitorable)=0; + virtual void area_set_pickable(RID p_area,bool p_pickable)=0; virtual void area_set_monitor_callback(RID p_area,Object *p_receiver,const StringName& p_method)=0; virtual void area_set_area_monitor_callback(RID p_area,Object *p_receiver,const StringName& p_method)=0; @@ -462,6 +465,8 @@ public: virtual bool body_collide_shape(RID p_body, int p_body_shape,RID p_shape, const Matrix32& p_shape_xform,const Vector2& p_motion,Vector2 *r_results,int p_result_max,int &r_result_count)=0; + virtual void body_set_pickable(RID p_body,bool p_pickable)=0; + /* JOINT API */ enum JointType { -- cgit v1.2.3 From cde55bee91322e47769a6eb34f25de95b6f19ad0 Mon Sep 17 00:00:00 2001 From: rollenrolm Date: Sun, 22 Mar 2015 10:25:18 +0100 Subject: Fix for Issue #1484: Don't strip whitespace on line comment --- tools/editor/plugins/script_editor_plugin.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/editor/plugins/script_editor_plugin.cpp b/tools/editor/plugins/script_editor_plugin.cpp index 1349d5ccab..bb9b36bb66 100644 --- a/tools/editor/plugins/script_editor_plugin.cpp +++ b/tools/editor/plugins/script_editor_plugin.cpp @@ -920,7 +920,7 @@ void ScriptEditor::_menu_option(int p_option) { String line_text = tx->get_line(i); if (line_text.begins_with("#")) - line_text = line_text.strip_edges().substr(1, line_text.length()); + line_text = line_text.substr(1, line_text.length()); else line_text = "#" + line_text; tx->set_line(i, line_text); @@ -932,7 +932,7 @@ void ScriptEditor::_menu_option(int p_option) { String line_text = tx->get_line(begin); if (line_text.begins_with("#")) - line_text = line_text.strip_edges().substr(1, line_text.length()); + line_text = line_text.substr(1, line_text.length()); else line_text = "#" + line_text; tx->set_line(begin, line_text); -- cgit v1.2.3 From dac2017dee8a58c85b8b3218a779260d3b5f4072 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sun, 22 Mar 2015 09:40:26 -0300 Subject: fixes/cleans up -input now correctly works when using viewport scaling -added function to get areas/bodies in given point -added function to get space state directly from world --- demos/2d/area_input/input.gd | 4 ---- demos/2d/area_input/input.scn | Bin 2886 -> 2886 bytes scene/main/viewport.cpp | 6 +++++- scene/resources/world.cpp | 6 ++++++ scene/resources/world.h | 2 ++ scene/resources/world_2d.cpp | 9 +++++++++ scene/resources/world_2d.h | 4 +++- servers/physics_2d_server.cpp | 31 +++++++++++++++++++++++++++++++ servers/physics_2d_server.h | 1 + 9 files changed, 57 insertions(+), 6 deletions(-) diff --git a/demos/2d/area_input/input.gd b/demos/2d/area_input/input.gd index acecd095ed..3f719fc853 100644 --- a/demos/2d/area_input/input.gd +++ b/demos/2d/area_input/input.gd @@ -1,10 +1,6 @@ extends Area2D -# member variables here, example: -# var a=2 -# var b="textvar" - #virtual from CollisionObject2D (also available as signal) func _input_event(viewport, event, shape_idx): #convert event to local coordinates diff --git a/demos/2d/area_input/input.scn b/demos/2d/area_input/input.scn index 0bb3a18834..1a2dcbc5f4 100644 Binary files a/demos/2d/area_input/input.scn and b/demos/2d/area_input/input.scn differ diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 18b8b46d90..ee400ae6d5 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -104,8 +104,10 @@ void Viewport::_update_stretch_transform() { stretch_transform.scale(scale); stretch_transform.elements[2]=size_override_margin*scale; + } else { + stretch_transform=Matrix32(); } @@ -1076,8 +1078,9 @@ Matrix32 Viewport::_get_input_pre_xform() const { ERR_FAIL_COND_V(to_screen_rect.size.x==0,pre_xf); ERR_FAIL_COND_V(to_screen_rect.size.y==0,pre_xf); - pre_xf.scale(rect.size/to_screen_rect.size); + pre_xf.elements[2]=-to_screen_rect.pos; + pre_xf.scale(rect.size/to_screen_rect.size); } else { pre_xf.elements[2]=-rect.pos; @@ -1141,6 +1144,7 @@ void Viewport::_make_input_local(InputEvent& ev) { } break; } + } diff --git a/scene/resources/world.cpp b/scene/resources/world.cpp index 880a3a32e3..30cf58bdd8 100644 --- a/scene/resources/world.cpp +++ b/scene/resources/world.cpp @@ -307,6 +307,11 @@ Ref World::get_environment() const { } +PhysicsDirectSpaceState *World::get_direct_space_state() { + + return PhysicsServer::get_singleton()->space_get_direct_state(space); +} + void World::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_space"),&World::get_space); @@ -314,6 +319,7 @@ void World::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_sound_space"),&World::get_sound_space); ObjectTypeDB::bind_method(_MD("set_environment","env:Environment"),&World::set_environment); ObjectTypeDB::bind_method(_MD("get_environment:Environment"),&World::get_environment); + ObjectTypeDB::bind_method(_MD("get_direct_space_state:PhysicsDirectSpaceState"),&World::get_direct_space_state); ADD_PROPERTY(PropertyInfo(Variant::OBJECT,"environment",PROPERTY_HINT_RESOURCE_TYPE,"Environment"),_SCS("set_environment"),_SCS("get_environment")); } diff --git a/scene/resources/world.h b/scene/resources/world.h index 60b3b99ab0..b10cadd6e0 100644 --- a/scene/resources/world.h +++ b/scene/resources/world.h @@ -75,6 +75,8 @@ public: void set_environment(const Ref& p_environment); Ref get_environment() const; + PhysicsDirectSpaceState *get_direct_space_state(); + World(); ~World(); diff --git a/scene/resources/world_2d.cpp b/scene/resources/world_2d.cpp index 0dd6a3d5e7..43a7af4bfd 100644 --- a/scene/resources/world_2d.cpp +++ b/scene/resources/world_2d.cpp @@ -352,8 +352,17 @@ void World2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_canvas"),&World2D::get_canvas); ObjectTypeDB::bind_method(_MD("get_space"),&World2D::get_space); ObjectTypeDB::bind_method(_MD("get_sound_space"),&World2D::get_sound_space); + + ObjectTypeDB::bind_method(_MD("get_direct_space_state:Physics2DDirectSpaceState"),&World2D::get_direct_space_state); + +} + +Physics2DDirectSpaceState *World2D::get_direct_space_state() { + + return Physics2DServer::get_singleton()->space_get_direct_state(space); } + World2D::World2D() { canvas = VisualServer::get_singleton()->canvas_create(); diff --git a/scene/resources/world_2d.h b/scene/resources/world_2d.h index 3feb23495d..865ec28fe9 100644 --- a/scene/resources/world_2d.h +++ b/scene/resources/world_2d.h @@ -30,7 +30,7 @@ #define WORLD_2D_H #include "resource.h" - +#include "servers/physics_2d_server.h" class SpatialIndexer2D; class VisibilityNotifier2D; @@ -68,6 +68,8 @@ public: RID get_space(); RID get_sound_space(); + Physics2DDirectSpaceState *get_direct_space_state(); + World2D(); ~World2D(); }; diff --git a/servers/physics_2d_server.cpp b/servers/physics_2d_server.cpp index 07389bc912..098f890222 100644 --- a/servers/physics_2d_server.cpp +++ b/servers/physics_2d_server.cpp @@ -289,6 +289,36 @@ Array Physics2DDirectSpaceState::_cast_motion(const Ref& p_exclude,uint32_t p_layers,uint32_t p_object_type_mask) { + + Set exclude; + for(int i=0;i ret; + ret.resize(p_max_results); + + int rc = intersect_point(p_point,ret.ptr(),ret.size(),exclude,p_layers,p_object_type_mask); + if (rc==0) + return Array(); + + Array r; + r.resize(rc); + for(int i=0;i &psq, int p_max_results){ Vector ret; @@ -336,6 +366,7 @@ Physics2DDirectSpaceState::Physics2DDirectSpaceState() { void Physics2DDirectSpaceState::_bind_methods() { + ObjectTypeDB::bind_method(_MD("intersect_point","point","max_results","exclude","layer_mask","type_mask"),&Physics2DDirectSpaceState::_intersect_point,DEFVAL(32),DEFVAL(Array()),DEFVAL(0x7FFFFFFF),DEFVAL(TYPE_MASK_COLLISION)); ObjectTypeDB::bind_method(_MD("intersect_ray:Dictionary","from","to","exclude","layer_mask","type_mask"),&Physics2DDirectSpaceState::_intersect_ray,DEFVAL(Array()),DEFVAL(0x7FFFFFFF),DEFVAL(TYPE_MASK_COLLISION)); ObjectTypeDB::bind_method(_MD("intersect_shape","shape:Physics2DShapeQueryParameters","max_results"),&Physics2DDirectSpaceState::_intersect_shape,DEFVAL(32)); ObjectTypeDB::bind_method(_MD("cast_motion","shape:Physics2DShapeQueryParameters"),&Physics2DDirectSpaceState::_cast_motion); diff --git a/servers/physics_2d_server.h b/servers/physics_2d_server.h index 657e5ce441..01670ace7e 100644 --- a/servers/physics_2d_server.h +++ b/servers/physics_2d_server.h @@ -137,6 +137,7 @@ class Physics2DDirectSpaceState : public Object { Dictionary _intersect_ray(const Vector2& p_from, const Vector2& p_to,const Vector& p_exclude=Vector(),uint32_t p_layers=0,uint32_t p_object_type_mask=TYPE_MASK_COLLISION); + Array _intersect_point(const Vector2& p_point,int p_max_results=32,const Vector& p_exclude=Vector(),uint32_t p_layers=0,uint32_t p_object_type_mask=TYPE_MASK_COLLISION); Array _intersect_shape(const Ref &p_shape_query,int p_max_results=32); Array _cast_motion(const Ref &p_shape_query); Array _collide_shape(const Ref &p_shape_query,int p_max_results=32); -- cgit v1.2.3 From a93e33f5c8afc8ce2e9c1674718ff103bfae49b0 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sun, 22 Mar 2015 10:33:58 -0300 Subject: added spatial and node2d helper methods to perform operations such as translaiton, rotation, etc directly on nodes. --- scene/2d/light_2d.cpp | 10 ++--- scene/2d/light_2d.h | 2 +- scene/2d/node_2d.cpp | 49 ++++++++++++++++------- scene/2d/node_2d.h | 8 +++- scene/3d/camera.cpp | 18 --------- scene/3d/camera.h | 2 - scene/3d/spatial.cpp | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++ scene/3d/spatial.h | 14 +++++++ 8 files changed, 166 insertions(+), 43 deletions(-) diff --git a/scene/2d/light_2d.cpp b/scene/2d/light_2d.cpp index 8f6907798f..949c952b39 100644 --- a/scene/2d/light_2d.cpp +++ b/scene/2d/light_2d.cpp @@ -23,7 +23,7 @@ Rect2 Light2D::get_item_rect() const { Size2i s; - s = texture->get_size()*scale; + s = texture->get_size()*_scale; Point2i ofs=texture_offset; ofs-=s/2; @@ -98,8 +98,8 @@ float Light2D::get_height() const { void Light2D::set_scale( float p_scale) { - scale=p_scale; - VS::get_singleton()->canvas_light_set_scale(canvas_light,scale); + _scale=p_scale; + VS::get_singleton()->canvas_light_set_scale(canvas_light,_scale); item_rect_changed(); } @@ -107,7 +107,7 @@ void Light2D::set_scale( float p_scale) { float Light2D::get_scale() const { - return scale; + return _scale; } void Light2D::set_z_range_min( int p_min_z) { @@ -322,7 +322,7 @@ Light2D::Light2D() { shadow=false; color=Color(1,1,1); height=0; - scale=1.0; + _scale=1.0; z_min=-1024; z_max=1024; layer_min=0; diff --git a/scene/2d/light_2d.h b/scene/2d/light_2d.h index 6eb6ad5237..95196af5e0 100644 --- a/scene/2d/light_2d.h +++ b/scene/2d/light_2d.h @@ -12,7 +12,7 @@ private: bool shadow; Color color; float height; - float scale; + float _scale; int z_min; int z_max; int layer_min; diff --git a/scene/2d/node_2d.cpp b/scene/2d/node_2d.cpp index 36b6b220b3..0b098f0cad 100644 --- a/scene/2d/node_2d.cpp +++ b/scene/2d/node_2d.cpp @@ -65,7 +65,7 @@ void Node2D::edit_set_state(const Variant& p_state) { pos = state[0]; angle = state[1]; - scale = state[2]; + _scale = state[2]; _update_transform(); _change_notify("transform/rot"); _change_notify("transform/scale"); @@ -93,11 +93,11 @@ void Node2D::edit_set_rect(const Rect2& p_edit_rect) { Point2 new_pos = p_edit_rect.pos + p_edit_rect.size*zero_offset;//p_edit_rect.pos - r.pos; Matrix32 postxf; - postxf.set_rotation_and_scale(angle,scale); + postxf.set_rotation_and_scale(angle,_scale); new_pos = postxf.xform(new_pos); pos+=new_pos; - scale*=new_scale; + _scale*=new_scale; _update_transform(); _change_notify("transform/scale"); @@ -118,14 +118,14 @@ void Node2D::_update_xform_values() { pos=_mat.elements[2]; angle=_mat.get_rotation(); - scale=_mat.get_scale(); + _scale=_mat.get_scale(); _xform_dirty=false; } void Node2D::_update_transform() { Matrix32 mat(angle,pos); - _mat.set_rotation_and_scale(angle,scale); + _mat.set_rotation_and_scale(angle,_scale); _mat.elements[2]=pos; VisualServer::get_singleton()->canvas_item_set_transform(get_canvas_item(),_mat); @@ -161,11 +161,11 @@ void Node2D::set_scale(const Size2& p_scale) { if (_xform_dirty) ((Node2D*)this)->_update_xform_values(); - scale=p_scale; - if (scale.x==0) - scale.x=CMP_EPSILON; - if (scale.y==0) - scale.y=CMP_EPSILON; + _scale=p_scale; + if (_scale.x==0) + _scale.x=CMP_EPSILON; + if (_scale.y==0) + _scale.y=CMP_EPSILON; _update_transform(); _change_notify("transform/scale"); @@ -187,7 +187,7 @@ Size2 Node2D::get_scale() const { if (_xform_dirty) ((Node2D*)this)->_update_xform_values(); - return scale; + return _scale; } void Node2D::_set_rotd(float p_angle) { @@ -224,11 +224,27 @@ Rect2 Node2D::get_item_rect() const { return Rect2(Point2(-32,-32),Size2(64,64)); } -void Node2D::rotate(float p_degrees) { +void Node2D::rotate(float p_radians) { - set_rot( get_rot() + p_degrees); + set_rot( get_rot() + p_radians); } +void Node2D::translate(const Vector2& p_amount) { + + set_pos( get_pos() + p_amount ); +} + +void Node2D::global_translate(const Vector2& p_amount) { + + set_global_pos( get_global_pos() + p_amount ); +} + +void Node2D::scale(const Vector2& p_amount) { + + set_scale( get_scale() * p_amount ); +} + + void Node2D::move_x(float p_delta,bool p_scaled){ Matrix32 t = get_transform(); @@ -345,9 +361,12 @@ void Node2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_rot"),&Node2D::get_rot); ObjectTypeDB::bind_method(_MD("get_scale"),&Node2D::get_scale); - ObjectTypeDB::bind_method(_MD("rotate","degrees"),&Node2D::rotate); + ObjectTypeDB::bind_method(_MD("rotate","radians"),&Node2D::rotate); ObjectTypeDB::bind_method(_MD("move_local_x","delta","scaled"),&Node2D::move_x,DEFVAL(false)); ObjectTypeDB::bind_method(_MD("move_local_y","delta","scaled"),&Node2D::move_y,DEFVAL(false)); + ObjectTypeDB::bind_method(_MD("translate","offset"),&Node2D::translate); + ObjectTypeDB::bind_method(_MD("global_translate","offset"),&Node2D::global_translate); + ObjectTypeDB::bind_method(_MD("scale","ratio"),&Node2D::scale); ObjectTypeDB::bind_method(_MD("set_global_pos","pos"),&Node2D::set_global_pos); ObjectTypeDB::bind_method(_MD("get_global_pos"),&Node2D::get_global_pos); @@ -379,7 +398,7 @@ Node2D::Node2D() { angle=0; - scale=Vector2(1,1); + _scale=Vector2(1,1); _xform_dirty=false; z=0; z_relative=true; diff --git a/scene/2d/node_2d.h b/scene/2d/node_2d.h index 7b059008c2..39a1061195 100644 --- a/scene/2d/node_2d.h +++ b/scene/2d/node_2d.h @@ -37,7 +37,7 @@ class Node2D : public CanvasItem { Point2 pos; float angle; - Size2 scale; + Size2 _scale; int z; bool z_relative; @@ -72,9 +72,12 @@ public: void set_rot(float p_angle); void set_scale(const Size2& p_scale); - void rotate(float p_degrees); + void rotate(float p_radians); void move_x(float p_delta,bool p_scaled=false); void move_y(float p_delta,bool p_scaled=false); + void translate(const Vector2& p_amount); + void global_translate(const Vector2& p_amount); + void scale(const Vector2& p_amount); Point2 get_pos() const; float get_rot() const; @@ -96,6 +99,7 @@ public: Matrix32 get_relative_transform(const Node *p_parent) const; + Matrix32 get_transform() const; Node2D(); diff --git a/scene/3d/camera.cpp b/scene/3d/camera.cpp index 1109139180..db69182ca0 100644 --- a/scene/3d/camera.cpp +++ b/scene/3d/camera.cpp @@ -680,8 +680,6 @@ void Camera::_bind_methods() { ObjectTypeDB::bind_method( _MD("get_projection"),&Camera::get_projection ); ObjectTypeDB::bind_method( _MD("set_visible_layers","mask"),&Camera::set_visible_layers ); ObjectTypeDB::bind_method( _MD("get_visible_layers"),&Camera::get_visible_layers ); - ObjectTypeDB::bind_method( _MD("look_at","target","up"),&Camera::look_at ); - ObjectTypeDB::bind_method( _MD("look_at_from_pos","pos","target","up"),&Camera::look_at_from_pos ); ObjectTypeDB::bind_method(_MD("set_environment","env:Environment"),&Camera::set_environment); ObjectTypeDB::bind_method(_MD("get_environment:Environment"),&Camera::get_environment); ObjectTypeDB::bind_method(_MD("set_keep_aspect_mode","mode"),&Camera::set_keep_aspect_mode); @@ -752,22 +750,6 @@ Vector Camera::get_frustum() const { -void Camera::look_at(const Vector3& p_target, const Vector3& p_up_normal) { - - Transform lookat; - lookat.origin=get_camera_transform().origin; - lookat=lookat.looking_at(p_target,p_up_normal); - set_global_transform(lookat); -} - -void Camera::look_at_from_pos(const Vector3& p_pos,const Vector3& p_target, const Vector3& p_up_normal) { - - Transform lookat; - lookat.origin=p_pos; - lookat=lookat.looking_at(p_target,p_up_normal); - set_global_transform(lookat); - -} void Camera::set_v_offset(float p_offset) { diff --git a/scene/3d/camera.h b/scene/3d/camera.h index 950688dfda..de03282021 100644 --- a/scene/3d/camera.h +++ b/scene/3d/camera.h @@ -139,8 +139,6 @@ public: void set_keep_aspect_mode(KeepAspect p_aspect); KeepAspect get_keep_aspect_mode() const; - void look_at(const Vector3& p_target, const Vector3& p_up_normal); - void look_at_from_pos(const Vector3& p_pos,const Vector3& p_target, const Vector3& p_up_normal); void set_v_offset(float p_offset); float get_v_offset() const; diff --git a/scene/3d/spatial.cpp b/scene/3d/spatial.cpp index a5b009823c..edca62ece5 100644 --- a/scene/3d/spatial.cpp +++ b/scene/3d/spatial.cpp @@ -593,6 +593,91 @@ bool Spatial::_is_visible_() const { return !is_hidden(); } +void Spatial::rotate(const Vector3& p_normal,float p_radians) { + + Transform t =get_transform(); + t.basis.rotate(p_normal,p_radians); + set_transform(t); +} + +void Spatial::rotate_x(float p_radians) { + + Transform t =get_transform(); + t.basis.rotate(Vector3(1,0,0),p_radians); + set_transform(t); + +} + +void Spatial::rotate_y(float p_radians){ + + Transform t =get_transform(); + t.basis.rotate(Vector3(0,1,0),p_radians); + set_transform(t); + +} +void Spatial::rotate_z(float p_radians){ + + Transform t =get_transform(); + t.basis.rotate(Vector3(0,0,1),p_radians); + set_transform(t); + +} + +void Spatial::translate(const Vector3& p_offset){ + + Transform t =get_transform(); + t.origin+=p_offset; + set_transform(t); + +} +void Spatial::scale(const Vector3& p_ratio){ + + Transform t =get_transform(); + t.basis.scale(p_ratio); + set_transform(t); + +} +void Spatial::global_rotate(const Vector3& p_normal,float p_radians){ + + Matrix3 rotation(p_normal,p_radians); + Transform t = get_global_transform(); + t.basis= rotation * t.basis; + set_global_transform(t); + +} +void Spatial::global_translate(const Vector3& p_offset){ + Transform t = get_global_transform(); + t.origin+=p_offset; + set_global_transform(t); + +} + +void Spatial::orthonormalize() { + + Transform t = get_transform(); + t.orthonormalize(); + set_transform(t); + +} + + +void Spatial::look_at(const Vector3& p_target, const Vector3& p_up_normal) { + + Transform lookat; + lookat.origin=get_global_transform().origin; + lookat=lookat.looking_at(p_target,p_up_normal); + set_global_transform(lookat); +} + +void Spatial::look_at_from_pos(const Vector3& p_pos,const Vector3& p_target, const Vector3& p_up_normal) { + + Transform lookat; + lookat.origin=p_pos; + lookat=lookat.looking_at(p_target,p_up_normal); + set_global_transform(lookat); + +} + void Spatial::_bind_methods() { @@ -633,6 +718,27 @@ void Spatial::_bind_methods() { ObjectTypeDB::bind_method(_MD("_set_visible_"), &Spatial::_set_visible_); ObjectTypeDB::bind_method(_MD("_is_visible_"), &Spatial::_is_visible_); + void rotate(const Vector3& p_normal,float p_radians); + void rotate_x(float p_radians); + void rotate_y(float p_radians); + void rotate_z(float p_radians); + void translate(const Vector3& p_offset); + void scale(const Vector3& p_ratio); + void global_rotate(const Vector3& p_normal,float p_radians); + void global_translate(const Vector3& p_offset); + + ObjectTypeDB::bind_method( _MD("rotate","normal","radians"),&Spatial::rotate ); + ObjectTypeDB::bind_method( _MD("global_rotate","normal","radians"),&Spatial::global_rotate ); + ObjectTypeDB::bind_method( _MD("rotate_x","radians"),&Spatial::rotate_x ); + ObjectTypeDB::bind_method( _MD("rotate_y","radians"),&Spatial::rotate_y ); + ObjectTypeDB::bind_method( _MD("rotate_z","radians"),&Spatial::rotate_z ); + ObjectTypeDB::bind_method( _MD("translate","offset"),&Spatial::translate ); + ObjectTypeDB::bind_method( _MD("global_translate","offset"),&Spatial::global_translate ); + ObjectTypeDB::bind_method( _MD("orthonormalize"),&Spatial::orthonormalize ); + + ObjectTypeDB::bind_method( _MD("look_at","target","up"),&Spatial::look_at ); + ObjectTypeDB::bind_method( _MD("look_at_from_pos","pos","target","up"),&Spatial::look_at_from_pos ); + BIND_CONSTANT( NOTIFICATION_TRANSFORM_CHANGED ); BIND_CONSTANT( NOTIFICATION_ENTER_WORLD ); BIND_CONSTANT( NOTIFICATION_EXIT_WORLD ); diff --git a/scene/3d/spatial.h b/scene/3d/spatial.h index 49ecf5779b..d7addbb792 100644 --- a/scene/3d/spatial.h +++ b/scene/3d/spatial.h @@ -167,6 +167,20 @@ public: Transform get_relative_transform(const Node *p_parent) const; + void rotate(const Vector3& p_normal,float p_radians); + void rotate_x(float p_radians); + void rotate_y(float p_radians); + void rotate_z(float p_radians); + void translate(const Vector3& p_offset); + void scale(const Vector3& p_ratio); + void global_rotate(const Vector3& p_normal,float p_radians); + void global_translate(const Vector3& p_offset); + + void look_at(const Vector3& p_target, const Vector3& p_up_normal); + void look_at_from_pos(const Vector3& p_pos,const Vector3& p_target, const Vector3& p_up_normal); + + void orthonormalize(); + void show(); void hide(); bool is_visible() const; -- cgit v1.2.3 From 92ab362afae275ac26ba24db88395d6d4977515d Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sun, 22 Mar 2015 10:39:32 -0300 Subject: avoid function naming conflict on light scale --- scene/2d/light_2d.cpp | 10 +++++----- scene/2d/light_2d.h | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/scene/2d/light_2d.cpp b/scene/2d/light_2d.cpp index 949c952b39..4abb7e5436 100644 --- a/scene/2d/light_2d.cpp +++ b/scene/2d/light_2d.cpp @@ -96,7 +96,7 @@ float Light2D::get_height() const { return height; } -void Light2D::set_scale( float p_scale) { +void Light2D::set_texture_scale( float p_scale) { _scale=p_scale; VS::get_singleton()->canvas_light_set_scale(canvas_light,_scale); @@ -105,7 +105,7 @@ void Light2D::set_scale( float p_scale) { } -float Light2D::get_scale() const { +float Light2D::get_texture_scale() const { return _scale; } @@ -260,8 +260,8 @@ void Light2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_height","height"),&Light2D::set_height); ObjectTypeDB::bind_method(_MD("get_height"),&Light2D::get_height); - ObjectTypeDB::bind_method(_MD("set_scale","scale"),&Light2D::set_scale); - ObjectTypeDB::bind_method(_MD("get_scale"),&Light2D::get_scale); + ObjectTypeDB::bind_method(_MD("set_texture_scale","texture_scale"),&Light2D::set_texture_scale); + ObjectTypeDB::bind_method(_MD("get_texture_scale"),&Light2D::get_texture_scale); ObjectTypeDB::bind_method(_MD("set_z_range_min","z"),&Light2D::set_z_range_min); @@ -298,7 +298,7 @@ void Light2D::_bind_methods() { ADD_PROPERTY( PropertyInfo(Variant::BOOL,"enabled"),_SCS("set_enabled"),_SCS("is_enabled")); ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"texture",PROPERTY_HINT_RESOURCE_TYPE,"Texture"),_SCS("set_texture"),_SCS("get_texture")); ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"offset"),_SCS("set_texture_offset"),_SCS("get_texture_offset")); - ADD_PROPERTY( PropertyInfo(Variant::REAL,"scale",PROPERTY_HINT_RANGE,"0.01,4096,0.01"),_SCS("set_scale"),_SCS("get_scale")); + ADD_PROPERTY( PropertyInfo(Variant::REAL,"scale",PROPERTY_HINT_RANGE,"0.01,4096,0.01"),_SCS("set_texture_scale"),_SCS("get_texture_scale")); ADD_PROPERTY( PropertyInfo(Variant::COLOR,"color"),_SCS("set_color"),_SCS("get_color")); ADD_PROPERTY( PropertyInfo(Variant::BOOL,"subtract"),_SCS("set_subtract_mode"),_SCS("get_subtract_mode")); ADD_PROPERTY( PropertyInfo(Variant::REAL,"range/height"),_SCS("set_height"),_SCS("get_height")); diff --git a/scene/2d/light_2d.h b/scene/2d/light_2d.h index 95196af5e0..6cfb055fa9 100644 --- a/scene/2d/light_2d.h +++ b/scene/2d/light_2d.h @@ -51,8 +51,8 @@ public: void set_height( float p_height); float get_height() const; - void set_scale( float p_scale); - float get_scale() const; + void set_texture_scale( float p_scale); + float get_texture_scale() const; void set_z_range_min( int p_min_z); int get_z_range_min() const; -- cgit v1.2.3 From 78694d85425b35d2c6c0e0a4b0ef3e57375553c6 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sun, 22 Mar 2015 11:52:07 -0300 Subject: gui in 3D demo now uses area for input --- demos/viewport/gui_in_3d/gui_3d.gd | 49 ++++++++++++++++++------------------ demos/viewport/gui_in_3d/gui_3d.scn | Bin 3498 -> 4668 bytes scene/3d/spatial.cpp | 7 ++++++ scene/3d/spatial.h | 1 + 4 files changed, 33 insertions(+), 24 deletions(-) diff --git a/demos/viewport/gui_in_3d/gui_3d.gd b/demos/viewport/gui_in_3d/gui_3d.gd index 5309db9acb..c2a9df0069 100644 --- a/demos/viewport/gui_in_3d/gui_3d.gd +++ b/demos/viewport/gui_in_3d/gui_3d.gd @@ -7,38 +7,39 @@ extends Spatial var prev_pos=null -func _input(ev): - if (ev.type in [InputEvent.MOUSE_BUTTON,InputEvent.MOUSE_MOTION]): - var pos = ev.pos - var rfrom = get_node("camera").project_ray_origin(pos) - var rnorm = get_node("camera").project_ray_normal(pos) + +func _input( ev ): + #all other (non-mouse) events + if (not ev.type in [InputEvent.MOUSE_BUTTON,InputEvent.MOUSE_MOTION,InputEvent.SCREEN_DRAG,InputEvent.SCREEN_TOUCH]): + get_node("viewport").input(ev) - #simple collision test against aligned plane - #for game UIs of this kind consider more complex collision against plane - var p = Plane(Vector3(0,0,1),0).intersects_ray(rfrom,rnorm) - if (p==null): - return - - pos.x=(p.x+1.5)*100 - pos.y=(-p.y+0.75)*100 - ev.pos=pos - ev.global_pos=pos - if (prev_pos==null): - prev_pos=pos - if (ev.type==InputEvent.MOUSE_MOTION): - ev.relative_pos=pos-prev_pos + +#mouse events for area +func _on_area_input_event( camera, ev, click_pos, click_normal, shape_idx ): + + #use click pos (click in 3d space, convert to area space + var pos = get_node("area").get_global_transform().affine_inverse() * click_pos + #convert to 2D + pos = Vector2(pos.x,pos.y) + #convert to viewport coordinate system + pos.x=(pos.x+1.5)*100 + pos.y=(-pos.y+0.75)*100 + #set to event + ev.pos=pos + ev.global_pos=pos + if (prev_pos==null): prev_pos=pos + if (ev.type==InputEvent.MOUSE_MOTION): + ev.relative_pos=pos-prev_pos + prev_pos=pos get_node("viewport").input(ev) - - + func _ready(): # Initalization here - get_node("quad").get_material_override().set_texture(FixedMaterial.PARAM_DIFFUSE, get_node("viewport").get_render_target_texture() ) + get_node("area/quad").get_material_override().set_texture(FixedMaterial.PARAM_DIFFUSE, get_node("viewport").get_render_target_texture() ) set_process_input(true) - pass - diff --git a/demos/viewport/gui_in_3d/gui_3d.scn b/demos/viewport/gui_in_3d/gui_3d.scn index df8f7d6dc5..c69d4dc73f 100644 Binary files a/demos/viewport/gui_in_3d/gui_3d.scn and b/demos/viewport/gui_in_3d/gui_3d.scn differ diff --git a/scene/3d/spatial.cpp b/scene/3d/spatial.cpp index edca62ece5..6e11855543 100644 --- a/scene/3d/spatial.cpp +++ b/scene/3d/spatial.cpp @@ -660,6 +660,12 @@ void Spatial::orthonormalize() { } +void Spatial::set_identity() { + + set_transform(Transform()); + +} + void Spatial::look_at(const Vector3& p_target, const Vector3& p_up_normal) { @@ -735,6 +741,7 @@ void Spatial::_bind_methods() { ObjectTypeDB::bind_method( _MD("translate","offset"),&Spatial::translate ); ObjectTypeDB::bind_method( _MD("global_translate","offset"),&Spatial::global_translate ); ObjectTypeDB::bind_method( _MD("orthonormalize"),&Spatial::orthonormalize ); + ObjectTypeDB::bind_method( _MD("set_identity"),&Spatial::set_identity ); ObjectTypeDB::bind_method( _MD("look_at","target","up"),&Spatial::look_at ); ObjectTypeDB::bind_method( _MD("look_at_from_pos","pos","target","up"),&Spatial::look_at_from_pos ); diff --git a/scene/3d/spatial.h b/scene/3d/spatial.h index d7addbb792..f2cde8f1e6 100644 --- a/scene/3d/spatial.h +++ b/scene/3d/spatial.h @@ -180,6 +180,7 @@ public: void look_at_from_pos(const Vector3& p_pos,const Vector3& p_target, const Vector3& p_up_normal); void orthonormalize(); + void set_identity(); void show(); void hide(); -- cgit v1.2.3 From 1e4841dc522585904d0b1564ddbda5fe913e890e Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sun, 22 Mar 2015 12:52:47 -0300 Subject: drag & drop demo (GUI) --- demos/gui/drag_and_drop/drag_and_drop.scn | Bin 0 -> 2596 bytes demos/gui/drag_and_drop/drag_drop_script.gd | 27 +++++++++++++++++++++++++++ demos/gui/drag_and_drop/engine.cfg | 4 ++++ scene/gui/color_picker.cpp | 1 + 4 files changed, 32 insertions(+) create mode 100644 demos/gui/drag_and_drop/drag_and_drop.scn create mode 100644 demos/gui/drag_and_drop/drag_drop_script.gd create mode 100644 demos/gui/drag_and_drop/engine.cfg diff --git a/demos/gui/drag_and_drop/drag_and_drop.scn b/demos/gui/drag_and_drop/drag_and_drop.scn new file mode 100644 index 0000000000..f2122a459e Binary files /dev/null and b/demos/gui/drag_and_drop/drag_and_drop.scn differ diff --git a/demos/gui/drag_and_drop/drag_drop_script.gd b/demos/gui/drag_and_drop/drag_drop_script.gd new file mode 100644 index 0000000000..a99b963efa --- /dev/null +++ b/demos/gui/drag_and_drop/drag_drop_script.gd @@ -0,0 +1,27 @@ + +extends ColorPickerButton + +# member variables here, example: +# var a=2 +# var b="textvar" +func get_drag_data(pos): + + #use another control as drag preview + var cpb = ColorPickerButton.new() + cpb.set_color( get_color() ) + cpb.set_size(Vector2(50,50)) + set_drag_preview(cpb) + #return color as drag data + return get_color() + +func can_drop_data(pos, data): + return typeof(data)==TYPE_COLOR + +func drop_data(pos, data): + set_color(data) + +func _ready(): + # Initialization here + pass + + diff --git a/demos/gui/drag_and_drop/engine.cfg b/demos/gui/drag_and_drop/engine.cfg new file mode 100644 index 0000000000..448939c61d --- /dev/null +++ b/demos/gui/drag_and_drop/engine.cfg @@ -0,0 +1,4 @@ +[application] + +name="Drag & Drop (GUI)" +main_scene="res://drag_and_drop.scn" diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp index 193649c815..d944b804a5 100644 --- a/scene/gui/color_picker.cpp +++ b/scene/gui/color_picker.cpp @@ -352,6 +352,7 @@ void ColorPickerButton::set_color(const Color& p_color){ picker->set_color(p_color); + update(); } Color ColorPickerButton::get_color() const{ -- cgit v1.2.3 From 8c91dadff7422c3f6ba5b259634e9ae64b5e270d Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sun, 22 Mar 2015 13:01:34 -0300 Subject: minor comments --- demos/gui/drag_and_drop/drag_and_drop.scn | Bin 2596 -> 2594 bytes demos/gui/drag_and_drop/drag_drop_script.gd | 17 +++++++---------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/demos/gui/drag_and_drop/drag_and_drop.scn b/demos/gui/drag_and_drop/drag_and_drop.scn index f2122a459e..94a25cc53e 100644 Binary files a/demos/gui/drag_and_drop/drag_and_drop.scn and b/demos/gui/drag_and_drop/drag_and_drop.scn differ diff --git a/demos/gui/drag_and_drop/drag_drop_script.gd b/demos/gui/drag_and_drop/drag_drop_script.gd index a99b963efa..21a737ce1a 100644 --- a/demos/gui/drag_and_drop/drag_drop_script.gd +++ b/demos/gui/drag_and_drop/drag_drop_script.gd @@ -1,27 +1,24 @@ extends ColorPickerButton -# member variables here, example: -# var a=2 -# var b="textvar" + +#virtual function func get_drag_data(pos): - #use another control as drag preview + #use another colorpicker as drag preview var cpb = ColorPickerButton.new() cpb.set_color( get_color() ) cpb.set_size(Vector2(50,50)) set_drag_preview(cpb) #return color as drag data return get_color() - + +#virtual function func can_drop_data(pos, data): return typeof(data)==TYPE_COLOR - + +#virtual function func drop_data(pos, data): set_color(data) -func _ready(): - # Initialization here - pass - -- cgit v1.2.3 From e9f94ce8d2cc6805e74fffdf733e6dc5b5c530f5 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sun, 22 Mar 2015 15:11:19 -0300 Subject: fix area center of gravity --- servers/physics/body_sw.cpp | 2 +- servers/physics_2d/body_2d_sw.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/servers/physics/body_sw.cpp b/servers/physics/body_sw.cpp index 725a440b59..c7c20a8bd1 100644 --- a/servers/physics/body_sw.cpp +++ b/servers/physics/body_sw.cpp @@ -358,7 +358,7 @@ void BodySW::_compute_area_gravity(const AreaSW *p_area) { if (p_area->is_gravity_point()) { - gravity = (p_area->get_gravity_vector() - get_transform().get_origin()).normalized() * p_area->get_gravity(); + gravity = (p_area->get_transform().xform(p_area->get_gravity_vector()) - get_transform().get_origin()).normalized() * p_area->get_gravity(); } else { gravity = p_area->get_gravity_vector() * p_area->get_gravity(); diff --git a/servers/physics_2d/body_2d_sw.cpp b/servers/physics_2d/body_2d_sw.cpp index 1cfe9a6ab9..06d466ace8 100644 --- a/servers/physics_2d/body_2d_sw.cpp +++ b/servers/physics_2d/body_2d_sw.cpp @@ -379,7 +379,7 @@ void Body2DSW::_compute_area_gravity(const Area2DSW *p_area) { if (p_area->is_gravity_point()) { - gravity = (p_area->get_transform().get_origin()+p_area->get_gravity_vector() - get_transform().get_origin()).normalized() * p_area->get_gravity(); + gravity = (p_area->get_transform().xform(p_area->get_gravity_vector()) - get_transform().get_origin()).normalized() * p_area->get_gravity(); } else { gravity = p_area->get_gravity_vector() * p_area->get_gravity(); -- cgit v1.2.3 From 182c86de3f9ca4bde72b61674e4b9e9757182be3 Mon Sep 17 00:00:00 2001 From: John Watson Date: Sun, 22 Mar 2015 14:05:24 -0700 Subject: Reverted change to classHint Using `char wmclass[] = "Godot"` causes `xprop` to report the following for WM_CLASS: `WM_CLASS(STRING) = "\200\326\322\365\377\177", "\200\326\322\365\377\177"` This makes the Unity window manager fail to connect the running app with the icon on the launcher. --- platform/x11/os_x11.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index 8196281732..e974fe5f9f 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -299,9 +299,8 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi /* set the name and class hints for the window manager to use */ classHint = XAllocClassHint(); if (classHint) { - char wmclass[] = "Godot"; - classHint->res_name = wmclass; - classHint->res_class = wmclass; + classHint->res_name = "Godot"; + classHint->res_class = "Godot"; } XSetClassHint(x11_display, x11_window, classHint); XFree(classHint); -- cgit v1.2.3 From 23e13ce3c209da13a7bbf771cf31588045ad432e Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sun, 22 Mar 2015 19:00:50 -0300 Subject: fixes to new window management API -needs testing on Linux -needs testing on Windows -NEED SOMEONE TO IMPLEMENT IT ON OSX!! PLEASE HELP! --- core/bind/core_bind.cpp | 68 ++++---- core/bind/core_bind.h | 24 +-- core/os/os.h | 36 ++--- demos/misc/window_management/control.gd | 38 ++--- drivers/windows/dir_access_windows.h | 1 + platform/windows/os_windows.cpp | 188 ++++++++++++++++++++++ platform/windows/os_windows.h | 36 ++++- platform/x11/os_x11.cpp | 31 ++-- platform/x11/os_x11.h | 28 ++-- tools/editor/io_plugins/editor_import_collada.cpp | 4 +- 10 files changed, 339 insertions(+), 115 deletions(-) diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index 858f5cec27..5839467388 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -176,17 +176,17 @@ bool _OS::is_video_mode_fullscreen(int p_screen) const { } -#ifdef NEW_WM_API + int _OS::get_screen_count() const { return OS::get_singleton()->get_screen_count(); } -int _OS::get_screen() const { - return OS::get_singleton()->get_screen(); +int _OS::get_current_screen() const { + return OS::get_singleton()->get_current_screen(); } -void _OS::set_screen(int p_screen) { - OS::get_singleton()->set_screen(p_screen); +void _OS::set_current_screen(int p_screen) { + OS::get_singleton()->set_current_screen(p_screen); } Point2 _OS::get_screen_position(int p_screen) const { @@ -213,38 +213,38 @@ void _OS::set_window_size(const Size2& p_size) { OS::get_singleton()->set_window_size(p_size); } -void _OS::set_fullscreen(bool p_enabled) { - OS::get_singleton()->set_fullscreen(p_enabled); +void _OS::set_window_fullscreen(bool p_enabled) { + OS::get_singleton()->set_window_fullscreen(p_enabled); } -bool _OS::is_fullscreen() const { - return OS::get_singleton()->is_fullscreen(); +bool _OS::is_window_fullscreen() const { + return OS::get_singleton()->is_window_fullscreen(); } -void _OS::set_resizable(bool p_enabled) { - OS::get_singleton()->set_resizable(p_enabled); +void _OS::set_window_resizable(bool p_enabled) { + OS::get_singleton()->set_window_resizable(p_enabled); } -bool _OS::is_resizable() const { - return OS::get_singleton()->is_resizable(); +bool _OS::is_window_resizable() const { + return OS::get_singleton()->is_window_resizable(); } -void _OS::set_minimized(bool p_enabled) { - OS::get_singleton()->set_minimized(p_enabled); +void _OS::set_window_minimized(bool p_enabled) { + OS::get_singleton()->set_window_minimized(p_enabled); } -bool _OS::is_minimized() const { - return OS::get_singleton()->is_minimized(); +bool _OS::is_window_minimized() const { + return OS::get_singleton()->is_window_minimized(); } -void _OS::set_maximized(bool p_enabled) { - OS::get_singleton()->set_maximized(p_enabled); +void _OS::set_window_maximized(bool p_enabled) { + OS::get_singleton()->set_window_maximized(p_enabled); } -bool _OS::is_maximized() const { - return OS::get_singleton()->is_maximized(); +bool _OS::is_window_maximized() const { + return OS::get_singleton()->is_window_maximized(); } -#endif + void _OS::set_use_file_access_save_and_swap(bool p_enable) { @@ -706,25 +706,25 @@ void _OS::_bind_methods() { ObjectTypeDB::bind_method(_MD("is_video_mode_resizable","screen"),&_OS::is_video_mode_resizable,DEFVAL(0)); ObjectTypeDB::bind_method(_MD("get_fullscreen_mode_list","screen"),&_OS::get_fullscreen_mode_list,DEFVAL(0)); -#ifdef NEW_WM_API + ObjectTypeDB::bind_method(_MD("get_screen_count"),&_OS::get_screen_count); - ObjectTypeDB::bind_method(_MD("get_screen"),&_OS::get_screen); - ObjectTypeDB::bind_method(_MD("set_screen"),&_OS::set_screen); + ObjectTypeDB::bind_method(_MD("get_current_screen"),&_OS::get_current_screen); + ObjectTypeDB::bind_method(_MD("set_current_screen"),&_OS::set_current_screen); ObjectTypeDB::bind_method(_MD("get_screen_position"),&_OS::get_screen_position,DEFVAL(0)); ObjectTypeDB::bind_method(_MD("get_screen_size"),&_OS::get_screen_size,DEFVAL(0)); ObjectTypeDB::bind_method(_MD("get_window_position"),&_OS::get_window_position); ObjectTypeDB::bind_method(_MD("set_window_position"),&_OS::set_window_position); ObjectTypeDB::bind_method(_MD("get_window_size"),&_OS::get_window_size); ObjectTypeDB::bind_method(_MD("set_window_size"),&_OS::set_window_size); - ObjectTypeDB::bind_method(_MD("set_fullscreen","enabled"),&_OS::set_fullscreen); - ObjectTypeDB::bind_method(_MD("is_fullscreen"),&_OS::is_fullscreen); - ObjectTypeDB::bind_method(_MD("set_resizable","enabled"),&_OS::set_resizable); - ObjectTypeDB::bind_method(_MD("is_resizable"),&_OS::is_resizable); - ObjectTypeDB::bind_method(_MD("set_minimized", "enabled"),&_OS::set_minimized); - ObjectTypeDB::bind_method(_MD("is_minimized"),&_OS::is_minimized); - ObjectTypeDB::bind_method(_MD("set_maximized", "enabled"),&_OS::set_maximized); - ObjectTypeDB::bind_method(_MD("is_maximized"),&_OS::is_maximized); -#endif + ObjectTypeDB::bind_method(_MD("set_window_fullscreen","enabled"),&_OS::set_window_fullscreen); + ObjectTypeDB::bind_method(_MD("is_window_fullscreen"),&_OS::is_window_fullscreen); + ObjectTypeDB::bind_method(_MD("set_window_resizable","enabled"),&_OS::set_window_resizable); + ObjectTypeDB::bind_method(_MD("is_window_resizable"),&_OS::is_window_resizable); + ObjectTypeDB::bind_method(_MD("set_window_minimized", "enabled"),&_OS::set_window_minimized); + ObjectTypeDB::bind_method(_MD("is_window_minimized"),&_OS::is_window_minimized); + 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("set_iterations_per_second","iterations_per_second"),&_OS::set_iterations_per_second); ObjectTypeDB::bind_method(_MD("get_iterations_per_second"),&_OS::get_iterations_per_second); diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index 1a80e35221..f3601e35fb 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -108,25 +108,25 @@ public: bool is_video_mode_resizable(int p_screen=0) const; Array get_fullscreen_mode_list(int p_screen=0) const; -#ifdef NEW_WM_API + virtual int get_screen_count() const; - virtual int get_screen() const; - virtual void set_screen(int p_screen); + virtual int get_current_screen() const; + virtual void set_current_screen(int p_screen); virtual Point2 get_screen_position(int p_screen=0) const; virtual Size2 get_screen_size(int p_screen=0) const; virtual Point2 get_window_position() const; virtual void set_window_position(const Point2& p_position); virtual Size2 get_window_size() const; virtual void set_window_size(const Size2& p_size); - virtual void set_fullscreen(bool p_enabled); - virtual bool is_fullscreen() const; - virtual void set_resizable(bool p_enabled); - virtual bool is_resizable() const; - virtual void set_minimized(bool p_enabled); - virtual bool is_minimized() const; - virtual void set_maximized(bool p_enabled); - virtual bool is_maximized() const; -#endif + virtual void set_window_fullscreen(bool p_enabled); + virtual bool is_window_fullscreen() const; + virtual void set_window_resizable(bool p_enabled); + virtual bool is_window_resizable() const; + virtual void set_window_minimized(bool p_enabled); + virtual bool is_window_minimized() const; + virtual void set_window_maximized(bool p_enabled); + virtual bool is_window_maximized() const; + Error native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track); bool native_video_is_playing(); diff --git a/core/os/os.h b/core/os/os.h index 6301bd495f..d4ac433644 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -150,25 +150,25 @@ public: virtual VideoMode get_video_mode(int p_screen=0) const=0; virtual void get_fullscreen_mode_list(List *p_list,int p_screen=0) const=0; -#ifdef NEW_WM_API - virtual int get_screen_count() const=0; - virtual int get_screen() const=0; - virtual void set_screen(int p_screen)=0; - virtual Point2 get_screen_position(int p_screen=0) const=0; - virtual Size2 get_screen_size(int p_screen=0) const=0; - virtual Point2 get_window_position() const=0; - virtual void set_window_position(const Point2& p_position)=0; + + 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 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) {} virtual Size2 get_window_size() const=0; - virtual void set_window_size(const Size2 p_size)=0; - virtual void set_fullscreen(bool p_enabled)=0; - virtual bool is_fullscreen() const=0; - virtual void set_resizable(bool p_enabled)=0; - virtual bool is_resizable() const=0; - virtual void set_minimized(bool p_enabled)=0; - virtual bool is_minimized() const=0; - virtual void set_maximized(bool p_enabled)=0; - virtual bool is_maximized() const=0; -#endif + virtual void set_window_size(const Size2 p_size){} + virtual void set_window_fullscreen(bool p_enabled) {} + virtual bool is_window_fullscreen() const { return true; } + virtual void set_window_resizable(bool p_enabled) {} + virtual bool is_window_resizable() const { return false; } + virtual void set_window_minimized(bool p_enabled) {} + virtual bool is_window_minimized() const { return false; } + virtual void set_window_maximized(bool p_enabled) {} + virtual bool is_window_maximized() const { return true; } + virtual void set_iterations_per_second(int p_ips); virtual int get_iterations_per_second() const; diff --git a/demos/misc/window_management/control.gd b/demos/misc/window_management/control.gd index bca13c5a0c..d1b8f0e71a 100644 --- a/demos/misc/window_management/control.gd +++ b/demos/misc/window_management/control.gd @@ -35,7 +35,7 @@ func _fixed_process(delta): get_node("Label_Screen_Count").set_text( str("Screen_Count:\n", OS.get_screen_count() ) ) - get_node("Label_Screen_Current").set_text( str("Screen:\n", OS.get_screen() ) ) + get_node("Label_Screen_Current").set_text( str("Screen:\n", OS.get_current_screen() ) ) get_node("Label_Screen0_Resolution").set_text( str("Screen0 Resolution:\n", OS.get_screen_size() ) ) @@ -54,10 +54,10 @@ func _fixed_process(delta): get_node("Label_Screen1_Resolution").hide() get_node("Label_Screen1_Position").hide() - get_node("Button_Fullscreen").set_pressed( OS.is_fullscreen() ) - get_node("Button_FixedSize").set_pressed( !OS.is_resizable() ) - get_node("Button_Minimized").set_pressed( OS.is_minimized() ) - get_node("Button_Maximized").set_pressed( OS.is_maximized() ) + get_node("Button_Fullscreen").set_pressed( OS.is_window_fullscreen() ) + get_node("Button_FixedSize").set_pressed( !OS.is_is_window_resizable() ) + get_node("Button_Minimized").set_pressed( OS.is_is_window_minimized() ) + get_node("Button_Maximized").set_pressed( OS.is_is_window_maximized() ) get_node("Button_Mouse_Grab").set_pressed( Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED ) @@ -137,39 +137,39 @@ func _on_Button_Resize_pressed(): func _on_Button_Screen0_pressed(): - OS.set_screen(0) + OS.set_current_screen(0) func _on_Button_Screen1_pressed(): - OS.set_screen(1) + OS.set_current_screen(1) func _on_Button_Fullscreen_pressed(): - if(OS.is_fullscreen()): - OS.set_fullscreen(false) + if(OS.is_window_fullscreen()): + OS.set_window_fullscreen(false) else: - OS.set_fullscreen(true) + OS.set_window_fullscreen(true) func _on_Button_FixedSize_pressed(): - if(OS.is_resizable()): - OS.set_resizable(false) + if(OS.is_window_resizable()): + OS.set_window_resizable(false) else: - OS.set_resizable(true) + OS.set_window_resizable(true) func _on_Button_Minimized_pressed(): - if(OS.is_minimized()): - OS.set_minimized(false) + if(OS.is_window_minimized()): + OS.set_window_minimized(false) else: - OS.set_minimized(true) + OS.set_window_minimized(true) func _on_Button_Maximized_pressed(): - if(OS.is_maximized()): - OS.set_maximized(false) + if(OS.is_window_maximized()): + OS.set_window_maximized(false) else: - OS.set_maximized(true) + OS.set_window_maximized(true) func _on_Button_Mouse_Grab_pressed(): diff --git a/drivers/windows/dir_access_windows.h b/drivers/windows/dir_access_windows.h index 906ce0d064..4a668a7364 100644 --- a/drivers/windows/dir_access_windows.h +++ b/drivers/windows/dir_access_windows.h @@ -65,6 +65,7 @@ public: virtual bool list_dir_begin(); ///< This starts dir listing virtual String get_next(); virtual bool current_is_dir() const; + virtual bool current_is_hidden() const; virtual void list_dir_end(); ///< virtual int get_drive_count(); diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index 50c42448f4..a8768ea9fd 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -171,6 +171,8 @@ void OS_Windows::initialize_core() { last_button_state=0; //RedirectIOToConsole(); + maximized=false; + minimized=false; ThreadWindows::make_default(); SemaphoreWindows::make_default(); @@ -1007,6 +1009,23 @@ void OS_Windows::process_joysticks() { }; }; + +BOOL CALLBACK OS_Windows::MonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) { + OS_Windows *self=(OS_Windows*)OS::get_singleton(); + MonitorInfo minfo; + minfo.hMonitor=hMonitor; + minfo.hdcMonitor=hdcMonitor; + minfo.rect.pos.x=lprcMonitor->left; + minfo.rect.pos.y=lprcMonitor->top; + minfo.rect.size.x=lprcMonitor->right - lprcMonitor->left; + minfo.rect.size.y=lprcMonitor->bottom - lprcMonitor->top; + + self->monitor_info.push_back(minfo); + + return TRUE; +} + + void OS_Windows::initialize(const VideoMode& p_desired,int p_video_driver,int p_audio_driver) { @@ -1045,6 +1064,9 @@ void OS_Windows::initialize(const VideoMode& p_desired,int p_video_driver,int p_ } + EnumDisplayMonitors(NULL,NULL,MonitorEnumProc,0); + + print_line("DETECTED MONITORS: "+itos(monitor_info.size())); if (video_mode.fullscreen) { DEVMODE current; @@ -1475,6 +1497,172 @@ void OS_Windows::get_fullscreen_mode_list(List *p_list,int p_screen) } +int OS_Windows::get_screen_count() const { + + return monitor_info.size(); +} +int OS_Windows::get_current_screen() const{ + + HMONITOR monitor = MonitorFromWindow(hWnd,MONITOR_DEFAULTTONEAREST); + for(int i=0;i* process_map; + struct MonitorInfo { + HMONITOR hMonitor; + HDC hdcMonitor; + Rect2 rect; + + + }; + + RECT pre_fs_rect; + Vector monitor_info; + bool maximized; + bool minimized; + + static BOOL CALLBACK MonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData); + + public: LRESULT WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam); @@ -218,6 +234,24 @@ public: virtual VideoMode get_video_mode(int p_screen=0) const; virtual void get_fullscreen_mode_list(List *p_list,int p_screen=0) const; + 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) const; + virtual Size2 get_screen_size(int p_screen=0) const; + virtual Point2 get_window_position() const; + virtual void set_window_position(const Point2& p_position); + virtual Size2 get_window_size() const; + virtual void set_window_size(const Size2 p_size); + virtual void set_window_fullscreen(bool p_enabled); + virtual bool is_window_fullscreen() const; + virtual void set_window_resizable(bool p_enabled); + virtual bool is_window_resizable() const; + virtual void set_window_minimized(bool p_enabled); + virtual bool is_window_minimized() const; + virtual void set_window_maximized(bool p_enabled); + virtual bool is_window_maximized() const; + virtual MainLoop *get_main_loop() const; virtual String get_name(); diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index 8196281732..f1573f4229 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -36,7 +36,7 @@ #include "servers/physics/physics_server_sw.h" #include "X11/Xutil.h" -#ifdef NEW_WM_API + #include "X11/Xatom.h" #include "X11/extensions/Xinerama.h" // ICCCM @@ -46,7 +46,7 @@ #define _NET_WM_STATE_REMOVE 0L // remove/unset property #define _NET_WM_STATE_ADD 1L // add/set property #define _NET_WM_STATE_TOGGLE 2L // toggle property -#endif + #include "main/main.h" @@ -187,7 +187,8 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi visual_server =memnew(VisualServerWrapMT(visual_server,get_render_thread_mode()==RENDER_SEPARATE_THREAD)); } -#ifndef NEW_WM_API +#if 1 + // NEW_WM_API // borderless fullscreen window mode if (current_videomode.fullscreen) { // needed for lxde/openbox, possibly others @@ -552,7 +553,7 @@ void OS_X11::get_fullscreen_mode_list(List *p_list,int p_screen) cons } -#ifdef NEW_WM_API +//#ifdef NEW_WM_API #if 0 // Just now not needed. Can be used for a possible OS.set_border(bool) method void OS_X11::set_wm_border(bool p_enabled) { @@ -598,7 +599,7 @@ int OS_X11::get_screen_count() const { return count; } -int OS_X11::get_screen() const { +int OS_X11::get_current_screen() const { int x,y; Window child; XTranslateCoordinates( x11_display, x11_window, DefaultRootWindow(x11_display), 0, 0, &x, &y, &child); @@ -613,7 +614,7 @@ int OS_X11::get_screen() const { return 0; } -void OS_X11::set_screen(int p_screen) { +void OS_X11::set_current_screen(int p_screen) { int count = get_screen_count(); if(p_screen >= count) return; @@ -730,18 +731,18 @@ void OS_X11::set_window_size(const Size2 p_size) { XResizeWindow(x11_display, x11_window, p_size.x, p_size.y); } -void OS_X11::set_fullscreen(bool p_enabled) { +void OS_X11::set_window_fullscreen(bool p_enabled) { set_wm_fullscreen(p_enabled); current_videomode.fullscreen = p_enabled; visual_server->init(); } -bool OS_X11::is_fullscreen() const { +bool OS_X11::is_window_fullscreen() const { return current_videomode.fullscreen; } -void OS_X11::set_resizable(bool p_enabled) { +void OS_X11::set_window_resizable(bool p_enabled) { XSizeHints *xsh; xsh = XAllocSizeHints(); xsh->flags = p_enabled ? 0L : PMinSize | PMaxSize; @@ -758,11 +759,11 @@ void OS_X11::set_resizable(bool p_enabled) { current_videomode.resizable = p_enabled; } -bool OS_X11::is_resizable() const { +bool OS_X11::is_window_resizable() const { return current_videomode.resizable; } -void OS_X11::set_minimized(bool p_enabled) { +void OS_X11::set_window_minimized(bool p_enabled) { // Using ICCCM -- Inter-Client Communication Conventions Manual XEvent xev; Atom wm_change = XInternAtom(x11_display, "WM_CHANGE_STATE", False); @@ -791,7 +792,7 @@ void OS_X11::set_minimized(bool p_enabled) { XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureRedirectMask | SubstructureNotifyMask, &xev); } -bool OS_X11::is_minimized() const { +bool OS_X11::is_window_minimized() const { // Using ICCCM -- Inter-Client Communication Conventions Manual Atom property = XInternAtom(x11_display,"WM_STATE", True); Atom type; @@ -823,7 +824,7 @@ bool OS_X11::is_minimized() const { return false; } -void OS_X11::set_maximized(bool p_enabled) { +void OS_X11::set_window_maximized(bool p_enabled) { // Using EWMH -- Extended Window Manager Hints XEvent xev; Atom wm_state = XInternAtom(x11_display, "_NET_WM_STATE", False); @@ -844,7 +845,7 @@ void OS_X11::set_maximized(bool p_enabled) { maximized = p_enabled; } -bool OS_X11::is_maximized() const { +bool OS_X11::is_window_maximized() const { // Using EWMH -- Extended Window Manager Hints Atom property = XInternAtom(x11_display,"_NET_WM_STATE",False ); Atom type; @@ -889,7 +890,7 @@ bool OS_X11::is_maximized() const { return false; } -#endif + InputModifierState OS_X11::get_key_modifier_state(unsigned int p_x11_state) { diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h index ffa1ce00b3..ebcb0dc2fc 100644 --- a/platform/x11/os_x11.h +++ b/platform/x11/os_x11.h @@ -159,12 +159,12 @@ class OS_X11 : public OS_Unix { int joystick_count; Joystick joysticks[JOYSTICKS_MAX]; -#ifdef NEW_WM_API + unsigned int capture_idle; bool maximized; //void set_wm_border(bool p_enabled); void set_wm_fullscreen(bool p_enabled); -#endif + protected: @@ -220,25 +220,25 @@ public: virtual VideoMode get_video_mode(int p_screen=0) const; virtual void get_fullscreen_mode_list(List *p_list,int p_screen=0) const; -#ifdef NEW_WM_API + virtual int get_screen_count() const; - virtual int get_screen() const; - virtual void set_screen(int p_screen); + virtual int get_current_screen() const; + virtual void set_current_screen(int p_screen); virtual Point2 get_screen_position(int p_screen=0) const; virtual Size2 get_screen_size(int p_screen=0) const; virtual Point2 get_window_position() const; virtual void set_window_position(const Point2& p_position); virtual Size2 get_window_size() const; virtual void set_window_size(const Size2 p_size); - virtual void set_fullscreen(bool p_enabled); - virtual bool is_fullscreen() const; - virtual void set_resizable(bool p_enabled); - virtual bool is_resizable() const; - virtual void set_minimized(bool p_enabled); - virtual bool is_minimized() const; - virtual void set_maximized(bool p_enabled); - virtual bool is_maximized() const; -#endif + virtual void set_window_fullscreen(bool p_enabled); + virtual bool is_window_fullscreen() const; + virtual void set_window_resizable(bool p_enabled); + virtual bool is_window_resizable() const; + virtual void set_window_minimized(bool p_enabled); + virtual bool is_window_minimized() const; + virtual void set_window_maximized(bool p_enabled); + virtual bool is_window_maximized() const; + virtual void move_window_to_foreground(); void run(); diff --git a/tools/editor/io_plugins/editor_import_collada.cpp b/tools/editor/io_plugins/editor_import_collada.cpp index d2c9f395d2..f113bd3593 100644 --- a/tools/editor/io_plugins/editor_import_collada.cpp +++ b/tools/editor/io_plugins/editor_import_collada.cpp @@ -1360,9 +1360,9 @@ Error ColladaImport::_create_mesh_surfaces(Ref& p_mesh,const Map Date: Sun, 22 Mar 2015 19:06:13 -0300 Subject: Revert "Camelcased script variables will now capitalize in the inspector." --- core/ustring.cpp | 25 +------------------------ core/ustring.h | 3 ++- 2 files changed, 3 insertions(+), 25 deletions(-) diff --git a/core/ustring.cpp b/core/ustring.cpp index 497e8f29ed..09d3d95b68 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -482,7 +482,7 @@ void String::erase(int p_pos, int p_chars) { String String::capitalize() const { - String aux=this->camelcase_to_underscore().replace("_"," ").to_lower(); + String aux=this->replace("_"," ").to_lower(); String cap; for (int i=0;isize()-1; i++ ) { - bool isCapital = cstr[i] >= A && cstr[i] <= Z; - - if ( isCapital ) { - newString += "_" + this->substr(startIndex, i-startIndex); - startIndex = i; - } - } - - newString += "_" + this->substr(startIndex, this->size()-startIndex); - - return newString; -} - - int String::get_slice_count(String p_splitter) const{ if (empty()) diff --git a/core/ustring.h b/core/ustring.h index f79e5ce306..d4b854ea76 100644 --- a/core/ustring.h +++ b/core/ustring.h @@ -149,7 +149,6 @@ public: static double to_double(const CharType* p_str, const CharType **r_end=NULL); static int64_t to_int(const CharType* p_str,int p_len=-1); String capitalize() const; - String camelcase_to_underscore() const; int get_slice_count(String p_splitter) const; String get_slice(String p_splitter,int p_slice) const; @@ -226,6 +225,8 @@ public: String(const char *p_str); String(const CharType *p_str,int p_clip_to_len=-1); String(const StrRange& p_range); + + }; -- cgit v1.2.3 From 817f9debe787fc8001c03407f924f61fd5f0f7ad Mon Sep 17 00:00:00 2001 From: Carl Olsson Date: Mon, 23 Mar 2015 08:24:52 +1000 Subject: Add iostream include to collada plugin and change to light occluder to use canvas item snap function. --- tools/editor/io_plugins/editor_import_collada.cpp | 1 + tools/editor/plugins/light_occluder_2d_editor_plugin.cpp | 15 ++------------- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/tools/editor/io_plugins/editor_import_collada.cpp b/tools/editor/io_plugins/editor_import_collada.cpp index d2c9f395d2..c12fb0535c 100644 --- a/tools/editor/io_plugins/editor_import_collada.cpp +++ b/tools/editor/io_plugins/editor_import_collada.cpp @@ -39,6 +39,7 @@ #include "scene/resources/packed_scene.h" #include "os/os.h" #include "tools/editor/editor_node.h" +#include struct ColladaImport { diff --git a/tools/editor/plugins/light_occluder_2d_editor_plugin.cpp b/tools/editor/plugins/light_occluder_2d_editor_plugin.cpp index 5fa3d8ac8f..bf882857d9 100644 --- a/tools/editor/plugins/light_occluder_2d_editor_plugin.cpp +++ b/tools/editor/plugins/light_occluder_2d_editor_plugin.cpp @@ -35,17 +35,6 @@ void LightOccluder2DEditor::_node_removed(Node *p_node) { } -Vector2 LightOccluder2DEditor::snap_point(const Vector2& p_point) const { - - if (canvas_item_editor->is_snap_active()) { - - return p_point.snapped(Vector2(1,1)*canvas_item_editor->get_snap()); - - } else { - return p_point; - } -} - void LightOccluder2DEditor::_menu_option(int p_option) { switch(p_option) { @@ -109,7 +98,7 @@ bool LightOccluder2DEditor::forward_input_event(const InputEvent& p_event) { Vector2 gpoint = Point2(mb.x,mb.y); Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint); - cpoint=snap_point(cpoint); + cpoint=canvas_item_editor->snap_point(cpoint); cpoint = node->get_global_transform().affine_inverse().xform(cpoint); Vector poly = Variant(node->get_occluder_polygon()->get_polygon()); @@ -317,7 +306,7 @@ bool LightOccluder2DEditor::forward_input_event(const InputEvent& p_event) { Vector2 gpoint = Point2(mm.x,mm.y); Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint); - cpoint=snap_point(cpoint); + cpoint=canvas_item_editor->snap_point(cpoint); edited_point_pos = node->get_global_transform().affine_inverse().xform(cpoint); canvas_item_editor->get_viewport_control()->update(); -- cgit v1.2.3 From ca0b3ce1f6e40827096e1fa66e4d159d7e16a83a Mon Sep 17 00:00:00 2001 From: rollenrolm Date: Mon, 23 Mar 2015 01:31:38 +0100 Subject: New API: build fixes for x11 --- platform/x11/detect.py | 1 + platform/x11/os_x11.cpp | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/platform/x11/detect.py b/platform/x11/detect.py index 2519dd6fdf..b0876d7fc6 100644 --- a/platform/x11/detect.py +++ b/platform/x11/detect.py @@ -113,6 +113,7 @@ def configure(env): env.Append(CCFLAGS=['-g2', '-Wall','-DDEBUG_ENABLED','-DDEBUG_MEMORY_ENABLED']) env.ParseConfig('pkg-config x11 --cflags --libs') + env.ParseConfig('pkg-config xinerama --cflags --libs') env.ParseConfig('pkg-config xcursor --cflags --libs') env.ParseConfig('pkg-config openssl --cflags --libs') diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index 5b36df6a53..92b0abff37 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -248,10 +248,10 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi set_wm_fullscreen(true); } if (!current_videomode.resizable) { - int screen = get_screen(); + int screen = get_current_screen(); Size2i screen_size = get_screen_size(screen); set_window_size(screen_size); - set_resizable(false); + set_window_resizable(false); } #endif @@ -624,7 +624,7 @@ void OS_X11::set_current_screen(int p_screen) { XMoveResizeWindow(x11_display, x11_window, position.x, position.y, size.x, size.y); } else { - if( p_screen != get_screen() ) { + if( p_screen != get_current_screen() ) { Point2i position = get_screen_position(p_screen); XMoveWindow(x11_display, x11_window, position.x, position.y); } @@ -667,7 +667,7 @@ Point2 OS_X11::get_window_position() const { Window child; XTranslateCoordinates( x11_display, x11_window, DefaultRootWindow(x11_display), 0, 0, &x, &y, &child); - int screen = get_screen(); + int screen = get_current_screen(); Point2i screen_position = get_screen_position(screen); return Point2i(x-screen_position.x, y-screen_position.y); @@ -711,7 +711,7 @@ void OS_X11::set_window_position(const Point2& p_position) { XFree(data); } - int screen = get_screen(); + int screen = get_current_screen(); Point2i screen_position = get_screen_position(screen); left -= screen_position.x; @@ -1152,7 +1152,7 @@ void OS_X11::process_xevents() { #ifdef NEW_WM_API if(current_videomode.fullscreen) { set_wm_fullscreen(false); - set_minimized(true); + set_window_minimized(true); visual_server->init(); } #endif -- cgit v1.2.3 From 001a16064f886944f2746828c3b8d8be813838e5 Mon Sep 17 00:00:00 2001 From: hurikhan Date: Mon, 23 Mar 2015 00:09:12 -0400 Subject: adjust the window_management demo to the new function names --- demos/misc/window_management/control.gd | 54 ++++++++++----------- demos/misc/window_management/window_management.scn | Bin 5087 -> 5129 bytes 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/demos/misc/window_management/control.gd b/demos/misc/window_management/control.gd index d1b8f0e71a..5eb5817619 100644 --- a/demos/misc/window_management/control.gd +++ b/demos/misc/window_management/control.gd @@ -5,18 +5,18 @@ func _fixed_process(delta): var modetext = "Mode:\n" - if(OS.is_fullscreen()): + if(OS.is_window_fullscreen()): modetext += "Fullscreen\n" else: modetext += "Windowed\n" - if(!OS.is_resizable()): + if(!OS.is_window_resizable()): modetext += "FixedSize\n" - if(OS.is_minimized()): + if(OS.is_window_minimized()): modetext += "Minimized\n" - if(OS.is_maximized()): + if(OS.is_window_maximized()): modetext += "Maximized\n" if(Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED): @@ -55,9 +55,9 @@ func _fixed_process(delta): get_node("Label_Screen1_Position").hide() get_node("Button_Fullscreen").set_pressed( OS.is_window_fullscreen() ) - get_node("Button_FixedSize").set_pressed( !OS.is_is_window_resizable() ) - get_node("Button_Minimized").set_pressed( OS.is_is_window_minimized() ) - get_node("Button_Maximized").set_pressed( OS.is_is_window_maximized() ) + get_node("Button_FixedSize").set_pressed( !OS.is_window_resizable() ) + get_node("Button_Minimized").set_pressed( OS.is_window_minimized() ) + get_node("Button_Maximized").set_pressed( OS.is_window_maximized() ) get_node("Button_Mouse_Grab").set_pressed( Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED ) @@ -66,11 +66,11 @@ func check_wm_api(): if( !OS.has_method("get_screen_count") ): s += " - get_screen_count()\n" - if( !OS.has_method("get_screen") ): - s += " - get_screen()\n" + if( !OS.has_method("get_current_screen") ): + s += " - get_current_screen()\n" - if( !OS.has_method("set_screen") ): - s += " - set_screen()\n" + if( !OS.has_method("set_current_screen") ): + s += " - set_current_screen()\n" if( !OS.has_method("get_screen_position") ): s += " - get_screen_position()\n" @@ -90,29 +90,29 @@ func check_wm_api(): if( !OS.has_method("set_window_size") ): s += " - set_window_size()\n" - if( !OS.has_method("set_fullscreen") ): - s += " - set_fullscreen()\n" + if( !OS.has_method("set_window_fullscreen") ): + s += " - set_window_fullscreen()\n" - if( !OS.has_method("is_fullscreen") ): - s += " - is_fullscreen()\n" + if( !OS.has_method("is_window_fullscreen") ): + s += " - is_window_fullscreen()\n" - if( !OS.has_method("set_resizable") ): - s += " - set_resizable()\n" + if( !OS.has_method("set_window_resizable") ): + s += " - set_window_resizable()\n" - if( !OS.has_method("is_resizable") ): - s += " - is_resizable()\n" + if( !OS.has_method("is_window_resizable") ): + s += " - is_window_resizable()\n" - if( !OS.has_method("set_minimized") ): - s += " - set_minimized()\n" + if( !OS.has_method("set_window_minimized") ): + s += " - set_window_minimized()\n" - if( !OS.has_method("is_minimized") ): - s += " - is_minimized()\n" + if( !OS.has_method("is_window_minimized") ): + s += " - is_window_minimized()\n" - if( !OS.has_method("set_maximized") ): - s += " - set_maximized()\n" + if( !OS.has_method("set_window_maximized") ): + s += " - set_window_maximized()\n" - if( !OS.has_method("is_maximized") ): - s += " - is_maximized()\n" + if( !OS.has_method("is_window_maximized") ): + s += " - is_window_maximized()\n" if( s.length() == 0 ): return true diff --git a/demos/misc/window_management/window_management.scn b/demos/misc/window_management/window_management.scn index b8b0ee210b..c7d6260df6 100644 Binary files a/demos/misc/window_management/window_management.scn and b/demos/misc/window_management/window_management.scn differ -- cgit v1.2.3 From 7ad7f2f6a986fa6598ae10f2bb940e15c3658f44 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Mon, 23 Mar 2015 11:31:03 -0300 Subject: android fixes, please test (can' t build android atm) --- platform/android/dir_access_jandroid.cpp | 6 ++++++ platform/android/dir_access_jandroid.h | 1 + platform/android/os_android.cpp | 5 +++++ platform/android/os_android.h | 2 ++ scene/2d/collision_polygon_2d.cpp | 12 ++++++++++++ scene/2d/collision_polygon_2d.h | 1 + scene/gui/file_dialog.cpp | 25 ++++++++++++++++++++++--- scene/gui/file_dialog.h | 9 +++++++++ tools/editor/editor_node.cpp | 1 + 9 files changed, 59 insertions(+), 3 deletions(-) diff --git a/platform/android/dir_access_jandroid.cpp b/platform/android/dir_access_jandroid.cpp index fda4ca7357..97c5bfed61 100644 --- a/platform/android/dir_access_jandroid.cpp +++ b/platform/android/dir_access_jandroid.cpp @@ -105,6 +105,12 @@ bool DirAccessJAndroid::current_is_dir() const{ return true; } + +bool DirAccessJAndroid::current_is_hidden() const { + + return current!="." && current!=".." && current.begins_with("."); +} + bool DirAccessAndroid::current_is_hidden() const{ return current!="." && current!=".." && current.begins_with("."); } diff --git a/platform/android/dir_access_jandroid.h b/platform/android/dir_access_jandroid.h index 958ea34891..0a696506e6 100644 --- a/platform/android/dir_access_jandroid.h +++ b/platform/android/dir_access_jandroid.h @@ -60,6 +60,7 @@ public: virtual bool list_dir_begin(); ///< This starts dir listing virtual String get_next(); virtual bool current_is_dir() const; + virtual bool current_is_hidden() const; virtual void list_dir_end(); ///< virtual int get_drive_count(); diff --git a/platform/android/os_android.cpp b/platform/android/os_android.cpp index 6b91c01dfc..f00e9c2d77 100644 --- a/platform/android/os_android.cpp +++ b/platform/android/os_android.cpp @@ -291,6 +291,11 @@ void OS_Android::get_fullscreen_mode_list(List *p_list,int p_screen) p_list->push_back(default_videomode); } +Size2 OS_Android::get_window_size() const { + + return Vector2(default_videomode.width,default_videomode.height); +} + String OS_Android::get_name() { return "Android"; diff --git a/platform/android/os_android.h b/platform/android/os_android.h index 26dbf4a509..bea5371bbc 100644 --- a/platform/android/os_android.h +++ b/platform/android/os_android.h @@ -170,6 +170,8 @@ public: virtual VideoMode get_video_mode(int p_screen=0) const; virtual void get_fullscreen_mode_list(List *p_list,int p_screen=0) const; + virtual Size2 get_window_size() const; + virtual String get_name(); virtual MainLoop *get_main_loop() const; diff --git a/scene/2d/collision_polygon_2d.cpp b/scene/2d/collision_polygon_2d.cpp index 1c0be60764..049017c0a5 100644 --- a/scene/2d/collision_polygon_2d.cpp +++ b/scene/2d/collision_polygon_2d.cpp @@ -33,6 +33,9 @@ void CollisionPolygon2D::_add_to_collision_object(Object *p_obj) { + if (unparenting) + return; + CollisionObject2D *co = p_obj->cast_to(); ERR_FAIL_COND(!co); @@ -96,6 +99,9 @@ void CollisionPolygon2D::_notification(int p_what) { switch(p_what) { + case NOTIFICATION_ENTER_TREE: { + unparenting=false; + } break; case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: { if (!is_inside_tree()) @@ -123,6 +129,11 @@ void CollisionPolygon2D::_notification(int p_what) { } #endif } break; + case NOTIFICATION_UNPARENTED: { + unparenting = true; + _update_parent(); + } break; + } } @@ -203,6 +214,7 @@ CollisionPolygon2D::CollisionPolygon2D() { aabb=Rect2(-10,-10,20,20); build_mode=BUILD_SOLIDS; trigger=false; + unparenting=false; } diff --git a/scene/2d/collision_polygon_2d.h b/scene/2d/collision_polygon_2d.h index b8e27b6fb4..735110efad 100644 --- a/scene/2d/collision_polygon_2d.h +++ b/scene/2d/collision_polygon_2d.h @@ -51,6 +51,7 @@ protected: BuildMode build_mode; Vector polygon; bool trigger; + bool unparenting; void _add_to_collision_object(Object *p_obj); void _update_parent(); diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp index 47f862a58d..2e8a84e39b 100644 --- a/scene/gui/file_dialog.cpp +++ b/scene/gui/file_dialog.cpp @@ -30,7 +30,7 @@ #include "scene/gui/label.h" #include "print_string.h" #include "os/keyboard.h" -#include "tools/editor/editor_settings.h" + FileDialog::GetIconFunc FileDialog::get_icon_func=NULL; @@ -281,7 +281,7 @@ void FileDialog::update_file_list() { bool isdir; bool ishidden; - bool show_hidden = EditorSettings::get_singleton()->get("file_dialog/show_hidden_files"); + bool show_hidden = show_hidden_files; String item; while ((item=dir_access->get_next(&isdir))!="") { @@ -625,6 +625,9 @@ void FileDialog::_update_drives() { } } +bool FileDialog::default_show_hidden_files=true; + + void FileDialog::_bind_methods() { ObjectTypeDB::bind_method(_MD("_tree_selected"),&FileDialog::_tree_selected); @@ -649,6 +652,8 @@ void FileDialog::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_vbox:VBoxContainer"),&FileDialog::get_vbox); ObjectTypeDB::bind_method(_MD("set_access","access"),&FileDialog::set_access); ObjectTypeDB::bind_method(_MD("get_access"),&FileDialog::get_access); + ObjectTypeDB::bind_method(_MD("set_show_hidden_files"),&FileDialog::set_show_hidden_files); + ObjectTypeDB::bind_method(_MD("is_showing_hidden_files"),&FileDialog::is_showing_hidden_files); ObjectTypeDB::bind_method(_MD("_select_drive"),&FileDialog::_select_drive); ObjectTypeDB::bind_method(_MD("_make_dir"),&FileDialog::_make_dir); ObjectTypeDB::bind_method(_MD("_make_dir_confirm"),&FileDialog::_make_dir_confirm); @@ -673,9 +678,23 @@ void FileDialog::_bind_methods() { } +void FileDialog::set_show_hidden_files(bool p_show) { + show_hidden_files=p_show; + invalidate(); +} + +bool FileDialog::is_showing_hidden_files() const { + return show_hidden_files; +} + +void FileDialog::set_default_show_hidden_files(bool p_show) { + default_show_hidden_files=p_show; +} FileDialog::FileDialog() { - + + show_hidden_files=true; + VBoxContainer *vbc = memnew( VBoxContainer ); add_child(vbc); set_child_rect(vbc); diff --git a/scene/gui/file_dialog.h b/scene/gui/file_dialog.h index bda1797696..6b35035829 100644 --- a/scene/gui/file_dialog.h +++ b/scene/gui/file_dialog.h @@ -89,6 +89,10 @@ private: Vector filters; + + static bool default_show_hidden_files; + bool show_hidden_files; + bool invalidated; void update_dir(); @@ -141,6 +145,11 @@ public: void set_access(Access p_access); Access get_access() const; + void set_show_hidden_files(bool p_show); + bool is_showing_hidden_files() const; + + static void set_default_show_hidden_files(bool p_show); + void invalidate(); FileDialog(); diff --git a/tools/editor/editor_node.cpp b/tools/editor/editor_node.cpp index 5e571373ea..f49597b1e2 100644 --- a/tools/editor/editor_node.cpp +++ b/tools/editor/editor_node.cpp @@ -3279,6 +3279,7 @@ EditorNode::EditorNode() { singleton=this; FileAccess::set_backup_save(true); + FileDialog::set_default_show_hidden_files(EditorSettings::get_singleton()->get("file_dialog/show_hidden_files")); PathRemap::get_singleton()->clear_remaps();; //editor uses no remaps TranslationServer::get_singleton()->set_enabled(false); -- cgit v1.2.3 From 92905075d377a494dfddc39e41bd2d99043cf154 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Mon, 23 Mar 2015 13:44:03 -0300 Subject: crash bug solved, fixes #1560 --- tools/editor/editor_node.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/editor/editor_node.cpp b/tools/editor/editor_node.cpp index f49597b1e2..41545b887a 100644 --- a/tools/editor/editor_node.cpp +++ b/tools/editor/editor_node.cpp @@ -3279,7 +3279,6 @@ EditorNode::EditorNode() { singleton=this; FileAccess::set_backup_save(true); - FileDialog::set_default_show_hidden_files(EditorSettings::get_singleton()->get("file_dialog/show_hidden_files")); PathRemap::get_singleton()->clear_remaps();; //editor uses no remaps TranslationServer::get_singleton()->set_enabled(false); @@ -3288,6 +3287,7 @@ EditorNode::EditorNode() { EditorSettings::create(); ResourceLoader::set_abort_on_missing_resources(false); + FileDialog::set_default_show_hidden_files(EditorSettings::get_singleton()->get("file_dialog/show_hidden_files")); ResourceLoader::set_error_notify_func(this,_load_error_notify); ResourceLoader::set_timestamp_on_load(true); -- cgit v1.2.3 From 8db3922f56dd08e8fa2fed76cbebc1ca5fd79c8f Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Mon, 23 Mar 2015 14:15:11 -0300 Subject: small android fix --- platform/android/dir_access_jandroid.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/android/dir_access_jandroid.cpp b/platform/android/dir_access_jandroid.cpp index 97c5bfed61..d74f9c7ad2 100644 --- a/platform/android/dir_access_jandroid.cpp +++ b/platform/android/dir_access_jandroid.cpp @@ -111,7 +111,7 @@ bool DirAccessJAndroid::current_is_hidden() const { return current!="." && current!=".." && current.begins_with("."); } -bool DirAccessAndroid::current_is_hidden() const{ +bool DirAccessJAndroid::current_is_hidden() const{ return current!="." && current!=".." && current.begins_with("."); } void DirAccessJAndroid::list_dir_end(){ -- cgit v1.2.3 From 0245d4a2b067fcc98651fe65dad34bed9eb8aa4d Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Mon, 23 Mar 2015 16:12:59 -0300 Subject: oops, fucntion was there twice --- platform/android/dir_access_jandroid.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/platform/android/dir_access_jandroid.cpp b/platform/android/dir_access_jandroid.cpp index d74f9c7ad2..98f20b2636 100644 --- a/platform/android/dir_access_jandroid.cpp +++ b/platform/android/dir_access_jandroid.cpp @@ -111,9 +111,6 @@ bool DirAccessJAndroid::current_is_hidden() const { return current!="." && current!=".." && current.begins_with("."); } -bool DirAccessJAndroid::current_is_hidden() const{ - return current!="." && current!=".." && current.begins_with("."); -} void DirAccessJAndroid::list_dir_end(){ if (id==0) -- cgit v1.2.3 From 3cf9490c46fdcc434cdfddf9dfd5a8e673409f0f Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Mon, 23 Mar 2015 20:47:53 -0300 Subject: window managements functions work but still side-functions, all API needs to be migrated to them --- platform/windows/os_windows.cpp | 119 +++++++++++++++++++++++++++++++++------- platform/windows/os_windows.h | 2 + 2 files changed, 102 insertions(+), 19 deletions(-) diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index a8768ea9fd..414c250bd4 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -1067,6 +1067,7 @@ void OS_Windows::initialize(const VideoMode& p_desired,int p_video_driver,int p_ EnumDisplayMonitors(NULL,NULL,MonitorEnumProc,0); print_line("DETECTED MONITORS: "+itos(monitor_info.size())); + pre_fs_valid=true; if (video_mode.fullscreen) { DEVMODE current; @@ -1089,6 +1090,7 @@ void OS_Windows::initialize(const VideoMode& p_desired,int p_video_driver,int p_ video_mode.fullscreen=false; }*/ + pre_fs_valid=false; } DWORD dwExStyle; @@ -1548,15 +1550,43 @@ void OS_Windows::set_window_position(const Point2& p_position){ Size2 OS_Windows::get_window_size() const{ RECT r; - GetWindowRect(hWnd,&r); + GetClientRect(hWnd,&r); return Vector2(r.right-r.left,r.bottom-r.top); } void OS_Windows::set_window_size(const Size2 p_size){ - RECT r; - GetWindowRect(hWnd,&r); - MoveWindow(hWnd,r.left,r.top,p_size.x,p_size.y,TRUE); + video_mode.width=p_size.width; + video_mode.height=p_size.height; + + if (video_mode.fullscreen) { + return; + } + + + RECT crect; + GetClientRect(hWnd,&crect); + + RECT rect; + GetWindowRect(hWnd,&rect); + int dx = (rect.right-rect.left)-(crect.right-crect.left); + int dy = (rect.bottom-rect.top)-(crect.bottom-crect.top); + + rect.right=rect.left+p_size.width+dx; + rect.bottom=rect.top+p_size.height+dy; + + + //print_line("PRE: "+itos(rect.left)+","+itos(rect.top)+","+itos(rect.right-rect.left)+","+itos(rect.bottom-rect.top)); + + /*if (video_mode.resizable) { + AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE); + } else { + AdjustWindowRect(&rect, WS_CAPTION | WS_POPUPWINDOW, FALSE); + }*/ + + //print_line("POST: "+itos(rect.left)+","+itos(rect.top)+","+itos(rect.right-rect.left)+","+itos(rect.bottom-rect.top)); + + MoveWindow(hWnd,rect.left,rect.top,rect.right-rect.left,rect.bottom-rect.top,TRUE); } void OS_Windows::set_window_fullscreen(bool p_enabled){ @@ -1564,31 +1594,65 @@ void OS_Windows::set_window_fullscreen(bool p_enabled){ if (video_mode.fullscreen==p_enabled) return; + + if (p_enabled) { - GetWindowRect(hWnd,&pre_fs_rect); + + if (pre_fs_valid) { + GetWindowRect(hWnd,&pre_fs_rect); + //print_line("A: "+itos(pre_fs_rect.left)+","+itos(pre_fs_rect.top)+","+itos(pre_fs_rect.right-pre_fs_rect.left)+","+itos(pre_fs_rect.bottom-pre_fs_rect.top)); + //MapWindowPoints(hWnd, GetParent(hWnd), (LPPOINT) &pre_fs_rect, 2); + //print_line("B: "+itos(pre_fs_rect.left)+","+itos(pre_fs_rect.top)+","+itos(pre_fs_rect.right-pre_fs_rect.left)+","+itos(pre_fs_rect.bottom-pre_fs_rect.top)); + } + int cs = get_current_screen(); Point2 pos = get_screen_position(cs); Size2 size = get_screen_size(cs); - RECT WindowRect; - WindowRect.left = pos.x; - WindowRect.top = pos.y; - WindowRect.bottom = pos.y+size.y; - WindowRect.right = pos.x+size.x; - DWORD dwExStyle=WS_EX_APPWINDOW; - DWORD dwStyle=WS_POPUP; - - AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle); + /* r.left = pos.x; + r.top = pos.y; + r.bottom = pos.y+size.y; + r.right = pos.x+size.x; +*/ + SetWindowLongPtr(hWnd, GWL_STYLE, + WS_SYSMENU | WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_VISIBLE); + MoveWindow(hWnd, pos.x, pos.y, size.width, size.height, TRUE); video_mode.fullscreen=true; - video_mode.width=size.x; - video_mode.height=size.y; } else { + RECT rect; + + if (pre_fs_valid) { + rect=pre_fs_rect; + } else { + rect.left=0; + rect.right=video_mode.width; + rect.top=0; + rect.bottom=video_mode.height; + } + + + + if (video_mode.resizable) { + + SetWindowLongPtr(hWnd, GWL_STYLE, WS_OVERLAPPEDWINDOW | WS_VISIBLE); + //AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE); + MoveWindow(hWnd, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top, TRUE); + } else { + + SetWindowLongPtr(hWnd, GWL_STYLE, WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE); + //AdjustWindowRect(&rect, WS_CAPTION | WS_POPUPWINDOW, FALSE); + MoveWindow(hWnd, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top, TRUE); + } + + video_mode.fullscreen=false; + pre_fs_valid=true; +/* DWORD dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; DWORD dwStyle=WS_OVERLAPPEDWINDOW; if (!video_mode.resizable) { @@ -1599,9 +1663,11 @@ void OS_Windows::set_window_fullscreen(bool p_enabled){ video_mode.fullscreen=false; video_mode.width=pre_fs_rect.right-pre_fs_rect.left; video_mode.height=pre_fs_rect.bottom-pre_fs_rect.top; - +*/ } +// MoveWindow(hWnd,r.left,r.top,p_size.x,p_size.y,TRUE); + } bool OS_Windows::is_window_fullscreen() const{ @@ -1610,9 +1676,9 @@ bool OS_Windows::is_window_fullscreen() const{ } void OS_Windows::set_window_resizable(bool p_enabled){ - if (video_mode.fullscreen || video_mode.resizable==p_enabled) + if (video_mode.resizable==p_enabled) return; - +/* GetWindowRect(hWnd,&pre_fs_rect); DWORD dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; DWORD dwStyle=WS_OVERLAPPEDWINDOW; @@ -1621,6 +1687,21 @@ void OS_Windows::set_window_resizable(bool p_enabled){ dwStyle &= ~WS_MAXIMIZEBOX; } AdjustWindowRectEx(&pre_fs_rect, dwStyle, FALSE, dwExStyle); + */ + + if (!video_mode.fullscreen) { + if (p_enabled) { + SetWindowLongPtr(hWnd, GWL_STYLE, WS_OVERLAPPEDWINDOW | WS_VISIBLE); + } else { + SetWindowLongPtr(hWnd, GWL_STYLE, WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE); + + } + + RECT rect; + GetWindowRect(hWnd,&rect); + MoveWindow(hWnd, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top, TRUE); + } + video_mode.resizable=p_enabled; } diff --git a/platform/windows/os_windows.h b/platform/windows/os_windows.h index c39b3c74a4..4995adc874 100644 --- a/platform/windows/os_windows.h +++ b/platform/windows/os_windows.h @@ -130,6 +130,7 @@ class OS_Windows : public OS { int joystick_count; Joystick joysticks[JOYSTICKS_MAX]; + Size2 window_rect; VideoMode video_mode; MainLoop *main_loop; @@ -204,6 +205,7 @@ protected: }; + bool pre_fs_valid; RECT pre_fs_rect; Vector monitor_info; bool maximized; -- cgit v1.2.3 From e3957e32deb80db1200082a8d6b4e429bbdbb4f4 Mon Sep 17 00:00:00 2001 From: steve Date: Mon, 23 Mar 2015 18:55:45 -0700 Subject: fixed iphone build with new window manamenet changes --- platform/iphone/os_iphone.cpp | 5 +++++ platform/iphone/os_iphone.h | 2 ++ 2 files changed, 7 insertions(+) diff --git a/platform/iphone/os_iphone.cpp b/platform/iphone/os_iphone.cpp index aee5f76684..06b48318ec 100644 --- a/platform/iphone/os_iphone.cpp +++ b/platform/iphone/os_iphone.cpp @@ -474,6 +474,11 @@ String OSIPhone::get_name() { return "iOS"; }; +Size2 OSIPhone::get_window_size() const { + + return Vector2(video_mode.width, video_mode.height); +} + bool OSIPhone::has_touchscreen_ui_hint() const { return true; diff --git a/platform/iphone/os_iphone.h b/platform/iphone/os_iphone.h index cb294d07eb..2585a26479 100644 --- a/platform/iphone/os_iphone.h +++ b/platform/iphone/os_iphone.h @@ -167,6 +167,8 @@ public: virtual void hide_virtual_keyboard(); virtual void set_cursor_shape(CursorShape p_shape); + + virtual Size2 get_window_size() const; virtual bool has_touchscreen_ui_hint() const; -- cgit v1.2.3 From a6f6bd85f982f7b24b71238de302bc534e3d4658 Mon Sep 17 00:00:00 2001 From: steve Date: Mon, 23 Mar 2015 22:07:03 -0700 Subject: fixed build error on OSX from new WM code --- platform/osx/os_osx.h | 2 ++ platform/osx/os_osx.mm | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/platform/osx/os_osx.h b/platform/osx/os_osx.h index 24f7115938..8f121b7dd5 100644 --- a/platform/osx/os_osx.h +++ b/platform/osx/os_osx.h @@ -133,6 +133,8 @@ public: virtual Point2 get_mouse_pos() const; virtual int get_mouse_button_state() const; virtual void set_window_title(const String& p_title); + + virtual Size2 get_window_size() const; virtual void set_icon(const Image& p_icon); diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm index 1c0d1f9991..55ef6c1516 100644 --- a/platform/osx/os_osx.mm +++ b/platform/osx/os_osx.mm @@ -1245,6 +1245,10 @@ void OS_OSX::get_fullscreen_mode_list(List *p_list,int p_screen) cons } +Size2 OS_OSX::get_window_size() const { + return Vector2(current_videomode.width, current_videomode.height); +} + void OS_OSX::move_window_to_foreground() { [window_object orderFrontRegardless]; -- cgit v1.2.3 From cbad0440ab078e72fcd5af50fa800d9720fb7761 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Tue, 24 Mar 2015 16:17:16 -0300 Subject: 2D normal mapping and lighting simple demos --- demos/2d/lights_shadows/bg.png | Bin 0 -> 294 bytes demos/2d/lights_shadows/caster.png | Bin 0 -> 122 bytes demos/2d/lights_shadows/engine.cfg | 8 ++++++++ demos/2d/lights_shadows/light.png | Bin 0 -> 243776 bytes demos/2d/lights_shadows/light_shadows.scn | Bin 0 -> 4293 bytes demos/2d/lights_shadows/spot.png | Bin 0 -> 3699 bytes demos/2d/normalmaps/diffuse.jpg | Bin 0 -> 535660 bytes demos/2d/normalmaps/diffuse.png | Bin 0 -> 2392221 bytes demos/2d/normalmaps/engine.cfg | 4 ++++ demos/2d/normalmaps/light.png | Bin 0 -> 243776 bytes demos/2d/normalmaps/normal.png | Bin 0 -> 2301245 bytes demos/2d/normalmaps/normal_material.res | Bin 0 -> 503 bytes demos/2d/normalmaps/normalmap.scn | Bin 0 -> 2450 bytes demos/2d/texscreen/OpenCV_Chessboard.png | Bin 0 -> 44884 bytes 14 files changed, 12 insertions(+) create mode 100644 demos/2d/lights_shadows/bg.png create mode 100644 demos/2d/lights_shadows/caster.png create mode 100644 demos/2d/lights_shadows/engine.cfg create mode 100644 demos/2d/lights_shadows/light.png create mode 100644 demos/2d/lights_shadows/light_shadows.scn create mode 100644 demos/2d/lights_shadows/spot.png create mode 100644 demos/2d/normalmaps/diffuse.jpg create mode 100644 demos/2d/normalmaps/diffuse.png create mode 100644 demos/2d/normalmaps/engine.cfg create mode 100644 demos/2d/normalmaps/light.png create mode 100644 demos/2d/normalmaps/normal.png create mode 100644 demos/2d/normalmaps/normal_material.res create mode 100644 demos/2d/normalmaps/normalmap.scn create mode 100644 demos/2d/texscreen/OpenCV_Chessboard.png diff --git a/demos/2d/lights_shadows/bg.png b/demos/2d/lights_shadows/bg.png new file mode 100644 index 0000000000..4a3376f484 Binary files /dev/null and b/demos/2d/lights_shadows/bg.png differ diff --git a/demos/2d/lights_shadows/caster.png b/demos/2d/lights_shadows/caster.png new file mode 100644 index 0000000000..bf53a4565b Binary files /dev/null and b/demos/2d/lights_shadows/caster.png differ diff --git a/demos/2d/lights_shadows/engine.cfg b/demos/2d/lights_shadows/engine.cfg new file mode 100644 index 0000000000..bb9d1ef256 --- /dev/null +++ b/demos/2d/lights_shadows/engine.cfg @@ -0,0 +1,8 @@ +[application] + +name="2D Lighting" +main_scene="res://light_shadows.scn" + +[rasterizer] + +shadow_filter=2 diff --git a/demos/2d/lights_shadows/light.png b/demos/2d/lights_shadows/light.png new file mode 100644 index 0000000000..936860de52 Binary files /dev/null and b/demos/2d/lights_shadows/light.png differ diff --git a/demos/2d/lights_shadows/light_shadows.scn b/demos/2d/lights_shadows/light_shadows.scn new file mode 100644 index 0000000000..34781b8049 Binary files /dev/null and b/demos/2d/lights_shadows/light_shadows.scn differ diff --git a/demos/2d/lights_shadows/spot.png b/demos/2d/lights_shadows/spot.png new file mode 100644 index 0000000000..9ab2d34963 Binary files /dev/null and b/demos/2d/lights_shadows/spot.png differ diff --git a/demos/2d/normalmaps/diffuse.jpg b/demos/2d/normalmaps/diffuse.jpg new file mode 100644 index 0000000000..87bc9cf158 Binary files /dev/null and b/demos/2d/normalmaps/diffuse.jpg differ diff --git a/demos/2d/normalmaps/diffuse.png b/demos/2d/normalmaps/diffuse.png new file mode 100644 index 0000000000..634d955f8d Binary files /dev/null and b/demos/2d/normalmaps/diffuse.png differ diff --git a/demos/2d/normalmaps/engine.cfg b/demos/2d/normalmaps/engine.cfg new file mode 100644 index 0000000000..3fc2048716 --- /dev/null +++ b/demos/2d/normalmaps/engine.cfg @@ -0,0 +1,4 @@ +[application] + +name="2D Normal Mapping" +main_scene="res://normalmap.scn" diff --git a/demos/2d/normalmaps/light.png b/demos/2d/normalmaps/light.png new file mode 100644 index 0000000000..9568298086 Binary files /dev/null and b/demos/2d/normalmaps/light.png differ diff --git a/demos/2d/normalmaps/normal.png b/demos/2d/normalmaps/normal.png new file mode 100644 index 0000000000..d5b3d53a24 Binary files /dev/null and b/demos/2d/normalmaps/normal.png differ diff --git a/demos/2d/normalmaps/normal_material.res b/demos/2d/normalmaps/normal_material.res new file mode 100644 index 0000000000..34129cccdc Binary files /dev/null and b/demos/2d/normalmaps/normal_material.res differ diff --git a/demos/2d/normalmaps/normalmap.scn b/demos/2d/normalmaps/normalmap.scn new file mode 100644 index 0000000000..ab737e83f3 Binary files /dev/null and b/demos/2d/normalmaps/normalmap.scn differ diff --git a/demos/2d/texscreen/OpenCV_Chessboard.png b/demos/2d/texscreen/OpenCV_Chessboard.png new file mode 100644 index 0000000000..31b7f8ccd8 Binary files /dev/null and b/demos/2d/texscreen/OpenCV_Chessboard.png differ -- cgit v1.2.3 From 7f8a0cddcfbd5744113de1826380310ad920360a Mon Sep 17 00:00:00 2001 From: reduz Date: Wed, 25 Mar 2015 22:56:35 -0300 Subject: fixes to shader to get most new demos working on mobile --- drivers/gles2/shaders/canvas.glsl | 10 +++++----- .../com/android/vending/expansion/downloader/BuildConfig.java | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/gles2/shaders/canvas.glsl b/drivers/gles2/shaders/canvas.glsl index e6d2569977..bd10c49559 100644 --- a/drivers/gles2/shaders/canvas.glsl +++ b/drivers/gles2/shaders/canvas.glsl @@ -36,7 +36,7 @@ uniform vec2 normal_flip; #endif #ifdef USE_SHADOWS -highp varying vec2 pos; +varying highp vec2 pos; #endif #endif @@ -161,11 +161,11 @@ varying vec4 local_rot; #ifdef USE_SHADOWS -uniform sampler2D shadow_texture; +uniform highp sampler2D shadow_texture; uniform float shadow_attenuation; uniform highp mat4 shadow_matrix; -highp varying vec2 pos; +varying highp vec2 pos; uniform float shadowpixel_size; #ifdef SHADOW_ESM @@ -292,12 +292,12 @@ LIGHT_SHADER_CODE } - vec4 s = shadow_matrix * vec4(point,0.0,1.0); + highp vec4 s = shadow_matrix * highp vec4(point,0.0,1.0); s.xyz/=s.w; su=s.x*0.5+0.5; sz=s.z*0.5+0.5; - float shadow_attenuation; + highp float shadow_attenuation; #ifdef SHADOW_PCF5 diff --git a/platform/android/libs/downloader_library/gen/com/android/vending/expansion/downloader/BuildConfig.java b/platform/android/libs/downloader_library/gen/com/android/vending/expansion/downloader/BuildConfig.java index 77ebb4b780..da9d06e63c 100644 --- a/platform/android/libs/downloader_library/gen/com/android/vending/expansion/downloader/BuildConfig.java +++ b/platform/android/libs/downloader_library/gen/com/android/vending/expansion/downloader/BuildConfig.java @@ -2,5 +2,5 @@ package com.android.vending.expansion.downloader; public final class BuildConfig { - public final static boolean DEBUG = true; + public final static boolean DEBUG = false; } \ No newline at end of file -- cgit v1.2.3 From ad634876b5b7d775f6d490cf7f874c6aae058a28 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Tue, 31 Mar 2015 14:58:52 -0300 Subject: fixes for light2d in androids that do not support read depth --- demos/2d/lights_shadows/light_shadows.scn | Bin 4293 -> 4293 bytes drivers/gles2/rasterizer_gles2.cpp | 2 ++ drivers/gles2/shaders/canvas.glsl | 53 +++++++++++++++++++----------- platform/android/detect.py | 4 +-- 4 files changed, 37 insertions(+), 22 deletions(-) diff --git a/demos/2d/lights_shadows/light_shadows.scn b/demos/2d/lights_shadows/light_shadows.scn index 34781b8049..a13e31376e 100644 Binary files a/demos/2d/lights_shadows/light_shadows.scn and b/demos/2d/lights_shadows/light_shadows.scn differ diff --git a/drivers/gles2/rasterizer_gles2.cpp b/drivers/gles2/rasterizer_gles2.cpp index 05c977f344..d2bf28a1bc 100644 --- a/drivers/gles2/rasterizer_gles2.cpp +++ b/drivers/gles2/rasterizer_gles2.cpp @@ -9129,6 +9129,7 @@ void RasterizerGLES2::canvas_render_items(CanvasItem *p_item_list,int p_z,const canvas_shader.set_conditional(CanvasShaderGLES2::USE_MODULATE,canvas_use_modulate); canvas_shader.set_conditional(CanvasShaderGLES2::USE_DISTANCE_FIELD,false); + bool reset_modulate=false; bool prev_distance_field=false; @@ -10578,6 +10579,7 @@ void RasterizerGLES2::init() { shadow_mat_ptr = material_owner.get(shadow_material); overdraw_material = create_overdraw_debug_material(); copy_shader.set_conditional(CopyShaderGLES2::USE_8BIT_HDR,!use_fp16_fb); + canvas_shader.set_conditional(CanvasShaderGLES2::USE_DEPTH_SHADOWS,read_depth_supported); canvas_shader.set_conditional(CanvasShaderGLES2::USE_PIXEL_SNAP,GLOBAL_DEF("rasterizer/use_pixel_snap",false)); diff --git a/drivers/gles2/shaders/canvas.glsl b/drivers/gles2/shaders/canvas.glsl index bd10c49559..afa58b7741 100644 --- a/drivers/gles2/shaders/canvas.glsl +++ b/drivers/gles2/shaders/canvas.glsl @@ -299,32 +299,45 @@ LIGHT_SHADER_CODE highp float shadow_attenuation; +#ifdef USE_DEPTH_SHADOWS + +#define SHADOW_DEPTH(m_tex,m_uv) (texture2D((m_tex),(m_uv)).z) + +#else + +//#define SHADOW_DEPTH(m_tex,m_uv) dot(texture2D((m_tex),(m_uv)),highp vec4(1.0 / (256.0 * 256.0 * 256.0),1.0 / (256.0 * 256.0),1.0 / 256.0,1) ) +#define SHADOW_DEPTH(m_tex,m_uv) dot(texture2D((m_tex),(m_uv)),vec4(1.0 / (256.0 * 256.0 * 256.0),1.0 / (256.0 * 256.0),1.0 / 256.0,1) ) + +#endif + + + #ifdef SHADOW_PCF5 shadow_attenuation=0.0; - shadow_attenuation += texture2D(shadow_texture,vec2(su,sh)).z Date: Tue, 31 Mar 2015 20:26:38 +0200 Subject: New node will be added to root node if nothing is selected --- tools/editor/scene_tree_dock.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tools/editor/scene_tree_dock.cpp b/tools/editor/scene_tree_dock.cpp index 2012d96664..84b34cf130 100644 --- a/tools/editor/scene_tree_dock.cpp +++ b/tools/editor/scene_tree_dock.cpp @@ -1059,14 +1059,15 @@ void SceneTreeDock::_create() { if (edited_scene) { - + // If root exists in edited scene parent = scene_tree->get_selected(); - ERR_FAIL_COND(!parent); - } else { + if( !parent ) + parent = edited_scene; + } else { + // If no root exist in edited scene parent = scene_root; ERR_FAIL_COND(!parent); - } Object *c = create_dialog->instance_selected(); -- cgit v1.2.3 From 7fc4059b1311afbf986f4b356bb93cd164ba829a Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Tue, 31 Mar 2015 17:57:16 -0300 Subject: read depth fixes --- drivers/gles2/rasterizer_gles2.cpp | 75 ++++++++++++++++++++++++++++++--- drivers/gles2/rasterizer_gles2.h | 1 + platform/android/detect.py | 2 +- servers/visual/visual_server_raster.cpp | 2 +- 4 files changed, 73 insertions(+), 7 deletions(-) diff --git a/drivers/gles2/rasterizer_gles2.cpp b/drivers/gles2/rasterizer_gles2.cpp index d2bf28a1bc..ae5f3d8f2f 100644 --- a/drivers/gles2/rasterizer_gles2.cpp +++ b/drivers/gles2/rasterizer_gles2.cpp @@ -8559,6 +8559,7 @@ RID RasterizerGLES2::canvas_light_shadow_buffer_create(int p_width) { #ifdef GLEW_ENABLED glDrawBuffer(GL_NONE); #endif + } else { // We'll use a RGBA texture into which we pack the depth info glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, cls->size, cls->height, 0, @@ -8567,6 +8568,7 @@ RID RasterizerGLES2::canvas_light_shadow_buffer_create(int p_width) { // Attach the RGBA texture to FBO color attachment point glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, cls->depth, 0); + cls->rgba=cls->depth; // Allocate 16-bit depth buffer glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, cls->size, cls->height); @@ -8845,10 +8847,14 @@ void RasterizerGLES2::canvas_debug_viewport_shadows(CanvasLight* p_lights_with_s int h = 10; int w = viewport.width; int ofs = h; + + //print_line(" debug lights "); while(light) { + // print_line("debug light"); if (light->shadow_buffer.is_valid()) { + // print_line("sb is valid"); CanvasLightShadow * sb = canvas_light_shadow_owner.get(light->shadow_buffer); if (sb) { glActiveTexture(GL_TEXTURE0); @@ -9858,9 +9864,9 @@ void RasterizerGLES2::free(const RID& p_rid) { glDeleteFramebuffers(1,&cls->fbo); glDeleteRenderbuffers(1,&cls->rbo); glDeleteTextures(1,&cls->depth); - if (!read_depth_supported) { - glDeleteTextures(1,&cls->rgba); - } + //if (!read_depth_supported) { + // glDeleteTextures(1,&cls->rgba); + //} canvas_light_shadow_owner.free(p_rid); memdelete(cls); @@ -10366,6 +10372,62 @@ void RasterizerGLES2::_update_blur_buffer() { } #endif + + +bool RasterizerGLES2::_test_depth_shadow_buffer() { + + + int size=16; + + GLuint fbo; + GLuint rbo; + GLuint depth; + + glActiveTexture(GL_TEXTURE0); + + glGenFramebuffers(1, &fbo); + glBindFramebuffer(GL_FRAMEBUFFER, fbo); + + // Create a render buffer + glGenRenderbuffers(1, &rbo); + glBindRenderbuffer(GL_RENDERBUFFER, rbo); + + // Create a texture for storing the depth + glGenTextures(1, &depth); + glBindTexture(GL_TEXTURE_2D, depth); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + + // Remove artifact on the edges of the shadowmap + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + + + + // We'll use a depth texture to store the depths in the shadow map + glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, size, size, 0, + GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL); + +#ifdef GLEW_ENABLED + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); +#endif + + // Attach the depth texture to FBO depth attachment point + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, + GL_TEXTURE_2D, depth, 0); + + + GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); + + glDeleteFramebuffers(1,&fbo); + glDeleteRenderbuffers(1,&rbo); + glDeleteTextures(1,&depth); + + return status == GL_FRAMEBUFFER_COMPLETE; + +} + void RasterizerGLES2::init() { #ifdef GLEW_ENABLED @@ -10438,7 +10500,7 @@ void RasterizerGLES2::init() { #ifdef GLEW_ENABLED - read_depth_supported=true; + pvr_supported=false; etc_supported=false; use_depth24 =true; @@ -10456,7 +10518,10 @@ void RasterizerGLES2::init() { use_anisotropic_filter=true; float_linear_supported=true; float_supported=true; - use_rgba_shadowmaps=false; + + read_depth_supported=_test_depth_shadow_buffer(); + use_rgba_shadowmaps=!read_depth_supported; + //print_line("read depth support? "+itos(read_depth_supported)); glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT,&anisotropic_level); anisotropic_level=MIN(anisotropic_level,float(GLOBAL_DEF("rasterizer/anisotropic_filter_level",4.0))); diff --git a/drivers/gles2/rasterizer_gles2.h b/drivers/gles2/rasterizer_gles2.h index b7895ad82e..ad18c8e7a1 100644 --- a/drivers/gles2/rasterizer_gles2.h +++ b/drivers/gles2/rasterizer_gles2.h @@ -1288,6 +1288,7 @@ class RasterizerGLES2 : public Rasterizer { void _copy_screen_quad(); void _copy_to_texscreen(); + bool _test_depth_shadow_buffer(); Vector3 chunk_vertex; Vector3 chunk_normal; diff --git a/platform/android/detect.py b/platform/android/detect.py index 86743fc370..5ef405f7b6 100644 --- a/platform/android/detect.py +++ b/platform/android/detect.py @@ -24,7 +24,7 @@ def get_opts(): ('NDK_TOOLCHAIN', 'toolchain to use for the NDK',"arm-eabi-4.4.0"), #android 2.3 ('ndk_platform', 'compile for platform: (2.2,2.3)',"2.2"), - ('NDK_TARGET', 'toolchain to use for the NDK',"arm-linux-androideabi-4.9"), + ('NDK_TARGET', 'toolchain to use for the NDK',"arm-linux-androideabi-4.8"), ('android_stl','enable STL support in android port (for modules)','no'), ('armv6','compile for older phones running arm v6 (instead of v7+neon+smp)','no'), ('x86','Xompile for Android-x86','no') diff --git a/servers/visual/visual_server_raster.cpp b/servers/visual/visual_server_raster.cpp index 83bfbbc6c3..916316a0e2 100644 --- a/servers/visual/visual_server_raster.cpp +++ b/servers/visual/visual_server_raster.cpp @@ -7155,7 +7155,7 @@ void VisualServerRaster::_draw_viewport(Viewport *p_viewport,int p_ofs_x, int p_ } - //rasterizer->canvas_debug_viewport_shadows(lights_with_shadow); +// rasterizer->canvas_debug_viewport_shadows(lights_with_shadow); } //capture -- cgit v1.2.3 From 3920c497b3811b3c0c970631599c13025c81ff14 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Tue, 31 Mar 2015 19:02:40 -0300 Subject: Option in Android export to use 32 bits buffer. --- demos/2d/isometric_light/export.cfg | 262 --------------------- platform/android/export/export.cpp | 13 + .../android/java/src/com/android/godot/Godot.java | 7 +- .../java/src/com/android/godot/GodotView.java | 18 +- 4 files changed, 32 insertions(+), 268 deletions(-) delete mode 100644 demos/2d/isometric_light/export.cfg diff --git a/demos/2d/isometric_light/export.cfg b/demos/2d/isometric_light/export.cfg deleted file mode 100644 index 578d4171b2..0000000000 --- a/demos/2d/isometric_light/export.cfg +++ /dev/null @@ -1,262 +0,0 @@ -[convert_images] - -action="none" -compress_quality=0.7 -formats="png" -shrink=1 - -[export_filter] - -filter="" -type="resources" - -[image_group_files] - -files=["res://faceNormal.png", "normal", "res://faceColor.png", "normal", "res://faceMask.png", "normal"] - -[image_groups] - -normal={"atlas":false, "action":"compress_ram", "shrink":1, "lossy_quality":0.7} - -[platform:Android] - -apk_expansion/SALT="" -apk_expansion/enable=false -apk_expansion/public_key="" -command_line/extra_args="" -custom_package/debug="" -custom_package/release="" -keystore/release="" -keystore/release_password="" -keystore/release_user="" -one_click_deploy/clear_previous_install=true -package/icon="" -package/name="" -package/signed=true -package/unique_name="com.android.noname" -permissions/access_checkin_properties=false -permissions/access_coarse_location=false -permissions/access_fine_location=false -permissions/access_location_extra_commands=false -permissions/access_mock_location=false -permissions/access_network_state=false -permissions/access_surface_flinger=false -permissions/access_wifi_state=false -permissions/account_manager=false -permissions/add_voicemail=false -permissions/authenticate_accounts=false -permissions/battery_stats=false -permissions/bind_accessibility_service=false -permissions/bind_appwidget=false -permissions/bind_device_admin=false -permissions/bind_input_method=false -permissions/bind_nfc_service=false -permissions/bind_notification_listener_service=false -permissions/bind_print_service=false -permissions/bind_remoteviews=false -permissions/bind_text_service=false -permissions/bind_vpn_service=false -permissions/bind_wallpaper=false -permissions/bluetooth=false -permissions/bluetooth_admin=false -permissions/bluetooth_privileged=false -permissions/brick=false -permissions/broadcast_package_removed=false -permissions/broadcast_sms=false -permissions/broadcast_sticky=false -permissions/broadcast_wap_push=false -permissions/call_phone=false -permissions/call_privileged=false -permissions/camera=false -permissions/capture_audio_output=false -permissions/capture_secure_video_output=false -permissions/capture_video_output=false -permissions/change_component_enabled_state=false -permissions/change_configuration=false -permissions/change_network_state=false -permissions/change_wifi_multicast_state=false -permissions/change_wifi_state=false -permissions/clear_app_cache=false -permissions/clear_app_user_data=false -permissions/control_location_updates=false -permissions/delete_cache_files=false -permissions/delete_packages=false -permissions/device_power=false -permissions/diagnostic=false -permissions/disable_keyguard=false -permissions/dump=false -permissions/expand_status_bar=false -permissions/factory_test=false -permissions/flashlight=false -permissions/force_back=false -permissions/get_accounts=false -permissions/get_package_size=false -permissions/get_tasks=false -permissions/get_top_activity_info=false -permissions/global_search=false -permissions/hardware_test=false -permissions/inject_events=false -permissions/install_location_provider=false -permissions/install_packages=false -permissions/install_shortcut=false -permissions/internal_system_window=false -permissions/internet=false -permissions/kill_background_processes=false -permissions/location_hardware=false -permissions/manage_accounts=false -permissions/manage_app_tokens=false -permissions/manage_documents=false -permissions/master_clear=false -permissions/media_content_control=false -permissions/modify_audio_settings=false -permissions/modify_phone_state=false -permissions/mount_format_filesystems=false -permissions/mount_unmount_filesystems=false -permissions/nfc=false -permissions/persistent_activity=false -permissions/process_outgoing_calls=false -permissions/read_calendar=false -permissions/read_call_log=false -permissions/read_contacts=false -permissions/read_external_storage=false -permissions/read_frame_buffer=false -permissions/read_history_bookmarks=false -permissions/read_input_state=false -permissions/read_logs=false -permissions/read_phone_state=false -permissions/read_profile=false -permissions/read_sms=false -permissions/read_social_stream=false -permissions/read_sync_settings=false -permissions/read_sync_stats=false -permissions/read_user_dictionary=false -permissions/reboot=false -permissions/receive_boot_completed=false -permissions/receive_mms=false -permissions/receive_sms=false -permissions/receive_wap_push=false -permissions/record_audio=false -permissions/reorder_tasks=false -permissions/restart_packages=false -permissions/send_respond_via_message=false -permissions/send_sms=false -permissions/set_activity_watcher=false -permissions/set_alarm=false -permissions/set_always_finish=false -permissions/set_animation_scale=false -permissions/set_debug_app=false -permissions/set_orientation=false -permissions/set_pointer_speed=false -permissions/set_preferred_applications=false -permissions/set_process_limit=false -permissions/set_time=false -permissions/set_time_zone=false -permissions/set_wallpaper=false -permissions/set_wallpaper_hints=false -permissions/signal_persistent_processes=false -permissions/status_bar=false -permissions/subscribed_feeds_read=false -permissions/subscribed_feeds_write=false -permissions/system_alert_window=false -permissions/transmit_ir=false -permissions/uninstall_shortcut=false -permissions/update_device_stats=false -permissions/use_credentials=false -permissions/use_sip=false -permissions/vibrate=false -permissions/wake_lock=false -permissions/write_apn_settings=false -permissions/write_calendar=false -permissions/write_call_log=false -permissions/write_contacts=false -permissions/write_external_storage=false -permissions/write_gservices=false -permissions/write_history_bookmarks=false -permissions/write_profile=false -permissions/write_secure_settings=false -permissions/write_settings=false -permissions/write_sms=false -permissions/write_social_stream=false -permissions/write_sync_settings=false -permissions/write_user_dictionary=false -screen/orientation=0 -screen/support_large=true -screen/support_normal=true -screen/support_small=true -screen/support_xlarge=true -user_permissions/0="" -user_permissions/1="" -user_permissions/10="" -user_permissions/11="" -user_permissions/12="" -user_permissions/13="" -user_permissions/14="" -user_permissions/15="" -user_permissions/16="" -user_permissions/17="" -user_permissions/18="" -user_permissions/19="" -user_permissions/2="" -user_permissions/3="" -user_permissions/4="" -user_permissions/5="" -user_permissions/6="" -user_permissions/7="" -user_permissions/8="" -user_permissions/9="" -version/code=1 -version/name="1.0" - -[platform:BlackBerry 10] - -package/category="core.games" -package/custom_template="" -package/description="Game made with Godot Engine" -package/icon="" -package/name="" -package/unique_name="com.godot.noname" -release/author="Cert. Name" -release/author_id="Cert. ID" -version/code=1 -version/name="1.0" - -[platform:HTML5] - -browser/enable_run=false -custom_package/debug="" -custom_package/release="" -options/memory_size=3 - -[platform:Linux X11] - -binary/64_bits=true -custom_binary/debug="" -custom_binary/release="" -resources/pack_mode=1 - -[platform:Mac OSX] - -application/64_bits=false -application/copyright="" -application/icon="" -application/identifier="com.godot.macgame" -application/info="This Game is Nice" -application/name="" -application/short_version="1.0" -application/signature="godotmacgame" -application/version="1.0" -custom_package/debug="" -custom_package/release="" -display/high_res=false - -[platform:Windows Desktop] - -binary/64_bits=true -custom_binary/debug="" -custom_binary/release="" -resources/pack_mode=1 - -[script] - -action="compile" -encrypt_key="" diff --git a/platform/android/export/export.cpp b/platform/android/export/export.cpp index 3e4ea8a4e0..18747734ab 100644 --- a/platform/android/export/export.cpp +++ b/platform/android/export/export.cpp @@ -185,6 +185,7 @@ class EditorExportPlatformAndroid : public EditorExportPlatform { bool _signed; bool apk_expansion; bool remove_prev; + bool use_32_fb; String apk_expansion_salt; String apk_expansion_pkey; int orientation; @@ -279,6 +280,8 @@ bool EditorExportPlatformAndroid::_set(const StringName& p_name, const Variant& icon=p_value; else if (n=="package/signed") _signed=p_value; + else if (n=="screen/use_32_bits_view") + use_32_fb=p_value; else if (n=="screen/orientation") orientation=p_value; else if (n=="screen/support_small") @@ -344,6 +347,8 @@ bool EditorExportPlatformAndroid::_get(const StringName& p_name,Variant &r_ret) r_ret=icon; else if (n=="package/signed") r_ret=_signed; + else if (n=="screen/use_32_bits_view") + r_ret=use_32_fb; else if (n=="screen/orientation") r_ret=orientation; else if (n=="screen/support_small") @@ -393,6 +398,7 @@ void EditorExportPlatformAndroid::_get_property_list( List *p_list p_list->push_back( PropertyInfo( Variant::STRING, "package/name") ); p_list->push_back( PropertyInfo( Variant::STRING, "package/icon",PROPERTY_HINT_FILE,"png") ); p_list->push_back( PropertyInfo( Variant::BOOL, "package/signed") ); + p_list->push_back( PropertyInfo( Variant::BOOL, "screen/use_32_bits_view") ); p_list->push_back( PropertyInfo( Variant::INT, "screen/orientation",PROPERTY_HINT_ENUM,"Landscape,Portrait") ); p_list->push_back( PropertyInfo( Variant::BOOL, "screen/support_small") ); p_list->push_back( PropertyInfo( Variant::BOOL, "screen/support_normal") ); @@ -1158,8 +1164,14 @@ Error EditorExportPlatformAndroid::export_project(const String& p_path, bool p_d err = export_project_files(save_apk_file,&ed,false); } + + } + if (use_32_fb) + cl.push_back("-use_depth_32"); + + if (cl.size()) { //add comandline Vector clf; @@ -1534,6 +1546,7 @@ EditorExportPlatformAndroid::EditorExportPlatformAndroid() { quit_request=false; orientation=0; remove_prev=true; + use_32_fb=false; device_thread=Thread::create(_device_poll_thread,this); devices_changed=true; diff --git a/platform/android/java/src/com/android/godot/Godot.java b/platform/android/java/src/com/android/godot/Godot.java index 1a7659a473..1fd37c98cd 100644 --- a/platform/android/java/src/com/android/godot/Godot.java +++ b/platform/android/java/src/com/android/godot/Godot.java @@ -109,6 +109,7 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC private Button mPauseButton; private Button mWiFiSettingsButton; + private boolean use_32_bits=false; private boolean mStatePaused; private int mState; @@ -255,7 +256,7 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC // ...add to FrameLayout layout.addView(edittext); - mView = new GodotView(getApplication(),io,use_gl2, this); + mView = new GodotView(getApplication(),io,use_gl2,use_32_bits, this); layout.addView(mView,new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT)); mView.setKeepScreenOn(true); @@ -399,7 +400,9 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC for(int i=0;i Date: Wed, 1 Apr 2015 12:23:13 -0300 Subject: fix shadow attenuation --- drivers/gles2/shaders/canvas.glsl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/gles2/shaders/canvas.glsl b/drivers/gles2/shaders/canvas.glsl index afa58b7741..12ff43479b 100644 --- a/drivers/gles2/shaders/canvas.glsl +++ b/drivers/gles2/shaders/canvas.glsl @@ -297,7 +297,7 @@ LIGHT_SHADER_CODE su=s.x*0.5+0.5; sz=s.z*0.5+0.5; - highp float shadow_attenuation; + highp float shadow_attenuation=0.0; #ifdef USE_DEPTH_SHADOWS @@ -314,7 +314,6 @@ LIGHT_SHADER_CODE #ifdef SHADOW_PCF5 - shadow_attenuation=0.0; shadow_attenuation += SHADOW_DEPTH(shadow_texture,vec2(su,sh)) Date: Wed, 1 Apr 2015 12:39:54 -0300 Subject: solved color depth issues on osx --- platform/osx/os_osx.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm index 55ef6c1516..5556a71918 100644 --- a/platform/osx/os_osx.mm +++ b/platform/osx/os_osx.mm @@ -903,7 +903,7 @@ void OS_OSX::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi unsigned int attributeCount = 0; // OS X needs non-zero color size, so set resonable values - int colorBits = 24; + int colorBits = 32; // Fail if a robustness strategy was requested -- cgit v1.2.3 From 7c1d516c013be7469b4bc4a8b6ef0b71381b160f Mon Sep 17 00:00:00 2001 From: Ariel m Date: Thu, 2 Apr 2015 01:32:02 -0300 Subject: fullscreen thing --- platform/osx/os_osx.h | 32 ++++++++-- platform/osx/os_osx.mm | 156 ++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 168 insertions(+), 20 deletions(-) diff --git a/platform/osx/os_osx.h b/platform/osx/os_osx.h index 8f121b7dd5..9ffd4fc3f8 100644 --- a/platform/osx/os_osx.h +++ b/platform/osx/os_osx.h @@ -99,6 +99,13 @@ public: CursorShape cursor_shape; MouseMode mouse_mode; + + bool minimized; + bool maximized; + bool zoomed; + Vector screens; + int current_screen; + Rect2 restore_rect; protected: virtual int get_video_driver_count() const; @@ -112,16 +119,13 @@ protected: virtual void set_main_loop( MainLoop * p_main_loop ); virtual void delete_main_loop(); - public: - - - - static OS_OSX* singleton; + void wm_minimized(bool p_minimized); + virtual String get_name(); virtual void set_cursor_shape(CursorShape p_shape); @@ -162,6 +166,24 @@ public: virtual void move_window_to_foreground(); + 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_window_position() const; + virtual void set_window_position(const Point2& p_position); + virtual void set_window_size(const Size2 p_size); + virtual void set_window_fullscreen(bool p_enabled); + virtual bool is_window_fullscreen() const; + virtual void set_window_resizable(bool p_enabled); + virtual bool is_window_resizable() const; + virtual void set_window_minimized(bool p_enabled); + virtual bool is_window_minimized() const; + virtual void set_window_maximized(bool p_enabled); + virtual bool is_window_maximized() const; + Size2 get_screen_size(int p_screen); + + void run(); void set_mouse_mode(MouseMode p_mode); diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm index 55ef6c1516..826e3b7f55 100644 --- a/platform/osx/os_osx.mm +++ b/platform/osx/os_osx.mm @@ -227,19 +227,6 @@ static int button_mask=0; // centerCursor(window); } -- (void)windowDidMiniaturize:(NSNotification *)notification -{ - // _GodotInputWindowIconify(window, GL_TRUE); -} - -- (void)windowDidDeminiaturize:(NSNotification *)notification -{ - //if (window->monitor) -// enterFullscreenMode(window); - - // _GodotInputWindowIconify(window, GL_FALSE); -} - - (void)windowDidBecomeKey:(NSNotification *)notification { // _GodotInputWindowFocus(window, GL_TRUE); @@ -256,6 +243,21 @@ static int button_mask=0; OS_OSX::singleton->get_main_loop()->notification(MainLoop::NOTIFICATION_WM_FOCUS_OUT); } +- (void)windowDidMiniaturize:(NSNotification*)notification +{ + OS_OSX::singleton->wm_minimized(true); + if (OS_OSX::singleton->get_main_loop()) + OS_OSX::singleton->get_main_loop()->notification(MainLoop::NOTIFICATION_WM_FOCUS_OUT); +}; + +- (void)windowDidDeminiaturize:(NSNotification*)notification +{ + + OS_OSX::singleton->wm_minimized(false); + if (OS_OSX::singleton->get_main_loop()) + OS_OSX::singleton->get_main_loop()->notification(MainLoop::NOTIFICATION_WM_FOCUS_IN); +}; + @end @interface GodotContentView : NSView @@ -1018,7 +1020,15 @@ void OS_OSX::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi _ensure_data_dir(); + NSArray *screenArray = [NSScreen screens]; + printf("nscreen count %i\n", (int)[screenArray count]); + for (int i=0; i<[screenArray count]; i++) { + NSRect nsrect = [[screenArray objectAtIndex: i] visibleFrame]; + screens.push_back(Rect2(nsrect.origin.x, nsrect.origin.y, nsrect.size.width, nsrect.size.height)); + printf("added screen %i\n", screens.size()); + }; + restore_rect = Rect2(get_window_position(), get_window_size()); } void OS_OSX::finalize() { @@ -1231,7 +1241,10 @@ void OS_OSX::swap_buffers() { } +void OS_OSX::wm_minimized(bool p_minimized) { + minimized = p_minimized; +}; void OS_OSX::set_video_mode(const VideoMode& p_video_mode,int p_screen) { @@ -1245,9 +1258,118 @@ void OS_OSX::get_fullscreen_mode_list(List *p_list,int p_screen) cons } + +int OS_OSX::get_screen_count() const { + + return screens.size(); +}; + +int OS_OSX::get_current_screen() const { + + return current_screen; +}; + +void OS_OSX::set_current_screen(int p_screen) { + + current_screen = p_screen; +}; + +Point2 OS_OSX::get_screen_position(int p_screen) { + + ERR_FAIL_INDEX_V(p_screen, screens.size(), Point2()); + return screens[p_screen].pos; +}; + +Size2 OS_OSX::get_screen_size(int p_screen) { + + ERR_FAIL_INDEX_V(p_screen, screens.size(), Point2()); + return screens[p_screen].size; +}; + +Point2 OS_OSX::get_window_position() const { + + return Size2([window_object frame].origin.x, [window_object frame].origin.y); +}; + + +void OS_OSX::set_window_position(const Point2& p_position) { + + [window_object setFrame:NSMakeRect(p_position.x, p_position.y, [window_object frame].size.width, [window_object frame].size.height) display:YES]; +}; + Size2 OS_OSX::get_window_size() const { - return Vector2(current_videomode.width, current_videomode.height); -} + + return Size2([window_object frame].size.width, [window_object frame].size.height); +}; + +void OS_OSX::set_window_size(const Size2 p_size) { + + NSRect frame = [window_object frame]; + [window_object setFrame:NSMakeRect(frame.origin.x, frame.origin.y, p_size.x, p_size.y) display:YES]; +}; + +void OS_OSX::set_window_fullscreen(bool p_enabled) { + + [window_object performZoom:nil]; + zoomed = p_enabled; +}; + +bool OS_OSX::is_window_fullscreen() const { + + if ( [window_object respondsToSelector:@selector(isZoomed)] ) + return [window_object isZoomed]; + + return zoomed; +}; + +void OS_OSX::set_window_resizable(bool p_enabled) { + + if (p_enabled) + [window_object setStyleMask:[window_object styleMask] | NSResizableWindowMask ]; + else + [window_object setStyleMask:[window_object styleMask] & ~NSResizableWindowMask ]; +}; + +bool OS_OSX::is_window_resizable() const { + + return [window_object styleMask] & NSResizableWindowMask; +}; + +void OS_OSX::set_window_minimized(bool p_enabled) { + + if (p_enabled) + [window_object performMiniaturize:nil]; + else + [window_object deminiaturize:nil]; +}; + +bool OS_OSX::is_window_minimized() const { + + if ( [window_object respondsToSelector:@selector(isMiniaturized)]) + return [window_object isMiniaturized]; + + return minimized; +}; + + +void OS_OSX::set_window_maximized(bool p_enabled) { + + if (p_enabled) { + restore_rect = Rect2(get_window_position(), get_window_size()); + [window_object setFrame:[[[NSScreen screens] objectAtIndex:current_screen] visibleFrame] display:YES]; + } else { + set_window_size(restore_rect.size); + set_window_position(restore_rect.pos); + }; + maximized = p_enabled; +}; + +bool OS_OSX::is_window_maximized() const { + + // don't know + return maximized; +}; + void OS_OSX::move_window_to_foreground() { @@ -1477,5 +1599,9 @@ OS_OSX::OS_OSX() { last_id=1; cursor_shape=CURSOR_ARROW; + current_screen = 0; + maximized = false; + minimized = false; + zoomed = false; } -- cgit v1.2.3 From 1572238adb5b68e18cf20ec73b2f437736e21152 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Thu, 2 Apr 2015 07:22:17 -0300 Subject: merging okam changes --- core/event_queue.cpp | 18 +++++++--- scene/2d/physics_body_2d.cpp | 2 +- scene/2d/visibility_notifier_2d.cpp | 7 +++- scene/3d/navigation.cpp | 6 ++-- scene/3d/navigation.h | 2 +- scene/gui/control.cpp | 2 +- .../editor/plugins/sprite_frames_editor_plugin.cpp | 37 +++++++++++++++++++- tools/editor/plugins/sprite_frames_editor_plugin.h | 2 ++ tools/export/blender25/io_scene_dae/export_dae.py | 39 ++++++++++++---------- 9 files changed, 84 insertions(+), 31 deletions(-) diff --git a/core/event_queue.cpp b/core/event_queue.cpp index cf6e742f79..161fb4fedd 100644 --- a/core/event_queue.cpp +++ b/core/event_queue.cpp @@ -56,28 +56,36 @@ Error EventQueue::push_call(uint32_t p_instance_ID, const StringName& p_method, buffer_end+=sizeof(Event); - if (args==1) { + if (args>=1) { Variant * v = memnew_placement( &event_buffer[ buffer_end ], Variant ); buffer_end+=sizeof(Variant); *v=p_arg1; - } else if (args==2) { + } + + if (args>=2) { Variant * v = memnew_placement( &event_buffer[ buffer_end ], Variant ); buffer_end+=sizeof(Variant); *v=p_arg2; - } else if (args==3) { + } + + if (args>=3) { Variant * v = memnew_placement( &event_buffer[ buffer_end ], Variant ); buffer_end+=sizeof(Variant); *v=p_arg3; - } else if (args==4) { + } + + if (args>=4) { Variant * v = memnew_placement( &event_buffer[ buffer_end ], Variant ); buffer_end+=sizeof(Variant); *v=p_arg4; - } else if (args==5) { + } + + if (args>=5) { Variant * v = memnew_placement( &event_buffer[ buffer_end ], Variant ); buffer_end+=sizeof(Variant); diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp index 22dd0f01d0..5457182ea7 100644 --- a/scene/2d/physics_body_2d.cpp +++ b/scene/2d/physics_body_2d.cpp @@ -1198,7 +1198,7 @@ void KinematicBody2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("move","rel_vec"),&KinematicBody2D::move); ObjectTypeDB::bind_method(_MD("move_to","position"),&KinematicBody2D::move_to); - ObjectTypeDB::bind_method(_MD("can_move_to","position"),&KinematicBody2D::can_move_to); + ObjectTypeDB::bind_method(_MD("can_move_to","position","discrete"),&KinematicBody2D::can_move_to,DEFVAL(false)); ObjectTypeDB::bind_method(_MD("is_colliding"),&KinematicBody2D::is_colliding); diff --git a/scene/2d/visibility_notifier_2d.cpp b/scene/2d/visibility_notifier_2d.cpp index cd3c788b65..abaaf3262a 100644 --- a/scene/2d/visibility_notifier_2d.cpp +++ b/scene/2d/visibility_notifier_2d.cpp @@ -65,8 +65,13 @@ void VisibilityNotifier2D::_exit_viewport(Viewport* p_viewport){ void VisibilityNotifier2D::set_rect(const Rect2& p_rect){ rect=p_rect; - if (is_inside_tree()) + if (is_inside_tree()) { get_world_2d()->_update_notifier(this,get_global_transform().xform(rect)); + if (get_tree()->is_editor_hint()) { + update(); + item_rect_changed(); + } + } _change_notify("rect"); } diff --git a/scene/3d/navigation.cpp b/scene/3d/navigation.cpp index ce002fb44b..6612d6bf12 100644 --- a/scene/3d/navigation.cpp +++ b/scene/3d/navigation.cpp @@ -490,10 +490,10 @@ Vector Navigation::get_simple_path(const Vector3& p_start, const Vector } -Vector3 Navigation::get_closest_point_to_segment(const Vector3& p_from,const Vector3& p_to) { +Vector3 Navigation::get_closest_point_to_segment(const Vector3& p_from,const Vector3& p_to,const bool& p_use_collision) { - bool use_collision=false; + bool use_collision=p_use_collision; Vector3 closest_point; float closest_point_d=1e20; NavMesh *closest_navmesh=NULL; @@ -633,7 +633,7 @@ void Navigation::_bind_methods() { ObjectTypeDB::bind_method(_MD("navmesh_remove","id"),&Navigation::navmesh_remove); ObjectTypeDB::bind_method(_MD("get_simple_path","start","end","optimize"),&Navigation::get_simple_path,DEFVAL(true)); - ObjectTypeDB::bind_method(_MD("get_closest_point_to_segment","start","end"),&Navigation::get_closest_point_to_segment); + ObjectTypeDB::bind_method(_MD("get_closest_point_to_segment","start","end","use_collision"),&Navigation::get_closest_point_to_segment,DEFVAL(false)); ObjectTypeDB::bind_method(_MD("get_closest_point","to_point"),&Navigation::get_closest_point); ObjectTypeDB::bind_method(_MD("get_closest_point_normal","to_point"),&Navigation::get_closest_point_normal); diff --git a/scene/3d/navigation.h b/scene/3d/navigation.h index 69d48531a7..19977c3110 100644 --- a/scene/3d/navigation.h +++ b/scene/3d/navigation.h @@ -135,7 +135,7 @@ public: void navmesh_remove(int p_id); Vector get_simple_path(const Vector3& p_start, const Vector3& p_end,bool p_optimize=true); - Vector3 get_closest_point_to_segment(const Vector3& p_from,const Vector3& p_to); + Vector3 get_closest_point_to_segment(const Vector3& p_from,const Vector3& p_to,const bool& p_use_collision=false); Vector3 get_closest_point(const Vector3& p_point); Vector3 get_closest_point_normal(const Vector3& p_point); diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 86f442fd8c..c539dc3284 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -2869,7 +2869,7 @@ void Control::_bind_methods() { BIND_CONSTANT( SIZE_EXPAND_FILL ); ADD_SIGNAL( MethodInfo("resized") ); - ADD_SIGNAL( MethodInfo("input_event") ); + ADD_SIGNAL( MethodInfo("input_event",PropertyInfo(Variant::INPUT_EVENT,"ev")) ); ADD_SIGNAL( MethodInfo("mouse_enter") ); ADD_SIGNAL( MethodInfo("mouse_exit") ); ADD_SIGNAL( MethodInfo("focus_enter") ); diff --git a/tools/editor/plugins/sprite_frames_editor_plugin.cpp b/tools/editor/plugins/sprite_frames_editor_plugin.cpp index e04d9dfddb..9a9e8ee611 100644 --- a/tools/editor/plugins/sprite_frames_editor_plugin.cpp +++ b/tools/editor/plugins/sprite_frames_editor_plugin.cpp @@ -229,6 +229,33 @@ void SpriteFramesEditor::_empty_pressed() { } +void SpriteFramesEditor::_empty2_pressed() { + + + int from=-1; + + if (tree->get_selected()) { + + from = tree->get_selected()->get_metadata(0); + sel=from; + + } else { + from=frames->get_frame_count(); + } + + + + Ref r; + + undo_redo->create_action("Add Empty"); + undo_redo->add_do_method(frames,"add_frame",r,from+1); + undo_redo->add_undo_method(frames,"remove_frame",from+1); + undo_redo->add_do_method(this,"_update_library"); + undo_redo->add_undo_method(this,"_update_library"); + undo_redo->commit_action(); + +} + void SpriteFramesEditor::_up_pressed() { if (!tree->get_selected()) @@ -322,6 +349,8 @@ void SpriteFramesEditor::_update_library() { ti->set_text(0,"Frame "+itos(i)); ti->set_icon(0,frames->get_frame(i)); } + if (frames->get_frame(i).is_valid()) + ti->set_tooltip(0,frames->get_frame(i)->get_path()); ti->set_metadata(0,i); ti->set_icon_max_width(0,96); if (sel==i) @@ -355,6 +384,7 @@ void SpriteFramesEditor::_bind_methods() { ObjectTypeDB::bind_method(_MD("_input_event"),&SpriteFramesEditor::_input_event); ObjectTypeDB::bind_method(_MD("_load_pressed"),&SpriteFramesEditor::_load_pressed); ObjectTypeDB::bind_method(_MD("_empty_pressed"),&SpriteFramesEditor::_empty_pressed); + ObjectTypeDB::bind_method(_MD("_empty2_pressed"),&SpriteFramesEditor::_empty2_pressed); ObjectTypeDB::bind_method(_MD("_item_edited"),&SpriteFramesEditor::_item_edited); ObjectTypeDB::bind_method(_MD("_delete_pressed"),&SpriteFramesEditor::_delete_pressed); ObjectTypeDB::bind_method(_MD("_paste_pressed"),&SpriteFramesEditor::_paste_pressed); @@ -387,9 +417,13 @@ SpriteFramesEditor::SpriteFramesEditor() { hbc->add_child(paste); empty = memnew( Button ); - empty->set_text("Insert Empty"); + empty->set_text("Insert Empty (Before)"); hbc->add_child(empty); + empty2 = memnew( Button ); + empty2->set_text("Insert Empty (After)"); + hbc->add_child(empty2); + move_up = memnew( Button ); move_up->set_text("Up"); hbc->add_child(move_up); @@ -422,6 +456,7 @@ SpriteFramesEditor::SpriteFramesEditor() { _delete->connect("pressed", this,"_delete_pressed"); paste->connect("pressed", this,"_paste_pressed"); empty->connect("pressed", this,"_empty_pressed"); + empty2->connect("pressed", this,"_empty2_pressed"); move_up->connect("pressed", this,"_up_pressed"); move_down->connect("pressed", this,"_down_pressed"); file->connect("files_selected", this,"_file_load_request"); diff --git a/tools/editor/plugins/sprite_frames_editor_plugin.h b/tools/editor/plugins/sprite_frames_editor_plugin.h index 99c6ad486e..b0f2201b9e 100644 --- a/tools/editor/plugins/sprite_frames_editor_plugin.h +++ b/tools/editor/plugins/sprite_frames_editor_plugin.h @@ -46,6 +46,7 @@ class SpriteFramesEditor : public PanelContainer { Button *_delete; Button *paste; Button *empty; + Button *empty2; Button *move_up; Button *move_down; Tree *tree; @@ -65,6 +66,7 @@ class SpriteFramesEditor : public PanelContainer { void _file_load_request(const DVector& p_path); void _paste_pressed(); void _empty_pressed(); + void _empty2_pressed(); void _delete_pressed(); void _delete_confirm_pressed(); void _up_pressed(); diff --git a/tools/export/blender25/io_scene_dae/export_dae.py b/tools/export/blender25/io_scene_dae/export_dae.py index 5e5febfb1f..020ab6ca08 100644 --- a/tools/export/blender25/io_scene_dae/export_dae.py +++ b/tools/export/blender25/io_scene_dae/export_dae.py @@ -208,13 +208,16 @@ class DaeExporter: imgid = self.new_id("image") + + print("FOR: "+imgpath) - if (not os.path.isfile(imgpath)): - if imgpath.endswith((".bmp",".rgb",".png",".jpeg",".jpg",".jp2",".tga",".cin",".dpx",".exr",".hdr",".tif")): - imgpath="images/"+os.path.basename(imgpath) - else: - imgpath="images/"+image.name+".png" - +# if (not os.path.isfile(imgpath)): +# print("NOT FILE?") +# if imgpath.endswith((".bmp",".rgb",".png",".jpeg",".jpg",".jp2",".tga",".cin",".dpx",".exr",".hdr",".tif")): +# imgpath="images/"+os.path.basename(imgpath) +# else: +# imgpath="images/"+image.name+".png" + self.writel(S_IMGS,1,'') self.writel(S_IMGS,2,''+imgpath+'"/>') self.writel(S_IMGS,1,'') @@ -529,8 +532,8 @@ class DaeExporter: if (not (f.material_index in surface_indices)): surface_indices[f.material_index]=[] - print("Type: "+str(type(f.material_index))) - print("IDX: "+str(f.material_index)+"/"+str(len(mesh.materials))) + #print("Type: "+str(type(f.material_index))) + #print("IDX: "+str(f.material_index)+"/"+str(len(mesh.materials))) try: #Bizarre blender behavior i don't understand, so catching exception @@ -914,14 +917,14 @@ class DaeExporter: if (node.data.shape_keys!=None): sk = node.data.shape_keys if (sk.animation_data): - print("HAS ANIM") - print("DRIVERS: "+str(len(sk.animation_data.drivers))) + #print("HAS ANIM") + #print("DRIVERS: "+str(len(sk.animation_data.drivers))) for d in sk.animation_data.drivers: if (d.driver): for v in d.driver.variables: for t in v.targets: if (t.id!=None and t.id.name in self.scene.objects): - print("LINKING "+str(node)+" WITH "+str(t.id.name)) + #print("LINKING "+str(node)+" WITH "+str(t.id.name)) self.armature_for_morph[node]=self.scene.objects[t.id.name] @@ -1234,7 +1237,7 @@ class DaeExporter: il+=1 self.writel(S_NODES,il,''+strmtx(node.matrix_local)+'') - print("NODE TYPE: "+node.type+" NAME: "+node.name) + #print("NODE TYPE: "+node.type+" NAME: "+node.name) if (node.type=="MESH"): self.export_mesh_node(node,il) elif (node.type=="CURVE"): @@ -1258,7 +1261,7 @@ class DaeExporter: return False if (self.config["use_active_layers"]): valid=False - print("NAME: "+node.name) + #print("NAME: "+node.name) for i in range(20): if (node.layers[i] and self.scene.layers[i]): valid=True @@ -1408,7 +1411,7 @@ class DaeExporter: # Change frames first, export objects last # This improves performance enormously - print("anim from: "+str(start)+" to "+str(end)+" allowed: "+str(allowed)) + #print("anim from: "+str(start)+" to "+str(end)+" allowed: "+str(allowed)) for t in range(start,end+1): self.scene.frame_set(t) key = t * frame_len - frame_sub @@ -1462,7 +1465,7 @@ class DaeExporter: bone_name=self.skeleton_info[node]["bone_ids"][bone] if (not (bone_name in xform_cache)): - print("has bone: "+bone_name) + #print("has bone: "+bone_name) xform_cache[bone_name]=[] posebone = node.pose.bones[bone.name] @@ -1548,15 +1551,15 @@ class DaeExporter: bone.matrix_basis = Matrix() - print("allowed skeletons "+str(allowed_skeletons)) + #print("allowed skeletons "+str(allowed_skeletons)) - print(str(x)) + #print(str(x)) tcn = self.export_animation(int(x.frame_range[0]),int(x.frame_range[1]+0.5),allowed_skeletons) framelen=(1.0/self.scene.render.fps) start = x.frame_range[0]*framelen end = x.frame_range[1]*framelen - print("Export anim: "+x.name) + #print("Export anim: "+x.name) self.writel(S_ANIM_CLIPS,1,'') for z in tcn: self.writel(S_ANIM_CLIPS,2,'') -- cgit v1.2.3 From 68e42f53badd6a501021e545c09b2c41ad21e1e0 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Thu, 2 Apr 2015 12:59:23 -0300 Subject: Beta1 Attempt #1 -=-==-=-=-=-=-=- -Small fixes in canvas item light shader -Fixed compilation in server target -Export for Android makes 32 bits display as default -changed version to 1.1beta1 --- drivers/gles2/shaders/canvas.glsl | 2 +- platform/android/export/export.cpp | 2 +- platform/server/os_server.cpp | 7 ++++++- platform/server/os_server.h | 2 ++ scene/resources/shader_graph.cpp | 15 ++++++++++++--- servers/visual/rasterizer_dummy.cpp | 32 ++++++++++++++++++++++++++++++++ servers/visual/rasterizer_dummy.h | 10 ++++++++++ version.py | 4 ++-- 8 files changed, 66 insertions(+), 8 deletions(-) diff --git a/drivers/gles2/shaders/canvas.glsl b/drivers/gles2/shaders/canvas.glsl index 12ff43479b..baa7e664b5 100644 --- a/drivers/gles2/shaders/canvas.glsl +++ b/drivers/gles2/shaders/canvas.glsl @@ -235,7 +235,7 @@ FRAGMENT_SHADER_CODE #if defined(USE_LIGHT_SHADER_CODE) //light is written by the light shader { - vec4 light_out=vec4(0.0,0.0,0.0,0.0); + vec4 light_out=light*color; LIGHT_SHADER_CODE color=light_out; } diff --git a/platform/android/export/export.cpp b/platform/android/export/export.cpp index 18747734ab..8199e7c622 100644 --- a/platform/android/export/export.cpp +++ b/platform/android/export/export.cpp @@ -1546,7 +1546,7 @@ EditorExportPlatformAndroid::EditorExportPlatformAndroid() { quit_request=false; orientation=0; remove_prev=true; - use_32_fb=false; + use_32_fb=true; device_thread=Thread::create(_device_poll_thread,this); devices_changed=true; diff --git a/platform/server/os_server.cpp b/platform/server/os_server.cpp index 7bc8f61744..1aabf5337b 100644 --- a/platform/server/os_server.cpp +++ b/platform/server/os_server.cpp @@ -56,7 +56,6 @@ void OS_Server::initialize(const VideoMode& p_desired,int p_video_driver,int p_a args=OS::get_singleton()->get_cmdline_args(); current_videomode=p_desired; main_loop=NULL; - rasterizer = memnew( RasterizerDummy ); @@ -163,6 +162,12 @@ OS::VideoMode OS_Server::get_video_mode(int p_screen) const { return current_videomode; } + +Size2 OS_Server::get_window_size() const { + + return Vector2(current_videomode.width,current_videomode.height) ; +} + void OS_Server::get_fullscreen_mode_list(List *p_list,int p_screen) const { diff --git a/platform/server/os_server.h b/platform/server/os_server.h index fcf96253ad..f8d346ce48 100644 --- a/platform/server/os_server.h +++ b/platform/server/os_server.h @@ -109,6 +109,8 @@ public: virtual VideoMode get_video_mode(int p_screen=0) const; virtual void get_fullscreen_mode_list(List *p_list,int p_screen=0) const; + virtual Size2 get_window_size() const; + virtual void move_window_to_foreground(); void run(); diff --git a/scene/resources/shader_graph.cpp b/scene/resources/shader_graph.cpp index b0d9ceee0e..be54d649e2 100644 --- a/scene/resources/shader_graph.cpp +++ b/scene/resources/shader_graph.cpp @@ -1351,15 +1351,24 @@ const ShaderGraph::InOutParamInfo ShaderGraph::inout_param_info[]={ {MODE_CANVAS_ITEM,SHADER_TYPE_FRAGMENT,"Normal","NORMAL","",SLOT_TYPE_VEC,SLOT_OUT}, //canvas item light in {MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"Color","COLOR.rgb","",SLOT_TYPE_VEC,SLOT_IN}, + {MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"Alpha","COLOR.a","",SLOT_TYPE_SCALAR,SLOT_IN}, {MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"Normal","NORMAL","",SLOT_TYPE_VEC,SLOT_IN}, - {MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"LightDist","LIGHT_DISTANCE","",SLOT_TYPE_SCALAR,SLOT_IN}, - {MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"LightDir","vec3(LIGHT_DIR,0)","",SLOT_TYPE_VEC,SLOT_IN}, + {MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"UV","vec3(UV,0)","",SLOT_TYPE_VEC,SLOT_IN}, + {MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"LightColor","LIGHT_COLOR.rgb","",SLOT_TYPE_VEC,SLOT_IN}, + {MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"LightAlpha","LIGHT_COLOR.a","",SLOT_TYPE_SCALAR,SLOT_IN}, + {MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"LightHeight","LIGHT_HEIGHT","",SLOT_TYPE_SCALAR,SLOT_IN}, + {MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"TexPixelSize","vec3(TEXTURE_PIXEL_SIZE,0)","",SLOT_TYPE_VEC,SLOT_IN}, + {MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"Var1","VAR1.rgb","",SLOT_TYPE_VEC,SLOT_IN}, + {MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"Var2","VAR2.rgb","",SLOT_TYPE_VEC,SLOT_IN}, {MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"PointCoord","POINT_COORD","",SLOT_TYPE_VEC,SLOT_IN}, //canvas item light out - {MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"Light","LIGHT","",SLOT_TYPE_VEC,SLOT_OUT}, + {MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"LightColor","LIGHT.rgb","",SLOT_TYPE_VEC,SLOT_OUT}, + {MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"LightAlpha","LIGHT.a","",SLOT_TYPE_SCALAR,SLOT_OUT}, //end {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,NULL,NULL,NULL,SLOT_TYPE_SCALAR,SLOT_OUT}, + + }; void ShaderGraph::get_input_output_node_slot_info(Mode p_mode, ShaderType p_type, List *r_slots) { diff --git a/servers/visual/rasterizer_dummy.cpp b/servers/visual/rasterizer_dummy.cpp index 7fb8eb02fc..45b29f5484 100644 --- a/servers/visual/rasterizer_dummy.cpp +++ b/servers/visual/rasterizer_dummy.cpp @@ -1543,11 +1543,38 @@ void RasterizerDummy::end_shadow_map() { void RasterizerDummy::end_frame() { +} + +RID RasterizerDummy::canvas_light_occluder_create() { + return RID(); +} + +void RasterizerDummy::canvas_light_occluder_set_polylines(RID p_occluder, const DVector& p_lines) { + + +} + +RID RasterizerDummy::canvas_light_shadow_buffer_create(int p_width) { + + return RID(); +} + +void RasterizerDummy::canvas_light_shadow_buffer_update(RID p_buffer, const Matrix32& p_light_xform, int p_light_mask,float p_near, float p_far, CanvasLightOccluderInstance* p_occluders, CameraMatrix *p_xform_cache) { + + +} + +void RasterizerDummy::canvas_debug_viewport_shadows(CanvasLight* p_lights_with_shadow) { + + } /* CANVAS API */ +void RasterizerDummy::begin_canvas_bg() { + +} void RasterizerDummy::canvas_begin() { @@ -1761,6 +1788,11 @@ bool RasterizerDummy::is_environment(const RID& p_rid) const { return environment_owner.owns(p_rid); } +bool RasterizerDummy::is_canvas_light_occluder(const RID& p_rid) const { + + return false; +} + bool RasterizerDummy::is_shader(const RID& p_rid) const { return false; diff --git a/servers/visual/rasterizer_dummy.h b/servers/visual/rasterizer_dummy.h index baa48951d6..99c76a1917 100644 --- a/servers/visual/rasterizer_dummy.h +++ b/servers/visual/rasterizer_dummy.h @@ -696,6 +696,7 @@ public: /* CANVAS API */ + virtual void begin_canvas_bg(); virtual void canvas_begin(); virtual void canvas_disable_blending(); virtual void canvas_set_opacity(float p_opacity); @@ -712,6 +713,14 @@ public: virtual void canvas_render_items(CanvasItem *p_item_list,int p_z,const Color& p_modulate,CanvasLight *p_light); + virtual RID canvas_light_occluder_create(); + virtual void canvas_light_occluder_set_polylines(RID p_occluder, const DVector& p_lines); + + virtual RID canvas_light_shadow_buffer_create(int p_width); + virtual void canvas_light_shadow_buffer_update(RID p_buffer, const Matrix32& p_light_xform, int p_light_mask,float p_near, float p_far, CanvasLightOccluderInstance* p_occluders, CameraMatrix *p_xform_cache); + + virtual void canvas_debug_viewport_shadows(CanvasLight* p_lights_with_shadow); + /* ENVIRONMENT */ virtual RID environment_create(); @@ -747,6 +756,7 @@ public: virtual bool is_particles_instance(const RID& p_rid) const; virtual bool is_skeleton(const RID& p_rid) const; virtual bool is_environment(const RID& p_rid) const; + virtual bool is_canvas_light_occluder(const RID& p_rid) const; virtual bool is_shader(const RID& p_rid) const; diff --git a/version.py b/version.py index 86601a22f2..46490c48f4 100644 --- a/version.py +++ b/version.py @@ -1,7 +1,7 @@ short_name="godot" name="Godot Engine" major=1 -minor=0 -status="stable" +minor=1 +status="beta1" -- cgit v1.2.3 From 8ea7e3e2b1b8f427a4023fec4626bad2a7de7585 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Thu, 2 Apr 2015 14:54:36 -0300 Subject: javascript build fix --- platform/javascript/os_javascript.cpp | 6 ++++++ platform/javascript/os_javascript.h | 1 + 2 files changed, 7 insertions(+) diff --git a/platform/javascript/os_javascript.cpp b/platform/javascript/os_javascript.cpp index 581df84925..f9ed752835 100644 --- a/platform/javascript/os_javascript.cpp +++ b/platform/javascript/os_javascript.cpp @@ -230,6 +230,12 @@ OS::VideoMode OS_JavaScript::get_video_mode(int p_screen) const { return default_videomode; } + +Size2 OS_JavaScript::get_screen_size(int p_screen) const { + + return Vector2(default_videomode.width,default_videomode.height); +} + void OS_JavaScript::get_fullscreen_mode_list(List *p_list,int p_screen) const { p_list->push_back(default_videomode); diff --git a/platform/javascript/os_javascript.h b/platform/javascript/os_javascript.h index dfc93d3ff0..681d85475c 100644 --- a/platform/javascript/os_javascript.h +++ b/platform/javascript/os_javascript.h @@ -127,6 +127,7 @@ public: virtual VideoMode get_video_mode(int p_screen=0) const; virtual void get_fullscreen_mode_list(List *p_list,int p_screen=0) const; + virtual Size2 get_screen_size(int p_screen=0) const; virtual String get_name(); virtual MainLoop *get_main_loop() const; -- cgit v1.2.3 From 42d41a3fbc79ff1014d3b65666d6f80240520c8c Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Thu, 2 Apr 2015 15:03:14 -0300 Subject: wrong function, changing.. --- platform/javascript/os_javascript.cpp | 2 +- platform/javascript/os_javascript.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/platform/javascript/os_javascript.cpp b/platform/javascript/os_javascript.cpp index f9ed752835..4c8d8a4205 100644 --- a/platform/javascript/os_javascript.cpp +++ b/platform/javascript/os_javascript.cpp @@ -231,7 +231,7 @@ OS::VideoMode OS_JavaScript::get_video_mode(int p_screen) const { return default_videomode; } -Size2 OS_JavaScript::get_screen_size(int p_screen) const { +Size2 OS_JavaScript::get_window_size() const { return Vector2(default_videomode.width,default_videomode.height); } diff --git a/platform/javascript/os_javascript.h b/platform/javascript/os_javascript.h index 681d85475c..2e9c8e14c2 100644 --- a/platform/javascript/os_javascript.h +++ b/platform/javascript/os_javascript.h @@ -127,7 +127,7 @@ public: virtual VideoMode get_video_mode(int p_screen=0) const; virtual void get_fullscreen_mode_list(List *p_list,int p_screen=0) const; - virtual Size2 get_screen_size(int p_screen=0) const; + virtual Size2 get_window_size() const; virtual String get_name(); virtual MainLoop *get_main_loop() const; -- cgit v1.2.3 From 9fa1698c7420bae2c6353bf300ce2cdb73434bf6 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Fri, 3 Apr 2015 01:43:37 -0300 Subject: Changes to Light -=-=-=-=-=-=-=-= -Changed material unshaded property for an enum, which supports light-only shading -Added a "Mix" shading mode, useful for using lights as masks -Added energy parameter to Light2D --- demos/2d/light_mask/burano.png | Bin 0 -> 974437 bytes demos/2d/light_mask/engine.cfg | 4 +++ demos/2d/light_mask/lightmask.scn | Bin 0 -> 2916 bytes demos/2d/light_mask/splat.png | Bin 0 -> 18255 bytes drivers/gles2/rasterizer_gles2.cpp | 42 +++++++++++++++++++++----------- drivers/gles2/shader_compiler_gles2.cpp | 8 ++++++ drivers/gles2/shader_compiler_gles2.h | 3 +++ drivers/gles2/shaders/canvas.glsl | 12 +++++++-- scene/2d/canvas_item.cpp | 33 ++++++++++++++----------- scene/2d/canvas_item.h | 15 +++++++++--- scene/2d/light_2d.cpp | 42 +++++++++++++++++++++++++------- scene/2d/light_2d.h | 18 +++++++++++--- scene/scene_string_names.cpp | 1 + scene/scene_string_names.h | 1 + servers/visual/rasterizer.h | 10 +++++--- servers/visual/shader_language.cpp | 2 ++ servers/visual/visual_server_raster.cpp | 17 ++++++++++--- servers/visual/visual_server_raster.h | 8 +++--- servers/visual/visual_server_wrap_mt.h | 7 +++--- servers/visual_server.h | 19 +++++++++++++-- 20 files changed, 181 insertions(+), 61 deletions(-) create mode 100644 demos/2d/light_mask/burano.png create mode 100644 demos/2d/light_mask/engine.cfg create mode 100644 demos/2d/light_mask/lightmask.scn create mode 100644 demos/2d/light_mask/splat.png diff --git a/demos/2d/light_mask/burano.png b/demos/2d/light_mask/burano.png new file mode 100644 index 0000000000..6eec09d585 Binary files /dev/null and b/demos/2d/light_mask/burano.png differ diff --git a/demos/2d/light_mask/engine.cfg b/demos/2d/light_mask/engine.cfg new file mode 100644 index 0000000000..0e9389f853 --- /dev/null +++ b/demos/2d/light_mask/engine.cfg @@ -0,0 +1,4 @@ +[application] + +name="Using Lights As Mask" +main_scene="res://lightmask.scn" diff --git a/demos/2d/light_mask/lightmask.scn b/demos/2d/light_mask/lightmask.scn new file mode 100644 index 0000000000..08805f44c6 Binary files /dev/null and b/demos/2d/light_mask/lightmask.scn differ diff --git a/demos/2d/light_mask/splat.png b/demos/2d/light_mask/splat.png new file mode 100644 index 0000000000..8c35f068a0 Binary files /dev/null and b/demos/2d/light_mask/splat.png differ diff --git a/drivers/gles2/rasterizer_gles2.cpp b/drivers/gles2/rasterizer_gles2.cpp index ae5f3d8f2f..3660be20db 100644 --- a/drivers/gles2/rasterizer_gles2.cpp +++ b/drivers/gles2/rasterizer_gles2.cpp @@ -4611,6 +4611,9 @@ void RasterizerGLES2::_update_shader( Shader* p_shader) const { if (fragment_flags.uses_texpixel_size) { enablers.push_back("#define USE_TEXPIXEL_SIZE\n"); } + if (light_flags.uses_shadow_color) { + enablers.push_back("#define USE_LIGHT_SHADOW_COLOR\n"); + } if (vertex_flags.uses_worldvec) { enablers.push_back("#define USE_WORLD_VEC\n"); @@ -9260,7 +9263,9 @@ void RasterizerGLES2::canvas_render_items(CanvasItem *p_item_list,int p_z,const _canvas_item_setup_shader_uniforms(material,shader_cache); } - if (material && material->unshaded) { + bool unshaded = material && material->shading_mode==VS::CANVAS_ITEM_SHADING_UNSHADED; + + if (unshaded) { canvas_shader.set_uniform(CanvasShaderGLES2::MODULATE,Color(1,1,1,1)); reset_modulate=true; } else if (reset_modulate) { @@ -9317,13 +9322,15 @@ void RasterizerGLES2::canvas_render_items(CanvasItem *p_item_list,int p_z,const canvas_opacity = ci->final_opacity; - _canvas_item_render_commands(ci,current_clip,reclip); - if (canvas_blend_mode==VS::MATERIAL_BLEND_MODE_MIX && p_light && (!material || !material->unshaded)) { + if (unshaded || (p_modulate.a>0.001 && (!material || material->shading_mode!=VS::CANVAS_ITEM_SHADING_ONLY_LIGHT))) + _canvas_item_render_commands(ci,current_clip,reclip); + + if (canvas_blend_mode==VS::MATERIAL_BLEND_MODE_MIX && p_light && !unshaded) { CanvasLight *light = p_light; bool light_used=false; - bool subtract=false; + VS::CanvasLightMode mode=VS::CANVAS_LIGHT_MODE_ADD; while(light) { @@ -9332,21 +9339,28 @@ void RasterizerGLES2::canvas_render_items(CanvasItem *p_item_list,int p_z,const //intersects this light - if (!light_used || subtract!=light->subtract) { + if (!light_used || mode!=light->mode) { - subtract=light->subtract; + mode=light->mode; - if (subtract) { + switch(mode) { - glBlendEquation(GL_FUNC_REVERSE_SUBTRACT); - glBlendFunc(GL_SRC_ALPHA,GL_ONE); - - } else { + case VS::CANVAS_LIGHT_MODE_ADD: { + glBlendEquation(GL_FUNC_ADD); + glBlendFunc(GL_SRC_ALPHA,GL_ONE); - glBlendEquation(GL_FUNC_ADD); - glBlendFunc(GL_SRC_ALPHA,GL_ONE); + } break; + case VS::CANVAS_LIGHT_MODE_SUB: { + glBlendEquation(GL_FUNC_REVERSE_SUBTRACT); + glBlendFunc(GL_SRC_ALPHA,GL_ONE); + } break; + case VS::CANVAS_LIGHT_MODE_MIX: { + glBlendEquation(GL_FUNC_ADD); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + } break; } + } if (!light_used) { @@ -9384,7 +9398,7 @@ void RasterizerGLES2::canvas_render_items(CanvasItem *p_item_list,int p_z,const canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_MATRIX,light->light_shader_xform); canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_POS,light->light_shader_pos); - canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_COLOR,light->color); + canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_COLOR,Color(light->color.r*light->energy,light->color.g*light->energy,light->color.b*light->energy,light->color.a)); canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_HEIGHT,light->height); canvas_shader.set_uniform(CanvasShaderGLES2::LIGHT_LOCAL_MATRIX,light->xform_cache.affine_inverse()); diff --git a/drivers/gles2/shader_compiler_gles2.cpp b/drivers/gles2/shader_compiler_gles2.cpp index 8d378ceec1..69bd269948 100644 --- a/drivers/gles2/shader_compiler_gles2.cpp +++ b/drivers/gles2/shader_compiler_gles2.cpp @@ -266,6 +266,9 @@ String ShaderCompilerGLES2::dump_node_code(SL::Node *p_node,int p_level,bool p_a uses_normal=true; } + if (vnode->name==vname_shadow) { + uses_shadow_color=true; + } } @@ -616,6 +619,7 @@ Error ShaderCompilerGLES2::compile(const String& p_code, ShaderLanguage::ShaderT uses_texpixel_size=false; uses_worldvec=false; vertex_code_writes_vertex=false; + uses_shadow_color=false; uniforms=r_uniforms; flags=&r_flags; r_flags.use_color_interp=false; @@ -651,6 +655,7 @@ Error ShaderCompilerGLES2::compile(const String& p_code, ShaderLanguage::ShaderT r_flags.uses_normal=uses_normal; r_flags.uses_texpixel_size=uses_texpixel_size; r_flags.uses_worldvec=uses_worldvec; + r_flags.uses_shadow_color=uses_shadow_color; r_code_line=code; r_globals_line=global_code; @@ -827,7 +832,9 @@ ShaderCompilerGLES2::ShaderCompilerGLES2() { mode_replace_table[5]["LIGHT_VEC"]="light_vec"; mode_replace_table[5]["LIGHT_HEIGHT"]="light_height"; mode_replace_table[5]["LIGHT_COLOR"]="light"; + mode_replace_table[5]["LIGHT_UV"]="light_uv"; mode_replace_table[5]["LIGHT"]="light_out"; + mode_replace_table[5]["SHADOW"]="shadow_color"; mode_replace_table[5]["SCREEN_UV"]="screen_uv"; mode_replace_table[5]["POINT_COORD"]="gl_PointCoord"; mode_replace_table[5]["TIME"]="time"; @@ -857,5 +864,6 @@ ShaderCompilerGLES2::ShaderCompilerGLES2() { vname_normal="NORMAL"; vname_texpixel_size="TEXTURE_PIXEL_SIZE"; vname_world_vec="WORLD_VERTEX"; + vname_shadow="SHADOW"; } diff --git a/drivers/gles2/shader_compiler_gles2.h b/drivers/gles2/shader_compiler_gles2.h index 87722602fd..87016fd968 100644 --- a/drivers/gles2/shader_compiler_gles2.h +++ b/drivers/gles2/shader_compiler_gles2.h @@ -55,6 +55,7 @@ private: bool uses_texpixel_size; bool uses_worldvec; bool vertex_code_writes_vertex; + bool uses_shadow_color; Flags *flags; StringName vname_discard; @@ -74,6 +75,7 @@ private: StringName vname_normal; StringName vname_texpixel_size; StringName vname_world_vec; + StringName vname_shadow; Map *uniforms; @@ -110,6 +112,7 @@ public: bool uses_normal; bool uses_texpixel_size; bool uses_worldvec; + bool uses_shadow_color; }; Error compile(const String& p_code, ShaderLanguage::ShaderType p_type, String& r_code_line, String& r_globals_line, Flags& r_flags, Map *r_uniforms=NULL); diff --git a/drivers/gles2/shaders/canvas.glsl b/drivers/gles2/shaders/canvas.glsl index baa7e664b5..bb47de6688 100644 --- a/drivers/gles2/shaders/canvas.glsl +++ b/drivers/gles2/shaders/canvas.glsl @@ -230,7 +230,11 @@ FRAGMENT_SHADER_CODE float att=1.0; - vec4 light = texture2D(light_texture,light_uv_interp.xy) * light_color; + vec2 light_uv = light_uv_interp.xy; + vec4 light = texture2D(light_texture,light_uv) * light_color; +#if defined(USE_LIGHT_SHADOW_COLOR) + vec4 shadow_color=vec4(0.0,0.0,0.0,0.0); +#endif #if defined(USE_LIGHT_SHADER_CODE) //light is written by the light shader @@ -362,7 +366,11 @@ LIGHT_SHADER_CODE #endif - color.rgb*=shadow_attenuation; +#if defined(USE_LIGHT_SHADOW_COLOR) + color=mix(shadow_color,color,shadow_attenuation); +#else + color.rgb*=shadow_attenuation; +#endif //use shadows #endif } diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp index c3ff03d8f4..118ba33bc6 100644 --- a/scene/2d/canvas_item.cpp +++ b/scene/2d/canvas_item.cpp @@ -42,8 +42,8 @@ bool CanvasItemMaterial::_set(const StringName& p_name, const Variant& p_value) if (p_name==SceneStringNames::get_singleton()->shader_shader) { set_shader(p_value); return true; - } else if (p_name==SceneStringNames::get_singleton()->shader_unshaded) { - set_unshaded(p_value); + } else if (p_name==SceneStringNames::get_singleton()->shading_mode) { + set_shading_mode(ShadingMode(p_value.operator int())); return true; } else { @@ -74,10 +74,10 @@ bool CanvasItemMaterial::_get(const StringName& p_name,Variant &r_ret) const { r_ret=get_shader(); return true; - } else if (p_name==SceneStringNames::get_singleton()->shader_unshaded) { + } else if (p_name==SceneStringNames::get_singleton()->shading_mode) { - r_ret=unshaded; + r_ret=shading_mode; return true; } else { @@ -100,7 +100,7 @@ bool CanvasItemMaterial::_get(const StringName& p_name,Variant &r_ret) const { void CanvasItemMaterial::_get_property_list( List *p_list) const { p_list->push_back( PropertyInfo( Variant::OBJECT, "shader/shader", PROPERTY_HINT_RESOURCE_TYPE,"CanvasItemShader,CanvasItemShaderGraph" ) ); - p_list->push_back( PropertyInfo( Variant::BOOL, "shader/unshaded") ); + p_list->push_back( PropertyInfo( Variant::INT, "shader/shading_mode",PROPERTY_HINT_ENUM,"Normal,Unshaded,Light Only") ); if (!shader.is_null()) { @@ -161,25 +161,30 @@ RID CanvasItemMaterial::get_rid() const { return material; } -void CanvasItemMaterial::set_unshaded(bool p_unshaded) { +void CanvasItemMaterial::set_shading_mode(ShadingMode p_mode) { - unshaded=p_unshaded; - VS::get_singleton()->canvas_item_material_set_unshaded(material,p_unshaded); + shading_mode=p_mode; + VS::get_singleton()->canvas_item_material_set_shading_mode(material,VS::CanvasItemShadingMode(p_mode)); } -bool CanvasItemMaterial::is_unshaded() const{ - - return unshaded; +CanvasItemMaterial::ShadingMode CanvasItemMaterial::get_shading_mode() const { + return shading_mode; } + void CanvasItemMaterial::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_shader","shader:Shader"),&CanvasItemMaterial::set_shader); ObjectTypeDB::bind_method(_MD("get_shader:Shader"),&CanvasItemMaterial::get_shader); ObjectTypeDB::bind_method(_MD("set_shader_param","param","value"),&CanvasItemMaterial::set_shader_param); ObjectTypeDB::bind_method(_MD("get_shader_param","param"),&CanvasItemMaterial::get_shader_param); - ObjectTypeDB::bind_method(_MD("set_unshaded","unshaded"),&CanvasItemMaterial::set_unshaded); - ObjectTypeDB::bind_method(_MD("is_unshaded"),&CanvasItemMaterial::is_unshaded); + ObjectTypeDB::bind_method(_MD("set_shading_mode","mode"),&CanvasItemMaterial::set_shading_mode); + ObjectTypeDB::bind_method(_MD("get_shading_mode"),&CanvasItemMaterial::get_shading_mode); + + BIND_CONSTANT( SHADING_NORMAL ); + BIND_CONSTANT( SHADING_UNSHADED ); + BIND_CONSTANT( SHADING_ONLY_LIGHT ); + } @@ -202,7 +207,7 @@ void CanvasItemMaterial::get_argument_options(const StringName& p_function,int p CanvasItemMaterial::CanvasItemMaterial() { material=VS::get_singleton()->canvas_item_material_create(); - unshaded=false; + shading_mode=SHADING_NORMAL; } CanvasItemMaterial::~CanvasItemMaterial(){ diff --git a/scene/2d/canvas_item.h b/scene/2d/canvas_item.h index c43642a8ec..167f2b96f3 100644 --- a/scene/2d/canvas_item.h +++ b/scene/2d/canvas_item.h @@ -45,10 +45,17 @@ class CanvasItemMaterial : public Resource{ OBJ_TYPE(CanvasItemMaterial,Resource); RID material; Ref shader; - bool unshaded; +public: + enum ShadingMode { + SHADING_NORMAL, + SHADING_UNSHADED, + SHADING_ONLY_LIGHT, + }; protected: + ShadingMode shading_mode; + bool _set(const StringName& p_name, const Variant& p_value); bool _get(const StringName& p_name,Variant &r_ret) const; void _get_property_list( List *p_list) const; @@ -66,14 +73,16 @@ public: void set_shader_param(const StringName& p_param,const Variant& p_value); Variant get_shader_param(const StringName& p_param) const; - void set_unshaded(bool p_unshaded); - bool is_unshaded() const; + void set_shading_mode(ShadingMode p_mode); + ShadingMode get_shading_mode() const; virtual RID get_rid() const; CanvasItemMaterial(); ~CanvasItemMaterial(); }; +VARIANT_ENUM_CAST( CanvasItemMaterial::ShadingMode ); + class CanvasItem : public Node { diff --git a/scene/2d/light_2d.cpp b/scene/2d/light_2d.cpp index 4abb7e5436..c0ab544d42 100644 --- a/scene/2d/light_2d.cpp +++ b/scene/2d/light_2d.cpp @@ -96,6 +96,21 @@ float Light2D::get_height() const { return height; } +void Light2D::set_energy( float p_energy) { + + energy=p_energy; + VS::get_singleton()->canvas_light_set_energy(canvas_light,energy); + +} + + +float Light2D::get_energy() const { + + return energy; +} + + + void Light2D::set_texture_scale( float p_scale) { _scale=p_scale; @@ -178,15 +193,15 @@ int Light2D::get_item_shadow_mask() const { return item_shadow_mask; } -void Light2D::set_subtract_mode( bool p_enable ) { +void Light2D::set_mode( Mode p_mode ) { - subtract_mode=p_enable; - VS::get_singleton()->canvas_light_set_subtract_mode(canvas_light,p_enable); + mode=p_mode; + VS::get_singleton()->canvas_light_set_mode(canvas_light,VS::CanvasLightMode(p_mode)); } -bool Light2D::get_subtract_mode() const { +Light2D::Mode Light2D::get_mode() const { - return subtract_mode; + return mode; } void Light2D::set_shadow_enabled( bool p_enabled) { @@ -260,6 +275,9 @@ void Light2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_height","height"),&Light2D::set_height); ObjectTypeDB::bind_method(_MD("get_height"),&Light2D::get_height); + ObjectTypeDB::bind_method(_MD("set_energy","energy"),&Light2D::set_energy); + ObjectTypeDB::bind_method(_MD("get_energy"),&Light2D::get_energy); + ObjectTypeDB::bind_method(_MD("set_texture_scale","texture_scale"),&Light2D::set_texture_scale); ObjectTypeDB::bind_method(_MD("get_texture_scale"),&Light2D::get_texture_scale); @@ -283,8 +301,8 @@ void Light2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_item_shadow_mask","item_shadow_mask"),&Light2D::set_item_shadow_mask); ObjectTypeDB::bind_method(_MD("get_item_shadow_mask"),&Light2D::get_item_shadow_mask); - ObjectTypeDB::bind_method(_MD("set_subtract_mode","enable"),&Light2D::set_subtract_mode); - ObjectTypeDB::bind_method(_MD("get_subtract_mode"),&Light2D::get_subtract_mode); + ObjectTypeDB::bind_method(_MD("set_mode","mode"),&Light2D::set_mode); + ObjectTypeDB::bind_method(_MD("get_mode"),&Light2D::get_mode); ObjectTypeDB::bind_method(_MD("set_shadow_enabled","enabled"),&Light2D::set_shadow_enabled); ObjectTypeDB::bind_method(_MD("is_shadow_enabled"),&Light2D::is_shadow_enabled); @@ -300,7 +318,8 @@ void Light2D::_bind_methods() { ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"offset"),_SCS("set_texture_offset"),_SCS("get_texture_offset")); ADD_PROPERTY( PropertyInfo(Variant::REAL,"scale",PROPERTY_HINT_RANGE,"0.01,4096,0.01"),_SCS("set_texture_scale"),_SCS("get_texture_scale")); ADD_PROPERTY( PropertyInfo(Variant::COLOR,"color"),_SCS("set_color"),_SCS("get_color")); - ADD_PROPERTY( PropertyInfo(Variant::BOOL,"subtract"),_SCS("set_subtract_mode"),_SCS("get_subtract_mode")); + ADD_PROPERTY( PropertyInfo(Variant::REAL,"energy"),_SCS("set_energy"),_SCS("get_energy")); + ADD_PROPERTY( PropertyInfo(Variant::INT,"mode",PROPERTY_HINT_ENUM,"Add,Sub,Mix"),_SCS("set_mode"),_SCS("get_mode")); ADD_PROPERTY( PropertyInfo(Variant::REAL,"range/height"),_SCS("set_height"),_SCS("get_height")); ADD_PROPERTY( PropertyInfo(Variant::INT,"range/z_min",PROPERTY_HINT_RANGE,itos(VS::CANVAS_ITEM_Z_MIN)+","+itos(VS::CANVAS_ITEM_Z_MAX)+",1"),_SCS("set_z_range_min"),_SCS("get_z_range_min")); ADD_PROPERTY( PropertyInfo(Variant::INT,"range/z_max",PROPERTY_HINT_RANGE,itos(VS::CANVAS_ITEM_Z_MIN)+","+itos(VS::CANVAS_ITEM_Z_MAX)+",1"),_SCS("set_z_range_max"),_SCS("get_z_range_max")); @@ -312,6 +331,10 @@ void Light2D::_bind_methods() { ADD_PROPERTY( PropertyInfo(Variant::REAL,"shadow/esm_multiplier",PROPERTY_HINT_RANGE,"1,4096,0.1"),_SCS("set_shadow_esm_multiplier"),_SCS("get_shadow_esm_multiplier")); ADD_PROPERTY( PropertyInfo(Variant::INT,"shadow/item_mask",PROPERTY_HINT_ALL_FLAGS),_SCS("set_item_shadow_mask"),_SCS("get_item_shadow_mask")); + BIND_CONSTANT( MODE_ADD ); + BIND_CONSTANT( MODE_SUB ); + BIND_CONSTANT( MODE_MIX ); + } @@ -329,9 +352,10 @@ Light2D::Light2D() { layer_max=0; item_mask=1; item_shadow_mask=1; - subtract_mode=false; + mode=MODE_ADD; shadow_buffer_size=2048; shadow_esm_multiplier=80; + energy=1.0; } diff --git a/scene/2d/light_2d.h b/scene/2d/light_2d.h index 6cfb055fa9..ef875aec2f 100644 --- a/scene/2d/light_2d.h +++ b/scene/2d/light_2d.h @@ -6,6 +6,13 @@ class Light2D : public Node2D { OBJ_TYPE(Light2D,Node2D); +public: + enum Mode { + MODE_ADD, + MODE_SUB, + MODE_MIX, + }; + private: RID canvas_light; bool enabled; @@ -13,6 +20,7 @@ private: Color color; float height; float _scale; + float energy; int z_min; int z_max; int layer_min; @@ -21,7 +29,7 @@ private: int item_shadow_mask; int shadow_buffer_size; float shadow_esm_multiplier; - bool subtract_mode; + Mode mode; Ref texture; Vector2 texture_offset; @@ -51,6 +59,9 @@ public: void set_height( float p_height); float get_height() const; + void set_energy( float p_energy); + float get_energy() const; + void set_texture_scale( float p_scale); float get_texture_scale() const; @@ -72,8 +83,8 @@ public: void set_item_shadow_mask( int p_mask); int get_item_shadow_mask() const; - void set_subtract_mode( bool p_enable ); - bool get_subtract_mode() const; + void set_mode( Mode p_mode ); + Mode get_mode() const; void set_shadow_enabled( bool p_enabled); bool is_shadow_enabled() const; @@ -90,5 +101,6 @@ public: ~Light2D(); }; +VARIANT_ENUM_CAST(Light2D::Mode); #endif // LIGHT_2D_H diff --git a/scene/scene_string_names.cpp b/scene/scene_string_names.cpp index d4159f0946..76cb5929cf 100644 --- a/scene/scene_string_names.cpp +++ b/scene/scene_string_names.cpp @@ -42,6 +42,7 @@ SceneStringNames::SceneStringNames() { input_event=StaticCString::create("input_event"); shader_shader=StaticCString::create("shader/shader"); shader_unshaded=StaticCString::create("shader/unshaded"); + shading_mode=StaticCString::create("shader/shading_mode"); enter_tree=StaticCString::create("enter_tree"); exit_tree=StaticCString::create("exit_tree"); item_rect_changed=StaticCString::create("item_rect_changed"); diff --git a/scene/scene_string_names.h b/scene/scene_string_names.h index aa29ef57dc..a69e8ba0b5 100644 --- a/scene/scene_string_names.h +++ b/scene/scene_string_names.h @@ -57,6 +57,7 @@ public: StringName item_rect_changed; StringName shader_shader; StringName shader_unshaded; + StringName shading_mode; StringName enter_tree; StringName exit_tree; StringName size_flags_changed; diff --git a/servers/visual/rasterizer.h b/servers/visual/rasterizer.h index ebc210fe3d..62563a0771 100644 --- a/servers/visual/rasterizer.h +++ b/servers/visual/rasterizer.h @@ -577,6 +577,7 @@ public: Color color; Matrix32 xform; float height; + float energy; float scale; int z_min; int z_max; @@ -584,7 +585,7 @@ public: int layer_max; int item_mask; int item_shadow_mask; - bool subtract; + VS::CanvasLightMode mode; RID texture; Vector2 texture_offset; RID canvas; @@ -616,8 +617,9 @@ public: layer_max=0; item_mask=1; scale=1.0; + energy=1.0; item_shadow_mask=-1; - subtract=false; + mode=VS::CANVAS_LIGHT_MODE_ADD; texture_cache=NULL; next_ptr=NULL; filter_next_ptr=NULL; @@ -635,9 +637,9 @@ public: Map shader_param; uint32_t shader_version; Set owners; - bool unshaded; + VS::CanvasItemShadingMode shading_mode; - CanvasItemMaterial() {unshaded=false; shader_version=0; } + CanvasItemMaterial() {shading_mode=VS::CANVAS_ITEM_SHADING_NORMAL; shader_version=0; } }; struct CanvasItem { diff --git a/servers/visual/shader_language.cpp b/servers/visual/shader_language.cpp index af65a7a639..4ad8aa6c71 100644 --- a/servers/visual/shader_language.cpp +++ b/servers/visual/shader_language.cpp @@ -1171,7 +1171,9 @@ const ShaderLanguage::BuiltinsDef ShaderLanguage::ci_light_builtins_defs[]={ { "LIGHT_VEC", TYPE_VEC2}, { "LIGHT_HEIGHT", TYPE_FLOAT}, { "LIGHT_COLOR", TYPE_VEC4}, + { "LIGHT_UV", TYPE_VEC2}, { "LIGHT", TYPE_VEC4}, + { "SHADOW", TYPE_VEC4}, { "POINT_COORD", TYPE_VEC2}, // { "SCREEN_POS", TYPE_VEC2}, // { "SCREEN_TEXEL_SIZE", TYPE_VEC2}, diff --git a/servers/visual/visual_server_raster.cpp b/servers/visual/visual_server_raster.cpp index 916316a0e2..7a9db4ba11 100644 --- a/servers/visual/visual_server_raster.cpp +++ b/servers/visual/visual_server_raster.cpp @@ -3977,6 +3977,15 @@ void VisualServerRaster::canvas_light_set_height(RID p_light, float p_height){ clight->height=p_height; } + +void VisualServerRaster::canvas_light_set_energy(RID p_light, float p_energy){ + + Rasterizer::CanvasLight *clight = canvas_light_owner.get(p_light); + ERR_FAIL_COND(!clight); + clight->energy=p_energy; + +} + void VisualServerRaster::canvas_light_set_z_range(RID p_light, int p_min_z,int p_max_z){ Rasterizer::CanvasLight *clight = canvas_light_owner.get(p_light); @@ -4012,12 +4021,12 @@ void VisualServerRaster::canvas_light_set_item_shadow_mask(RID p_light, int p_ma } -void VisualServerRaster::canvas_light_set_subtract_mode(RID p_light, bool p_enable) { +void VisualServerRaster::canvas_light_set_mode(RID p_light, CanvasLightMode p_mode) { Rasterizer::CanvasLight *clight = canvas_light_owner.get(p_light); ERR_FAIL_COND(!clight); - clight->subtract=p_enable; + clight->mode=p_mode; } void VisualServerRaster::canvas_light_set_shadow_enabled(RID p_light, bool p_enabled){ @@ -4267,12 +4276,12 @@ Variant VisualServerRaster::canvas_item_material_get_shader_param(RID p_material return material->shader_param[p_param]; } -void VisualServerRaster::canvas_item_material_set_unshaded(RID p_material, bool p_unshaded){ +void VisualServerRaster::canvas_item_material_set_shading_mode(RID p_material, CanvasItemShadingMode p_mode) { VS_CHANGED; Rasterizer::CanvasItemMaterial *material = canvas_item_material_owner.get( p_material ); ERR_FAIL_COND(!material); - material->unshaded=p_unshaded; + material->shading_mode=p_mode; } diff --git a/servers/visual/visual_server_raster.h b/servers/visual/visual_server_raster.h index 72af793278..a89a685e30 100644 --- a/servers/visual/visual_server_raster.h +++ b/servers/visual/visual_server_raster.h @@ -1170,12 +1170,13 @@ public: virtual void canvas_light_set_texture_offset(RID p_light, const Vector2& p_offset); virtual void canvas_light_set_color(RID p_light, const Color& p_color); virtual void canvas_light_set_height(RID p_light, float p_height); + virtual void canvas_light_set_energy(RID p_light, float p_energy); virtual void canvas_light_set_z_range(RID p_light, int p_min_z,int p_max_z); virtual void canvas_light_set_layer_range(RID p_light, int p_min_layer,int p_max_layer); virtual void canvas_light_set_item_mask(RID p_light, int p_mask); virtual void canvas_light_set_item_shadow_mask(RID p_light, int p_mask); - virtual void canvas_light_set_subtract_mode(RID p_light, bool p_enable); + virtual void canvas_light_set_mode(RID p_light, CanvasLightMode p_mode); virtual void canvas_light_set_shadow_enabled(RID p_light, bool p_enabled); virtual void canvas_light_set_shadow_buffer_size(RID p_light, int p_size); virtual void canvas_light_set_shadow_esm_multiplier(RID p_light, float p_multiplier); @@ -1204,8 +1205,9 @@ public: virtual RID canvas_item_material_create(); virtual void canvas_item_material_set_shader(RID p_material, RID p_shader); virtual void canvas_item_material_set_shader_param(RID p_material, const StringName& p_param, const Variant& p_value); - virtual Variant canvas_item_material_get_shader_param(RID p_material, const StringName& p_param) const; - virtual void canvas_item_material_set_unshaded(RID p_material, bool p_unshaded); + virtual Variant canvas_item_material_get_shader_param(RID p_material, const StringName& p_param) const; + virtual void canvas_item_material_set_shading_mode(RID p_material, CanvasItemShadingMode p_mode); + /* CURSOR */ diff --git a/servers/visual/visual_server_wrap_mt.h b/servers/visual/visual_server_wrap_mt.h index ded4c6fc00..6cd374aa08 100644 --- a/servers/visual/visual_server_wrap_mt.h +++ b/servers/visual/visual_server_wrap_mt.h @@ -1160,12 +1160,13 @@ public: FUNC2(canvas_light_set_texture_offset,RID,const Vector2&); FUNC2(canvas_light_set_color,RID,const Color&); FUNC2(canvas_light_set_height,RID,float); + FUNC2(canvas_light_set_energy,RID,float); FUNC3(canvas_light_set_layer_range,RID,int,int); FUNC3(canvas_light_set_z_range,RID,int,int); FUNC2(canvas_light_set_item_mask,RID,int); FUNC2(canvas_light_set_item_shadow_mask,RID,int); - FUNC2(canvas_light_set_subtract_mode,RID,bool); + FUNC2(canvas_light_set_mode,RID,CanvasLightMode); FUNC2(canvas_light_set_shadow_enabled,RID,bool); FUNC2(canvas_light_set_shadow_buffer_size,RID,int); FUNC2(canvas_light_set_shadow_esm_multiplier,RID,float); @@ -1191,8 +1192,8 @@ public: FUNC0R(RID,canvas_item_material_create); FUNC2(canvas_item_material_set_shader,RID,RID); FUNC3(canvas_item_material_set_shader_param,RID,const StringName&,const Variant&); - FUNC2RC(Variant,canvas_item_material_get_shader_param,RID,const StringName&); - FUNC2(canvas_item_material_set_unshaded,RID,bool); + FUNC2RC(Variant,canvas_item_material_get_shader_param,RID,const StringName&); + FUNC2(canvas_item_material_set_shading_mode,RID,CanvasItemShadingMode); /* CURSOR */ FUNC2(cursor_set_rotation,float , int ); // radians diff --git a/servers/visual_server.h b/servers/visual_server.h index b6d354454e..e9425afbab 100644 --- a/servers/visual_server.h +++ b/servers/visual_server.h @@ -1014,12 +1014,19 @@ public: virtual void canvas_light_set_texture_offset(RID p_light, const Vector2& p_offset)=0; virtual void canvas_light_set_color(RID p_light, const Color& p_color)=0; virtual void canvas_light_set_height(RID p_light, float p_height)=0; + virtual void canvas_light_set_energy(RID p_light, float p_energy)=0; virtual void canvas_light_set_z_range(RID p_light, int p_min_z,int p_max_z)=0; virtual void canvas_light_set_layer_range(RID p_light, int p_min_layer,int p_max_layer)=0; virtual void canvas_light_set_item_mask(RID p_light, int p_mask)=0; virtual void canvas_light_set_item_shadow_mask(RID p_light, int p_mask)=0; - virtual void canvas_light_set_subtract_mode(RID p_light, bool p_enable)=0; + enum CanvasLightMode { + CANVAS_LIGHT_MODE_ADD, + CANVAS_LIGHT_MODE_SUB, + CANVAS_LIGHT_MODE_MIX, + }; + + virtual void canvas_light_set_mode(RID p_light, CanvasLightMode p_mode)=0; virtual void canvas_light_set_shadow_enabled(RID p_light, bool p_enabled)=0; virtual void canvas_light_set_shadow_buffer_size(RID p_light, int p_size)=0; virtual void canvas_light_set_shadow_esm_multiplier(RID p_light, float p_multiplier)=0; @@ -1049,7 +1056,15 @@ public: virtual void canvas_item_material_set_shader(RID p_material, RID p_shader)=0; virtual void canvas_item_material_set_shader_param(RID p_material, const StringName& p_param, const Variant& p_value)=0; virtual Variant canvas_item_material_get_shader_param(RID p_material, const StringName& p_param) const=0; - virtual void canvas_item_material_set_unshaded(RID p_material, bool p_unshaded)=0; + + + enum CanvasItemShadingMode { + CANVAS_ITEM_SHADING_NORMAL, + CANVAS_ITEM_SHADING_UNSHADED, + CANVAS_ITEM_SHADING_ONLY_LIGHT, + }; + + virtual void canvas_item_material_set_shading_mode(RID p_material, CanvasItemShadingMode p_mode)=0; /* CURSOR */ virtual void cursor_set_rotation(float p_rotation, int p_cursor = 0)=0; // radians -- cgit v1.2.3 From 5d99e15e43d5a446b35d48e8a3b08a478f1998a9 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Fri, 3 Apr 2015 14:36:10 -0300 Subject: fix shadow issue with lights in mix mode, i think fixes #1611 --- demos/2d/light_mask/engine.cfg | 4 ++++ drivers/gles2/shaders/canvas.glsl | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/demos/2d/light_mask/engine.cfg b/demos/2d/light_mask/engine.cfg index 0e9389f853..8b0ae6f61d 100644 --- a/demos/2d/light_mask/engine.cfg +++ b/demos/2d/light_mask/engine.cfg @@ -2,3 +2,7 @@ name="Using Lights As Mask" main_scene="res://lightmask.scn" + +[rasterizer] + +shadow_filter=3 diff --git a/drivers/gles2/shaders/canvas.glsl b/drivers/gles2/shaders/canvas.glsl index bb47de6688..c4f0847870 100644 --- a/drivers/gles2/shaders/canvas.glsl +++ b/drivers/gles2/shaders/canvas.glsl @@ -369,7 +369,7 @@ LIGHT_SHADER_CODE #if defined(USE_LIGHT_SHADOW_COLOR) color=mix(shadow_color,color,shadow_attenuation); #else - color.rgb*=shadow_attenuation; + color*=shadow_attenuation; #endif //use shadows #endif -- cgit v1.2.3