summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md5
-rw-r--r--SConstruct4
-rw-r--r--bin/tests/test_gdscript.cpp20
-rw-r--r--bin/tests/test_math.cpp1
-rw-r--r--core/bind/core_bind.cpp7
-rw-r--r--core/bind/core_bind.h2
-rw-r--r--core/dictionary.cpp2
-rw-r--r--core/io/http_client.cpp2
-rw-r--r--core/io/ip.cpp2
-rw-r--r--core/io/json.cpp2
-rw-r--r--core/io/stream_peer_tcp.cpp2
-rw-r--r--core/io/xml_parser.cpp4
-rw-r--r--core/math/math_funcs.h6
-rw-r--r--core/method_bind.cpp4
-rw-r--r--core/method_bind.h1
-rw-r--r--core/object.cpp5
-rw-r--r--core/object.h1
-rw-r--r--core/object_type_db.cpp29
-rw-r--r--core/object_type_db.h4
-rw-r--r--core/os/input.cpp25
-rw-r--r--core/os/input.h2
-rw-r--r--core/os/keyboard.cpp105
-rw-r--r--core/os/keyboard.h1
-rw-r--r--core/os/os.cpp5
-rw-r--r--core/os/os.h13
-rw-r--r--core/register_core_types.cpp1
-rw-r--r--core/script_language.h2
-rw-r--r--core/translation.cpp74
-rw-r--r--core/ustring.cpp14
-rw-r--r--core/ustring.h2
-rw-r--r--core/variant.cpp126
-rw-r--r--core/variant.h8
-rw-r--r--core/variant_call.cpp6
-rw-r--r--core/variant_op.cpp36
-rw-r--r--demos/2d/platformer/player.gd3
-rw-r--r--demos/2d/platformer/player.xml173
-rw-r--r--demos/3d/mousepick_test/mousepick.gd2
-rw-r--r--demos/misc/tween/main.gd4
-rw-r--r--drivers/SCsub1
-rw-r--r--drivers/builtin_openssl2/openssl/md5.h4
-rw-r--r--drivers/chibi/cp_loader_s3m.cpp2
-rw-r--r--drivers/gles1/rasterizer_gles1.cpp10
-rw-r--r--drivers/gles1/rasterizer_gles1.h3
-rw-r--r--drivers/gles2/rasterizer_gles2.cpp82
-rw-r--r--drivers/gles2/rasterizer_gles2.h6
-rw-r--r--drivers/gles2/shader_compiler_gles2.cpp3
-rw-r--r--drivers/gles2/shaders/material.glsl2
-rw-r--r--drivers/mpc/audio_stream_mpc.cpp10
-rw-r--r--drivers/png/pngpriv.h6
-rw-r--r--drivers/pulseaudio/SCsub5
-rw-r--r--drivers/pulseaudio/audio_driver_pulseaudio.cpp194
-rw-r--r--drivers/pulseaudio/audio_driver_pulseaudio.h (renamed from scene/gui/empty_control.h)73
-rw-r--r--drivers/theoraplayer/SCsub13
-rw-r--r--drivers/theoraplayer/src/TheoraVideoClip.cpp1
-rw-r--r--drivers/theoraplayer/video_stream_theoraplayer.cpp6
-rw-r--r--drivers/unix/ip_unix.cpp2
-rw-r--r--drivers/unix/memory_pool_static_malloc.cpp8
-rw-r--r--drivers/unix/os_unix.cpp6
-rw-r--r--drivers/vorbis/os.h2
-rw-r--r--drivers/webp/dsp/dsp.h2
-rw-r--r--drivers/webp/utils/bit_reader.h1
-rw-r--r--drivers/windows/dir_access_windows.cpp7
-rw-r--r--drivers/windows/file_access_windows.cpp1
-rw-r--r--main/main.cpp1
-rw-r--r--makefile30
-rw-r--r--modules/gdscript/gd_compiler.cpp62
-rw-r--r--modules/gdscript/gd_editor.cpp1568
-rw-r--r--modules/gdscript/gd_functions.cpp4
-rw-r--r--modules/gdscript/gd_parser.cpp320
-rw-r--r--modules/gdscript/gd_parser.h56
-rw-r--r--modules/gdscript/gd_script.cpp5
-rw-r--r--modules/gdscript/gd_script.h20
-rw-r--r--modules/gdscript/gd_tokenizer.cpp6
-rw-r--r--modules/gdscript/gd_tokenizer.h1
-rw-r--r--modules/gridmap/grid_map_editor_plugin.cpp10
-rw-r--r--modules/gridmap/register_types.cpp4
-rw-r--r--platform/android/detect.py6
-rw-r--r--platform/android/java/src/com/android/godot/Godot.java2
-rw-r--r--platform/android/java/src/com/android/godot/GodotIO.java22
-rw-r--r--platform/iphone/detect.py41
-rw-r--r--platform/iphone/platform_config.h1
-rw-r--r--platform/iphone/platform_refcount.h18
-rw-r--r--platform/osx/detect.py2
-rw-r--r--platform/osx/os_osx.h2
-rw-r--r--platform/osx/os_osx.mm98
-rw-r--r--platform/windows/detect.py21
-rw-r--r--platform/windows/os_windows.cpp3
-rw-r--r--platform/winrt/SCsub2
-rw-r--r--platform/winrt/app.cpp245
-rw-r--r--platform/winrt/app.h14
-rw-r--r--platform/winrt/detect.py125
-rw-r--r--platform/winrt/gl_context_egl.cpp28
-rw-r--r--platform/winrt/gl_context_egl.h1
-rw-r--r--platform/winrt/include/EGL/eglext.h21
-rw-r--r--platform/winrt/include/EGL/eglplatform.h4
-rw-r--r--platform/winrt/include/GLSLANG/ShaderLang.h216
-rw-r--r--platform/winrt/include/GLSLANG/ShaderVars.h93
-rw-r--r--platform/winrt/include/angle_windowsstore.h37
-rw-r--r--platform/winrt/os_winrt.cpp31
-rw-r--r--platform/winrt/os_winrt.h7
-rw-r--r--platform/x11/detect.py8
-rw-r--r--platform/x11/os_x11.cpp16
-rw-r--r--platform/x11/os_x11.h10
-rw-r--r--scene/2d/area_2d.cpp34
-rw-r--r--scene/2d/area_2d.h10
-rw-r--r--scene/2d/collision_polygon_2d.cpp22
-rw-r--r--scene/2d/collision_polygon_2d.h4
-rw-r--r--scene/2d/physics_body_2d.cpp58
-rw-r--r--scene/2d/physics_body_2d.h12
-rw-r--r--scene/2d/sample_player_2d.cpp1
-rw-r--r--scene/3d/camera.cpp35
-rw-r--r--scene/3d/camera.h8
-rw-r--r--scene/3d/collision_object.cpp5
-rw-r--r--scene/3d/immediate_geometry.cpp2
-rw-r--r--scene/3d/physics_body.cpp6
-rw-r--r--scene/3d/ray_cast.cpp58
-rw-r--r--scene/3d/ray_cast.h9
-rw-r--r--scene/3d/spatial_sample_player.cpp1
-rw-r--r--scene/3d/sprite_3d.cpp2
-rw-r--r--scene/animation/animation_player.cpp13
-rw-r--r--scene/animation/animation_player.h3
-rw-r--r--scene/animation/animation_tree_player.cpp3
-rw-r--r--scene/animation/tween.cpp195
-rw-r--r--scene/animation/tween.h45
-rw-r--r--scene/audio/sample_player.cpp1
-rw-r--r--scene/gui/box_container.cpp4
-rw-r--r--scene/gui/control.cpp102
-rw-r--r--scene/gui/empty_control.cpp59
-rw-r--r--scene/gui/graph_edit.cpp586
-rw-r--r--scene/gui/graph_edit.h100
-rw-r--r--scene/gui/graph_node.cpp583
-rw-r--r--scene/gui/graph_node.h101
-rw-r--r--scene/gui/menu_button.cpp1
-rw-r--r--scene/gui/popup.cpp15
-rw-r--r--scene/gui/popup_menu.cpp19
-rw-r--r--scene/gui/popup_menu.h4
-rw-r--r--scene/gui/tab_container.cpp33
-rw-r--r--scene/gui/tab_container.h2
-rw-r--r--scene/gui/text_edit.cpp6079
-rw-r--r--scene/gui/text_edit.h19
-rw-r--r--scene/gui/texture_button.cpp81
-rw-r--r--scene/gui/texture_button.h7
-rw-r--r--scene/main/node.cpp25
-rw-r--r--scene/main/node.h1
-rw-r--r--scene/register_scene_types.cpp22
-rw-r--r--scene/resources/audio_stream_resampled.cpp30
-rw-r--r--scene/resources/audio_stream_resampled.h4
-rw-r--r--scene/resources/curve.cpp6
-rw-r--r--scene/resources/default_theme/default_theme.cpp19
-rw-r--r--scene/resources/default_theme/graph_node.pngbin0 -> 770 bytes
-rw-r--r--scene/resources/default_theme/graph_node_close.pngbin0 -> 243 bytes
-rw-r--r--scene/resources/default_theme/graph_port.pngbin0 -> 509 bytes
-rw-r--r--scene/resources/default_theme/theme_data.h15
-rw-r--r--scene/resources/material.cpp18
-rw-r--r--scene/resources/material.h1
-rw-r--r--scene/resources/polygon_path_finder.cpp4
-rw-r--r--scene/resources/shader.cpp59
-rw-r--r--scene/resources/shader.h25
-rw-r--r--scene/resources/shader_graph.cpp2531
-rw-r--r--scene/resources/shader_graph.h413
-rw-r--r--scene/resources/surface_tool.cpp4
-rw-r--r--scene/resources/world_2d.cpp4
-rw-r--r--scene/scene_string_names.cpp1
-rw-r--r--scene/scene_string_names.h1
-rw-r--r--servers/physics/body_pair_sw.cpp62
-rw-r--r--servers/physics/body_pair_sw.h1
-rw-r--r--servers/physics/physics_server_sw.cpp2
-rw-r--r--servers/physics_2d/area_2d_sw.cpp9
-rw-r--r--servers/physics_2d/area_2d_sw.h10
-rw-r--r--servers/physics_2d/body_2d_sw.cpp45
-rw-r--r--servers/physics_2d/body_2d_sw.h14
-rw-r--r--servers/physics_2d/body_pair_2d_sw.cpp2
-rw-r--r--servers/physics_2d/space_2d_sw.cpp5
-rw-r--r--servers/physics_2d/space_2d_sw.h3
-rw-r--r--servers/physics_2d_server.cpp19
-rw-r--r--servers/physics_2d_server.h12
-rw-r--r--servers/visual/rasterizer.h4
-rw-r--r--servers/visual/rasterizer_dummy.cpp10
-rw-r--r--servers/visual/rasterizer_dummy.h4
-rw-r--r--servers/visual/shader_graph.h3
-rw-r--r--servers/visual/shader_language.cpp31
-rw-r--r--servers/visual/visual_server_raster.cpp10
-rw-r--r--servers/visual/visual_server_raster.h4
-rw-r--r--servers/visual/visual_server_wrap_mt.h4
-rw-r--r--servers/visual_server.h4
-rw-r--r--tools/SCsub17
-rw-r--r--tools/doc/doc_data.cpp6
-rw-r--r--tools/editor/animation_editor.cpp10
-rw-r--r--tools/editor/animation_editor.h4
-rw-r--r--tools/editor/code_editor.cpp28
-rw-r--r--tools/editor/code_editor.h4
-rw-r--r--tools/editor/editor_help.cpp4
-rw-r--r--tools/editor/editor_import_export.cpp12
-rw-r--r--tools/editor/editor_log.cpp4
-rw-r--r--tools/editor/editor_log.h4
-rw-r--r--tools/editor/editor_node.cpp50
-rw-r--r--tools/editor/editor_node.h6
-rw-r--r--tools/editor/editor_settings.cpp4
-rw-r--r--tools/editor/icons/icon_canvas_item_shader.pngbin0 -> 568 bytes
-rw-r--r--tools/editor/icons/icon_canvas_item_shader_graph.pngbin0 -> 575 bytes
-rw-r--r--tools/editor/icons/icon_graph_comment.pngbin0 -> 310 bytes
-rw-r--r--tools/editor/icons/icon_graph_cube_uniform.pngbin0 -> 652 bytes
-rw-r--r--tools/editor/icons/icon_graph_input.pngbin0 -> 585 bytes
-rw-r--r--tools/editor/icons/icon_graph_rgb.pngbin0 -> 174 bytes
-rw-r--r--tools/editor/icons/icon_graph_rgb_op.pngbin0 -> 280 bytes
-rw-r--r--tools/editor/icons/icon_graph_rgb_uniform.pngbin0 -> 419 bytes
-rw-r--r--tools/editor/icons/icon_graph_scalar.pngbin0 -> 328 bytes
-rw-r--r--tools/editor/icons/icon_graph_scalar_interp.pngbin0 -> 352 bytes
-rw-r--r--tools/editor/icons/icon_graph_scalar_op.pngbin0 -> 238 bytes
-rw-r--r--tools/editor/icons/icon_graph_scalar_uniform.pngbin0 -> 392 bytes
-rw-r--r--tools/editor/icons/icon_graph_scalars_to_vec.pngbin0 -> 300 bytes
-rw-r--r--tools/editor/icons/icon_graph_texscreen.pngbin0 -> 578 bytes
-rw-r--r--tools/editor/icons/icon_graph_texture_uniform.pngbin0 -> 358 bytes
-rw-r--r--tools/editor/icons/icon_graph_time.pngbin0 -> 678 bytes
-rw-r--r--tools/editor/icons/icon_graph_vec_dp.pngbin0 -> 279 bytes
-rw-r--r--tools/editor/icons/icon_graph_vec_interp.pngbin0 -> 332 bytes
-rw-r--r--tools/editor/icons/icon_graph_vec_length.pngbin0 -> 303 bytes
-rw-r--r--tools/editor/icons/icon_graph_vec_op.pngbin0 -> 256 bytes
-rw-r--r--tools/editor/icons/icon_graph_vec_scalar_op.pngbin0 -> 267 bytes
-rw-r--r--tools/editor/icons/icon_graph_vec_to_scalars.pngbin0 -> 306 bytes
-rw-r--r--tools/editor/icons/icon_graph_vecs_to_xform.pngbin0 -> 288 bytes
-rw-r--r--tools/editor/icons/icon_graph_vector.pngbin0 -> 480 bytes
-rw-r--r--tools/editor/icons/icon_graph_vector_uniform.pngbin0 -> 531 bytes
-rw-r--r--tools/editor/icons/icon_graph_xform.pngbin0 -> 262 bytes
-rw-r--r--tools/editor/icons/icon_graph_xform_mult.pngbin0 -> 311 bytes
-rw-r--r--tools/editor/icons/icon_graph_xform_scalar_func.pngbin0 -> 378 bytes
-rw-r--r--tools/editor/icons/icon_graph_xform_to_vecs.pngbin0 -> 272 bytes
-rw-r--r--tools/editor/icons/icon_graph_xform_uniform.pngbin0 -> 346 bytes
-rw-r--r--tools/editor/icons/icon_graph_xform_vec_func.pngbin0 -> 389 bytes
-rw-r--r--tools/editor/icons/icon_graph_xform_vec_imult.pngbin0 -> 430 bytes
-rw-r--r--tools/editor/icons/icon_graph_xform_vec_mult.pngbin0 -> 422 bytes
-rw-r--r--tools/editor/icons/icon_material_shader.pngbin0 -> 844 bytes
-rw-r--r--tools/editor/icons/icon_material_shader_graph.pngbin0 -> 949 bytes
-rw-r--r--tools/editor/plugins/animation_player_editor_plugin.cpp4
-rw-r--r--tools/editor/plugins/canvas_item_editor_plugin.cpp16
-rw-r--r--tools/editor/plugins/canvas_item_editor_plugin.h6
-rw-r--r--tools/editor/plugins/collision_polygon_2d_editor_plugin.cpp2
-rw-r--r--tools/editor/plugins/collision_polygon_editor_plugin.cpp2
-rw-r--r--tools/editor/plugins/item_list_editor_plugin.cpp1
-rw-r--r--tools/editor/plugins/script_editor_plugin.cpp55
-rw-r--r--tools/editor/plugins/script_editor_plugin.h2
-rw-r--r--tools/editor/plugins/shader_editor_plugin.cpp1
-rw-r--r--tools/editor/plugins/shader_graph_editor_plugin.cpp2088
-rw-r--r--tools/editor/plugins/shader_graph_editor_plugin.h174
-rw-r--r--tools/editor/plugins/spatial_editor_plugin.cpp37
-rw-r--r--tools/editor/plugins/spatial_editor_plugin.h6
-rw-r--r--tools/editor/plugins/tile_map_editor_plugin.cpp54
-rw-r--r--tools/editor/plugins/tile_map_editor_plugin.h13
-rw-r--r--tools/editor/progress_dialog.cpp6
-rw-r--r--tools/editor/project_export.cpp4
-rw-r--r--tools/editor/project_export.h2
-rw-r--r--tools/editor/project_manager.cpp10
-rw-r--r--tools/editor/property_editor.cpp85
-rw-r--r--tools/editor/property_editor.h4
-rw-r--r--tools/editor/scene_tree_dock.cpp51
-rw-r--r--tools/editor/script_editor_debugger.cpp2
-rw-r--r--version.py2
257 files changed, 12827 insertions, 6032 deletions
diff --git a/README.md b/README.md
index dba980bba9..3456290f74 100644
--- a/README.md
+++ b/README.md
@@ -10,11 +10,6 @@ The editor, language and APIs are feature rich, yet simple to learn, allowing yo
Godot has been developed by Juan Linietsky and Ariel Manzur for several years, and was born as an in-house engine, used to publish several work-for-hire titles.
Development is sponsored by OKAM Studio (http://www.okamstudio.com).
-### Godot is BETA. Collaborate!!
-
-Having been developed as in-house means that the user experience may still not be ideal for everyone. The features needed to make a great game are there, but we really need your help to fix all the rough edges and improve usability (via feedback and/or code contributions).
-We know we are close to having an awesome, open source, game engine with nothing to envy from the best commercial offerings, but we can't do this alone. This is why Godot is now open source, so everyone can help us reach this goal.
-
### Documentation
Documentation has been moved to the [GitHub Wiki](https://github.com/okamstudio/godot/wiki).
diff --git a/SConstruct b/SConstruct
index 42e9085171..b9f2b7e2c4 100644
--- a/SConstruct
+++ b/SConstruct
@@ -133,8 +133,8 @@ Help(opts.GenerateHelpText(env_base)) # generate help
# add default include paths
env_base.Append(CPPPATH=['#core','#core/math','#tools','#drivers','#'])
-
-# configure ENV for platform
+
+# configure ENV for platform
env_base.platform_exporters=platform_exporters
"""
diff --git a/bin/tests/test_gdscript.cpp b/bin/tests/test_gdscript.cpp
index b62deee2cd..4b4030954a 100644
--- a/bin/tests/test_gdscript.cpp
+++ b/bin/tests/test_gdscript.cpp
@@ -738,6 +738,26 @@ static void _disassemble_class(const Ref<GDScript>& p_class,const Vector<String>
incr=4+argc;
} break;
+ case GDFunction::OPCODE_YIELD: {
+
+ txt+=" yield ";
+ incr=1;
+
+ } break;
+ case GDFunction::OPCODE_YIELD_SIGNAL: {
+
+ txt+=" yield_signal ";
+ txt+=DADDR(1);
+ txt+=",";
+ txt+=DADDR(2);
+ incr=3;
+ } break;
+ case GDFunction::OPCODE_YIELD_RESUME: {
+
+ txt+=" yield resume: ";
+ txt+=DADDR(1);
+ incr=2;
+ } break;
case GDFunction::OPCODE_JUMP: {
txt+=" jump ";
diff --git a/bin/tests/test_math.cpp b/bin/tests/test_math.cpp
index 2db945d5fd..ea324a7381 100644
--- a/bin/tests/test_math.cpp
+++ b/bin/tests/test_math.cpp
@@ -80,6 +80,7 @@ MainLoop* test() {
{
+
// print_line("NUM: "+itos(237641278346127));
print_line("NUM: "+itos(-128));
return NULL;
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp
index 0dd467986e..0c5d21b4f6 100644
--- a/core/bind/core_bind.cpp
+++ b/core/bind/core_bind.cpp
@@ -12,9 +12,9 @@ Ref<ResourceInteractiveLoader> _ResourceLoader::load_interactive(const String& p
return ResourceLoader::load_interactive(p_path,p_type_hint);
}
-RES _ResourceLoader::load(const String &p_path,const String& p_type_hint) {
+RES _ResourceLoader::load(const String &p_path,const String& p_type_hint, bool p_no_cache) {
- RES ret = ResourceLoader::load(p_path,p_type_hint);
+ RES ret = ResourceLoader::load(p_path,p_type_hint, p_no_cache);
return ret;
}
@@ -59,7 +59,7 @@ void _ResourceLoader::_bind_methods() {
ObjectTypeDB::bind_method(_MD("load_interactive:ResourceInteractiveLoader","path","type_hint"),&_ResourceLoader::load_interactive,DEFVAL(""));
- ObjectTypeDB::bind_method(_MD("load:Resource","path","type_hint"),&_ResourceLoader::load,DEFVAL(""));
+ ObjectTypeDB::bind_method(_MD("load:Resource","path","type_hint", "p_no_cache"),&_ResourceLoader::load,DEFVAL(""), DEFVAL(false));
ObjectTypeDB::bind_method(_MD("get_recognized_extensions_for_type","type"),&_ResourceLoader::get_recognized_extensions_for_type);
ObjectTypeDB::bind_method(_MD("set_abort_on_missing_resources","abort"),&_ResourceLoader::set_abort_on_missing_resources);
ObjectTypeDB::bind_method(_MD("get_dependencies"),&_ResourceLoader::get_dependencies);
@@ -1121,6 +1121,7 @@ String _File::get_as_text() const {
text+=l+"\n";
l = get_line();
}
+ text+=l;
return text;
diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h
index a76b4aa81f..12a4ae86eb 100644
--- a/core/bind/core_bind.h
+++ b/core/bind/core_bind.h
@@ -21,7 +21,7 @@ public:
static _ResourceLoader *get_singleton() { return singleton; }
Ref<ResourceInteractiveLoader> load_interactive(const String& p_path,const String& p_type_hint="");
- RES load(const String &p_path,const String& p_type_hint="");
+ RES load(const String &p_path,const String& p_type_hint="", bool p_no_cache = false);
DVector<String> get_recognized_extensions_for_type(const String& p_type);
void set_abort_on_missing_resources(bool p_abort);
StringArray get_dependencies(const String& p_path);
diff --git a/core/dictionary.cpp b/core/dictionary.cpp
index 16ee397382..2d503bae50 100644
--- a/core/dictionary.cpp
+++ b/core/dictionary.cpp
@@ -186,10 +186,12 @@ Error Dictionary::parse_json(const String& p_json) {
String errstr;
int errline=0;
+ if (p_json != ""){
Error err = JSON::parse(p_json,*this,errstr,errline);
if (err!=OK) {
ERR_EXPLAIN("Error parsing JSON: "+errstr+" at line: "+itos(errline));
ERR_FAIL_COND_V(err!=OK,err);
+ }
}
return OK;
diff --git a/core/io/http_client.cpp b/core/io/http_client.cpp
index 60a200af12..faead675d4 100644
--- a/core/io/http_client.cpp
+++ b/core/io/http_client.cpp
@@ -29,6 +29,8 @@
#include "http_client.h"
#include "io/stream_peer_ssl.h"
+VARIANT_ENUM_CAST(HTTPClient::Status);
+
Error HTTPClient::connect_url(const String& p_url) {
return OK;
diff --git a/core/io/ip.cpp b/core/io/ip.cpp
index d2a685f6b0..6ef6b31188 100644
--- a/core/io/ip.cpp
+++ b/core/io/ip.cpp
@@ -31,7 +31,7 @@
#include "os/semaphore.h"
#include "hash_map.h"
-
+VARIANT_ENUM_CAST(IP::ResolverStatus);
/************* RESOLVER ******************/
diff --git a/core/io/json.cpp b/core/io/json.cpp
index a83d7e4d6e..88a23eb4cd 100644
--- a/core/io/json.cpp
+++ b/core/io/json.cpp
@@ -250,7 +250,7 @@ Error JSON::_get_token(const CharType *p_str, int &idx, int p_len, Token& r_toke
if (p_str[idx]=='-' || (p_str[idx]>='0' && p_str[idx]<='9')) {
//a number
const CharType *rptr;
- double number = String::to_double(&p_str[idx],-1,&rptr);
+ double number = String::to_double(&p_str[idx],&rptr);
idx+=(rptr - &p_str[idx]);
r_token.type=TK_NUMBER;
r_token.value=number;
diff --git a/core/io/stream_peer_tcp.cpp b/core/io/stream_peer_tcp.cpp
index 0e75e22767..f83c174084 100644
--- a/core/io/stream_peer_tcp.cpp
+++ b/core/io/stream_peer_tcp.cpp
@@ -32,7 +32,7 @@ StreamPeerTCP* (*StreamPeerTCP::_create)()=NULL;
void StreamPeerTCP::_bind_methods() {
- ObjectTypeDB::bind_method(_MD("connect","host","ip"),&StreamPeerTCP::connect);
+ ObjectTypeDB::bind_method(_MD("connect","host","port"),&StreamPeerTCP::connect);
ObjectTypeDB::bind_method(_MD("is_connected"),&StreamPeerTCP::is_connected);
ObjectTypeDB::bind_method(_MD("get_status"),&StreamPeerTCP::get_status);
ObjectTypeDB::bind_method(_MD("get_connected_host"),&StreamPeerTCP::get_connected_host);
diff --git a/core/io/xml_parser.cpp b/core/io/xml_parser.cpp
index 5d3e4f61ad..1d69f8e5e7 100644
--- a/core/io/xml_parser.cpp
+++ b/core/io/xml_parser.cpp
@@ -30,9 +30,11 @@
#include "print_string.h"
//#define DEBUG_XML
+VARIANT_ENUM_CAST(XMLParser::NodeType);
+
static bool _equalsn(const CharType* str1, const CharType* str2, int len) {
int i;
- for(i=0; str1[i] && str2[i] && i < len; ++i)
+ for(i=0; i < len && str1[i] && str2[i] ; ++i)
if (str1[i] != str2[i])
return false;
diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h
index c98a088912..6d43ed8e64 100644
--- a/core/math/math_funcs.h
+++ b/core/math/math_funcs.h
@@ -136,7 +136,10 @@ public:
static int b;
-#if defined(_MSC_VER) && _MSC_VER < 1800
+#if (defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0603) || WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP // windows 8 phone?
+ b = (int)((a>0.0f) ? (a + 0.5f):(a -0.5f));
+
+#elif defined(_MSC_VER) && _MSC_VER < 1800
__asm fld a
__asm fistp b
/*#elif defined( __GNUC__ ) && ( defined( __i386__ ) || defined( __x86_64__ ) )
@@ -147,6 +150,7 @@ public:
"fistpl %0 \n\t"
: "=m" (b)
: "m" (a));*/
+
#else
b=lrintf(a); //assuming everything but msvc 2012 or earlier has lrint
#endif
diff --git a/core/method_bind.cpp b/core/method_bind.cpp
index 739745f70f..6ee4882571 100644
--- a/core/method_bind.cpp
+++ b/core/method_bind.cpp
@@ -87,7 +87,9 @@ Vector<StringName> MethodBind::get_argument_names() const {
void MethodBind::set_default_arguments(const Vector<Variant>& p_defargs) {
- default_arguments=p_defargs; default_argument_count=default_arguments.size();
+ default_arguments=p_defargs;
+ default_argument_count=default_arguments.size();
+
}
#ifdef DEBUG_METHODS_ENABLED
diff --git a/core/method_bind.h b/core/method_bind.h
index 3f08c70af8..6ea9340ad5 100644
--- a/core/method_bind.h
+++ b/core/method_bind.h
@@ -178,6 +178,7 @@ public:
#ifdef DEBUG_METHODS_ENABLED
_FORCE_INLINE_ void set_return_type(const StringName& p_type) { ret_type=p_type; }
+ _FORCE_INLINE_ StringName get_return_type() const { return ret_type; }
_FORCE_INLINE_ Variant::Type get_argument_type(int p_argument) const {
diff --git a/core/object.cpp b/core/object.cpp
index 42d570042f..82144ab4be 100644
--- a/core/object.cpp
+++ b/core/object.cpp
@@ -1694,6 +1694,11 @@ void ObjectDB::debug_objects(DebugFunc p_func) {
}
+void Object::get_argument_options(const StringName& p_function,int p_idx,List<String>*r_options) const {
+
+
+}
+
int ObjectDB::get_object_count() {
GLOBAL_LOCK_FUNCTION;
diff --git a/core/object.h b/core/object.h
index 7ce07869a6..97ca50cb1a 100644
--- a/core/object.h
+++ b/core/object.h
@@ -583,6 +583,7 @@ public:
virtual void get_translatable_strings(List<String> *p_strings) const;
+ virtual void get_argument_options(const StringName& p_function,int p_idx,List<String>*r_options) const;
StringName XL_MESSAGE(const StringName& p_message) const; //translate message (internationalization)
StringName tr(const StringName& p_message) const; //translate message (alternative)
diff --git a/core/object_type_db.cpp b/core/object_type_db.cpp
index 62244cbd4f..f7917b7418 100644
--- a/core/object_type_db.cpp
+++ b/core/object_type_db.cpp
@@ -191,6 +191,7 @@ MethodDefinition _MD(const char* p_name,const char *p_arg1,const char *p_arg2,co
HashMap<StringName,ObjectTypeDB::TypeInfo,StringNameHasher> ObjectTypeDB::types;
HashMap<StringName,StringName,StringNameHasher> ObjectTypeDB::resource_base_extensions;
+HashMap<StringName,StringName,StringNameHasher> ObjectTypeDB::compat_types;
ObjectTypeDB::TypeInfo::TypeInfo() {
@@ -263,12 +264,22 @@ bool ObjectTypeDB::type_exists(const String &p_type) {
return types.has(p_type);
}
+void ObjectTypeDB::add_compatibility_type(const StringName& p_type,const StringName& p_fallback) {
+
+ compat_types[p_type]=p_fallback;
+}
+
Object *ObjectTypeDB::instance(const String &p_type) {
TypeInfo *ti;
{
OBJTYPE_LOCK;
ti=types.getptr(p_type);
+ if (!ti || ti->disabled || !ti->creation_func) {
+ if (compat_types.has(p_type)) {
+ ti=types.getptr(compat_types[p_type]);
+ }
+ }
ERR_FAIL_COND_V(!ti,NULL);
ERR_FAIL_COND_V(ti->disabled,NULL);
ERR_FAIL_COND_V(!ti->creation_func,NULL);
@@ -805,12 +816,25 @@ void ObjectTypeDB::add_virtual_method(const StringName& p_type,const MethodInfo&
}
-void ObjectTypeDB::get_virtual_methods(const StringName& p_type,List<MethodInfo> * p_methods ) {
+void ObjectTypeDB::get_virtual_methods(const StringName& p_type, List<MethodInfo> * p_methods , bool p_no_inheritance) {
ERR_FAIL_COND(!types.has(p_type));
#ifdef DEBUG_METHODS_ENABLED
- *p_methods=types[p_type].virtual_methods;
+
+ TypeInfo *type=types.getptr(p_type);
+ TypeInfo *check=type;
+ while(check) {
+
+ for(List<MethodInfo>::Element *E=check->virtual_methods.front();E;E=E->next()) {
+ p_methods->push_back(E->get());
+ }
+
+ if (p_no_inheritance)
+ return;
+ check=check->inherits_ptr;
+ }
+
#endif
}
@@ -901,6 +925,7 @@ void ObjectTypeDB::cleanup() {
}
types.clear();
resource_base_extensions.clear();
+ compat_types.clear();
}
//
diff --git a/core/object_type_db.h b/core/object_type_db.h
index ae0644f9b3..617a0a7c20 100644
--- a/core/object_type_db.h
+++ b/core/object_type_db.h
@@ -151,6 +151,7 @@ class ObjectTypeDB {
static Mutex *lock;
static HashMap<StringName,TypeInfo,StringNameHasher> types;
static HashMap<StringName,StringName,StringNameHasher> resource_base_extensions;
+ static HashMap<StringName,StringName,StringNameHasher> compat_types;
#ifdef DEBUG_METHODS_ENABLED
static MethodBind* bind_methodfi(uint32_t p_flags, MethodBind *p_bind , const MethodDefinition &method_name, const Variant **p_defs, int p_defcount);
@@ -468,7 +469,7 @@ public:
static MethodBind *get_method(StringName p_type, StringName p_name);
static void add_virtual_method(const StringName& p_type,const MethodInfo& p_method );
- static void get_virtual_methods(const StringName& p_type,List<MethodInfo> * p_methods );
+ static void get_virtual_methods(const StringName& p_type,List<MethodInfo> * p_methods,bool p_no_inheritance=false );
static void bind_integer_constant(const StringName& p_type, const StringName &p_name, int p_constant);
static void get_integer_constant_list(const StringName& p_type, List<String> *p_constants, bool p_no_inheritance=false);
@@ -482,6 +483,7 @@ public:
static void get_resource_base_extensions(List<String> *p_extensions);
static void get_extensions_for_type(const StringName& p_type,List<String> *p_extensions);
+ static void add_compatibility_type(const StringName& p_type,const StringName& p_fallback);
static void init();
static void cleanup();
};
diff --git a/core/os/input.cpp b/core/os/input.cpp
index 4151c1b5a8..a827e75896 100644
--- a/core/os/input.cpp
+++ b/core/os/input.cpp
@@ -29,6 +29,7 @@
#include "input.h"
#include "input_map.h"
#include "os/os.h"
+#include "globals.h"
Input *Input::singleton=NULL;
Input *Input::get_singleton() {
@@ -69,6 +70,30 @@ void Input::_bind_methods() {
ADD_SIGNAL( MethodInfo("joy_connection_changed", PropertyInfo(Variant::INT, "index"), PropertyInfo(Variant::BOOL, "connected")) );
}
+void Input::get_argument_options(const StringName& p_function,int p_idx,List<String>*r_options) const {
+#ifdef TOOLS_ENABLED
+
+ String pf=p_function;
+ if (p_idx==0 && (pf=="is_action_pressed" || pf=="action_press" || pf=="action_release")) {
+
+ List<PropertyInfo> pinfo;
+ Globals::get_singleton()->get_property_list(&pinfo);
+
+ for(List<PropertyInfo>::Element *E=pinfo.front();E;E=E->next()) {
+ const PropertyInfo &pi=E->get();
+
+ if (!pi.name.begins_with("input/"))
+ continue;
+
+ String name = pi.name.substr(pi.name.find("/")+1,pi.name.length());
+ r_options->push_back("\""+name+"\"");
+
+ }
+ }
+#endif
+
+}
+
Input::Input() {
singleton=this;
diff --git a/core/os/input.h b/core/os/input.h
index 1cb0f35d96..387a43a35a 100644
--- a/core/os/input.h
+++ b/core/os/input.h
@@ -76,6 +76,8 @@ public:
virtual void action_press(const StringName& p_action)=0;
virtual void action_release(const StringName& p_action)=0;
+ void get_argument_options(const StringName& p_function,int p_idx,List<String>*r_options) const;
+
Input();
};
diff --git a/core/os/keyboard.cpp b/core/os/keyboard.cpp
index a4201c34ea..e2a992ecb9 100644
--- a/core/os/keyboard.cpp
+++ b/core/os/keyboard.cpp
@@ -27,7 +27,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "keyboard.h"
-
+#include "os/os.h"
struct _KeyCodeText {
int code;
@@ -353,3 +353,106 @@ int find_keycode(const String& p_code) {
return 0;
}
+
+
+
+
+struct _KeyCodeReplace {
+ int from;
+ int to;
+};
+
+static const _KeyCodeReplace _keycode_replace_qwertz[]={
+{KEY_Y,KEY_Z},
+{KEY_Z,KEY_Y},
+{0,0}
+};
+
+static const _KeyCodeReplace _keycode_replace_azerty[]={
+{KEY_W,KEY_Z},
+{KEY_Z,KEY_W},
+{KEY_A,KEY_Q},
+{KEY_Q,KEY_A},
+{KEY_SEMICOLON,KEY_M},
+{KEY_M,KEY_SEMICOLON},
+{0,0}
+};
+
+static const _KeyCodeReplace _keycode_replace_qzerty[]={
+{KEY_W,KEY_Z},
+{KEY_Z,KEY_W},
+{KEY_SEMICOLON,KEY_M},
+{KEY_M,KEY_SEMICOLON},
+{0,0}
+};
+
+static const _KeyCodeReplace _keycode_replace_dvorak[]={
+{KEY_UNDERSCORE,KEY_BRACELEFT},
+{KEY_EQUAL,KEY_BRACERIGHT},
+{KEY_Q,KEY_APOSTROPHE},
+{KEY_W,KEY_COMMA},
+{KEY_E,KEY_PERIOD},
+{KEY_R,KEY_P},
+{KEY_T,KEY_Y},
+{KEY_Y,KEY_F},
+{KEY_U,KEY_G},
+{KEY_I,KEY_C},
+{KEY_O,KEY_R},
+{KEY_P,KEY_L},
+{KEY_BRACELEFT,KEY_SLASH},
+{KEY_BRACERIGHT,KEY_EQUAL},
+{KEY_A,KEY_A},
+{KEY_S,KEY_O},
+{KEY_D,KEY_E},
+{KEY_F,KEY_U},
+{KEY_G,KEY_I},
+{KEY_H,KEY_D},
+{KEY_J,KEY_H},
+{KEY_K,KEY_T},
+{KEY_L,KEY_N},
+{KEY_SEMICOLON,KEY_S},
+{KEY_APOSTROPHE,KEY_UNDERSCORE},
+{KEY_Z,KEY_SEMICOLON},
+{KEY_X,KEY_Q},
+{KEY_C,KEY_J},
+{KEY_V,KEY_K},
+{KEY_B,KEY_X},
+{KEY_N,KEY_B},
+{KEY_M,KEY_M},
+{KEY_COMMA,KEY_W},
+{KEY_PERIOD,KEY_V},
+{KEY_SLASH,KEY_Z},
+{0,0}
+};
+
+static const _KeyCodeReplace _keycode_replace_neo[]={
+{0,0}
+};
+
+
+int latin_keyboard_keycode_convert(int p_keycode) {
+
+ const _KeyCodeReplace *kcr=NULL;
+ switch(OS::get_singleton()->get_latin_keyboard_variant()) {
+
+ case OS::LATIN_KEYBOARD_QWERTY: return p_keycode; break;
+ case OS::LATIN_KEYBOARD_QWERTZ: kcr=_keycode_replace_qwertz; break;
+ case OS::LATIN_KEYBOARD_AZERTY: kcr=_keycode_replace_azerty; break;
+ case OS::LATIN_KEYBOARD_QZERTY: kcr=_keycode_replace_qzerty; break;
+ case OS::LATIN_KEYBOARD_DVORAK: kcr=_keycode_replace_dvorak; break;
+ case OS::LATIN_KEYBOARD_NEO: kcr=_keycode_replace_neo; break;
+ default: return p_keycode;
+ }
+
+ if (!kcr) {
+ return p_keycode;
+ }
+
+ while(kcr->from) {
+ if (kcr->from==p_keycode)
+ return kcr->to;
+ kcr++;
+ }
+
+ return p_keycode;
+}
diff --git a/core/os/keyboard.h b/core/os/keyboard.h
index 18b56b5830..b4ec5da26f 100644
--- a/core/os/keyboard.h
+++ b/core/os/keyboard.h
@@ -328,5 +328,6 @@ enum KeyModifierMask {
String keycode_get_string(uint32_t p_code);
bool keycode_has_unicode(uint32_t p_unicode);
int find_keycode(const String& p_code);
+int latin_keyboard_keycode_convert(int p_keycode);
#endif
diff --git a/core/os/os.cpp b/core/os/os.cpp
index 081f7c1c5e..5e0e5eed77 100644
--- a/core/os/os.cpp
+++ b/core/os/os.cpp
@@ -485,6 +485,11 @@ void OS::set_time_scale(float p_scale) {
_time_scale=p_scale;
}
+OS::LatinKeyboardVariant OS::get_latin_keyboard_variant() const {
+
+ return LATIN_KEYBOARD_QWERTY;
+}
+
float OS::get_time_scale() const {
return _time_scale;
diff --git a/core/os/os.h b/core/os/os.h
index 805d6ac57d..d4deff2f5e 100644
--- a/core/os/os.h
+++ b/core/os/os.h
@@ -34,6 +34,7 @@
#include "vector.h"
#include "os/main_loop.h"
#include <stdarg.h>
+
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
@@ -348,6 +349,18 @@ public:
virtual Error dialog_input_text(String p_title, String p_description, String p_partial, Object* p_obj, String p_callback);
+ enum LatinKeyboardVariant {
+ LATIN_KEYBOARD_QWERTY,
+ LATIN_KEYBOARD_QWERTZ,
+ LATIN_KEYBOARD_AZERTY,
+ LATIN_KEYBOARD_QZERTY,
+ LATIN_KEYBOARD_DVORAK,
+ LATIN_KEYBOARD_NEO,
+ };
+
+
+ virtual LatinKeyboardVariant get_latin_keyboard_variant() const;
+
void set_time_scale(float p_scale);
float get_time_scale() const;
diff --git a/core/register_core_types.cpp b/core/register_core_types.cpp
index 2f16e31de6..4935136eeb 100644
--- a/core/register_core_types.cpp
+++ b/core/register_core_types.cpp
@@ -110,6 +110,7 @@ void register_core_types() {
ObjectTypeDB::register_type<Reference>();
+ ObjectTypeDB::register_type<WeakRef>();
ObjectTypeDB::register_type<ResourceImportMetadata>();
ObjectTypeDB::register_type<Resource>();
ObjectTypeDB::register_type<FuncRef>();
diff --git a/core/script_language.h b/core/script_language.h
index d62e9849a1..802eff190a 100644
--- a/core/script_language.h
+++ b/core/script_language.h
@@ -144,7 +144,7 @@ public:
virtual bool has_named_classes() const=0;
virtual int find_function(const String& p_function,const String& p_code) const=0;
virtual String make_function(const String& p_class,const String& p_name,const StringArray& p_args) const=0;
- virtual Error complete_keyword(const String& p_code, int p_line, const String& p_base_path, const String& p_keyword, List<String>* r_options) { return ERR_UNAVAILABLE; }
+ virtual Error complete_code(const String& p_code, const String& p_base_path, Object*p_owner,List<String>* r_options,String& r_call_hint) { return ERR_UNAVAILABLE; }
virtual void auto_indent_code(String& p_code,int p_from_line,int p_to_line) const=0;
/* DEBUGGER FUNCTIONS */
diff --git a/core/translation.cpp b/core/translation.cpp
index 81f2c36075..6ad34651b2 100644
--- a/core/translation.cpp
+++ b/core/translation.cpp
@@ -550,7 +550,7 @@ StringName TranslationServer::translate(const StringName& p_message) const {
continue; // locale not match
//near match
- bool match = (l!=lptr);
+ bool match = (l!=locale);
if (near_match && !match)
continue; //only near-match once
@@ -570,6 +570,42 @@ StringName TranslationServer::translate(const StringName& p_message) const {
}
+ if (!res) {
+ //try again with fallback
+ if (fallback.length()>=2) {
+
+ const CharType *fptr=&fallback[0];
+ bool near_match=false;
+ for (const Set< Ref<Translation> >::Element *E=translations.front();E;E=E->next()) {
+
+ const Ref<Translation>& t = E->get();
+ String l = t->get_locale();
+ if (fptr[0]!=l[0] || fptr[1]!=l[1])
+ continue; // locale not match
+
+ //near match
+ bool match = (l!=fallback);
+
+ if (near_match && !match)
+ continue; //only near-match once
+
+ StringName r=t->get_message(p_message);
+
+ if (!r)
+ continue;
+
+ res=r;
+
+ if (match)
+ break;
+ else
+ near_match=true;
+
+ }
+ }
+ }
+
+
if (!res)
return p_message;
@@ -604,9 +640,27 @@ bool TranslationServer::_load_translations(const String& p_from) {
void TranslationServer::setup() {
-
- set_locale( GLOBAL_DEF("locale/default",OS::get_singleton()->get_locale()) );
- fallback = GLOBAL_DEF("locale/fallback","");
+ String test = GLOBAL_DEF("locale/test","");
+ test=test.strip_edges();
+ if (test!="")
+ set_locale( test );
+ else
+ set_locale( OS::get_singleton()->get_locale() );
+ fallback = GLOBAL_DEF("locale/fallback","en");
+#ifdef TOOLS_ENABLED
+
+ {
+ String options="";
+ int idx=0;
+ while(locale_list[idx]) {
+ if (idx>0)
+ options+=", ";
+ options+=locale_list[idx];
+ idx++;
+ }
+ Globals::get_singleton()->set_custom_property_info("locale/fallback",PropertyInfo(Variant::STRING,"locale/fallback",PROPERTY_HINT_ENUM,options));
+ }
+#endif
//load translations
}
@@ -629,6 +683,7 @@ void TranslationServer::load_translations() {
String locale = get_locale();
bool found = _load_translations("locale/translations"); //all
+
if (_load_translations("locale/translations_"+locale.substr(0,2)))
found=true;
if ( locale.substr(0,2) != locale ) {
@@ -637,17 +692,6 @@ void TranslationServer::load_translations() {
}
- if (!found && fallback!="") { //none found anywhere, use fallback
-
- _load_translations("locale/translations_"+fallback.substr(0,2));
- if ( fallback.substr(0,2) != fallback ) {
- _load_translations("locale/translations_"+fallback);
- }
-
- this->locale=fallback;
-
- }
-
}
TranslationServer::TranslationServer() {
diff --git a/core/ustring.cpp b/core/ustring.cpp
index d75c21d16e..581cc29440 100644
--- a/core/ustring.cpp
+++ b/core/ustring.cpp
@@ -626,7 +626,7 @@ Vector<float> String::split_floats(const String &p_splitter,bool p_allow_empty)
if (end<0)
end=len;
if (p_allow_empty || (end>from))
- ret.push_back(String::to_double(&c_str()[from],end-from));
+ ret.push_back(String::to_double(&c_str()[from]));
if (end==len)
break;
@@ -654,8 +654,9 @@ Vector<float> String::split_floats_mk(const Vector<String> &p_splitters,bool p_a
spl_len=p_splitters[idx].length();
}
- if (p_allow_empty || (end>from))
- ret.push_back(String::to_double(&c_str()[from],end-from));
+ if (p_allow_empty || (end>from)) {
+ ret.push_back(String::to_double(&c_str()[from]));
+ }
if (end==len)
break;
@@ -1959,8 +1960,10 @@ float String::to_float() const {
return to_double();
}
-double String::to_double(const CharType* p_str, int p_len, const CharType **r_end) {
+double String::to_double(const CharType* p_str, const CharType **r_end) {
+ return built_in_strtod<CharType>(p_str,(CharType**)r_end);
+#if 0
#if 0
//ndef NO_USE_STDLIB
return wcstod(p_str,p_len<0?NULL:p_str+p_len);
@@ -2053,6 +2056,7 @@ double String::to_double(const CharType* p_str, int p_len, const CharType **r_en
return sign*(integer+decimal)*Math::pow(10,exp_sign*exp);
#endif
+#endif
}
int64_t String::to_int(const CharType* p_str,int p_len) {
@@ -3437,7 +3441,7 @@ String String::percent_encode() const {
uint8_t c = cs[i];
if ( (c>='A' && c<='Z') || (c>='a' && c<='z') || (c>='0' && c<='9') || c=='-' || c=='_' || c=='~' || c=='.') {
- char p[2]={c,0};
+ char p[2]={(char)c,0};
encoded+=p;
} else {
char p[4]={'%',0,0,0};
diff --git a/core/ustring.h b/core/ustring.h
index 8fe3a95463..e1d6761742 100644
--- a/core/ustring.h
+++ b/core/ustring.h
@@ -142,7 +142,7 @@ public:
int64_t to_int64() const;
static int to_int(const char* p_str);
static double to_double(const char* p_str);
- static double to_double(const CharType* p_str, int p_len=-1, const CharType **r_end=NULL);
+ 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;
diff --git a/core/variant.cpp b/core/variant.cpp
index fdb14c0c0f..2f0eca9e91 100644
--- a/core/variant.cpp
+++ b/core/variant.cpp
@@ -2631,3 +2631,129 @@ Variant Variant::call(const StringName& p_method,VARIANT_ARG_DECLARE) {
return ret;
}
+
+String Variant::get_construct_string() const {
+
+ switch( type ) {
+
+ case NIL: return "null";
+ case BOOL: return _data._bool ? "true" : "false";
+ case INT: return String::num(_data._int);
+ case REAL: return String::num(_data._real);
+ case STRING: return "\""+*reinterpret_cast<const String*>(_data._mem)+"\"";
+ case VECTOR2: return "Vector2("+operator Vector2()+")";
+ case RECT2: return "Rect2("+operator Rect2()+")";
+ case MATRIX32: return "Matrix32("+operator Matrix32()+")";
+ case VECTOR3: return "Vector3("+operator Vector3()+")";
+ case PLANE: return "Plane("+operator Plane()+")";
+ //case QUAT:
+ case _AABB: return "AABB("+operator AABB()+")";
+ case QUAT: return "Quat("+operator Quat()+")";
+ case MATRIX3: return "Matrix3("+operator Matrix3()+")";
+ case TRANSFORM: return "Transform("+operator Transform()+")";
+ case NODE_PATH: return "@\""+operator NodePath()+"\"";
+ case INPUT_EVENT: return "InputEvent()";
+ case COLOR: return "Color("+String::num( operator Color().r)+","+String::num( operator Color().g)+","+String::num( operator Color().b)+","+String::num( operator Color().a)+")" ;
+ case DICTIONARY: {
+
+ const Dictionary &d =*reinterpret_cast<const Dictionary*>(_data._mem);
+ //const String *K=NULL;
+ String str="{";
+ List<Variant> keys;
+ d.get_key_list(&keys);
+
+ Vector<_VariantStrPair> pairs;
+
+ for(List<Variant>::Element *E=keys.front();E;E=E->next()) {
+
+ _VariantStrPair sp;
+ sp.key=E->get().get_construct_string();
+ sp.value=d[E->get()].get_construct_string();
+ pairs.push_back(sp);
+ }
+
+ pairs.sort();
+
+ for(int i=0;i<pairs.size();i++) {
+ if (i>0)
+ str+=", ";
+ str+="("+pairs[i].key+":"+pairs[i].value+")";
+ }
+ str+="}";
+
+ return str;
+ } break;
+ case VECTOR3_ARRAY: {
+
+ DVector<Vector3> vec = operator DVector<Vector3>();
+ String str="[";
+ for(int i=0;i<vec.size();i++) {
+
+ if (i>0)
+ str+=", ";
+ str+=Variant( vec[i] ).get_construct_string();
+ }
+ return str+"]";
+ } break;
+ case STRING_ARRAY: {
+
+ DVector<String> vec = operator DVector<String>();
+ String str="[";
+ for(int i=0;i<vec.size();i++) {
+
+ if (i>0)
+ str+=", ";
+ str=str+=Variant( vec[i] ).get_construct_string();
+ }
+ return str+"]";
+ } break;
+ case INT_ARRAY: {
+
+ DVector<int> vec = operator DVector<int>();
+ String str="[";
+ for(int i=0;i<vec.size();i++) {
+
+ if (i>0)
+ str+=", ";
+ str=str+itos(vec[i]);
+ }
+ return str+"]";
+ } break;
+ case REAL_ARRAY: {
+
+ DVector<real_t> vec = operator DVector<real_t>();
+ String str="[";
+ for(int i=0;i<vec.size();i++) {
+
+ if (i>0)
+ str+=", ";
+ str=str+rtos(vec[i]);
+ }
+ return str+"]";
+ } break;
+ case ARRAY: {
+
+ Array arr = operator Array();
+ String str="[";
+ for (int i=0; i<arr.size(); i++) {
+ if (i)
+ str+=", ";
+ str += arr[i].get_construct_string();
+ };
+ return str+"]";
+
+ } break;
+ case OBJECT: {
+
+ if (_get_obj().obj)
+ return _get_obj().obj->get_type()+".new()";
+ else
+ return "null";
+
+ } break;
+ default: {
+ return "["+get_type_name(type)+"]";
+ }
+ }
+
+}
diff --git a/core/variant.h b/core/variant.h
index 9109f4ad08..47fc3f43ac 100644
--- a/core/variant.h
+++ b/core/variant.h
@@ -167,14 +167,18 @@ public:
static String get_type_name(Variant::Type p_type);
static bool can_convert(Type p_type_from,Type p_type_to);
+
+
template<class T>
static Type get_type_for() {
GetSimpleType<T> t;
Variant v(t.type);
- return v.get_type();
+ Type r = v.get_type();
+ return r;
}
+
bool is_ref() const;
_FORCE_INLINE_ bool is_num() const { return type==INT || type==REAL; };
_FORCE_INLINE_ bool is_array() const { return type>=ARRAY; };
@@ -415,6 +419,8 @@ public:
static bool has_numeric_constant(Variant::Type p_type, const StringName& p_value);
static int get_numeric_constant_value(Variant::Type p_type, const StringName& p_value);
+ String get_construct_string() const;
+
void operator=(const Variant& p_variant); // only this is enough for all the other types
Variant(const Variant& p_variant);
_FORCE_INLINE_ Variant() { type=NIL; }
diff --git a/core/variant_call.cpp b/core/variant_call.cpp
index 93a9e6475f..3f2800494d 100644
--- a/core/variant_call.cpp
+++ b/core/variant_call.cpp
@@ -757,6 +757,11 @@ static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Var
r_ret=Quat(*p_args[0],*p_args[1],*p_args[2],*p_args[3]);
}
+ static void Quat_init2(Variant& r_ret,const Variant** p_args) {
+
+ r_ret=Quat(((Vector3)(*p_args[0])),((float)(*p_args[1])));
+ }
+
static void Color_init1(Variant& r_ret,const Variant** p_args) {
r_ret=Color(*p_args[0],*p_args[1],*p_args[2],*p_args[3]);
@@ -1509,6 +1514,7 @@ _VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_SCS(#m_method),VCALL(m_cl
_VariantCall::add_constructor(_VariantCall::Plane_init3,Variant::PLANE,"normal",Variant::VECTOR3,"d",Variant::REAL);
_VariantCall::add_constructor(_VariantCall::Quat_init1,Variant::QUAT,"x",Variant::REAL,"y",Variant::REAL,"z",Variant::REAL,"w",Variant::REAL);
+ _VariantCall::add_constructor(_VariantCall::Quat_init2,Variant::QUAT,"axis",Variant::VECTOR3,"angle",Variant::REAL);
_VariantCall::add_constructor(_VariantCall::Color_init1,Variant::COLOR,"r",Variant::REAL,"g",Variant::REAL,"b",Variant::REAL,"a",Variant::REAL);
_VariantCall::add_constructor(_VariantCall::Color_init2,Variant::COLOR,"r",Variant::REAL,"g",Variant::REAL,"b",Variant::REAL);
diff --git a/core/variant_op.cpp b/core/variant_op.cpp
index 9c489c5ef2..ec43b1275c 100644
--- a/core/variant_op.cpp
+++ b/core/variant_op.cpp
@@ -922,21 +922,31 @@ void Variant::set(const Variant& p_index, const Variant& p_value, bool *r_valid)
case REAL: { return; } break;
case STRING: {
- if (p_value.type!=Variant::STRING)
+
+ if (p_index.type!=Variant::INT && p_index.type!=Variant::REAL)
return;
- if (p_index.get_type()==Variant::INT || p_index.get_type()==Variant::REAL) {
- //string index
- int idx=p_index;
- String *str=reinterpret_cast<String*>(_data._mem);
- if (idx >=0 && idx<str->length()) {
- String chr = p_value;
- *str = str->substr(0,idx-1)+chr+str->substr(idx+1,str->length());
- valid=true;
- return;
- }
+ int idx=p_index;
+ String *str=reinterpret_cast<String*>(_data._mem);
+ if (idx <0 || idx>=str->length())
+ return;
+
+ String chr;
+ if (p_value.type==Variant::INT || p_value.type==Variant::REAL) {
+
+ chr = String::chr(p_value);
+ } else if (p_value.type==Variant::STRING) {
+
+ chr = p_value;
+ } else {
+ return;
}
+ *str = str->substr(0,idx-1)+chr+str->substr(idx+1,str->length());
+ valid=true;
+ return;
+
+
} break;
case VECTOR2: {
@@ -951,7 +961,7 @@ void Variant::set(const Variant& p_index, const Variant& p_value, bool *r_valid)
Vector2 *v=reinterpret_cast<Vector2*>(_data._mem);
valid=true;
- v[idx]=p_value;
+ (*v)[idx]=p_value;
return;
}
} else if (p_index.get_type()==Variant::STRING) {
@@ -1045,7 +1055,7 @@ void Variant::set(const Variant& p_index, const Variant& p_value, bool *r_valid)
Vector3 *v=reinterpret_cast<Vector3*>(_data._mem);
valid=true;
- v[idx]=p_value;
+ (*v)[idx]=p_value;
return;
}
} else if (p_index.get_type()==Variant::STRING) {
diff --git a/demos/2d/platformer/player.gd b/demos/2d/platformer/player.gd
index 481f340ab8..b08105212c 100644
--- a/demos/2d/platformer/player.gd
+++ b/demos/2d/platformer/player.gd
@@ -53,12 +53,15 @@ var enemy
func _integrate_forces(s):
+
+
var lv = s.get_linear_velocity()
var step = s.get_step()
var new_anim=anim
var new_siding_left=siding_left
+
# Get the controls
var move_left = Input.is_action_pressed("move_left")
var move_right = Input.is_action_pressed("move_right")
diff --git a/demos/2d/platformer/player.xml b/demos/2d/platformer/player.xml
index c129d01f0d..196881dee4 100644
--- a/demos/2d/platformer/player.xml
+++ b/demos/2d/platformer/player.xml
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<resource_file type="PackedScene" subresource_count="24" version="1.0" version_name="Godot Engine v1.0.3917-beta1">
+<resource_file type="PackedScene" subresource_count="24" version="1.0" version_name="Godot Engine v1.0.rc2.custom_build">
<ext_resource path="res://osb_jump.png" type="Texture"></ext_resource>
<ext_resource path="res://bullet.png" type="Texture"></ext_resource>
<ext_resource path="res://osb_right.png" type="Texture"></ext_resource>
<ext_resource path="res://sound_coin.wav" type="Sample"></ext_resource>
- <ext_resource path="res://sound_shoot.wav" type="Sample"></ext_resource>
<ext_resource path="res://osb_fire.png" type="Texture"></ext_resource>
- <ext_resource path="res://robot_demo.png" type="Texture"></ext_resource>
+ <ext_resource path="res://sound_shoot.wav" type="Sample"></ext_resource>
<ext_resource path="res://osb_left.png" type="Texture"></ext_resource>
+ <ext_resource path="res://robot_demo.png" type="Texture"></ext_resource>
<ext_resource path="res://player.gd" type="Script"></ext_resource>
<ext_resource path="res://sound_jump.wav" type="Sample"></ext_resource>
<resource type="RayShape2D" path="local://1">
@@ -50,8 +50,8 @@
</resource>
<resource type="Animation" path="local://4">
- <string name="resource/name"> "run" </string>
- <real name="length"> 1.25 </real>
+ <string name="resource/name"> "jumping" </string>
+ <real name="length"> 0.5 </real>
<bool name="loop"> True </bool>
<real name="step"> 0.25 </real>
<string name="tracks/0/type"> "value" </string>
@@ -61,24 +61,21 @@
<string> "cont" </string>
<bool> False </bool>
<string> "transitions" </string>
- <real_array len="6"> 1, 1, 1, 1, 1, 1 </real_array>
+ <real_array len="3"> 1, 1, 1 </real_array>
<string> "values" </string>
- <array len="6" shared="false">
- <int> 0 </int>
- <int> 1 </int>
- <int> 2 </int>
- <int> 3 </int>
- <int> 4 </int>
- <int> 0 </int>
+ <array len="3" shared="false">
+ <int> 23 </int>
+ <int> 24 </int>
+ <int> 23 </int>
</array>
<string> "times" </string>
- <real_array len="6"> 0, 0.25, 0.5, 0.75, 1, 1.25 </real_array>
+ <real_array len="3"> 0, 0.25, 0.5 </real_array>
</dictionary>
</resource>
<resource type="Animation" path="local://5">
- <string name="resource/name"> "run_gun_fire" </string>
- <real name="length"> 1.25 </real>
+ <string name="resource/name"> "idle_weapon" </string>
+ <real name="length"> 0.5 </real>
<bool name="loop"> True </bool>
<real name="step"> 0.25 </real>
<string name="tracks/0/type"> "value" </string>
@@ -88,24 +85,18 @@
<string> "cont" </string>
<bool> False </bool>
<string> "transitions" </string>
- <real_array len="6"> 1, 1, 1, 1, 1, 1 </real_array>
+ <real_array len="1"> 1 </real_array>
<string> "values" </string>
- <array len="6" shared="false">
- <int> 10 </int>
- <int> 11 </int>
- <int> 12 </int>
- <int> 13 </int>
- <int> 14 </int>
- <int> 5 </int>
+ <array len="1" shared="false">
+ <int> 25 </int>
</array>
<string> "times" </string>
- <real_array len="6"> 0, 0.25, 0.5, 0.75, 1, 1.25 </real_array>
+ <real_array len="1"> 0 </real_array>
</dictionary>
</resource>
<resource type="Animation" path="local://6">
- <string name="resource/name"> "jumping_weapon" </string>
- <real name="length"> 0.5 </real>
+ <real name="length"> 1.25 </real>
<bool name="loop"> True </bool>
<real name="step"> 0.25 </real>
<string name="tracks/0/type"> "value" </string>
@@ -115,13 +106,18 @@
<string> "cont" </string>
<bool> False </bool>
<string> "transitions" </string>
- <real_array len="1"> 1 </real_array>
+ <real_array len="6"> 1, 1, 1, 1, 1, 1 </real_array>
<string> "values" </string>
- <array len="1" shared="false">
- <int> 26 </int>
+ <array len="6" shared="false">
+ <int> 0 </int>
+ <int> 1 </int>
+ <int> 2 </int>
+ <int> 3 </int>
+ <int> 4 </int>
+ <int> 0 </int>
</array>
<string> "times" </string>
- <real_array len="1"> 0 </real_array>
+ <real_array len="6"> 0, 0.25, 0.5, 0.75, 1, 1.25 </real_array>
</dictionary>
</resource>
@@ -148,8 +144,8 @@
</resource>
<resource type="Animation" path="local://8">
- <string name="resource/name"> "jumping" </string>
- <real name="length"> 0.5 </real>
+ <string name="resource/name"> "falling" </string>
+ <real name="length"> 0.01 </real>
<bool name="loop"> True </bool>
<real name="step"> 0.25 </real>
<string name="tracks/0/type"> "value" </string>
@@ -159,20 +155,17 @@
<string> "cont" </string>
<bool> False </bool>
<string> "transitions" </string>
- <real_array len="3"> 1, 1, 1 </real_array>
+ <real_array len="1"> 1 </real_array>
<string> "values" </string>
- <array len="3" shared="false">
- <int> 23 </int>
- <int> 24 </int>
- <int> 23 </int>
+ <array len="1" shared="false">
+ <int> 21 </int>
</array>
<string> "times" </string>
- <real_array len="3"> 0, 0.25, 0.5 </real_array>
+ <real_array len="1"> 0 </real_array>
</dictionary>
</resource>
<resource type="Animation" path="local://9">
- <string name="resource/name"> "run_weapon" </string>
<real name="length"> 1.25 </real>
<bool name="loop"> True </bool>
<real name="step"> 0.25 </real>
@@ -186,11 +179,11 @@
<real_array len="6"> 1, 1, 1, 1, 1, 1 </real_array>
<string> "values" </string>
<array len="6" shared="false">
- <int> 5 </int>
- <int> 6 </int>
- <int> 7 </int>
- <int> 8 </int>
- <int> 9 </int>
+ <int> 10 </int>
+ <int> 11 </int>
+ <int> 12 </int>
+ <int> 13 </int>
+ <int> 14 </int>
<int> 5 </int>
</array>
<string> "times" </string>
@@ -199,7 +192,7 @@
</resource>
<resource type="Animation" path="local://10">
- <string name="resource/name"> "idle_weapon" </string>
+ <string name="resource/name"> "falling_weapon" </string>
<real name="length"> 0.5 </real>
<bool name="loop"> True </bool>
<real name="step"> 0.25 </real>
@@ -213,7 +206,7 @@
<real_array len="1"> 1 </real_array>
<string> "values" </string>
<array len="1" shared="false">
- <int> 25 </int>
+ <int> 26 </int>
</array>
<string> "times" </string>
<real_array len="1"> 0 </real_array>
@@ -221,8 +214,7 @@
</resource>
<resource type="Animation" path="local://11">
- <string name="resource/name"> "falling_weapon" </string>
- <real name="length"> 0.5 </real>
+ <real name="length"> 1.25 </real>
<bool name="loop"> True </bool>
<real name="step"> 0.25 </real>
<string name="tracks/0/type"> "value" </string>
@@ -232,19 +224,23 @@
<string> "cont" </string>
<bool> False </bool>
<string> "transitions" </string>
- <real_array len="1"> 1 </real_array>
+ <real_array len="6"> 1, 1, 1, 1, 1, 1 </real_array>
<string> "values" </string>
- <array len="1" shared="false">
- <int> 26 </int>
+ <array len="6" shared="false">
+ <int> 5 </int>
+ <int> 6 </int>
+ <int> 7 </int>
+ <int> 8 </int>
+ <int> 9 </int>
+ <int> 5 </int>
</array>
<string> "times" </string>
- <real_array len="1"> 0 </real_array>
+ <real_array len="6"> 0, 0.25, 0.5, 0.75, 1, 1.25 </real_array>
</dictionary>
</resource>
<resource type="Animation" path="local://12">
- <string name="resource/name"> "falling" </string>
- <real name="length"> 0.01 </real>
+ <real name="length"> 0.5 </real>
<bool name="loop"> True </bool>
<real name="step"> 0.25 </real>
<string name="tracks/0/type"> "value" </string>
@@ -257,7 +253,7 @@
<real_array len="1"> 1 </real_array>
<string> "values" </string>
<array len="1" shared="false">
- <int> 21 </int>
+ <int> 26 </int>
</array>
<string> "times" </string>
<real_array len="1"> 0 </real_array>
@@ -294,9 +290,10 @@
<main_resource>
<dictionary name="_bundled" shared="false">
<string> "names" </string>
- <string_array len="170">
+ <string_array len="180">
<string> "player" </string>
<string> "RigidBody2D" </string>
+ <string> "_import_path" </string>
<string> "visibility/visible" </string>
<string> "visibility/opacity" </string>
<string> "visibility/self_opacity" </string>
@@ -311,6 +308,7 @@
<string> "shapes/1/shape" </string>
<string> "shapes/1/transform" </string>
<string> "shapes/1/trigger" </string>
+ <string> "layers" </string>
<string> "mode" </string>
<string> "mass" </string>
<string> "friction" </string>
@@ -319,7 +317,7 @@
<string> "continuous_cd" </string>
<string> "contacts_reported" </string>
<string> "contact_monitor" </string>
- <string> "active" </string>
+ <string> "sleeping" </string>
<string> "can_sleep" </string>
<string> "velocity/linear" </string>
<string> "velocity/angular" </string>
@@ -354,6 +352,8 @@
<string> "config/flip_h" </string>
<string> "config/flip_v" </string>
<string> "config/texture" </string>
+ <string> "config/h_frames" </string>
+ <string> "config/v_frames" </string>
<string> "params/direction" </string>
<string> "params/spread" </string>
<string> "params/linear_velocity" </string>
@@ -364,9 +364,12 @@
<string> "params/radial_accel" </string>
<string> "params/tangential_accel" </string>
<string> "params/damping" </string>
+ <string> "params/initial_angle" </string>
<string> "params/initial_size" </string>
<string> "params/final_size" </string>
<string> "params/hue_variation" </string>
+ <string> "params/anim_speed_scale" </string>
+ <string> "params/anim_initial_pos" </string>
<string> "randomness/direction" </string>
<string> "randomness/spread" </string>
<string> "randomness/linear_velocity" </string>
@@ -377,9 +380,12 @@
<string> "randomness/radial_accel" </string>
<string> "randomness/tangential_accel" </string>
<string> "randomness/damping" </string>
+ <string> "randomness/initial_angle" </string>
<string> "randomness/initial_size" </string>
<string> "randomness/final_size" </string>
<string> "randomness/hue_variation" </string>
+ <string> "randomness/anim_speed_scale" </string>
+ <string> "randomness/anim_initial_pos" </string>
<string> "color_phases/count" </string>
<string> "phase_0/pos" </string>
<string> "phase_0/color" </string>
@@ -396,15 +402,15 @@
<string> "playback/default_blend_time" </string>
<string> "root/root" </string>
<string> "anims/idle" </string>
- <string> "anims/run" </string>
- <string> "anims/standing_weapon_ready" </string>
- <string> "anims/jumping_weapon" </string>
- <string> "anims/crouch" </string>
<string> "anims/jumping" </string>
- <string> "anims/run_weapon" </string>
<string> "anims/idle_weapon" </string>
- <string> "anims/falling_weapon" </string>
+ <string> "anims/run" </string>
+ <string> "anims/crouch" </string>
<string> "anims/falling" </string>
+ <string> "anims/standing_weapon_ready" </string>
+ <string> "anims/falling_weapon" </string>
+ <string> "anims/run_weapon" </string>
+ <string> "anims/jumping_weapon" </string>
<string> "playback/active" </string>
<string> "playback/speed" </string>
<string> "blend_times" </string>
@@ -473,7 +479,8 @@
<string> "node_count" </string>
<int> 14 </int>
<string> "variants" </string>
- <array len="71" shared="false">
+ <array len="72" shared="false">
+ <node_path> "" </node_path>
<bool> True </bool>
<real> 1 </real>
<bool> False </bool>
@@ -485,6 +492,7 @@
<matrix32> 1, -0, 0, 1.76469, 0.291992, -12.1587 </matrix32>
<resource resource_type="Shape2D" path="local://2"> </resource>
<matrix32> 1, -0, 0, 1, 0, 0 </matrix32>
+ <int> 1 </int>
<real> 3 </real>
<int> 0 </int>
<int> 3 </int>
@@ -507,11 +515,17 @@
<bool> False </bool>
<string> "zoom" </string>
<real> 2.272073 </real>
+ <string> "use_snap" </string>
+ <bool> False </bool>
<string> "ofs" </string>
<vector2> -181.946, -86.2812 </vector2>
+ <string> "snap" </string>
+ <int> 10 </int>
</dictionary>
<string> "3D" </string>
<dictionary shared="false">
+ <string> "deflight_rot_y" </string>
+ <real> 0.628319 </real>
<string> "zfar" </string>
<real> 500 </real>
<string> "fov" </string>
@@ -525,10 +539,12 @@
<real> 0 </real>
<string> "y_rot" </string>
<real> 0 </real>
- <string> "use_orthogonal" </string>
- <bool> False </bool>
+ <string> "listener" </string>
+ <bool> True </bool>
<string> "use_environment" </string>
<bool> False </bool>
+ <string> "use_orthogonal" </string>
+ <bool> False </bool>
<string> "pos" </string>
<vector3> 0, 0, 0 </vector3>
</dictionary>
@@ -539,10 +555,12 @@
<real> 0 </real>
<string> "y_rot" </string>
<real> 0 </real>
- <string> "use_orthogonal" </string>
+ <string> "listener" </string>
<bool> False </bool>
<string> "use_environment" </string>
<bool> False </bool>
+ <string> "use_orthogonal" </string>
+ <bool> False </bool>
<string> "pos" </string>
<vector3> 0, 0, 0 </vector3>
</dictionary>
@@ -553,10 +571,12 @@
<real> 0 </real>
<string> "y_rot" </string>
<real> 0 </real>
- <string> "use_orthogonal" </string>
+ <string> "listener" </string>
<bool> False </bool>
<string> "use_environment" </string>
<bool> False </bool>
+ <string> "use_orthogonal" </string>
+ <bool> False </bool>
<string> "pos" </string>
<vector3> 0, 0, 0 </vector3>
</dictionary>
@@ -567,10 +587,12 @@
<real> 0 </real>
<string> "y_rot" </string>
<real> 0 </real>
- <string> "use_orthogonal" </string>
+ <string> "listener" </string>
<bool> False </bool>
<string> "use_environment" </string>
<bool> False </bool>
+ <string> "use_orthogonal" </string>
+ <bool> False </bool>
<string> "pos" </string>
<vector3> 0, 0, 0 </vector3>
</dictionary>
@@ -579,12 +601,18 @@
<int> 1 </int>
<string> "default_light" </string>
<bool> True </bool>
+ <string> "ambient_light_color" </string>
+ <color> 0.15, 0.15, 0.15, 1 </color>
<string> "show_grid" </string>
<bool> True </bool>
<string> "show_origin" </string>
<bool> True </bool>
<string> "znear" </string>
<real> 0.1 </real>
+ <string> "default_srgb" </string>
+ <bool> False </bool>
+ <string> "deflight_rot_x" </string>
+ <real> 0.942478 </real>
</dictionary>
</dictionary>
<string> "__editor_run_settings__" </string>
@@ -595,14 +623,13 @@
<int> 0 </int>
</dictionary>
<string> "__editor_plugin_screen__" </string>
- <string> "3D" </string>
+ <string> "Script" </string>
</dictionary>
<resource resource_type="Texture" path="res://robot_demo.png"> </resource>
<int> 16 </int>
<color> 1, 1, 1, 1 </color>
<rect2> 0, 0, 0, 0 </rect2>
<real> 0.363636 </real>
- <int> 1 </int>
<vector2> 20.7312, 3.21187 </vector2>
<real> 83.450417 </real>
<int> 4 </int>
@@ -654,7 +681,7 @@
<string> "shoot" </string>
</array>
<string> "nodes" </string>
- <int_array len="572"> -1, -1, 1, 0, -1, 28, 2, 0, 3, 1, 4, 1, 5, 2, 6, 3, 7, 4, 8, 5, 9, 6, 10, 7, 11, 8, 12, 2, 13, 9, 14, 10, 15, 2, 16, 6, 17, 11, 18, 4, 19, 4, 20, 0, 21, 12, 22, 13, 23, 2, 24, 0, 25, 0, 26, 3, 27, 4, 28, 14, 29, 15, 0, 0, 0, 31, 30, -1, 18, 2, 0, 3, 1, 4, 1, 5, 2, 6, 3, 7, 4, 8, 5, 32, 16, 33, 0, 34, 3, 35, 2, 36, 2, 37, 6, 38, 17, 39, 12, 40, 18, 41, 2, 42, 19, 0, 1, 0, 44, 43, -1, 57, 2, 0, 3, 1, 4, 20, 5, 2, 45, 21, 6, 22, 7, 23, 8, 5, 46, 24, 47, 25, 48, 1, 49, 4, 50, 25, 51, 2, 52, 3, 53, 3, 54, 2, 55, 26, 56, 2, 57, 2, 58, 27, 59, 4, 60, 28, 61, 29, 62, 1, 63, 4, 64, 4, 65, 30, 66, 4, 67, 4, 68, 4, 69, 31, 70, 31, 71, 4, 72, 4, 73, 4, 74, 4, 75, 31, 76, 4, 77, 4, 78, 4, 79, 4, 80, 4, 81, 4, 82, 4, 83, 4, 84, 4, 85, 6, 86, 4, 87, 18, 88, 1, 89, 32, 90, 1, 91, 33, 92, 1, 93, 34, 94, 35, 0, 0, 0, 96, 95, -1, 17, 97, 21, 98, 4, 99, 36, 100, 37, 101, 38, 102, 39, 103, 40, 104, 41, 105, 42, 106, 43, 107, 44, 108, 45, 109, 46, 110, 0, 111, 31, 112, 47, 113, 48, 0, 0, 0, 115, 114, -1, 22, 2, 0, 3, 1, 4, 1, 5, 2, 6, 3, 7, 4, 8, 5, 33, 0, 116, 2, 117, 0, 118, 4, 119, 5, 120, 12, 121, 12, 122, 49, 123, 49, 124, 0, 125, 0, 126, 50, 127, 50, 128, 50, 129, 50, 0, 0, 0, 131, 130, -1, 7, 2, 0, 3, 1, 4, 1, 5, 2, 6, 51, 7, 4, 8, 5, 0, 0, 0, 132, 132, -1, 9, 2, 0, 3, 1, 4, 1, 5, 2, 6, 52, 7, 4, 8, 53, 133, 7, 134, 2, 0, 0, 0, 136, 135, -1, 14, 137, 13, 138, 54, 139, 4, 140, 1, 141, 4, 142, 4, 143, 4, 144, 55, 145, 55, 146, 55, 147, 55, 148, 6, 149, 4, 150, 4, 0, 0, 0, 151, 151, -1, 9, 2, 0, 3, 1, 4, 1, 5, 2, 6, 3, 7, 4, 8, 5, 152, 12, 153, 56, 0, 0, 0, 155, 154, -1, 4, 156, 12, 34, 3, 157, 4, 158, 5, 0, 9, 0, 160, 159, -1, 13, 2, 0, 3, 1, 4, 1, 5, 2, 6, 57, 7, 4, 8, 58, 161, 59, 162, 60, 163, 60, 164, 0, 165, 61, 166, 21, 0, 9, 0, 160, 167, -1, 13, 2, 0, 3, 1, 4, 1, 5, 2, 6, 62, 7, 4, 8, 58, 161, 63, 162, 60, 163, 60, 164, 0, 165, 64, 166, 21, 0, 9, 0, 160, 168, -1, 13, 2, 0, 3, 1, 4, 1, 5, 2, 6, 65, 7, 4, 8, 58, 161, 66, 162, 60, 163, 60, 164, 2, 165, 67, 166, 21, 0, 9, 0, 160, 169, -1, 13, 2, 0, 3, 1, 4, 1, 5, 2, 6, 68, 7, 4, 8, 58, 161, 69, 162, 60, 163, 60, 164, 2, 165, 70, 166, 21, 0 </int_array>
+ <int_array len="618"> -1, -1, 1, 0, -1, 30, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 7, 4, 8, 5, 9, 6, 10, 7, 11, 8, 12, 9, 13, 3, 14, 10, 15, 11, 16, 3, 17, 12, 18, 7, 19, 13, 20, 5, 21, 5, 22, 1, 23, 14, 24, 15, 25, 3, 26, 3, 27, 1, 28, 4, 29, 5, 30, 16, 31, 17, 0, 0, 0, 33, 32, -1, 19, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 7, 4, 8, 5, 9, 6, 34, 18, 35, 1, 36, 4, 37, 3, 38, 3, 39, 7, 40, 19, 41, 14, 42, 20, 43, 3, 44, 21, 0, 1, 0, 46, 45, -1, 66, 2, 0, 3, 1, 4, 2, 5, 22, 6, 3, 47, 12, 7, 23, 8, 24, 9, 6, 48, 25, 49, 26, 50, 2, 51, 5, 52, 26, 53, 3, 54, 4, 55, 4, 56, 3, 57, 27, 58, 3, 59, 3, 60, 28, 61, 12, 62, 12, 63, 5, 64, 29, 65, 30, 66, 2, 67, 5, 68, 5, 69, 31, 70, 5, 71, 5, 72, 5, 73, 5, 74, 32, 75, 32, 76, 5, 77, 2, 78, 5, 79, 5, 80, 5, 81, 5, 82, 32, 83, 5, 84, 5, 85, 5, 86, 5, 87, 5, 88, 5, 89, 5, 90, 5, 91, 5, 92, 5, 93, 5, 94, 5, 95, 7, 96, 5, 97, 20, 98, 2, 99, 33, 100, 2, 101, 34, 102, 2, 103, 35, 104, 36, 0, 0, 0, 106, 105, -1, 18, 2, 0, 107, 12, 108, 5, 109, 37, 110, 38, 111, 39, 112, 40, 113, 41, 114, 42, 115, 43, 116, 44, 117, 45, 118, 46, 119, 47, 120, 1, 121, 32, 122, 48, 123, 49, 0, 0, 0, 125, 124, -1, 23, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 7, 4, 8, 5, 9, 6, 35, 1, 126, 3, 127, 1, 128, 5, 129, 6, 130, 14, 131, 14, 132, 50, 133, 50, 134, 1, 135, 1, 136, 51, 137, 51, 138, 51, 139, 51, 0, 0, 0, 141, 140, -1, 8, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 7, 52, 8, 5, 9, 6, 0, 0, 0, 142, 142, -1, 10, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 7, 53, 8, 5, 9, 54, 143, 8, 144, 3, 0, 0, 0, 146, 145, -1, 15, 2, 0, 147, 15, 148, 55, 149, 5, 150, 2, 151, 5, 152, 5, 153, 5, 154, 56, 155, 56, 156, 56, 157, 56, 158, 7, 159, 5, 160, 5, 0, 0, 0, 161, 161, -1, 10, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 7, 4, 8, 5, 9, 6, 162, 14, 163, 57, 0, 0, 0, 165, 164, -1, 5, 2, 0, 166, 14, 36, 4, 167, 5, 168, 6, 0, 9, 0, 170, 169, -1, 14, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 7, 58, 8, 5, 9, 59, 171, 60, 172, 61, 173, 61, 174, 1, 175, 62, 176, 12, 0, 9, 0, 170, 177, -1, 14, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 7, 63, 8, 5, 9, 59, 171, 64, 172, 61, 173, 61, 174, 1, 175, 65, 176, 12, 0, 9, 0, 170, 178, -1, 14, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 7, 66, 8, 5, 9, 59, 171, 67, 172, 61, 173, 61, 174, 3, 175, 68, 176, 12, 0, 9, 0, 170, 179, -1, 14, 2, 0, 3, 1, 4, 2, 5, 2, 6, 3, 7, 69, 8, 5, 9, 59, 171, 70, 172, 61, 173, 61, 174, 3, 175, 71, 176, 12, 0 </int_array>
<string> "conns" </string>
<int_array len="0"> </int_array>
</dictionary>
diff --git a/demos/3d/mousepick_test/mousepick.gd b/demos/3d/mousepick_test/mousepick.gd
index cf3d9f1e4e..c96091b650 100644
--- a/demos/3d/mousepick_test/mousepick.gd
+++ b/demos/3d/mousepick_test/mousepick.gd
@@ -9,7 +9,7 @@ var gray_mat = FixedMaterial.new()
var selected=false
-func _input_event(event,pos,normal,shape):
+func _input_event(camera,event,pos,normal,shape):
if (event.type==InputEvent.MOUSE_BUTTON and event.pressed):
if (not selected):
get_node("mesh").set_material_override(gray_mat)
diff --git a/demos/misc/tween/main.gd b/demos/misc/tween/main.gd
index 364651c827..a0106a7682 100644
--- a/demos/misc/tween/main.gd
+++ b/demos/misc/tween/main.gd
@@ -112,8 +112,8 @@ func reset_tween():
tween.interpolate_property(sprite, "transform/rot", 360, 0, 2, state.trans, state.eases, 2)
if get_node("modes/callback").is_pressed():
- tween.interpolate_callback(self, "on_callback", 0.5, "0.5 second's after")
- tween.interpolate_callback(self, "on_callback", 1.2, "1.2 second's after")
+ tween.interpolate_callback(self, 0.5, "on_callback", "0.5 second's after")
+ tween.interpolate_callback(self, 0.2, "on_callback", "1.2 second's after")
if get_node("modes/follow").is_pressed():
follow.show()
diff --git a/drivers/SCsub b/drivers/SCsub
index bfd35344ea..46334468ba 100644
--- a/drivers/SCsub
+++ b/drivers/SCsub
@@ -7,6 +7,7 @@ Export('env')
SConscript('unix/SCsub');
SConscript('alsa/SCsub');
+SConscript('pulseaudio/SCsub');
SConscript('windows/SCsub');
SConscript('gles2/SCsub');
SConscript('gles1/SCsub');
diff --git a/drivers/builtin_openssl2/openssl/md5.h b/drivers/builtin_openssl2/openssl/md5.h
index 8f392f0ec6..765be94335 100644
--- a/drivers/builtin_openssl2/openssl/md5.h
+++ b/drivers/builtin_openssl2/openssl/md5.h
@@ -105,9 +105,9 @@ typedef struct MD5state_st
unsigned int num;
} MD5_CTX;
-#ifdef OPENSSL_FIPS
+//#ifdef OPENSSL_FIPS
int private_MD5_Init(MD5_CTX *c);
-#endif
+//#endif
//#define MD5_Init _SSL_MD5_Init
#define MD5_Final _SSL_MD5_Final
diff --git a/drivers/chibi/cp_loader_s3m.cpp b/drivers/chibi/cp_loader_s3m.cpp
index c5f0830ae6..8b9871463f 100644
--- a/drivers/chibi/cp_loader_s3m.cpp
+++ b/drivers/chibi/cp_loader_s3m.cpp
@@ -162,7 +162,7 @@ CPLoader::Error CPLoader_S3M::load_sample(CPSample *p_sample) {
p_sample->set_default_volume(def_volume);
p_sample->set_name(name);
- char scrs[4];
+ char scrs[5];
file->get_byte_array((uint8_t*)scrs,4);
scrs[4]=0;
diff --git a/drivers/gles1/rasterizer_gles1.cpp b/drivers/gles1/rasterizer_gles1.cpp
index 00fc85c41c..902c105d64 100644
--- a/drivers/gles1/rasterizer_gles1.cpp
+++ b/drivers/gles1/rasterizer_gles1.cpp
@@ -1021,6 +1021,16 @@ void RasterizerGLES1::shader_get_param_list(RID p_shader, List<PropertyInfo> *p_
}
+
+void RasterizerGLES1::shader_set_default_texture_param(RID p_shader, const StringName& p_name, RID p_texture) {
+
+}
+
+RID RasterizerGLES1::shader_get_default_texture_param(RID p_shader, const StringName& p_name) const {
+
+ return RID();
+}
+
/* COMMON MATERIAL API */
diff --git a/drivers/gles1/rasterizer_gles1.h b/drivers/gles1/rasterizer_gles1.h
index 0995089dd7..d3e38f3ded 100644
--- a/drivers/gles1/rasterizer_gles1.h
+++ b/drivers/gles1/rasterizer_gles1.h
@@ -875,6 +875,9 @@ public:
virtual void shader_get_param_list(RID p_shader, List<PropertyInfo> *p_param_list) const;
+ virtual void shader_set_default_texture_param(RID p_shader, const StringName& p_name, RID p_texture);
+ virtual RID shader_get_default_texture_param(RID p_shader, const StringName& p_name) const;
+
/* COMMON MATERIAL API */
virtual RID material_create();
diff --git a/drivers/gles2/rasterizer_gles2.cpp b/drivers/gles2/rasterizer_gles2.cpp
index 9f2fd032fa..2092187431 100644
--- a/drivers/gles2/rasterizer_gles2.cpp
+++ b/drivers/gles2/rasterizer_gles2.cpp
@@ -139,11 +139,13 @@ static _FORCE_INLINE_ uint16_t make_half_float(float f) {
else if (exp <= 0x38000000)
{
- // store a denorm half-float value or zero
+ /*// store a denorm half-float value or zero
exp = (0x38000000 - exp) >> 23;
mantissa >>= (14 + exp);
hf = (((uint16_t)sign) << 15) | (uint16_t)(mantissa);
+ */
+ hf=0; //denormals do not work for 3D, convert to zero
}
else
{
@@ -969,7 +971,7 @@ void RasterizerGLES2::texture_set_data(RID p_texture,const Image& p_image,VS::Cu
- if (img.detect_alpha()==Image::ALPHA_BLEND) {
+ if ((!texture->flags&VS::TEXTURE_FLAG_VIDEO_SURFACE) && img.detect_alpha()==Image::ALPHA_BLEND) {
texture->has_alpha=true;
}
@@ -1539,6 +1541,31 @@ void RasterizerGLES2::shader_get_param_list(RID p_shader, List<PropertyInfo> *p_
}
+void RasterizerGLES2::shader_set_default_texture_param(RID p_shader, const StringName& p_name, RID p_texture) {
+
+ Shader *shader=shader_owner.get(p_shader);
+ ERR_FAIL_COND(!shader);
+ ERR_FAIL_COND(p_texture.is_valid() && !texture_owner.owns(p_texture));
+
+ if (p_texture.is_valid())
+ shader->default_textures[p_name]=p_texture;
+ else
+ shader->default_textures.erase(p_name);
+
+ _shader_make_dirty(shader);
+
+}
+
+RID RasterizerGLES2::shader_get_default_texture_param(RID p_shader, const StringName& p_name) const{
+ const Shader *shader=shader_owner.get(p_shader);
+
+ const Map<StringName,RID>::Element *E=shader->default_textures.find(p_name);
+ if (!E)
+ return RID();
+ return E->get();
+}
+
+
/* COMMON MATERIAL API */
@@ -1581,6 +1608,7 @@ void RasterizerGLES2::material_set_param(RID p_material, const StringName& p_par
material->shader_version=0; //get default!
} else {
E->get().value=p_value;
+ E->get().inuse=true;
}
} else {
@@ -1588,6 +1616,7 @@ void RasterizerGLES2::material_set_param(RID p_material, const StringName& p_par
ud.index=-1;
ud.value=p_value;
ud.istexture=p_value.get_type()==Variant::_RID; /// cache it being texture
+ ud.inuse=true;
material->shader_params[p_param]=ud; //may be got at some point, or erased
}
@@ -1619,7 +1648,7 @@ Variant RasterizerGLES2::material_get_param(RID p_material, const StringName& p_
}
- if (material->shader_params.has(p_param))
+ if (material->shader_params.has(p_param) && material->shader_params[p_param].inuse)
return material->shader_params[p_param].value;
else
return Variant();
@@ -4201,7 +4230,6 @@ void RasterizerGLES2::capture_viewport(Image* r_capture) {
}
w=DVector<uint8_t>::Write();
-
r_capture->create(viewport.width,viewport.height,0,Image::FORMAT_RGBA,pixels);
//r_capture->flip_y();
@@ -4852,31 +4880,46 @@ _FORCE_INLINE_ void RasterizerGLES2::_update_material_shader_params(Material *p_
Material::UniformData ud;
- bool keep=true;
+ bool keep=true; //keep material value
+ bool has_old = old_mparams.has(E->key());
+ bool old_inuse=has_old && old_mparams[E->key()].inuse;
- if (!old_mparams.has(E->key()))
+ if (!has_old || !old_inuse)
keep=false;
else if (old_mparams[E->key()].value.get_type()!=E->value().default_value.get_type()) {
-
- if (old_mparams[E->key()].value.get_type()==Variant::OBJECT) {
+ //type changed between old and new
+ /*if (old_mparams[E->key()].value.get_type()==Variant::OBJECT) {
if (E->value().default_value.get_type()!=Variant::_RID) //hackfor textures
keep=false;
} else if (!old_mparams[E->key()].value.is_num() || !E->value().default_value.get_type())
+ keep=false;*/
+
+ //value is invalid because type differs and default is not null
+ if (E->value().default_value.get_type()!=Variant::NIL)
keep=false;
}
+ ud.istexture=(E->get().type==ShaderLanguage::TYPE_TEXTURE || E->get().type==ShaderLanguage::TYPE_CUBEMAP);
+
if (keep) {
ud.value=old_mparams[E->key()].value;
+
//print_line("KEEP: "+String(E->key()));
} else {
- ud.value=E->value().default_value;
+ if (ud.istexture && p_material->shader_cache->default_textures.has(E->key()))
+ ud.value=p_material->shader_cache->default_textures[E->key()];
+ else
+ ud.value=E->value().default_value;
+ old_inuse=false; //if reverted to default, obviously did not work
+
//print_line("NEW: "+String(E->key())+" because: hasold-"+itos(old_mparams.has(E->key())));
//if (old_mparams.has(E->key()))
// print_line(" told "+Variant::get_type_name(old_mparams[E->key()].value.get_type())+" tnew "+Variant::get_type_name(E->value().default_value.get_type()));
}
- ud.istexture=(E->get().type==ShaderLanguage::TYPE_TEXTURE || E->get().type==ShaderLanguage::TYPE_CUBEMAP);
+
ud.index=idx++;
+ ud.inuse=old_inuse;
mparams[E->key()]=ud;
}
@@ -4991,12 +5034,14 @@ bool RasterizerGLES2::_setup_material(const Geometry *p_geometry,const Material
Texture *t=NULL;
if (rid.is_valid()) {
+
t=texture_owner.get(rid);
- if (!t)
+ if (!t) {
E->get().value=RID(); //nullify, invalid texture
+ rid=RID();
+ }
}
-
glActiveTexture(GL_TEXTURE0+texcoord);
glUniform1i(loc,texcoord); //TODO - this could happen automatically on compile...
if (t) {
@@ -5020,6 +5065,7 @@ bool RasterizerGLES2::_setup_material(const Geometry *p_geometry,const Material
}
+
if (p_material->shader_cache->has_texscreen && framebuffer.active) {
material_shader.set_uniform(MaterialShaderGLES2::TEXSCREEN_SCREEN_MULT,Vector2(float(viewport.width)/framebuffer.width,float(viewport.height)/framebuffer.height));
material_shader.set_uniform(MaterialShaderGLES2::TEXSCREEN_TEX,texcoord);
@@ -8141,8 +8187,18 @@ void RasterizerGLES2::canvas_draw_polygon(int p_vertex_count, const int* p_indic
}
if (p_indices) {
-
+#ifdef GLEW_ENABLED
glDrawElements(GL_TRIANGLES, p_vertex_count, GL_UNSIGNED_INT, p_indices );
+#else
+ static const int _max_draw_poly_indices = 16*1024; // change this size if needed!!!
+ ERR_FAIL_COND(p_vertex_count > _max_draw_poly_indices);
+ static uint16_t _draw_poly_indices[_max_draw_poly_indices];
+ for (int i=0; i<p_vertex_count; i++) {
+ _draw_poly_indices[i] = p_indices[i];
+ };
+ glDrawElements(GL_TRIANGLES, p_vertex_count, GL_UNSIGNED_SHORT, _draw_poly_indices );
+#endif
+ //glDrawElements(GL_TRIANGLES, p_vertex_count, GL_UNSIGNED_INT, p_indices );
} else {
glDrawArrays(GL_TRIANGLES,0,p_vertex_count);
}
diff --git a/drivers/gles2/rasterizer_gles2.h b/drivers/gles2/rasterizer_gles2.h
index 27f7848b13..aa6a4e1f67 100644
--- a/drivers/gles2/rasterizer_gles2.h
+++ b/drivers/gles2/rasterizer_gles2.h
@@ -195,6 +195,7 @@ class RasterizerGLES2 : public Rasterizer {
Map<StringName,ShaderLanguage::Uniform> uniforms;
StringName first_texture;
+ Map<StringName,RID> default_textures;
SelfList<Shader> dirty_list;
@@ -240,8 +241,9 @@ class RasterizerGLES2 : public Rasterizer {
struct UniformData {
+ bool inuse;
bool istexture;
- Variant value;
+ Variant value;
int index;
};
@@ -1255,6 +1257,8 @@ public:
virtual void shader_get_param_list(RID p_shader, List<PropertyInfo> *p_param_list) const;
+ virtual void shader_set_default_texture_param(RID p_shader, const StringName& p_name, RID p_texture);
+ virtual RID shader_get_default_texture_param(RID p_shader, const StringName& p_name) const;
/* COMMON MATERIAL API */
diff --git a/drivers/gles2/shader_compiler_gles2.cpp b/drivers/gles2/shader_compiler_gles2.cpp
index 50b63e1aa0..8eed423b8a 100644
--- a/drivers/gles2/shader_compiler_gles2.cpp
+++ b/drivers/gles2/shader_compiler_gles2.cpp
@@ -131,6 +131,7 @@ String ShaderCompilerGLES2::dump_node_code(SL::Node *p_node,int p_level,bool p_a
SL::BlockNode *bnode=(SL::BlockNode*)p_node;
//variables
+ code+="{"ENDL;
for(Map<StringName,SL::DataType>::Element *E=bnode->variables.front();E;E=E->next()) {
code+=_mktab(p_level)+_typestr(E->value())+" "+replace_string(E->key())+";"ENDL;
@@ -141,6 +142,7 @@ String ShaderCompilerGLES2::dump_node_code(SL::Node *p_node,int p_level,bool p_a
code+=_mktab(p_level)+dump_node_code(bnode->statements[i],p_level)+";"ENDL;
}
+ code+="}"ENDL;
} break;
case SL::Node::TYPE_VARIABLE: {
@@ -676,6 +678,7 @@ ShaderCompilerGLES2::ShaderCompilerGLES2() {
//mode_replace_table[1]["POSITION"]="IN_POSITION";
mode_replace_table[1]["NORMAL"]="normal";
mode_replace_table[1]["TANGENT"]="tangent";
+ mode_replace_table[1]["POSITION"]="gl_Position";
mode_replace_table[1]["BINORMAL"]="binormal";
mode_replace_table[1]["NORMALMAP"]="normalmap";
mode_replace_table[1]["NORMALMAP_DEPTH"]="normaldepth";
diff --git a/drivers/gles2/shaders/material.glsl b/drivers/gles2/shaders/material.glsl
index f2d9eaf1e5..718dd56249 100644
--- a/drivers/gles2/shaders/material.glsl
+++ b/drivers/gles2/shaders/material.glsl
@@ -1230,7 +1230,7 @@ LIGHT_SHADER_CODE
vec3 ambient = const_light_mult*ambient_light*diffuse.rgb;
# if defined(LIGHT_TYPE_OMNI) || defined (LIGHT_TYPE_SPOT)
- ambient*=diffuse_interp.a; //attenuation affects ambient too
+// ambient*=diffuse_interp.a; //attenuation affects ambient too
# endif
diff --git a/drivers/mpc/audio_stream_mpc.cpp b/drivers/mpc/audio_stream_mpc.cpp
index e1f9aacf5f..cd8125c9af 100644
--- a/drivers/mpc/audio_stream_mpc.cpp
+++ b/drivers/mpc/audio_stream_mpc.cpp
@@ -8,6 +8,7 @@ Error AudioStreamMPC::_open_file() {
f=NULL;
}
Error err;
+ //printf("mpc open file %ls\n", file.c_str());
f=FileAccess::open(file,FileAccess::READ,&err);
if (err) {
@@ -16,9 +17,10 @@ Error AudioStreamMPC::_open_file() {
return err;
}
- f->seek_end(0);
- streamlen=f->get_pos();
- f->seek(0);
+ //printf("file size is %i\n", f->get_len());
+ //f->seek_end(0);
+ streamlen=f->get_len();
+ //f->seek(0);
if (streamlen<=0) {
memdelete(f);
f=NULL;
@@ -275,7 +277,7 @@ void AudioStreamMPC::stop() {
}
bool AudioStreamMPC::is_playing() const {
- return active;
+ return active || (get_total() - get_todo() -1 > 0);
}
void AudioStreamMPC::set_paused(bool p_paused) {
diff --git a/drivers/png/pngpriv.h b/drivers/png/pngpriv.h
index 67e486c577..56532f4eeb 100644
--- a/drivers/png/pngpriv.h
+++ b/drivers/png/pngpriv.h
@@ -341,7 +341,11 @@ typedef PNG_CONST png_uint_16p FAR * png_const_uint_16pp;
# ifdef _WINDOWS_ /* Favor Windows over C runtime fns */
# define CVT_PTR(ptr) (ptr)
# define CVT_PTR_NOCHECK(ptr) (ptr)
-# define png_strlen lstrlenA
+# ifdef WINRT_ENABLED
+# define png_strlen strlen
+# else
+# define png_strlen lstrlenA
+# endif
# define png_memcmp memcmp
# define png_memcpy CopyMemory
# define png_memset memset
diff --git a/drivers/pulseaudio/SCsub b/drivers/pulseaudio/SCsub
new file mode 100644
index 0000000000..9fbb467baa
--- /dev/null
+++ b/drivers/pulseaudio/SCsub
@@ -0,0 +1,5 @@
+Import('env')
+
+env.add_source_files(env.drivers_sources,"*.cpp")
+
+Export('env')
diff --git a/drivers/pulseaudio/audio_driver_pulseaudio.cpp b/drivers/pulseaudio/audio_driver_pulseaudio.cpp
new file mode 100644
index 0000000000..dfe9ddc55f
--- /dev/null
+++ b/drivers/pulseaudio/audio_driver_pulseaudio.cpp
@@ -0,0 +1,194 @@
+/*************************************************************************/
+/* audio_driver_alsa.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 "audio_driver_pulseaudio.h"
+
+#ifdef PULSEAUDIO_ENABLED
+
+#include <pulse/error.h>
+
+#include "globals.h"
+
+Error AudioDriverPulseAudio::init() {
+
+ active = false;
+ thread_exited = false;
+ exit_thread = false;
+ pcm_open = false;
+ samples_in = NULL;
+ samples_out = NULL;
+
+ mix_rate = 44100;
+ output_format = OUTPUT_STEREO;
+ channels = 2;
+
+ pa_sample_spec spec;
+ spec.format = PA_SAMPLE_S16LE;
+ spec.channels = channels;
+ spec.rate = mix_rate;
+
+ int error_code;
+ pulse = pa_simple_new(NULL, // default server
+ "Godot", // application name
+ PA_STREAM_PLAYBACK,
+ NULL, // default device
+ "Sound", // stream description
+ &spec,
+ NULL, // use default channel map
+ NULL, // use default buffering attributes
+ &error_code
+ );
+
+ if (pulse == NULL) {
+
+ fprintf(stderr, "PulseAudio ERR: %s\n", pa_strerror(error_code));\
+ ERR_FAIL_COND_V(pulse == NULL, ERR_CANT_OPEN);
+ }
+
+ int latency = GLOBAL_DEF("audio/output_latency", 25);
+ buffer_size = nearest_power_of_2(latency * mix_rate / 1000);
+
+ samples_in = memnew_arr(int32_t, buffer_size * channels);
+ samples_out = memnew_arr(int16_t, buffer_size * channels);
+
+ mutex = Mutex::create();
+ thread = Thread::create(AudioDriverPulseAudio::thread_func, this);
+
+ return OK;
+}
+
+void AudioDriverPulseAudio::thread_func(void* p_udata) {
+
+ AudioDriverPulseAudio* ad = (AudioDriverPulseAudio*)p_udata;
+
+ while (!ad->exit_thread) {
+
+ if (!ad->active) {
+
+ for (unsigned int i=0; i < ad->buffer_size * ad->channels; i++) {
+
+ ad->samples_out[i] = 0;
+ }
+
+ } else {
+
+ ad->lock();
+
+ ad->audio_server_process(ad->buffer_size, ad->samples_in);
+
+ ad->unlock();
+
+ for (unsigned int i=0; i < ad->buffer_size * ad->channels;i ++) {
+
+ ad->samples_out[i] = ad->samples_in[i] >> 16;
+ }
+ }
+
+ // pa_simple_write always consumes the entire buffer
+
+ int error_code;
+ int byte_size = ad->buffer_size * sizeof(int16_t) * ad->channels;
+ if (pa_simple_write(ad->pulse, ad->samples_out, byte_size, &error_code) < 0) {
+
+ // can't recover here
+ fprintf(stderr, "PulseAudio failed and can't recover: %s\n", pa_strerror(error_code));
+ ad->active = false;
+ ad->exit_thread = true;
+ break;
+ }
+ }
+
+ ad->thread_exited = true;
+}
+
+void AudioDriverPulseAudio::start() {
+
+ active = true;
+}
+
+int AudioDriverPulseAudio::get_mix_rate() const {
+
+ return mix_rate;
+}
+
+AudioDriverSW::OutputFormat AudioDriverPulseAudio::get_output_format() const {
+
+ return output_format;
+}
+
+void AudioDriverPulseAudio::lock() {
+
+ if (!thread || !mutex)
+ return;
+ mutex->lock();
+}
+
+void AudioDriverPulseAudio::unlock() {
+
+ if (!thread || !mutex)
+ return;
+ mutex->unlock();
+}
+
+void AudioDriverPulseAudio::finish() {
+
+ if (!thread)
+ return;
+
+ exit_thread = true;
+ Thread::wait_to_finish(thread);
+
+ if (pulse)
+ pa_simple_free(pulse);
+
+ if (samples_in) {
+ memdelete_arr(samples_in);
+ memdelete_arr(samples_out);
+ };
+
+ memdelete(thread);
+ if (mutex) {
+ memdelete(mutex);
+ mutex = NULL;
+ }
+
+ thread = NULL;
+}
+
+AudioDriverPulseAudio::AudioDriverPulseAudio() {
+
+ mutex = NULL;
+ thread = NULL;
+ pulse = NULL;
+}
+
+AudioDriverPulseAudio::~AudioDriverPulseAudio() {
+
+}
+
+#endif
diff --git a/scene/gui/empty_control.h b/drivers/pulseaudio/audio_driver_pulseaudio.h
index 993af45ac4..e82e0c24be 100644
--- a/scene/gui/empty_control.h
+++ b/drivers/pulseaudio/audio_driver_pulseaudio.h
@@ -1,5 +1,5 @@
/*************************************************************************/
-/* empty_control.h */
+/* audio_driver_pulseaudio.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@@ -26,23 +26,54 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#ifndef EMPTY_CONTROL_H
-#define EMPTY_CONTROL_H
-
-#include "scene/gui/control.h"
-
-class EmptyControl : public Control {
-
- OBJ_TYPE(EmptyControl,Control);
- Size2 minsize;
-protected:
- static void _bind_methods();
-public:
- virtual Size2 get_minimum_size() const;
- void set_minsize(const Size2& p_size);
- Size2 get_minsize() const;
-
- EmptyControl();
-};
-
-#endif // EMPTY_CONTROL_H
+#include "servers/audio/audio_server_sw.h"
+
+#ifdef PULSEAUDIO_ENABLED
+
+#include "core/os/thread.h"
+#include "core/os/mutex.h"
+
+#include <pulse/simple.h>
+
+class AudioDriverPulseAudio : public AudioDriverSW {
+
+ Thread* thread;
+ Mutex* mutex;
+
+ pa_simple* pulse;
+
+ int32_t* samples_in;
+ int16_t* samples_out;
+
+ static void thread_func(void* p_udata);
+
+ unsigned int mix_rate;
+ OutputFormat output_format;
+
+ unsigned int buffer_size;
+ int channels;
+
+ bool active;
+ bool thread_exited;
+ mutable bool exit_thread;
+ bool pcm_open;
+
+public:
+
+ const char* get_name() const {
+ return "PulseAudio";
+ };
+
+ virtual Error init();
+ virtual void start();
+ virtual int get_mix_rate() const;
+ virtual OutputFormat get_output_format() const;
+ virtual void lock();
+ virtual void unlock();
+ virtual void finish();
+
+ AudioDriverPulseAudio();
+ ~AudioDriverPulseAudio();
+};
+
+#endif
diff --git a/drivers/theoraplayer/SCsub b/drivers/theoraplayer/SCsub
index d4218debb6..09fb13d8e9 100644
--- a/drivers/theoraplayer/SCsub
+++ b/drivers/theoraplayer/SCsub
@@ -61,13 +61,17 @@ src/YUV/C/yuv420_rgb_c.c
src/TheoraVideoFrame.cpp
""")
+env_theora = env.Clone()
+
if env["platform"] == "iphone":
sources.append("src/AVFoundation/TheoraVideoClip_AVFoundation.mm")
env.Append(LINKFLAGS=['-framework', 'CoreVideo', '-framework', 'CoreMedia', '-framework', 'AVFoundation'])
+ if env["target"] == "release":
+ env_theora.Append(CPPFLAGS=["-D_IOS", "-D__ARM_NEON__", "-fstrict-aliasing", "-fmessage-length=210", "-fdiagnostics-show-note-include-stack", "-fmacro-backtrace-limit=0", "-fcolor-diagnostics", "-Wno-trigraphs", "-fpascal-strings", "-fvisibility=hidden", "-fvisibility-inlines-hidden"])
-env_theora = env.Clone()
-
-env_theora.Append(CPPFLAGS=["-D_YUV_C", "-D_LIB", "-D__THEORA"])
+env_theora.Append(CPPFLAGS=["-D_LIB", "-D__THEORA"]) # removed -D_YUV_C
+env_theora.Append(CPPFLAGS=["-D_YUV_LIBYUV"])
+#env_theora.Append(CPPFLAGS=["-D_YUV_C"])
if env["platform"] == "iphone":
env_theora.Append(CPPFLAGS=["-D__AVFOUNDATION"])
@@ -78,6 +82,9 @@ else:
if env["platform"] == "android":
env_theora.Append(CPPFLAGS=["-D_ANDROID"])
+if env["platform"] == "winrt":
+ env_theora.Append(CPPFLAGS=["-D_WINRT"])
+
env_theora.Append(CPPPATH=["#drivers/theoraplayer/include/theoraplayer", "#drivers/theoraplayer/src/YUV", "#drivers/theoraplayer/src/YUV/libyuv/include", "#drivers/theoraplayer/src/Theora", "#drivers/theoraplayer/src/AVFoundation"])
objs = []
diff --git a/drivers/theoraplayer/src/TheoraVideoClip.cpp b/drivers/theoraplayer/src/TheoraVideoClip.cpp
index ed9f2c22da..16897ee80e 100644
--- a/drivers/theoraplayer/src/TheoraVideoClip.cpp
+++ b/drivers/theoraplayer/src/TheoraVideoClip.cpp
@@ -249,6 +249,7 @@ int TheoraVideoClip::discardOutdatedFrames(float absTime)
if (nPop > 0)
{
+#define _DEBUG
#ifdef _DEBUG
std::string log = getName() + ": dropped frame ";
diff --git a/drivers/theoraplayer/video_stream_theoraplayer.cpp b/drivers/theoraplayer/video_stream_theoraplayer.cpp
index 62dee1336a..9f4a44ae9d 100644
--- a/drivers/theoraplayer/video_stream_theoraplayer.cpp
+++ b/drivers/theoraplayer/video_stream_theoraplayer.cpp
@@ -215,7 +215,7 @@ public:
channels = p_channels;
freq = p_freq;
total_wrote = 0;
- rb_power = 12;
+ rb_power = 22;
rb.resize(rb_power);
};
@@ -258,10 +258,12 @@ public:
void update(float time_increase)
{
+ float prev_time = mTime;
//mTime = (float)(stream->get_total_wrote()) / freq;
//mTime = MAX(0,mTime-AudioServer::get_singleton()->get_output_delay());
//mTime = (float)sample_count / channels / freq;
mTime += time_increase;
+ if (mTime - prev_time > .02) printf("time increase %f secs\n", mTime - prev_time);
//float duration=mClip->getDuration();
//if (mTime > duration) mTime=duration;
//printf("time at timer is %f, %f, samples %i\n", mTime, time_increase, sample_count);
@@ -386,7 +388,7 @@ void VideoStreamTheoraplayer::pop_frame(Ref<ImageTexture> p_tex) {
{
DVector<uint8_t>::Write wr = data.write();
uint8_t* ptr = wr.ptr();
- copymem(ptr, f->getBuffer(), imgsize);
+ memcpy(ptr, f->getBuffer(), imgsize);
}
/*
for (int i=0; i<h; i++) {
diff --git a/drivers/unix/ip_unix.cpp b/drivers/unix/ip_unix.cpp
index c221743457..841160f941 100644
--- a/drivers/unix/ip_unix.cpp
+++ b/drivers/unix/ip_unix.cpp
@@ -28,7 +28,7 @@
/*************************************************************************/
#include "ip_unix.h"
-#if defined(UNIX_ENABLED) || defined(WINDOWS_ENABLED)
+#if defined(UNIX_ENABLED) || defined(WINDOWS_ENABLED) && !defined(WINRT_ENABLED)
#ifdef WINDOWS_ENABLED
diff --git a/drivers/unix/memory_pool_static_malloc.cpp b/drivers/unix/memory_pool_static_malloc.cpp
index fa1266b2df..4711f4f090 100644
--- a/drivers/unix/memory_pool_static_malloc.cpp
+++ b/drivers/unix/memory_pool_static_malloc.cpp
@@ -40,10 +40,9 @@
* so BE CAREFUL!
*/
-
void* MemoryPoolStaticMalloc::alloc(size_t p_bytes,const char *p_description) {
- #if DFAULT_ALIGNMENT == 1
+ #if DEFAULT_ALIGNMENT == 1
return _alloc(p_bytes, p_description);
@@ -123,7 +122,7 @@ void* MemoryPoolStaticMalloc::_alloc(size_t p_bytes,const char *p_description) {
void* MemoryPoolStaticMalloc::realloc(void *p_memory,size_t p_bytes) {
- #if DFAULT_ALIGNMENT == 1
+ #if DEFAULT_ALIGNMENT == 1
return _realloc(p_memory,p_bytes);
#else
@@ -172,7 +171,6 @@ void* MemoryPoolStaticMalloc::_realloc(void *p_memory,size_t p_bytes) {
bool single_element = (ringptr->next == ringptr) && (ringptr->prev == ringptr);
bool is_list = ( ringlist == ringptr );
-
RingPtr *new_ringptr=(RingPtr*)::realloc(ringptr, p_bytes+sizeof(RingPtr));
ERR_FAIL_COND_V( new_ringptr == 0, NULL ); /// reallocation failed
@@ -213,7 +211,7 @@ void MemoryPoolStaticMalloc::free(void *p_ptr) {
ERR_FAIL_COND( !MemoryPoolStatic::get_singleton());
- #if DFAULT_ALIGNMENT == 1
+ #if DEFAULT_ALIGNMENT == 1
_free(p_ptr);
#else
diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp
index e6458068ea..2de975e5d1 100644
--- a/drivers/unix/os_unix.cpp
+++ b/drivers/unix/os_unix.cpp
@@ -332,6 +332,12 @@ Error OS_Unix::execute(const String& p_path, const List<String>& p_arguments,boo
Error OS_Unix::kill(const ProcessID& p_pid) {
int ret = ::kill(p_pid,SIGKILL);
+ if (!ret) {
+ //avoid zombie process
+ int st;
+ ::waitpid(p_pid,&st,0);
+
+ }
return ret?ERR_INVALID_PARAMETER:OK;
}
diff --git a/drivers/vorbis/os.h b/drivers/vorbis/os.h
index 276b4decc7..3df1d194e9 100644
--- a/drivers/vorbis/os.h
+++ b/drivers/vorbis/os.h
@@ -120,7 +120,7 @@ static inline int vorbis_ftoi(double f){ /* yes, double! Otherwise,
/* MSVC inline assembly. 32 bit only; inline ASM isn't implemented in the
* 64 bit compiler */
-#if defined(_MSC_VER) && !defined(_WIN64) && !defined(_WIN32_WCE)
+#if defined(_MSC_VER) && !defined(_WIN64) && !defined(_WIN32_WCE) && !defined(WINDOWSPHONE_ENABLED)
# define VORBIS_FPU_CONTROL
typedef ogg_int16_t vorbis_fpu_control;
diff --git a/drivers/webp/dsp/dsp.h b/drivers/webp/dsp/dsp.h
index 9ff53174d4..afe30413c6 100644
--- a/drivers/webp/dsp/dsp.h
+++ b/drivers/webp/dsp/dsp.h
@@ -33,7 +33,7 @@ extern "C" {
#define WEBP_ANDROID_NEON // Android targets that might support NEON
#endif
-#if (defined(__ARM_NEON__) || defined(WEBP_ANDROID_NEON)) && !defined(PSP2_ENABLED)
+#if ( (defined(__ARM_NEON__) && !defined(__aarch64__)) || defined(WEBP_ANDROID_NEON)) && !defined(PSP2_ENABLED)
#define WEBP_USE_NEON
#endif
diff --git a/drivers/webp/utils/bit_reader.h b/drivers/webp/utils/bit_reader.h
index d80b497149..43cd948fd4 100644
--- a/drivers/webp/utils/bit_reader.h
+++ b/drivers/webp/utils/bit_reader.h
@@ -1,3 +1,4 @@
+//
// Copyright 2010 Google Inc. All Rights Reserved.
//
// This code is licensed under the same terms as WebM:
diff --git a/drivers/windows/dir_access_windows.cpp b/drivers/windows/dir_access_windows.cpp
index df6cc6c5e2..d1e9766105 100644
--- a/drivers/windows/dir_access_windows.cpp
+++ b/drivers/windows/dir_access_windows.cpp
@@ -106,6 +106,7 @@ String DirAccessWindows::get_next() {
return name;
} else {
+#ifndef WINRT_ENABLED
_cisdir=(p->fu.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
String name=p->f.cFileName;
@@ -117,7 +118,8 @@ String DirAccessWindows::get_next() {
}
return name;
-
+#endif
+ return "";
}
}
@@ -358,6 +360,7 @@ bool DirAccessWindows::dir_exists(String p_dir) {
return (fileAttr&FILE_ATTRIBUTE_DIRECTORY);
} else {
+#ifndef WINRT_ENABLED
DWORD fileAttr;
fileAttr = GetFileAttributesExA(p_dir.ascii().get_data(), GetFileExInfoStandard, &fileInfo);
@@ -366,8 +369,8 @@ bool DirAccessWindows::dir_exists(String p_dir) {
return (fileAttr&FILE_ATTRIBUTE_DIRECTORY);
+#endif
}
-
return false;
}
diff --git a/drivers/windows/file_access_windows.cpp b/drivers/windows/file_access_windows.cpp
index 3cd065841f..a6073cbb29 100644
--- a/drivers/windows/file_access_windows.cpp
+++ b/drivers/windows/file_access_windows.cpp
@@ -54,7 +54,6 @@ void FileAccessWindows::check_errors() const {
Error FileAccessWindows::_open(const String& p_filename, int p_mode_flags) {
String filename=fix_path(p_filename);
-
if (f)
close();
diff --git a/main/main.cpp b/main/main.cpp
index 116dbb1d0d..f0e376a045 100644
--- a/main/main.cpp
+++ b/main/main.cpp
@@ -147,6 +147,7 @@ void Main::print_help(const char* p_binary) {
OS::get_singleton()->print(", ");
OS::get_singleton()->print("%s",OS::get_singleton()->get_audio_driver_name(i));
}
+ OS::get_singleton()->print(")\n");
OS::get_singleton()->print("\t-rthread <mode>\t : Render Thread Mode ('unsafe', 'safe', 'separate).");
OS::get_singleton()->print(")\n");
OS::get_singleton()->print("\t-s,-script [script] : Run a script.\n");
diff --git a/makefile b/makefile
deleted file mode 100644
index d24bd0cd32..0000000000
--- a/makefile
+++ /dev/null
@@ -1,30 +0,0 @@
-#*************************************************************************/
-#* This file is part of: */
-#* GODOT ENGINE */
-#* http://www.godotengine.org */
-#*************************************************************************/
-# Simple makefile to give support for external C/C++ IDEs */
-#*************************************************************************/
-
-# Default build
-all: debug
-
-# Release Build
-release:
- scons target="release" bin/godot
-
-# Profile Build
-profile:
- scons target="profile" bin/godot
-
-# Debug Build
-debug:
- # Debug information (code size gets severely affected):
- # g: Default (same as g2)
- # g0: no debug info
- # g1: minimal info
- # g3: maximal info
- scons target="debug" CCFLAGS="-g" bin/godot
-
-clean:
- scons -c bin/godot
diff --git a/modules/gdscript/gd_compiler.cpp b/modules/gdscript/gd_compiler.cpp
index 5595db95de..278651d642 100644
--- a/modules/gdscript/gd_compiler.cpp
+++ b/modules/gdscript/gd_compiler.cpp
@@ -45,8 +45,13 @@ void GDCompiler::_set_error(const String& p_error,const GDParser::Node *p_node)
return;
error=p_error;
- err_line=p_node->line;
- err_column=p_node->column;
+ if (p_node) {
+ err_line=p_node->line;
+ err_column=p_node->column;
+ } else {
+ err_line=0;
+ err_column=0;
+ }
}
bool GDCompiler::_create_unary_operator(CodeGen& codegen,const GDParser::OperatorNode *on,Variant::Operator op, int p_stack_level) {
@@ -523,7 +528,7 @@ int GDCompiler::_parse_expression(CodeGen& codegen,const GDParser::Node *p_expre
int ret = _parse_expression(codegen,on->arguments[i],slevel);
if (ret<0)
return ret;
- if (ret&GDFunction::ADDR_TYPE_STACK<<GDFunction::ADDR_BITS) {
+ if (ret&(GDFunction::ADDR_TYPE_STACK<<GDFunction::ADDR_BITS)) {
slevel++;
codegen.alloc_stack(slevel);
}
@@ -1168,6 +1173,7 @@ Error GDCompiler::_parse_function(GDScript *p_script,const GDParser::ClassNode *
codegen.current_line=0;
codegen.call_max=0;
codegen.debug_stack=ScriptDebugger::get_singleton()!=NULL;
+ Vector<StringName> argnames;
int stack_level=0;
@@ -1175,6 +1181,9 @@ Error GDCompiler::_parse_function(GDScript *p_script,const GDParser::ClassNode *
for(int i=0;i<p_func->arguments.size();i++) {
int idx = i;
codegen.add_stack_identifier(p_func->arguments[i],i);
+#ifdef TOOLS_ENABLED
+ argnames.push_back(p_func->arguments[i]);
+#endif
}
stack_level=p_func->arguments.size();
}
@@ -1249,6 +1258,9 @@ Error GDCompiler::_parse_function(GDScript *p_script,const GDParser::ClassNode *
if (p_func)
gdfunc->_static=p_func->_static;
+#ifdef TOOLS_ENABLED
+ gdfunc->arg_names=argnames;
+#endif
//constants
if (codegen.constant_map.size()) {
gdfunc->_constant_count=codegen.constant_map.size();
@@ -1515,7 +1527,7 @@ Error GDCompiler::_parse_class(GDScript *p_script,GDScript *p_owner,const GDPars
GDScript::MemberInfo minfo;
minfo.index = p_script->member_indices.size();
minfo.setter = p_class->variables[i].setter;
- minfo.getter = p_class->variables[i].getter;
+ minfo.getter = p_class->variables[i].getter;
p_script->member_indices[name]=minfo;
p_script->members.insert(name);
@@ -1579,6 +1591,48 @@ Error GDCompiler::_parse_class(GDScript *p_script,GDScript *p_owner,const GDPars
return err;
}
+#ifdef DEBUG_ENABLED
+ //validate setters/getters if debug is enabled
+ for(int i=0;i<p_class->variables.size();i++) {
+
+ if (p_class->variables[i].setter) {
+ const Map<StringName,GDFunction>::Element *E=p_script->get_member_functions().find(p_class->variables[i].setter);
+ if (!E) {
+ _set_error("Setter function '"+String(p_class->variables[i].setter)+"' not found in class.",NULL);
+ err_line=p_class->variables[i].line;
+ err_column=0;
+ return ERR_PARSE_ERROR;
+ }
+
+ if (E->get().is_static()) {
+
+ _set_error("Setter function '"+String(p_class->variables[i].setter)+"' is static.",NULL);
+ err_line=p_class->variables[i].line;
+ err_column=0;
+ return ERR_PARSE_ERROR;
+ }
+
+ }
+ if (p_class->variables[i].getter) {
+ const Map<StringName,GDFunction>::Element *E=p_script->get_member_functions().find(p_class->variables[i].getter);
+ if (!E) {
+ _set_error("Getter function '"+String(p_class->variables[i].getter)+"' not found in class.",NULL);
+ err_line=p_class->variables[i].line;
+ err_column=0;
+ return ERR_PARSE_ERROR;
+ }
+
+ if (E->get().is_static()) {
+
+ _set_error("Getter function '"+String(p_class->variables[i].getter)+"' is static.",NULL);
+ err_line=p_class->variables[i].line;
+ err_column=0;
+ return ERR_PARSE_ERROR;
+ }
+
+ }
+ }
+#endif
return OK;
}
diff --git a/modules/gdscript/gd_editor.cpp b/modules/gdscript/gd_editor.cpp
index 546fed4e8a..12dc1bb139 100644
--- a/modules/gdscript/gd_editor.cpp
+++ b/modules/gdscript/gd_editor.cpp
@@ -28,7 +28,7 @@
/*************************************************************************/
#include "gd_script.h"
#include "gd_compiler.h"
-
+#include "globals.h"
void GDScriptLanguage::get_comment_delimiters(List<String> *p_delimiters) const {
@@ -312,171 +312,278 @@ String GDScriptLanguage::make_function(const String& p_class,const String& p_nam
}
-static void _parse_native_symbols(const StringName& p_native,bool p_static,List<String>* r_options) {
+#if defined(DEBUG_METHODS_ENABLED) && defined(TOOLS_ENABLED)
- if (!p_static) {
- List<MethodInfo> methods;
- ObjectTypeDB::get_method_list(p_native,&methods);
- for(List<MethodInfo>::Element *E=methods.front();E;E=E->next()) {
- if (!E->get().name.begins_with("_")) {
- r_options->push_back(E->get().name);
- }
+struct GDCompletionIdentifier {
+
+ StringName obj_type;
+ Variant::Type type;
+ Variant value; //im case there is a value, also return it
+};
+
+
+
+static GDCompletionIdentifier _get_type_from_variant(const Variant& p_variant) {
+
+ GDCompletionIdentifier t;
+ t.type=p_variant.get_type();
+ t.value=p_variant;
+ if (p_variant.get_type()==Variant::OBJECT) {
+ Object *obj = p_variant;
+ if (obj) {
+ //if (obj->cast_to<GDNativeClass>()) {
+ // t.obj_type=obj->cast_to<GDNativeClass>()->get_name();
+ // t.value=Variant();
+ //} else {
+ t.obj_type=obj->get_type();
+ //}
}
}
+ return t;
+}
- List<String> constants;
- ObjectTypeDB::get_integer_constant_list(p_native,&constants);
+static GDCompletionIdentifier _get_type_from_pinfo(const PropertyInfo& p_info) {
- for(List<String>::Element *E=constants.front();E;E=E->next()) {
- r_options->push_back(E->get());
+ GDCompletionIdentifier t;
+ t.type=p_info.type;
+ if (p_info.hint==PROPERTY_HINT_RESOURCE_TYPE) {
+ t.obj_type=p_info.hint_string;
}
-
+ return t;
}
+struct GDCompletionContext {
-static bool _parse_script_symbols(const Ref<GDScript>& p_script,bool p_static,List<String>* r_options,List<String>::Element *p_indices);
+ const GDParser::ClassNode *_class;
+ const GDParser::FunctionNode *function;
+ const GDParser::BlockNode *block;
+ Object* base;
+ String base_path;
+};
-static bool _parse_completion_variant(const Variant& p_var,List<String>* r_options,List<String>::Element *p_indices) {
- if (p_indices) {
+static Ref<Reference> _get_parent_class(GDCompletionContext& context) {
- bool ok;
- Variant si = p_var.get(p_indices->get(),&ok);
- if (!ok)
- return false;
- return _parse_completion_variant(si,r_options,p_indices->next());
- } else {
- switch(p_var.get_type()) {
+ if (context._class->extends_used) {
+ //do inheritance
+ String path = context._class->extends_file;
- case Variant::DICTIONARY: {
+ Ref<GDScript> script;
+ Ref<GDNativeClass> native;
- Dictionary d=p_var;
- List<Variant> vl;
- d.get_key_list(&vl);
- for (List<Variant>::Element *E=vl.front();E;E=E->next()) {
+ if (path!="") {
+ //path (and optionally subclasses)
- if (E->get().get_type()==Variant::STRING)
- r_options->push_back(E->get());
- }
+ if (path.is_rel_path()) {
+ path=context.base_path.plus_file(path);
+ }
+ script = ResourceLoader::load(path);
+ if (script.is_null()) {
+ return REF();
+ }
+ if (script->is_valid()) {
- List<MethodInfo> ml;
- p_var.get_method_list(&ml);
- for(List<MethodInfo>::Element *E=ml.front();E;E=E->next()) {
- r_options->push_back(E->get().name);
+ return REF();
+ }
+ //print_line("EXTENDS PATH: "+path+" script is "+itos(script.is_valid())+" indices is "+itos(script->member_indices.size())+" valid? "+itos(script->valid));
+
+ if (context._class->extends_class.size()) {
+
+ for(int i=0;i<context._class->extends_class.size();i++) {
+
+ String sub = context._class->extends_class[i];
+ if (script->get_subclasses().has(sub)) {
+
+ script=script->get_subclasses()[sub];
+ } else {
+
+ return REF();
+ }
}
+ }
- } break;
- case Variant::OBJECT: {
+ if (script.is_valid())
+ return script;
+
+ } else {
+ if (context._class->extends_class.size()==0) {
+ ERR_PRINT("BUG");
+ return REF();
+ }
+
+ String base=context._class->extends_class[0];
+ const GDParser::ClassNode *p = context._class->owner;
+ Ref<GDScript> base_class;
+#if 0
+ while(p) {
+
+ if (p->subclasses.has(base)) {
+
+ base_class=p->subclasses[base];
+ break;
+ }
+ p=p->_owner;
+ }
+#endif
+ if (base_class.is_valid()) {
+#if 0
+ for(int i=1;i<context._class->extends_class.size();i++) {
- Object *o=p_var;
- if (o) {
- print_line("OBJECT: "+o->get_type());
- if (p_var.is_ref() && o->cast_to<GDScript>()) {
+ String subclass=context._class->extends_class[i];
- Ref<GDScript> gds = p_var;
- _parse_script_symbols(gds,true,r_options,NULL);
- } else if (o->is_type("GDNativeClass")){
+ if (base_class->subclasses.has(subclass)) {
- GDNativeClass *gnc = o->cast_to<GDNativeClass>();
- _parse_native_symbols(gnc->get_name(),false,r_options);
+ base_class=base_class->subclasses[subclass];
} else {
- print_line("REGULAR BLEND");
- _parse_native_symbols(o->get_type(),false,r_options);
+ print_line("Could not find subclass: "+subclass);
+ return _get_type_from_class(context); //fail please
}
}
- } break;
- default: {
+ script=base_class;
+#endif
+
+ } else {
+
+ if (context._class->extends_class.size()>1) {
+
+ return REF();
+
- List<PropertyInfo> pi;
- p_var.get_property_list(&pi);
- for(List<PropertyInfo>::Element *E=pi.front();E;E=E->next()) {
- r_options->push_back(E->get().name);
}
- List<StringName> cl;
+ //if not found, try engine classes
+ if (!GDScriptLanguage::get_singleton()->get_global_map().has(base)) {
- p_var.get_numeric_constants_for_type(p_var.get_type(),&cl);
- for(List<StringName>::Element *E=cl.front();E;E=E->next()) {
- r_options->push_back(E->get());
+ return REF();
}
- List<MethodInfo> ml;
- p_var.get_method_list(&ml);
- for(List<MethodInfo>::Element *E=ml.front();E;E=E->next()) {
- r_options->push_back(E->get().name);
+ int base_idx = GDScriptLanguage::get_singleton()->get_global_map()[base];
+ native = GDScriptLanguage::get_singleton()->get_global_array()[base_idx];
+ if (!native.is_valid()) {
+
+ print_line("Global not a class: '"+base+"'");
+
}
+ return native;
+ }
+
- } break;
}
- return true;
}
-
+ return Ref<Reference>();
}
-struct GDCompletionIdentifier {
- StringName obj_type;
- Variant::Type type;
-};
+static GDCompletionIdentifier _get_native_class(GDCompletionContext& context) {
+ //eeh...
+ GDCompletionIdentifier id;
+ id.type=Variant::NIL;
-static GDCompletionIdentifier _guess_identifier_type(const GDParser::ClassNode *p_class,int p_line,const StringName& p_identifier);
+ REF pc = _get_parent_class(context);
+ if (!pc.is_valid()) {
+ return id;
+ }
+ Ref<GDNativeClass> nc = pc;
+ Ref<GDScript> s = pc;
+ if (s.is_null() && nc.is_null()) {
+ return id;
+ }
+ while(!s.is_null()) {
+ nc=s->get_native();
+ s=s->get_base();
+ }
+ if (nc.is_null()) {
+ return id;
+ }
+
+
+
+ id.type=Variant::OBJECT;
+ if (context.base)
+ id.value=context.base;
+ id.obj_type=nc->get_name();
+ return id;
+}
-static bool _guess_identifier_type_in_expression(const GDParser::ClassNode *p_class,const GDParser::Node *p_node,int p_line,GDCompletionIdentifier &r_type) {
+static bool _guess_identifier_type(GDCompletionContext& context,int p_line,const StringName& p_identifier,GDCompletionIdentifier &r_type);
+
+
+static bool _guess_expression_type(GDCompletionContext& context,const GDParser::Node* p_node,int p_line,GDCompletionIdentifier &r_type) {
if (p_node->type==GDParser::Node::TYPE_CONSTANT) {
const GDParser::ConstantNode *cn=static_cast<const GDParser::ConstantNode *>(p_node);
- r_type.type=cn->value.get_type();
- if (r_type.type==Variant::OBJECT) {
- Object *obj = cn->value;
- if (obj) {
- r_type.obj_type=obj->get_type();
- }
- }
+ r_type=_get_type_from_variant(cn->value);
return true;
} else if (p_node->type==GDParser::Node::TYPE_DICTIONARY) {
r_type.type=Variant::DICTIONARY;
+
+
+ //what the heck, fill it anyway
+ const GDParser::DictionaryNode *an = static_cast<const GDParser::DictionaryNode *>(p_node);
+ Dictionary d;
+ for(int i=0;i<an->elements.size();i++) {
+ GDCompletionIdentifier k;
+ if (_guess_expression_type(context,an->elements[i].key,p_line,k) && k.value.get_type()!=Variant::NIL) {
+ GDCompletionIdentifier v;
+ if (_guess_expression_type(context,an->elements[i].value,p_line,v)) {
+ d[k.value]=v.value;
+ }
+
+ }
+ }
+ r_type.value=d;
return true;
} else if (p_node->type==GDParser::Node::TYPE_ARRAY) {
r_type.type=Variant::ARRAY;
+ //what the heck, fill it anyway
+ const GDParser::ArrayNode *an = static_cast<const GDParser::ArrayNode *>(p_node);
+ Array arr;
+ arr.resize(an->elements.size());
+ for(int i=0;i<an->elements.size();i++) {
+ GDCompletionIdentifier ci;
+ if (_guess_expression_type(context,an->elements[i],p_line,ci)) {
+ arr[i]=ci.value;
+ }
+ }
+ r_type.value=arr;
return true;
} else if (p_node->type==GDParser::Node::TYPE_BUILT_IN_FUNCTION) {
MethodInfo mi = GDFunctions::get_info(static_cast<const GDParser::BuiltInFunctionNode*>(p_node)->function);
- r_type.type=mi.return_val.type;
- if (mi.return_val.hint==PROPERTY_HINT_RESOURCE_TYPE) {
- r_type.obj_type=mi.return_val.hint_string;
- }
+ r_type=_get_type_from_pinfo(mi.return_val);
+
return true;
} else if (p_node->type==GDParser::Node::TYPE_IDENTIFIER) {
-
- r_type=_guess_identifier_type(p_class,p_line,static_cast<const GDParser::IdentifierNode *>(p_node)->name);
- return true;
+ return _guess_identifier_type(context,p_line-1,static_cast<const GDParser::IdentifierNode *>(p_node)->name,r_type);
} else if (p_node->type==GDParser::Node::TYPE_SELF) {
//eeh...
- return false;
+
+ r_type=_get_native_class(context);
+ return r_type.type!=Variant::NIL;
} else if (p_node->type==GDParser::Node::TYPE_OPERATOR) {
+
+
const GDParser::OperatorNode *op = static_cast<const GDParser::OperatorNode *>(p_node);
if (op->op==GDParser::OperatorNode::OP_CALL) {
-
if (op->arguments[0]->type==GDParser::Node::TYPE_TYPE) {
const GDParser::TypeNode *tn = static_cast<const GDParser::TypeNode *>(op->arguments[0]);
@@ -486,25 +593,86 @@ static bool _guess_identifier_type_in_expression(const GDParser::ClassNode *p_cl
const GDParser::BuiltInFunctionNode *bin = static_cast<const GDParser::BuiltInFunctionNode *>(op->arguments[0]);
- return _guess_identifier_type_in_expression(p_class,bin,p_line,r_type);
+ return _guess_expression_type(context,bin,p_line,r_type);
} else if (op->arguments.size()>1 && op->arguments[1]->type==GDParser::Node::TYPE_IDENTIFIER) {
+
GDCompletionIdentifier base;
- if (!_guess_identifier_type_in_expression(p_class,op->arguments[0],p_line,base))
+ if (!_guess_expression_type(context,op->arguments[0],p_line,base))
return false;
- StringName id = static_cast<const GDParser::IdentifierNode *>(p_node)->name;
+
+ StringName id = static_cast<const GDParser::IdentifierNode *>(op->arguments[1])->name;
+
if (base.type==Variant::OBJECT) {
+ if (id.operator String()=="new" && base.value.get_type()==Variant::OBJECT) {
+ Object *obj = base.value;
+ if (obj && obj->cast_to<GDNativeClass>()) {
+ GDNativeClass *gdnc = obj->cast_to<GDNativeClass>();
+ r_type.type=Variant::OBJECT;
+ r_type.value=Variant();
+ r_type.obj_type=gdnc->get_name();
+ return true;
+ }
+ }
+
if (ObjectTypeDB::has_method(base.obj_type,id)) {
+
#ifdef TOOLS_ENABLED
MethodBind *mb = ObjectTypeDB::get_method(base.obj_type,id);
PropertyInfo pi = mb->get_argument_info(-1);
+ //try calling the function if constant and all args are constant, should not crash..
+ Object *baseptr = base.value;
+
+ if (baseptr && mb->is_const() && pi.type==Variant::OBJECT) {
+ bool all_valid=true;
+ Vector<Variant> args;
+ for(int i=2;i<op->arguments.size();i++) {
+ GDCompletionIdentifier arg;
+
+ if (_guess_expression_type(context,op->arguments[i],p_line,arg)) {
+ if (arg.value.get_type()!=Variant::NIL && arg.value.get_type()!=Variant::OBJECT) { // calling with object seems dangerous, i don' t know
+ args.push_back(arg.value);
+ } else {
+ all_valid=false;
+ break;
+ }
+ } else {
+ all_valid=false;
+ }
+ }
+ if (all_valid) {
+ Vector<const Variant*> argptr;
+ for(int i=0;i<args.size();i++) {
+ argptr.push_back(&args[i]);
+ }
+
+ Variant::CallError ce;
+ Variant ret=mb->call(baseptr,argptr.ptr(),argptr.size(),ce);
+
+
+ if (ce.error==Variant::CallError::CALL_OK && ret.get_type()!=Variant::NIL) {
+
+ if (ret.get_type()!=Variant::OBJECT || ret.operator Object*()!=NULL) {
+
+ r_type=_get_type_from_variant(ret);
+ return true;
+ }
+ }
+
+ }
+ }
+
r_type.type=pi.type;
if (pi.hint==PROPERTY_HINT_RESOURCE_TYPE) {
r_type.obj_type=pi.hint_string;
}
+
+
+
+ return true;
#else
return false;
#endif
@@ -519,7 +687,8 @@ static bool _guess_identifier_type_in_expression(const GDParser::ClassNode *p_cl
v.get_method_list(&mi);
for (List<MethodInfo>::Element *E=mi.front();E;E=E->next()) {
- if (E->get().name==id.operator String()) {
+ if (!E->get().name.begins_with("_") && E->get().name==id.operator String()) {
+
MethodInfo mi = E->get();
r_type.type=mi.return_val.type;
@@ -534,49 +703,157 @@ static bool _guess_identifier_type_in_expression(const GDParser::ClassNode *p_cl
}
+ } else if (op->op==GDParser::OperatorNode::OP_INDEX || op->op==GDParser::OperatorNode::OP_INDEX_NAMED) {
+
+ GDCompletionIdentifier p1;
+ GDCompletionIdentifier p2;
+
+
+
+ if (op->op==GDParser::OperatorNode::OP_INDEX_NAMED) {
+
+ if (op->arguments[1]->type==GDParser::Node::TYPE_IDENTIFIER) {
+ String id = static_cast<const GDParser::IdentifierNode*>(op->arguments[1])->name;
+ p2.type=Variant::STRING;
+ p2.value=id;
+ }
+
+ } else {
+ if (op->arguments[1]) {
+ if (!_guess_expression_type(context,op->arguments[1],p_line,p2)) {
+
+ return false;
+ }
+ }
+ }
+
+ if (op->arguments[0]->type==GDParser::Node::TYPE_ARRAY) {
+
+ const GDParser::ArrayNode *an = static_cast<const GDParser::ArrayNode *>(op->arguments[0]);
+ if (p2.value.is_num()) {
+ int index = p2.value;
+ if (index<0 || index>=an->elements.size())
+ return false;
+ return _guess_expression_type(context,an->elements[index],p_line,r_type);
+ }
+
+ } else if (op->arguments[0]->type==GDParser::Node::TYPE_DICTIONARY) {
+
+ const GDParser::DictionaryNode *dn = static_cast<const GDParser::DictionaryNode *>(op->arguments[0]);
+
+ if (p2.value.get_type()==Variant::NIL)
+ return false;
+
+ for(int i=0;i<dn->elements.size();i++) {
+
+ GDCompletionIdentifier k;
+
+ if (!_guess_expression_type(context,dn->elements[i].key,p_line,k)) {
+
+ return false;
+ }
+
+ if (k.value.get_type()==Variant::NIL)
+ return false;
+
+ if (k.value==p2.value) {
+
+ return _guess_expression_type(context,dn->elements[i].value,p_line,r_type);
+ }
+ }
+
+ } else {
+
+ if (op->arguments[0]) {
+ if (!_guess_expression_type(context,op->arguments[0],p_line,p1)) {
+
+ return false;
+ }
+
+ }
+
+ if (p1.value.get_type()==Variant::OBJECT) {
+ //??
+ } else if (p1.value.get_type()!=Variant::NIL) {
+
+ bool valid;
+ Variant ret = p1.value.get(p2.value,&valid);
+ if (valid) {
+ r_type=_get_type_from_variant(ret);
+ return true;
+ }
+
+ } else {
+ if (p1.type!=Variant::NIL) {
+ Variant::CallError ce;
+ Variant base = Variant::construct(p1.type,NULL,0,ce);
+ bool valid;
+ Variant ret = base.get(p2.value,&valid);
+ if (valid) {
+ r_type=_get_type_from_variant(ret);
+ return true;
+ }
+ }
+ }
+ }
+
} else {
+
Variant::Operator vop = Variant::OP_MAX;
switch(op->op) {
- case GDParser::OperatorNode::OP_ASSIGN_ADD: vop=Variant::OP_ADD; break;
- case GDParser::OperatorNode::OP_ASSIGN_SUB: vop=Variant::OP_SUBSTRACT; break;
- case GDParser::OperatorNode::OP_ASSIGN_MUL: vop=Variant::OP_MULTIPLY; break;
- case GDParser::OperatorNode::OP_ASSIGN_DIV: vop=Variant::OP_DIVIDE; break;
- case GDParser::OperatorNode::OP_ASSIGN_MOD: vop=Variant::OP_MODULE; break;
- case GDParser::OperatorNode::OP_ASSIGN_SHIFT_LEFT: vop=Variant::OP_SHIFT_LEFT; break;
- case GDParser::OperatorNode::OP_ASSIGN_SHIFT_RIGHT: vop=Variant::OP_SHIFT_RIGHT; break;
- case GDParser::OperatorNode::OP_ASSIGN_BIT_AND: vop=Variant::OP_BIT_AND; break;
- case GDParser::OperatorNode::OP_ASSIGN_BIT_OR: vop=Variant::OP_BIT_OR; break;
- case GDParser::OperatorNode::OP_ASSIGN_BIT_XOR: vop=Variant::OP_BIT_XOR; break;
+ case GDParser::OperatorNode::OP_ADD: vop=Variant::OP_ADD; break;
+ case GDParser::OperatorNode::OP_SUB: vop=Variant::OP_SUBSTRACT; break;
+ case GDParser::OperatorNode::OP_MUL: vop=Variant::OP_MULTIPLY; break;
+ case GDParser::OperatorNode::OP_DIV: vop=Variant::OP_DIVIDE; break;
+ case GDParser::OperatorNode::OP_MOD: vop=Variant::OP_MODULE; break;
+ case GDParser::OperatorNode::OP_SHIFT_LEFT: vop=Variant::OP_SHIFT_LEFT; break;
+ case GDParser::OperatorNode::OP_SHIFT_RIGHT: vop=Variant::OP_SHIFT_RIGHT; break;
+ case GDParser::OperatorNode::OP_BIT_AND: vop=Variant::OP_BIT_AND; break;
+ case GDParser::OperatorNode::OP_BIT_OR: vop=Variant::OP_BIT_OR; break;
+ case GDParser::OperatorNode::OP_BIT_XOR: vop=Variant::OP_BIT_XOR; break;
default:{}
}
+
+
if (vop==Variant::OP_MAX)
return false;
+
+
GDCompletionIdentifier p1;
GDCompletionIdentifier p2;
if (op->arguments[0]) {
- if (!_guess_identifier_type_in_expression(p_class,op->arguments[0],p_line,p1))
+ if (!_guess_expression_type(context,op->arguments[0],p_line,p1)) {
+
return false;
+ }
+
}
if (op->arguments.size()>1) {
- if (!_guess_identifier_type_in_expression(p_class,op->arguments[1],p_line,p2))
+ if (!_guess_expression_type(context,op->arguments[1],p_line,p2)) {
+
return false;
+ }
}
Variant::CallError ce;
- Variant v1 = Variant::construct(p1.type,NULL,0,ce);
- Variant v2 = Variant::construct(p2.type,NULL,0,ce);
+ bool v1_use_value = p1.value.get_type()!=Variant::NIL && p1.value.get_type()!=Variant::OBJECT;
+ Variant v1 = (v1_use_value)?p1.value:Variant::construct(p1.type,NULL,0,ce);
+ bool v2_use_value = p2.value.get_type()!=Variant::NIL && p2.value.get_type()!=Variant::OBJECT;
+ Variant v2 = (v2_use_value)?p2.value:Variant::construct(p2.type,NULL,0,ce);
// avoid potential invalid ops
if ((vop==Variant::OP_DIVIDE || vop==Variant::OP_MODULE) && v2.get_type()==Variant::INT) {
v2=1;
+ v2_use_value=false;
}
if (vop==Variant::OP_DIVIDE && v2.get_type()==Variant::REAL) {
v2=1.0;
+ v2_use_value=false;
}
Variant r;
@@ -585,6 +862,9 @@ static bool _guess_identifier_type_in_expression(const GDParser::ClassNode *p_cl
if (!valid)
return false;
r_type.type=r.get_type();
+ if (v1_use_value && v2_use_value)
+ r_type.value=r;
+
return true;
}
@@ -594,46 +874,42 @@ static bool _guess_identifier_type_in_expression(const GDParser::ClassNode *p_cl
return false;
}
-static bool _guess_identifier_type_in_block(const GDParser::ClassNode *p_class,const GDParser::BlockNode *p_block,int p_line,const StringName& p_identifier,GDCompletionIdentifier &r_type) {
-
-
- for(int i=0;i<p_block->sub_blocks.size();i++) {
- //parse inner first
- if (p_line>=p_block->sub_blocks[i]->line && (p_line<=p_block->sub_blocks[i]->end_line || p_block->sub_blocks[i]->end_line==-1)) {
- if (_guess_identifier_type_in_block(p_class,p_block->sub_blocks[i],p_line,p_identifier,r_type))
- return true;
- }
- }
+static bool _guess_identifier_type_in_block(GDCompletionContext& context,int p_line,const StringName& p_identifier,GDCompletionIdentifier &r_type) {
const GDParser::Node *last_assign=NULL;
int last_assign_line=-1;
- for (int i=0;i<p_block->statements.size();i++) {
+ for (int i=0;i<context.block->statements.size();i++) {
+
+ if (context.block->statements[i]->line>p_line)
+ continue;
- if (p_block->statements[i]->line>p_line)
- break;
+ if (context.block->statements[i]->type==GDParser::BlockNode::TYPE_LOCAL_VAR) {
- if (p_block->statements[i]->type==GDParser::BlockNode::TYPE_LOCAL_VAR) {
+ const GDParser::LocalVarNode *lv=static_cast<const GDParser::LocalVarNode *>(context.block->statements[i]);
- const GDParser::LocalVarNode *lv=static_cast<const GDParser::LocalVarNode *>(p_block->statements[i]);
if (lv->assign && lv->name==p_identifier) {
+
last_assign=lv->assign;
- last_assign_line=p_block->statements[i]->line;
+ last_assign_line=context.block->statements[i]->line;
}
}
- if (p_block->statements[i]->type==GDParser::BlockNode::TYPE_OPERATOR) {
- const GDParser::OperatorNode *op = static_cast<const GDParser::OperatorNode *>(p_block->statements[i]);
+ if (context.block->statements[i]->type==GDParser::BlockNode::TYPE_OPERATOR) {
+ const GDParser::OperatorNode *op = static_cast<const GDParser::OperatorNode *>(context.block->statements[i]);
if (op->op==GDParser::OperatorNode::OP_ASSIGN) {
if (op->arguments.size() && op->arguments[0]->type==GDParser::Node::TYPE_IDENTIFIER) {
+
const GDParser::IdentifierNode *id = static_cast<const GDParser::IdentifierNode *>(op->arguments[0]);
+
if (id->name==p_identifier) {
+
last_assign=op->arguments[1];
- last_assign_line=p_block->statements[i]->line;
+ last_assign_line=context.block->statements[i]->line;
}
}
}
@@ -642,418 +918,982 @@ static bool _guess_identifier_type_in_block(const GDParser::ClassNode *p_class,c
//use the last assignment, (then backwards?)
if (last_assign) {
- return _guess_identifier_type_in_expression(p_class,last_assign,last_assign_line-1,r_type);
+
+ return _guess_expression_type(context,last_assign,last_assign_line,r_type);
}
+
return false;
}
-static GDCompletionIdentifier _guess_identifier_type(const GDParser::ClassNode *p_class,int p_line,const StringName& p_identifier) {
+static bool _guess_identifier_type(GDCompletionContext& context,int p_line,const StringName& p_identifier,GDCompletionIdentifier &r_type) {
+ //go to block first
- return GDCompletionIdentifier();
-}
-static void _parse_expression_node(const GDParser::ClassNode *p_class,const GDParser::Node *p_node,int p_line,List<String>* r_options,List<String>::Element *p_indices) {
+ const GDParser::BlockNode *block=context.block;
+ while(block) {
+ GDCompletionContext c = context;
+ c.block=block;
- if (p_node->type==GDParser::Node::TYPE_CONSTANT) {
-
- const GDParser::ConstantNode *cn=static_cast<const GDParser::ConstantNode *>(p_node);
- _parse_completion_variant(cn->value,r_options,p_indices?p_indices->next():NULL);
- } else if (p_node->type==GDParser::Node::TYPE_DICTIONARY) {
-
- const GDParser::DictionaryNode *dn=static_cast<const GDParser::DictionaryNode*>(p_node);
- for (int i=0;i<dn->elements.size();i++) {
+ if (_guess_identifier_type_in_block(c,p_line,p_identifier,r_type)) {
+ return true;
+ }
- if (dn->elements[i].key->type==GDParser::Node::TYPE_CONSTANT) {
+ block=block->parent_block;
+ }
- const GDParser::ConstantNode *cn=static_cast<const GDParser::ConstantNode *>(dn->elements[i].key);
- if (cn->value.get_type()==Variant::STRING) {
+ //guess from argument if virtual
+ if (context.function && context.function->name!=StringName()) {
- String str=cn->value;
- if (p_indices) {
+ int argindex = -1;
- if (str==p_indices->get()) {
- _parse_expression_node(p_class,dn->elements[i].value,p_line,r_options,p_indices->next());
- return;
- }
+ for(int i=0;i<context.function->arguments.size();i++) {
- } else {
- r_options->push_back(str);
- }
- }
+ if (context.function->arguments[i]==p_identifier) {
+ argindex=i;
+ break;
}
+
}
- } else if (p_node->type==GDParser::Node::TYPE_BUILT_IN_FUNCTION) {
- MethodInfo mi = GDFunctions::get_info(static_cast<const GDParser::BuiltInFunctionNode*>(p_node)->function);
+ if (argindex!=-1) {
+ GDCompletionIdentifier id =_get_native_class(context);
+ if (id.type==Variant::OBJECT && id.obj_type!=StringName()) {
+ //this kinda sucks but meh
- Variant::CallError ce;
- _parse_completion_variant(Variant::construct(mi.return_val.type,NULL,0,ce),r_options,p_indices?p_indices->next():NULL);
- } else if (p_node->type==GDParser::Node::TYPE_IDENTIFIER) {
+ List<MethodInfo> vmethods;
+ ObjectTypeDB::get_virtual_methods(id.obj_type,&vmethods);
+ for (List<MethodInfo>::Element *E=vmethods.front();E;E=E->next()) {
- //GDCompletionIdentifier idt = _guess_identifier_type(p_class,p_line-1,static_cast<const GDParser::IdentifierNode *>(p_node)->name);
- //Variant::CallError ce;
- //_parse_completion_variant(Variant::construct(mi.return_val.type,NULL,0,ce),r_options,p_indices?p_indices->next():NULL);
- }
-}
-static bool _parse_completion_block(const GDParser::ClassNode *p_class,const GDParser::BlockNode *p_block,int p_line,List<String>* r_options,List<String>::Element *p_indices) {
+ if (E->get().name==context.function->name && argindex<E->get().arguments.size()) {
- print_line("COMPLETION BLOCK "+itos(p_block->line)+" -> "+itos(p_block->end_line));
+ PropertyInfo arg=E->get().arguments[argindex];
- for(int i=0;i<p_block->sub_blocks.size();i++) {
- //parse inner first
- if (p_line>=p_block->sub_blocks[i]->line && (p_line<=p_block->sub_blocks[i]->end_line || p_block->sub_blocks[i]->end_line==-1)) {
- if (_parse_completion_block(p_class,p_block->sub_blocks[i],p_line,r_options,p_indices))
- return true;
+ int scp = arg.name.find(":");
+ if (scp!=-1) {
+
+
+ r_type.type=Variant::OBJECT;
+ r_type.obj_type=arg.name.substr(scp+1,arg.name.length());
+ return true;
+
+ } else {
+
+ r_type.type=arg.type;
+ if (arg.hint==PROPERTY_HINT_RESOURCE_TYPE)
+ r_type.obj_type=arg.hint_string;
+ return true;
+ }
+ }
+ }
+ }
}
}
- if (p_indices) {
+ //guess type in constant
- //parse indices in expressions :|
+ for(int i=0;i<context._class->constant_expressions.size();i++) {
- const GDParser::Node *last_assign=NULL;
- int last_assign_line=-1;
+ if (context._class->constant_expressions[i].identifier==p_identifier) {
- for (int i=0;i<p_block->statements.size();i++) {
+ ERR_FAIL_COND_V( context._class->constant_expressions[i].expression->type!=GDParser::Node::TYPE_CONSTANT, false );
+ r_type=_get_type_from_variant(static_cast<const GDParser::ConstantNode*>(context._class->constant_expressions[i].expression)->value );
+ return true;
+ }
+ }
- if (p_block->statements[i]->line>p_line)
- break;
+ if (!(context.function && context.function->_static)) {
+
+ for(int i=0;i<context._class->variables.size();i++) {
+ if (context._class->variables[i].identifier==p_identifier) {
- if (p_block->statements[i]->type==GDParser::BlockNode::TYPE_LOCAL_VAR) {
+ if (context._class->variables[i]._export.type!=Variant::NIL) {
- const GDParser::LocalVarNode *lv=static_cast<const GDParser::LocalVarNode *>(p_block->statements[i]);
- if (lv->assign && String(lv->name)==p_indices->get()) {
- last_assign=lv->assign;
- last_assign_line=p_block->statements[i]->line;
+ r_type=_get_type_from_pinfo(context._class->variables[i]._export);
+ return true;
+ } else if (context._class->variables[i].expression) {
+ return _guess_expression_type(context,context._class->variables[i].expression,context._class->variables[i].line,r_type);
}
}
}
+ }
- //use the last assignment, (then backwards?)
- if (last_assign) {
- _parse_expression_node(p_class,last_assign,last_assign_line,r_options,p_indices->next());
- return true;
- }
- } else {
- //no indices, just add all variables and continue
- for(int i=0;i<p_block->variables.size();i++) {
- //parse variables second
- if (p_line>=p_block->variable_lines[i]) {
- r_options->push_back(p_block->variables[i]);
- } else break;
+ for(Map<StringName,int>::Element *E=GDScriptLanguage::get_singleton()->get_global_map().front();E;E=E->next()) {
+ if (E->key()==p_identifier) {
+
+ r_type=_get_type_from_variant(GDScriptLanguage::get_singleton()->get_global_array()[E->get()]);
+ return true;
}
- }
+ }
return false;
}
-static bool _parse_script_symbols(const Ref<GDScript>& p_script,bool p_static,List<String>* r_options,List<String>::Element *p_indices) {
+static void _find_identifiers_in_block(GDCompletionContext& context,int p_line,bool p_only_functions,Set<String>& result) {
+
+ if (p_only_functions)
+ return;
+
+ for (int i=0;i<context.block->statements.size();i++) {
+
+ if (context.block->statements[i]->line>p_line)
+ continue;
- //for (Map<StringName,Ref<GDScript> >::Element ?
- if (!p_static && !p_indices) {
- for(const Set<StringName>::Element *E=p_script->get_members().front();E;E=E->next()) {
+ if (context.block->statements[i]->type==GDParser::BlockNode::TYPE_LOCAL_VAR) {
- r_options->push_back(E->get());
+ const GDParser::LocalVarNode *lv=static_cast<const GDParser::LocalVarNode *>(context.block->statements[i]);
+ result.insert(lv->name.operator String());
}
}
+}
- for (const Map<StringName,Variant >::Element *E=p_script->get_constants().front();E;E=E->next()) {
+static void _find_identifiers_in_class(GDCompletionContext& context,bool p_static,bool p_only_functions,Set<String>& result) {
- if( p_indices) {
- if (p_indices->get()==String(E->get())) {
- _parse_completion_variant(E->get(),r_options,p_indices->next());
- return true;
- }
- } else {
- r_options->push_back(E->key());
+ if (!p_static && !p_only_functions) {
+
+ for(int i=0;i<context._class->variables.size();i++) {
+ result.insert(context._class->variables[i].identifier);
}
}
+ if (!p_only_functions) {
- if (!p_indices){
- for (const Map<StringName,GDFunction>::Element *E=p_script->get_member_functions().front();E;E=E->next()) {
+ for(int i=0;i<context._class->constant_expressions.size();i++) {
+ result.insert(context._class->constant_expressions[i].identifier);
+ }
- if (E->get().is_static() || !p_static)
- r_options->push_back(E->key());
+ for(int i=0;i<context._class->subclasses.size();i++) {
+ result.insert(context._class->subclasses[i]->name);
}
+
}
- if (p_script->get_base().is_valid()){
- if (_parse_script_symbols(p_script->get_base(),p_static,r_options,p_indices))
- return true;
- } else if (p_script->get_native().is_valid() && !p_indices) {
- _parse_native_symbols(p_script->get_native()->get_name(),p_static,r_options);
+ for(int i=0;i<context._class->static_functions.size();i++) {
+ if (context._class->static_functions[i]->arguments.size())
+ result.insert(context._class->static_functions[i]->name.operator String()+"(");
+ else
+ result.insert(context._class->static_functions[i]->name.operator String()+"()");
}
- return false;
-}
+ if (!p_static) {
+
+ for(int i=0;i<context._class->functions.size();i++) {
+ if (context._class->functions[i]->arguments.size())
+ result.insert(context._class->functions[i]->name.operator String()+"(");
+ else
+ result.insert(context._class->functions[i]->name.operator String()+"()");
+ }
+ }
+
+ //globals
+
+ Ref<Reference> base = _get_parent_class(context);
+
+ while(true) {
+ Ref<GDScript> script = base;
+ Ref<GDNativeClass> nc = base;
+ if (script.is_valid()) {
-static bool _parse_completion_class(const String& p_base_path,const GDParser::ClassNode *p_class,int p_line,List<String>* r_options,List<String>::Element *p_indices) {
+ if (!p_static && !p_only_functions) {
+ for (const Set<StringName>::Element *E=script->get_members().front();E;E=E->next()) {
+ result.insert(E->get().operator String());
+ }
+ }
- //checks known classes or built-in types for completion
+ if (!p_only_functions) {
+ for (const Map<StringName,Variant>::Element *E=script->get_constants().front();E;E=E->next()) {
+ result.insert(E->key().operator String());
+ }
+ }
- if (p_indices && !p_indices->next()) {
- //built-in types do not have sub-classes, try these first if no sub-indices exist.
- static const char*_type_names[Variant::VARIANT_MAX]={
- "null","bool","int","float","String","Vector2","Rect2","Vector3","Matrix32","Plane","Quat","AABB","Matrix3","Trasnform",
- "Color","Image","NodePath","RID","Object","InputEvent","Dictionary","Array","RawArray","IntArray","FloatArray","StringArray",
- "Vector2Array","Vector3Array","ColorArray"};
+ for (const Map<StringName,GDFunction>::Element *E=script->get_member_functions().front();E;E=E->next()) {
+ if (!p_static || E->get().is_static()) {
+ if (E->get().get_argument_count())
+ result.insert(E->key().operator String()+"(");
+ else
+ result.insert(E->key().operator String()+"()");
+ }
+ }
+
+ if (!p_only_functions) {
+ for (const Map<StringName,Ref<GDScript> >::Element *E=script->get_subclasses().front();E;E=E->next()) {
+ result.insert(E->key().operator String());
+ }
+ }
- for(int i=0;i<Variant::VARIANT_MAX;i++) {
+ base=script->get_base();
+ if (base.is_null())
+ base=script->get_native();
+ } else if (nc.is_valid()) {
- if (p_indices->get()==_type_names[i]) {
+ if (!p_only_functions) {
- List<StringName> ic;
+ StringName type = nc->get_name();
+ List<String> constants;
+ ObjectTypeDB::get_integer_constant_list(type,&constants);
+ for(List<String>::Element *E=constants.front();E;E=E->next()) {
+ result.insert(E->get());
+ }
- Variant::get_numeric_constants_for_type(Variant::Type(i),&ic);
- for(List<StringName>::Element *E=ic.front();E;E=E->next()) {
- r_options->push_back(E->get());
+ List<MethodInfo> methods;
+ ObjectTypeDB::get_method_list(type,&methods);
+ for(List<MethodInfo>::Element *E=methods.front();E;E=E->next()) {
+ if (E->get().name.begins_with("_"))
+ continue;
+ if (E->get().arguments.size())
+ result.insert(E->get().name+"(");
+ else
+ result.insert(E->get().name+"()");
}
- return true;
}
- }
+ break;
+ } else
+ break;
+
}
- // check the sub-classes of current class
+}
- for(int i=0;i<p_class->subclasses.size();i++) {
+static void _find_identifiers(GDCompletionContext& context,int p_line,bool p_only_functions,Set<String>& result) {
- if (p_line>=p_class->subclasses[i]->line && (p_line<=p_class->subclasses[i]->end_line || p_class->subclasses[i]->end_line==-1)) {
- // if OK in sub-classes, try completing the sub-class
- if (_parse_completion_class(p_base_path,p_class->subclasses[i],p_line,r_options,p_indices))
- return true;
- }
+ const GDParser::BlockNode *block=context.block;
+
+ while(block) {
+
+ GDCompletionContext c = context;
+ c.block=block;
+
+ _find_identifiers_in_block(c,p_line,p_only_functions,result);
+ block=block->parent_block;
}
- bool in_static_func=false;
+ const GDParser::ClassNode *clss=context._class;
- for(int i=0;i<p_class->functions.size();i++) {
+ bool _static=context.function && context.function->_static;
- const GDParser::FunctionNode *fu = p_class->functions[i];
+ while(clss) {
+ GDCompletionContext c = context;
+ c._class=clss;
+ c.block=NULL;
+ c.function=NULL;
+ _find_identifiers_in_class(c,_static,p_only_functions,result);
+ clss=clss->owner;
+ }
- if (p_line>=fu->body->line && (p_line<=fu->body->end_line || fu->body->end_line==-1)) {
- //if in function, first block stuff from outer to inner
- if (_parse_completion_block(p_class,fu->body,p_line,r_options,p_indices))
- return true;
- //then function arguments
- if (!p_indices) {
- for(int j=0;j<fu->arguments.size();j++) {
+ for(int i=0;i<GDFunctions::FUNC_MAX;i++) {
+
+ result.insert(GDFunctions::get_func_name(GDFunctions::Function(i)));
+ }
+
+ static const char*_type_names[Variant::VARIANT_MAX]={
+ "null","bool","int","float","String","Vector2","Rect2","Vector3","Matrix32","Plane","Quat","AABB","Matrix3","Trasnform",
+ "Color","Image","NodePath","RID","Object","InputEvent","Dictionary","Array","RawArray","IntArray","FloatArray","StringArray",
+ "Vector2Array","Vector3Array","ColorArray"};
+
+ for(int i=0;i<Variant::VARIANT_MAX;i++) {
+ result.insert(_type_names[i]);
+ }
+
+ for(const Map<StringName,int>::Element *E=GDScriptLanguage::get_singleton()->get_global_map().front();E;E=E->next()) {
+ result.insert(E->key().operator String());
+ }
+}
+
+
+static String _get_visual_datatype(const PropertyInfo& p_info,bool p_isarg=true) {
+
+ String n = p_info.name;
+ int idx = n.find(":");
+ if (idx!=-1) {
+ return n.substr(idx+1,n.length());
+ }
+
+ if (p_info.type==Variant::OBJECT && p_info.hint==PROPERTY_HINT_RESOURCE_TYPE)
+ return p_info.hint_string;
+ if (p_info.type==Variant::NIL) {
+ if (p_isarg)
+ return "var";
+ else
+ return "void";
+ }
+
+ return Variant::get_type_name(p_info.type);
+}
+
+static void _make_function_hint(const GDParser::FunctionNode* p_func,int p_argidx,String& arghint) {
+
+ arghint="func "+p_func->name+"(";
+ for (int i=0;i<p_func->arguments.size();i++) {
+ if (i>0)
+ arghint+=", ";
+ else
+ arghint+=" ";
+
+ if (i==p_argidx) {
+ arghint+=String::chr(0xFFFF);
+ }
+ arghint+=p_func->arguments[i].operator String();
+ int deffrom = p_func->arguments.size()-p_func->default_values.size();
+
+ if (i>=deffrom) {
+ int defidx = deffrom-i;
+
+ if (defidx>=0 && defidx<p_func->default_values.size()) {
+
+ if (p_func->default_values[defidx]->type==GDParser::Node::TYPE_OPERATOR) {
+
+ const GDParser::OperatorNode *op=static_cast<const GDParser::OperatorNode *>(p_func->default_values[defidx]);
+ if (op->op==GDParser::OperatorNode::OP_ASSIGN) {
+ const GDParser::ConstantNode *cn=static_cast<const GDParser::ConstantNode *>(op->arguments[1]);
+ arghint+="="+cn->value.get_construct_string();
+
+ }
+ } else {
- r_options->push_back(fu->arguments[j]);
}
}
}
+ if (i==p_argidx) {
+ arghint+=String::chr(0xFFFF);
+ }
}
+ if (p_func->arguments.size()>0)
+ arghint+=" ";
+ arghint+=")";
+}
- for(int i=0;i<p_class->static_functions.size();i++) {
- const GDParser::FunctionNode *fu = p_class->static_functions[i];
+static void _find_type_arguments(const GDParser::Node*p_node,int p_line,const StringName& p_method,const GDCompletionIdentifier& id, int p_argidx, Set<String>& result, String& arghint) {
- if (p_line>=fu->body->line && (p_line<=fu->body->end_line || fu->body->end_line==-1)) {
- //if in function, first block stuff from outer to inne
- if (_parse_completion_block(p_class,fu->body,p_line,r_options,p_indices))
- return true;
- //then function arguments
- if (!p_indices) {
- for(int j=0;j<fu->arguments.size();j++) {
+ if (id.type==Variant::INPUT_EVENT && String(p_method)=="is_action" && p_argidx==0) {
- r_options->push_back(fu->arguments[j]);
- }
- }
+ List<PropertyInfo> pinfo;
+ Globals::get_singleton()->get_property_list(&pinfo);
+
+ for(List<PropertyInfo>::Element *E=pinfo.front();E;E=E->next()) {
+ const PropertyInfo &pi=E->get();
- in_static_func=true;
+ if (!pi.name.begins_with("input/"))
+ continue;
+
+ String name = pi.name.substr(pi.name.find("/")+1,pi.name.length());
+ result.insert("\""+name+"\"");
}
- }
+ } else if (id.type==Variant::OBJECT && id.obj_type!=StringName()) {
- //add all local names
- if (!p_indices) {
- if (!in_static_func) {
+ MethodBind *m = ObjectTypeDB::get_method(id.obj_type,p_method);
+ if (!m)
+ return;
- for(int i=0;i<p_class->variables.size();i++) {
+ if (p_method.operator String()=="connect") {
- r_options->push_back(p_class->variables[i].identifier);
+
+ if (p_argidx==0) {
+ List<MethodInfo> sigs;
+ ObjectTypeDB::get_signal_list(id.obj_type,&sigs);
+ for (List<MethodInfo>::Element *E=sigs.front();E;E=E->next()) {
+ result.insert("\""+E->get().name+"\"");
+ }
}
- }
+ /*if (p_argidx==2) {
- for(int i=0;i<p_class->constant_expressions.size();i++) {
+ ERR_FAIL_COND(p_node->type!=GDParser::Node::TYPE_OPERATOR);
+ const GDParser::OperatorNode *op=static_cast<const GDParser::OperatorNode *>(p_node);
+ if (op->arguments.size()>)
- r_options->push_back(p_class->constant_expressions[i].identifier);
- }
+ }*/
+ } else {
- if (!in_static_func) {
- for(int i=0;i<p_class->functions.size();i++) {
+ Object *obj=id.value;
+ if (obj) {
+ List<String> options;
+ obj->get_argument_options(p_method,p_argidx,&options);
+ for(List<String>::Element *E=options.front();E;E=E->next()) {
- r_options->push_back(p_class->functions[i]->name);
+ result.insert(E->get());
+ }
}
+
}
- for(int i=0;i<p_class->static_functions.size();i++) {
+ arghint = _get_visual_datatype(m->get_argument_info(-1),false)+" "+p_method.operator String()+String("(");
+
+ for(int i=0;i<m->get_argument_count();i++) {
+ if (i>0)
+ arghint+=", ";
+ else
+ arghint+=" ";
+
+ if (i==p_argidx) {
+ arghint+=String::chr(0xFFFF);
+ }
+ String n = m->get_argument_info(i).name;
+ int dp = n.find(":");
+ if (dp!=-1)
+ n=n.substr(0,dp);
+ arghint+=_get_visual_datatype(m->get_argument_info(i))+" "+n;
+ int deffrom = m->get_argument_count()-m->get_default_argument_count();
+
+
+ if (i>=deffrom) {
+ int defidx = i-deffrom;
+
+ if (defidx>=0 && defidx<m->get_default_argument_count()) {
+ Variant v= m->get_default_argument(i);
+ arghint+="="+v.get_construct_string();
+ }
+ }
+
+ if (i==p_argidx) {
+ arghint+=String::chr(0xFFFF);
+ }
- r_options->push_back(p_class->static_functions[i]->name);
}
+ if (m->get_argument_count()>0)
+ arghint+=" ";
+
+
+ arghint+=")";
+
}
+}
- if (p_class->extends_used) {
- //do inheritance
- String path = p_class->extends_file;
+static void _find_call_arguments(GDCompletionContext& context,const GDParser::Node* p_node, int p_line,int p_argidx, Set<String>& result, String& arghint) {
- Ref<GDScript> script;
- Ref<GDNativeClass> native;
- if (path!="") {
- //path (and optionally subclasses)
- script = ResourceLoader::load(path);
- if (script.is_null()) {
- return false;
+ if (!p_node || p_node->type!=GDParser::Node::TYPE_OPERATOR) {
+
+ return;
+ }
+
+ const GDParser::OperatorNode *op = static_cast<const GDParser::OperatorNode *>(p_node);
+
+ if (op->op!=GDParser::OperatorNode::OP_CALL) {
+
+ return;
+ }
+
+ if (op->arguments[0]->type==GDParser::Node::TYPE_BUILT_IN_FUNCTION) {
+ //complete built-in function
+ const GDParser::BuiltInFunctionNode *fn = static_cast<const GDParser::BuiltInFunctionNode*>(op->arguments[0]);
+ MethodInfo mi = GDFunctions::get_info(fn->function);
+
+ arghint = _get_visual_datatype(mi.return_val,false)+" "+GDFunctions::get_func_name(fn->function)+String("(");
+ for(int i=0;i<mi.arguments.size();i++) {
+ if (i>0)
+ arghint+=", ";
+ else
+ arghint+=" ";
+ if (i==p_argidx) {
+ arghint+=String::chr(0xFFFF);
+ }
+ arghint+=_get_visual_datatype(mi.arguments[i])+" "+mi.arguments[i].name;
+ if (i==p_argidx) {
+ arghint+=String::chr(0xFFFF);
}
- if (p_class->extends_class.size()) {
+ }
+ if (mi.arguments.size()>0)
+ arghint+=" ";
+ arghint+=")";
+
+ } else if (op->arguments[0]->type==GDParser::Node::TYPE_TYPE) {
+ //complete built-in function
+ const GDParser::TypeNode *tn = static_cast<const GDParser::TypeNode*>(op->arguments[0]);
+
+ List<MethodInfo> mil;
+ Variant::get_constructor_list(tn->vtype,&mil);
+
+ for(List<MethodInfo>::Element *E=mil.front();E;E=E->next()) {
+
+ MethodInfo mi = E->get();
+ if (mi.arguments.size()==0)
+ continue;
+ if (E->prev())
+ arghint+="\n";
+ arghint += Variant::get_type_name(tn->vtype)+" "+Variant::get_type_name(tn->vtype)+String("(");
+ for(int i=0;i<mi.arguments.size();i++) {
+ if (i>0)
+ arghint+=", ";
+ else
+ arghint+=" ";
+ if (i==p_argidx) {
+ arghint+=String::chr(0xFFFF);
+ }
+ arghint+=_get_visual_datatype(mi.arguments[i])+" "+mi.arguments[i].name;
+ if (i==p_argidx) {
+ arghint+=String::chr(0xFFFF);
+ }
- for(int i=0;i<p_class->extends_class.size();i++) {
+ }
+ if (mi.arguments.size()>0)
+ arghint+=" ";
+ arghint+=")";
+ }
- String sub = p_class->extends_class[i];
- if (script->get_subclasses().has(sub)) {
+ } else if (op->arguments.size()>=2 && op->arguments[1]->type==GDParser::Node::TYPE_IDENTIFIER) {
+ //make sure identifier exists...
- script=script->get_subclasses()[sub];
- } else {
+ const GDParser::IdentifierNode *id=static_cast<const GDParser::IdentifierNode *>(op->arguments[1]);
- return false;
+ if (op->arguments[0]->type==GDParser::Node::TYPE_SELF) {
+ //self, look up
+
+ for(int i=0;i<context._class->static_functions.size();i++) {
+ if (context._class->static_functions[i]->name==id->name) {
+ _make_function_hint(context._class->static_functions[i],p_argidx,arghint);
+ return;
+ }
+ }
+
+ if (context.function && !context.function->_static) {
+
+ for(int i=0;i<context._class->functions.size();i++) {
+ if (context._class->functions[i]->name==id->name) {
+ _make_function_hint(context._class->functions[i],p_argidx,arghint);
+ return;
}
}
}
- } else {
+ Ref<Reference> base = _get_parent_class(context);
- ERR_FAIL_COND_V(p_class->extends_class.size()==0,false);
- //look around for the subclasses
+ while(true) {
- String base=p_class->extends_class[0];
- Ref<GDScript> base_class;
-#if 0
- while(p) {
+ Ref<GDScript> script = base;
+ Ref<GDNativeClass> nc = base;
+ if (script.is_valid()) {
- if (p->subclasses.has(base)) {
- base_class=p->subclasses[base];
+ for (const Map<StringName,GDFunction>::Element *E=script->get_member_functions().front();E;E=E->next()) {
+
+ if (E->key()==id->name) {
+
+ if (context.function && context.function->_static && !E->get().is_static())
+ continue;
+
+
+ arghint = "func "+id->name.operator String()+String("(");
+ for(int i=0;i<E->get().get_argument_count();i++) {
+ if (i>0)
+ arghint+=", ";
+ else
+ arghint+=" ";
+ if (i==p_argidx) {
+ arghint+=String::chr(0xFFFF);
+ }
+ arghint+=E->get().get_argument_name(i);
+ int deffrom = E->get().get_argument_count()-E->get().get_default_argument_count();
+ if (i>=deffrom) {
+ int defidx = deffrom-i;
+ if (defidx>=0 && defidx<E->get().get_default_argument_count()) {
+ arghint+="="+E->get().get_default_argument(defidx).get_construct_string();
+ }
+ }
+ if (i==p_argidx) {
+ arghint+=String::chr(0xFFFF);
+ }
+
+ }
+ if (E->get().get_argument_count()>0)
+ arghint+=" ";
+ arghint+=")";
+ return;
+ }
+ }
+
+ base=script->get_base();
+ if (base.is_null())
+ base=script->get_native();
+ } else if (nc.is_valid()) {
+
+ if (context.function && !context.function->_static) {
+
+ GDCompletionIdentifier ci;
+ ci.type=Variant::OBJECT;
+ ci.obj_type=nc->get_name();
+ if (!context._class->owner)
+ ci.value=context.base;
+
+ _find_type_arguments(p_node,p_line,id->name,ci,p_argidx,result,arghint);
+ //guess type..
+ /*
+ List<MethodInfo> methods;
+ ObjectTypeDB::get_method_list(type,&methods);
+ for(List<MethodInfo>::Element *E=methods.front();E;E=E->next()) {
+ //if (E->get().arguments.size())
+ // result.insert(E->get().name+"(");
+ //else
+ // result.insert(E->get().name+"()");
+ }*/
+ }
break;
- }
- p=p->_owner;
+ } else
+ break;
+
}
+ } else {
- if (base_class.is_valid()) {
- for(int i=1;i<p_class->extends_class.size();i++) {
+ GDCompletionIdentifier ci;
+ if (_guess_expression_type(context,op->arguments[0],p_line,ci)) {
- String subclass=p_class->extends_class[i];
+ _find_type_arguments(p_node,p_line,id->name,ci,p_argidx,result,arghint);
+ return;
+ }
- if (base_class->subclasses.has(subclass)) {
+ }
- base_class=base_class->subclasses[subclass];
- } else {
+ }
+#if 0
+ bool _static=context.function->_static;
- _set_error("Could not find subclass: "+subclass,p_class);
- return ERR_FILE_NOT_FOUND;
- }
- }
- } else {
-#endif
- if (p_class->extends_class.size()>1) {
- return false;
+ for(int i=0;i<context._class->static_functions.size();i++) {
+ if (context._class->static_functions[i]->arguments.size())
+ result.insert(context._class->static_functions[i]->name.operator String()+"(");
+ else
+ result.insert(context._class->static_functions[i]->name.operator String()+"()");
+ }
+
+ if (!p_static) {
+ for(int i=0;i<context._class->functions.size();i++) {
+ if (context._class->functions[i]->arguments.size())
+ result.insert(context._class->functions[i]->name.operator String()+"(");
+ else
+ result.insert(context._class->functions[i]->name.operator String()+"()");
+ }
+ }
+
+ Ref<Reference> base = _get_parent_class(context);
+
+ while(true) {
+
+ Ref<GDScript> script = base;
+ Ref<GDNativeClass> nc = base;
+ if (script.is_valid()) {
+
+ if (!p_static && !p_only_functions) {
+ for (const Set<StringName>::Element *E=script->get_members().front();E;E=E->next()) {
+ result.insert(E->get().operator String());
}
- //if not found, try engine classes
- if (!GDScriptLanguage::get_singleton()->get_global_map().has(base)) {
- return false;
+ }
+
+ if (!p_only_functions) {
+ for (const Map<StringName,Variant>::Element *E=script->get_constants().front();E;E=E->next()) {
+ result.insert(E->key().operator String());
}
+ }
- int base_idx = GDScriptLanguage::get_singleton()->get_global_map()[base];
- native = GDScriptLanguage::get_singleton()->get_global_array()[base_idx];
- if (!native.is_valid()) {
- return false;
+ for (const Map<StringName,GDFunction>::Element *E=script->get_member_functions().front();E;E=E->next()) {
+ if (!p_static || E->get().is_static()) {
+ if (E->get().get_argument_count())
+ result.insert(E->key().operator String()+"(");
+ else
+ result.insert(E->key().operator String()+"()");
}
-#if 0
}
-#endif
- }
+ if (!p_only_functions) {
+ for (const Map<StringName,Ref<GDScript> >::Element *E=script->get_subclasses().front();E;E=E->next()) {
+ result.insert(E->key().operator String());
+ }
+ }
- if (script.is_valid()) {
- if (_parse_script_symbols(script,in_static_func,r_options,p_indices))
- return true;
+ base=script->get_base();
+ if (base.is_null())
+ base=script->get_native();
+ } else if (nc.is_valid()) {
- } else if (native.is_valid() && !p_indices) {
+ if (!p_only_functions) {
- _parse_native_symbols(native->get_name(),in_static_func,r_options);
- }
- }
+ StringName type = nc->get_name();
+ List<String> constants;
+ ObjectTypeDB::get_integer_constant_list(type,&constants);
+ for(List<String>::Element *E=constants.front();E;E=E->next()) {
+ result.insert(E->get());
+ }
- return false;
+ List<MethodInfo> methods;
+ ObjectTypeDB::get_method_list(type,&methods);
+ for(List<MethodInfo>::Element *E=methods.front();E;E=E->next()) {
+ if (E->get().arguments.size())
+ result.insert(E->get().name+"(");
+ else
+ result.insert(E->get().name+"()");
+ }
+ }
+ break;
+ } else
+ break;
-}
+ }
+ for(int i=0;i<GDFunctions::FUNC_MAX;i++) {
-Error GDScriptLanguage::complete_keyword(const String& p_code, int p_line, const String& p_base_path, const String& p_base, List<String>* r_options) {
+ result.insert(GDFunctions::get_func_name(GDFunctions::Function(i)));
+ }
+#endif
+
+}
+Error GDScriptLanguage::complete_code(const String& p_code, const String& p_base_path, Object*p_owner, List<String>* r_options, String &r_call_hint) {
+ //print_line( p_code.replace(String::chr(0xFFFF),"<cursor>"));
GDParser p;
Error err = p.parse(p_code,p_base_path);
- // don't care much about error I guess
- const GDParser::Node* root = p.get_parse_tree();
- ERR_FAIL_COND_V(root->type!=GDParser::Node::TYPE_CLASS,ERR_INVALID_DATA);
+ bool isfunction=false;
+ Set<String> options;
+
+ GDCompletionContext context;
+ context._class=p.get_completion_class();
+ context.block=p.get_completion_block();
+ context.function=p.get_completion_function();
+ context.base=p_owner;
+ context.base_path=p_base_path;
+
+ switch(p.get_completion_type()) {
+
+ case GDParser::COMPLETION_NONE: {
+ print_line("No completion");
+ } break;
+ case GDParser::COMPLETION_BUILT_IN_TYPE_CONSTANT: {
+ print_line("Built in type constant");
+ List<StringName> constants;
+ Variant::get_numeric_constants_for_type(p.get_completion_built_in_constant(),&constants);
+ for(List<StringName>::Element *E=constants.front();E;E=E->next()) {
+ options.insert(E->get().operator String());
+ }
- print_line("BASE: "+p_base);
- const GDParser::ClassNode *cl = static_cast<const GDParser::ClassNode*>(root);
- List<String> indices;
- Vector<String> spl = p_base.split(".");
+ } break;
+ case GDParser::COMPLETION_FUNCTION:
+ isfunction=true;
+ case GDParser::COMPLETION_IDENTIFIER: {
- for(int i=0;i<spl.size()-1;i++) {
- print_line("INDEX "+itos(i)+": "+spl[i]);
- indices.push_back(spl[i]);
- }
+ _find_identifiers(context,p.get_completion_line(),isfunction,options);
+ } break;
+ case GDParser::COMPLETION_PARENT_FUNCTION: {
+ print_line("parent function");
- //parse completion inside of the class first
- if (_parse_completion_class(p_base,cl,p_line,r_options,indices.front()))
- return OK;
+ } break;
+ case GDParser::COMPLETION_METHOD:
+ isfunction=true;
+ case GDParser::COMPLETION_INDEX: {
+
+ const GDParser::Node *node = p.get_completion_node();
+ if (node->type!=GDParser::Node::TYPE_OPERATOR)
+ break;
- //if parsing completion inside of the class fails (none found), try using globals for completion
- for(Map<StringName,int>::Element *E=globals.front();E;E=E->next()) {
- if (!indices.empty()) {
- if (String(E->key())==indices.front()->get()) {
- _parse_completion_variant(global_array[E->get()],r_options,indices.front()->next());
- return OK;
+
+ GDCompletionIdentifier t;
+ if (_guess_expression_type(context,static_cast<const GDParser::OperatorNode *>(node)->arguments[0],p.get_completion_line(),t)) {
+
+ if (t.type==Variant::OBJECT && t.obj_type!=StringName()) {
+
+
+ if (t.value.get_type()) {
+ Object *obj=t.value;
+ if (obj) {
+ GDScript *scr = obj->cast_to<GDScript>();
+ while (scr) {
+
+ if (!isfunction) {
+ for (const Map<StringName,Variant>::Element *E=scr->get_constants().front();E;E=E->next()) {
+ options.insert(E->key());
+ }
+ }
+ for (const Map<StringName,GDFunction>::Element *E=scr->get_member_functions().front();E;E=E->next()) {
+ options.insert(E->key());
+ }
+
+ if (scr->get_base().is_valid())
+ scr=scr->get_base().ptr();
+ else
+ scr=NULL;
+ }
+ }
+ }
+
+
+ if (!isfunction) {
+ ObjectTypeDB::get_integer_constant_list(t.obj_type,r_options);
+ }
+ List<MethodInfo> mi;
+ ObjectTypeDB::get_method_list(t.obj_type,&mi);
+ for (List<MethodInfo>::Element *E=mi.front();E;E=E->next()) {
+
+ if (E->get().name.begins_with("_"))
+ continue;
+
+ if (E->get().arguments.size())
+ options.insert(E->get().name+"(");
+ else
+ options.insert(E->get().name+"()");
+
+ }
+ } else {
+
+
+ if (t.type==Variant::INPUT_EVENT) {
+
+ //this is hardcoded otherwise it's not obvious
+ Set<String> exclude;
+
+ for(int i=0;i<InputEvent::TYPE_MAX;i++) {
+
+ InputEvent ie;
+ ie.type=InputEvent::Type(i);
+ static const char*evnames[]={
+ "# Common",
+ "# Key",
+ "# MouseMotion",
+ "# MouseButton",
+ "# JoyMotion",
+ "# JoyButton",
+ "# ScreenTouch",
+ "# ScreenDrag",
+ "# Action"
+ };
+
+ r_options->push_back(evnames[i]);
+
+ Variant v = ie;
+
+ if (i==0) {
+ List<MethodInfo> mi;
+ v.get_method_list(&mi);
+ for (List<MethodInfo>::Element *E=mi.front();E;E=E->next()) {
+ r_options->push_back(E->get().name+"(");
+
+ }
+
+ }
+
+ List<PropertyInfo> pi;
+ v.get_property_list(&pi);
+
+ for (List<PropertyInfo>::Element *E=pi.front();E;E=E->next()) {
+
+ if (i==0)
+ exclude.insert(E->get().name);
+ else if (exclude.has(E->get().name))
+ continue;
+
+ r_options->push_back(E->get().name);
+ }
+ }
+ return OK;
+ } else {
+ if (t.value.get_type()==Variant::NIL) {
+ Variant::CallError ce;
+ t.value=Variant::construct(t.type,NULL,0,ce);
+ }
+
+
+ if (!isfunction) {
+ List<PropertyInfo> pl;
+ t.value.get_property_list(&pl);
+ for (List<PropertyInfo>::Element *E=pl.front();E;E=E->next()) {
+
+ if (E->get().name.find("/")==-1)
+ options.insert(E->get().name);
+ }
+ }
+
+ List<MethodInfo> mi;
+ t.value.get_method_list(&mi);
+ for (List<MethodInfo>::Element *E=mi.front();E;E=E->next()) {
+ if (E->get().arguments.size())
+ options.insert(E->get().name+"(");
+ else
+ options.insert(E->get().name+"()");
+
+ }
+ }
+ }
}
- } else {
- r_options->push_back(E->key());
- }
+
+
+ } break;
+ case GDParser::COMPLETION_CALL_ARGUMENTS: {
+
+ _find_call_arguments(context,p.get_completion_node(),p.get_completion_line(),p.get_completion_argument_index(),options,r_call_hint);
+ } break;
+ case GDParser::COMPLETION_VIRTUAL_FUNC: {
+
+ GDCompletionIdentifier cid = _get_native_class(context);
+
+ if (cid.obj_type!=StringName()) {
+ List<MethodInfo> vm;
+ ObjectTypeDB::get_virtual_methods(cid.obj_type,&vm);
+ for(List<MethodInfo>::Element *E=vm.front();E;E=E->next()) {
+
+ MethodInfo &mi=E->get();
+ String m = mi.name;
+ if (m.find(":")!=-1)
+ m=m.substr(0,m.find(":"));
+ m+="(";
+
+ if (mi.arguments.size()) {
+ for(int i=0;i<mi.arguments.size();i++) {
+ if (i>0)
+ m+=", ";
+ String n =mi.arguments[i].name;
+ if (n.find(":")!=-1)
+ n=n.substr(0,n.find(":"));
+ m+=n;
+ }
+ }
+ m+="):";
+
+ options.insert(m);
+ }
+ }
+ } break;
+
+
+ }
+
+
+ for(Set<String>::Element *E=options.front();E;E=E->next()) {
+ r_options->push_back(E->get());
}
return OK;
}
+#else
+
+Error GDScriptLanguage::complete_code(const String& p_code, const String& p_base_path, Object*p_owner, List<String>* r_options, String &r_call_hint) {
+ return OK;
+}
+
+#endif
+
+
void GDScriptLanguage::auto_indent_code(String& p_code,int p_from_line,int p_to_line) const {
diff --git a/modules/gdscript/gd_functions.cpp b/modules/gdscript/gd_functions.cpp
index 0d11734bbd..fcfbbb04da 100644
--- a/modules/gdscript/gd_functions.cpp
+++ b/modules/gdscript/gd_functions.cpp
@@ -1166,6 +1166,8 @@ MethodInfo GDFunctions::get_info(Function p_func) {
MethodInfo mi("weakref",PropertyInfo(Variant::OBJECT,"obj"));
mi.return_val.type=Variant::OBJECT;
+ mi.return_val.name="WeakRef";
+
return mi;
} break;
@@ -1173,6 +1175,7 @@ MethodInfo GDFunctions::get_info(Function p_func) {
MethodInfo mi("funcref",PropertyInfo(Variant::OBJECT,"instance"),PropertyInfo(Variant::STRING,"funcname"));
mi.return_val.type=Variant::OBJECT;
+ mi.return_val.name="FuncRef";
return mi;
} break;
@@ -1231,6 +1234,7 @@ MethodInfo GDFunctions::get_info(Function p_func) {
MethodInfo mi("load",PropertyInfo(Variant::STRING,"path"));
mi.return_val.type=Variant::OBJECT;
+ mi.return_val.name="Resource";
return mi;
} break;
case INST2DICT: {
diff --git a/modules/gdscript/gd_parser.cpp b/modules/gdscript/gd_parser.cpp
index 904b6ba52f..aa2878f9e1 100644
--- a/modules/gdscript/gd_parser.cpp
+++ b/modules/gdscript/gd_parser.cpp
@@ -30,19 +30,6 @@
#include "print_string.h"
#include "io/resource_loader.h"
#include "os/file_access.h"
-/* TODO:
-
- *Property reduce constant expressions
- *Implement missing operators in variant?
- *constructor
- */
-
-/*
- todo:
- fix post ++,--
- make sure ++,-- don't work on constant expressions
- seems passing parent node as param is not needed
- */
template<class T>
T* GDParser::alloc_node() {
@@ -116,14 +103,20 @@ bool GDParser::_enter_indent_block(BlockNode* p_block) {
}
}
-bool GDParser::_parse_arguments(Node* p_parent,Vector<Node*>& p_args,bool p_static) {
+bool GDParser::_parse_arguments(Node* p_parent,Vector<Node*>& p_args,bool p_static,bool p_can_codecomplete) {
if (tokenizer->get_token()==GDTokenizer::TK_PARENTHESIS_CLOSE) {
tokenizer->advance();
} else {
+ int argidx=0;
+
while(true) {
+ if (tokenizer->get_token()==GDTokenizer::TK_CURSOR) {
+ _make_completable_call(argidx);
+ completion_node=p_parent;
+ }
Node*arg = _parse_expression(p_parent,p_static);
if (!arg)
@@ -144,6 +137,7 @@ bool GDParser::_parse_arguments(Node* p_parent,Vector<Node*>& p_args,bool p_stat
}
tokenizer->advance();
+ argidx++;
} else {
// something is broken
_set_error("Expected ',' or ')'");
@@ -158,6 +152,48 @@ bool GDParser::_parse_arguments(Node* p_parent,Vector<Node*>& p_args,bool p_stat
}
+void GDParser::_make_completable_call(int p_arg) {
+
+ completion_cursor=StringName();
+ completion_type=COMPLETION_CALL_ARGUMENTS;
+ completion_class=current_class;
+ completion_function=current_function;
+ completion_line=tokenizer->get_token_line();
+ completion_argument=p_arg;
+ completion_block=current_block;
+ tokenizer->advance();
+
+}
+
+
+bool GDParser::_get_completable_identifier(CompletionType p_type,StringName& identifier) {
+
+ identifier=StringName();
+ if (tokenizer->get_token()==GDTokenizer::TK_IDENTIFIER) {
+ identifier=tokenizer->get_token_identifier();
+ tokenizer->advance();
+ }
+ if (tokenizer->get_token()==GDTokenizer::TK_CURSOR) {
+
+ completion_cursor=identifier;
+ completion_type=p_type;
+ completion_class=current_class;
+ completion_function=current_function;
+ completion_line=tokenizer->get_token_line();
+ completion_block=current_block;
+ tokenizer->advance();
+
+ if (tokenizer->get_token()==GDTokenizer::TK_IDENTIFIER) {
+ identifier=identifier.operator String() + tokenizer->get_token_identifier().operator String();
+ tokenizer->advance();
+ }
+
+ return true;
+ }
+
+ return false;
+}
+
GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_allow_assign) {
@@ -199,6 +235,9 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_
tokenizer->advance();
expr=subexpr;
+ } else if (tokenizer->get_token()==GDTokenizer::TK_CURSOR) {
+ tokenizer->advance();
+ continue; //no point in cursor in the middle of expression
} else if (tokenizer->get_token()==GDTokenizer::TK_CONSTANT) {
@@ -327,12 +366,19 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_
Variant::Type bi_type = tokenizer->get_token_type();
tokenizer->advance(2);
- if (tokenizer->get_token()!=GDTokenizer::TK_IDENTIFIER) {
+
+ StringName identifier;
+
+ if (_get_completable_identifier(COMPLETION_BUILT_IN_TYPE_CONSTANT,identifier)) {
+
+ completion_built_in_constant=bi_type;
+ }
+
+ if (identifier==StringName()) {
_set_error("Built-in type constant expected after '.'");
return NULL;
}
- StringName identifier = tokenizer->get_token_identifier();
if (!Variant::has_numeric_constant(bi_type,identifier)) {
_set_error("Static constant '"+identifier.operator String()+"' not present in built-in type "+Variant::get_type_name(bi_type)+".");
@@ -342,7 +388,7 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_
ConstantNode *cn = alloc_node<ConstantNode>();
cn->value=Variant::get_numeric_constant_value(bi_type,identifier);
expr=cn;
- tokenizer->advance();
+
} else if (tokenizer->get_token(1)==GDTokenizer::TK_PARENTHESIS_OPEN && (tokenizer->get_token()==GDTokenizer::TK_BUILT_IN_TYPE || tokenizer->get_token()==GDTokenizer::TK_IDENTIFIER || tokenizer->get_token()==GDTokenizer::TK_BUILT_IN_FUNC)) {
//function or constructor
@@ -355,23 +401,35 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_
TypeNode *tn = alloc_node<TypeNode>();
tn->vtype=tokenizer->get_token_type();
op->arguments.push_back(tn);
+ tokenizer->advance(2);
} else if (tokenizer->get_token()==GDTokenizer::TK_BUILT_IN_FUNC) {
BuiltInFunctionNode *bn = alloc_node<BuiltInFunctionNode>();
bn->function=tokenizer->get_token_built_in_func();
op->arguments.push_back(bn);
+ tokenizer->advance(2);
} else {
SelfNode *self = alloc_node<SelfNode>();
op->arguments.push_back(self);
+ StringName identifier;
+ if (_get_completable_identifier(COMPLETION_FUNCTION,identifier)) {
+
+ }
+
IdentifierNode* id = alloc_node<IdentifierNode>();
- id->name=tokenizer->get_token_identifier();
+ id->name=identifier;
op->arguments.push_back(id);
+ tokenizer->advance(1);
}
- tokenizer->advance(2);
- if (!_parse_arguments(op,op->arguments,p_static))
+ if (tokenizer->get_token()==GDTokenizer::TK_CURSOR) {
+ _make_completable_call(0);
+ completion_node=op;
+
+ }
+ if (!_parse_arguments(op,op->arguments,p_static,true))
return NULL;
expr=op;
@@ -380,25 +438,27 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_
//identifier (reference)
const ClassNode* cln = static_cast<const ClassNode*>(get_parse_tree());
- bool bfn = false;
- StringName idn( tokenizer->get_token_identifier() );
-
- for( int i=0; i<cln->constant_expressions.size(); ++i ) {
-
- if( cln->constant_expressions[i].identifier == idn ) {
- tokenizer->advance();
- expr = cln->constant_expressions[i].expression;
- bfn = true;
- break;
- }
- }
-
- if( !bfn ) {
- IdentifierNode *id = alloc_node<IdentifierNode>();
- id->name = idn;
- tokenizer->advance();
- expr = id;
- }
+ bool bfn = false;
+ StringName identifier;
+ if (_get_completable_identifier(COMPLETION_IDENTIFIER,identifier)) {
+
+ }
+
+ for( int i=0; i<cln->constant_expressions.size(); ++i ) {
+
+ if( cln->constant_expressions[i].identifier == identifier ) {
+
+ expr = cln->constant_expressions[i].expression;
+ bfn = true;
+ break;
+ }
+ }
+
+ if ( !bfn ) {
+ IdentifierNode *id = alloc_node<IdentifierNode>();
+ id->name = identifier;
+ expr = id;
+ }
} else if (/*tokenizer->get_token()==GDTokenizer::TK_OP_ADD ||*/ tokenizer->get_token()==GDTokenizer::TK_OP_SUB || tokenizer->get_token()==GDTokenizer::TK_OP_NOT || tokenizer->get_token()==GDTokenizer::TK_OP_BIT_INVERT) {
@@ -600,7 +660,7 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_
expr=dict;
- } else if (tokenizer->get_token()==GDTokenizer::TK_PERIOD && tokenizer->get_token(1)==GDTokenizer::TK_IDENTIFIER && tokenizer->get_token(2)==GDTokenizer::TK_PARENTHESIS_OPEN) {
+ } else if (tokenizer->get_token()==GDTokenizer::TK_PERIOD && (tokenizer->get_token(1)==GDTokenizer::TK_IDENTIFIER || tokenizer->get_token(1)==GDTokenizer::TK_CURSOR) && tokenizer->get_token(2)==GDTokenizer::TK_PARENTHESIS_OPEN) {
// parent call
tokenizer->advance(); //goto identifier
@@ -611,12 +671,16 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_
/*SelfNode *self = alloc_node<SelfNode>();
op->arguments.push_back(self);
forbidden for now */
+ StringName identifier;
+ if (_get_completable_identifier(COMPLETION_PARENT_FUNCTION,identifier)) {
+ //indexing stuff
+ }
- IdentifierNode* id = alloc_node<IdentifierNode>();
- id->name=tokenizer->get_token_identifier();
+ IdentifierNode *id = alloc_node<IdentifierNode>();
+ id->name=identifier;
op->arguments.push_back(id);
- tokenizer->advance(2);
+ tokenizer->advance(1);
if (!_parse_arguments(op,op->arguments,p_static))
return NULL;
@@ -651,7 +715,7 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_
//indexing using "."
- if (tokenizer->get_token(1)!=GDTokenizer::TK_IDENTIFIER && tokenizer->get_token(1)!=GDTokenizer::TK_BUILT_IN_FUNC ) {
+ if (tokenizer->get_token(1)!=GDTokenizer::TK_CURSOR && tokenizer->get_token(1)!=GDTokenizer::TK_IDENTIFIER && tokenizer->get_token(1)!=GDTokenizer::TK_BUILT_IN_FUNC ) {
_set_error("Expected identifier as member");
return NULL;
} else if (tokenizer->get_token(2)==GDTokenizer::TK_PARENTHESIS_OPEN) {
@@ -659,37 +723,67 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_
OperatorNode * op = alloc_node<OperatorNode>();
op->op=OperatorNode::OP_CALL;
+ tokenizer->advance();
+
IdentifierNode * id = alloc_node<IdentifierNode>();
- if (tokenizer->get_token(1)==GDTokenizer::TK_BUILT_IN_FUNC ) {
+ if (tokenizer->get_token()==GDTokenizer::TK_BUILT_IN_FUNC ) {
//small hack so built in funcs don't obfuscate methods
- id->name=GDFunctions::get_func_name(tokenizer->get_token_built_in_func(1));
+ id->name=GDFunctions::get_func_name(tokenizer->get_token_built_in_func());
+ tokenizer->advance();
+
} else {
- id->name=tokenizer->get_token_identifier(1);
+ StringName identifier;
+ if (_get_completable_identifier(COMPLETION_METHOD,identifier)) {
+ completion_node=op;
+ //indexing stuff
+ }
+
+ id->name=identifier;
}
op->arguments.push_back(expr); // call what
op->arguments.push_back(id); // call func
//get arguments
- tokenizer->advance(3);
- if (!_parse_arguments(op,op->arguments,p_static))
+ tokenizer->advance(1);
+ if (tokenizer->get_token()==GDTokenizer::TK_CURSOR) {
+ _make_completable_call(0);
+ completion_node=op;
+
+ }
+ if (!_parse_arguments(op,op->arguments,p_static,true))
return NULL;
expr=op;
} else {
//simple indexing!
+
+
OperatorNode * op = alloc_node<OperatorNode>();
op->op=OperatorNode::OP_INDEX_NAMED;
+ tokenizer->advance();
+
+
+ StringName identifier;
+ if (_get_completable_identifier(COMPLETION_INDEX,identifier)) {
+
+ if (identifier==StringName()) {
+ identifier="@temp"; //so it parses allright
+ }
+ completion_node=op;
+
+ //indexing stuff
+ }
IdentifierNode * id = alloc_node<IdentifierNode>();
- id->name=tokenizer->get_token_identifier(1);
+ id->name=identifier;
op->arguments.push_back(expr);
op->arguments.push_back(id);
expr=op;
- tokenizer->advance(2);
+
}
} else if (tokenizer->get_token()==GDTokenizer::TK_BRACKET_OPEN) {
@@ -1442,6 +1536,7 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) {
cf_if->arguments.push_back(condition);
cf_if->body = alloc_node<BlockNode>();
+ cf_if->body->parent_block=p_block;
p_block->sub_blocks.push_back(cf_if->body);
if (!_enter_indent_block(cf_if->body)) {
@@ -1449,7 +1544,10 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) {
return;
}
+ current_block=cf_if->body;
_parse_block(cf_if->body,p_static);
+ current_block=p_block;
+
if (error_set)
return;
p_block->statements.push_back(cf_if);
@@ -1476,6 +1574,7 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) {
tokenizer->advance();
cf_if->body_else=alloc_node<BlockNode>();
+ cf_if->body_else->parent_block=p_block;
p_block->sub_blocks.push_back(cf_if->body_else);
ControlFlowNode *cf_else = alloc_node<ControlFlowNode>();
@@ -1491,6 +1590,7 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) {
cf_if->body_else->statements.push_back(cf_else);
cf_if=cf_else;
cf_if->body=alloc_node<BlockNode>();
+ cf_if->body->parent_block=p_block;
p_block->sub_blocks.push_back(cf_if->body);
@@ -1499,7 +1599,9 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) {
return;
}
+ current_block=cf_else->body;
_parse_block(cf_else->body,p_static);
+ current_block=p_block;
if (error_set)
return;
@@ -1515,13 +1617,16 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) {
tokenizer->advance();
cf_if->body_else=alloc_node<BlockNode>();
+ cf_if->body_else->parent_block=p_block;
p_block->sub_blocks.push_back(cf_if->body_else);
if (!_enter_indent_block(cf_if->body_else)) {
p_block->end_line=tokenizer->get_token_line();
return;
}
+ current_block=cf_if->body_else;
_parse_block(cf_if->body_else,p_static);
+ current_block=p_block;
if (error_set)
return;
@@ -1548,6 +1653,7 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) {
cf_while->arguments.push_back(condition);
cf_while->body = alloc_node<BlockNode>();
+ cf_while->body->parent_block=p_block;
p_block->sub_blocks.push_back(cf_while->body);
if (!_enter_indent_block(cf_while->body)) {
@@ -1555,7 +1661,9 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) {
return;
}
+ current_block=cf_while->body;
_parse_block(cf_while->body,p_static);
+ current_block=p_block;
if (error_set)
return;
p_block->statements.push_back(cf_while);
@@ -1592,6 +1700,7 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) {
cf_for->arguments.push_back(container);
cf_for->body = alloc_node<BlockNode>();
+ cf_for->body->parent_block=p_block;
p_block->sub_blocks.push_back(cf_for->body);
if (!_enter_indent_block(cf_for->body)) {
@@ -1599,7 +1708,10 @@ void GDParser::_parse_block(BlockNode *p_block,bool p_static) {
return;
}
+ current_block=cf_for->body;
_parse_block(cf_for->body,p_static);
+ current_block=p_block;
+
if (error_set)
return;
p_block->statements.push_back(cf_for);
@@ -1865,7 +1977,9 @@ void GDParser::_parse_class(ClassNode *p_class) {
ClassNode *newclass = alloc_node<ClassNode>();
newclass->initializer = alloc_node<BlockNode>();
+ newclass->initializer->parent_class=newclass;
newclass->name=name;
+ newclass->owner=p_class;
p_class->subclasses.push_back(newclass);
@@ -1882,7 +1996,9 @@ void GDParser::_parse_class(ClassNode *p_class) {
_set_error("Indented block expected.");
return;
}
+ current_class=newclass;
_parse_class(newclass);
+ current_class=p_class;
} break;
/* this is for functions....
@@ -1911,14 +2027,20 @@ void GDParser::_parse_class(ClassNode *p_class) {
}
- if (tokenizer->get_token(1)!=GDTokenizer::TK_IDENTIFIER) {
+ tokenizer->advance();
+ StringName name;
+
+ if (_get_completable_identifier(COMPLETION_VIRTUAL_FUNC,name)) {
+
+ }
+
+
+ if (name==StringName()) {
_set_error("Expected identifier after 'func' (syntax: 'func <identifier>([arguments]):' ).");
return;
}
- StringName name = tokenizer->get_token_identifier(1);
-
for(int i=0;i<p_class->functions.size();i++) {
if (p_class->functions[i]->name==name) {
_set_error("Function '"+String(name)+"' already exists in this class (at line: "+itos(p_class->functions[i]->line)+").");
@@ -1929,7 +2051,7 @@ void GDParser::_parse_class(ClassNode *p_class) {
_set_error("Function '"+String(name)+"' already exists in this class (at line: "+itos(p_class->static_functions[i]->line)+").");
}
}
- tokenizer->advance(2);
+
if (tokenizer->get_token()!=GDTokenizer::TK_PARENTHESIS_OPEN) {
@@ -2020,6 +2142,7 @@ void GDParser::_parse_class(ClassNode *p_class) {
tokenizer->advance();
BlockNode *block = alloc_node<BlockNode>();
+ block->parent_class=p_class;
if (name=="_init") {
@@ -2095,8 +2218,12 @@ void GDParser::_parse_class(ClassNode *p_class) {
p_class->functions.push_back(function);
- _parse_block(block,_static);
+ current_function=function;
function->body=block;
+ current_block=block;
+ _parse_block(block,_static);
+ current_block=NULL;
+
//arguments
} break;
case GDTokenizer::TK_PR_EXPORT: {
@@ -2401,7 +2528,9 @@ void GDParser::_parse_class(ClassNode *p_class) {
}
member.identifier=tokenizer->get_token_identifier();
+ member.expression=NULL;
member._export.name=member.identifier;
+ member.line=tokenizer->get_token_line();
tokenizer->advance();
if (tokenizer->get_token()==GDTokenizer::TK_OP_ASSIGN) {
@@ -2417,6 +2546,8 @@ void GDParser::_parse_class(ClassNode *p_class) {
if (!subexpr)
return;
+ member.expression=subexpr;
+
if (autoexport) {
if (subexpr->type==Node::TYPE_ARRAY) {
@@ -2608,6 +2739,8 @@ Error GDParser::_parse(const String& p_base_path) {
//assume class
ClassNode *main_class = alloc_node<ClassNode>();
main_class->initializer = alloc_node<BlockNode>();
+ main_class->initializer->parent_class=main_class;
+ current_class=main_class;
_parse_class(main_class);
@@ -2625,6 +2758,15 @@ Error GDParser::_parse(const String& p_base_path) {
Error GDParser::parse_bytecode(const Vector<uint8_t> &p_bytecode,const String& p_base_path, const String &p_self_path) {
+ completion_type=COMPLETION_NONE;
+ completion_node=NULL;
+ completion_class=NULL;
+ completion_function=NULL;
+ completion_block=NULL;
+ current_block=NULL;
+ current_class=NULL;
+ current_function=NULL;
+
self_path=p_self_path;
GDTokenizerBuffer *tb = memnew( GDTokenizerBuffer );
tb->set_code_buffer(p_bytecode);
@@ -2638,6 +2780,16 @@ Error GDParser::parse_bytecode(const Vector<uint8_t> &p_bytecode,const String& p
Error GDParser::parse(const String& p_code, const String& p_base_path, bool p_just_validate, const String &p_self_path) {
+ completion_type=COMPLETION_NONE;
+ completion_node=NULL;
+ completion_class=NULL;
+ completion_function=NULL;
+ completion_block=NULL;
+ current_block=NULL;
+ current_class=NULL;
+
+ current_function=NULL;
+
self_path=p_self_path;
GDTokenizerText *tt = memnew( GDTokenizerText );
tt->set_code(p_code);
@@ -2667,6 +2819,16 @@ void GDParser::clear() {
head=NULL;
list=NULL;
+ completion_type=COMPLETION_NONE;
+ completion_node=NULL;
+ completion_class=NULL;
+ completion_function=NULL;
+ completion_block=NULL;
+ current_block=NULL;
+ current_class=NULL;
+
+ current_function=NULL;
+
validating=false;
error_set=false;
tab_level.clear();
@@ -2680,6 +2842,52 @@ void GDParser::clear() {
}
+
+GDParser::CompletionType GDParser::get_completion_type() {
+
+ return completion_type;
+}
+
+StringName GDParser::get_completion_cursor() {
+
+ return completion_cursor;
+}
+
+int GDParser::get_completion_line() {
+
+ return completion_line;
+}
+
+Variant::Type GDParser::get_completion_built_in_constant(){
+
+ return completion_built_in_constant;
+}
+
+GDParser::Node *GDParser::get_completion_node(){
+
+ return completion_node;
+}
+
+GDParser::BlockNode *GDParser::get_completion_block() {
+
+ return completion_block;
+}
+
+GDParser::ClassNode *GDParser::get_completion_class(){
+
+ return completion_class;
+}
+
+GDParser::FunctionNode *GDParser::get_completion_function(){
+
+ return completion_function;
+}
+
+int GDParser::get_completion_argument_index() {
+
+ return completion_argument;
+}
+
GDParser::GDParser() {
head=NULL;
diff --git a/modules/gdscript/gd_parser.h b/modules/gdscript/gd_parser.h
index 3f82cafc61..44e7b55323 100644
--- a/modules/gdscript/gd_parser.h
+++ b/modules/gdscript/gd_parser.h
@@ -84,6 +84,8 @@ public:
StringName identifier;
StringName setter;
StringName getter;
+ int line;
+ Node *expression;
};
struct Constant {
StringName identifier;
@@ -96,10 +98,11 @@ public:
Vector<FunctionNode*> functions;
Vector<FunctionNode*> static_functions;
BlockNode *initializer;
+ ClassNode *owner;
//Vector<Node*> initializers;
int end_line;
- ClassNode() { tool=false; type=TYPE_CLASS; extends_used=false; end_line=-1;}
+ ClassNode() { tool=false; type=TYPE_CLASS; extends_used=false; end_line=-1; owner=NULL;}
};
@@ -118,6 +121,8 @@ public:
struct BlockNode : public Node {
+ ClassNode *parent_class;
+ BlockNode *parent_block;
Map<StringName,int> locals;
List<Node*> statements;
Vector<StringName> variables;
@@ -126,7 +131,7 @@ public:
//the following is useful for code completion
List<BlockNode*> sub_blocks;
int end_line;
- BlockNode() { type=TYPE_BLOCK; end_line=-1;}
+ BlockNode() { type=TYPE_BLOCK; end_line=-1; parent_block=NULL; parent_class=NULL; }
};
struct TypeNode : public Node {
@@ -349,6 +354,19 @@ public:
};
*/
+ enum CompletionType {
+ COMPLETION_NONE,
+ COMPLETION_BUILT_IN_TYPE_CONSTANT,
+ COMPLETION_FUNCTION,
+ COMPLETION_IDENTIFIER,
+ COMPLETION_PARENT_FUNCTION,
+ COMPLETION_METHOD,
+ COMPLETION_CALL_ARGUMENTS,
+ COMPLETION_INDEX,
+ COMPLETION_VIRTUAL_FUNC
+ };
+
+
private:
@@ -375,12 +393,31 @@ private:
String base_path;
String self_path;
+
+ ClassNode *current_class;
+ FunctionNode *current_function;
+ BlockNode *current_block;
+
+ bool _get_completable_identifier(CompletionType p_type,StringName& identifier);
+ void _make_completable_call(int p_arg);
+
+ CompletionType completion_type;
+ StringName completion_cursor;
+ bool completion_static;
+ Variant::Type completion_built_in_constant;
+ Node *completion_node;
+ ClassNode *completion_class;
+ FunctionNode *completion_function;
+ BlockNode *completion_block;
+ int completion_line;
+ int completion_argument;
+
PropertyInfo current_export;
void _set_error(const String& p_error, int p_line=-1, int p_column=-1);
- bool _parse_arguments(Node* p_parent,Vector<Node*>& p_args,bool p_static);
+ bool _parse_arguments(Node* p_parent, Vector<Node*>& p_args, bool p_static, bool p_can_codecomplete=false);
bool _enter_indent_block(BlockNode *p_block=NULL);
bool _parse_newline();
Node* _parse_expression(Node *p_parent,bool p_static,bool p_allow_assign=false);
@@ -404,6 +441,19 @@ public:
const Node *get_parse_tree() const;
+ //completion info
+
+ CompletionType get_completion_type();
+ StringName get_completion_cursor();
+ int get_completion_line();
+ Variant::Type get_completion_built_in_constant();
+ Node *get_completion_node();
+ ClassNode *get_completion_class();
+ BlockNode *get_completion_block();
+ FunctionNode *get_completion_function();
+ int get_completion_argument_index();
+
+
void clear();
GDParser();
~GDParser();
diff --git a/modules/gdscript/gd_script.cpp b/modules/gdscript/gd_script.cpp
index 982584c75c..0aa115ffbc 100644
--- a/modules/gdscript/gd_script.cpp
+++ b/modules/gdscript/gd_script.cpp
@@ -820,7 +820,7 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a
gdfs->state.stack.resize(alloca_size);
//copy variant stack
for(int i=0;i<_stack_size;i++) {
- memnew_placement(&stack[sizeof(Variant)*i],Variant(stack[i]));
+ memnew_placement(&gdfs->state.stack[sizeof(Variant)*i],Variant(stack[i]));
}
gdfs->state.stack_size=_stack_size;
gdfs->state.self=self;
@@ -1440,8 +1440,8 @@ GDInstance* GDScript::_create_instance(const Variant** p_args,int p_argcount,Obj
if (err.error!=Variant::CallError::CALL_OK) {
instance->script=Ref<GDScript>();
+ instance->owner->set_script_instance(NULL);
instances.erase(p_owner);
- memdelete(instance);
ERR_FAIL_COND_V(err.error!=Variant::CallError::CALL_OK, NULL); //error consrtucting
}
@@ -1756,6 +1756,7 @@ bool GDScript::_update_exports() {
return changed;
#endif
+ return false;
}
void GDScript::update_exports() {
diff --git a/modules/gdscript/gd_script.h b/modules/gdscript/gd_script.h
index f4e4dffaa5..5574b30d44 100644
--- a/modules/gdscript/gd_script.h
+++ b/modules/gdscript/gd_script.h
@@ -129,6 +129,10 @@ friend class GDCompiler;
const char*_func_cname;
#endif
+#ifdef TOOLS_ENABLED
+ Vector<StringName> arg_names;
+#endif
+
List<StackDebug> stack_debug;
_FORCE_INLINE_ Variant *_get_variant(int p_address,GDInstance *p_instance,GDScript *p_script,Variant &self,Variant *p_stack,String& r_error) const;
@@ -169,6 +173,19 @@ public:
_FORCE_INLINE_ bool is_empty() const { return _code_size==0; }
int get_argument_count() const { return _argument_count; }
+ StringName get_argument_name(int p_idx) const {
+#ifdef TOOLS_ENABLED
+ ERR_FAIL_INDEX_V(p_idx,arg_names.size(),StringName());
+ return arg_names[p_idx];
+#endif
+ return StringName();
+
+ }
+ Variant get_default_argument(int p_idx) const {
+ ERR_FAIL_INDEX_V(p_idx,default_arguments.size(),Variant());
+ return default_arguments[p_idx];
+ }
+
Variant call(GDInstance *p_instance,const Variant **p_args, int p_argcount,Variant::CallError& r_err,CallState *p_state=NULL);
GDFunction();
@@ -293,6 +310,7 @@ protected:
static void _bind_methods();
public:
+ bool is_valid() const { return valid; }
const Map<StringName,Ref<GDScript> >& get_subclasses() const { return subclasses; }
const Map<StringName,Variant >& get_constants() const { return constants; }
@@ -488,7 +506,7 @@ public:
virtual bool has_named_classes() const;
virtual int find_function(const String& p_function,const String& p_code) const;
virtual String make_function(const String& p_class,const String& p_name,const StringArray& p_args) const;
- virtual Error complete_keyword(const String& p_code, int p_line, const String& p_base_path,const String& p_keyword, List<String>* r_options);
+ virtual Error complete_code(const String& p_code, const String& p_base_path, Object*p_owner,List<String>* r_options,String& r_call_hint);
virtual void auto_indent_code(String& p_code,int p_from_line,int p_to_line) const;
/* DEBUGGER FUNCTIONS */
diff --git a/modules/gdscript/gd_tokenizer.cpp b/modules/gdscript/gd_tokenizer.cpp
index 0f6ee41616..6f968f2080 100644
--- a/modules/gdscript/gd_tokenizer.cpp
+++ b/modules/gdscript/gd_tokenizer.cpp
@@ -110,7 +110,8 @@ const char* GDTokenizer::token_names[TK_MAX]={
"':'",
"'\\n'",
"Error",
-"EOF"};
+"EOF",
+"Cursor"};
const char *GDTokenizer::get_token_name(Token p_token) {
@@ -648,6 +649,9 @@ void GDTokenizerText::_advance() {
}
} break;
+ case 0xFFFF: {
+ _make_token(TK_CURSOR);
+ } break;
default: {
if (_is_number(GETCHAR(0)) || (GETCHAR(0)=='.' && _is_number(GETCHAR(1)))) {
diff --git a/modules/gdscript/gd_tokenizer.h b/modules/gdscript/gd_tokenizer.h
index fe7bfa73ca..ff59c249a7 100644
--- a/modules/gdscript/gd_tokenizer.h
+++ b/modules/gdscript/gd_tokenizer.h
@@ -118,6 +118,7 @@ public:
TK_NEWLINE,
TK_ERROR,
TK_EOF,
+ TK_CURSOR, //used for code completion
TK_MAX
};
diff --git a/modules/gridmap/grid_map_editor_plugin.cpp b/modules/gridmap/grid_map_editor_plugin.cpp
index 140718a91a..f2afffd321 100644
--- a/modules/gridmap/grid_map_editor_plugin.cpp
+++ b/modules/gridmap/grid_map_editor_plugin.cpp
@@ -1192,8 +1192,8 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) {
undo_redo=p_editor->get_undo_redo();
int mw = EDITOR_DEF("grid_map/palette_min_width",230);
- EmptyControl *ec = memnew( EmptyControl);
- ec->set_minsize(Size2(mw,0));
+ Control *ec = memnew( Control);
+ ec->set_custom_minimum_size(Size2(mw,0));
add_child(ec);
@@ -1222,9 +1222,9 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) {
options->get_popup()->add_item("Cursor Rotate X",MENU_OPTION_CURSOR_ROTATE_X,KEY_A);
options->get_popup()->add_item("Cursor Rotate Y",MENU_OPTION_CURSOR_ROTATE_Y,KEY_S);
options->get_popup()->add_item("Cursor Rotate Z",MENU_OPTION_CURSOR_ROTATE_Z,KEY_D);
- options->get_popup()->add_item("Cursor Back Rotate X",MENU_OPTION_CURSOR_ROTATE_X,KEY_ALT+KEY_A);
- options->get_popup()->add_item("Cursor Back Rotate Y",MENU_OPTION_CURSOR_ROTATE_Y,KEY_ALT+KEY_S);
- options->get_popup()->add_item("Cursor Back Rotate Z",MENU_OPTION_CURSOR_ROTATE_Z,KEY_ALT+KEY_D);
+ options->get_popup()->add_item("Cursor Back Rotate X",MENU_OPTION_CURSOR_ROTATE_X,KEY_MASK_SHIFT+KEY_A);
+ options->get_popup()->add_item("Cursor Back Rotate Y",MENU_OPTION_CURSOR_ROTATE_Y,KEY_MASK_SHIFT+KEY_S);
+ options->get_popup()->add_item("Cursor Back Rotate Z",MENU_OPTION_CURSOR_ROTATE_Z,KEY_MASK_SHIFT+KEY_D);
options->get_popup()->add_item("Cursor Clear Rotation",MENU_OPTION_CURSOR_CLEAR_ROTATION,KEY_W);
options->get_popup()->add_separator();
options->get_popup()->add_check_item("Duplicate Selects",MENU_OPTION_DUPLICATE_SELECTS);
diff --git a/modules/gridmap/register_types.cpp b/modules/gridmap/register_types.cpp
index 3c3c8aa98f..887687a37b 100644
--- a/modules/gridmap/register_types.cpp
+++ b/modules/gridmap/register_types.cpp
@@ -27,16 +27,20 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "register_types.h"
+#ifndef _3D_DISABLED
#include "object_type_db.h"
#include "grid_map.h"
#include "grid_map_editor_plugin.h"
+#endif
void register_gridmap_types() {
+#ifndef _3D_DISABLED
ObjectTypeDB::register_type<GridMap>();
#ifdef TOOLS_ENABLED
EditorPlugins::add_by_type<GridMapEditorPlugin>();
#endif
+#endif
}
diff --git a/platform/android/detect.py b/platform/android/detect.py
index 417f3e68ab..695caf1e5d 100644
--- a/platform/android/detect.py
+++ b/platform/android/detect.py
@@ -124,11 +124,11 @@ def configure(env):
# env['CCFLAGS'] = string.split('-DNO_THREADS -MMD -MP -MF -fpic -ffunction-sections -funwind-tables -fstack-protector -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ -Wno-psabi -march=armv5te -mtune=xscale -msoft-float -fno-exceptions -mthumb -fno-strict-aliasing -DANDROID -Wa,--noexecstack -DGLES2_ENABLED ')
if env['x86']=='yes':
- env['CCFLAGS'] = string.split('-DNO_STATVFS -MMD -MP -MF -fpic -ffunction-sections -funwind-tables -fstack-protector -D__GLIBC__ -Wno-psabi -ftree-vectorize -funsafe-math-optimizations -fno-strict-aliasing -DANDROID -Wa,--noexecstack -DGLES2_ENABLED -DGLES1_ENABLED')
+ env['CCFLAGS'] = string.split('-DNO_STATVFS -MMD -MP -MF -fpic -ffunction-sections -funwind-tables -fstack-protector -fvisibility=hidden -D__GLIBC__ -Wno-psabi -ftree-vectorize -funsafe-math-optimizations -fno-strict-aliasing -DANDROID -Wa,--noexecstack -DGLES2_ENABLED -DGLES1_ENABLED')
elif env["armv6"]!="no":
- env['CCFLAGS'] = string.split('-DNO_STATVFS -MMD -MP -MF -fpic -ffunction-sections -funwind-tables -fstack-protector -D__ARM_ARCH_6__ -D__GLIBC__ -Wno-psabi -march=armv6 -mfpu=vfp -mfloat-abi=softfp -funsafe-math-optimizations -fno-strict-aliasing -DANDROID -Wa,--noexecstack -DGLES2_ENABLED -DGLES1_ENABLED')
+ env['CCFLAGS'] = string.split('-DNO_STATVFS -MMD -MP -MF -fpic -ffunction-sections -funwind-tables -fstack-protector -fvisibility=hidden -D__ARM_ARCH_6__ -D__GLIBC__ -Wno-psabi -march=armv6 -mfpu=vfp -mfloat-abi=softfp -funsafe-math-optimizations -fno-strict-aliasing -DANDROID -Wa,--noexecstack -DGLES2_ENABLED -DGLES1_ENABLED')
else:
- env['CCFLAGS'] = string.split('-DNO_STATVFS -MMD -MP -MF -fpic -ffunction-sections -funwind-tables -fstack-protector -D__ARM_ARCH_7__ -D__GLIBC__ -Wno-psabi -march=armv6 -mfpu=neon -mfloat-abi=softfp -ftree-vectorize -funsafe-math-optimizations -fno-strict-aliasing -DANDROID -Wa,--noexecstack -DGLES2_ENABLED -DGLES1_ENABLED')
+ env['CCFLAGS'] = string.split('-DNO_STATVFS -MMD -MP -MF -fpic -ffunction-sections -funwind-tables -fstack-protector -fvisibility=hidden -D__ARM_ARCH_7__ -D__GLIBC__ -Wno-psabi -march=armv6 -mfpu=neon -mfloat-abi=softfp -ftree-vectorize -funsafe-math-optimizations -fno-strict-aliasing -DANDROID -Wa,--noexecstack -DGLES2_ENABLED -DGLES1_ENABLED')
env.Append(LDPATH=[ld_path])
env.Append(LIBS=['OpenSLES'])
diff --git a/platform/android/java/src/com/android/godot/Godot.java b/platform/android/java/src/com/android/godot/Godot.java
index f6cd57f4f3..1a7659a473 100644
--- a/platform/android/java/src/com/android/godot/Godot.java
+++ b/platform/android/java/src/com/android/godot/Godot.java
@@ -358,7 +358,7 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC
GodotLib.initialize(this,io.needsReloadHooks(),command_line);
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
- mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_NORMAL);
+ mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_GAME);
result_callback = null;
diff --git a/platform/android/java/src/com/android/godot/GodotIO.java b/platform/android/java/src/com/android/godot/GodotIO.java
index d149916893..ff0eb5edcc 100644
--- a/platform/android/java/src/com/android/godot/GodotIO.java
+++ b/platform/android/java/src/com/android/godot/GodotIO.java
@@ -438,8 +438,26 @@ public class GodotIO {
try {
Log.v("MyApp", "TRYING TO OPEN URI: " + p_uri);
- Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(p_uri));
- activity.startActivity(myIntent);
+ String path = p_uri;
+ String type="";
+ if (path.startsWith("/")) {
+ //absolute path to filesystem, prepend file://
+ path="file://"+path;
+ if (p_uri.endsWith(".png") || p_uri.endsWith(".jpg") || p_uri.endsWith(".gif") || p_uri.endsWith(".webp")) {
+
+ type="image/*";
+ }
+ }
+
+ Intent intent = new Intent();
+ intent.setAction(Intent.ACTION_VIEW);
+ if (!type.equals("")) {
+ intent.setDataAndType(Uri.parse(path), type);
+ } else {
+ intent.setData(Uri.parse(path));
+ }
+
+ activity.startActivity(intent);
return 0;
} catch (ActivityNotFoundException e) {
diff --git a/platform/iphone/detect.py b/platform/iphone/detect.py
index 93345be730..f8d86a3c7a 100644
--- a/platform/iphone/detect.py
+++ b/platform/iphone/detect.py
@@ -54,20 +54,35 @@ def configure(env):
env['AR'] = 'ar'
import string
- #env['CCFLAGS'] = string.split('-arch armv7 -Wall -fno-strict-aliasing -fno-common -D__IPHONE_OS_VERSION_MIN_REQUIRED=20000 -isysroot $IPHONESDK -fvisibility=hidden -mmacosx-version-min=10.5 -DCUSTOM_MATRIX_TRANSFORM_H=\\\"build/iphone/matrix4_iphone.h\\\" -DCUSTOM_VECTOR3_TRANSFORM_H=\\\"build/iphone/vector3_iphone.h\\\" -DNO_THUMB')
- env['CCFLAGS'] = string.split('-fno-objc-arc -arch armv7 -fmessage-length=0 -fno-strict-aliasing -fdiagnostics-print-source-range-info -fdiagnostics-show-category=id -fdiagnostics-parseable-fixits -Wno-trigraphs -fpascal-strings -Wmissing-prototypes -Wreturn-type -Wparentheses -Wswitch -Wno-unused-parameter -Wunused-variable -Wunused-value -Wno-shorten-64-to-32 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk -gdwarf-2 -fvisibility=hidden -Wno-sign-conversion -mthumb "-DIBOutlet=__attribute__((iboutlet))" "-DIBOutletCollection(ClassName)=__attribute__((iboutletcollection(ClassName)))" "-DIBAction=void)__attribute__((ibaction)" -miphoneos-version-min=4.3 -MMD -MT dependencies -isysroot $IPHONESDK')
-
-
-#/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/clang++ fno-objc-arc -arch armv7 -fmessage-length=0 -fdiagnostics-print-source-range-info -fdiagnostics-show-category=id -fdiagnostics-parseable-fixits -Wno-trigraphs -fpascal-strings -Wmissing-prototypes -Wreturn-type -Wparentheses -Wswitch -Wno-unused-parameter -Wunused-variable -Wunused-value -Wno-shorten-64-to-32 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk -gdwarf-2 -fvisibility=hidden -Wno-sign-conversion -mthumb "-DIBOutlet=__attribute__((iboutlet))" "-DIBOutletCollection(ClassName)=__attribute__((iboutletcollection(ClassName)))" "-DIBAction=void)__attribute__((ibaction)" -miphoneos-version-min=4.3 -MMD -MT dependencies -v -Os -ffast-math -DSTOREKIT_ENABLED -DIPHONE_ENABLED -DUNIX_ENABLED -DGLES2_ENABLED -DNO_THREADS -DMODULE_GRIDMAP_ENABLED -DMUSEPACK_ENABLED -DOLD_SCENE_FORMAT_ENABLED -DSQUIRREL_ENABLED -DVORBIS_ENABLED -DTHEORA_ENABLED -DPNG_ENABLED -DDDS_ENABLED -DPVR_ENABLED -DJPG_ENABLED -DSPEEX_ENABLED -DTOOLS_ENABLED -DGDSCRIPT_ENABLED -DMINIZIP_ENABLED -DXML_ENABLED -Icore -Icore/math -Itools -Idrivers -I. -Iplatform/iphone -Iplatform/iphone/include -Iplatform/iphone/scoreloop/SDKs -I/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/System/Library/Frameworks/OpenGLES.framework/Headers -Iscript/squirrel/src -Iscript/vorbis script/gdscript/gd_script.cpp
-#/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/clang -x objective-c -arch armv7 -fmessage-length=0 -fdiagnostics-print-source-range-info -fdiagnostics-show-category=id -fdiagnostics-parseable-fixits -std=gnu99 -fobjc-arc -Wno-trigraphs -fpascal-strings -Os -Wmissing-prototypes -Wreturn-type -Wparentheses -Wswitch -Wno-unused-parameter -Wunused-variable -Wunused-value -Wno-shorten-64-to-32 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk -gdwarf-2 -fvisibility=hidden -Wno-sign-conversion -mthumb "-DIBOutlet=__attribute__((iboutlet))" "-DIBOutletCollection(ClassName)=__attribute__((iboutletcollection(ClassName)))" "-DIBAction=void)__attribute__((ibaction)" -miphoneos-version-min=4.3 -iquote /Users/red/test2/build/test2.build/Release-iphoneos/test2.build/test2-generated-files.hmap -I/Users/red/test2/build/test2.build/Release-iphoneos/test2.build/test2-own-target-headers.hmap -I/Users/red/test2/build/test2.build/Release-iphoneos/test2.build/test2-all-target-headers.hmap -iquote /Users/red/test2/build/test2.build/Release-iphoneos/test2.build/test2-project-headers.hmap -I/Users/red/test2/build/Release-iphoneos/include -I/Users/red/test2/build/test2.build/Release-iphoneos/test2.build/DerivedSources/armv7 -I/Users/red/test2/build/test2.build/Release-iphoneos/test2.build/DerivedSources -F/Users/red/test2/build/Release-iphoneos -DNS_BLOCK_ASSERTIONS=1 -include /var/folders/LX/LXYXHTeSHSqbkhuPJRIsuE+++TI/-Caches-/com.apple.Xcode.501/SharedPrecompiledHeaders/test2-Prefix-dvdhnltoisfpmyalexovdrmfyeky/test2-Prefix.pch -MMD -MT dependencies -MF /Users/red/test2/build/test2.build/Release-iphoneos/test2.build/Objects-normal/armv7/main.d -c /Users/red/test2/test2/main.m -o /Users/red/test2/build/test2.build/Release-iphoneos/test2.build/Objects-normal/armv7/main.o
-
-
-
-
+ if (env["bits"]=="64"):
+ #env['CCFLAGS'] = string.split('-arch arm64 -fmessage-length=0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -Wno-trigraphs -fpascal-strings -O0 -Wno-missing-field-initializers -Wno-missing-prototypes -Wno-return-type -Wno-non-virtual-dtor -Wno-overloaded-virtual -Wno-exit-time-destructors -Wno-missing-braces -Wparentheses -Wswitch -Wno-unused-function -Wno-unused-label -Wno-unused-parameter -Wno-unused-variable -Wunused-value -Wno-empty-body -Wno-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wno-constant-conversion -Wno-int-conversion -Wno-bool-conversion -Wno-enum-conversion -Wshorten-64-to-32 -Wno-newline-eof -Wno-c++11-extensions -fstrict-aliasing -Wdeprecated-declarations -Winvalid-offsetof -g -Wno-sign-conversion -miphoneos-version-min=5.1.1 -Wmost -Wno-four-char-constants -Wno-unknown-pragmas -Wno-invalid-offsetof -ffast-math -m64 -DDEBUG -D_DEBUG -MMD -MT dependencies -isysroot $IPHONESDK')
+ env['CCFLAGS'] = string.split('-fno-objc-arc -arch arm64 -fmessage-length=0 -fno-strict-aliasing -fdiagnostics-print-source-range-info -fdiagnostics-show-category=id -fdiagnostics-parseable-fixits -Wno-trigraphs -fpascal-strings -Wmissing-prototypes -Wreturn-type -Wparentheses -Wswitch -Wno-unused-parameter -Wunused-variable -Wunused-value -Wno-shorten-64-to-32 -gdwarf-2 -fvisibility=hidden -Wno-sign-conversion -MMD -MT dependencies -miphoneos-version-min=5.1.1 -isysroot $IPHONESDK')
+ env.Append(CPPFLAGS=['-DNEED_LONG_INT'])
+ env.Append(CPPFLAGS=['-DLIBYUV_DISABLE_NEON'])
+ else:
+ env['CCFLAGS'] = string.split('-fno-objc-arc -arch armv7 -fmessage-length=0 -fno-strict-aliasing -fdiagnostics-print-source-range-info -fdiagnostics-show-category=id -fdiagnostics-parseable-fixits -Wno-trigraphs -fpascal-strings -Wmissing-prototypes -Wreturn-type -Wparentheses -Wswitch -Wno-unused-parameter -Wunused-variable -Wunused-value -Wno-shorten-64-to-32 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk -gdwarf-2 -fvisibility=hidden -Wno-sign-conversion -mthumb "-DIBOutlet=__attribute__((iboutlet))" "-DIBOutletCollection(ClassName)=__attribute__((iboutletcollection(ClassName)))" "-DIBAction=void)__attribute__((ibaction)" -miphoneos-version-min=4.3 -MMD -MT dependencies -isysroot $IPHONESDK')
- env.Append(LINKFLAGS=['-arch', 'armv7', '-Wl,-dead_strip', '-miphoneos-version-min=4.3',
+ if (env["bits"]=="64"):
+ env.Append(LINKFLAGS=['-arch', 'arm64', '-Wl,-dead_strip', '-miphoneos-version-min=5.1.1',
+ '-isysroot', '$IPHONESDK',
+ #'-stdlib=libc++',
+ '-framework', 'Foundation',
+ '-framework', 'UIKit',
+ '-framework', 'CoreGraphics',
+ '-framework', 'OpenGLES',
+ '-framework', 'QuartzCore',
+ '-framework', 'CoreAudio',
+ '-framework', 'AudioToolbox',
+ '-framework', 'SystemConfiguration',
+ '-framework', 'Security',
+ #'-framework', 'AdSupport',
+ '-framework', 'MediaPlayer',
+ '-framework', 'AVFoundation',
+ '-framework', 'CoreMedia',
+ ])
+ else:
+ env.Append(LINKFLAGS=['-arch', 'armv7', '-Wl,-dead_strip', '-miphoneos-version-min=4.3',
'-isysroot', '$IPHONESDK',
- #'-mmacosx-version-min=10.5',
'-framework', 'Foundation',
'-framework', 'UIKit',
'-framework', 'CoreGraphics',
@@ -128,4 +143,4 @@ def configure(env):
env.Append( BUILDERS = { 'GLSL' : env.Builder(action = methods.build_glsl_headers, suffix = 'glsl.h',src_suffix = '.glsl') } )
env.Append( BUILDERS = { 'GLSL120GLES' : env.Builder(action = methods.build_gles2_headers, suffix = 'glsl.h',src_suffix = '.glsl') } )
-# /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x objective-c-header -arch armv7s -fmessage-length=0 -std=gnu99 -fobjc-arc -Wno-trigraphs -fpascal-strings -Os -Wno-missing-field-initializers -Wno-missing-prototypes -Wreturn-type -Wno-implicit-atomic-properties -Wno-receiver-is-weak -Wduplicate-method-match -Wformat -Wno-missing-braces -Wparentheses -Wswitch -Wno-unused-function -Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wempty-body -Wuninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wno-shorten-64-to-32 -Wpointer-sign -Wno-newline-eof -Wno-selector -Wno-strict-selector-match -Wno-undeclared-selector -Wno-deprecated-implementations -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk -Wprotocol -Wdeprecated-declarations -g -fvisibility=hidden -Wno-sign-conversion "-DIBOutlet=__attribute__((iboutlet))" "-DIBOutletCollection(ClassName)=__attribute__((iboutletcollection(ClassName)))" "-DIBAction=void)__attribute__((ibaction)" -miphoneos-version-min=4.3 -iquote /Users/lucasgondolo/test/build/test.build/Release-iphoneos/test.build/test-generated-files.hmap -I/Users/lucasgondolo/test/build/test.build/Release-iphoneos/test.build/test-own-target-headers.hmap -I/Users/lucasgondolo/test/build/test.build/Release-iphoneos/test.build/test-all-target-headers.hmap -iquote /Users/lucasgondolo/test/build/test.build/Release-iphoneos/test.build/test-project-headers.hmap -I/Users/lucasgondolo/test/build/Release-iphoneos/include -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -I/Users/lucasgondolo/test/build/test.build/Release-iphoneos/test.build/DerivedSources/armv7s -I/Users/lucasgondolo/test/build/test.build/Release-iphoneos/test.build/DerivedSources -F/Users/lucasgondolo/test/build/Release-iphoneos -DNS_BLOCK_ASSERTIONS=1 --serialize-diagnostics /var/folders/9r/_65jj9457bgb4n4nxcsm0xl80000gn/C/com.apple.Xcode.501/SharedPrecompiledHeaders/test-Prefix-esrzoamhgruxcxbhemvvlrjmmvoh/test-Prefix.pch.dia -c /Users/lucasgondolo/test/test/test-Prefix.pch -o /var/folders/9r/_65jj9457bgb4n4nxcsm0xl80000gn/C/com.apple.Xcode.501/SharedPrecompiledHeaders/test-Prefix-esrzoamhgruxcxbhemvvlrjmmvoh/test-Prefix.pch.pth -MMD -MT dependencies -MF /var/folders/9r/_65jj9457bgb4n4nxcsm0xl80000gn/C/com.apple.Xcode.501/SharedPrecompiledHeaders/test-Prefix-esrzoamhgruxcxbhemvvlrjmmvoh/test-Prefix.pch.d
+
diff --git a/platform/iphone/platform_config.h b/platform/iphone/platform_config.h
index df50d30f40..7e961176d9 100644
--- a/platform/iphone/platform_config.h
+++ b/platform/iphone/platform_config.h
@@ -30,3 +30,4 @@
#define GLES2_INCLUDE_H <ES2/gl.h>
#define GLES1_INCLUDE_H <ES1/gl.h>
+#define PLATFORM_REFCOUNT
diff --git a/platform/iphone/platform_refcount.h b/platform/iphone/platform_refcount.h
new file mode 100644
index 0000000000..45391e651a
--- /dev/null
+++ b/platform/iphone/platform_refcount.h
@@ -0,0 +1,18 @@
+#include "safe_refcount.h"
+
+#ifdef IPHONE_ENABLED
+
+#define REFCOUNT_T int
+#define REFCOUNT_GET_T int const volatile&
+
+#include <libkern/OSAtomic.h>
+
+inline int atomic_conditional_increment(volatile int* v) {
+ return (*v==0)? 0 : OSAtomicIncrement32(v);
+}
+
+inline int atomic_decrement(volatile int* v) {
+ return OSAtomicDecrement32(v);
+}
+
+#endif
diff --git a/platform/osx/detect.py b/platform/osx/detect.py
index 1b32838525..141a876657 100644
--- a/platform/osx/detect.py
+++ b/platform/osx/detect.py
@@ -78,7 +78,7 @@ def configure(env):
env.Append(LIBS=['pthread'])
#env.Append(CPPFLAGS=['-F/Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks', '-isysroot', '/Developer/SDKs/MacOSX10.4u.sdk', '-mmacosx-version-min=10.4'])
#env.Append(LINKFLAGS=['-mmacosx-version-min=10.4', '-isysroot', '/Developer/SDKs/MacOSX10.4u.sdk', '-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk'])
- env.Append(LINKFLAGS=['-framework', 'Cocoa', '-framework', 'OpenGL', '-framework', 'AGL', '-framework', 'AudioUnit','-lz'])
+ env.Append(LINKFLAGS=['-framework', 'Cocoa', '-framework', 'Carbon', '-framework', 'OpenGL', '-framework', 'AGL', '-framework', 'AudioUnit','-lz'])
if (env["CXX"]=="clang++"):
env.Append(CPPFLAGS=['-DTYPED_METHOD_BIND'])
diff --git a/platform/osx/os_osx.h b/platform/osx/os_osx.h
index 5df85bca2a..24f7115938 100644
--- a/platform/osx/os_osx.h
+++ b/platform/osx/os_osx.h
@@ -156,6 +156,8 @@ public:
virtual String get_executable_path() const;
+ virtual LatinKeyboardVariant get_latin_keyboard_variant() const;
+
virtual void move_window_to_foreground();
void run();
diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm
index 643c287c95..5bc47a74c1 100644
--- a/platform/osx/os_osx.mm
+++ b/platform/osx/os_osx.mm
@@ -27,6 +27,8 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#import <Cocoa/Cocoa.h>
+
+#include <Carbon/Carbon.h>
#include <IOKit/IOKitLib.h>
#include <IOKit/IOCFPlugIn.h>
#include <IOKit/hid/IOHIDLib.h>
@@ -694,7 +696,7 @@ static int translateKey(unsigned int key)
ev.type=InputEvent::KEY;
ev.key.pressed=true;
ev.key.mod=translateFlags([event modifierFlags]);
- ev.key.scancode = translateKey([event keyCode]);
+ ev.key.scancode = latin_keyboard_keycode_convert(translateKey([event keyCode]));
ev.key.echo = [event isARepeat];
NSString* characters = [event characters];
@@ -740,7 +742,7 @@ static int translateKey(unsigned int key)
ev.type=InputEvent::KEY;
ev.key.pressed=false;
ev.key.mod=translateFlags([event modifierFlags]);
- ev.key.scancode = translateKey([event keyCode]);
+ ev.key.scancode = latin_keyboard_keycode_convert(translateKey([event keyCode]));
OS_OSX::singleton->push_input(ev);
@@ -835,11 +837,24 @@ void OS_OSX::initialize_core() {
}
+static bool keyboard_layout_dirty = true;
+static void keyboardLayoutChanged(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) {
+ keyboard_layout_dirty = true;
+}
+
void OS_OSX::initialize(const VideoMode& p_desired,int p_video_driver,int p_audio_driver) {
/*** OSX INITIALIZATION ***/
/*** OSX INITIALIZATION ***/
/*** OSX INITIALIZATION ***/
+
+ keyboard_layout_dirty = true;
+
+ // Register to be notified on keyboard layout changes
+ CFNotificationCenterAddObserver(CFNotificationCenterGetDistributedCenter(),
+ NULL, keyboardLayoutChanged,
+ kTISNotifySelectedKeyboardInputSourceChanged, NULL,
+ CFNotificationSuspensionBehaviorDeliverImmediately);
window_delegate = [[GodotWindowDelegate alloc] init];
@@ -1007,6 +1022,8 @@ void OS_OSX::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi
}
void OS_OSX::finalize() {
+ CFNotificationCenterRemoveObserver(CFNotificationCenterGetDistributedCenter(), NULL, kTISNotifySelectedKeyboardInputSourceChanged, NULL);
+
}
void OS_OSX::set_main_loop( MainLoop * p_main_loop ) {
@@ -1241,6 +1258,83 @@ String OS_OSX::get_executable_path() const {
}
+// Returns string representation of keys, if they are printable.
+//
+static NSString *createStringForKeys(const CGKeyCode *keyCode, int length) {
+
+ TISInputSourceRef currentKeyboard = TISCopyCurrentKeyboardInputSource();
+ if (!currentKeyboard)
+ return nil;
+
+ CFDataRef layoutData = (CFDataRef)TISGetInputSourceProperty(currentKeyboard, kTISPropertyUnicodeKeyLayoutData);
+ if (!layoutData)
+ return nil;
+
+ const UCKeyboardLayout *keyboardLayout = (const UCKeyboardLayout *)CFDataGetBytePtr(layoutData);
+
+ OSStatus err;
+ CFMutableStringRef output = CFStringCreateMutable(NULL, 0);
+
+ for (int i=0; i<length; ++i) {
+
+ UInt32 keysDown = 0;
+ UniChar chars[4];
+ UniCharCount realLength;
+
+ err = UCKeyTranslate(keyboardLayout,
+ keyCode[i],
+ kUCKeyActionDisplay,
+ 0,
+ LMGetKbdType(),
+ kUCKeyTranslateNoDeadKeysBit,
+ &keysDown,
+ sizeof(chars) / sizeof(chars[0]),
+ &realLength,
+ chars);
+
+ if (err != noErr) {
+ CFRelease(output);
+ return nil;
+ }
+
+ CFStringAppendCharacters(output, chars, 1);
+ }
+
+ //CFStringUppercase(output, NULL);
+
+ return (NSString *)output;
+}
+OS::LatinKeyboardVariant OS_OSX::get_latin_keyboard_variant() const {
+
+ static LatinKeyboardVariant layout = LATIN_KEYBOARD_QWERTY;
+
+ if (keyboard_layout_dirty) {
+
+ layout = LATIN_KEYBOARD_QWERTY;
+
+ CGKeyCode keys[] = {kVK_ANSI_Q, kVK_ANSI_W, kVK_ANSI_E, kVK_ANSI_R, kVK_ANSI_T, kVK_ANSI_Y};
+ NSString *test = createStringForKeys(keys, 6);
+
+ if ([test isEqualToString:@"qwertz"]) {
+ layout = LATIN_KEYBOARD_QWERTZ;
+ } else if ([test isEqualToString:@"azerty"]) {
+ layout = LATIN_KEYBOARD_AZERTY;
+ } else if ([test isEqualToString:@"qzerty"]) {
+ layout = LATIN_KEYBOARD_QZERTY;
+ } else if ([test isEqualToString:@"',.pyf"]) {
+ layout = LATIN_KEYBOARD_DVORAK;
+ } else if ([test isEqualToString:@"xvlcwk"]) {
+ layout = LATIN_KEYBOARD_NEO;
+ }
+
+ [test release];
+
+ keyboard_layout_dirty = false;
+ return layout;
+ }
+
+ return layout;
+}
void OS_OSX::process_events() {
diff --git a/platform/windows/detect.py b/platform/windows/detect.py
index be92ee8f6d..245d6f1bd3 100644
--- a/platform/windows/detect.py
+++ b/platform/windows/detect.py
@@ -135,6 +135,27 @@ def configure(env):
env.Append(LIBPATH=[DIRECTX_PATH+"/Lib/x86"])
env['ENV'] = os.environ;
else:
+
+ # Workaround for MinGW. See:
+ # 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
+ 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)
+ data, err = proc.communicate()
+ rv = proc.wait()
+ if rv:
+ print "====="
+ print err
+ print "====="
+ 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
diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp
index 1ab15dcda3..a10152a025 100644
--- a/platform/windows/os_windows.cpp
+++ b/platform/windows/os_windows.cpp
@@ -1396,8 +1396,9 @@ void OS_Windows::set_window_title(const String& p_title) {
void OS_Windows::set_video_mode(const VideoMode& p_video_mode,int p_screen) {
-
+
}
+
OS::VideoMode OS_Windows::get_video_mode(int p_screen) const {
return video_mode;
diff --git a/platform/winrt/SCsub b/platform/winrt/SCsub
index 07e2ba81a6..2ea8cbd0de 100644
--- a/platform/winrt/SCsub
+++ b/platform/winrt/SCsub
@@ -8,4 +8,4 @@ files = [
'os_winrt.cpp',
]
-env.Program('#bin/godot_rt', files)
+env.Program('#bin/godot', files)
diff --git a/platform/winrt/app.cpp b/platform/winrt/app.cpp
index e3213d574a..662229b04e 100644
--- a/platform/winrt/app.cpp
+++ b/platform/winrt/app.cpp
@@ -5,6 +5,8 @@
#include "app.h"
#include "main/main.h"
+#include "core/os/dir_access.h"
+#include "core/os/file_access.h"
using namespace Windows::ApplicationModel::Core;
using namespace Windows::ApplicationModel::Activation;
@@ -70,8 +72,9 @@ void App::Initialize(CoreApplicationView^ applicationView)
}
// Called when the CoreWindow object is created (or re-created).
-void App::SetWindow(CoreWindow^ window)
+void App::SetWindow(CoreWindow^ p_window)
{
+ window = p_window;
window->VisibilityChanged +=
ref new TypedEventHandler<CoreWindow^, VisibilityChangedEventArgs^>(this, &App::OnVisibilityChanged);
@@ -89,23 +92,230 @@ void App::SetWindow(CoreWindow^ window)
pointerVisualizationSettings->IsBarrelButtonFeedbackEnabled = false;
#endif
- // The CoreWindow has been created, so EGL can be initialized.
+
+ window->PointerPressed +=
+ ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &App::OnPointerPressed);
+
+ window->PointerMoved +=
+ ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &App::OnPointerMoved);
+
+ window->PointerReleased +=
+ ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &App::OnPointerReleased);
+
+ //window->PointerWheelChanged +=
+ // ref new TypedEventHandler<CoreWindow^, PointerEventArgs^>(this, &App::OnPointerWheelChanged);
+
+
+
+ char* args[] = {"-path", "game", NULL};
+ Main::setup("winrt", 2, args, false);
+
+ // The CoreWindow has been created, so EGL can be initialized.
ContextEGL* context = memnew(ContextEGL(window));
os->set_gl_context(context);
- UpdateWindowSize(Size(window->Bounds.Width, window->Bounds.Height));
+ UpdateWindowSize(Size(window->Bounds.Width, window->Bounds.Height));
+
+ Main::setup2();
+}
+
+static int _get_button(Windows::UI::Input::PointerPoint ^pt) {
+
+ using namespace Windows::UI::Input;
+
+#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
+ return BUTTON_LEFT;
+#else
+ switch (pt->Properties->PointerUpdateKind)
+ {
+ case PointerUpdateKind::LeftButtonPressed:
+ case PointerUpdateKind::LeftButtonReleased:
+ return BUTTON_LEFT;
+
+ case PointerUpdateKind::RightButtonPressed:
+ case PointerUpdateKind::RightButtonReleased:
+ return BUTTON_RIGHT;
+
+ case PointerUpdateKind::MiddleButtonPressed:
+ case PointerUpdateKind::MiddleButtonReleased:
+ return BUTTON_MIDDLE;
+
+ case PointerUpdateKind::XButton1Pressed:
+ case PointerUpdateKind::XButton1Released:
+ return BUTTON_WHEEL_UP;
+
+ case PointerUpdateKind::XButton2Pressed:
+ case PointerUpdateKind::XButton2Released:
+ return BUTTON_WHEEL_DOWN;
+
+ default:
+ break;
+ }
+#endif
+
+ return 0;
+};
+
+static bool _is_touch(Windows::UI::Input::PointerPoint ^pointerPoint) {
+#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
+ return true;
+#else
+ using namespace Windows::Devices::Input;
+ switch (pointerPoint->PointerDevice->PointerDeviceType) {
+ case PointerDeviceType::Touch:
+ case PointerDeviceType::Pen:
+ return true;
+ default:
+ return false;
+ }
+#endif
}
+
+static Windows::Foundation::Point _get_pixel_position(CoreWindow^ window, Windows::Foundation::Point rawPosition, OS* os) {
+
+ Windows::Foundation::Point outputPosition;
+
+ // Compute coordinates normalized from 0..1.
+ // If the coordinates need to be sized to the SDL window,
+ // we'll do that after.
+ #if 1 || WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP
+ outputPosition.X = rawPosition.X / window->Bounds.Width;
+ outputPosition.Y = rawPosition.Y / window->Bounds.Height;
+ #else
+ switch (DisplayProperties::CurrentOrientation)
+ {
+ case DisplayOrientations::Portrait:
+ outputPosition.X = rawPosition.X / window->Bounds.Width;
+ outputPosition.Y = rawPosition.Y / window->Bounds.Height;
+ break;
+ case DisplayOrientations::PortraitFlipped:
+ outputPosition.X = 1.0f - (rawPosition.X / window->Bounds.Width);
+ outputPosition.Y = 1.0f - (rawPosition.Y / window->Bounds.Height);
+ break;
+ case DisplayOrientations::Landscape:
+ outputPosition.X = rawPosition.Y / window->Bounds.Height;
+ outputPosition.Y = 1.0f - (rawPosition.X / window->Bounds.Width);
+ break;
+ case DisplayOrientations::LandscapeFlipped:
+ outputPosition.X = 1.0f - (rawPosition.Y / window->Bounds.Height);
+ outputPosition.Y = rawPosition.X / window->Bounds.Width;
+ break;
+ default:
+ break;
+ }
+ #endif
+
+ OS::VideoMode vm = os->get_video_mode();
+ outputPosition.X *= vm.width;
+ outputPosition.Y *= vm.height;
+
+ return outputPosition;
+};
+
+static int _get_finger(uint32_t p_touch_id) {
+
+ return p_touch_id % 31; // for now
+};
+
+void App::pointer_event(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args, bool p_pressed) {
+
+ Windows::UI::Input::PointerPoint ^point = args->CurrentPoint;
+ Windows::Foundation::Point pos = _get_pixel_position(window, point->Position, os);
+ int but = _get_button(point);
+ if (_is_touch(point)) {
+
+ InputEvent event;
+ event.type = InputEvent::SCREEN_TOUCH;
+ event.device = 0;
+ event.screen_touch.pressed = p_pressed;
+ event.screen_touch.x = pos.X;
+ event.screen_touch.y = pos.Y;
+ event.screen_touch.index = _get_finger(point->PointerId);
+
+ last_touch_x[event.screen_touch.index] = pos.X;
+ last_touch_y[event.screen_touch.index] = pos.Y;
+
+ os->input_event(event);
+ if (event.screen_touch.index != 0)
+ return;
+
+ }; // fallthrought of sorts
+
+ InputEvent event;
+ event.type = InputEvent::MOUSE_BUTTON;
+ event.device = 0;
+ event.mouse_button.pressed = p_pressed;
+ event.mouse_button.button_index = but;
+ event.mouse_button.x = pos.X;
+ event.mouse_button.y = pos.Y;
+ event.mouse_button.global_x = pos.X;
+ event.mouse_button.global_y = pos.Y;
+
+ last_touch_x[31] = pos.X;
+ last_touch_y[31] = pos.Y;
+
+ os->input_event(event);
+};
+
+
+void App::OnPointerPressed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args) {
+
+ pointer_event(sender, args, true);
+};
+
+
+void App::OnPointerReleased(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args) {
+
+ pointer_event(sender, args, false);
+};
+
+void App::OnPointerMoved(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args) {
+
+ Windows::UI::Input::PointerPoint ^point = args->CurrentPoint;
+ Windows::Foundation::Point pos = _get_pixel_position(window, point->Position, os);
+
+ if (_is_touch(point)) {
+
+ InputEvent event;
+ event.type = InputEvent::SCREEN_DRAG;
+ event.device = 0;
+ event.screen_drag.x = pos.X;
+ event.screen_drag.y = pos.Y;
+ event.screen_drag.index = _get_finger(point->PointerId);
+ event.screen_drag.relative_x = event.screen_drag.x - last_touch_x[event.screen_drag.index];
+ event.screen_drag.relative_y = event.screen_drag.y - last_touch_y[event.screen_drag.index];
+
+ os->input_event(event);
+ if (event.screen_drag.index != 0)
+ return;
+
+ }; // fallthrought of sorts
+
+ InputEvent event;
+ event.type = InputEvent::MOUSE_MOTION;
+ event.device = 0;
+ event.mouse_motion.x = pos.X;
+ event.mouse_motion.y = pos.Y;
+ event.mouse_motion.global_x = pos.X;
+ event.mouse_motion.global_y = pos.Y;
+ event.mouse_motion.relative_x = pos.X - last_touch_x[31];
+ event.mouse_motion.relative_y = pos.Y - last_touch_y[31];
+
+ os->input_event(event);
+
+};
+
+
// Initializes scene resources
void App::Load(Platform::String^ entryPoint)
{
- char** args = {NULL};
- Main::setup("winrt", 0, args);
+ //char* args[] = {"-test", "render", NULL};
+ //Main::setup("winrt", 2, args);
}
// This method is called after the window becomes active.
void App::Run()
{
-
if (Main::start())
os->run();
}
@@ -147,16 +357,29 @@ void App::OnWindowSizeChanged(CoreWindow^ sender, WindowSizeChangedEventArgs^ ar
// On Windows Phone 8.1, the window size changes when the device is rotated.
// The default framebuffer will not be automatically resized when this occurs.
// It is therefore up to the app to handle rotation-specific logic in its rendering code.
+ //os->screen_size_changed();
+ UpdateWindowSize(args->Size);
#endif
}
void App::UpdateWindowSize(Size size)
{
- /*
- DisplayInformation^ currentDisplayInformation = DisplayInformation::GetForCurrentView();
- Size pixelSize(ConvertDipsToPixels(size.Width, currentDisplayInformation->LogicalDpi), ConvertDipsToPixels(size.Height, currentDisplayInformation->LogicalDpi));
-
+ float dpi;
+#if (WINAPI_FAMILY == WINAPI_FAMILY_PC_APP)
+ DisplayInformation^ currentDisplayInformation = DisplayInformation::GetForCurrentView();
+ dpi = currentDisplayInformation->LogicalDpi;
+#else if (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
+ dpi = DisplayProperties::LogicalDpi;
+#endif
+ Size pixelSize(ConvertDipsToPixels(size.Width, dpi), ConvertDipsToPixels(size.Height, dpi));
+
mWindowWidth = static_cast<GLsizei>(pixelSize.Width);
mWindowHeight = static_cast<GLsizei>(pixelSize.Height);
- */
+
+ OS::VideoMode vm;
+ vm.width = mWindowWidth;
+ vm.height = mWindowHeight;
+ vm.fullscreen = true;
+ vm.resizable = false;
+ os->set_video_mode(vm);
}
diff --git a/platform/winrt/app.h b/platform/winrt/app.h
index a67b936cdf..7926465ff8 100644
--- a/platform/winrt/app.h
+++ b/platform/winrt/app.h
@@ -32,6 +32,12 @@ namespace $ext_safeprojectname$
void OnVisibilityChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::VisibilityChangedEventArgs^ args);
void OnWindowClosed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::CoreWindowEventArgs^ args);
+ void pointer_event(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args, bool p_pressed);
+ void OnPointerPressed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
+ void OnPointerReleased(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
+ void OnPointerMoved(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args);
+
+
void UpdateWindowSize(Windows::Foundation::Size size);
void InitializeEGL(Windows::UI::Core::CoreWindow^ window);
void CleanupEGL();
@@ -44,8 +50,12 @@ namespace $ext_safeprojectname$
EGLDisplay mEglDisplay;
EGLContext mEglContext;
EGLSurface mEglSurface;
-
+
+ CoreWindow^ window;
OSWinrt* os;
- };
+
+ int last_touch_x[32]; // 20 fingers, index 31 reserved for the mouse
+ int last_touch_y[32];
+ };
}
diff --git a/platform/winrt/detect.py b/platform/winrt/detect.py
index 00913b0ade..d97d974a19 100644
--- a/platform/winrt/detect.py
+++ b/platform/winrt/detect.py
@@ -3,6 +3,7 @@
import os
import sys
+import string
def is_active():
@@ -29,55 +30,127 @@ def get_flags():
def configure(env):
env.Append(CPPPATH=['#platform/winrt', '#platform/winrt/include'])
+ arch = ""
- env['OBJSUFFIX'] = ".rt" + env['OBJSUFFIX']
- env['LIBSUFFIX'] = ".rt" + env['LIBSUFFIX']
+ if os.getenv('PLATFORM') == "ARM":
- env.Append(LIBPATH=['#platform/winrt/x64/lib'])
+ # compiler commandline
+ # debug: /Yu"pch.h" /MP /GS /analyze- /W3 /wd"4453" /wd"28204" /Zc:wchar_t /I"C:\Users\ariel\Documents\Visual Studio 2013\Projects\App2\App2\App2.WindowsPhone\" /I"Generated Files\" /I"ARM\Debug\" /I"C:\Users\ariel\Documents\Visual Studio 2013\Projects\App2\App2\App2.Shared\" /ZW:nostdlib /Zi /Gm- /Od /sdl /Fd"ARM\Debug\vc120.pdb" /fp:precise /D "PSAPI_VERSION=2" /D "WINAPI_FAMILY=WINAPI_FAMILY_PHONE_APP" /D "_UITHREADCTXT_SUPPORT=0" /D "_UNICODE" /D "UNICODE" /D "_DEBUG" /errorReport:prompt /WX- /Zc:forScope /RTC1 /ZW /Gd /Oy- /MDd /Fa"ARM\Debug\" /EHsc /nologo /Fo"ARM\Debug\" /Fp"ARM\Debug\App2.WindowsPhone.pch"
+ # release: /Yu"pch.h" /MP /GS /GL /analyze- /W3 /wd"4453" /wd"28204" /Gy /Zc:wchar_t /I"C:\Users\ariel\Documents\Visual Studio 2013\Projects\App2\App2\App2.WindowsPhone\" /I"Generated Files\" /I"ARM\Release\" /I"C:\Users\ariel\Documents\Visual Studio 2013\Projects\App2\App2\App2.Shared\" /ZW:nostdlib /Zi /Gm- /O2 /sdl /Fd"ARM\Release\vc120.pdb" /fp:precise /D "PSAPI_VERSION=2" /D "WINAPI_FAMILY=WINAPI_FAMILY_PHONE_APP" /D "_UITHREADCTXT_SUPPORT=0" /D "_UNICODE" /D "UNICODE" /errorReport:prompt /WX- /Zc:forScope /ZW /Gd /Oy- /Oi /MD /Fa"ARM\Release\" /EHsc /nologo /Fo"ARM\Release\" /Fp"ARM\Release\App2.WindowsPhone.pch"
- if (env["target"]=="release"):
+ # linker commandline
+ # debug: /OUT:"C:\Users\ariel\Documents\Visual Studio 2013\Projects\App2\ARM\Debug\App2.WindowsPhone\App2.WindowsPhone.exe" /MANIFEST:NO /NXCOMPAT /PDB:"C:\Users\ariel\Documents\Visual Studio 2013\Projects\App2\ARM\Debug\App2.WindowsPhone\App2.WindowsPhone.pdb" /DYNAMICBASE "WindowsPhoneCore.lib" "RuntimeObject.lib" "PhoneAppModelHost.lib" /DEBUG /MACHINE:ARM /NODEFAULTLIB:"kernel32.lib" /NODEFAULTLIB:"ole32.lib" /WINMD /APPCONTAINER /INCREMENTAL /PGD:"C:\Users\ariel\Documents\Visual Studio 2013\Projects\App2\ARM\Debug\App2.WindowsPhone\App2.WindowsPhone.pgd" /WINMDFILE:"C:\Users\ariel\Documents\Visual Studio 2013\Projects\App2\ARM\Debug\App2.WindowsPhone\App2.winmd" /SUBSYSTEM:WINDOWS /MANIFESTUAC:NO /ManifestFile:"ARM\Debug\App2.WindowsPhone.exe.intermediate.manifest" /ERRORREPORT:PROMPT /NOLOGO /TLBID:1
+ # release: /OUT:"C:\Users\ariel\Documents\Visual Studio 2013\Projects\App2\ARM\Release\App2.WindowsPhone\App2.WindowsPhone.exe" /MANIFEST:NO /LTCG /NXCOMPAT /PDB:"C:\Users\ariel\Documents\Visual Studio 2013\Projects\App2\ARM\Release\App2.WindowsPhone\App2.WindowsPhone.pdb" /DYNAMICBASE "WindowsPhoneCore.lib" "RuntimeObject.lib" "PhoneAppModelHost.lib" /DEBUG /MACHINE:ARM /NODEFAULTLIB:"kernel32.lib" /NODEFAULTLIB:"ole32.lib" /WINMD /APPCONTAINER /OPT:REF /PGD:"C:\Users\ariel\Documents\Visual Studio 2013\Projects\App2\ARM\Release\App2.WindowsPhone\App2.WindowsPhone.pgd" /WINMDFILE:"C:\Users\ariel\Documents\Visual Studio 2013\Projects\App2\ARM\Release\App2.WindowsPhone\App2.winmd" /SUBSYSTEM:WINDOWS /MANIFESTUAC:NO /ManifestFile:"ARM\Release\App2.WindowsPhone.exe.intermediate.manifest" /OPT:ICF /ERRORREPORT:PROMPT /NOLOGO /TLBID:1
- env.Append(CCFLAGS=['/O2'])
- env.Append(LINKFLAGS=['/SUBSYSTEM:WINDOWS'])
- env.Append(LINKFLAGS=['/ENTRY:mainCRTStartup'])
+ arch = "arm"
- elif (env["target"]=="test"):
+ env.Append(LINKFLAGS=['/INCREMENTAL:NO', '/MANIFEST:NO', '/NXCOMPAT', '/DYNAMICBASE', "WindowsPhoneCore.lib", "RuntimeObject.lib", "PhoneAppModelHost.lib", "/DEBUG", "/MACHINE:ARM", '/NODEFAULTLIB:"kernel32.lib"', '/NODEFAULTLIB:"ole32.lib"', '/WINMD', '/APPCONTAINER', '/MANIFESTUAC:NO', '/ERRORREPORT:PROMPT', '/NOLOGO', '/TLBID:1'])
+ env.Append(LIBPATH=['#platform/winrt/ARM/lib'])
- env.Append(CCFLAGS=['/O2','/DDEBUG_ENABLED','/DD3D_DEBUG_INFO'])
- env.Append(LINKFLAGS=['/SUBSYSTEM:CONSOLE'])
+ env.Append(CCFLAGS=string.split('/MP /GS /wd"4453" /wd"28204" /analyze- /Zc:wchar_t /Zi /Gm- /Od /fp:precise /fp:precise /D "PSAPI_VERSION=2" /D "WINAPI_FAMILY=WINAPI_FAMILY_PHONE_APP" /DWINDOWSPHONE_ENABLED /D "_UITHREADCTXT_SUPPORT=0" /D "_UNICODE" /D "UNICODE" /errorReport:prompt /WX- /Zc:forScope /Gd /Oy- /Oi /MD /RTC1 /Gd /EHsc /nologo'))
+ env.Append(CXXFLAGS=string.split('/ZW'))
- elif (env["target"]=="debug"):
+ if (env["target"]=="release"):
- env.Append(CCFLAGS=['/Zi','/DDEBUG_ENABLED','/DD3D_DEBUG_INFO','/O1'])
- env.Append(LINKFLAGS=['/SUBSYSTEM:CONSOLE'])
- env.Append(LINKFLAGS=['/DEBUG'])
+ env.Append(CCFLAGS=['/O2'])
+ env.Append(LINKFLAGS=['/SUBSYSTEM:WINDOWS'])
- elif (env["target"]=="profile"):
+ elif (env["target"]=="test"):
- env.Append(CCFLAGS=['-g','-pg'])
- env.Append(LINKFLAGS=['-pg'])
+ env.Append(CCFLAGS=['/O2','/DDEBUG_ENABLED','/DD3D_DEBUG_INFO'])
+ env.Append(LINKFLAGS=['/SUBSYSTEM:CONSOLE'])
- env.Append(CCFLAGS=['/Gd','/GR','/nologo', '/EHsc'])
- env.Append(CXXFLAGS=['/TP', '/ZW'])
- env.Append(CPPFLAGS=['/DMSVC', '/GR', ])
- #env.Append(CCFLAGS=['/I'+os.getenv("WindowsSdkDir")+"/Include"])
+ elif (env["target"]=="debug"):
+
+ env.Append(CCFLAGS=['/Zi','/DDEBUG_ENABLED','/DD3D_DEBUG_INFO'])
+ env.Append(LINKFLAGS=['/SUBSYSTEM:CONSOLE'])
+ env.Append(LINKFLAGS=['/DEBUG', '/D_DEBUG'])
+
+ elif (env["target"]=="profile"):
+
+ env.Append(CCFLAGS=['-g','-pg'])
+ env.Append(LINKFLAGS=['-pg'])
+
+
+ env['ENV'] = os.environ;
+ # fix environment for windows phone 8.1
+ env['ENV']['WINDOWSPHONEKITDIR'] = env['ENV']['WINDOWSPHONEKITDIR'].replace("8.0", "8.1") # wtf
+ env['ENV']['INCLUDE'] = env['ENV']['INCLUDE'].replace("8.0", "8.1")
+ env['ENV']['LIB'] = env['ENV']['LIB'].replace("8.0", "8.1")
+ env['ENV']['PATH'] = env['ENV']['PATH'].replace("8.0", "8.1")
+ env['ENV']['LIBPATH'] = env['ENV']['LIBPATH'].replace("8.0\\Windows Metadata", "8.1\\References\\CommonConfiguration\\Neutral")
+
+ else:
+
+ arch = "x64"
+ env.Append(LINKFLAGS=['/MANIFEST:NO', '/NXCOMPAT', '/DYNAMICBASE', "kernel32.lib", '/MACHINE:X64', '/WINMD', '/APPCONTAINER', '/MANIFESTUAC:NO', '/ERRORREPORT:PROMPT', '/NOLOGO', '/TLBID:1'])
+
+ env.Append(LIBPATH=['#platform/winrt/x64/lib'])
+
+
+ if (env["target"]=="release"):
+
+ env.Append(CCFLAGS=['/O2'])
+ env.Append(LINKFLAGS=['/SUBSYSTEM:WINDOWS'])
+ env.Append(LINKFLAGS=['/ENTRY:mainCRTStartup'])
+
+ elif (env["target"]=="test"):
+
+ env.Append(CCFLAGS=['/O2','/DDEBUG_ENABLED','/DD3D_DEBUG_INFO'])
+ env.Append(LINKFLAGS=['/SUBSYSTEM:CONSOLE'])
+
+ elif (env["target"]=="debug"):
+
+ env.Append(CCFLAGS=['/Zi','/DDEBUG_ENABLED','/DD3D_DEBUG_INFO'])
+ env.Append(LINKFLAGS=['/SUBSYSTEM:CONSOLE'])
+ env.Append(LINKFLAGS=['/DEBUG', '/D_DEBUG'])
+
+ elif (env["target"]=="profile"):
+
+ env.Append(CCFLAGS=['-g','-pg'])
+ env.Append(LINKFLAGS=['-pg'])
+
+
+ env.Append(CCFLAGS=string.split('/MP /GS /wd"4453" /wd"28204" /Zc:wchar_t /Gm- /Od /fp:precise /D "_UNICODE" /D "UNICODE" /D "WINAPI_FAMILY=WINAPI_FAMILY_APP" /errorReport:prompt /WX- /Zc:forScope /RTC1 /Gd /MDd /EHsc /nologo'))
+ env.Append(CXXFLAGS=string.split('/ZW'))
+ env.Append(CCFLAGS=['/AI', os.environ['VCINSTALLDIR']+'\\vcpackages', '/AI', os.environ['WINDOWSSDKDIR']+'\\References\\CommonConfiguration\\Neutral'])
+ env.Append(CCFLAGS=['/DWINAPI_FAMILY=WINAPI_FAMILY_APP', '/D_WIN32_WINNT=0x0603', '/DNTDDI_VERSION=0x06030000'])
+
+ env['ENV'] = os.environ;
+
+
+ env["PROGSUFFIX"]="."+arch+env["PROGSUFFIX"]
+ env["OBJSUFFIX"]="."+arch+env["OBJSUFFIX"]
+ env["LIBSUFFIX"]="."+arch+env["LIBSUFFIX"]
+
+
+ #env.Append(CCFLAGS=['/Gd','/GR','/nologo', '/EHsc'])
+ #env.Append(CXXFLAGS=['/TP', '/ZW'])
+ #env.Append(CPPFLAGS=['/DMSVC', '/GR', ])
+ ##env.Append(CCFLAGS=['/I'+os.getenv("WindowsSdkDir")+"/Include"])
env.Append(CCFLAGS=['/DWINRT_ENABLED'])
env.Append(CCFLAGS=['/DWINDOWS_ENABLED'])
- env.Append(CCFLAGS=['/DWINAPI_FAMILY=WINAPI_FAMILY_APP', '/D_WIN32_WINNT=0x0603', '/DNTDDI_VERSION=0x06030000'])
env.Append(CCFLAGS=['/DRTAUDIO_ENABLED'])
#env.Append(CCFLAGS=['/DWIN32'])
env.Append(CCFLAGS=['/DTYPED_METHOD_BIND'])
env.Append(CCFLAGS=['/DGLES2_ENABLED'])
#env.Append(CCFLAGS=['/DGLES1_ENABLED'])
- env.Append(LIBS=['winmm','opengl32','dsound','kernel32','ole32','user32','gdi32', 'IPHLPAPI', 'wsock32', 'shell32','advapi32'])
-
+
+ LIBS=[
+ #'winmm',
+ 'libEGL',
+ 'libGLESv2',
+ 'libANGLE',
+ #'kernel32','ole32','user32', 'advapi32'
+ ]
+ env.Append(LINKFLAGS=[p+".lib" for p in LIBS])
+
import methods
env.Append( BUILDERS = { 'GLSL120' : env.Builder(action = methods.build_legacygl_headers, suffix = 'glsl.h',src_suffix = '.glsl') } )
env.Append( BUILDERS = { 'GLSL' : env.Builder(action = methods.build_glsl_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') } )
env.Append( BUILDERS = { 'GLSL120GLES' : env.Builder(action = methods.build_gles2_headers, suffix = 'glsl.h',src_suffix = '.glsl') } )
- env['ENV'] = os.environ;
-
+#/c/Program Files (x86)/Windows Phone Kits/8.1/lib/ARM/WindowsPhoneCore.lib
diff --git a/platform/winrt/gl_context_egl.cpp b/platform/winrt/gl_context_egl.cpp
index ca592c5d19..fd9fbe406f 100644
--- a/platform/winrt/gl_context_egl.cpp
+++ b/platform/winrt/gl_context_egl.cpp
@@ -1,5 +1,7 @@
#include "gl_context_egl.h"
+#include "EGL/eglext.h"
+
using namespace Platform;
void ContextEGL::release_current() {
@@ -22,6 +24,14 @@ int ContextEGL::get_window_height() {
return height;
};
+void ContextEGL::reset() {
+
+ cleanup();
+
+ window = CoreWindow::GetForCurrentThread();
+ initialize();
+};
+
void ContextEGL::swap_buffers() {
if (eglSwapBuffers(mEglDisplay, mEglSurface) != EGL_TRUE)
@@ -63,7 +73,23 @@ Error ContextEGL::initialize() {
try {
- display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
+ const EGLint displayAttributes[] =
+ {
+ EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE,
+ EGL_PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE, 9,
+ EGL_PLATFORM_ANGLE_MAX_VERSION_MINOR_ANGLE, 3,
+ EGL_NONE,
+ };
+
+ PFNEGLGETPLATFORMDISPLAYEXTPROC eglGetPlatformDisplayEXT = reinterpret_cast<PFNEGLGETPLATFORMDISPLAYEXTPROC>(eglGetProcAddress("eglGetPlatformDisplayEXT"));
+
+ if (!eglGetPlatformDisplayEXT)
+ {
+ throw Exception::CreateException(E_FAIL, L"Failed to get function eglGetPlatformDisplayEXT");
+ }
+
+ display = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, EGL_DEFAULT_DISPLAY, displayAttributes);
+
if (display == EGL_NO_DISPLAY)
{
throw Exception::CreateException(E_FAIL, L"Failed to get default EGL display");
diff --git a/platform/winrt/gl_context_egl.h b/platform/winrt/gl_context_egl.h
index 56bf654ee5..ca3760e723 100644
--- a/platform/winrt/gl_context_egl.h
+++ b/platform/winrt/gl_context_egl.h
@@ -32,6 +32,7 @@ public:
virtual void swap_buffers();
virtual Error initialize();
+ void reset();
void cleanup();
diff --git a/platform/winrt/include/EGL/eglext.h b/platform/winrt/include/EGL/eglext.h
index 9828628e75..459ecf4a3d 100644
--- a/platform/winrt/include/EGL/eglext.h
+++ b/platform/winrt/include/EGL/eglext.h
@@ -432,31 +432,38 @@ EGLAPI EGLBoolean EGLAPIENTRY eglQuerySurfacePointerANGLE (EGLDisplay dpy, EGLSu
#define EGL_ANGLE_direct3d_display 1
#define EGL_D3D11_ELSE_D3D9_DISPLAY_ANGLE ((EGLNativeDisplayType)-2)
#define EGL_D3D11_ONLY_DISPLAY_ANGLE ((EGLNativeDisplayType)-3)
-#define EGL_D3D11_FL9_3_ONLY_DISPLAY_ANGLE ((EGLNativeDisplayType)-4)
#endif /* EGL_ANGLE_direct3d_display */
#ifndef EGL_ANGLE_surface_d3d_texture_2d_share_handle
#define EGL_ANGLE_surface_d3d_texture_2d_share_handle 1
#endif /* EGL_ANGLE_surface_d3d_texture_2d_share_handle */
+#ifndef EGL_ANGLE_surface_d3d_render_to_back_buffer
+#define EGL_ANGLE_surface_d3d_render_to_back_buffer 1
+#define EGL_ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER 0x320B
+#define EGL_ANGLE_SURFACE_RENDER_TO_BACK_BUFFER 0x320C
+#endif /* EGL_ANGLE_surface_d3d_render_to_back_buffer */
+
#ifndef EGL_ANGLE_platform_angle
#define EGL_ANGLE_platform_angle 1
#define EGL_PLATFORM_ANGLE_ANGLE 0x3201
#define EGL_PLATFORM_ANGLE_TYPE_ANGLE 0x3202
-#define EGL_PLATFORM_ANGLE_TYPE_DEFAULT_ANGLE 0x3203
+#define EGL_PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE 0x3203
+#define EGL_PLATFORM_ANGLE_MAX_VERSION_MINOR_ANGLE 0x3204
+#define EGL_PLATFORM_ANGLE_TYPE_DEFAULT_ANGLE 0x3205
#endif /* EGL_ANGLE_platform_angle */
#ifndef EGL_ANGLE_platform_angle_d3d
#define EGL_ANGLE_platform_angle_d3d 1
-#define EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE 0x3204
-#define EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE 0x3205
-#define EGL_PLATFORM_ANGLE_TYPE_D3D11_WARP_ANGLE 0x3206
+#define EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE 0x3206
+#define EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE 0x3207
+#define EGL_PLATFORM_ANGLE_USE_WARP_ANGLE 0x3208
#endif /* EGL_ANGLE_platform_angle_d3d */
#ifndef EGL_ANGLE_platform_angle_opengl
#define EGL_ANGLE_platform_angle_opengl 1
-#define EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE 0x3207
-#define EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE 0x3208
+#define EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE 0x3209
+#define EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE 0x320A
#endif /* EGL_ANGLE_platform_angle_opengl */
#ifndef EGL_ARM_pixmap_multisample_discard
diff --git a/platform/winrt/include/EGL/eglplatform.h b/platform/winrt/include/EGL/eglplatform.h
index d2e30bddbe..b0e88f94d4 100644
--- a/platform/winrt/include/EGL/eglplatform.h
+++ b/platform/winrt/include/EGL/eglplatform.h
@@ -76,12 +76,12 @@
typedef HDC EGLNativeDisplayType;
typedef HBITMAP EGLNativePixmapType;
-#if defined(WINAPI_FAMILY) && !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
+#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_PC_APP || WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP) /* Windows Store */
#include <inspectable.h>
typedef IInspectable* EGLNativeWindowType;
#else
typedef HWND EGLNativeWindowType;
-#endif // defined(WINAPI_FAMILY) && !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
+#endif
#elif defined(__WINSCW__) || defined(__SYMBIAN32__) /* Symbian */
diff --git a/platform/winrt/include/GLSLANG/ShaderLang.h b/platform/winrt/include/GLSLANG/ShaderLang.h
index 86bf221c90..d925b88f24 100644
--- a/platform/winrt/include/GLSLANG/ShaderLang.h
+++ b/platform/winrt/include/GLSLANG/ShaderLang.h
@@ -27,6 +27,10 @@
#include "KHR/khrplatform.h"
+#include <map>
+#include <string>
+#include <vector>
+
//
// This is the platform independent interface between an OGL driver
// and the shading language compiler.
@@ -39,20 +43,20 @@ typedef unsigned int GLenum;
}
// Must be included after GLenum proxy typedef
+// Note: make sure to increment ANGLE_SH_VERSION when changing ShaderVars.h
#include "ShaderVars.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
-
// Version number for shader translation API.
// It is incremented every time the API changes.
-#define ANGLE_SH_VERSION 129
+#define ANGLE_SH_VERSION 132
typedef enum {
SH_GLES2_SPEC = 0x8B40,
SH_WEBGL_SPEC = 0x8B41,
+ SH_GLES3_SPEC = 0x8B86,
+ SH_WEBGL2_SPEC = 0x8B87,
+
// The CSS Shaders spec is a subset of the WebGL spec.
//
// In both CSS vertex and fragment shaders, ANGLE:
@@ -84,31 +88,6 @@ typedef enum {
SH_HLSL11_OUTPUT = 0x8B48
} ShShaderOutput;
-typedef enum {
- SH_PRECISION_HIGHP = 0x5001,
- SH_PRECISION_MEDIUMP = 0x5002,
- SH_PRECISION_LOWP = 0x5003,
- SH_PRECISION_UNDEFINED = 0
-} ShPrecisionType;
-
-typedef enum {
- SH_INFO_LOG_LENGTH = 0x8B84,
- SH_OBJECT_CODE_LENGTH = 0x8B88, // GL_SHADER_SOURCE_LENGTH
- SH_ACTIVE_UNIFORMS = 0x8B86,
- SH_ACTIVE_UNIFORM_MAX_LENGTH = 0x8B87,
- SH_ACTIVE_ATTRIBUTES = 0x8B89,
- SH_ACTIVE_ATTRIBUTE_MAX_LENGTH = 0x8B8A,
- SH_VARYINGS = 0x8BBB,
- SH_VARYING_MAX_LENGTH = 0x8BBC,
- SH_MAPPED_NAME_MAX_LENGTH = 0x6000,
- SH_NAME_MAX_LENGTH = 0x6001,
- SH_HASHED_NAME_MAX_LENGTH = 0x6002,
- SH_HASHED_NAMES_COUNT = 0x6003,
- SH_SHADER_VERSION = 0x6004,
- SH_RESOURCES_STRING_LENGTH = 0x6005,
- SH_OUTPUT_TYPE = 0x6006
-} ShShaderInfo;
-
// Compile options.
typedef enum {
SH_VALIDATE = 0,
@@ -188,6 +167,11 @@ typedef enum {
// This flag scalarizes vec/ivec/bvec/mat constructor args.
// It is intended as a workaround for Linux/Mac driver bugs.
SH_SCALARIZE_VEC_AND_MAT_CONSTRUCTOR_ARGS = 0x40000,
+
+ // This flag overwrites a struct name with a unique prefix.
+ // It is intended as a workaround for drivers that do not handle
+ // struct scopes correctly, including all Mac drivers and Linux AMD.
+ SH_REGENERATE_STRUCT_NAMES = 0x80000,
} ShCompileOptions;
// Defines alternate strategies for implementing array index clamping.
@@ -202,14 +186,14 @@ typedef enum {
//
// Driver must call this first, once, before doing any other
// compiler operations.
-// If the function succeeds, the return value is nonzero, else zero.
+// If the function succeeds, the return value is true, else false.
//
-COMPILER_EXPORT int ShInitialize();
+COMPILER_EXPORT bool ShInitialize();
//
// Driver should call this at shutdown.
-// If the function succeeds, the return value is nonzero, else zero.
+// If the function succeeds, the return value is true, else false.
//
-COMPILER_EXPORT int ShFinalize();
+COMPILER_EXPORT bool ShFinalize();
// The 64 bits hash function. The first parameter is the input string; the
// second parameter is the string length.
@@ -240,6 +224,12 @@ typedef struct
int EXT_frag_depth;
int EXT_shader_texture_lod;
+ // Set to 1 to enable replacing GL_EXT_draw_buffers #extension directives
+ // with GL_NV_draw_buffers in ESSL output. This flag can be used to emulate
+ // EXT_draw_buffers by using it in combination with GLES3.0 glDrawBuffers
+ // function. This applies to Tegra K1 devices.
+ int NV_draw_buffers;
+
// Set to 1 if highp precision is supported in the fragment language.
// Default is 0.
int FragmentPrecisionHigh;
@@ -268,8 +258,10 @@ typedef struct
//
// Initialize built-in resources with minimum expected values.
+// Parameters:
+// resources: The object to initialize. Will be comparable with memcmp.
//
-COMPILER_EXPORT void ShInitBuiltInResources(ShBuiltInResources* resources);
+COMPILER_EXPORT void ShInitBuiltInResources(ShBuiltInResources *resources);
//
// ShHandle held by but opaque to the driver. It is allocated,
@@ -278,18 +270,15 @@ COMPILER_EXPORT void ShInitBuiltInResources(ShBuiltInResources* resources);
//
// If handle creation fails, 0 will be returned.
//
-typedef void* ShHandle;
+typedef void *ShHandle;
//
-// Returns the a concatenated list of the items in ShBuiltInResources as a string.
+// Returns the a concatenated list of the items in ShBuiltInResources as a
+// null-terminated string.
// This function must be updated whenever ShBuiltInResources is changed.
// Parameters:
// handle: Specifies the handle of the compiler to be used.
-// outStringLen: Specifies the size of the buffer, in number of characters. The size
-// of the buffer required to store the resources string can be obtained
-// by calling ShGetInfo with SH_RESOURCES_STRING_LENGTH.
-// outStr: Returns a null-terminated string representing all the built-in resources.
-COMPILER_EXPORT void ShGetBuiltInResourcesString(const ShHandle handle, size_t outStringLen, char *outStr);
+COMPILER_EXPORT const std::string &ShGetBuiltInResourcesString(const ShHandle handle);
//
// Driver calls these to create and destroy compiler objects.
@@ -307,12 +296,12 @@ COMPILER_EXPORT ShHandle ShConstructCompiler(
sh::GLenum type,
ShShaderSpec spec,
ShShaderOutput output,
- const ShBuiltInResources* resources);
+ const ShBuiltInResources *resources);
COMPILER_EXPORT void ShDestruct(ShHandle handle);
//
// Compiles the given shader source.
-// If the function succeeds, the return value is nonzero, else zero.
+// If the function succeeds, the return value is true, else false.
// Parameters:
// handle: Specifies the handle of compiler to be used.
// shaderStrings: Specifies an array of pointers to null-terminated strings
@@ -334,123 +323,36 @@ COMPILER_EXPORT void ShDestruct(ShHandle handle);
// SH_VARIABLES: Extracts attributes, uniforms, and varyings.
// Can be queried by calling ShGetVariableInfo().
//
-COMPILER_EXPORT int ShCompile(
+COMPILER_EXPORT bool ShCompile(
const ShHandle handle,
- const char* const shaderStrings[],
+ const char * const shaderStrings[],
size_t numStrings,
- int compileOptions
- );
+ int compileOptions);
-// Returns a parameter from a compiled shader.
-// Parameters:
-// handle: Specifies the compiler
-// pname: Specifies the parameter to query.
-// The following parameters are defined:
-// SH_INFO_LOG_LENGTH: the number of characters in the information log
-// including the null termination character.
-// SH_OBJECT_CODE_LENGTH: the number of characters in the object code
-// including the null termination character.
-// SH_ACTIVE_ATTRIBUTES: the number of active attribute variables.
-// SH_ACTIVE_ATTRIBUTE_MAX_LENGTH: the length of the longest active attribute
-// variable name including the null
-// termination character.
-// SH_ACTIVE_UNIFORMS: the number of active uniform variables.
-// SH_ACTIVE_UNIFORM_MAX_LENGTH: the length of the longest active uniform
-// variable name including the null
-// termination character.
-// SH_VARYINGS: the number of varying variables.
-// SH_VARYING_MAX_LENGTH: the length of the longest varying variable name
-// including the null termination character.
-// SH_MAPPED_NAME_MAX_LENGTH: the length of the mapped variable name including
-// the null termination character.
-// SH_NAME_MAX_LENGTH: the max length of a user-defined name including the
-// null termination character.
-// SH_HASHED_NAME_MAX_LENGTH: the max length of a hashed name including the
-// null termination character.
-// SH_HASHED_NAMES_COUNT: the number of hashed names from the latest compile.
-// SH_SHADER_VERSION: the version of the shader language
-// SH_OUTPUT_TYPE: the currently set language output type
-//
-// params: Requested parameter
-COMPILER_EXPORT void ShGetInfo(const ShHandle handle,
- ShShaderInfo pname,
- size_t* params);
+// Return the version of the shader language.
+COMPILER_EXPORT int ShGetShaderVersion(const ShHandle handle);
-// Returns nul-terminated information log for a compiled shader.
+// Return the currently set language output type.
+COMPILER_EXPORT ShShaderOutput ShGetShaderOutputType(
+ const ShHandle handle);
+
+// Returns null-terminated information log for a compiled shader.
// Parameters:
// handle: Specifies the compiler
-// infoLog: Specifies an array of characters that is used to return
-// the information log. It is assumed that infoLog has enough memory
-// to accomodate the information log. The size of the buffer required
-// to store the returned information log can be obtained by calling
-// ShGetInfo with SH_INFO_LOG_LENGTH.
-COMPILER_EXPORT void ShGetInfoLog(const ShHandle handle, char* infoLog);
+COMPILER_EXPORT const std::string &ShGetInfoLog(const ShHandle handle);
// Returns null-terminated object code for a compiled shader.
// Parameters:
// handle: Specifies the compiler
-// infoLog: Specifies an array of characters that is used to return
-// the object code. It is assumed that infoLog has enough memory to
-// accomodate the object code. The size of the buffer required to
-// store the returned object code can be obtained by calling
-// ShGetInfo with SH_OBJECT_CODE_LENGTH.
-COMPILER_EXPORT void ShGetObjectCode(const ShHandle handle, char* objCode);
-
-// Returns information about a shader variable.
-// Parameters:
-// handle: Specifies the compiler
-// variableType: Specifies the variable type; options include
-// SH_ACTIVE_ATTRIBUTES, SH_ACTIVE_UNIFORMS, SH_VARYINGS.
-// index: Specifies the index of the variable to be queried.
-// length: Returns the number of characters actually written in the string
-// indicated by name (excluding the null terminator) if a value other
-// than NULL is passed.
-// size: Returns the size of the variable.
-// type: Returns the data type of the variable.
-// precision: Returns the precision of the variable.
-// staticUse: Returns 1 if the variable is accessed in a statement after
-// pre-processing, whether or not run-time flow of control will
-// cause that statement to be executed.
-// Returns 0 otherwise.
-// name: Returns a null terminated string containing the name of the
-// variable. It is assumed that name has enough memory to accormodate
-// the variable name. The size of the buffer required to store the
-// variable name can be obtained by calling ShGetInfo with
-// SH_ACTIVE_ATTRIBUTE_MAX_LENGTH, SH_ACTIVE_UNIFORM_MAX_LENGTH,
-// SH_VARYING_MAX_LENGTH.
-// mappedName: Returns a null terminated string containing the mapped name of
-// the variable, It is assumed that mappedName has enough memory
-// (SH_MAPPED_NAME_MAX_LENGTH), or NULL if don't care about the
-// mapped name. If the name is not mapped, then name and mappedName
-// are the same.
-COMPILER_EXPORT void ShGetVariableInfo(const ShHandle handle,
- ShShaderInfo variableType,
- int index,
- size_t* length,
- int* size,
- sh::GLenum* type,
- ShPrecisionType* precision,
- int* staticUse,
- char* name,
- char* mappedName);
-
-// Returns information about a name hashing entry from the latest compile.
+COMPILER_EXPORT const std::string &ShGetObjectCode(const ShHandle handle);
+
+// Returns a (original_name, hash) map containing all the user defined
+// names in the shader, including variable names, function names, struct
+// names, and struct field names.
// Parameters:
// handle: Specifies the compiler
-// index: Specifies the index of the name hashing entry to be queried.
-// name: Returns a null terminated string containing the user defined name.
-// It is assumed that name has enough memory to accomodate the name.
-// The size of the buffer required to store the user defined name can
-// be obtained by calling ShGetInfo with SH_NAME_MAX_LENGTH.
-// hashedName: Returns a null terminated string containing the hashed name of
-// the uniform variable, It is assumed that hashedName has enough
-// memory to accomodate the name. The size of the buffer required
-// to store the name can be obtained by calling ShGetInfo with
-// SH_HASHED_NAME_MAX_LENGTH.
-COMPILER_EXPORT void ShGetNameHashingEntry(const ShHandle handle,
- int index,
- char* name,
- char* hashedName);
+COMPILER_EXPORT const std::map<std::string, std::string> *ShGetNameHashingMap(
+ const ShHandle handle);
// Shader variable inspection.
// Returns a pointer to a list of variables of the designated type.
@@ -470,17 +372,17 @@ typedef struct
int size;
} ShVariableInfo;
-// Returns 1 if the passed in variables pack in maxVectors following
+// Returns true if the passed in variables pack in maxVectors following
// the packing rules from the GLSL 1.017 spec, Appendix A, section 7.
-// Returns 0 otherwise. Also look at the SH_ENFORCE_PACKING_RESTRICTIONS
+// Returns false otherwise. Also look at the SH_ENFORCE_PACKING_RESTRICTIONS
// flag above.
// Parameters:
// maxVectors: the available rows of registers.
// varInfoArray: an array of variable info (types and sizes).
// varInfoArraySize: the size of the variable array.
-COMPILER_EXPORT int ShCheckVariablesWithinPackingLimits(
+COMPILER_EXPORT bool ShCheckVariablesWithinPackingLimits(
int maxVectors,
- ShVariableInfo* varInfoArray,
+ ShVariableInfo *varInfoArray,
size_t varInfoArraySize);
// Gives the compiler-assigned register for an interface block.
@@ -491,7 +393,7 @@ COMPILER_EXPORT int ShCheckVariablesWithinPackingLimits(
// interfaceBlockName: Specifies the interface block
// indexOut: output variable that stores the assigned register
COMPILER_EXPORT bool ShGetInterfaceBlockRegister(const ShHandle handle,
- const char *interfaceBlockName,
+ const std::string &interfaceBlockName,
unsigned int *indexOut);
// Gives the compiler-assigned register for uniforms in the default
@@ -503,11 +405,7 @@ COMPILER_EXPORT bool ShGetInterfaceBlockRegister(const ShHandle handle,
// interfaceBlockName: Specifies the uniform
// indexOut: output variable that stores the assigned register
COMPILER_EXPORT bool ShGetUniformRegister(const ShHandle handle,
- const char *uniformName,
+ const std::string &uniformName,
unsigned int *indexOut);
-#ifdef __cplusplus
-}
-#endif
-
#endif // _COMPILER_INTERFACE_INCLUDED_
diff --git a/platform/winrt/include/GLSLANG/ShaderVars.h b/platform/winrt/include/GLSLANG/ShaderVars.h
index 03ddf956f1..dc452b0cf4 100644
--- a/platform/winrt/include/GLSLANG/ShaderVars.h
+++ b/platform/winrt/include/GLSLANG/ShaderVars.h
@@ -15,6 +15,7 @@
#include <algorithm>
// Assume ShaderLang.h is included before ShaderVars.h, for sh::GLenum
+// Note: make sure to increment ANGLE_SH_VERSION when changing ShaderVars.h
namespace sh
{
@@ -39,7 +40,7 @@ enum BlockLayoutType
// Note: we must override the copy constructor and assignment operator so we can
// work around excessive GCC binary bloating:
// See https://code.google.com/p/angleproject/issues/detail?id=697
-struct ShaderVariable
+struct COMPILER_EXPORT ShaderVariable
{
ShaderVariable();
ShaderVariable(GLenum typeIn, unsigned int arraySizeIn);
@@ -49,6 +50,22 @@ struct ShaderVariable
bool isArray() const { return arraySize > 0; }
unsigned int elementCount() const { return std::max(1u, arraySize); }
+ bool isStruct() const { return !fields.empty(); }
+
+ // All of the shader's variables are described using nested data
+ // structures. This is needed in order to disambiguate similar looking
+ // types, such as two structs containing the same fields, but in
+ // different orders. "findInfoByMappedName" provides an easy query for
+ // users to dive into the data structure and fetch the unique variable
+ // instance corresponding to a dereferencing chain of the top-level
+ // variable.
+ // Given a mapped name like 'a[0].b.c[0]', return the ShaderVariable
+ // that defines 'c' in |leafVar|, and the original name 'A[0].B.C[0]'
+ // in |originalName|, based on the assumption that |this| defines 'a'.
+ // If no match is found, return false.
+ bool findInfoByMappedName(const std::string &mappedFullName,
+ const ShaderVariable **leafVar,
+ std::string* originalFullName) const;
GLenum type;
GLenum precision;
@@ -56,58 +73,97 @@ struct ShaderVariable
std::string mappedName;
unsigned int arraySize;
bool staticUse;
+ std::vector<ShaderVariable> fields;
+ std::string structName;
+
+ protected:
+ bool isSameVariableAtLinkTime(const ShaderVariable &other,
+ bool matchPrecision) const;
+
+ bool operator==(const ShaderVariable &other) const;
+ bool operator!=(const ShaderVariable &other) const
+ {
+ return !operator==(other);
+ }
};
-struct Uniform : public ShaderVariable
+struct COMPILER_EXPORT Uniform : public ShaderVariable
{
Uniform();
~Uniform();
Uniform(const Uniform &other);
Uniform &operator=(const Uniform &other);
-
- bool isStruct() const { return !fields.empty(); }
-
- std::vector<Uniform> fields;
+ bool operator==(const Uniform &other) const;
+ bool operator!=(const Uniform &other) const
+ {
+ return !operator==(other);
+ }
+
+ // Decide whether two uniforms are the same at shader link time,
+ // assuming one from vertex shader and the other from fragment shader.
+ // See GLSL ES Spec 3.00.3, sec 4.3.5.
+ bool isSameUniformAtLinkTime(const Uniform &other) const;
};
-struct Attribute : public ShaderVariable
+struct COMPILER_EXPORT Attribute : public ShaderVariable
{
Attribute();
~Attribute();
Attribute(const Attribute &other);
Attribute &operator=(const Attribute &other);
+ bool operator==(const Attribute &other) const;
+ bool operator!=(const Attribute &other) const
+ {
+ return !operator==(other);
+ }
int location;
};
-struct InterfaceBlockField : public ShaderVariable
+struct COMPILER_EXPORT InterfaceBlockField : public ShaderVariable
{
InterfaceBlockField();
~InterfaceBlockField();
InterfaceBlockField(const InterfaceBlockField &other);
InterfaceBlockField &operator=(const InterfaceBlockField &other);
+ bool operator==(const InterfaceBlockField &other) const;
+ bool operator!=(const InterfaceBlockField &other) const
+ {
+ return !operator==(other);
+ }
+
+ // Decide whether two InterfaceBlock fields are the same at shader
+ // link time, assuming one from vertex shader and the other from
+ // fragment shader.
+ // See GLSL ES Spec 3.00.3, sec 4.3.7.
+ bool isSameInterfaceBlockFieldAtLinkTime(
+ const InterfaceBlockField &other) const;
- bool isStruct() const { return !fields.empty(); }
-
- bool isRowMajorMatrix;
- std::vector<InterfaceBlockField> fields;
+ bool isRowMajorLayout;
};
-struct Varying : public ShaderVariable
+struct COMPILER_EXPORT Varying : public ShaderVariable
{
Varying();
~Varying();
- Varying(const Varying &other);
+ Varying(const Varying &otherg);
Varying &operator=(const Varying &other);
+ bool operator==(const Varying &other) const;
+ bool operator!=(const Varying &other) const
+ {
+ return !operator==(other);
+ }
- bool isStruct() const { return !fields.empty(); }
+ // Decide whether two varyings are the same at shader link time,
+ // assuming one from vertex shader and the other from fragment shader.
+ // See GLSL ES Spec 3.00.3, sec 4.3.9.
+ bool isSameVaryingAtLinkTime(const Varying &other) const;
InterpolationType interpolation;
- std::vector<Varying> fields;
- std::string structName;
+ bool isInvariant;
};
-struct InterfaceBlock
+struct COMPILER_EXPORT InterfaceBlock
{
InterfaceBlock();
~InterfaceBlock();
@@ -116,6 +172,7 @@ struct InterfaceBlock
std::string name;
std::string mappedName;
+ std::string instanceName;
unsigned int arraySize;
BlockLayoutType layout;
bool isRowMajorLayout;
diff --git a/platform/winrt/include/angle_windowsstore.h b/platform/winrt/include/angle_windowsstore.h
new file mode 100644
index 0000000000..fe587bf269
--- /dev/null
+++ b/platform/winrt/include/angle_windowsstore.h
@@ -0,0 +1,37 @@
+//
+// Copyright (c) 2014 The ANGLE Project Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+//
+// angle_windowsstore.h:
+
+#ifndef ANGLE_WINDOWSSTORE_H_
+#define ANGLE_WINDOWSSTORE_H_
+
+// The following properties can be set on the CoreApplication to support additional
+// ANGLE configuration options.
+//
+// The Visual Studio sample templates provided with this version of ANGLE have examples
+// of how to set these property values.
+
+//
+// Property: EGLNativeWindowTypeProperty
+// Type: IInspectable
+// Description: Set this property to specify the window type to use for creating a surface.
+// If this property is missing, surface creation will fail.
+//
+const wchar_t EGLNativeWindowTypeProperty[] = L"EGLNativeWindowTypeProperty";
+
+//
+// Property: EGLRenderSurfaceSizeProperty
+// Type: Size
+// Description: Set this property to specify a preferred size in pixels of the render surface.
+// The render surface size width and height must be greater than 0.
+// If this property is set, then the render surface size is fixed.
+// If this property is missing, a default behavior will be provided.
+// The default behavior uses the window size if a CoreWindow is specified or
+// the size of the SwapChainPanel control if one is specified.
+//
+const wchar_t EGLRenderSurfaceSizeProperty[] = L"EGLRenderSurfaceSizeProperty";
+
+#endif // ANGLE_WINDOWSSTORE_H_
diff --git a/platform/winrt/os_winrt.cpp b/platform/winrt/os_winrt.cpp
index 99c4ad968e..89fa93c5c4 100644
--- a/platform/winrt/os_winrt.cpp
+++ b/platform/winrt/os_winrt.cpp
@@ -71,7 +71,7 @@ const char * OSWinrt::get_video_driver_name(int p_driver) const {
OS::VideoMode OSWinrt::get_default_video_mode() const {
- return VideoMode(800,600,false);
+ return video_mode;
}
int OSWinrt::get_audio_driver_count() const {
@@ -142,12 +142,27 @@ void OSWinrt::set_gl_context(ContextEGL* p_context) {
gl_context = p_context;
};
+void OSWinrt::screen_size_changed() {
+
+ gl_context->reset();
+};
+
void OSWinrt::initialize(const VideoMode& p_desired,int p_video_driver,int p_audio_driver) {
main_loop=NULL;
outside=true;
gl_context->initialize();
+ VideoMode vm;
+ vm.width = gl_context->get_window_width();
+ vm.height = gl_context->get_window_height();
+ vm.fullscreen = true;
+ vm.resizable = false;
+
+ set_video_mode(vm);
+
+ gl_context->make_current();
+ rasterizer = memnew( RasterizerGLES2 );
visual_server = memnew( VisualServerRaster(rasterizer) );
if (get_render_thread_mode()!=RENDER_THREAD_UNSAFE) {
@@ -270,6 +285,11 @@ String OSWinrt::get_clipboard() const {
};
+void OSWinrt::input_event(InputEvent &p_event) {
+ p_event.ID = ++last_id;
+ input->parse_input_event(p_event);
+};
+
void OSWinrt::delete_main_loop() {
if (main_loop)
@@ -392,7 +412,7 @@ void OSWinrt::set_window_title(const String& p_title) {
void OSWinrt::set_video_mode(const VideoMode& p_video_mode,int p_screen) {
-
+ video_mode = p_video_mode;
}
OS::VideoMode OSWinrt::get_video_mode(int p_screen) const {
@@ -512,7 +532,7 @@ Error OSWinrt::kill(const ProcessID& p_pid) {
Error OSWinrt::set_cwd(const String& p_cwd) {
- return OK;
+ return FAILED;
}
String OSWinrt::get_executable_path() const {
@@ -553,8 +573,12 @@ Error OSWinrt::shell_open(String p_uri) {
String OSWinrt::get_locale() const {
+#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP // this should work on phone 8.1, but it doesn't
+ return "en";
+#else
Platform::String ^language = Windows::Globalization::Language::CurrentInputMethodLanguageTag;
return language->Data();
+#endif
}
void OSWinrt::release_rendering_thread() {
@@ -634,6 +658,7 @@ OSWinrt::OSWinrt() {
gl_context = NULL;
+ AudioDriverManagerSW::add_driver(&audio_driver);
}
diff --git a/platform/winrt/os_winrt.h b/platform/winrt/os_winrt.h
index c309239af1..68236309a9 100644
--- a/platform/winrt/os_winrt.h
+++ b/platform/winrt/os_winrt.h
@@ -40,6 +40,7 @@
#include "servers/spatial_sound/spatial_sound_server_sw.h"
#include "servers/spatial_sound_2d/spatial_sound_2d_server_sw.h"
#include "servers/physics_2d/physics_2d_server_sw.h"
+#include "servers/audio/audio_driver_dummy.h"
#include "gl_context_egl.h"
@@ -124,6 +125,7 @@ class OSWinrt : public OS {
MainLoop *main_loop;
+ AudioDriverDummy audio_driver;
AudioServerSW *audio_server;
SampleManagerMallocSW *sample_manager;
SpatialSoundServerSW *spatial_sound_server;
@@ -226,17 +228,22 @@ public:
virtual String get_data_dir() const;
void set_gl_context(ContextEGL* p_context);
+ void screen_size_changed();
virtual void release_rendering_thread();
virtual void make_rendering_thread();
virtual void swap_buffers();
+ virtual bool has_touchscreen_ui_hint() const { return true; };
+
virtual Error shell_open(String p_uri);
void run();
virtual bool get_swap_ok_cancel() { return true; }
+ void input_event(InputEvent &p_event);
+
OSWinrt();
~OSWinrt();
diff --git a/platform/x11/detect.py b/platform/x11/detect.py
index 1c8d231d4a..dd5fa827ff 100644
--- a/platform/x11/detect.py
+++ b/platform/x11/detect.py
@@ -114,6 +114,14 @@ def configure(env):
env.Append(CPPFLAGS=['-DOPENGL_ENABLED','-DGLEW_ENABLED'])
env.Append(CPPFLAGS=["-DALSA_ENABLED"])
+
+ if not os.system("pkg-config --exists libpulse-simple"):
+ print("Enabling PulseAudio")
+ env.Append(CPPFLAGS=["-DPULSEAUDIO_ENABLED"])
+ env.ParseConfig('pkg-config --cflags --libs libpulse-simple')
+ else:
+ print("PulseAudio development libraries not found, disabling driver")
+
env.Append(CPPFLAGS=['-DX11_ENABLED','-DUNIX_ENABLED','-DGLES2_ENABLED','-DGLES1_ENABLED','-DGLES_OVER_GL'])
env.Append(LIBS=['GL', 'GLU', 'pthread','asound','z']) #TODO detect linux/BSD!
#env.Append(CPPFLAGS=['-DMPC_FIXED_POINT'])
diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp
index 0466984359..aa9e4c63c9 100644
--- a/platform/x11/os_x11.cpp
+++ b/platform/x11/os_x11.cpp
@@ -74,6 +74,18 @@ OS::VideoMode OS_X11::get_default_video_mode() const {
return OS::VideoMode(800,600,false);
}
+int OS_X11::get_audio_driver_count() const {
+
+ return AudioDriverManagerSW::get_driver_count();
+}
+
+const char *OS_X11::get_audio_driver_name(int p_driver) const {
+
+ AudioDriverSW* driver = AudioDriverManagerSW::get_driver(p_driver);
+ ERR_FAIL_COND_V( !driver, "" );
+ return AudioDriverManagerSW::get_driver(p_driver)->get_name();
+}
+
void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audio_driver) {
last_button_state=0;
@@ -1446,6 +1458,10 @@ OS_X11::OS_X11() {
AudioDriverManagerSW::add_driver(&driver_rtaudio);
#endif
+#ifdef PULSEAUDIO_ENABLED
+ AudioDriverManagerSW::add_driver(&driver_pulseaudio);
+#endif
+
#ifdef ALSA_ENABLED
AudioDriverManagerSW::add_driver(&driver_alsa);
#endif
diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h
index 67772894fa..dd2476ec1b 100644
--- a/platform/x11/os_x11.h
+++ b/platform/x11/os_x11.h
@@ -43,6 +43,7 @@
#include "servers/spatial_sound_2d/spatial_sound_2d_server_sw.h"
#include "drivers/rtaudio/audio_driver_rtaudio.h"
#include "drivers/alsa/audio_driver_alsa.h"
+#include "drivers/pulseaudio/audio_driver_pulseaudio.h"
#include "servers/physics_2d/physics_2d_server_sw.h"
#include <X11/keysym.h>
@@ -129,6 +130,10 @@ class OS_X11 : public OS_Unix {
AudioDriverALSA driver_alsa;
#endif
+#ifdef PULSEAUDIO_ENABLED
+ AudioDriverPulseAudio driver_pulseaudio;
+#endif
+
enum {
JOYSTICKS_MAX = 8,
MAX_JOY_AXIS = 32768, // I've no idea
@@ -160,7 +165,10 @@ protected:
virtual int get_video_driver_count() const;
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 void initialize(const VideoMode& p_desired,int p_video_driver,int p_audio_driver);
virtual void finalize();
diff --git a/scene/2d/area_2d.cpp b/scene/2d/area_2d.cpp
index ca2a42026d..fce21f6001 100644
--- a/scene/2d/area_2d.cpp
+++ b/scene/2d/area_2d.cpp
@@ -73,14 +73,25 @@ real_t Area2D::get_gravity() const{
return gravity;
}
-void Area2D::set_density(real_t p_density){
+void Area2D::set_linear_damp(real_t p_linear_damp){
- density=p_density;
- Physics2DServer::get_singleton()->area_set_param(get_rid(),Physics2DServer::AREA_PARAM_DENSITY,p_density);
+ linear_damp=p_linear_damp;
+ Physics2DServer::get_singleton()->area_set_param(get_rid(),Physics2DServer::AREA_PARAM_LINEAR_DAMP,p_linear_damp);
}
-real_t Area2D::get_density() const{
+real_t Area2D::get_linear_damp() const{
- return density;
+ return linear_damp;
+}
+
+void Area2D::set_angular_damp(real_t p_angular_damp){
+
+ angular_damp=p_angular_damp;
+ Physics2DServer::get_singleton()->area_set_param(get_rid(),Physics2DServer::AREA_PARAM_ANGULAR_DAMP,p_angular_damp);
+}
+
+real_t Area2D::get_angular_damp() const{
+
+ return angular_damp;
}
void Area2D::set_priority(real_t p_priority){
@@ -314,8 +325,11 @@ void Area2D::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_gravity","gravity"),&Area2D::set_gravity);
ObjectTypeDB::bind_method(_MD("get_gravity"),&Area2D::get_gravity);
- ObjectTypeDB::bind_method(_MD("set_density","density"),&Area2D::set_density);
- ObjectTypeDB::bind_method(_MD("get_density"),&Area2D::get_density);
+ ObjectTypeDB::bind_method(_MD("set_linear_damp","linear_damp"),&Area2D::set_linear_damp);
+ ObjectTypeDB::bind_method(_MD("get_linear_damp"),&Area2D::get_linear_damp);
+
+ ObjectTypeDB::bind_method(_MD("set_angular_damp","angular_damp"),&Area2D::set_angular_damp);
+ ObjectTypeDB::bind_method(_MD("get_angular_damp"),&Area2D::get_angular_damp);
ObjectTypeDB::bind_method(_MD("set_priority","priority"),&Area2D::set_priority);
ObjectTypeDB::bind_method(_MD("get_priority"),&Area2D::get_priority);
@@ -337,7 +351,8 @@ void Area2D::_bind_methods() {
ADD_PROPERTY( PropertyInfo(Variant::BOOL,"gravity_point"),_SCS("set_gravity_is_point"),_SCS("is_gravity_a_point"));
ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"gravity_vec"),_SCS("set_gravity_vector"),_SCS("get_gravity_vector"));
ADD_PROPERTY( PropertyInfo(Variant::REAL,"gravity",PROPERTY_HINT_RANGE,"-1024,1024,0.01"),_SCS("set_gravity"),_SCS("get_gravity"));
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"density",PROPERTY_HINT_RANGE,"0,1024,0.001"),_SCS("set_density"),_SCS("get_density"));
+ ADD_PROPERTY( PropertyInfo(Variant::REAL,"linear_damp",PROPERTY_HINT_RANGE,"0,1024,0.001"),_SCS("set_linear_damp"),_SCS("get_linear_damp"));
+ 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"));
@@ -349,7 +364,8 @@ Area2D::Area2D() : CollisionObject2D(Physics2DServer::get_singleton()->area_crea
set_gravity(98);;
set_gravity_vector(Vector2(0,1));
gravity_is_point=false;
- density=0.1;
+ linear_damp=0.1;
+ angular_damp=1;
locked=false;
priority=0;
monitoring=false;
diff --git a/scene/2d/area_2d.h b/scene/2d/area_2d.h
index 2044cc7db0..f770e88a19 100644
--- a/scene/2d/area_2d.h
+++ b/scene/2d/area_2d.h
@@ -49,7 +49,8 @@ private:
Vector2 gravity_vec;
real_t gravity;
bool gravity_is_point;
- real_t density;
+ real_t linear_damp;
+ real_t angular_damp;
int priority;
bool monitoring;
bool locked;
@@ -104,8 +105,11 @@ public:
void set_gravity(real_t p_gravity);
real_t get_gravity() const;
- void set_density(real_t p_density);
- real_t get_density() const;
+ void set_linear_damp(real_t p_linear_damp);
+ real_t get_linear_damp() const;
+
+ void set_angular_damp(real_t p_angular_damp);
+ real_t get_angular_damp() const;
void set_priority(real_t p_priority);
real_t get_priority() const;
diff --git a/scene/2d/collision_polygon_2d.cpp b/scene/2d/collision_polygon_2d.cpp
index 57495b5cb0..1c0be60764 100644
--- a/scene/2d/collision_polygon_2d.cpp
+++ b/scene/2d/collision_polygon_2d.cpp
@@ -41,7 +41,6 @@ void CollisionPolygon2D::_add_to_collision_object(Object *p_obj) {
bool solids=build_mode==BUILD_SOLIDS;
-
if (solids) {
//here comes the sun, lalalala
@@ -51,6 +50,8 @@ void CollisionPolygon2D::_add_to_collision_object(Object *p_obj) {
Ref<ConvexPolygonShape2D> convex = memnew( ConvexPolygonShape2D );
convex->set_points(decomp[i]);
co->add_shape(convex,get_transform());
+ if (trigger)
+ co->set_shape_as_trigger(co->get_shape_count()-1,true);
}
@@ -71,6 +72,8 @@ void CollisionPolygon2D::_add_to_collision_object(Object *p_obj) {
concave->set_segments(segments);
co->add_shape(concave,get_transform());
+ if (trigger)
+ co->set_shape_as_trigger(co->get_shape_count()-1,true);
}
@@ -166,6 +169,18 @@ Rect2 CollisionPolygon2D::get_item_rect() const {
return aabb;
}
+void CollisionPolygon2D::set_trigger(bool p_trigger) {
+
+ trigger=p_trigger;
+ _update_parent();
+}
+
+bool CollisionPolygon2D::is_trigger() const{
+
+ return trigger;
+}
+
+
void CollisionPolygon2D::_bind_methods() {
ObjectTypeDB::bind_method(_MD("_add_to_collision_object"),&CollisionPolygon2D::_add_to_collision_object);
@@ -175,14 +190,19 @@ void CollisionPolygon2D::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_build_mode"),&CollisionPolygon2D::set_build_mode);
ObjectTypeDB::bind_method(_MD("get_build_mode"),&CollisionPolygon2D::get_build_mode);
+ ObjectTypeDB::bind_method(_MD("set_trigger"),&CollisionPolygon2D::set_trigger);
+ ObjectTypeDB::bind_method(_MD("is_trigger"),&CollisionPolygon2D::is_trigger);
+
ADD_PROPERTY( PropertyInfo(Variant::INT,"build_mode",PROPERTY_HINT_ENUM,"Solids,Segments"),_SCS("set_build_mode"),_SCS("get_build_mode"));
ADD_PROPERTY( PropertyInfo(Variant::VECTOR2_ARRAY,"polygon"),_SCS("set_polygon"),_SCS("get_polygon"));
+ ADD_PROPERTY( PropertyInfo(Variant::BOOL,"trigger"),_SCS("set_trigger"),_SCS("is_trigger"));
}
CollisionPolygon2D::CollisionPolygon2D() {
aabb=Rect2(-10,-10,20,20);
build_mode=BUILD_SOLIDS;
+ trigger=false;
}
diff --git a/scene/2d/collision_polygon_2d.h b/scene/2d/collision_polygon_2d.h
index 09c2060088..b8e27b6fb4 100644
--- a/scene/2d/collision_polygon_2d.h
+++ b/scene/2d/collision_polygon_2d.h
@@ -50,6 +50,7 @@ protected:
Rect2 aabb;
BuildMode build_mode;
Vector<Point2> polygon;
+ bool trigger;
void _add_to_collision_object(Object *p_obj);
void _update_parent();
@@ -60,6 +61,9 @@ protected:
static void _bind_methods();
public:
+ void set_trigger(bool p_trigger);
+ bool is_trigger() const;
+
void set_build_mode(BuildMode p_mode);
BuildMode get_build_mode() const;
diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp
index 655c6e8bf6..2413fbded1 100644
--- a/scene/2d/physics_body_2d.cpp
+++ b/scene/2d/physics_body_2d.cpp
@@ -496,6 +496,42 @@ real_t RigidBody2D::get_bounce() const{
return bounce;
}
+
+void RigidBody2D::set_gravity_scale(real_t p_gravity_scale){
+
+ gravity_scale=p_gravity_scale;
+ Physics2DServer::get_singleton()->body_set_param(get_rid(),Physics2DServer::BODY_PARAM_GRAVITY_SCALE,gravity_scale);
+
+}
+real_t RigidBody2D::get_gravity_scale() const{
+
+ return gravity_scale;
+}
+
+void RigidBody2D::set_linear_damp(real_t p_linear_damp){
+
+ ERR_FAIL_COND(p_linear_damp<-1);
+ linear_damp=p_linear_damp;
+ Physics2DServer::get_singleton()->body_set_param(get_rid(),Physics2DServer::BODY_PARAM_LINEAR_DAMP,linear_damp);
+
+}
+real_t RigidBody2D::get_linear_damp() const{
+
+ return linear_damp;
+}
+
+void RigidBody2D::set_angular_damp(real_t p_angular_damp){
+
+ ERR_FAIL_COND(p_angular_damp<-1);
+ angular_damp=p_angular_damp;
+ Physics2DServer::get_singleton()->body_set_param(get_rid(),Physics2DServer::BODY_PARAM_ANGULAR_DAMP,angular_damp);
+
+}
+real_t RigidBody2D::get_angular_damp() const{
+
+ return angular_damp;
+}
+
void RigidBody2D::set_axis_velocity(const Vector2& p_axis) {
Vector2 v = state? state->get_linear_velocity() : linear_velocity;
@@ -683,6 +719,15 @@ void RigidBody2D::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_bounce","bounce"),&RigidBody2D::set_bounce);
ObjectTypeDB::bind_method(_MD("get_bounce"),&RigidBody2D::get_bounce);
+ ObjectTypeDB::bind_method(_MD("set_gravity_scale","gravity_scale"),&RigidBody2D::set_gravity_scale);
+ ObjectTypeDB::bind_method(_MD("get_gravity_scale"),&RigidBody2D::get_gravity_scale);
+
+ ObjectTypeDB::bind_method(_MD("set_linear_damp","linear_damp"),&RigidBody2D::set_linear_damp);
+ ObjectTypeDB::bind_method(_MD("get_linear_damp"),&RigidBody2D::get_linear_damp);
+
+ ObjectTypeDB::bind_method(_MD("set_angular_damp","angular_damp"),&RigidBody2D::set_angular_damp);
+ ObjectTypeDB::bind_method(_MD("get_angular_damp"),&RigidBody2D::get_angular_damp);
+
ObjectTypeDB::bind_method(_MD("set_linear_velocity","linear_velocity"),&RigidBody2D::set_linear_velocity);
ObjectTypeDB::bind_method(_MD("get_linear_velocity"),&RigidBody2D::get_linear_velocity);
@@ -726,6 +771,7 @@ void RigidBody2D::_bind_methods() {
ADD_PROPERTY( PropertyInfo(Variant::REAL,"weight",PROPERTY_HINT_EXP_RANGE,"0.01,65535,0.01",PROPERTY_USAGE_EDITOR),_SCS("set_weight"),_SCS("get_weight"));
ADD_PROPERTY( PropertyInfo(Variant::REAL,"friction",PROPERTY_HINT_RANGE,"0,1,0.01"),_SCS("set_friction"),_SCS("get_friction"));
ADD_PROPERTY( PropertyInfo(Variant::REAL,"bounce",PROPERTY_HINT_RANGE,"0,1,0.01"),_SCS("set_bounce"),_SCS("get_bounce"));
+ ADD_PROPERTY( PropertyInfo(Variant::REAL,"gravity_scale",PROPERTY_HINT_RANGE,"-128,128,0.01"),_SCS("set_gravity_scale"),_SCS("get_gravity_scale"));
ADD_PROPERTY( PropertyInfo(Variant::BOOL,"custom_integrator"),_SCS("set_use_custom_integrator"),_SCS("is_using_custom_integrator"));
ADD_PROPERTY( PropertyInfo(Variant::INT,"continuous_cd",PROPERTY_HINT_ENUM,"Disabled,Cast Ray,Cast Shape"),_SCS("set_continuous_collision_detection_mode"),_SCS("get_continuous_collision_detection_mode"));
ADD_PROPERTY( PropertyInfo(Variant::INT,"contacts_reported"),_SCS("set_max_contacts_reported"),_SCS("get_max_contacts_reported"));
@@ -734,6 +780,8 @@ void RigidBody2D::_bind_methods() {
ADD_PROPERTY( PropertyInfo(Variant::BOOL,"can_sleep"),_SCS("set_can_sleep"),_SCS("is_able_to_sleep"));
ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"velocity/linear"),_SCS("set_linear_velocity"),_SCS("get_linear_velocity"));
ADD_PROPERTY( PropertyInfo(Variant::REAL,"velocity/angular"),_SCS("set_angular_velocity"),_SCS("get_angular_velocity"));
+ ADD_PROPERTY( PropertyInfo(Variant::REAL,"damp_override/linear",PROPERTY_HINT_RANGE,"-1,128,0.01"),_SCS("set_linear_damp"),_SCS("get_linear_damp"));
+ ADD_PROPERTY( PropertyInfo(Variant::REAL,"damp_override/angular",PROPERTY_HINT_RANGE,"-1,128,0.01"),_SCS("set_angular_damp"),_SCS("get_angular_damp"));
ADD_SIGNAL( MethodInfo("body_enter_shape",PropertyInfo(Variant::INT,"body_id"),PropertyInfo(Variant::OBJECT,"body"),PropertyInfo(Variant::INT,"body_shape"),PropertyInfo(Variant::INT,"local_shape")));
ADD_SIGNAL( MethodInfo("body_exit_shape",PropertyInfo(Variant::INT,"body_id"),PropertyInfo(Variant::OBJECT,"body"),PropertyInfo(Variant::INT,"body_shape"),PropertyInfo(Variant::INT,"local_shape")));
@@ -758,6 +806,11 @@ RigidBody2D::RigidBody2D() : PhysicsBody2D(Physics2DServer::BODY_MODE_RIGID) {
bounce=0;
mass=1;
friction=1;
+
+ gravity_scale=1;
+ linear_damp=-1;
+ angular_damp=-1;
+
max_contacts_reported=0;
state=NULL;
@@ -858,7 +911,8 @@ Vector2 KinematicBody2D::move(const Vector2& p_motion) {
//motion recover
for(int i=0;i<get_shape_count();i++) {
-
+ if (is_shape_set_as_trigger(i))
+ continue;
if (dss->collide_shape(get_shape(i)->get_rid(), get_global_transform() * get_shape_transform(i),Vector2(),margin,sr,max_shapes,res_shapes,exclude,get_layer_mask(),mask))
collided=true;
@@ -902,6 +956,8 @@ Vector2 KinematicBody2D::move(const Vector2& p_motion) {
for(int i=0;i<get_shape_count();i++) {
+ if (is_shape_set_as_trigger(i))
+ continue;
float lsafe,lunsafe;
bool valid = dss->cast_motion(get_shape(i)->get_rid(), get_global_transform() * get_shape_transform(i), p_motion, 0,lsafe,lunsafe,exclude,get_layer_mask(),mask);
diff --git a/scene/2d/physics_body_2d.h b/scene/2d/physics_body_2d.h
index ca7b757497..956999ce31 100644
--- a/scene/2d/physics_body_2d.h
+++ b/scene/2d/physics_body_2d.h
@@ -119,6 +119,9 @@ private:
real_t bounce;
real_t mass;
real_t friction;
+ real_t gravity_scale;
+ real_t linear_damp;
+ real_t angular_damp;
Vector2 linear_velocity;
real_t angular_velocity;
@@ -198,6 +201,15 @@ public:
void set_bounce(real_t p_bounce);
real_t get_bounce() const;
+ void set_gravity_scale(real_t p_gravity_scale);
+ real_t get_gravity_scale() const;
+
+ void set_linear_damp(real_t p_linear_damp);
+ real_t get_linear_damp() const;
+
+ void set_angular_damp(real_t p_angular_damp);
+ real_t get_angular_damp() const;
+
void set_linear_velocity(const Vector2& p_velocity);
Vector2 get_linear_velocity() const;
diff --git a/scene/2d/sample_player_2d.cpp b/scene/2d/sample_player_2d.cpp
index 99dfa67c27..a231acd13d 100644
--- a/scene/2d/sample_player_2d.cpp
+++ b/scene/2d/sample_player_2d.cpp
@@ -102,6 +102,7 @@ void SamplePlayer2D::_notification(int p_what) {
void SamplePlayer2D::set_sample_library(const Ref<SampleLibrary>& p_library) {
library=p_library;
+ _change_notify();
}
Ref<SampleLibrary> SamplePlayer2D::get_sample_library() const {
diff --git a/scene/3d/camera.cpp b/scene/3d/camera.cpp
index 1db9886261..27420f8002 100644
--- a/scene/3d/camera.cpp
+++ b/scene/3d/camera.cpp
@@ -86,6 +86,10 @@ bool Camera::_set(const StringName& p_name, const Variant& p_value) {
set_keep_aspect_mode(KeepAspect(int(p_value)));
else if (p_name=="vaspect")
set_keep_aspect_mode(p_value?KEEP_WIDTH:KEEP_HEIGHT);
+ else if (p_name=="h_offset")
+ h_offset=p_value;
+ else if (p_name=="v_offset")
+ v_offset=p_value;
else if (p_name=="current") {
if (p_value.operator bool()) {
make_current();
@@ -128,6 +132,10 @@ bool Camera::_get(const StringName& p_name,Variant &r_ret) const {
}
} else if (p_name=="visible_layers") {
r_ret=get_visible_layers();
+ } else if (p_name=="h_offset") {
+ r_ret=get_h_offset();
+ } else if (p_name=="v_offset") {
+ r_ret=get_v_offset();
} else if (p_name=="environment") {
r_ret=get_environment();
} else
@@ -170,12 +178,16 @@ void Camera::_get_property_list( List<PropertyInfo> *p_list) const {
p_list->push_back( PropertyInfo( Variant::BOOL, "current" ) );
p_list->push_back( PropertyInfo( Variant::INT, "visible_layers",PROPERTY_HINT_ALL_FLAGS ) );
p_list->push_back( PropertyInfo( Variant::OBJECT, "environment",PROPERTY_HINT_RESOURCE_TYPE,"Environment" ) );
+ p_list->push_back( PropertyInfo( Variant::REAL, "h_offset" ) );
+ p_list->push_back( PropertyInfo( Variant::REAL, "v_offset" ) );
}
void Camera::_update_camera() {
Transform tr = get_camera_transform();
+ tr.origin+=tr.basis.get_axis(1)*v_offset;
+ tr.origin+=tr.basis.get_axis(0)*h_offset;
VisualServer::get_singleton()->camera_set_transform( camera, tr );
// here goes listener stuff
@@ -757,6 +769,27 @@ void Camera::look_at_from_pos(const Vector3& p_pos,const Vector3& p_target, cons
}
+void Camera::set_v_offset(float p_offset) {
+
+ v_offset=p_offset;
+ _update_camera();;
+}
+
+float Camera::get_v_offset() const {
+
+ return v_offset;
+}
+
+void Camera::set_h_offset(float p_offset) {
+ h_offset=p_offset;
+ _update_camera();
+}
+
+float Camera::get_h_offset() const {
+
+ return h_offset;
+}
+
Camera::Camera() {
@@ -772,6 +805,8 @@ Camera::Camera() {
set_perspective(60.0,0.1,100.0);
keep_aspect=KEEP_HEIGHT;
layers=0xfffff;
+ v_offset=0;
+ h_offset=0;
VisualServer::get_singleton()->camera_set_visible_layers(camera,layers);
//active=false;
}
diff --git a/scene/3d/camera.h b/scene/3d/camera.h
index bac8173bb7..950688dfda 100644
--- a/scene/3d/camera.h
+++ b/scene/3d/camera.h
@@ -61,6 +61,8 @@ private:
float fov;
float size;
float near,far;
+ float v_offset;
+ float h_offset;
KeepAspect keep_aspect;
RID camera;
@@ -140,6 +142,12 @@ public:
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;
+
+ void set_h_offset(float p_offset);
+ float get_h_offset() const;
+
Camera();
~Camera();
diff --git a/scene/3d/collision_object.cpp b/scene/3d/collision_object.cpp
index 82158405ea..9c388a2883 100644
--- a/scene/3d/collision_object.cpp
+++ b/scene/3d/collision_object.cpp
@@ -47,6 +47,11 @@ void CollisionObject::_notification(int p_what) {
case NOTIFICATION_ENTER_WORLD: {
+ if (area)
+ PhysicsServer::get_singleton()->area_set_transform(rid,get_global_transform());
+ else
+ PhysicsServer::get_singleton()->body_set_state(rid,PhysicsServer::BODY_STATE_TRANSFORM,get_global_transform());
+
RID space = get_world()->get_space();
if (area) {
PhysicsServer::get_singleton()->area_set_space(rid,space);
diff --git a/scene/3d/immediate_geometry.cpp b/scene/3d/immediate_geometry.cpp
index a4206894ff..651d20ae71 100644
--- a/scene/3d/immediate_geometry.cpp
+++ b/scene/3d/immediate_geometry.cpp
@@ -127,7 +127,7 @@ void ImmediateGeometry::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_color","color"),&ImmediateGeometry::set_color);
ObjectTypeDB::bind_method(_MD("set_uv","uv"),&ImmediateGeometry::set_uv);
ObjectTypeDB::bind_method(_MD("set_uv2","uv"),&ImmediateGeometry::set_uv2);
- ObjectTypeDB::bind_method(_MD("add_vertex","color"),&ImmediateGeometry::add_vertex);
+ ObjectTypeDB::bind_method(_MD("add_vertex","pos"),&ImmediateGeometry::add_vertex);
ObjectTypeDB::bind_method(_MD("add_sphere","lats","lons","radius"),&ImmediateGeometry::add_sphere);
ObjectTypeDB::bind_method(_MD("end"),&ImmediateGeometry::end);
ObjectTypeDB::bind_method(_MD("clear"),&ImmediateGeometry::clear);
diff --git a/scene/3d/physics_body.cpp b/scene/3d/physics_body.cpp
index 21ecac6e3d..f2806f2af2 100644
--- a/scene/3d/physics_body.cpp
+++ b/scene/3d/physics_body.cpp
@@ -852,6 +852,8 @@ Vector3 KinematicBody::move(const Vector3& p_motion) {
//motion recover
for(int i=0;i<get_shape_count();i++) {
+ if (is_shape_set_as_trigger(i))
+ continue;
if (dss->collide_shape(get_shape(i)->get_rid(), get_global_transform() * get_shape_transform(i),m,sr,max_shapes,res_shapes,exclude,get_layer_mask(),mask)) {
collided=true;
@@ -930,6 +932,8 @@ Vector3 KinematicBody::move(const Vector3& p_motion) {
for(int i=0;i<get_shape_count();i++) {
+ if (is_shape_set_as_trigger(i))
+ continue;
float lsafe,lunsafe;
PhysicsDirectSpaceState::ShapeRestInfo lrest;
@@ -1041,6 +1045,8 @@ bool KinematicBody::can_move_to(const Vector3& p_position, bool p_discrete) {
//fill exclude list..
for(int i=0;i<get_shape_count();i++) {
+ if (is_shape_set_as_trigger(i))
+ continue;
bool col = dss->intersect_shape(get_shape(i)->get_rid(), xform * get_shape_transform(i),0,NULL,0,exclude,get_layer_mask(),mask);
if (col)
diff --git a/scene/3d/ray_cast.cpp b/scene/3d/ray_cast.cpp
index 6bc0c677c0..639a86e759 100644
--- a/scene/3d/ray_cast.cpp
+++ b/scene/3d/ray_cast.cpp
@@ -95,18 +95,6 @@ void RayCast::_notification(int p_what) {
if (enabled && !get_tree()->is_editor_hint()) {
set_fixed_process(true);
- Node *p = get_parent();
- while( p && p->cast_to<Spatial>() ) {
-
- CollisionObject *co = p->cast_to<CollisionObject>();
- if (co) {
-
- exception=co->get_rid();
- exceptions.insert(exception);
- }
-
- p=p->get_parent();
- }
} else
set_fixed_process(false);
@@ -119,7 +107,6 @@ void RayCast::_notification(int p_what) {
set_fixed_process(false);
}
- exceptions.erase(exception);
} break;
case NOTIFICATION_FIXED_PROCESS: {
@@ -143,7 +130,7 @@ void RayCast::_notification(int p_what) {
PhysicsDirectSpaceState::RayResult rr;
- if (dss->intersect_ray(gt.get_origin(),gt.xform(to),rr,exceptions)) {
+ if (dss->intersect_ray(gt.get_origin(),gt.xform(to),rr,exclude)) {
collided=true;
against=rr.collider_id;
@@ -160,6 +147,41 @@ void RayCast::_notification(int p_what) {
}
}
+void RayCast::add_exception_rid(const RID& p_rid) {
+
+ exclude.insert(p_rid);
+}
+
+void RayCast::add_exception(const Object* p_object){
+
+ ERR_FAIL_NULL(p_object);
+ CollisionObject *co=((Object*)p_object)->cast_to<CollisionObject>();
+ if (!co)
+ return;
+ add_exception_rid(co->get_rid());
+}
+
+void RayCast::remove_exception_rid(const RID& p_rid) {
+
+ exclude.erase(p_rid);
+}
+
+void RayCast::remove_exception(const Object* p_object){
+
+ ERR_FAIL_NULL(p_object);
+ CollisionObject *co=((Object*)p_object)->cast_to<CollisionObject>();
+ if (!co)
+ return;
+ remove_exception_rid(co->get_rid());
+}
+
+
+void RayCast::clear_exceptions(){
+
+ exclude.clear();
+}
+
+
void RayCast::_bind_methods() {
@@ -176,6 +198,14 @@ void RayCast::_bind_methods() {
ObjectTypeDB::bind_method(_MD("get_collision_point"),&RayCast::get_collision_point);
ObjectTypeDB::bind_method(_MD("get_collision_normal"),&RayCast::get_collision_normal);
+ ObjectTypeDB::bind_method(_MD("add_exception_rid","rid"),&RayCast::add_exception_rid);
+ ObjectTypeDB::bind_method(_MD("add_exception","node"),&RayCast::add_exception);
+
+ ObjectTypeDB::bind_method(_MD("remove_exception_rid","rid"),&RayCast::remove_exception_rid);
+ ObjectTypeDB::bind_method(_MD("remove_exception","node"),&RayCast::remove_exception);
+
+ ObjectTypeDB::bind_method(_MD("clear_exceptions"),&RayCast::clear_exceptions);
+
ADD_PROPERTY(PropertyInfo(Variant::BOOL,"enabled"),_SCS("set_enabled"),_SCS("is_enabled"));
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3,"cast_to"),_SCS("set_cast_to"),_SCS("get_cast_to"));
}
diff --git a/scene/3d/ray_cast.h b/scene/3d/ray_cast.h
index 96606b1628..0239c61b67 100644
--- a/scene/3d/ray_cast.h
+++ b/scene/3d/ray_cast.h
@@ -45,8 +45,7 @@ class RayCast : public Spatial {
Vector3 cast_to;
- RID exception;
- Set<RID> exceptions;
+ Set<RID> exclude;
protected:
@@ -66,6 +65,12 @@ public:
Vector3 get_collision_point() const;
Vector3 get_collision_normal() const;
+ void add_exception_rid(const RID& p_rid);
+ void add_exception(const Object* p_object);
+ void remove_exception_rid(const RID& p_rid);
+ void remove_exception(const Object* p_object);
+ void clear_exceptions();
+
RayCast();
};
diff --git a/scene/3d/spatial_sample_player.cpp b/scene/3d/spatial_sample_player.cpp
index b4a5d3bc1b..6dc71e06ad 100644
--- a/scene/3d/spatial_sample_player.cpp
+++ b/scene/3d/spatial_sample_player.cpp
@@ -103,6 +103,7 @@ void SpatialSamplePlayer::_notification(int p_what) {
void SpatialSamplePlayer::set_sample_library(const Ref<SampleLibrary>& p_library) {
library=p_library;
+ _change_notify();
}
Ref<SampleLibrary> SpatialSamplePlayer::get_sample_library() const {
diff --git a/scene/3d/sprite_3d.cpp b/scene/3d/sprite_3d.cpp
index 77f2cf5cc1..35f6523c6a 100644
--- a/scene/3d/sprite_3d.cpp
+++ b/scene/3d/sprite_3d.cpp
@@ -497,7 +497,7 @@ void Sprite3D::set_frame(int p_frame) {
frame=p_frame;
_queue_update();
- ADD_SIGNAL(MethodInfo("frame_changed"));
+ emit_signal(SceneStringNames::get_singleton()->frame_changed);
}
diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp
index 011850138b..f9d36138a2 100644
--- a/scene/animation/animation_player.cpp
+++ b/scene/animation/animation_player.cpp
@@ -1178,6 +1178,19 @@ NodePath AnimationPlayer::get_root() const {
return root;
}
+void AnimationPlayer::get_argument_options(const StringName& p_function,int p_idx,List<String>*r_options) const {
+
+ String pf = p_function;
+ if (p_function=="play" || p_function=="remove_animation" || p_function=="has_animation" || p_function=="queue") {
+ List<StringName> al;
+ get_animation_list(&al);
+ for (List<StringName>::Element *E=al.front();E;E=E->next()) {
+
+ r_options->push_back("\""+String(E->get())+"\"");
+ }
+ }
+ Node::get_argument_options(p_function,p_idx,r_options);
+}
void AnimationPlayer::_bind_methods() {
diff --git a/scene/animation/animation_player.h b/scene/animation/animation_player.h
index 038c43d569..8ac5d96bf3 100644
--- a/scene/animation/animation_player.h
+++ b/scene/animation/animation_player.h
@@ -289,6 +289,9 @@ public:
NodePath get_root() const;
void clear_caches(); ///< must be called by hand if an animation was modified after added
+
+ void get_argument_options(const StringName& p_function,int p_idx,List<String>*r_options) const;
+
AnimationPlayer();
~AnimationPlayer();
diff --git a/scene/animation/animation_tree_player.cpp b/scene/animation/animation_tree_player.cpp
index ec72123c98..5172907d18 100644
--- a/scene/animation/animation_tree_player.cpp
+++ b/scene/animation/animation_tree_player.cpp
@@ -83,7 +83,8 @@ bool AnimationTreePlayer::_set(const StringName& p_name, const Variant& p_value)
ERR_FAIL_COND_V(nt==NODE_MAX,false);
- add_node(nt,id);
+ if (nt!=NODE_OUTPUT)
+ add_node(nt,id);
node_set_pos(id,pos);
diff --git a/scene/animation/tween.cpp b/scene/animation/tween.cpp
index 59793815f5..f668e52590 100644
--- a/scene/animation/tween.cpp
+++ b/scene/animation/tween.cpp
@@ -124,32 +124,34 @@ void Tween::_bind_methods() {
ObjectTypeDB::bind_method(_MD("get_tween_process_mode"),&Tween::get_tween_process_mode);
ObjectTypeDB::bind_method(_MD("start"),&Tween::start );
- ObjectTypeDB::bind_method(_MD("reset","node","key"),&Tween::reset );
+ ObjectTypeDB::bind_method(_MD("reset","object","key"),&Tween::reset );
ObjectTypeDB::bind_method(_MD("reset_all"),&Tween::reset_all );
- ObjectTypeDB::bind_method(_MD("stop","node","key"),&Tween::stop );
+ ObjectTypeDB::bind_method(_MD("stop","object","key"),&Tween::stop );
ObjectTypeDB::bind_method(_MD("stop_all"),&Tween::stop_all );
- ObjectTypeDB::bind_method(_MD("resume","node","key"),&Tween::resume );
+ ObjectTypeDB::bind_method(_MD("resume","object","key"),&Tween::resume );
ObjectTypeDB::bind_method(_MD("resume_all"),&Tween::resume_all );
- ObjectTypeDB::bind_method(_MD("remove","node","key"),&Tween::remove );
+ ObjectTypeDB::bind_method(_MD("remove","object","key"),&Tween::remove );
ObjectTypeDB::bind_method(_MD("remove_all"),&Tween::remove_all );
ObjectTypeDB::bind_method(_MD("seek","time"),&Tween::seek );
ObjectTypeDB::bind_method(_MD("tell"),&Tween::tell );
ObjectTypeDB::bind_method(_MD("get_runtime"),&Tween::get_runtime );
- ObjectTypeDB::bind_method(_MD("interpolate_property","node","property","initial_val","final_val","times_in_sec","trans_type","ease_type","delay"),&Tween::interpolate_property, DEFVAL(0) );
- ObjectTypeDB::bind_method(_MD("interpolate_method","node","method","initial_val","final_val","times_in_sec","trans_type","ease_type","delay"),&Tween::interpolate_method, DEFVAL(0) );
- ObjectTypeDB::bind_method(_MD("interpolate_callback","node","callback","times_in_sec","args"),&Tween::interpolate_callback, DEFVAL(Variant()) );
- ObjectTypeDB::bind_method(_MD("follow_property","node","property","initial_val","target","target_property","times_in_sec","trans_type","ease_type","delay"),&Tween::follow_property, DEFVAL(0) );
- ObjectTypeDB::bind_method(_MD("follow_method","node","method","initial_val","target","target_method","times_in_sec","trans_type","ease_type","delay"),&Tween::follow_method, DEFVAL(0) );
- ObjectTypeDB::bind_method(_MD("targeting_property","node","property","initial","initial_val","final_val","times_in_sec","trans_type","ease_type","delay"),&Tween::targeting_property, DEFVAL(0) );
- ObjectTypeDB::bind_method(_MD("targeting_method","node","method","initial","initial_method","final_val","times_in_sec","trans_type","ease_type","delay"),&Tween::targeting_method, DEFVAL(0) );
+ ObjectTypeDB::bind_method(_MD("interpolate_property","object","property","initial_val","final_val","times_in_sec","trans_type","ease_type","delay"),&Tween::interpolate_property, DEFVAL(0) );
+ ObjectTypeDB::bind_method(_MD("interpolate_method","object","method","initial_val","final_val","times_in_sec","trans_type","ease_type","delay"),&Tween::interpolate_method, DEFVAL(0) );
+ ObjectTypeDB::bind_method(_MD("interpolate_callback","object","times_in_sec","callback","args"),&Tween::interpolate_callback, DEFVAL(Variant()) );
+ ObjectTypeDB::bind_method(_MD("follow_property","object","property","initial_val","target","target_property","times_in_sec","trans_type","ease_type","delay"),&Tween::follow_property, DEFVAL(0) );
+ ObjectTypeDB::bind_method(_MD("follow_method","object","method","initial_val","target","target_method","times_in_sec","trans_type","ease_type","delay"),&Tween::follow_method, DEFVAL(0) );
+ ObjectTypeDB::bind_method(_MD("targeting_property","object","property","initial","initial_val","final_val","times_in_sec","trans_type","ease_type","delay"),&Tween::targeting_property, DEFVAL(0) );
+ ObjectTypeDB::bind_method(_MD("targeting_method","object","method","initial","initial_method","final_val","times_in_sec","trans_type","ease_type","delay"),&Tween::targeting_method, DEFVAL(0) );
- ADD_SIGNAL( MethodInfo("tween_start", PropertyInfo( Variant::OBJECT,"node"), PropertyInfo( Variant::STRING,"key")) );
- ADD_SIGNAL( MethodInfo("tween_step", PropertyInfo( Variant::OBJECT,"node"), PropertyInfo( Variant::STRING,"key"), PropertyInfo( Variant::REAL,"elapsed"), PropertyInfo( Variant::OBJECT,"value")) );
- ADD_SIGNAL( MethodInfo("tween_complete", PropertyInfo( Variant::OBJECT,"node"), PropertyInfo( Variant::STRING,"key")) );
+ ADD_SIGNAL( MethodInfo("tween_start", PropertyInfo( Variant::OBJECT,"object"), PropertyInfo( Variant::STRING,"key")) );
+ ADD_SIGNAL( MethodInfo("tween_step", PropertyInfo( Variant::OBJECT,"object"), PropertyInfo( Variant::STRING,"key"), PropertyInfo( Variant::REAL,"elapsed"), PropertyInfo( Variant::OBJECT,"value")) );
+ ADD_SIGNAL( MethodInfo("tween_complete", PropertyInfo( Variant::OBJECT,"object"), PropertyInfo( Variant::STRING,"key")) );
ADD_PROPERTY( PropertyInfo( Variant::INT, "playback/process_mode", PROPERTY_HINT_ENUM, "Fixed,Idle"), _SCS("set_tween_process_mode"), _SCS("get_tween_process_mode"));
- //ADD_PROPERTY( PropertyInfo( Variant::BOOL, "activate"), _SCS("set_active"), _SCS("is_active"));
+
+ BIND_CONSTANT(TWEEN_PROCESS_FIXED);
+ BIND_CONSTANT(TWEEN_PROCESS_IDLE);
BIND_CONSTANT(TRANS_LINEAR);
BIND_CONSTANT(TRANS_SINE);
@@ -181,19 +183,19 @@ Variant& Tween::_get_initial_val(InterpolateData& p_data) {
case TARGETING_PROPERTY:
case TARGETING_METHOD: {
- Node *node = get_node(p_data.target);
- ERR_FAIL_COND_V(node == NULL,p_data.initial_val);
+ Object *object = ObjectDB::get_instance(p_data.target_id);
+ ERR_FAIL_COND_V(object == NULL,p_data.initial_val);
static Variant initial_val;
if(p_data.type == TARGETING_PROPERTY) {
bool valid = false;
- initial_val = node->get(p_data.target_key, &valid);
+ initial_val = object->get(p_data.target_key, &valid);
ERR_FAIL_COND_V(!valid,p_data.initial_val);
} else {
Variant::CallError error;
- initial_val = node->call(p_data.target_key, NULL, 0, error);
+ initial_val = object->call(p_data.target_key, NULL, 0, error);
ERR_FAIL_COND_V(error.error != Variant::CallError::CALL_OK,p_data.initial_val);
}
return initial_val;
@@ -213,7 +215,7 @@ Variant& Tween::_get_delta_val(InterpolateData& p_data) {
case FOLLOW_PROPERTY:
case FOLLOW_METHOD: {
- Node *target = get_node(p_data.target);
+ Object *target = ObjectDB::get_instance(p_data.target_id);
ERR_FAIL_COND_V(target == NULL,p_data.initial_val);
Variant final_val;
@@ -264,6 +266,11 @@ Variant Tween::_run_equation(InterpolateData& p_data) {
switch(initial_val.get_type())
{
+
+ case Variant::BOOL:
+ result = ((int) _run_equation(p_data.trans_type, p_data.ease_type, p_data.elapsed - p_data.delay, (int) initial_val, (int) delta_val, p_data.times_in_sec)) >= 0.5;
+ break;
+
case Variant::INT:
result = (int) _run_equation(p_data.trans_type, p_data.ease_type, p_data.elapsed - p_data.delay, (int) initial_val, (int) delta_val, p_data.times_in_sec);
break;
@@ -409,7 +416,7 @@ Variant Tween::_run_equation(InterpolateData& p_data) {
bool Tween::_apply_tween_value(InterpolateData& p_data, Variant& value) {
- Object *object = get_node(p_data.path);
+ Object *object = ObjectDB::get_instance(p_data.id);
ERR_FAIL_COND_V(object == NULL, false);
switch(p_data.type) {
@@ -452,6 +459,7 @@ void Tween::_tween_process(float p_delta) {
return;
p_delta *= speed_scale;
+ pending_update ++;
// if repeat and all interpolates was finished then reset all interpolates
if(repeat) {
bool all_finished = true;
@@ -476,7 +484,7 @@ void Tween::_tween_process(float p_delta) {
if(!data.active || data.finish)
continue;
- Object *object = get_node(data.path);
+ Object *object = ObjectDB::get_instance(data.id);
if(object == NULL)
continue;
@@ -523,6 +531,7 @@ void Tween::_tween_process(float p_delta) {
if(data.finish)
emit_signal("tween_complete",object,data.key);
}
+ pending_update --;
}
void Tween::set_tween_process_mode(TweenProcessMode p_mode) {
@@ -598,16 +607,17 @@ bool Tween::start() {
return true;
}
-bool Tween::reset(Node *p_node, String p_key) {
+bool Tween::reset(Object *p_object, String p_key) {
+ pending_update ++;
for(List<InterpolateData>::Element *E=interpolates.front();E;E=E->next()) {
InterpolateData& data = E->get();
- Node *node = get_node(data.path);
- if(node == NULL)
+ Object *object = ObjectDB::get_instance(data.id);
+ if(object == NULL)
continue;
- if(node == p_node && data.key == p_key) {
+ if(object == p_object && data.key == p_key) {
data.elapsed = 0;
data.finish = false;
@@ -615,11 +625,13 @@ bool Tween::reset(Node *p_node, String p_key) {
_apply_tween_value(data, data.initial_val);
}
}
+ pending_update --;
return true;
}
bool Tween::reset_all() {
+ pending_update ++;
for(List<InterpolateData>::Element *E=interpolates.front();E;E=E->next()) {
InterpolateData& data = E->get();
@@ -628,20 +640,23 @@ bool Tween::reset_all() {
if(data.delay == 0)
_apply_tween_value(data, data.initial_val);
}
+ pending_update --;
return true;
}
-bool Tween::stop(Node *p_node, String p_key) {
+bool Tween::stop(Object *p_object, String p_key) {
+ pending_update ++;
for(List<InterpolateData>::Element *E=interpolates.front();E;E=E->next()) {
InterpolateData& data = E->get();
- Node *node = get_node(data.path);
- if(node == NULL)
+ Object *object = ObjectDB::get_instance(data.id);
+ if(object == NULL)
continue;
- if(node == p_node && data.key == p_key)
+ if(object == p_object && data.key == p_key)
data.active = false;
}
+ pending_update --;
return true;
}
@@ -650,28 +665,32 @@ bool Tween::stop_all() {
set_active(false);
_set_process(false);
+ pending_update ++;
for(List<InterpolateData>::Element *E=interpolates.front();E;E=E->next()) {
InterpolateData& data = E->get();
data.active = false;
}
+ pending_update --;
return true;
}
-bool Tween::resume(Node *p_node, String p_key) {
+bool Tween::resume(Object *p_object, String p_key) {
set_active(true);
_set_process(true);
+ pending_update ++;
for(List<InterpolateData>::Element *E=interpolates.front();E;E=E->next()) {
InterpolateData& data = E->get();
- Node *node = get_node(data.path);
- if(node == NULL)
+ Object *object = ObjectDB::get_instance(data.id);
+ if(object == NULL)
continue;
- if(node == p_node && data.key == p_key)
+ if(object == p_object && data.key == p_key)
data.active = true;
}
+ pending_update --;
return true;
}
@@ -680,23 +699,26 @@ bool Tween::resume_all() {
set_active(true);
_set_process(true);
+ pending_update ++;
for(List<InterpolateData>::Element *E=interpolates.front();E;E=E->next()) {
InterpolateData& data = E->get();
data.active = true;
}
+ pending_update --;
return true;
}
-bool Tween::remove(Node *p_node, String p_key) {
+bool Tween::remove(Object *p_object, String p_key) {
+ ERR_FAIL_COND_V(pending_update != 0, false);
for(List<InterpolateData>::Element *E=interpolates.front();E;E=E->next()) {
InterpolateData& data = E->get();
- Node *node = get_node(data.path);
- if(node == NULL)
+ Object *object = ObjectDB::get_instance(data.id);
+ if(object == NULL)
continue;
- if(node == p_node && data.key == p_key) {
+ if(object == p_object && data.key == p_key) {
interpolates.erase(E);
return true;
}
@@ -706,6 +728,7 @@ bool Tween::remove(Node *p_node, String p_key) {
bool Tween::remove_all() {
+ ERR_FAIL_COND_V(pending_update != 0, false);
set_active(false);
_set_process(false);
interpolates.clear();
@@ -714,6 +737,7 @@ bool Tween::remove_all() {
bool Tween::seek(real_t p_time) {
+ pending_update ++;
for(List<InterpolateData>::Element *E=interpolates.front();E;E=E->next()) {
InterpolateData& data = E->get();
@@ -744,11 +768,13 @@ bool Tween::seek(real_t p_time) {
_apply_tween_value(data, result);
}
+ pending_update --;
return true;
}
real_t Tween::tell() const {
+ pending_update ++;
real_t pos = 0;
for(const List<InterpolateData>::Element *E=interpolates.front();E;E=E->next()) {
@@ -756,11 +782,13 @@ real_t Tween::tell() const {
if(data.elapsed > pos)
pos = data.elapsed;
}
+ pending_update --;
return pos;
}
real_t Tween::get_runtime() const {
+ pending_update ++;
real_t runtime = 0;
for(const List<InterpolateData>::Element *E=interpolates.front();E;E=E->next()) {
@@ -769,6 +797,7 @@ real_t Tween::get_runtime() const {
if(t > runtime)
runtime = t;
}
+ pending_update --;
return runtime;
}
@@ -779,6 +808,12 @@ bool Tween::_calc_delta_val(const Variant& p_initial_val, const Variant& p_final
Variant& delta_val = p_delta_val;
switch(initial_val.get_type()) {
+
+ case Variant::BOOL:
+ //delta_val = p_final_val;
+ delta_val = (int) p_final_val - (int) p_initial_val;
+ break;
+
case Variant::INT:
delta_val = (int) final_val - (int) initial_val;
break;
@@ -873,7 +908,7 @@ bool Tween::_calc_delta_val(const Variant& p_initial_val, const Variant& p_final
return true;
}
-bool Tween::interpolate_property(Node *p_node
+bool Tween::interpolate_property(Object *p_object
, String p_property
, Variant p_initial_val
, Variant p_final_val
@@ -882,11 +917,12 @@ bool Tween::interpolate_property(Node *p_node
, EaseType p_ease_type
, real_t p_delay
) {
+ ERR_FAIL_COND_V(pending_update != 0, false);
// convert INT to REAL is better for interpolaters
if(p_initial_val.get_type() == Variant::INT) p_initial_val = p_initial_val.operator real_t();
if(p_final_val.get_type() == Variant::INT) p_final_val = p_final_val.operator real_t();
- ERR_FAIL_COND_V(p_node == NULL, false);
+ ERR_FAIL_COND_V(p_object == NULL, false);
ERR_FAIL_COND_V(p_initial_val.get_type() != p_final_val.get_type(), false);
ERR_FAIL_COND_V(p_times_in_sec <= 0, false);
ERR_FAIL_COND_V(p_trans_type < 0 || p_trans_type >= TRANS_COUNT, false);
@@ -894,7 +930,7 @@ bool Tween::interpolate_property(Node *p_node
ERR_FAIL_COND_V(p_delay < 0, false);
bool prop_valid = false;
- p_node->get(p_property,&prop_valid);
+ p_object->get(p_property,&prop_valid);
ERR_FAIL_COND_V(!prop_valid, false);
InterpolateData data;
@@ -903,7 +939,7 @@ bool Tween::interpolate_property(Node *p_node
data.finish = false;
data.elapsed = 0;
- data.path = p_node->get_path();
+ data.id = p_object->get_instance_ID();
data.key = p_property;
data.initial_val = p_initial_val;
data.final_val = p_final_val;
@@ -919,7 +955,7 @@ bool Tween::interpolate_property(Node *p_node
return true;
}
-bool Tween::interpolate_method(Node *p_node
+bool Tween::interpolate_method(Object *p_object
, String p_method
, Variant p_initial_val
, Variant p_final_val
@@ -928,18 +964,19 @@ bool Tween::interpolate_method(Node *p_node
, EaseType p_ease_type
, real_t p_delay
) {
+ ERR_FAIL_COND_V(pending_update != 0, false);
// convert INT to REAL is better for interpolaters
if(p_initial_val.get_type() == Variant::INT) p_initial_val = p_initial_val.operator real_t();
if(p_final_val.get_type() == Variant::INT) p_final_val = p_final_val.operator real_t();
- ERR_FAIL_COND_V(p_node == NULL, false);
+ ERR_FAIL_COND_V(p_object == NULL, false);
ERR_FAIL_COND_V(p_initial_val.get_type() != p_final_val.get_type(), false);
ERR_FAIL_COND_V(p_times_in_sec <= 0, false);
ERR_FAIL_COND_V(p_trans_type < 0 || p_trans_type >= TRANS_COUNT, false);
ERR_FAIL_COND_V(p_ease_type < 0 || p_ease_type >= EASE_COUNT, false);
ERR_FAIL_COND_V(p_delay < 0, false);
- ERR_FAIL_COND_V(!p_node->has_method(p_method), false);
+ ERR_FAIL_COND_V(!p_object->has_method(p_method), false);
InterpolateData data;
data.active = true;
@@ -947,7 +984,7 @@ bool Tween::interpolate_method(Node *p_node
data.finish = false;
data.elapsed = 0;
- data.path = p_node->get_path();
+ data.id = p_object->get_instance_ID();
data.key = p_method;
data.initial_val = p_initial_val;
data.final_val = p_final_val;
@@ -963,16 +1000,17 @@ bool Tween::interpolate_method(Node *p_node
return true;
}
-bool Tween::interpolate_callback(Node *p_node
- , String p_callback
+bool Tween::interpolate_callback(Object *p_object
, real_t p_times_in_sec
+ , String p_callback
, Variant p_arg
) {
- ERR_FAIL_COND_V(p_node == NULL, false);
+ ERR_FAIL_COND_V(pending_update != 0, false);
+ ERR_FAIL_COND_V(p_object == NULL, false);
ERR_FAIL_COND_V(p_times_in_sec < 0, false);
- ERR_FAIL_COND_V(!p_node->has_method(p_callback), false);
+ ERR_FAIL_COND_V(!p_object->has_method(p_callback), false);
InterpolateData data;
data.active = true;
@@ -980,30 +1018,33 @@ bool Tween::interpolate_callback(Node *p_node
data.finish = false;
data.elapsed = 0;
- data.path = p_node->get_path();
+ data.id = p_object->get_instance_ID();
data.key = p_callback;
data.times_in_sec = p_times_in_sec;
data.delay = 0;
data.arg = p_arg;
+ pending_update ++;
interpolates.push_back(data);
+ pending_update --;
return true;
}
-bool Tween::follow_property(Node *p_node
+bool Tween::follow_property(Object *p_object
, String p_property
, Variant p_initial_val
- , Node *p_target
+ , Object *p_target
, String p_target_property
, real_t p_times_in_sec
, TransitionType p_trans_type
, EaseType p_ease_type
, real_t p_delay
) {
+ ERR_FAIL_COND_V(pending_update != 0, false);
// convert INT to REAL is better for interpolaters
if(p_initial_val.get_type() == Variant::INT) p_initial_val = p_initial_val.operator real_t();
- ERR_FAIL_COND_V(p_node == NULL, false);
+ ERR_FAIL_COND_V(p_object == NULL, false);
ERR_FAIL_COND_V(p_target == NULL, false);
ERR_FAIL_COND_V(p_times_in_sec <= 0, false);
ERR_FAIL_COND_V(p_trans_type < 0 || p_trans_type >= TRANS_COUNT, false);
@@ -1011,7 +1052,7 @@ bool Tween::follow_property(Node *p_node
ERR_FAIL_COND_V(p_delay < 0, false);
bool prop_valid = false;
- p_node->get(p_property,&prop_valid);
+ p_object->get(p_property,&prop_valid);
ERR_FAIL_COND_V(!prop_valid, false);
bool target_prop_valid = false;
@@ -1028,10 +1069,10 @@ bool Tween::follow_property(Node *p_node
data.finish = false;
data.elapsed = 0;
- data.path = p_node->get_path();
+ data.id = p_object->get_instance_ID();
data.key = p_property;
data.initial_val = p_initial_val;
- data.target = p_target->get_path();
+ data.target_id = p_target->get_instance_ID();
data.target_key = p_target_property;
data.times_in_sec = p_times_in_sec;
data.trans_type = p_trans_type;
@@ -1042,27 +1083,28 @@ bool Tween::follow_property(Node *p_node
return true;
}
-bool Tween::follow_method(Node *p_node
+bool Tween::follow_method(Object *p_object
, String p_method
, Variant p_initial_val
- , Node *p_target
+ , Object *p_target
, String p_target_method
, real_t p_times_in_sec
, TransitionType p_trans_type
, EaseType p_ease_type
, real_t p_delay
) {
+ ERR_FAIL_COND_V(pending_update != 0, false);
// convert INT to REAL is better for interpolaters
if(p_initial_val.get_type() == Variant::INT) p_initial_val = p_initial_val.operator real_t();
- ERR_FAIL_COND_V(p_node == NULL, false);
+ ERR_FAIL_COND_V(p_object == NULL, false);
ERR_FAIL_COND_V(p_target == NULL, false);
ERR_FAIL_COND_V(p_times_in_sec <= 0, false);
ERR_FAIL_COND_V(p_trans_type < 0 || p_trans_type >= TRANS_COUNT, false);
ERR_FAIL_COND_V(p_ease_type < 0 || p_ease_type >= EASE_COUNT, false);
ERR_FAIL_COND_V(p_delay < 0, false);
- ERR_FAIL_COND_V(!p_node->has_method(p_method), false);
+ ERR_FAIL_COND_V(!p_object->has_method(p_method), false);
ERR_FAIL_COND_V(!p_target->has_method(p_target_method), false);
Variant::CallError error;
@@ -1079,10 +1121,10 @@ bool Tween::follow_method(Node *p_node
data.finish = false;
data.elapsed = 0;
- data.path = p_node->get_path();
+ data.id = p_object->get_instance_ID();
data.key = p_method;
data.initial_val = p_initial_val;
- data.target = p_target->get_path();
+ data.target_id = p_target->get_instance_ID();
data.target_key = p_target_method;
data.times_in_sec = p_times_in_sec;
data.trans_type = p_trans_type;
@@ -1093,9 +1135,9 @@ bool Tween::follow_method(Node *p_node
return true;
}
-bool Tween::targeting_property(Node *p_node
+bool Tween::targeting_property(Object *p_object
, String p_property
- , Node *p_initial
+ , Object *p_initial
, String p_initial_property
, Variant p_final_val
, real_t p_times_in_sec
@@ -1103,10 +1145,11 @@ bool Tween::targeting_property(Node *p_node
, EaseType p_ease_type
, real_t p_delay
) {
+ ERR_FAIL_COND_V(pending_update != 0, false);
// convert INT to REAL is better for interpolaters
if(p_final_val.get_type() == Variant::INT) p_final_val = p_final_val.operator real_t();
- ERR_FAIL_COND_V(p_node == NULL, false);
+ ERR_FAIL_COND_V(p_object == NULL, false);
ERR_FAIL_COND_V(p_initial == NULL, false);
ERR_FAIL_COND_V(p_times_in_sec <= 0, false);
ERR_FAIL_COND_V(p_trans_type < 0 || p_trans_type >= TRANS_COUNT, false);
@@ -1114,7 +1157,7 @@ bool Tween::targeting_property(Node *p_node
ERR_FAIL_COND_V(p_delay < 0, false);
bool prop_valid = false;
- p_node->get(p_property,&prop_valid);
+ p_object->get(p_property,&prop_valid);
ERR_FAIL_COND_V(!prop_valid, false);
bool initial_prop_valid = false;
@@ -1131,9 +1174,9 @@ bool Tween::targeting_property(Node *p_node
data.finish = false;
data.elapsed = 0;
- data.path = p_node->get_path();
+ data.id = p_object->get_instance_ID();
data.key = p_property;
- data.target = p_initial->get_path();
+ data.target_id = p_initial->get_instance_ID();
data.target_key = p_initial_property;
data.initial_val = initial_val;
data.final_val = p_final_val;
@@ -1150,9 +1193,9 @@ bool Tween::targeting_property(Node *p_node
}
-bool Tween::targeting_method(Node *p_node
+bool Tween::targeting_method(Object *p_object
, String p_method
- , Node *p_initial
+ , Object *p_initial
, String p_initial_method
, Variant p_final_val
, real_t p_times_in_sec
@@ -1160,17 +1203,18 @@ bool Tween::targeting_method(Node *p_node
, EaseType p_ease_type
, real_t p_delay
) {
+ ERR_FAIL_COND_V(pending_update != 0, false);
// convert INT to REAL is better for interpolaters
if(p_final_val.get_type() == Variant::INT) p_final_val = p_final_val.operator real_t();
- ERR_FAIL_COND_V(p_node == NULL, false);
+ ERR_FAIL_COND_V(p_object == NULL, false);
ERR_FAIL_COND_V(p_initial == NULL, false);
ERR_FAIL_COND_V(p_times_in_sec <= 0, false);
ERR_FAIL_COND_V(p_trans_type < 0 || p_trans_type >= TRANS_COUNT, false);
ERR_FAIL_COND_V(p_ease_type < 0 || p_ease_type >= EASE_COUNT, false);
ERR_FAIL_COND_V(p_delay < 0, false);
- ERR_FAIL_COND_V(!p_node->has_method(p_method), false);
+ ERR_FAIL_COND_V(!p_object->has_method(p_method), false);
ERR_FAIL_COND_V(!p_initial->has_method(p_initial_method), false);
Variant::CallError error;
@@ -1187,9 +1231,9 @@ bool Tween::targeting_method(Node *p_node
data.finish = false;
data.elapsed = 0;
- data.path = p_node->get_path();
+ data.id = p_object->get_instance_ID();
data.key = p_method;
- data.target = p_initial->get_path();
+ data.target_id = p_initial->get_instance_ID();
data.target_key = p_initial_method;
data.initial_val = initial_val;
data.final_val = p_final_val;
@@ -1213,6 +1257,7 @@ Tween::Tween() {
active=false;
repeat=false;
speed_scale=1;
+ pending_update=0;
}
Tween::~Tween() {
diff --git a/scene/animation/tween.h b/scene/animation/tween.h
index c9d9863397..3e23cc362a 100644
--- a/scene/animation/tween.h
+++ b/scene/animation/tween.h
@@ -54,15 +54,17 @@ public:
TRANS_CIRC,
TRANS_BOUNCE,
TRANS_BACK,
- TRANS_COUNT,
+
+ TRANS_COUNT,
};
enum EaseType {
EASE_IN,
EASE_OUT,
EASE_IN_OUT,
- EASE_OUT_IN,
- EASE_COUNT,
+ EASE_OUT_IN,
+
+ EASE_COUNT,
};
private:
@@ -82,12 +84,12 @@ private:
InterpolateType type;
bool finish;
real_t elapsed;
- NodePath path;
+ ObjectID id;
StringName key;
Variant initial_val;
Variant delta_val;
Variant final_val;
- NodePath target;
+ ObjectID target_id;
StringName target_key;
real_t times_in_sec;
TransitionType trans_type;
@@ -102,6 +104,7 @@ private:
bool active;
bool repeat;
float speed_scale;
+ mutable int pending_update;
List<InterpolateData> interpolates;
@@ -142,20 +145,20 @@ public:
float get_speed() const;
bool start();
- bool reset(Node *p_node, String p_key);
+ bool reset(Object *p_node, String p_key);
bool reset_all();
- bool stop(Node *p_node, String p_key);
+ bool stop(Object *p_node, String p_key);
bool stop_all();
- bool resume(Node *p_node, String p_key);
+ bool resume(Object *p_node, String p_key);
bool resume_all();
- bool remove(Node *p_node, String p_key);
+ bool remove(Object *p_node, String p_key);
bool remove_all();
bool seek(real_t p_time);
real_t tell() const;
real_t get_runtime() const;
- bool interpolate_property(Node *p_node
+ bool interpolate_property(Object *p_node
, String p_property
, Variant p_initial_val
, Variant p_final_val
@@ -165,7 +168,7 @@ public:
, real_t p_delay = 0
);
- bool interpolate_method(Node *p_node
+ bool interpolate_method(Object *p_node
, String p_method
, Variant p_initial_val
, Variant p_final_val
@@ -175,16 +178,16 @@ public:
, real_t p_delay = 0
);
- bool interpolate_callback(Node *p_node
- , String p_callback
+ bool interpolate_callback(Object *p_node
, real_t p_times_in_sec
+ , String p_callback
, Variant p_arg = Variant()
);
- bool follow_property(Node *p_node
+ bool follow_property(Object *p_node
, String p_property
, Variant p_initial_val
- , Node *p_target
+ , Object *p_target
, String p_target_property
, real_t p_times_in_sec
, TransitionType p_trans_type
@@ -192,10 +195,10 @@ public:
, real_t p_delay = 0
);
- bool follow_method(Node *p_node
+ bool follow_method(Object *p_node
, String p_method
, Variant p_initial_val
- , Node *p_target
+ , Object *p_target
, String p_target_method
, real_t p_times_in_sec
, TransitionType p_trans_type
@@ -203,9 +206,9 @@ public:
, real_t p_delay = 0
);
- bool targeting_property(Node *p_node
+ bool targeting_property(Object *p_node
, String p_property
- , Node *p_initial
+ , Object *p_initial
, String p_initial_property
, Variant p_final_val
, real_t p_times_in_sec
@@ -214,9 +217,9 @@ public:
, real_t p_delay = 0
);
- bool targeting_method(Node *p_node
+ bool targeting_method(Object *p_node
, String p_method
- , Node *p_initial
+ , Object *p_initial
, String p_initial_method
, Variant p_final_val
, real_t p_times_in_sec
diff --git a/scene/audio/sample_player.cpp b/scene/audio/sample_player.cpp
index 90994f01b4..bf1c5e97a3 100644
--- a/scene/audio/sample_player.cpp
+++ b/scene/audio/sample_player.cpp
@@ -498,6 +498,7 @@ bool SamplePlayer::is_active() const {
void SamplePlayer::set_sample_library(const Ref<SampleLibrary>& p_library) {
library=p_library;
+ _change_notify();
}
Ref<SampleLibrary> SamplePlayer::get_sample_library() const {
diff --git a/scene/gui/box_container.cpp b/scene/gui/box_container.cpp
index 216c6d7122..5ed60e88f8 100644
--- a/scene/gui/box_container.cpp
+++ b/scene/gui/box_container.cpp
@@ -44,7 +44,7 @@ void BoxContainer::_resort() {
Size2i new_size=get_size();;
- int sep=get_constant("separation",vertical?"VBoxContainer":"HBoxContainer");
+ int sep=get_constant("separation");//,vertical?"VBoxContainer":"HBoxContainer");
bool first=true;
int children_count=0;
@@ -202,7 +202,7 @@ Size2 BoxContainer::get_minimum_size() const {
/* Calculate MINIMUM SIZE */
Size2i minimum;
- int sep=get_constant("separation",vertical?"VBoxContainer":"HBoxContainer");
+ int sep=get_constant("separation");//,vertical?"VBoxContainer":"HBoxContainer");
bool first=true;
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp
index aea0aacf42..ce268843b1 100644
--- a/scene/gui/control.cpp
+++ b/scene/gui/control.cpp
@@ -1126,6 +1126,7 @@ void Control::_window_input_event(InputEvent p_event) {
over = _find_control_at_pos(this,pos,parent_xform,window->focus_inv_xform);
}
+
if (window->drag_data.get_type()==Variant::NIL && over && !window->modal_stack.empty()) {
Control *top = window->modal_stack.back()->get();
@@ -1325,9 +1326,12 @@ Size2 Control::get_minimum_size() const {
Ref<Texture> Control::get_icon(const StringName& p_name,const StringName& p_type) const {
- const Ref<Texture>* tex = data.icon_override.getptr(p_name);
- if (tex)
- return *tex;
+ if (p_type==StringName()) {
+
+ const Ref<Texture>* tex = data.icon_override.getptr(p_name);
+ if (tex)
+ return *tex;
+ }
StringName type = p_type?p_type:get_type_name();
@@ -1353,12 +1357,11 @@ Ref<Texture> Control::get_icon(const StringName& p_name,const StringName& p_type
Ref<StyleBox> Control::get_stylebox(const StringName& p_name,const StringName& p_type) const {
-
- const Ref<StyleBox>* style = data.style_override.getptr(p_name);
-
-
- if (style)
- return *style;
+ if (p_type==StringName()) {
+ const Ref<StyleBox>* style = data.style_override.getptr(p_name);
+ if (style)
+ return *style;
+ }
StringName type = p_type?p_type:get_type_name();
@@ -1381,10 +1384,12 @@ Ref<StyleBox> Control::get_stylebox(const StringName& p_name,const StringName& p
}
Ref<Font> Control::get_font(const StringName& p_name,const StringName& p_type) const {
-
- const Ref<Font>* font = data.font_override.getptr(p_name);
- if (font)
- return *font;
+
+ if (p_type==StringName()) {
+ const Ref<Font>* font = data.font_override.getptr(p_name);
+ if (font)
+ return *font;
+ }
StringName type = p_type?p_type:get_type_name();
@@ -1410,10 +1415,12 @@ Ref<Font> Control::get_font(const StringName& p_name,const StringName& p_type) c
}
Color Control::get_color(const StringName& p_name,const StringName& p_type) const {
-
- const Color* color = data.color_override.getptr(p_name);
- if (color)
- return *color;
+
+ if (p_type==StringName()) {
+ const Color* color = data.color_override.getptr(p_name);
+ if (color)
+ return *color;
+ }
StringName type = p_type?p_type:get_type_name();
// try with custom themes
@@ -1437,10 +1444,12 @@ Color Control::get_color(const StringName& p_name,const StringName& p_type) cons
}
int Control::get_constant(const StringName& p_name,const StringName& p_type) const {
-
- const int* constant = data.constant_override.getptr(p_name);
- if (constant)
- return *constant;
+
+ if (p_type==StringName()) {
+ const int* constant = data.constant_override.getptr(p_name);
+ if (constant)
+ return *constant;
+ }
StringName type = p_type?p_type:get_type_name();
// try with custom themes
@@ -1467,9 +1476,11 @@ int Control::get_constant(const StringName& p_name,const StringName& p_type) con
bool Control::has_icon(const StringName& p_name,const StringName& p_type) const {
- const Ref<Texture>* tex = data.icon_override.getptr(p_name);
- if (tex)
- return true;
+ if (p_type==StringName()) {
+ const Ref<Texture>* tex = data.icon_override.getptr(p_name);
+ if (tex)
+ return true;
+ }
StringName type = p_type?p_type:get_type_name();
@@ -1494,11 +1505,12 @@ bool Control::has_icon(const StringName& p_name,const StringName& p_type) const
}
bool Control::has_stylebox(const StringName& p_name,const StringName& p_type) const {
-
- const Ref<StyleBox>* style = data.style_override.getptr(p_name);
-
- if (style)
- return true;
+ if (p_type==StringName()) {
+ const Ref<StyleBox>* style = data.style_override.getptr(p_name);
+
+ if (style)
+ return true;
+ }
StringName type = p_type?p_type:get_type_name();
@@ -1523,9 +1535,11 @@ bool Control::has_stylebox(const StringName& p_name,const StringName& p_type) co
}
bool Control::has_font(const StringName& p_name,const StringName& p_type) const {
- const Ref<Font>* font = data.font_override.getptr(p_name);
- if (font)
- return true;
+ if (p_type==StringName()) {
+ const Ref<Font>* font = data.font_override.getptr(p_name);
+ if (font)
+ return true;
+ }
StringName type = p_type?p_type:get_type_name();
@@ -1551,9 +1565,11 @@ bool Control::has_font(const StringName& p_name,const StringName& p_type) const
}
bool Control::has_color(const StringName& p_name,const StringName& p_type) const {
- const Color* color = data.color_override.getptr(p_name);
- if (color)
- return true;
+ if (p_type==StringName()) {
+ const Color* color = data.color_override.getptr(p_name);
+ if (color)
+ return true;
+ }
StringName type = p_type?p_type:get_type_name();
@@ -1578,10 +1594,13 @@ bool Control::has_color(const StringName& p_name,const StringName& p_type) const
}
bool Control::has_constant(const StringName& p_name,const StringName& p_type) const {
-
- const int* constant = data.constant_override.getptr(p_name);
- if (constant)
- return true;
+
+ if (p_type==StringName()) {
+
+ const int* constant = data.constant_override.getptr(p_name);
+ if (constant)
+ return true;
+ }
StringName type = p_type?p_type:get_type_name();
@@ -2249,6 +2268,7 @@ void Control::_window_sort_subwindows() {
return;
window->modal_stack.sort_custom<CComparator>();
+ window->subwindows.sort_custom<CComparator>();
window->subwindow_order_dirty=false;
}
@@ -2664,8 +2684,8 @@ bool Control::is_stopping_mouse() const {
Control *Control::get_focus_owner() const {
ERR_FAIL_COND_V(!is_inside_tree(),NULL);
- ERR_FAIL_COND_V(!window,NULL);
- return window->key_focus;
+ ERR_FAIL_COND_V(!data.window,NULL);
+ return data.window->window->key_focus;
}
void Control::_bind_methods() {
diff --git a/scene/gui/empty_control.cpp b/scene/gui/empty_control.cpp
deleted file mode 100644
index 1e377b2b73..0000000000
--- a/scene/gui/empty_control.cpp
+++ /dev/null
@@ -1,59 +0,0 @@
-/*************************************************************************/
-/* empty_control.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 "empty_control.h"
-
-Size2 EmptyControl::get_minimum_size() const {
-
- return minsize;
-}
-
-void EmptyControl::set_minsize(const Size2& p_size) {
-
- minsize=p_size;
- minimum_size_changed();
-}
-
-Size2 EmptyControl::get_minsize() const {
-
- return minsize;
-}
-
-
-void EmptyControl::_bind_methods() {
-
-
- ObjectTypeDB::bind_method(_MD("set_minsize","minsize"),&EmptyControl::set_minsize);
- ObjectTypeDB::bind_method(_MD("get_minsize"),&EmptyControl::get_minsize);
-
- ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"minsize"), _SCS("set_minsize"),_SCS("get_minsize") );
-}
-
-EmptyControl::EmptyControl()
-{
-}
diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp
new file mode 100644
index 0000000000..3cd0dd3d16
--- /dev/null
+++ b/scene/gui/graph_edit.cpp
@@ -0,0 +1,586 @@
+#include "graph_edit.h"
+#include "os/input.h"
+#include "os/keyboard.h"
+bool GraphEditFilter::has_point(const Point2& p_point) const {
+
+ return ge->_filter_input(p_point);
+}
+
+
+GraphEditFilter::GraphEditFilter(GraphEdit *p_edit) {
+
+ ge=p_edit;
+}
+
+
+Error GraphEdit::connect_node(const StringName& p_from, int p_from_port,const StringName& p_to,int p_to_port) {
+
+ if (is_node_connected(p_from,p_from_port,p_to,p_to_port))
+ return OK;
+ Connection c;
+ c.from=p_from;
+ c.from_port=p_from_port;
+ c.to=p_to;
+ c.to_port=p_to_port;
+ connections.push_back(c);
+ top_layer->update();
+
+ return OK;
+}
+
+bool GraphEdit::is_node_connected(const StringName& p_from, int p_from_port,const StringName& p_to,int p_to_port) {
+
+ for(List<Connection>::Element *E=connections.front();E;E=E->next()) {
+
+ if (E->get().from==p_from && E->get().from_port==p_from_port && E->get().to==p_to && E->get().to_port==p_to_port)
+ return true;
+ }
+
+ return false;
+
+}
+
+void GraphEdit::disconnect_node(const StringName& p_from, int p_from_port,const StringName& p_to,int p_to_port){
+
+
+ for(List<Connection>::Element *E=connections.front();E;E=E->next()) {
+
+ if (E->get().from==p_from && E->get().from_port==p_from_port && E->get().to==p_to && E->get().to_port==p_to_port) {
+
+ connections.erase(E);
+ top_layer->update();
+ return;
+ }
+ }
+}
+
+void GraphEdit::get_connection_list(List<Connection> *r_connections) const {
+
+ *r_connections=connections;
+}
+
+
+void GraphEdit::_scroll_moved(double) {
+
+
+ _update_scroll_offset();
+ top_layer->update();
+}
+
+void GraphEdit::_update_scroll_offset() {
+
+ for(int i=0;i<get_child_count();i++) {
+
+ GraphNode *gn=get_child(i)->cast_to<GraphNode>();
+ if (!gn)
+ continue;
+
+ Point2 pos=gn->get_offset();
+ pos-=Point2(h_scroll->get_val(),v_scroll->get_val());
+ gn->set_pos(pos);
+ }
+
+}
+
+void GraphEdit::_update_scroll() {
+
+ if (updating)
+ return;
+
+ updating=true;
+ Rect2 screen;
+ for(int i=0;i<get_child_count();i++) {
+
+ GraphNode *gn=get_child(i)->cast_to<GraphNode>();
+ if (!gn)
+ continue;
+
+ Rect2 r;
+ r.pos=gn->get_offset();
+ r.size=gn->get_size();
+ screen = screen.merge(r);
+ }
+
+ screen.pos-=get_size();
+ screen.size+=get_size()*2.0;
+
+
+ h_scroll->set_min(screen.pos.x);
+ h_scroll->set_max(screen.pos.x+screen.size.x);
+ h_scroll->set_page(get_size().x);
+ if (h_scroll->get_max() - h_scroll->get_min() <= h_scroll->get_page())
+ h_scroll->hide();
+ else
+ h_scroll->show();
+
+ v_scroll->set_min(screen.pos.y);
+ v_scroll->set_max(screen.pos.y+screen.size.y);
+ v_scroll->set_page(get_size().y);
+
+ if (v_scroll->get_max() - v_scroll->get_min() <= v_scroll->get_page())
+ v_scroll->hide();
+ else
+ v_scroll->show();
+
+ _update_scroll_offset();
+ updating=false;
+}
+
+
+void GraphEdit::_graph_node_raised(Node* p_gn) {
+
+ GraphNode *gn=p_gn->cast_to<GraphNode>();
+ ERR_FAIL_COND(!gn);
+ gn->raise();
+ top_layer->raise();
+
+}
+
+
+void GraphEdit::_graph_node_moved(Node *p_gn) {
+
+ GraphNode *gn=p_gn->cast_to<GraphNode>();
+ ERR_FAIL_COND(!gn);
+
+ //gn->set_pos(gn->get_offset()+scroll_offset);
+
+ top_layer->update();
+}
+
+void GraphEdit::add_child_notify(Node *p_child) {
+
+ top_layer->call_deferred("raise"); //top layer always on top!
+ GraphNode *gn = p_child->cast_to<GraphNode>();
+ if (gn) {
+ gn->connect("offset_changed",this,"_graph_node_moved",varray(gn));
+ gn->connect("raise_request",this,"_graph_node_raised",varray(gn));
+ _graph_node_moved(gn);
+ gn->set_stop_mouse(false);
+ }
+}
+
+void GraphEdit::remove_child_notify(Node *p_child) {
+
+ top_layer->call_deferred("raise"); //top layer always on top!
+ GraphNode *gn = p_child->cast_to<GraphNode>();
+ if (gn) {
+ gn->disconnect("offset_changed",this,"_graph_node_moved");
+ gn->disconnect("raise_request",this,"_graph_node_raised");
+ }
+}
+
+void GraphEdit::_notification(int p_what) {
+
+ if (p_what==NOTIFICATION_READY) {
+ Size2 size = top_layer->get_size();
+ Size2 hmin = h_scroll->get_combined_minimum_size();
+ Size2 vmin = v_scroll->get_combined_minimum_size();
+
+ v_scroll->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_END,vmin.width);
+ v_scroll->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_END,0);
+ v_scroll->set_anchor_and_margin(MARGIN_TOP,ANCHOR_BEGIN,0);
+ v_scroll->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_END,0);
+
+ h_scroll->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_BEGIN,0);
+ h_scroll->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_END,0);
+ h_scroll->set_anchor_and_margin(MARGIN_TOP,ANCHOR_END,hmin.height);
+ h_scroll->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_END,0);
+
+ }
+ if (p_what==NOTIFICATION_DRAW) {
+ VS::get_singleton()->canvas_item_set_clip(get_canvas_item(),true);
+
+ }
+
+ if (p_what==NOTIFICATION_RESIZED) {
+ _update_scroll();
+ top_layer->update();
+ }
+}
+
+bool GraphEdit::_filter_input(const Point2& p_point) {
+
+ Ref<Texture> port =get_icon("port","GraphNode");
+
+ float grab_r=port->get_width()*0.5;
+ for(int i=get_child_count()-1;i>=0;i--) {
+
+ GraphNode *gn=get_child(i)->cast_to<GraphNode>();
+ if (!gn)
+ continue;
+
+ for(int j=0;j<gn->get_connection_output_count();j++) {
+
+ Vector2 pos = gn->get_connection_output_pos(j)+gn->get_pos();
+ if (pos.distance_to(p_point)<grab_r)
+ return true;
+
+
+ }
+
+ for(int j=0;j<gn->get_connection_input_count();j++) {
+
+ Vector2 pos = gn->get_connection_input_pos(j)+gn->get_pos();
+ if (pos.distance_to(p_point)<grab_r)
+ return true;
+
+
+ }
+
+ }
+
+ return false;
+}
+
+void GraphEdit::_top_layer_input(const InputEvent& p_ev) {
+
+ if (p_ev.type==InputEvent::MOUSE_BUTTON && p_ev.mouse_button.button_index==BUTTON_LEFT && p_ev.mouse_button.pressed) {
+
+ Ref<Texture> port =get_icon("port","GraphNode");
+ Vector2 mpos(p_ev.mouse_button.x,p_ev.mouse_button.y);
+ float grab_r=port->get_width()*0.5;
+ for(int i=get_child_count()-1;i>=0;i--) {
+
+ GraphNode *gn=get_child(i)->cast_to<GraphNode>();
+ if (!gn)
+ continue;
+
+ for(int j=0;j<gn->get_connection_output_count();j++) {
+
+ Vector2 pos = gn->get_connection_output_pos(j)+gn->get_pos();
+ if (pos.distance_to(mpos)<grab_r) {
+
+ connecting=true;
+ connecting_from=gn->get_name();
+ connecting_index=j;
+ connecting_out=true;
+ connecting_type=gn->get_connection_output_type(j);
+ connecting_color=gn->get_connection_output_color(j);
+ connecting_target=false;
+ connecting_to=pos;
+ return;
+ }
+
+
+ }
+
+ for(int j=0;j<gn->get_connection_input_count();j++) {
+
+ Vector2 pos = gn->get_connection_input_pos(j)+gn->get_pos();
+
+ if (pos.distance_to(mpos)<grab_r) {
+
+ if (right_disconnects) {
+ //check disconnect
+ for (List<Connection>::Element*E=connections.front();E;E=E->next()) {
+
+ if (E->get().to==gn->get_name() && E->get().to_port==j) {
+
+ Node*fr = get_node(String(E->get().from));
+ if (fr && fr->cast_to<GraphNode>()) {
+
+ connecting_from=E->get().from;
+ connecting_index=E->get().from_port;
+ connecting_out=true;
+ connecting_type=fr->cast_to<GraphNode>()->get_connection_output_type(E->get().from_port);
+ connecting_color=fr->cast_to<GraphNode>()->get_connection_output_color(E->get().from_port);
+ connecting_target=false;
+ connecting_to=pos;
+
+ emit_signal("disconnection_request",E->get().from,E->get().from_port,E->get().to,E->get().to_port);
+ fr = get_node(String(connecting_from)); //maybe it was erased
+ if (fr && fr->cast_to<GraphNode>()) {
+ connecting=true;
+ }
+ return;
+ }
+
+ }
+ }
+ }
+
+
+ connecting=true;
+ connecting_from=gn->get_name();
+ connecting_index=j;
+ connecting_out=false;
+ connecting_type=gn->get_connection_input_type(j);
+ connecting_color=gn->get_connection_input_color(j);
+ connecting_target=false;
+ connecting_to=pos;
+ return;
+ }
+
+
+ }
+ }
+ }
+
+ if (p_ev.type==InputEvent::MOUSE_MOTION && connecting) {
+
+ connecting_to=Vector2(p_ev.mouse_motion.x,p_ev.mouse_motion.y);
+ connecting_target=false;
+ top_layer->update();
+
+ Ref<Texture> port =get_icon("port","GraphNode");
+ Vector2 mpos(p_ev.mouse_button.x,p_ev.mouse_button.y);
+ float grab_r=port->get_width()*0.5;
+ for(int i=get_child_count()-1;i>=0;i--) {
+
+ GraphNode *gn=get_child(i)->cast_to<GraphNode>();
+ if (!gn)
+ continue;
+
+ if (!connecting_out) {
+ for(int j=0;j<gn->get_connection_output_count();j++) {
+
+ Vector2 pos = gn->get_connection_output_pos(j)+gn->get_pos();
+ int type =gn->get_connection_output_type(j);
+ if (type==connecting_type && pos.distance_to(mpos)<grab_r) {
+
+ connecting_target=true;
+ connecting_to=pos;
+ connecting_target_to=gn->get_name();
+ connecting_target_index=j;
+ return;
+ }
+
+
+ }
+ } else {
+
+ for(int j=0;j<gn->get_connection_input_count();j++) {
+
+ Vector2 pos = gn->get_connection_input_pos(j)+gn->get_pos();
+ int type =gn->get_connection_input_type(j);
+ if (type==connecting_type && pos.distance_to(mpos)<grab_r) {
+ connecting_target=true;
+ connecting_to=pos;
+ connecting_target_to=gn->get_name();
+ connecting_target_index=j;
+ return;
+ }
+ }
+ }
+ }
+ }
+
+ if (p_ev.type==InputEvent::MOUSE_BUTTON && p_ev.mouse_button.button_index==BUTTON_LEFT && !p_ev.mouse_button.pressed) {
+
+ if (connecting && connecting_target) {
+
+ String from = connecting_from;
+ int from_slot = connecting_index;
+ String to =connecting_target_to;
+ int to_slot = connecting_target_index;
+
+ if (!connecting_out) {
+ SWAP(from,to);
+ SWAP(from_slot,to_slot);
+ }
+ emit_signal("connection_request",from,from_slot,to,to_slot);
+
+ }
+ connecting=false;
+ top_layer->update();
+
+ }
+
+
+
+}
+
+void GraphEdit::_draw_cos_line(const Vector2& p_from, const Vector2& p_to,const Color& p_color) {
+
+ static const int steps = 20;
+
+ Rect2 r;
+ r.pos=p_from;
+ r.expand_to(p_to);
+ Vector2 sign=Vector2((p_from.x < p_to.x) ? 1 : -1,(p_from.y < p_to.y) ? 1 : -1);
+ bool flip = sign.x * sign.y < 0;
+
+ Vector2 prev;
+ for(int i=0;i<=steps;i++) {
+
+ float d = i/float(steps);
+ float c=-Math::cos(d*Math_PI) * 0.5+0.5;
+ if (flip)
+ c=1.0-c;
+ Vector2 p = r.pos+Vector2(d*r.size.width,c*r.size.height);
+
+ if (i>0) {
+
+ top_layer->draw_line(prev,p,p_color,2);
+ }
+
+ prev=p;
+ }
+}
+
+void GraphEdit::_top_layer_draw() {
+
+ _update_scroll();
+
+ if (connecting) {
+
+ Node *fromn = get_node(connecting_from);
+ ERR_FAIL_COND(!fromn);
+ GraphNode *from = fromn->cast_to<GraphNode>();
+ ERR_FAIL_COND(!from);
+ Vector2 pos;
+ if (connecting_out)
+ pos=from->get_connection_output_pos(connecting_index);
+ else
+ pos=from->get_connection_input_pos(connecting_index);
+ pos+=from->get_pos();
+
+ Vector2 topos;
+ topos=connecting_to;
+
+ Color col=connecting_color;
+
+ if (connecting_target) {
+ col.r+=0.4;
+ col.g+=0.4;
+ col.b+=0.4;
+ }
+ _draw_cos_line(pos,topos,col);
+ }
+
+ List<List<Connection>::Element* > to_erase;
+ for(List<Connection>::Element *E=connections.front();E;E=E->next()) {
+
+ NodePath fromnp(E->get().from);
+
+ Node * from = get_node(fromnp);
+ if (!from) {
+ to_erase.push_back(E);
+ continue;
+ }
+
+ GraphNode *gfrom = from->cast_to<GraphNode>();
+
+ if (!gfrom) {
+ to_erase.push_back(E);
+ continue;
+ }
+
+ NodePath tonp(E->get().to);
+ Node * to = get_node(tonp);
+ if (!to) {
+ to_erase.push_back(E);
+ continue;
+ }
+
+ GraphNode *gto = to->cast_to<GraphNode>();
+
+ if (!gto) {
+ to_erase.push_back(E);
+ continue;
+ }
+
+ Vector2 frompos=gfrom->get_connection_output_pos(E->get().from_port)+gfrom->get_pos();
+ Color color = gfrom->get_connection_output_color(E->get().from_port);
+ Vector2 topos=gto->get_connection_input_pos(E->get().to_port)+gto->get_pos();
+ _draw_cos_line(frompos,topos,color);
+
+ }
+
+ while(to_erase.size()) {
+ connections.erase(to_erase.front()->get());
+ to_erase.pop_front();
+ }
+ //draw connections
+}
+
+void GraphEdit::_input_event(const InputEvent& p_ev) {
+
+ if (p_ev.type==InputEvent::MOUSE_MOTION && (p_ev.mouse_motion.button_mask&BUTTON_MASK_MIDDLE || (p_ev.mouse_motion.button_mask&BUTTON_MASK_LEFT && Input::get_singleton()->is_key_pressed(KEY_SPACE)))) {
+ h_scroll->set_val( h_scroll->get_val() - p_ev.mouse_motion.relative_x );
+ v_scroll->set_val( v_scroll->get_val() - p_ev.mouse_motion.relative_y );
+ }
+}
+
+void GraphEdit::clear_connections() {
+
+ connections.clear();
+ update();
+}
+
+
+void GraphEdit::set_right_disconnects(bool p_enable) {
+
+ right_disconnects=p_enable;
+}
+
+bool GraphEdit::is_right_disconnects_enabled() const{
+
+ return right_disconnects;
+}
+
+Array GraphEdit::_get_connection_list() const {
+
+ List<Connection> conns;
+ get_connection_list(&conns);
+ Array arr;
+ for(List<Connection>::Element *E=conns.front();E;E=E->next()) {
+ Dictionary d;
+ d["from"]=E->get().from;
+ d["from_port"]=E->get().from_port;
+ d["to"]=E->get().to;
+ d["to_port"]=E->get().to_port;
+ arr.push_back(d);
+ }
+ return arr;
+}
+void GraphEdit::_bind_methods() {
+
+ ObjectTypeDB::bind_method(_MD("connect_node:Error","from","from_port","to","to_port"),&GraphEdit::connect_node);
+ ObjectTypeDB::bind_method(_MD("is_node_connected","from","from_port","to","to_port"),&GraphEdit::is_node_connected);
+ ObjectTypeDB::bind_method(_MD("disconnect_node","from","from_port","to","to_port"),&GraphEdit::disconnect_node);
+ ObjectTypeDB::bind_method(_MD("get_connection_list"),&GraphEdit::_get_connection_list);
+
+ ObjectTypeDB::bind_method(_MD("set_right_disconnects","enable"),&GraphEdit::set_right_disconnects);
+ ObjectTypeDB::bind_method(_MD("is_right_disconnects_enabled"),&GraphEdit::is_right_disconnects_enabled);
+
+ ObjectTypeDB::bind_method(_MD("_graph_node_moved"),&GraphEdit::_graph_node_moved);
+ ObjectTypeDB::bind_method(_MD("_graph_node_raised"),&GraphEdit::_graph_node_raised);
+
+ ObjectTypeDB::bind_method(_MD("_top_layer_input"),&GraphEdit::_top_layer_input);
+ ObjectTypeDB::bind_method(_MD("_top_layer_draw"),&GraphEdit::_top_layer_draw);
+ ObjectTypeDB::bind_method(_MD("_scroll_moved"),&GraphEdit::_scroll_moved);
+
+ ObjectTypeDB::bind_method(_MD("_input_event"),&GraphEdit::_input_event);
+
+ ADD_SIGNAL(MethodInfo("connection_request",PropertyInfo(Variant::STRING,"from"),PropertyInfo(Variant::INT,"from_slot"),PropertyInfo(Variant::STRING,"to"),PropertyInfo(Variant::INT,"to_slot")));
+ ADD_SIGNAL(MethodInfo("disconnection_request",PropertyInfo(Variant::STRING,"from"),PropertyInfo(Variant::INT,"from_slot"),PropertyInfo(Variant::STRING,"to"),PropertyInfo(Variant::INT,"to_slot")));
+
+}
+
+
+
+GraphEdit::GraphEdit() {
+ top_layer=NULL;
+ top_layer=memnew(GraphEditFilter(this));
+ add_child(top_layer);
+ top_layer->set_stop_mouse(false);
+ top_layer->set_area_as_parent_rect();
+ top_layer->connect("draw",this,"_top_layer_draw");
+ top_layer->set_stop_mouse(false);
+ top_layer->connect("input_event",this,"_top_layer_input");
+
+ h_scroll = memnew(HScrollBar);
+ h_scroll->set_name("_h_scroll");
+ top_layer->add_child(h_scroll);
+
+ v_scroll = memnew(VScrollBar);
+ v_scroll->set_name("_v_scroll");
+ top_layer->add_child(v_scroll);
+ updating=false;
+ connecting=false;
+ right_disconnects=false;
+
+ h_scroll->connect("value_changed", this,"_scroll_moved");
+ v_scroll->connect("value_changed", this,"_scroll_moved");
+}
diff --git a/scene/gui/graph_edit.h b/scene/gui/graph_edit.h
new file mode 100644
index 0000000000..0a9da73ab6
--- /dev/null
+++ b/scene/gui/graph_edit.h
@@ -0,0 +1,100 @@
+#ifndef GRAPH_EDIT_H
+#define GRAPH_EDIT_H
+
+#include "scene/gui/graph_node.h"
+#include "scene/gui/scroll_bar.h"
+
+class GraphEdit;
+
+class GraphEditFilter : public Control {
+
+ OBJ_TYPE(GraphEditFilter,Control);
+
+friend class GraphEdit;
+ GraphEdit *ge;
+ virtual bool has_point(const Point2& p_point) const;
+
+public:
+
+
+ GraphEditFilter(GraphEdit *p_edit);
+};
+
+class GraphEdit : public Control {
+
+ OBJ_TYPE(GraphEdit,Control);
+public:
+
+ struct Connection {
+ StringName from;
+ StringName to;
+ int from_port;
+ int to_port;
+
+ };
+private:
+
+ HScrollBar* h_scroll;
+ VScrollBar* v_scroll;
+
+
+ bool connecting;
+ String connecting_from;
+ bool connecting_out;
+ int connecting_index;
+ int connecting_type;
+ Color connecting_color;
+ bool connecting_target;
+ Vector2 connecting_to;
+ String connecting_target_to;
+ int connecting_target_index;
+
+
+
+ bool right_disconnects;
+ bool updating;
+ List<Connection> connections;
+
+ void _draw_cos_line(const Vector2& p_from, const Vector2& p_to,const Color& p_color);
+
+ void _graph_node_raised(Node* p_gn);
+ void _graph_node_moved(Node *p_gn);
+
+ void _update_scroll();
+ void _scroll_moved(double);
+ void _input_event(const InputEvent& p_ev);
+
+ GraphEditFilter *top_layer;
+ void _top_layer_input(const InputEvent& p_ev);
+ void _top_layer_draw();
+ void _update_scroll_offset();
+
+ Array _get_connection_list() const;
+
+friend class GraphEditFilter;
+ bool _filter_input(const Point2& p_point);
+protected:
+
+ static void _bind_methods();
+ virtual void add_child_notify(Node *p_child);
+ virtual void remove_child_notify(Node *p_child);
+ void _notification(int p_what);
+
+public:
+
+ Error connect_node(const StringName& p_from, int p_from_port,const StringName& p_to,int p_to_port);
+ bool is_node_connected(const StringName& p_from, int p_from_port,const StringName& p_to,int p_to_port);
+ void disconnect_node(const StringName& p_from, int p_from_port,const StringName& p_to,int p_to_port);
+ void clear_connections();
+
+ GraphEditFilter *get_top_layer() const { return top_layer; }
+ void get_connection_list(List<Connection> *r_connections) const;
+
+ void set_right_disconnects(bool p_enable);
+ bool is_right_disconnects_enabled() const;
+
+
+ GraphEdit();
+};
+
+#endif // GRAPHEdit_H
diff --git a/scene/gui/graph_node.cpp b/scene/gui/graph_node.cpp
new file mode 100644
index 0000000000..444b37855f
--- /dev/null
+++ b/scene/gui/graph_node.cpp
@@ -0,0 +1,583 @@
+#include "graph_node.h"
+#include "method_bind_ext.inc"
+
+
+bool GraphNode::_set(const StringName& p_name, const Variant& p_value) {
+
+ if (!p_name.operator String().begins_with("slot/"))
+ return false;
+
+ int idx=p_name.operator String().get_slice("/",1).to_int();
+ String what = p_name.operator String().get_slice("/",2);
+
+
+ Slot si;
+ if (slot_info.has(idx))
+ si=slot_info[idx];
+
+
+ if (what=="left_enabled")
+ si.enable_left=p_value;
+ else if (what=="left_type")
+ si.type_left=p_value;
+ else if (what=="left_color")
+ si.color_left=p_value;
+ else if (what=="right_enabled")
+ si.enable_right=p_value;
+ else if (what=="right_type")
+ si.type_right=p_value;
+ else if (what=="right_color")
+ si.color_right=p_value;
+ else
+ return false;
+
+ set_slot(idx,si.enable_left,si.type_left,si.color_left,si.enable_right,si.type_right,si.color_right);
+ update();
+ return true;
+}
+
+bool GraphNode::_get(const StringName& p_name,Variant &r_ret) const{
+
+
+
+ if (!p_name.operator String().begins_with("slot/")) {
+ return false;
+ }
+
+ int idx=p_name.operator String().get_slice("/",1).to_int();
+ String what = p_name.operator String().get_slice("/",2);
+
+
+
+ Slot si;
+ if (slot_info.has(idx))
+ si=slot_info[idx];
+
+ if (what=="left_enabled")
+ r_ret=si.enable_left;
+ else if (what=="left_type")
+ r_ret=si.type_left;
+ else if (what=="left_color")
+ r_ret=si.color_left;
+ else if (what=="right_enabled")
+ r_ret=si.enable_right;
+ else if (what=="right_type")
+ r_ret=si.type_right;
+ else if (what=="right_color")
+ r_ret=si.color_right;
+ else
+ return false;
+
+ return true;
+}
+void GraphNode::_get_property_list( List<PropertyInfo> *p_list) const{
+
+ int idx=0;
+ for(int i=0;i<get_child_count();i++) {
+ Control *c=get_child(i)->cast_to<Control>();
+ if (!c || c->is_set_as_toplevel() )
+ continue;
+
+ String base="slot/"+itos(idx)+"/";
+
+ p_list->push_back(PropertyInfo(Variant::BOOL,base+"left_enabled"));
+ p_list->push_back(PropertyInfo(Variant::INT,base+"left_type"));
+ p_list->push_back(PropertyInfo(Variant::COLOR,base+"left_color"));
+ p_list->push_back(PropertyInfo(Variant::BOOL,base+"right_enabled"));
+ p_list->push_back(PropertyInfo(Variant::INT,base+"right_type"));
+ p_list->push_back(PropertyInfo(Variant::COLOR,base+"right_color"));
+
+ idx++;
+ }
+}
+
+
+void GraphNode::_resort() {
+
+
+
+ int sep=get_constant("separation");
+ Ref<StyleBox> sb=get_stylebox("frame");
+ bool first=true;
+
+ Size2 minsize;
+
+ for(int i=0;i<get_child_count();i++) {
+ Control *c=get_child(i)->cast_to<Control>();
+ if (!c)
+ continue;
+ if (c->is_set_as_toplevel())
+ continue;
+
+ Size2i size=c->get_combined_minimum_size();
+
+ minsize.y+=size.y;
+ minsize.x=MAX(minsize.x,size.x);
+
+ if (first)
+ first=false;
+ else
+ minsize.y+=sep;
+
+ }
+
+
+ int vofs=0;
+ int w = get_size().x - sb->get_minimum_size().x;
+
+
+ cache_y.clear();
+ for(int i=0;i<get_child_count();i++) {
+ Control *c=get_child(i)->cast_to<Control>();
+ if (!c)
+ continue;
+ if (c->is_set_as_toplevel())
+ continue;
+
+ Size2i size=c->get_combined_minimum_size();
+
+ Rect2 r(sb->get_margin(MARGIN_LEFT),sb->get_margin(MARGIN_TOP)+vofs,w,size.y);
+
+ fit_child_in_rect(c,r);
+ cache_y.push_back(vofs+size.y*0.5);
+
+ if (vofs>0)
+ vofs+=sep;
+ vofs+=size.y;
+
+
+ }
+
+ _change_notify();
+ update();
+ connpos_dirty=true;
+
+
+}
+
+
+void GraphNode::_notification(int p_what) {
+
+ if (p_what==NOTIFICATION_DRAW) {
+
+ Ref<StyleBox> sb=get_stylebox("frame");
+ Ref<Texture> port =get_icon("port");
+ Ref<Texture> close =get_icon("close");
+ int close_offset = get_constant("close_offset");
+ Ref<Font> title_font = get_font("title_font");
+ int title_offset = get_constant("title_offset");
+ Color title_color = get_color("title_color");
+ Point2i icofs = -port->get_size()*0.5;
+ int edgeofs=get_constant("port_offset");
+ icofs.y+=sb->get_margin(MARGIN_TOP);
+ draw_style_box(sb,Rect2(Point2(),get_size()));
+
+ int w = get_size().width-sb->get_minimum_size().x;
+
+ if (show_close)
+ w-=close->get_width();
+
+ draw_string(title_font,Point2(sb->get_margin(MARGIN_LEFT),-title_font->get_height()+title_font->get_ascent()+title_offset),title,title_color,w);
+ if (show_close) {
+ Vector2 cpos = Point2(w+sb->get_margin(MARGIN_LEFT),-close->get_height()+close_offset);
+ draw_texture(close,cpos);
+ close_rect.pos=cpos;
+ close_rect.size=close->get_size();
+ } else {
+ close_rect=Rect2();
+ }
+
+ for (Map<int,Slot>::Element *E=slot_info.front();E;E=E->next()) {
+
+ if (E->key() < 0 || E->key()>=cache_y.size())
+ continue;
+ if (!slot_info.has(E->key()))
+ continue;
+ const Slot &s=slot_info[E->key()];
+ //left
+ if (s.enable_left)
+ port->draw(get_canvas_item(),icofs+Point2(edgeofs,cache_y[E->key()]),s.color_left);
+ if (s.enable_right)
+ port->draw(get_canvas_item(),icofs+Point2(get_size().x-edgeofs,cache_y[E->key()]),s.color_right);
+
+ }
+ }
+
+ if (p_what==NOTIFICATION_SORT_CHILDREN) {
+
+ _resort();
+ }
+
+}
+
+
+void GraphNode::set_slot(int p_idx,bool p_enable_left,int p_type_left,const Color& p_color_left, bool p_enable_right,int p_type_right,const Color& p_color_right) {
+
+ ERR_FAIL_COND(p_idx<0);
+
+ if (!p_enable_left && p_type_left==0 && p_color_left==Color(1,1,1,1) && !p_enable_right && p_type_right==0 && p_color_right==Color(1,1,1,1)) {
+ slot_info.erase(p_idx);
+ return;
+ }
+
+ Slot s;
+ s.enable_left=p_enable_left;
+ s.type_left=p_type_left;
+ s.color_left=p_color_left;
+ s.enable_right=p_enable_right;
+ s.type_right=p_type_right;
+ s.color_right=p_color_right;
+ slot_info[p_idx]=s;
+ update();
+ connpos_dirty=true;
+
+}
+
+void GraphNode::clear_slot(int p_idx){
+
+ slot_info.erase(p_idx);
+ update();
+ connpos_dirty=true;
+
+}
+void GraphNode::clear_all_slots(){
+
+ slot_info.clear();
+ update();
+ connpos_dirty=true;
+
+}
+bool GraphNode::is_slot_enabled_left(int p_idx) const{
+
+ if (!slot_info.has(p_idx))
+ return false;
+ return slot_info[p_idx].enable_left;
+
+}
+
+int GraphNode::get_slot_type_left(int p_idx) const{
+
+ if (!slot_info.has(p_idx))
+ return 0;
+ return slot_info[p_idx].type_left;
+
+}
+
+Color GraphNode::get_slot_color_left(int p_idx) const{
+
+ if (!slot_info.has(p_idx))
+ return Color(1,1,1,1);
+ return slot_info[p_idx].color_left;
+
+}
+
+bool GraphNode::is_slot_enabled_right(int p_idx) const{
+
+ if (!slot_info.has(p_idx))
+ return false;
+ return slot_info[p_idx].enable_right;
+
+}
+
+
+
+int GraphNode::get_slot_type_right(int p_idx) const{
+
+ if (!slot_info.has(p_idx))
+ return 0;
+ return slot_info[p_idx].type_right;
+
+}
+
+Color GraphNode::get_slot_color_right(int p_idx) const{
+
+ if (!slot_info.has(p_idx))
+ return Color(1,1,1,1);
+ return slot_info[p_idx].color_right;
+
+}
+
+Size2 GraphNode::get_minimum_size() const {
+
+ Ref<Font> title_font = get_font("title_font");
+
+ int sep=get_constant("separation");
+ Ref<StyleBox> sb=get_stylebox("frame");
+ bool first=true;
+
+ Size2 minsize;
+ minsize.x=title_font->get_string_size(title).x;
+ if (show_close) {
+ Ref<Texture> close =get_icon("close");
+ minsize.x+=sep+close->get_width();
+ }
+
+
+ for(int i=0;i<get_child_count();i++) {
+
+ Control *c=get_child(i)->cast_to<Control>();
+ if (!c)
+ continue;
+ if (c->is_set_as_toplevel())
+ continue;
+
+ Size2i size=c->get_combined_minimum_size();
+
+ minsize.y+=size.y;
+ minsize.x=MAX(minsize.x,size.x);
+
+ if (first)
+ first=false;
+ else
+ minsize.y+=sep;
+ }
+
+ return minsize+sb->get_minimum_size();
+}
+
+void GraphNode::set_title(const String& p_title) {
+
+ title=p_title;
+ minimum_size_changed();
+ update();
+
+}
+
+String GraphNode::get_title() const{
+
+ return title;
+}
+
+void GraphNode::set_offset(const Vector2& p_offset) {
+
+ offset=p_offset;
+ emit_signal("offset_changed");
+ update();
+}
+
+Vector2 GraphNode::get_offset() const {
+
+ return offset;
+}
+
+
+
+void GraphNode::set_show_close_button(bool p_enable){
+
+ show_close=p_enable;
+ update();
+}
+bool GraphNode::is_close_button_visible() const{
+
+ return show_close;
+}
+
+void GraphNode::_connpos_update() {
+
+
+ int edgeofs=get_constant("port_offset");
+ int sep=get_constant("separation");
+
+ Ref<StyleBox> sb=get_stylebox("frame");
+ Ref<Texture> port =get_icon("port");
+ conn_input_cache.clear();
+ conn_output_cache.clear();
+ int vofs=0;
+
+ int idx=0;
+
+ for(int i=0;i<get_child_count();i++) {
+ Control *c=get_child(i)->cast_to<Control>();
+ if (!c)
+ continue;
+ if (c->is_set_as_toplevel())
+ continue;
+
+ Size2i size=c->get_combined_minimum_size();
+
+ int y = sb->get_margin(MARGIN_TOP)+vofs;
+ int h = size.y;
+
+
+ if (slot_info.has(idx)) {
+
+ if (slot_info[idx].enable_left) {
+ ConnCache cc;
+ cc.pos=Point2i(edgeofs,y+h/2);
+ cc.type=slot_info[idx].type_left;
+ cc.color=slot_info[idx].color_left;
+ conn_input_cache.push_back(cc);
+ }
+ if (slot_info[idx].enable_right) {
+ ConnCache cc;
+ cc.pos=Point2i(get_size().width-edgeofs,y+h/2);
+ cc.type=slot_info[idx].type_right;
+ cc.color=slot_info[idx].color_right;
+ conn_output_cache.push_back(cc);
+ }
+ }
+
+ if (vofs>0)
+ vofs+=sep;
+ vofs+=size.y;
+ idx++;
+
+ }
+
+
+ connpos_dirty=false;
+}
+
+int GraphNode::get_connection_input_count() {
+
+ if (connpos_dirty)
+ _connpos_update();
+
+ return conn_input_cache.size();
+
+}
+int GraphNode::get_connection_output_count() {
+
+ if (connpos_dirty)
+ _connpos_update();
+
+ return conn_output_cache.size();
+
+}
+
+
+Vector2 GraphNode::get_connection_input_pos(int p_idx) {
+
+ if (connpos_dirty)
+ _connpos_update();
+
+ ERR_FAIL_INDEX_V(p_idx,conn_input_cache.size(),Vector2());
+ return conn_input_cache[p_idx].pos;
+}
+
+int GraphNode::get_connection_input_type(int p_idx) {
+
+ if (connpos_dirty)
+ _connpos_update();
+
+ ERR_FAIL_INDEX_V(p_idx,conn_input_cache.size(),0);
+ return conn_input_cache[p_idx].type;
+}
+
+Color GraphNode::get_connection_input_color(int p_idx) {
+
+ if (connpos_dirty)
+ _connpos_update();
+
+ ERR_FAIL_INDEX_V(p_idx,conn_input_cache.size(),Color());
+ return conn_input_cache[p_idx].color;
+}
+
+Vector2 GraphNode::get_connection_output_pos(int p_idx){
+
+ if (connpos_dirty)
+ _connpos_update();
+
+ ERR_FAIL_INDEX_V(p_idx,conn_output_cache.size(),Vector2());
+ return conn_output_cache[p_idx].pos;
+
+}
+
+int GraphNode::get_connection_output_type(int p_idx) {
+
+ if (connpos_dirty)
+ _connpos_update();
+
+ ERR_FAIL_INDEX_V(p_idx,conn_output_cache.size(),0);
+ return conn_output_cache[p_idx].type;
+}
+
+Color GraphNode::get_connection_output_color(int p_idx) {
+
+ if (connpos_dirty)
+ _connpos_update();
+
+ ERR_FAIL_INDEX_V(p_idx,conn_output_cache.size(),Color());
+ return conn_output_cache[p_idx].color;
+}
+
+void GraphNode::_input_event(const InputEvent& p_ev) {
+
+ if (p_ev.type==InputEvent::MOUSE_BUTTON && p_ev.mouse_button.pressed && p_ev.mouse_button.button_index==BUTTON_LEFT) {
+
+ Vector2 mpos = Vector2(p_ev.mouse_button.x,p_ev.mouse_button.y);
+ if (close_rect.size!=Size2() && close_rect.has_point(mpos)) {
+ emit_signal("close_request");
+ return;
+ }
+
+ drag_from=get_offset();
+ drag_accum=Vector2();
+ dragging=true;
+ emit_signal("raise_request");
+
+ }
+
+ if (p_ev.type==InputEvent::MOUSE_BUTTON && !p_ev.mouse_button.pressed && p_ev.mouse_button.button_index==BUTTON_LEFT) {
+
+ dragging=false;
+ emit_signal("dragged",drag_from,get_offset()); //useful for undo/redo
+ }
+
+ if (p_ev.type==InputEvent::MOUSE_MOTION && dragging) {
+
+ drag_accum+=Vector2(p_ev.mouse_motion.relative_x,p_ev.mouse_motion.relative_y);
+ set_offset(drag_from+drag_accum);
+ }
+
+}
+
+
+void GraphNode::_bind_methods() {
+
+ ObjectTypeDB::bind_method(_MD("set_title","title"),&GraphNode::set_title);
+ ObjectTypeDB::bind_method(_MD("get_title"),&GraphNode::get_title);
+ ObjectTypeDB::bind_method(_MD("_input_event"),&GraphNode::_input_event);
+
+ ObjectTypeDB::bind_method(_MD("set_slot","idx","enable_left","type_left","color_left","enable_right","type_right","color_right"),&GraphNode::set_slot);
+ ObjectTypeDB::bind_method(_MD("clear_slot","idx"),&GraphNode::clear_slot);
+ ObjectTypeDB::bind_method(_MD("clear_all_slots","idx"),&GraphNode::clear_all_slots);
+ ObjectTypeDB::bind_method(_MD("is_slot_enabled_left","idx"),&GraphNode::is_slot_enabled_left);
+ ObjectTypeDB::bind_method(_MD("get_slot_type_left","idx"),&GraphNode::get_slot_type_left);
+ ObjectTypeDB::bind_method(_MD("get_slot_color_left","idx"),&GraphNode::get_slot_color_left);
+ ObjectTypeDB::bind_method(_MD("is_slot_enabled_right","idx"),&GraphNode::is_slot_enabled_right);
+ ObjectTypeDB::bind_method(_MD("get_slot_type_right","idx"),&GraphNode::get_slot_type_right);
+ ObjectTypeDB::bind_method(_MD("get_slot_color_right","idx"),&GraphNode::get_slot_color_right);
+
+ ObjectTypeDB::bind_method(_MD("set_offset","offset"),&GraphNode::set_offset);
+ ObjectTypeDB::bind_method(_MD("get_offset"),&GraphNode::get_offset);
+
+ ObjectTypeDB::bind_method(_MD("get_connection_output_count"),&GraphNode::get_connection_output_count);
+ ObjectTypeDB::bind_method(_MD("get_connection_input_count"),&GraphNode::get_connection_input_count);
+
+ ObjectTypeDB::bind_method(_MD("get_connection_output_pos","idx"),&GraphNode::get_connection_output_pos);
+ ObjectTypeDB::bind_method(_MD("get_connection_output_type","idx"),&GraphNode::get_connection_output_type);
+ ObjectTypeDB::bind_method(_MD("get_connection_output_color","idx"),&GraphNode::get_connection_output_color);
+ ObjectTypeDB::bind_method(_MD("get_connection_input_pos","idx"),&GraphNode::get_connection_input_pos);
+ ObjectTypeDB::bind_method(_MD("get_connection_input_type","idx"),&GraphNode::get_connection_input_type);
+ ObjectTypeDB::bind_method(_MD("get_connection_input_color","idx"),&GraphNode::get_connection_input_color);
+
+
+ ObjectTypeDB::bind_method(_MD("set_show_close_button","show"),&GraphNode::set_show_close_button);
+ ObjectTypeDB::bind_method(_MD("is_close_button_visible"),&GraphNode::is_close_button_visible);
+
+ ADD_PROPERTY( PropertyInfo(Variant::STRING,"title"),_SCS("set_title"),_SCS("get_title"));
+ ADD_PROPERTY( PropertyInfo(Variant::BOOL,"show_close"),_SCS("set_show_close_button"),_SCS("is_close_button_visible"));
+
+ ADD_SIGNAL(MethodInfo("offset_changed"));
+ ADD_SIGNAL(MethodInfo("dragged",PropertyInfo(Variant::VECTOR2,"from"),PropertyInfo(Variant::VECTOR2,"to")));
+ ADD_SIGNAL(MethodInfo("raise_request"));
+ ADD_SIGNAL(MethodInfo("close_request"));
+}
+
+GraphNode::GraphNode() {
+
+ dragging=false;
+ show_close=false;
+ connpos_dirty=true;
+}
diff --git a/scene/gui/graph_node.h b/scene/gui/graph_node.h
new file mode 100644
index 0000000000..0d5cbf8dd3
--- /dev/null
+++ b/scene/gui/graph_node.h
@@ -0,0 +1,101 @@
+#ifndef GRAPH_NODE_H
+#define GRAPH_NODE_H
+
+#include "scene/gui/container.h"
+
+class GraphNode : public Container {
+
+ OBJ_TYPE(GraphNode,Container);
+
+
+
+ struct Slot {
+ bool enable_left;
+ int type_left;
+ Color color_left;
+ bool enable_right;
+ int type_right;
+ Color color_right;
+
+
+ Slot() { enable_left=false; type_left=0; color_left=Color(1,1,1,1); enable_right=false; type_right=0; color_right=Color(1,1,1,1); };
+ };
+
+ String title;
+ bool show_close;
+ Vector2 offset;
+
+ Rect2 close_rect;
+
+ Vector<int> cache_y;
+
+ struct ConnCache {
+ Vector2 pos;
+ int type;
+ Color color;
+ };
+
+ Vector<ConnCache> conn_input_cache;
+ Vector<ConnCache> conn_output_cache;
+
+ Map<int,Slot> slot_info;
+
+ bool connpos_dirty;
+
+ void _connpos_update();
+ void _resort();
+
+ Vector2 drag_from;
+ Vector2 drag_accum;
+ bool dragging;
+protected:
+
+ void _input_event(const InputEvent& p_ev);
+ void _notification(int p_what);
+ static void _bind_methods();
+
+ 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<PropertyInfo> *p_list) const;
+
+public:
+
+
+
+
+ void set_slot(int p_idx,bool p_enable_left,int p_type_left,const Color& p_color_left, bool p_enable_right,int p_type_right,const Color& p_color_right);
+ void clear_slot(int p_idx);
+ void clear_all_slots();
+ bool is_slot_enabled_left(int p_idx) const;
+ int get_slot_type_left(int p_idx) const;
+ Color get_slot_color_left(int p_idx) const;
+ bool is_slot_enabled_right(int p_idx) const;
+ int get_slot_type_right(int p_idx) const;
+ Color get_slot_color_right(int p_idx) const;
+
+ void set_title(const String& p_title);
+ String get_title() const;
+
+ void set_offset(const Vector2& p_offset);
+ Vector2 get_offset() const;
+
+ void set_show_close_button(bool p_enable);
+ bool is_close_button_visible() const;
+
+ int get_connection_input_count() ;
+ int get_connection_output_count() ;
+ Vector2 get_connection_input_pos(int p_idx);
+ int get_connection_input_type(int p_idx);
+ Color get_connection_input_color(int p_idx);
+ Vector2 get_connection_output_pos(int p_idx);
+ int get_connection_output_type(int p_idx);
+ Color get_connection_output_color(int p_idx);
+
+
+ virtual Size2 get_minimum_size() const;
+
+ GraphNode();
+};
+
+
+#endif // GRAPH_NODE_H
diff --git a/scene/gui/menu_button.cpp b/scene/gui/menu_button.cpp
index 7353744d07..d10ca20fc3 100644
--- a/scene/gui/menu_button.cpp
+++ b/scene/gui/menu_button.cpp
@@ -84,6 +84,7 @@ void MenuButton::pressed() {
popup->set_parent_rect( Rect2(Point2(gp-popup->get_global_pos()),get_size()));
popup->popup();
popup->call_deferred("grab_click_focus");
+ popup->set_invalidate_click_until_motion();
}
diff --git a/scene/gui/popup.cpp b/scene/gui/popup.cpp
index 65ad02723c..bccd05d4fe 100644
--- a/scene/gui/popup.cpp
+++ b/scene/gui/popup.cpp
@@ -51,11 +51,18 @@ void Popup::_fix_size() {
Control *window = get_window();
ERR_FAIL_COND(!window);
-
+
+#if 0
Point2 pos = get_pos();
Size2 size = get_size();
Point2 window_size = window==this ? get_parent_area_size() :window->get_size();
+#else
+
+ Point2 pos = get_global_pos();
+ Size2 size = get_size();
+ Point2 window_size = get_viewport_rect().size;
+#endif
if (pos.x+size.width > window_size.width)
pos.x=window_size.width-size.width;
if (pos.x<0)
@@ -65,8 +72,14 @@ void Popup::_fix_size() {
pos.y=window_size.height-size.height;
if (pos.y<0)
pos.y=0;
+#if 0
if (pos!=get_pos())
set_pos(pos);
+#else
+ if (pos!=get_pos())
+ set_global_pos(pos);
+
+#endif
}
diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp
index 0ba3bdb7c6..1fd1d8adc8 100644
--- a/scene/gui/popup_menu.cpp
+++ b/scene/gui/popup_menu.cpp
@@ -30,6 +30,7 @@
#include "print_string.h"
#include "os/keyboard.h"
#include "translation.h"
+#include "os/input.h"
String PopupMenu::_get_accel_text(uint32_t p_accel) const {
@@ -318,6 +319,10 @@ void PopupMenu::_input_event(const InputEvent &p_event) {
int over=_get_mouse_over(Point2(b.x,b.y));
+ if (invalidated_click) {
+ invalidated_click=false;
+ break;
+ }
if (over<0 || items[over].separator || items[over].disabled)
break; //non-activable
@@ -336,6 +341,13 @@ void PopupMenu::_input_event(const InputEvent &p_event) {
case InputEvent::MOUSE_MOTION: {
+ if (invalidated_click) {
+ moved+=Vector2(p_event.mouse_motion.relative_x,p_event.mouse_motion.relative_y);
+ if (moved.length()>4)
+ invalidated_click=false;
+
+ }
+
const InputEventMouseMotion &m=p_event.mouse_motion;
for(List<Rect2>::Element *E=autohide_areas.front();E;E=E->next()) {
@@ -893,12 +905,17 @@ void PopupMenu::_bind_methods() {
}
+
+void PopupMenu::set_invalidate_click_until_motion() {
+ moved=Vector2();
+ invalidated_click=true;
+}
+
PopupMenu::PopupMenu() {
idcount=0;
mouse_over=-1;
-
set_focus_mode(FOCUS_ALL);
set_as_toplevel(true);
diff --git a/scene/gui/popup_menu.h b/scene/gui/popup_menu.h
index b150be1008..c2e988de95 100644
--- a/scene/gui/popup_menu.h
+++ b/scene/gui/popup_menu.h
@@ -70,6 +70,8 @@ class PopupMenu : public Popup {
void _activate_submenu(int over);
void _submenu_timeout();
+ bool invalidated_click;
+ Vector2 moved;
Array _get_items() const;
void _set_items(const Array& p_items);
@@ -134,6 +136,8 @@ public:
void add_autohide_area(const Rect2& p_area);
void clear_autohide_areas();
+ void set_invalidate_click_until_motion();
+
PopupMenu();
~PopupMenu();
diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp
index 2d6f3cd27a..12a8a83f26 100644
--- a/scene/gui/tab_container.cpp
+++ b/scene/gui/tab_container.cpp
@@ -602,6 +602,39 @@ void TabContainer::get_translatable_strings(List<String> *p_strings) const {
}
+Size2 TabContainer::get_minimum_size() const {
+
+ Size2 ms;
+
+ for(int i=0;i<get_child_count();i++) {
+
+ Control *c = get_child(i)->cast_to<Control>();
+ if (!c)
+ continue;
+ if (c->is_set_as_toplevel())
+ continue;
+
+ if (!c->has_meta("_tab_name"))
+ continue;
+
+ if (!c->is_visible())
+ continue;
+
+ Size2 cms = c->get_minimum_size();
+ ms.x=MAX(ms.x,cms.x);
+ ms.y=MAX(ms.y,cms.y);
+ }
+
+ Ref<StyleBox> tab_bg = get_stylebox("tab_bg");
+ Ref<StyleBox> tab_fg = get_stylebox("tab_fg");
+ Ref<Font> font = get_font("font");
+
+ ms.y+=MAX(tab_bg->get_minimum_size().y,tab_fg->get_minimum_size().y);
+ ms.y+=font->get_height();
+
+ return ms;
+}
+
void TabContainer::_bind_methods() {
ObjectTypeDB::bind_method(_MD("_input_event"),&TabContainer::_input_event);
diff --git a/scene/gui/tab_container.h b/scene/gui/tab_container.h
index d5b6a2b503..df7b03e040 100644
--- a/scene/gui/tab_container.h
+++ b/scene/gui/tab_container.h
@@ -85,6 +85,8 @@ public:
void set_current_tab(int p_current);
int get_current_tab() const;
+ virtual Size2 get_minimum_size() const;
+
virtual void get_translatable_strings(List<String> *p_strings) const;
TabContainer();
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index ba68948e6b..d589b93049 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -26,7 +26,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
- /*****f********************************************/
+/*****f********************************************/
/* text_edit.cpp */
/*************************************************/
/* This file is part of: */
@@ -47,2160 +47,2409 @@
#define TAB_PIXELS
static bool _is_text_char(CharType c) {
-
- return (c>='a' && c<='z') || (c>='A' && c<='Z') || (c>='0' && c<='9') || c=='_';
+
+ return (c>='a' && c<='z') || (c>='A' && c<='Z') || (c>='0' && c<='9') || c=='_';
}
static bool _is_symbol(CharType c) {
-
- return c!='_' && ((c>='!' && c<='/') || (c>=':' && c<='@') || (c>='[' && c<='`') || (c>='{' && c<='~') || c=='\t');
+
+ return c!='_' && ((c>='!' && c<='/') || (c>=':' && c<='@') || (c>='[' && c<='`') || (c>='{' && c<='~') || c=='\t');
}
static bool _is_pair_right_symbol(CharType c) {
- return
- c == '"' ||
- c == '\'' ||
- c == ')' ||
- c == ']' ||
- c == '}';
+ return
+ c == '"' ||
+ c == '\'' ||
+ c == ')' ||
+ c == ']' ||
+ c == '}';
}
static bool _is_pair_left_symbol(CharType c) {
- return
- c == '"' ||
- c == '\'' ||
- c == '(' ||
- c == '[' ||
- c == '{';
+ return
+ c == '"' ||
+ c == '\'' ||
+ c == '(' ||
+ c == '[' ||
+ c == '{';
}
static bool _is_pair_symbol(CharType c) {
- return _is_pair_left_symbol(c) || _is_pair_right_symbol(c);
+ return _is_pair_left_symbol(c) || _is_pair_right_symbol(c);
}
static CharType _get_right_pair_symbol(CharType c) {
- if(c == '"')
- return '"';
- if(c == '\'')
- return '\'';
- if(c == '(')
- return ')';
- if(c == '[')
- return ']';
- if(c == '{')
- return '}';
- return 0;
+ if(c == '"')
+ return '"';
+ if(c == '\'')
+ return '\'';
+ if(c == '(')
+ return ')';
+ if(c == '[')
+ return ']';
+ if(c == '{')
+ return '}';
+ return 0;
}
void TextEdit::Text::set_font(const Ref<Font>& p_font) {
-
- font=p_font;
+
+ font=p_font;
}
void TextEdit::Text::set_tab_size(int p_tab_size) {
-
- tab_size=p_tab_size;
+
+ tab_size=p_tab_size;
}
void TextEdit::Text::_update_line_cache(int p_line) const {
-
- int w =0;
- int tab_w=font->get_char_size(' ').width;
-
- int len = text[p_line].data.length();
- const CharType *str = text[p_line].data.c_str();
-
- //update width
-
- for(int i=0;i<len;i++) {
- if (str[i]=='\t') {
-
- int left = w%tab_w;
- if (left==0)
- w+=tab_w;
- else
- w+=tab_w-w%tab_w; // is right...
-
- } else {
-
- w+=font->get_char_size(str[i],str[i+1]).width;
- }
- }
-
-
- text[p_line].width_cache=w;
-
- //update regions
-
- text[p_line].region_info.clear();
-
- for(int i=0;i<len;i++) {
-
- if (!_is_symbol(str[i]))
- continue;
- if (str[i]=='\\') {
- i++; //skip quoted anything
- continue;
- }
-
- int left=len-i;
-
- for(int j=0;j<color_regions->size();j++) {
-
- const ColorRegion& cr=color_regions->operator [](j);
-
- /* BEGIN */
-
- int lr=cr.begin_key.length();
- if (lr==0 || lr>left)
- continue;
-
- const CharType* kc = cr.begin_key.c_str();
-
- bool match=true;
-
- for(int k=0;k<lr;k++) {
- if (kc[k]!=str[i+k]) {
- match=false;
- break;
- }
- }
-
- if (match) {
-
- ColorRegionInfo cri;
- cri.end=false;
- cri.region=j;
- text[p_line].region_info[i]=cri;
- i+=lr-1;
- break;
- }
-
- /* END */
-
- lr=cr.end_key.length();
- if (lr==0 || lr>left)
- continue;
-
- kc = cr.end_key.c_str();
-
- match=true;
-
- for(int k=0;k<lr;k++) {
- if (kc[k]!=str[i+k]) {
- match=false;
- break;
- }
- }
-
- if (match) {
-
- ColorRegionInfo cri;
- cri.end=true;
- cri.region=j;
- text[p_line].region_info[i]=cri;
- i+=lr-1;
- break;
- }
-
- }
- }
-
-
+
+ int w =0;
+ int tab_w=font->get_char_size(' ').width;
+
+ int len = text[p_line].data.length();
+ const CharType *str = text[p_line].data.c_str();
+
+ //update width
+
+ for(int i=0;i<len;i++) {
+ if (str[i]=='\t') {
+
+ int left = w%tab_w;
+ if (left==0)
+ w+=tab_w;
+ else
+ w+=tab_w-w%tab_w; // is right...
+
+ } else {
+
+ w+=font->get_char_size(str[i],str[i+1]).width;
+ }
+ }
+
+
+ text[p_line].width_cache=w;
+
+ //update regions
+
+ text[p_line].region_info.clear();
+
+ for(int i=0;i<len;i++) {
+
+ if (!_is_symbol(str[i]))
+ continue;
+ if (str[i]=='\\') {
+ i++; //skip quoted anything
+ continue;
+ }
+
+ int left=len-i;
+
+ for(int j=0;j<color_regions->size();j++) {
+
+ const ColorRegion& cr=color_regions->operator [](j);
+
+ /* BEGIN */
+
+ int lr=cr.begin_key.length();
+ if (lr==0 || lr>left)
+ continue;
+
+ const CharType* kc = cr.begin_key.c_str();
+
+ bool match=true;
+
+ for(int k=0;k<lr;k++) {
+ if (kc[k]!=str[i+k]) {
+ match=false;
+ break;
+ }
+ }
+
+ if (match) {
+
+ ColorRegionInfo cri;
+ cri.end=false;
+ cri.region=j;
+ text[p_line].region_info[i]=cri;
+ i+=lr-1;
+ break;
+ }
+
+ /* END */
+
+ lr=cr.end_key.length();
+ if (lr==0 || lr>left)
+ continue;
+
+ kc = cr.end_key.c_str();
+
+ match=true;
+
+ for(int k=0;k<lr;k++) {
+ if (kc[k]!=str[i+k]) {
+ match=false;
+ break;
+ }
+ }
+
+ if (match) {
+
+ ColorRegionInfo cri;
+ cri.end=true;
+ cri.region=j;
+ text[p_line].region_info[i]=cri;
+ i+=lr-1;
+ break;
+ }
+
+ }
+ }
+
+
}
const Map<int,TextEdit::Text::ColorRegionInfo>& TextEdit::Text::get_color_region_info(int p_line) {
-
- Map<int,ColorRegionInfo> *cri=NULL;
- ERR_FAIL_INDEX_V(p_line,text.size(),*cri); //enjoy your crash
-
- if (text[p_line].width_cache==-1) {
- _update_line_cache(p_line);
- }
-
- return text[p_line].region_info;
+
+ Map<int,ColorRegionInfo> *cri=NULL;
+ ERR_FAIL_INDEX_V(p_line,text.size(),*cri); //enjoy your crash
+
+ if (text[p_line].width_cache==-1) {
+ _update_line_cache(p_line);
+ }
+
+ return text[p_line].region_info;
}
int TextEdit::Text::get_line_width(int p_line) const {
-
- ERR_FAIL_INDEX_V(p_line,text.size(),-1);
-
- if (text[p_line].width_cache==-1) {
- _update_line_cache(p_line);
- }
-
- return text[p_line].width_cache;
+
+ ERR_FAIL_INDEX_V(p_line,text.size(),-1);
+
+ if (text[p_line].width_cache==-1) {
+ _update_line_cache(p_line);
+ }
+
+ return text[p_line].width_cache;
}
void TextEdit::Text::clear_caches() {
-
- for(int i=0;i<text.size();i++)
- text[i].width_cache=-1;
-
+
+ for(int i=0;i<text.size();i++)
+ text[i].width_cache=-1;
+
}
void TextEdit::Text::clear() {
-
-
- text.clear();;
- insert(0,"");
+
+
+ text.clear();;
+ insert(0,"");
}
int TextEdit::Text::get_max_width() const {
- //quite some work.. but should be fast enough.
-
- int max = 0;
-
- for(int i=0;i<text.size();i++)
- max=MAX(max,get_line_width(i));
- return max;
-
+ //quite some work.. but should be fast enough.
+
+ int max = 0;
+
+ for(int i=0;i<text.size();i++)
+ max=MAX(max,get_line_width(i));
+ return max;
+
}
void TextEdit::Text::set(int p_line,const String& p_text) {
-
- ERR_FAIL_INDEX(p_line,text.size());
-
- text[p_line].width_cache=-1;
- text[p_line].data=p_text;
+
+ ERR_FAIL_INDEX(p_line,text.size());
+
+ text[p_line].width_cache=-1;
+ text[p_line].data=p_text;
}
void TextEdit::Text::insert(int p_at,const String& p_text) {
-
- Line line;
- line.marked=false;
- line.breakpoint=false;
- line.width_cache=-1;
- line.data=p_text;
- text.insert(p_at,line);
+
+ Line line;
+ line.marked=false;
+ line.breakpoint=false;
+ line.width_cache=-1;
+ line.data=p_text;
+ text.insert(p_at,line);
}
void TextEdit::Text::remove(int p_at) {
-
- text.remove(p_at);
+
+ text.remove(p_at);
}
void TextEdit::_update_scrollbars() {
-
-
- Size2 size = get_size();
- Size2 hmin = h_scroll->get_combined_minimum_size();
- Size2 vmin = v_scroll->get_combined_minimum_size();
-
-
-
- v_scroll->set_begin( Point2(size.width - vmin.width, cache.style_normal->get_margin(MARGIN_TOP)) );
- v_scroll->set_end( Point2(size.width, size.height - cache.style_normal->get_margin(MARGIN_TOP) - cache.style_normal->get_margin(MARGIN_BOTTOM)) );
-
- h_scroll->set_begin( Point2( 0, size.height - hmin.height) );
- h_scroll->set_end( Point2(size.width-vmin.width, size.height) );
-
-
- int hscroll_rows = ((hmin.height-1)/get_row_height())+1;
- int visible_rows = get_visible_rows();
- int total_rows = text.size() * cache.line_spacing;
-
- int vscroll_pixels = v_scroll->get_combined_minimum_size().width;
- int visible_width = size.width - cache.style_normal->get_minimum_size().width;
- int total_width = text.get_max_width();
-
- bool use_hscroll=true;
- bool use_vscroll=true;
-
- if (total_rows <= visible_rows && total_width <= visible_width) {
- //thanks yessopie for this clever bit of logic
- use_hscroll=false;
- use_vscroll=false;
-
- } else {
-
- if (total_rows > visible_rows && total_width <= visible_width - vscroll_pixels) {
- //thanks yessopie for this clever bit of logic
- use_hscroll=false;
- }
-
- if (total_rows <= visible_rows - hscroll_rows && total_width > visible_width) {
- //thanks yessopie for this clever bit of logic
- use_vscroll=false;
- }
- }
-
- updating_scrolls=true;
-
- if (use_vscroll) {
-
- v_scroll->show();
- v_scroll->set_max(total_rows);
- v_scroll->set_page(visible_rows);
-
- v_scroll->set_val(cursor.line_ofs);
-
- } else {
- cursor.line_ofs = 0;
- v_scroll->hide();
- }
-
- if (use_hscroll) {
-
- h_scroll->show();
- h_scroll->set_max(total_width);
- h_scroll->set_page(visible_width);
- h_scroll->set_val(cursor.x_ofs);
- } else {
-
- h_scroll->hide();
- }
-
-
-
- updating_scrolls=false;
+
+
+ Size2 size = get_size();
+ Size2 hmin = h_scroll->get_combined_minimum_size();
+ Size2 vmin = v_scroll->get_combined_minimum_size();
+
+
+
+ v_scroll->set_begin( Point2(size.width - vmin.width, cache.style_normal->get_margin(MARGIN_TOP)) );
+ v_scroll->set_end( Point2(size.width, size.height - cache.style_normal->get_margin(MARGIN_TOP) - cache.style_normal->get_margin(MARGIN_BOTTOM)) );
+
+ h_scroll->set_begin( Point2( 0, size.height - hmin.height) );
+ h_scroll->set_end( Point2(size.width-vmin.width, size.height) );
+
+
+ int hscroll_rows = ((hmin.height-1)/get_row_height())+1;
+ int visible_rows = get_visible_rows();
+ int total_rows = text.size() * cache.line_spacing;
+
+ int vscroll_pixels = v_scroll->get_combined_minimum_size().width;
+ int visible_width = size.width - cache.style_normal->get_minimum_size().width;
+ int total_width = text.get_max_width();
+
+ bool use_hscroll=true;
+ bool use_vscroll=true;
+
+ if (total_rows <= visible_rows && total_width <= visible_width) {
+ //thanks yessopie for this clever bit of logic
+ use_hscroll=false;
+ use_vscroll=false;
+
+ } else {
+
+ if (total_rows > visible_rows && total_width <= visible_width - vscroll_pixels) {
+ //thanks yessopie for this clever bit of logic
+ use_hscroll=false;
+ }
+
+ if (total_rows <= visible_rows - hscroll_rows && total_width > visible_width) {
+ //thanks yessopie for this clever bit of logic
+ use_vscroll=false;
+ }
+ }
+
+ updating_scrolls=true;
+
+ if (use_vscroll) {
+
+ v_scroll->show();
+ v_scroll->set_max(total_rows);
+ v_scroll->set_page(visible_rows);
+
+ v_scroll->set_val(cursor.line_ofs);
+
+ } else {
+ cursor.line_ofs = 0;
+ v_scroll->hide();
+ }
+
+ if (use_hscroll) {
+
+ h_scroll->show();
+ h_scroll->set_max(total_width);
+ h_scroll->set_page(visible_width);
+ h_scroll->set_val(cursor.x_ofs);
+ } else {
+
+ h_scroll->hide();
+ }
+
+
+
+ updating_scrolls=false;
}
void TextEdit::_notification(int p_what) {
-
- switch(p_what) {
- case NOTIFICATION_ENTER_TREE: {
-
- _update_caches();
- if (cursor_changed_dirty)
- MessageQueue::get_singleton()->push_call(this,"_cursor_changed_emit");
- if (text_changed_dirty)
- MessageQueue::get_singleton()->push_call(this,"_text_changed_emit");
-
- } break;
- case NOTIFICATION_RESIZED: {
-
- cache.size=get_size();
- adjust_viewport_to_cursor();
-
-
- } break;
- case NOTIFICATION_THEME_CHANGED: {
-
- _update_caches();
- };
- case NOTIFICATION_DRAW: {
-
- int line_number_char_count=0;
-
- {
- int lc=text.size()+1;
- cache.line_number_w=0;
- while(lc) {
- cache.line_number_w+=1;
- lc/=10;
- };
-
- if (line_numbers) {
-
- line_number_char_count=cache.line_number_w;
- cache.line_number_w=(cache.line_number_w+1)*cache.font->get_char_size('0').width;
- } else {
- cache.line_number_w=0;
- }
-
-
- }
- _update_scrollbars();
-
-
- RID ci = get_canvas_item();
- int xmargin_beg=cache.style_normal->get_margin(MARGIN_LEFT)+cache.line_number_w;
- int xmargin_end=cache.size.width-cache.style_normal->get_margin(MARGIN_RIGHT);
- //let's do it easy for now:
- cache.style_normal->draw(ci,Rect2(Point2(),cache.size));
- if (has_focus())
- cache.style_focus->draw(ci,Rect2(Point2(),cache.size));
-
-
- int ascent=cache.font->get_ascent();
-
- int visible_rows = get_visible_rows();
-
- int tab_w = cache.font->get_char_size(' ').width*tab_size;
-
- Color color = cache.font_color;
- int in_region=-1;
-
- if (syntax_coloring) {
-
- if (custom_bg_color.a>0.01) {
-
- Point2i ofs = Point2i(cache.style_normal->get_offset())/2.0;
- VisualServer::get_singleton()->canvas_item_add_rect(ci,Rect2(ofs, get_size()-cache.style_normal->get_minimum_size()+ofs),custom_bg_color);
- }
- //compute actual region to start (may be inside say, a comment).
- //slow in very large documments :( but ok for source!
-
- for(int i=0;i<cursor.line_ofs;i++) {
-
- const Map<int,Text::ColorRegionInfo>& cri_map=text.get_color_region_info(i);
-
- if (in_region>=0 && color_regions[in_region].line_only) {
- in_region=-1; //reset regions that end at end of line
- }
-
- for( const Map<int,Text::ColorRegionInfo>::Element* E= cri_map.front();E;E=E->next() ) {
-
- const Text::ColorRegionInfo &cri=E->get();
-
- if (in_region==-1) {
-
- if (!cri.end) {
-
- in_region=cri.region;
- }
- } else if (in_region==cri.region && !color_regions[cri.region].line_only) { //ignore otherwise
-
- if (cri.end || color_regions[cri.region].eq) {
-
- in_region=-1;
- }
- }
- }
- }
- }
-
- int deregion=0; //force it to clear inrgion
- Point2 cursor_pos;
-
- for (int i=0;i<visible_rows;i++) {
-
- int line=i+cursor.line_ofs;
-
- if (line<0 || line>=(int)text.size())
- continue;
-
- const String &str=text[line];
-
- int char_margin=xmargin_beg-cursor.x_ofs;
- int char_ofs=0;
- int ofs_y=i*get_row_height()+cache.line_spacing/2;
- bool prev_is_char=false;
- bool in_keyword=false;
- Color keyword_color;
-
- if (cache.line_number_w) {
- Color fcol = cache.font_color;
- fcol.a*=0.4;
- String fc = String::num(line+1);
- while (fc.length() < line_number_char_count) {
- fc="0"+fc;
- }
-
- cache.font->draw(ci,Point2(cache.style_normal->get_margin(MARGIN_LEFT),ofs_y+cache.font->get_ascent()),fc,fcol);
- }
-
- const Map<int,Text::ColorRegionInfo>& cri_map=text.get_color_region_info(line);
-
-
- if (text.is_marked(line)) {
-
- VisualServer::get_singleton()->canvas_item_add_rect(ci,Rect2(xmargin_beg, ofs_y,xmargin_end-xmargin_beg,get_row_height()),cache.mark_color);
- }
-
- if (text.is_breakpoint(line)) {
-
- VisualServer::get_singleton()->canvas_item_add_rect(ci,Rect2(xmargin_beg, ofs_y,xmargin_end-xmargin_beg,get_row_height()),cache.breakpoint_color);
- }
-
-
- if (line==cursor.line) {
-
- VisualServer::get_singleton()->canvas_item_add_rect(ci,Rect2(xmargin_beg, ofs_y,xmargin_end-xmargin_beg,get_row_height()),cache.current_line_color);
-
- }
- for (int j=0;j<str.length();j++) {
-
- //look for keyword
-
- if (deregion>0) {
- deregion--;
- if (deregion==0)
- in_region=-1;
- }
- if (syntax_coloring && deregion==0) {
-
-
- color = cache.font_color; //reset
- //find keyword
- bool is_char = _is_text_char(str[j]);
- bool is_symbol=_is_symbol(str[j]);
-
- if (j==0 && in_region>=0 && color_regions[in_region].line_only) {
- in_region=-1; //reset regions that end at end of line
- }
-
- if (is_symbol && cri_map.has(j)) {
-
-
- const Text::ColorRegionInfo &cri=cri_map[j];
-
- if (in_region==-1) {
-
- if (!cri.end) {
-
- in_region=cri.region;
- }
- } else if (in_region==cri.region && !color_regions[cri.region].line_only) { //ignore otherwise
-
- if (cri.end || color_regions[cri.region].eq) {
-
- deregion=color_regions[cri.region].eq?color_regions[cri.region].begin_key.length():color_regions[cri.region].end_key.length();
- }
- }
- }
-
- if (!is_char)
- in_keyword=false;
-
- if (in_region==-1 && !in_keyword && is_char && !prev_is_char) {
-
- int to=j;
- while(_is_text_char(str[to]) && to<str.length())
- to++;
-
- uint32_t hash = String::hash(&str[j],to-j);
- StrRange range(&str[j],to-j);
-
- const Color *col=keywords.custom_getptr(range,hash);
-
- if (col) {
-
- in_keyword=true;
- keyword_color=*col;
- }
- }
-
-
- if (in_region>=0)
- color=color_regions[in_region].color;
- else if (in_keyword)
- color=keyword_color;
- else if (is_symbol)
- color=symbol_color;
-
- prev_is_char=is_char;
-
- }
- int char_w;
-
- //handle tabulator
-
-
- if (str[j]=='\t') {
- int left = char_ofs%tab_w;
- if (left==0)
- char_w=tab_w;
- else
- char_w=tab_w-char_ofs%tab_w; // is right...
-
- } else {
- char_w=cache.font->get_char_size(str[j],str[j+1]).width;
- }
-
- if ( (char_ofs+char_margin)<xmargin_beg) {
- char_ofs+=char_w;
- continue;
- }
-
- if ( (char_ofs+char_margin+char_w)>=xmargin_end) {
- if (syntax_coloring)
- continue;
- else
- break;
- }
-
- bool in_selection = (selection.active && line>=selection.from_line && line<=selection.to_line && (line>selection.from_line || j>=selection.from_column) && (line<selection.to_line || j<selection.to_column));
-
-
- if (in_selection) {
- //inside selection!
- VisualServer::get_singleton()->canvas_item_add_rect(ci,Rect2(Point2i( char_ofs+char_margin, ofs_y ), Size2i(char_w,get_row_height())),cache.selection_color);
- }
-
-
-
- if (str[j]>=32)
- cache.font->draw_char(ci,Point2i( char_ofs+char_margin, ofs_y+ascent),str[j],str[j+1],in_selection?cache.font_selected_color:color);
- else if (draw_tabs && str[j]=='\t') {
- int yofs= (get_row_height() - cache.tab_icon->get_height())/2;
- cache.tab_icon->draw(ci, Point2(char_ofs+char_margin,ofs_y+yofs),in_selection?cache.font_selected_color:color);
- }
-
-
- if (cursor.column==j && cursor.line==line) {
-
- cursor_pos = Point2i( char_ofs+char_margin, ofs_y );
- VisualServer::get_singleton()->canvas_item_add_rect(ci,Rect2(cursor_pos, Size2i(1,get_row_height())),cache.font_color);
-
-
- }
- char_ofs+=char_w;
-
- }
-
- if (cursor.column==str.length() && cursor.line==line) {
-
- cursor_pos=Point2i( char_ofs+char_margin, ofs_y );
- VisualServer::get_singleton()->canvas_item_add_rect(ci,Rect2(cursor_pos, Size2i(1,get_row_height())),cache.font_color);
-
- }
- }
-
- if (completion_active) {
- // code completion box
- Ref<StyleBox> csb = get_stylebox("completion");
- Ref<StyleBox> csel = get_stylebox("completion_selected");
- int maxlines = get_constant("completion_lines");
- int cmax_width = get_constant("completion_max_width")*cache.font->get_char_size('x').x;
- Color existing = get_color("completion_existing");
- int scrollw = get_constant("completion_scroll_width");
- Color scrollc = get_color("completion_scroll_color");
-
-
-
- int lines = MIN(completion_options.size(),maxlines);
- int w=0;
- int h=lines*get_row_height();
- int nofs = cache.font->get_string_size(completion_base).width;
-
-
- if (completion_options.size() < 50) {
- for(int i=0;i<completion_options.size();i++) {
- int w2=MIN(cache.font->get_string_size(completion_options[i]).x,cmax_width);
- if (w2>w)
- w=w2;
- }
- } else {
- w=cmax_width;
- }
-
- int th = h + csb->get_minimum_size().y;
- if (cursor_pos.y+get_row_height()+th > get_size().height) {
- completion_rect.pos.y=cursor_pos.y-th;
- } else {
- completion_rect.pos.y=cursor_pos.y+get_row_height()+csb->get_offset().y;
- }
-
- if (cursor_pos.x-nofs+w+scrollw > get_size().width) {
- completion_rect.pos.x=get_size().width-w-scrollw;
- } else {
- completion_rect.pos.x=cursor_pos.x-nofs;
- }
-
- completion_rect.size.width=w;
- completion_rect.size.height=h;
- if (completion_options.size()<=maxlines)
- scrollw=0;
-
- draw_style_box(csb,Rect2(completion_rect.pos-csb->get_offset(),completion_rect.size+csb->get_minimum_size()+Size2(scrollw,0)));
-
-
- int line_from = CLAMP(completion_index - lines/2, 0, completion_options.size() - lines);
- draw_style_box(csel,Rect2(Point2(completion_rect.pos.x,completion_rect.pos.y+(completion_index-line_from)*get_row_height()),Size2(completion_rect.size.width,get_row_height())));
-
- draw_rect(Rect2(completion_rect.pos,Size2(nofs,completion_rect.size.height)),existing);
-
- for(int i=0;i<lines;i++) {
-
- int l = line_from + i;
- ERR_CONTINUE( l < 0 || l>= completion_options.size());
- draw_string(cache.font,Point2(completion_rect.pos.x,completion_rect.pos.y+i*get_row_height()+cache.font->get_ascent()),completion_options[l],cache.font_color,completion_rect.size.width);
- }
-
- if (scrollw) {
- //draw a small scroll rectangle to show a position in the options
- float r = maxlines / (float)completion_options.size();
- float o = line_from / (float)completion_options.size();
- draw_rect(Rect2(completion_rect.pos.x+completion_rect.size.width,completion_rect.pos.y+o*completion_rect.size.y,scrollw,completion_rect.size.y*r),scrollc);
- }
-
- completion_line_ofs=line_from;
-
- }
-
-
-
- } break;
- case NOTIFICATION_FOCUS_ENTER: {
-
- if (OS::get_singleton()->has_virtual_keyboard())
- OS::get_singleton()->show_virtual_keyboard(get_text(),get_global_rect());
-
- } break;
- case NOTIFICATION_FOCUS_EXIT: {
-
- if (OS::get_singleton()->has_virtual_keyboard())
- OS::get_singleton()->hide_virtual_keyboard();
-
- } break;
-
- }
+
+ switch(p_what) {
+ case NOTIFICATION_ENTER_TREE: {
+
+ _update_caches();
+ if (cursor_changed_dirty)
+ MessageQueue::get_singleton()->push_call(this,"_cursor_changed_emit");
+ if (text_changed_dirty)
+ MessageQueue::get_singleton()->push_call(this,"_text_changed_emit");
+
+ } break;
+ case NOTIFICATION_RESIZED: {
+
+ cache.size=get_size();
+ adjust_viewport_to_cursor();
+
+
+ } break;
+ case NOTIFICATION_THEME_CHANGED: {
+
+ _update_caches();
+ };
+ case NOTIFICATION_DRAW: {
+
+ int line_number_char_count=0;
+
+ {
+ int lc=text.size()+1;
+ cache.line_number_w=0;
+ while(lc) {
+ cache.line_number_w+=1;
+ lc/=10;
+ };
+
+ if (line_numbers) {
+
+ line_number_char_count=cache.line_number_w;
+ cache.line_number_w=(cache.line_number_w+1)*cache.font->get_char_size('0').width;
+ } else {
+ cache.line_number_w=0;
+ }
+
+
+ }
+ _update_scrollbars();
+
+
+ RID ci = get_canvas_item();
+ int xmargin_beg=cache.style_normal->get_margin(MARGIN_LEFT)+cache.line_number_w;
+ int xmargin_end=cache.size.width-cache.style_normal->get_margin(MARGIN_RIGHT);
+ //let's do it easy for now:
+ cache.style_normal->draw(ci,Rect2(Point2(),cache.size));
+ if (has_focus())
+ cache.style_focus->draw(ci,Rect2(Point2(),cache.size));
+
+
+ int ascent=cache.font->get_ascent();
+
+ int visible_rows = get_visible_rows();
+
+ int tab_w = cache.font->get_char_size(' ').width*tab_size;
+
+ Color color = cache.font_color;
+ int in_region=-1;
+
+ if (syntax_coloring) {
+
+ if (custom_bg_color.a>0.01) {
+
+ Point2i ofs = Point2i(cache.style_normal->get_offset())/2.0;
+ VisualServer::get_singleton()->canvas_item_add_rect(ci,Rect2(ofs, get_size()-cache.style_normal->get_minimum_size()+ofs),custom_bg_color);
+ }
+ //compute actual region to start (may be inside say, a comment).
+ //slow in very large documments :( but ok for source!
+
+ for(int i=0;i<cursor.line_ofs;i++) {
+
+ const Map<int,Text::ColorRegionInfo>& cri_map=text.get_color_region_info(i);
+
+ if (in_region>=0 && color_regions[in_region].line_only) {
+ in_region=-1; //reset regions that end at end of line
+ }
+
+ for( const Map<int,Text::ColorRegionInfo>::Element* E= cri_map.front();E;E=E->next() ) {
+
+ const Text::ColorRegionInfo &cri=E->get();
+
+ if (in_region==-1) {
+
+ if (!cri.end) {
+
+ in_region=cri.region;
+ }
+ } else if (in_region==cri.region && !color_regions[cri.region].line_only) { //ignore otherwise
+
+ if (cri.end || color_regions[cri.region].eq) {
+
+ in_region=-1;
+ }
+ }
+ }
+ }
+ }
+
+ int brace_open_match_line=-1;
+ int brace_open_match_column=-1;
+ bool brace_open_matching=false;
+ bool brace_open_mismatch=false;
+ int brace_close_match_line=-1;
+ int brace_close_match_column=-1;
+ bool brace_close_matching=false;
+ bool brace_close_mismatch=false;
+
+
+ if (brace_matching_enabled) {
+
+ if (cursor.column<text[cursor.line].length()) {
+ //check for open
+ CharType c = text[cursor.line][cursor.column];
+ CharType closec=0;
+
+ if (c=='[') {
+ closec=']';
+ } else if (c=='{') {
+ closec='}';
+ } else if (c=='(') {
+ closec=')';
+ }
+
+ if (closec!=0) {
+
+ int stack=1;
+
+
+ for(int i=cursor.line;i<text.size();i++) {
+
+ int from = i==cursor.line?cursor.column+1:0;
+ for(int j=from;j<text[i].length();j++) {
+
+ CharType cc = text[i][j];
+ if (cc==c)
+ stack++;
+ else if (cc==closec)
+ stack--;
+
+ if (stack==0) {
+ brace_open_match_line=i;
+ brace_open_match_column=j;
+ brace_open_matching=true;
+
+ break;
+ }
+ }
+ if (brace_open_match_line!=-1)
+ break;
+ }
+
+ if (!brace_open_matching)
+ brace_open_mismatch=true;
+
+
+ }
+ }
+
+ if (cursor.column>0) {
+ CharType c = text[cursor.line][cursor.column-1];
+ CharType closec=0;
+
+
+
+ if (c==']') {
+ closec='[';
+ } else if (c=='}') {
+ closec='{';
+ } else if (c==')') {
+ closec='(';
+ }
+
+ if (closec!=0) {
+
+ int stack=1;
+
+
+ for(int i=cursor.line;i>=0;i--) {
+
+ int from = i==cursor.line?cursor.column-2:text[i].length()-1;
+ for(int j=from;j>=0;j--) {
+
+ CharType cc = text[i][j];
+ if (cc==c)
+ stack++;
+ else if (cc==closec)
+ stack--;
+
+ if (stack==0) {
+ brace_close_match_line=i;
+ brace_close_match_column=j;
+ brace_close_matching=true;
+
+ break;
+ }
+ }
+ if (brace_close_match_line!=-1)
+ break;
+ }
+
+ if (!brace_close_matching)
+ brace_close_mismatch=true;
+
+
+ }
+
+
+ }
+ }
+
+
+ int deregion=0; //force it to clear inrgion
+ Point2 cursor_pos;
+
+ for (int i=0;i<visible_rows;i++) {
+
+ int line=i+cursor.line_ofs;
+
+ if (line<0 || line>=(int)text.size())
+ continue;
+
+ const String &str=text[line];
+
+ int char_margin=xmargin_beg-cursor.x_ofs;
+ int char_ofs=0;
+ int ofs_y=i*get_row_height()+cache.line_spacing/2;
+ bool prev_is_char=false;
+ bool in_keyword=false;
+ Color keyword_color;
+
+ if (cache.line_number_w) {
+ Color fcol = cache.font_color;
+ fcol.a*=0.4;
+ String fc = String::num(line+1);
+ while (fc.length() < line_number_char_count) {
+ fc="0"+fc;
+ }
+
+ cache.font->draw(ci,Point2(cache.style_normal->get_margin(MARGIN_LEFT),ofs_y+cache.font->get_ascent()),fc,fcol);
+ }
+
+ const Map<int,Text::ColorRegionInfo>& cri_map=text.get_color_region_info(line);
+
+
+ if (text.is_marked(line)) {
+
+ VisualServer::get_singleton()->canvas_item_add_rect(ci,Rect2(xmargin_beg, ofs_y,xmargin_end-xmargin_beg,get_row_height()),cache.mark_color);
+ }
+
+ if (text.is_breakpoint(line)) {
+
+ VisualServer::get_singleton()->canvas_item_add_rect(ci,Rect2(xmargin_beg, ofs_y,xmargin_end-xmargin_beg,get_row_height()),cache.breakpoint_color);
+ }
+
+
+ if (line==cursor.line) {
+
+ VisualServer::get_singleton()->canvas_item_add_rect(ci,Rect2(xmargin_beg, ofs_y,xmargin_end-xmargin_beg,get_row_height()),cache.current_line_color);
+
+ }
+ for (int j=0;j<str.length();j++) {
+
+ //look for keyword
+
+ if (deregion>0) {
+ deregion--;
+ if (deregion==0)
+ in_region=-1;
+ }
+ if (syntax_coloring && deregion==0) {
+
+
+ color = cache.font_color; //reset
+ //find keyword
+ bool is_char = _is_text_char(str[j]);
+ bool is_symbol=_is_symbol(str[j]);
+
+ if (j==0 && in_region>=0 && color_regions[in_region].line_only) {
+ in_region=-1; //reset regions that end at end of line
+ }
+
+ if (is_symbol && cri_map.has(j)) {
+
+
+ const Text::ColorRegionInfo &cri=cri_map[j];
+
+ if (in_region==-1) {
+
+ if (!cri.end) {
+
+ in_region=cri.region;
+ }
+ } else if (in_region==cri.region && !color_regions[cri.region].line_only) { //ignore otherwise
+
+ if (cri.end || color_regions[cri.region].eq) {
+
+ deregion=color_regions[cri.region].eq?color_regions[cri.region].begin_key.length():color_regions[cri.region].end_key.length();
+ }
+ }
+ }
+
+ if (!is_char)
+ in_keyword=false;
+
+ if (in_region==-1 && !in_keyword && is_char && !prev_is_char) {
+
+ int to=j;
+ while(_is_text_char(str[to]) && to<str.length())
+ to++;
+
+ uint32_t hash = String::hash(&str[j],to-j);
+ StrRange range(&str[j],to-j);
+
+ const Color *col=keywords.custom_getptr(range,hash);
+
+ if (col) {
+
+ in_keyword=true;
+ keyword_color=*col;
+ }
+ }
+
+
+ if (in_region>=0)
+ color=color_regions[in_region].color;
+ else if (in_keyword)
+ color=keyword_color;
+ else if (is_symbol)
+ color=symbol_color;
+
+ prev_is_char=is_char;
+
+ }
+ int char_w;
+
+ //handle tabulator
+
+
+ if (str[j]=='\t') {
+ int left = char_ofs%tab_w;
+ if (left==0)
+ char_w=tab_w;
+ else
+ char_w=tab_w-char_ofs%tab_w; // is right...
+
+ } else {
+ char_w=cache.font->get_char_size(str[j],str[j+1]).width;
+ }
+
+ if ( (char_ofs+char_margin)<xmargin_beg) {
+ char_ofs+=char_w;
+ continue;
+ }
+
+ if ( (char_ofs+char_margin+char_w)>=xmargin_end) {
+ if (syntax_coloring)
+ continue;
+ else
+ break;
+ }
+
+ bool in_selection = (selection.active && line>=selection.from_line && line<=selection.to_line && (line>selection.from_line || j>=selection.from_column) && (line<selection.to_line || j<selection.to_column));
+
+
+ if (in_selection) {
+ //inside selection!
+ VisualServer::get_singleton()->canvas_item_add_rect(ci,Rect2(Point2i( char_ofs+char_margin, ofs_y ), Size2i(char_w,get_row_height())),cache.selection_color);
+ }
+
+
+ if (brace_matching_enabled) {
+ if ( (brace_open_match_line==line && brace_open_match_column==j) ||
+ (cursor.column==j && cursor.line==line && (brace_open_matching||brace_open_mismatch))) {
+
+ if (brace_open_mismatch)
+ color=cache.brace_mismatch_color;
+ cache.font->draw_char(ci,Point2i( char_ofs+char_margin, ofs_y+ascent),'_',str[j+1],in_selection?cache.font_selected_color:color);
+
+ }
+
+ if (
+ (brace_close_match_line==line && brace_close_match_column==j) ||
+ (cursor.column==j+1 && cursor.line==line && (brace_close_matching||brace_close_mismatch))) {
+
+
+ if (brace_close_mismatch)
+ color=cache.brace_mismatch_color;
+ cache.font->draw_char(ci,Point2i( char_ofs+char_margin, ofs_y+ascent),'_',str[j+1],in_selection?cache.font_selected_color:color);
+
+ }
+ }
+
+
+ if (str[j]>=32)
+ cache.font->draw_char(ci,Point2i( char_ofs+char_margin, ofs_y+ascent),str[j],str[j+1],in_selection?cache.font_selected_color:color);
+
+ else if (draw_tabs && str[j]=='\t') {
+ int yofs= (get_row_height() - cache.tab_icon->get_height())/2;
+ cache.tab_icon->draw(ci, Point2(char_ofs+char_margin,ofs_y+yofs),in_selection?cache.font_selected_color:color);
+ }
+
+
+ if (cursor.column==j && cursor.line==line) {
+
+ cursor_pos = Point2i( char_ofs+char_margin, ofs_y );
+ VisualServer::get_singleton()->canvas_item_add_rect(ci,Rect2(cursor_pos, Size2i(1,get_row_height())),cache.font_color);
+
+
+ }
+ char_ofs+=char_w;
+
+ }
+
+ if (cursor.column==str.length() && cursor.line==line) {
+
+ cursor_pos=Point2i( char_ofs+char_margin, ofs_y );
+ VisualServer::get_singleton()->canvas_item_add_rect(ci,Rect2(cursor_pos, Size2i(1,get_row_height())),cache.font_color);
+
+ }
+ }
+
+
+ if (completion_active) {
+ // code completion box
+ Ref<StyleBox> csb = get_stylebox("completion");
+ Ref<StyleBox> csel = get_stylebox("completion_selected");
+ int maxlines = get_constant("completion_lines");
+ int cmax_width = get_constant("completion_max_width")*cache.font->get_char_size('x').x;
+ Color existing = get_color("completion_existing");
+ existing.a=0.2;
+ int scrollw = get_constant("completion_scroll_width");
+ Color scrollc = get_color("completion_scroll_color");
+
+
+
+ int lines = MIN(completion_options.size(),maxlines);
+ int w=0;
+ int h=lines*get_row_height();
+ int nofs = cache.font->get_string_size(completion_base).width;
+
+
+ if (completion_options.size() < 50) {
+ for(int i=0;i<completion_options.size();i++) {
+ int w2=MIN(cache.font->get_string_size(completion_options[i]).x,cmax_width);
+ if (w2>w)
+ w=w2;
+ }
+ } else {
+ w=cmax_width;
+ }
+
+ int th = h + csb->get_minimum_size().y;
+ if (cursor_pos.y+get_row_height()+th > get_size().height) {
+ completion_rect.pos.y=cursor_pos.y-th;
+ } else {
+ completion_rect.pos.y=cursor_pos.y+get_row_height()+csb->get_offset().y;
+
+ }
+
+ if (cursor_pos.x-nofs+w+scrollw > get_size().width) {
+ completion_rect.pos.x=get_size().width-w-scrollw;
+ } else {
+ completion_rect.pos.x=cursor_pos.x-nofs;
+ }
+
+ completion_rect.size.width=w+2;
+ completion_rect.size.height=h;
+ if (completion_options.size()<=maxlines)
+ scrollw=0;
+
+ draw_style_box(csb,Rect2(completion_rect.pos-csb->get_offset(),completion_rect.size+csb->get_minimum_size()+Size2(scrollw,0)));
+
+
+ int line_from = CLAMP(completion_index - lines/2, 0, completion_options.size() - lines);
+ draw_style_box(csel,Rect2(Point2(completion_rect.pos.x,completion_rect.pos.y+(completion_index-line_from)*get_row_height()),Size2(completion_rect.size.width,get_row_height())));
+
+ draw_rect(Rect2(completion_rect.pos,Size2(nofs,completion_rect.size.height)),existing);
+
+
+
+
+ for(int i=0;i<lines;i++) {
+
+ int l = line_from + i;
+ ERR_CONTINUE( l < 0 || l>= completion_options.size());
+ Color text_color = cache.font_color;
+ for(int j=0;j<color_regions.size();j++) {
+ if (completion_options[l].begins_with(color_regions[j].begin_key)) {
+ text_color=color_regions[j].color;
+ }
+ }
+ draw_string(cache.font,Point2(completion_rect.pos.x,completion_rect.pos.y+i*get_row_height()+cache.font->get_ascent()),completion_options[l],text_color,completion_rect.size.width);
+ }
+
+ if (scrollw) {
+ //draw a small scroll rectangle to show a position in the options
+ float r = maxlines / (float)completion_options.size();
+ float o = line_from / (float)completion_options.size();
+ draw_rect(Rect2(completion_rect.pos.x+completion_rect.size.width,completion_rect.pos.y+o*completion_rect.size.y,scrollw,completion_rect.size.y*r),scrollc);
+ }
+
+ completion_line_ofs=line_from;
+
+ }
+
+ if (completion_hint!="") {
+
+ Ref<StyleBox> sb = get_stylebox("panel","TooltipPanel");
+ Ref<Font> font = cache.font;
+ Color font_color = get_color("font_color","TooltipLabel");
+
+
+ int max_w=0;
+ int sc = completion_hint.get_slice_count("\n");
+ int offset=0;
+ int spacing=0;
+ for(int i=0;i<sc;i++) {
+
+ String l = completion_hint.get_slice("\n",i);
+ int len = font->get_string_size(l).x;
+ max_w = MAX(len,max_w);
+ if (i==0) {
+ offset = font->get_string_size(l.substr(0,l.find(String::chr(0xFFFF)))).x;
+ } else {
+ spacing+=cache.line_spacing;
+ }
+
+
+ }
+
+
+
+ Size2 size = Size2(max_w,sc*font->get_height()+spacing);
+ Size2 minsize = size+sb->get_minimum_size();
+
+
+ if (completion_hint_offset==-0xFFFF) {
+ completion_hint_offset=cursor_pos.x-offset;
+ }
+
+
+ Point2 hint_ofs = Vector2(completion_hint_offset,cursor_pos.y-minsize.y);
+ draw_style_box(sb,Rect2(hint_ofs,minsize));
+
+ spacing=0;
+ for(int i=0;i<sc;i++) {
+ int begin=0;
+ int end=0;
+ String l = completion_hint.get_slice("\n",i);
+
+ if (l.find(String::chr(0xFFFF))!=-1) {
+ begin = font->get_string_size(l.substr(0,l.find(String::chr(0xFFFF)))).x;
+ end = font->get_string_size(l.substr(0,l.rfind(String::chr(0xFFFF)))).x;
+ }
+
+ draw_string(font,hint_ofs+sb->get_offset()+Vector2(0,font->get_ascent()+font->get_height()*i+spacing),l.replace(String::chr(0xFFFF),""),font_color);
+ if (end>0) {
+ Vector2 b = hint_ofs+sb->get_offset()+Vector2(begin,font->get_height()+font->get_height()*i+spacing-1);
+ draw_line(b,b+Vector2(end-begin,0),font_color);
+ }
+ spacing+=cache.line_spacing;
+ }
+ }
+
+
+ } break;
+ case NOTIFICATION_FOCUS_ENTER: {
+
+ if (OS::get_singleton()->has_virtual_keyboard())
+ OS::get_singleton()->show_virtual_keyboard(get_text(),get_global_rect());
+
+ } break;
+ case NOTIFICATION_FOCUS_EXIT: {
+
+ if (OS::get_singleton()->has_virtual_keyboard())
+ OS::get_singleton()->hide_virtual_keyboard();
+
+ } break;
+
+ }
}
void TextEdit::_consume_pair_symbol(CharType ch) {
-
- int cursor_position_to_move = cursor_get_column() + 1;
-
- CharType ch_single[2] = {ch, 0};
- CharType ch_single_pair[2] = {_get_right_pair_symbol(ch), 0};
- CharType ch_pair[3] = {ch, _get_right_pair_symbol(ch), 0};
-
- if(is_selection_active()) {
-
- int new_column,new_line;
-
- _begin_compex_operation();
- _insert_text(get_selection_from_line(), get_selection_from_column(),
- ch_single,
- &new_line, &new_column);
-
- int to_col_offset = 0;
- if(get_selection_from_line() == get_selection_to_line())
- to_col_offset = 1;
-
- _insert_text(get_selection_to_line(),
- get_selection_to_column() + to_col_offset,
- ch_single_pair,
- &new_line,&new_column);
- _end_compex_operation();
-
- cursor_set_line(get_selection_to_line());
- cursor_set_column(get_selection_to_column() + to_col_offset);
-
- deselect();
- update();
- return;
- }
-
- if( (ch == '\'' || ch == '"') &&
- cursor_get_column() > 0 &&
- _is_text_char(text[cursor.line][cursor_get_column() - 1])
- ) {
- insert_text_at_cursor(ch_single);
- cursor_set_column(cursor_position_to_move);
- return;
- }
-
- if(cursor_get_column() < text[cursor.line].length()) {
- if(_is_text_char(text[cursor.line][cursor_get_column()])) {
- insert_text_at_cursor(ch_single);
- cursor_set_column(cursor_position_to_move);
- return;
- }
- if( _is_pair_right_symbol(ch) &&
- text[cursor.line][cursor_get_column()] == ch
- ) {
- cursor_set_column(cursor_position_to_move);
- return;
- }
- }
-
-
- insert_text_at_cursor(ch_pair);
- cursor_set_column(cursor_position_to_move);
- return;
-
+
+ int cursor_position_to_move = cursor_get_column() + 1;
+
+ CharType ch_single[2] = {ch, 0};
+ CharType ch_single_pair[2] = {_get_right_pair_symbol(ch), 0};
+ CharType ch_pair[3] = {ch, _get_right_pair_symbol(ch), 0};
+
+ if(is_selection_active()) {
+
+ int new_column,new_line;
+
+ _begin_compex_operation();
+ _insert_text(get_selection_from_line(), get_selection_from_column(),
+ ch_single,
+ &new_line, &new_column);
+
+ int to_col_offset = 0;
+ if(get_selection_from_line() == get_selection_to_line())
+ to_col_offset = 1;
+
+ _insert_text(get_selection_to_line(),
+ get_selection_to_column() + to_col_offset,
+ ch_single_pair,
+ &new_line,&new_column);
+ _end_compex_operation();
+
+ cursor_set_line(get_selection_to_line());
+ cursor_set_column(get_selection_to_column() + to_col_offset);
+
+ deselect();
+ update();
+ return;
+ }
+
+ if( (ch == '\'' || ch == '"') &&
+ cursor_get_column() > 0 &&
+ _is_text_char(text[cursor.line][cursor_get_column() - 1])
+ ) {
+ insert_text_at_cursor(ch_single);
+ cursor_set_column(cursor_position_to_move);
+ return;
+ }
+
+ if(cursor_get_column() < text[cursor.line].length()) {
+ if(_is_text_char(text[cursor.line][cursor_get_column()])) {
+ insert_text_at_cursor(ch_single);
+ cursor_set_column(cursor_position_to_move);
+ return;
+ }
+ if( _is_pair_right_symbol(ch) &&
+ text[cursor.line][cursor_get_column()] == ch
+ ) {
+ cursor_set_column(cursor_position_to_move);
+ return;
+ }
+ }
+
+
+ insert_text_at_cursor(ch_pair);
+ cursor_set_column(cursor_position_to_move);
+ return;
+
}
void TextEdit::_consume_backspace_for_pair_symbol(int prev_line, int prev_column) {
-
- bool remove_right_symbol = false;
-
- if(cursor.column < text[cursor.line].length() && cursor.column > 0) {
-
- CharType left_char = text[cursor.line][cursor.column - 1];
- CharType right_char = text[cursor.line][cursor.column];
-
- if(right_char == _get_right_pair_symbol(left_char)) {
- remove_right_symbol = true;
- }
-
- }
- if(remove_right_symbol) {
- _remove_text(prev_line,prev_column,cursor.line,cursor.column + 1);
- } else {
- _remove_text(prev_line,prev_column,cursor.line,cursor.column);
- }
-
+
+ bool remove_right_symbol = false;
+
+ if(cursor.column < text[cursor.line].length() && cursor.column > 0) {
+
+ CharType left_char = text[cursor.line][cursor.column - 1];
+ CharType right_char = text[cursor.line][cursor.column];
+
+ if(right_char == _get_right_pair_symbol(left_char)) {
+ remove_right_symbol = true;
+ }
+
+ }
+ if(remove_right_symbol) {
+ _remove_text(prev_line,prev_column,cursor.line,cursor.column + 1);
+ } else {
+ _remove_text(prev_line,prev_column,cursor.line,cursor.column);
+ }
+
}
void TextEdit::backspace_at_cursor() {
-
- if (cursor.column==0 && cursor.line==0)
- return;
-
- int prev_line = cursor.column?cursor.line:cursor.line-1;
- int prev_column = cursor.column?(cursor.column-1):(text[cursor.line-1].length());
- if(auto_brace_completion_enabled &&
- cursor.column > 0 &&
- _is_pair_left_symbol(text[cursor.line][cursor.column - 1])) {
- _consume_backspace_for_pair_symbol(prev_line, prev_column);
- } else {
- _remove_text(prev_line,prev_column,cursor.line,cursor.column);
- }
-
- cursor_set_line(prev_line);
- cursor_set_column(prev_column);
-
+ if (readonly)
+ return;
+
+ if (cursor.column==0 && cursor.line==0)
+ return;
+
+ int prev_line = cursor.column?cursor.line:cursor.line-1;
+ int prev_column = cursor.column?(cursor.column-1):(text[cursor.line-1].length());
+ if(auto_brace_completion_enabled &&
+ cursor.column > 0 &&
+ _is_pair_left_symbol(text[cursor.line][cursor.column - 1])) {
+ _consume_backspace_for_pair_symbol(prev_line, prev_column);
+ } else {
+ _remove_text(prev_line,prev_column,cursor.line,cursor.column);
+ }
+
+ cursor_set_line(prev_line);
+ cursor_set_column(prev_column);
+
}
bool TextEdit::_get_mouse_pos(const Point2i& p_mouse, int &r_row, int &r_col) const {
-
- int row=p_mouse.y;
- row-=cache.style_normal->get_margin(MARGIN_TOP);
- row/=get_row_height();
-
- if (row<0 || row>=get_visible_rows())
- return false;
-
- row+=cursor.line_ofs;
- int col=0;
-
- if (row>=text.size()) {
-
- row=text.size()-1;
- col=text[row].size();
- } else {
-
- col=p_mouse.x-(cache.style_normal->get_margin(MARGIN_LEFT)+cache.line_number_w);
- col+=cursor.x_ofs;
- col=get_char_pos_for( col, get_line(row) );
- }
-
- r_row=row;
- r_col=col;
- return true;
+
+ int row=p_mouse.y;
+ row-=cache.style_normal->get_margin(MARGIN_TOP);
+ row/=get_row_height();
+
+ if (row<0 || row>=get_visible_rows())
+ return false;
+
+ row+=cursor.line_ofs;
+ int col=0;
+
+ if (row>=text.size()) {
+
+ row=text.size()-1;
+ col=text[row].size();
+ } else {
+
+ col=p_mouse.x-(cache.style_normal->get_margin(MARGIN_LEFT)+cache.line_number_w);
+ col+=cursor.x_ofs;
+ col=get_char_pos_for( col, get_line(row) );
+ }
+
+ r_row=row;
+ r_col=col;
+ return true;
}
void TextEdit::_input_event(const InputEvent& p_input_event) {
-
- switch(p_input_event.type) {
-
- case InputEvent::MOUSE_BUTTON: {
-
- const InputEventMouseButton &mb=p_input_event.mouse_button;
-
- if (completion_active && completion_rect.has_point(Point2(mb.x,mb.y))) {
-
- if (!mb.pressed)
- return;
-
- if (mb.button_index==BUTTON_WHEEL_UP) {
- if (completion_index>0) {
- completion_index--;
- completion_current=completion_options[completion_index];
- update();
- }
-
- }
- if (mb.button_index==BUTTON_WHEEL_DOWN) {
-
- if (completion_index<completion_options.size()-1) {
- completion_index++;
- completion_current=completion_options[completion_index];
- update();
- }
- }
-
- if (mb.button_index==BUTTON_LEFT) {
-
- completion_index=CLAMP(completion_line_ofs+(mb.y-completion_rect.pos.y)/get_row_height(),0,completion_options.size()-1);
-
- completion_current=completion_options[completion_index];
- update();
- if (mb.doubleclick)
- _confirm_completion();
- }
- return;
- } else {
- _cancel_completion();
- }
-
- if (mb.pressed) {
- if (mb.button_index==BUTTON_WHEEL_UP) {
- v_scroll->set_val( v_scroll->get_val() -3 );
- }
- if (mb.button_index==BUTTON_WHEEL_DOWN) {
- v_scroll->set_val( v_scroll->get_val() +3 );
- }
- if (mb.button_index==BUTTON_LEFT) {
-
- int row,col;
- if (!_get_mouse_pos(Point2i(mb.x,mb.y), row,col))
- return;
-
- int prev_col=cursor.column;
- int prev_line=cursor.line;
-
-
-
- cursor_set_line( row );
- cursor_set_column( col );
-
- if (mb.mod.shift && (cursor.column!=prev_col || cursor.line!=prev_line)) {
-
- selection.active=true;
- selection.selecting_mode=Selection::MODE_POINTER;
- selection.from_column=prev_col;
- selection.from_line=prev_line;
- selection.to_column=cursor.column;
- selection.to_line=cursor.line;
- if (selection.from_column>selection.to_column) {
- SWAP(selection.from_column,selection.to_column);
- SWAP(selection.from_line,selection.to_line);
- }
- selection.selecting_line=prev_line;
- selection.selecting_column=prev_col;
- update();
-
- } else {
-
- //if sel active and dblick last time < something
-
- //else
- selection.active=false;
- selection.selecting_mode=Selection::MODE_POINTER;
- selection.selecting_line=row;
- selection.selecting_column=col;
- }
-
-
- if (!mb.doubleclick && (OS::get_singleton()->get_ticks_msec()-last_dblclk)<600) {
- //tripleclick select line
- select(cursor.line,0,cursor.line,text[cursor.line].length());
- last_dblclk=0;
-
- } else if (mb.doubleclick && text[cursor.line].length()) {
-
- //doubleclick select world
- String s = text[cursor.line];
- int beg=CLAMP(cursor.column,0,s.length());
- int end=beg;
-
- if (s[beg]>32 || beg==s.length()) {
-
- bool symbol = beg < s.length() && _is_symbol(s[beg]); //not sure if right but most editors behave like this
-
- while(beg>0 && s[beg-1]>32 && (symbol==_is_symbol(s[beg-1]))) {
- beg--;
- }
- while(end<s.length() && s[end+1]>32 && (symbol==_is_symbol(s[end+1]))) {
- end++;
- }
-
- if (end<s.length())
- end+=1;
-
- select(cursor.line,beg,cursor.line,end);
- }
-
- last_dblclk = OS::get_singleton()->get_ticks_msec();
-
- }
-
- update();
- }
- } else {
-
- selection.selecting_mode=Selection::MODE_NONE;
- // notify to show soft keyboard
- notification(NOTIFICATION_FOCUS_ENTER);
- }
-
- } break;
- case InputEvent::MOUSE_MOTION: {
-
- const InputEventMouseMotion &mm=p_input_event.mouse_motion;
-
- if (mm.button_mask&BUTTON_MASK_LEFT) {
-
- int row,col;
- if (!_get_mouse_pos(Point2i(mm.x,mm.y), row,col))
- return;
-
- if (selection.selecting_mode==Selection::MODE_POINTER) {
-
- select(selection.selecting_line,selection.selecting_column,row,col);
-
- cursor_set_line( row );
- cursor_set_column( col );
- update();
-
- }
-
- }
-
- } break;
-
- case InputEvent::KEY: {
-
- InputEventKey k=p_input_event.key;
-
- if (!k.pressed)
- return;
-
- if (completion_active) {
-
- bool valid=true;
- if (k.mod.command || k.mod.alt || k.mod.meta)
- valid=false;
-
- if (valid) {
-
- if (k.scancode==KEY_UP) {
-
- if (completion_index>0) {
- completion_index--;
- completion_current=completion_options[completion_index];
- update();
- }
- accept_event();
- return;
- }
-
-
- if (k.scancode==KEY_DOWN) {
-
- if (completion_index<completion_options.size()-1) {
- completion_index++;
- completion_current=completion_options[completion_index];
- update();
- }
- accept_event();
- return;
- }
-
- if (k.scancode==KEY_PAGEUP) {
-
- completion_index-=get_constant("completion_lines");
- if (completion_index<0)
- completion_index=0;
- completion_current=completion_options[completion_index];
- update();
- accept_event();
- return;
- }
-
-
- if (k.scancode==KEY_PAGEDOWN) {
-
- completion_index+=get_constant("completion_lines");
- if (completion_index>=completion_options.size())
- completion_index=completion_options.size()-1;
- completion_current=completion_options[completion_index];
- update();
- accept_event();
- return;
- }
-
- if (k.scancode==KEY_HOME) {
-
- completion_index=0;
- completion_current=completion_options[completion_index];
- update();
- accept_event();
- return;
- }
-
- if (k.scancode==KEY_END) {
-
- completion_index=completion_options.size()-1;
- completion_current=completion_options[completion_index];
- update();
- accept_event();
- return;
- }
-
-
- if (k.scancode==KEY_DOWN) {
-
- if (completion_index<completion_options.size()-1) {
- completion_index++;
- completion_current=completion_options[completion_index];
- update();
- }
- accept_event();
- return;
- }
-
- if (k.scancode==KEY_RETURN || k.scancode==KEY_TAB) {
-
- _confirm_completion();
- accept_event();
- return;
- }
-
- if (k.scancode==KEY_BACKSPACE) {
-
- backspace_at_cursor();
- _update_completion_candidates();
- accept_event();
- return;
- }
-
-
- if (k.scancode==KEY_SHIFT) {
- accept_event();
- return;
- }
-
- if (k.unicode>32) {
-
- if (cursor.column<text[cursor.line].length() && text[cursor.line][cursor.column]==k.unicode) {
- //same char, move ahead
- cursor_set_column(cursor.column+1);
-
- } else {
- //different char, go back
- const CharType chr[2] = {k.unicode, 0};
- if(auto_brace_completion_enabled && _is_pair_symbol(chr[0])) {
- _consume_pair_symbol(chr[0]);
- } else {
- _insert_text_at_cursor(chr);
- }
- }
-
- _update_completion_candidates();
- accept_event();
-
- return;
- }
- }
-
- _cancel_completion();
- }
-
- /* TEST CONTROL FIRST!! */
-
- // some remaps for duplicate functions..
- if (k.mod.command && !k.mod.shift && !k.mod.alt && !k.mod.meta && k.scancode==KEY_INSERT) {
-
- k.scancode=KEY_C;
- }
- if (!k.mod.command && k.mod.shift && !k.mod.alt && !k.mod.meta && k.scancode==KEY_INSERT) {
-
- k.scancode=KEY_V;
- k.mod.command=true;
- k.mod.shift=false;
- }
-
- // stuff to do when selection is active..
-
- if (selection.active) {
-
- bool clear=false;
- bool unselect=false;
- bool dobreak=false;
-
- switch(k.scancode) {
-
- case KEY_TAB: {
-
- String txt = _base_get_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column);
- String prev_txt=txt;
-
- if (k.mod.shift) {
-
- for(int i=0;i<txt.length();i++) {
- if (((i>0 && txt[i-1]=='\n') || (i==0 /*&& selection.from_column==0*/)) && (txt[i]=='\t' || txt[i]==' ')) {
- txt.remove(i);
- //i--;
- }
- }
- } else {
-
- for(int i=0;i<txt.length();i++) {
-
- if (((i>0 && txt[i-1]=='\n') || (i==0 /*&& selection.from_column==0*/))) {
- txt=txt.insert(i,"\t");
- //i--;
- }
- }
- }
-
- if (txt!=prev_txt) {
-
- int sel_line=selection.from_line;
- int sel_column=selection.from_column;
-
- cursor_set_line(selection.from_line);
- cursor_set_column(selection.from_column);
- _begin_compex_operation();
- _remove_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column);
- _insert_text_at_cursor(txt);
- _end_compex_operation();
- selection.active=true;
- selection.from_column=sel_column;
- selection.from_line=sel_line;
- selection.to_column=cursor.column;
- selection.to_line=cursor.line;
- update();
- }
-
- dobreak=true;
- accept_event();
-
- } break;
- case KEY_X:
- case KEY_C:
- //special keys often used with control, wait...
- clear=(!k.mod.command || k.mod.shift || k.mod.alt );
- break;
- case KEY_DELETE:
- case KEY_BACKSPACE:
- accept_event();
- clear=true; dobreak=true;
- break;
- case KEY_LEFT:
- case KEY_RIGHT:
- case KEY_UP:
- case KEY_DOWN:
- case KEY_PAGEUP:
- case KEY_PAGEDOWN:
- case KEY_HOME:
- case KEY_END:
- // ignore arrows if any modifiers are held (shift = selecting, others may be used for editor hotkeys)
- if (k.mod.command || k.mod.shift || k.mod.alt || k.mod.command)
- break;
- unselect=true;
- break;
- default:
- if (k.unicode>=32 && !k.mod.command && !k.mod.alt && !k.mod.meta)
- clear=true;
- if (auto_brace_completion_enabled && _is_pair_left_symbol(k.unicode))
- clear=false;
- }
-
- if (unselect) {
- selection.active=false;
- selection.selecting_mode=Selection::MODE_NONE;
- update();
- }
- if (clear) {
-
- selection.active=false;
- update();
- _remove_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column);
- cursor_set_line(selection.from_line);
- cursor_set_column(selection.from_column);
- update();
- }
- if (dobreak)
- break;
- }
-
- selection.selecting_test=false;
-
- bool scancode_handled=true;
-
- // special scancode test...
-
- switch (k.scancode) {
-
- case KEY_ENTER:
- case KEY_RETURN: {
-
- String ins="\n";
-
- //keep indentation
- for(int i=0;i<text[cursor.line].length();i++) {
- if (text[cursor.line][i]=='\t')
- ins+="\t";
- else
- break;
- }
-
- _insert_text_at_cursor(ins);
- _push_current_op();
-
- } break;
- case KEY_TAB: {
-
- if (readonly)
- break;
-
- if (selection.active) {
-
-
- } else {
- if (k.mod.shift) {
-
- int cc = cursor.column;
- if (cc>0 && cc<=text[cursor.line].length() && text[cursor.line][cursor.column-1]=='\t') {
- //simple unindent
-
- backspace_at_cursor();
- }
- } else {
- //simple indent
- _insert_text_at_cursor("\t");
- }
- }
-
- } break;
- case KEY_BACKSPACE: {
- if (readonly)
- break;
- backspace_at_cursor();
-
- } break;
- case KEY_LEFT: {
-
- if (k.mod.shift)
- _pre_shift_selection();
-
+
+ switch(p_input_event.type) {
+
+ case InputEvent::MOUSE_BUTTON: {
+
+ const InputEventMouseButton &mb=p_input_event.mouse_button;
+
+ if (completion_active && completion_rect.has_point(Point2(mb.x,mb.y))) {
+
+ if (!mb.pressed)
+ return;
+
+ if (mb.button_index==BUTTON_WHEEL_UP) {
+ if (completion_index>0) {
+ completion_index--;
+ completion_current=completion_options[completion_index];
+ update();
+ }
+
+ }
+ if (mb.button_index==BUTTON_WHEEL_DOWN) {
+
+ if (completion_index<completion_options.size()-1) {
+ completion_index++;
+ completion_current=completion_options[completion_index];
+ update();
+ }
+ }
+
+ if (mb.button_index==BUTTON_LEFT) {
+
+ completion_index=CLAMP(completion_line_ofs+(mb.y-completion_rect.pos.y)/get_row_height(),0,completion_options.size()-1);
+
+ completion_current=completion_options[completion_index];
+ update();
+ if (mb.doubleclick)
+ _confirm_completion();
+ }
+ return;
+ } else {
+ _cancel_completion();
+ _cancel_code_hint();
+ }
+
+ if (mb.pressed) {
+ if (mb.button_index==BUTTON_WHEEL_UP) {
+ v_scroll->set_val( v_scroll->get_val() -3 );
+ }
+ if (mb.button_index==BUTTON_WHEEL_DOWN) {
+ v_scroll->set_val( v_scroll->get_val() +3 );
+ }
+ if (mb.button_index==BUTTON_LEFT) {
+
+ int row,col;
+ if (!_get_mouse_pos(Point2i(mb.x,mb.y), row,col))
+ return;
+
+ int prev_col=cursor.column;
+ int prev_line=cursor.line;
+
+
+
+ cursor_set_line( row );
+ cursor_set_column( col );
+
+ if (mb.mod.shift && (cursor.column!=prev_col || cursor.line!=prev_line)) {
+
+ if (!selection.active) {
+ selection.active=true;
+ selection.selecting_mode=Selection::MODE_POINTER;
+ selection.from_column=prev_col;
+ selection.from_line=prev_line;
+ selection.to_column=cursor.column;
+ selection.to_line=cursor.line;
+
+ if (selection.from_line>selection.to_line || (selection.from_line==selection.to_line && selection.from_column>selection.to_column)) {
+ SWAP(selection.from_column,selection.to_column);
+ SWAP(selection.from_line,selection.to_line);
+ selection.shiftclick_left=false;
+ } else {
+ selection.shiftclick_left=true;
+ }
+ selection.selecting_line=prev_line;
+ selection.selecting_column=prev_col;
+ update();
+ } else {
+
+ if (cursor.line<selection.from_line || (cursor.line==selection.from_line && cursor.column<=selection.from_column)) {
+ selection.from_column=cursor.column;
+ selection.from_line=cursor.line;
+ } else if (cursor.line>selection.to_line || (cursor.line==selection.to_line && cursor.column>=selection.to_column)) {
+ selection.to_column=cursor.column;
+ selection.to_line=cursor.line;
+
+ } else if (!selection.shiftclick_left) {
+
+ selection.from_column=cursor.column;
+ selection.from_line=cursor.line;
+ } else {
+
+ selection.to_column=cursor.column;
+ selection.to_line=cursor.line;
+ }
+
+ if (selection.from_line>selection.to_line || (selection.from_line==selection.to_line && selection.from_column>selection.to_column)) {
+ SWAP(selection.from_column,selection.to_column);
+ SWAP(selection.from_line,selection.to_line);
+ }
+ update();
+ }
+
+
+
+
+
+
+
+ } else {
+
+ //if sel active and dblick last time < something
+
+ //else
+ selection.active=false;
+ selection.selecting_mode=Selection::MODE_POINTER;
+ selection.selecting_line=row;
+ selection.selecting_column=col;
+ }
+
+
+ if (!mb.doubleclick && (OS::get_singleton()->get_ticks_msec()-last_dblclk)<600) {
+ //tripleclick select line
+ select(cursor.line,0,cursor.line,text[cursor.line].length());
+ last_dblclk=0;
+
+ } else if (mb.doubleclick && text[cursor.line].length()) {
+
+ //doubleclick select world
+ String s = text[cursor.line];
+ int beg=CLAMP(cursor.column,0,s.length());
+ int end=beg;
+
+ if (s[beg]>32 || beg==s.length()) {
+
+ bool symbol = beg < s.length() && _is_symbol(s[beg]); //not sure if right but most editors behave like this
+
+ while(beg>0 && s[beg-1]>32 && (symbol==_is_symbol(s[beg-1]))) {
+ beg--;
+ }
+ while(end<s.length() && s[end+1]>32 && (symbol==_is_symbol(s[end+1]))) {
+ end++;
+ }
+
+ if (end<s.length())
+ end+=1;
+
+ select(cursor.line,beg,cursor.line,end);
+ }
+
+ last_dblclk = OS::get_singleton()->get_ticks_msec();
+
+ }
+
+ update();
+ }
+ } else {
+
+ selection.selecting_mode=Selection::MODE_NONE;
+ // notify to show soft keyboard
+ notification(NOTIFICATION_FOCUS_ENTER);
+ }
+
+ } break;
+ case InputEvent::MOUSE_MOTION: {
+
+ const InputEventMouseMotion &mm=p_input_event.mouse_motion;
+
+ if (mm.button_mask&BUTTON_MASK_LEFT) {
+
+ int row,col;
+ if (!_get_mouse_pos(Point2i(mm.x,mm.y), row,col))
+ return;
+
+ if (selection.selecting_mode==Selection::MODE_POINTER) {
+
+ select(selection.selecting_line,selection.selecting_column,row,col);
+
+ cursor_set_line( row );
+ cursor_set_column( col );
+ update();
+
+ }
+
+ }
+
+ } break;
+
+ case InputEvent::KEY: {
+
+ InputEventKey k=p_input_event.key;
+
+ if (!k.pressed)
+ return;
+
+ if (completion_active) {
+ if (readonly)
+ break;
+
+ bool valid=true;
+ if (k.mod.command || k.mod.meta)
+ valid=false;
+
+ if (valid) {
+
+ if (!k.mod.alt) {
+ if (k.scancode==KEY_UP) {
+
+ if (completion_index>0) {
+ completion_index--;
+ completion_current=completion_options[completion_index];
+ update();
+ }
+ accept_event();
+ return;
+ }
+
+
+ if (k.scancode==KEY_DOWN) {
+
+ if (completion_index<completion_options.size()-1) {
+ completion_index++;
+ completion_current=completion_options[completion_index];
+ update();
+ }
+ accept_event();
+ return;
+ }
+
+ if (k.scancode==KEY_PAGEUP) {
+
+ completion_index-=get_constant("completion_lines");
+ if (completion_index<0)
+ completion_index=0;
+ completion_current=completion_options[completion_index];
+ update();
+ accept_event();
+ return;
+ }
+
+
+ if (k.scancode==KEY_PAGEDOWN) {
+
+ completion_index+=get_constant("completion_lines");
+ if (completion_index>=completion_options.size())
+ completion_index=completion_options.size()-1;
+ completion_current=completion_options[completion_index];
+ update();
+ accept_event();
+ return;
+ }
+
+ if (k.scancode==KEY_HOME) {
+
+ completion_index=0;
+ completion_current=completion_options[completion_index];
+ update();
+ accept_event();
+ return;
+ }
+
+ if (k.scancode==KEY_END) {
+
+ completion_index=completion_options.size()-1;
+ completion_current=completion_options[completion_index];
+ update();
+ accept_event();
+ return;
+ }
+
+
+ if (k.scancode==KEY_DOWN) {
+
+ if (completion_index<completion_options.size()-1) {
+ completion_index++;
+ completion_current=completion_options[completion_index];
+ update();
+ }
+ accept_event();
+ return;
+ }
+
+ if (k.scancode==KEY_RETURN || k.scancode==KEY_TAB) {
+
+ _confirm_completion();
+ accept_event();
+ return;
+ }
+
+ if (k.scancode==KEY_BACKSPACE) {
+
+ backspace_at_cursor();
+ _update_completion_candidates();
+ accept_event();
+ return;
+ }
+
+
+ if (k.scancode==KEY_SHIFT) {
+ accept_event();
+ return;
+ }
+ }
+
+ if (k.unicode>32) {
+
+ if (cursor.column<text[cursor.line].length() && text[cursor.line][cursor.column]==k.unicode) {
+ //same char, move ahead
+ cursor_set_column(cursor.column+1);
+
+ } else {
+ //different char, go back
+ const CharType chr[2] = {k.unicode, 0};
+ if(auto_brace_completion_enabled && _is_pair_symbol(chr[0])) {
+ _consume_pair_symbol(chr[0]);
+ } else {
+ _insert_text_at_cursor(chr);
+ }
+ }
+
+ _update_completion_candidates();
+ accept_event();
+
+ return;
+ }
+ }
+
+ _cancel_completion();
+
+ }
+
+ /* TEST CONTROL FIRST!! */
+
+ // some remaps for duplicate functions..
+ if (k.mod.command && !k.mod.shift && !k.mod.alt && !k.mod.meta && k.scancode==KEY_INSERT) {
+
+ k.scancode=KEY_C;
+ }
+ if (!k.mod.command && k.mod.shift && !k.mod.alt && !k.mod.meta && k.scancode==KEY_INSERT) {
+
+ k.scancode=KEY_V;
+ k.mod.command=true;
+ k.mod.shift=false;
+ }
+
+ // stuff to do when selection is active..
+
+ if (selection.active) {
+
+ if (readonly)
+ break;
+
+ bool clear=false;
+ bool unselect=false;
+ bool dobreak=false;
+
+ switch(k.scancode) {
+
+ case KEY_TAB: {
+
+ String txt = _base_get_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column);
+ String prev_txt=txt;
+
+ if (k.mod.shift) {
+
+ for(int i=0;i<txt.length();i++) {
+ if (((i>0 && txt[i-1]=='\n') || (i==0 /*&& selection.from_column==0*/)) && (txt[i]=='\t' || txt[i]==' ')) {
+ txt.remove(i);
+ //i--;
+ }
+ }
+ } else {
+
+ for(int i=0;i<txt.length();i++) {
+
+ if (((i>0 && txt[i-1]=='\n') || (i==0 /*&& selection.from_column==0*/))) {
+ txt=txt.insert(i,"\t");
+ //i--;
+ }
+ }
+ }
+
+ if (txt!=prev_txt) {
+
+ int sel_line=selection.from_line;
+ int sel_column=selection.from_column;
+
+ cursor_set_line(selection.from_line);
+ cursor_set_column(selection.from_column);
+ _begin_compex_operation();
+ _remove_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column);
+ _insert_text_at_cursor(txt);
+ _end_compex_operation();
+ selection.active=true;
+ selection.from_column=sel_column;
+ selection.from_line=sel_line;
+ selection.to_column=cursor.column;
+ selection.to_line=cursor.line;
+ update();
+ }
+
+ dobreak=true;
+ accept_event();
+
+ } break;
+ case KEY_X:
+ case KEY_C:
+ //special keys often used with control, wait...
+ clear=(!k.mod.command || k.mod.shift || k.mod.alt );
+ break;
+ case KEY_DELETE:
+ case KEY_BACKSPACE:
+ accept_event();
+ clear=true; dobreak=true;
+ break;
+ case KEY_LEFT:
+ case KEY_RIGHT:
+ case KEY_UP:
+ case KEY_DOWN:
+ case KEY_PAGEUP:
+ case KEY_PAGEDOWN:
+ case KEY_HOME:
+ case KEY_END:
+ // ignore arrows if any modifiers are held (shift = selecting, others may be used for editor hotkeys)
+ if (k.mod.command || k.mod.shift || k.mod.alt || k.mod.command)
+ break;
+ unselect=true;
+ break;
+
+ default:
+ if (k.unicode>=32 && !k.mod.command && !k.mod.alt && !k.mod.meta)
+ clear=true;
+ if (auto_brace_completion_enabled && _is_pair_left_symbol(k.unicode))
+ clear=false;
+ }
+
+ if (unselect) {
+ selection.active=false;
+ selection.selecting_mode=Selection::MODE_NONE;
+ update();
+ }
+ if (clear) {
+
+ selection.active=false;
+ update();
+ _remove_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column);
+ cursor_set_line(selection.from_line);
+ cursor_set_column(selection.from_column);
+ update();
+ }
+ if (dobreak)
+ break;
+ }
+
+ selection.selecting_test=false;
+
+ bool scancode_handled=true;
+
+ // special scancode test...
+
+ switch (k.scancode) {
+
+ case KEY_ENTER:
+ case KEY_RETURN: {
+
+ if (readonly)
+ break;
+
+ String ins="\n";
+
+ //keep indentation
+ for(int i=0;i<text[cursor.line].length();i++) {
+ if (text[cursor.line][i]=='\t')
+ ins+="\t";
+ else
+ break;
+ }
+
+ _insert_text_at_cursor(ins);
+ _push_current_op();
+
+ } break;
+ case KEY_ESCAPE: {
+ if (completion_hint!="") {
+ completion_hint="";
+ update();
+
+ }
+ } break;
+ case KEY_TAB: {
+
+ if (readonly)
+ break;
+
+ if (selection.active) {
+
+
+ } else {
+ if (k.mod.shift) {
+
+ int cc = cursor.column;
+ if (cc>0 && cc<=text[cursor.line].length() && text[cursor.line][cursor.column-1]=='\t') {
+ //simple unindent
+
+ backspace_at_cursor();
+ }
+ } else {
+ //simple indent
+ _insert_text_at_cursor("\t");
+ }
+ }
+
+ } break;
+ case KEY_BACKSPACE: {
+ if (readonly)
+ break;
+ backspace_at_cursor();
+
+ } break;
+ case KEY_LEFT: {
+
+ if (k.mod.shift)
+ _pre_shift_selection();
+
#ifdef APPLE_STYLE_KEYS
- if (k.mod.command) {
- cursor_set_column(0);
- } else if (k.mod.alt) {
-
+ if (k.mod.command) {
+ cursor_set_column(0);
+ } else if (k.mod.alt) {
+
#else
- if (k.mod.alt) {
- scancode_handled=false;
- break;
- } else if (k.mod.command) {
+ if (k.mod.alt) {
+ scancode_handled=false;
+ break;
+ } else if (k.mod.command) {
#endif
- bool prev_char=false;
- int cc=cursor.column;
- while (cc>0) {
-
- bool ischar=_is_text_char(text[cursor.line][cc-1]);
-
- if (prev_char && !ischar)
- break;
-
- prev_char=ischar;
- cc--;
-
- }
-
- cursor_set_column(cc);
-
- } else if (cursor.column==0) {
-
- if (cursor.line>0) {
- cursor_set_line(cursor.line-1);
- cursor_set_column(text[cursor.line].length());
- }
- } else {
- cursor_set_column(cursor_get_column()-1);
- }
-
- if (k.mod.shift)
- _post_shift_selection();
-
- } break;
- case KEY_RIGHT: {
-
- if (k.mod.shift)
- _pre_shift_selection();
-
+ bool prev_char=false;
+ int cc=cursor.column;
+ while (cc>0) {
+
+ bool ischar=_is_text_char(text[cursor.line][cc-1]);
+
+ if (prev_char && !ischar)
+ break;
+
+ prev_char=ischar;
+ cc--;
+
+ }
+
+ cursor_set_column(cc);
+
+ } else if (cursor.column==0) {
+
+ if (cursor.line>0) {
+ cursor_set_line(cursor.line-1);
+ cursor_set_column(text[cursor.line].length());
+ }
+ } else {
+ cursor_set_column(cursor_get_column()-1);
+ }
+
+ if (k.mod.shift)
+ _post_shift_selection();
+
+ } break;
+ case KEY_RIGHT: {
+
+ if (k.mod.shift)
+ _pre_shift_selection();
+
#ifdef APPLE_STYLE_KEYS
- if (k.mod.command) {
- cursor_set_column(text[cursor.line].length());
- } else if (k.mod.alt) {
+ if (k.mod.command) {
+ cursor_set_column(text[cursor.line].length());
+ } else if (k.mod.alt) {
#else
- if (k.mod.alt) {
- scancode_handled=false;
- break;
- } else if (k.mod.command) {
+ if (k.mod.alt) {
+ scancode_handled=false;
+ break;
+ } else if (k.mod.command) {
#endif
- bool prev_char=false;
- int cc=cursor.column;
- while (cc<text[cursor.line].length()) {
-
- bool ischar=_is_text_char(text[cursor.line][cc]);
-
- if (prev_char && !ischar)
- break;
- prev_char=ischar;
- cc++;
- }
-
- cursor_set_column(cc);
-
- } else if (cursor.column==text[cursor.line].length()) {
-
- if (cursor.line<text.size()-1) {
- cursor_set_line(cursor.line+1);
- cursor_set_column(0);
- }
- } else {
- cursor_set_column(cursor_get_column()+1);
- }
-
- if (k.mod.shift)
- _post_shift_selection();
-
- } break;
- case KEY_UP: {
-
- if (k.mod.shift)
- _pre_shift_selection();
- if (k.mod.alt) {
- scancode_handled=false;
- break;
- }
+ bool prev_char=false;
+ int cc=cursor.column;
+ while (cc<text[cursor.line].length()) {
+
+ bool ischar=_is_text_char(text[cursor.line][cc]);
+
+ if (prev_char && !ischar)
+ break;
+ prev_char=ischar;
+ cc++;
+ }
+
+ cursor_set_column(cc);
+
+ } else if (cursor.column==text[cursor.line].length()) {
+
+ if (cursor.line<text.size()-1) {
+ cursor_set_line(cursor.line+1);
+ cursor_set_column(0);
+ }
+ } else {
+ cursor_set_column(cursor_get_column()+1);
+ }
+
+ if (k.mod.shift)
+ _post_shift_selection();
+
+ } break;
+ case KEY_UP: {
+
+ if (k.mod.shift)
+ _pre_shift_selection();
+ if (k.mod.alt) {
+ scancode_handled=false;
+ break;
+ }
#ifdef APPLE_STYLE_KEYS
- if (k.mod.command)
- cursor_set_line(0);
- else
+ if (k.mod.command)
+ cursor_set_line(0);
+ else
#endif
- cursor_set_line(cursor_get_line()-1);
-
- if (k.mod.shift)
- _post_shift_selection();
-
- } break;
- case KEY_DOWN: {
-
- if (k.mod.shift)
- _pre_shift_selection();
- if (k.mod.alt) {
- scancode_handled=false;
- break;
- }
+ cursor_set_line(cursor_get_line()-1);
+
+ if (k.mod.shift)
+ _post_shift_selection();
+ _cancel_code_hint();
+
+ } break;
+ case KEY_DOWN: {
+
+ if (k.mod.shift)
+ _pre_shift_selection();
+ if (k.mod.alt) {
+ scancode_handled=false;
+ break;
+ }
#ifdef APPLE_STYLE_KEYS
- if (k.mod.command)
- cursor_set_line(text.size()-1);
- else
+ if (k.mod.command)
+ cursor_set_line(text.size()-1);
+ else
#endif
- cursor_set_line(cursor_get_line()+1);
-
- if (k.mod.shift)
- _post_shift_selection();
-
- } break;
-
- case KEY_DELETE: {
-
- if (readonly)
- break;
- int curline_len = text[cursor.line].length();
-
- if (cursor.line==text.size()-1 && cursor.column==curline_len)
- break; //nothing to do
-
- int next_line = cursor.column<curline_len?cursor.line:cursor.line+1;
- int next_column = cursor.column<curline_len?(cursor.column+1):0;
- _remove_text(cursor.line,cursor.column,next_line,next_column);
- update();
- } break;
+ cursor_set_line(cursor_get_line()+1);
+
+ if (k.mod.shift)
+ _post_shift_selection();
+ _cancel_code_hint();
+
+ } break;
+
+ case KEY_DELETE: {
+
+ if (readonly)
+ break;
+ int curline_len = text[cursor.line].length();
+
+ if (cursor.line==text.size()-1 && cursor.column==curline_len)
+ break; //nothing to do
+
+ int next_line = cursor.column<curline_len?cursor.line:cursor.line+1;
+ int next_column = cursor.column<curline_len?(cursor.column+1):0;
+ _remove_text(cursor.line,cursor.column,next_line,next_column);
+ update();
+ } break;
#ifdef APPLE_STYLE_KEYS
- case KEY_HOME: {
-
-
- if (k.mod.shift)
- _pre_shift_selection();
-
- cursor_set_line(0);
-
- if (k.mod.shift)
- _post_shift_selection();
-
- } break;
- case KEY_END: {
-
- if (k.mod.shift)
- _pre_shift_selection();
-
- cursor_set_line(text.size()-1);
-
- if (k.mod.shift)
- _post_shift_selection();
-
- } break;
-
+ case KEY_HOME: {
+
+
+ if (k.mod.shift)
+ _pre_shift_selection();
+
+ cursor_set_line(0);
+
+ if (k.mod.shift)
+ _post_shift_selection();
+
+ } break;
+ case KEY_END: {
+
+ if (k.mod.shift)
+ _pre_shift_selection();
+
+ cursor_set_line(text.size()-1);
+
+ if (k.mod.shift)
+ _post_shift_selection();
+
+ } break;
+
#else
- case KEY_HOME: {
-
-
- if (k.mod.shift)
- _pre_shift_selection();
-
- // compute whitespace symbols seq length
- int current_line_whitespace_len = 0;
- while(current_line_whitespace_len < text[cursor.line].length()) {
- CharType c = text[cursor.line][current_line_whitespace_len];
- if(c != '\t' && c != ' ')
- break;
- current_line_whitespace_len++;
- }
-
- if(cursor_get_column() == current_line_whitespace_len)
- cursor_set_column(0);
- else
- cursor_set_column(current_line_whitespace_len);
-
- if (k.mod.command)
- cursor_set_line(0);
-
- if (k.mod.shift)
- _post_shift_selection();
-
- } break;
- case KEY_END: {
-
- if (k.mod.shift)
- _pre_shift_selection();
-
- if (k.mod.command)
- cursor_set_line(text.size()-1);
- cursor_set_column(text[cursor.line].length());
-
- if (k.mod.shift)
- _post_shift_selection();
-
- } break;
+ case KEY_HOME: {
+
+
+ if (k.mod.shift)
+ _pre_shift_selection();
+
+ // compute whitespace symbols seq length
+ int current_line_whitespace_len = 0;
+ while(current_line_whitespace_len < text[cursor.line].length()) {
+ CharType c = text[cursor.line][current_line_whitespace_len];
+ if(c != '\t' && c != ' ')
+ break;
+ current_line_whitespace_len++;
+ }
+
+ if(cursor_get_column() == current_line_whitespace_len)
+ cursor_set_column(0);
+ else
+ cursor_set_column(current_line_whitespace_len);
+
+ if (k.mod.command)
+ cursor_set_line(0);
+
+ if (k.mod.shift)
+ _post_shift_selection();
+
+ } break;
+ case KEY_END: {
+
+ if (k.mod.shift)
+ _pre_shift_selection();
+
+ if (k.mod.command)
+ cursor_set_line(text.size()-1);
+ cursor_set_column(text[cursor.line].length());
+
+ if (k.mod.shift)
+ _post_shift_selection();
+
+ } break;
#endif
- case KEY_PAGEUP: {
-
- if (k.mod.shift)
- _pre_shift_selection();
-
- cursor_set_line(cursor_get_line()-get_visible_rows());
-
- if (k.mod.shift)
- _post_shift_selection();
-
- } break;
- case KEY_PAGEDOWN: {
-
- if (k.mod.shift)
- _pre_shift_selection();
-
- cursor_set_line(cursor_get_line()+get_visible_rows());
-
- if (k.mod.shift)
- _post_shift_selection();
-
- } break;
- case KEY_A: {
-
- if (!k.mod.command || k.mod.shift || k.mod.alt) {
- scancode_handled=false;
- break;
- }
-
- if (text.size()==1 && text[0].length()==0)
- break;
- selection.active=true;
- selection.from_line=0;
- selection.from_column=0;
- selection.to_line=text.size()-1;
- selection.to_column=text[selection.to_line].size();
- selection.selecting_mode=Selection::MODE_NONE;
- update();
-
- } break;
- case KEY_X: {
-
- if (!k.mod.command || k.mod.shift || k.mod.alt) {
- scancode_handled=false;
- break;
- }
-
- if (!selection.active){
-
- String clipboard = text[cursor.line];
- OS::get_singleton()->set_clipboard(clipboard);
- cursor_set_line(cursor.line);
- cursor_set_column(0);
- _remove_text(cursor.line,0,cursor.line,text[cursor.line].length());
-
- backspace_at_cursor();
- update();
- cursor_set_line(cursor.line+1);
- cut_copy_line = true;
-
- }
- else
- {
-
- String clipboard = _base_get_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column);
- OS::get_singleton()->set_clipboard(clipboard);
-
- cursor_set_line(selection.from_line);
- cursor_set_column(selection.from_column);
-
- _remove_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column);
- selection.active=false;
- selection.selecting_mode=Selection::MODE_NONE;
- update();
- cut_copy_line = false;
- }
-
- } break;
- case KEY_C: {
-
- if (!k.mod.command || k.mod.shift || k.mod.alt) {
- scancode_handled=false;
- break;
- }
-
- if (!selection.active){
- String clipboard = _base_get_text(cursor.line,0,cursor.line,text[cursor.line].length());
- OS::get_singleton()->set_clipboard(clipboard);
- cut_copy_line = true;
- }
- else{
- String clipboard = _base_get_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column);
- OS::get_singleton()->set_clipboard(clipboard);
- cut_copy_line = false;
- }
- } break;
- case KEY_Z: {
-
- if (!k.mod.command) {
- scancode_handled=false;
- break;
- }
-
- if (k.mod.shift)
- redo();
- else
- undo();
- } break;
- case KEY_V: {
-
- if (!k.mod.command || k.mod.shift || k.mod.alt) {
- scancode_handled=false;
- break;
- }
-
- String clipboard = OS::get_singleton()->get_clipboard();
-
- if (selection.active) {
- selection.active=false;
- _remove_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column);
- cursor_set_line(selection.from_line);
- cursor_set_column(selection.from_column);
-
- }
- else if (cut_copy_line)
- {
- cursor_set_column(0);
- String ins="\n";
- clipboard += ins;
- }
-
- _insert_text_at_cursor(clipboard);
-
- update();
- } break;
- case KEY_SPACE: {
- if (completion_enabled && k.mod.command) {
-
- query_code_comple();
- scancode_handled=true;
- } else {
- scancode_handled=false;
- }
-
- } break;
-
- case KEY_K:{
- if (!k.mod.command || k.mod.shift || k.mod.alt) {
- scancode_handled=false;
- break;
- }
- else {
- if (selection.active) {
- int ini = selection.from_line;
- int end = selection.to_line;
- for (int i=ini; i<= end; i++)
- {
- _insert_text(i,0,"#");
- }
- }
- else{
- _insert_text(cursor.line,0,"#");
- }
- update();
- }
- break;}
-
- case KEY_U:{
- if (!k.mod.command || k.mod.shift || k.mod.alt) {
- scancode_handled=false;
- break;
- }
- else {
- if (selection.active) {
- int ini = selection.from_line;
- int end = selection.to_line;
- for (int i=ini; i<= end; i++)
- {
- if (text[i][0] == '#')
- _remove_text(i,0,i,1);
- }
- }
- else{
- if (text[cursor.line][0] == '#')
- _remove_text(cursor.line,0,cursor.line,1);
- }
- update();
- }
- break;}
-
- default: {
-
- scancode_handled=false;
- } break;
-
- }
-
- if (scancode_handled)
- accept_event();
-/*
- if (!scancode_handled && !k.mod.command && !k.mod.alt) {
-
- if (k.unicode>=32) {
-
- if (readonly)
- break;
-
- accept_event();
- } else {
-
- break;
- }
- }
+ case KEY_PAGEUP: {
+
+ if (k.mod.shift)
+ _pre_shift_selection();
+
+ cursor_set_line(cursor_get_line()-get_visible_rows());
+
+ if (k.mod.shift)
+ _post_shift_selection();
+
+ } break;
+ case KEY_PAGEDOWN: {
+
+ if (k.mod.shift)
+ _pre_shift_selection();
+
+ cursor_set_line(cursor_get_line()+get_visible_rows());
+
+ if (k.mod.shift)
+ _post_shift_selection();
+
+ } break;
+ case KEY_A: {
+
+ if (!k.mod.command || k.mod.shift || k.mod.alt) {
+ scancode_handled=false;
+ break;
+ }
+
+ if (text.size()==1 && text[0].length()==0)
+ break;
+ selection.active=true;
+ selection.from_line=0;
+ selection.from_column=0;
+ selection.to_line=text.size()-1;
+ selection.to_column=text[selection.to_line].size();
+ selection.selecting_mode=Selection::MODE_NONE;
+ update();
+
+ } break;
+ case KEY_X: {
+
+ if (!k.mod.command || k.mod.shift || k.mod.alt) {
+ scancode_handled=false;
+ break;
+ }
+
+ if (!selection.active){
+
+ String clipboard = text[cursor.line];
+ OS::get_singleton()->set_clipboard(clipboard);
+ cursor_set_line(cursor.line);
+ cursor_set_column(0);
+ _remove_text(cursor.line,0,cursor.line,text[cursor.line].length());
+
+ backspace_at_cursor();
+ update();
+ cursor_set_line(cursor.line+1);
+ cut_copy_line = true;
+
+ }
+ else
+ {
+
+ String clipboard = _base_get_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column);
+ OS::get_singleton()->set_clipboard(clipboard);
+
+ cursor_set_line(selection.from_line);
+ cursor_set_column(selection.from_column);
+
+ _remove_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column);
+ selection.active=false;
+ selection.selecting_mode=Selection::MODE_NONE;
+ update();
+ cut_copy_line = false;
+ }
+
+ } break;
+ case KEY_C: {
+
+ if (!k.mod.command || k.mod.shift || k.mod.alt) {
+ scancode_handled=false;
+ break;
+ }
+
+ if (!selection.active){
+ String clipboard = _base_get_text(cursor.line,0,cursor.line,text[cursor.line].length());
+ OS::get_singleton()->set_clipboard(clipboard);
+ cut_copy_line = true;
+ }
+ else{
+ String clipboard = _base_get_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column);
+ OS::get_singleton()->set_clipboard(clipboard);
+ cut_copy_line = false;
+ }
+ } break;
+ case KEY_Z: {
+
+ if (!k.mod.command) {
+ scancode_handled=false;
+ break;
+ }
+
+ if (k.mod.shift)
+ redo();
+ else
+ undo();
+ } break;
+ case KEY_V: {
+
+ if (!k.mod.command || k.mod.shift || k.mod.alt) {
+ scancode_handled=false;
+ break;
+ }
+
+ String clipboard = OS::get_singleton()->get_clipboard();
+
+ if (selection.active) {
+ selection.active=false;
+ _remove_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column);
+ cursor_set_line(selection.from_line);
+ cursor_set_column(selection.from_column);
+
+ }
+ else if (cut_copy_line)
+ {
+ cursor_set_column(0);
+ String ins="\n";
+ clipboard += ins;
+ }
+
+ _insert_text_at_cursor(clipboard);
+
+ update();
+ } break;
+ case KEY_SPACE: {
+#ifdef OSX_ENABLED
+ if (completion_enabled && k.mod.meta) { //cmd-space is spotlight shortcut in OSX
+#else
+ if (completion_enabled && k.mod.command) {
+#endif
+
+ query_code_comple();
+ scancode_handled=true;
+ } else {
+ scancode_handled=false;
+ }
+
+ } break;
+
+ case KEY_U:{
+ if (!k.mod.command || k.mod.shift) {
+ scancode_handled=false;
+ break;
+ }
+ else {
+ if (selection.active) {
+ int ini = selection.from_line;
+ int end = selection.to_line;
+ for (int i=ini; i<= end; i++)
+ {
+ if (text[i][0] == '#')
+ _remove_text(i,0,i,1);
+ }
+ }
+ else{
+ if (text[cursor.line][0] == '#')
+ _remove_text(cursor.line,0,cursor.line,1);
+ }
+ update();
+ }
+ break;}
+
+ default: {
+
+ scancode_handled=false;
+ } break;
+
+ }
+
+ if (scancode_handled)
+ accept_event();
+ /*
+ if (!scancode_handled && !k.mod.command && !k.mod.alt) {
+
+ if (k.unicode>=32) {
+
+ if (readonly)
+ break;
+
+ accept_event();
+ } else {
+
+ break;
+ }
+ }
*/
- if (!scancode_handled && !k.mod.command && !k.mod.alt) { //for german kbds
-
- if (k.unicode>=32) {
-
- if (readonly)
- break;
-
- const CharType chr[2] = {k.unicode, 0};
-
- if(auto_brace_completion_enabled && _is_pair_symbol(chr[0])) {
- _consume_pair_symbol(chr[0]);
- } else {
- _insert_text_at_cursor(chr);
- }
-
- accept_event();
- } else {
-
- break;
- }
- }
-
-
- if (!selection.selecting_test) {
-
- selection.selecting_mode=Selection::MODE_NONE;
- }
-
- return;
- } break;
-
- }
-
+ if (!scancode_handled && !k.mod.command) { //for german kbds
+
+ if (k.unicode>=32) {
+
+ if (readonly)
+ break;
+
+ const CharType chr[2] = {k.unicode, 0};
+
+ if(auto_brace_completion_enabled && _is_pair_symbol(chr[0])) {
+ _consume_pair_symbol(chr[0]);
+ } else {
+ _insert_text_at_cursor(chr);
+ }
+
+ accept_event();
+ } else {
+
+ break;
+ }
+ }
+
+
+ if (!selection.selecting_test) {
+
+ selection.selecting_mode=Selection::MODE_NONE;
+ }
+
+ return;
+ } break;
+
+ }
+
}
void TextEdit::_pre_shift_selection() {
-
-
- if (!selection.active || selection.selecting_mode!=Selection::MODE_SHIFT) {
-
- selection.selecting_line=cursor.line;
- selection.selecting_column=cursor.column;
- selection.active=true;
- selection.selecting_mode=Selection::MODE_SHIFT;
- }
+
+
+ if (!selection.active || selection.selecting_mode!=Selection::MODE_SHIFT) {
+
+ selection.selecting_line=cursor.line;
+ selection.selecting_column=cursor.column;
+ selection.active=true;
+ selection.selecting_mode=Selection::MODE_SHIFT;
+ }
}
void TextEdit::_post_shift_selection() {
-
-
- if (selection.active && selection.selecting_mode==Selection::MODE_SHIFT) {
-
- select(selection.selecting_line,selection.selecting_column,cursor.line,cursor.column);
- update();
- }
-
-
- selection.selecting_test=true;
+
+
+ if (selection.active && selection.selecting_mode==Selection::MODE_SHIFT) {
+
+ select(selection.selecting_line,selection.selecting_column,cursor.line,cursor.column);
+ update();
+ }
+
+
+ selection.selecting_test=true;
}
/**** TEXT EDIT CORE API ****/
void TextEdit::_base_insert_text(int p_line, int p_char,const String& p_text,int &r_end_line,int &r_end_column) {
-
- //save for undo...
- ERR_FAIL_INDEX(p_line,text.size());
- ERR_FAIL_COND(p_char<0);
-
- /* STEP 1 add spaces if the char is greater than the end of the line */
- while(p_char>text[p_line].length()) {
-
- text.set(p_line,text[p_line]+String::chr(' '));
- }
-
- /* STEP 2 separate dest string in pre and post text */
-
- String preinsert_text = text[p_line].substr(0,p_char);
- String postinsert_text = text[p_line].substr(p_char,text[p_line].size());
-
- /* STEP 3 remove \r from source text and separate in substrings */
-
- //buh bye \r and split
- Vector<String> substrings = p_text.replace("\r","").split("\n");
-
-
- for(int i=0;i<substrings.size();i++) {
- //insert the substrings
-
- if (i==0) {
-
- text.set(p_line,preinsert_text+substrings[i]);
- } else {
-
- text.insert(p_line+i,substrings[i]);
- }
-
- if (i==substrings.size()-1){
-
- text.set(p_line+i,text[p_line+i]+postinsert_text);
- }
- }
-
- r_end_line=p_line+substrings.size()-1;
- r_end_column=text[r_end_line].length()-postinsert_text.length();
-
- if (!text_changed_dirty && !setting_text) {
- if (is_inside_tree())
- MessageQueue::get_singleton()->push_call(this,"_text_changed_emit");
- text_changed_dirty=true;
- }
-
+
+ //save for undo...
+ ERR_FAIL_INDEX(p_line,text.size());
+ ERR_FAIL_COND(p_char<0);
+
+ /* STEP 1 add spaces if the char is greater than the end of the line */
+ while(p_char>text[p_line].length()) {
+
+ text.set(p_line,text[p_line]+String::chr(' '));
+ }
+
+ /* STEP 2 separate dest string in pre and post text */
+
+ String preinsert_text = text[p_line].substr(0,p_char);
+ String postinsert_text = text[p_line].substr(p_char,text[p_line].size());
+
+ /* STEP 3 remove \r from source text and separate in substrings */
+
+ //buh bye \r and split
+ Vector<String> substrings = p_text.replace("\r","").split("\n");
+
+
+ for(int i=0;i<substrings.size();i++) {
+ //insert the substrings
+
+ if (i==0) {
+
+ text.set(p_line,preinsert_text+substrings[i]);
+ } else {
+
+ text.insert(p_line+i,substrings[i]);
+ }
+
+ if (i==substrings.size()-1){
+
+ text.set(p_line+i,text[p_line+i]+postinsert_text);
+ }
+ }
+
+ r_end_line=p_line+substrings.size()-1;
+ r_end_column=text[r_end_line].length()-postinsert_text.length();
+
+ if (!text_changed_dirty && !setting_text) {
+ if (is_inside_tree())
+ MessageQueue::get_singleton()->push_call(this,"_text_changed_emit");
+ text_changed_dirty=true;
+ }
+
}
String TextEdit::_base_get_text(int p_from_line, int p_from_column,int p_to_line,int p_to_column) const {
-
- ERR_FAIL_INDEX_V(p_from_line,text.size(),String());
- ERR_FAIL_INDEX_V(p_from_column,text[p_from_line].length()+1,String());
- ERR_FAIL_INDEX_V(p_to_line,text.size(),String());
- ERR_FAIL_INDEX_V(p_to_column,text[p_to_line].length()+1,String());
- ERR_FAIL_COND_V(p_to_line < p_from_line ,String()); // from > to
- ERR_FAIL_COND_V(p_to_line == p_from_line && p_to_column<p_from_column,String()); // from > to
-
- String ret;
-
- for(int i=p_from_line;i<=p_to_line;i++) {
-
- int begin = (i==p_from_line)?p_from_column:0;
- int end = (i==p_to_line)?p_to_column:text[i].length();
-
- if (i>p_from_line)
- ret+="\n";
- ret+=text[i].substr(begin,end-begin);
- }
-
- return ret;
+
+ ERR_FAIL_INDEX_V(p_from_line,text.size(),String());
+ ERR_FAIL_INDEX_V(p_from_column,text[p_from_line].length()+1,String());
+ ERR_FAIL_INDEX_V(p_to_line,text.size(),String());
+ ERR_FAIL_INDEX_V(p_to_column,text[p_to_line].length()+1,String());
+ ERR_FAIL_COND_V(p_to_line < p_from_line ,String()); // from > to
+ ERR_FAIL_COND_V(p_to_line == p_from_line && p_to_column<p_from_column,String()); // from > to
+
+ String ret;
+
+ for(int i=p_from_line;i<=p_to_line;i++) {
+
+ int begin = (i==p_from_line)?p_from_column:0;
+ int end = (i==p_to_line)?p_to_column:text[i].length();
+
+ if (i>p_from_line)
+ ret+="\n";
+ ret+=text[i].substr(begin,end-begin);
+ }
+
+ return ret;
}
void TextEdit::_base_remove_text(int p_from_line, int p_from_column,int p_to_line,int p_to_column) {
-
- ERR_FAIL_INDEX(p_from_line,text.size());
- ERR_FAIL_INDEX(p_from_column,text[p_from_line].length()+1);
- ERR_FAIL_INDEX(p_to_line,text.size());
- ERR_FAIL_INDEX(p_to_column,text[p_to_line].length()+1);
- ERR_FAIL_COND(p_to_line < p_from_line ); // from > to
- ERR_FAIL_COND(p_to_line == p_from_line && p_to_column<p_from_column); // from > to
-
-
- String pre_text = text[p_from_line].substr(0,p_from_column);
- String post_text = text[p_to_line].substr(p_to_column,text[p_to_line].length());
-
- for(int i=p_from_line;i<p_to_line;i++) {
-
- text.remove(p_from_line+1);
- }
-
- text.set(p_from_line,pre_text+post_text);
-
- if (!text_changed_dirty && !setting_text) {
- if (is_inside_tree())
- MessageQueue::get_singleton()->push_call(this,"_text_changed_emit");
- text_changed_dirty=true;
- }
+
+ ERR_FAIL_INDEX(p_from_line,text.size());
+ ERR_FAIL_INDEX(p_from_column,text[p_from_line].length()+1);
+ ERR_FAIL_INDEX(p_to_line,text.size());
+ ERR_FAIL_INDEX(p_to_column,text[p_to_line].length()+1);
+ ERR_FAIL_COND(p_to_line < p_from_line ); // from > to
+ ERR_FAIL_COND(p_to_line == p_from_line && p_to_column<p_from_column); // from > to
+
+
+ String pre_text = text[p_from_line].substr(0,p_from_column);
+ String post_text = text[p_to_line].substr(p_to_column,text[p_to_line].length());
+
+ for(int i=p_from_line;i<p_to_line;i++) {
+
+ text.remove(p_from_line+1);
+ }
+
+ text.set(p_from_line,pre_text+post_text);
+
+ if (!text_changed_dirty && !setting_text) {
+ if (is_inside_tree())
+ MessageQueue::get_singleton()->push_call(this,"_text_changed_emit");
+ text_changed_dirty=true;
+ }
}
void TextEdit::_insert_text(int p_line, int p_char,const String& p_text,int *r_end_line,int *r_end_column) {
-
- if (!setting_text)
- idle_detect->start();
-
- if (undo_enabled) {
- _clear_redo();
- }
-
- int retline,retchar;
- _base_insert_text(p_line,p_char,p_text,retline,retchar);
- if (r_end_line)
- *r_end_line=retline;
- if (r_end_column)
- *r_end_column=retchar;
-
- if (!undo_enabled)
- return;
-
- /* UNDO!! */
- TextOperation op;
- op.type=TextOperation::TYPE_INSERT;
- op.from_line=p_line;
- op.from_column=p_char;
- op.to_line=retline;
- op.to_column=retchar;
- op.text=p_text;
- op.version=++version;
- op.chain_forward=false;
- op.chain_backward=false;
-
- //see if it shold just be set as current op
- if (current_op.type!=op.type) {
- _push_current_op();
- current_op=op;
-
- return; //set as current op, return
- }
- //see if it can be merged
- if (current_op.to_line!=p_line || current_op.to_column!=p_char) {
- _push_current_op();
- current_op=op;
- return; //set as current op, return
- }
- //merge current op
-
- current_op.text+=p_text;
- current_op.to_column=retchar;
- current_op.to_line=retline;
- current_op.version=op.version;
-
+
+ if (!setting_text)
+ idle_detect->start();
+
+ if (undo_enabled) {
+ _clear_redo();
+ }
+
+ int retline,retchar;
+ _base_insert_text(p_line,p_char,p_text,retline,retchar);
+ if (r_end_line)
+ *r_end_line=retline;
+ if (r_end_column)
+ *r_end_column=retchar;
+
+ if (!undo_enabled)
+ return;
+
+ /* UNDO!! */
+ TextOperation op;
+ op.type=TextOperation::TYPE_INSERT;
+ op.from_line=p_line;
+ op.from_column=p_char;
+ op.to_line=retline;
+ op.to_column=retchar;
+ op.text=p_text;
+ op.version=++version;
+ op.chain_forward=false;
+ op.chain_backward=false;
+
+ //see if it shold just be set as current op
+ if (current_op.type!=op.type) {
+ _push_current_op();
+ current_op=op;
+
+ return; //set as current op, return
+ }
+ //see if it can be merged
+ if (current_op.to_line!=p_line || current_op.to_column!=p_char) {
+ _push_current_op();
+ current_op=op;
+ return; //set as current op, return
+ }
+ //merge current op
+
+ current_op.text+=p_text;
+ current_op.to_column=retchar;
+ current_op.to_line=retline;
+ current_op.version=op.version;
+
}
void TextEdit::_remove_text(int p_from_line, int p_from_column,int p_to_line,int p_to_column) {
-
- if (!setting_text)
- idle_detect->start();
-
- String text;
- if (undo_enabled) {
- _clear_redo();
- text=_base_get_text(p_from_line,p_from_column,p_to_line,p_to_column);
- }
-
- _base_remove_text(p_from_line,p_from_column,p_to_line,p_to_column);
-
- if (!undo_enabled)
- return;
-
- /* UNDO!! */
- TextOperation op;
- op.type=TextOperation::TYPE_REMOVE;
- op.from_line=p_from_line;
- op.from_column=p_from_column;
- op.to_line=p_to_line;
- op.to_column=p_to_column;
- op.text=text;
- op.version=++version;
- op.chain_forward=false;
- op.chain_backward=false;
-
- //see if it shold just be set as current op
- if (current_op.type!=op.type) {
- _push_current_op();
- current_op=op;
- return; //set as current op, return
- }
- //see if it can be merged
- if (current_op.from_line==p_to_line && current_op.from_column==p_to_column) {
- //basckace or similar
- current_op.text=text+current_op.text;
- current_op.from_line=p_from_line;
- current_op.from_column=p_from_column;
- return; //update current op
- }
- if (current_op.from_line==p_from_line && current_op.from_column==p_from_column) {
-
- //current_op.text=text+current_op.text;
- //current_op.from_line=p_from_line;
- //current_op.from_column=p_from_column;
- //return; //update current op
- }
-
- _push_current_op();
- current_op=op;
-
+
+ if (!setting_text)
+ idle_detect->start();
+
+ String text;
+ if (undo_enabled) {
+ _clear_redo();
+ text=_base_get_text(p_from_line,p_from_column,p_to_line,p_to_column);
+ }
+
+ _base_remove_text(p_from_line,p_from_column,p_to_line,p_to_column);
+
+ if (!undo_enabled)
+ return;
+
+ /* UNDO!! */
+ TextOperation op;
+ op.type=TextOperation::TYPE_REMOVE;
+ op.from_line=p_from_line;
+ op.from_column=p_from_column;
+ op.to_line=p_to_line;
+ op.to_column=p_to_column;
+ op.text=text;
+ op.version=++version;
+ op.chain_forward=false;
+ op.chain_backward=false;
+
+ //see if it shold just be set as current op
+ if (current_op.type!=op.type) {
+ _push_current_op();
+ current_op=op;
+ return; //set as current op, return
+ }
+ //see if it can be merged
+ if (current_op.from_line==p_to_line && current_op.from_column==p_to_column) {
+ //basckace or similar
+ current_op.text=text+current_op.text;
+ current_op.from_line=p_from_line;
+ current_op.from_column=p_from_column;
+ return; //update current op
+ }
+ if (current_op.from_line==p_from_line && current_op.from_column==p_from_column) {
+
+ //current_op.text=text+current_op.text;
+ //current_op.from_line=p_from_line;
+ //current_op.from_column=p_from_column;
+ //return; //update current op
+ }
+
+ _push_current_op();
+ current_op=op;
+
}
void TextEdit::_insert_text_at_cursor(const String& p_text) {
-
- int new_column,new_line;
- _insert_text(cursor.line,cursor.column,p_text,&new_line,&new_column);
- cursor_set_line(new_line);
- cursor_set_column(new_column);
-
- update();
+
+ int new_column,new_line;
+ _insert_text(cursor.line,cursor.column,p_text,&new_line,&new_column);
+ cursor_set_line(new_line);
+ cursor_set_column(new_column);
+
+ update();
}
int TextEdit::get_char_count() {
-
- int totalsize=0;
-
- for (int i=0;i<text.size();i++) {
-
- if (i>0)
- totalsize++; // incliude \n
- totalsize+=text[i].length();
- }
-
- return totalsize; // omit last \n
+
+ int totalsize=0;
+
+ for (int i=0;i<text.size();i++) {
+
+ if (i>0)
+ totalsize++; // incliude \n
+ totalsize+=text[i].length();
+ }
+
+ return totalsize; // omit last \n
}
Size2 TextEdit::get_minimum_size() {
-
- return cache.style_normal->get_minimum_size();
+
+ return cache.style_normal->get_minimum_size();
}
int TextEdit::get_visible_rows() const {
-
- int total=cache.size.height;
- total-=cache.style_normal->get_minimum_size().height;
- total/=get_row_height();
- return total;
+
+ int total=cache.size.height;
+ total-=cache.style_normal->get_minimum_size().height;
+ total/=get_row_height();
+ return total;
}
void TextEdit::adjust_viewport_to_cursor() {
-
- if (cursor.line_ofs>cursor.line)
- cursor.line_ofs=cursor.line;
-
- int visible_width=cache.size.width-cache.style_normal->get_minimum_size().width-cache.line_number_w;
- if (v_scroll->is_visible())
- visible_width-=v_scroll->get_combined_minimum_size().width;
- visible_width-=20; // give it a little more space
-
-
- //printf("rowofs %i, visrows %i, cursor.line %i\n",cursor.line_ofs,get_visible_rows(),cursor.line);
-
- int visible_rows = get_visible_rows();
- if (h_scroll->is_visible())
- visible_rows-=((h_scroll->get_combined_minimum_size().height-1)/get_row_height());
-
- if (cursor.line>=(cursor.line_ofs+visible_rows))
- cursor.line_ofs=cursor.line-visible_rows+1;
- if (cursor.line<cursor.line_ofs)
- cursor.line_ofs=cursor.line;
-
- int cursor_x = get_column_x_offset( cursor.column, text[cursor.line] );
-
- if (cursor_x>(cursor.x_ofs+visible_width))
- cursor.x_ofs=cursor_x-visible_width+1;
-
- if (cursor_x < cursor.x_ofs)
- cursor.x_ofs=cursor_x;
-
- update();
-/*
+
+ if (cursor.line_ofs>cursor.line)
+ cursor.line_ofs=cursor.line;
+
+ int visible_width=cache.size.width-cache.style_normal->get_minimum_size().width-cache.line_number_w;
+ if (v_scroll->is_visible())
+ visible_width-=v_scroll->get_combined_minimum_size().width;
+ visible_width-=20; // give it a little more space
+
+
+ //printf("rowofs %i, visrows %i, cursor.line %i\n",cursor.line_ofs,get_visible_rows(),cursor.line);
+
+ int visible_rows = get_visible_rows();
+ if (h_scroll->is_visible())
+ visible_rows-=((h_scroll->get_combined_minimum_size().height-1)/get_row_height());
+
+ if (cursor.line>=(cursor.line_ofs+visible_rows))
+ cursor.line_ofs=cursor.line-visible_rows+1;
+ if (cursor.line<cursor.line_ofs)
+ cursor.line_ofs=cursor.line;
+
+ int cursor_x = get_column_x_offset( cursor.column, text[cursor.line] );
+
+ if (cursor_x>(cursor.x_ofs+visible_width))
+ cursor.x_ofs=cursor_x-visible_width+1;
+
+ if (cursor_x < cursor.x_ofs)
+ cursor.x_ofs=cursor_x;
+
+ update();
+ /*
get_range()->set_max(text.size());
-
+
get_range()->set_page(get_visible_rows());
-
+
get_range()->set((int)cursor.line_ofs);
*/
-
-
+
+
}
void TextEdit::cursor_set_column(int p_col) {
-
- if (p_col<0)
- p_col=0;
-
- cursor.column=p_col;
- if (cursor.column > get_line( cursor.line ).length())
- cursor.column=get_line( cursor.line ).length();
-
- cursor.last_fit_x=get_column_x_offset(cursor.column,get_line(cursor.line));
-
- adjust_viewport_to_cursor();
-
- if (!cursor_changed_dirty) {
- if (is_inside_tree())
- MessageQueue::get_singleton()->push_call(this,"_cursor_changed_emit");
- cursor_changed_dirty=true;
- }
-
+
+ if (p_col<0)
+ p_col=0;
+
+ cursor.column=p_col;
+ if (cursor.column > get_line( cursor.line ).length())
+ cursor.column=get_line( cursor.line ).length();
+
+ cursor.last_fit_x=get_column_x_offset(cursor.column,get_line(cursor.line));
+
+ adjust_viewport_to_cursor();
+
+ if (!cursor_changed_dirty) {
+ if (is_inside_tree())
+ MessageQueue::get_singleton()->push_call(this,"_cursor_changed_emit");
+ cursor_changed_dirty=true;
+ }
+
}
void TextEdit::cursor_set_line(int p_row) {
-
- if (setting_row)
- return;
-
- setting_row=true;
- if (p_row<0)
- p_row=0;
-
-
- if (p_row>=(int)text.size())
- p_row=(int)text.size()-1;
-
- cursor.line=p_row;
- cursor.column=get_char_pos_for( cursor.last_fit_x, get_line( cursor.line) );
-
-
- adjust_viewport_to_cursor();
-
- setting_row=false;
-
-
- if (!cursor_changed_dirty) {
- if (is_inside_tree())
- MessageQueue::get_singleton()->push_call(this,"_cursor_changed_emit");
- cursor_changed_dirty=true;
- }
-
+
+ if (setting_row)
+ return;
+
+ setting_row=true;
+ if (p_row<0)
+ p_row=0;
+
+
+ if (p_row>=(int)text.size())
+ p_row=(int)text.size()-1;
+
+ cursor.line=p_row;
+ cursor.column=get_char_pos_for( cursor.last_fit_x, get_line( cursor.line) );
+
+
+ adjust_viewport_to_cursor();
+
+ setting_row=false;
+
+
+ if (!cursor_changed_dirty) {
+ if (is_inside_tree())
+ MessageQueue::get_singleton()->push_call(this,"_cursor_changed_emit");
+ cursor_changed_dirty=true;
+ }
+
}
int TextEdit::cursor_get_column() const {
-
- return cursor.column;
+
+ return cursor.column;
}
int TextEdit::cursor_get_line() const {
-
- return cursor.line;
+
+ return cursor.line;
}
void TextEdit::_scroll_moved(double p_to_val) {
-
- if (updating_scrolls)
- return;
-
- if (h_scroll->is_visible())
- cursor.x_ofs=h_scroll->get_val();
- if (v_scroll->is_visible())
- cursor.line_ofs=v_scroll->get_val();
- update();
+
+ if (updating_scrolls)
+ return;
+
+ if (h_scroll->is_visible())
+ cursor.x_ofs=h_scroll->get_val();
+ if (v_scroll->is_visible())
+ cursor.line_ofs=v_scroll->get_val();
+ update();
}
@@ -2208,950 +2457,1008 @@ void TextEdit::_scroll_moved(double p_to_val) {
int TextEdit::get_row_height() const {
-
- return cache.font->get_height()+cache.line_spacing;
+
+ return cache.font->get_height()+cache.line_spacing;
}
int TextEdit::get_char_pos_for(int p_px,String p_str) const {
-
- int px=0;
- int c=0;
-
- int tab_w = cache.font->get_char_size(' ').width*tab_size;
-
- while (c<p_str.length()) {
-
- int w=0;
-
- if (p_str[c]=='\t') {
-
- int left = px%tab_w;
- if (left==0)
- w=tab_w;
- else
- w=tab_w-px%tab_w; // is right...
-
- } else {
-
- w=cache.font->get_char_size(p_str[c],p_str[c+1]).width;
- }
-
- if (p_px<(px+w/2))
- break;
- px+=w;
- c++;
- }
-
- return c;
+
+ int px=0;
+ int c=0;
+
+ int tab_w = cache.font->get_char_size(' ').width*tab_size;
+
+ while (c<p_str.length()) {
+
+ int w=0;
+
+ if (p_str[c]=='\t') {
+
+ int left = px%tab_w;
+ if (left==0)
+ w=tab_w;
+ else
+ w=tab_w-px%tab_w; // is right...
+
+ } else {
+
+ w=cache.font->get_char_size(p_str[c],p_str[c+1]).width;
+ }
+
+ if (p_px<(px+w/2))
+ break;
+ px+=w;
+ c++;
+ }
+
+ return c;
}
int TextEdit::get_column_x_offset(int p_char,String p_str) {
-
- int px=0;
-
- int tab_w = cache.font->get_char_size(' ').width*tab_size;
-
- for (int i=0;i<p_char;i++) {
-
- if (i>=p_str.length())
- break;
-
- if (p_str[i]=='\t') {
-
- int left = px%tab_w;
- if (left==0)
- px+=tab_w;
- else
- px+=tab_w-px%tab_w; // is right...
-
- } else {
- px+=cache.font->get_char_size(p_str[i],p_str[i+1]).width;
- }
- }
-
- return px;
-
+
+ int px=0;
+
+ int tab_w = cache.font->get_char_size(' ').width*tab_size;
+
+ for (int i=0;i<p_char;i++) {
+
+ if (i>=p_str.length())
+ break;
+
+ if (p_str[i]=='\t') {
+
+ int left = px%tab_w;
+ if (left==0)
+ px+=tab_w;
+ else
+ px+=tab_w-px%tab_w; // is right...
+
+ } else {
+ px+=cache.font->get_char_size(p_str[i],p_str[i+1]).width;
+ }
+ }
+
+ return px;
+
}
void TextEdit::insert_text_at_cursor(const String& p_text) {
-
- if (selection.active) {
-
- cursor_set_line(selection.from_line);
- cursor_set_column(selection.from_column);
-
- _remove_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column);
- selection.active=false;
- selection.selecting_mode=Selection::MODE_NONE;
-
- }
-
- _insert_text_at_cursor(p_text);
- update();
-
+
+ if (selection.active) {
+
+ cursor_set_line(selection.from_line);
+ cursor_set_column(selection.from_column);
+
+ _remove_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column);
+ selection.active=false;
+ selection.selecting_mode=Selection::MODE_NONE;
+
+ }
+
+ _insert_text_at_cursor(p_text);
+ update();
+
}
Control::CursorShape TextEdit::get_cursor_shape(const Point2& p_pos) const {
- if(completion_active && completion_rect.has_point(p_pos)) {
- return CURSOR_ARROW;
- }
- return CURSOR_IBEAM;
+ if(completion_active && completion_rect.has_point(p_pos)) {
+ return CURSOR_ARROW;
+ }
+ return CURSOR_IBEAM;
}
void TextEdit::set_text(String p_text){
-
- setting_text=true;
- _clear();
- _insert_text_at_cursor(p_text);
-
- cursor.column=0;
- cursor.line=0;
- cursor.x_ofs=0;
- cursor.line_ofs=0;
- cursor.last_fit_x=0;
- cursor_set_line(0);
- cursor_set_column(0);
- update();
- setting_text=false;
-
- //get_range()->set(0);
+
+ setting_text=true;
+ _clear();
+ _insert_text_at_cursor(p_text);
+
+ cursor.column=0;
+ cursor.line=0;
+ cursor.x_ofs=0;
+ cursor.line_ofs=0;
+ cursor.last_fit_x=0;
+ cursor_set_line(0);
+ cursor_set_column(0);
+ update();
+ setting_text=false;
+
+ //get_range()->set(0);
};
String TextEdit::get_text() {
- String longthing;
- int len = text.size();
- for (int i=0;i<len;i++) {
-
-
- longthing+=text[i];
- if (i!=len-1)
- longthing+="\n";
- }
-
- return longthing;
+ String longthing;
+ int len = text.size();
+ for (int i=0;i<len;i++) {
+
+
+ longthing+=text[i];
+ if (i!=len-1)
+ longthing+="\n";
+ }
+
+ return longthing;
+
+};
+String TextEdit::get_text_for_completion() {
+
+ String longthing;
+ int len = text.size();
+ for (int i=0;i<len;i++) {
+
+ if (i==cursor.line) {
+ longthing+=text[i].substr(0,cursor.column);
+ longthing+=String::chr(0xFFFF); //not unicode, represents the cursor
+ longthing+=text[i].substr(cursor.column,text[i].size());
+ } else {
+
+ longthing+=text[i];
+ }
+
+
+ if (i!=len-1)
+ longthing+="\n";
+ }
+
+ return longthing;
+
};
String TextEdit::get_line(int line) const {
-
- if (line<0 || line>=text.size())
- return "";
-
- return text[line];
-
+
+ if (line<0 || line>=text.size())
+ return "";
+
+ return text[line];
+
};
void TextEdit::_clear() {
-
- clear_undo_history();
- text.clear();
- cursor.column=0;
- cursor.line=0;
- cursor.x_ofs=0;
- cursor.line_ofs=0;
- cursor.last_fit_x=0;
+
+ clear_undo_history();
+ text.clear();
+ cursor.column=0;
+ cursor.line=0;
+ cursor.x_ofs=0;
+ cursor.line_ofs=0;
+ cursor.last_fit_x=0;
}
void TextEdit::clear() {
-
- setting_text=true;
- _clear();
- setting_text=false;
-
+
+ setting_text=true;
+ _clear();
+ setting_text=false;
+
};
void TextEdit::set_readonly(bool p_readonly) {
-
-
- readonly=p_readonly;
+
+
+ readonly=p_readonly;
}
void TextEdit::set_wrap(bool p_wrap) {
-
- wrap=p_wrap;
+
+ wrap=p_wrap;
}
void TextEdit::set_max_chars(int p_max_chars) {
-
- max_chars=p_max_chars;
+
+ max_chars=p_max_chars;
}
void TextEdit::_update_caches() {
-
- cache.style_normal=get_stylebox("normal");
- cache.style_focus=get_stylebox("focus");
- cache.font=get_font("font");
- cache.font_color=get_color("font_color");
- cache.font_selected_color=get_color("font_selected_color");
- cache.keyword_color=get_color("keyword_color");
- cache.selection_color=get_color("selection_color");
- cache.mark_color=get_color("mark_color");
- cache.current_line_color=get_color("current_line_color");
- cache.breakpoint_color=get_color("breakpoint_color");
- cache.line_spacing=get_constant("line_spacing");
- cache.row_height = cache.font->get_height() + cache.line_spacing;
- cache.tab_icon=get_icon("tab");
- text.set_font(cache.font);
-
+
+ cache.style_normal=get_stylebox("normal");
+ cache.style_focus=get_stylebox("focus");
+ cache.font=get_font("font");
+ cache.font_color=get_color("font_color");
+ cache.font_selected_color=get_color("font_selected_color");
+ cache.keyword_color=get_color("keyword_color");
+ cache.selection_color=get_color("selection_color");
+ cache.mark_color=get_color("mark_color");
+ cache.current_line_color=get_color("current_line_color");
+ cache.breakpoint_color=get_color("breakpoint_color");
+ cache.brace_mismatch_color=get_color("brace_mismatch_color");
+ cache.line_spacing=get_constant("line_spacing");
+ cache.row_height = cache.font->get_height() + cache.line_spacing;
+ cache.tab_icon=get_icon("tab");
+ text.set_font(cache.font);
+
}
void TextEdit::clear_colors() {
-
- keywords.clear();
- color_regions.clear();;
- text.clear_caches();
- custom_bg_color=Color(0,0,0,0);
+
+ keywords.clear();
+ color_regions.clear();;
+ text.clear_caches();
+ custom_bg_color=Color(0,0,0,0);
}
void TextEdit::set_custom_bg_color(const Color& p_color) {
-
- custom_bg_color=p_color;
- update();
+
+ custom_bg_color=p_color;
+ update();
}
void TextEdit::add_keyword_color(const String& p_keyword,const Color& p_color) {
-
- keywords[p_keyword]=p_color;
- update();
-
+
+ keywords[p_keyword]=p_color;
+ update();
+
}
void TextEdit::add_color_region(const String& p_begin_key,const String& p_end_key,const Color &p_color,bool p_line_only) {
-
- color_regions.push_back(ColorRegion(p_begin_key,p_end_key,p_color,p_line_only));
- text.clear_caches();
- update();
-
+
+ color_regions.push_back(ColorRegion(p_begin_key,p_end_key,p_color,p_line_only));
+ text.clear_caches();
+ update();
+
}
void TextEdit::set_symbol_color(const Color& p_color) {
-
- symbol_color=p_color;
- update();
+
+ symbol_color=p_color;
+ update();
}
void TextEdit::set_syntax_coloring(bool p_enabled) {
-
- syntax_coloring=p_enabled;
- update();
+
+ syntax_coloring=p_enabled;
+ update();
}
bool TextEdit::is_syntax_coloring_enabled() const {
-
- return syntax_coloring;
+
+ return syntax_coloring;
}
void TextEdit::cut() {
-
- if (!selection.active)
- return;
-
- String clipboard = _base_get_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column);
- OS::get_singleton()->set_clipboard(clipboard);
-
- cursor_set_line(selection.from_line);
- cursor_set_column(selection.from_column);
-
- _remove_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column);
- selection.active=false;
- selection.selecting_mode=Selection::MODE_NONE;
- update();
-
+
+ if (!selection.active)
+ return;
+
+ String clipboard = _base_get_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column);
+ OS::get_singleton()->set_clipboard(clipboard);
+
+ cursor_set_line(selection.from_line);
+ cursor_set_column(selection.from_column);
+
+ _remove_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column);
+ selection.active=false;
+ selection.selecting_mode=Selection::MODE_NONE;
+ update();
+
}
void TextEdit::copy() {
-
- if (!selection.active)
- return;
-
- String clipboard = _base_get_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column);
- OS::get_singleton()->set_clipboard(clipboard);
-
+
+ if (!selection.active)
+ return;
+
+ String clipboard = _base_get_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column);
+ OS::get_singleton()->set_clipboard(clipboard);
+
}
void TextEdit::paste() {
-
- if (selection.active) {
-
- cursor_set_line(selection.from_line);
- cursor_set_column(selection.from_column);
-
- _remove_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column);
- selection.active=false;
- selection.selecting_mode=Selection::MODE_NONE;
-
- }
-
- String clipboard = OS::get_singleton()->get_clipboard();
- _insert_text_at_cursor(clipboard);
- update();
-
+
+ if (selection.active) {
+
+ cursor_set_line(selection.from_line);
+ cursor_set_column(selection.from_column);
+
+ _remove_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column);
+ selection.active=false;
+ selection.selecting_mode=Selection::MODE_NONE;
+
+ }
+
+ String clipboard = OS::get_singleton()->get_clipboard();
+ _insert_text_at_cursor(clipboard);
+ update();
+
}
void TextEdit::select_all() {
-
- if (text.size()==1 && text[0].length()==0)
- return;
- selection.active=true;
- selection.from_line=0;
- selection.from_column=0;
- selection.to_line=text.size()-1;
- selection.to_column=text[selection.to_line].size();
- selection.selecting_mode=Selection::MODE_NONE;
- update();
-
+
+ if (text.size()==1 && text[0].length()==0)
+ return;
+ selection.active=true;
+ selection.from_line=0;
+ selection.from_column=0;
+ selection.to_line=text.size()-1;
+ selection.to_column=text[selection.to_line].size();
+ selection.selecting_mode=Selection::MODE_NONE;
+ update();
+
}
void TextEdit::deselect() {
-
- selection.active=false;
- update();
+
+ selection.active=false;
+ update();
}
void TextEdit::select(int p_from_line,int p_from_column,int p_to_line,int p_to_column) {
-
- if (p_from_line>=text.size())
- p_from_line=text.size()-1;
- if (p_from_column>=text[p_from_line].length())
- p_from_column=text[p_from_line].length();
-
- if (p_to_line>=text.size())
- p_to_line=text.size()-1;
- if (p_to_column>=text[p_to_line].length())
- p_to_column=text[p_to_line].length();
-
- selection.from_line=p_from_line;
- selection.from_column=p_from_column;
- selection.to_line=p_to_line;
- selection.to_column=p_to_column;
-
- selection.active=true;
-
- if (selection.from_line==selection.to_line) {
-
- if (selection.from_column==selection.to_column) {
-
- selection.active=false;
-
- } else if (selection.from_column>selection.to_column) {
-
- SWAP( selection.from_column, selection.to_column );
- }
- } else if (selection.from_line>selection.to_line) {
-
- SWAP( selection.from_line, selection.to_line );
- SWAP( selection.from_column, selection.to_column );
- }
-
-
- update();
+
+ if (p_from_line>=text.size())
+ p_from_line=text.size()-1;
+ if (p_from_column>=text[p_from_line].length())
+ p_from_column=text[p_from_line].length();
+
+ if (p_to_line>=text.size())
+ p_to_line=text.size()-1;
+ if (p_to_column>=text[p_to_line].length())
+ p_to_column=text[p_to_line].length();
+
+ selection.from_line=p_from_line;
+ selection.from_column=p_from_column;
+ selection.to_line=p_to_line;
+ selection.to_column=p_to_column;
+
+ selection.active=true;
+
+ if (selection.from_line==selection.to_line) {
+
+ if (selection.from_column==selection.to_column) {
+
+ selection.active=false;
+
+ } else if (selection.from_column>selection.to_column) {
+
+ SWAP( selection.from_column, selection.to_column );
+ }
+ } else if (selection.from_line>selection.to_line) {
+
+ SWAP( selection.from_line, selection.to_line );
+ SWAP( selection.from_column, selection.to_column );
+ }
+
+
+ update();
}
bool TextEdit::is_selection_active() const {
-
- return selection.active;
+
+ return selection.active;
}
int TextEdit::get_selection_from_line() const {
-
- ERR_FAIL_COND_V(!selection.active,-1);
- return selection.from_line;
-
+
+ ERR_FAIL_COND_V(!selection.active,-1);
+ return selection.from_line;
+
}
int TextEdit::get_selection_from_column() const {
-
- ERR_FAIL_COND_V(!selection.active,-1);
- return selection.from_column;
-
+
+ ERR_FAIL_COND_V(!selection.active,-1);
+ return selection.from_column;
+
}
int TextEdit::get_selection_to_line() const {
-
- ERR_FAIL_COND_V(!selection.active,-1);
- return selection.to_line;
-
+
+ ERR_FAIL_COND_V(!selection.active,-1);
+ return selection.to_line;
+
}
int TextEdit::get_selection_to_column() const {
-
- ERR_FAIL_COND_V(!selection.active,-1);
- return selection.to_column;
-
+
+ ERR_FAIL_COND_V(!selection.active,-1);
+ return selection.to_column;
+
}
String TextEdit::get_selection_text() const {
-
- if (!selection.active)
- return "";
-
- return _base_get_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column);
-
+
+ if (!selection.active)
+ return "";
+
+ return _base_get_text(selection.from_line,selection.from_column,selection.to_line,selection.to_column);
+
}
String TextEdit::get_word_under_cursor() const {
-
- int prev_cc = cursor.column;
- while(prev_cc >0) {
- bool is_char = _is_text_char(text[cursor.line][prev_cc-1]);
- if (!is_char)
- break;
- --prev_cc;
- }
-
- int next_cc = cursor.column;
- while(next_cc<text[cursor.line].length()) {
- bool is_char = _is_text_char(text[cursor.line][next_cc]);
- if(!is_char)
- break;
- ++ next_cc;
- }
- if (prev_cc == cursor.column || next_cc == cursor.column)
- return "";
- return text[cursor.line].substr(prev_cc, next_cc-prev_cc);
+
+ int prev_cc = cursor.column;
+ while(prev_cc >0) {
+ bool is_char = _is_text_char(text[cursor.line][prev_cc-1]);
+ if (!is_char)
+ break;
+ --prev_cc;
+ }
+
+ int next_cc = cursor.column;
+ while(next_cc<text[cursor.line].length()) {
+ bool is_char = _is_text_char(text[cursor.line][next_cc]);
+ if(!is_char)
+ break;
+ ++ next_cc;
+ }
+ if (prev_cc == cursor.column || next_cc == cursor.column)
+ return "";
+ return text[cursor.line].substr(prev_cc, next_cc-prev_cc);
}
DVector<int> TextEdit::_search_bind(const String &p_key,uint32_t p_search_flags, int p_from_line,int p_from_column) const {
-
- int col,line;
- if (search(p_key,p_search_flags,p_from_line,p_from_column,col,line)) {
- DVector<int> result;
- result.resize(2);
- result.set(0,line);
- result.set(1,col);
- return result;
-
- } else {
-
- return DVector<int>();
- }
+
+ int col,line;
+ if (search(p_key,p_search_flags,p_from_line,p_from_column,col,line)) {
+ DVector<int> result;
+ result.resize(2);
+ result.set(0,line);
+ result.set(1,col);
+ return result;
+
+ } else {
+
+ return DVector<int>();
+ }
}
bool TextEdit::search(const String &p_key,uint32_t p_search_flags, int p_from_line, int p_from_column,int &r_line,int &r_column) const {
-
- if (p_key.length()==0)
- return false;
- ERR_FAIL_INDEX_V(p_from_line,text.size(),false);
- ERR_FAIL_INDEX_V(p_from_column,text[p_from_line].length()+1,false);
-
- //search through the whole documment, but start by current line
-
- int line=-1;
- int pos=-1;
-
- line=p_from_line;
-
- for(int i=0;i<text.size()+1;i++) {
- //backwards is broken...
- //int idx=(p_search_flags&SEARCH_BACKWARDS)?(text.size()-i):i; //do backwards seearch
-
-
- if (line<0) {
- line=text.size()-1;
- }
- if (line==text.size()) {
- line=0;
- }
-
- String text_line = text[line];
- int from_column=0;
- if (line==p_from_line) {
-
- if (i==text.size()) {
- //wrapped
-
- if (p_search_flags&SEARCH_BACKWARDS) {
- text_line=text_line.substr(from_column,text_line.length());
- from_column=text_line.length();
- } else {
- text_line=text_line.substr(0,from_column);
- from_column=0;
- }
-
- } else {
-
- from_column=p_from_column;
- }
-
-
- } else {
- //text_line=text_line.substr(0,p_from_column); //wrap around for missing begining.
- if (p_search_flags&SEARCH_BACKWARDS)
- from_column=text_line.length()-1;
- else
- from_column=0;
- }
-
- pos=-1;
-
- if (!(p_search_flags&SEARCH_BACKWARDS)) {
-
- pos = (p_search_flags&SEARCH_MATCH_CASE)?text_line.find(p_key,from_column):text_line.findn(p_key,from_column);
- } else {
-
- pos = (p_search_flags&SEARCH_MATCH_CASE)?text_line.rfind(p_key,from_column):text_line.rfindn(p_key,from_column);
- }
-
- if (pos!=-1 && (p_search_flags&SEARCH_WHOLE_WORDS)) {
- //validate for whole words
- if (pos>0 && _is_text_char(text_line[pos-1]))
- pos=-1;
- else if (_is_text_char(text_line[pos+p_key.length()]))
- pos=-1;
- }
-
- if (pos!=-1)
- break;
-
- if (p_search_flags&SEARCH_BACKWARDS)
- line--;
- else
- line++;
-
- }
-
- if (pos==-1) {
- r_line=-1;
- r_column=-1;
- return false;
- }
-
- r_line=line;
- r_column=pos;
-
-
- return true;
+
+ if (p_key.length()==0)
+ return false;
+ ERR_FAIL_INDEX_V(p_from_line,text.size(),false);
+ ERR_FAIL_INDEX_V(p_from_column,text[p_from_line].length()+1,false);
+
+ //search through the whole documment, but start by current line
+
+ int line=-1;
+ int pos=-1;
+
+ line=p_from_line;
+
+ for(int i=0;i<text.size()+1;i++) {
+ //backwards is broken...
+ //int idx=(p_search_flags&SEARCH_BACKWARDS)?(text.size()-i):i; //do backwards seearch
+
+
+ if (line<0) {
+ line=text.size()-1;
+ }
+ if (line==text.size()) {
+ line=0;
+ }
+
+ String text_line = text[line];
+ int from_column=0;
+ if (line==p_from_line) {
+
+ if (i==text.size()) {
+ //wrapped
+
+ if (p_search_flags&SEARCH_BACKWARDS) {
+ text_line=text_line.substr(from_column,text_line.length());
+ from_column=text_line.length();
+ } else {
+ text_line=text_line.substr(0,from_column);
+ from_column=0;
+ }
+
+ } else {
+
+ from_column=p_from_column;
+ }
+
+
+ } else {
+ //text_line=text_line.substr(0,p_from_column); //wrap around for missing begining.
+ if (p_search_flags&SEARCH_BACKWARDS)
+ from_column=text_line.length()-1;
+ else
+ from_column=0;
+ }
+
+ pos=-1;
+
+ if (!(p_search_flags&SEARCH_BACKWARDS)) {
+
+ pos = (p_search_flags&SEARCH_MATCH_CASE)?text_line.find(p_key,from_column):text_line.findn(p_key,from_column);
+ } else {
+
+ pos = (p_search_flags&SEARCH_MATCH_CASE)?text_line.rfind(p_key,from_column):text_line.rfindn(p_key,from_column);
+ }
+
+ if (pos!=-1 && (p_search_flags&SEARCH_WHOLE_WORDS)) {
+ //validate for whole words
+ if (pos>0 && _is_text_char(text_line[pos-1]))
+ pos=-1;
+ else if (_is_text_char(text_line[pos+p_key.length()]))
+ pos=-1;
+ }
+
+ if (pos!=-1)
+ break;
+
+ if (p_search_flags&SEARCH_BACKWARDS)
+ line--;
+ else
+ line++;
+
+ }
+
+ if (pos==-1) {
+ r_line=-1;
+ r_column=-1;
+ return false;
+ }
+
+ r_line=line;
+ r_column=pos;
+
+
+ return true;
}
void TextEdit::_cursor_changed_emit() {
-
- emit_signal("cursor_changed");
- cursor_changed_dirty=false;
+
+ emit_signal("cursor_changed");
+ cursor_changed_dirty=false;
}
void TextEdit::_text_changed_emit() {
-
- emit_signal("text_changed");
- text_changed_dirty=false;
+
+ emit_signal("text_changed");
+ text_changed_dirty=false;
}
void TextEdit::set_line_as_marked(int p_line,bool p_marked) {
-
- ERR_FAIL_INDEX(p_line,text.size());
- text.set_marked(p_line,p_marked);
- update();
+
+ ERR_FAIL_INDEX(p_line,text.size());
+ text.set_marked(p_line,p_marked);
+ update();
}
bool TextEdit::is_line_set_as_breakpoint(int p_line) const {
-
- ERR_FAIL_INDEX_V(p_line,text.size(),false);
- return text.is_breakpoint(p_line);
-
+
+ ERR_FAIL_INDEX_V(p_line,text.size(),false);
+ return text.is_breakpoint(p_line);
+
}
void TextEdit::set_line_as_breakpoint(int p_line,bool p_breakpoint) {
-
-
- ERR_FAIL_INDEX(p_line,text.size());
- text.set_breakpoint(p_line,p_breakpoint);
- update();
+
+
+ ERR_FAIL_INDEX(p_line,text.size());
+ text.set_breakpoint(p_line,p_breakpoint);
+ update();
}
void TextEdit::get_breakpoints(List<int> *p_breakpoints) const {
-
- for(int i=0;i<text.size();i++) {
- if (text.is_breakpoint(i))
- p_breakpoints->push_back(i);
- }
+
+ for(int i=0;i<text.size();i++) {
+ if (text.is_breakpoint(i))
+ p_breakpoints->push_back(i);
+ }
}
int TextEdit::get_line_count() const {
-
- return text.size();
+
+ return text.size();
}
void TextEdit::_do_text_op(const TextOperation& p_op, bool p_reverse) {
-
- ERR_FAIL_COND(p_op.type==TextOperation::TYPE_NONE);
-
- bool insert = p_op.type==TextOperation::TYPE_INSERT;
- if (p_reverse)
- insert=!insert;
-
- if (insert) {
-
- int check_line;
- int check_column;
- _base_insert_text(p_op.from_line,p_op.from_column,p_op.text,check_line,check_column);
- ERR_FAIL_COND( check_line != p_op.to_line ); // BUG
- ERR_FAIL_COND( check_column != p_op.to_column ); // BUG
- } else {
-
- _base_remove_text(p_op.from_line,p_op.from_column,p_op.to_line,p_op.to_column);
- }
-
+
+ ERR_FAIL_COND(p_op.type==TextOperation::TYPE_NONE);
+
+ bool insert = p_op.type==TextOperation::TYPE_INSERT;
+ if (p_reverse)
+ insert=!insert;
+
+ if (insert) {
+
+ int check_line;
+ int check_column;
+ _base_insert_text(p_op.from_line,p_op.from_column,p_op.text,check_line,check_column);
+ ERR_FAIL_COND( check_line != p_op.to_line ); // BUG
+ ERR_FAIL_COND( check_column != p_op.to_column ); // BUG
+ } else {
+
+ _base_remove_text(p_op.from_line,p_op.from_column,p_op.to_line,p_op.to_column);
+ }
+
}
void TextEdit::_clear_redo() {
-
- if (undo_stack_pos==NULL)
- return; //nothing to clear
-
- _push_current_op();
-
- while (undo_stack_pos) {
- List<TextOperation>::Element *elem = undo_stack_pos;
- undo_stack_pos=undo_stack_pos->next();
- undo_stack.erase(elem);
- }
+
+ if (undo_stack_pos==NULL)
+ return; //nothing to clear
+
+ _push_current_op();
+
+ while (undo_stack_pos) {
+ List<TextOperation>::Element *elem = undo_stack_pos;
+ undo_stack_pos=undo_stack_pos->next();
+ undo_stack.erase(elem);
+ }
}
void TextEdit::undo() {
-
- _push_current_op();
-
- if (undo_stack_pos==NULL) {
-
- if (!undo_stack.size())
- return; //nothing to undo
-
- undo_stack_pos=undo_stack.back();
-
- } else if (undo_stack_pos==undo_stack.front())
- return; // at the bottom of the undo stack
- else
- undo_stack_pos=undo_stack_pos->prev();
-
- _do_text_op( undo_stack_pos->get(),true);
- if(undo_stack_pos->get().chain_backward) {
- do {
- undo_stack_pos = undo_stack_pos->prev();
- _do_text_op(undo_stack_pos->get(), true);
- } while(!undo_stack_pos->get().chain_forward);
- }
-
- cursor_set_line(undo_stack_pos->get().from_line);
- cursor_set_column(undo_stack_pos->get().from_column);
- update();
+
+ _push_current_op();
+
+ if (undo_stack_pos==NULL) {
+
+ if (!undo_stack.size())
+ return; //nothing to undo
+
+ undo_stack_pos=undo_stack.back();
+
+ } else if (undo_stack_pos==undo_stack.front())
+ return; // at the bottom of the undo stack
+ else
+ undo_stack_pos=undo_stack_pos->prev();
+
+ _do_text_op( undo_stack_pos->get(),true);
+ if(undo_stack_pos->get().chain_backward) {
+ do {
+ undo_stack_pos = undo_stack_pos->prev();
+ _do_text_op(undo_stack_pos->get(), true);
+ } while(!undo_stack_pos->get().chain_forward);
+ }
+
+ cursor_set_line(undo_stack_pos->get().from_line);
+ cursor_set_column(undo_stack_pos->get().from_column);
+ update();
}
void TextEdit::redo() {
-
- _push_current_op();
-
- if (undo_stack_pos==NULL)
- return; //nothing to do.
-
- _do_text_op(undo_stack_pos->get(), false);
- if(undo_stack_pos->get().chain_forward) {
- do {
- undo_stack_pos=undo_stack_pos->next();
- _do_text_op(undo_stack_pos->get(), false);
- } while(!undo_stack_pos->get().chain_backward);
- }
- cursor_set_line(undo_stack_pos->get().from_line);
- cursor_set_column(undo_stack_pos->get().from_column);
- undo_stack_pos=undo_stack_pos->next();
- update();
+
+ _push_current_op();
+
+ if (undo_stack_pos==NULL)
+ return; //nothing to do.
+
+ _do_text_op(undo_stack_pos->get(), false);
+ if(undo_stack_pos->get().chain_forward) {
+ do {
+ undo_stack_pos=undo_stack_pos->next();
+ _do_text_op(undo_stack_pos->get(), false);
+ } while(!undo_stack_pos->get().chain_backward);
+ }
+ cursor_set_line(undo_stack_pos->get().from_line);
+ cursor_set_column(undo_stack_pos->get().from_column);
+ undo_stack_pos=undo_stack_pos->next();
+ update();
}
void TextEdit::clear_undo_history() {
-
- saved_version=0;
- current_op.type=TextOperation::TYPE_NONE;
- undo_stack_pos=NULL;
- undo_stack.clear();
-
+
+ saved_version=0;
+ current_op.type=TextOperation::TYPE_NONE;
+ undo_stack_pos=NULL;
+ undo_stack.clear();
+
}
void TextEdit::_begin_compex_operation() {
- _push_current_op();
- next_operation_is_complex=true;
+ _push_current_op();
+ next_operation_is_complex=true;
}
void TextEdit::_end_compex_operation() {
-
- _push_current_op();
- ERR_FAIL_COND(undo_stack.size() == 0);
-
- if(undo_stack.back()->get().chain_forward) {
- undo_stack.back()->get().chain_forward=false;
- return;
- }
-
- undo_stack.back()->get().chain_backward=true;
+
+ _push_current_op();
+ ERR_FAIL_COND(undo_stack.size() == 0);
+
+ if(undo_stack.back()->get().chain_forward) {
+ undo_stack.back()->get().chain_forward=false;
+ return;
+ }
+
+ undo_stack.back()->get().chain_backward=true;
}
void TextEdit::_push_current_op() {
-
- if (current_op.type==TextOperation::TYPE_NONE)
- return; // do nothing
-
- if(next_operation_is_complex) {
- current_op.chain_forward=true;
- next_operation_is_complex=false;
- }
-
- undo_stack.push_back(current_op);
- current_op.type=TextOperation::TYPE_NONE;
- current_op.text="";
- current_op.chain_forward=false;
-
+
+ if (current_op.type==TextOperation::TYPE_NONE)
+ return; // do nothing
+
+ if(next_operation_is_complex) {
+ current_op.chain_forward=true;
+ next_operation_is_complex=false;
+ }
+
+ undo_stack.push_back(current_op);
+ current_op.type=TextOperation::TYPE_NONE;
+ current_op.text="";
+ current_op.chain_forward=false;
+
}
void TextEdit::set_draw_tabs(bool p_draw) {
-
- draw_tabs=p_draw;
+
+ draw_tabs=p_draw;
}
bool TextEdit::is_drawing_tabs() const{
-
- return draw_tabs;
+
+ return draw_tabs;
}
uint32_t TextEdit::get_version() const {
- return current_op.version;
+ return current_op.version;
}
uint32_t TextEdit::get_saved_version() const {
-
- return saved_version;
+
+ return saved_version;
}
void TextEdit::tag_saved_version() {
-
- saved_version=get_version();
+
+ saved_version=get_version();
}
int TextEdit::get_v_scroll() const {
-
- return v_scroll->get_val();
+
+ return v_scroll->get_val();
}
void TextEdit::set_v_scroll(int p_scroll) {
-
- v_scroll->set_val(p_scroll);
- cursor.line_ofs=p_scroll;
+
+ v_scroll->set_val(p_scroll);
+ cursor.line_ofs=p_scroll;
}
int TextEdit::get_h_scroll() const {
-
- return h_scroll->get_val();
+
+ return h_scroll->get_val();
}
void TextEdit::set_h_scroll(int p_scroll) {
-
- h_scroll->set_val(p_scroll);
+
+ h_scroll->set_val(p_scroll);
}
void TextEdit::set_completion(bool p_enabled,const Vector<String>& p_prefixes) {
-
- completion_prefixes.clear();
- completion_enabled=p_enabled;
- for(int i=0;i<p_prefixes.size();i++)
- completion_prefixes.insert(p_prefixes[i]);
+
+ completion_prefixes.clear();
+ completion_enabled=p_enabled;
+ for(int i=0;i<p_prefixes.size();i++)
+ completion_prefixes.insert(p_prefixes[i]);
}
void TextEdit::_confirm_completion() {
-
- String remaining=completion_current.substr(completion_base.length(),completion_current.length()-completion_base.length());
- String l = text[cursor.line];
- bool same=true;
- //if what is going to be inserted is the same as what it is, don't change it
- for(int i=0;i<remaining.length();i++) {
- int c=i+cursor.column;
- if (c>=l.length() || l[c]!=remaining[i]) {
- same=false;
- break;
- }
- }
-
- if (same)
- cursor_set_column(cursor.column+remaining.length());
- else
- insert_text_at_cursor(remaining);
-
- _cancel_completion();
+
+ String remaining=completion_current.substr(completion_base.length(),completion_current.length()-completion_base.length());
+ String l = text[cursor.line];
+ bool same=true;
+ //if what is going to be inserted is the same as what it is, don't change it
+ for(int i=0;i<remaining.length();i++) {
+ int c=i+cursor.column;
+ if (c>=l.length() || l[c]!=remaining[i]) {
+ same=false;
+ break;
+ }
+ }
+
+ if (same)
+ cursor_set_column(cursor.column+remaining.length());
+ else {
+ insert_text_at_cursor(remaining);
+ if (remaining.ends_with("(") && auto_brace_completion_enabled) {
+ insert_text_at_cursor(")");
+ cursor.column--;
+ }
+ }
+
+ _cancel_completion();
+}
+
+
+void TextEdit::_cancel_code_hint() {
+ completion_hint="";
+ update();
}
void TextEdit::_cancel_completion() {
-
- if (!completion_active)
- return;
-
- completion_active=false;
- update();
-
+
+ if (!completion_active)
+ return;
+
+ completion_active=false;
+ update();
+
}
-void TextEdit::_update_completion_candidates() {
+static bool _is_completable(CharType c) {
+
+ return !_is_symbol(c) || c=='"' || c=='\'';
+}
- String l = text[cursor.line];
- int cofs = CLAMP(cursor.column,0,l.length());
-
- String s;
- while(cofs>0 && l[cofs-1]>32 && !_is_symbol(l[cofs-1])) {
- s=String::chr(l[cofs-1])+s;
- cofs--;
- }
-
- update();
-
- if (s=="" && (cofs==0 || !completion_prefixes.has(String::chr(l[cofs-1])))) {
- //none to complete, cancel
- _cancel_completion();
- return;
- }
-
- completion_options.clear();
- completion_index=0;
- completion_base=s;
- int ci_match=0;
- for(int i=0;i<completion_strings.size();i++) {
- if (completion_strings[i].begins_with(s)) {
- completion_options.push_back(completion_strings[i]);
- int m=0;
- int max=MIN(completion_current.length(),completion_strings[i].length());
- if (max<ci_match)
- continue;
- for(int j=0;j<max;j++) {
-
- if (j>=completion_strings[i].length())
- break;
- if (completion_current[j]!=completion_strings[i][j])
- break;
- m++;
- }
- if (m>ci_match) {
- ci_match=m;
- completion_index=completion_options.size()-1;
- }
-
- }
- }
-
-
-
- if (completion_options.size()==0) {
- //no options to complete, cancel
- _cancel_completion();
- return;
-
- }
-
- completion_current=completion_options[completion_index];
+void TextEdit::_update_completion_candidates() {
+
+ String l = text[cursor.line];
+ int cofs = CLAMP(cursor.column,0,l.length());
+
+
+ String s;
+
+ //look for keywords first
+
+ bool pre_keyword=false;
+
+ if (cofs>0 && l[cofs-1]==' ') {
+ int kofs=cofs-1;
+ String kw;
+ while (kofs>=0 && l[kofs]==' ')
+ kofs--;
+
+ while(kofs>=0 && l[kofs]>32 && _is_completable(l[kofs])) {
+ kw=String::chr(l[kofs])+kw;
+ kofs--;
+ }
+
+ pre_keyword=keywords.has(kw);
+ print_line("KW "+kw+"? "+itos(pre_keyword));
+
+ } else {
+
+
+ while(cofs>0 && l[cofs-1]>32 && _is_completable(l[cofs-1])) {
+ s=String::chr(l[cofs-1])+s;
+ if (l[cofs-1]=='\'' || l[cofs-1]=='"')
+ break;
+
+ cofs--;
+ }
+ }
+
+
+ update();
+
+ if (!pre_keyword && s=="" && (cofs==0 || !completion_prefixes.has(String::chr(l[cofs-1])))) {
+ //none to complete, cancel
+ _cancel_completion();
+ return;
+ }
+
+ completion_options.clear();
+ completion_index=0;
+ completion_base=s;
+ int ci_match=0;
+ for(int i=0;i<completion_strings.size();i++) {
+ if (completion_strings[i].begins_with(s)) {
+ completion_options.push_back(completion_strings[i]);
+ int m=0;
+ int max=MIN(completion_current.length(),completion_strings[i].length());
+ if (max<ci_match)
+ continue;
+ for(int j=0;j<max;j++) {
+
+ if (j>=completion_strings[i].length())
+ break;
+ if (completion_current[j]!=completion_strings[i][j])
+ break;
+ m++;
+ }
+ if (m>ci_match) {
+ ci_match=m;
+ completion_index=completion_options.size()-1;
+ }
+
+ }
+ }
+
+
+
+ if (completion_options.size()==0) {
+ //no options to complete, cancel
+ _cancel_completion();
+ return;
+
+ }
+
+ completion_current=completion_options[completion_index];
+
#if 0 // even there's only one option, user still get the chance to choose using it or not
- if (completion_options.size()==1) {
- //one option to complete, just complete it automagically
- _confirm_completion();
-// insert_text_at_cursor(completion_options[0].substr(s.length(),completion_options[0].length()-s.length()));
- _cancel_completion();
- return;
-
- }
+ if (completion_options.size()==1) {
+ //one option to complete, just complete it automagically
+ _confirm_completion();
+ // insert_text_at_cursor(completion_options[0].substr(s.length(),completion_options[0].length()-s.length()));
+ _cancel_completion();
+ return;
+
+ }
#endif
- if (completion_options.size()==1 && s==completion_options[0])
- _cancel_completion();
-
- completion_enabled=true;
+ if (completion_options.size()==1 && s==completion_options[0])
+ _cancel_completion();
+
+ completion_enabled=true;
}
-void TextEdit::query_code_comple() {
-
- String l = text[cursor.line];
- int ofs = CLAMP(cursor.column,0,l.length());
- String cs;
- while(ofs>0 && l[ofs-1]>32) {
- if (_is_symbol(l[ofs-1])) {
- String s;
- while(ofs>0 && l[ofs-1]>32 && _is_symbol(l[ofs-1])) {
- s=String::chr(l[ofs-1])+s;
- ofs--;
- }
- if (completion_prefixes.has(s))
- cs=s+cs;
- else
- break;
- } else {
- cs=String::chr(l[ofs-1])+cs;
- ofs--;
- }
-
- }
-
- if (cs!="") {
- emit_signal("request_completion",cs,cursor.line);
+void TextEdit::query_code_comple() {
+
+ String l = text[cursor.line];
+ int ofs = CLAMP(cursor.column,0,l.length());
+
+ if (ofs>0 && (_is_completable(l[ofs-1]) || completion_prefixes.has(String::chr(l[ofs-1]))))
+ emit_signal("request_completion");
+
+}
- }
+void TextEdit::set_code_hint(const String& p_hint) {
+
+ completion_hint=p_hint;
+ completion_hint_offset=-0xFFFF;
+ update();
}
void TextEdit::code_complete(const Vector<String> &p_strings) {
-
-
- completion_strings=p_strings;
- completion_active=true;
- completion_current="";
- completion_index=0;
- _update_completion_candidates();
-//
+
+
+ completion_strings=p_strings;
+ completion_active=true;
+ completion_current="";
+ completion_index=0;
+ _update_completion_candidates();
+ //
}
String TextEdit::get_tooltip(const Point2& p_pos) const {
-
- if (!tooltip_obj)
- return Control::get_tooltip(p_pos);
- int row,col;
- if (!_get_mouse_pos(p_pos, row,col)) {
- return Control::get_tooltip(p_pos);
- }
-
- String s = text[row];
- if (s.length()==0)
- return Control::get_tooltip(p_pos);
- int beg=CLAMP(col,0,s.length());
- int end=beg;
-
-
- if (s[beg]>32 || beg==s.length()) {
-
- bool symbol = beg < s.length() && _is_symbol(s[beg]); //not sure if right but most editors behave like this
-
- while(beg>0 && s[beg-1]>32 && (symbol==_is_symbol(s[beg-1]))) {
- beg--;
- }
- while(end<s.length() && s[end+1]>32 && (symbol==_is_symbol(s[end+1]))) {
- end++;
- }
-
- if (end<s.length())
- end+=1;
-
- String tt = tooltip_obj->call(tooltip_func,s.substr(beg,end-beg),tooltip_ud);
-
- return tt;
-
- }
-
- return Control::get_tooltip(p_pos);
-
+
+ if (!tooltip_obj)
+ return Control::get_tooltip(p_pos);
+ int row,col;
+ if (!_get_mouse_pos(p_pos, row,col)) {
+ return Control::get_tooltip(p_pos);
+ }
+
+ String s = text[row];
+ if (s.length()==0)
+ return Control::get_tooltip(p_pos);
+ int beg=CLAMP(col,0,s.length());
+ int end=beg;
+
+
+ if (s[beg]>32 || beg==s.length()) {
+
+ bool symbol = beg < s.length() && _is_symbol(s[beg]); //not sure if right but most editors behave like this
+
+ while(beg>0 && s[beg-1]>32 && (symbol==_is_symbol(s[beg-1]))) {
+ beg--;
+ }
+ while(end<s.length() && s[end+1]>32 && (symbol==_is_symbol(s[end+1]))) {
+ end++;
+ }
+
+ if (end<s.length())
+ end+=1;
+
+ String tt = tooltip_obj->call(tooltip_func,s.substr(beg,end-beg),tooltip_ud);
+
+ return tt;
+
+ }
+
+ return Control::get_tooltip(p_pos);
+
}
void TextEdit::set_tooltip_request_func(Object *p_obj, const StringName& p_function,const Variant& p_udata) {
-
- tooltip_obj=p_obj;
- tooltip_func=p_function;
- tooltip_ud=p_udata;
+
+ tooltip_obj=p_obj;
+ tooltip_func=p_function;
+ tooltip_ud=p_udata;
}
void TextEdit::set_line(int line, String new_text)
{
- if (line < 0 || line > text.size())
- return;
- _remove_text(line, 0, line, text[line].length());
- _insert_text(line, 0, new_text);
+ if (line < 0 || line > text.size())
+ return;
+ _remove_text(line, 0, line, text[line].length());
+ _insert_text(line, 0, new_text);
}
void TextEdit::insert_at(const String &p_text, int at)
@@ -3162,165 +3469,167 @@ void TextEdit::insert_at(const String &p_text, int at)
}
void TextEdit::set_show_line_numbers(bool p_show) {
-
- line_numbers=p_show;
- update();
+
+ line_numbers=p_show;
+ update();
}
void TextEdit::_bind_methods() {
-
-
- ObjectTypeDB::bind_method(_MD("_input_event"),&TextEdit::_input_event);
- ObjectTypeDB::bind_method(_MD("_scroll_moved"),&TextEdit::_scroll_moved);
- ObjectTypeDB::bind_method(_MD("_cursor_changed_emit"),&TextEdit::_cursor_changed_emit);
- ObjectTypeDB::bind_method(_MD("_text_changed_emit"),&TextEdit::_text_changed_emit);
- ObjectTypeDB::bind_method(_MD("_push_current_op"),&TextEdit::_push_current_op);
-
- BIND_CONSTANT( SEARCH_MATCH_CASE );
- BIND_CONSTANT( SEARCH_WHOLE_WORDS );
- BIND_CONSTANT( SEARCH_BACKWARDS );
-
-/*
+
+
+ ObjectTypeDB::bind_method(_MD("_input_event"),&TextEdit::_input_event);
+ ObjectTypeDB::bind_method(_MD("_scroll_moved"),&TextEdit::_scroll_moved);
+ ObjectTypeDB::bind_method(_MD("_cursor_changed_emit"),&TextEdit::_cursor_changed_emit);
+ ObjectTypeDB::bind_method(_MD("_text_changed_emit"),&TextEdit::_text_changed_emit);
+ ObjectTypeDB::bind_method(_MD("_push_current_op"),&TextEdit::_push_current_op);
+
+ BIND_CONSTANT( SEARCH_MATCH_CASE );
+ BIND_CONSTANT( SEARCH_WHOLE_WORDS );
+ BIND_CONSTANT( SEARCH_BACKWARDS );
+
+ /*
ObjectTypeDB::bind_method(_MD("delete_char"),&TextEdit::delete_char);
ObjectTypeDB::bind_method(_MD("delete_line"),&TextEdit::delete_line);
*/
-
- ObjectTypeDB::bind_method(_MD("set_text","text"),&TextEdit::set_text);
- ObjectTypeDB::bind_method(_MD("insert_text_at_cursor","text"),&TextEdit::insert_text_at_cursor);
-
- ObjectTypeDB::bind_method(_MD("get_line_count"),&TextEdit::get_line_count);
- ObjectTypeDB::bind_method(_MD("get_text"),&TextEdit::get_text);
- ObjectTypeDB::bind_method(_MD("get_line"),&TextEdit::get_line);
-
- ObjectTypeDB::bind_method(_MD("cursor_set_column","column"),&TextEdit::cursor_set_column);
- ObjectTypeDB::bind_method(_MD("cursor_set_line","line"),&TextEdit::cursor_set_line);
-
- ObjectTypeDB::bind_method(_MD("cursor_get_column"),&TextEdit::cursor_get_column);
- ObjectTypeDB::bind_method(_MD("cursor_get_line"),&TextEdit::cursor_get_line);
-
-
- ObjectTypeDB::bind_method(_MD("set_readonly","enable"),&TextEdit::set_readonly);
- ObjectTypeDB::bind_method(_MD("set_wrap","enable"),&TextEdit::set_wrap);
- ObjectTypeDB::bind_method(_MD("set_max_chars","amount"),&TextEdit::set_max_chars);
-
- ObjectTypeDB::bind_method(_MD("cut"),&TextEdit::cut);
- ObjectTypeDB::bind_method(_MD("copy"),&TextEdit::copy);
- ObjectTypeDB::bind_method(_MD("paste"),&TextEdit::paste);
- ObjectTypeDB::bind_method(_MD("select_all"),&TextEdit::select_all);
- ObjectTypeDB::bind_method(_MD("select","from_line","from_column","to_line","to_column"),&TextEdit::select);
-
- ObjectTypeDB::bind_method(_MD("is_selection_active"),&TextEdit::is_selection_active);
- ObjectTypeDB::bind_method(_MD("get_selection_from_line"),&TextEdit::get_selection_from_line);
- ObjectTypeDB::bind_method(_MD("get_selection_from_column"),&TextEdit::get_selection_from_column);
- ObjectTypeDB::bind_method(_MD("get_selection_to_line"),&TextEdit::get_selection_to_line);
- ObjectTypeDB::bind_method(_MD("get_selection_to_column"),&TextEdit::get_selection_to_column);
- ObjectTypeDB::bind_method(_MD("get_selection_text"),&TextEdit::get_selection_text);
- ObjectTypeDB::bind_method(_MD("get_word_under_cursor"),&TextEdit::get_word_under_cursor);
- ObjectTypeDB::bind_method(_MD("search","flags","from_line","from_column","to_line","to_column"),&TextEdit::_search_bind);
-
- ObjectTypeDB::bind_method(_MD("undo"),&TextEdit::undo);
- ObjectTypeDB::bind_method(_MD("redo"),&TextEdit::redo);
- ObjectTypeDB::bind_method(_MD("clear_undo_history"),&TextEdit::clear_undo_history);
-
- ObjectTypeDB::bind_method(_MD("set_syntax_coloring","enable"),&TextEdit::set_syntax_coloring);
- ObjectTypeDB::bind_method(_MD("is_syntax_coloring_enabled"),&TextEdit::is_syntax_coloring_enabled);
-
-
- ObjectTypeDB::bind_method(_MD("add_keyword_color","keyword","color"),&TextEdit::add_keyword_color);
- ObjectTypeDB::bind_method(_MD("add_color_region","begin_key","end_key","color","line_only"),&TextEdit::add_color_region,DEFVAL(false));
- ObjectTypeDB::bind_method(_MD("set_symbol_color","color"),&TextEdit::set_symbol_color);
- ObjectTypeDB::bind_method(_MD("set_custom_bg_color","color"),&TextEdit::set_custom_bg_color);
- ObjectTypeDB::bind_method(_MD("clear_colors"),&TextEdit::clear_colors);
-
-
- ADD_SIGNAL(MethodInfo("cursor_changed"));
- ADD_SIGNAL(MethodInfo("text_changed"));
- ADD_SIGNAL(MethodInfo("request_completion",PropertyInfo(Variant::STRING,"keyword"),PropertyInfo(Variant::INT,"line")));
-
+
+ ObjectTypeDB::bind_method(_MD("set_text","text"),&TextEdit::set_text);
+ ObjectTypeDB::bind_method(_MD("insert_text_at_cursor","text"),&TextEdit::insert_text_at_cursor);
+
+ ObjectTypeDB::bind_method(_MD("get_line_count"),&TextEdit::get_line_count);
+ ObjectTypeDB::bind_method(_MD("get_text"),&TextEdit::get_text);
+ ObjectTypeDB::bind_method(_MD("get_line"),&TextEdit::get_line);
+
+ ObjectTypeDB::bind_method(_MD("cursor_set_column","column"),&TextEdit::cursor_set_column);
+ ObjectTypeDB::bind_method(_MD("cursor_set_line","line"),&TextEdit::cursor_set_line);
+
+ ObjectTypeDB::bind_method(_MD("cursor_get_column"),&TextEdit::cursor_get_column);
+ ObjectTypeDB::bind_method(_MD("cursor_get_line"),&TextEdit::cursor_get_line);
+
+
+ ObjectTypeDB::bind_method(_MD("set_readonly","enable"),&TextEdit::set_readonly);
+ ObjectTypeDB::bind_method(_MD("set_wrap","enable"),&TextEdit::set_wrap);
+ ObjectTypeDB::bind_method(_MD("set_max_chars","amount"),&TextEdit::set_max_chars);
+
+ ObjectTypeDB::bind_method(_MD("cut"),&TextEdit::cut);
+ ObjectTypeDB::bind_method(_MD("copy"),&TextEdit::copy);
+ ObjectTypeDB::bind_method(_MD("paste"),&TextEdit::paste);
+ ObjectTypeDB::bind_method(_MD("select_all"),&TextEdit::select_all);
+ ObjectTypeDB::bind_method(_MD("select","from_line","from_column","to_line","to_column"),&TextEdit::select);
+
+ ObjectTypeDB::bind_method(_MD("is_selection_active"),&TextEdit::is_selection_active);
+ ObjectTypeDB::bind_method(_MD("get_selection_from_line"),&TextEdit::get_selection_from_line);
+ ObjectTypeDB::bind_method(_MD("get_selection_from_column"),&TextEdit::get_selection_from_column);
+ ObjectTypeDB::bind_method(_MD("get_selection_to_line"),&TextEdit::get_selection_to_line);
+ ObjectTypeDB::bind_method(_MD("get_selection_to_column"),&TextEdit::get_selection_to_column);
+ ObjectTypeDB::bind_method(_MD("get_selection_text"),&TextEdit::get_selection_text);
+ ObjectTypeDB::bind_method(_MD("get_word_under_cursor"),&TextEdit::get_word_under_cursor);
+ ObjectTypeDB::bind_method(_MD("search","flags","from_line","from_column","to_line","to_column"),&TextEdit::_search_bind);
+
+ ObjectTypeDB::bind_method(_MD("undo"),&TextEdit::undo);
+ ObjectTypeDB::bind_method(_MD("redo"),&TextEdit::redo);
+ ObjectTypeDB::bind_method(_MD("clear_undo_history"),&TextEdit::clear_undo_history);
+
+ ObjectTypeDB::bind_method(_MD("set_syntax_coloring","enable"),&TextEdit::set_syntax_coloring);
+ ObjectTypeDB::bind_method(_MD("is_syntax_coloring_enabled"),&TextEdit::is_syntax_coloring_enabled);
+
+
+ ObjectTypeDB::bind_method(_MD("add_keyword_color","keyword","color"),&TextEdit::add_keyword_color);
+ ObjectTypeDB::bind_method(_MD("add_color_region","begin_key","end_key","color","line_only"),&TextEdit::add_color_region,DEFVAL(false));
+ ObjectTypeDB::bind_method(_MD("set_symbol_color","color"),&TextEdit::set_symbol_color);
+ ObjectTypeDB::bind_method(_MD("set_custom_bg_color","color"),&TextEdit::set_custom_bg_color);
+ ObjectTypeDB::bind_method(_MD("clear_colors"),&TextEdit::clear_colors);
+
+
+ ADD_SIGNAL(MethodInfo("cursor_changed"));
+ ADD_SIGNAL(MethodInfo("text_changed"));
+ ADD_SIGNAL(MethodInfo("request_completion"));
+
}
TextEdit::TextEdit() {
-
- readonly=false;
- setting_row=false;
- draw_tabs=false;
- max_chars=0;
- clear();
- wrap=false;
- set_focus_mode(FOCUS_ALL);
- _update_caches();
- cache.size=Size2(1,1);
- tab_size=4;
- text.set_tab_size(tab_size);
- text.clear();
-// text.insert(1,"Mongolia..");
-// text.insert(2,"PAIS GENEROSO!!");
- text.set_color_regions(&color_regions);
-
- h_scroll = memnew( HScrollBar );
- v_scroll = memnew( VScrollBar );
-
- add_child(h_scroll);
- add_child(v_scroll);
-
- updating_scrolls=false;
- selection.active=false;
-
- h_scroll->connect("value_changed", this,"_scroll_moved");
- v_scroll->connect("value_changed", this,"_scroll_moved");
-
- cursor_changed_dirty=false;
- text_changed_dirty=false;
-
- selection.selecting_mode=Selection::MODE_NONE;
- selection.selecting_line=0;
- selection.selecting_column=0;
- selection.selecting_test=false;
- selection.active=false;
- syntax_coloring=false;
-
- custom_bg_color=Color(0,0,0,0);
- idle_detect = memnew( Timer );
- add_child(idle_detect);
- idle_detect->set_one_shot(true);
- idle_detect->set_wait_time(GLOBAL_DEF("display/text_edit_idle_detect_sec",3));
- idle_detect->connect("timeout", this,"_push_current_op");
-
+
+ readonly=false;
+ setting_row=false;
+ draw_tabs=false;
+ max_chars=0;
+ clear();
+ wrap=false;
+ set_focus_mode(FOCUS_ALL);
+ _update_caches();
+ cache.size=Size2(1,1);
+ tab_size=4;
+ text.set_tab_size(tab_size);
+ text.clear();
+ // text.insert(1,"Mongolia..");
+ // text.insert(2,"PAIS GENEROSO!!");
+ text.set_color_regions(&color_regions);
+
+ h_scroll = memnew( HScrollBar );
+ v_scroll = memnew( VScrollBar );
+
+ add_child(h_scroll);
+ add_child(v_scroll);
+
+ updating_scrolls=false;
+ selection.active=false;
+
+ h_scroll->connect("value_changed", this,"_scroll_moved");
+ v_scroll->connect("value_changed", this,"_scroll_moved");
+
+ cursor_changed_dirty=false;
+ text_changed_dirty=false;
+
+ selection.selecting_mode=Selection::MODE_NONE;
+ selection.selecting_line=0;
+ selection.selecting_column=0;
+ selection.selecting_test=false;
+ selection.active=false;
+ syntax_coloring=false;
+
+ custom_bg_color=Color(0,0,0,0);
+ idle_detect = memnew( Timer );
+ add_child(idle_detect);
+ idle_detect->set_one_shot(true);
+ idle_detect->set_wait_time(GLOBAL_DEF("display/text_edit_idle_detect_sec",3));
+ idle_detect->connect("timeout", this,"_push_current_op");
+
#if 0
- syntax_coloring=true;
- keywords["void"]=Color(0.3,0.0,0.1);
- keywords["int"]=Color(0.3,0.0,0.1);
- keywords["function"]=Color(0.3,0.0,0.1);
- keywords["class"]=Color(0.3,0.0,0.1);
- keywords["extends"]=Color(0.3,0.0,0.1);
- keywords["constructor"]=Color(0.3,0.0,0.1);
- symbol_color=Color(0.1,0.0,0.3,1.0);
-
- color_regions.push_back(ColorRegion("/*","*/",Color(0.4,0.6,0,4)));
- color_regions.push_back(ColorRegion("//","",Color(0.6,0.6,0.4)));
- color_regions.push_back(ColorRegion("\"","\"",Color(0.4,0.7,0.7)));
- color_regions.push_back(ColorRegion("'","'",Color(0.4,0.8,0.8)));
- color_regions.push_back(ColorRegion("#","",Color(0.2,1.0,0.2)));
-
+ syntax_coloring=true;
+ keywords["void"]=Color(0.3,0.0,0.1);
+ keywords["int"]=Color(0.3,0.0,0.1);
+ keywords["function"]=Color(0.3,0.0,0.1);
+ keywords["class"]=Color(0.3,0.0,0.1);
+ keywords["extends"]=Color(0.3,0.0,0.1);
+ keywords["constructor"]=Color(0.3,0.0,0.1);
+ symbol_color=Color(0.1,0.0,0.3,1.0);
+
+ color_regions.push_back(ColorRegion("/*","*/",Color(0.4,0.6,0,4)));
+ color_regions.push_back(ColorRegion("//","",Color(0.6,0.6,0.4)));
+ color_regions.push_back(ColorRegion("\"","\"",Color(0.4,0.7,0.7)));
+ color_regions.push_back(ColorRegion("'","'",Color(0.4,0.8,0.8)));
+ color_regions.push_back(ColorRegion("#","",Color(0.2,1.0,0.2)));
+
#endif
-
- current_op.type=TextOperation::TYPE_NONE;
- undo_enabled=true;
- undo_stack_pos=NULL;
- setting_text=false;
- last_dblclk=0;
- current_op.version=0;
- version=0;
- saved_version=0;
-
- completion_enabled=false;
- completion_active=false;
- completion_line_ofs=0;
- tooltip_obj=NULL;
- line_numbers=false;
- next_operation_is_complex=false;
- auto_brace_completion_enabled=false;
+
+ current_op.type=TextOperation::TYPE_NONE;
+ undo_enabled=true;
+ undo_stack_pos=NULL;
+ setting_text=false;
+ last_dblclk=0;
+ current_op.version=0;
+ version=0;
+ saved_version=0;
+
+ completion_enabled=false;
+ completion_active=false;
+ completion_line_ofs=0;
+ tooltip_obj=NULL;
+ line_numbers=false;
+ next_operation_is_complex=false;
+ auto_brace_completion_enabled=false;
+ brace_matching_enabled=false;
+
}
TextEdit::~TextEdit()
diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h
index d70403a944..1d57aef416 100644
--- a/scene/gui/text_edit.h
+++ b/scene/gui/text_edit.h
@@ -63,6 +63,7 @@ class TextEdit : public Control {
int from_line,from_column;
int to_line,to_column;
+ bool shiftclick_left;
} selection;
@@ -79,6 +80,7 @@ class TextEdit : public Control {
Color mark_color;
Color breakpoint_color;
Color current_line_color;
+ Color brace_mismatch_color;
int row_height;
int line_spacing;
@@ -185,6 +187,8 @@ class TextEdit : public Control {
int completion_index;
Rect2i completion_rect;
int completion_line_ofs;
+ String completion_hint;
+ int completion_hint_offset;
bool setting_text;
@@ -208,6 +212,7 @@ class TextEdit : public Control {
bool line_numbers;
bool auto_brace_completion_enabled;
+ bool brace_matching_enabled;
bool cut_copy_line;
uint64_t last_dblclk;
@@ -261,6 +266,7 @@ class TextEdit : public Control {
void _clear();
void _cancel_completion();
+ void _cancel_code_hint();
void _confirm_completion();
void _update_completion_candidates();
@@ -313,7 +319,11 @@ public:
inline void set_auto_brace_completion(bool p_enabled) {
auto_brace_completion_enabled = p_enabled;
}
-
+ inline void set_brace_matching(bool p_enabled) {
+ brace_matching_enabled=p_enabled;
+ update();
+ }
+
void cursor_set_column(int p_col);
void cursor_set_line(int p_row);
@@ -350,7 +360,7 @@ public:
void undo();
void redo();
- void clear_undo_history();
+ void clear_undo_history();
void set_draw_tabs(bool p_draw);
@@ -376,10 +386,13 @@ public:
void set_tooltip_request_func(Object *p_obj, const StringName& p_function, const Variant& p_udata);
- void set_completion(bool p_enabled,const Vector<String>& p_prefixes);
+ void set_completion(bool p_enabled,const Vector<String>& p_prefixes);
void code_complete(const Vector<String> &p_strings);
+ void set_code_hint(const String& p_hint);
void query_code_comple();
+ String get_text_for_completion();
+
TextEdit();
~TextEdit();
};
diff --git a/scene/gui/texture_button.cpp b/scene/gui/texture_button.cpp
index 7954ac65df..1a7087b7ef 100644
--- a/scene/gui/texture_button.cpp
+++ b/scene/gui/texture_button.cpp
@@ -31,28 +31,37 @@
Size2 TextureButton::get_minimum_size() const {
+ Size2 rscale;
if (normal.is_null()) {
if (pressed.is_null()) {
if (hover.is_null())
if (click_mask.is_null())
- return Size2();
+ rscale= Size2();
else
- return click_mask->get_size();
+ rscale= click_mask->get_size();
else
- return hover->get_size();
+ rscale= hover->get_size();
} else
- return pressed->get_size();
+ rscale= pressed->get_size()*scale;
} else
- return normal->get_size();
+ rscale= normal->get_size();
+
+ return rscale*scale;
}
bool TextureButton::has_point(const Point2& p_point) const {
+ if (scale[0] <= 0 || scale[1] <= 0) {
+ return false;
+ }
+
+ Point2 ppos = p_point/scale;
+
if (click_mask.is_valid()) {
- Point2i p =p_point;
+ Point2i p =ppos;
if (p.x<0 || p.x>=click_mask->get_size().width || p.y<0 || p.y>=click_mask->get_size().height)
return false;
@@ -71,46 +80,57 @@ void TextureButton::_notification(int p_what) {
DrawMode draw_mode = get_draw_mode();
// if (normal.is_null())
// break;
+
+ Ref<Texture> texdraw;
+
switch (draw_mode) {
case DRAW_NORMAL: {
if (normal.is_valid())
- normal->draw(canvas_item,Point2());
+ texdraw=normal;
} break;
case DRAW_PRESSED: {
if (pressed.is_null()) {
if (hover.is_null()) {
if (normal.is_valid())
- normal->draw(canvas_item,Point2());
+ texdraw=normal;
} else
- hover->draw(canvas_item,Point2());
+ texdraw=hover;
} else
- pressed->draw(canvas_item,Point2());
+ texdraw=pressed;
} break;
case DRAW_HOVER: {
if (hover.is_null()) {
if (pressed.is_valid() && is_pressed())
- pressed->draw(canvas_item,Point2());
+ texdraw=pressed;
else if (normal.is_valid())
- normal->draw(canvas_item,Point2());
+ texdraw=normal;
} else
- hover->draw(canvas_item,Point2());
+ texdraw=hover;
} break;
case DRAW_DISABLED: {
if (disabled.is_null()) {
if (normal.is_valid())
- normal->draw(canvas_item,Point2());
+ texdraw=normal;
} else
- disabled->draw(canvas_item,Point2());
+ texdraw=disabled;
} break;
}
+
+ if (texdraw.is_valid()) {
+ Rect2 drect(Point2(),texdraw->get_size()*scale);
+ draw_texture_rect(texdraw,drect,false,modulate);
+
+ }
if (has_focus() && focused.is_valid()) {
- focused->draw(canvas_item, Point2());
+ Rect2 drect(Point2(),focused->get_size()*scale);
+ draw_texture_rect(focused,drect,false,modulate);
+
};
} break;
@@ -125,6 +145,8 @@ void TextureButton::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_disabled_texture","texture:Texture"),&TextureButton::set_disabled_texture);
ObjectTypeDB::bind_method(_MD("set_focused_texture","texture:Texture"),&TextureButton::set_focused_texture);
ObjectTypeDB::bind_method(_MD("set_click_mask","mask:BitMap"),&TextureButton::set_click_mask);
+ ObjectTypeDB::bind_method(_MD("set_scale","scale"),&TextureButton::set_scale);
+ ObjectTypeDB::bind_method(_MD("set_modulate","color"),&TextureButton::set_modulate);
ObjectTypeDB::bind_method(_MD("get_normal_texture:Texture"),&TextureButton::get_normal_texture);
ObjectTypeDB::bind_method(_MD("get_pressed_texture:Texture"),&TextureButton::get_pressed_texture);
@@ -132,6 +154,8 @@ void TextureButton::_bind_methods() {
ObjectTypeDB::bind_method(_MD("get_disabled_texture:Texture"),&TextureButton::get_disabled_texture);
ObjectTypeDB::bind_method(_MD("get_focused_texture:Texture"),&TextureButton::get_focused_texture);
ObjectTypeDB::bind_method(_MD("get_click_mask:BitMap"),&TextureButton::get_click_mask);
+ ObjectTypeDB::bind_method(_MD("get_scale"),&TextureButton::get_scale);
+ ObjectTypeDB::bind_method(_MD("get_modulate"),&TextureButton::get_modulate);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT,"textures/normal",PROPERTY_HINT_RESOURCE_TYPE,"Texture"), _SCS("set_normal_texture"), _SCS("get_normal_texture"));
ADD_PROPERTY(PropertyInfo(Variant::OBJECT,"textures/pressed",PROPERTY_HINT_RESOURCE_TYPE,"Texture"), _SCS("set_pressed_texture"), _SCS("get_pressed_texture"));
@@ -139,6 +163,8 @@ void TextureButton::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::OBJECT,"textures/disabled",PROPERTY_HINT_RESOURCE_TYPE,"Texture"), _SCS("set_disabled_texture"), _SCS("get_disabled_texture"));
ADD_PROPERTY(PropertyInfo(Variant::OBJECT,"textures/focused",PROPERTY_HINT_RESOURCE_TYPE,"Texture"), _SCS("set_focused_texture"), _SCS("get_focused_texture"));
ADD_PROPERTY(PropertyInfo(Variant::OBJECT,"textures/click_mask",PROPERTY_HINT_RESOURCE_TYPE,"BitMap"), _SCS("set_click_mask"), _SCS("get_click_mask")) ;
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2,"params/scale",PROPERTY_HINT_RANGE,"0.01,1024,0.01"), _SCS("set_scale"), _SCS("get_scale"));
+ ADD_PROPERTY(PropertyInfo(Variant::COLOR,"params/modulate"), _SCS("set_modulate"), _SCS("get_modulate"));
}
@@ -206,6 +232,29 @@ void TextureButton::set_focused_texture(const Ref<Texture>& p_focused) {
focused = p_focused;
};
+void TextureButton::set_scale(Size2 p_scale) {
+
+ scale=p_scale;
+ minimum_size_changed();
+ update();
+}
+
+Size2 TextureButton::get_scale() const{
+
+ return scale;
+}
+
+void TextureButton::set_modulate(const Color& p_modulate) {
+ modulate=p_modulate;
+ update();
+}
+
+Color TextureButton::get_modulate() const {
+ return modulate;
+}
+
TextureButton::TextureButton() {
+ scale=Size2(1.0, 1.0);
+ modulate=Color(1,1,1);
}
diff --git a/scene/gui/texture_button.h b/scene/gui/texture_button.h
index d186966cb1..94bc53b3ff 100644
--- a/scene/gui/texture_button.h
+++ b/scene/gui/texture_button.h
@@ -41,6 +41,8 @@ class TextureButton : public BaseButton {
Ref<Texture> disabled;
Ref<Texture> focused;
Ref<BitMap> click_mask;
+ Size2 scale;
+ Color modulate;
protected:
@@ -66,6 +68,11 @@ public:
Ref<Texture> get_focused_texture() const;
Ref<BitMap> get_click_mask() const;
+ void set_scale(Size2 p_scale);
+ Size2 get_scale() const;
+
+ void set_modulate(const Color& p_modulate);
+ Color get_modulate() const;
TextureButton();
};
diff --git a/scene/main/node.cpp b/scene/main/node.cpp
index 45a30d7bca..fbdc87a7cc 100644
--- a/scene/main/node.cpp
+++ b/scene/main/node.cpp
@@ -382,6 +382,8 @@ bool Node::can_process() const {
if (get_tree()->is_paused()) {
+ if (data.pause_mode==PAUSE_MODE_STOP)
+ return false;
if (data.pause_mode==PAUSE_MODE_PROCESS)
return true;
if (data.pause_mode==PAUSE_MODE_INHERIT) {
@@ -391,6 +393,9 @@ bool Node::can_process() const {
if (data.pause_owner->data.pause_mode==PAUSE_MODE_PROCESS)
return true;
+
+ if (data.pause_owner->data.pause_mode==PAUSE_MODE_STOP)
+ return false;
}
}
@@ -1731,6 +1736,26 @@ NodePath Node::get_import_path() const {
#endif
+static void _add_nodes_to_options(const Node *p_base,const Node *p_node,List<String>*r_options) {
+
+ if (p_node!=p_base && !p_node->get_owner())
+ return;
+ String n = p_base->get_path_to(p_node);
+ r_options->push_back("\""+n+"\"");
+ for(int i=0;i<p_node->get_child_count();i++) {
+ _add_nodes_to_options(p_base,p_node->get_child(i),r_options);
+ }
+}
+
+void Node::get_argument_options(const StringName& p_function,int p_idx,List<String>*r_options) const {
+
+ String pf=p_function;
+ if ((pf=="has_node" || pf=="get_node") && p_idx==0) {
+
+ _add_nodes_to_options(this,this,r_options);
+ }
+ Object::get_argument_options(p_function,p_idx,r_options);
+}
void Node::_bind_methods() {
diff --git a/scene/main/node.h b/scene/main/node.h
index 371a5325ca..47f49eb625 100644
--- a/scene/main/node.h
+++ b/scene/main/node.h
@@ -284,6 +284,7 @@ public:
NodePath get_import_path() const;
#endif
+ void get_argument_options(const StringName& p_function,int p_idx,List<String>*r_options) const;
_FORCE_INLINE_ Viewport *get_viewport() const { return data.viewport; }
diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp
index 741deccdbe..cf49979118 100644
--- a/scene/register_scene_types.cpp
+++ b/scene/register_scene_types.cpp
@@ -39,7 +39,6 @@
#include "scene/main/viewport.h"
#include "scene/gui/control.h"
#include "scene/gui/texture_progress.h"
-#include "scene/gui/empty_control.h"
#include "scene/gui/button.h"
#include "scene/gui/button_array.h"
#include "scene/gui/button_group.h"
@@ -75,6 +74,8 @@
#include "scene/gui/split_container.h"
#include "scene/gui/video_player.h"
#include "scene/gui/reference_frame.h"
+#include "scene/gui/graph_node.h"
+#include "scene/gui/graph_edit.h"
#include "scene/resources/video_stream.h"
#include "scene/2d/particles_2d.h"
#include "scene/2d/path_2d.h"
@@ -152,6 +153,8 @@
#include "scene/resources/mesh.h"
#include "scene/resources/room.h"
+#include "scene/resources/shader_graph.h"
+
#include "scene/resources/world.h"
#include "scene/resources/world_2d.h"
#include "scene/resources/volume.h"
@@ -268,7 +271,8 @@ void register_scene_types() {
OS::get_singleton()->yield(); //may take time to init
ObjectTypeDB::register_type<Control>();
- ObjectTypeDB::register_type<EmptyControl>();
+// ObjectTypeDB::register_type<EmptyControl>();
+ ObjectTypeDB::add_compatibility_type("EmptyControl","control");
ObjectTypeDB::register_type<Button>();
ObjectTypeDB::register_type<Label>();
ObjectTypeDB::register_type<HScrollBar>();
@@ -303,6 +307,8 @@ void register_scene_types() {
ObjectTypeDB::register_virtual_type<SplitContainer>();
ObjectTypeDB::register_type<HSplitContainer>();
ObjectTypeDB::register_type<VSplitContainer>();
+ ObjectTypeDB::register_type<GraphNode>();
+ ObjectTypeDB::register_type<GraphEdit>();
OS::get_singleton()->yield(); //may take time to init
@@ -494,11 +500,17 @@ void register_scene_types() {
ObjectTypeDB::register_type<Mesh>();
ObjectTypeDB::register_virtual_type<Material>();
ObjectTypeDB::register_type<FixedMaterial>();
- ObjectTypeDB::register_type<ParticleSystemMaterial>();
- ObjectTypeDB::register_type<UnshadedMaterial>();
+ //ObjectTypeDB::register_type<ParticleSystemMaterial>();
+ //ObjectTypeDB::register_type<UnshadedMaterial>();
ObjectTypeDB::register_type<ShaderMaterial>();
ObjectTypeDB::register_type<RoomBounds>();
- ObjectTypeDB::register_type<Shader>();
+ ObjectTypeDB::register_virtual_type<Shader>();
+ ObjectTypeDB::register_virtual_type<ShaderGraph>();
+ ObjectTypeDB::register_type<MaterialShaderGraph>();
+ ObjectTypeDB::register_type<MaterialShader>();
+ ObjectTypeDB::add_compatibility_type("Shader","MaterialShader");
+ ObjectTypeDB::add_compatibility_type("ParticleSystemMaterial","FixedMaterial");
+ ObjectTypeDB::add_compatibility_type("UnshadedMaterial","FixedMaterial");
ObjectTypeDB::register_type<MultiMesh>();
ObjectTypeDB::register_type<MeshLibrary>();
diff --git a/scene/resources/audio_stream_resampled.cpp b/scene/resources/audio_stream_resampled.cpp
index 8e694a6110..bc7bffa9d2 100644
--- a/scene/resources/audio_stream_resampled.cpp
+++ b/scene/resources/audio_stream_resampled.cpp
@@ -38,15 +38,18 @@ int AudioStreamResampled::get_channel_count() const {
template<int C>
-void AudioStreamResampled::_resample(int32_t *p_dest,int p_todo,int32_t p_increment) {
+uint32_t AudioStreamResampled::_resample(int32_t *p_dest,int p_todo,int32_t p_increment) {
+
+ uint32_t read=offset&MIX_FRAC_MASK;
for (int i=0;i<p_todo;i++) {
offset = (offset + p_increment)&(((1<<(rb_bits+MIX_FRAC_BITS))-1));
+ read+=p_increment;
uint32_t pos = offset >> MIX_FRAC_BITS;
uint32_t frac = offset & MIX_FRAC_MASK;
#ifndef FAST_AUDIO
- ERR_FAIL_COND(pos>=rb_len);
+ ERR_FAIL_COND_V(pos>=rb_len,0);
#endif
uint32_t pos_next = (pos+1)&rb_mask;
//printf("rb pos %i\n",pos);
@@ -151,7 +154,7 @@ void AudioStreamResampled::_resample(int32_t *p_dest,int p_todo,int32_t p_increm
}
- rb_read_pos=offset>>MIX_FRAC_BITS;
+ return read>>MIX_FRAC_BITS;//rb_read_pos=offset>>MIX_FRAC_BITS;
}
@@ -173,10 +176,10 @@ bool AudioStreamResampled::mix(int32_t *p_dest, int p_frames) {
} else if (rb_read_pos<write_pos_cache) {
- rb_todo=write_pos_cache-rb_read_pos-1;
+ rb_todo=write_pos_cache-rb_read_pos; //-1?
} else {
- rb_todo=(rb_len-rb_read_pos)+write_pos_cache-1;
+ rb_todo=(rb_len-rb_read_pos)+write_pos_cache; //-1?
}
int todo = MIN( ((int64_t(rb_todo)<<MIX_FRAC_BITS)/increment)+1, p_frames );
@@ -220,13 +223,22 @@ bool AudioStreamResampled::mix(int32_t *p_dest, int p_frames) {
#endif
{
+ uint32_t read=0;
switch(channels) {
- case 1: _resample<1>(p_dest,todo,increment); break;
- case 2: _resample<2>(p_dest,todo,increment); break;
- case 4: _resample<4>(p_dest,todo,increment); break;
- case 6: _resample<6>(p_dest,todo,increment); break;
+ case 1: read=_resample<1>(p_dest,todo,increment); break;
+ case 2: read=_resample<2>(p_dest,todo,increment); break;
+ case 4: read=_resample<4>(p_dest,todo,increment); break;
+ case 6: read=_resample<6>(p_dest,todo,increment); break;
}
+ if (read>rb_todo)
+ read=rb_todo;
+
+ rb_read_pos = (rb_read_pos+read)&rb_mask;
+
+
+
+
}
return true;
diff --git a/scene/resources/audio_stream_resampled.h b/scene/resources/audio_stream_resampled.h
index f1e3629ac7..a1b95e81d5 100644
--- a/scene/resources/audio_stream_resampled.h
+++ b/scene/resources/audio_stream_resampled.h
@@ -57,7 +57,7 @@ class AudioStreamResampled : public AudioStream {
template<int C>
- void _resample(int32_t *p_dest,int p_todo,int32_t p_increment);
+ uint32_t _resample(int32_t *p_dest,int p_todo,int32_t p_increment);
protected:
@@ -97,7 +97,7 @@ protected:
_FORCE_INLINE_ int16_t *get_write_buffer() { return read_buf; }
_FORCE_INLINE_ void write(uint32_t p_frames) {
- ERR_FAIL_COND(p_frames > rb_len);
+ ERR_FAIL_COND(p_frames >= rb_len);
switch(channels) {
case 1: {
diff --git a/scene/resources/curve.cpp b/scene/resources/curve.cpp
index ae2c07ff56..6c27ffc6d9 100644
--- a/scene/resources/curve.cpp
+++ b/scene/resources/curve.cpp
@@ -134,7 +134,7 @@ Vector2 Curve2D::interpolate(int p_index, float p_offset) const {
Vector2 Curve2D::interpolatef(real_t p_findex) const {
- if (p_findex>0)
+ if (p_findex<0)
p_findex=0;
else if (p_findex>=points.size())
p_findex=points.size();
@@ -485,7 +485,7 @@ Vector2 Curve2D::interpolate(int p_index, float p_offset) const {
Vector2 Curve2D::interpolatef(real_t p_findex) const {
- if (p_findex>0)
+ if (p_findex<0)
p_findex=0;
else if (p_findex>=points.size())
p_findex=points.size();
@@ -956,7 +956,7 @@ Vector3 Curve3D::interpolate(int p_index, float p_offset) const {
Vector3 Curve3D::interpolatef(real_t p_findex) const {
- if (p_findex>0)
+ if (p_findex<0)
p_findex=0;
else if (p_findex>=points.size())
p_findex=points.size();
diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp
index d10bb37f60..e7f0d9b1f5 100644
--- a/scene/resources/default_theme/default_theme.cpp
+++ b/scene/resources/default_theme/default_theme.cpp
@@ -65,7 +65,7 @@ static Ref<Texture> make_icon(T p_src) {
Ref<ImageTexture> texture( memnew( ImageTexture ) );
- texture->create_from_image( Image(p_src) );
+ texture->create_from_image( Image(p_src),ImageTexture::FLAG_FILTER );
return texture;
}
@@ -331,6 +331,7 @@ void make_default_theme() {
t->set_color("current_line_color","TextEdit", Color(0.3,0.5,0.8,0.15) );
t->set_color("cursor_color","TextEdit", control_font_color );
t->set_color("symbol_color","TextEdit", control_font_color_hover );
+ t->set_color("brace_mismatch_color","TextEdit", Color(1,0.2,0.2) );
t->set_constant("line_spacing","TextEdit",1 );
t->set_stylebox("scroll","HScrollBar", make_stylebox( hscroll_bg_png,3,3,3,3,0,0,0,0) );
@@ -415,7 +416,21 @@ void make_default_theme() {
t->set_color("font_color_hover","PopupMenu", control_font_color );
t->set_constant("hseparation","PopupMenu",2);
t->set_constant("vseparation","PopupMenu",1);
-
+
+ Ref<StyleBoxTexture> graphsb = make_stylebox(graph_node_png,6,24,6,5,16,24,16,5);
+ //graphsb->set_expand_margin_size(MARGIN_LEFT,10);
+ //graphsb->set_expand_margin_size(MARGIN_RIGHT,10);
+ t->set_stylebox("frame","GraphNode", graphsb );
+ t->set_constant("separation","GraphNode", 1 );
+ t->set_icon("port","GraphNode", make_icon( graph_port_png ) );
+ t->set_icon("close","GraphNode", make_icon( graph_node_close_png ) );
+ t->set_font("title_font","GraphNode", default_font );
+ t->set_color("title_color","GraphNode", Color(0,0,0,1));
+ t->set_constant("title_offset","GraphNode", 18);
+ t->set_constant("close_offset","GraphNode", 18);
+ t->set_constant("port_offset","GraphNode", 3);
+
+
t->set_stylebox("bg","Tree", make_stylebox( tree_bg_png,4,4,4,5,3,3,3,3) );
t->set_stylebox("bg_focus","Tree", focus );
Ref<StyleBoxTexture> tree_selected = make_stylebox( selection_png,4,4,4,4);
diff --git a/scene/resources/default_theme/graph_node.png b/scene/resources/default_theme/graph_node.png
new file mode 100644
index 0000000000..3adccf2c3b
--- /dev/null
+++ b/scene/resources/default_theme/graph_node.png
Binary files differ
diff --git a/scene/resources/default_theme/graph_node_close.png b/scene/resources/default_theme/graph_node_close.png
new file mode 100644
index 0000000000..ea5b510418
--- /dev/null
+++ b/scene/resources/default_theme/graph_node_close.png
Binary files differ
diff --git a/scene/resources/default_theme/graph_port.png b/scene/resources/default_theme/graph_port.png
new file mode 100644
index 0000000000..92f425f977
--- /dev/null
+++ b/scene/resources/default_theme/graph_port.png
Binary files differ
diff --git a/scene/resources/default_theme/theme_data.h b/scene/resources/default_theme/theme_data.h
index 9cef0265ee..a0f3dcd988 100644
--- a/scene/resources/default_theme/theme_data.h
+++ b/scene/resources/default_theme/theme_data.h
@@ -99,6 +99,21 @@ static const unsigned char full_panel_bg_png[]={
};
+static const unsigned char graph_node_png[]={
+0x89,0x50,0x4e,0x47,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0xd,0x49,0x48,0x44,0x52,0x0,0x0,0x0,0x10,0x0,0x0,0x0,0x40,0x8,0x6,0x0,0x0,0x0,0x13,0x7d,0xf7,0x96,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,0xde,0xc,0x14,0x10,0x3,0x2e,0x15,0xb6,0x7,0x4a,0x0,0x0,0x0,0x19,0x74,0x45,0x58,0x74,0x43,0x6f,0x6d,0x6d,0x65,0x6e,0x74,0x0,0x43,0x72,0x65,0x61,0x74,0x65,0x64,0x20,0x77,0x69,0x74,0x68,0x20,0x47,0x49,0x4d,0x50,0x57,0x81,0xe,0x17,0x0,0x0,0x2,0x6a,0x49,0x44,0x41,0x54,0x58,0xc3,0xed,0x97,0xbb,0x6e,0x13,0x51,0x10,0x86,0xbf,0xf1,0x2e,0xb1,0x83,0x85,0x63,0x5,0x10,0xe2,0x22,0xa5,0x0,0x1a,0x24,0x90,0x22,0x9e,0x81,0x2,0xd1,0x53,0xf1,0x2,0x20,0xa,0x1a,0xa,0xa0,0x44,0xd0,0xd0,0x20,0x81,0xe0,0x5,0xa8,0xe8,0x11,0x5,0xcf,0x80,0x22,0x81,0x42,0x3,0x14,0x91,0xb8,0x4,0x85,0x58,0x8e,0x21,0x78,0xd7,0xd9,0x73,0x86,0xe2,0x9c,0xdd,0xec,0xae,0xd7,0xce,0x85,0xe,0xed,0x34,0xbb,0x3a,0x3e,0xf3,0xcd,0xcc,0x3f,0x63,0x69,0x47,0xd8,0x36,0x1,0x1a,0x40,0xe0,0x9f,0x42,0xd1,0x14,0xb0,0x80,0xf1,0x4f,0x25,0x77,0xa9,0x1,0x1c,0x4,0xe6,0x81,0xa3,0x40,0x7,0x38,0x50,0x2,0x6c,0x1,0x3,0x60,0xd,0xe8,0x1,0x7f,0x0,0x9b,0x46,0x6d,0x3,0x67,0xe6,0xe,0x75,0xaf,0xb7,0x9a,0xad,0xcb,0x33,0x33,0xcd,0x53,0x54,0xd8,0x68,0x14,0x7f,0x89,0xe2,0xe8,0xf5,0xc6,0xaf,0xfe,0x73,0xe0,0x13,0xb0,0x29,0x3e,0xd2,0xc2,0x7c,0xf7,0xf0,0xe3,0xd3,0xb,0x67,0xaf,0x3c,0xb8,0xfb,0x88,0xd9,0x4e,0xab,0xca,0x9f,0xe1,0x20,0xe2,0xde,0xc3,0xdb,0x7c,0x5e,0xf9,0xf8,0xaa,0xd7,0x5f,0xbf,0x5,0xac,0x8,0xd0,0x2,0x16,0x8f,0x1f,0x3b,0xf9,0xe6,0xc5,0xb3,0x97,0xed,0x24,0xb1,0x24,0xa3,0xa4,0x12,0x10,0xce,0x84,0x84,0x61,0x83,0x6b,0x37,0xae,0x6e,0x7e,0xff,0xf1,0xf5,0x12,0xb0,0x14,0x7a,0x1d,0xda,0x61,0x10,0xb6,0x87,0xbf,0x63,0x10,0x75,0x47,0xa,0x2a,0x79,0x85,0x95,0x51,0xbc,0xc5,0x28,0x86,0x30,0x8,0xdb,0xbe,0x6c,0x49,0x1,0x1,0x80,0x51,0xeb,0xfc,0x9d,0xc0,0x4e,0x6b,0xf,0xd1,0xfc,0xb9,0xb3,0x20,0x5,0x68,0xfa,0x8b,0x5a,0x8b,0xaa,0x80,0x28,0x82,0xa0,0x28,0xa2,0x92,0x73,0xd3,0xb1,0xde,0x86,0x85,0x46,0x5b,0x45,0x51,0x50,0x45,0xc4,0x95,0x61,0x53,0x27,0x71,0x61,0x74,0x1a,0xc0,0xaa,0xcd,0x6e,0xa8,0x64,0x2f,0xee,0x5d,0x29,0x8a,0x32,0x39,0x3,0x5f,0xb6,0x2f,0x4c,0x45,0x73,0x5a,0xd8,0x31,0x48,0x1,0x60,0xac,0x2d,0xf1,0x5,0x51,0x75,0x45,0x68,0x5a,0xbf,0x4e,0xcf,0x60,0xfb,0x82,0x2b,0x5a,0x73,0x4e,0xb6,0xe2,0xf,0x52,0x2,0xd8,0x82,0xe2,0x14,0x50,0x54,0xc4,0x2f,0x8b,0x68,0xad,0x1f,0x99,0x54,0x79,0x41,0xdd,0x0,0xf8,0xb6,0x82,0x88,0x4e,0xeb,0x82,0x66,0x89,0xaa,0x3b,0xc8,0x52,0x48,0x41,0x56,0x76,0xcc,0x60,0x7b,0x74,0x75,0xac,0x1a,0x49,0x47,0x72,0x72,0x6,0xe2,0xe7,0x56,0x45,0xfd,0x5d,0xc9,0x44,0x28,0x40,0x2b,0x45,0x34,0xea,0x7,0xa8,0x14,0xc9,0x92,0x75,0x64,0x7,0x11,0x8d,0x8f,0x98,0x9b,0x87,0xf2,0xf4,0x4d,0xd5,0x40,0xd5,0xc9,0x97,0xf,0xa3,0x5a,0x74,0x9c,0x36,0x89,0xf7,0x9f,0xdc,0x61,0xaf,0x96,0x1,0x92,0x2d,0xc3,0xe2,0xf9,0x8b,0xbb,0x72,0x5a,0x7a,0xff,0xb6,0x3a,0x83,0x8d,0x41,0x7f,0xcf,0x19,0x34,0xf8,0x47,0xab,0x1,0x35,0xa0,0x6,0xd4,0x80,0x1a,0x50,0x3,0x6a,0xc0,0x7f,0x9,0x90,0x8a,0x4f,0xe0,0x3d,0x67,0x60,0xf7,0xe1,0x6b,0x53,0x80,0x5,0x22,0x63,0x4c,0x6c,0x93,0x5d,0x78,0x25,0x60,0x8c,0x89,0x81,0x8,0xb0,0xd,0xbf,0xca,0xae,0x47,0xf1,0x70,0x79,0xad,0xb7,0xca,0x34,0x88,0x4d,0x60,0xad,0xb7,0x4a,0x14,0xf,0x97,0x81,0x75,0xc0,0xa4,0x9b,0xeb,0x1c,0x70,0xa1,0xd3,0xee,0x3e,0x6d,0x35,0x67,0xcf,0x5,0x41,0x50,0x29,0xae,0x31,0xc6,0x46,0xf1,0xf0,0xc3,0x60,0xb3,0x7f,0x13,0x78,0x7,0x6c,0x48,0x6e,0x85,0xeb,0x0,0x27,0x80,0x23,0x40,0x73,0xc2,0xf2,0x1d,0x3,0x3f,0x81,0x6f,0x7e,0x8f,0x36,0x52,0x12,0x34,0x4c,0xf7,0xc1,0x9,0x55,0xa8,0x2f,0x39,0xd9,0xa7,0xf0,0xe3,0xf6,0x17,0x4c,0x97,0x1d,0x24,0x5b,0x8,0x8b,0x95,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82
+};
+
+
+static const unsigned char graph_node_close_png[]={
+0x89,0x50,0x4e,0x47,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0xd,0x49,0x48,0x44,0x52,0x0,0x0,0x0,0xc,0x0,0x0,0x0,0xc,0x8,0x6,0x0,0x0,0x0,0x56,0x75,0x5c,0xe7,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,0xde,0xc,0x15,0x14,0x15,0x39,0x35,0x48,0xf8,0xe3,0x0,0x0,0x0,0x80,0x49,0x44,0x41,0x54,0x28,0xcf,0xa5,0xd1,0xb1,0xa,0xc2,0x40,0x10,0x84,0xe1,0x4f,0xe5,0x30,0xad,0x9d,0xb5,0x60,0xeb,0x3,0x88,0x2f,0x6d,0xfa,0xb4,0x29,0x83,0xbd,0xb5,0xb5,0x9d,0x68,0x15,0x9b,0x3d,0xb9,0x4,0x11,0xe,0x7,0xb6,0xd9,0xfd,0x67,0xb9,0xb9,0xa5,0x52,0xab,0xa8,0x13,0xb6,0x78,0xe0,0x39,0x63,0x36,0x38,0x60,0x87,0x1b,0x34,0xb8,0x60,0xc4,0x19,0xa9,0x80,0x53,0xf4,0xc6,0x60,0x9a,0x72,0xd0,0xc6,0xa0,0x2b,0xc,0x5d,0xf4,0xda,0xd9,0xa2,0x8f,0x29,0x3,0x43,0x54,0x5e,0x90,0x7e,0xe5,0xca,0x60,0x36,0x4e,0xb4,0xf4,0x87,0xaa,0x9e,0x54,0x15,0xba,0xea,0x5b,0x17,0x71,0xb8,0x23,0x5e,0xb8,0xe2,0xfe,0xe5,0x70,0x7b,0xac,0xd1,0x57,0x7,0x7d,0x3,0x51,0x8f,0x29,0x6b,0x3c,0x49,0x28,0x81,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82
+};
+
+
+static const unsigned char graph_port_png[]={
+0x89,0x50,0x4e,0x47,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0xd,0x49,0x48,0x44,0x52,0x0,0x0,0x0,0xa,0x0,0x0,0x0,0xa,0x8,0x6,0x0,0x0,0x0,0x8d,0x32,0xcf,0xbd,0x0,0x0,0x0,0x6,0x62,0x4b,0x47,0x44,0x0,0x0,0x0,0x0,0x0,0x0,0xf9,0x43,0xbb,0x7f,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,0xde,0xc,0x14,0x17,0x20,0x3,0xeb,0x8f,0x3a,0xdb,0x0,0x0,0x0,0x19,0x74,0x45,0x58,0x74,0x43,0x6f,0x6d,0x6d,0x65,0x6e,0x74,0x0,0x43,0x72,0x65,0x61,0x74,0x65,0x64,0x20,0x77,0x69,0x74,0x68,0x20,0x47,0x49,0x4d,0x50,0x57,0x81,0xe,0x17,0x0,0x0,0x1,0x65,0x49,0x44,0x41,0x54,0x18,0xd3,0x4d,0xd0,0x4f,0x6b,0xda,0x70,0x1c,0x7,0xe0,0xcf,0x37,0x7f,0x7e,0x49,0x66,0xd2,0x64,0x61,0x5,0x61,0x76,0x47,0xf1,0xa4,0x2d,0xdb,0x75,0x5,0x11,0x84,0xb0,0x5e,0xeb,0xd9,0xeb,0xf4,0x6d,0xec,0x2d,0xf8,0x26,0xb6,0x77,0xe0,0x45,0xba,0xa3,0x6c,0xa0,0x3b,0xad,0x39,0xb6,0x36,0x8,0x1b,0x4b,0x32,0xd2,0xc6,0x6c,0x9a,0x4f,0x4f,0x85,0x3e,0x2f,0xe1,0x11,0x0,0x20,0x29,0xd3,0xe9,0xd4,0xda,0x6e,0xb7,0x23,0xdf,0xf7,0xbb,0x0,0x90,0xe7,0xf9,0x8f,0x66,0xb3,0xf9,0x79,0x36,0x9b,0x55,0x22,0x42,0x83,0xa4,0x44,0x51,0xf4,0xea,0xe2,0xe2,0xc3,0xf7,0xf1,0x78,0xdc,0xa,0x82,0x40,0x8,0x20,0xcf,0x32,0x2e,0x97,0xcb,0x4f,0x51,0x14,0xbd,0x25,0xf9,0x5b,0x26,0x93,0x89,0xdd,0xe9,0x74,0xe2,0xf7,0xe7,0xe7,0x27,0x59,0xfa,0x87,0x65,0xb9,0x13,0x0,0xb0,0x1d,0x9b,0xe1,0xcb,0x50,0xbe,0x5e,0x5d,0xdd,0xfe,0xbc,0xbe,0x6e,0x6b,0x49,0x92,0x8c,0x4e,0x7b,0xa7,0xad,0xbf,0x79,0x4e,0xd3,0x54,0x12,0x86,0x21,0xc2,0x30,0x84,0x32,0x95,0xe4,0x79,0xc6,0xde,0xd9,0x59,0x2b,0x49,0xee,0x46,0x86,0xeb,0xba,0x5d,0xfb,0x85,0x23,0x87,0xfd,0x1e,0xb6,0xed,0x40,0xd7,0x35,0x0,0x40,0x7d,0x38,0xa0,0xdc,0xed,0x44,0x37,0x74,0xb8,0xae,0xd7,0x35,0x48,0x62,0xff,0xff,0x1f,0xfc,0x20,0x80,0xae,0xe9,0x78,0x42,0x0,0xca,0xb2,0x90,0x65,0x19,0x58,0xd7,0xd0,0x8a,0xa2,0x58,0xa7,0x69,0x56,0x6b,0xa2,0x51,0x29,0x5,0xcb,0x52,0xb0,0x94,0x5,0x4b,0x29,0x88,0x8,0xd3,0x34,0xad,0x8b,0xfb,0x62,0xad,0xf,0x6,0x83,0xb8,0xaa,0xaa,0xb1,0xe7,0x79,0xbe,0x77,0x74,0x44,0xb7,0xe1,0x89,0x69,0x1a,0x28,0xcb,0x92,0x9b,0xcd,0x46,0x56,0xab,0xd5,0x86,0xe4,0x47,0x21,0x29,0xc3,0xe1,0xf0,0xb8,0xdf,0xef,0x7f,0x6b,0xb7,0xdb,0xaf,0x1b,0x8d,0x86,0x46,0x10,0xf,0xf7,0xf,0x75,0x1c,0xc7,0x77,0x8b,0xc5,0xe2,0xdd,0x7c,0x3e,0xff,0x25,0xcf,0xc3,0x6f,0x6e,0x6f,0x2e,0x1d,0xdb,0xe9,0x9,0x80,0xb2,0x2a,0xd7,0x27,0xad,0x37,0x5f,0x9e,0xc2,0x1f,0x1,0x3a,0xe6,0xa5,0x7b,0xef,0xf2,0xf3,0xcd,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82
+};
+
+
static const unsigned char hscroll_bg_png[]={
0x89,0x50,0x4e,0x47,0xd,0xa,0x1a,0xa,0x0,0x0,0x0,0xd,0x49,0x48,0x44,0x52,0x0,0x0,0x0,0x8,0x0,0x0,0x0,0x8,0x8,0x6,0x0,0x0,0x0,0xc4,0xf,0xbe,0x8b,0x0,0x0,0x0,0x6,0x62,0x4b,0x47,0x44,0x0,0x49,0x0,0x42,0x0,0x4e,0x4e,0xda,0xb4,0x7e,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,0xdd,0x9,0x1b,0x12,0x30,0x1c,0x3c,0x99,0xa,0x1c,0x0,0x0,0x0,0x19,0x74,0x45,0x58,0x74,0x43,0x6f,0x6d,0x6d,0x65,0x6e,0x74,0x0,0x43,0x72,0x65,0x61,0x74,0x65,0x64,0x20,0x77,0x69,0x74,0x68,0x20,0x47,0x49,0x4d,0x50,0x57,0x81,0xe,0x17,0x0,0x0,0x0,0x53,0x49,0x44,0x41,0x54,0x18,0xd3,0x7d,0x8f,0xc9,0xd,0x80,0x20,0x0,0xc0,0xca,0x21,0xe8,0x5f,0x12,0x89,0x84,0xfd,0x5c,0x48,0x26,0x34,0x3e,0x74,0x2,0xa2,0xe8,0x2,0x40,0xbf,0xed,0xa7,0xc2,0xbb,0xb0,0x3,0x1b,0x75,0x92,0xf0,0x2e,0x7c,0x46,0x9b,0xaa,0xcd,0x4f,0x46,0x3,0x8c,0x76,0xea,0x7,0x4a,0x29,0x5a,0x68,0x0,0x29,0x65,0x3f,0x30,0x83,0xed,0x6,0xe9,0xbc,0x8e,0xf6,0x45,0x79,0xb,0xc0,0x5c,0xb3,0xeb,0x12,0xef,0x1f,0xc6,0x6f,0x12,0x2,0xa,0xbd,0xc9,0x5d,0x0,0x0,0x0,0x0,0x49,0x45,0x4e,0x44,0xae,0x42,0x60,0x82
};
diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp
index 2c278f4fed..faba339fe1 100644
--- a/scene/resources/material.cpp
+++ b/scene/resources/material.cpp
@@ -458,6 +458,8 @@ FixedMaterial::~FixedMaterial() {
}
+
+
bool ShaderMaterial::_set(const StringName& p_name, const Variant& p_value) {
if (p_name==SceneStringNames::get_singleton()->shader_shader) {
@@ -499,7 +501,7 @@ bool ShaderMaterial::_get(const StringName& p_name,Variant &r_ret) const {
void ShaderMaterial::_get_property_list( List<PropertyInfo> *p_list) const {
- p_list->push_back( PropertyInfo( Variant::OBJECT, "shader/shader", PROPERTY_HINT_RESOURCE_TYPE,"Shader" ) );
+ p_list->push_back( PropertyInfo( Variant::OBJECT, "shader/shader", PROPERTY_HINT_RESOURCE_TYPE,"MaterialShader,MaterialShaderGraph" ) );
if (!shader.is_null()) {
@@ -558,7 +560,21 @@ void ShaderMaterial::_bind_methods() {
}
+void ShaderMaterial::get_argument_options(const StringName& p_function,int p_idx,List<String>*r_options) const {
+
+ String f = p_function.operator String();
+ if ((f=="get_shader_param" || f=="set_shader_param") && p_idx==0) {
+ if (shader.is_valid()) {
+ List<PropertyInfo> pl;
+ shader->get_param_list(&pl);
+ for (List<PropertyInfo>::Element *E=pl.front();E;E=E->next()) {
+ r_options->push_back(E->get().name);
+ }
+ }
+ }
+ Material::get_argument_options(p_function,p_idx,r_options);
+}
ShaderMaterial::ShaderMaterial() :Material(VisualServer::get_singleton()->material_create()){
diff --git a/scene/resources/material.h b/scene/resources/material.h
index 9c3feede08..2b10078e16 100644
--- a/scene/resources/material.h
+++ b/scene/resources/material.h
@@ -243,6 +243,7 @@ public:
void set_shader_param(const StringName& p_param,const Variant& p_value);
Variant get_shader_param(const StringName& p_param) const;
+ void get_argument_options(const StringName& p_function,int p_idx,List<String>*r_options) const;
ShaderMaterial();
};
diff --git a/scene/resources/polygon_path_finder.cpp b/scene/resources/polygon_path_finder.cpp
index afb0ae1815..9f691d6ad3 100644
--- a/scene/resources/polygon_path_finder.cpp
+++ b/scene/resources/polygon_path_finder.cpp
@@ -142,6 +142,7 @@ Vector<Vector2> PolygonPathFinder::find_path(const Vector2& p_from, const Vector
if (d<closest_dist) {
ignore_from_edge=E->get();
closest_dist=d;
+ closest_point=closest;
}
}
@@ -168,6 +169,7 @@ Vector<Vector2> PolygonPathFinder::find_path(const Vector2& p_from, const Vector
if (d<closest_dist) {
ignore_to_edge=E->get();
closest_dist=d;
+ closest_point=closest;
}
}
@@ -529,7 +531,7 @@ Vector2 PolygonPathFinder::get_closest_point(const Vector2& p_point) const {
float d = p_point.distance_squared_to(points[i].pos);
if (d<closest_dist) {
- d=closest_dist;
+ closest_dist=d;
closest_idx=i;
}
diff --git a/scene/resources/shader.cpp b/scene/resources/shader.cpp
index 6d65da3782..f3e625917a 100644
--- a/scene/resources/shader.cpp
+++ b/scene/resources/shader.cpp
@@ -33,12 +33,6 @@
#include "scene/scene_string_names.h"
-void Shader::set_mode(Mode p_mode) {
-
- ERR_FAIL_INDEX(p_mode,2);
- VisualServer::get_singleton()->shader_set_mode(shader,VisualServer::ShaderMode(p_mode));
- emit_signal(SceneStringNames::get_singleton()->changed);
-}
Shader::Mode Shader::get_mode() const {
@@ -120,6 +114,13 @@ Dictionary Shader::_get_code() {
c["vertex_ofs"]=0;
c["light"]=ls;
c["light_ofs"]=0;
+ Array arr;
+ for(const Map<StringName,Ref<Texture> >::Element *E=default_textures.front();E;E=E->next()) {
+ arr.push_back(E->key());
+ arr.push_back(E->get());
+ }
+ if (arr.size())
+ c["default_tex"]=arr;
return c;
}
@@ -132,11 +133,46 @@ void Shader::_set_code(const Dictionary& p_string) {
light=p_string["light"];
set_code(p_string["vertex"],p_string["fragment"],light);
+ if (p_string.has("default_tex")) {
+ Array arr=p_string["default_tex"];
+ if ((arr.size()&1)==0) {
+ for(int i=0;i<arr.size();i+=2)
+ set_default_texture_param(arr[i],arr[i+1]);
+ }
+ }
}
+void Shader::set_default_texture_param(const StringName& p_param,const Ref<Texture>& p_texture) {
+
+ if (p_texture.is_valid()) {
+ default_textures[p_param]=p_texture;
+ VS::get_singleton()->shader_set_default_texture_param(shader,p_param,p_texture->get_rid());
+ } else {
+ default_textures.erase(p_param);
+ VS::get_singleton()->shader_set_default_texture_param(shader,p_param,RID());
+ }
+}
+
+Ref<Texture> Shader::get_default_texture_param(const StringName& p_param) const{
+
+ if (default_textures.has(p_param))
+ return default_textures[p_param];
+ else
+ return Ref<Texture>();
+}
+
+void Shader::get_default_texture_param_list(List<StringName>* r_textures) const{
+
+ for(const Map<StringName,Ref<Texture> >::Element *E=default_textures.front();E;E=E->next()) {
+
+ r_textures->push_back(E->key());
+ }
+
+}
+
+
void Shader::_bind_methods() {
- ObjectTypeDB::bind_method(_MD("set_mode","mode"),&Shader::set_mode);
ObjectTypeDB::bind_method(_MD("get_mode"),&Shader::get_mode);
ObjectTypeDB::bind_method(_MD("set_code","vcode","fcode","lcode","fofs","lofs"),&Shader::set_code,DEFVAL(0),DEFVAL(0));
@@ -144,6 +180,9 @@ void Shader::_bind_methods() {
ObjectTypeDB::bind_method(_MD("get_fragment_code"),&Shader::get_fragment_code);
ObjectTypeDB::bind_method(_MD("get_light_code"),&Shader::get_light_code);
+ ObjectTypeDB::bind_method(_MD("set_default_texture_param","param","texture:Texture"),&Shader::set_default_texture_param);
+ ObjectTypeDB::bind_method(_MD("get_default_texture_param:Texture","param"),&Shader::get_default_texture_param);
+
ObjectTypeDB::bind_method(_MD("has_param","name"),&Shader::has_param);
ObjectTypeDB::bind_method(_MD("_set_code","code"),&Shader::_set_code);
@@ -160,9 +199,9 @@ void Shader::_bind_methods() {
}
-Shader::Shader() {
+Shader::Shader(Mode p_mode) {
- shader = VisualServer::get_singleton()->shader_create();
+ shader = VisualServer::get_singleton()->shader_create(VS::ShaderMode(p_mode));
params_cache_dirty=true;
}
@@ -194,7 +233,7 @@ RES ResourceFormatLoaderShader::load(const String &p_path,const String& p_origin
String base_path = p_path.get_base_dir();
- Ref<Shader> shader( memnew( Shader ) );
+ Ref<Shader> shader;//( memnew( Shader ) );
int line=0;
diff --git a/scene/resources/shader.h b/scene/resources/shader.h
index fff6f1d28a..8c15ca43d4 100644
--- a/scene/resources/shader.h
+++ b/scene/resources/shader.h
@@ -31,7 +31,7 @@
#include "resource.h"
#include "io/resource_loader.h"
-
+#include "scene/resources/texture.h"
class Shader : public Resource {
OBJ_TYPE(Shader,Resource);
@@ -48,6 +48,9 @@ class Shader : public Resource {
// convertion fast and save memory.
mutable bool params_cache_dirty;
mutable Map<StringName,StringName> params_cache; //map a shader param to a material param..
+ Map<StringName,Ref<Texture> > default_textures;
+
+
protected:
@@ -58,10 +61,11 @@ public:
MODE_MATERIAL,
MODE_CANVAS_ITEM,
- MODE_POST_PROCESS
+ MODE_POST_PROCESS,
+ MODE_MAX
};
- void set_mode(Mode p_mode);
+ //void set_mode(Mode p_mode);
Mode get_mode() const;
void set_code( const String& p_vertex, const String& p_fragment, const String& p_light,int p_fragment_ofs=0,int p_light_ofs=0);
@@ -72,15 +76,28 @@ public:
void get_param_list(List<PropertyInfo> *p_params) const;
bool has_param(const StringName& p_param) const;
+ void set_default_texture_param(const StringName& p_param, const Ref<Texture> &p_texture);
+ Ref<Texture> get_default_texture_param(const StringName& p_param) const;
+ void get_default_texture_param_list(List<StringName>* r_textures) const;
+
virtual RID get_rid() const;
- Shader();
+ Shader(Mode p_mode);
~Shader();
};
VARIANT_ENUM_CAST( Shader::Mode );
+class MaterialShader : public Shader {
+
+ OBJ_TYPE(MaterialShader,Shader);
+
+public:
+
+ MaterialShader() : Shader(MODE_MATERIAL) {};
+};
+
class ResourceFormatLoaderShader : public ResourceFormatLoader {
diff --git a/scene/resources/shader_graph.cpp b/scene/resources/shader_graph.cpp
index 3ed6cebf07..8b2f318ec0 100644
--- a/scene/resources/shader_graph.cpp
+++ b/scene/resources/shader_graph.cpp
@@ -27,121 +27,346 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "shader_graph.h"
+#include "scene/scene_string_names.h"
+//todo
+//-RGB ops
+//-mostrar error de conexion
+Array ShaderGraph::_get_node_list(ShaderType p_type) const {
+ List<int> nodes;
+ get_node_list(p_type,&nodes);
+ Array arr(true);
+ for (List<int>::Element *E=nodes.front();E;E=E->next())
+ arr.push_back(E->get());
+ return arr;
+}
+Array ShaderGraph::_get_connections(ShaderType p_type) const {
+
+ List<Connection> connections;
+ get_node_connections(p_type,&connections);
+ Array arr(true);
+ for (List<Connection>::Element *E=connections.front();E;E=E->next()) {
+
+ Dictionary d(true);
+ d["src_id"]=E->get().src_id;
+ d["src_slot"]=E->get().src_slot;
+ d["dst_id"]=E->get().dst_id;
+ d["dst_slot"]=E->get().dst_slot;
+ arr.push_back(d);
-# if 0
-void ShaderGraph::_set(const String& p_name, const Variant& p_value) {
+ }
+ return arr;
+}
- if (p_name.begins_with("nodes/")) {
- int idx=p_name.get_slice("/",1).to_int();
- Dictionary data=p_value;
+void ShaderGraph::_set_data(const Dictionary &p_data) {
- ERR_FAIL_COND(!data.has("type"));
- String type=data["type"];
+ Dictionary d=p_data;
+ ERR_FAIL_COND(!d.has("shaders"));
+ Array sh=d["shaders"];
+ ERR_FAIL_COND(sh.size()!=3);
- VS::NodeType node_type=VS::NODE_TYPE_MAX;
- for(int i=0;i<NODE_TYPE_MAX;i++) {
+ for(int t=0;t<3;t++) {
+ Array data=sh[t];
+ ERR_FAIL_COND((data.size()%6)!=0);
+ shader[t].node_map.clear();
+ for(int i=0;i<data.size();i+=6) {
- if (type==VisualServer::shader_node_get_type_info((VS::NodeType)i).name)
- node_type=(VS::NodeType)i;
- }
+ Node n;
+ n.id=data[i+0];
+ n.type=NodeType(int(data[i+1]));
+ n.pos=data[i+2];
+ n.param1=data[i+3];
+ n.param2=data[i+4];
- ERR_FAIL_COND(node_type==VS::NODE_TYPE_MAX);
+ Array conns=data[i+5];
+ ERR_FAIL_COND((conns.size()%3)!=0);
- node_add( (NodeType)node_type, idx );
- if (data.has("param"))
- node_set_param(idx,data["param"]);
- if (data.has("pos"))
- node_set_pos(idx,data["pos"]);
- }
+ for(int j=0;j<conns.size();j+=3) {
- if (p_name.begins_with("conns/")) {
- Dictionary data=p_value;
- ERR_FAIL_COND( !data.has("src_id") );
- ERR_FAIL_COND( !data.has("src_slot") );
- ERR_FAIL_COND( !data.has("dst_id") );
- ERR_FAIL_COND( !data.has("dst_slot") );
+ SourceSlot ss;
+ int ls=conns[j+0];
+ ss.id=conns[j+1];
+ ss.slot=conns[j+2];
+ n.connections[ls]=ss;
+ }
+ shader[t].node_map[n.id]=n;
- connect(data["src_id"],data["src_slot"],data["dst_id"],data["dst_slot"]);
+ }
}
- return false;
+ _update_shader();
+
}
-Variant ShaderGraph::_get(const String& p_name) const {
- if (p_name.begins_with("nodes/")) {
- int idx=p_name.get_slice("/",1).to_int();
- Dictionary data;
- data["type"]=VisualServer::shader_node_get_type_info((VS::NodeType)node_get_type(idx)).name;
- data["pos"]=node_get_pos(idx);
- data["param"]=node_get_param(idx);
- return data;
- }
- if (p_name.begins_with("conns/")) {
- int idx=p_name.get_slice("/",1).to_int();
- Dictionary data;
-
- List<Connection> connections;
- get_connections(&connections);
- ERR_FAIL_INDEX_V( idx,connections.size(), Variant() );
- Connection c = connections[idx];
-
- data["src_id"]=c.src_id;
- data["src_slot"]=c.src_slot;
- data["dst_id"]=c.dst_id;
- data["dst_slot"]=c.dst_slot;
- return data;
+Dictionary ShaderGraph::_get_data() const {
+
+ Array sh;
+ for(int i=0;i<3;i++) {
+ Array data;
+ int ec = shader[i].node_map.size();
+ data.resize(ec*6);
+ int idx=0;
+ for (Map<int,Node>::Element*E=shader[i].node_map.front();E;E=E->next()) {
+
+ data[idx+0]=E->key();
+ data[idx+1]=E->get().type;
+ data[idx+2]=E->get().pos;
+ data[idx+3]=E->get().param1;
+ data[idx+4]=E->get().param2;
+
+ Array conns;
+ conns.resize(E->get().connections.size()*3);
+ int idx2=0;
+ for(Map<int,SourceSlot>::Element*F=E->get().connections.front();F;F=F->next()) {
+
+ conns[idx2+0]=F->key();
+ conns[idx2+1]=F->get().id;
+ conns[idx2+2]=F->get().slot;
+ idx2+=3;
+ }
+ data[idx+5]=conns;
+ idx+=6;
+ }
+ sh.push_back(data);
}
- return Variant();
+ Dictionary data;
+ data["shaders"]=sh;
+ return data;
}
-void ShaderGraph::_get_property_list( List<PropertyInfo> *p_list) const {
- List<int> nodes;
- get_node_list(&nodes);
- for(List<int>::Element *E=nodes.front();E;E=E->next()) {
- int idx=E->get();
- p_list->push_back(PropertyInfo( Variant::DICTIONARY , "nodes/"+itos(idx),PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NETWORK|PROPERTY_USAGE_STORAGE ) );
- }
-
- List<Connection> connections;
- get_connections(&connections);
- int idx=0;
- for(List<Connection>::Element *E=connections.front();E;E=E->next()) {
- p_list->push_back(PropertyInfo( Variant::DICTIONARY , "conns/"+itos(idx++),PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NETWORK|PROPERTY_USAGE_STORAGE ) );
- }
+ShaderGraph::GraphError ShaderGraph::get_graph_error(ShaderType p_type) const {
+ ERR_FAIL_INDEX_V(p_type,3,GRAPH_OK);
+ return shader[p_type].error;
}
-#endif
-#if 0
-Array ShaderGraph::_get_connections_helper() const {
+void ShaderGraph::_bind_methods() {
- Array connections_ret;
- List<Connection> connections;
- get_connections(&connections);
- connections_ret.resize(connections.size());
-
- int idx=0;
- for(List<Connection>::Element *E=connections.front();E;E=E->next()) {
-
- Connection c = E->get();
- Dictionary data;
- data["src_id"]=c.src_id;
- data["src_slot"]=c.src_slot;
- data["dst_id"]=c.dst_id;
- data["dst_slot"]=c.dst_slot;
- connections_ret.set(idx++,data);
- }
+ ObjectTypeDB::bind_method(_MD("_update_shader"),&ShaderGraph::_update_shader);
- return connections_ret;
-}
+ ObjectTypeDB::bind_method(_MD("node_add","shader_type","node_type","id"),&ShaderGraph::node_add);
+ ObjectTypeDB::bind_method(_MD("node_remove","shader_type","id"),&ShaderGraph::node_remove);
+ ObjectTypeDB::bind_method(_MD("node_set_pos","shader_type","id","pos"),&ShaderGraph::node_set_pos);
+ ObjectTypeDB::bind_method(_MD("node_get_pos","shader_type","id"),&ShaderGraph::node_get_pos);
-void ShaderGraph::_bind_methods() {
+ ObjectTypeDB::bind_method(_MD("node_get_type","shader_type","id"),&ShaderGraph::node_get_type);
+
+ ObjectTypeDB::bind_method(_MD("get_node_list","shader_type"),&ShaderGraph::_get_node_list);
+
+ ObjectTypeDB::bind_method(_MD("scalar_const_node_set_value","shader_type","id","value"),&ShaderGraph::scalar_const_node_set_value);
+ ObjectTypeDB::bind_method(_MD("scalar_const_node_get_value","shader_type","id"),&ShaderGraph::scalar_const_node_set_value);
+
+ ObjectTypeDB::bind_method(_MD("vec_const_node_set_value","shader_type","id","value"),&ShaderGraph::vec_const_node_set_value);
+ ObjectTypeDB::bind_method(_MD("vec_const_node_get_value","shader_type","id"),&ShaderGraph::vec_const_node_set_value);
+
+ ObjectTypeDB::bind_method(_MD("rgb_const_node_set_value","shader_type","id","value"),&ShaderGraph::rgb_const_node_set_value);
+ ObjectTypeDB::bind_method(_MD("rgb_const_node_get_value","shader_type","id"),&ShaderGraph::rgb_const_node_set_value);
+
+ ObjectTypeDB::bind_method(_MD("xform_const_node_set_value","shader_type","id","value"),&ShaderGraph::xform_const_node_set_value);
+ ObjectTypeDB::bind_method(_MD("xform_const_node_get_value","shader_type","id"),&ShaderGraph::xform_const_node_set_value);
+
+
+// void get_node_list(ShaderType p_which,List<int> *p_node_list) const;
+
+ ObjectTypeDB::bind_method(_MD("texture_node_set_filter_size","shader_type","id","filter_size"),&ShaderGraph::texture_node_set_filter_size);
+ ObjectTypeDB::bind_method(_MD("texture_node_get_filter_size","shader_type","id"),&ShaderGraph::texture_node_set_filter_size);
+
+ ObjectTypeDB::bind_method(_MD("texture_node_set_filter_strength","shader_type","id","filter_strength"),&ShaderGraph::texture_node_set_filter_strength);
+ ObjectTypeDB::bind_method(_MD("texture_node_get_filter_strength","shader_type","id"),&ShaderGraph::texture_node_set_filter_strength);
+
+ ObjectTypeDB::bind_method(_MD("scalar_op_node_set_op","shader_type","id","op"),&ShaderGraph::scalar_op_node_set_op);
+ ObjectTypeDB::bind_method(_MD("scalar_op_node_get_op","shader_type","id"),&ShaderGraph::scalar_op_node_get_op);
+
+ ObjectTypeDB::bind_method(_MD("vec_op_node_set_op","shader_type","id","op"),&ShaderGraph::vec_op_node_set_op);
+ ObjectTypeDB::bind_method(_MD("vec_op_node_get_op","shader_type","id"),&ShaderGraph::vec_op_node_get_op);
+
+ ObjectTypeDB::bind_method(_MD("vec_scalar_op_node_set_op","shader_type","id","op"),&ShaderGraph::vec_scalar_op_node_set_op);
+ ObjectTypeDB::bind_method(_MD("vec_scalar_op_node_get_op","shader_type","id"),&ShaderGraph::vec_scalar_op_node_get_op);
+
+ ObjectTypeDB::bind_method(_MD("rgb_op_node_set_op","shader_type","id","op"),&ShaderGraph::rgb_op_node_set_op);
+ ObjectTypeDB::bind_method(_MD("rgb_op_node_get_op","shader_type","id"),&ShaderGraph::rgb_op_node_get_op);
+
+ ObjectTypeDB::bind_method(_MD("xform_vec_mult_node_set_no_translation","shader_type","id","disable"),&ShaderGraph::xform_vec_mult_node_set_no_translation);
+ ObjectTypeDB::bind_method(_MD("xform_vec_mult_node_get_no_translation","shader_type","id"),&ShaderGraph::xform_vec_mult_node_get_no_translation);
+
+ ObjectTypeDB::bind_method(_MD("scalar_func_node_set_function","shader_type","id","func"),&ShaderGraph::scalar_func_node_set_function);
+ ObjectTypeDB::bind_method(_MD("scalar_func_node_get_function","shader_type","id"),&ShaderGraph::scalar_func_node_get_function);
+
+ ObjectTypeDB::bind_method(_MD("vec_func_node_set_function","shader_type","id","func"),&ShaderGraph::vec_func_node_set_function);
+ ObjectTypeDB::bind_method(_MD("vec_func_node_get_function","shader_type","id"),&ShaderGraph::vec_func_node_get_function);
+
+ ObjectTypeDB::bind_method(_MD("input_node_set_name","shader_type","id","name"),&ShaderGraph::input_node_set_name);
+ ObjectTypeDB::bind_method(_MD("input_node_get_name","shader_type","id"),&ShaderGraph::input_node_get_name);
+
+ ObjectTypeDB::bind_method(_MD("scalar_input_node_set_value","shader_type","id","value"),&ShaderGraph::scalar_input_node_set_value);
+ ObjectTypeDB::bind_method(_MD("scalar_input_node_get_value","shader_type","id"),&ShaderGraph::scalar_input_node_get_value);
+
+ ObjectTypeDB::bind_method(_MD("vec_input_node_set_value","shader_type","id","value"),&ShaderGraph::vec_input_node_set_value);
+ ObjectTypeDB::bind_method(_MD("vec_input_node_get_value","shader_type","id"),&ShaderGraph::vec_input_node_get_value);
+
+ ObjectTypeDB::bind_method(_MD("rgb_input_node_set_value","shader_type","id","value"),&ShaderGraph::rgb_input_node_set_value);
+ ObjectTypeDB::bind_method(_MD("rgb_input_node_get_value","shader_type","id"),&ShaderGraph::rgb_input_node_get_value);
+
+ ObjectTypeDB::bind_method(_MD("xform_input_node_set_value","shader_type","id","value"),&ShaderGraph::xform_input_node_set_value);
+ ObjectTypeDB::bind_method(_MD("xform_input_node_get_value","shader_type","id"),&ShaderGraph::xform_input_node_get_value);
+
+ ObjectTypeDB::bind_method(_MD("texture_input_node_set_value","shader_type","id","value:Texture"),&ShaderGraph::texture_input_node_set_value);
+ ObjectTypeDB::bind_method(_MD("texture_input_node_get_value:Texture","shader_type","id"),&ShaderGraph::texture_input_node_get_value);
+
+ ObjectTypeDB::bind_method(_MD("cubemap_input_node_set_value","shader_type","id","value:CubeMap"),&ShaderGraph::cubemap_input_node_set_value);
+ ObjectTypeDB::bind_method(_MD("cubemap_input_node_get_value:CubeMap","shader_type","id"),&ShaderGraph::cubemap_input_node_get_value);
+
+ ObjectTypeDB::bind_method(_MD("comment_node_set_text","shader_type","id","text"),&ShaderGraph::comment_node_set_text);
+ ObjectTypeDB::bind_method(_MD("comment_node_get_text","shader_type","id"),&ShaderGraph::comment_node_get_text);
+
+ ObjectTypeDB::bind_method(_MD("connect_node:Error","shader_type","src_id","src_slot","dst_id","dst_slot"),&ShaderGraph::connect_node);
+ ObjectTypeDB::bind_method(_MD("is_node_connected","shader_type","src_id","src_slot","dst_id","dst_slot"),&ShaderGraph::is_node_connected);
+ ObjectTypeDB::bind_method(_MD("disconnect_node","shader_type","src_id","src_slot","dst_id","dst_slot"),&ShaderGraph::disconnect_node);
+ ObjectTypeDB::bind_method(_MD("get_node_connections","shader_type"),&ShaderGraph::_get_connections);
+
+ ObjectTypeDB::bind_method(_MD("clear","shader_type"),&ShaderGraph::clear);
+
+ ObjectTypeDB::bind_method(_MD("node_set_state","shader_type","id","state"),&ShaderGraph::node_set_state);
+ ObjectTypeDB::bind_method(_MD("node_get_state:var","shader_type","id"),&ShaderGraph::node_get_state);
+
+ ObjectTypeDB::bind_method(_MD("_set_data"),&ShaderGraph::_set_data);
+ ObjectTypeDB::bind_method(_MD("_get_data"),&ShaderGraph::_get_data);
+
+ ADD_PROPERTY( PropertyInfo(Variant::DICTIONARY,"_data",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR), _SCS("_set_data"),_SCS("_get_data"));
+
+ //void get_connections(ShaderType p_which,List<Connection> *p_connections) const;
+
+
+ BIND_CONSTANT( NODE_INPUT ); // all inputs (shader type dependent)
+ BIND_CONSTANT( NODE_SCALAR_CONST ); //scalar constant
+ BIND_CONSTANT( NODE_VEC_CONST ); //vec3 constant
+ BIND_CONSTANT( NODE_RGB_CONST ); //rgb constant (shows a color picker instead)
+ BIND_CONSTANT( NODE_XFORM_CONST ); // 4x4 matrix constant
+ BIND_CONSTANT( NODE_TIME ); // time in seconds
+ BIND_CONSTANT( NODE_SCREEN_TEX ); // screen texture sampler (takes UV) (only usable in fragment shader)
+ BIND_CONSTANT( NODE_SCALAR_OP ); // scalar vs scalar op (mul ); add ); div ); etc)
+ BIND_CONSTANT( NODE_VEC_OP ); // vec3 vs vec3 op (mul );ad );div );crossprod );etc)
+ BIND_CONSTANT( NODE_VEC_SCALAR_OP ); // vec3 vs scalar op (mul ); add ); div ); etc)
+ BIND_CONSTANT( NODE_RGB_OP ); // vec3 vs vec3 rgb op (with scalar amount) ); like brighten ); darken ); burn ); dodge ); multiply ); etc.
+ BIND_CONSTANT( NODE_XFORM_MULT ); // mat4 x mat4
+ BIND_CONSTANT( NODE_XFORM_VEC_MULT ); // mat4 x vec3 mult (with no-translation option)
+ BIND_CONSTANT( NODE_XFORM_VEC_INV_MULT ); // mat4 x vec3 inverse mult (with no-translation option)
+ BIND_CONSTANT( NODE_SCALAR_FUNC ); // scalar function (sin ); cos ); etc)
+ BIND_CONSTANT( NODE_VEC_FUNC ); // vector function (normalize ); negate ); reciprocal ); rgb2hsv ); hsv2rgb ); etc ); etc)
+ BIND_CONSTANT( NODE_VEC_LEN ); // vec3 length
+ BIND_CONSTANT( NODE_DOT_PROD ); // vec3 . vec3 (dot product -> scalar output)
+ BIND_CONSTANT( NODE_VEC_TO_SCALAR ); // 1 vec3 input ); 3 scalar outputs
+ BIND_CONSTANT( NODE_SCALAR_TO_VEC ); // 3 scalar input ); 1 vec3 output
+ BIND_CONSTANT( NODE_VEC_TO_XFORM ); // 3 vec input ); 1 xform output
+ BIND_CONSTANT( NODE_XFORM_TO_VEC ); // 3 vec input ); 1 xform output
+ BIND_CONSTANT( NODE_SCALAR_INTERP ); // scalar interpolation (with optional curve)
+ BIND_CONSTANT( NODE_VEC_INTERP ); // vec3 interpolation (with optional curve)
+ BIND_CONSTANT( NODE_SCALAR_INPUT ); // scalar uniform (assignable in material)
+ BIND_CONSTANT( NODE_VEC_INPUT ); // vec3 uniform (assignable in material)
+ BIND_CONSTANT( NODE_RGB_INPUT ); // color uniform (assignable in material)
+ BIND_CONSTANT( NODE_XFORM_INPUT ); // mat4 uniform (assignable in material)
+ BIND_CONSTANT( NODE_TEXTURE_INPUT ); // texture input (assignable in material)
+ BIND_CONSTANT( NODE_CUBEMAP_INPUT ); // cubemap input (assignable in material)
+ BIND_CONSTANT( NODE_OUTPUT ); // output (shader type dependent)
+ BIND_CONSTANT( NODE_COMMENT ); // comment
+ BIND_CONSTANT( NODE_TYPE_MAX );
+
+ BIND_CONSTANT( SLOT_TYPE_SCALAR );
+ BIND_CONSTANT( SLOT_TYPE_VEC );
+ BIND_CONSTANT( SLOT_TYPE_XFORM );
+ BIND_CONSTANT( SLOT_TYPE_TEXTURE );
+ BIND_CONSTANT( SLOT_MAX );
+
+ BIND_CONSTANT( SHADER_TYPE_VERTEX );
+ BIND_CONSTANT( SHADER_TYPE_FRAGMENT );
+ BIND_CONSTANT( SHADER_TYPE_LIGHT );
+ BIND_CONSTANT( SHADER_TYPE_MAX );
+
+
+ BIND_CONSTANT( SLOT_IN );
+ BIND_CONSTANT( SLOT_OUT );
+
+ BIND_CONSTANT( GRAPH_OK );
+ BIND_CONSTANT( GRAPH_ERROR_CYCLIC );
+ BIND_CONSTANT( GRAPH_ERROR_MISSING_CONNECTIONS );
+
+ BIND_CONSTANT( SCALAR_OP_ADD );
+ BIND_CONSTANT( SCALAR_OP_SUB );
+ BIND_CONSTANT( SCALAR_OP_MUL );
+ BIND_CONSTANT( SCALAR_OP_DIV );
+ BIND_CONSTANT( SCALAR_OP_MOD );
+ BIND_CONSTANT( SCALAR_OP_POW );
+ BIND_CONSTANT( SCALAR_OP_MAX );
+ BIND_CONSTANT( SCALAR_OP_MIN );
+ BIND_CONSTANT( SCALAR_OP_ATAN2 );
+ BIND_CONSTANT( SCALAR_MAX_OP );
+
+ BIND_CONSTANT( VEC_OP_ADD );
+ BIND_CONSTANT( VEC_OP_SUB );
+ BIND_CONSTANT( VEC_OP_MUL );
+ BIND_CONSTANT( VEC_OP_DIV );
+ BIND_CONSTANT( VEC_OP_MOD );
+ BIND_CONSTANT( VEC_OP_POW );
+ BIND_CONSTANT( VEC_OP_MAX );
+ BIND_CONSTANT( VEC_OP_MIN );
+ BIND_CONSTANT( VEC_OP_CROSS );
+ BIND_CONSTANT( VEC_MAX_OP );
+
+ BIND_CONSTANT( VEC_SCALAR_OP_MUL );
+ BIND_CONSTANT( VEC_SCALAR_OP_DIV );
+ BIND_CONSTANT( VEC_SCALAR_OP_POW );
+ BIND_CONSTANT( VEC_SCALAR_MAX_OP );
+
+ BIND_CONSTANT( RGB_OP_SCREEN );
+ BIND_CONSTANT( RGB_OP_DIFFERENCE );
+ BIND_CONSTANT( RGB_OP_DARKEN );
+ BIND_CONSTANT( RGB_OP_LIGHTEN );
+ BIND_CONSTANT( RGB_OP_OVERLAY );
+ BIND_CONSTANT( RGB_OP_DODGE );
+ BIND_CONSTANT( RGB_OP_BURN );
+ BIND_CONSTANT( RGB_OP_SOFT_LIGHT );
+ BIND_CONSTANT( RGB_OP_HARD_LIGHT );
+ BIND_CONSTANT( RGB_MAX_OP );
+
+ BIND_CONSTANT( SCALAR_FUNC_SIN );
+ BIND_CONSTANT( SCALAR_FUNC_COS );
+ BIND_CONSTANT( SCALAR_FUNC_TAN );
+ BIND_CONSTANT( SCALAR_FUNC_ASIN );
+ BIND_CONSTANT( SCALAR_FUNC_ACOS );
+ BIND_CONSTANT( SCALAR_FUNC_ATAN );
+ BIND_CONSTANT( SCALAR_FUNC_SINH );
+ BIND_CONSTANT( SCALAR_FUNC_COSH );
+ BIND_CONSTANT( SCALAR_FUNC_TANH );
+ BIND_CONSTANT( SCALAR_FUNC_LOG );
+ BIND_CONSTANT( SCALAR_FUNC_EXP );
+ BIND_CONSTANT( SCALAR_FUNC_SQRT );
+ BIND_CONSTANT( SCALAR_FUNC_ABS );
+ BIND_CONSTANT( SCALAR_FUNC_SIGN );
+ BIND_CONSTANT( SCALAR_FUNC_FLOOR );
+ BIND_CONSTANT( SCALAR_FUNC_ROUND );
+ BIND_CONSTANT( SCALAR_FUNC_CEIL );
+ BIND_CONSTANT( SCALAR_FUNC_FRAC );
+ BIND_CONSTANT( SCALAR_FUNC_SATURATE );
+ BIND_CONSTANT( SCALAR_FUNC_NEGATE );
+ BIND_CONSTANT( SCALAR_MAX_FUNC );
+
+ BIND_CONSTANT( VEC_FUNC_NORMALIZE );
+ BIND_CONSTANT( VEC_FUNC_SATURATE );
+ BIND_CONSTANT( VEC_FUNC_NEGATE );
+ BIND_CONSTANT( VEC_FUNC_RECIPROCAL );
+ BIND_CONSTANT( VEC_FUNC_RGB2HSV );
+ BIND_CONSTANT( VEC_FUNC_HSV2RGB );
+ BIND_CONSTANT( VEC_MAX_FUNC );
+
+ ADD_SIGNAL(MethodInfo("updated"));
+
+
+#if 0
ObjectTypeDB::bind_method(_MD("node_add"),&ShaderGraph::node_add );
ObjectTypeDB::bind_method(_MD("node_remove"),&ShaderGraph::node_remove );
ObjectTypeDB::bind_method(_MD("node_set_param"),&ShaderGraph::node_set_param );
@@ -212,73 +437,158 @@ void ShaderGraph::_bind_methods() {
BIND_CONSTANT( NODE_TEXTURE_2D_PARAMETER );
BIND_CONSTANT( NODE_TEXTURE_CUBE_PARAMETER );
BIND_CONSTANT( NODE_TYPE_MAX );
+#endif
}
-void ShaderGraph::node_add(NodeType p_type,int p_id) {
+
+String ShaderGraph::_find_unique_name(const String& p_base) {
+
- ERR_FAIL_COND( node_map.has(p_id ) );
- ERR_FAIL_INDEX( p_type, NODE_TYPE_MAX );
+ int idx=1;
+ while(true) {
+ String tocmp=p_base;
+ if (idx>1) {
+ tocmp+="_"+itos(idx);
+ }
+ bool valid=true;
+ for(int i=0;i<3;i++) {
+ if (!valid)
+ break;
+ for (Map<int,Node>::Element *E=shader[i].node_map.front();E;E=E->next()) {
+ if (E->get().type!=NODE_SCALAR_INPUT && E->get().type!=NODE_VEC_INPUT && E->get().type==NODE_RGB_INPUT && E->get().type==NODE_XFORM_INPUT && E->get().type==NODE_TEXTURE_INPUT && E->get().type==NODE_CUBEMAP_INPUT)
+ continue;
+ String name = E->get().param1;
+ if (name==tocmp) {
+ valid=false;
+ break;
+ }
+
+ }
+ }
+
+ if (!valid) {
+ idx++;
+ continue;
+ }
+ return tocmp;
+ }
+ return String();
+}
+
+void ShaderGraph::node_add(ShaderType p_type, NodeType p_node_type,int p_id) {
+
+ ERR_FAIL_INDEX(p_type,3);
+ ERR_FAIL_COND(p_id==0);
+ ERR_FAIL_COND(p_node_type==NODE_OUTPUT); //can't create output
+ ERR_FAIL_COND( shader[p_type].node_map.has(p_id ) );
+ ERR_FAIL_INDEX( p_node_type, NODE_TYPE_MAX );
Node node;
- node.type=p_type;
+ if (p_node_type==NODE_INPUT) {
+ //see if it already exists
+ for(Map<int,Node>::Element *E=shader[p_type].node_map.front();E;E=E->next()) {
+ if (E->get().type==NODE_INPUT) {
+ ERR_EXPLAIN("Only one input node can be added to the graph.");
+ ERR_FAIL_COND(E->get().type==NODE_INPUT);
+ }
+ }
+ }
+ node.type=p_node_type;
node.id=p_id;
- node.x=0;
- node.y=0;
- node_map[p_id]=node;
+ switch(p_node_type) {
+ case NODE_INPUT: {} break; // all inputs (shader type dependent)
+ case NODE_SCALAR_CONST: { node.param1=0;} break; //scalar constant
+ case NODE_VEC_CONST: {node.param1=Vector3();} break; //vec3 constant
+ case NODE_RGB_CONST: {node.param1=Color();} break; //rgb constant (shows a color picker instead)
+ case NODE_XFORM_CONST: {node.param1=Transform();} break; // 4x4 matrix constant
+ case NODE_TIME: {} break; // time in seconds
+ case NODE_SCREEN_TEX: {Array arr; arr.push_back(0); arr.push_back(0); node.param2=arr;} break; // screen texture sampler (takes UV) (only usable in fragment shader)
+ case NODE_SCALAR_OP: {node.param1=SCALAR_OP_ADD;} break; // scalar vs scalar op (mul: {} break; add: {} break; div: {} break; etc)
+ case NODE_VEC_OP: {node.param1=VEC_OP_ADD;} break; // vec3 vs vec3 op (mul: {} break;ad: {} break;div: {} break;crossprod: {} break;etc)
+ case NODE_VEC_SCALAR_OP: {node.param1=VEC_SCALAR_OP_MUL;} break; // vec3 vs scalar op (mul: {} break; add: {} break; div: {} break; etc)
+ case NODE_RGB_OP: {node.param1=RGB_OP_SCREEN;} break; // vec3 vs vec3 rgb op (with scalar amount): {} break; like brighten: {} break; darken: {} break; burn: {} break; dodge: {} break; multiply: {} break; etc.
+ case NODE_XFORM_MULT: {} break; // mat4 x mat4
+ case NODE_XFORM_VEC_MULT: {} break; // mat4 x vec3 mult (with no-translation option)
+ case NODE_XFORM_VEC_INV_MULT: {} break; // mat4 x vec3 inverse mult (with no-translation option)
+ case NODE_SCALAR_FUNC: {node.param1=SCALAR_FUNC_SIN;} break; // scalar function (sin: {} break; cos: {} break; etc)
+ case NODE_VEC_FUNC: {node.param1=VEC_FUNC_NORMALIZE;} break; // vector function (normalize: {} break; negate: {} break; reciprocal: {} break; rgb2hsv: {} break; hsv2rgb: {} break; etc: {} break; etc)
+ case NODE_VEC_LEN: {} break; // vec3 length
+ case NODE_DOT_PROD: {} break; // vec3 . vec3 (dot product -> scalar output)
+ case NODE_VEC_TO_SCALAR: {} break; // 1 vec3 input: {} break; 3 scalar outputs
+ case NODE_SCALAR_TO_VEC: {} break; // 3 scalar input: {} break; 1 vec3 output
+ case NODE_VEC_TO_XFORM: {} break; // 3 scalar input: {} break; 1 vec3 output
+ case NODE_XFORM_TO_VEC: {} break; // 3 scalar input: {} break; 1 vec3 output
+ case NODE_SCALAR_INTERP: {} break; // scalar interpolation (with optional curve)
+ case NODE_VEC_INTERP: {} break; // vec3 interpolation (with optional curve)
+ case NODE_SCALAR_INPUT: {node.param1=_find_unique_name("Scalar"); node.param2=0;} break; // scalar uniform (assignable in material)
+ case NODE_VEC_INPUT: {node.param1=_find_unique_name("Vec3");node.param2=Vector3();} break; // vec3 uniform (assignable in material)
+ case NODE_RGB_INPUT: {node.param1=_find_unique_name("Color");node.param2=Color();} break; // color uniform (assignable in material)
+ case NODE_XFORM_INPUT: {node.param1=_find_unique_name("XForm"); node.param2=Transform();} break; // mat4 uniform (assignable in material)
+ case NODE_TEXTURE_INPUT: {node.param1=_find_unique_name("Tex"); } break; // texture input (assignable in material)
+ case NODE_CUBEMAP_INPUT: {node.param1=_find_unique_name("Cube"); } break; // cubemap input (assignable in material)
+ case NODE_OUTPUT: {} break; // output (shader type dependent)
+ case NODE_COMMENT: {} break; // comment
+ case NODE_TYPE_MAX: {};
+ }
+ shader[p_type].node_map[p_id]=node;
+ _request_update();
}
-void ShaderGraph::node_set_pos(int p_id, const Vector2& p_pos) {
+void ShaderGraph::node_set_pos(ShaderType p_type,int p_id, const Vector2& p_pos) {
+ ERR_FAIL_INDEX(p_type,3);
+
+ ERR_FAIL_COND(!shader[p_type].node_map.has(p_id));
+ shader[p_type].node_map[p_id].pos=p_pos;
+ _request_update();
- ERR_FAIL_COND(!node_map.has(p_id));
- node_map[p_id].x=p_pos.x;
- node_map[p_id].y=p_pos.y;
}
-Vector2 ShaderGraph::node_get_pos(int p_id) const {
+Vector2 ShaderGraph::node_get_pos(ShaderType p_type,int p_id) const {
+ ERR_FAIL_INDEX_V(p_type,3,Vector2());
- ERR_FAIL_COND_V(!node_map.has(p_id),Vector2());
- return Vector2(node_map[p_id].x,node_map[p_id].y);
+ ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),Vector2());
+ return shader[p_type].node_map[p_id].pos;
}
-void ShaderGraph::node_remove(int p_id) {
+void ShaderGraph::node_remove(ShaderType p_type,int p_id) {
+
+ ERR_FAIL_COND(p_id==0);
+ ERR_FAIL_INDEX(p_type,3);
- ERR_FAIL_COND(!node_map.has(p_id));
+ ERR_FAIL_COND(!shader[p_type].node_map.has(p_id));
//erase connections associated with node
- List<Connection>::Element *N,*E=connections.front();
- while(E) {
- N=E->next();
- const Connection &c = E->get();
- if (c.src_id==p_id || c.dst_id==p_id) {
+ for(Map<int,Node>::Element *E=shader[p_type].node_map.front();E;E=E->next()) {
+ if (E->key()==p_id)
+ continue; //no self
+
+ for (Map<int,SourceSlot>::Element *F=E->get().connections.front();F;) {
+ Map<int,SourceSlot>::Element *N=F->next();
+
+ if (F->get().id==p_id) {
+ E->get().connections.erase(F);
+ }
- connections.erase(E);
+ F=N;
}
- E=N;
}
- node_map.erase(p_id);
-}
-
-void ShaderGraph::node_change_type(int p_id, NodeType p_type) {
+ shader[p_type].node_map.erase(p_id);
- ERR_FAIL_COND(!node_map.has(p_id));
- node_map[p_id].type=p_type;
- node_map[p_id].param=Variant();
+ _request_update();
}
-void ShaderGraph::node_set_param(int p_id, const Variant& p_value) {
- ERR_FAIL_COND(!node_map.has(p_id));
- node_map[p_id].param=p_value;
-}
-void ShaderGraph::get_node_list(List<int> *p_node_list) const {
+void ShaderGraph::get_node_list(ShaderType p_type,List<int> *p_node_list) const {
- Map<int,Node>::Element *E = node_map.front();
+ ERR_FAIL_INDEX(p_type,3);
+
+ Map<int,Node>::Element *E = shader[p_type].node_map.front();
while(E) {
@@ -288,740 +598,1463 @@ void ShaderGraph::get_node_list(List<int> *p_node_list) const {
}
-ShaderGraph::NodeType ShaderGraph::node_get_type(int p_id) const {
+ShaderGraph::NodeType ShaderGraph::node_get_type(ShaderType p_type,int p_id) const {
- ERR_FAIL_COND_V(!node_map.has(p_id),NODE_TYPE_MAX);
- return node_map[p_id].type;
-}
+ ERR_FAIL_INDEX_V(p_type,3,NODE_TYPE_MAX);
-Variant ShaderGraph::node_get_param(int p_id) const {
-
- ERR_FAIL_COND_V(!node_map.has(p_id),Variant());
- return node_map[p_id].param;
+ ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),NODE_TYPE_MAX);
+ return shader[p_type].node_map[p_id].type;
}
-Error ShaderGraph::connect(int p_src_id,int p_src_slot, int p_dst_id,int p_dst_slot) {
+Error ShaderGraph::connect_node(ShaderType p_type,int p_src_id,int p_src_slot, int p_dst_id,int p_dst_slot) {
+ ERR_FAIL_INDEX_V(p_type,3,ERR_INVALID_PARAMETER);
ERR_FAIL_COND_V(p_src_id==p_dst_id, ERR_INVALID_PARAMETER);
- ERR_FAIL_COND_V(!node_map.has(p_src_id), ERR_INVALID_PARAMETER);
- ERR_FAIL_COND_V(!node_map.has(p_dst_id), ERR_INVALID_PARAMETER);
- NodeType type_src=node_map[p_src_id].type;
- NodeType type_dst=node_map[p_dst_id].type;
- //ERR_FAIL_INDEX_V( p_src_slot, VisualServer::shader_get_output_count(type_src), ERR_INVALID_PARAMETER );
- //ERR_FAIL_INDEX_V( p_dst_slot, VisualServer::shader_get_input_count(type_dst), ERR_INVALID_PARAMETER );
- //ERR_FAIL_COND_V(VisualServer::shader_is_output_vector(type_src,p_src_slot) != VisualServer::shader_is_input_vector(type_dst,p_dst_slot), ERR_INVALID_PARAMETER );
+ ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_src_id), ERR_INVALID_PARAMETER);
+ ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_dst_id), ERR_INVALID_PARAMETER);
+ NodeType type_src=shader[p_type].node_map[p_src_id].type;
+ NodeType type_dst=shader[p_type].node_map[p_dst_id].type;
+ ERR_FAIL_INDEX_V( p_src_slot, get_node_output_slot_count(get_mode(),p_type,type_src), ERR_INVALID_PARAMETER );
+ ERR_FAIL_INDEX_V( p_dst_slot, get_node_input_slot_count(get_mode(),p_type,type_dst), ERR_INVALID_PARAMETER );
+ ERR_FAIL_COND_V(get_node_output_slot_type(get_mode(),p_type,type_src,p_src_slot) != get_node_input_slot_type(get_mode(),p_type,type_dst,p_dst_slot), ERR_INVALID_PARAMETER );
- List<Connection>::Element *E=connections.front();
- while(E) {
- const Connection &c = E->get();
- ERR_FAIL_COND_V(c.dst_slot==p_dst_slot && c.dst_id == p_dst_id, ERR_ALREADY_EXISTS);
+ SourceSlot ts;
+ ts.id=p_src_id;
+ ts.slot=p_src_slot;
+ shader[p_type].node_map[p_dst_id].connections[p_dst_slot]=ts;
+ _request_update();
- E=E->next();
- }
+ return OK;
+}
- Connection c;
- c.src_slot=p_src_slot;
- c.src_id=p_src_id;
- c.dst_slot=p_dst_slot;
- c.dst_id=p_dst_id;
+bool ShaderGraph::is_node_connected(ShaderType p_type,int p_src_id,int p_src_slot, int p_dst_id,int p_dst_slot) const {
- connections.push_back(c);
+ ERR_FAIL_INDEX_V(p_type,3,false);
- return OK;
+ SourceSlot ts;
+ ts.id=p_src_id;
+ ts.slot=p_src_slot;
+ return shader[p_type].node_map.has(p_dst_id) && shader[p_type].node_map[p_dst_id].connections.has(p_dst_slot) &&
+ shader[p_type].node_map[p_dst_id].connections[p_dst_slot]==ts;
}
-bool ShaderGraph::is_connected(int p_src_id,int p_src_slot, int p_dst_id,int p_dst_slot) const {
+void ShaderGraph::disconnect_node(ShaderType p_type,int p_src_id,int p_src_slot, int p_dst_id,int p_dst_slot) {
+ ERR_FAIL_INDEX(p_type,3);
- const List<Connection>::Element *E=connections.front();
- while(E) {
- const Connection &c = E->get();
- if (c.dst_slot==p_dst_slot && c.dst_id == p_dst_id && c.src_slot==p_src_slot && c.src_id == p_src_id)
- return true;
+ SourceSlot ts;
+ ts.id=p_src_id;
+ ts.slot=p_src_slot;
+ if (shader[p_type].node_map.has(p_dst_id) && shader[p_type].node_map[p_dst_id].connections.has(p_dst_slot) &&
+ shader[p_type].node_map[p_dst_id].connections[p_dst_slot]==ts) {
+ shader[p_type].node_map[p_dst_id].connections.erase(p_dst_slot);
- E=E->next();
}
+ _request_update();
- return false;
}
-void ShaderGraph::disconnect(int p_src_id,int p_src_slot, int p_dst_id,int p_dst_slot) {
+void ShaderGraph::get_node_connections(ShaderType p_type,List<Connection> *p_connections) const {
- List<Connection>::Element *N,*E=connections.front();
- while(E) {
- N=E->next();
- const Connection &c = E->get();
- if (c.src_slot==p_src_slot && c.src_id==p_src_id && c.dst_slot==p_dst_slot && c.dst_id == p_dst_id) {
+ ERR_FAIL_INDEX(p_type,3);
+
+ for(const Map<int,Node>::Element *E=shader[p_type].node_map.front();E;E=E->next()) {
+ for (const Map<int,SourceSlot>::Element *F=E->get().connections.front();F;F=F->next()) {
- connections.erase(E);
+ Connection c;
+ c.dst_id=E->key();
+ c.dst_slot=F->key();
+ c.src_id=F->get().id;
+ c.src_slot=F->get().slot;
+ p_connections->push_back(c);
}
- E=N;
}
+}
+
+
+void ShaderGraph::clear(ShaderType p_type) {
+ ERR_FAIL_INDEX(p_type,3);
+ shader[p_type].node_map.clear();
+ Node out;
+ out.pos=Vector2(300,300);
+ out.type=NODE_OUTPUT;
+ shader[p_type].node_map.insert(0,out);
+
+ _request_update();
}
-void ShaderGraph::get_connections(List<Connection> *p_connections) const {
- const List<Connection>::Element*E=connections.front();
- while(E) {
- p_connections->push_back(E->get());
- E=E->next();
- }
+void ShaderGraph::scalar_const_node_set_value(ShaderType p_type,int p_id,float p_value) {
+ ERR_FAIL_INDEX(p_type,3);
+ ERR_FAIL_COND(!shader[p_type].node_map.has(p_id));
+ Node& n = shader[p_type].node_map[p_id];
+ ERR_FAIL_COND(n.type!=NODE_SCALAR_CONST);
+ n.param1=p_value;
+ _request_update();
}
+float ShaderGraph::scalar_const_node_get_value(ShaderType p_type,int p_id) const{
+
+ ERR_FAIL_INDEX_V(p_type,3,0);
+ ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),0);
+ const Node& n = shader[p_type].node_map[p_id];
+ ERR_FAIL_COND_V(n.type!=NODE_SCALAR_CONST,0);
+ return n.param1;
+}
+
+void ShaderGraph::vec_const_node_set_value(ShaderType p_type,int p_id,const Vector3& p_value){
+
+ ERR_FAIL_INDEX(p_type,3);
+ ERR_FAIL_COND(!shader[p_type].node_map.has(p_id));
+ Node& n = shader[p_type].node_map[p_id];
+ ERR_FAIL_COND(n.type!=NODE_VEC_CONST);
+ n.param1=p_value;
+ _request_update();
-void ShaderGraph::clear() {
- connections.clear();
- node_map.clear();
}
+Vector3 ShaderGraph::vec_const_node_get_value(ShaderType p_type,int p_id) const{
+ ERR_FAIL_INDEX_V(p_type,3,Vector3());
+ ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),Vector3());
+ const Node& n = shader[p_type].node_map[p_id];
+ ERR_FAIL_COND_V(n.type!=NODE_VEC_CONST,Vector3());
+ return n.param1;
-#if 0
-void ShaderGraph::node_add(NodeType p_type,int p_id) {
+}
+
+void ShaderGraph::rgb_const_node_set_value(ShaderType p_type,int p_id,const Color& p_value){
+
+ ERR_FAIL_INDEX(p_type,3);
+ ERR_FAIL_COND(!shader[p_type].node_map.has(p_id));
+ Node& n = shader[p_type].node_map[p_id];
+ ERR_FAIL_COND(n.type!=NODE_RGB_CONST);
+ n.param1=p_value;
+ _request_update();
- ShaderNode sn;
- sn.type=p_type;
- nodes[p_id]=sn;
- version++;
}
-void ShaderGraph::node_remove(int p_id) {
+Color ShaderGraph::rgb_const_node_get_value(ShaderType p_type,int p_id) const{
- nodes.erase(p_id);
+ ERR_FAIL_INDEX_V(p_type,3,Color());
+ ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),Color());
+ const Node& n = shader[p_type].node_map[p_id];
+ ERR_FAIL_COND_V(n.type!=NODE_RGB_CONST,Color());
+ return n.param1;
}
-void ShaderGraph::node_set_param( int p_id, const Variant& p_value) {
- VisualServer::get_singleton()->shader_node_set_param(shader,p_id,p_value);
- version++;
+void ShaderGraph::xform_const_node_set_value(ShaderType p_type,int p_id,const Transform& p_value){
+
+ ERR_FAIL_INDEX(p_type,3);
+ ERR_FAIL_COND(!shader[p_type].node_map.has(p_id));
+ Node& n = shader[p_type].node_map[p_id];
+ ERR_FAIL_COND(n.type!=NODE_XFORM_CONST);
+ n.param1=p_value;
+ _request_update();
+
}
+Transform ShaderGraph::xform_const_node_get_value(ShaderType p_type,int p_id) const{
-void ShaderGraph::get_node_list(List<int> *p_node_list) const {
+ ERR_FAIL_INDEX_V(p_type,3,Transform());
+ ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),Transform());
+ const Node& n = shader[p_type].node_map[p_id];
+ ERR_FAIL_COND_V(n.type!=NODE_XFORM_CONST,Transform());
+ return n.param1;
- VisualServer::get_singleton()->shader_get_node_list(shader,p_node_list);
}
-ShaderGraph::NodeType ShaderGraph::node_get_type(int p_id) const {
- return (NodeType)VisualServer::get_singleton()->shader_node_get_type(shader,p_id);
+void ShaderGraph::texture_node_set_filter_size(ShaderType p_type,int p_id,int p_size){
+
+ ERR_FAIL_INDEX(p_type,3);
+ ERR_FAIL_COND(!shader[p_type].node_map.has(p_id));
+ Node& n = shader[p_type].node_map[p_id];
+ ERR_FAIL_COND(n.type!=NODE_TEXTURE_INPUT && n.type!=NODE_SCREEN_TEX);
+ Array arr = n.param2;
+ arr[0]=p_size;
+ n.param2=arr;
+ _request_update();
+
}
-Variant ShaderGraph::node_get_param(int p_id) const {
+int ShaderGraph::texture_node_get_filter_size(ShaderType p_type,int p_id) const{
+
+ ERR_FAIL_INDEX_V(p_type,3,0);
+ ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),0);
+ const Node& n = shader[p_type].node_map[p_id];
+ ERR_FAIL_COND_V(n.type!=NODE_TEXTURE_INPUT && n.type!=NODE_SCREEN_TEX,0);
+ Array arr = n.param2;
+ return arr[0];
- return VisualServer::get_singleton()->shader_node_get_param(shader,p_id);
}
-void ShaderGraph::connect(int p_src_id,int p_src_slot, int p_dst_id,int p_dst_slot) {
+void ShaderGraph::texture_node_set_filter_strength(ShaderType p_type,float p_id,float p_strength){
- VisualServer::get_singleton()->shader_connect(shader,p_src_id,p_src_slot,p_dst_id,p_dst_slot);
- version++;
+ ERR_FAIL_INDEX(p_type,3);
+ ERR_FAIL_COND(!shader[p_type].node_map.has(p_id));
+ Node& n = shader[p_type].node_map[p_id];
+ ERR_FAIL_COND(n.type!=NODE_TEXTURE_INPUT && n.type!=NODE_SCREEN_TEX);
+ Array arr = n.param2;
+ arr[1]=p_strength;
+ n.param2=arr;
+ _request_update();
+
+}
+float ShaderGraph::texture_node_get_filter_strength(ShaderType p_type,float p_id) const{
+
+ ERR_FAIL_INDEX_V(p_type,3,0);
+ ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),0);
+ const Node& n = shader[p_type].node_map[p_id];
+ ERR_FAIL_COND_V(n.type!=NODE_TEXTURE_INPUT && n.type!=NODE_SCREEN_TEX,0);
+ Array arr = n.param2;
+ return arr[1];
}
-void ShaderGraph::disconnect(int p_src_id,int p_src_slot, int p_dst_id,int p_dst_slot) {
- VisualServer::get_singleton()->shader_disconnect(shader,p_src_id,p_src_slot,p_dst_id,p_dst_slot);
- version++;
+
+void ShaderGraph::scalar_op_node_set_op(ShaderType p_type,float p_id,ScalarOp p_op){
+
+ ERR_FAIL_INDEX(p_type,3);
+ ERR_FAIL_COND(!shader[p_type].node_map.has(p_id));
+ Node& n = shader[p_type].node_map[p_id];
+ ERR_FAIL_COND(n.type!=NODE_SCALAR_OP);
+ n.param1=p_op;
+ _request_update();
+
}
+ShaderGraph::ScalarOp ShaderGraph::scalar_op_node_get_op(ShaderType p_type,float p_id) const{
-void ShaderGraph::get_connections(List<Connection> *p_connections) const {
+ ERR_FAIL_INDEX_V(p_type,3,SCALAR_MAX_OP);
+ ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),SCALAR_MAX_OP);
+ const Node& n = shader[p_type].node_map[p_id];
+ ERR_FAIL_COND_V(n.type!=NODE_SCALAR_OP,SCALAR_MAX_OP);
+ int op = n.param1;
+ return ScalarOp(op);
- List<VS::ShaderGraphConnection> connections;
- VisualServer::get_singleton()->shader_get_connections(shader,&connections);
- for( List<VS::ShaderGraphConnection>::Element *E=connections.front();E;E=E->next()) {
+}
+
+
+void ShaderGraph::vec_op_node_set_op(ShaderType p_type,float p_id,VecOp p_op){
+
+ ERR_FAIL_INDEX(p_type,3);
+ ERR_FAIL_COND(!shader[p_type].node_map.has(p_id));
+ Node& n = shader[p_type].node_map[p_id];
+ ERR_FAIL_COND(n.type!=NODE_VEC_OP);
+ n.param1=p_op;
+ _request_update();
- Connection c;
- c.src_id=E->get().src_id;
- c.src_slot=E->get().src_slot;
- c.dst_id=E->get().dst_id;
- c.dst_slot=E->get().dst_slot;
- p_connections->push_back(c);
- }
}
+ShaderGraph::VecOp ShaderGraph::vec_op_node_get_op(ShaderType p_type,float p_id) const{
-void ShaderGraph::node_set_pos(int p_id,const Point2& p_pos) {
+ ERR_FAIL_INDEX_V(p_type,3,VEC_MAX_OP);
+ ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),VEC_MAX_OP);
+ const Node& n = shader[p_type].node_map[p_id];
+ ERR_FAIL_COND_V(n.type!=NODE_VEC_OP,VEC_MAX_OP);
+ int op = n.param1;
+ return VecOp(op);
-#ifdef TOOLS_ENABLED
- ERR_FAIL_COND(!positions.has(p_id));
- positions[p_id]=p_pos;
-#endif
}
-Point2 ShaderGraph::node_get_pos(int p_id) const {
-#ifdef TOOLS_ENABLED
- ERR_FAIL_COND_V(!positions.has(p_id),Point2());
- return positions[p_id];
-#endif
+
+void ShaderGraph::vec_scalar_op_node_set_op(ShaderType p_type,float p_id,VecScalarOp p_op){
+
+ ERR_FAIL_INDEX(p_type,3);
+ ERR_FAIL_COND(!shader[p_type].node_map.has(p_id));
+ Node& n = shader[p_type].node_map[p_id];
+ ERR_FAIL_COND(n.type!=NODE_VEC_SCALAR_OP);
+ n.param1=p_op;
+ _request_update();
+
}
+ShaderGraph::VecScalarOp ShaderGraph::vec_scalar_op_node_get_op(ShaderType p_type,float p_id) const{
-void ShaderGraph::clear() {
+ ERR_FAIL_INDEX_V(p_type,3,VEC_SCALAR_MAX_OP);
+ ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),VEC_SCALAR_MAX_OP);
+ const Node& n = shader[p_type].node_map[p_id];
+ ERR_FAIL_COND_V(n.type!=NODE_VEC_SCALAR_OP,VEC_SCALAR_MAX_OP);
+ int op = n.param1;
+ return VecScalarOp(op);
- VisualServer::get_singleton()->shader_clear(shader);
- version++;
}
-#endif
-ShaderGraph::ShaderGraph() {
+void ShaderGraph::rgb_op_node_set_op(ShaderType p_type,float p_id,RGBOp p_op){
+
+ ERR_FAIL_INDEX(p_type,3);
+ ERR_FAIL_COND(!shader[p_type].node_map.has(p_id));
+ Node& n = shader[p_type].node_map[p_id];
+ ERR_FAIL_COND(n.type!=NODE_RGB_OP);
+ n.param1=p_op;
+
+ _request_update();
- //shader = VisualServer::get_singleton()->shader_create();
- version = 1;
}
+ShaderGraph::RGBOp ShaderGraph::rgb_op_node_get_op(ShaderType p_type,float p_id) const{
-ShaderGraph::~ShaderGraph() {
+ ERR_FAIL_INDEX_V(p_type,3,RGB_MAX_OP);
+ ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),RGB_MAX_OP);
+ const Node& n = shader[p_type].node_map[p_id];
+ ERR_FAIL_COND_V(n.type!=NODE_RGB_OP,RGB_MAX_OP);
+ int op = n.param1;
+ return RGBOp(op);
- //VisualServer::get_singleton()->free(shader);
}
-#if 0
-void ShaderGraph::shader_get_default_input_nodes(Mode p_type,List<PropertyInfo> *p_inputs) {
- switch(p_type) {
+void ShaderGraph::xform_vec_mult_node_set_no_translation(ShaderType p_type,int p_id,bool p_no_translation){
- case SHADER_VERTEX: {
+ ERR_FAIL_INDEX(p_type,3);
+ ERR_FAIL_COND(!shader[p_type].node_map.has(p_id));
+ Node& n = shader[p_type].node_map[p_id];
+ ERR_FAIL_COND(n.type!=NODE_XFORM_VEC_MULT && n.type!=NODE_XFORM_VEC_INV_MULT);
+ n.param1=p_no_translation;
+ _request_update();
- p_inputs->push_back( PropertyInfo( Variant::VECTOR3,"vertex") );
- p_inputs->push_back( PropertyInfo( Variant::VECTOR3,"normal") );
- p_inputs->push_back( PropertyInfo( Variant::VECTOR3,"binormal") );
- p_inputs->push_back( PropertyInfo( Variant::VECTOR3,"tangent") );
- p_inputs->push_back( PropertyInfo( Variant::VECTOR3,"uv") );
- p_inputs->push_back( PropertyInfo( Variant::VECTOR3,"color") );
- p_inputs->push_back( PropertyInfo( Variant::REAL,"alpha") );
- } break;
- case SHADER_FRAGMENT: {
+}
+bool ShaderGraph::xform_vec_mult_node_get_no_translation(ShaderType p_type,int p_id) const{
- p_inputs->push_back( PropertyInfo( Variant::VECTOR3,"position") );
- p_inputs->push_back( PropertyInfo( Variant::VECTOR3,"normal") );
- p_inputs->push_back( PropertyInfo( Variant::VECTOR3,"binormal") );
- p_inputs->push_back( PropertyInfo( Variant::VECTOR3,"tangent") );
- p_inputs->push_back( PropertyInfo( Variant::VECTOR3,"uv") );
- p_inputs->push_back( PropertyInfo( Variant::VECTOR3,"color") );
- p_inputs->push_back( PropertyInfo( Variant::REAL,"alpha") );
+ ERR_FAIL_INDEX_V(p_type,3,false);
+ ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),false);
+ const Node& n = shader[p_type].node_map[p_id];
+ ERR_FAIL_COND_V(n.type!=NODE_XFORM_VEC_MULT && n.type!=NODE_XFORM_VEC_INV_MULT,false);
+ return n.param1;
- } break;
- case SHADER_POST_PROCESS: {
- p_inputs->push_back( PropertyInfo( Variant::VECTOR3,"color") );
- p_inputs->push_back( PropertyInfo( Variant::REAL,"alpha") );
- } break;
+}
- }
+void ShaderGraph::scalar_func_node_set_function(ShaderType p_type,int p_id,ScalarFunc p_func){
+ ERR_FAIL_INDEX(p_type,3);
+ ERR_FAIL_COND(!shader[p_type].node_map.has(p_id));
+ Node& n = shader[p_type].node_map[p_id];
+ ERR_FAIL_COND(n.type!=NODE_SCALAR_FUNC);
+ int func = p_func;
+ ERR_FAIL_INDEX(func,SCALAR_MAX_FUNC);
+ n.param1=func;
+ _request_update();
+
+}
+ShaderGraph::ScalarFunc ShaderGraph::scalar_func_node_get_function(ShaderType p_type,int p_id) const{
+
+ ERR_FAIL_INDEX_V(p_type,3,SCALAR_MAX_FUNC);
+ ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),SCALAR_MAX_FUNC);
+ const Node& n = shader[p_type].node_map[p_id];
+ ERR_FAIL_COND_V(n.type!=NODE_SCALAR_FUNC,SCALAR_MAX_FUNC);
+ int func = n.param1;
+ return ScalarFunc(func);
}
-void ShaderGraph::shader_get_default_output_nodes(ShaderGraphType p_type,List<PropertyInfo> *p_outputs) {
- switch(p_type) {
+void ShaderGraph::vec_func_node_set_function(ShaderType p_type,int p_id,VecFunc p_func){
- case SHADER_VERTEX: {
+ ERR_FAIL_INDEX(p_type,3);
+ ERR_FAIL_COND(!shader[p_type].node_map.has(p_id));
+ Node& n = shader[p_type].node_map[p_id];
+ ERR_FAIL_COND(n.type!=NODE_VEC_FUNC);
+ int func = p_func;
+ ERR_FAIL_INDEX(func,VEC_MAX_FUNC);
+ n.param1=func;
- p_outputs->push_back( PropertyInfo( Variant::VECTOR3,"vertex") );
- p_outputs->push_back( PropertyInfo( Variant::VECTOR3,"normal") );
- p_outputs->push_back( PropertyInfo( Variant::VECTOR3,"binormal") );
- p_outputs->push_back( PropertyInfo( Variant::VECTOR3,"tangent") );
- p_outputs->push_back( PropertyInfo( Variant::VECTOR3,"uv") );
- p_outputs->push_back( PropertyInfo( Variant::VECTOR3,"color") );
- p_outputs->push_back( PropertyInfo( Variant::REAL,"alpha") );
- } break;
- case SHADER_FRAGMENT: {
+ _request_update();
- p_outputs->push_back( PropertyInfo( Variant::VECTOR3,"normal") );
- p_outputs->push_back( PropertyInfo( Variant::VECTOR3,"diffuse") );
- p_outputs->push_back( PropertyInfo( Variant::VECTOR3,"specular") );
- p_outputs->push_back( PropertyInfo( Variant::REAL,"alpha") );
- p_outputs->push_back( PropertyInfo( Variant::REAL,"emission") );
- p_outputs->push_back( PropertyInfo( Variant::REAL,"spec_exp") );
- p_outputs->push_back( PropertyInfo( Variant::REAL,"glow") );
- p_outputs->push_back( PropertyInfo( Variant::REAL,"alpha_discard") );
+}
+ShaderGraph::VecFunc ShaderGraph::vec_func_node_get_function(ShaderType p_type, int p_id) const{
+
+ ERR_FAIL_INDEX_V(p_type,3,VEC_MAX_FUNC);
+ ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),VEC_MAX_FUNC);
+ const Node& n = shader[p_type].node_map[p_id];
+ ERR_FAIL_COND_V(n.type!=NODE_VEC_FUNC,VEC_MAX_FUNC);
+ int func = n.param1;
+ return VecFunc(func);
+}
- } break;
- case SHADER_POST_PROCESS: {
- p_outputs->push_back( PropertyInfo( Variant::VECTOR3,"color") );
- p_outputs->push_back( PropertyInfo( Variant::REAL,"alpha") );
- } break;
+void ShaderGraph::input_node_set_name(ShaderType p_type,int p_id,const String& p_name){
+
+ ERR_FAIL_INDEX(p_type,3);
+ ERR_FAIL_COND(!shader[p_type].node_map.has(p_id));
+ ERR_FAIL_COND(!p_name.is_valid_identifier());
+ Node& n = shader[p_type].node_map[p_id];
+ ERR_FAIL_COND(n.type!=NODE_SCALAR_INPUT && n.type!=NODE_VEC_INPUT && n.type==NODE_RGB_INPUT && n.type==NODE_XFORM_INPUT && n.type==NODE_TEXTURE_INPUT && n.type==NODE_CUBEMAP_INPUT);
+
+ n.param1="";
+ n.param1=_find_unique_name(p_name);
+ _request_update();
+
+}
+String ShaderGraph::input_node_get_name(ShaderType p_type,int p_id){
+
+ ERR_FAIL_INDEX_V(p_type,3,String());
+ ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),String());
+ const Node& n = shader[p_type].node_map[p_id];
+ ERR_FAIL_COND_V(n.type!=NODE_SCALAR_INPUT && n.type!=NODE_VEC_INPUT && n.type==NODE_RGB_INPUT && n.type==NODE_XFORM_INPUT && n.type==NODE_TEXTURE_INPUT && n.type==NODE_CUBEMAP_INPUT,String());
+ return n.param1;
+}
+
+
+void ShaderGraph::scalar_input_node_set_value(ShaderType p_type,int p_id,float p_value) {
+
+ ERR_FAIL_INDEX(p_type,3);
+ ERR_FAIL_COND(!shader[p_type].node_map.has(p_id));
+ Node& n = shader[p_type].node_map[p_id];
+ ERR_FAIL_COND(n.type!=NODE_SCALAR_INPUT);
+ n.param2=p_value;
+ _request_update();
+
+}
+
+float ShaderGraph::scalar_input_node_get_value(ShaderType p_type,int p_id) const{
+
+ ERR_FAIL_INDEX_V(p_type,3,0);
+ ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),0);
+ const Node& n = shader[p_type].node_map[p_id];
+ ERR_FAIL_COND_V(n.type!=NODE_SCALAR_INPUT,0);
+
+ return n.param2;
+}
+
+void ShaderGraph::vec_input_node_set_value(ShaderType p_type,int p_id,const Vector3& p_value){
+
+ ERR_FAIL_INDEX(p_type,3);
+ ERR_FAIL_COND(!shader[p_type].node_map.has(p_id));
+ Node& n = shader[p_type].node_map[p_id];
+ ERR_FAIL_COND(n.type!=NODE_VEC_INPUT);
+
+ n.param2=p_value;
+ _request_update();
+
+}
+Vector3 ShaderGraph::vec_input_node_get_value(ShaderType p_type,int p_id) const{
+
+ ERR_FAIL_INDEX_V(p_type,3,Vector3());
+ ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),Vector3());
+ const Node& n = shader[p_type].node_map[p_id];
+ ERR_FAIL_COND_V(n.type!=NODE_VEC_INPUT,Vector3());
+ return n.param2;
+}
+
+void ShaderGraph::rgb_input_node_set_value(ShaderType p_type,int p_id,const Color& p_value){
+
+ ERR_FAIL_INDEX(p_type,3);
+ ERR_FAIL_COND(!shader[p_type].node_map.has(p_id));
+ Node& n = shader[p_type].node_map[p_id];
+ ERR_FAIL_COND(n.type!=NODE_RGB_INPUT);
+ n.param2=p_value;
+ _request_update();
+
+}
+Color ShaderGraph::rgb_input_node_get_value(ShaderType p_type,int p_id) const{
+
+ ERR_FAIL_INDEX_V(p_type,3,Color());
+ ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),Color());
+ const Node& n = shader[p_type].node_map[p_id];
+ ERR_FAIL_COND_V(n.type!=NODE_RGB_INPUT,Color());
+ return n.param2;
+}
+
+void ShaderGraph::xform_input_node_set_value(ShaderType p_type,int p_id,const Transform& p_value){
+
+ ERR_FAIL_INDEX(p_type,3);
+ ERR_FAIL_COND(!shader[p_type].node_map.has(p_id));
+ Node& n = shader[p_type].node_map[p_id];
+ ERR_FAIL_COND(n.type!=NODE_XFORM_INPUT);
+ n.param2=p_value;
+ _request_update();
+
+}
+Transform ShaderGraph::xform_input_node_get_value(ShaderType p_type,int p_id) const{
+
+ ERR_FAIL_INDEX_V(p_type,3,Transform());
+ ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),Transform());
+ const Node& n = shader[p_type].node_map[p_id];
+ ERR_FAIL_COND_V(n.type!=NODE_XFORM_INPUT,Transform());
+ return n.param2;
+}
+
+
+void ShaderGraph::texture_input_node_set_value(ShaderType p_type,int p_id,const Ref<Texture>& p_texture) {
+
+ ERR_FAIL_INDEX(p_type,3);
+ ERR_FAIL_COND(!shader[p_type].node_map.has(p_id));
+ Node& n = shader[p_type].node_map[p_id];
+ ERR_FAIL_COND(n.type!=NODE_TEXTURE_INPUT);
+ n.param2=p_texture;
+ _request_update();
+}
+
+Ref<Texture> ShaderGraph::texture_input_node_get_value(ShaderType p_type,int p_id) const{
+
+ ERR_FAIL_INDEX_V(p_type,3,Ref<Texture>());
+ ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),Ref<Texture>());
+ const Node& n = shader[p_type].node_map[p_id];
+ ERR_FAIL_COND_V(n.type!=NODE_TEXTURE_INPUT,Ref<Texture>());
+ return n.param2;
+}
+
+void ShaderGraph::cubemap_input_node_set_value(ShaderType p_type,int p_id,const Ref<CubeMap>& p_cubemap){
+
+ ERR_FAIL_INDEX(p_type,3);
+ ERR_FAIL_COND(!shader[p_type].node_map.has(p_id));
+ Node& n = shader[p_type].node_map[p_id];
+ ERR_FAIL_COND(n.type!=NODE_CUBEMAP_INPUT);
+ n.param2=p_cubemap;
+ _request_update();
+
+}
+
+Ref<CubeMap> ShaderGraph::cubemap_input_node_get_value(ShaderType p_type,int p_id) const{
+
+ ERR_FAIL_INDEX_V(p_type,3,Ref<CubeMap>());
+ ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),Ref<CubeMap>());
+ const Node& n = shader[p_type].node_map[p_id];
+ ERR_FAIL_COND_V(n.type!=NODE_CUBEMAP_INPUT,Ref<CubeMap>());
+ return n.param2;
+
+}
+
+
+void ShaderGraph::comment_node_set_text(ShaderType p_type,int p_id,const String& p_comment) {
+
+ ERR_FAIL_INDEX(p_type,3);
+ ERR_FAIL_COND(!shader[p_type].node_map.has(p_id));
+ Node& n = shader[p_type].node_map[p_id];
+ ERR_FAIL_COND(n.type!=NODE_COMMENT);
+ n.param1=p_comment;
+
+}
+
+String ShaderGraph::comment_node_get_text(ShaderType p_type,int p_id) const{
+
+ ERR_FAIL_INDEX_V(p_type,3,String());
+ ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),String());
+ const Node& n = shader[p_type].node_map[p_id];
+ ERR_FAIL_COND_V(n.type!=NODE_COMMENT,String());
+ return n.param1;
+
+}
+
+void ShaderGraph::_request_update() {
+
+ if (_pending_update_shader)
+ return;
+
+ _pending_update_shader=true;
+ call_deferred("_update_shader");
+
+}
+
+Variant ShaderGraph::node_get_state(ShaderType p_type,int p_id) const {
+
+ ERR_FAIL_INDEX_V(p_type,3,Variant());
+ ERR_FAIL_COND_V(!shader[p_type].node_map.has(p_id),Variant());
+ const Node& n = shader[p_type].node_map[p_id];
+ Dictionary s;
+ s["pos"]=n.pos;
+ s["param1"]=n.param1;
+ s["param2"]=n.param2;
+ return s;
+
+}
+void ShaderGraph::node_set_state(ShaderType p_type,int p_id,const Variant& p_state) {
+
+ ERR_FAIL_INDEX(p_type,3);
+ ERR_FAIL_COND(!shader[p_type].node_map.has(p_id));
+ Node& n = shader[p_type].node_map[p_id];
+ Dictionary d = p_state;
+ ERR_FAIL_COND(!d.has("pos"));
+ ERR_FAIL_COND(!d.has("param1"));
+ ERR_FAIL_COND(!d.has("param2"));
+ n.pos=d["pos"];
+ n.param1=d["param1"];
+ n.param2=d["param2"];
+
+}
+
+ShaderGraph::ShaderGraph(Mode p_mode) : Shader(p_mode) {
+
+ //shader = VisualServer::get_singleton()->shader_create();
+ _pending_update_shader=false;
+ Node out;
+ out.id=0;
+ out.pos=Vector2(250,20);
+ out.type=NODE_OUTPUT;
+ for(int i=0;i<3;i++) {
+
+ shader[i].node_map.insert(0,out);
}
+}
+
+ShaderGraph::~ShaderGraph() {
+ //VisualServer::get_singleton()->free(shader);
+}
+
+
+const ShaderGraph::InOutParamInfo ShaderGraph::inout_param_info[]={
+ //material vertex in
+ {MODE_MATERIAL,SHADER_TYPE_VERTEX,"Vertex","SRC_VERTEX","",SLOT_TYPE_VEC,SLOT_IN},
+ {MODE_MATERIAL,SHADER_TYPE_VERTEX,"Normal","SRC_NORMAL","",SLOT_TYPE_VEC,SLOT_IN},
+ {MODE_MATERIAL,SHADER_TYPE_VERTEX,"Tangent","SRC_TANGENT","",SLOT_TYPE_VEC,SLOT_IN},
+ {MODE_MATERIAL,SHADER_TYPE_VERTEX,"BinormalF","SRC_BINORMALF","",SLOT_TYPE_SCALAR,SLOT_IN},
+ {MODE_MATERIAL,SHADER_TYPE_VERTEX,"Color","SRC_COLOR","",SLOT_TYPE_VEC,SLOT_IN},
+ {MODE_MATERIAL,SHADER_TYPE_VERTEX,"Alpha","SRC_ALPHA","",SLOT_TYPE_SCALAR,SLOT_IN},
+ {MODE_MATERIAL,SHADER_TYPE_VERTEX,"UV","SRC_UV","",SLOT_TYPE_VEC,SLOT_IN},
+ {MODE_MATERIAL,SHADER_TYPE_VERTEX,"UV2","SRC_UV2","",SLOT_TYPE_VEC,SLOT_IN},
+ {MODE_MATERIAL,SHADER_TYPE_VERTEX,"WorldMatrix","WORLD_MATRIX","",SLOT_TYPE_XFORM,SLOT_IN},
+ {MODE_MATERIAL,SHADER_TYPE_VERTEX,"InvCameraMatrix","INV_CAMERA_MATRIX","",SLOT_TYPE_XFORM,SLOT_IN},
+ {MODE_MATERIAL,SHADER_TYPE_VERTEX,"ProjectionMatrix","PROJECTION_MATRIX","",SLOT_TYPE_XFORM,SLOT_IN},
+ {MODE_MATERIAL,SHADER_TYPE_VERTEX,"ModelviewMatrix","MODELVIEW_MATRIX","",SLOT_TYPE_XFORM,SLOT_IN},
+ {MODE_MATERIAL,SHADER_TYPE_VERTEX,"InstanceID","INSTANCE_ID","",SLOT_TYPE_SCALAR,SLOT_IN},
+
+ //material vertex out
+ {MODE_MATERIAL,SHADER_TYPE_VERTEX,"Vertex","VERTEX","",SLOT_TYPE_VEC,SLOT_OUT},
+ {MODE_MATERIAL,SHADER_TYPE_VERTEX,"Normal","NORMAL","",SLOT_TYPE_VEC,SLOT_OUT},
+ {MODE_MATERIAL,SHADER_TYPE_VERTEX,"Tangent","TANGENT","",SLOT_TYPE_VEC,SLOT_OUT},
+ {MODE_MATERIAL,SHADER_TYPE_VERTEX,"Binormal","BINORMAL","",SLOT_TYPE_VEC,SLOT_OUT},
+ {MODE_MATERIAL,SHADER_TYPE_VERTEX,"UV","UV",".xy",SLOT_TYPE_VEC,SLOT_OUT},
+ {MODE_MATERIAL,SHADER_TYPE_VERTEX,"UV2","UV2",".xy",SLOT_TYPE_VEC,SLOT_OUT},
+ {MODE_MATERIAL,SHADER_TYPE_VERTEX,"Color","COLOR.rgb","",SLOT_TYPE_VEC,SLOT_OUT},
+ {MODE_MATERIAL,SHADER_TYPE_VERTEX,"Alpha","COLOR.a","",SLOT_TYPE_SCALAR,SLOT_OUT},
+ {MODE_MATERIAL,SHADER_TYPE_VERTEX,"Var1","VAR1.rgb","",SLOT_TYPE_VEC,SLOT_OUT},
+ {MODE_MATERIAL,SHADER_TYPE_VERTEX,"Var2","VAR2.rgb","",SLOT_TYPE_VEC,SLOT_OUT},
+ {MODE_MATERIAL,SHADER_TYPE_VERTEX,"SpecExp","SPEC_EXP","",SLOT_TYPE_SCALAR,SLOT_OUT},
+ {MODE_MATERIAL,SHADER_TYPE_VERTEX,"PointSize","POINT_SIZE","",SLOT_TYPE_SCALAR,SLOT_OUT},
+ //pixel vertex in
+ {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Vertex","VERTEX","",SLOT_TYPE_VEC,SLOT_IN},
+ {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Position","POSITION.xyz","",SLOT_TYPE_VEC,SLOT_IN},
+ {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Normal","IN_NORMAL","",SLOT_TYPE_VEC,SLOT_IN},
+ {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Tangent","TANGENT","",SLOT_TYPE_VEC,SLOT_IN},
+ {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Binormal","BINORMAL","",SLOT_TYPE_VEC,SLOT_IN},
+ {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"UV","vec3(UV,0);","",SLOT_TYPE_VEC,SLOT_IN},
+ {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"UV2","UV2","",SLOT_TYPE_VEC,SLOT_IN},
+ {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"UVScreen","SCREEN_UV","",SLOT_TYPE_VEC,SLOT_IN},
+ {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"PointCoord","POINT_COORD","",SLOT_TYPE_VEC,SLOT_IN},
+ {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Color","COLOR.rgb","",SLOT_TYPE_VEC,SLOT_IN},
+ {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Alpha","COLOR.a","",SLOT_TYPE_SCALAR,SLOT_IN},
+ {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"InvCameraMatrix","INV_CAMERA_MATRIX","",SLOT_TYPE_XFORM,SLOT_IN},
+ {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Var1","VAR1.rgb","",SLOT_TYPE_VEC,SLOT_IN},
+ {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Var2","VAR2.rgb","",SLOT_TYPE_VEC,SLOT_IN},
+ //pixel vertex out
+ {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Diffuse","DIFFUSE_OUT","",SLOT_TYPE_VEC,SLOT_OUT},
+ {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"DiffuseAlpha","ALPHA_OUT","",SLOT_TYPE_SCALAR,SLOT_OUT},
+ {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Specular","SPECULAR","",SLOT_TYPE_VEC,SLOT_OUT},
+ {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"SpecularExp","SPECULAR","",SLOT_TYPE_SCALAR,SLOT_OUT},
+ {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Emission","EMISSION","",SLOT_TYPE_VEC,SLOT_OUT},
+ {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Glow","GLOW","",SLOT_TYPE_SCALAR,SLOT_OUT},
+ {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"ShadeParam","SHADE_PARAM","",SLOT_TYPE_SCALAR,SLOT_OUT},
+ {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Normal","NORMAL","",SLOT_TYPE_VEC,SLOT_OUT},
+ {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"NormalMap","NORMALMAP","",SLOT_TYPE_VEC,SLOT_OUT},
+ {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"NormalMapDepth","NORMALMAP_DEPTH","",SLOT_TYPE_SCALAR,SLOT_OUT},
+ {MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Discard","DISCARD",">0.5",SLOT_TYPE_SCALAR,SLOT_OUT},
+ //light in
+ {MODE_MATERIAL,SHADER_TYPE_LIGHT,"Normal","NORMAL","",SLOT_TYPE_VEC,SLOT_IN},
+ {MODE_MATERIAL,SHADER_TYPE_LIGHT,"LightDir","LIGHT_DIR","",SLOT_TYPE_VEC,SLOT_IN},
+ {MODE_MATERIAL,SHADER_TYPE_LIGHT,"LightDiffuse","LIGHT_DIFFUSE","",SLOT_TYPE_VEC,SLOT_IN},
+ {MODE_MATERIAL,SHADER_TYPE_LIGHT,"LightSpecular","LIGHT_SPECULAR","",SLOT_TYPE_VEC,SLOT_IN},
+ {MODE_MATERIAL,SHADER_TYPE_LIGHT,"EyeVec","EYE_VEC","",SLOT_TYPE_VEC,SLOT_IN},
+ {MODE_MATERIAL,SHADER_TYPE_LIGHT,"Diffuse","DIFFUSE","",SLOT_TYPE_VEC,SLOT_IN},
+ {MODE_MATERIAL,SHADER_TYPE_LIGHT,"Specular","SPECULAR","",SLOT_TYPE_VEC,SLOT_IN},
+ {MODE_MATERIAL,SHADER_TYPE_LIGHT,"SpecExp","SPECULAR_EXP","",SLOT_TYPE_SCALAR,SLOT_IN},
+ {MODE_MATERIAL,SHADER_TYPE_LIGHT,"ShadeParam","SHADE_PARAM","",SLOT_TYPE_SCALAR,SLOT_IN},
+ //light out
+ {MODE_MATERIAL,SHADER_TYPE_LIGHT,"Light","LIGHT","",SLOT_TYPE_VEC,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<SlotInfo> *r_slots) {
+
+ const InOutParamInfo* iop = &inout_param_info[0];
+ while(iop->name) {
+ if (p_mode==iop->shader_mode && p_type==iop->shader_type) {
+
+ SlotInfo si;
+ si.dir=iop->dir;
+ si.name=iop->name;
+ si.type=iop->slot_type;
+ r_slots->push_back(si);
+ }
+ iop++;
+ }
}
-PropertyInfo ShaderGraph::shader_node_get_type_info(NodeType p_type) {
-
- switch(p_type) {
-
- case NODE_IN: return PropertyInfo(Variant::STRING,"in");
- case NODE_OUT: return PropertyInfo(Variant::STRING,"out");
- case NODE_CONSTANT: return PropertyInfo(Variant::REAL,"const");
- case NODE_PARAMETER: return PropertyInfo(Variant::STRING,"param");
- case NODE_ADD: return PropertyInfo(Variant::NIL,"add");
- case NODE_SUB: return PropertyInfo(Variant::NIL,"sub");
- case NODE_MUL: return PropertyInfo(Variant::NIL,"mul");
- case NODE_DIV: return PropertyInfo(Variant::NIL,"div");
- case NODE_MOD: return PropertyInfo(Variant::NIL,"rem");
- case NODE_SIN: return PropertyInfo(Variant::NIL,"sin");
- case NODE_COS: return PropertyInfo(Variant::NIL,"cos");
- case NODE_TAN: return PropertyInfo(Variant::NIL,"tan");
- case NODE_ARCSIN: return PropertyInfo(Variant::NIL,"arcsin");
- case NODE_ARCCOS: return PropertyInfo(Variant::NIL,"arccos");
- case NODE_ARCTAN: return PropertyInfo(Variant::NIL,"arctan");
- case NODE_POW: return PropertyInfo(Variant::NIL,"pow");
- case NODE_LOG: return PropertyInfo(Variant::NIL,"log");
- case NODE_MAX: return PropertyInfo(Variant::NIL,"max");
- case NODE_MIN: return PropertyInfo(Variant::NIL,"min");
- case NODE_COMPARE: return PropertyInfo(Variant::NIL,"cmp");
- case NODE_TEXTURE: return PropertyInfo(Variant::_RID,"texture1D",PROPERTY_HINT_RESOURCE_TYPE,"Texture");
- case NODE_TIME: return PropertyInfo(Variant::NIL,"time");
- case NODE_NOISE: return PropertyInfo(Variant::NIL,"noise");
- case NODE_PASS: return PropertyInfo(Variant::NIL,"pass");
- case NODE_VEC_IN: return PropertyInfo(Variant::STRING,"vin");
- case NODE_VEC_OUT: return PropertyInfo(Variant::STRING,"vout");
- case NODE_VEC_CONSTANT: return PropertyInfo(Variant::VECTOR3,"vconst");
- case NODE_VEC_PARAMETER: return PropertyInfo(Variant::STRING,"vparam");
- case NODE_VEC_ADD: return PropertyInfo(Variant::NIL,"vadd");
- case NODE_VEC_SUB: return PropertyInfo(Variant::NIL,"vsub");
- case NODE_VEC_MUL: return PropertyInfo(Variant::NIL,"vmul");
- case NODE_VEC_DIV: return PropertyInfo(Variant::NIL,"vdiv");
- case NODE_VEC_MOD: return PropertyInfo(Variant::NIL,"vrem");
- case NODE_VEC_CROSS: return PropertyInfo(Variant::NIL,"cross");
- case NODE_VEC_DOT: return PropertyInfo(Variant::NIL,"dot");
- case NODE_VEC_POW: return PropertyInfo(Variant::NIL,"vpow");
- case NODE_VEC_NORMALIZE: return PropertyInfo(Variant::NIL,"normalize");
- case NODE_VEC_INTERPOLATE: return PropertyInfo(Variant::NIL,"mix");
- case NODE_VEC_SCREEN_TO_UV: return PropertyInfo(Variant::NIL,"scrn2uv");
- case NODE_VEC_TRANSFORM3: return PropertyInfo(Variant::NIL,"xform3");
- case NODE_VEC_TRANSFORM4: return PropertyInfo(Variant::NIL,"xform4");
- case NODE_VEC_COMPARE: return PropertyInfo(Variant::_RID,"vcmp",PROPERTY_HINT_RESOURCE_TYPE,"Texture");
- case NODE_VEC_TEXTURE_2D: return PropertyInfo(Variant::_RID,"texture2D",PROPERTY_HINT_RESOURCE_TYPE,"Texture");
- case NODE_VEC_TEXTURE_CUBE: return PropertyInfo(Variant::NIL,"texcube");
- case NODE_VEC_NOISE: return PropertyInfo(Variant::NIL,"vec_noise");
- case NODE_VEC_0: return PropertyInfo(Variant::NIL,"vec_0");
- case NODE_VEC_1: return PropertyInfo(Variant::NIL,"vec_1");
- case NODE_VEC_2: return PropertyInfo(Variant::NIL,"vec_2");
- case NODE_VEC_BUILD: return PropertyInfo(Variant::NIL,"vbuild");
- case NODE_VEC_PASS: return PropertyInfo(Variant::NIL,"vpass");
- case NODE_COLOR_CONSTANT: return PropertyInfo(Variant::COLOR,"color_const");
- case NODE_COLOR_PARAMETER: return PropertyInfo(Variant::STRING,"color_param");
- case NODE_TEXTURE_PARAMETER: return PropertyInfo(Variant::STRING,"tex1D_param");
- case NODE_TEXTURE_2D_PARAMETER: return PropertyInfo(Variant::STRING,"tex2D_param");
- case NODE_TEXTURE_CUBE_PARAMETER: return PropertyInfo(Variant::STRING,"texcube_param");
- case NODE_TRANSFORM_CONSTANT: return PropertyInfo(Variant::TRANSFORM,"xform_const");
- case NODE_TRANSFORM_PARAMETER: return PropertyInfo(Variant::STRING,"xform_param");
- case NODE_LABEL: return PropertyInfo(Variant::STRING,"label");
-
- default: {}
+const ShaderGraph::NodeSlotInfo ShaderGraph::node_slot_info[]= {
+
+ {NODE_SCALAR_CONST,{SLOT_MAX},{SLOT_TYPE_SCALAR,SLOT_MAX}}, //scalar constant
+ {NODE_VEC_CONST,{SLOT_MAX},{SLOT_TYPE_VEC,SLOT_MAX}}, //vec3 constant
+ {NODE_RGB_CONST,{SLOT_MAX},{SLOT_TYPE_VEC,SLOT_TYPE_SCALAR,SLOT_MAX}}, //rgb constant (shows a color picker instead)
+ {NODE_XFORM_CONST,{SLOT_MAX},{SLOT_TYPE_XFORM,SLOT_MAX}}, // 4x4 matrix constant
+ {NODE_TIME,{SLOT_MAX},{SLOT_TYPE_SCALAR,SLOT_MAX}}, // time in seconds
+ {NODE_SCREEN_TEX,{SLOT_TYPE_VEC,SLOT_MAX},{SLOT_TYPE_VEC,SLOT_MAX}}, // screen texture sampler (takes UV) (only usable in fragment shader)
+ {NODE_SCALAR_OP,{SLOT_TYPE_SCALAR,SLOT_TYPE_SCALAR,SLOT_MAX},{SLOT_TYPE_SCALAR,SLOT_MAX}}, // scalar vs scalar op (mul,{SLOT_MAX},{SLOT_MAX}}, add,{SLOT_MAX},{SLOT_MAX}}, div,{SLOT_MAX},{SLOT_MAX}}, etc)
+ {NODE_VEC_OP,{SLOT_TYPE_VEC,SLOT_TYPE_VEC,SLOT_MAX},{SLOT_TYPE_VEC,SLOT_MAX}}, // scalar vs scalar op (mul,{SLOT_MAX},{SLOT_MAX}}, add,{SLOT_MAX},{SLOT_MAX}}, div,{SLOT_MAX},{SLOT_MAX}}, etc)
+ {NODE_VEC_SCALAR_OP,{SLOT_TYPE_VEC,SLOT_TYPE_SCALAR,SLOT_MAX},{SLOT_TYPE_VEC,SLOT_MAX}}, // vec3 vs scalar op (mul,{SLOT_MAX},{SLOT_MAX}}, add,{SLOT_MAX},{SLOT_MAX}}, div,{SLOT_MAX},{SLOT_MAX}}, etc)
+ {NODE_RGB_OP,{SLOT_TYPE_VEC,SLOT_TYPE_VEC,SLOT_MAX},{SLOT_TYPE_VEC,SLOT_MAX}}, // vec3 vs scalar op (mul,{SLOT_MAX},{SLOT_MAX}}, add,{SLOT_MAX},{SLOT_MAX}}, div,{SLOT_MAX},{SLOT_MAX}}, etc)
+ {NODE_XFORM_MULT,{SLOT_TYPE_XFORM,SLOT_TYPE_XFORM,SLOT_MAX},{SLOT_TYPE_XFORM,SLOT_MAX}}, // mat4 x mat4
+ {NODE_XFORM_VEC_MULT,{SLOT_TYPE_XFORM,SLOT_TYPE_VEC,SLOT_MAX},{SLOT_TYPE_VEC,SLOT_MAX}}, // mat4 x vec3 mult (with no-translation option)
+ {NODE_XFORM_VEC_INV_MULT,{SLOT_TYPE_VEC,SLOT_TYPE_XFORM,SLOT_MAX},{SLOT_TYPE_VEC,SLOT_MAX}}, // mat4 x vec3 inverse mult (with no-translation option)
+ {NODE_SCALAR_FUNC,{SLOT_TYPE_SCALAR,SLOT_MAX},{SLOT_TYPE_SCALAR,SLOT_MAX}}, // scalar function (sin,{SLOT_MAX},{SLOT_MAX}}, cos,{SLOT_MAX},{SLOT_MAX}}, etc)
+ {NODE_VEC_FUNC,{SLOT_TYPE_VEC,SLOT_MAX},{SLOT_TYPE_VEC,SLOT_MAX}}, // vector function (normalize,{SLOT_MAX},{SLOT_MAX}}, negate,{SLOT_MAX},{SLOT_MAX}}, reciprocal,{SLOT_MAX},{SLOT_MAX}}, rgb2hsv,{SLOT_MAX},{SLOT_MAX}}, hsv2rgb,{SLOT_MAX},{SLOT_MAX}}, etc,{SLOT_MAX},{SLOT_MAX}}, etc)
+ {NODE_VEC_LEN,{SLOT_TYPE_VEC,SLOT_MAX},{SLOT_TYPE_SCALAR,SLOT_MAX}}, // vec3 length
+ {NODE_DOT_PROD,{SLOT_TYPE_VEC,SLOT_TYPE_VEC,SLOT_MAX},{SLOT_TYPE_SCALAR,SLOT_MAX}}, // vec3 . vec3 (dot product -> scalar output)
+ {NODE_VEC_TO_SCALAR,{SLOT_TYPE_VEC,SLOT_MAX},{SLOT_TYPE_SCALAR,SLOT_TYPE_SCALAR,SLOT_TYPE_SCALAR}}, // 1 vec3 input,{SLOT_MAX},{SLOT_MAX}}, 3 scalar outputs
+ {NODE_SCALAR_TO_VEC,{SLOT_TYPE_SCALAR,SLOT_TYPE_SCALAR,SLOT_TYPE_SCALAR},{SLOT_TYPE_VEC,SLOT_MAX}}, // 3 scalar input,{SLOT_MAX},{SLOT_MAX}}, 1 vec3 output
+ {NODE_SCALAR_INTERP,{SLOT_TYPE_SCALAR,SLOT_TYPE_SCALAR,SLOT_TYPE_SCALAR},{SLOT_TYPE_SCALAR,SLOT_MAX}}, // scalar interpolation (with optional curve)
+ {NODE_VEC_INTERP,{SLOT_TYPE_VEC,SLOT_TYPE_VEC,SLOT_TYPE_SCALAR},{SLOT_TYPE_VEC,SLOT_MAX}}, // vec3 interpolation (with optional curve)
+ {NODE_SCALAR_INPUT,{SLOT_MAX},{SLOT_TYPE_SCALAR,SLOT_MAX}}, // scalar uniform (assignable in material)
+ {NODE_VEC_INPUT,{SLOT_MAX},{SLOT_TYPE_VEC,SLOT_MAX}}, // vec3 uniform (assignable in material)
+ {NODE_RGB_INPUT,{SLOT_MAX},{SLOT_TYPE_VEC,SLOT_MAX}}, // color uniform (assignable in material)
+ {NODE_XFORM_INPUT,{SLOT_MAX},{SLOT_TYPE_XFORM,SLOT_MAX}}, // mat4 uniform (assignable in material)
+ {NODE_TEXTURE_INPUT,{SLOT_TYPE_VEC,SLOT_MAX},{SLOT_TYPE_VEC,SLOT_TYPE_SCALAR,SLOT_MAX}}, // texture input (assignable in material)
+ {NODE_CUBEMAP_INPUT,{SLOT_TYPE_VEC,SLOT_MAX},{SLOT_TYPE_VEC,SLOT_TYPE_SCALAR,SLOT_MAX}}, // cubemap input (assignable in material)
+ {NODE_COMMENT,{SLOT_MAX},{SLOT_MAX}}, // comment
+ {NODE_TYPE_MAX,{SLOT_MAX},{SLOT_MAX}}
+};
+
+int ShaderGraph::get_node_input_slot_count(Mode p_mode, ShaderType p_shader_type,NodeType p_type) {
+
+ if (p_type==NODE_INPUT || p_type==NODE_OUTPUT) {
+
+ const InOutParamInfo* iop = &inout_param_info[0];
+ int pc=0;
+ while(iop->name) {
+ if (p_mode==iop->shader_mode && p_shader_type==iop->shader_type) {
+
+ if (iop->dir==SLOT_OUT)
+ pc++;
+ }
+ iop++;
+ }
+ return pc;
+ } else if (p_type==NODE_VEC_TO_XFORM){
+ return 4;
+ } else if (p_type==NODE_XFORM_TO_VEC){
+ return 1;
+ } else {
+
+ const NodeSlotInfo*nsi=&node_slot_info[0];
+ while(nsi->type!=NODE_TYPE_MAX) {
+
+ if (nsi->type==p_type) {
+ int pc=0;
+ for(int i=0;i<NodeSlotInfo::MAX_INS;i++) {
+ if (nsi->ins[i]==SLOT_MAX)
+ break;
+ pc++;
+ }
+ return pc;
+ }
+
+ nsi++;
+ }
+
+ return 0;
}
+}
+
+int ShaderGraph::get_node_output_slot_count(Mode p_mode, ShaderType p_shader_type,NodeType p_type){
+
+ if (p_type==NODE_INPUT || p_type==NODE_OUTPUT) {
+
+ const InOutParamInfo* iop = &inout_param_info[0];
+ int pc=0;
+ while(iop->name) {
+ if (p_mode==iop->shader_mode && p_shader_type==iop->shader_type) {
+
+ if (iop->dir==SLOT_IN)
+ pc++;
+ }
+ iop++;
+ }
+ return pc;
+ } else if (p_type==NODE_VEC_TO_XFORM){
+ return 1;
+ } else if (p_type==NODE_XFORM_TO_VEC){
+ return 4;
+ } else {
+
+ const NodeSlotInfo*nsi=&node_slot_info[0];
+ while(nsi->type!=NODE_TYPE_MAX) {
+
+ if (nsi->type==p_type) {
+ int pc=0;
+ for(int i=0;i<NodeSlotInfo::MAX_OUTS;i++) {
+ if (nsi->outs[i]==SLOT_MAX)
+ break;
+ pc++;
+ }
+ return pc;
+ }
+
+ nsi++;
+ }
+
+ return 0;
- ERR_FAIL_V( PropertyInfo(Variant::NIL,"error") );
-}
-int ShaderGraph::shader_get_input_count(NodeType p_type) {
-
- switch(p_type) {
- case NODE_IN: return 0;
- case NODE_OUT: return 1;
- case NODE_CONSTANT: return 0;
- case NODE_PARAMETER: return 0;
- case NODE_ADD: return 2;
- case NODE_SUB: return 2;
- case NODE_MUL: return 2;
- case NODE_DIV: return 2;
- case NODE_MOD: return 2;
- case NODE_SIN: return 1;
- case NODE_COS: return 1;
- case NODE_TAN: return 1;
- case NODE_ARCSIN: return 1;
- case NODE_ARCCOS: return 1;
- case NODE_ARCTAN: return 1;
- case NODE_POW: return 2;
- case NODE_LOG: return 1;
- case NODE_MAX: return 2;
- case NODE_MIN: return 2;
- case NODE_COMPARE: return 4;
- case NODE_TEXTURE: return 1; ///< param 0: texture
- case NODE_TIME: return 1; ///< param 0: interval length
- case NODE_NOISE: return 0;
- case NODE_PASS: return 1;
- case NODE_VEC_IN: return 0; ///< param 0: name
- case NODE_VEC_OUT: return 1; ///< param 0: name
- case NODE_VEC_CONSTANT: return 0; ///< param 0: value
- case NODE_VEC_PARAMETER: return 0; ///< param 0: name
- case NODE_VEC_ADD: return 2;
- case NODE_VEC_SUB: return 2;
- case NODE_VEC_MUL: return 2;
- case NODE_VEC_DIV: return 2;
- case NODE_VEC_MOD: return 2;
- case NODE_VEC_CROSS: return 2;
- case NODE_VEC_DOT: return 2;
- case NODE_VEC_POW: return 2;
- case NODE_VEC_NORMALIZE: return 1;
- case NODE_VEC_INTERPOLATE: return 3;
- case NODE_VEC_SCREEN_TO_UV: return 1;
- case NODE_VEC_TRANSFORM3: return 4;
- case NODE_VEC_TRANSFORM4: return 5;
- case NODE_VEC_COMPARE: return 4;
- case NODE_VEC_TEXTURE_2D: return 1;
- case NODE_VEC_TEXTURE_CUBE: return 1;
- case NODE_VEC_NOISE: return 0;
- case NODE_VEC_0: return 1;
- case NODE_VEC_1: return 1;
- case NODE_VEC_2: return 1;
- case NODE_VEC_BUILD: return 3;
- case NODE_VEC_PASS: return 1;
- case NODE_COLOR_CONSTANT: return 0;
- case NODE_COLOR_PARAMETER: return 0;
- case NODE_TEXTURE_PARAMETER: return 1;
- case NODE_TEXTURE_2D_PARAMETER: return 1;
- case NODE_TEXTURE_CUBE_PARAMETER: return 1;
- case NODE_TRANSFORM_CONSTANT: return 1;
- case NODE_TRANSFORM_PARAMETER: return 1;
- case NODE_LABEL: return 0;
- default: {}
}
- ERR_FAIL_V( 0 );
-}
-int ShaderGraph::shader_get_output_count(NodeType p_type) {
-
- switch(p_type) {
- case NODE_IN: return 1;
- case NODE_OUT: return 0;
- case NODE_CONSTANT: return 1;
- case NODE_PARAMETER: return 1;
- case NODE_ADD: return 1;
- case NODE_SUB: return 1;
- case NODE_MUL: return 1;
- case NODE_DIV: return 1;
- case NODE_MOD: return 1;
- case NODE_SIN: return 1;
- case NODE_COS: return 1;
- case NODE_TAN: return 1;
- case NODE_ARCSIN: return 1;
- case NODE_ARCCOS: return 1;
- case NODE_ARCTAN: return 1;
- case NODE_POW: return 1;
- case NODE_LOG: return 1;
- case NODE_MAX: return 1;
- case NODE_MIN: return 1;
- case NODE_COMPARE: return 2;
- case NODE_TEXTURE: return 3; ///< param 0: texture
- case NODE_TIME: return 1; ///< param 0: interval length
- case NODE_NOISE: return 1;
- case NODE_PASS: return 1;
- case NODE_VEC_IN: return 1; ///< param 0: name
- case NODE_VEC_OUT: return 0; ///< param 0: name
- case NODE_VEC_CONSTANT: return 1; ///< param 0: value
- case NODE_VEC_PARAMETER: return 1; ///< param 0: name
- case NODE_VEC_ADD: return 1;
- case NODE_VEC_SUB: return 1;
- case NODE_VEC_MUL: return 1;
- case NODE_VEC_DIV: return 1;
- case NODE_VEC_MOD: return 1;
- case NODE_VEC_CROSS: return 1;
- case NODE_VEC_DOT: return 1;
- case NODE_VEC_POW: return 1;
- case NODE_VEC_NORMALIZE: return 1;
- case NODE_VEC_INTERPOLATE: return 1;
- case NODE_VEC_SCREEN_TO_UV: return 1;
- case NODE_VEC_TRANSFORM3: return 1;
- case NODE_VEC_TRANSFORM4: return 1;
- case NODE_VEC_COMPARE: return 2;
- case NODE_VEC_TEXTURE_2D: return 3;
- case NODE_VEC_TEXTURE_CUBE: return 3;
- case NODE_VEC_NOISE: return 1;
- case NODE_VEC_0: return 1;
- case NODE_VEC_1: return 1;
- case NODE_VEC_2: return 1;
- case NODE_VEC_BUILD: return 1;
- case NODE_VEC_PASS: return 1;
- case NODE_COLOR_CONSTANT: return 2;
- case NODE_COLOR_PARAMETER: return 2;
- case NODE_TEXTURE_PARAMETER: return 3;
- case NODE_TEXTURE_2D_PARAMETER: return 3;
- case NODE_TEXTURE_CUBE_PARAMETER: return 3;
- case NODE_TRANSFORM_CONSTANT: return 1;
- case NODE_TRANSFORM_PARAMETER: return 1;
- case NODE_LABEL: return 0;
-
- default: {}
+}
+ShaderGraph::SlotType ShaderGraph::get_node_input_slot_type(Mode p_mode, ShaderType p_shader_type,NodeType p_type,int p_idx){
+
+ if (p_type==NODE_INPUT || p_type==NODE_OUTPUT) {
+
+ const InOutParamInfo* iop = &inout_param_info[0];
+ int pc=0;
+ while(iop->name) {
+ if (p_mode==iop->shader_mode && p_shader_type==iop->shader_type) {
+
+ if (iop->dir==SLOT_OUT) {
+ if (pc==p_idx)
+ return iop->slot_type;
+ pc++;
+ }
+ }
+ iop++;
+ }
+ ERR_FAIL_V(SLOT_MAX);
+ } else if (p_type==NODE_VEC_TO_XFORM){
+ return SLOT_TYPE_VEC;
+ } else if (p_type==NODE_XFORM_TO_VEC){
+ return SLOT_TYPE_XFORM;
+ } else {
+
+ const NodeSlotInfo*nsi=&node_slot_info[0];
+ while(nsi->type!=NODE_TYPE_MAX) {
+
+ if (nsi->type==p_type) {
+ for(int i=0;i<NodeSlotInfo::MAX_INS;i++) {
+
+ if (nsi->ins[i]==SLOT_MAX)
+ break;
+ if (i==p_idx)
+ return nsi->ins[i];
+ }
+ }
+
+ nsi++;
+ }
+
+ ERR_FAIL_V(SLOT_MAX);
+
}
- ERR_FAIL_V( 0 );
-
-}
-
-#define RET2(m_a,m_b) if (p_idx==0) return m_a; else if (p_idx==1) return m_b; else return "";
-#define RET3(m_a,m_b,m_c) if (p_idx==0) return m_a; else if (p_idx==1) return m_b; else if (p_idx==2) return m_c; else return "";
-#define RET4(m_a,m_b,m_c,m_d) if (p_idx==0) return m_a; else if (p_idx==1) return m_b; else if (p_idx==2) return m_c; else if (p_idx==3) return m_d; else return "";
-
-#define RET5(m_a,m_b,m_c,m_d,m_e) if (p_idx==0) return m_a; else if (p_idx==1) return m_b; else if (p_idx==2) return m_c; else if (p_idx==3) return m_d; else if (p_idx==4) return m_e; else return "";
-
-String ShaderGraph::shader_get_input_name(NodeType p_type,int p_idx) {
-
- switch(p_type) {
-
- case NODE_IN: return "";
- case NODE_OUT: return "out";
- case NODE_CONSTANT: return "";
- case NODE_PARAMETER: return "";
- case NODE_ADD: RET2("a","b");
- case NODE_SUB: RET2("a","b");
- case NODE_MUL: RET2("a","b");
- case NODE_DIV: RET2("a","b");
- case NODE_MOD: RET2("a","b");
- case NODE_SIN: return "rad";
- case NODE_COS: return "rad";
- case NODE_TAN: return "rad";
- case NODE_ARCSIN: return "in";
- case NODE_ARCCOS: return "in";
- case NODE_ARCTAN: return "in";
- case NODE_POW: RET2("in","exp");
- case NODE_LOG: return "in";
- case NODE_MAX: return "in";
- case NODE_MIN: return "in";
- case NODE_COMPARE: RET4("a","b","ret1","ret2");
- case NODE_TEXTURE: return "u";
- case NODE_TIME: return "";
- case NODE_NOISE: return "";
- case NODE_PASS: return "in";
- case NODE_VEC_IN: return "";
- case NODE_VEC_OUT: return "out";
- case NODE_VEC_CONSTANT: return "";
- case NODE_VEC_PARAMETER: return "";
- case NODE_VEC_ADD: RET2("a","b");
- case NODE_VEC_SUB: RET2("a","b");
- case NODE_VEC_MUL: RET2("a","b");
- case NODE_VEC_DIV: RET2("a","b");
- case NODE_VEC_MOD: RET2("a","b");
- case NODE_VEC_CROSS: RET2("a","b");
- case NODE_VEC_DOT: RET2("a","b");
- case NODE_VEC_POW: RET2("a","b");
- case NODE_VEC_NORMALIZE: return "vec";
- case NODE_VEC_INTERPOLATE: RET3("a","b","c");
- case NODE_VEC_SCREEN_TO_UV: return "scr";
- case NODE_VEC_TRANSFORM3: RET4("in","col0","col1","col2");
- case NODE_VEC_TRANSFORM4: RET5("in","col0","col1","col2","col3");
- case NODE_VEC_COMPARE: RET4("a","b","ret1","ret2");
- case NODE_VEC_TEXTURE_2D: return "uv";
- case NODE_VEC_TEXTURE_CUBE: return "uvw";
- case NODE_VEC_NOISE: return "";
- case NODE_VEC_0: return "vec";
- case NODE_VEC_1: return "vec";
- case NODE_VEC_2: return "vec";
- case NODE_VEC_BUILD: RET3("x/r","y/g","z/b");
- case NODE_VEC_PASS: return "in";
- case NODE_COLOR_CONSTANT: return "";
- case NODE_COLOR_PARAMETER: return "";
- case NODE_TEXTURE_PARAMETER: return "u";
- case NODE_TEXTURE_2D_PARAMETER: return "uv";
- case NODE_TEXTURE_CUBE_PARAMETER: return "uvw";
- case NODE_TRANSFORM_CONSTANT: return "in";
- case NODE_TRANSFORM_PARAMETER: return "in";
- case NODE_LABEL: return "";
-
- default: {}
+}
+ShaderGraph::SlotType ShaderGraph::get_node_output_slot_type(Mode p_mode, ShaderType p_shader_type,NodeType p_type,int p_idx){
+
+ if (p_type==NODE_INPUT || p_type==NODE_OUTPUT) {
+
+ const InOutParamInfo* iop = &inout_param_info[0];
+ int pc=0;
+ while(iop->name) {
+ if (p_mode==iop->shader_mode && p_shader_type==iop->shader_type) {
+
+ if (iop->dir==SLOT_IN) {
+ if (pc==p_idx)
+ return iop->slot_type;
+ pc++;
+ }
+ }
+ iop++;
+ }
+ ERR_FAIL_V(SLOT_MAX);
+ } else if (p_type==NODE_VEC_TO_XFORM){
+ return SLOT_TYPE_XFORM;
+ } else if (p_type==NODE_XFORM_TO_VEC){
+ return SLOT_TYPE_VEC;
+ } else {
+
+ const NodeSlotInfo*nsi=&node_slot_info[0];
+ while(nsi->type!=NODE_TYPE_MAX) {
+
+ if (nsi->type==p_type) {
+ for(int i=0;i<NodeSlotInfo::MAX_OUTS;i++) {
+ if (nsi->outs[i]==SLOT_MAX)
+ break;
+ if (i==p_idx)
+ return nsi->outs[i];
+ }
+ }
+
+ nsi++;
+ }
+
+ ERR_FAIL_V(SLOT_MAX);
}
+}
+
+
- ERR_FAIL_V("");
-}
-String ShaderGraph::shader_get_output_name(NodeType p_type,int p_idx) {
-
- switch(p_type) {
-
- case NODE_IN: return "in";
- case NODE_OUT: return "";
- case NODE_CONSTANT: return "out";
- case NODE_PARAMETER: return "out";
- case NODE_ADD: return "sum";
- case NODE_SUB: return "dif";
- case NODE_MUL: return "prod";
- case NODE_DIV: return "quot";
- case NODE_MOD: return "rem";
- case NODE_SIN: return "out";
- case NODE_COS: return "out";
- case NODE_TAN: return "out";
- case NODE_ARCSIN: return "rad";
- case NODE_ARCCOS: return "rad";
- case NODE_ARCTAN: return "rad";
- case NODE_POW: RET2("in","exp");
- case NODE_LOG: return "out";
- case NODE_MAX: return "out";
- case NODE_MIN: return "out";
- case NODE_COMPARE: RET2("a/b","a/b");
- case NODE_TEXTURE: RET3("rgb","a","v");
- case NODE_TIME: return "out";
- case NODE_NOISE: return "out";
- case NODE_PASS: return "out";
- case NODE_VEC_IN: return "in";
- case NODE_VEC_OUT: return "";
- case NODE_VEC_CONSTANT: return "out";
- case NODE_VEC_PARAMETER: return "out";
- case NODE_VEC_ADD: return "sum";
- case NODE_VEC_SUB: return "sub";
- case NODE_VEC_MUL: return "mul";
- case NODE_VEC_DIV: return "div";
- case NODE_VEC_MOD: return "rem";
- case NODE_VEC_CROSS: return "crs";
- case NODE_VEC_DOT: return "prod";
- case NODE_VEC_POW: return "out";
- case NODE_VEC_NORMALIZE: return "norm";
- case NODE_VEC_INTERPOLATE: return "out";
- case NODE_VEC_SCREEN_TO_UV: return "uv";
- case NODE_VEC_TRANSFORM3: return "prod";
- case NODE_VEC_TRANSFORM4: return "prod";
- case NODE_VEC_COMPARE: RET2("a/b","a/b");
- case NODE_VEC_TEXTURE_2D: RET3("rgb","a","v");
- case NODE_VEC_TEXTURE_CUBE: RET3("rgb","a","v");
- case NODE_VEC_NOISE: return "out";
- case NODE_VEC_0: return "x/r";
- case NODE_VEC_1: return "y/g";
- case NODE_VEC_2: return "z/b";
- case NODE_VEC_BUILD: return "vec";
- case NODE_VEC_PASS: return "out";
- case NODE_COLOR_CONSTANT: RET2("rgb","a");
- case NODE_COLOR_PARAMETER: RET2("rgb","a");
- case NODE_TEXTURE_PARAMETER: RET3("rgb","a","v");
- case NODE_TEXTURE_2D_PARAMETER: RET3("rgb","a","v");
- case NODE_TEXTURE_CUBE_PARAMETER: RET3("rgb","a","v");
- case NODE_TRANSFORM_CONSTANT: return "out";
- case NODE_TRANSFORM_PARAMETER: return "out";
- case NODE_LABEL: return "";
-
- default: {}
+
+
+void ShaderGraph::_update_shader() {
+
+
+ String code[3];
+
+ List<StringName> names;
+ get_default_texture_param_list(&names);
+
+ for (List<StringName>::Element *E=names.front();E;E=E->next()) {
+ set_default_texture_param(E->get(),Ref<Texture>());
}
- ERR_FAIL_V("");
-}
-bool ShaderGraph::shader_is_input_vector(NodeType p_type,int p_input) {
-
- switch(p_type) {
-
- case NODE_IN: return false;
- case NODE_OUT: return false;
- case NODE_CONSTANT: return false;
- case NODE_PARAMETER: return false;
- case NODE_ADD: return false;
- case NODE_SUB: return false;
- case NODE_MUL: return false;
- case NODE_DIV: return false;
- case NODE_MOD: return false;
- case NODE_SIN: return false;
- case NODE_COS: return false;
- case NODE_TAN: return false;
- case NODE_ARCSIN: return false;
- case NODE_ARCCOS: return false;
- case NODE_ARCTAN: return false;
- case NODE_POW: return false;
- case NODE_LOG: return false;
- case NODE_MAX: return false;
- case NODE_MIN: return false;
- case NODE_COMPARE: return false;
- case NODE_TEXTURE: return false;
- case NODE_TIME: return false;
- case NODE_NOISE: return false;
- case NODE_PASS: return false;
- case NODE_VEC_IN: return false;
- case NODE_VEC_OUT: return true;
- case NODE_VEC_CONSTANT: return false;
- case NODE_VEC_PARAMETER: return false;
- case NODE_VEC_ADD: return true;
- case NODE_VEC_SUB: return true;
- case NODE_VEC_MUL: return true;
- case NODE_VEC_DIV: return true;
- case NODE_VEC_MOD: return true;
- case NODE_VEC_CROSS: return true;
- case NODE_VEC_DOT: return true;
- case NODE_VEC_POW: return (p_input==0)?true:false;
- case NODE_VEC_NORMALIZE: return true;
- case NODE_VEC_INTERPOLATE: return (p_input<2)?true:false;
- case NODE_VEC_SCREEN_TO_UV: return true;
- case NODE_VEC_TRANSFORM3: return true;
- case NODE_VEC_TRANSFORM4: return true;
- case NODE_VEC_COMPARE: return (p_input<2)?false:true;
- case NODE_VEC_TEXTURE_2D: return true;
- case NODE_VEC_TEXTURE_CUBE: return true;
- case NODE_VEC_NOISE: return false;
- case NODE_VEC_0: return true;
- case NODE_VEC_1: return true;
- case NODE_VEC_2: return true;
- case NODE_VEC_BUILD: return false;
- case NODE_VEC_PASS: return true;
- case NODE_COLOR_CONSTANT: return false;
- case NODE_COLOR_PARAMETER: return false;
- case NODE_TEXTURE_PARAMETER: return false;
- case NODE_TEXTURE_2D_PARAMETER: return true;
- case NODE_TEXTURE_CUBE_PARAMETER: return true;
- case NODE_TRANSFORM_CONSTANT: return true;
- case NODE_TRANSFORM_PARAMETER: return true;
- case NODE_LABEL: return false;
-
- default: {}
+
+ for(int i=0;i<3;i++) {
+
+ int idx=0;
+ for (Map<int,Node>::Element *E=shader[i].node_map.front();E;E=E->next()) {
+
+ E->get().sort_order=idx++;
+ }
+ //simple method for graph solving using bubblesort derived algorithm
+ int iters=0;
+ int iter_max=shader[i].node_map.size()*shader[i].node_map.size();
+
+ while(true) {
+ if (iters>iter_max)
+ break;
+
+ int swaps=0;
+ for (Map<int,Node>::Element *E=shader[i].node_map.front();E;E=E->next()) {
+
+ for(Map<int,SourceSlot>::Element *F=E->get().connections.front();F;F=F->next()) {
+
+ //this is kinda slow, could be sped up
+ Map<int,Node>::Element *G = shader[i].node_map.find(F->get().id);
+ ERR_FAIL_COND(!G);
+ if (G->get().sort_order > E->get().sort_order) {
+
+ SWAP(G->get().sort_order,E->get().sort_order);
+ swaps++;
+ }
+ }
+ }
+
+ iters++;
+ if (swaps==0) {
+ iters=0;
+ break;
+ }
+ }
+
+ if (iters>0) {
+
+ shader[i].error=GRAPH_ERROR_CYCLIC;
+ continue;
+ }
+
+ Vector<Node*> order;
+ order.resize(shader[i].node_map.size());
+
+ for (Map<int,Node>::Element *E=shader[i].node_map.front();E;E=E->next()) {
+
+ order[E->get().sort_order]=&E->get();
+ }
+
+ //generate code for the ordered graph
+ bool failed=false;
+
+ if (i==SHADER_TYPE_FRAGMENT && get_mode()==MODE_MATERIAL) {
+ code[i]+="vec3 DIFFUSE_OUT=vec3(0,0,0);\n";
+ code[i]+="float ALPHA_OUT=0;\n";
+ }
+
+
+ Map<String,String> inputs_xlate;
+ Map<String,String> input_names_xlate;
+ Set<String> inputs_used;
+
+ for(int j=0;j<order.size();j++) {
+
+ Node *n=order[j];
+ if (n->type==NODE_INPUT) {
+
+ const InOutParamInfo* iop = &inout_param_info[0];
+ int idx=0;
+ while(iop->name) {
+ if (get_mode()==iop->shader_mode && i==iop->shader_type && SLOT_IN==iop->dir) {
+
+ const char *typestr[4]={"float","vec3","mat4","texture"};
+
+ String vname=("nd"+itos(n->id)+"sl"+itos(idx));
+ inputs_xlate[vname]=String(typestr[iop->slot_type])+" "+vname+"="+iop->variable+";\n";
+ input_names_xlate[vname]=iop->variable;
+ idx++;
+ }
+ iop++;
+ }
+
+ } else if (n->type==NODE_OUTPUT) {
+
+
+ bool use_alpha=false;
+ const InOutParamInfo* iop = &inout_param_info[0];
+ int idx=0;
+ while(iop->name) {
+ if (get_mode()==iop->shader_mode && i==iop->shader_type && SLOT_OUT==iop->dir) {
+
+ if (n->connections.has(idx)) {
+ String iname=("nd"+itos(n->connections[idx].id)+"sl"+itos(n->connections[idx].slot));
+ if (node_get_type(ShaderType(i),n->connections[idx].id)==NODE_INPUT)
+ inputs_used.insert(iname);
+ code[i]+=String(iop->variable)+"="+iname+String(iop->postfix)+";\n";
+ if (i==SHADER_TYPE_FRAGMENT && get_mode()==MODE_MATERIAL && String(iop->name)=="DiffuseAlpha")
+ use_alpha=true;
+ }
+ idx++;
+ }
+ iop++;
+ }
+
+ if (i==SHADER_TYPE_FRAGMENT && get_mode()==MODE_MATERIAL) {
+
+ if (use_alpha) {
+ code[i]+="DIFFUSE_ALPHA=vec4(DIFFUSE_OUT,ALPHA_OUT);\n";
+ } else {
+ code[i]+="DIFFUSE=DIFFUSE_OUT;\n";
+ }
+ }
+
+ } else {
+ Vector<String> inputs;
+ int max = get_node_input_slot_count(get_mode(),ShaderType(i),n->type);
+ for(int k=0;k<max;k++) {
+ if (!n->connections.has(k)) {
+ shader[i].error=GRAPH_ERROR_MISSING_CONNECTIONS;
+ failed=true;
+ break;
+ }
+ String iname="nd"+itos(n->connections[k].id)+"sl"+itos(n->connections[k].slot);
+ inputs.push_back(iname);
+ if (node_get_type(ShaderType(i),n->connections[k].id)==NODE_INPUT) {
+ inputs_used.insert(iname);
+ }
+
+ }
+
+ if (failed)
+ break;
+
+ if (n->type==NODE_TEXTURE_INPUT || n->type==NODE_CUBEMAP_INPUT) {
+
+ set_default_texture_param(n->param1,n->param2);
+ }
+ _add_node_code(ShaderType(i),n,inputs,code[i]);
+ }
+
+ }
+
+ if (failed)
+ continue;
+
+
+ for(Set<String>::Element *E=inputs_used.front();E;E=E->next()) {
+
+ ERR_CONTINUE( !inputs_xlate.has(E->get()));
+ code[i]=inputs_xlate[E->get()]+code[i];
+ String name=input_names_xlate[E->get()];
+
+ if (i==SHADER_TYPE_VERTEX && get_mode()==MODE_MATERIAL) {
+ if (name==("SRC_COLOR"))
+ code[i]="vec3 SRC_COLOR=COLOR.rgb;\n"+code[i];
+ if (name==("SRC_ALPHA"))
+ code[i]="float SRC_ALPHA=COLOR.a;\n"+code[i];
+ if (name==("SRC_UV"))
+ code[i]="vec3 SRC_UV=vec3(UV,0);\n"+code[i];
+ if (name==("SRC_UV2"))
+ code[i]="float SRC_UV2=vec3(UV2,0);\n"+code[i];
+ } else if (i==SHADER_TYPE_FRAGMENT && get_mode()==MODE_MATERIAL) {
+ if (name==("IN_NORMAL"))
+ code[i]="vec3 IN_NORMAL=NORMAL;\n"+code[i];
+ }
+
+ }
+
+
+
+ shader[i].error=GRAPH_OK;
+
+ }
+
+ bool all_ok=true;
+ for(int i=0;i<3;i++) {
+ if (shader[i].error!=GRAPH_OK)
+ all_ok=false;
}
- ERR_FAIL_V(false);
-}
-bool ShaderGraph::shader_is_output_vector(NodeType p_type,int p_input) {
-
- switch(p_type) {
-
- case NODE_IN: return false;
- case NODE_OUT: return false ;
- case NODE_CONSTANT: return false;
- case NODE_PARAMETER: return false;
- case NODE_ADD: return false;
- case NODE_SUB: return false;
- case NODE_MUL: return false;
- case NODE_DIV: return false;
- case NODE_MOD: return false;
- case NODE_SIN: return false;
- case NODE_COS: return false;
- case NODE_TAN: return false;
- case NODE_ARCSIN: return false;
- case NODE_ARCCOS: return false;
- case NODE_ARCTAN: return false;
- case NODE_POW: return false;
- case NODE_LOG: return false;
- case NODE_MAX: return false;
- case NODE_MIN: return false;
- case NODE_COMPARE: return false;
- case NODE_TEXTURE: return false;
- case NODE_TIME: return false;
- case NODE_NOISE: return false;
- case NODE_PASS: return false;
- case NODE_VEC_IN: return true;
- case NODE_VEC_OUT: return false;
- case NODE_VEC_CONSTANT: return true;
- case NODE_VEC_PARAMETER: return true;
- case NODE_VEC_ADD: return true;
- case NODE_VEC_SUB: return true;
- case NODE_VEC_MUL: return true;
- case NODE_VEC_DIV: return true;
- case NODE_VEC_MOD: return true;
- case NODE_VEC_CROSS: return true;
- case NODE_VEC_DOT: return false;
- case NODE_VEC_POW: return true;
- case NODE_VEC_NORMALIZE: return true;
- case NODE_VEC_INTERPOLATE: return true;
- case NODE_VEC_SCREEN_TO_UV: return true;
- case NODE_VEC_TRANSFORM3: return true;
- case NODE_VEC_TRANSFORM4: return true;
- case NODE_VEC_COMPARE: return true;
- case NODE_VEC_TEXTURE_2D: return (p_input==0)?true:false;
- case NODE_VEC_TEXTURE_CUBE: return (p_input==0)?true:false;
- case NODE_VEC_NOISE: return true;
- case NODE_VEC_0: return false;
- case NODE_VEC_1: return false;
- case NODE_VEC_2: return false;
- case NODE_VEC_BUILD: return true;
- case NODE_VEC_PASS: return true;
- case NODE_COLOR_CONSTANT: return (p_input==0)?true:false;
- case NODE_COLOR_PARAMETER: return (p_input==0)?true:false;
- case NODE_TEXTURE_PARAMETER: return (p_input==0)?true:false;
- case NODE_TEXTURE_2D_PARAMETER: return (p_input==0)?true:false;
- case NODE_TEXTURE_CUBE_PARAMETER: return (p_input==0)?true:false;
- case NODE_TRANSFORM_CONSTANT: return true;
- case NODE_TRANSFORM_PARAMETER: return true;
- case NODE_LABEL: return false;
-
- default: {}
+ if (all_ok) {
+ set_code(code[0],code[1],code[2]);
}
+ //do shader here
- ERR_FAIL_V("");
+ _pending_update_shader=false;
+ emit_signal(SceneStringNames::get_singleton()->updated);
}
-#endif
-#endif
+void ShaderGraph::_add_node_code(ShaderType p_type,Node *p_node,const Vector<String>& p_inputs,String& code) {
+
+
+ const char *typestr[4]={"float","vec3","mat4","texture"};
+#define OUTNAME(id,slot) (String(typestr[get_node_output_slot_type(get_mode(),p_type,p_node->type,slot)])+" "+("nd"+itos(id)+"sl"+itos(slot)))
+#define OUTVAR(id,slot) ("nd"+itos(id)+"sl"+itos(slot))
+
+ switch(p_node->type) {
+
+ case NODE_INPUT: {
+
+
+ }break;
+ case NODE_SCALAR_CONST: {
+
+ double scalar = p_node->param1;
+ code+=OUTNAME(p_node->id,0)+"="+rtos(scalar)+";\n";
+ }break;
+ case NODE_VEC_CONST: {
+ Vector3 vec = p_node->param1;
+ code+=OUTNAME(p_node->id,0)+"=vec3("+rtos(vec.x)+","+rtos(vec.y)+","+rtos(vec.z)+");\n";
+ }break;
+ case NODE_RGB_CONST: {
+ Color col = p_node->param1;
+ code+=OUTNAME(p_node->id,0)+"=vec3("+rtos(col.r)+","+rtos(col.g)+","+rtos(col.b)+");\n";
+ code+=OUTNAME(p_node->id,1)+"="+rtos(col.a)+";\n";
+ }break;
+ case NODE_XFORM_CONST: {
+
+ Transform xf = p_node->param1;
+ code+=OUTNAME(p_node->id,0)+"=mat4(\n";
+ code+="\tvec4(vec3("+rtos(xf.basis.get_axis(0).x)+","+rtos(xf.basis.get_axis(0).y)+","+rtos(xf.basis.get_axis(0).z)+"),0),\n";
+ code+="\tvec4(vec3("+rtos(xf.basis.get_axis(1).x)+","+rtos(xf.basis.get_axis(1).y)+","+rtos(xf.basis.get_axis(1).z)+"),0),\n";
+ code+="\tvec4(vec3("+rtos(xf.basis.get_axis(2).x)+","+rtos(xf.basis.get_axis(2).y)+","+rtos(xf.basis.get_axis(2).z)+"),0),\n";
+ code+="\tvec4(vec3("+rtos(xf.origin.x)+","+rtos(xf.origin.y)+","+rtos(xf.origin.z)+"),1)\n";
+ code+=");";
+
+ }break;
+ case NODE_TIME: {
+ code+=OUTNAME(p_node->id,0)+"=TIME;\n";
+ }break;
+ case NODE_SCREEN_TEX: {
+ code+=OUTNAME(p_node->id,0)+"=texscreen("+p_inputs[0]+");\n";
+ }break;
+ case NODE_SCALAR_OP: {
+ int op = p_node->param1;
+ String optxt;
+ switch(op) {
+
+ case SCALAR_OP_ADD: optxt = p_inputs[0]+"+"+p_inputs[1]+";"; break;
+ case SCALAR_OP_SUB: optxt = p_inputs[0]+"-"+p_inputs[1]+";"; break;
+ case SCALAR_OP_MUL: optxt = p_inputs[0]+"*"+p_inputs[1]+";"; break;
+ case SCALAR_OP_DIV: optxt = p_inputs[0]+"/"+p_inputs[1]+";"; break;
+ case SCALAR_OP_MOD: optxt = "mod("+p_inputs[0]+","+p_inputs[1]+");"; break;
+ case SCALAR_OP_POW: optxt = "pow("+p_inputs[0]+","+p_inputs[1]+");"; break;
+ case SCALAR_OP_MAX: optxt = "max("+p_inputs[0]+","+p_inputs[1]+");"; break;
+ case SCALAR_OP_MIN: optxt = "min("+p_inputs[0]+","+p_inputs[1]+");"; break;
+ case SCALAR_OP_ATAN2: optxt = "atan2("+p_inputs[0]+","+p_inputs[1]+");"; break;
+
+ }
+ code+=OUTNAME(p_node->id,0)+"="+optxt+"\n";;
+
+ }break;
+ case NODE_VEC_OP: {
+ int op = p_node->param1;
+ String optxt;
+ switch(op) {
+ case VEC_OP_ADD: optxt = p_inputs[0]+"+"+p_inputs[1]+";"; break;
+ case VEC_OP_SUB: optxt = p_inputs[0]+"-"+p_inputs[1]+";"; break;
+ case VEC_OP_MUL: optxt = p_inputs[0]+"*"+p_inputs[1]+";"; break;
+ case VEC_OP_DIV: optxt = p_inputs[0]+"/"+p_inputs[1]+";"; break;
+ case VEC_OP_MOD: optxt = "mod("+p_inputs[0]+","+p_inputs[1]+");"; break;
+ case VEC_OP_POW: optxt = "pow("+p_inputs[0]+","+p_inputs[1]+");"; break;
+ case VEC_OP_MAX: optxt = "max("+p_inputs[0]+","+p_inputs[1]+");"; break;
+ case VEC_OP_MIN: optxt = "min("+p_inputs[0]+","+p_inputs[1]+");"; break;
+ case VEC_OP_CROSS: optxt = "cross("+p_inputs[0]+","+p_inputs[1]+");"; break;
+ }
+ code+=OUTNAME(p_node->id,0)+"="+optxt+"\n";
+
+ }break;
+ case NODE_VEC_SCALAR_OP: {
+ int op = p_node->param1;
+ String optxt;
+ switch(op) {
+ case VEC_SCALAR_OP_MUL: optxt = p_inputs[0]+"*"+p_inputs[1]+";"; break;
+ case VEC_SCALAR_OP_DIV: optxt = p_inputs[0]+"/"+p_inputs[1]+";"; break;
+ case VEC_SCALAR_OP_POW: optxt = "pow("+p_inputs[0]+","+p_inputs[1]+");"; break;
+ }
+ code+=OUTNAME(p_node->id,0)+"="+optxt+"\n";
+
+ }break;
+ case NODE_RGB_OP: {
+
+ int op = p_node->param1;
+ static const char*axisn[3]={"x","y","z"};
+ switch(op) {
+ case RGB_OP_SCREEN: {
+
+ code += OUTNAME(p_node->id,0)+"=vec3(1.0)-(vec3(1.0)-"+p_inputs[0]+")*(vec3(1.0)-"+p_inputs[1]+");\n";
+ } break;
+ case RGB_OP_DIFFERENCE: {
+
+ code += OUTNAME(p_node->id,0)+"=abs("+p_inputs[0]+"-"+p_inputs[1]+");\n";
+
+ } break;
+ case RGB_OP_DARKEN: {
+
+ code += OUTNAME(p_node->id,0)+"=min("+p_inputs[0]+","+p_inputs[1]+");\n";
+ } break;
+ case RGB_OP_LIGHTEN: {
+
+ code += OUTNAME(p_node->id,0)+"=max("+p_inputs[0]+","+p_inputs[1]+");\n";
+
+ } break;
+ case RGB_OP_OVERLAY: {
+
+ code += OUTNAME(p_node->id,0)+";\n";
+ for(int i=0;i<3;i++) {
+ code += "{\n";
+ code += "\tfloat base="+p_inputs[0]+"."+axisn[i]+";\n";
+ code += "\tfloat blend="+p_inputs[1]+"."+axisn[i]+";\n";
+ code += "\tif (base < 0.5) {\n";
+ code += "\t\t"+OUTVAR(p_node->id,0)+"."+axisn[i]+" = 2.0 * base * blend;\n";
+ code += "\t} else {\n";
+ code += "\t\t"+OUTVAR(p_node->id,0)+"."+axisn[i]+" = 1.0 - 2.0 * (1.0 - blend) * (1.0 - base);\n";
+ code += "\t}\n";
+ code += "}\n";
+ }
+
+ } break;
+ case RGB_OP_DODGE: {
+
+ code += OUTNAME(p_node->id,0)+"=("+p_inputs[0]+")/(vec3(1.0)-"+p_inputs[1]+");\n";
+
+ } break;
+ case RGB_OP_BURN: {
+
+ code += OUTNAME(p_node->id,0)+"=vec3(1.0)-(vec3(1.0)-"+p_inputs[0]+")/("+p_inputs[1]+");\n";
+ } break;
+ case RGB_OP_SOFT_LIGHT: {
+
+ code += OUTNAME(p_node->id,0)+";\n";
+ for(int i=0;i<3;i++) {
+ code += "{\n";
+ code += "\tfloat base="+p_inputs[0]+"."+axisn[i]+";\n";
+ code += "\tfloat blend="+p_inputs[1]+"."+axisn[i]+";\n";
+ code += "\tif (base < 0.5) {\n";
+ code += "\t\t"+OUTVAR(p_node->id,0)+"."+axisn[i]+" = (base * (blend+0.5));\n";
+ code += "\t} else {\n";
+ code += "\t\t"+OUTVAR(p_node->id,0)+"."+axisn[i]+" = (1 - (1-base) * (1-(blend-0.5)));\n";
+ code += "\t}\n";
+ code += "}\n";
+ }
+
+ } break;
+ case RGB_OP_HARD_LIGHT: {
+
+ code += OUTNAME(p_node->id,0)+";\n";
+ for(int i=0;i<3;i++) {
+ code += "{\n";
+ code += "\tfloat base="+p_inputs[0]+"."+axisn[i]+";\n";
+ code += "\tfloat blend="+p_inputs[1]+"."+axisn[i]+";\n";
+ code += "\tif (base < 0.5) {\n";
+ code += "\t\t"+OUTVAR(p_node->id,0)+"."+axisn[i]+" = (base * (2*blend));\n";
+ code += "\t} else {\n";
+ code += "\t\t"+OUTVAR(p_node->id,0)+"."+axisn[i]+" = (1 - (1-base) * (1-2*(blend-0.5)));\n";
+ code += "\t}\n";
+ code += "}\n";
+ }
+
+ } break;
+ }
+ }break;
+ case NODE_XFORM_MULT: {
+
+ code += OUTNAME(p_node->id,0)+"="+p_inputs[0]+"*"+p_inputs[1]+";\n";
+
+ }break;
+ case NODE_XFORM_VEC_MULT: {
+
+ bool no_translation = p_node->param1;
+ if (no_translation) {
+ code += OUTNAME(p_node->id,0)+"=("+p_inputs[0]+"*vec4("+p_inputs[1]+",0)).xyz;\n";
+ } else {
+ code += OUTNAME(p_node->id,0)+"=("+p_inputs[0]+"*vec4("+p_inputs[1]+",1)).xyz;\n";
+ }
+
+ }break;
+ case NODE_XFORM_VEC_INV_MULT: {
+ bool no_translation = p_node->param1;
+ if (no_translation) {
+ code += OUTNAME(p_node->id,0)+"=("+p_inputs[1]+"*vec4("+p_inputs[0]+",0)).xyz;\n";
+ } else {
+ code += OUTNAME(p_node->id,0)+"=("+p_inputs[1]+"*vec4("+p_inputs[0]+",1)).xyz;\n";
+ }
+ }break;
+ case NODE_SCALAR_FUNC: {
+ static const char*scalar_func_id[SCALAR_MAX_FUNC]={
+ "sin($)",
+ "cos($)",
+ "tan($)",
+ "asin($)",
+ "acos($)",
+ "atan($)",
+ "sinh($)",
+ "cosh($)",
+ "tanh($)",
+ "log($)",
+ "exp($)",
+ "sqrt($)",
+ "abs($)",
+ "sign($)",
+ "floor($)",
+ "round($)",
+ "ceil($)",
+ "frac($)",
+ "min(max($,0),1)",
+ "-($)",
+ };
+
+ int func = p_node->param1;
+ ERR_FAIL_INDEX(func,SCALAR_MAX_FUNC);
+ code += OUTNAME(p_node->id,0)+"="+String(scalar_func_id[func]).replace("$",p_inputs[0])+";\n";
+
+ } break;
+ case NODE_VEC_FUNC: {
+ static const char*vec_func_id[VEC_MAX_FUNC]={
+ "normalize($)",
+ "max(min($,vec3(1,1,1)),vec3(0,0,0))",
+ "-($)",
+ "1.0/($)",
+ "",
+ "",
+ };
+
+
+ int func = p_node->param1;
+ ERR_FAIL_INDEX(func,VEC_MAX_FUNC);
+ if (func==VEC_FUNC_RGB2HSV) {
+ code += OUTNAME(p_node->id,0)+";\n";
+ code+="{\n";
+ code+="\tvec3 c = "+p_inputs[0]+";\n";
+ code+="\tvec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n";
+ code+="\tvec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));\n";
+ code+="\tvec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));\n";
+ code+="\tfloat d = q.x - min(q.w, q.y);\n";
+ code+="\tfloat e = 1.0e-10;\n";
+ code+="\t"+OUTVAR(p_node->id,0)+"=vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n";
+ code+="}\n";
+ } else if (func==VEC_FUNC_HSV2RGB) {
+ code += OUTNAME(p_node->id,0)+";\n";;
+ code+="{\n";
+ code+="\tvec3 c = "+p_inputs[0]+";\n";
+ code+="\tvec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n";
+ code+="\tvec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n";
+ code+="\t"+OUTVAR(p_node->id,0)+"=c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n";
+ code+="}\n";
+
+ } else {
+ code += OUTNAME(p_node->id,0)+"="+String(vec_func_id[func]).replace("$",p_inputs[0])+";\n";
+ }
+ }break;
+ case NODE_VEC_LEN: {
+
+ code += OUTNAME(p_node->id,0)+"=length("+p_inputs[1]+");\n";
+
+ }break;
+ case NODE_DOT_PROD: {
+ code += OUTNAME(p_node->id,0)+"=dot("+p_inputs[1]+","+p_inputs[0]+");\n";
+
+ }break;
+ case NODE_VEC_TO_SCALAR: {
+ code += OUTNAME(p_node->id,0)+"="+p_inputs[0]+".x;\n";
+ code += OUTNAME(p_node->id,1)+"="+p_inputs[0]+".y;\n";
+ code += OUTNAME(p_node->id,2)+"="+p_inputs[0]+".z;\n";
+
+ }break;
+ case NODE_SCALAR_TO_VEC: {
+ code += OUTNAME(p_node->id,0)+"=vec3("+p_inputs[0]+","+p_inputs[1]+","+p_inputs[2]+""+");\n";
+
+ }break;
+ case NODE_VEC_TO_XFORM: {
+ code += OUTNAME(p_node->id,0)+"=xform("+p_inputs[0]+","+p_inputs[1]+","+p_inputs[2]+","+","+p_inputs[3]+");\n";
+
+ }break;
+ case NODE_XFORM_TO_VEC: {
+ code += OUTNAME(p_node->id,0)+"="+p_inputs[0]+".x;\n";
+ code += OUTNAME(p_node->id,1)+"="+p_inputs[0]+".y;\n";
+ code += OUTNAME(p_node->id,2)+"="+p_inputs[0]+".z;\n";
+ code += OUTNAME(p_node->id,3)+"="+p_inputs[0]+".o;\n";
+ }break;
+ case NODE_SCALAR_INTERP: {
+
+ code += OUTNAME(p_node->id,0)+"=mix("+p_inputs[0]+","+p_inputs[1]+","+p_inputs[2]+");\n";
+
+ }break;
+ case NODE_VEC_INTERP: {
+ code += OUTNAME(p_node->id,0)+"=mix("+p_inputs[0]+","+p_inputs[1]+","+p_inputs[2]+");\n";
+
+ }break;
+ case NODE_SCALAR_INPUT: {
+ String name = p_node->param1;
+ float dv=p_node->param2;
+ code +="uniform float "+name+"="+rtos(dv)+";\n";
+ code += OUTNAME(p_node->id,0)+"="+name+";\n";
+ }break;
+ case NODE_VEC_INPUT: {
+
+ String name = p_node->param1;
+ Vector3 dv=p_node->param2;
+ code +="uniform float "+name+"=vec3("+rtos(dv.x)+","+rtos(dv.y)+","+rtos(dv.z)+");\n";
+ code += OUTNAME(p_node->id,0)+"="+name+";\n";
+ }break;
+ case NODE_RGB_INPUT: {
+
+ String name = p_node->param1;
+ Color dv= p_node->param2;
+
+ code +="uniform color "+name+"=vec4("+rtos(dv.r)+","+rtos(dv.g)+","+rtos(dv.g)+","+rtos(dv.a)+");\n";
+ code += OUTNAME(p_node->id,0)+"="+name+".rgb;\n";
+
+ }break;
+ case NODE_XFORM_INPUT: {
+
+ String name = p_node->param1;
+ Transform dv= p_node->param2;
+
+ code +="uniform mat4 "+name+"=mat4(\n";
+ code+="\tvec4(vec3("+rtos(dv.basis.get_axis(0).x)+","+rtos(dv.basis.get_axis(0).y)+","+rtos(dv.basis.get_axis(0).z)+"),0),\n";
+ code+="\tvec4(vec3("+rtos(dv.basis.get_axis(1).x)+","+rtos(dv.basis.get_axis(1).y)+","+rtos(dv.basis.get_axis(1).z)+"),0),\n";
+ code+="\tvec4(vec3("+rtos(dv.basis.get_axis(2).x)+","+rtos(dv.basis.get_axis(2).y)+","+rtos(dv.basis.get_axis(2).z)+"),0),\n";
+ code+="\tvec4(vec3("+rtos(dv.origin.x)+","+rtos(dv.origin.y)+","+rtos(dv.origin.z)+"),1)\n";
+ code+=");";
+
+ code += OUTNAME(p_node->id,0)+"="+name+";\n";
+
+ }break;
+ case NODE_TEXTURE_INPUT: {
+ String name = p_node->param1;
+ String rname="rt_read_tex"+itos(p_node->id);
+ code +="uniform texture "+name+";";
+ code +="vec4 "+rname+"=tex("+name+","+p_inputs[0]+".xy);\n";
+ code += OUTNAME(p_node->id,0)+"="+rname+".rgb;\n";
+ code += OUTNAME(p_node->id,1)+"="+rname+".a;\n";
+
+ }break;
+ case NODE_CUBEMAP_INPUT: {
+
+ String name = p_node->param1;
+ code +="uniform cubemap "+name+";";
+ String rname="rt_read_tex"+itos(p_node->id);
+ code +="vec4 "+rname+"=texcube("+name+","+p_inputs[0]+".xy);\n";
+ code += OUTNAME(p_node->id,0)+"="+rname+".rgb;\n";
+ code += OUTNAME(p_node->id,1)+"="+rname+".a;\n";
+ }break;
+ case NODE_OUTPUT: {
+
+
+ }break;
+ case NODE_COMMENT: {
+
+ }break;
+ case NODE_TYPE_MAX: {
+
+ }
+ }
+}
diff --git a/scene/resources/shader_graph.h b/scene/resources/shader_graph.h
index e20e010c6b..55d09b4c38 100644
--- a/scene/resources/shader_graph.h
+++ b/scene/resources/shader_graph.h
@@ -29,87 +29,54 @@
#ifndef SHADER_GRAPH_H
#define SHADER_GRAPH_H
-#if 0
+
#include "map.h"
#include "scene/resources/shader.h"
-class ShaderGraph : public Resource {
+class ShaderGraph : public Shader {
- OBJ_TYPE( ShaderGraph, Resource );
+ OBJ_TYPE( ShaderGraph, Shader );
RES_BASE_EXTENSION("sgp");
public:
enum NodeType {
- NODE_IN, ///< param 0: name
- NODE_OUT, ///< param 0: name
- NODE_CONSTANT, ///< param 0: value
- NODE_PARAMETER, ///< param 0: name
- NODE_ADD,
- NODE_SUB,
- NODE_MUL,
- NODE_DIV,
- NODE_MOD,
- NODE_SIN,
- NODE_COS,
- NODE_TAN,
- NODE_ARCSIN,
- NODE_ARCCOS,
- NODE_ARCTAN,
- NODE_POW,
- NODE_LOG,
- NODE_MAX,
- NODE_MIN,
- NODE_COMPARE,
- NODE_TEXTURE, ///< param 0: texture
- NODE_TIME, ///< param 0: interval length
- NODE_NOISE,
- NODE_PASS,
- NODE_VEC_IN, ///< param 0: name
- NODE_VEC_OUT, ///< param 0: name
- NODE_VEC_CONSTANT, ///< param 0: value
- NODE_VEC_PARAMETER, ///< param 0: name
- NODE_VEC_ADD,
- NODE_VEC_SUB,
- NODE_VEC_MUL,
- NODE_VEC_DIV,
- NODE_VEC_MOD,
- NODE_VEC_CROSS,
- NODE_VEC_DOT,
- NODE_VEC_POW,
- NODE_VEC_NORMALIZE,
- NODE_VEC_INTERPOLATE,
- NODE_VEC_SCREEN_TO_UV,
- NODE_VEC_TRANSFORM3,
- NODE_VEC_TRANSFORM4,
- NODE_VEC_COMPARE,
- NODE_VEC_TEXTURE_2D,
- NODE_VEC_TEXTURE_CUBE,
- NODE_VEC_NOISE,
- NODE_VEC_0,
- NODE_VEC_1,
- NODE_VEC_2,
- NODE_VEC_BUILD,
- NODE_VEC_PASS,
- NODE_COLOR_CONSTANT,
- NODE_COLOR_PARAMETER,
- NODE_TEXTURE_PARAMETER,
- NODE_TEXTURE_2D_PARAMETER,
- NODE_TEXTURE_CUBE_PARAMETER,
- NODE_TRANSFORM_CONSTANT,
- NODE_TRANSFORM_PARAMETER,
- NODE_LABEL,
+ NODE_INPUT, // all inputs (shader type dependent)
+ NODE_SCALAR_CONST, //scalar constant
+ NODE_VEC_CONST, //vec3 constant
+ NODE_RGB_CONST, //rgb constant (shows a color picker instead)
+ NODE_XFORM_CONST, // 4x4 matrix constant
+ NODE_TIME, // time in seconds
+ NODE_SCREEN_TEX, // screen texture sampler (takes UV) (only usable in fragment shader)
+ NODE_SCALAR_OP, // scalar vs scalar op (mul, add, div, etc)
+ NODE_VEC_OP, // vec3 vs vec3 op (mul,ad,div,crossprod,etc)
+ NODE_VEC_SCALAR_OP, // vec3 vs scalar op (mul, add, div, etc)
+ NODE_RGB_OP, // vec3 vs vec3 rgb op (with scalar amount), like brighten, darken, burn, dodge, multiply, etc.
+ NODE_XFORM_MULT, // mat4 x mat4
+ NODE_XFORM_VEC_MULT, // mat4 x vec3 mult (with no-translation option)
+ NODE_XFORM_VEC_INV_MULT, // mat4 x vec3 inverse mult (with no-translation option)
+ NODE_SCALAR_FUNC, // scalar function (sin, cos, etc)
+ NODE_VEC_FUNC, // vector function (normalize, negate, reciprocal, rgb2hsv, hsv2rgb, etc, etc)
+ NODE_VEC_LEN, // vec3 length
+ NODE_DOT_PROD, // vec3 . vec3 (dot product -> scalar output)
+ NODE_VEC_TO_SCALAR, // 1 vec3 input, 3 scalar outputs
+ NODE_SCALAR_TO_VEC, // 3 scalar input, 1 vec3 output
+ NODE_XFORM_TO_VEC, // 3 vec input, 1 xform output
+ NODE_VEC_TO_XFORM, // 3 vec input, 1 xform output
+ NODE_SCALAR_INTERP, // scalar interpolation (with optional curve)
+ NODE_VEC_INTERP, // vec3 interpolation (with optional curve)
+ NODE_SCALAR_INPUT, // scalar uniform (assignable in material)
+ NODE_VEC_INPUT, // vec3 uniform (assignable in material)
+ NODE_RGB_INPUT, // color uniform (assignable in material)
+ NODE_XFORM_INPUT, // mat4 uniform (assignable in material)
+ NODE_TEXTURE_INPUT, // texture input (assignable in material)
+ NODE_CUBEMAP_INPUT, // cubemap input (assignable in material)
+ NODE_OUTPUT, // output (shader type dependent)
+ NODE_COMMENT, // comment
NODE_TYPE_MAX
};
- enum ShaderType {
- SHADER_VERTEX,
- SHADER_FRAGMENT,
- SHADER_LIGHT
- };
-
-private:
struct Connection {
@@ -119,70 +86,292 @@ private:
int dst_slot;
};
+ enum SlotType {
+
+ SLOT_TYPE_SCALAR,
+ SLOT_TYPE_VEC,
+ SLOT_TYPE_XFORM,
+ SLOT_TYPE_TEXTURE,
+ SLOT_MAX
+ };
+
+ enum ShaderType {
+ SHADER_TYPE_VERTEX,
+ SHADER_TYPE_FRAGMENT,
+ SHADER_TYPE_LIGHT,
+ SHADER_TYPE_MAX
+ };
+
+ enum SlotDir {
+ SLOT_IN,
+ SLOT_OUT
+ };
+
+ enum GraphError {
+ GRAPH_OK,
+ GRAPH_ERROR_CYCLIC,
+ GRAPH_ERROR_MISSING_CONNECTIONS
+ };
+
+private:
+
+ String _find_unique_name(const String& p_base);
+
+ struct SourceSlot {
+
+ int id;
+ int slot;
+ bool operator==(const SourceSlot& p_slot) const {
+ return id==p_slot.id && slot==p_slot.slot;
+ }
+ };
+
struct Node {
- int16_t x,y;
+ Vector2 pos;
NodeType type;
- Variant param;
+ Variant param1;
+ Variant param2;
int id;
mutable int order; // used for sorting
- mutable bool out_valid;
- mutable bool in_valid;
+ int sort_order;
+ Map<int,SourceSlot> connections;
+
};
struct ShaderData {
Map<int,Node> node_map;
- List<Connection> connections;
+ GraphError error;
} shader[3];
- uint64_t version;
-protected:
-/* 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<PropertyInfo> *p_list) const;*/
- static void _bind_methods();
+ struct InOutParamInfo {
+ Mode shader_mode;
+ ShaderType shader_type;
+ const char *name;
+ const char *variable;
+ const char *postfix;
+ SlotType slot_type;
+ SlotDir dir;
+ };
+
+ static const InOutParamInfo inout_param_info[];
+
+ struct NodeSlotInfo {
+
+ enum { MAX_INS=3, MAX_OUTS=3 };
+ NodeType type;
+ const SlotType ins[MAX_INS];
+ const SlotType outs[MAX_OUTS];
+ };
- Array _get_connections_helper() const;
+ static const NodeSlotInfo node_slot_info[];
+
+ bool _pending_update_shader;
+ void _update_shader();
+ void _request_update();
+
+ void _add_node_code(ShaderType p_type,Node *p_node,const Vector<String>& p_inputs,String& code);
+
+ Array _get_node_list(ShaderType p_type) const;
+ Array _get_connections(ShaderType p_type) const;
+
+ void _set_data(const Dictionary& p_data);
+ Dictionary _get_data() const;
+protected:
+
+ static void _bind_methods();
public:
- void node_add(ShaderType p_which, NodeType p_type,int p_id);
+ void node_add(ShaderType p_type, NodeType p_node_type, int p_id);
void node_remove(ShaderType p_which,int p_id);
- void node_set_param(ShaderType p_which, int p_id, const Variant& p_value);
void node_set_pos(ShaderType p_which,int p_id,const Point2& p_pos);
- void node_change_type(ShaderType p_which,int p_id, NodeType p_type);
Point2 node_get_pos(ShaderType p_which,int p_id) const;
void get_node_list(ShaderType p_which,List<int> *p_node_list) const;
NodeType node_get_type(ShaderType p_which,int p_id) const;
- Variant node_get_param(ShaderType p_which,int p_id) const;
- Error connect(ShaderType p_which,int p_src_id,int p_src_slot, int p_dst_id,int p_dst_slot);
- bool is_connected(ShaderType p_which,int p_src_id,int p_src_slot, int p_dst_id,int p_dst_slot) const;
- void disconnect(ShaderType p_which,int p_src_id,int p_src_slot, int p_dst_id,int p_dst_slot);
+ void scalar_const_node_set_value(ShaderType p_which,int p_id,float p_value);
+ float scalar_const_node_get_value(ShaderType p_which,int p_id) const;
- void get_connections(ShaderType p_which,List<Connection> *p_connections) const;
+ void vec_const_node_set_value(ShaderType p_which,int p_id,const Vector3& p_value);
+ Vector3 vec_const_node_get_value(ShaderType p_which,int p_id) const;
- void clear();
+ void rgb_const_node_set_value(ShaderType p_which,int p_id,const Color& p_value);
+ Color rgb_const_node_get_value(ShaderType p_which,int p_id) const;
- uint64_t get_version() const { return version; }
+ void xform_const_node_set_value(ShaderType p_which,int p_id,const Transform& p_value);
+ Transform xform_const_node_get_value(ShaderType p_which,int p_id) const;
- static void get_default_input_nodes(Mode p_type,List<PropertyInfo> *p_inputs);
- static void get_default_output_nodes(Mode p_type,List<PropertyInfo> *p_outputs);
+ void texture_node_set_filter_size(ShaderType p_which,int p_id,int p_size);
+ int texture_node_get_filter_size(ShaderType p_which,int p_id) const;
- static PropertyInfo node_get_type_info(NodeType p_type);
- static int get_input_count(NodeType p_type);
- static int get_output_count(NodeType p_type);
- static String get_input_name(NodeType p_type,int p_input);
- static String get_output_name(NodeType p_type,int p_output);
- static bool is_input_vector(NodeType p_type,int p_input);
- static bool is_output_vector(NodeType p_type,int p_input);
+ void texture_node_set_filter_strength(ShaderType p_which,float p_id,float p_strength);
+ float texture_node_get_filter_strength(ShaderType p_which,float p_id) const;
+ enum ScalarOp {
+ SCALAR_OP_ADD,
+ SCALAR_OP_SUB,
+ SCALAR_OP_MUL,
+ SCALAR_OP_DIV,
+ SCALAR_OP_MOD,
+ SCALAR_OP_POW,
+ SCALAR_OP_MAX,
+ SCALAR_OP_MIN,
+ SCALAR_OP_ATAN2,
+ SCALAR_MAX_OP
+ };
+
+ void scalar_op_node_set_op(ShaderType p_which,float p_id,ScalarOp p_op);
+ ScalarOp scalar_op_node_get_op(ShaderType p_which,float p_id) const;
+
+ enum VecOp {
+ VEC_OP_ADD,
+ VEC_OP_SUB,
+ VEC_OP_MUL,
+ VEC_OP_DIV,
+ VEC_OP_MOD,
+ VEC_OP_POW,
+ VEC_OP_MAX,
+ VEC_OP_MIN,
+ VEC_OP_CROSS,
+ VEC_MAX_OP
+ };
- ShaderGraph();
+ void vec_op_node_set_op(ShaderType p_which,float p_id,VecOp p_op);
+ VecOp vec_op_node_get_op(ShaderType p_which,float p_id) const;
+
+ enum VecScalarOp {
+ VEC_SCALAR_OP_MUL,
+ VEC_SCALAR_OP_DIV,
+ VEC_SCALAR_OP_POW,
+ VEC_SCALAR_MAX_OP
+ };
+
+ void vec_scalar_op_node_set_op(ShaderType p_which,float p_id,VecScalarOp p_op);
+ VecScalarOp vec_scalar_op_node_get_op(ShaderType p_which,float p_id) const;
+
+ enum RGBOp {
+ RGB_OP_SCREEN,
+ RGB_OP_DIFFERENCE,
+ RGB_OP_DARKEN,
+ RGB_OP_LIGHTEN,
+ RGB_OP_OVERLAY,
+ RGB_OP_DODGE,
+ RGB_OP_BURN,
+ RGB_OP_SOFT_LIGHT,
+ RGB_OP_HARD_LIGHT,
+ RGB_MAX_OP
+ };
+
+ void rgb_op_node_set_op(ShaderType p_which,float p_id,RGBOp p_op);
+ RGBOp rgb_op_node_get_op(ShaderType p_which,float p_id) const;
+
+ void xform_vec_mult_node_set_no_translation(ShaderType p_which,int p_id,bool p_no_translation);
+ bool xform_vec_mult_node_get_no_translation(ShaderType p_which,int p_id) const;
+
+ enum ScalarFunc {
+ SCALAR_FUNC_SIN,
+ SCALAR_FUNC_COS,
+ SCALAR_FUNC_TAN,
+ SCALAR_FUNC_ASIN,
+ SCALAR_FUNC_ACOS,
+ SCALAR_FUNC_ATAN,
+ SCALAR_FUNC_SINH,
+ SCALAR_FUNC_COSH,
+ SCALAR_FUNC_TANH,
+ SCALAR_FUNC_LOG,
+ SCALAR_FUNC_EXP,
+ SCALAR_FUNC_SQRT,
+ SCALAR_FUNC_ABS,
+ SCALAR_FUNC_SIGN,
+ SCALAR_FUNC_FLOOR,
+ SCALAR_FUNC_ROUND,
+ SCALAR_FUNC_CEIL,
+ SCALAR_FUNC_FRAC,
+ SCALAR_FUNC_SATURATE,
+ SCALAR_FUNC_NEGATE,
+ SCALAR_MAX_FUNC
+ };
+
+ void scalar_func_node_set_function(ShaderType p_which,int p_id,ScalarFunc p_func);
+ ScalarFunc scalar_func_node_get_function(ShaderType p_which,int p_id) const;
+
+ enum VecFunc {
+ VEC_FUNC_NORMALIZE,
+ VEC_FUNC_SATURATE,
+ VEC_FUNC_NEGATE,
+ VEC_FUNC_RECIPROCAL,
+ VEC_FUNC_RGB2HSV,
+ VEC_FUNC_HSV2RGB,
+ VEC_MAX_FUNC
+ };
+
+ void vec_func_node_set_function(ShaderType p_which,int p_id,VecFunc p_func);
+ VecFunc vec_func_node_get_function(ShaderType p_which,int p_id) const;
+
+ void input_node_set_name(ShaderType p_which,int p_id,const String& p_name);
+ String input_node_get_name(ShaderType p_which,int p_id);
+
+ void scalar_input_node_set_value(ShaderType p_which,int p_id,float p_value);
+ float scalar_input_node_get_value(ShaderType p_which,int p_id) const;
+
+ void vec_input_node_set_value(ShaderType p_which,int p_id,const Vector3& p_value);
+ Vector3 vec_input_node_get_value(ShaderType p_which,int p_id) const;
+
+ void rgb_input_node_set_value(ShaderType p_which,int p_id,const Color& p_value);
+ Color rgb_input_node_get_value(ShaderType p_which,int p_id) const;
+
+ void xform_input_node_set_value(ShaderType p_which,int p_id,const Transform& p_value);
+ Transform xform_input_node_get_value(ShaderType p_which,int p_id) const;
+
+ void texture_input_node_set_value(ShaderType p_which,int p_id,const Ref<Texture>& p_texture);
+ Ref<Texture> texture_input_node_get_value(ShaderType p_which,int p_id) const;
+
+ void cubemap_input_node_set_value(ShaderType p_which,int p_id,const Ref<CubeMap>& p_cubemap);
+ Ref<CubeMap> cubemap_input_node_get_value(ShaderType p_which,int p_id) const;
+
+ void comment_node_set_text(ShaderType p_which,int p_id,const String& p_comment);
+ String comment_node_get_text(ShaderType p_which,int p_id) const;
+
+ Error connect_node(ShaderType p_which,int p_src_id,int p_src_slot, int p_dst_id,int p_dst_slot);
+ bool is_node_connected(ShaderType p_which,int p_src_id,int p_src_slot, int p_dst_id,int p_dst_slot) const;
+ void disconnect_node(ShaderType p_which,int p_src_id,int p_src_slot, int p_dst_id,int p_dst_slot);
+
+ void get_node_connections(ShaderType p_which,List<Connection> *p_connections) const;
+
+ void clear(ShaderType p_which);
+
+ Variant node_get_state(ShaderType p_type, int p_node) const;
+ void node_set_state(ShaderType p_type, int p_id, const Variant& p_state);
+
+ GraphError get_graph_error(ShaderType p_type) const;
+
+ static int get_type_input_count(NodeType p_type);
+ static int get_type_output_count(NodeType p_type);
+ static SlotType get_type_input_type(NodeType p_type,int p_idx);
+ static SlotType get_type_output_type(NodeType p_type,int p_idx);
+ static bool is_type_valid(Mode p_mode,ShaderType p_type);
+
+
+ struct SlotInfo {
+ String name;
+ SlotType type;
+ SlotDir dir;
+ };
+
+ static void get_input_output_node_slot_info(Mode p_mode, ShaderType p_type, List<SlotInfo> *r_slots);
+
+ static int get_node_input_slot_count(Mode p_mode, ShaderType p_shader_type,NodeType p_type);
+ static int get_node_output_slot_count(Mode p_mode, ShaderType p_shader_type,NodeType p_type);
+ static SlotType get_node_input_slot_type(Mode p_mode, ShaderType p_shader_type,NodeType p_type,int p_idx);
+ static SlotType get_node_output_slot_type(Mode p_mode, ShaderType p_shader_type,NodeType p_type,int p_idx);
+
+
+ ShaderGraph(Mode p_mode);
~ShaderGraph();
};
@@ -192,6 +381,28 @@ public:
VARIANT_ENUM_CAST( ShaderGraph::NodeType );
+VARIANT_ENUM_CAST( ShaderGraph::ShaderType );
+VARIANT_ENUM_CAST( ShaderGraph::SlotType );
+VARIANT_ENUM_CAST( ShaderGraph::ScalarOp );
+VARIANT_ENUM_CAST( ShaderGraph::VecOp );
+VARIANT_ENUM_CAST( ShaderGraph::VecScalarOp );
+VARIANT_ENUM_CAST( ShaderGraph::RGBOp );
+VARIANT_ENUM_CAST( ShaderGraph::ScalarFunc );
+VARIANT_ENUM_CAST( ShaderGraph::VecFunc );
+VARIANT_ENUM_CAST( ShaderGraph::GraphError );
+
+
+class MaterialShaderGraph : public ShaderGraph {
+
+ OBJ_TYPE( MaterialShaderGraph, ShaderGraph );
+ RES_BASE_EXTENSION("sgp");
+
+public:
+
+
+ MaterialShaderGraph() : ShaderGraph(MODE_MATERIAL) {
+
+ }
+};
-#endif
#endif // SHADER_GRAPH_H
diff --git a/scene/resources/surface_tool.cpp b/scene/resources/surface_tool.cpp
index dd39205932..113fd8209d 100644
--- a/scene/resources/surface_tool.cpp
+++ b/scene/resources/surface_tool.cpp
@@ -650,8 +650,8 @@ void SurfaceTool::mikktGetTexCoord(const SMikkTSpaceContext * pContext, float fv
Vector<List<Vertex>::Element*> &varr = *((Vector<List<Vertex>::Element*>*)pContext->m_pUserData);
Vector2 v = varr[iFace*3+iVert]->get().uv;
fvTexcOut[0]=v.x;
- //fvTexcOut[1]=v.y;
- fvTexcOut[1]=1.0-v.y;
+ fvTexcOut[1]=v.y;
+ //fvTexcOut[1]=1.0-v.y;
}
void SurfaceTool::mikktSetTSpaceBasic(const SMikkTSpaceContext * pContext, const float fvTangent[], const float fSign, const int iFace, const int iVert){
diff --git a/scene/resources/world_2d.cpp b/scene/resources/world_2d.cpp
index aee7ddde00..0dd6a3d5e7 100644
--- a/scene/resources/world_2d.cpp
+++ b/scene/resources/world_2d.cpp
@@ -364,12 +364,12 @@ World2D::World2D() {
Physics2DServer::get_singleton()->space_set_active(space,true);
Physics2DServer::get_singleton()->area_set_param(space,Physics2DServer::AREA_PARAM_GRAVITY,GLOBAL_DEF("physics_2d/default_gravity",98));
Physics2DServer::get_singleton()->area_set_param(space,Physics2DServer::AREA_PARAM_GRAVITY_VECTOR,GLOBAL_DEF("physics_2d/default_gravity_vector",Vector2(0,1)));
- Physics2DServer::get_singleton()->area_set_param(space,Physics2DServer::AREA_PARAM_DENSITY,GLOBAL_DEF("physics_2d/default_density",0.1));
+ Physics2DServer::get_singleton()->area_set_param(space,Physics2DServer::AREA_PARAM_LINEAR_DAMP,GLOBAL_DEF("physics_2d/default_density",0.1));
+ Physics2DServer::get_singleton()->area_set_param(space,Physics2DServer::AREA_PARAM_ANGULAR_DAMP,GLOBAL_DEF("physics_2d/default_density",1));
Physics2DServer::get_singleton()->space_set_param(space,Physics2DServer::SPACE_PARAM_CONTACT_RECYCLE_RADIUS,1.0);
Physics2DServer::get_singleton()->space_set_param(space,Physics2DServer::SPACE_PARAM_CONTACT_MAX_SEPARATION,1.5);
Physics2DServer::get_singleton()->space_set_param(space,Physics2DServer::SPACE_PARAM_BODY_MAX_ALLOWED_PENETRATION,0.3);
Physics2DServer::get_singleton()->space_set_param(space,Physics2DServer::SPACE_PARAM_BODY_LINEAR_VELOCITY_SLEEP_TRESHOLD,2);
- Physics2DServer::get_singleton()->space_set_param(space,Physics2DServer::SPACE_PARAM_BODY_ANGULAR_VELOCITY_DAMP_RATIO,20);
Physics2DServer::get_singleton()->space_set_param(space,Physics2DServer::SPACE_PARAM_CONSTRAINT_DEFAULT_BIAS,0.2);
indexer = memnew( SpatialIndexer2D );
diff --git a/scene/scene_string_names.cpp b/scene/scene_string_names.cpp
index 0d66257eda..af5e6d4165 100644
--- a/scene/scene_string_names.cpp
+++ b/scene/scene_string_names.cpp
@@ -67,6 +67,7 @@ SceneStringNames::SceneStringNames() {
idle=StaticCString::create("idle");
iteration=StaticCString::create("iteration");
update=StaticCString::create("update");
+ updated=StaticCString::create("updated");
_get_gizmo_geometry=StaticCString::create("_get_gizmo_geometry");
_can_gizmo_scale=StaticCString::create("_can_gizmo_scale");
diff --git a/scene/scene_string_names.h b/scene/scene_string_names.h
index b0628c86b6..14e5e83b8d 100644
--- a/scene/scene_string_names.h
+++ b/scene/scene_string_names.h
@@ -63,6 +63,7 @@ public:
StringName idle;
StringName iteration;
StringName update;
+ StringName updated;
StringName line_separation;
diff --git a/servers/physics/body_pair_sw.cpp b/servers/physics/body_pair_sw.cpp
index 2e66c9e27b..5847b942fb 100644
--- a/servers/physics/body_pair_sw.cpp
+++ b/servers/physics/body_pair_sw.cpp
@@ -172,6 +172,53 @@ void BodyPairSW::validate_contacts() {
}
}
+
+bool BodyPairSW::_test_ccd(float p_step,BodySW *p_A, int p_shape_A,const Transform& p_xform_A,BodySW *p_B, int p_shape_B,const Transform& p_xform_B) {
+
+
+
+ Vector3 motion = p_A->get_linear_velocity()*p_step;
+ real_t mlen = motion.length();
+ if (mlen<CMP_EPSILON)
+ return false;
+
+ Vector3 mnormal = motion / mlen;
+
+ real_t min,max;
+ p_A->get_shape(p_shape_A)->project_range(mnormal,p_xform_A,min,max);
+ bool fast_object = mlen > (max-min)*0.3; //going too fast in that direction
+
+ if (!fast_object) { //did it move enough in this direction to even attempt raycast? let's say it should move more than 1/3 the size of the object in that axis
+ return false;
+ }
+
+ //cast a segment from support in motion normal, in the same direction of motion by motion length
+ //support is the worst case collision point, so real collision happened before
+ int a;
+ Vector3 s=p_A->get_shape(p_shape_A)->get_support(p_xform_A.basis.xform(mnormal).normalized());
+ Vector3 from = p_xform_A.xform(s);
+ Vector3 to = from + motion;
+
+ Transform from_inv = p_xform_B.affine_inverse();
+
+ Vector3 local_from = from_inv.xform(from-mnormal*mlen*0.1); //start from a little inside the bounding box
+ Vector3 local_to = from_inv.xform(to);
+
+ Vector3 rpos,rnorm;
+ if (!p_B->get_shape(p_shape_B)->intersect_segment(local_from,local_to,rpos,rnorm)) {
+ return false;
+ }
+
+ //shorten the linear velocity so it does not hit, but gets close enough, next frame will hit softly or soft enough
+ Vector3 hitpos = p_xform_B.xform(rpos);
+
+ float newlen = hitpos.distance_to(from)-(max-min)*0.01;
+ p_A->set_linear_velocity((mnormal*newlen)/p_step);
+
+ return true;
+}
+
+
bool BodyPairSW::setup(float p_step) {
//cannot collide
@@ -198,8 +245,21 @@ bool BodyPairSW::setup(float p_step) {
bool collided = CollisionSolverSW::solve_static(shape_A_ptr,xform_A,shape_B_ptr,xform_B,_contact_added_callback,this,&sep_axis);
this->collided=collided;
- if (!collided)
+
+ if (!collided) {
+
+ //test ccd (currently just a raycast)
+
+ if (A->is_continuous_collision_detection_enabled() && A->get_mode()>PhysicsServer::BODY_MODE_KINEMATIC && B->get_mode()<=PhysicsServer::BODY_MODE_KINEMATIC) {
+ _test_ccd(p_step,A,shape_A,xform_A,B,shape_B,xform_B);
+ }
+
+ if (B->is_continuous_collision_detection_enabled() && B->get_mode()>PhysicsServer::BODY_MODE_KINEMATIC && A->get_mode()<=PhysicsServer::BODY_MODE_KINEMATIC) {
+ _test_ccd(p_step,B,shape_B,xform_B,A,shape_A,xform_A);
+ }
+
return false;
+ }
diff --git a/servers/physics/body_pair_sw.h b/servers/physics/body_pair_sw.h
index 937c295c63..e64464e2c1 100644
--- a/servers/physics/body_pair_sw.h
+++ b/servers/physics/body_pair_sw.h
@@ -82,6 +82,7 @@ class BodyPairSW : public ConstraintSW {
void contact_added_callback(const Vector3& p_point_A,const Vector3& p_point_B);
void validate_contacts();
+ bool _test_ccd(float p_step,BodySW *p_A, int p_shape_A,const Transform& p_xform_A,BodySW *p_B, int p_shape_B,const Transform& p_xform_B);
SpaceSW *space;
diff --git a/servers/physics/physics_server_sw.cpp b/servers/physics/physics_server_sw.cpp
index 510a6ea93f..cfe5a73ce1 100644
--- a/servers/physics/physics_server_sw.cpp
+++ b/servers/physics/physics_server_sw.cpp
@@ -770,7 +770,7 @@ void PhysicsServerSW::body_remove_collision_exception(RID p_body, RID p_body_b)
BodySW *body = body_owner.get(p_body);
ERR_FAIL_COND(!body);
- body->remove_exception(p_body);
+ body->remove_exception(p_body_b);
};
diff --git a/servers/physics_2d/area_2d_sw.cpp b/servers/physics_2d/area_2d_sw.cpp
index 8be583c235..2e911288ae 100644
--- a/servers/physics_2d/area_2d_sw.cpp
+++ b/servers/physics_2d/area_2d_sw.cpp
@@ -99,7 +99,8 @@ void Area2DSW::set_param(Physics2DServer::AreaParameter p_param, const Variant&
case Physics2DServer::AREA_PARAM_GRAVITY_VECTOR: gravity_vector=p_value; ; break;
case Physics2DServer::AREA_PARAM_GRAVITY_IS_POINT: gravity_is_point=p_value; ; break;
case Physics2DServer::AREA_PARAM_GRAVITY_POINT_ATTENUATION: point_attenuation=p_value; ; break;
- case Physics2DServer::AREA_PARAM_DENSITY: density=p_value; ; break;
+ case Physics2DServer::AREA_PARAM_LINEAR_DAMP: linear_damp=p_value; ; break;
+ case Physics2DServer::AREA_PARAM_ANGULAR_DAMP: angular_damp=p_value; ; break;
case Physics2DServer::AREA_PARAM_PRIORITY: priority=p_value; ; break;
}
@@ -114,7 +115,8 @@ Variant Area2DSW::get_param(Physics2DServer::AreaParameter p_param) const {
case Physics2DServer::AREA_PARAM_GRAVITY_VECTOR: return gravity_vector;
case Physics2DServer::AREA_PARAM_GRAVITY_IS_POINT: return gravity_is_point;
case Physics2DServer::AREA_PARAM_GRAVITY_POINT_ATTENUATION: return point_attenuation;
- case Physics2DServer::AREA_PARAM_DENSITY: return density;
+ case Physics2DServer::AREA_PARAM_LINEAR_DAMP: return linear_damp;
+ case Physics2DServer::AREA_PARAM_ANGULAR_DAMP: return angular_damp;
case Physics2DServer::AREA_PARAM_PRIORITY: return priority;
}
@@ -181,7 +183,8 @@ Area2DSW::Area2DSW() : CollisionObject2DSW(TYPE_AREA), monitor_query_list(this),
gravity_is_point=false;
point_attenuation=1;
- density=0.1;
+ angular_damp=1.0;
+ linear_damp=0.1;
priority=0;
monitor_callback_id=0;
diff --git a/servers/physics_2d/area_2d_sw.h b/servers/physics_2d/area_2d_sw.h
index 0eda1050fa..d94b2f9ccf 100644
--- a/servers/physics_2d/area_2d_sw.h
+++ b/servers/physics_2d/area_2d_sw.h
@@ -47,7 +47,8 @@ class Area2DSW : public CollisionObject2DSW{
Vector2 gravity_vector;
bool gravity_is_point;
float point_attenuation;
- float density;
+ float linear_damp;
+ float angular_damp;
int priority;
ObjectID monitor_callback_id;
@@ -128,8 +129,11 @@ public:
_FORCE_INLINE_ void set_point_attenuation(float p_point_attenuation) { point_attenuation=p_point_attenuation; }
_FORCE_INLINE_ float get_point_attenuation() const { return point_attenuation; }
- _FORCE_INLINE_ void set_density(float p_density) { density=p_density; }
- _FORCE_INLINE_ float get_density() const { return density; }
+ _FORCE_INLINE_ void set_linear_damp(float p_linear_damp) { linear_damp=p_linear_damp; }
+ _FORCE_INLINE_ float get_linear_damp() const { return linear_damp; }
+
+ _FORCE_INLINE_ void set_angular_damp(float p_angular_damp) { angular_damp=p_angular_damp; }
+ _FORCE_INLINE_ float get_angular_damp() const { return angular_damp; }
_FORCE_INLINE_ void set_priority(int p_priority) { priority=p_priority; }
_FORCE_INLINE_ int get_priority() const { return priority; }
diff --git a/servers/physics_2d/body_2d_sw.cpp b/servers/physics_2d/body_2d_sw.cpp
index 591bf046ef..d93d4d5c35 100644
--- a/servers/physics_2d/body_2d_sw.cpp
+++ b/servers/physics_2d/body_2d_sw.cpp
@@ -156,6 +156,17 @@ void Body2DSW::set_param(Physics2DServer::BodyParameter p_param, float p_value)
_update_inertia();
} break;
+ case Physics2DServer::BODY_PARAM_GRAVITY_SCALE: {
+ gravity_scale=p_value;
+ } break;
+ case Physics2DServer::BODY_PARAM_LINEAR_DAMP: {
+
+ linear_damp=p_value;
+ } break;
+ case Physics2DServer::BODY_PARAM_ANGULAR_DAMP: {
+
+ angular_damp=p_value;
+ } break;
default:{}
}
}
@@ -174,6 +185,17 @@ float Body2DSW::get_param(Physics2DServer::BodyParameter p_param) const {
case Physics2DServer::BODY_PARAM_MASS: {
return mass;
} break;
+ case Physics2DServer::BODY_PARAM_GRAVITY_SCALE: {
+ return gravity_scale;
+ } break;
+ case Physics2DServer::BODY_PARAM_LINEAR_DAMP: {
+
+ return linear_damp;
+ } break;
+ case Physics2DServer::BODY_PARAM_ANGULAR_DAMP: {
+
+ return angular_damp;
+ } break;
default:{}
}
@@ -362,6 +384,8 @@ void Body2DSW::_compute_area_gravity(const Area2DSW *p_area) {
} else {
gravity = p_area->get_gravity_vector() * p_area->get_gravity();
}
+
+ gravity*=gravity_scale;
}
void Body2DSW::integrate_forces(real_t p_step) {
@@ -385,7 +409,16 @@ void Body2DSW::integrate_forces(real_t p_step) {
}
_compute_area_gravity(current_area);
- density=current_area->get_density();
+
+ if (angular_damp>=0)
+ area_angular_damp=angular_damp;
+ else
+ area_angular_damp=current_area->get_angular_damp();
+
+ if (linear_damp>=0)
+ area_linear_damp=linear_damp;
+ else
+ area_linear_damp=current_area->get_linear_damp();
Vector2 motion;
bool do_motion=false;
@@ -414,12 +447,12 @@ void Body2DSW::integrate_forces(real_t p_step) {
force+=applied_force;
real_t torque=applied_torque;
- real_t damp = 1.0 - p_step * density;
+ real_t damp = 1.0 - p_step * area_linear_damp;
if (damp<0) // reached zero in the given time
damp=0;
- real_t angular_damp = 1.0 - p_step * density * get_space()->get_body_angular_velocity_damp_ratio();
+ real_t angular_damp = 1.0 - p_step * area_angular_damp;
if (angular_damp<0) // reached zero in the given time
angular_damp=0;
@@ -608,8 +641,12 @@ Body2DSW::Body2DSW() : CollisionObject2DSW(TYPE_BODY), active_list(this), inerti
island_list_next=NULL;
_set_static(false);
first_time_kinematic=false;
- density=0;
+ linear_damp=-1;
+ angular_damp=-1;
+ area_angular_damp=0;
+ area_linear_damp=0;
contact_count=0;
+ gravity_scale=1.0;
still_time=0;
continuous_cd_mode=Physics2DServer::CCD_MODE_DISABLED;
diff --git a/servers/physics_2d/body_2d_sw.h b/servers/physics_2d/body_2d_sw.h
index 789fb1cfee..5bd68ba976 100644
--- a/servers/physics_2d/body_2d_sw.h
+++ b/servers/physics_2d/body_2d_sw.h
@@ -47,6 +47,10 @@ class Body2DSW : public CollisionObject2DSW {
Vector2 linear_velocity;
real_t angular_velocity;
+ real_t linear_damp;
+ real_t angular_damp;
+ real_t gravity_scale;
+
real_t mass;
real_t bounce;
real_t friction;
@@ -55,7 +59,8 @@ class Body2DSW : public CollisionObject2DSW {
real_t _inv_inertia;
Vector2 gravity;
- real_t density;
+ real_t area_linear_damp;
+ real_t area_angular_damp;
real_t still_time;
@@ -219,8 +224,10 @@ public:
_FORCE_INLINE_ real_t get_inv_inertia() const { return _inv_inertia; }
_FORCE_INLINE_ real_t get_friction() const { return friction; }
_FORCE_INLINE_ Vector2 get_gravity() const { return gravity; }
- _FORCE_INLINE_ real_t get_density() const { return density; }
_FORCE_INLINE_ real_t get_bounce() const { return bounce; }
+ _FORCE_INLINE_ real_t get_linear_damp() const { return linear_damp; }
+ _FORCE_INLINE_ real_t get_angular_damp() const { return angular_damp; }
+
void integrate_forces(real_t p_step);
void integrate_velocities(real_t p_step);
@@ -306,7 +313,8 @@ public:
real_t step;
virtual Vector2 get_total_gravity() const { return body->get_gravity(); } // get gravity vector working on this body space/area
- virtual float get_total_density() const { return body->get_density(); } // get density of this body space/area
+ virtual float get_total_angular_damp() const { return body->get_angular_damp(); } // get density of this body space/area
+ virtual float get_total_linear_damp() const { return body->get_linear_damp(); } // get density of this body space/area
virtual float get_inverse_mass() const { return body->get_inv_mass(); } // get the mass
virtual real_t get_inverse_inertia() const { return body->get_inv_inertia(); } // get density of this body space
diff --git a/servers/physics_2d/body_pair_2d_sw.cpp b/servers/physics_2d/body_pair_2d_sw.cpp
index 9abdd01791..c4d6abe5ac 100644
--- a/servers/physics_2d/body_pair_2d_sw.cpp
+++ b/servers/physics_2d/body_pair_2d_sw.cpp
@@ -190,7 +190,7 @@ bool BodyPair2DSW::_test_ccd(float p_step,Body2DSW *p_A, int p_shape_A,const Mat
p_A->get_shape(p_shape_A)->project_rangev(mnormal,p_xform_A,min,max);
bool fast_object = mlen > (max-min)*0.3; //going too fast in that direction
- if (fast_object) { //did it move enough in this direction to even attempt raycast? let's say it should move more than 1/3 the size of the object in that axis
+ if (!fast_object) { //did it move enough in this direction to even attempt raycast? let's say it should move more than 1/3 the size of the object in that axis
return false;
}
diff --git a/servers/physics_2d/space_2d_sw.cpp b/servers/physics_2d/space_2d_sw.cpp
index b642242d02..76069de9a0 100644
--- a/servers/physics_2d/space_2d_sw.cpp
+++ b/servers/physics_2d/space_2d_sw.cpp
@@ -606,8 +606,7 @@ void Space2DSW::set_param(Physics2DServer::SpaceParameter p_param, real_t p_valu
case Physics2DServer::SPACE_PARAM_BODY_MAX_ALLOWED_PENETRATION: contact_max_allowed_penetration=p_value; break;
case Physics2DServer::SPACE_PARAM_BODY_LINEAR_VELOCITY_SLEEP_TRESHOLD: body_linear_velocity_sleep_treshold=p_value; break;
case Physics2DServer::SPACE_PARAM_BODY_ANGULAR_VELOCITY_SLEEP_TRESHOLD: body_angular_velocity_sleep_treshold=p_value; break;
- case Physics2DServer::SPACE_PARAM_BODY_TIME_TO_SLEEP: body_time_to_sleep=p_value; break;
- case Physics2DServer::SPACE_PARAM_BODY_ANGULAR_VELOCITY_DAMP_RATIO: body_angular_velocity_damp_ratio=p_value; break;
+ case Physics2DServer::SPACE_PARAM_BODY_TIME_TO_SLEEP: body_time_to_sleep=p_value; break;
case Physics2DServer::SPACE_PARAM_CONSTRAINT_DEFAULT_BIAS: constraint_bias=p_value; break;
}
}
@@ -622,7 +621,6 @@ real_t Space2DSW::get_param(Physics2DServer::SpaceParameter p_param) const {
case Physics2DServer::SPACE_PARAM_BODY_LINEAR_VELOCITY_SLEEP_TRESHOLD: return body_linear_velocity_sleep_treshold;
case Physics2DServer::SPACE_PARAM_BODY_ANGULAR_VELOCITY_SLEEP_TRESHOLD: return body_angular_velocity_sleep_treshold;
case Physics2DServer::SPACE_PARAM_BODY_TIME_TO_SLEEP: return body_time_to_sleep;
- case Physics2DServer::SPACE_PARAM_BODY_ANGULAR_VELOCITY_DAMP_RATIO: return body_angular_velocity_damp_ratio;
case Physics2DServer::SPACE_PARAM_CONSTRAINT_DEFAULT_BIAS: return constraint_bias;
}
return 0;
@@ -664,7 +662,6 @@ Space2DSW::Space2DSW() {
body_linear_velocity_sleep_treshold=0.01;
body_angular_velocity_sleep_treshold=(8.0 / 180.0 * Math_PI);
body_time_to_sleep=0.5;
- body_angular_velocity_damp_ratio=15;
broadphase = BroadPhase2DSW::create_func();
diff --git a/servers/physics_2d/space_2d_sw.h b/servers/physics_2d/space_2d_sw.h
index c638a0c45b..7977b19063 100644
--- a/servers/physics_2d/space_2d_sw.h
+++ b/servers/physics_2d/space_2d_sw.h
@@ -93,7 +93,6 @@ class Space2DSW {
float body_linear_velocity_sleep_treshold;
float body_angular_velocity_sleep_treshold;
float body_time_to_sleep;
- float body_angular_velocity_damp_ratio;
bool locked;
@@ -142,7 +141,7 @@ public:
_FORCE_INLINE_ real_t get_body_linear_velocity_sleep_treshold() const { return body_linear_velocity_sleep_treshold; }
_FORCE_INLINE_ real_t get_body_angular_velocity_sleep_treshold() const { return body_angular_velocity_sleep_treshold; }
_FORCE_INLINE_ real_t get_body_time_to_sleep() const { return body_time_to_sleep; }
- _FORCE_INLINE_ real_t get_body_angular_velocity_damp_ratio() const { return body_angular_velocity_damp_ratio; }
+
void update();
diff --git a/servers/physics_2d_server.cpp b/servers/physics_2d_server.cpp
index 22fb4fc0a8..3633efc5eb 100644
--- a/servers/physics_2d_server.cpp
+++ b/servers/physics_2d_server.cpp
@@ -39,20 +39,24 @@ void Physics2DDirectBodyState::integrate_forces() {
real_t av = get_angular_velocity();
- float damp = 1.0 - step * get_total_density();
+ float damp = 1.0 - step * get_total_linear_damp();
if (damp<0) // reached zero in the given time
damp=0;
lv*=damp;
+
+ damp = 1.0 - step * get_total_angular_damp();
+
+ if (damp<0) // reached zero in the given time
+ damp=0;
+
av*=damp;
set_linear_velocity(lv);
set_angular_velocity(av);
-
-
}
Object* Physics2DDirectBodyState::get_contact_collider_object(int p_contact_idx) const {
@@ -70,7 +74,8 @@ Physics2DServer * Physics2DServer::get_singleton() {
void Physics2DDirectBodyState::_bind_methods() {
ObjectTypeDB::bind_method(_MD("get_total_gravity"),&Physics2DDirectBodyState::get_total_gravity);
- ObjectTypeDB::bind_method(_MD("get_total_density"),&Physics2DDirectBodyState::get_total_density);
+ ObjectTypeDB::bind_method(_MD("get_total_linear_damp"),&Physics2DDirectBodyState::get_total_linear_damp);
+ ObjectTypeDB::bind_method(_MD("get_total_angular_damp"),&Physics2DDirectBodyState::get_total_angular_damp);
ObjectTypeDB::bind_method(_MD("get_inverse_mass"),&Physics2DDirectBodyState::get_inverse_mass);
ObjectTypeDB::bind_method(_MD("get_inverse_inertia"),&Physics2DDirectBodyState::get_inverse_inertia);
@@ -538,7 +543,8 @@ void Physics2DServer::_bind_methods() {
BIND_CONSTANT( AREA_PARAM_GRAVITY_VECTOR );
BIND_CONSTANT( AREA_PARAM_GRAVITY_IS_POINT );
BIND_CONSTANT( AREA_PARAM_GRAVITY_POINT_ATTENUATION );
- BIND_CONSTANT( AREA_PARAM_DENSITY );
+ BIND_CONSTANT( AREA_PARAM_LINEAR_DAMP);
+ BIND_CONSTANT( AREA_PARAM_ANGULAR_DAMP);
BIND_CONSTANT( AREA_PARAM_PRIORITY );
BIND_CONSTANT( AREA_SPACE_OVERRIDE_COMBINE );
@@ -553,6 +559,9 @@ void Physics2DServer::_bind_methods() {
BIND_CONSTANT( BODY_PARAM_BOUNCE );
BIND_CONSTANT( BODY_PARAM_FRICTION );
BIND_CONSTANT( BODY_PARAM_MASS );
+ BIND_CONSTANT( BODY_PARAM_GRAVITY_SCALE );
+ BIND_CONSTANT( BODY_PARAM_LINEAR_DAMP);
+ BIND_CONSTANT( BODY_PARAM_ANGULAR_DAMP);
BIND_CONSTANT( BODY_PARAM_MAX );
BIND_CONSTANT( BODY_STATE_TRANSFORM );
diff --git a/servers/physics_2d_server.h b/servers/physics_2d_server.h
index 20d7c3ad28..6e53cde55c 100644
--- a/servers/physics_2d_server.h
+++ b/servers/physics_2d_server.h
@@ -43,7 +43,8 @@ protected:
public:
virtual Vector2 get_total_gravity() const=0; // get gravity vector working on this body space/area
- virtual float get_total_density() const=0; // get density of this body space/area
+ virtual float get_total_linear_damp() const=0; // get density of this body space/area
+ virtual float get_total_angular_damp() const=0; // get density of this body space/area
virtual float get_inverse_mass() const=0; // get the mass
virtual real_t get_inverse_inertia() const=0; // get density of this body space
@@ -277,7 +278,6 @@ public:
SPACE_PARAM_BODY_LINEAR_VELOCITY_SLEEP_TRESHOLD,
SPACE_PARAM_BODY_ANGULAR_VELOCITY_SLEEP_TRESHOLD,
SPACE_PARAM_BODY_TIME_TO_SLEEP,
- SPACE_PARAM_BODY_ANGULAR_VELOCITY_DAMP_RATIO,
SPACE_PARAM_CONSTRAINT_DEFAULT_BIAS,
};
@@ -301,7 +301,8 @@ public:
AREA_PARAM_GRAVITY_VECTOR,
AREA_PARAM_GRAVITY_IS_POINT,
AREA_PARAM_GRAVITY_POINT_ATTENUATION,
- AREA_PARAM_DENSITY,
+ AREA_PARAM_LINEAR_DAMP,
+ AREA_PARAM_ANGULAR_DAMP,
AREA_PARAM_PRIORITY
};
@@ -401,6 +402,9 @@ public:
BODY_PARAM_BOUNCE,
BODY_PARAM_FRICTION,
BODY_PARAM_MASS, ///< unused for static, always infinite
+ BODY_PARAM_GRAVITY_SCALE,
+ BODY_PARAM_LINEAR_DAMP,
+ BODY_PARAM_ANGULAR_DAMP,
BODY_PARAM_MAX,
};
@@ -414,7 +418,7 @@ public:
BODY_STATE_LINEAR_VELOCITY,
BODY_STATE_ANGULAR_VELOCITY,
BODY_STATE_SLEEPING,
- BODY_STATE_CAN_SLEEP
+ BODY_STATE_CAN_SLEEP,
};
virtual void body_set_state(RID p_body, BodyState p_state, const Variant& p_variant)=0;
diff --git a/servers/visual/rasterizer.h b/servers/visual/rasterizer.h
index 55625a2218..8731095425 100644
--- a/servers/visual/rasterizer.h
+++ b/servers/visual/rasterizer.h
@@ -187,6 +187,7 @@ public:
virtual bool texture_has_alpha(RID p_texture) const=0;
virtual void texture_set_size_override(RID p_texture,int p_width, int p_height)=0;
+
virtual void texture_set_reload_hook(RID p_texture,ObjectID p_owner,const StringName& p_function) const=0;
/* SHADER API */
@@ -203,6 +204,9 @@ public:
virtual void shader_get_param_list(RID p_shader, List<PropertyInfo> *p_param_list) const=0;
+ virtual void shader_set_default_texture_param(RID p_shader, const StringName& p_name, RID p_texture)=0;
+ virtual RID shader_get_default_texture_param(RID p_shader, const StringName& p_name) const=0;
+
/* COMMON MATERIAL API */
virtual RID material_create()=0;
diff --git a/servers/visual/rasterizer_dummy.cpp b/servers/visual/rasterizer_dummy.cpp
index a671821e25..a399960014 100644
--- a/servers/visual/rasterizer_dummy.cpp
+++ b/servers/visual/rasterizer_dummy.cpp
@@ -221,6 +221,16 @@ void RasterizerDummy::shader_get_param_list(RID p_shader, List<PropertyInfo> *p_
}
+
+void RasterizerDummy::shader_set_default_texture_param(RID p_shader, const StringName& p_name, RID p_texture) {
+
+}
+
+RID RasterizerDummy::shader_get_default_texture_param(RID p_shader, const StringName& p_name) const {
+
+ return RID();
+}
+
/* COMMON MATERIAL API */
diff --git a/servers/visual/rasterizer_dummy.h b/servers/visual/rasterizer_dummy.h
index 44bca423a4..d879fcafeb 100644
--- a/servers/visual/rasterizer_dummy.h
+++ b/servers/visual/rasterizer_dummy.h
@@ -429,6 +429,10 @@ public:
virtual void shader_get_param_list(RID p_shader, List<PropertyInfo> *p_param_list) const;
+
+ virtual void shader_set_default_texture_param(RID p_shader, const StringName& p_name, RID p_texture);
+ virtual RID shader_get_default_texture_param(RID p_shader, const StringName& p_name) const;
+
/* COMMON MATERIAL API */
virtual RID material_create();
diff --git a/servers/visual/shader_graph.h b/servers/visual/shader_graph.h
index 5c5079202f..fe305f3955 100644
--- a/servers/visual/shader_graph.h
+++ b/servers/visual/shader_graph.h
@@ -26,8 +26,6 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#ifndef SHADER_GRAPH_H
-#define SHADER_GRAPH_H
#if 0
@@ -109,4 +107,3 @@ public:
};
#endif
-#endif
diff --git a/servers/visual/shader_language.cpp b/servers/visual/shader_language.cpp
index 40e36d2a89..f2348bf59f 100644
--- a/servers/visual/shader_language.cpp
+++ b/servers/visual/shader_language.cpp
@@ -768,16 +768,20 @@ const ShaderLanguage::IntrinsicFuncDef ShaderLanguage::intrinsic_func_defs[]={
//constructors
{"bool",TYPE_BOOL,{TYPE_BOOL,TYPE_VOID}},
{"float",TYPE_FLOAT,{TYPE_FLOAT,TYPE_VOID}},
+ {"vec2",TYPE_VEC2,{TYPE_FLOAT,TYPE_VOID}},
{"vec2",TYPE_VEC2,{TYPE_FLOAT,TYPE_FLOAT,TYPE_VOID}},
+ {"vec3",TYPE_VEC3,{TYPE_FLOAT,TYPE_VOID}},
{"vec3",TYPE_VEC3,{TYPE_FLOAT,TYPE_FLOAT,TYPE_FLOAT,TYPE_VOID}},
{"vec3",TYPE_VEC3,{TYPE_VEC2,TYPE_FLOAT,TYPE_VOID}},
{"vec3",TYPE_VEC3,{TYPE_FLOAT,TYPE_VEC2,TYPE_VOID}},
+ {"vec4",TYPE_VEC4,{TYPE_FLOAT,TYPE_VOID}},
{"vec4",TYPE_VEC4,{TYPE_FLOAT,TYPE_FLOAT,TYPE_FLOAT,TYPE_FLOAT,TYPE_VOID}},
{"vec4",TYPE_VEC4,{TYPE_FLOAT,TYPE_VEC2,TYPE_FLOAT,TYPE_VOID}},
{"vec4",TYPE_VEC4,{TYPE_VEC2,TYPE_FLOAT,TYPE_FLOAT,TYPE_VOID}},
{"vec4",TYPE_VEC4,{TYPE_FLOAT,TYPE_FLOAT,TYPE_VEC2,TYPE_VOID}},
{"vec4",TYPE_VEC4,{TYPE_FLOAT,TYPE_VEC3,TYPE_VOID}},
{"vec4",TYPE_VEC4,{TYPE_VEC3,TYPE_FLOAT,TYPE_VOID}},
+ {"vec4",TYPE_VEC4,{TYPE_VEC2,TYPE_VEC2,TYPE_VOID}},
{"mat3",TYPE_MAT3,{TYPE_VEC3,TYPE_VEC3,TYPE_VEC3,TYPE_VOID}},
{"mat4",TYPE_MAT4,{TYPE_VEC4,TYPE_VEC4,TYPE_VEC4,TYPE_VEC4,TYPE_VOID}},
//intrinsics - trigonometry
@@ -856,6 +860,9 @@ const ShaderLanguage::IntrinsicFuncDef ShaderLanguage::intrinsic_func_defs[]={
{"clamp",TYPE_VEC2,{TYPE_VEC2,TYPE_VEC2,TYPE_VEC2,TYPE_VOID}},
{"clamp",TYPE_VEC3,{TYPE_VEC3,TYPE_VEC3,TYPE_VEC3,TYPE_VOID}},
{"clamp",TYPE_VEC4,{TYPE_VEC4,TYPE_VEC4,TYPE_VEC4,TYPE_VOID}},
+ {"clamp",TYPE_VEC2,{TYPE_VEC2,TYPE_FLOAT,TYPE_FLOAT,TYPE_VOID}},
+ {"clamp",TYPE_VEC3,{TYPE_VEC3,TYPE_FLOAT,TYPE_FLOAT,TYPE_VOID}},
+ {"clamp",TYPE_VEC4,{TYPE_VEC4,TYPE_FLOAT,TYPE_FLOAT,TYPE_VOID}},
{"mix",TYPE_FLOAT,{TYPE_FLOAT,TYPE_FLOAT,TYPE_FLOAT,TYPE_VOID}},
{"mix",TYPE_VEC2,{TYPE_VEC2,TYPE_VEC2,TYPE_FLOAT,TYPE_VOID}},
{"mix",TYPE_VEC2,{TYPE_VEC2,TYPE_VEC2,TYPE_VEC2,TYPE_VOID}},
@@ -1047,7 +1054,7 @@ const ShaderLanguage::BuiltinsDef ShaderLanguage::vertex_builtins_defs[]={
const ShaderLanguage::BuiltinsDef ShaderLanguage::fragment_builtins_defs[]={
{ "VERTEX", TYPE_VEC3},
- { "POSITION", TYPE_VEC3},
+ { "POSITION", TYPE_VEC4},
{ "NORMAL", TYPE_VEC3},
{ "TANGENT", TYPE_VEC3},
{ "BINORMAL", TYPE_VEC3},
@@ -1210,9 +1217,25 @@ ShaderLanguage::Node* ShaderLanguage::validate_function_call(Parser&parser, Oper
Variant data;
switch(p_func->return_cache) {
case TYPE_FLOAT: data = cdata[0]; break;
- case TYPE_VEC2: data = Vector2(cdata[0],cdata[1]); break;
- case TYPE_VEC3: data = Vector3(cdata[0],cdata[1],cdata[2]); break;
- case TYPE_VEC4: data = Plane(cdata[0],cdata[1],cdata[2],cdata[3]); break;
+ case TYPE_VEC2:
+ if (cdata.size()==1)
+ data = Vector2(cdata[0],cdata[0]);
+ else
+ data = Vector2(cdata[0],cdata[1]);
+
+ break;
+ case TYPE_VEC3:
+ if (cdata.size()==1)
+ data = Vector3(cdata[0],cdata[0],cdata[0]);
+ else
+ data = Vector3(cdata[0],cdata[1],cdata[2]);
+ break;
+ case TYPE_VEC4:
+ if (cdata.size()==1)
+ data = Plane(cdata[0],cdata[0],cdata[0],cdata[0]);
+ else
+ data = Plane(cdata[0],cdata[1],cdata[2],cdata[3]);
+ break;
}
cn->datatype=p_func->return_cache;
diff --git a/servers/visual/visual_server_raster.cpp b/servers/visual/visual_server_raster.cpp
index af50b9b592..7cfa6dbb32 100644
--- a/servers/visual/visual_server_raster.cpp
+++ b/servers/visual/visual_server_raster.cpp
@@ -157,6 +157,16 @@ void VisualServerRaster::shader_get_param_list(RID p_shader, List<PropertyInfo>
}
+void VisualServerRaster::shader_set_default_texture_param(RID p_shader, const StringName& p_name, RID p_texture) {
+
+ rasterizer->shader_set_default_texture_param(p_shader,p_name,p_texture);
+}
+
+RID VisualServerRaster::shader_get_default_texture_param(RID p_shader, const StringName& p_name) const{
+
+ return rasterizer->shader_get_default_texture_param(p_shader,p_name);
+}
+
/* Material */
diff --git a/servers/visual/visual_server_raster.h b/servers/visual/visual_server_raster.h
index 3064f9ceb0..ce52077550 100644
--- a/servers/visual/visual_server_raster.h
+++ b/servers/visual/visual_server_raster.h
@@ -756,6 +756,10 @@ public:
virtual void shader_get_param_list(RID p_shader, List<PropertyInfo> *p_param_list) const;
+ virtual void shader_set_default_texture_param(RID p_shader, const StringName& p_name, RID p_texture);
+ virtual RID shader_get_default_texture_param(RID p_shader, const StringName& p_name) const;
+
+
/* COMMON MATERIAL API */
virtual RID material_create();
diff --git a/servers/visual/visual_server_wrap_mt.h b/servers/visual/visual_server_wrap_mt.h
index a4653b1013..7d2b8a3767 100644
--- a/servers/visual/visual_server_wrap_mt.h
+++ b/servers/visual/visual_server_wrap_mt.h
@@ -653,6 +653,10 @@ public:
FUNC1RC(String,shader_get_light_code,RID);
FUNC2SC(shader_get_param_list,RID,List<PropertyInfo>*);
+ FUNC3(shader_set_default_texture_param,RID,const StringName&,RID);
+ FUNC2RC(RID,shader_get_default_texture_param,RID,const StringName&);
+
+
/*virtual void shader_get_param_list(RID p_shader, List<PropertyInfo> *p_param_list) {
if (Thread::get_caller_ID()!=server_thread) {
command_queue.push_and_sync( visual_server, &VisualServer::shader_get_param_list,p_shader,p_param_list);
diff --git a/servers/visual_server.h b/servers/visual_server.h
index ed04b0d09c..4336a91407 100644
--- a/servers/visual_server.h
+++ b/servers/visual_server.h
@@ -140,6 +140,7 @@ public:
SHADER_POST_PROCESS,
};
+
virtual RID shader_create(ShaderMode p_mode=SHADER_MATERIAL)=0;
virtual void shader_set_mode(RID p_shader,ShaderMode p_mode)=0;
@@ -151,6 +152,9 @@ public:
virtual String shader_get_light_code(RID p_shader) const=0;
virtual void shader_get_param_list(RID p_shader, List<PropertyInfo> *p_param_list) const=0;
+ virtual void shader_set_default_texture_param(RID p_shader, const StringName& p_name, RID p_texture)=0;
+ virtual RID shader_get_default_texture_param(RID p_shader, const StringName& p_name) const=0;
+
/* COMMON MATERIAL API */
diff --git a/tools/SCsub b/tools/SCsub
index 875663b849..4d8b05fe79 100644
--- a/tools/SCsub
+++ b/tools/SCsub
@@ -5,13 +5,16 @@ env.add_source_files(env.tool_sources,"*.cpp")
Export('env')
-SConscript('editor/SCsub');
-#SConscript('scintilla/SCsub');
-SConscript('collada/SCsub');
-SConscript('docdump/SCsub');
-SConscript('freetype/SCsub');
-SConscript('doc/SCsub');
-SConscript('pck/SCsub');
+if (env["tools"]!="no"):
+ SConscript('editor/SCsub');
+ #SConscript('scintilla/SCsub');
+ SConscript('collada/SCsub');
+ SConscript('docdump/SCsub');
+ SConscript('freetype/SCsub');
+ SConscript('doc/SCsub')
+ SConscript('pck/SCsub')
+
+
lib = env.Library("tool",env.tool_sources)
diff --git a/tools/doc/doc_data.cpp b/tools/doc/doc_data.cpp
index d13c7ea73c..75759e7d30 100644
--- a/tools/doc/doc_data.cpp
+++ b/tools/doc/doc_data.cpp
@@ -186,8 +186,10 @@ void DocData::generate(bool p_basic_types) {
arginfo=E->get().return_val;
if (arginfo.type==Variant::NIL)
continue;
-
- method.return_type=(arginfo.hint==PROPERTY_HINT_RESOURCE_TYPE)?arginfo.hint_string:Variant::get_type_name(arginfo.type);
+ if (m && m->get_return_type()!=StringName())
+ method.return_type=m->get_return_type();
+ else
+ method.return_type=(arginfo.hint==PROPERTY_HINT_RESOURCE_TYPE)?arginfo.hint_string:Variant::get_type_name(arginfo.type);
} else {
diff --git a/tools/editor/animation_editor.cpp b/tools/editor/animation_editor.cpp
index 95f9ee6509..db70a2675a 100644
--- a/tools/editor/animation_editor.cpp
+++ b/tools/editor/animation_editor.cpp
@@ -2909,11 +2909,11 @@ void AnimationKeyEditor::set_anim_pos(float p_pos) {
void AnimationKeyEditor::_pane_drag(const Point2& p_delta) {
- Size2 ecs = ec->get_minsize();
+ Size2 ecs = ec->get_custom_minimum_size();
ecs.y-=p_delta.y;
if (ecs.y<100)
ecs.y=100;
- ec->set_minsize(ecs);;
+ ec->set_custom_minimum_size(ecs);;
}
@@ -3238,7 +3238,7 @@ AnimationKeyEditor::AnimationKeyEditor(UndoRedo *p_undo_redo, EditorHistory *p_h
move_down_button->connect("pressed",this,"_menu_track",make_binds(TRACK_MENU_MOVE_DOWN));
move_down_button->set_focus_mode(FOCUS_NONE);
move_down_button->set_disabled(true);
- move_down_button->set_tooltip("Move current track dosn.");
+ move_down_button->set_tooltip("Move current track down.");
remove_button = memnew( ToolButton );
hb->add_child(remove_button);
@@ -3296,8 +3296,8 @@ AnimationKeyEditor::AnimationKeyEditor(UndoRedo *p_undo_redo, EditorHistory *p_h
// menu->get_popup()->connect("item_pressed",this,"_menu_callback");
- ec = memnew (EmptyControl);
- ec->set_minsize(Size2(0,50));
+ ec = memnew (Control);
+ ec->set_custom_minimum_size(Size2(0,50));
add_child(ec);
ec->set_v_size_flags(SIZE_EXPAND_FILL);
diff --git a/tools/editor/animation_editor.h b/tools/editor/animation_editor.h
index 9d3e692fad..1f17922552 100644
--- a/tools/editor/animation_editor.h
+++ b/tools/editor/animation_editor.h
@@ -37,7 +37,7 @@
#include "scene/gui/scroll_bar.h"
#include "scene/gui/tool_button.h"
#include "scene/gui/file_dialog.h"
-#include "scene/gui/empty_control.h"
+
#include "scene/resources/animation.h"
#include "scene/animation/animation_cache.h"
#include "scene_tree_editor.h"
@@ -157,7 +157,7 @@ class AnimationKeyEditor : public VBoxContainer {
PopupMenu *track_menu;
PopupMenu *type_menu;
- EmptyControl *ec;
+ Control *ec;
TextureFrame *zoomicon;
HSlider *zoom;
//MenuButton *menu;
diff --git a/tools/editor/code_editor.cpp b/tools/editor/code_editor.cpp
index 6de59f184a..2209b24245 100644
--- a/tools/editor/code_editor.cpp
+++ b/tools/editor/code_editor.cpp
@@ -487,6 +487,7 @@ FindReplaceDialog::FindReplaceDialog() {
vb->add_child(error_label);
+
set_hide_on_ok(false);
}
@@ -507,15 +508,19 @@ void CodeTextEditor::_text_changed() {
}
void CodeTextEditor::_code_complete_timer_timeout() {
+ if (!is_visible())
+ return;
if (enable_complete_timer)
text_editor->query_code_comple();
}
-void CodeTextEditor::_complete_request(const String& p_request, int p_line) {
+void CodeTextEditor::_complete_request() {
List<String> entries;
- _code_complete_script(text_editor->get_text(),p_request,p_line,&entries);
+ _code_complete_script(text_editor->get_text_for_completion(),&entries);
// print_line("COMPLETE: "+p_request);
+ if (entries.size()==0)
+ return;
Vector<String> strs;
strs.resize(entries.size());
int i=0;
@@ -555,7 +560,7 @@ void CodeTextEditor::_on_settings_change() {
// AUTO BRACE COMPLETION
text_editor->set_auto_brace_completion(
- EDITOR_DEF("text_editor/auto_brace_complete", false)
+ EDITOR_DEF("text_editor/auto_brace_complete", true)
);
code_complete_timer->set_wait_time(
@@ -594,8 +599,21 @@ CodeTextEditor::CodeTextEditor() {
add_child(text_editor);
text_editor->set_area_as_parent_rect();
text_editor->set_margin(MARGIN_BOTTOM,20);
- text_editor->add_font_override("font",get_font("source","Fonts"));
+
+ String editor_font = EDITOR_DEF("text_editor/font", "");
+ bool font_overrode = false;
+ if (editor_font!="") {
+ Ref<Font> fnt = ResourceLoader::load(editor_font);
+ if (fnt.is_valid()) {
+ text_editor->add_font_override("font",fnt);
+ font_overrode = true;
+ }
+ }
+
+ if (!font_overrode)
+ text_editor->add_font_override("font",get_font("source","Fonts"));
text_editor->set_show_line_numbers(true);
+ text_editor->set_brace_matching(true);
line_col = memnew( Label );
add_child(line_col);
@@ -632,6 +650,8 @@ CodeTextEditor::CodeTextEditor() {
text_editor->connect("request_completion", this,"_complete_request");
Vector<String> cs;
cs.push_back(".");
+ cs.push_back(",");
+ cs.push_back("(");
text_editor->set_completion(true,cs);
idle->connect("timeout", this,"_text_changed_idle_timeout");
diff --git a/tools/editor/code_editor.h b/tools/editor/code_editor.h
index 1804237f18..f82eaf5ec5 100644
--- a/tools/editor/code_editor.h
+++ b/tools/editor/code_editor.h
@@ -135,7 +135,7 @@ class CodeTextEditor : public Control {
void _on_settings_change();
- void _complete_request(const String& p_request,int p_line);
+ void _complete_request();
protected:
void set_error(const String& p_error);
@@ -143,7 +143,7 @@ protected:
virtual void _load_theme_settings() {}
virtual void _validate_script()=0;
- virtual void _code_complete_script(const String& p_code, const String& p_keyword,int p_line, List<String>* r_options) {};
+ virtual void _code_complete_script(const String& p_code, List<String>* r_options) {};
void _text_changed_idle_timeout();
diff --git a/tools/editor/editor_help.cpp b/tools/editor/editor_help.cpp
index 8408436a6c..2283a2df14 100644
--- a/tools/editor/editor_help.cpp
+++ b/tools/editor/editor_help.cpp
@@ -1361,8 +1361,8 @@ EditorHelp::EditorHelp(EditorNode *p_editor) {
Separator *hs = memnew( VSeparator );
panel_hb->add_child(hs);
- EmptyControl *ec = memnew( EmptyControl );
- ec->set_minsize(Size2(200,1));
+ Control *ec = memnew( Control );
+ ec->set_custom_minimum_size(Size2(200,1));
panel_hb->add_child(ec);
search = memnew( LineEdit );
ec->add_child(search);
diff --git a/tools/editor/editor_import_export.cpp b/tools/editor/editor_import_export.cpp
index a511e78863..58f9afaa5d 100644
--- a/tools/editor/editor_import_export.cpp
+++ b/tools/editor/editor_import_export.cpp
@@ -292,7 +292,11 @@ Vector<StringName> EditorExportPlatform::get_dependencies(bool p_bundles) const
_add_filter_to_list(exported,"*");
} else {
_add_to_list(EditorFileSystem::get_singleton()->get_filesystem(),exported);
- _add_filter_to_list(exported,EditorImportExport::get_singleton()->get_export_custom_filter());
+ String cf = EditorImportExport::get_singleton()->get_export_custom_filter();
+ if (cf!="")
+ cf+=",";
+ cf+="*.flags";
+ _add_filter_to_list(exported,cf);
}
@@ -361,8 +365,12 @@ Vector<StringName> EditorExportPlatform::get_dependencies(bool p_bundles) const
}
}
}
+ String cf = EditorImportExport::get_singleton()->get_export_custom_filter();
+ if (cf!="")
+ cf+=",";
+ cf+="*.flags";
+ _add_filter_to_list(exported,cf);
- _add_filter_to_list(exported,EditorImportExport::get_singleton()->get_export_custom_filter());
}
diff --git a/tools/editor/editor_log.cpp b/tools/editor/editor_log.cpp
index f7f5f596d7..7c3fa6c1bd 100644
--- a/tools/editor/editor_log.cpp
+++ b/tools/editor/editor_log.cpp
@@ -203,9 +203,9 @@ EditorLog::EditorLog() {
tb->connect("pressed",this,"_close_request");
- ec = memnew( EmptyControl);
+ ec = memnew( Control);
vb->add_child(ec);
- ec->set_minsize(Size2(0,100));
+ ec->set_custom_minimum_size(Size2(0,100));
ec->set_v_size_flags(SIZE_EXPAND_FILL);
diff --git a/tools/editor/editor_log.h b/tools/editor/editor_log.h
index b6cd951287..27cce4a584 100644
--- a/tools/editor/editor_log.h
+++ b/tools/editor/editor_log.h
@@ -33,7 +33,7 @@
#include "scene/gui/label.h"
#include "scene/gui/rich_text_label.h"
#include "scene/gui/texture_button.h"
-#include "scene/gui/empty_control.h"
+//#include "scene/gui/empty_control.h"
#include "scene/gui/box_container.h"
#include "scene/gui/panel_container.h"
#include "scene/gui/texture_frame.h"
@@ -50,7 +50,7 @@ class EditorLog : public PanelContainer {
TextureButton *tb;
HBoxContainer *title_hb;
// PaneDrag *pd;
- EmptyControl *ec;
+ Control *ec;
static void _error_handler(void *p_self, const char*p_func, const char*p_file,int p_line, const char*p_error,const char*p_errorexp,ErrorHandlerType p_type);
diff --git a/tools/editor/editor_node.cpp b/tools/editor/editor_node.cpp
index 2927e7c870..52c75c6d7e 100644
--- a/tools/editor/editor_node.cpp
+++ b/tools/editor/editor_node.cpp
@@ -75,6 +75,7 @@
#include "plugins/tile_map_editor_plugin.h"
#include "plugins/cube_grid_theme_editor_plugin.h"
#include "plugins/shader_editor_plugin.h"
+#include "plugins/shader_graph_editor_plugin.h"
#include "plugins/path_editor_plugin.h"
#include "plugins/rich_text_editor_plugin.h"
#include "plugins/collision_polygon_editor_plugin.h"
@@ -977,6 +978,15 @@ void EditorNode::_dialog_action(String p_file) {
}
} break;
+
+ case FILE_SAVE_AND_RUN: {
+ if (file->get_mode()==FileDialog::MODE_SAVE_FILE) {
+
+ _save_scene(p_file);
+ _run(false);
+ }
+ } break;
+
case FILE_EXPORT_MESH_LIBRARY: {
Ref<MeshLibrary> ml;
@@ -1390,13 +1400,10 @@ void EditorNode::_run(bool p_current,const String& p_custom) {
}
if (scene->get_filename()=="") {
-
-
current_option=-1;
//accept->get_cancel()->hide();
- accept->get_ok()->set_text("I see..");
- accept->set_text("Scene has never been saved. Save before running!");
- accept->popup_centered(Size2(300,70));;
+ /**/
+ _menu_option_confirm(FILE_SAVE_BEFORE_RUN, false);
return;
}
@@ -1663,6 +1670,18 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) {
} break;
+ case FILE_SAVE_BEFORE_RUN: {
+ if (!p_confirmed) {
+ accept->get_ok()->set_text("Yes");
+ accept->set_text("This scene has never been saved. Save before running?");
+ accept->popup_centered(Size2(300, 70));
+ break;
+ }
+
+ _menu_option(FILE_SAVE_AS_SCENE);
+ _menu_option_confirm(FILE_SAVE_AND_RUN, true);
+ } break;
+
case FILE_DUMP_STRINGS: {
Node *scene = edited_scene;
@@ -3245,7 +3264,7 @@ EditorNode::EditorNode() {
gui_base->set_area_as_parent_rect();
- Ref<Theme> theme( memnew( Theme ) );
+ theme = Ref<Theme>( memnew( Theme ) );
gui_base->set_theme( theme );
editor_register_icons(theme);
editor_register_fonts(theme);
@@ -3308,13 +3327,13 @@ EditorNode::EditorNode() {
main_editor_tabs->connect("tab_changed",this,"_editor_select");
HBoxContainer *srth = memnew( HBoxContainer );
srt->add_child( srth );
- EmptyControl *tec = memnew( EmptyControl );
- tec->set_minsize(Size2(100,0));
+ Control *tec = memnew( Control );
+ tec->set_custom_minimum_size(Size2(100,0));
tec->set_h_size_flags(Control::SIZE_EXPAND_FILL);
srth->add_child(tec);
srth->add_child(main_editor_tabs);
- tec = memnew( EmptyControl );
- tec->set_minsize(Size2(100,0));
+ tec = memnew( Control );
+ tec->set_custom_minimum_size(Size2(100,0));
srth->add_child(tec);
tec->set_h_size_flags(Control::SIZE_EXPAND_FILL);
@@ -3422,7 +3441,7 @@ EditorNode::EditorNode() {
p->add_item("New Scene",FILE_NEW_SCENE);
p->add_item("Open Scene..",FILE_OPEN_SCENE,KEY_MASK_CMD+KEY_O);
p->add_item("Save Scene",FILE_SAVE_SCENE,KEY_MASK_CMD+KEY_S);
- p->add_item("Save Scene As..",FILE_SAVE_AS_SCENE);
+ p->add_item("Save Scene As..",FILE_SAVE_AS_SCENE,KEY_MASK_SHIFT+KEY_MASK_CMD+KEY_S);
p->add_separator();
p->add_item("Goto Prev. Scene",FILE_OPEN_PREV,KEY_MASK_SHIFT+KEY_MASK_CMD+KEY_P);
p->add_submenu_item("Open Recent","RecentScenes",FILE_OPEN_RECENT);
@@ -3674,8 +3693,8 @@ EditorNode::EditorNode() {
top_pallete->add_child(resources_dock);
top_pallete->set_v_size_flags(Control::SIZE_EXPAND_FILL);
- EmptyControl *editor_spacer = memnew( EmptyControl );
- editor_spacer->set_minsize(Size2(260,200));
+ Control *editor_spacer = memnew( Control );
+ editor_spacer->set_custom_minimum_size(Size2(260,200));
editor_spacer->set_v_size_flags(Control::SIZE_EXPAND_FILL);
editor_vsplit->add_child( editor_spacer );
editor_spacer->add_child( top_pallete );
@@ -3686,8 +3705,8 @@ EditorNode::EditorNode() {
prop_pallete->set_v_size_flags(Control::SIZE_EXPAND_FILL);
- editor_spacer = memnew( EmptyControl );
- editor_spacer->set_minsize(Size2(260,200));
+ editor_spacer = memnew( Control );
+ editor_spacer->set_custom_minimum_size(Size2(260,200));
editor_spacer->set_v_size_flags(Control::SIZE_EXPAND_FILL);
editor_vsplit->add_child( editor_spacer );
editor_spacer->add_child( prop_pallete );
@@ -4016,6 +4035,7 @@ EditorNode::EditorNode() {
add_editor_plugin( memnew( ScriptEditorPlugin(this) ) );
add_editor_plugin( memnew( EditorHelpPlugin(this) ) );
add_editor_plugin( memnew( AnimationPlayerEditorPlugin(this) ) );
+ add_editor_plugin( memnew( ShaderGraphEditorPlugin(this) ) );
add_editor_plugin( memnew( ShaderEditorPlugin(this) ) );
add_editor_plugin( memnew( CameraEditorPlugin(this) ) );
add_editor_plugin( memnew( SampleEditorPlugin(this) ) );
diff --git a/tools/editor/editor_node.h b/tools/editor/editor_node.h
index 7b66a7809e..7560c2b149 100644
--- a/tools/editor/editor_node.h
+++ b/tools/editor/editor_node.h
@@ -108,6 +108,8 @@ class EditorNode : public Node {
FILE_OPEN_SCENE,
FILE_SAVE_SCENE,
FILE_SAVE_AS_SCENE,
+ FILE_SAVE_BEFORE_RUN,
+ FILE_SAVE_AND_RUN,
FILE_IMPORT_SUBSCENE,
FILE_EXPORT_PROJECT,
FILE_EXPORT_MESH_LIBRARY,
@@ -212,6 +214,7 @@ class EditorNode : public Node {
AcceptDialog *load_error_dialog;
Control *scene_root_base;
+ Ref<Theme> theme;
PopupMenu *recent_scenes;
Button *property_back;
@@ -472,6 +475,9 @@ public:
void stop_child_process();
+ Ref<Theme> get_editor_theme() const { return theme; }
+
+
Error export_platform(const String& p_platform, const String& p_path, bool p_debug,const String& p_password,bool p_quit_after=false);
static void register_editor_types();
diff --git a/tools/editor/editor_settings.cpp b/tools/editor/editor_settings.cpp
index 8b4d899437..bc800d7e9e 100644
--- a/tools/editor/editor_settings.cpp
+++ b/tools/editor/editor_settings.cpp
@@ -403,6 +403,7 @@ void EditorSettings::_load_defaults() {
set("text_editor/string_color",Color::html("ef6ebe"));
set("text_editor/symbol_color",Color::html("badfff"));
set("text_editor/selection_color",Color::html("7b5dbe"));
+ set("text_editor/brace_mismatch_color",Color(1,0.2,0.2));
set("text_editor/idle_parse_delay",2);
set("text_editor/create_signal_callbacks",true);
@@ -418,6 +419,8 @@ void EditorSettings::_load_defaults() {
set("3d_editor/navigation_scheme",0);
hints["3d_editor/navigation_scheme"]=PropertyInfo(Variant::INT,"3d_editor/navigation_scheme",PROPERTY_HINT_ENUM,"Godot,Maya,Modo");
+ set("3d_editor/zoom_style",0);
+ hints["3d_editor/zoom_style"]=PropertyInfo(Variant::INT,"3d_editor/zoom_style",PROPERTY_HINT_ENUM,"Vertical, Horizontal");
set("3d_editor/orbit_modifier",0);
hints["3d_editor/orbit_modifier"]=PropertyInfo(Variant::INT,"3d_editor/orbit_modifier",PROPERTY_HINT_ENUM,"None,Shift,Alt,Meta,Ctrl");
set("3d_editor/pan_modifier",1);
@@ -443,6 +446,7 @@ void EditorSettings::_load_defaults() {
set("animation/confirm_insert_track",true);
set("property_editor/texture_preview_width",48);
+ set("property_editor/auto_refresh_interval",0.3);
set("help/doc_path","");
set("import/ask_save_before_reimport",false);
diff --git a/tools/editor/icons/icon_canvas_item_shader.png b/tools/editor/icons/icon_canvas_item_shader.png
new file mode 100644
index 0000000000..a5f4e7bf85
--- /dev/null
+++ b/tools/editor/icons/icon_canvas_item_shader.png
Binary files differ
diff --git a/tools/editor/icons/icon_canvas_item_shader_graph.png b/tools/editor/icons/icon_canvas_item_shader_graph.png
new file mode 100644
index 0000000000..bba966b43e
--- /dev/null
+++ b/tools/editor/icons/icon_canvas_item_shader_graph.png
Binary files differ
diff --git a/tools/editor/icons/icon_graph_comment.png b/tools/editor/icons/icon_graph_comment.png
new file mode 100644
index 0000000000..bf7889c510
--- /dev/null
+++ b/tools/editor/icons/icon_graph_comment.png
Binary files differ
diff --git a/tools/editor/icons/icon_graph_cube_uniform.png b/tools/editor/icons/icon_graph_cube_uniform.png
new file mode 100644
index 0000000000..d1b92b4943
--- /dev/null
+++ b/tools/editor/icons/icon_graph_cube_uniform.png
Binary files differ
diff --git a/tools/editor/icons/icon_graph_input.png b/tools/editor/icons/icon_graph_input.png
new file mode 100644
index 0000000000..a396bc2350
--- /dev/null
+++ b/tools/editor/icons/icon_graph_input.png
Binary files differ
diff --git a/tools/editor/icons/icon_graph_rgb.png b/tools/editor/icons/icon_graph_rgb.png
new file mode 100644
index 0000000000..abffaedd34
--- /dev/null
+++ b/tools/editor/icons/icon_graph_rgb.png
Binary files differ
diff --git a/tools/editor/icons/icon_graph_rgb_op.png b/tools/editor/icons/icon_graph_rgb_op.png
new file mode 100644
index 0000000000..642fc838c2
--- /dev/null
+++ b/tools/editor/icons/icon_graph_rgb_op.png
Binary files differ
diff --git a/tools/editor/icons/icon_graph_rgb_uniform.png b/tools/editor/icons/icon_graph_rgb_uniform.png
new file mode 100644
index 0000000000..92c79997ef
--- /dev/null
+++ b/tools/editor/icons/icon_graph_rgb_uniform.png
Binary files differ
diff --git a/tools/editor/icons/icon_graph_scalar.png b/tools/editor/icons/icon_graph_scalar.png
new file mode 100644
index 0000000000..028d0e9ea4
--- /dev/null
+++ b/tools/editor/icons/icon_graph_scalar.png
Binary files differ
diff --git a/tools/editor/icons/icon_graph_scalar_interp.png b/tools/editor/icons/icon_graph_scalar_interp.png
new file mode 100644
index 0000000000..4f178a27c4
--- /dev/null
+++ b/tools/editor/icons/icon_graph_scalar_interp.png
Binary files differ
diff --git a/tools/editor/icons/icon_graph_scalar_op.png b/tools/editor/icons/icon_graph_scalar_op.png
new file mode 100644
index 0000000000..0fc4cae94c
--- /dev/null
+++ b/tools/editor/icons/icon_graph_scalar_op.png
Binary files differ
diff --git a/tools/editor/icons/icon_graph_scalar_uniform.png b/tools/editor/icons/icon_graph_scalar_uniform.png
new file mode 100644
index 0000000000..fc6590a8cf
--- /dev/null
+++ b/tools/editor/icons/icon_graph_scalar_uniform.png
Binary files differ
diff --git a/tools/editor/icons/icon_graph_scalars_to_vec.png b/tools/editor/icons/icon_graph_scalars_to_vec.png
new file mode 100644
index 0000000000..7ca39a2f56
--- /dev/null
+++ b/tools/editor/icons/icon_graph_scalars_to_vec.png
Binary files differ
diff --git a/tools/editor/icons/icon_graph_texscreen.png b/tools/editor/icons/icon_graph_texscreen.png
new file mode 100644
index 0000000000..e183a8fa56
--- /dev/null
+++ b/tools/editor/icons/icon_graph_texscreen.png
Binary files differ
diff --git a/tools/editor/icons/icon_graph_texture_uniform.png b/tools/editor/icons/icon_graph_texture_uniform.png
new file mode 100644
index 0000000000..7517ac1d92
--- /dev/null
+++ b/tools/editor/icons/icon_graph_texture_uniform.png
Binary files differ
diff --git a/tools/editor/icons/icon_graph_time.png b/tools/editor/icons/icon_graph_time.png
new file mode 100644
index 0000000000..b61e45589f
--- /dev/null
+++ b/tools/editor/icons/icon_graph_time.png
Binary files differ
diff --git a/tools/editor/icons/icon_graph_vec_dp.png b/tools/editor/icons/icon_graph_vec_dp.png
new file mode 100644
index 0000000000..059c3025e7
--- /dev/null
+++ b/tools/editor/icons/icon_graph_vec_dp.png
Binary files differ
diff --git a/tools/editor/icons/icon_graph_vec_interp.png b/tools/editor/icons/icon_graph_vec_interp.png
new file mode 100644
index 0000000000..daf7a00203
--- /dev/null
+++ b/tools/editor/icons/icon_graph_vec_interp.png
Binary files differ
diff --git a/tools/editor/icons/icon_graph_vec_length.png b/tools/editor/icons/icon_graph_vec_length.png
new file mode 100644
index 0000000000..60ade8c90a
--- /dev/null
+++ b/tools/editor/icons/icon_graph_vec_length.png
Binary files differ
diff --git a/tools/editor/icons/icon_graph_vec_op.png b/tools/editor/icons/icon_graph_vec_op.png
new file mode 100644
index 0000000000..f2a7a51123
--- /dev/null
+++ b/tools/editor/icons/icon_graph_vec_op.png
Binary files differ
diff --git a/tools/editor/icons/icon_graph_vec_scalar_op.png b/tools/editor/icons/icon_graph_vec_scalar_op.png
new file mode 100644
index 0000000000..f0f4e7a196
--- /dev/null
+++ b/tools/editor/icons/icon_graph_vec_scalar_op.png
Binary files differ
diff --git a/tools/editor/icons/icon_graph_vec_to_scalars.png b/tools/editor/icons/icon_graph_vec_to_scalars.png
new file mode 100644
index 0000000000..a677a7cc53
--- /dev/null
+++ b/tools/editor/icons/icon_graph_vec_to_scalars.png
Binary files differ
diff --git a/tools/editor/icons/icon_graph_vecs_to_xform.png b/tools/editor/icons/icon_graph_vecs_to_xform.png
new file mode 100644
index 0000000000..51216c93eb
--- /dev/null
+++ b/tools/editor/icons/icon_graph_vecs_to_xform.png
Binary files differ
diff --git a/tools/editor/icons/icon_graph_vector.png b/tools/editor/icons/icon_graph_vector.png
new file mode 100644
index 0000000000..9dfe47d757
--- /dev/null
+++ b/tools/editor/icons/icon_graph_vector.png
Binary files differ
diff --git a/tools/editor/icons/icon_graph_vector_uniform.png b/tools/editor/icons/icon_graph_vector_uniform.png
new file mode 100644
index 0000000000..611539fca7
--- /dev/null
+++ b/tools/editor/icons/icon_graph_vector_uniform.png
Binary files differ
diff --git a/tools/editor/icons/icon_graph_xform.png b/tools/editor/icons/icon_graph_xform.png
new file mode 100644
index 0000000000..22df472be4
--- /dev/null
+++ b/tools/editor/icons/icon_graph_xform.png
Binary files differ
diff --git a/tools/editor/icons/icon_graph_xform_mult.png b/tools/editor/icons/icon_graph_xform_mult.png
new file mode 100644
index 0000000000..5d0ce7982d
--- /dev/null
+++ b/tools/editor/icons/icon_graph_xform_mult.png
Binary files differ
diff --git a/tools/editor/icons/icon_graph_xform_scalar_func.png b/tools/editor/icons/icon_graph_xform_scalar_func.png
new file mode 100644
index 0000000000..e53f08a564
--- /dev/null
+++ b/tools/editor/icons/icon_graph_xform_scalar_func.png
Binary files differ
diff --git a/tools/editor/icons/icon_graph_xform_to_vecs.png b/tools/editor/icons/icon_graph_xform_to_vecs.png
new file mode 100644
index 0000000000..847261f726
--- /dev/null
+++ b/tools/editor/icons/icon_graph_xform_to_vecs.png
Binary files differ
diff --git a/tools/editor/icons/icon_graph_xform_uniform.png b/tools/editor/icons/icon_graph_xform_uniform.png
new file mode 100644
index 0000000000..94c9759b25
--- /dev/null
+++ b/tools/editor/icons/icon_graph_xform_uniform.png
Binary files differ
diff --git a/tools/editor/icons/icon_graph_xform_vec_func.png b/tools/editor/icons/icon_graph_xform_vec_func.png
new file mode 100644
index 0000000000..f3ba528896
--- /dev/null
+++ b/tools/editor/icons/icon_graph_xform_vec_func.png
Binary files differ
diff --git a/tools/editor/icons/icon_graph_xform_vec_imult.png b/tools/editor/icons/icon_graph_xform_vec_imult.png
new file mode 100644
index 0000000000..7e7330cb8c
--- /dev/null
+++ b/tools/editor/icons/icon_graph_xform_vec_imult.png
Binary files differ
diff --git a/tools/editor/icons/icon_graph_xform_vec_mult.png b/tools/editor/icons/icon_graph_xform_vec_mult.png
new file mode 100644
index 0000000000..f80a28c80d
--- /dev/null
+++ b/tools/editor/icons/icon_graph_xform_vec_mult.png
Binary files differ
diff --git a/tools/editor/icons/icon_material_shader.png b/tools/editor/icons/icon_material_shader.png
new file mode 100644
index 0000000000..0e476b2540
--- /dev/null
+++ b/tools/editor/icons/icon_material_shader.png
Binary files differ
diff --git a/tools/editor/icons/icon_material_shader_graph.png b/tools/editor/icons/icon_material_shader_graph.png
new file mode 100644
index 0000000000..68d8b4cb49
--- /dev/null
+++ b/tools/editor/icons/icon_material_shader_graph.png
Binary files differ
diff --git a/tools/editor/plugins/animation_player_editor_plugin.cpp b/tools/editor/plugins/animation_player_editor_plugin.cpp
index 8bb37f1d71..f706d67f6d 100644
--- a/tools/editor/plugins/animation_player_editor_plugin.cpp
+++ b/tools/editor/plugins/animation_player_editor_plugin.cpp
@@ -76,6 +76,8 @@ void AnimationPlayerEditor::_notification(int p_what) {
seek->set_val(player->get_current_animation_pos());
if (edit_anim->is_pressed())
editor->get_animation_editor()->set_anim_pos(player->get_current_animation_pos());
+ EditorNode::get_singleton()->get_property_editor()->refresh();
+
} else if (last_active) {
//need the last frame after it stopped
@@ -854,6 +856,8 @@ void AnimationPlayerEditor::_animation_key_editor_seek(float p_pos) {
return;
seek->set_val(p_pos);
+ EditorNode::get_singleton()->get_property_editor()->refresh();
+
//seekit
diff --git a/tools/editor/plugins/canvas_item_editor_plugin.cpp b/tools/editor/plugins/canvas_item_editor_plugin.cpp
index 599160eb46..43ebebeb22 100644
--- a/tools/editor/plugins/canvas_item_editor_plugin.cpp
+++ b/tools/editor/plugins/canvas_item_editor_plugin.cpp
@@ -2307,7 +2307,7 @@ void CanvasItemEditor::_popup_callback(int p_op) {
} break;
case ANIM_INSERT_ROT: {
- key_pos = key_rot_button->is_pressed();
+ key_rot = key_rot_button->is_pressed();
} break;
case ANIM_INSERT_SCALE: {
@@ -2683,6 +2683,11 @@ void CanvasItemEditor::add_control_to_menu_panel(Control *p_control) {
hb->add_child(p_control);
}
+HSplitContainer *CanvasItemEditor::get_palette_split() {
+
+ return palette_split;
+}
+
CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) {
tool = TOOL_SELECT;
@@ -2697,15 +2702,20 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) {
add_child( hb );
hb->set_area_as_parent_rect();
+ palette_split = memnew( HSplitContainer);
+ palette_split->set_v_size_flags(SIZE_EXPAND_FILL);
+ add_child(palette_split);
+
Control *vp_base = memnew (Control);
- add_child(vp_base);
vp_base->set_v_size_flags(SIZE_EXPAND_FILL);
+ palette_split->add_child(vp_base);
Control *vp = memnew (Control);
vp_base->add_child(vp);
vp->set_area_as_parent_rect();
vp->add_child(p_editor->get_scene_root());
+
viewport = memnew( Control );
vp_base->add_child(viewport);
viewport->set_area_as_parent_rect();
@@ -2878,7 +2888,7 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) {
p->add_separator();
p->add_item("Copy Pose",ANIM_COPY_POSE);
p->add_item("Paste Pose",ANIM_PASTE_POSE);
- p->add_item("Clear Pose",ANIM_CLEAR_POSE,KEY_MASK_ALT|KEY_K);
+ p->add_item("Clear Pose",ANIM_CLEAR_POSE,KEY_MASK_SHIFT|KEY_K);
value_dialog = memnew( AcceptDialog );
value_dialog->set_title("Set a Value");
diff --git a/tools/editor/plugins/canvas_item_editor_plugin.h b/tools/editor/plugins/canvas_item_editor_plugin.h
index 15ac7b1bb3..c56570d43f 100644
--- a/tools/editor/plugins/canvas_item_editor_plugin.h
+++ b/tools/editor/plugins/canvas_item_editor_plugin.h
@@ -289,6 +289,10 @@ class CanvasItemEditor : public VBoxContainer {
void _viewport_input_event(const InputEvent& p_event);
void _viewport_draw();
+
+private:
+ HSplitContainer *palette_split;
+
friend class CanvasItemEditorPlugin;
protected:
@@ -341,6 +345,8 @@ public:
void add_control_to_menu_panel(Control *p_control);
+ HSplitContainer *get_palette_split();
+
Control *get_viewport_control() { return viewport; }
diff --git a/tools/editor/plugins/collision_polygon_2d_editor_plugin.cpp b/tools/editor/plugins/collision_polygon_2d_editor_plugin.cpp
index 6bae0d2fd0..ed228e9a1c 100644
--- a/tools/editor/plugins/collision_polygon_2d_editor_plugin.cpp
+++ b/tools/editor/plugins/collision_polygon_2d_editor_plugin.cpp
@@ -398,11 +398,13 @@ CollisionPolygon2DEditor::CollisionPolygon2DEditor(EditorNode *p_editor) {
add_child(button_create);
button_create->connect("pressed",this,"_menu_option",varray(MODE_CREATE));
button_create->set_toggle_mode(true);
+ button_create->set_tooltip("Create a new polygon from scratch");
button_edit = memnew( ToolButton );
add_child(button_edit);
button_edit->connect("pressed",this,"_menu_option",varray(MODE_EDIT));
button_edit->set_toggle_mode(true);
+ button_edit->set_tooltip("Edit existing polygon:\nLMB: Move Point.\nCtrl+LMB: Split Segment.\nRMB: Erase Point.");
//add_constant_override("separation",0);
diff --git a/tools/editor/plugins/collision_polygon_editor_plugin.cpp b/tools/editor/plugins/collision_polygon_editor_plugin.cpp
index 35f22aa6f8..b92acb60f9 100644
--- a/tools/editor/plugins/collision_polygon_editor_plugin.cpp
+++ b/tools/editor/plugins/collision_polygon_editor_plugin.cpp
@@ -120,6 +120,8 @@ void CollisionPolygonEditor::_wip_close() {
bool CollisionPolygonEditor::forward_spatial_input_event(Camera* p_camera,const InputEvent& p_event) {
+ if (!node)
+ return false;
Transform gt = node->get_global_transform();
float depth = node->get_depth()*0.5;
diff --git a/tools/editor/plugins/item_list_editor_plugin.cpp b/tools/editor/plugins/item_list_editor_plugin.cpp
index eb7ab69987..a8b34ef503 100644
--- a/tools/editor/plugins/item_list_editor_plugin.cpp
+++ b/tools/editor/plugins/item_list_editor_plugin.cpp
@@ -210,6 +210,7 @@ void ItemListEditor::_bind_methods() {
}
bool ItemListEditor::handles(Object *p_object) const {
+ return false;
for(int i=0;i<item_plugins.size();i++) {
if (item_plugins[i]->handles(p_object)) {
return true;
diff --git a/tools/editor/plugins/script_editor_plugin.cpp b/tools/editor/plugins/script_editor_plugin.cpp
index c5fb574c71..55957887dc 100644
--- a/tools/editor/plugins/script_editor_plugin.cpp
+++ b/tools/editor/plugins/script_editor_plugin.cpp
@@ -209,6 +209,7 @@ void ScriptTextEditor::_load_theme_settings() {
get_text_edit()->add_color_override("font_color",EDITOR_DEF("text_editor/text_color",Color(0,0,0)));
get_text_edit()->add_color_override("font_selected_color",EDITOR_DEF("text_editor/text_selected_color",Color(1,1,1)));
get_text_edit()->add_color_override("selection_color",EDITOR_DEF("text_editor/selection_color",Color(0.2,0.2,1)));
+ get_text_edit()->add_color_override("brace_mismatch_color",EDITOR_DEF("text_editor/brace_mismatch_color",Color(1,0.2,0.2)));
Color keyword_color= EDITOR_DEF("text_editor/keyword_color",Color(0.5,0.0,0.2));
@@ -384,9 +385,35 @@ void ScriptTextEditor::_validate_script() {
_update_name();
}
-void ScriptTextEditor::_code_complete_script(const String& p_code, const String& p_keyword,int p_line, List<String>* r_options) {
- Error err = script->get_language()->complete_keyword(p_code,p_line,script->get_path().get_base_dir(),p_keyword,r_options);
+static Node* _find_node_for_script(Node* p_base, Node*p_current, const Ref<Script>& p_script) {
+
+ if (p_current->get_owner()!=p_base && p_base!=p_current)
+ return NULL;
+ Ref<Script> c = p_current->get_script();
+ if (c==p_script)
+ return p_current;
+ for(int i=0;i<p_current->get_child_count();i++) {
+ Node *found = _find_node_for_script(p_base,p_current->get_child(i),p_script);
+ if (found)
+ return found;
+ }
+
+ return NULL;
+}
+
+void ScriptTextEditor::_code_complete_script(const String& p_code, List<String>* r_options) {
+
+ Node *base = get_tree()->get_edited_scene_root();
+ if (base) {
+ base = _find_node_for_script(base,base,script);
+ }
+ String hint;
+ Error err = script->get_language()->complete_code(p_code,script->get_path().get_base_dir(),base,r_options,hint);
+ if (hint!="") {
+ get_text_edit()->set_code_hint(hint);
+ print_line("hint: "+hint.replace(String::chr(0xFFFF),"|"));
+ }
}
@@ -1551,7 +1578,7 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) {
menu_hb->add_child(file_menu);
file_menu->set_text("File");
file_menu->get_popup()->add_item("Open",FILE_OPEN);
- file_menu->get_popup()->add_item("Save",FILE_SAVE,KEY_MASK_ALT|KEY_S);
+ file_menu->get_popup()->add_item("Save",FILE_SAVE,KEY_MASK_ALT|KEY_MASK_CMD|KEY_S);
file_menu->get_popup()->add_item("Save As..",FILE_SAVE_AS);
file_menu->get_popup()->add_item("Save All",FILE_SAVE_ALL,KEY_MASK_CMD|KEY_MASK_SHIFT|KEY_S);
file_menu->get_popup()->connect("item_pressed", this,"_menu_option");
@@ -1559,23 +1586,27 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) {
edit_menu = memnew( MenuButton );
menu_hb->add_child(edit_menu);
edit_menu->set_text("Edit");
- edit_menu->get_popup()->add_item("Undo",EDIT_UNDO,KEY_MASK_CMD|KEY_Z);
- edit_menu->get_popup()->add_item("Redo",EDIT_REDO,KEY_MASK_CMD|KEY_Y);
+ edit_menu->get_popup()->add_item("Undo",EDIT_UNDO,KEY_MASK_CMD|KEY_Z);
+ edit_menu->get_popup()->add_item("Redo",EDIT_REDO,KEY_MASK_CMD|KEY_Y);
edit_menu->get_popup()->add_separator();
edit_menu->get_popup()->add_item("Cut",EDIT_CUT,KEY_MASK_CMD|KEY_X);
edit_menu->get_popup()->add_item("Copy",EDIT_COPY,KEY_MASK_CMD|KEY_C);
edit_menu->get_popup()->add_item("Paste",EDIT_PASTE,KEY_MASK_CMD|KEY_V);
edit_menu->get_popup()->add_separator();
edit_menu->get_popup()->add_item("Select All",EDIT_SELECT_ALL,KEY_MASK_CMD|KEY_A);
- edit_menu->get_popup()->add_separator();
- edit_menu->get_popup()->add_item("Move Up",EDIT_MOVE_LINE_UP,KEY_MASK_ALT|KEY_UP);
- edit_menu->get_popup()->add_item("Move Down",EDIT_MOVE_LINE_DOWN,KEY_MASK_ALT|KEY_DOWN);
- edit_menu->get_popup()->add_item("Indent Left",EDIT_INDENT_LEFT,KEY_MASK_ALT|KEY_LEFT);
- edit_menu->get_popup()->add_item("Indent Right",EDIT_INDENT_RIGHT,KEY_MASK_ALT|KEY_RIGHT);
- edit_menu->get_popup()->add_item("Toggle Comment",EDIT_TOGGLE_COMMENT,KEY_MASK_CMD|KEY_SLASH);
- edit_menu->get_popup()->add_item("Clone Down",EDIT_CLONE_DOWN,KEY_MASK_CMD|KEY_B);
edit_menu->get_popup()->add_separator();
+ edit_menu->get_popup()->add_item("Move Up",EDIT_MOVE_LINE_UP,KEY_MASK_ALT|KEY_UP);
+ edit_menu->get_popup()->add_item("Move Down",EDIT_MOVE_LINE_DOWN,KEY_MASK_ALT|KEY_DOWN);
+ edit_menu->get_popup()->add_item("Indent Left",EDIT_INDENT_LEFT,KEY_MASK_ALT|KEY_LEFT);
+ edit_menu->get_popup()->add_item("Indent Right",EDIT_INDENT_RIGHT,KEY_MASK_ALT|KEY_RIGHT);
+ edit_menu->get_popup()->add_item("Toggle Comment",EDIT_TOGGLE_COMMENT,KEY_MASK_CMD|KEY_K);
+ edit_menu->get_popup()->add_item("Clone Down",EDIT_CLONE_DOWN,KEY_MASK_CMD|KEY_B);
+ edit_menu->get_popup()->add_separator();
+#ifdef OSX_ENABLED
+ edit_menu->get_popup()->add_item("Complete Symbol",EDIT_COMPLETE,KEY_MASK_META|KEY_SPACE);
+#else
edit_menu->get_popup()->add_item("Complete Symbol",EDIT_COMPLETE,KEY_MASK_CMD|KEY_SPACE);
+#endif
edit_menu->get_popup()->add_item("Auto Indent",EDIT_AUTO_INDENT,KEY_MASK_CMD|KEY_I);
edit_menu->get_popup()->connect("item_pressed", this,"_menu_option");
diff --git a/tools/editor/plugins/script_editor_plugin.h b/tools/editor/plugins/script_editor_plugin.h
index 01942fab2a..136d966587 100644
--- a/tools/editor/plugins/script_editor_plugin.h
+++ b/tools/editor/plugins/script_editor_plugin.h
@@ -85,7 +85,7 @@ protected:
virtual void _validate_script();
- virtual void _code_complete_script(const String& p_code,const String& p_keyword, int p_line, List<String>* r_options);
+ virtual void _code_complete_script(const String& p_code, List<String>* r_options);
virtual void _load_theme_settings();
void _notification(int p_what);
diff --git a/tools/editor/plugins/shader_editor_plugin.cpp b/tools/editor/plugins/shader_editor_plugin.cpp
index a6172ee098..3166383fc8 100644
--- a/tools/editor/plugins/shader_editor_plugin.cpp
+++ b/tools/editor/plugins/shader_editor_plugin.cpp
@@ -80,6 +80,7 @@ void ShaderTextEditor::_load_theme_settings() {
get_text_edit()->add_color_override("font_color",EDITOR_DEF("text_editor/text_color",Color(0,0,0)));
get_text_edit()->add_color_override("font_selected_color",EDITOR_DEF("text_editor/text_selected_color",Color(1,1,1)));
get_text_edit()->add_color_override("selection_color",EDITOR_DEF("text_editor/selection_color",Color(0.2,0.2,1)));
+ get_text_edit()->add_color_override("brace_mismatch_color",EDITOR_DEF("text_editor/brace_mismatch_color",Color(1,0.2,0.2)));
Color keyword_color= EDITOR_DEF("text_editor/keyword_color",Color(0.5,0.0,0.2));
diff --git a/tools/editor/plugins/shader_graph_editor_plugin.cpp b/tools/editor/plugins/shader_graph_editor_plugin.cpp
index 2686ca895e..0a206c4a45 100644
--- a/tools/editor/plugins/shader_graph_editor_plugin.cpp
+++ b/tools/editor/plugins/shader_graph_editor_plugin.cpp
@@ -28,1082 +28,1518 @@
/*************************************************************************/
#include "shader_graph_editor_plugin.h"
-#if 0
+
#include "scene/gui/menu_button.h"
#include "scene/gui/panel.h"
+#include "spatial_editor_plugin.h"
+
+////cbacks
+///
+void ShaderGraphView::_scalar_const_changed(double p_value,int p_id) {
+
+ UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo();
+ ur->create_action("Change Scalar Constant",true);
+ ur->add_do_method(graph.ptr(),"scalar_const_node_set_value",type,p_id,p_value);
+ ur->add_undo_method(graph.ptr(),"scalar_const_node_set_value",type,p_id,graph->scalar_const_node_get_value(type,p_id));
+ ur->add_do_method(this,"_update_graph");
+ ur->add_undo_method(this,"_update_graph");
+ block_update=true;
+ ur->commit_action();
+ block_update=false;
+}
-class _ShaderTester : public ShaderCodeGenerator {
-public:
+void ShaderGraphView::_vec_const_changed(double p_value, int p_id,Array p_arr){
- Set<int> *_set;
+ Vector3 val;
+ for(int i=0;i<p_arr.size();i++) {
+ val[i]=p_arr[i].call("get_val");
+ }
- virtual void begin() {}
- virtual Error add_node(VS::ShaderNodeType p_type,int p_node_pos,int p_id,const Variant& p_param,const Vector<int>& p_in_connections,const Vector<int>& p_out_connections,const Vector<int>& p_out_connection_outputs) { if (_set) _set->insert(p_id); return OK; }
- virtual void end() {}
+ UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo();
+ ur->create_action("Change Vec Constant",true);
+ ur->add_do_method(graph.ptr(),"vec_const_node_set_value",type,p_id,val);
+ ur->add_undo_method(graph.ptr(),"vec_const_node_set_value",type,p_id,graph->vec_const_node_get_value(type,p_id));
+ ur->add_do_method(this,"_update_graph");
+ ur->add_undo_method(this,"_update_graph");
+ block_update=true;
+ ur->commit_action();
+ block_update=false;
- _ShaderTester() { _set=NULL; }
-};
+}
+void ShaderGraphView::_rgb_const_changed(const Color& p_color, int p_id){
+
+ UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo();
+ ur->create_action("Change RGB Constant",true);
+ ur->add_do_method(graph.ptr(),"rgb_const_node_set_value",type,p_id,p_color);
+ ur->add_undo_method(graph.ptr(),"rgb_const_node_set_value",type,p_id,graph->rgb_const_node_get_value(type,p_id));
+ ur->add_do_method(this,"_update_graph");
+ ur->add_undo_method(this,"_update_graph");
+ block_update=true;
+ ur->commit_action();
+ block_update=false;
+}
+void ShaderGraphView::_scalar_op_changed(int p_op, int p_id){
+
+ UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo();
+ ur->create_action("Change Scalar Operator");
+ ur->add_do_method(graph.ptr(),"scalar_op_node_set_op",type,p_id,p_op);
+ ur->add_undo_method(graph.ptr(),"scalar_op_node_set_op",type,p_id,graph->scalar_op_node_get_op(type,p_id));
+ ur->add_do_method(this,"_update_graph");
+ ur->add_undo_method(this,"_update_graph");
+ block_update=true;
+ ur->commit_action();
+ block_update=false;
+}
+void ShaderGraphView::_vec_op_changed(int p_op, int p_id){
+
+ UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo();
+ ur->create_action("Change Vec Operator");
+ ur->add_do_method(graph.ptr(),"vec_op_node_set_op",type,p_id,p_op);
+ ur->add_undo_method(graph.ptr(),"vec_op_node_set_op",type,p_id,graph->vec_op_node_get_op(type,p_id));
+ ur->add_do_method(this,"_update_graph");
+ ur->add_undo_method(this,"_update_graph");
+ block_update=true;
+ ur->commit_action();
+ block_update=false;
+}
+void ShaderGraphView::_vec_scalar_op_changed(int p_op, int p_id){
+
+ UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo();
+ ur->create_action("Change VecxScalar Operator");
+ ur->add_do_method(graph.ptr(),"vec_scalar_op_node_set_op",type,p_id,p_op);
+ ur->add_undo_method(graph.ptr(),"vec_scalar_op_node_set_op",type,p_id,graph->vec_scalar_op_node_get_op(type,p_id));
+ ur->add_do_method(this,"_update_graph");
+ ur->add_undo_method(this,"_update_graph");
+ block_update=true;
+ ur->commit_action();
+ block_update=false;
-void ShaderEditor::edit(Ref<Shader> p_shader) {
+}
+void ShaderGraphView::_rgb_op_changed(int p_op, int p_id){
+
+ UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo();
+ ur->create_action("Change RGB Operator");
+ ur->add_do_method(graph.ptr(),"rgb_op_node_set_op",type,p_id,p_op);
+ ur->add_undo_method(graph.ptr(),"rgb_op_node_set_op",type,p_id,graph->rgb_op_node_get_op(type,p_id));
+ ur->add_do_method(this,"_update_graph");
+ ur->add_undo_method(this,"_update_graph");
+ block_update=true;
+ ur->commit_action();
+ block_update=false;
+}
+void ShaderGraphView::_xform_inv_rev_changed(bool p_enabled, int p_id){
+
+ UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo();
+ ur->create_action("Toggle Rot Only");
+ ur->add_do_method(graph.ptr(),"xform_vec_mult_node_set_no_translation",type,p_id,p_enabled);
+ ur->add_undo_method(graph.ptr(),"xform_vec_mult_node_set_no_translation",type,p_id,graph->xform_vec_mult_node_get_no_translation(type,p_id));
+ ur->add_do_method(this,"_update_graph");
+ ur->add_undo_method(this,"_update_graph");
+ block_update=true;
+ ur->commit_action();
+ block_update=false;
+}
+void ShaderGraphView::_scalar_func_changed(int p_func, int p_id){
+
+
+ UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo();
+ ur->create_action("Change Scalar Function");
+ ur->add_do_method(graph.ptr(),"scalar_func_node_set_function",type,p_id,p_func);
+ ur->add_undo_method(graph.ptr(),"scalar_func_node_set_function",type,p_id,graph->scalar_func_node_get_function(type,p_id));
+ ur->add_do_method(this,"_update_graph");
+ ur->add_undo_method(this,"_update_graph");
+ block_update=true;
+ ur->commit_action();
+ block_update=false;
+}
+void ShaderGraphView::_vec_func_changed(int p_func, int p_id){
+
+ UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo();
+ ur->create_action("Change Vec Function");
+ ur->add_do_method(graph.ptr(),"vec_func_node_set_function",type,p_id,p_func);
+ ur->add_undo_method(graph.ptr(),"vec_func_node_set_function",type,p_id,graph->vec_func_node_get_function(type,p_id));
+ ur->add_do_method(this,"_update_graph");
+ ur->add_undo_method(this,"_update_graph");
+ block_update=true;
+ ur->commit_action();
+ block_update=false;
+}
+void ShaderGraphView::_scalar_input_changed(double p_value,int p_id){
+
+ UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo();
+ ur->create_action("Change Scalar Uniform",true);
+ ur->add_do_method(graph.ptr(),"scalar_input_node_set_value",type,p_id,p_value);
+ ur->add_undo_method(graph.ptr(),"scalar_input_node_set_value",type,p_id,graph->scalar_input_node_get_value(type,p_id));
+ ur->add_do_method(this,"_update_graph");
+ ur->add_undo_method(this,"_update_graph");
+ block_update=true;
+ ur->commit_action();
+ block_update=false;
- shader=p_shader;
+}
+void ShaderGraphView::_vec_input_changed(double p_value, int p_id,Array p_arr){
- if (shader.is_null())
- hide();
- else {
- _read_shader_graph();
+ Vector3 val;
+ for(int i=0;i<p_arr.size();i++) {
+ val[i]=p_arr[i].call("get_val");
}
+ UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo();
+ ur->create_action("Change Vec Uniform",true);
+ ur->add_do_method(graph.ptr(),"vec_input_node_set_value",type,p_id,val);
+ ur->add_undo_method(graph.ptr(),"vec_input_node_set_value",type,p_id,graph->vec_input_node_get_value(type,p_id));
+ ur->add_do_method(this,"_update_graph");
+ ur->add_undo_method(this,"_update_graph");
+ block_update=true;
+ ur->commit_action();
+ block_update=false;
+
}
+void ShaderGraphView::_xform_input_changed(int p_id, Node *p_button){
-Size2 ShaderEditor::_get_maximum_size() {
- Size2 max;
+ ToolButton *tb = p_button->cast_to<ToolButton>();
+ ped_popup->set_pos(tb->get_global_pos()+Vector2(0,tb->get_size().height));
+ ped_popup->set_size(tb->get_size());
+ edited_id=p_id;
+ ped_popup->edit(NULL,"",Variant::TRANSFORM,graph->xform_input_node_get_value(type,p_id),PROPERTY_HINT_NONE,"");
+ ped_popup->popup();
- for(List<int>::Element *E=order.front();E;E=E->next()) {
+}
+void ShaderGraphView::_xform_const_changed(int p_id, Node *p_button){
- Point2 pos = Point2( shader_graph.node_get_pos_x(E->get()), shader_graph.node_get_pos_y(E->get()) );
+ ToolButton *tb = p_button->cast_to<ToolButton>();
+ ped_popup->set_pos(tb->get_global_pos()+Vector2(0,tb->get_size().height));
+ ped_popup->set_size(tb->get_size());
+ edited_id=p_id;
+ ped_popup->edit(NULL,"",Variant::TRANSFORM,graph->xform_const_node_get_value(type,p_id),PROPERTY_HINT_NONE,"");
+ ped_popup->popup();
- if (click_type==CLICK_NODE && click_node==E->get()) {
+}
- pos+=click_motion-click_pos;
- }
- pos+=get_node_size(E->get());
- if (pos.x>max.x)
- max.x=pos.x;
- if (pos.y>max.y)
- max.y=pos.y;
+void ShaderGraphView::_rgb_input_changed(const Color& p_color, int p_id){
- }
- return max;
+ UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo();
+ ur->create_action("Change RGB Uniform",true);
+ ur->add_do_method(graph.ptr(),"rgb_input_node_set_value",type,p_id,p_color);
+ ur->add_undo_method(graph.ptr(),"rgb_input_node_set_value",type,p_id,graph->rgb_input_node_get_value(type,p_id));
+ ur->add_do_method(this,"_update_graph");
+ ur->add_undo_method(this,"_update_graph");
+ block_update=true;
+ ur->commit_action();
+ block_update=false;
}
+void ShaderGraphView::_tex_input_change(int p_id, Node *p_button){
-Size2 ShaderEditor::get_node_size(int p_node) const {
- VisualServer::ShaderNodeType type=shader_graph.node_get_type(p_node);
- Ref<StyleBox> style = get_stylebox("panel","PopupMenu");
- Ref<Font> font = get_font("font","PopupMenu");
- Color font_color = get_color("font_color","PopupMenu");
-
- Size2 size = style->get_minimum_size();
-
- int count=1; // title
- count += VisualServer::shader_get_input_count( type) + VisualServer::shader_get_output_count( type);
+}
+void ShaderGraphView::_cube_input_change(int p_id){
- float max_w=font->get_string_size( VisualServer::shader_node_get_type_info(type).name ).width;
- for(int i=0;i<VisualServer::shader_get_input_count(type);i++)
- max_w = MAX( max_w, font->get_string_size( VisualServer::shader_get_input_name(type,i) ).width );
+}
+void ShaderGraphView::_variant_edited() {
- for(int i=0;i<VisualServer::shader_get_output_count(type);i++)
- max_w = MAX( max_w, font->get_string_size( VisualServer::shader_get_output_name(type,i) ).width );
+ if (graph->node_get_type(type,edited_id)==ShaderGraph::NODE_XFORM_CONST) {
+ UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo();
+ ur->create_action("Change XForm Uniform");
+ ur->add_do_method(graph.ptr(),"xform_const_node_set_value",type,edited_id,ped_popup->get_variant());
+ ur->add_undo_method(graph.ptr(),"xform_const_node_set_value",type,edited_id,graph->xform_const_node_get_value(type,edited_id));
+ ur->add_do_method(this,"_update_graph");
+ ur->add_undo_method(this,"_update_graph");
+ ur->commit_action();
+ }
+ if (graph->node_get_type(type,edited_id)==ShaderGraph::NODE_XFORM_INPUT) {
- switch(type) {
+ UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo();
+ ur->create_action("Change XForm Uniform");
+ ur->add_do_method(graph.ptr(),"xform_input_node_set_value",type,edited_id,ped_popup->get_variant());
+ ur->add_undo_method(graph.ptr(),"xform_input_node_set_value",type,edited_id,graph->xform_input_node_get_value(type,edited_id));
+ ur->add_do_method(this,"_update_graph");
+ ur->add_undo_method(this,"_update_graph");
+ ur->commit_action();
+ }
- case VS::NODE_IN:
- case VS::NODE_OUT:
- case VS::NODE_VEC_IN:
- case VS::NODE_VEC_OUT:
- case VS::NODE_PARAMETER:
- case VS::NODE_VEC_PARAMETER:
- case VS::NODE_COLOR_PARAMETER:
- case VS::NODE_TEXTURE_PARAMETER:
- case VS::NODE_TEXTURE_2D_PARAMETER:
- case VS::NODE_TEXTURE_CUBE_PARAMETER:
- case VS::NODE_TRANSFORM_PARAMETER:
- case VS::NODE_LABEL: {
+ if (graph->node_get_type(type,edited_id)==ShaderGraph::NODE_TEXTURE_INPUT) {
- max_w=MAX( max_w, font->get_string_size( shader_graph.node_get_param(p_node) ).width );
- count++;
- } break;
- case VS::NODE_TIME:
- case VS::NODE_CONSTANT:
- case VS::NODE_VEC_CONSTANT:
- case VS::NODE_COLOR_CONSTANT:
- case VS::NODE_TRANSFORM_CONSTANT: {
- count++;
- } break;
- case VS::NODE_TEXTURE:
- case VS::NODE_VEC_TEXTURE_2D:
- case VS::NODE_VEC_TEXTURE_CUBE: {
+ UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo();
+ ur->create_action("Change Texture Uniform");
+ ur->add_do_method(graph.ptr(),"texture_input_node_set_value",type,edited_id,ped_popup->get_variant());
+ ur->add_undo_method(graph.ptr(),"texture_input_node_set_value",type,edited_id,graph->texture_input_node_get_value(type,edited_id));
+ ur->add_do_method(this,"_update_graph");
+ ur->add_undo_method(this,"_update_graph");
+ ur->commit_action();
+ }
- RefPtr res = shader_graph.node_get_param(p_node);
- Ref<Texture> texture = res;
- if (texture.is_null() || texture->get_width()==0) {
+ if (graph->node_get_type(type,edited_id)==ShaderGraph::NODE_CUBEMAP_INPUT) {
- size.y+=max_w;
- } else {
+ UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo();
+ ur->create_action("Change Cubemap Uniform");
+ ur->add_do_method(graph.ptr(),"cubemap_input_node_set_value",type,edited_id,ped_popup->get_variant());
+ ur->add_undo_method(graph.ptr(),"cubemap_input_node_set_value",type,edited_id,graph->cubemap_input_node_get_value(type,edited_id));
+ ur->add_do_method(this,"_update_graph");
+ ur->add_undo_method(this,"_update_graph");
+ ur->commit_action();
+ }
- size.y+=max_w * texture->get_height() / texture->get_width();
- }
- } break;
- default: {}
+}
- }
+void ShaderGraphView::_comment_edited(int p_id,Node* p_button) {
- size.x+=max_w;
- size.y+=count*(font->get_height()+get_constant("vseparation","PopupMenu"));
+ UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo();
+ TextEdit *te=p_button->cast_to<TextEdit>();
+ ur->create_action("Change Comment",true);
+ ur->add_do_method(graph.ptr(),"comment_node_set_text",type,p_id,te->get_text());
+ ur->add_undo_method(graph.ptr(),"comment_node_set_text",type,p_id,graph->comment_node_get_text(type,p_id));
+ ur->add_do_method(this,"_update_graph");
+ ur->add_undo_method(this,"_update_graph");
+ block_update=true;
+ ur->commit_action();
+ block_update=false;
- return size;
}
-Error ShaderEditor::validate_graph() {
+void ShaderGraphView::_input_name_changed(const String& p_name, int p_id, Node *p_line_edit) {
+
+ LineEdit *le=p_line_edit->cast_to<LineEdit>();
+ ERR_FAIL_COND(!le);
- _ShaderTester st;
- active_nodes.clear();
- st._set=&active_nodes;
- return shader_graph.generate(&st);
+ UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo();
+ ur->create_action("Change Input Name");
+ ur->add_do_method(graph.ptr(),"input_node_set_name",type,p_id,p_name);
+ ur->add_undo_method(graph.ptr(),"input_node_set_name",type,p_id,graph->input_node_get_name(type,p_id));
+ ur->add_do_method(this,"_update_graph");
+ ur->add_undo_method(this,"_update_graph");
+ block_update=true;
+ ur->commit_action();
+ block_update=false;
+ le->set_text(graph->input_node_get_name(type,p_id));
}
-void ShaderEditor::_draw_node(int p_node) {
+void ShaderGraphView::_tex_edited(int p_id,Node* p_button) {
- VisualServer::ShaderNodeType type=shader_graph.node_get_type(p_node);
- Ref<StyleBox> style = active_nodes.has(p_node)?get_stylebox("panel","PopupMenu"):get_stylebox("panel_disabled","PopupMenu");
- Ref<Font> font = get_font("font","PopupMenu");
- Color font_color = get_color("font_color","PopupMenu");
- Color font_color_title = get_color("font_color_hover","PopupMenu");
- Size2 size=get_node_size(p_node);
- Point2 pos = Point2( shader_graph.node_get_pos_x(p_node), shader_graph.node_get_pos_y(p_node) )-offset;
+ ToolButton *tb = p_button->cast_to<ToolButton>();
+ ped_popup->set_pos(tb->get_global_pos()+Vector2(0,tb->get_size().height));
+ ped_popup->set_size(tb->get_size());
+ edited_id=p_id;
+ ped_popup->edit(NULL,"",Variant::OBJECT,graph->texture_input_node_get_value(type,p_id),PROPERTY_HINT_RESOURCE_TYPE,"Texture");
+}
- if (click_type==CLICK_NODE && click_node==p_node) {
+void ShaderGraphView::_cube_edited(int p_id,Node* p_button) {
- pos+=click_motion-click_pos;
- }
+ ToolButton *tb = p_button->cast_to<ToolButton>();
+ ped_popup->set_pos(tb->get_global_pos()+Vector2(0,tb->get_size().height));
+ ped_popup->set_size(tb->get_size());
+ edited_id=p_id;
+ ped_popup->edit(NULL,"",Variant::OBJECT,graph->cubemap_input_node_get_value(type,p_id),PROPERTY_HINT_RESOURCE_TYPE,"CubeMap");
+}
- RID ci = get_canvas_item();
- style->draw(ci,Rect2(pos,size));
- Point2 ofs=style->get_offset()+pos;
- Point2 ascent=Point2(0,font->get_ascent());
- float w = size.width-style->get_minimum_size().width;
- float h = font->get_height()+get_constant("vseparation","PopupMenu");
+//////////////view/////////////
- font->draw_halign( ci, ofs+ascent, HALIGN_CENTER,w, VisualServer::shader_node_get_type_info(type).name,font_color_title);
- ofs.y+=h;
- Ref<Texture> vec_icon = get_icon("NodeVecSlot","EditorIcons");
- Ref<Texture> real_icon = get_icon("NodeRealSlot","EditorIcons");
- float icon_h_ofs = Math::floor(( font->get_height()-vec_icon->get_height())/2.0 )+1;
+void ShaderGraphView::_connection_request(const String& p_from, int p_from_slot,const String& p_to,int p_to_slot) {
+ UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo();
- for(int i=0;i<VisualServer::shader_get_input_count(type);i++) {
+ int from_idx=-1;
+ int to_idx=-1;
+ for (Map<int,GraphNode*>::Element *E=node_map.front();E;E=E->next()) {
- String name = VisualServer::shader_get_input_name(type,i);
- font->draw_halign( ci, ofs+ascent, HALIGN_LEFT,w, name,font_color);
- Ref<Texture> icon = VisualServer::shader_is_input_vector(type,i)?vec_icon:real_icon;
- icon->draw(ci,ofs+Point2(-real_icon->get_width(),icon_h_ofs));
- ofs.y+=h;
+ if (p_from==E->get()->get_name())
+ from_idx=E->key();
+ if (p_to==E->get()->get_name())
+ to_idx=E->key();
}
- for(int i=0;i<VisualServer::shader_get_output_count(type);i++) {
+ ERR_FAIL_COND(from_idx==-1);
+ ERR_FAIL_COND(to_idx==-1);
- String name = VisualServer::shader_get_output_name(type,i);
- font->draw_halign( ci, ofs+ascent, HALIGN_RIGHT,w, name,font_color);
- Ref<Texture> icon = VisualServer::shader_is_output_vector(type,i)?vec_icon:real_icon;
- icon->draw(ci,ofs+Point2(w,icon_h_ofs));
- ofs.y+=h;
- }
-
- switch(type) {
-
- case VS::NODE_IN:
- case VS::NODE_OUT:
- case VS::NODE_PARAMETER:
- case VS::NODE_VEC_IN:
- case VS::NODE_COLOR_PARAMETER:
- case VS::NODE_VEC_OUT:
- case VS::NODE_TEXTURE_PARAMETER:
- case VS::NODE_TEXTURE_2D_PARAMETER:
- case VS::NODE_TEXTURE_CUBE_PARAMETER:
- case VS::NODE_TRANSFORM_CONSTANT:
- case VS::NODE_TRANSFORM_PARAMETER:
- case VS::NODE_VEC_PARAMETER:
- case VS::NODE_LABEL: {
- String text = shader_graph.node_get_param(p_node);
- font->draw_halign( ci, ofs+ascent, HALIGN_CENTER,w, text,font_color);
- } break;
- case VS::NODE_TIME:
- case VS::NODE_CONSTANT: {
- String text = rtos(shader_graph.node_get_param(p_node));
- font->draw_halign( ci, ofs+ascent, HALIGN_CENTER,w, text,font_color);
+ ur->create_action("Connect Graph Nodes");
- } break;
- case VS::NODE_VEC_CONSTANT: {
- String text = Vector3(shader_graph.node_get_param(p_node));
- font->draw_halign( ci, ofs+ascent, HALIGN_CENTER,w, text,font_color);
- } break;
- case VS::NODE_COLOR_CONSTANT: {
+ List<ShaderGraph::Connection> conns;
- Color color = shader_graph.node_get_param(p_node);
- Rect2 r(ofs,Size2(w,h));
- VisualServer::get_singleton()->canvas_item_add_rect(ci,r,color);
- } break;
- case VS::NODE_TEXTURE:
- case VS::NODE_VEC_TEXTURE_2D:
- case VS::NODE_VEC_TEXTURE_CUBE: {
-
- Rect2 r(ofs,Size2(w,(pos.y+size.y-style->get_margin(MARGIN_BOTTOM))-ofs.y));
- Vector<Point2> points;
- Vector<Point2> uvs;
- points.resize(4);
- uvs.resize(4);
- points[0]=r.pos;
- points[1]=r.pos+Point2(r.size.x,0);
- points[2]=r.pos+r.size;
- points[3]=r.pos+Point2(0,r.size.y);
- uvs[0]=Point2(0,0);
- uvs[1]=Point2(1,0);
- uvs[2]=Point2(1,1);
- uvs[3]=Point2(0,1);
-
- Ref<Texture> texture = shader_graph.node_get_param(p_node).operator RefPtr();
- if (texture.is_null() || texture->get_width()==0) {
- texture=get_icon("Click2Edit","EditorIcons");
- }
+ graph->get_node_connections(type,&conns);
+ //disconnect/reconnect dependencies
+ ur->add_undo_method(graph.ptr(),"disconnect_node",type,from_idx,p_from_slot,to_idx,p_to_slot);
+ for(List<ShaderGraph::Connection>::Element *E=conns.front();E;E=E->next()) {
- VisualServer::get_singleton()->canvas_item_add_primitive(ci,points,Vector<Color>(),uvs,texture->get_rid());
- } break;
- default: {}
+ if (E->get().dst_id==to_idx && E->get().dst_slot==p_to_slot) {
+ ur->add_do_method(graph.ptr(),"disconnect_node",type,E->get().src_id,E->get().src_slot,E->get().dst_id,E->get().dst_slot);
+ ur->add_undo_method(graph.ptr(),"connect_node",type,E->get().src_id,E->get().src_slot,E->get().dst_id,E->get().dst_slot);
+ }
}
-}
+ ur->add_do_method(graph.ptr(),"connect_node",type,from_idx,p_from_slot,to_idx,p_to_slot);
+ ur->add_do_method(this,"_update_graph");
+ ur->add_undo_method(this,"_update_graph");
+ ur->commit_action();
-void ShaderEditor::_node_param_changed() {
- shader_graph.node_set_param( click_node,property_editor->get_variant() );
- update();
- _write_shader_graph();
}
-ShaderEditor::ClickType ShaderEditor::_locate_click(const Point2& p_click,int *p_node_id,int *p_slot_index) const {
-
- Ref<StyleBox> style = get_stylebox("panel","PopupMenu");
- Ref<Texture> real_icon = get_icon("NodeRealSlot","EditorIcons");
- Ref<Font> font = get_font("font","PopupMenu");
- float h = font->get_height()+get_constant("vseparation","PopupMenu");
- float extra_left=MAX( real_icon->get_width()-style->get_margin(MARGIN_LEFT), 0 );
- float extra_right=MAX( real_icon->get_width()-style->get_margin(MARGIN_RIGHT), 0 );
-
+void ShaderGraphView::_disconnection_request(const String& p_from, int p_from_slot,const String& p_to,int p_to_slot) {
- for(const List<int>::Element *E=order.back();E;E=E->prev()) {
+ UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo();
- Size2 size=get_node_size(E->get());
- size.width+=extra_left+extra_right;
- Point2 pos = Point2( shader_graph.node_get_pos_x(E->get()), shader_graph.node_get_pos_y(E->get()) )-offset;
- pos.x-=extra_left;
+ int from_idx=-1;
+ int to_idx=-1;
+ for (Map<int,GraphNode*>::Element *E=node_map.front();E;E=E->next()) {
- Rect2 rect( pos, size );
- if (!rect.has_point(p_click))
- continue;
- VisualServer::ShaderNodeType type=shader_graph.node_get_type(E->get());
- if (p_node_id)
- *p_node_id=E->get();
- float y=p_click.y-(pos.y+style->get_margin(MARGIN_TOP));
- if (y<h)
- return CLICK_NODE;
- y-=h;
-
- for(int i=0;i<VisualServer::shader_get_input_count(type);i++) {
+ if (p_from==E->get()->get_name())
+ from_idx=E->key();
+ if (p_to==E->get()->get_name())
+ to_idx=E->key();
+ }
- if (y<h) {
- if (p_slot_index)
- *p_slot_index=i;
- return CLICK_INPUT_SLOT;
- }
- y-=h;
- }
+ ERR_FAIL_COND(from_idx==-1);
+ ERR_FAIL_COND(to_idx==-1);
- for(int i=0;i<VisualServer::shader_get_output_count(type);i++) {
+ if (!graph->is_node_connected(type,from_idx,p_from_slot,to_idx,p_to_slot))
+ return; //nothing to disconnect
- if (y<h) {
- if (p_slot_index)
- *p_slot_index=i;
- return CLICK_OUTPUT_SLOT;
- }
- y-=h;
- }
+ ur->create_action("Disconnect Graph Nodes");
- if (p_click.y<(rect.pos.y+rect.size.height-style->get_margin(MARGIN_BOTTOM)))
- return CLICK_PARAMETER;
- else
- return CLICK_NODE;
+ List<ShaderGraph::Connection> conns;
- }
+ graph->get_node_connections(type,&conns);
+ //disconnect/reconnect dependencies
+ ur->add_do_method(graph.ptr(),"disconnect_node",type,from_idx,p_from_slot,to_idx,p_to_slot);
+ ur->add_undo_method(graph.ptr(),"connect_node",type,from_idx,p_from_slot,to_idx,p_to_slot);
+ ur->add_do_method(this,"_update_graph");
+ ur->add_undo_method(this,"_update_graph");
+ ur->commit_action();
- return CLICK_NONE;
}
-Point2 ShaderEditor::_get_slot_pos(int p_node_id,bool p_input,int p_slot) {
+void ShaderGraphView::_node_removed(int p_id) {
- Ref<StyleBox> style = get_stylebox("panel","PopupMenu");
- float w = get_node_size(p_node_id).width;
- Ref<Font> font = get_font("font","PopupMenu");
- float h = font->get_height()+get_constant("vseparation","PopupMenu");
- Ref<Texture> vec_icon = get_icon("NodeVecSlot","EditorIcons");
- Point2 pos = Point2( shader_graph.node_get_pos_x(p_node_id), shader_graph.node_get_pos_y(p_node_id) )-offset;
- pos+=style->get_offset();
- pos.y+=h;
+ UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo();
+ ur->create_action("Remove Shader Graph Node");
- if(p_input) {
+ ur->add_do_method(graph.ptr(),"node_remove",type,p_id);
+ ur->add_undo_method(graph.ptr(),"node_add",type,graph->node_get_type(type,p_id),p_id);
+ ur->add_undo_method(graph.ptr(),"node_set_state",type,p_id,graph->node_get_state(type,p_id));
+ List<ShaderGraph::Connection> conns;
- pos.y+=p_slot*h;
- pos+=Point2( -vec_icon->get_width()/2.0, h/2.0).floor();
- return pos;
- } else {
+ graph->get_node_connections(type,&conns);
+ for(List<ShaderGraph::Connection>::Element *E=conns.front();E;E=E->next()) {
- pos.y+=VisualServer::shader_get_input_count( shader_graph.node_get_type(p_node_id ) )*h;
+ if (E->get().dst_id==p_id || E->get().src_id==p_id) {
+ ur->add_undo_method(graph.ptr(),"connect_node",type,E->get().src_id,E->get().src_slot,E->get().dst_id,E->get().dst_slot);
+ }
}
-
- pos.y+=p_slot*h;
- pos+=Point2( w-style->get_minimum_size().width+vec_icon->get_width()/2.0, h/2.0).floor();
-
- return pos;
+ ur->add_do_method(this,"_update_graph");
+ ur->add_undo_method(this,"_update_graph");
+ ur->commit_action();
}
-void ShaderEditor::_node_edit_property(int p_node) {
-
- Ref<StyleBox> style = get_stylebox("panel","PopupMenu");
- Size2 size = get_node_size(p_node);
- Point2 pos = Point2( shader_graph.node_get_pos_x(p_node), shader_graph.node_get_pos_y(p_node) )-offset;
+void ShaderGraphView::_node_moved(const Vector2& p_from, const Vector2& p_to,int p_id) {
- VisualServer::ShaderNodeType type=shader_graph.node_get_type(p_node);
- PropertyInfo ph = VisualServer::get_singleton()->shader_node_get_type_info(type);
- if (ph.type==Variant::NIL)
- return;
- if (ph.type==Variant::_RID)
- ph.type=Variant::OBJECT;
-
- property_editor->edit(NULL,ph.name,ph.type,shader_graph.node_get_param(p_node),ph.hint,ph.hint_string);
-
- Point2 popup_pos=Point2( pos.x+(size.width-property_editor->get_size().width)/2.0,pos.y+(size.y-style->get_margin(MARGIN_BOTTOM))).floor();
- popup_pos+=get_global_pos();
- property_editor->set_pos(popup_pos);
+ ERR_FAIL_COND(!node_map.has(p_id));
+ UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo();
+ ur->create_action("Move Shader Graph Node");
+ ur->add_do_method(this,"_move_node",p_id,p_to);
+ ur->add_undo_method(this,"_move_node",p_id,p_from);
+ ur->commit_action();
+}
- property_editor->popup();
+void ShaderGraphView::_move_node(int p_id,const Vector2& p_to) {
+ ERR_FAIL_COND(!node_map.has(p_id));
+ node_map[p_id]->set_offset(p_to);
+ graph->node_set_pos(type,p_id,p_to);
}
-bool ShaderEditor::has_point(const Point2& p_point) const {
- int n,si;
+void ShaderGraphView::_create_node(int p_id) {
- return _locate_click(p_point,&n,&si)!=CLICK_NONE;
-}
-void ShaderEditor::_input_event(InputEvent p_event) {
-
- switch(p_event.type) {
-
- case InputEvent::MOUSE_BUTTON: {
-
- if (p_event.mouse_button.pressed) {
-
-
- if (p_event.mouse_button.button_index==1) {
- click_pos=Point2(p_event.mouse_button.x,p_event.mouse_button.y);
- click_motion=click_pos;
- click_type = _locate_click(click_pos,&click_node,&click_slot);
- if( click_type!=CLICK_NONE) {
-
- order.erase(click_node);
- order.push_back(click_node);
- update();
- }
- switch(click_type) {
- case CLICK_INPUT_SLOT: {
- click_pos=_get_slot_pos(click_node,true,click_slot);
- } break;
- case CLICK_OUTPUT_SLOT: {
- click_pos=_get_slot_pos(click_node,false,click_slot);
- } break;
- case CLICK_PARAMETER: {
- //open editor
- _node_edit_property(click_node);
- } break;
- }
- }
- if (p_event.mouse_button.button_index==2) {
+ GraphNode *gn = memnew( GraphNode );
+ gn->set_show_close_button(true);
+ Color typecol[4]={
+ Color(0.9,0.4,1),
+ Color(0.8,1,0.2),
+ Color(1,0.2,0.2),
+ Color(0,1,1)
+ };
- if (click_type!=CLICK_NONE) {
- click_type=CLICK_NONE;
- update();
- } else {
- // try to disconnect/remove
- Point2 rclick_pos=Point2(p_event.mouse_button.x,p_event.mouse_button.y);
- rclick_type = _locate_click(rclick_pos,&rclick_node,&rclick_slot);
- if (rclick_type==CLICK_INPUT_SLOT || rclick_type==CLICK_OUTPUT_SLOT) {
+ switch(graph->node_get_type(type,p_id)) {
- node_popup->clear();
- node_popup->add_item("Disconnect",NODE_DISCONNECT);
- node_popup->set_pos(rclick_pos);
- node_popup->popup();
+ case ShaderGraph::NODE_INPUT: {
- }
+ gn->set_title("Input");
- if (rclick_type==CLICK_NODE) {
- node_popup->clear();
- node_popup->add_item("Remove",NODE_ERASE);
- node_popup->set_pos(rclick_pos);
- node_popup->popup();
- }
+ List<ShaderGraph::SlotInfo> si;
+ ShaderGraph::get_input_output_node_slot_info(graph->get_mode(),type,&si);
+ int idx=0;
+ for (List<ShaderGraph::SlotInfo>::Element *E=si.front();E;E=E->next()) {
+ ShaderGraph::SlotInfo& s=E->get();
+ if (s.dir==ShaderGraph::SLOT_IN) {
- }
+ Label *l= memnew( Label );
+ l->set_text(s.name);
+ l->set_align(Label::ALIGN_RIGHT);
+ gn->add_child(l);
+ gn->set_slot(idx,false,0,Color(),true,s.type,typecol[s.type]);
+ idx++;
}
- } else {
+ }
- if (p_event.mouse_button.button_index==1 && click_type!=CLICK_NONE) {
+ } break; // all inputs (case Shader type dependent)
+ case ShaderGraph::NODE_SCALAR_CONST: {
+ gn->set_title("Scalar");
+ SpinBox *sb = memnew( SpinBox );
+ sb->set_min(-100000);
+ sb->set_max(100000);
+ sb->set_step(0.001);
+ sb->set_val(graph->scalar_const_node_get_value(type,p_id));
+ sb->connect("value_changed",this,"_scalar_const_changed",varray(p_id));
+ gn->add_child(sb);
+ gn->set_slot(0,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]);
+
+ } break; //scalar constant
+ case ShaderGraph::NODE_VEC_CONST: {
+
+ gn->set_title("Vector");
+ Array v3p(true);
+ for(int i=0;i<3;i++) {
+ HBoxContainer *hbc = memnew( HBoxContainer );
+ Label *l = memnew( Label );
+ l->set_text(String::chr('X'+i));
+ hbc->add_child(l);
+ SpinBox *sb = memnew( SpinBox );
+ sb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
+ sb->set_min(-100000);
+ sb->set_max(100000);
+ sb->set_step(0.001);
+ sb->set_val(graph->vec_const_node_get_value(type,p_id)[i]);
+ sb->connect("value_changed",this,"_vec_const_changed",varray(p_id,v3p));
+ v3p.push_back(sb);
+ hbc->add_child(sb);
+ gn->add_child(hbc);
+ }
+ gn->set_slot(0,false,0,Color(),true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]);
+
+ } break; //vec3 constant
+ case ShaderGraph::NODE_RGB_CONST: {
+
+ gn->set_title("Color");
+ ColorPickerButton *cpb = memnew( ColorPickerButton );
+ cpb->set_color(graph->rgb_const_node_get_value(type,p_id));
+ cpb->connect("color_changed",this,"_rgb_const_changed",varray(p_id));
+ gn->add_child(cpb);
+ Label *l = memnew( Label );
+ l->set_text("RGB");
+ l->set_align(Label::ALIGN_RIGHT);
+ gn->add_child(l);
+ l = memnew( Label );
+ l->set_text("Alpha");
+ l->set_align(Label::ALIGN_RIGHT);
+ gn->add_child(l);
+
+ gn->set_slot(1,false,0,Color(),true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]);
+ gn->set_slot(2,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]);
+
+ } break; //rgb constant (shows a color picker instead)
+ case ShaderGraph::NODE_XFORM_CONST: {
+ gn->set_title("XForm");
+ ToolButton *edit = memnew( ToolButton );
+ edit->set_text("edit..");
+ edit->connect("pressed",this,"_xform_const_changed",varray(p_id,edit));
+ gn->add_child(edit);
+ gn->set_slot(0,false,0,Color(),true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM]);
+
+ } break; // 4x4 matrix constant
+ case ShaderGraph::NODE_TIME: {
+
+ gn->set_title("Time");
+ Label *l = memnew( Label );
+ l->set_text("(s)");
+ l->set_align(Label::ALIGN_RIGHT);
+ gn->add_child(l);
+ gn->set_slot(0,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]);
+
+ } break; // time in seconds
+ case ShaderGraph::NODE_SCREEN_TEX: {
+
+ gn->set_title("ScreenTex");
+ HBoxContainer *hbc = memnew( HBoxContainer );
+ hbc->add_constant_override("separation",0);
+ hbc->add_child( memnew(Label("UV")));
+ hbc->add_spacer();
+ hbc->add_child( memnew(Label("RGB")));
+ gn->add_child(hbc);
+ gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]);
+
+ } break; // screen texture sampler (takes UV) (only usable in fragment case Shader)
+ case ShaderGraph::NODE_SCALAR_OP: {
+
+ gn->set_title("ScalarOp");
+ static const char* op_name[ShaderGraph::SCALAR_MAX_OP]={
+ "Add",
+ "Sub",
+ "Mul",
+ "Div",
+ "Mod",
+ "Pow",
+ "Max",
+ "Min",
+ "Atan2"
+ };
+
+ OptionButton *ob = memnew( OptionButton );
+ for(int i=0;i<ShaderGraph::SCALAR_MAX_OP;i++) {
+
+ ob->add_item(op_name[i],i);
+ }
- switch(click_type) {
- case CLICK_INPUT_SLOT:
- case CLICK_OUTPUT_SLOT: {
+ ob->select(graph->scalar_op_node_get_op(type,p_id));
+ ob->connect("item_selected",this,"_scalar_op_changed",varray(p_id));
+ gn->add_child(ob);
+
+ HBoxContainer *hbc = memnew( HBoxContainer );
+ hbc->add_constant_override("separation",0);
+ hbc->add_child( memnew(Label("a")));
+ hbc->add_spacer();
+ hbc->add_child( memnew(Label("out")));
+ gn->add_child(hbc);
+ gn->add_child( memnew(Label("b")));
+
+ gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]);
+ gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],false,0,Color());
+
+
+ } break; // scalar vs scalar op (mul: { } break; add: { } break; div: { } break; etc)
+ case ShaderGraph::NODE_VEC_OP: {
+
+ gn->set_title("VecOp");
+ static const char* op_name[ShaderGraph::VEC_MAX_OP]={
+ "Add",
+ "Sub",
+ "Mul",
+ "Div",
+ "Mod",
+ "Pow",
+ "Max",
+ "Min",
+ "Cross"
+ };
+
+ OptionButton *ob = memnew( OptionButton );
+ for(int i=0;i<ShaderGraph::VEC_MAX_OP;i++) {
+
+ ob->add_item(op_name[i],i);
+ }
- Point2 dst_click_pos=Point2(p_event.mouse_button.x,p_event.mouse_button.y);
- int id;
- int slot;
- ClickType dst_click_type = _locate_click(dst_click_pos,&id,&slot);
- if (dst_click_type==CLICK_INPUT_SLOT && click_type==CLICK_OUTPUT_SLOT) {
+ ob->select(graph->vec_op_node_get_op(type,p_id));
+ ob->connect("item_selected",this,"_vec_op_changed",varray(p_id));
+ gn->add_child(ob);
- shader_graph.connect(click_node,click_slot,id,slot);
+ HBoxContainer *hbc = memnew( HBoxContainer );
+ hbc->add_constant_override("separation",0);
+ hbc->add_child( memnew(Label("a")));
+ hbc->add_spacer();
+ hbc->add_child( memnew(Label("out")));
+ gn->add_child(hbc);
+ gn->add_child( memnew(Label("b")));
- Error err = validate_graph();
- if (err==ERR_CYCLIC_LINK)
- shader_graph.disconnect(click_node,click_slot,id,slot);
- _write_shader_graph();
+ gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]);
+ gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color());
- }
- if (click_type==CLICK_INPUT_SLOT && dst_click_type==CLICK_OUTPUT_SLOT) {
- shader_graph.connect(id,slot,click_node,click_slot);
+ } break; // vec3 vs vec3 op (mul: { } break;ad: { } break;div: { } break;crossprod: { } break;etc)
+ case ShaderGraph::NODE_VEC_SCALAR_OP: {
- Error err = validate_graph();
- if (err==ERR_CYCLIC_LINK)
- shader_graph.disconnect(id,slot,click_node,click_slot);
- _write_shader_graph();
- }
+ gn->set_title("VecScalarOp");
+ static const char* op_name[ShaderGraph::VEC_SCALAR_MAX_OP]={
+ "Mul",
+ "Div",
+ "Pow",
+ };
- } break;
- case CLICK_NODE: {
- int new_x=shader_graph.node_get_pos_x(click_node)+(click_motion.x-click_pos.x);
- int new_y=shader_graph.node_get_pos_y(click_node)+(click_motion.y-click_pos.y);
- shader_graph.node_set_pos(click_node,new_x,new_y);
- _write_shader_graph();
+ OptionButton *ob = memnew( OptionButton );
+ for(int i=0;i<ShaderGraph::VEC_SCALAR_MAX_OP;i++) {
- } break;
- }
+ ob->add_item(op_name[i],i);
+ }
- click_type=CLICK_NONE;
- update();
- }
+ ob->select(graph->vec_scalar_op_node_get_op(type,p_id));
+ ob->connect("item_selected",this,"_vec_scalar_op_changed",varray(p_id));
+ gn->add_child(ob);
+
+ HBoxContainer *hbc = memnew( HBoxContainer );
+ hbc->add_constant_override("separation",0);
+ hbc->add_child( memnew(Label("a")));
+ hbc->add_spacer();
+ hbc->add_child( memnew(Label("out")));
+ gn->add_child(hbc);
+ gn->add_child( memnew(Label("b")));
+
+ gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]);
+ gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],false,0,Color());
+
+
+ } break; // vec3 vs scalar op (mul: { } break; add: { } break; div: { } break; etc)
+ case ShaderGraph::NODE_RGB_OP: {
+
+ gn->set_title("RGB Op");
+ static const char* op_name[ShaderGraph::RGB_MAX_OP]={
+ "Screen",
+ "Difference",
+ "Darken",
+ "Lighten",
+ "Overlay",
+ "Dodge",
+ "Burn",
+ "SoftLight",
+ "HardLight"
+ };
+
+ OptionButton *ob = memnew( OptionButton );
+ for(int i=0;i<ShaderGraph::RGB_MAX_OP;i++) {
+
+ ob->add_item(op_name[i],i);
}
- }
+ ob->select(graph->rgb_op_node_get_op(type,p_id));
+ ob->connect("item_selected",this,"_rgb_op_changed",varray(p_id));
+ gn->add_child(ob);
- case InputEvent::MOUSE_MOTION: {
+ HBoxContainer *hbc = memnew( HBoxContainer );
+ hbc->add_constant_override("separation",0);
+ hbc->add_child( memnew(Label("a")));
+ hbc->add_spacer();
+ hbc->add_child( memnew(Label("out")));
+ gn->add_child(hbc);
+ gn->add_child( memnew(Label("b")));
- if (p_event.mouse_motion.button_mask&1 && click_type!=CLICK_NONE) {
+ gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]);
+ gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color());
- click_motion=Point2(p_event.mouse_button.x,p_event.mouse_button.y);
- update();
- }
+ } break; // vec3 vs vec3 rgb op (with scalar amount): { } break; like brighten: { } break; darken: { } break; burn: { } break; dodge: { } break; multiply: { } break; etc.
+ case ShaderGraph::NODE_XFORM_MULT: {
- } break;
- }
-}
+ gn->set_title("XFMult");
+ HBoxContainer *hbc = memnew( HBoxContainer );
+ hbc->add_child( memnew(Label("a")));
+ hbc->add_spacer();
+ hbc->add_child( memnew(Label("out")));
+ gn->add_child(hbc);
+ gn->add_child( memnew(Label("b")));
-void ShaderEditor::_notification(int p_what) {
+ gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM],true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM]);
+ gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM],false,0,Color());
- switch(p_what) {
+ } break; // mat4 x mat4
+ case ShaderGraph::NODE_XFORM_VEC_MULT: {
- case NOTIFICATION_DRAW: {
+ gn->set_title("XFVecMult");
- _update_scrollbars();
- //VisualServer::get_singleton()->canvas_item_add_rect(get_canvas_item(),Rect2(Point2(),get_size()),Color(0,0,0,1));
+ Button *button = memnew( Button("RotOnly"));
+ button->set_toggle_mode(true);
+ button->set_pressed(graph->xform_vec_mult_node_get_no_translation(type,p_id));
+ button->connect("toggled",this,"_xform_inv_rev_changed",varray(p_id));
- for(List<int>::Element *E=order.front();E;E=E->next()) {
+ gn->add_child(button);
- _draw_node(E->get());
- }
+ HBoxContainer *hbc = memnew( HBoxContainer );
+ hbc->add_constant_override("separation",0);
+ hbc->add_child( memnew(Label("xf")));
+ hbc->add_spacer();
+ Label *l = memnew(Label("out"));
+ l->set_align(Label::ALIGN_RIGHT);
+ hbc->add_child( l);
+ gn->add_child(hbc);
+ gn->add_child( memnew(Label("vec")));
- if (click_type==CLICK_INPUT_SLOT || click_type==CLICK_OUTPUT_SLOT) {
+ gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]);
+ gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color());
- VisualServer::get_singleton()->canvas_item_add_line(get_canvas_item(),click_pos,click_motion,Color(0.5,1,0.5,0.8),2);
+ } break;
+ case ShaderGraph::NODE_XFORM_VEC_INV_MULT: {
+
+ gn->set_title("XFVecInvMult");
+
+
+ Button *button = memnew( Button("RotOnly"));
+ button->set_toggle_mode(true);
+ button->set_pressed(graph->xform_vec_mult_node_get_no_translation(type,p_id));
+ button->connect("toggled",this,"_xform_inv_rev_changed",varray(p_id));
+
+ gn->add_child(button);
+
+ gn->add_child( memnew(Label("vec")));
+ HBoxContainer *hbc = memnew( HBoxContainer );
+ hbc->add_constant_override("separation",0);
+ hbc->add_child( memnew(Label("xf")));
+ hbc->add_spacer();
+ Label *l = memnew(Label("out"));
+ l->set_align(Label::ALIGN_RIGHT);
+ hbc->add_child( l);
+ gn->add_child(hbc);
+
+ gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color());
+ gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]);
+
+
+ } break; // mat4 x vec3 inverse mult (with no-translation option)
+ case ShaderGraph::NODE_SCALAR_FUNC: {
+
+ gn->set_title("ScalarFunc");
+ static const char* func_name[ShaderGraph::SCALAR_MAX_FUNC]={
+ "Sin",
+ "Cos",
+ "Tan",
+ "ASin",
+ "ACos",
+ "ATan",
+ "SinH",
+ "CosH",
+ "TanH",
+ "Log",
+ "Exp",
+ "Sqrt",
+ "Abs",
+ "Sign",
+ "Floor",
+ "Round",
+ "Ceil",
+ "Frac",
+ "Satr",
+ "Neg"
+ };
+
+ OptionButton *ob = memnew( OptionButton );
+ for(int i=0;i<ShaderGraph::SCALAR_MAX_FUNC;i++) {
+
+ ob->add_item(func_name[i],i);
}
- List<ShaderGraph::Connection> connections = shader_graph.get_connection_list();
- for(List<ShaderGraph::Connection>::Element *E=connections.front();E;E=E->next()) {
-
- const ShaderGraph::Connection &c=E->get();
- Point2 source = _get_slot_pos(c.src_id,false,c.src_slot);
- Point2 dest = _get_slot_pos(c.dst_id,true,c.dst_slot);
- bool vec = VisualServer::shader_is_input_vector( shader_graph.node_get_type(c.dst_id), c.dst_slot );
- Color col = vec?Color(1,0.5,0.5,0.8):Color(1,1,0.5,0.8);
-
- if (click_type==CLICK_NODE && click_node==c.src_id) {
+ ob->select(graph->scalar_func_node_get_function(type,p_id));
+ ob->connect("item_selected",this,"_scalar_func_changed",varray(p_id));
+ gn->add_child(ob);
- source+=click_motion-click_pos;
- }
+ HBoxContainer *hbc = memnew( HBoxContainer );
+ hbc->add_child( memnew(Label("in")));
+ hbc->add_spacer();
+ hbc->add_child( memnew(Label("out")));
+ gn->add_child(hbc);
- if (click_type==CLICK_NODE && click_node==c.dst_id) {
+ gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]);
- dest+=click_motion-click_pos;
- }
- VisualServer::get_singleton()->canvas_item_add_line(get_canvas_item(),source,dest,col,2);
+ } break; // scalar function (sin: { } break; cos: { } break; etc)
+ case ShaderGraph::NODE_VEC_FUNC: {
- }
- } break;
- }
-}
-void ShaderEditor::_update_scrollbars() {
+ gn->set_title("VecFunc");
+ static const char* func_name[ShaderGraph::VEC_MAX_FUNC]={
+ "Normalize",
+ "Saturate",
+ "Negate",
+ "Reciprocal",
+ "RGB to HSV",
+ "HSV to RGB",
+ };
- Size2 size = get_size();
- Size2 hmin = h_scroll->get_minimum_size();
- Size2 vmin = v_scroll->get_minimum_size();
+ OptionButton *ob = memnew( OptionButton );
+ for(int i=0;i<ShaderGraph::VEC_MAX_FUNC;i++) {
- v_scroll->set_begin( Point2(size.width - vmin.width, 0) );
- v_scroll->set_end( Point2(size.width, size.height) );
+ ob->add_item(func_name[i],i);
+ }
- h_scroll->set_begin( Point2( 0, size.height - hmin.height) );
- h_scroll->set_end( Point2(size.width-vmin.width, size.height) );
+ ob->select(graph->vec_func_node_get_function(type,p_id));
+ ob->connect("item_selected",this,"_vec_func_changed",varray(p_id));
+ gn->add_child(ob);
+
+ HBoxContainer *hbc = memnew( HBoxContainer );
+ hbc->add_constant_override("separation",0);
+ hbc->add_child( memnew(Label("in")));
+ hbc->add_spacer();
+ hbc->add_child( memnew(Label("out")));
+ gn->add_child(hbc);
+
+ gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]);
+
+ } break; // vector function (normalize: { } break; negate: { } break; reciprocal: { } break; rgb2hsv: { } break; hsv2rgb: { } break; etc: { } break; etc)
+ case ShaderGraph::NODE_VEC_LEN: {
+ gn->set_title("VecLength");
+ HBoxContainer *hbc = memnew( HBoxContainer );
+ hbc->add_child( memnew(Label("in")));
+ hbc->add_spacer();
+ hbc->add_child( memnew(Label("len")));
+ gn->add_child(hbc);
+
+ gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]);
+
+ } break; // vec3 length
+ case ShaderGraph::NODE_DOT_PROD: {
+
+ gn->set_title("DotProduct");
+ HBoxContainer *hbc = memnew( HBoxContainer );
+ hbc->add_constant_override("separation",0);
+ hbc->add_child( memnew(Label("a")));
+ hbc->add_spacer();
+ hbc->add_child( memnew(Label("dp")));
+ gn->add_child(hbc);
+ gn->add_child( memnew(Label("b")));
+
+ gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]);
+ gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color());
+
+ } break; // vec3 . vec3 (dot product -> scalar output)
+ case ShaderGraph::NODE_VEC_TO_SCALAR: {
+
+ gn->set_title("Vec2Scalar");
+ HBoxContainer *hbc = memnew( HBoxContainer );
+ hbc->add_constant_override("separation",0);
+ hbc->add_child( memnew(Label("vec")));
+ hbc->add_spacer();
+ Label *l=memnew(Label("x"));
+ l->set_align(Label::ALIGN_RIGHT);
+ hbc->add_child( l);
+ gn->add_child(hbc);
+ l=memnew(Label("y"));
+ l->set_align(Label::ALIGN_RIGHT);
+ gn->add_child( l );
+ l=memnew(Label("z"));
+ l->set_align(Label::ALIGN_RIGHT);
+ gn->add_child( l);
+
+ gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]);
+ gn->set_slot(1,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]);
+ gn->set_slot(2,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]);
+
+
+
+
+ } break; // 1 vec3 input: { } break; 3 scalar outputs
+ case ShaderGraph::NODE_SCALAR_TO_VEC: {
+
+ gn->set_title("Scalar2Vec");
+ HBoxContainer *hbc = memnew( HBoxContainer );
+ hbc->add_child( memnew(Label("x")));
+ hbc->add_spacer();
+ hbc->add_child( memnew(Label("vec")));
+ gn->add_child(hbc);
+ gn->add_child( memnew(Label("y")));
+ gn->add_child( memnew(Label("z")));
+
+ gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]);
+ gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],false,0,Color());
+ gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],false,0,Color());
+
+ } break; // 3 scalar input: { } break; 1 vec3 output
+ case ShaderGraph::NODE_VEC_TO_XFORM: {
+
+ gn->set_title("Vec2XForm");
+ HBoxContainer *hbc = memnew( HBoxContainer );
+ hbc->add_constant_override("separation",0);
+ hbc->add_child( memnew(Label("x")));
+ hbc->add_spacer();
+ hbc->add_child( memnew(Label("xf")));
+ gn->add_child(hbc);
+ gn->add_child( memnew(Label("y")));
+ gn->add_child( memnew(Label("z")));
+ gn->add_child( memnew(Label("ofs")));
+
+ gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM]);
+ gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color());
+ gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color());
+ gn->set_slot(3,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color());
+
+ } break; // 3 vec input: { } break; 1 xform output
+ case ShaderGraph::NODE_XFORM_TO_VEC: {
+
+ gn->set_title("XForm2Vec");
+
+ HBoxContainer *hbc = memnew( HBoxContainer );
+ hbc->add_constant_override("separation",0);
+ hbc->add_child( memnew(Label("xf")));
+ hbc->add_spacer();
+ Label *l=memnew(Label("x"));
+ l->set_align(Label::ALIGN_RIGHT);
+ hbc->add_child( l);
+ gn->add_child(hbc);
+ l=memnew(Label("y"));
+ l->set_align(Label::ALIGN_RIGHT);
+ gn->add_child( l );
+ l=memnew(Label("z"));
+ l->set_align(Label::ALIGN_RIGHT);
+ gn->add_child( l);
+ l=memnew(Label("ofs"));
+ l->set_align(Label::ALIGN_RIGHT);
+ gn->add_child( l);
+
+ gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]);
+ gn->set_slot(1,false,0,Color(),true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]);
+ gn->set_slot(2,false,0,Color(),true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]);
+ gn->set_slot(3,false,0,Color(),true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]);
+
+ } break; // 3 vec input: { } break; 1 xform output
+ case ShaderGraph::NODE_SCALAR_INTERP: {
+
+ gn->set_title("ScalarInterp");
+ HBoxContainer *hbc = memnew( HBoxContainer );
+ hbc->add_constant_override("separation",0);
+ hbc->add_child( memnew(Label("a")));
+ hbc->add_spacer();
+ hbc->add_child( memnew(Label("interp")));
+ gn->add_child(hbc);
+ gn->add_child( memnew(Label("b")));
+ gn->add_child( memnew(Label("c")));
+
+ gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]);
+ gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],false,0,Color());
+ gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],false,0,Color());
+
+
+ } break; // scalar interpolation (with optional curve)
+ case ShaderGraph::NODE_VEC_INTERP: {
+
+ gn->set_title("VecInterp");
+ HBoxContainer *hbc = memnew( HBoxContainer );
+ hbc->add_child( memnew(Label("a")));
+ hbc->add_spacer();
+ hbc->add_child( memnew(Label("interp")));
+ gn->add_child(hbc);
+ gn->add_child( memnew(Label("b")));
+ gn->add_child( memnew(Label("c")));
+
+ gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]);
+ gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color());
+ gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],false,0,Color());
+
+ } break; // vec3 interpolation (with optional curve)
+ case ShaderGraph::NODE_SCALAR_INPUT: {
+
+ gn->set_title("ScalarUniform");
+ LineEdit *le = memnew( LineEdit );
+ gn->add_child(le);
+ le->set_text(graph->input_node_get_name(type,p_id));
+ le->connect("text_entered",this,"_input_name_changed",varray(p_id,le));
+ SpinBox *sb = memnew( SpinBox );
+ sb->set_min(-100000);
+ sb->set_max(100000);
+ sb->set_step(0.001);
+ sb->set_val(graph->scalar_input_node_get_value(type,p_id));
+ sb->connect("value_changed",this,"_scalar_input_changed",varray(p_id));
+ gn->add_child(sb);
+ gn->set_slot(1,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]);
+
+ } break; // scalar uniform (assignable in material)
+ case ShaderGraph::NODE_VEC_INPUT: {
+
+ gn->set_title("VectorUniform");
+ LineEdit *le = memnew( LineEdit );
+ gn->add_child(le);
+ le->set_text(graph->input_node_get_name(type,p_id));
+ le->connect("text_entered",this,"_input_name_changed",varray(p_id,le));
+ Array v3p(true);
+ for(int i=0;i<3;i++) {
+ HBoxContainer *hbc = memnew( HBoxContainer );
+ Label *l = memnew( Label );
+ l->set_text(String::chr('X'+i));
+ hbc->add_child(l);
+ SpinBox *sb = memnew( SpinBox );
+ sb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
+ sb->set_min(-100000);
+ sb->set_max(100000);
+ sb->set_step(0.001);
+ sb->set_val(graph->vec_input_node_get_value(type,p_id)[i]);
+ sb->connect("value_changed",this,"_vec_input_changed",varray(p_id,v3p));
+ v3p.push_back(sb);
+ hbc->add_child(sb);
+ gn->add_child(hbc);
+ }
+ gn->set_slot(1,false,0,Color(),true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]);
+
+ } break; // vec3 uniform (assignable in material)
+ case ShaderGraph::NODE_RGB_INPUT: {
+
+ gn->set_title("ColorUniform");
+ LineEdit *le = memnew( LineEdit );
+ gn->add_child(le);
+ le->set_text(graph->input_node_get_name(type,p_id));
+ le->connect("text_entered",this,"_input_name_changed",varray(p_id,le));
+ ColorPickerButton *cpb = memnew( ColorPickerButton );
+ cpb->set_color(graph->rgb_input_node_get_value(type,p_id));
+ cpb->connect("color_changed",this,"_rgb_input_changed",varray(p_id));
+ gn->add_child(cpb);
+ Label *l = memnew( Label );
+ l->set_text("RGB");
+ l->set_align(Label::ALIGN_RIGHT);
+ gn->add_child(l);
+ l = memnew( Label );
+ l->set_text("Alpha");
+ l->set_align(Label::ALIGN_RIGHT);
+ gn->add_child(l);
+
+ gn->set_slot(2,false,0,Color(),true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]);
+ gn->set_slot(3,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]);
+
+
+ } break; // color uniform (assignable in material)
+ case ShaderGraph::NODE_XFORM_INPUT: {
+ gn->set_title("XFUniform");
+ LineEdit *le = memnew( LineEdit );
+ gn->add_child(le);
+ le->set_text(graph->input_node_get_name(type,p_id));
+ le->connect("text_entered",this,"_input_name_changed",varray(p_id,le));
+ ToolButton *edit = memnew( ToolButton );
+ edit->set_text("edit..");
+ edit->connect("pressed",this,"_xform_input_changed",varray(p_id,edit));
+ gn->add_child(edit);
+ gn->set_slot(1,false,0,Color(),true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM]);
+
+ } break; // mat4 uniform (assignable in material)
+ case ShaderGraph::NODE_TEXTURE_INPUT: {
+
+ gn->set_title("TexUniform");
+ LineEdit *le = memnew( LineEdit );
+ gn->add_child(le);
+ le->set_text(graph->input_node_get_name(type,p_id));
+ le->connect("text_entered",this,"_input_name_changed",varray(p_id,le));
+ TextureFrame *tex = memnew( TextureFrame );
+ tex->set_expand(true);
+ tex->set_custom_minimum_size(Size2(80,80));
+ gn->add_child(tex);
+ tex->set_texture(graph->texture_input_node_get_value(type,p_id));
+ ToolButton *edit = memnew( ToolButton );
+ edit->set_text("edit..");
+ edit->connect("pressed",this,"_tex_edited",varray(p_id,edit));
+ gn->add_child(edit);
+
+ HBoxContainer *hbc = memnew( HBoxContainer );
+ hbc->add_constant_override("separation",0);
+ hbc->add_child( memnew(Label("UV")));
+ hbc->add_spacer();
+ Label *l=memnew(Label("RGB"));
+ l->set_align(Label::ALIGN_RIGHT);
+ hbc->add_child(l);
+ gn->add_child(hbc);
+ l = memnew( Label );
+ l->set_text("Alpha");
+ l->set_align(Label::ALIGN_RIGHT);
+ gn->add_child(l);
+
+ gn->set_slot(3,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]);
+ gn->set_slot(4,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]);
+
+ } break; // texture input (assignable in material)
+ case ShaderGraph::NODE_CUBEMAP_INPUT: {
+
+ gn->set_title("TexUniform");
+ LineEdit *le = memnew( LineEdit );
+ gn->add_child(le);
+ le->set_text(graph->input_node_get_name(type,p_id));
+ le->connect("text_entered",this,"_input_name_changed",varray(p_id,le));
+
+ ToolButton *edit = memnew( ToolButton );
+ edit->set_text("edit..");
+ edit->connect("pressed",this,"_cube_edited",varray(p_id,edit));
+ gn->add_child(edit);
+
+
+ HBoxContainer *hbc = memnew( HBoxContainer );
+ hbc->add_constant_override("separation",0);
+ hbc->add_child( memnew(Label("UV")));
+ hbc->add_spacer();
+ Label *l=memnew(Label("RGB"));
+ l->set_align(Label::ALIGN_RIGHT);
+ hbc->add_child(l);
+ gn->add_child(hbc);
+ l = memnew( Label );
+ l->set_text("Alpha");
+ l->set_align(Label::ALIGN_RIGHT);
+ gn->add_child(l);
+
+ gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]);
+ gn->set_slot(3,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]);
+
+ } break; // cubemap input (assignable in material)
+ case ShaderGraph::NODE_OUTPUT: {
+ gn->set_title("Output");
+
+ List<ShaderGraph::SlotInfo> si;
+ ShaderGraph::get_input_output_node_slot_info(graph->get_mode(),type,&si);
+
+ int idx=0;
+ for (List<ShaderGraph::SlotInfo>::Element *E=si.front();E;E=E->next()) {
+ ShaderGraph::SlotInfo& s=E->get();
+ if (s.dir==ShaderGraph::SLOT_OUT) {
+
+ Label *l= memnew( Label );
+ l->set_text(s.name);
+ l->set_align(Label::ALIGN_LEFT);
+ gn->add_child(l);
+ gn->set_slot(idx,true,s.type,typecol[s.type],false,0,Color());
+ idx++;
+ }
+ }
+ } break; // output (case Shader type dependent)
+ case ShaderGraph::NODE_COMMENT: {
+ gn->set_title("Comment");
+ TextEdit *te = memnew(TextEdit);
+ te->set_custom_minimum_size(Size2(100,100));
+ gn->add_child(te);
+ te->set_text(graph->comment_node_get_text(type,p_id));
+ te->connect("text_changed",this,"_comment_edited",varray(p_id,te));
- Size2 min = _get_maximum_size();
+ } break; // comment
- if (min.height < size.height - hmin.height) {
- v_scroll->hide();
- offset.y=0;
- } else {
- v_scroll->show();
- v_scroll->set_max(min.height);
- v_scroll->set_page(size.height - hmin.height);
- offset.y=v_scroll->get_val();
}
- if (min.width < size.width - vmin.width) {
-
- h_scroll->hide();
- offset.x=0;
- } else {
-
- h_scroll->show();
- h_scroll->set_max(min.width);
- h_scroll->set_page(size.width - vmin.width);
- offset.x=h_scroll->get_val();
- }
-}
+ gn->connect("dragged",this,"_node_moved",varray(p_id));
+ gn->connect("close_request",this,"_node_removed",varray(p_id),CONNECT_DEFERRED);
+ graph_edit->add_child(gn);
+ node_map[p_id]=gn;
+ gn->set_offset(graph->node_get_pos(type,p_id));
-void ShaderEditor::_scroll_moved() {
- offset.x=h_scroll->get_val();
- offset.y=v_scroll->get_val();
- update();
}
-void ShaderEditor::_bind_methods() {
-
- ObjectTypeDB::bind_method( "_node_menu_item", &ShaderEditor::_node_menu_item );
- ObjectTypeDB::bind_method( "_node_add_callback", &ShaderEditor::_node_add_callback );
- ObjectTypeDB::bind_method( "_input_event", &ShaderEditor::_input_event );
- ObjectTypeDB::bind_method( "_node_param_changed", &ShaderEditor::_node_param_changed );
- ObjectTypeDB::bind_method( "_scroll_moved", &ShaderEditor::_scroll_moved );
- ObjectTypeDB::bind_method( "_vertex_item", &ShaderEditor::_vertex_item );
- ObjectTypeDB::bind_method( "_fragment_item", &ShaderEditor::_fragment_item );
- ObjectTypeDB::bind_method( "_post_item", &ShaderEditor::_post_item );
-}
+void ShaderGraphView::_update_graph() {
-void ShaderEditor::_read_shader_graph() {
- shader_graph.clear();;
- order.clear();
- List<int> nodes;
- shader->get_node_list(&nodes);
- int larger_id=0;
- for(List<int>::Element *E=nodes.front();E;E=E->next()) {
+ if (block_update)
+ return;
- if (E->get() > larger_id)
- larger_id = E->get();
+ for (Map<int,GraphNode*>::Element *E=node_map.front();E;E=E->next()) {
- shader_graph.node_add( (VS::ShaderNodeType)shader->node_get_type(E->get()), E->get() );
- shader_graph.node_set_param( E->get(), shader->node_get_param( E->get() ) );
- Point2 pos = shader->node_get_pos(E->get());
- shader_graph.node_set_pos( E->get(), pos.x,pos.y );
- order.push_back(E->get());
+ memdelete(E->get());
}
- last_id=larger_id+1;
+ node_map.clear();
- List<Shader::Connection> connections;
- shader->get_connections(&connections);
-
- for(List<Shader::Connection>::Element *E=connections.front();E;E=E->next()) {
-
- Shader::Connection &c=E->get();
- shader_graph.connect(c.src_id,c.src_slot,c.dst_id,c.dst_slot);
- }
+ if (!graph.is_valid())
+ return;
- validate_graph();
- update();
-}
-void ShaderEditor::_write_shader_graph() {
+ List<int> nl;
+ graph->get_node_list(type,&nl);
- shader->clear();
- List<int> nodes;
- shader_graph.get_node_list(&nodes);
- for(List<int>::Element *E=nodes.front();E;E=E->next()) {
+ for(List<int>::Element *E=nl.front();E;E=E->next()) {
- shader->node_add((Shader::NodeType)shader_graph.node_get_type(E->get()),E->get());
- shader->node_set_param(E->get(),shader_graph.node_get_param(E->get()));
- shader->node_set_pos(E->get(),Point2( shader_graph.node_get_pos_x(E->get()),shader_graph.node_get_pos_y(E->get()) ) );
+ _create_node(E->get());
}
+ graph_edit->clear_connections();
- List<ShaderGraph::Connection> connections = shader_graph.get_connection_list();
+ List<ShaderGraph::Connection> connections;
+ graph->get_node_connections(type,&connections);
for(List<ShaderGraph::Connection>::Element *E=connections.front();E;E=E->next()) {
- const ShaderGraph::Connection &c=E->get();
- shader->connect(c.src_id,c.src_slot,c.dst_id,c.dst_slot);
+ ERR_CONTINUE(!node_map.has(E->get().src_id) || !node_map.has(E->get().dst_id));
+ graph_edit->connect_node(node_map[E->get().src_id]->get_name(),E->get().src_slot,node_map[E->get().dst_id]->get_name(),E->get().dst_slot);
}
-}
-void ShaderEditor::_add_node_from_text(const String& p_text) {
- ERR_FAIL_COND( p_text.get_slice_count(" ") != 3 );
- bool input = p_text.get_slice(" ",0)=="In:";
- String name = p_text.get_slice(" ",1);
- bool vec = p_text.get_slice(" ",2)=="(vec3)";
- _node_add( input?
- ( vec? VisualServer::NODE_VEC_IN : VisualServer::NODE_IN ) :
- ( vec? VisualServer::NODE_VEC_OUT : VisualServer::NODE_OUT ) );
-
- shader_graph.node_set_param( last_id-1,name );
- _write_shader_graph();
}
-void ShaderEditor::_vertex_item(int p_item) {
-
- _add_node_from_text(vertex_popup->get_item_text(p_item));
-}
-void ShaderEditor::_fragment_item(int p_item) {
-
- _add_node_from_text(fragment_popup->get_item_text(p_item));
-}
-void ShaderEditor::_post_item(int p_item) {
-
- _add_node_from_text(post_popup->get_item_text(p_item));
-}
-
-
-void ShaderEditor::_node_menu_item(int p_item) {
-
- switch(p_item) {
-
- case GRAPH_ADD_NODE: {
- add_popup->popup_centered_ratio();
- validate_graph();
- } break;
- case NODE_DISCONNECT: {
-
- if (rclick_type==CLICK_INPUT_SLOT) {
-
- List<ShaderGraph::Connection> connections = shader_graph.get_connection_list();
- for(List<ShaderGraph::Connection>::Element *E=connections.front();E;E=E->next()) {
-
- const ShaderGraph::Connection &c=E->get();
- if( c.dst_id==rclick_node && c.dst_slot==rclick_slot) {
+void ShaderGraphView::_sg_updated() {
- shader_graph.disconnect(c.src_id,c.src_slot,c.dst_id,c.dst_slot);
- }
- }
- update();
- _write_shader_graph();
- validate_graph();
- }
-
- if (rclick_type==CLICK_OUTPUT_SLOT) {
-
- List<ShaderGraph::Connection> connections = shader_graph.get_connection_list();
- for(List<ShaderGraph::Connection>::Element *E=connections.front();E;E=E->next()) {
-
- const ShaderGraph::Connection &c=E->get();
- if( c.src_id==rclick_node && c.src_slot==rclick_slot) {
-
- shader_graph.disconnect(c.src_id,c.src_slot,c.dst_id,c.dst_slot);
- }
- }
- update();
- _write_shader_graph();
- validate_graph();
- }
-
- } break;
- case NODE_ERASE: {
-
- order.erase(rclick_node);
- shader_graph.node_remove(rclick_node);
- update();
- _write_shader_graph();
- validate_graph();
- } break;
- case GRAPH_CLEAR: {
-
- order.clear();
- shader_graph.clear();
- last_id=1;
- last_x=20;
- last_y=20;
- update();
- _write_shader_graph();
- validate_graph();
-
- } break;
+ if (!graph.is_valid())
+ return;
+ switch(graph->get_graph_error(type)) {
+ case ShaderGraph::GRAPH_OK: status->set_text(""); break;
+ case ShaderGraph::GRAPH_ERROR_CYCLIC: status->set_text("Error: Cyclic Connection Link"); break;
+ case ShaderGraph::GRAPH_ERROR_MISSING_CONNECTIONS: status->set_text("Error: Missing Input Connections"); break;
}
}
-void ShaderEditor::_node_add(VisualServer::ShaderNodeType p_type) {
-
- shader_graph.node_add(p_type,last_id );
- shader_graph.node_set_pos(last_id ,last_x,last_y);
- String test_param;
-
- switch(p_type) {
- case VS::NODE_PARAMETER: {
+void ShaderGraphView::set_graph(Ref<ShaderGraph> p_graph){
- test_param="param";
- } break;
- case VS::NODE_VEC_PARAMETER: {
-
- test_param="vec";
- } break;
- case VS::NODE_COLOR_PARAMETER: {
- test_param="color";
- } break;
- case VS::NODE_TEXTURE_PARAMETER: {
-
- test_param="tex";
- } break;
- case VS::NODE_TEXTURE_2D_PARAMETER: {
-
- test_param="tex2D";
- } break;
- case VS::NODE_TEXTURE_CUBE_PARAMETER: {
-
- test_param="cubemap";
- } break;
- case VS::NODE_TRANSFORM_PARAMETER: {
- test_param="xform";
- } break;
- case VS::NODE_LABEL: {
-
- test_param="label";
- } break;
+ if (graph.is_valid()) {
+ graph->disconnect("updated",this,"_sg_updated");
+ }
+ graph=p_graph;
+ if (graph.is_valid()) {
+ graph->connect("updated",this,"_sg_updated");
}
+ _update_graph();
+ _sg_updated();
- if(test_param!="") {
+}
- int iter=0;
- List<int> l;
+void ShaderGraphView::_notification(int p_what) {
- shader_graph.get_node_list(&l);
+ if (p_what==NOTIFICATION_ENTER_TREE) {
- bool found;
- String test;
- do {
- iter++;
- test=test_param;
- if (iter>1)
- test+="_"+itos(iter);
- found=false;
- for(List<int>::Element *E=l.front();E;E=E->next()) {
+ ped_popup->connect("variant_changed",this,"_variant_edited");
+ }
+ }
+
+void ShaderGraphView::add_node(int p_type) {
+
+ List<int> existing;
+ graph->get_node_list(type,&existing);
+ existing.sort();
+ int newid=1;
+ for(List<int>::Element *E=existing.front();E;E=E->next()) {
+ if (!E->next() || (E->get()+1!=E->next()->get())){
+ newid=E->get()+1;
+ break;
+ }
+ }
+ Vector2 init_ofs(20,20);
+ while(true) {
+ bool valid=true;
+ for(List<int>::Element *E=existing.front();E;E=E->next()) {
+ Vector2 pos = graph->node_get_pos(type,E->get());
+ if (init_ofs==pos) {
+ init_ofs+=Vector2(20,20);
+ valid=false;
+ break;
- String param = shader_graph.node_get_param( E->get() );
- if (param==test) {
- found=true;
- break;
- }
}
+ }
- } while (found);
-
-
- shader_graph.node_set_param(last_id,test);
-
+ if (valid)
+ break;
}
- order.push_back(last_id);
- last_x+=10;
- last_y+=10;
- last_id++;
- last_x=last_x % (int)get_size().width;
- last_y=last_y % (int)get_size().height;
- update();
- add_popup->hide();;
- _write_shader_graph();
+ UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo();
+ ur->create_action("Add Shader Graph Node");
+ ur->add_do_method(graph.ptr(),"node_add",type,p_type,newid);
+ ur->add_do_method(graph.ptr(),"node_set_pos",type,newid,init_ofs);
+ ur->add_undo_method(graph.ptr(),"node_remove",type,newid);
+ ur->add_do_method(this,"_update_graph");
+ ur->add_undo_method(this,"_update_graph");
+ ur->commit_action();
}
-void ShaderEditor::_node_add_callback() {
-
- TreeItem * item = add_types->get_selected();
- ERR_FAIL_COND(!item);
- _node_add((VisualServer::ShaderNodeType)(int)item->get_metadata(0));
- add_popup->hide() ;
+void ShaderGraphView::_bind_methods() {
+
+ ObjectTypeDB::bind_method("_update_graph",&ShaderGraphView::_update_graph);
+ ObjectTypeDB::bind_method("_node_moved",&ShaderGraphView::_node_moved);
+ ObjectTypeDB::bind_method("_move_node",&ShaderGraphView::_move_node);
+ ObjectTypeDB::bind_method("_node_removed",&ShaderGraphView::_node_removed);
+ ObjectTypeDB::bind_method("_connection_request",&ShaderGraphView::_connection_request);
+ ObjectTypeDB::bind_method("_disconnection_request",&ShaderGraphView::_disconnection_request);
+
+ ObjectTypeDB::bind_method("_scalar_const_changed",&ShaderGraphView::_scalar_const_changed);
+ ObjectTypeDB::bind_method("_vec_const_changed",&ShaderGraphView::_vec_const_changed);
+ ObjectTypeDB::bind_method("_rgb_const_changed",&ShaderGraphView::_rgb_const_changed);
+ ObjectTypeDB::bind_method("_xform_const_changed",&ShaderGraphView::_xform_const_changed);
+ ObjectTypeDB::bind_method("_scalar_op_changed",&ShaderGraphView::_scalar_op_changed);
+ ObjectTypeDB::bind_method("_vec_op_changed",&ShaderGraphView::_vec_op_changed);
+ ObjectTypeDB::bind_method("_vec_scalar_op_changed",&ShaderGraphView::_vec_scalar_op_changed);
+ ObjectTypeDB::bind_method("_rgb_op_changed",&ShaderGraphView::_rgb_op_changed);
+ ObjectTypeDB::bind_method("_xform_inv_rev_changed",&ShaderGraphView::_xform_inv_rev_changed);
+ ObjectTypeDB::bind_method("_scalar_func_changed",&ShaderGraphView::_scalar_func_changed);
+ ObjectTypeDB::bind_method("_vec_func_changed",&ShaderGraphView::_vec_func_changed);
+ ObjectTypeDB::bind_method("_scalar_input_changed",&ShaderGraphView::_scalar_input_changed);
+ ObjectTypeDB::bind_method("_vec_input_changed",&ShaderGraphView::_vec_input_changed);
+ ObjectTypeDB::bind_method("_xform_input_changed",&ShaderGraphView::_xform_input_changed);
+ ObjectTypeDB::bind_method("_rgb_input_changed",&ShaderGraphView::_rgb_input_changed);
+ ObjectTypeDB::bind_method("_tex_input_change",&ShaderGraphView::_tex_input_change);
+ ObjectTypeDB::bind_method("_cube_input_change",&ShaderGraphView::_cube_input_change);
+ ObjectTypeDB::bind_method("_input_name_changed",&ShaderGraphView::_input_name_changed);
+ ObjectTypeDB::bind_method("_tex_edited",&ShaderGraphView::_tex_edited);
+ ObjectTypeDB::bind_method("_variant_edited",&ShaderGraphView::_variant_edited);
+ ObjectTypeDB::bind_method("_cube_edited",&ShaderGraphView::_cube_edited);
+ ObjectTypeDB::bind_method("_comment_edited",&ShaderGraphView::_comment_edited);
+
+ ObjectTypeDB::bind_method("_sg_updated",&ShaderGraphView::_sg_updated);
}
-ShaderEditor::ShaderEditor() {
-
- set_focus_mode(FOCUS_ALL);
-
- Panel* menu_panel = memnew( Panel );
- menu_panel->set_anchor( MARGIN_RIGHT, Control::ANCHOR_END );
- menu_panel->set_end( Point2(0,22) );
-
- add_child( menu_panel );
-
- PopupMenu *p;
- List<PropertyInfo> defaults;
-
- MenuButton* node_menu = memnew( MenuButton );
- node_menu->set_text("Graph");
- node_menu->set_pos( Point2( 5,0) );
- menu_panel->add_child( node_menu );
-
- p=node_menu->get_popup();
- p->add_item("Add Node",GRAPH_ADD_NODE);
- p->add_separator();
- p->add_item("Clear",GRAPH_CLEAR);
- p->connect("item_pressed", this,"_node_menu_item");
-
- MenuButton* vertex_menu = memnew( MenuButton );
- vertex_menu->set_text("Vertex");
- vertex_menu->set_pos( Point2( 49,0) );
- menu_panel->add_child( vertex_menu );
-
- p=vertex_menu->get_popup();
- defaults.clear();
- VisualServer::shader_get_default_input_nodes(VisualServer::SHADER_VERTEX,&defaults);
-
- int id=0;
- for(int i=0;i<defaults.size();i++) {
-
- p->add_item("In: "+defaults[i].name+(defaults[i].type==Variant::VECTOR3?" (vec3)":" (real)"),id++);
- }
- p->add_separator();
- id++;
-
- defaults.clear();
- VisualServer::shader_get_default_output_nodes(VisualServer::SHADER_VERTEX,&defaults);
-
- for(int i=0;i<defaults.size();i++) {
-
- p->add_item("Out: "+defaults[i].name+(defaults[i].type==Variant::VECTOR3?" (vec3)":" (real)"),id++);
- }
+ShaderGraphView::ShaderGraphView(ShaderGraph::ShaderType p_type) {
+
+ type=p_type;
+ graph_edit = memnew( GraphEdit );
+ block_update=false;
+ ped_popup = memnew( CustomPropertyEditor );
+ graph_edit->add_child(ped_popup);
+ status = memnew( Label );
+ graph_edit->get_top_layer()->add_child(status);
+ status->set_pos(Vector2(5,5));
+ status->add_color_override("font_color_shadow",Color(0,0,0));
+ status->add_color_override("font_color",Color(1,0.4,0.3));
+ status->add_constant_override("shadow_as_outline",1);
+ status->add_constant_override("shadow_offset_x",2);
+ status->add_constant_override("shadow_offset_y",2);
+ status->set_text("");
+}
- vertex_popup=p;
- vertex_popup->connect("item_pressed", this,"_vertex_item");
- MenuButton* fragment_menu = memnew( MenuButton );
- fragment_menu->set_text("Fragment");
- fragment_menu->set_pos( Point2( 95 ,0) );
- menu_panel->add_child( fragment_menu );
- p=fragment_menu->get_popup();
- defaults.clear();
- VisualServer::shader_get_default_input_nodes(VisualServer::SHADER_FRAGMENT,&defaults);
- id=0;
- for(int i=0;i<defaults.size();i++) {
+//////////////edit//////////////
+void ShaderGraphEditor::edit(Ref<ShaderGraph> p_shader) {
- p->add_item("In: "+defaults[i].name+(defaults[i].type==Variant::VECTOR3?" (vec3)":" (real)"),id++);
+ for(int i=0;i<ShaderGraph::SHADER_TYPE_MAX;i++) {
+ graph_edits[i]->set_graph(p_shader);
}
- p->add_separator();
- id++;
- defaults.clear();
- VisualServer::shader_get_default_output_nodes(VisualServer::SHADER_FRAGMENT,&defaults);
+}
- for(int i=0;i<defaults.size();i++) {
+void ShaderGraphEditor::_add_node(int p_type) {
- p->add_item("Out: "+defaults[i].name+(defaults[i].type==Variant::VECTOR3?" (vec3)":" (real)"),id++);
- }
+ ShaderGraph::ShaderType shader_type=ShaderGraph::ShaderType(tabs->get_current_tab());
- fragment_popup=p;
- fragment_popup->connect("item_pressed", this,"_fragment_item");
+ graph_edits[shader_type]->add_node(p_type);
+}
- MenuButton* post_menu = memnew( MenuButton );
- post_menu->set_text("Post");
- post_menu->set_pos( Point2( 161,0) );
- menu_panel->add_child( post_menu );
- p=post_menu->get_popup();
- defaults.clear();
- VisualServer::shader_get_default_input_nodes(VisualServer::SHADER_POST_PROCESS,&defaults);
- id=0;
- for(int i=0;i<defaults.size();i++) {
+void ShaderGraphEditor::_notification(int p_what) {
+ if (p_what==NOTIFICATION_ENTER_TREE) {
- p->add_item("In: "+defaults[i].name+(defaults[i].type==Variant::VECTOR3?" (vec3)":" (real)"),id++);
- }
- p->add_separator();
- id++;
+ for(int i=0;i<ShaderGraph::NODE_TYPE_MAX;i++) {
- defaults.clear();
- VisualServer::shader_get_default_output_nodes(VisualServer::SHADER_POST_PROCESS,&defaults);
+ if (i==ShaderGraph::NODE_OUTPUT)
+ continue;
+ String nn = node_names[i];
+ String ic = nn.get_slice(":",0);
+ String v = nn.get_slice(":",1);
+ bool addsep=false;
+ if (nn.ends_with(":")) {
+ addsep=true;
+ }
+ menu->get_popup()->add_icon_item(get_icon(ic,"EditorIcons"),v,i);
+ if (addsep)
+ menu->get_popup()->add_separator();
+ }
+ menu->get_popup()->connect("item_pressed",this,"_add_node");
- for(int i=0;i<defaults.size();i++) {
- p->add_item("Out: "+defaults[i].name+(defaults[i].type==Variant::VECTOR3?" (vec3)":" (real)"),id++);
}
+}
- post_popup=p;
- post_popup->connect("item_pressed", this,"_post_item");
-
-
- /* add popup */
-
- add_popup = memnew( Popup );
- add_child(add_popup);
- add_popup->set_as_toplevel(true);
- Panel *add_panel = memnew( Panel );
- add_popup->add_child(add_panel);
- add_panel->set_area_as_parent_rect();
+void ShaderGraphEditor::_bind_methods() {
- Label *add_label = memnew (Label );
- add_label->set_pos(Point2(5,5));
- add_label->set_text("Available Nodes:");
- add_panel->add_child(add_label);
+ ObjectTypeDB::bind_method("_add_node",&ShaderGraphEditor::_add_node);
+}
- add_types = memnew( Tree );
- add_types->set_anchor( MARGIN_RIGHT, ANCHOR_END );
- add_types->set_anchor( MARGIN_BOTTOM, ANCHOR_END );
- add_types->set_begin( Point2( 20,25 ) );
- add_types->set_end( Point2( 10, 30 ) );
- add_types->set_hide_root(true);
- add_types->set_columns(4);
- add_types->set_select_mode(Tree::SELECT_ROW);
+const char* ShaderGraphEditor::node_names[ShaderGraph::NODE_TYPE_MAX]={
+ "GraphInput:Input", // all inputs (shader type dependent)
+ "GraphScalar:Scalar Constant", //scalar constant
+ "GraphVector:Vector Constant", //vec3 constant
+ "GraphRgb:RGB Constant", //rgb constant (shows a color picker instead)
+ "GraphXform:XForm Constant", // 4x4 matrix constant
+ "GraphTime:Time:", // time in seconds
+ "GraphTexscreen:Screen Sample", // screen texture sampler (takes uv) (only usable in fragment shader)
+ "GraphScalarOp:Scalar Operator", // scalar vs scalar op (mul", add", div", etc)
+ "GraphVecOp:Vector Operator", // vec3 vs vec3 op (mul",ad",div",crossprod",etc)
+ "GraphVecScalarOp:Scalar+Vector Operator", // vec3 vs scalar op (mul", add", div", etc)
+ "GraphRgbOp:RGB Operator:", // vec3 vs vec3 rgb op (with scalar amount)", like brighten", darken", burn", dodge", multiply", etc.
+ "GraphXformMult:XForm Multiply", // mat4 x mat4
+ "GraphXformVecMult:XForm+Vector Multiply", // mat4 x vec3 mult (with no-translation option)
+ "GraphXformVecImult:Form+Vector InvMultiply:", // mat4 x vec3 inverse mult (with no-translation option)
+ "GraphXformScalarFunc:Scalar Function", // scalar function (sin", cos", etc)
+ "GraphXformVecFunc:Vector Function", // vector function (normalize", negate", reciprocal", rgb2hsv", hsv2rgb", etc", etc)
+ "GraphVecLength:Vector Length", // vec3 length
+ "GraphVecDp:Dot Product:", // vec3 . vec3 (dot product -> scalar output)
+ "GraphVecToScalars:Vector -> Scalars", // 1 vec3 input", 3 scalar outputs
+ "GraphScalarsToVec:Scalars -> Vector", // 3 scalar input", 1 vec3 output
+ "GraphXformToVecs:XForm -> Vectors", // 3 vec input", 1 xform output
+ "GraphVecsToXform:Vectors -> XForm:", // 3 vec input", 1 xform output
+ "GraphScalarInterp:Scalar Interpolate", // scalar interpolation (with optional curve)
+ "GraphVecInterp:Vector Interpolate:", // vec3 interpolation (with optional curve)
+ "GraphScalarUniform:Scalar Uniform", // scalar uniform (assignable in material)
+ "GraphVectorUniform:Vector Uniform", // vec3 uniform (assignable in material)
+ "GraphRgbUniform:RGB Uniform", // color uniform (assignable in material)
+ "GraphXformUniform:XForm Uniform", // mat4 uniform (assignable in material)
+ "GraphTextureUniform:Texture Uniform", // texture input (assignable in material)
+ "GraphCubeUniform:CubeMap Uniform:", // cubemap input (assignable in material)
+ "Output", // output (shader type dependent)
+ "GraphComment:Comment", // comment
- TreeItem *add_types_root = add_types->create_item(NULL);
- TreeItem *info_item = add_types->create_item(add_types_root);
- for(int i=0;i<VisualServer::NODE_TYPE_MAX;i++) {
+};
+ShaderGraphEditor::ShaderGraphEditor() {
+
+ HBoxContainer *hbc = memnew( HBoxContainer );
+ menu = memnew( MenuButton );
+ menu->set_text("Add Node..");
+ hbc->add_child(menu);
+ add_child(hbc);
+
+
+ tabs = memnew(TabContainer);
+ tabs->set_v_size_flags(SIZE_EXPAND_FILL);
+ add_child(tabs);
+ const char* sname[ShaderGraph::SHADER_TYPE_MAX]={
+ "Vertex",
+ "Fragment",
+ "Light"
+ };
+ for(int i=0;i<ShaderGraph::SHADER_TYPE_MAX;i++) {
+
+ graph_edits[i]= memnew( ShaderGraphView(ShaderGraph::ShaderType(i)) );
+ add_child(graph_edits[i]);
+ graph_edits[i]->get_graph_edit()->set_name(sname[i]);
+ tabs->add_child(graph_edits[i]->get_graph_edit());
+ graph_edits[i]->get_graph_edit()->connect("connection_request",graph_edits[i],"_connection_request");
+ graph_edits[i]->get_graph_edit()->connect("disconnection_request",graph_edits[i],"_disconnection_request");
+ graph_edits[i]->get_graph_edit()->set_right_disconnects(true);
- TreeItem *item = add_types->create_item(add_types_root);
- PropertyInfo prop = VisualServer::shader_node_get_type_info((VisualServer::ShaderNodeType)i);
- item->set_text(0,prop.name);
- item->set_text(1,itos(VisualServer::shader_get_input_count((VisualServer::ShaderNodeType)i)));
- item->set_text(2,itos(VisualServer::shader_get_output_count((VisualServer::ShaderNodeType)i)));
- String hint = (prop.type==Variant::_RID)?prop.hint_string:Variant::get_type_name(prop.type);
- item->set_text(3,hint);
- item->set_metadata(0,i);
}
- info_item->set_text(0,"::NODE::");
- info_item->set_custom_color(0,Color(0.6,0.1,0.1));
- info_item->set_text(1,"::INPUTS::");
- info_item->set_custom_color(1,Color(0.6,0.1,0.1));
- info_item->set_text(2,"::OUTPUTS::");
- info_item->set_custom_color(2,Color(0.6,0.1,0.1));
- info_item->set_text(3,"::PARAM::");
- info_item->set_custom_color(3,Color(0.6,0.1,0.1));
- info_item->set_selectable(0,false);
- info_item->set_selectable(1,false);
- info_item->set_selectable(2,false);
- info_item->set_selectable(3,false);
-
- add_panel->add_child(add_types);
-
- add_confirm = memnew( Button );
- add_confirm->set_anchor( MARGIN_LEFT, ANCHOR_END );
- add_confirm->set_anchor( MARGIN_TOP, ANCHOR_END );
- add_confirm->set_anchor( MARGIN_RIGHT, ANCHOR_END );
- add_confirm->set_anchor( MARGIN_BOTTOM, ANCHOR_END );
- add_confirm->set_begin( Point2( 75, 29 ) );
- add_confirm->set_end( Point2( 10, 15 ) );
- add_confirm->set_text("Add");
- add_panel->add_child(add_confirm);
- add_confirm->connect("pressed", this,"_node_add_callback");
-
- last_id=1;
- last_x=20;
- last_y=20;
-
- property_editor = memnew( CustomPropertyEditor );
- add_child(property_editor);
- property_editor->connect("variant_changed", this,"_node_param_changed");
-
- h_scroll = memnew( HScrollBar );
- v_scroll = memnew( VScrollBar );
-
- add_child(h_scroll);
- add_child(v_scroll);
-
- h_scroll->connect("value_changed", this,"_scroll_moved");
- v_scroll->connect("value_changed", this,"_scroll_moved");
-
- node_popup= memnew(PopupMenu );
- add_child(node_popup);
- node_popup->set_as_toplevel(true);
-
- node_popup->connect("item_pressed", this,"_node_menu_item");
+ tabs->set_current_tab(1);
+
+ set_custom_minimum_size(Size2(100,300));
}
-void ShaderEditorPlugin::edit(Object *p_object) {
+void ShaderGraphEditorPlugin::edit(Object *p_object) {
- shader_editor->edit(p_object->cast_to<Shader>());
+ shader_editor->edit(p_object->cast_to<ShaderGraph>());
}
-bool ShaderEditorPlugin::handles(Object *p_object) const {
+bool ShaderGraphEditorPlugin::handles(Object *p_object) const {
- return p_object->is_type("Shader");
+ return p_object->is_type("ShaderGraph");
}
-void ShaderEditorPlugin::make_visible(bool p_visible) {
+void ShaderGraphEditorPlugin::make_visible(bool p_visible) {
if (p_visible) {
shader_editor->show();
- shader_editor->set_process(true);
} else {
shader_editor->hide();
- shader_editor->set_process(false);
}
}
-ShaderEditorPlugin::ShaderEditorPlugin(EditorNode *p_node) {
+ShaderGraphEditorPlugin::ShaderGraphEditorPlugin(EditorNode *p_node) {
editor=p_node;
- shader_editor = memnew( ShaderEditor );
- editor->get_viewport()->add_child(shader_editor);
- shader_editor->set_area_as_parent_rect();
+ shader_editor = memnew( ShaderGraphEditor );
shader_editor->hide();
+ SpatialEditor::get_singleton()->get_shader_split()->add_child(shader_editor);
+// editor->get_viewport()->add_child(shader_editor);
+// shader_editor->set_area_as_parent_rect();
+// shader_editor->hide();
}
-ShaderEditorPlugin::~ShaderEditorPlugin()
+ShaderGraphEditorPlugin::~ShaderGraphEditorPlugin()
{
}
-#endif
+
diff --git a/tools/editor/plugins/shader_graph_editor_plugin.h b/tools/editor/plugins/shader_graph_editor_plugin.h
index 5b0767dc82..bd983c59be 100644
--- a/tools/editor/plugins/shader_graph_editor_plugin.h
+++ b/tools/editor/plugins/shader_graph_editor_plugin.h
@@ -29,122 +29,124 @@
#ifndef SHADER_GRAPH_EDITOR_PLUGIN_H
#define SHADER_GRAPH_EDITOR_PLUGIN_H
-#if 0
+
#include "tools/editor/editor_plugin.h"
#include "tools/editor/editor_node.h"
#include "scene/resources/shader.h"
#include "servers/visual/shader_graph.h"
#include "scene/gui/tree.h"
#include "scene/gui/button.h"
+#include "scene/gui/graph_edit.h"
#include "scene/gui/popup.h"
#include "tools/editor/property_editor.h"
+#include "scene/resources/shader_graph.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
-class ShaderEditor : public Control {
-
- OBJ_TYPE(ShaderEditor, Control );
-
- enum MenuAction {
-
- GRAPH_ADD_NODE,
- GRAPH_CLEAR,
- NODE_DISCONNECT,
- NODE_ERASE,
-
- };
-
- enum ClickType {
- CLICK_NONE,
- CLICK_NODE,
- CLICK_INPUT_SLOT,
- CLICK_OUTPUT_SLOT,
- CLICK_PARAMETER
- };
-
- PopupMenu *node_popup;
- Popup *add_popup;
- PopupMenu *vertex_popup;
- PopupMenu *fragment_popup;
- PopupMenu *post_popup;
- Tree *add_types;
- Button *add_confirm;
- HScrollBar *h_scroll;
- VScrollBar *v_scroll;
-
- Ref<Shader> shader;
- List<int> order;
- Set<int> active_nodes;
- ShaderGraph shader_graph;
- int last_x,last_y;
- uint32_t last_id;
-
- CustomPropertyEditor *property_editor;
-
- Point2 offset;
- ClickType click_type;
- Point2 click_pos;
- int click_node;
- int click_slot;
- Point2 click_motion;
- ClickType rclick_type;
- int rclick_node;
- int rclick_slot;
-
- Size2 _get_maximum_size();
- Size2 get_node_size(int p_node) const;
- void _draw_node(int p_node);
-
- void _add_node_from_text(const String& p_text);
- void _update_scrollbars();
- void _scroll_moved();
- void _node_param_changed();
- void _node_add_callback();
- void _node_add(VisualServer::ShaderNodeType p_type);
- void _node_edit_property(int p_node);
- void _node_menu_item(int p_item);
- void _vertex_item(int p_item);
- void _fragment_item(int p_item);
- void _post_item(int p_item);
-
- ClickType _locate_click(const Point2& p_click,int *p_node_id,int *p_slot_index) const;
- Point2 _get_slot_pos(int p_node_id,bool p_input,int p_slot);
-
- Error validate_graph();
-
- void _read_shader_graph();
- void _write_shader_graph();
-
- virtual bool has_point(const Point2& p_point) const;
+
+class ShaderGraphView : public Node {
+
+ OBJ_TYPE(ShaderGraphView,Node);
+
+
+
+ CustomPropertyEditor *ped_popup;
+ bool block_update;
+
+ Label *status;
+ GraphEdit *graph_edit;
+ Ref<ShaderGraph> graph;
+ int edited_id;
+
+ ShaderGraph::ShaderType type;
+
+ void _update_graph();
+ void _create_node(int p_id);
+
+
+
+ void _connection_request(const String& p_from, int p_from_slot,const String& p_to,int p_to_slot);
+ void _disconnection_request(const String& p_from, int p_from_slot,const String& p_to,int p_to_slot);
+
+ void _node_removed(int p_id);
+ void _node_moved(const Vector2& p_from, const Vector2& p_to,int p_id);
+ void _move_node(int p_id,const Vector2& p_to);
+
+ void _scalar_const_changed(double p_value,int p_id);
+ void _vec_const_changed(double p_value, int p_id, Array p_arr);
+ void _rgb_const_changed(const Color& p_color, int p_id);
+ void _xform_const_changed(int p_id,Node* p_button);
+ void _scalar_op_changed(int p_op, int p_id);
+ void _vec_op_changed(int p_op, int p_id);
+ void _vec_scalar_op_changed(int p_op, int p_id);
+ void _rgb_op_changed(int p_op, int p_id);
+ void _xform_inv_rev_changed(bool p_enabled, int p_id);
+ void _scalar_func_changed(int p_func, int p_id);
+ void _vec_func_changed(int p_func, int p_id);
+ void _scalar_input_changed(double p_value,int p_id);
+ void _vec_input_changed(double p_value, int p_id, Array p_arr);
+ void _xform_input_changed(int p_id,Node* p_button);
+ void _rgb_input_changed(const Color& p_color, int p_id);
+ void _tex_input_change(int p_id,Node* p_button);
+ void _cube_input_change(int p_id);
+ void _input_name_changed(const String& p_name,int p_id,Node* p_line_edit);
+ void _tex_edited(int p_id,Node* p_button);
+ void _cube_edited(int p_id,Node* p_button);
+ void _variant_edited();
+ void _comment_edited(int p_id,Node* p_button);
+
+ void _sg_updated();
+ Map<int,GraphNode*> node_map;
protected:
void _notification(int p_what);
- void _input_event(InputEvent p_event);
static void _bind_methods();
public:
- void edit(Ref<Shader> p_shader);
- ShaderEditor();
+ void add_node(int p_type);
+ GraphEdit *get_graph_edit() { return graph_edit; }
+ void set_graph(Ref<ShaderGraph> p_graph);
+
+ ShaderGraphView(ShaderGraph::ShaderType p_type=ShaderGraph::SHADER_TYPE_FRAGMENT);
};
-class ShaderEditorPlugin : public EditorPlugin {
+class ShaderGraphEditor : public VBoxContainer {
- OBJ_TYPE( ShaderEditorPlugin, EditorPlugin );
+ OBJ_TYPE(ShaderGraphEditor,VBoxContainer);
- ShaderEditor *shader_editor;
+ MenuButton *menu;
+ TabContainer *tabs;
+ ShaderGraphView *graph_edits[ShaderGraph::SHADER_TYPE_MAX];
+ static const char* node_names[ShaderGraph::NODE_TYPE_MAX];
+
+ void _add_node(int p_type);
+protected:
+ void _notification(int p_what);
+ static void _bind_methods();
+public:
+
+ void edit(Ref<ShaderGraph> p_shader);
+ ShaderGraphEditor();
+};
+
+class ShaderGraphEditorPlugin : public EditorPlugin {
+
+ OBJ_TYPE( ShaderGraphEditorPlugin, EditorPlugin );
+
+ ShaderGraphEditor *shader_editor;
EditorNode *editor;
public:
- virtual String get_name() const { return "Shader"; }
+ virtual String get_name() const { return "ShaderGraph"; }
bool has_main_screen() const { return false; }
virtual void edit(Object *p_node);
virtual bool handles(Object *p_node) const;
virtual void make_visible(bool p_visible);
- ShaderEditorPlugin(EditorNode *p_node);
- ~ShaderEditorPlugin();
+ ShaderGraphEditorPlugin(EditorNode *p_node);
+ ~ShaderGraphEditorPlugin();
};
#endif
-#endif // SHADER_GRAPH_EDITOR_PLUGIN_H
+
diff --git a/tools/editor/plugins/spatial_editor_plugin.cpp b/tools/editor/plugins/spatial_editor_plugin.cpp
index a1f1ccf5e3..87bd8105af 100644
--- a/tools/editor/plugins/spatial_editor_plugin.cpp
+++ b/tools/editor/plugins/spatial_editor_plugin.cpp
@@ -535,6 +535,14 @@ SpatialEditorViewport::NavigationScheme SpatialEditorViewport::_get_navigation_s
return NAVIGATION_GODOT;
}
+SpatialEditorViewport::NavigationZoomStyle SpatialEditorViewport::_get_navigation_zoom_style(const String& p_property) {
+ switch(EditorSettings::get_singleton()->get(p_property).operator int()) {
+ case 0: return NAVIGATION_ZOOM_VERTICAL;
+ case 1: return NAVIGATION_ZOOM_HORIZONTAL;
+ }
+ return NAVIGATION_ZOOM_VERTICAL;
+}
+
bool SpatialEditorViewport::_gizmo_select(const Vector2& p_screenpos,bool p_hilite_only) {
if (!spatial_editor->is_gizmo_visible())
@@ -1429,10 +1437,19 @@ void SpatialEditorViewport::_sinput(const InputEvent &p_event) {
if (nav_scheme==NAVIGATION_MAYA && m.mod.shift)
zoom_speed *= zoom_speed_modifier;
- if ( m.relative_y > 0)
- cursor.distance*=1+m.relative_y*zoom_speed;
- else if (m.relative_y < 0)
- cursor.distance/=1-m.relative_y*zoom_speed;
+ NavigationZoomStyle zoom_style = _get_navigation_zoom_style("3d_editor/zoom_style");
+ if (zoom_style == NAVIGATION_ZOOM_HORIZONTAL) {
+ if ( m.relative_x > 0)
+ cursor.distance*=1-m.relative_x*zoom_speed;
+ else if (m.relative_x < 0)
+ cursor.distance/=1+m.relative_x*zoom_speed;
+ }
+ else {
+ if ( m.relative_y > 0)
+ cursor.distance*=1+m.relative_y*zoom_speed;
+ else if (m.relative_y < 0)
+ cursor.distance/=1-m.relative_y*zoom_speed;
+ }
} break;
@@ -3633,12 +3650,12 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) {
p->add_check_item("Use Default sRGB",MENU_VIEW_USE_DEFAULT_SRGB);
p->add_separator();
- p->add_check_item("1 Viewport",MENU_VIEW_USE_1_VIEWPORT,KEY_MASK_ALT+KEY_1);
- p->add_check_item("2 Viewports",MENU_VIEW_USE_2_VIEWPORTS,KEY_MASK_ALT+KEY_2);
- p->add_check_item("2 Viewports (Alt)",MENU_VIEW_USE_2_VIEWPORTS_ALT,KEY_MASK_SHIFT+KEY_MASK_ALT+KEY_2);
- p->add_check_item("3 Viewports",MENU_VIEW_USE_3_VIEWPORTS,KEY_MASK_ALT+KEY_3);
- p->add_check_item("3 Viewports (Alt)",MENU_VIEW_USE_3_VIEWPORTS_ALT,KEY_MASK_SHIFT+KEY_MASK_ALT+KEY_3);
- p->add_check_item("4 Viewports",MENU_VIEW_USE_4_VIEWPORTS,KEY_MASK_ALT+KEY_4);
+ p->add_check_item("1 Viewport",MENU_VIEW_USE_1_VIEWPORT,KEY_MASK_CMD+KEY_1);
+ p->add_check_item("2 Viewports",MENU_VIEW_USE_2_VIEWPORTS,KEY_MASK_CMD+KEY_2);
+ p->add_check_item("2 Viewports (Alt)",MENU_VIEW_USE_2_VIEWPORTS_ALT,KEY_MASK_SHIFT+KEY_MASK_CMD+KEY_2);
+ p->add_check_item("3 Viewports",MENU_VIEW_USE_3_VIEWPORTS,KEY_MASK_CMD+KEY_3);
+ p->add_check_item("3 Viewports (Alt)",MENU_VIEW_USE_3_VIEWPORTS_ALT,KEY_MASK_SHIFT+KEY_MASK_CMD+KEY_3);
+ p->add_check_item("4 Viewports",MENU_VIEW_USE_4_VIEWPORTS,KEY_MASK_CMD+KEY_4);
p->add_separator();
p->add_check_item("Display Normal",MENU_VIEW_DISPLAY_NORMAL);
diff --git a/tools/editor/plugins/spatial_editor_plugin.h b/tools/editor/plugins/spatial_editor_plugin.h
index 1fdc97c49d..646a4d2d86 100644
--- a/tools/editor/plugins/spatial_editor_plugin.h
+++ b/tools/editor/plugins/spatial_editor_plugin.h
@@ -144,6 +144,12 @@ private:
};
NavigationScheme _get_navigation_schema(const String& p_property);
+ enum NavigationZoomStyle {
+ NAVIGATION_ZOOM_VERTICAL,
+ NAVIGATION_ZOOM_HORIZONTAL
+ };
+ NavigationZoomStyle _get_navigation_zoom_style(const String& p_property);
+
enum NavigationMode {
NAVIGATION_NONE,
NAVIGATION_PAN,
diff --git a/tools/editor/plugins/tile_map_editor_plugin.cpp b/tools/editor/plugins/tile_map_editor_plugin.cpp
index a25997108b..a7e6a0d1f9 100644
--- a/tools/editor/plugins/tile_map_editor_plugin.cpp
+++ b/tools/editor/plugins/tile_map_editor_plugin.cpp
@@ -42,7 +42,6 @@ void TileMapEditor::_notification(int p_what) {
case NOTIFICATION_READY: {
- pane_drag->connect("dragged", this,"_pane_drag");
mirror_x->set_icon( get_icon("MirrorX","EditorIcons"));
mirror_y->set_icon( get_icon("MirrorY","EditorIcons"));
@@ -701,23 +700,10 @@ void TileMapEditor::_tileset_settings_changed() {
canvas_item_editor->update();
}
-void TileMapEditor::_pane_drag(const Point2& p_to) {
-
- int x = theme_panel->get_margin(MARGIN_RIGHT);
-
- x+=p_to.x;
- if (x<10)
- x=10;
- if (x>300)
- x=300;
- theme_panel->set_margin(MARGIN_RIGHT,x);
-}
-
void TileMapEditor::_bind_methods() {
ObjectTypeDB::bind_method(_MD("_menu_option"),&TileMapEditor::_menu_option);
ObjectTypeDB::bind_method(_MD("_canvas_draw"),&TileMapEditor::_canvas_draw);
- ObjectTypeDB::bind_method(_MD("_pane_drag"),&TileMapEditor::_pane_drag);
ObjectTypeDB::bind_method(_MD("_canvas_mouse_enter"),&TileMapEditor::_canvas_mouse_enter);
ObjectTypeDB::bind_method(_MD("_canvas_mouse_exit"),&TileMapEditor::_canvas_mouse_exit);
ObjectTypeDB::bind_method(_MD("_tileset_settings_changed"),&TileMapEditor::_tileset_settings_changed);
@@ -731,36 +717,31 @@ TileMapEditor::TileMapEditor(EditorNode *p_editor) {
editor=p_editor;
undo_redo = editor->get_undo_redo();
- theme_panel = memnew( Panel );
- theme_panel->set_anchor(MARGIN_BOTTOM,ANCHOR_END);
- theme_panel->set_begin( Point2(0,26));
- theme_panel->set_end( Point2(100,0) );
- p_editor->get_viewport()->add_child(theme_panel);
- theme_panel->hide();
+ int mw = EDITOR_DEF("tile_map/palette_min_width",80);
+ Control *ec = memnew( Control);
+ ec->set_custom_minimum_size(Size2(mw,0));
+ add_child(ec);
+ // Add tile palette
palette = memnew( Tree );
- palette->set_area_as_parent_rect(4);
- palette->set_margin(MARGIN_TOP,25);;
- theme_panel->add_child(palette);
-
- pane_drag = memnew( PaneDrag ) ;
- pane_drag->set_anchor(MARGIN_LEFT,ANCHOR_END);
- pane_drag->set_begin(Point2(16,4));
- theme_panel->add_child(pane_drag);
-
- add_child( memnew( VSeparator ));
+ palette->set_v_size_flags(SIZE_EXPAND_FILL);
+ add_child(palette);
+ // Add menu items
+ canvas_item_editor_hb = memnew( HBoxContainer );
+ CanvasItemEditor::get_singleton()->add_control_to_menu_panel(canvas_item_editor_hb);
+ canvas_item_editor_hb->add_child( memnew( VSeparator ));
mirror_x = memnew( ToolButton );
mirror_x->set_toggle_mode(true);
mirror_x->set_tooltip("Mirror X (A)");
mirror_x->set_focus_mode(FOCUS_NONE);
- add_child(mirror_x);
+ canvas_item_editor_hb->add_child(mirror_x);
mirror_y = memnew( ToolButton );
mirror_y->set_toggle_mode(true);
mirror_y->set_tooltip("Mirror Y (S)");
mirror_y->set_focus_mode(FOCUS_NONE);
- add_child(mirror_y);
-
+ canvas_item_editor_hb->add_child(mirror_y);
+ canvas_item_editor_hb->hide();
tool=TOOL_NONE;
selection_active=false;
@@ -782,12 +763,12 @@ void TileMapEditorPlugin::make_visible(bool p_visible) {
if (p_visible) {
tile_map_editor->show();
- tile_map_editor->theme_panel->show();
+ tile_map_editor->get_canvas_item_editor_hb()->show();
} else {
tile_map_editor->hide();
- tile_map_editor->theme_panel->hide();
+ tile_map_editor->get_canvas_item_editor_hb()->hide();
tile_map_editor->edit(NULL);
}
@@ -797,7 +778,8 @@ TileMapEditorPlugin::TileMapEditorPlugin(EditorNode *p_node) {
editor=p_node;
tile_map_editor = memnew( TileMapEditor(p_node) );
- CanvasItemEditor::get_singleton()->add_control_to_menu_panel(tile_map_editor);
+ CanvasItemEditor::get_singleton()->get_palette_split()->add_child(tile_map_editor);
+ CanvasItemEditor::get_singleton()->get_palette_split()->move_child(tile_map_editor,0);
tile_map_editor->hide();
diff --git a/tools/editor/plugins/tile_map_editor_plugin.h b/tools/editor/plugins/tile_map_editor_plugin.h
index 2336507f1b..ef869591bd 100644
--- a/tools/editor/plugins/tile_map_editor_plugin.h
+++ b/tools/editor/plugins/tile_map_editor_plugin.h
@@ -34,15 +34,14 @@
#include "scene/2d/tile_map.h"
#include "scene/gui/tool_button.h"
#include "scene/gui/button_group.h"
-#include "tools/editor/pane_drag.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
class CanvasItemEditor;
-class TileMapEditor : public HBoxContainer {
+class TileMapEditor : public VBoxContainer {
- OBJ_TYPE(TileMapEditor, BoxContainer );
+ OBJ_TYPE(TileMapEditor, VBoxContainer );
UndoRedo *undo_redo;
@@ -63,7 +62,6 @@ class TileMapEditor : public HBoxContainer {
Panel *panel;
TileMap *node;
MenuButton *options;
- PaneDrag *pane_drag;
bool selection_active;
Point2i selection_begin;
@@ -75,6 +73,8 @@ class TileMapEditor : public HBoxContainer {
ToolButton *mirror_x;
ToolButton *mirror_y;
+ HBoxContainer *canvas_item_editor_hb;
+
struct CellOp {
int idx;
@@ -88,7 +88,6 @@ class TileMapEditor : public HBoxContainer {
int get_selected_tile() const;
void _update_palette();
- void _pane_drag(const Point2& p_to);
void _canvas_draw();
void _menu_option(int p_option);
@@ -99,14 +98,13 @@ class TileMapEditor : public HBoxContainer {
void _tileset_settings_changed();
-friend class TileMapEditorPlugin;
- Panel *theme_panel;
protected:
void _notification(int p_what);
void _node_removed(Node *p_node);
static void _bind_methods();
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);
@@ -120,6 +118,7 @@ class TileMapEditorPlugin : public EditorPlugin {
TileMapEditor *tile_map_editor;
EditorNode *editor;
+
public:
virtual bool forward_input_event(const InputEvent& p_event) { return tile_map_editor->forward_input_event(p_event); }
diff --git a/tools/editor/progress_dialog.cpp b/tools/editor/progress_dialog.cpp
index ac54796c64..df40c5d5a5 100644
--- a/tools/editor/progress_dialog.cpp
+++ b/tools/editor/progress_dialog.cpp
@@ -29,7 +29,7 @@
#include "progress_dialog.h"
#include "main/main.h"
#include "message_queue.h"
-#include "scene/gui/empty_control.h"
+
void BackgroundProgress::_add_task(const String& p_task,const String& p_label, int p_steps) {
@@ -43,12 +43,12 @@ void BackgroundProgress::_add_task(const String& p_task,const String& p_label, i
t.progress = memnew( ProgressBar );
t.progress->set_max(p_steps);
t.progress->set_val(p_steps);
- EmptyControl *ec = memnew( EmptyControl );
+ Control *ec = memnew( Control );
ec->set_h_size_flags(SIZE_EXPAND_FILL);
ec->set_v_size_flags(SIZE_EXPAND_FILL);
t.progress->set_area_as_parent_rect();
ec->add_child(t.progress);
- ec->set_minsize(Size2(80,5));
+ ec->set_custom_minimum_size(Size2(80,5));
t.hb->add_child(ec);
add_child(t.hb);
diff --git a/tools/editor/project_export.cpp b/tools/editor/project_export.cpp
index 3a0f1e76b5..449e54e12f 100644
--- a/tools/editor/project_export.cpp
+++ b/tools/editor/project_export.cpp
@@ -1240,8 +1240,8 @@ ProjectExportDialog::ProjectExportDialog(EditorNode *p_editor) {
group_options->add_child(atlas_preview);
atlas_preview->show();
atlas_preview->connect("pressed",this,"_group_atlas_preview");
- EmptyControl *ec = memnew(EmptyControl );
- ec->set_minsize(Size2(150,1));
+ Control *ec = memnew(Control );
+ ec->set_custom_minimum_size(Size2(150,1));
gvb->add_child(ec);
VBoxContainer *group_vb_right = memnew( VBoxContainer );
diff --git a/tools/editor/project_export.h b/tools/editor/project_export.h
index dfe7a2d900..e437497dd2 100644
--- a/tools/editor/project_export.h
+++ b/tools/editor/project_export.h
@@ -40,7 +40,7 @@
#include "os/dir_access.h"
#include "os/thread.h"
#include "scene/gui/option_button.h"
-#include "scene/gui/empty_control.h"
+
#include "scene/gui/slider.h"
#include "tools/editor/editor_file_system.h"
#include "property_editor.h"
diff --git a/tools/editor/project_manager.cpp b/tools/editor/project_manager.cpp
index 4eadd980f4..0af4a23547 100644
--- a/tools/editor/project_manager.cpp
+++ b/tools/editor/project_manager.cpp
@@ -39,7 +39,7 @@
#include "scene/gui/line_edit.h"
#include "scene/gui/panel_container.h"
-#include "scene/gui/empty_control.h"
+
#include "scene/gui/texture_frame.h"
#include "scene/gui/margin_container.h"
#include "io/resource_saver.h"
@@ -65,7 +65,7 @@ class NewProjectDialog : public ConfirmationDialog {
error->set_text("");
get_ok()->set_disabled(true);
DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
- if (d->change_dir(project_path->get_text())!=OK) {
+ if (project_path->get_text() != "" && d->change_dir(project_path->get_text())!=OK) {
error->set_text("Invalid Path for Project, Path Must Exist!");
memdelete(d);
return false;
@@ -82,7 +82,7 @@ class NewProjectDialog : public ConfirmationDialog {
} else {
- if (!d->file_exists("engine.cfg")) {
+ if (project_path->get_text() != "" && !d->file_exists("engine.cfg")) {
error->set_text("Invalid Project Path (engine.cfg must exist).");
memdelete(d);
@@ -580,8 +580,8 @@ void ProjectManager::_load_recent_projects() {
VBoxContainer *vb = memnew(VBoxContainer);
hb->add_child(vb);
- EmptyControl *ec = memnew( EmptyControl );
- ec->set_minsize(Size2(0,1));
+ Control *ec = memnew( Control );
+ ec->set_custom_minimum_size(Size2(0,1));
vb->add_child(ec);
Label *title = memnew( Label(project_name) );
title->add_font_override("font",get_font("large","Fonts"));
diff --git a/tools/editor/property_editor.cpp b/tools/editor/property_editor.cpp
index 777694481b..a600683097 100644
--- a/tools/editor/property_editor.cpp
+++ b/tools/editor/property_editor.cpp
@@ -142,7 +142,7 @@ void CustomPropertyEditor::_menu_option(int p_which) {
}
String orig_type = res_orig->get_type();
- print_line("orig type: "+orig_type);
+
Object *inst = ObjectTypeDB::instance( orig_type );
Ref<Resource> res = Ref<Resource>( inst->cast_to<Resource>() );
@@ -187,6 +187,7 @@ void CustomPropertyEditor::_menu_option(int p_which) {
ERR_FAIL_COND( inheritors_array.empty() );
+
String intype=inheritors_array[p_which-TYPE_BASE_ID];
Object *obj = ObjectTypeDB::instance(intype);
@@ -603,6 +604,7 @@ bool CustomPropertyEditor::edit(Object* p_owner,const String& p_name,Variant::Ty
if (hint_text!="") {
+ int idx=0;
for(int i=0;i<hint_text.get_slice_count(",");i++) {
@@ -620,19 +622,19 @@ bool CustomPropertyEditor::edit(Object* p_owner,const String& p_name,Variant::Ty
E=E->next();
}
- int idx=0;
for(Set<String>::Element *E=valid_inheritors.front();E;E=E->next()) {
String t = E->get();
if (!ObjectTypeDB::can_instance(t))
continue;
inheritors_array.push_back(t);
+ int id = TYPE_BASE_ID+idx;
if (has_icon(t,"EditorIcons")) {
- menu->add_icon_item(get_icon(t,"EditorIcons"),"New "+t,TYPE_BASE_ID+idx);
+ menu->add_icon_item(get_icon(t,"EditorIcons"),"New "+t,id);
} else {
- menu->add_item("New "+t,TYPE_BASE_ID+idx);
+ menu->add_item("New "+t,id);
}
idx++;
@@ -970,9 +972,11 @@ void CustomPropertyEditor::_action_pressed(int p_which) {
if (p_which==0) {
+
ERR_FAIL_COND( inheritors_array.empty() );
String intype=inheritors_array[0];
+
if (hint==PROPERTY_HINT_RESOURCE_TYPE) {
@@ -1876,6 +1880,14 @@ void PropertyEditor::_notification(int p_what) {
if (p_what==NOTIFICATION_FIXED_PROCESS) {
+ if (refresh_countdown>0) {
+ refresh_countdown-=get_fixed_process_delta_time();
+ if (refresh_countdown<=0) {
+ TreeItem *root = tree->get_root();
+ _refresh_item(root);
+ }
+ }
+
changing=true;
if (update_tree_pending) {
@@ -1982,7 +1994,71 @@ TreeItem *PropertyEditor::get_parent_node(String p_path,HashMap<String,TreeItem*
}
+void PropertyEditor::_refresh_item(TreeItem *p_item) {
+
+ if (!p_item)
+ return;
+
+ String name = p_item->get_metadata(1);
+
+ if (name!=String()) {
+
+ if (get_instanced_node()) {
+
+ Dictionary d = get_instanced_node()->get_instance_state();
+ if (d.has(name)) {
+ Variant v = obj->get(name);
+ Variant vorig = d[name];
+
+ int found=-1;
+ for(int i=0;i<p_item->get_button_count(1);i++) {
+
+ if (p_item->get_button_id(1,i)==3) {
+ found=i;
+ break;
+ }
+ }
+
+ bool changed = ! (v==vorig);
+
+ if ((found!=-1)!=changed) {
+
+ if (changed) {
+
+ p_item->add_button(1,get_icon("Reload","EditorIcons"),3);
+ } else {
+
+ p_item->erase_button(1,found);
+ }
+
+ }
+
+ }
+
+ }
+
+ Dictionary d=p_item->get_metadata(0);
+ set_item_text(p_item,d["type"],d["name"],d["hint"],d["hint_text"]);
+ }
+
+ TreeItem *c=p_item->get_children();
+
+ while (c) {
+
+ _refresh_item(c);
+
+ c=c->get_next();
+ }
+
+}
+
+void PropertyEditor::refresh() {
+
+ if (refresh_countdown>0)
+ return;
+ refresh_countdown=EditorSettings::get_singleton()->get("property_editor/auto_refresh_interval");
+}
void PropertyEditor::update_tree() {
@@ -3021,6 +3097,7 @@ PropertyEditor::PropertyEditor() {
keying=false;
read_only=false;
show_categories=false;
+ refresh_countdown=0;
}
diff --git a/tools/editor/property_editor.h b/tools/editor/property_editor.h
index 08435ad75d..c05e13b90e 100644
--- a/tools/editor/property_editor.h
+++ b/tools/editor/property_editor.h
@@ -156,6 +156,7 @@ class PropertyEditor : public Control {
bool keying;
bool read_only;
bool show_categories;
+ float refresh_countdown;
HashMap<String,String> pending;
String selected_property;
@@ -185,6 +186,7 @@ class PropertyEditor : public Control {
void _draw_flags(Object *ti,const Rect2& p_rect);
Node *get_instanced_node();
+ void _refresh_item(TreeItem *p_item);
UndoRedo *undo_redo;
protected:
@@ -203,6 +205,8 @@ public:
void update_tree();
void update_property(const String& p_prop);
+ void refresh();
+
void edit(Object* p_object);
void set_keying(bool p_active);
diff --git a/tools/editor/scene_tree_dock.cpp b/tools/editor/scene_tree_dock.cpp
index 3455582bbc..f5d9e83bf8 100644
--- a/tools/editor/scene_tree_dock.cpp
+++ b/tools/editor/scene_tree_dock.cpp
@@ -212,17 +212,50 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
if (!_validate_no_foreign())
break;
- Node * node=scene_tree->get_selected();
- ERR_FAIL_COND(!node->get_parent());
- int current_pos = node->get_index();
- int next_pos = current_pos + ((p_tool==TOOL_MOVE_DOWN)?1:-1);
+ bool MOVING_DOWN = (p_tool == TOOL_MOVE_DOWN);
+ bool MOVING_UP = !MOVING_DOWN;
- if (next_pos< 0 || next_pos>=node->get_parent()->get_child_count())
- break; // invalid position
+ Node *common_parent = scene_tree->get_selected()->get_parent();
+ List<Node*> selection = editor_selection->get_selected_node_list();
+ selection.sort_custom<Node::Comparator>(); // sort by index
+ if (MOVING_DOWN)
+ selection.invert();
+
+ int lowest_id = common_parent->get_child_count() - 1;
+ int highest_id = 0;
+ for (List<Node*>::Element *E = selection.front(); E; E = E->next()) {
+ int index = E->get()->get_index();
+
+ if (index > highest_id) highest_id = index;
+ if (index < lowest_id) lowest_id = index;
+
+ if (E->get()->get_parent() != common_parent)
+ common_parent = NULL;
+ }
+
+ if (!common_parent || (MOVING_DOWN && highest_id >= common_parent->get_child_count() - MOVING_DOWN) || (MOVING_UP && lowest_id == 0))
+ break; // one or more nodes can not be moved
+
+ if (selection.size() == 1) editor_data->get_undo_redo().create_action("Move Node In Parent");
+ if (selection.size() > 1) editor_data->get_undo_redo().create_action("Move Nodes In Parent");
+
+ for (int i = 0; i < selection.size(); i++) {
+ Node *top_node = selection[i];
+ Node *bottom_node = selection[selection.size() - 1 - i];
+
+ ERR_FAIL_COND(!top_node->get_parent());
+ ERR_FAIL_COND(!bottom_node->get_parent());
+
+ int top_node_pos = top_node->get_index();
+ int bottom_node_pos = bottom_node->get_index();
+
+ int top_node_pos_next = top_node_pos + (MOVING_DOWN ? 1 : -1);
+ int bottom_node_pos_next = bottom_node_pos + (MOVING_DOWN ? 1 : -1);
+
+ editor_data->get_undo_redo().add_do_method(top_node->get_parent(), "move_child", top_node, top_node_pos_next);
+ editor_data->get_undo_redo().add_undo_method(bottom_node->get_parent(), "move_child", bottom_node, bottom_node_pos);
+ }
- editor_data->get_undo_redo().create_action("Move Node In Parent");
- editor_data->get_undo_redo().add_do_method(node->get_parent(),"move_child",node,next_pos);
- editor_data->get_undo_redo().add_undo_method(node->get_parent(),"move_child",node,current_pos);
editor_data->get_undo_redo().commit_action();
} break;
diff --git a/tools/editor/script_editor_debugger.cpp b/tools/editor/script_editor_debugger.cpp
index 024377ad18..5043c5cdcd 100644
--- a/tools/editor/script_editor_debugger.cpp
+++ b/tools/editor/script_editor_debugger.cpp
@@ -478,8 +478,6 @@ void ScriptEditorDebugger::_notification(int p_what) {
if (!connection->is_connected()) {
stop();
editor->notify_child_process_exited(); //somehow, exited
- msgdialog->set_text("Process being debugged exited.");
- msgdialog->popup_centered(Size2(250,100));
break;
};
diff --git a/version.py b/version.py
index 1e88d24e54..86601a22f2 100644
--- a/version.py
+++ b/version.py
@@ -2,6 +2,6 @@ short_name="godot"
name="Godot Engine"
major=1
minor=0
-status="rc2"
+status="stable"