diff options
71 files changed, 2774 insertions, 470 deletions
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index 9c484f313e..3270b33f1c 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -336,6 +336,14 @@ void _OS::set_borderless_window(bool p_borderless) { OS::get_singleton()->set_borderless_window(p_borderless); } +bool _OS::get_window_per_pixel_transparency_enabled() const { + return OS::get_singleton()->get_window_per_pixel_transparency_enabled(); +} + +void _OS::set_window_per_pixel_transparency_enabled(bool p_enabled) { + OS::get_singleton()->set_window_per_pixel_transparency_enabled(p_enabled); +} + bool _OS::get_borderless_window() const { return OS::get_singleton()->get_borderless_window(); } @@ -1068,6 +1076,9 @@ void _OS::_bind_methods() { ClassDB::bind_method(D_METHOD("set_borderless_window", "borderless"), &_OS::set_borderless_window); ClassDB::bind_method(D_METHOD("get_borderless_window"), &_OS::get_borderless_window); + ClassDB::bind_method(D_METHOD("get_window_per_pixel_transparency_enabled"), &_OS::get_window_per_pixel_transparency_enabled); + ClassDB::bind_method(D_METHOD("set_window_per_pixel_transparency_enabled", "enabled"), &_OS::set_window_per_pixel_transparency_enabled); + ClassDB::bind_method(D_METHOD("set_ime_position", "position"), &_OS::set_ime_position); ClassDB::bind_method(D_METHOD("set_screen_orientation", "orientation"), &_OS::set_screen_orientation); @@ -1185,6 +1196,7 @@ void _OS::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "screen_orientation", PROPERTY_HINT_ENUM, "Landscape,Portrait,Reverse Landscape,Reverse Portrait,Sensor Landscape,Sensor Portrait,Sensor"), "set_screen_orientation", "get_screen_orientation"); ADD_GROUP("Window", "window_"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "window_borderless"), "set_borderless_window", "get_borderless_window"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "window_per_pixel_transparency_enabled"), "set_window_per_pixel_transparency_enabled", "get_window_per_pixel_transparency_enabled"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "window_fullscreen"), "set_window_fullscreen", "is_window_fullscreen"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "window_maximized"), "set_window_maximized", "is_window_maximized"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "window_minimized"), "set_window_minimized", "is_window_minimized"); diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index 625cac25a0..a363f5970f 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -180,6 +180,9 @@ public: virtual void set_borderless_window(bool p_borderless); virtual bool get_borderless_window() const; + virtual bool get_window_per_pixel_transparency_enabled() const; + virtual void set_window_per_pixel_transparency_enabled(bool p_enabled); + virtual void set_ime_position(const Point2 &p_pos); Error native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track); diff --git a/core/io/packet_peer.cpp b/core/io/packet_peer.cpp index bd851ebb6d..b777a9f960 100644 --- a/core/io/packet_peer.cpp +++ b/core/io/packet_peer.cpp @@ -172,6 +172,7 @@ Error PacketPeerStream::_poll_buffer() const { ERR_FAIL_COND_V(peer.is_null(), ERR_UNCONFIGURED); int read = 0; + ERR_FAIL_COND_V(input_buffer.size() < ring_buffer.space_left(), ERR_UNAVAILABLE); Error err = peer->get_partial_data(&input_buffer[0], ring_buffer.space_left(), read); if (err) return err; @@ -223,6 +224,7 @@ Error PacketPeerStream::get_packet(const uint8_t **r_buffer, int &r_buffer_size) uint32_t len = decode_uint32(lbuf); ERR_FAIL_COND_V(remaining < (int)len, ERR_UNAVAILABLE); + ERR_FAIL_COND_V(input_buffer.size() < len, ERR_UNAVAILABLE); ring_buffer.read(lbuf, 4); //get rid of first 4 bytes ring_buffer.read(&input_buffer[0], len); // read packet diff --git a/core/method_bind.h b/core/method_bind.h index e02d64c935..41b500c401 100644 --- a/core/method_bind.h +++ b/core/method_bind.h @@ -128,10 +128,36 @@ struct VariantCaster<const T &> { // Object enum casts must go here VARIANT_ENUM_CAST(Object::ConnectFlags); +template <typename T> +struct VariantObjectClassChecker { + static _FORCE_INLINE_ bool check(const Variant &p_variant) { + return true; + } +}; + +template <> +struct VariantObjectClassChecker<Node *> { + static _FORCE_INLINE_ bool check(const Variant &p_variant) { + Object *obj = p_variant; + Node *node = p_variant; + return node || !obj; + } +}; + +template <> +struct VariantObjectClassChecker<Control *> { + static _FORCE_INLINE_ bool check(const Variant &p_variant) { + Object *obj = p_variant; + Control *control = p_variant; + return control || !obj; + } +}; + #define CHECK_ARG(m_arg) \ if ((m_arg - 1) < p_arg_count) { \ Variant::Type argtype = get_argument_type(m_arg - 1); \ - if (!Variant::can_convert_strict(p_args[m_arg - 1]->get_type(), argtype)) { \ + if (!Variant::can_convert_strict(p_args[m_arg - 1]->get_type(), argtype) || \ + !VariantObjectClassChecker<P##m_arg>::check(*p_args[m_arg - 1])) { \ r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT; \ r_error.argument = m_arg - 1; \ r_error.expected = argtype; \ diff --git a/core/os/os.cpp b/core/os/os.cpp index 854d554b10..5eed10e30c 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -672,6 +672,7 @@ OS::OS() { _render_thread_mode = RENDER_THREAD_SAFE; _allow_hidpi = false; + _allow_layered = false; _stack_bottom = (void *)(&stack_bottom); _logger = NULL; diff --git a/core/os/os.h b/core/os/os.h index 943c0498f1..b36f94060c 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -65,6 +65,7 @@ class OS { int _exit_code; int _orientation; bool _allow_hidpi; + bool _allow_layered; bool _use_vsync; char *last_error; @@ -102,6 +103,8 @@ public: bool maximized; bool always_on_top; bool use_vsync; + bool layered_splash; + bool layered; float get_aspect() const { return (float)width / (float)height; } VideoMode(int p_width = 1024, int p_height = 600, bool p_fullscreen = false, bool p_resizable = true, bool p_borderless_window = false, bool p_maximized = false, bool p_always_on_top = false, bool p_use_vsync = false) { width = p_width; @@ -112,6 +115,8 @@ public: maximized = p_maximized; always_on_top = p_always_on_top; use_vsync = p_use_vsync; + layered = false; + layered_splash = false; } }; @@ -220,6 +225,13 @@ public: virtual void set_borderless_window(bool p_borderless) {} virtual bool get_borderless_window() { return 0; } + virtual bool get_window_per_pixel_transparency_enabled() const { return false; } + virtual void set_window_per_pixel_transparency_enabled(bool p_enabled) {} + + virtual uint8_t *get_layered_buffer_data() { return NULL; } + virtual Size2 get_layered_buffer_size() { return Size2(0, 0); } + virtual void swap_layered_buffer() {} + virtual void set_ime_position(const Point2 &p_pos) {} virtual void set_ime_intermediate_text_callback(ImeCallback p_callback, void *p_inp) {} @@ -320,6 +332,7 @@ public: virtual void disable_crash_handler() {} virtual bool is_disable_crash_handler() const { return false; } + virtual void initialize_debugging() {} enum CursorShape { CURSOR_ARROW, @@ -480,6 +493,7 @@ public: virtual void force_process_input(){}; bool has_feature(const String &p_feature); + bool is_layered_allowed() const { return _allow_layered; } bool is_hidpi_allowed() const { return _allow_hidpi; } OS(); virtual ~OS(); diff --git a/core/script_debugger_local.cpp b/core/script_debugger_local.cpp index c0e115e300..55d7270473 100644 --- a/core/script_debugger_local.cpp +++ b/core/script_debugger_local.cpp @@ -29,12 +29,23 @@ /*************************************************************************/ #include "script_debugger_local.h" +#include "scene/main/scene_tree.h" #include "os/os.h" void ScriptDebuggerLocal::debug(ScriptLanguage *p_script, bool p_can_continue) { - print_line("Debugger Break, Reason: '" + p_script->debug_get_error() + "'"); + if (!target_function.empty()) { + String current_function = p_script->debug_get_stack_level_function(0); + if (current_function != target_function) { + set_depth(0); + set_lines_left(1); + return; + } + target_function = ""; + } + + print_line("\nDebugger Break, Reason: '" + p_script->debug_get_error() + "'"); print_line("*Frame " + itos(0) + " - " + p_script->debug_get_stack_level_source(0) + ":" + itos(p_script->debug_get_stack_level_line(0)) + " in function '" + p_script->debug_get_stack_level_function(0) + "'"); print_line("Enter \"help\" for assistance."); int current_frame = 0; @@ -44,8 +55,11 @@ void ScriptDebuggerLocal::debug(ScriptLanguage *p_script, bool p_can_continue) { OS::get_singleton()->print("debug> "); String line = OS::get_singleton()->get_stdin_string().strip_edges(); + // Cache options + String variable_prefix = options["variable_prefix"]; + if (line == "") { - print_line("Debugger Break, Reason: '" + p_script->debug_get_error() + "'"); + print_line("\nDebugger Break, Reason: '" + p_script->debug_get_error() + "'"); print_line("*Frame " + itos(current_frame) + " - " + p_script->debug_get_stack_level_source(current_frame) + ":" + itos(p_script->debug_get_stack_level_line(current_frame)) + " in function '" + p_script->debug_get_stack_level_function(current_frame) + "'"); print_line("Enter \"help\" for assistance."); } else if (line == "c" || line == "continue") @@ -72,38 +86,56 @@ void ScriptDebuggerLocal::debug(ScriptLanguage *p_script, bool p_can_continue) { } } + } else if (line.begins_with("set")) { + + if (line.get_slice_count(" ") == 1) { + + for (Map<String, String>::Element *E = options.front(); E; E = E->next()) { + print_line("\t" + E->key() + "=" + E->value()); + } + + } else { + String key_value = line.get_slicec(' ', 1); + int value_pos = key_value.find("="); + + if (value_pos < 0) { + print_line("Error: Invalid set format. Use: set key=value"); + } else { + + String key = key_value.left(value_pos); + + if (!options.has(key)) { + print_line("Error: Unknown option " + key); + } else { + + // Allow explicit tab character + String value = key_value.right(value_pos + 1).replace("\\t", "\t"); + + options[key] = value; + } + } + } + } else if (line == "lv" || line == "locals") { List<String> locals; List<Variant> values; p_script->debug_get_stack_level_locals(current_frame, &locals, &values); - List<Variant>::Element *V = values.front(); - for (List<String>::Element *E = locals.front(); E; E = E->next()) { - print_line(E->get() + ": " + String(V->get())); - V = V->next(); - } + print_variables(locals, values, variable_prefix); } else if (line == "gv" || line == "globals") { - List<String> locals; + List<String> globals; List<Variant> values; - p_script->debug_get_globals(&locals, &values); - List<Variant>::Element *V = values.front(); - for (List<String>::Element *E = locals.front(); E; E = E->next()) { - print_line(E->get() + ": " + String(V->get())); - V = V->next(); - } + p_script->debug_get_globals(&globals, &values); + print_variables(globals, values, variable_prefix); } else if (line == "mv" || line == "members") { - List<String> locals; + List<String> members; List<Variant> values; - p_script->debug_get_stack_level_members(current_frame, &locals, &values); - List<Variant>::Element *V = values.front(); - for (List<String>::Element *E = locals.front(); E; E = E->next()) { - print_line(E->get() + ": " + String(V->get())); - V = V->next(); - } + p_script->debug_get_stack_level_members(current_frame, &members, &values); + print_variables(members, values, variable_prefix); } else if (line.begins_with("p") || line.begins_with("print")) { @@ -121,65 +153,149 @@ void ScriptDebuggerLocal::debug(ScriptLanguage *p_script, bool p_can_continue) { set_depth(-1); set_lines_left(1); break; - } else if (line.begins_with("n") || line.begins_with("next")) { + } else if (line == "n" || line == "next") { set_depth(0); set_lines_left(1); break; + } else if (line == "fin" || line == "finish") { + + String current_function = p_script->debug_get_stack_level_function(0); + + for (int i = 0; i < total_frames; i++) { + target_function = p_script->debug_get_stack_level_function(i); + if (target_function != current_function) { + set_depth(0); + set_lines_left(1); + return; + } + } + + print_line("Error: Reached last frame."); + target_function = ""; + } else if (line.begins_with("br") || line.begins_with("break")) { if (line.get_slice_count(" ") <= 1) { - //show breakpoints + + const Map<int, Set<StringName> > &breakpoints = get_breakpoints(); + if (breakpoints.size() == 0) { + print_line("No Breakpoints."); + continue; + } + + print_line("Breakpoint(s): " + itos(breakpoints.size())); + for (Map<int, Set<StringName> >::Element *E = breakpoints.front(); E; E = E->next()) { + print_line("\t" + String(E->value().front()->get()) + ":" + itos(E->key())); + } + } else { - String bppos = line.get_slicec(' ', 1); - String source = bppos.get_slicec(':', 0).strip_edges(); - int line = bppos.get_slicec(':', 1).strip_edges().to_int(); + Pair<String, int> breakpoint = to_breakpoint(line); + + String source = breakpoint.first; + int linenr = breakpoint.second; - source = breakpoint_find_source(source); + if (source.empty()) + continue; - insert_breakpoint(line, source); + insert_breakpoint(linenr, source); - print_line("BreakPoint at " + source + ":" + itos(line)); + print_line("Added breakpoint at " + source + ":" + itos(linenr)); } + } else if (line == "q" || line == "quit") { + + // Do not stop again on quit + clear_breakpoints(); + ScriptDebugger::get_singleton()->set_depth(-1); + ScriptDebugger::get_singleton()->set_lines_left(-1); + + SceneTree::get_singleton()->quit(); + break; } else if (line.begins_with("delete")) { if (line.get_slice_count(" ") <= 1) { clear_breakpoints(); } else { - String bppos = line.get_slicec(' ', 1); - String source = bppos.get_slicec(':', 0).strip_edges(); - int line = bppos.get_slicec(':', 1).strip_edges().to_int(); + Pair<String, int> breakpoint = to_breakpoint(line); + + String source = breakpoint.first; + int linenr = breakpoint.second; - source = breakpoint_find_source(source); + if (source.empty()) + continue; - remove_breakpoint(line, source); + remove_breakpoint(linenr, source); - print_line("Removed BreakPoint at " + source + ":" + itos(line)); + print_line("Removed breakpoint at " + source + ":" + itos(linenr)); } } else if (line == "h" || line == "help") { print_line("Built-In Debugger command list:\n"); - print_line("\tc,continue :\t\t Continue execution."); - print_line("\tbt,backtrace :\t\t Show stack trace (frames)."); + print_line("\tc,continue\t\t Continue execution."); + print_line("\tbt,backtrace\t\t Show stack trace (frames)."); print_line("\tfr,frame <frame>:\t Change current frame."); - print_line("\tlv,locals :\t\t Show local variables for current frame."); - print_line("\tmv,members :\t\t Show member variables for \"this\" in frame."); - print_line("\tgv,globals :\t\t Show global variables."); - print_line("\tp,print <expr> :\t Execute and print variable in expression."); - print_line("\ts,step :\t\t Step to next line."); - print_line("\tn,next :\t\t Next line."); - print_line("\tbr,break source:line :\t Place a breakpoint."); - print_line("\tdelete [source:line]:\t\t Delete one/all breakpoints."); + print_line("\tlv,locals\t\t Show local variables for current frame."); + print_line("\tmv,members\t\t Show member variables for \"this\" in frame."); + print_line("\tgv,globals\t\t Show global variables."); + print_line("\tp,print <expr>\t\t Execute and print variable in expression."); + print_line("\ts,step\t\t\t Step to next line."); + print_line("\tn,next\t\t\t Next line."); + print_line("\tfin,finish\t\t Step out of current frame."); + print_line("\tbr,break [source:line]\t List all breakpoints or place a breakpoint."); + print_line("\tdelete [source:line]:\t Delete one/all breakpoints."); + print_line("\tset [key=value]:\t List all options, or set one."); + print_line("\tq,quit\t\t\t Quit application."); } else { print_line("Error: Invalid command, enter \"help\" for assistance."); } } } +void ScriptDebuggerLocal::print_variables(const List<String> &names, const List<Variant> &values, const String &variable_prefix) { + + String value; + Vector<String> value_lines; + const List<Variant>::Element *V = values.front(); + for (const List<String>::Element *E = names.front(); E; E = E->next()) { + + value = String(V->get()); + + if (variable_prefix.empty()) { + print_line(E->get() + ": " + String(V->get())); + } else { + + print_line(E->get() + ":"); + value_lines = value.split("\n"); + for (int i = 0; i < value_lines.size(); ++i) { + print_line(variable_prefix + value_lines[i]); + } + } + + V = V->next(); + } +} + +Pair<String, int> ScriptDebuggerLocal::to_breakpoint(const String &p_line) { + + String breakpoint_part = p_line.get_slicec(' ', 1); + Pair<String, int> breakpoint; + + int last_colon = breakpoint_part.rfind(":"); + if (last_colon < 0) { + print_line("Error: Invalid breakpoint format. Expected [source:line]"); + return breakpoint; + } + + breakpoint.first = breakpoint_find_source(breakpoint_part.left(last_colon).strip_edges()); + breakpoint.second = breakpoint_part.right(last_colon).strip_edges().to_int(); + + return breakpoint; +} + struct _ScriptDebuggerLocalProfileInfoSort { bool operator()(const ScriptLanguage::ProfilingInfo &A, const ScriptLanguage::ProfilingInfo &B) const { @@ -304,4 +420,5 @@ ScriptDebuggerLocal::ScriptDebuggerLocal() { profiling = false; idle_accum = OS::get_singleton()->get_ticks_usec(); + options["variable_prefix"] = ""; } diff --git a/core/script_debugger_local.h b/core/script_debugger_local.h index c87bc90bb4..7eea6ef215 100644 --- a/core/script_debugger_local.h +++ b/core/script_debugger_local.h @@ -31,6 +31,7 @@ #ifndef SCRIPT_DEBUGGER_LOCAL_H #define SCRIPT_DEBUGGER_LOCAL_H +#include "list.h" #include "script_language.h" class ScriptDebuggerLocal : public ScriptDebugger { @@ -38,9 +39,14 @@ class ScriptDebuggerLocal : public ScriptDebugger { bool profiling; float frame_time, idle_time, physics_time, physics_frame_time; uint64_t idle_accum; + String target_function; + Map<String, String> options; Vector<ScriptLanguage::ProfilingInfo> pinfo; + Pair<String, int> to_breakpoint(const String &p_line); + void print_variables(const List<String> &names, const List<Variant> &values, const String &variable_prefix); + public: void debug(ScriptLanguage *p_script, bool p_can_continue); virtual void send_message(const String &p_message, const Array &p_args); diff --git a/core/script_language.h b/core/script_language.h index 0c1f99cea6..55a20c7478 100644 --- a/core/script_language.h +++ b/core/script_language.h @@ -386,6 +386,7 @@ public: bool is_breakpoint(int p_line, const StringName &p_source) const; bool is_breakpoint_line(int p_line) const; void clear_breakpoints(); + const Map<int, Set<StringName> > &get_breakpoints() const { return breakpoints; } virtual void debug(ScriptLanguage *p_script, bool p_can_continue = true) = 0; virtual void idle_poll(); diff --git a/doc/classes/Generic6DOFJoint.xml b/doc/classes/Generic6DOFJoint.xml index 2aec6d7f4e..0863ead4ec 100644 --- a/doc/classes/Generic6DOFJoint.xml +++ b/doc/classes/Generic6DOFJoint.xml @@ -167,6 +167,33 @@ <member name="linear_limit_z/upper_distance" type="float" setter="set_param_z" getter="get_param_z"> The maximum difference between the pivot points' z-axis. </member> + <member name="linear_motor_x/enabled" type="bool" setter="set_flag_x" getter="get_flag_x"> + If [code]true[/code] then there is a linear motor on the x-axis. It will attempt to reach the target velocity while staying within the force limits. + </member> + <member name="linear_motor_x/force_limit" type="float" setter="set_param_x" getter="get_param_x"> + The maximum force the linear motor can apply on the x-axis while trying to reach the target velocity. + </member> + <member name="linear_motor_x/target_velocity" type="float" setter="set_param_x" getter="get_param_x"> + The speed that the linear motor will attempt to reach on the x-axis. + </member> + <member name="linear_motor_y/enabled" type="bool" setter="set_flag_y" getter="get_flag_y"> + If [code]true[/code] then there is a linear motor on the y-axis. It will attempt to reach the target velocity while staying within the force limits. + </member> + <member name="linear_motor_y/force_limit" type="float" setter="set_param_y" getter="get_param_y"> + The maximum force the linear motor can apply on the y-axis while trying to reach the target velocity. + </member> + <member name="linear_motor_y/target_velocity" type="float" setter="set_param_y" getter="get_param_y"> + The speed that the linear motor will attempt to reach on the y-axis. + </member> + <member name="linear_motor_z/enabled" type="bool" setter="set_flag_z" getter="get_flag_z"> + If [code]true[/code] then there is a linear motor on the z-axis. It will attempt to reach the target velocity while staying within the force limits. + </member> + <member name="linear_motor_z/force_limit" type="float" setter="set_param_z" getter="get_param_z"> + The maximum force the linear motor can apply on the z-axis while trying to reach the target velocity. + </member> + <member name="linear_motor_z/target_velocity" type="float" setter="set_param_z" getter="get_param_z"> + The speed that the linear motor will attempt to reach on the z-axis. + </member> </members> <constants> <constant name="PARAM_LINEAR_LOWER_LIMIT" value="0" enum="Param"> @@ -184,34 +211,40 @@ <constant name="PARAM_LINEAR_DAMPING" value="4" enum="Param"> The amount of damping that happens at the linear motion across the axes. </constant> - <constant name="PARAM_ANGULAR_LOWER_LIMIT" value="5" enum="Param"> + <constant name="PARAM_LINEAR_MOTOR_TARGET_VELOCITY" value="5" enum="Param"> + The velocity the linear motor will try to reach. + </constant> + <constant name="PARAM_LINEAR_MOTOR_FORCE_LIMIT" value="6" enum="Param"> + The maximum force the linear motor will apply while trying to reach the velocity target. + </constant> + <constant name="PARAM_ANGULAR_LOWER_LIMIT" value="7" enum="Param"> The minimum rotation in negative direction to break loose and rotate around the axes. </constant> - <constant name="PARAM_ANGULAR_UPPER_LIMIT" value="6" enum="Param"> + <constant name="PARAM_ANGULAR_UPPER_LIMIT" value="8" enum="Param"> The minimum rotation in positive direction to break loose and rotate around the axes. </constant> - <constant name="PARAM_ANGULAR_LIMIT_SOFTNESS" value="7" enum="Param"> + <constant name="PARAM_ANGULAR_LIMIT_SOFTNESS" value="9" enum="Param"> The speed of all rotations across the axes. </constant> - <constant name="PARAM_ANGULAR_DAMPING" value="8" enum="Param"> + <constant name="PARAM_ANGULAR_DAMPING" value="10" enum="Param"> The amount of rotational damping across the axes. The lower, the more dampening occurs. </constant> - <constant name="PARAM_ANGULAR_RESTITUTION" value="9" enum="Param"> + <constant name="PARAM_ANGULAR_RESTITUTION" value="11" enum="Param"> The amount of rotational restitution across the axes. The lower, the more restitution occurs. </constant> - <constant name="PARAM_ANGULAR_FORCE_LIMIT" value="10" enum="Param"> + <constant name="PARAM_ANGULAR_FORCE_LIMIT" value="12" enum="Param"> The maximum amount of force that can occur, when rotating around the axes. </constant> - <constant name="PARAM_ANGULAR_ERP" value="11" enum="Param"> + <constant name="PARAM_ANGULAR_ERP" value="13" enum="Param"> When rotating across the axes, this error tolerance factor defines how much the correction gets slowed down. The lower, the slower. </constant> - <constant name="PARAM_ANGULAR_MOTOR_TARGET_VELOCITY" value="12" enum="Param"> + <constant name="PARAM_ANGULAR_MOTOR_TARGET_VELOCITY" value="14" enum="Param"> Target speed for the motor at the axes. </constant> - <constant name="PARAM_ANGULAR_MOTOR_FORCE_LIMIT" value="13" enum="Param"> + <constant name="PARAM_ANGULAR_MOTOR_FORCE_LIMIT" value="15" enum="Param"> Maximum acceleration for the motor at the axes. </constant> - <constant name="PARAM_MAX" value="14" enum="Param"> + <constant name="PARAM_MAX" value="16" enum="Param"> End flag of PARAM_* constants, used internally. </constant> <constant name="FLAG_ENABLE_LINEAR_LIMIT" value="0" enum="Flag"> @@ -223,7 +256,9 @@ <constant name="FLAG_ENABLE_MOTOR" value="2" enum="Flag"> If [code]set[/code] there is a rotational motor across these axes. </constant> - <constant name="FLAG_MAX" value="3" enum="Flag"> + <constant name="FLAG_ENABLE_LINEAR_MOTOR" value="3" enum="Flag"> + </constant> + <constant name="FLAG_MAX" value="4" enum="Flag"> End flag of FLAG_* constants, used internally. </constant> </constants> diff --git a/doc/classes/PhysicsServer.xml b/doc/classes/PhysicsServer.xml index 6c3a435360..dd2c322ee3 100644 --- a/doc/classes/PhysicsServer.xml +++ b/doc/classes/PhysicsServer.xml @@ -1331,31 +1331,37 @@ <constant name="G6DOF_JOINT_LINEAR_DAMPING" value="4" enum="G6DOFJointAxisParam"> The amount of damping that happens at the linear motion across the axes. </constant> - <constant name="G6DOF_JOINT_ANGULAR_LOWER_LIMIT" value="5" enum="G6DOFJointAxisParam"> + <constant name="G6DOF_JOINT_LINEAR_MOTOR_TARGET_VELOCITY" value="5" enum="G6DOFJointAxisParam"> + The velocity that the joint's linear motor will attempt to reach. + </constant> + <constant name="G6DOF_JOINT_LINEAR_MOTOR_FORCE_LIMIT" value="6" enum="G6DOFJointAxisParam"> + The maximum force that the linear motor can apply while trying to reach the target velocity. + </constant> + <constant name="G6DOF_JOINT_ANGULAR_LOWER_LIMIT" value="7" enum="G6DOFJointAxisParam"> The minimum rotation in negative direction to break loose and rotate around the axes. </constant> - <constant name="G6DOF_JOINT_ANGULAR_UPPER_LIMIT" value="6" enum="G6DOFJointAxisParam"> + <constant name="G6DOF_JOINT_ANGULAR_UPPER_LIMIT" value="8" enum="G6DOFJointAxisParam"> The minimum rotation in positive direction to break loose and rotate around the axes. </constant> - <constant name="G6DOF_JOINT_ANGULAR_LIMIT_SOFTNESS" value="7" enum="G6DOFJointAxisParam"> + <constant name="G6DOF_JOINT_ANGULAR_LIMIT_SOFTNESS" value="9" enum="G6DOFJointAxisParam"> A factor that gets multiplied onto all rotations across the axes. </constant> - <constant name="G6DOF_JOINT_ANGULAR_DAMPING" value="8" enum="G6DOFJointAxisParam"> + <constant name="G6DOF_JOINT_ANGULAR_DAMPING" value="10" enum="G6DOFJointAxisParam"> The amount of rotational damping across the axes. The lower, the more dampening occurs. </constant> - <constant name="G6DOF_JOINT_ANGULAR_RESTITUTION" value="9" enum="G6DOFJointAxisParam"> + <constant name="G6DOF_JOINT_ANGULAR_RESTITUTION" value="11" enum="G6DOFJointAxisParam"> The amount of rotational restitution across the axes. The lower, the more restitution occurs. </constant> - <constant name="G6DOF_JOINT_ANGULAR_FORCE_LIMIT" value="10" enum="G6DOFJointAxisParam"> + <constant name="G6DOF_JOINT_ANGULAR_FORCE_LIMIT" value="12" enum="G6DOFJointAxisParam"> The maximum amount of force that can occur, when rotating around the axes. </constant> - <constant name="G6DOF_JOINT_ANGULAR_ERP" value="11" enum="G6DOFJointAxisParam"> + <constant name="G6DOF_JOINT_ANGULAR_ERP" value="13" enum="G6DOFJointAxisParam"> When correcting the crossing of limits in rotation across the axes, this error tolerance factor defines how much the correction gets slowed down. The lower, the slower. </constant> - <constant name="G6DOF_JOINT_ANGULAR_MOTOR_TARGET_VELOCITY" value="12" enum="G6DOFJointAxisParam"> + <constant name="G6DOF_JOINT_ANGULAR_MOTOR_TARGET_VELOCITY" value="14" enum="G6DOFJointAxisParam"> Target speed for the motor at the axes. </constant> - <constant name="G6DOF_JOINT_ANGULAR_MOTOR_FORCE_LIMIT" value="13" enum="G6DOFJointAxisParam"> + <constant name="G6DOF_JOINT_ANGULAR_MOTOR_FORCE_LIMIT" value="15" enum="G6DOFJointAxisParam"> Maximum acceleration for the motor at the axes. </constant> <constant name="G6DOF_JOINT_FLAG_ENABLE_LINEAR_LIMIT" value="0" enum="G6DOFJointAxisFlag"> @@ -1367,6 +1373,9 @@ <constant name="G6DOF_JOINT_FLAG_ENABLE_MOTOR" value="2" enum="G6DOFJointAxisFlag"> If [code]set[/code] there is a rotational motor across these axes. </constant> + <constant name="G6DOF_JOINT_FLAG_ENABLE_LINEAR_MOTOR" value="3" enum="G6DOFJointAxisFlag"> + If [code]set[/code] there is a linear motor on this axis that targets a specific velocity. + </constant> <constant name="SHAPE_PLANE" value="0" enum="ShapeType"> The [Shape] is a [PlaneShape]. </constant> diff --git a/drivers/gles2/rasterizer_gles2.cpp b/drivers/gles2/rasterizer_gles2.cpp index 9339167c8e..4626a5ed3c 100644 --- a/drivers/gles2/rasterizer_gles2.cpp +++ b/drivers/gles2/rasterizer_gles2.cpp @@ -316,7 +316,11 @@ void RasterizerGLES2::set_boot_image(const Ref<Image> &p_image, const Color &p_c glViewport(0, 0, window_w, window_h); glDisable(GL_BLEND); glDepthMask(GL_FALSE); - glClearColor(p_color.r, p_color.g, p_color.b, p_color.a); + if (OS::get_singleton()->get_window_per_pixel_transparency_enabled()) { + glClearColor(0.0, 0.0, 0.0, 0.0); + } else { + glClearColor(p_color.r, p_color.g, p_color.b, 1.0); + } glClear(GL_COLOR_BUFFER_BIT); canvas->canvas_begin(); @@ -340,6 +344,27 @@ void RasterizerGLES2::set_boot_image(const Ref<Image> &p_image, const Color &p_c storage->free(texture); + if (OS::get_singleton()->is_layered_allowed()) { + if (OS::get_singleton()->get_window_per_pixel_transparency_enabled()) { +#ifdef WINDOWS_ENABLED + Size2 wndsize = OS::get_singleton()->get_layered_buffer_size(); + uint8_t *data = OS::get_singleton()->get_layered_buffer_data(); + if (data) { + glReadPixels(0, 0, wndsize.x, wndsize.y, GL_BGRA, GL_UNSIGNED_BYTE, data); + OS::get_singleton()->swap_layered_buffer(); + + return; + } +#endif + } else { + //clear alpha + glColorMask(false, false, false, true); + glClearColor(0, 0, 0, 1); + glClear(GL_COLOR_BUFFER_BIT); + glColorMask(true, true, true, true); + } + } + OS::get_singleton()->swap_buffers(); } @@ -373,6 +398,28 @@ void RasterizerGLES2::blit_render_target_to_screen(RID p_render_target, const Re } void RasterizerGLES2::end_frame(bool p_swap_buffers) { + + if (OS::get_singleton()->is_layered_allowed()) { + if (OS::get_singleton()->get_window_per_pixel_transparency_enabled()) { +#ifdef WINDOWS_ENABLED + Size2 wndsize = OS::get_singleton()->get_layered_buffer_size(); + uint8_t *data = OS::get_singleton()->get_layered_buffer_data(); + if (data) { + glReadPixels(0, 0, wndsize.x, wndsize.y, GL_BGRA, GL_UNSIGNED_BYTE, data); + OS::get_singleton()->swap_layered_buffer(); + + return; + } +#endif + } else { + //clear alpha + glColorMask(false, false, false, true); + glClearColor(0, 0, 0, 1); + glClear(GL_COLOR_BUFFER_BIT); + glColorMask(true, true, true, true); + } + } + if (p_swap_buffers) OS::get_singleton()->swap_buffers(); else diff --git a/drivers/gles3/rasterizer_gles3.cpp b/drivers/gles3/rasterizer_gles3.cpp index 0fb69494f4..12e29827b0 100644 --- a/drivers/gles3/rasterizer_gles3.cpp +++ b/drivers/gles3/rasterizer_gles3.cpp @@ -290,7 +290,11 @@ void RasterizerGLES3::set_boot_image(const Ref<Image> &p_image, const Color &p_c glViewport(0, 0, window_w, window_h); glDisable(GL_BLEND); glDepthMask(GL_FALSE); - glClearColor(p_color.r, p_color.g, p_color.b, 1.0); + if (OS::get_singleton()->get_window_per_pixel_transparency_enabled()) { + glClearColor(0.0, 0.0, 0.0, 0.0); + } else { + glClearColor(p_color.r, p_color.g, p_color.b, 1.0); + } glClear(GL_COLOR_BUFFER_BIT); canvas->canvas_begin(); @@ -329,6 +333,27 @@ void RasterizerGLES3::set_boot_image(const Ref<Image> &p_image, const Color &p_c storage->free(texture); // free since it's only one frame that stays there + if (OS::get_singleton()->is_layered_allowed()) { + if (OS::get_singleton()->get_window_per_pixel_transparency_enabled()) { +#ifdef WINDOWS_ENABLED + Size2 wndsize = OS::get_singleton()->get_layered_buffer_size(); + uint8_t *data = OS::get_singleton()->get_layered_buffer_data(); + if (data) { + glReadPixels(0, 0, wndsize.x, wndsize.y, GL_BGRA, GL_UNSIGNED_BYTE, data); + OS::get_singleton()->swap_layered_buffer(); + + return; + } +#endif + } else { + //clear alpha + glColorMask(false, false, false, true); + glClearColor(0, 0, 0, 1); + glClear(GL_COLOR_BUFFER_BIT); + glColorMask(true, true, true, true); + } + } + OS::get_singleton()->swap_buffers(); } @@ -365,6 +390,27 @@ void RasterizerGLES3::blit_render_target_to_screen(RID p_render_target, const Re void RasterizerGLES3::end_frame(bool p_swap_buffers) { + if (OS::get_singleton()->is_layered_allowed()) { + if (OS::get_singleton()->get_window_per_pixel_transparency_enabled()) { +#ifdef WINDOWS_ENABLED + Size2 wndsize = OS::get_singleton()->get_layered_buffer_size(); + uint8_t *data = OS::get_singleton()->get_layered_buffer_data(); + if (data) { + glReadPixels(0, 0, wndsize.x, wndsize.y, GL_BGRA, GL_UNSIGNED_BYTE, data); + OS::get_singleton()->swap_layered_buffer(); + + return; + } +#endif + } else { + //clear alpha + glColorMask(false, false, false, true); + glClearColor(0, 0, 0, 1); + glClear(GL_COLOR_BUFFER_BIT); + glColorMask(true, true, true, true); + } + } + if (p_swap_buffers) OS::get_singleton()->swap_buffers(); else diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp index eeb3b31fc2..1e34d63b13 100644 --- a/drivers/unix/os_unix.cpp +++ b/drivers/unix/os_unix.cpp @@ -73,6 +73,23 @@ void OS_Unix::debug_break() { assert(false); }; +static void handle_interrupt(int sig) { + if (ScriptDebugger::get_singleton() == NULL) + return; + + ScriptDebugger::get_singleton()->set_depth(-1); + ScriptDebugger::get_singleton()->set_lines_left(1); +} + +void OS_Unix::initialize_debugging() { + + if (ScriptDebugger::get_singleton() != NULL) { + struct sigaction action; + action.sa_handler = handle_interrupt; + sigaction(SIGINT, &action, NULL); + } +} + int OS_Unix::unix_initialize_audio(int p_audio_driver) { return 0; diff --git a/drivers/unix/os_unix.h b/drivers/unix/os_unix.h index db0fe1e00b..95b74d23ff 100644 --- a/drivers/unix/os_unix.h +++ b/drivers/unix/os_unix.h @@ -101,6 +101,7 @@ public: virtual int get_processor_count() const; virtual void debug_break(); + virtual void initialize_debugging(); virtual String get_executable_path() const; virtual String get_user_data_dir() const; diff --git a/editor/editor_data.cpp b/editor/editor_data.cpp index b584107bcb..4ac3e33cb9 100644 --- a/editor/editor_data.cpp +++ b/editor/editor_data.cpp @@ -898,7 +898,7 @@ Array EditorSelection::_get_transformable_selected_nodes() { return ret; } -Array EditorSelection::_get_selected_nodes() { +Array EditorSelection::get_selected_nodes() { Array ret; @@ -916,7 +916,7 @@ void EditorSelection::_bind_methods() { ClassDB::bind_method(D_METHOD("clear"), &EditorSelection::clear); ClassDB::bind_method(D_METHOD("add_node", "node"), &EditorSelection::add_node); ClassDB::bind_method(D_METHOD("remove_node", "node"), &EditorSelection::remove_node); - ClassDB::bind_method(D_METHOD("get_selected_nodes"), &EditorSelection::_get_selected_nodes); + ClassDB::bind_method(D_METHOD("get_selected_nodes"), &EditorSelection::get_selected_nodes); ClassDB::bind_method(D_METHOD("get_transformable_selected_nodes"), &EditorSelection::_get_transformable_selected_nodes); ClassDB::bind_method(D_METHOD("_emit_change"), &EditorSelection::_emit_change); ADD_SIGNAL(MethodInfo("selection_changed")); diff --git a/editor/editor_data.h b/editor/editor_data.h index 5a0b58464a..f020d07ea7 100644 --- a/editor/editor_data.h +++ b/editor/editor_data.h @@ -226,7 +226,6 @@ private: List<Node *> selected_node_list; void _update_nl(); - Array _get_selected_nodes(); Array _get_transformable_selected_nodes(); void _emit_change(); @@ -234,6 +233,7 @@ protected: static void _bind_methods(); public: + Array get_selected_nodes(); void add_node(Node *p_node); void remove_node(Node *p_node); bool is_selected(Node *) const; diff --git a/editor/editor_help.cpp b/editor/editor_help.cpp index f3be02a8c7..f9b104cdae 100644 --- a/editor/editor_help.cpp +++ b/editor/editor_help.cpp @@ -526,18 +526,7 @@ void EditorHelp::_unhandled_key_input(const Ref<InputEvent> &p_ev) { void EditorHelp::_search(const String &) { - if (search->get_text() == "") - return; - - String stext = search->get_text(); - bool keep = prev_search == stext; - - bool ret = class_desc->search(stext, keep); - if (!ret) { - class_desc->search(stext, false); - } - - prev_search = stext; + find_bar->search_next(); } void EditorHelp::_class_list_select(const String &p_select) { @@ -598,14 +587,6 @@ void EditorHelp::_class_desc_select(const String &p_select) { } void EditorHelp::_class_desc_input(const Ref<InputEvent> &p_input) { - - Ref<InputEventMouseButton> mb = p_input; - - if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == 1 && !mb->is_doubleclick()) { - class_desc->set_selection_enabled(false); - class_desc->set_selection_enabled(true); - } - set_focused(); } void EditorHelp::_add_type(const String &p_type, const String &p_enum) { @@ -1816,13 +1797,7 @@ void EditorHelp::scroll_to_section(int p_section_index) { void EditorHelp::popup_search() { - search_dialog->popup_centered(Size2(250, 80) * EDSCALE); - search->grab_focus(); -} - -void EditorHelp::_search_cbk() { - - _search(search->get_text()); + find_bar->popup_search(); } String EditorHelp::get_class() { @@ -1851,7 +1826,6 @@ void EditorHelp::_bind_methods() { ClassDB::bind_method("_request_help", &EditorHelp::_request_help); ClassDB::bind_method("_unhandled_key_input", &EditorHelp::_unhandled_key_input); ClassDB::bind_method("_search", &EditorHelp::_search); - ClassDB::bind_method("_search_cbk", &EditorHelp::_search_cbk); ClassDB::bind_method("_help_callback", &EditorHelp::_help_callback); ADD_SIGNAL(MethodInfo("go_to_help")); @@ -1863,6 +1837,10 @@ EditorHelp::EditorHelp() { EDITOR_DEF("text_editor/help/sort_functions_alphabetically", true); + find_bar = memnew(FindBar); + add_child(find_bar); + find_bar->hide(); + class_desc = memnew(RichTextLabel); add_child(class_desc); class_desc->set_v_size_flags(SIZE_EXPAND_FILL); @@ -1870,24 +1848,14 @@ EditorHelp::EditorHelp() { class_desc->connect("meta_clicked", this, "_class_desc_select"); class_desc->connect("gui_input", this, "_class_desc_input"); + find_bar->set_rich_text_label(class_desc); + class_desc->set_selection_enabled(true); scroll_locked = false; select_locked = false; - set_process_unhandled_key_input(true); + //set_process_unhandled_key_input(true); class_desc->hide(); - - search_dialog = memnew(ConfirmationDialog); - add_child(search_dialog); - VBoxContainer *search_vb = memnew(VBoxContainer); - search_dialog->add_child(search_vb); - - search = memnew(LineEdit); - search_dialog->register_text_enter(search); - search_vb->add_margin_child(TTR("Search Text"), search); - search_dialog->get_ok()->set_text(TTR("Find")); - search_dialog->connect("confirmed", this, "_search_cbk"); - search_dialog->set_hide_on_ok(false); } EditorHelp::~EditorHelp() { @@ -1964,3 +1932,177 @@ EditorHelpBit::EditorHelpBit() { rich_text->set_override_selected_font_color(false); set_custom_minimum_size(Size2(0, 70 * EDSCALE)); } + +FindBar::FindBar() { + + container = memnew(Control); + add_child(container); + + container->set_clip_contents(true); + container->set_h_size_flags(SIZE_EXPAND_FILL); + + hbc = memnew(HBoxContainer); + container->add_child(hbc); + + vbc_search_text = memnew(VBoxContainer); + hbc->add_child(vbc_search_text); + vbc_search_text->set_h_size_flags(SIZE_EXPAND_FILL); + hbc->set_anchor_and_margin(MARGIN_RIGHT, 1, 0); + + search_text = memnew(LineEdit); + vbc_search_text->add_child(search_text); + search_text->set_custom_minimum_size(Size2(100 * EDSCALE, 0)); + search_text->connect("text_changed", this, "_search_text_changed"); + search_text->connect("text_entered", this, "_search_text_entered"); + + find_prev = memnew(ToolButton); + hbc->add_child(find_prev); + find_prev->set_focus_mode(FOCUS_NONE); + find_prev->connect("pressed", this, "_search_prev"); + + find_next = memnew(ToolButton); + hbc->add_child(find_next); + find_next->set_focus_mode(FOCUS_NONE); + find_next->connect("pressed", this, "_search_next"); + + error_label = memnew(Label); + hbc->add_child(error_label); + error_label->add_color_override("font_color", EditorNode::get_singleton()->get_gui_base()->get_color("error_color", "Editor")); + + hide_button = memnew(TextureButton); + add_child(hide_button); + hide_button->set_focus_mode(FOCUS_NONE); + hide_button->set_expand(true); + hide_button->set_stretch_mode(TextureButton::STRETCH_KEEP_CENTERED); + hide_button->connect("pressed", this, "_hide_pressed"); +} + +void FindBar::popup_search() { + show(); + search_text->grab_focus(); + container->set_custom_minimum_size(Size2(0, hbc->get_size().height)); +} + +void FindBar::_notification(int p_what) { + + if (p_what == NOTIFICATION_READY) { + + find_prev->set_icon(get_icon("MoveUp", "EditorIcons")); + find_next->set_icon(get_icon("MoveDown", "EditorIcons")); + hide_button->set_normal_texture(get_icon("Close", "EditorIcons")); + hide_button->set_hover_texture(get_icon("Close", "EditorIcons")); + hide_button->set_pressed_texture(get_icon("Close", "EditorIcons")); + hide_button->set_custom_minimum_size(hide_button->get_normal_texture()->get_size()); + } else if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { + + set_process_unhandled_input(is_visible_in_tree()); + } else if (p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) { + + find_prev->set_icon(get_icon("MoveUp", "EditorIcons")); + find_next->set_icon(get_icon("MoveDown", "EditorIcons")); + hide_button->set_normal_texture(get_icon("Close", "EditorIcons")); + hide_button->set_hover_texture(get_icon("Close", "EditorIcons")); + hide_button->set_pressed_texture(get_icon("Close", "EditorIcons")); + hide_button->set_custom_minimum_size(hide_button->get_normal_texture()->get_size()); + } +} + +void FindBar::_bind_methods() { + + ClassDB::bind_method("_unhandled_input", &FindBar::_unhandled_input); + + ClassDB::bind_method("_search_text_changed", &FindBar::_search_text_changed); + ClassDB::bind_method("_search_text_entered", &FindBar::_search_text_entered); + ClassDB::bind_method("_search_next", &FindBar::search_next); + ClassDB::bind_method("_search_prev", &FindBar::search_prev); + ClassDB::bind_method("_hide_pressed", &FindBar::_hide_bar); + + ADD_SIGNAL(MethodInfo("search")); +} + +void FindBar::set_rich_text_label(RichTextLabel *p_rich_text_label) { + + rich_text_label = p_rich_text_label; +} + +bool FindBar::search_next() { + + return _search(); +} + +bool FindBar::search_prev() { + + return _search(true); +} + +bool FindBar::_search(bool p_search_previous) { + + String stext = search_text->get_text(); + bool keep = prev_search == stext; + + bool ret = rich_text_label->search(stext, keep, p_search_previous); + if (!ret) { + ret = rich_text_label->search(stext, false, p_search_previous); + } + + prev_search = stext; + + if (ret) { + set_error(""); + } else { + set_error(stext.empty() ? "" : TTR("No Matches")); + } + + return ret; +} + +void FindBar::set_error(const String &p_label) { + + error_label->set_text(p_label); +} + +void FindBar::_hide_bar() { + + if (search_text->has_focus()) + rich_text_label->grab_focus(); + + hide(); +} + +void FindBar::_unhandled_input(const Ref<InputEvent> &p_event) { + + Ref<InputEventKey> k = p_event; + if (k.is_valid()) { + + if (k->is_pressed() && (rich_text_label->has_focus() || hbc->is_a_parent_of(get_focus_owner()))) { + + bool accepted = true; + + switch (k->get_scancode()) { + + case KEY_ESCAPE: { + + _hide_bar(); + } break; + default: { + + accepted = false; + } break; + } + + if (accepted) { + accept_event(); + } + } + } +} + +void FindBar::_search_text_changed(const String &p_text) { + + search_next(); +} + +void FindBar::_search_text_entered(const String &p_text) { + + search_next(); +} diff --git a/editor/editor_help.h b/editor/editor_help.h index 0f93e1b55b..35d98d274c 100644 --- a/editor/editor_help.h +++ b/editor/editor_help.h @@ -125,6 +125,50 @@ public: EditorHelpIndex(); }; +class FindBar : public HBoxContainer { + + GDCLASS(FindBar, HBoxContainer); + + LineEdit *search_text; + ToolButton *find_prev; + ToolButton *find_next; + Label *error_label; + TextureButton *hide_button; + String prev_search; + + Control *container; + HBoxContainer *hbc; + VBoxContainer *vbc_search_text; + + RichTextLabel *rich_text_label; + + void _show_search(); + void _hide_bar(); + + void _search_text_changed(const String &p_text); + void _search_text_entered(const String &p_text); + +protected: + void _notification(int p_what); + void _unhandled_input(const Ref<InputEvent> &p_event); + + bool _search(bool p_search_previous = false); + + static void _bind_methods(); + +public: + void set_error(const String &p_label); + + void set_rich_text_label(RichTextLabel *p_rich_text_label); + + void popup_search(); + + bool search_prev(); + bool search_next(); + + FindBar(); +}; + class EditorHelp : public VBoxContainer { GDCLASS(EditorHelp, VBoxContainer); @@ -161,6 +205,7 @@ class EditorHelp : public VBoxContainer { ConfirmationDialog *search_dialog; LineEdit *search; + FindBar *find_bar; String base_path; @@ -194,7 +239,6 @@ class EditorHelp : public VBoxContainer { void _request_help(const String &p_string); void _search(const String &p_str); - void _search_cbk(); void _unhandled_key_input(const Ref<InputEvent> &p_ev); diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp index 6eae7be9d5..c4e6d18163 100644 --- a/editor/editor_settings.cpp +++ b/editor/editor_settings.cpp @@ -403,10 +403,10 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) { _initial_set("editors/grid_map/pick_distance", 5000.0); _initial_set("editors/3d/primary_grid_color", Color::html("909090")); - hints["editors/3d/primary_grid_color"] = PropertyInfo(Variant::COLOR, "editors/3d/primary_grid_color", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED); + hints["editors/3d/primary_grid_color"] = PropertyInfo(Variant::COLOR, "editors/3d/primary_grid_color", PROPERTY_HINT_COLOR_NO_ALPHA, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED); _initial_set("editors/3d/secondary_grid_color", Color::html("606060")); - hints["editors/3d/secondary_grid_color"] = PropertyInfo(Variant::COLOR, "editors/3d/secondary_grid_color", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED); + hints["editors/3d/secondary_grid_color"] = PropertyInfo(Variant::COLOR, "editors/3d/secondary_grid_color", PROPERTY_HINT_COLOR_NO_ALPHA, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED); _initial_set("editors/3d/grid_size", 50); hints["editors/3d/grid_size"] = PropertyInfo(Variant::INT, "editors/3d/grid_size", PROPERTY_HINT_RANGE, "1,500,1", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED); diff --git a/editor/output_strings.cpp b/editor/output_strings.cpp index b0b72510a9..e6cadee3e3 100644 --- a/editor/output_strings.cpp +++ b/editor/output_strings.cpp @@ -87,6 +87,7 @@ void OutputStrings::_notification(int p_what) { float h_ofs = (int)h_scroll->get_value(); Point2 icon_ofs = Point2(0, (font_height - (int)icon_error->get_height()) / 2); + FontDrawer drawer(font, Color(1, 1, 1)); while (E && ofs.y < (size_height - (int)margin.y)) { String str = E->get().text; diff --git a/editor/plugins/skeleton_editor_plugin.cpp b/editor/plugins/skeleton_editor_plugin.cpp index c41e3b546f..40a696119e 100644 --- a/editor/plugins/skeleton_editor_plugin.cpp +++ b/editor/plugins/skeleton_editor_plugin.cpp @@ -154,10 +154,7 @@ SkeletonEditor::SkeletonEditor() { options->hide(); } -SkeletonEditor::~SkeletonEditor() { - SpatialEditor::get_singleton()->remove_child(options); - memdelete(options); -} +SkeletonEditor::~SkeletonEditor() {} void SkeletonEditorPlugin::edit(Object *p_object) { skeleton_editor->edit(Object::cast_to<Skeleton>(p_object)); @@ -183,7 +180,4 @@ SkeletonEditorPlugin::SkeletonEditorPlugin(EditorNode *p_node) { editor->get_viewport()->add_child(skeleton_editor); } -SkeletonEditorPlugin::~SkeletonEditorPlugin() { - editor->get_viewport()->remove_child(skeleton_editor); - memdelete(skeleton_editor); -} +SkeletonEditorPlugin::~SkeletonEditorPlugin() {} diff --git a/editor/rename_dialog.cpp b/editor/rename_dialog.cpp new file mode 100644 index 0000000000..d617089142 --- /dev/null +++ b/editor/rename_dialog.cpp @@ -0,0 +1,691 @@ +/*************************************************************************/ +/* rename_dialog.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* 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 "rename_dialog.h" + +#include "editor_node.h" +#include "editor_settings.h" +#include "editor_themes.h" +#include "modules/regex/regex.h" +#include "plugins/script_editor_plugin.h" +#include "print_string.h" +#include "scene/gui/control.h" +#include "scene/gui/label.h" +#include "scene/gui/tab_container.h" + +RenameDialog::RenameDialog(SceneTreeEditor *p_scene_tree_editor, UndoRedo *p_undo_redo) { + + scene_tree_editor = p_scene_tree_editor; + undo_redo = p_undo_redo; + preview_node = NULL; + + set_title(TTR("Batch Rename")); + + VBoxContainer *vbc = memnew(VBoxContainer); + add_child(vbc); + + // -- Search/Replace Area + + GridContainer *grd_main = memnew(GridContainer); + grd_main->set_columns(2); + grd_main->set_v_size_flags(SIZE_EXPAND_FILL); + vbc->add_child(grd_main); + + // ---- 1st & 2nd row + + Label *lbl_search = memnew(Label); + lbl_search->set_text(TTR("Search")); + + lne_search = memnew(LineEdit); + lne_search->set_placeholder(TTR("Search")); + lne_search->set_name("lne_search"); + lne_search->set_h_size_flags(SIZE_EXPAND_FILL); + + Label *lbl_replace = memnew(Label); + lbl_replace->set_text(TTR("Replace")); + + lne_replace = memnew(LineEdit); + lne_replace->set_placeholder(TTR("Replace")); + lne_replace->set_name("lne_replace"); + lne_replace->set_h_size_flags(SIZE_EXPAND_FILL); + + grd_main->add_child(lbl_search); + grd_main->add_child(lbl_replace); + grd_main->add_child(lne_search); + grd_main->add_child(lne_replace); + + // ---- 3rd & 4th row + + Label *lbl_prefix = memnew(Label); + lbl_prefix->set_text(TTR("Prefix")); + + lne_prefix = memnew(LineEdit); + lne_prefix->set_placeholder(TTR("Prefix")); + lne_prefix->set_name("lne_prefix"); + lne_prefix->set_h_size_flags(SIZE_EXPAND_FILL); + + Label *lbl_suffix = memnew(Label); + lbl_suffix->set_text(TTR("Suffix")); + + lne_suffix = memnew(LineEdit); + lne_suffix->set_placeholder(TTR("Suffix")); + lne_suffix->set_name("lne_suffix"); + lne_suffix->set_h_size_flags(SIZE_EXPAND_FILL); + + grd_main->add_child(lbl_prefix); + grd_main->add_child(lbl_suffix); + grd_main->add_child(lne_prefix); + grd_main->add_child(lne_suffix); + + // -- Feature Tabs + + const int feature_min_height = 160; + + Ref<Theme> collapse_theme = create_editor_theme(); + collapse_theme->set_icon("checked", "CheckBox", collapse_theme->get_icon("GuiTreeArrowDown", "EditorIcons")); + collapse_theme->set_icon("unchecked", "CheckBox", collapse_theme->get_icon("GuiTreeArrowRight", "EditorIcons")); + + CheckBox *chk_collapse_features = memnew(CheckBox); + chk_collapse_features->set_text(TTR("Advanced options")); + chk_collapse_features->set_theme(collapse_theme); + chk_collapse_features->set_focus_mode(FOCUS_NONE); + vbc->add_child(chk_collapse_features); + + tabc_features = memnew(TabContainer); + tabc_features->set_tab_align(TabContainer::ALIGN_LEFT); + vbc->add_child(tabc_features); + + // ---- Tab Substitute + + VBoxContainer *vbc_substitute = memnew(VBoxContainer); + vbc_substitute->set_h_size_flags(SIZE_EXPAND_FILL); + vbc_substitute->set_custom_minimum_size(Size2(0, feature_min_height)); + + vbc_substitute->set_name(TTR("Substitute")); + tabc_features->add_child(vbc_substitute); + + cbut_substitute = memnew(CheckButton); + cbut_substitute->set_text(TTR("Substitute")); + vbc_substitute->add_child(cbut_substitute); + + GridContainer *grd_substitute = memnew(GridContainer); + grd_substitute->set_columns(3); + vbc_substitute->add_child(grd_substitute); + + // Name + + but_insert_name = memnew(Button); + but_insert_name->set_text("NAME"); + but_insert_name->set_tooltip(String("${NAME}\n") + TTR("Node name")); + but_insert_name->set_focus_mode(FOCUS_NONE); + but_insert_name->connect("pressed", this, "_insert_text", make_binds("${NAME}")); + but_insert_name->set_h_size_flags(SIZE_EXPAND_FILL); + grd_substitute->add_child(but_insert_name); + + // Parent + + but_insert_parent = memnew(Button); + but_insert_parent->set_text("PARENT"); + but_insert_parent->set_tooltip(String("${PARENT}\n") + TTR("Node's parent name, if available")); + but_insert_parent->set_focus_mode(FOCUS_NONE); + but_insert_parent->connect("pressed", this, "_insert_text", make_binds("${PARENT}")); + but_insert_parent->set_h_size_flags(SIZE_EXPAND_FILL); + grd_substitute->add_child(but_insert_parent); + + // Type + + but_insert_type = memnew(Button); + but_insert_type->set_text("TYPE"); + but_insert_type->set_tooltip(String("${TYPE}\n") + TTR("Node type")); + but_insert_type->set_focus_mode(FOCUS_NONE); + but_insert_type->connect("pressed", this, "_insert_text", make_binds("${TYPE}")); + but_insert_type->set_h_size_flags(SIZE_EXPAND_FILL); + grd_substitute->add_child(but_insert_type); + + // Scene + + but_insert_scene = memnew(Button); + but_insert_scene->set_text("SCENE"); + but_insert_scene->set_tooltip(String("${SCENE}\n") + TTR("Current scene name")); + but_insert_scene->set_focus_mode(FOCUS_NONE); + but_insert_scene->connect("pressed", this, "_insert_text", make_binds("${SCENE}")); + but_insert_scene->set_h_size_flags(SIZE_EXPAND_FILL); + grd_substitute->add_child(but_insert_scene); + + // Root + + but_insert_root = memnew(Button); + but_insert_root->set_text("ROOT"); + but_insert_root->set_tooltip(String("${ROOT}\n") + TTR("Root node name")); + but_insert_root->set_focus_mode(FOCUS_NONE); + but_insert_root->connect("pressed", this, "_insert_text", make_binds("${ROOT}")); + but_insert_root->set_h_size_flags(SIZE_EXPAND_FILL); + grd_substitute->add_child(but_insert_root); + + // Count + + but_insert_count = memnew(Button); + but_insert_count->set_text("COUNTER"); + but_insert_count->set_tooltip(String("${COUNTER}\n") + TTR("Sequential integer counter.\nCompare counter options.")); + but_insert_count->set_focus_mode(FOCUS_NONE); + but_insert_count->connect("pressed", this, "_insert_text", make_binds("${COUNTER}")); + but_insert_count->set_h_size_flags(SIZE_EXPAND_FILL); + grd_substitute->add_child(but_insert_count); + + chk_per_level_counter = memnew(CheckBox); + chk_per_level_counter->set_text(TTR("Per Level counter")); + chk_per_level_counter->set_tooltip(TTR("If set the counter restarts for each group of child nodes")); + vbc_substitute->add_child(chk_per_level_counter); + + HBoxContainer *hbc_count_options = memnew(HBoxContainer); + vbc_substitute->add_child(hbc_count_options); + + Label *lbl_count_start = memnew(Label); + lbl_count_start->set_text(TTR("Start")); + lbl_count_start->set_tooltip(TTR("Initial value for the counter")); + hbc_count_options->add_child(lbl_count_start); + + spn_count_start = memnew(SpinBox); + spn_count_start->set_tooltip(TTR("Initial value for the counter")); + spn_count_start->set_step(1); + spn_count_start->set_min(0); + hbc_count_options->add_child(spn_count_start); + + Label *lbl_count_step = memnew(Label); + lbl_count_step->set_text(TTR("Step")); + lbl_count_step->set_tooltip(TTR("Ammount by which counter is incremented for each node")); + hbc_count_options->add_child(lbl_count_step); + + spn_count_step = memnew(SpinBox); + spn_count_step->set_tooltip(TTR("Ammount by which counter is incremented for each node")); + spn_count_step->set_step(1); + hbc_count_options->add_child(spn_count_step); + + Label *lbl_count_padding = memnew(Label); + lbl_count_padding->set_text(TTR("Padding")); + lbl_count_padding->set_tooltip(TTR("Minium number of digits for the counter.\nMissing digits are padded with leading zeros.")); + hbc_count_options->add_child(lbl_count_padding); + + spn_count_padding = memnew(SpinBox); + spn_count_padding->set_tooltip(TTR("Minium number of digits for the counter.\nMissing digits are padded with leading zeros.")); + spn_count_padding->set_step(1); + hbc_count_options->add_child(spn_count_padding); + + // ---- Tab RegEx + + VBoxContainer *vbc_regex = memnew(VBoxContainer); + vbc_regex->set_h_size_flags(SIZE_EXPAND_FILL); + vbc_regex->set_name(TTR("Regular Expressions")); + vbc_regex->set_custom_minimum_size(Size2(0, feature_min_height)); + tabc_features->add_child(vbc_regex); + + cbut_regex = memnew(CheckButton); + cbut_regex->set_text(TTR("Regular Expressions")); + vbc_regex->add_child(cbut_regex); + + // ---- Tab Process + + VBoxContainer *vbc_process = memnew(VBoxContainer); + vbc_process->set_h_size_flags(SIZE_EXPAND_FILL); + vbc_process->set_name(TTR("Post-Process")); + vbc_process->set_custom_minimum_size(Size2(0, feature_min_height)); + tabc_features->add_child(vbc_process); + + cbut_process = memnew(CheckButton); + cbut_process->set_text(TTR("Post-Process")); + vbc_process->add_child(cbut_process); + + // ------ Style + + HBoxContainer *hbc_style = memnew(HBoxContainer); + vbc_process->add_child(hbc_style); + + Label *lbl_style = memnew(Label); + lbl_style->set_text(TTR("Style")); + hbc_style->add_child(lbl_style); + + opt_style = memnew(OptionButton); + opt_style->add_item(TTR("Keep")); + opt_style->add_item(TTR("CamelCase to under_scored")); + opt_style->add_item(TTR("under_scored to CamelCase")); + hbc_style->add_child(opt_style); + + // ------ Case + + HBoxContainer *hbc_case = memnew(HBoxContainer); + vbc_process->add_child(hbc_case); + + Label *lbl_case = memnew(Label); + lbl_case->set_text(TTR("Case")); + hbc_case->add_child(lbl_case); + + opt_case = memnew(OptionButton); + opt_case->add_item(TTR("Keep")); + opt_case->add_item(TTR("To Lowercase")); + opt_case->add_item(TTR("To Uppercase")); + hbc_case->add_child(opt_case); + + // -- Preview + + HSeparator *sep_preview = memnew(HSeparator); + sep_preview->set_custom_minimum_size(Size2(10, 20)); + vbc->add_child(sep_preview); + + lbl_preview_title = memnew(Label); + lbl_preview_title->set_text(TTR("Preview")); + vbc->add_child(lbl_preview_title); + + lbl_preview = memnew(Label); + lbl_preview->set_text(""); + lbl_preview->add_color_override("font_color", Color(1, 0.5f, 0, 1)); + vbc->add_child(lbl_preview); + + // ---- Dialog related + + set_custom_minimum_size(Size2(383, 0)); + set_as_toplevel(true); + get_ok()->set_text(TTR("Rename")); + Button *but_reset = add_button(TTR("Reset")); + + eh.errfunc = _error_handler; + eh.userdata = this; + + // ---- Connections + + chk_collapse_features->connect("toggled", this, "_features_toggled"); + + // Substitite Buttons + + lne_search->connect("focus_entered", this, "_update_substitute"); + lne_search->connect("focus_exited", this, "_update_substitute"); + lne_replace->connect("focus_entered", this, "_update_substitute"); + lne_replace->connect("focus_exited", this, "_update_substitute"); + lne_prefix->connect("focus_entered", this, "_update_substitute"); + lne_prefix->connect("focus_exited", this, "_update_substitute"); + lne_suffix->connect("focus_entered", this, "_update_substitute"); + lne_suffix->connect("focus_exited", this, "_update_substitute"); + + // Preview + + lne_prefix->connect("text_changed", this, "_update_preview"); + lne_suffix->connect("text_changed", this, "_update_preview"); + lne_search->connect("text_changed", this, "_update_preview"); + lne_replace->connect("text_changed", this, "_update_preview"); + spn_count_start->connect("value_changed", this, "_update_preview_int"); + spn_count_step->connect("value_changed", this, "_update_preview_int"); + spn_count_padding->connect("value_changed", this, "_update_preview_int"); + opt_style->connect("item_selected", this, "_update_preview_int"); + opt_case->connect("item_selected", this, "_update_preview_int"); + cbut_substitute->connect("pressed", this, "_update_preview", varray("")); + cbut_regex->connect("pressed", this, "_update_preview", varray("")); + cbut_process->connect("pressed", this, "_update_preview", varray("")); + + but_reset->connect("pressed", this, "reset"); + + reset(); + _features_toggled(false); +} + +void RenameDialog::_bind_methods() { + + ClassDB::bind_method("_features_toggled", &RenameDialog::_features_toggled); + ClassDB::bind_method("_update_preview", &RenameDialog::_update_preview); + ClassDB::bind_method("_update_preview_int", &RenameDialog::_update_preview_int); + ClassDB::bind_method("_insert_text", &RenameDialog::_insert_text); + ClassDB::bind_method("_update_substitute", &RenameDialog::_update_substitute); + ClassDB::bind_method("reset", &RenameDialog::reset); + ClassDB::bind_method("rename", &RenameDialog::rename); +} + +void RenameDialog::_update_substitute() { + + LineEdit *focus_owner_line_edit = Object::cast_to<LineEdit>(get_focus_owner()); + bool is_main_field = _is_main_field(focus_owner_line_edit); + + but_insert_name->set_disabled(!is_main_field); + but_insert_parent->set_disabled(!is_main_field); + but_insert_type->set_disabled(!is_main_field); + but_insert_scene->set_disabled(!is_main_field); + but_insert_root->set_disabled(!is_main_field); + but_insert_count->set_disabled(!is_main_field); + + // The focus mode seems to be reset when disabling/re-enabling + but_insert_name->set_focus_mode(FOCUS_NONE); + but_insert_parent->set_focus_mode(FOCUS_NONE); + but_insert_type->set_focus_mode(FOCUS_NONE); + but_insert_scene->set_focus_mode(FOCUS_NONE); + but_insert_root->set_focus_mode(FOCUS_NONE); + but_insert_count->set_focus_mode(FOCUS_NONE); +} + +void RenameDialog::_post_popup() { + + EditorSelection *editor_selection = EditorNode::get_singleton()->get_editor_selection(); + preview_node = NULL; + + Array selected_node_list = editor_selection->get_selected_nodes(); + ERR_FAIL_COND(selected_node_list.size() == 0); + + preview_node = selected_node_list[0]; + + _update_preview(); + _update_substitute(); +} + +void RenameDialog::_update_preview_int(int new_value) { + _update_preview(); +} + +void RenameDialog::_update_preview(String new_text) { + + if (lock_preview_update || preview_node == NULL) + return; + + has_errors = false; + add_error_handler(&eh); + + String new_name = _apply_rename(preview_node, spn_count_start->get_value()); + + if (!has_errors) { + + lbl_preview_title->set_text(TTR("Preview")); + lbl_preview->set_text(new_name); + + if (new_name == preview_node->get_name()) { + lbl_preview->add_color_override("font_color", Color(0, 0.5f, 0.25f, 1)); + } else { + lbl_preview->add_color_override("font_color", Color(0, 1, 0.5f, 1)); + } + } + + remove_error_handler(&eh); +} + +String RenameDialog::_apply_rename(const Node *node, int count) { + + String search = lne_search->get_text(); + String replace = lne_replace->get_text(); + String prefix = lne_prefix->get_text(); + String suffix = lne_suffix->get_text(); + String new_name = node->get_name(); + + if (cbut_substitute->is_pressed()) { + search = _substitute(search, node, count); + replace = _substitute(replace, node, count); + prefix = _substitute(prefix, node, count); + suffix = _substitute(suffix, node, count); + } + + if (cbut_regex->is_pressed()) { + + new_name = _regex(search, new_name, replace); + } else { + new_name = new_name.replace(search, replace); + } + + new_name = prefix + new_name + suffix; + + if (cbut_process->is_pressed()) { + new_name = _postprocess(new_name); + } + + return new_name; +} + +String RenameDialog::_substitute(const String &subject, const Node *node, int count) { + + String result = subject.replace("${COUNTER}", vformat("%0" + itos(spn_count_padding->get_value()) + "d", count)); + + if (node) { + result = result.replace("${NAME}", node->get_name()); + result = result.replace("${TYPE}", node->get_class()); + } + + int current = EditorNode::get_singleton()->get_editor_data().get_edited_scene(); + result = result.replace("${SCENE}", EditorNode::get_singleton()->get_editor_data().get_scene_title(current)); + + Node *root_node = SceneTree::get_singleton()->get_edited_scene_root(); + if (root_node) { + result = result.replace("${ROOT}", root_node->get_name()); + } + + Node *parent_node = node->get_parent(); + if (parent_node) { + if (node == root_node) { + // Can not substitute parent of root. + result = result.replace("${PARENT}", ""); + } else { + result = result.replace("${PARENT}", parent_node->get_name()); + } + } + + return result; +} + +void RenameDialog::_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) { + + RenameDialog *self = (RenameDialog *)p_self; + String source_file(p_file); + + // Only show first error that is related to "regex" + if (self->has_errors || source_file.find("regex") < 0) + return; + + String err_str; + if (p_errorexp && p_errorexp[0]) { + err_str = p_errorexp; + } else { + err_str = p_error; + } + + self->has_errors = true; + self->lbl_preview_title->set_text(TTR("Error")); + self->lbl_preview->add_color_override("font_color", Color(1, 0.25f, 0, 1)); + self->lbl_preview->set_text(err_str); +} + +String RenameDialog::_regex(const String &pattern, const String &subject, const String &replacement) { + + RegEx regex(pattern); + + return regex.sub(subject, replacement, true); +} + +String RenameDialog::_postprocess(const String &subject) { + + int style_id = opt_style->get_selected(); + + String result = subject; + + if (style_id == 1) { + + // CamelCase to Under_Line + result = result.camelcase_to_underscore(true); + result = _regex("_+", result, "_"); + + } else if (style_id == 2) { + + // Under_Line to CamelCase + RegEx pattern("_+(.?)"); + Array matches = pattern.search_all(result); + + // _ name would become empty. Ignore + if (matches.size() && result != "_") { + String buffer; + int start = 0; + int end = 0; + for (int i = 0; i < matches.size(); ++i) { + start = ((Ref<RegExMatch>)matches[i])->get_start(1); + buffer += result.substr(end, start - end - 1); + buffer += result.substr(start, 1).to_upper(); + end = start + 1; + } + buffer += result.substr(end, result.size() - (end + 1)); + result = buffer.replace("_", "").capitalize(); + } + } + + int case_id = opt_case->get_selected(); + + if (case_id == 1) { + // To Lowercase + result = result.to_lower(); + } else if (case_id == 2) { + // To Upercase + result = result.to_upper(); + } + + return result; +} + +void RenameDialog::_iterate_scene(const Node *node, const Array &selection, int *counter) { + + if (!node) + return; + + if (selection.has(node)) { + + String new_name = _apply_rename(node, *counter); + + if (node->get_name() != new_name) { + Pair<NodePath, String> rename_item; + rename_item.first = node->get_path(); + rename_item.second = new_name; + to_rename.push_back(rename_item); + } + + *counter += spn_count_step->get_value(); + } + + int *cur_counter = counter; + int level_counter = spn_count_start->get_value(); + + if (chk_per_level_counter->is_pressed()) { + cur_counter = &level_counter; + } + + for (int i = 0; i < node->get_child_count(); ++i) { + _iterate_scene(node->get_child(i), selection, cur_counter); + } +} + +void RenameDialog::rename() { + + // Editor selection is not ordered via scene tree. Instead iterate + // over scene tree until all selected nodes are found in order. + + EditorSelection *editor_selection = EditorNode::get_singleton()->get_editor_selection(); + Array selected_node_list = editor_selection->get_selected_nodes(); + Node *root_node = SceneTree::get_singleton()->get_edited_scene_root(); + + global_count = spn_count_start->get_value(); + to_rename.clear(); + + // Forward recursive as opposed to the actual renaming. + _iterate_scene(root_node, selected_node_list, &global_count); + + if (undo_redo && !to_rename.empty()) { + + undo_redo->create_action(TTR("Batch Rename")); + + // Make sure to iterate reversed so that child nodes will find parents. + for (int i = to_rename.size() - 1; i >= 0; --i) { + + Node *n = root_node->get_node(to_rename[i].first); + const String &new_name = to_rename[i].second; + + if (!n) { + ERR_PRINTS("Skipping missing node: " + to_rename[i].first.get_concatenated_subnames()); + continue; + } + + scene_tree_editor->emit_signal("node_prerename", n, new_name); + undo_redo->add_do_method(scene_tree_editor, "_rename_node", n->get_instance_id(), new_name); + undo_redo->add_undo_method(scene_tree_editor, "_rename_node", n->get_instance_id(), n->get_name()); + } + + undo_redo->commit_action(); + } +} + +void RenameDialog::reset() { + + lock_preview_update = true; + + lne_prefix->clear(); + lne_suffix->clear(); + lne_search->clear(); + lne_replace->clear(); + + cbut_substitute->set_pressed(false); + cbut_regex->set_pressed(false); + cbut_process->set_pressed(false); + + chk_per_level_counter->set_pressed(true); + + spn_count_start->set_value(1); + spn_count_step->set_value(1); + spn_count_padding->set_value(1); + + opt_style->select(0); + opt_case->select(0); + + lock_preview_update = false; + _update_preview(); +} + +bool RenameDialog::_is_main_field(LineEdit *line_edit) { + return line_edit && + (line_edit == lne_search || line_edit == lne_replace || line_edit == lne_prefix || line_edit == lne_suffix); +} + +void RenameDialog::_insert_text(String text) { + + LineEdit *focus_owner = Object::cast_to<LineEdit>(get_focus_owner()); + + if (_is_main_field(focus_owner)) { + focus_owner->selection_delete(); + focus_owner->append_at_cursor(text); + _update_preview(); + } +} + +void RenameDialog::_features_toggled(bool pressed) { + if (pressed) { + tabc_features->show(); + } else { + tabc_features->hide(); + } + + // Adjust to minimum size in y + Size2i size = get_size(); + size.y = 0; + set_size(size); +} diff --git a/editor/rename_dialog.h b/editor/rename_dialog.h new file mode 100644 index 0000000000..c5ebc30c0c --- /dev/null +++ b/editor/rename_dialog.h @@ -0,0 +1,119 @@ +/*************************************************************************/ +/* rename_dialog.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef RENAME_DIALOG_H +#define RENAME_DIALOG_H + +#include "scene/gui/check_box.h" +#include "scene/gui/check_button.h" +#include "scene/gui/dialogs.h" +#include "scene/gui/option_button.h" +#include "scene/gui/spin_box.h" + +#include "editor/scene_tree_editor.h" +#include "undo_redo.h" + +/** +@author Blazej Floch +*/ + +class RenameDialog : public ConfirmationDialog { + + GDCLASS(RenameDialog, ConfirmationDialog); + + virtual void ok_pressed() { rename(); }; + void _cancel_pressed(){}; + void _features_toggled(bool pressed); + void _insert_text(String text); + void _update_substitute(); + bool _is_main_field(LineEdit *line_edit); + + void _iterate_scene(const Node *node, const Array &selection, int *count); + String _apply_rename(const Node *node, int count); + String _substitute(const String &subject, const Node *node, int count); + String _regex(const String &pattern, const String &subject, const String &replacement); + String _postprocess(const String &subject); + void _update_preview(String new_text = ""); + void _update_preview_int(int new_value = 0); + 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); + + SceneTreeEditor *scene_tree_editor; + UndoRedo *undo_redo; + int global_count; + + LineEdit *lne_search; + LineEdit *lne_replace; + LineEdit *lne_prefix; + LineEdit *lne_suffix; + + TabContainer *tabc_features; + + CheckButton *cbut_substitute; + CheckButton *cbut_regex; + CheckButton *cbut_process; + CheckBox *chk_per_level_counter; + + Button *but_insert_name; + Button *but_insert_parent; + Button *but_insert_type; + Button *but_insert_scene; + Button *but_insert_root; + Button *but_insert_count; + + SpinBox *spn_count_start; + SpinBox *spn_count_step; + SpinBox *spn_count_padding; + + OptionButton *opt_style; + OptionButton *opt_case; + + Label *lbl_preview_title; + Label *lbl_preview; + + List<Pair<NodePath, String> > to_rename; + Node *preview_node; + bool lock_preview_update; + ErrorHandlerList eh; + bool has_errors; + +protected: + void _notification(int p_what){}; + static void _bind_methods(); + virtual void _post_popup(); + +public: + void reset(); + void rename(); + + RenameDialog(SceneTreeEditor *p_scene_tree_editor, UndoRedo *p_undo_redo = NULL); + ~RenameDialog(){}; +}; + +#endif diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index ba661813d6..8b99a3d503 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -73,7 +73,9 @@ void SceneTreeDock::_unhandled_key_input(Ref<InputEvent> p_event) { if (!p_event->is_pressed() || p_event->is_echo()) return; - if (ED_IS_SHORTCUT("scene_tree/add_child_node", p_event)) { + if (ED_IS_SHORTCUT("scene_tree/batch_rename", p_event)) { + _tool_selected(TOOL_BATCH_RENAME); + } else if (ED_IS_SHORTCUT("scene_tree/add_child_node", p_event)) { _tool_selected(TOOL_NEW); } else if (ED_IS_SHORTCUT("scene_tree/instance_scene", p_event)) { _tool_selected(TOOL_INSTANCE); @@ -285,6 +287,12 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { switch (p_tool) { + case TOOL_BATCH_RENAME: { + Tree *tree = scene_tree->get_scene_tree(); + if (tree->is_anything_selected()) { + rename_dialog->popup_centered(); + } + } break; case TOOL_NEW: { String preferred = ""; @@ -1862,6 +1870,7 @@ void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) { menu->clear(); + menu->add_icon_shortcut(get_icon("Rename", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/batch_rename"), TOOL_BATCH_RENAME); if (selection.size() == 1) { subresources.clear(); @@ -2055,6 +2064,7 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor, Node *p_scene_root, EditorSel filter_hbc->add_constant_override("separate", 0); ToolButton *tb; + ED_SHORTCUT("scene_tree/batch_rename", TTR("Batch Rename"), KEY_MASK_CMD | KEY_F2); ED_SHORTCUT("scene_tree/add_child_node", TTR("Add Child Node"), KEY_MASK_CMD | KEY_A); ED_SHORTCUT("scene_tree/instance_scene", TTR("Instance Child Scene")); ED_SHORTCUT("scene_tree/change_node_type", TTR("Change Type")); @@ -2153,6 +2163,9 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor, Node *p_scene_root, EditorSel add_child(create_dialog); create_dialog->connect("create", this, "_create"); + rename_dialog = memnew(RenameDialog(scene_tree, &editor_data->get_undo_redo())); + add_child(rename_dialog); + script_create_dialog = memnew(ScriptCreateDialog); add_child(script_create_dialog); script_create_dialog->connect("script_created", this, "_script_created"); diff --git a/editor/scene_tree_dock.h b/editor/scene_tree_dock.h index a4f36e31ee..fd7d616a80 100644 --- a/editor/scene_tree_dock.h +++ b/editor/scene_tree_dock.h @@ -36,6 +36,7 @@ #include "editor/editor_data.h" #include "editor/editor_sub_scene.h" #include "editor/groups_editor.h" +#include "editor/rename_dialog.h" #include "editor/reparent_dialog.h" #include "editor/script_create_dialog.h" #include "scene/animation/animation_player.h" @@ -58,6 +59,7 @@ class SceneTreeDock : public VBoxContainer { TOOL_NEW, TOOL_INSTANCE, + TOOL_BATCH_RENAME, TOOL_REPLACE, TOOL_ATTACH_SCRIPT, TOOL_CLEAR_SCRIPT, @@ -90,6 +92,7 @@ class SceneTreeDock : public VBoxContainer { int current_option; CreateDialog *create_dialog; + RenameDialog *rename_dialog; ToolButton *button_add; ToolButton *button_instance; diff --git a/main/main.cpp b/main/main.cpp index fa60bd4e96..1c5540fd19 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -730,6 +730,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph } else if (debug_mode == "local") { script_debugger = memnew(ScriptDebuggerLocal); + OS::get_singleton()->initialize_debugging(); } FileAccessNetwork::configure(); @@ -874,7 +875,11 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph OS::get_singleton()->_allow_hidpi = GLOBAL_DEF("display/window/dpi/allow_hidpi", false); } + OS::get_singleton()->_allow_layered = GLOBAL_DEF("display/window/allow_per_pixel_transparency", false); + video_mode.use_vsync = GLOBAL_DEF("display/window/vsync/use_vsync", true); + video_mode.layered = GLOBAL_DEF("display/window/per_pixel_transparency", false); + video_mode.layered_splash = GLOBAL_DEF("display/window/per_pixel_transparency_splash", false); GLOBAL_DEF("rendering/quality/intended_usage/framebuffer_allocation", 2); GLOBAL_DEF("rendering/quality/intended_usage/framebuffer_allocation.mobile", 3); @@ -882,6 +887,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph if (editor || project_manager) { // The editor and project manager always detect and use hiDPI if needed OS::get_singleton()->_allow_hidpi = true; + OS::get_singleton()->_allow_layered = false; } Engine::get_singleton()->_pixel_snap = GLOBAL_DEF("rendering/quality/2d/use_pixel_snap", false); diff --git a/modules/bmp/SCsub b/modules/bmp/SCsub new file mode 100644 index 0000000000..e7da7cf108 --- /dev/null +++ b/modules/bmp/SCsub @@ -0,0 +1,9 @@ +#!/usr/bin/env python + +Import('env') +Import('env_modules') + +env_bmp = env_modules.Clone() + +# Godot's own source files +env_bmp.add_source_files(env.modules_sources, "*.cpp") diff --git a/modules/bmp/config.py b/modules/bmp/config.py new file mode 100644 index 0000000000..fb920482f5 --- /dev/null +++ b/modules/bmp/config.py @@ -0,0 +1,7 @@ + +def can_build(platform): + return True + + +def configure(env): + pass diff --git a/modules/bmp/image_loader_bmp.cpp b/modules/bmp/image_loader_bmp.cpp new file mode 100644 index 0000000000..769119a0dc --- /dev/null +++ b/modules/bmp/image_loader_bmp.cpp @@ -0,0 +1,194 @@ +/*************************************************************************/ +/* image_loader_bmp.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* 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 "image_loader_bmp.h" + +Error ImageLoaderBMP::convert_to_image(Ref<Image> p_image, + const uint8_t *p_buffer, + const uint8_t *p_color_buffer, + const bmp_header_s &p_header) { + + Error err = OK; + + if (p_buffer == NULL) + err = FAILED; + + if (err == OK) { + size_t index = 0; + size_t width = + static_cast<size_t>(p_header.bmp_info_header.bmp_width < 0 ? -p_header.bmp_info_header.bmp_width : p_header.bmp_info_header.bmp_width); + size_t height = + static_cast<size_t>(p_header.bmp_info_header.bmp_height < 0 ? -p_header.bmp_info_header.bmp_height : p_header.bmp_info_header.bmp_height); + size_t bits_per_pixel = + static_cast<size_t>(p_header.bmp_info_header.bmp_bit_count); + + if (p_header.bmp_info_header.bmp_compression != 0) { + err = FAILED; + } + + if (bits_per_pixel != 24 || bits_per_pixel != 32) { + err = FAILED; + } + + if (err == OK) { + + uint32_t line_width = ((p_header.bmp_info_header.bmp_width * + p_header.bmp_info_header.bmp_bit_count / 8) + + 3) & + ~3; + + PoolVector<uint8_t> image_data; + err = image_data.resize(width * height * 4); + + PoolVector<uint8_t>::Write image_data_w = image_data.write(); + uint8_t *write_buffer = image_data_w.ptr(); + + const uint8_t *line = p_buffer + (line_width * (height - 1)); + for (unsigned int i = 0; i < height; i++) { + const uint8_t *line_ptr = line; + for (unsigned int j = 0; j < width; j++) { + switch (bits_per_pixel) { + case 24: { + uint32_t color = *((uint32_t *)line_ptr); + + write_buffer[index + 2] = color & 0xff; + write_buffer[index + 1] = (color >> 8) & 0xff; + write_buffer[index + 0] = (color >> 16) & 0xff; + write_buffer[index + 3] = 0xff; + index += 4; + line_ptr += 3; + } break; + case 32: { + uint32_t color = *((uint32_t *)line_ptr); + + write_buffer[index + 2] = color & 0xff; + write_buffer[index + 1] = (color >> 8) & 0xff; + write_buffer[index + 0] = (color >> 16) & 0xff; + write_buffer[index + 3] = color >> 24; + index += 4; + line_ptr += 4; + } break; + } + } + line -= line_width; + } + p_image->create(width, height, 0, Image::FORMAT_RGBA8, image_data); + } + } + return err; +} + +Error ImageLoaderBMP::load_image(Ref<Image> p_image, FileAccess *f, + bool p_force_linear, float p_scale) { + + bmp_header_s bmp_header; + Error err = ERR_INVALID_DATA; + + if (f->get_len() > sizeof(bmp_header)) { + // File Header + bmp_header.bmp_file_header.bmp_signature = f->get_16(); + if (bmp_header.bmp_file_header.bmp_signature == BITMAP_SIGNATURE) { + bmp_header.bmp_file_header.bmp_file_size = f->get_32(); + bmp_header.bmp_file_header.bmp_file_padding = f->get_32(); + bmp_header.bmp_file_header.bmp_file_offset = f->get_32(); + + // Info Header + bmp_header.bmp_info_header.bmp_header_size = f->get_32(); + bmp_header.bmp_info_header.bmp_width = f->get_32(); + bmp_header.bmp_info_header.bmp_height = f->get_32(); + bmp_header.bmp_info_header.bmp_planes = f->get_16(); + bmp_header.bmp_info_header.bmp_bit_count = f->get_16(); + bmp_header.bmp_info_header.bmp_compression = f->get_32(); + bmp_header.bmp_info_header.bmp_size_image = f->get_32(); + bmp_header.bmp_info_header.bmp_pixels_per_meter_x = f->get_32(); + bmp_header.bmp_info_header.bmp_pixels_per_meter_y = f->get_32(); + bmp_header.bmp_info_header.bmp_colors_used = f->get_32(); + bmp_header.bmp_info_header.bmp_important_colors = f->get_32(); + + bmp_header.bmp_info_header.bmp_red_mask = f->get_32(); + bmp_header.bmp_info_header.bmp_green_mask = f->get_32(); + bmp_header.bmp_info_header.bmp_blue_mask = f->get_32(); + bmp_header.bmp_info_header.bmp_alpha_mask = f->get_32(); + bmp_header.bmp_info_header.bmp_cs_type = f->get_32(); + for (int i = 0; i < 9; i++) + bmp_header.bmp_info_header.bmp_endpoints[i] = f->get_32(); + + bmp_header.bmp_info_header.bmp_gamma_red = f->get_32(); + bmp_header.bmp_info_header.bmp_gamma_green = f->get_32(); + bmp_header.bmp_info_header.bmp_gamma_blue = f->get_32(); + + f->seek(sizeof(bmp_header.bmp_file_header) + + bmp_header.bmp_info_header.bmp_header_size); + + uint32_t color_table_size = 0; + if (bmp_header.bmp_info_header.bmp_bit_count == 1) + color_table_size = 2; + else if (bmp_header.bmp_info_header.bmp_bit_count == 4) + color_table_size = 16; + else if (bmp_header.bmp_info_header.bmp_bit_count == 8) + color_table_size = 256; + + PoolVector<uint8_t> bmp_color_table; + if (color_table_size > 0) { + err = bmp_color_table.resize(color_table_size * 4); + PoolVector<uint8_t>::Write bmp_color_table_w = bmp_color_table.write(); + f->get_buffer(bmp_color_table_w.ptr(), + bmp_header.bmp_info_header.bmp_colors_used * 4); + } + + f->seek(bmp_header.bmp_file_header.bmp_file_offset); + + uint32_t bmp_buffer_size = (bmp_header.bmp_file_header.bmp_file_size - + bmp_header.bmp_file_header.bmp_file_offset); + + PoolVector<uint8_t> bmp_buffer; + err = bmp_buffer.resize(bmp_buffer_size); + if (err == OK) { + PoolVector<uint8_t>::Write bmp_buffer_w = bmp_buffer.write(); + f->get_buffer(bmp_buffer_w.ptr(), bmp_buffer_size); + + PoolVector<uint8_t>::Read bmp_buffer_r = bmp_buffer.read(); + PoolVector<uint8_t>::Read bmp_color_table_r = bmp_color_table.read(); + err = convert_to_image(p_image, bmp_buffer_r.ptr(), + bmp_color_table_r.ptr(), bmp_header); + } + f->close(); + } + } + return err; +} + +void ImageLoaderBMP::get_recognized_extensions( + List<String> *p_extensions) const { + + p_extensions->push_back("bmp"); +} + +ImageLoaderBMP::ImageLoaderBMP() {} diff --git a/modules/bmp/image_loader_bmp.h b/modules/bmp/image_loader_bmp.h new file mode 100644 index 0000000000..3fa7481287 --- /dev/null +++ b/modules/bmp/image_loader_bmp.h @@ -0,0 +1,84 @@ +/*************************************************************************/ +/* image_loader_bmp.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef IMAGE_LOADER_BMP_H +#define IMAGE_LOADER_BMP_H + +#include "io/image_loader.h" + +class ImageLoaderBMP : public ImageFormatLoader { +protected: + static const unsigned BITMAP_SIGNATURE = 0x4d42; + + struct bmp_header_s { + struct bmp_file_header_s { + uint16_t bmp_signature; + uint32_t bmp_file_size; + uint32_t bmp_file_padding; + uint32_t bmp_file_offset; + } bmp_file_header; + + struct bmp_info_header_s { + uint32_t bmp_header_size; + uint32_t bmp_width; + uint32_t bmp_height; + uint16_t bmp_planes; + uint16_t bmp_bit_count; + uint32_t bmp_compression; + uint32_t bmp_size_image; + uint32_t bmp_pixels_per_meter_x; + uint32_t bmp_pixels_per_meter_y; + uint32_t bmp_colors_used; + uint32_t bmp_important_colors; + uint32_t bmp_red_mask; + uint32_t bmp_green_mask; + uint32_t bmp_blue_mask; + uint32_t bmp_alpha_mask; + uint32_t bmp_cs_type; + uint32_t bmp_endpoints[9]; + uint32_t bmp_gamma_red; + uint32_t bmp_gamma_green; + uint32_t bmp_gamma_blue; + } bmp_info_header; + }; + + static Error convert_to_image(Ref<Image> p_image, + const uint8_t *p_buffer, + const uint8_t *p_color_buffer, + const bmp_header_s &p_header); + +public: + virtual Error load_image(Ref<Image> p_image, FileAccess *f, + bool p_force_linear, float p_scale); + virtual void get_recognized_extensions(List<String> *p_extensions) const; + ImageLoaderBMP(); +}; + +#endif // IMAGE_LOADER_BMP_H diff --git a/modules/bmp/register_types.cpp b/modules/bmp/register_types.cpp new file mode 100644 index 0000000000..1f68a03e85 --- /dev/null +++ b/modules/bmp/register_types.cpp @@ -0,0 +1,44 @@ +/*************************************************************************/ +/* register_types.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* 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 "register_types.h" + +#include "image_loader_bmp.h" + +static ImageLoaderBMP *image_loader_bmp = NULL; + +void register_bmp_types() { + image_loader_bmp = memnew(ImageLoaderBMP); + ImageLoader::add_image_format_loader(image_loader_bmp); +} + +void unregister_bmp_types() { + memdelete(image_loader_bmp); +} diff --git a/modules/bmp/register_types.h b/modules/bmp/register_types.h new file mode 100644 index 0000000000..d8755db397 --- /dev/null +++ b/modules/bmp/register_types.h @@ -0,0 +1,32 @@ +/*************************************************************************/ +/* register_types.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* 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. */ +/*************************************************************************/ + +void register_bmp_types(); +void unregister_bmp_types(); diff --git a/modules/bullet/generic_6dof_joint_bullet.cpp b/modules/bullet/generic_6dof_joint_bullet.cpp index 151a79a69f..adfad7803f 100644 --- a/modules/bullet/generic_6dof_joint_bullet.cpp +++ b/modules/bullet/generic_6dof_joint_bullet.cpp @@ -138,6 +138,12 @@ void Generic6DOFJointBullet::set_param(Vector3::Axis p_axis, PhysicsServer::G6DO case PhysicsServer::G6DOF_JOINT_LINEAR_DAMPING: sixDOFConstraint->getTranslationalLimitMotor()->m_damping = p_value; break; + case PhysicsServer::G6DOF_JOINT_LINEAR_MOTOR_TARGET_VELOCITY: + sixDOFConstraint->getTranslationalLimitMotor()->m_targetVelocity.m_floats[p_axis] = p_value; + break; + case PhysicsServer::G6DOF_JOINT_LINEAR_MOTOR_FORCE_LIMIT: + sixDOFConstraint->getTranslationalLimitMotor()->m_maxMotorForce.m_floats[p_axis] = p_value; + break; case PhysicsServer::G6DOF_JOINT_ANGULAR_LOWER_LIMIT: limits_lower[1][p_axis] = p_value; set_flag(p_axis, PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_ANGULAR_LIMIT, flags[p_axis][p_param]); // Reload bullet parameter @@ -185,6 +191,10 @@ real_t Generic6DOFJointBullet::get_param(Vector3::Axis p_axis, PhysicsServer::G6 return sixDOFConstraint->getTranslationalLimitMotor()->m_restitution; case PhysicsServer::G6DOF_JOINT_LINEAR_DAMPING: return sixDOFConstraint->getTranslationalLimitMotor()->m_damping; + case PhysicsServer::G6DOF_JOINT_LINEAR_MOTOR_TARGET_VELOCITY: + return sixDOFConstraint->getTranslationalLimitMotor()->m_targetVelocity.m_floats[p_axis]; + case PhysicsServer::G6DOF_JOINT_LINEAR_MOTOR_FORCE_LIMIT: + return sixDOFConstraint->getTranslationalLimitMotor()->m_maxMotorForce.m_floats[p_axis]; case PhysicsServer::G6DOF_JOINT_ANGULAR_LOWER_LIMIT: return limits_lower[1][p_axis]; case PhysicsServer::G6DOF_JOINT_ANGULAR_UPPER_LIMIT: @@ -232,6 +242,9 @@ void Generic6DOFJointBullet::set_flag(Vector3::Axis p_axis, PhysicsServer::G6DOF case PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_MOTOR: sixDOFConstraint->getRotationalLimitMotor(p_axis)->m_enableMotor = flags[p_axis][p_flag]; break; + case PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_LINEAR_MOTOR: + sixDOFConstraint->getTranslationalLimitMotor()->m_enableMotor[p_axis] = flags[p_axis][p_flag]; + break; default: WARN_PRINT("This flag is not supported by Bullet engine"); return; diff --git a/modules/gdnative/gdnative.cpp b/modules/gdnative/gdnative.cpp index 897588385a..e7ebcc73af 100644 --- a/modules/gdnative/gdnative.cpp +++ b/modules/gdnative/gdnative.cpp @@ -469,7 +469,9 @@ Variant GDNative::call_native(StringName p_native_call_type, StringName p_proced godot_variant result = E->get()(procedure_handle, (godot_array *)&p_arguments); - return *(Variant *)&result; + Variant res = *(Variant *)&result; + godot_variant_destroy(&result); + return res; } Error GDNative::get_symbol(StringName p_procedure_name, void *&r_handle, bool p_optional) { diff --git a/platform/android/AndroidManifest.xml.template b/platform/android/AndroidManifest.xml.template index 3e42b7a3cd..13d10b5026 100644 --- a/platform/android/AndroidManifest.xml.template +++ b/platform/android/AndroidManifest.xml.template @@ -201,6 +201,6 @@ $$ADD_PERMISSION_CHUNKS$$ <uses-permission android:name="godot.custom.18"/> <uses-permission android:name="godot.custom.19"/> -<uses-sdk android:minSdkVersion="18" android:targetSdkVersion="23"/> +<uses-sdk android:minSdkVersion="18" android:targetSdkVersion="27"/> </manifest> diff --git a/platform/osx/os_osx.h b/platform/osx/os_osx.h index fee25e98cb..c1022a1aca 100644 --- a/platform/osx/os_osx.h +++ b/platform/osx/os_osx.h @@ -99,6 +99,8 @@ public: id pixelFormat; id context; + bool layered_window; + CursorShape cursor_shape; NSCursor *cursors[CURSOR_MAX]; MouseMode mouse_mode; @@ -226,6 +228,10 @@ public: virtual void set_borderless_window(bool p_borderless); virtual bool get_borderless_window(); + + virtual bool get_window_per_pixel_transparency_enabled() const; + virtual void set_window_per_pixel_transparency_enabled(bool p_enabled); + virtual void set_ime_position(const Point2 &p_pos); virtual void set_ime_intermediate_text_callback(ImeCallback p_callback, void *p_inp); diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm index fbefd41bb7..eaf89f7d0f 100644 --- a/platform/osx/os_osx.mm +++ b/platform/osx/os_osx.mm @@ -1330,6 +1330,9 @@ Error OS_OSX::initialize(const VideoMode &p_desired, int p_video_driver, int p_a restore_rect = Rect2(get_window_position(), get_window_size()); + if (p_desired.layered_splash) { + set_window_per_pixel_transparency_enabled(true); + } return OK; } @@ -2042,6 +2045,8 @@ void OS_OSX::set_window_size(const Size2 p_size) { void OS_OSX::set_window_fullscreen(bool p_enabled) { if (zoomed != p_enabled) { + if (layered_window) + set_window_per_pixel_transparency_enabled(false); [window_object toggleFullScreen:nil]; } zoomed = p_enabled; @@ -2123,6 +2128,39 @@ void OS_OSX::request_attention() { [NSApp requestUserAttention:NSCriticalRequest]; } +bool OS_OSX::get_window_per_pixel_transparency_enabled() const { + + if (!is_layered_allowed()) return false; + return layered_window; +} + +void OS_OSX::set_window_per_pixel_transparency_enabled(bool p_enabled) { + + if (!is_layered_allowed()) return; + if (layered_window != p_enabled) { + if (p_enabled) { + set_borderless_window(true); + GLint opacity = 0; + [window_object setBackgroundColor:[NSColor clearColor]]; + [window_object setOpaque:NO]; + [window_object setHasShadow:NO]; + [context setValues:&opacity forParameter:NSOpenGLCPSurfaceOpacity]; + layered_window = true; + } else { + GLint opacity = 1; + [window_object setBackgroundColor:[NSColor colorWithCalibratedWhite:1 alpha:1]]; + [window_object setOpaque:YES]; + [window_object setHasShadow:YES]; + [context setValues:&opacity forParameter:NSOpenGLCPSurfaceOpacity]; + layered_window = false; + } + [context update]; + NSRect frame = [window_object frame]; + [window_object setFrame:NSMakeRect(frame.origin.x, frame.origin.y, 1, 1) display:YES]; + [window_object setFrame:frame display:YES]; + } +} + void OS_OSX::set_borderless_window(bool p_borderless) { // OrderOut prevents a lose focus bug with the window @@ -2131,6 +2169,9 @@ void OS_OSX::set_borderless_window(bool p_borderless) { if (p_borderless) { [window_object setStyleMask:NSWindowStyleMaskBorderless]; } else { + if (layered_window) + set_window_per_pixel_transparency_enabled(false); + [window_object setStyleMask:NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskResizable]; // Force update of the window styles @@ -2435,6 +2476,7 @@ OS_OSX::OS_OSX() { im_position = Point2(); im_callback = NULL; im_target = NULL; + layered_window = false; autoreleasePool = [[NSAutoreleasePool alloc] init]; eventSource = CGEventSourceCreate(kCGEventSourceStateHIDSystemState); diff --git a/platform/windows/detect.py b/platform/windows/detect.py index 2ce55d98be..6d559520d7 100644 --- a/platform/windows/detect.py +++ b/platform/windows/detect.py @@ -193,7 +193,10 @@ def configure_msvc(env, manual_msvc_config): env.AppendUnique(CCFLAGS=['/MT', '/Gd', '/GR', '/nologo']) env.AppendUnique(CXXFLAGS=['/TP']) # assume all sources are C++ if manual_msvc_config: # should be automatic if SCons found it - env.Append(CPPPATH=[os.getenv("WindowsSdkDir") + "/Include"]) + if os.getenv("WindowsSdkDir") is not None: + env.Append(CPPPATH=[os.getenv("WindowsSdkDir") + "/Include"]) + else: + print("Missing environment variable: WindowsSdkDir") env.AppendUnique(CPPDEFINES = ['WINDOWS_ENABLED', 'OPENGL_ENABLED', 'RTAUDIO_ENABLED', 'WASAPI_ENABLED', @@ -211,7 +214,10 @@ def configure_msvc(env, manual_msvc_config): env.Append(LINKFLAGS=[p + env["LIBSUFFIX"] for p in LIBS]) if manual_msvc_config: - env.Append(LIBPATH=[os.getenv("WindowsSdkDir") + "/Lib"]) + if os.getenv("WindowsSdkDir") is not None: + env.Append(LIBPATH=[os.getenv("WindowsSdkDir") + "/Lib"]) + else: + print("Missing environment variable: WindowsSdkDir") ## LTO diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index bed5781ae4..54a5d91eb4 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -152,6 +152,25 @@ void RedirectIOToConsole() { // point to console as well } +BOOL WINAPI HandlerRoutine(_In_ DWORD dwCtrlType) { + if (ScriptDebugger::get_singleton() == NULL) + return FALSE; + + switch (dwCtrlType) { + case CTRL_C_EVENT: + ScriptDebugger::get_singleton()->set_depth(-1); + ScriptDebugger::get_singleton()->set_lines_left(1); + return TRUE; + default: + return FALSE; + } +} + +void OS_Windows::initialize_debugging() { + + SetConsoleCtrlHandler(HandlerRoutine, TRUE); +} + void OS_Windows::initialize_core() { crash_handler.initialize(); @@ -618,6 +637,28 @@ LRESULT OS_Windows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) maximized = false; minimized = false; } + if (is_layered_allowed() && layered_window) { + DeleteObject(hBitmap); + + RECT r; + GetWindowRect(hWnd, &r); + dib_size = Size2(r.right - r.left, r.bottom - r.top); + + BITMAPINFO bmi; + ZeroMemory(&bmi, sizeof(BITMAPINFO)); + bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); + bmi.bmiHeader.biWidth = dib_size.x; + bmi.bmiHeader.biHeight = dib_size.y; + bmi.bmiHeader.biPlanes = 1; + bmi.bmiHeader.biBitCount = 32; + bmi.bmiHeader.biCompression = BI_RGB; + bmi.bmiHeader.biSizeImage = dib_size.x, dib_size.y * 4; + hBitmap = CreateDIBSection(hDC_dib, &bmi, DIB_RGB_COLORS, (void **)&dib_data, NULL, 0x0); + SelectObject(hDC_dib, hBitmap); + + ZeroMemory(dib_data, dib_size.x * dib_size.y * 4); + } + //return 0; // Jump Back } break; case WM_ENTERSIZEMOVE: { @@ -1132,6 +1173,9 @@ Error OS_Windows::initialize(const VideoMode &p_desired, int p_video_driver, int SetFocus(hWnd); // Sets Keyboard Focus To } + if (p_desired.layered_splash) { + set_window_per_pixel_transparency_enabled(true); + } return OK; } @@ -1523,6 +1567,9 @@ void OS_Windows::set_window_fullscreen(bool p_enabled) { if (video_mode.fullscreen == p_enabled) return; + if (layered_window) + set_window_per_pixel_transparency_enabled(false); + if (p_enabled) { if (pre_fs_valid) { @@ -1627,10 +1674,97 @@ bool OS_Windows::is_window_always_on_top() const { return video_mode.always_on_top; } +bool OS_Windows::get_window_per_pixel_transparency_enabled() const { + + if (!is_layered_allowed()) return false; + return layered_window; +} + +void OS_Windows::set_window_per_pixel_transparency_enabled(bool p_enabled) { + + if (!is_layered_allowed()) return; + if (layered_window != p_enabled) { + if (p_enabled) { + set_borderless_window(true); + //enable per-pixel alpha + hDC_dib = CreateCompatibleDC(GetDC(hWnd)); + + SetWindowLong(hWnd, GWL_EXSTYLE, GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_LAYERED); + + RECT r; + GetWindowRect(hWnd, &r); + dib_size = Size2(r.right - r.left, r.bottom - r.top); + + BITMAPINFO bmi; + ZeroMemory(&bmi, sizeof(BITMAPINFO)); + bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); + bmi.bmiHeader.biWidth = dib_size.x; + bmi.bmiHeader.biHeight = dib_size.y; + bmi.bmiHeader.biPlanes = 1; + bmi.bmiHeader.biBitCount = 32; + bmi.bmiHeader.biCompression = BI_RGB; + bmi.bmiHeader.biSizeImage = dib_size.x * dib_size.y * 4; + hBitmap = CreateDIBSection(hDC_dib, &bmi, DIB_RGB_COLORS, (void **)&dib_data, NULL, 0x0); + SelectObject(hDC_dib, hBitmap); + + ZeroMemory(dib_data, dib_size.x * dib_size.y * 4); + + layered_window = true; + } else { + //disable per-pixel alpha + layered_window = false; + + SetWindowLong(hWnd, GWL_EXSTYLE, GetWindowLong(hWnd, GWL_EXSTYLE) & ~WS_EX_LAYERED); + + //cleanup + DeleteObject(hBitmap); + DeleteDC(hDC_dib); + } + } +} + +uint8_t *OS_Windows::get_layered_buffer_data() { + + return (is_layered_allowed() && layered_window) ? dib_data : NULL; +} + +Size2 OS_Windows::get_layered_buffer_size() { + + return (is_layered_allowed() && layered_window) ? dib_size : Size2(); +} + +void OS_Windows::swap_layered_buffer() { + + if (is_layered_allowed() && layered_window) { + + //premultiply alpha + for (int y = 0; y < dib_size.y; y++) { + for (int x = 0; x < dib_size.x; x++) { + float alpha = (float)dib_data[y * (int)dib_size.x * 4 + x * 4 + 3] / (float)0xFF; + dib_data[y * (int)dib_size.x * 4 + x * 4 + 0] *= alpha; + dib_data[y * (int)dib_size.x * 4 + x * 4 + 1] *= alpha; + dib_data[y * (int)dib_size.x * 4 + x * 4 + 2] *= alpha; + } + } + //swap layered window buffer + POINT ptSrc = { 0, 0 }; + SIZE sizeWnd = { (long)dib_size.x, (long)dib_size.y }; + BLENDFUNCTION bf; + bf.BlendOp = AC_SRC_OVER; + bf.BlendFlags = 0; + bf.AlphaFormat = AC_SRC_ALPHA; + bf.SourceConstantAlpha = 0xFF; + UpdateLayeredWindow(hWnd, NULL, NULL, &sizeWnd, hDC_dib, &ptSrc, 0, &bf, ULW_ALPHA); + } +} + void OS_Windows::set_borderless_window(bool p_borderless) { if (video_mode.borderless_window == p_borderless) return; + if (!p_borderless && layered_window) + set_window_per_pixel_transparency_enabled(false); + video_mode.borderless_window = p_borderless; _update_window_style(); @@ -2563,6 +2697,8 @@ Error OS_Windows::move_to_trash(const String &p_path) { OS_Windows::OS_Windows(HINSTANCE _hInstance) { key_event_pos = 0; + layered_window = false; + hBitmap = NULL; force_quit = false; alt_mem = false; gr_mem = false; @@ -2596,6 +2732,10 @@ OS_Windows::OS_Windows(HINSTANCE _hInstance) { } OS_Windows::~OS_Windows() { + if (is_layered_allowed() && layered_window) { + DeleteObject(hBitmap); + DeleteDC(hDC_dib); + } #ifdef STDOUT_FILE fclose(stdo); #endif diff --git a/platform/windows/os_windows.h b/platform/windows/os_windows.h index 3d13627bfa..221109318e 100644 --- a/platform/windows/os_windows.h +++ b/platform/windows/os_windows.h @@ -93,6 +93,12 @@ class OS_Windows : public OS { HINSTANCE hInstance; // Holds The Instance Of The Application HWND hWnd; + HBITMAP hBitmap; //DIB section for layered window + uint8_t *dib_data; + Size2 dib_size; + HDC hDC_dib; + bool layered_window; + uint32_t move_timer_id; HCURSOR hCursor; @@ -212,6 +218,13 @@ public: virtual void set_borderless_window(bool p_borderless); virtual bool get_borderless_window(); + virtual bool get_window_per_pixel_transparency_enabled() const; + virtual void set_window_per_pixel_transparency_enabled(bool p_enabled); + + virtual uint8_t *get_layered_buffer_data(); + virtual Size2 get_layered_buffer_size(); + virtual void swap_layered_buffer(); + virtual Error open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path = false); virtual Error close_dynamic_library(void *p_library_handle); virtual Error get_dynamic_library_symbol_handle(void *p_library_handle, const String p_name, void *&p_symbol_handle, bool p_optional = false); @@ -294,6 +307,7 @@ public: void disable_crash_handler(); bool is_disable_crash_handler() const; + virtual void initialize_debugging(); void force_process_input(); diff --git a/platform/x11/context_gl_x11.cpp b/platform/x11/context_gl_x11.cpp index 1a7cbc0d6d..cd76667c64 100644 --- a/platform/x11/context_gl_x11.cpp +++ b/platform/x11/context_gl_x11.cpp @@ -116,32 +116,76 @@ Error ContextGL_X11::initialize() { None }; + static int visual_attribs_layered[] = { + GLX_RENDER_TYPE, GLX_RGBA_BIT, + GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, + GLX_DOUBLEBUFFER, true, + GLX_RED_SIZE, 8, + GLX_GREEN_SIZE, 8, + GLX_BLUE_SIZE, 8, + GLX_ALPHA_SIZE, 8, + GLX_DEPTH_SIZE, 24, + None + }; + int fbcount; - GLXFBConfig *fbc = glXChooseFBConfig(x11_display, DefaultScreen(x11_display), visual_attribs, &fbcount); - ERR_FAIL_COND_V(!fbc, ERR_UNCONFIGURED); + GLXFBConfig fbconfig; + XVisualInfo *vi = NULL; + + if (OS::get_singleton()->is_layered_allowed()) { + GLXFBConfig *fbc = glXChooseFBConfig(x11_display, DefaultScreen(x11_display), visual_attribs_layered, &fbcount); + ERR_FAIL_COND_V(!fbc, ERR_UNCONFIGURED); + + for (int i = 0; i < fbcount; i++) { + vi = (XVisualInfo *)glXGetVisualFromFBConfig(x11_display, fbc[i]); + if (!vi) + continue; + + XRenderPictFormat *pict_format = XRenderFindVisualFormat(x11_display, vi->visual); + if (!pict_format) { + XFree(vi); + vi = NULL; + continue; + } + + fbconfig = fbc[i]; + if (pict_format->direct.alphaMask > 0) { + break; + } + } + ERR_FAIL_COND_V(!fbconfig, ERR_UNCONFIGURED); + + XSetWindowAttributes swa; + + swa.colormap = XCreateColormap(x11_display, RootWindow(x11_display, vi->screen), vi->visual, AllocNone); + swa.border_pixel = 0; + swa.background_pixmap = None; + swa.background_pixel = 0; + swa.border_pixmap = None; + swa.event_mask = StructureNotifyMask; + + x11_window = XCreateWindow(x11_display, RootWindow(x11_display, vi->screen), 0, 0, OS::get_singleton()->get_video_mode().width, OS::get_singleton()->get_video_mode().height, 0, vi->depth, InputOutput, vi->visual, CWBorderPixel | CWColormap | CWEventMask | CWBackPixel, &swa); - XVisualInfo *vi = glXGetVisualFromFBConfig(x11_display, fbc[0]); + } else { + GLXFBConfig *fbc = glXChooseFBConfig(x11_display, DefaultScreen(x11_display), visual_attribs, &fbcount); + ERR_FAIL_COND_V(!fbc, ERR_UNCONFIGURED); - XSetWindowAttributes swa; + vi = glXGetVisualFromFBConfig(x11_display, fbc[0]); - swa.colormap = XCreateColormap(x11_display, RootWindow(x11_display, vi->screen), vi->visual, AllocNone); - swa.border_pixel = 0; - swa.event_mask = StructureNotifyMask; + fbconfig = fbc[0]; - /* - char* windowid = getenv("GODOT_WINDOWID"); - if (windowid) { + XSetWindowAttributes swa; + + swa.colormap = XCreateColormap(x11_display, RootWindow(x11_display, vi->screen), vi->visual, AllocNone); + swa.border_pixel = 0; + swa.event_mask = StructureNotifyMask; + + x11_window = XCreateWindow(x11_display, RootWindow(x11_display, vi->screen), 0, 0, OS::get_singleton()->get_video_mode().width, OS::get_singleton()->get_video_mode().height, 0, vi->depth, InputOutput, vi->visual, CWBorderPixel | CWColormap | CWEventMask, &swa); + } - //freopen("/home/punto/stdout", "w", stdout); - //reopen("/home/punto/stderr", "w", stderr); - x11_window = atol(windowid); - } else { - */ - x11_window = XCreateWindow(x11_display, RootWindow(x11_display, vi->screen), 0, 0, OS::get_singleton()->get_video_mode().width, OS::get_singleton()->get_video_mode().height, 0, vi->depth, InputOutput, vi->visual, CWBorderPixel | CWColormap | CWEventMask, &swa); ERR_FAIL_COND_V(!x11_window, ERR_UNCONFIGURED); set_class_hint(x11_display, x11_window); XMapWindow(x11_display, x11_window); - //}; int (*oldHandler)(Display *, XErrorEvent *) = XSetErrorHandler(&ctxErrorHandler); @@ -160,7 +204,7 @@ Error ContextGL_X11::initialize() { None }; - p->glx_context = glXCreateContextAttribsARB(x11_display, fbc[0], NULL, true, context_attribs); + p->glx_context = glXCreateContextAttribsARB(x11_display, fbconfig, NULL, true, context_attribs); ERR_EXPLAIN("Could not obtain an OpenGL 3.0 context!"); ERR_FAIL_COND_V(!p->glx_context, ERR_UNCONFIGURED); } break; @@ -175,7 +219,7 @@ Error ContextGL_X11::initialize() { None }; - p->glx_context = glXCreateContextAttribsARB(x11_display, fbc[0], NULL, true, context_attribs); + p->glx_context = glXCreateContextAttribsARB(x11_display, fbconfig, NULL, true, context_attribs); ERR_EXPLAIN("Could not obtain an OpenGL 3.3 context!"); ERR_FAIL_COND_V(ctxErrorOccurred || !p->glx_context, ERR_UNCONFIGURED); } break; @@ -195,7 +239,6 @@ Error ContextGL_X11::initialize() { //glXMakeCurrent(x11_display, None, NULL); XFree(vi); - XFree(fbc); return OK; } diff --git a/platform/x11/context_gl_x11.h b/platform/x11/context_gl_x11.h index b54cc84fac..b8f3eb95d4 100644 --- a/platform/x11/context_gl_x11.h +++ b/platform/x11/context_gl_x11.h @@ -41,6 +41,7 @@ #include "drivers/gl_context/context_gl.h" #include "os/os.h" #include <X11/Xlib.h> +#include <X11/extensions/Xrender.h> struct ContextGL_X11_Private; diff --git a/platform/x11/detect.py b/platform/x11/detect.py index 5820a926e9..ad2620c9f5 100644 --- a/platform/x11/detect.py +++ b/platform/x11/detect.py @@ -42,6 +42,11 @@ def can_build(): print("xrandr not found.. x11 disabled.") return False + x11_error = os.system("pkg-config xrender --modversion > /dev/null ") + if (x11_error): + print("xrender not found.. x11 disabled.") + return False + return True def get_opts(): @@ -141,6 +146,7 @@ def configure(env): env.ParseConfig('pkg-config xcursor --cflags --libs') env.ParseConfig('pkg-config xinerama --cflags --libs') env.ParseConfig('pkg-config xrandr --cflags --libs') + env.ParseConfig('pkg-config xrender --cflags --libs') if (env['touch']): x11_error = os.system("pkg-config xi --modversion > /dev/null ") diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index 336068cb1e..d1b87dac6f 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -517,6 +517,10 @@ Error OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_a power_manager = memnew(PowerX11); + if (p_desired.layered_splash) { + set_window_per_pixel_transparency_enabled(true); + } + XEvent xevent; while (XPending(x11_display) > 0) { XNextEvent(x11_display, &xevent); @@ -707,6 +711,25 @@ Point2 OS_X11::get_mouse_position() const { return last_mouse_pos; } +bool OS_X11::get_window_per_pixel_transparency_enabled() const { + + if (!is_layered_allowed()) return false; + return layered_window; +} + +void OS_X11::set_window_per_pixel_transparency_enabled(bool p_enabled) { + + if (!is_layered_allowed()) return; + if (layered_window != p_enabled) { + if (p_enabled) { + set_borderless_window(true); + layered_window = true; + } else { + layered_window = false; + } + } +} + void OS_X11::set_window_title(const String &p_title) { XStoreName(x11_display, x11_window, p_title.utf8().get_data()); @@ -1006,9 +1029,13 @@ void OS_X11::set_window_size(const Size2 p_size) { } void OS_X11::set_window_fullscreen(bool p_enabled) { + if (current_videomode.fullscreen == p_enabled) return; + if (layered_window) + set_window_per_pixel_transparency_enabled(false); + if (p_enabled && current_videomode.always_on_top) { // Fullscreen + Always-on-top requires a maximized window on some window managers (Metacity) set_window_maximized(true); @@ -1254,6 +1281,9 @@ void OS_X11::set_borderless_window(bool p_borderless) { if (current_videomode.borderless_window == p_borderless) return; + if (!p_borderless && layered_window) + set_window_per_pixel_transparency_enabled(false); + current_videomode.borderless_window = p_borderless; Hints hints; @@ -2715,6 +2745,7 @@ OS_X11::OS_X11() { AudioDriverManager::add_driver(&driver_alsa); #endif + layered_window = false; minimized = false; xim_style = 0L; mouse_mode = MOUSE_MODE_VISIBLE; diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h index 0a39da77de..09ed9588c4 100644 --- a/platform/x11/os_x11.h +++ b/platform/x11/os_x11.h @@ -172,6 +172,8 @@ class OS_X11 : public OS_Unix { PowerX11 *power_manager; + bool layered_window; + CrashHandler crash_handler; int audio_driver_index; @@ -263,6 +265,10 @@ public: virtual void set_borderless_window(bool p_borderless); virtual bool get_borderless_window(); + + virtual bool get_window_per_pixel_transparency_enabled() const; + virtual void set_window_per_pixel_transparency_enabled(bool p_enabled); + virtual void set_ime_position(const Point2 &p_pos); virtual String get_unique_id() const; diff --git a/scene/2d/animated_sprite.cpp b/scene/2d/animated_sprite.cpp index 447bd9a090..60a7961293 100644 --- a/scene/2d/animated_sprite.cpp +++ b/scene/2d/animated_sprite.cpp @@ -351,7 +351,7 @@ void AnimatedSprite::_notification(int p_what) { if (frame < 0) return; - float speed = frames->get_animation_speed(animation); + float speed = frames->get_animation_speed(animation) * speed_scale; if (speed == 0) return; //do nothing @@ -481,6 +481,16 @@ int AnimatedSprite::get_frame() const { return frame; } +void AnimatedSprite::set_speed_scale(float p_speed_scale) { + + speed_scale = MAX(p_speed_scale, 0.0f); +} + +float AnimatedSprite::get_speed_scale() const { + + return speed_scale; +} + void AnimatedSprite::set_centered(bool p_center) { centered = p_center; @@ -570,7 +580,7 @@ void AnimatedSprite::_reset_timeout() { return; if (frames.is_valid() && frames->has_animation(animation)) { - float speed = frames->get_animation_speed(animation); + float speed = frames->get_animation_speed(animation) * speed_scale; if (speed > 0) { timeout = 1.0 / speed; } else { @@ -636,6 +646,9 @@ void AnimatedSprite::_bind_methods() { ClassDB::bind_method(D_METHOD("set_frame", "frame"), &AnimatedSprite::set_frame); ClassDB::bind_method(D_METHOD("get_frame"), &AnimatedSprite::get_frame); + ClassDB::bind_method(D_METHOD("set_speed_scale", "speed_scale"), &AnimatedSprite::set_speed_scale); + ClassDB::bind_method(D_METHOD("get_speed_scale"), &AnimatedSprite::get_speed_scale); + ClassDB::bind_method(D_METHOD("_res_changed"), &AnimatedSprite::_res_changed); ADD_SIGNAL(MethodInfo("frame_changed")); @@ -644,6 +657,7 @@ void AnimatedSprite::_bind_methods() { ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "frames", PROPERTY_HINT_RESOURCE_TYPE, "SpriteFrames"), "set_sprite_frames", "get_sprite_frames"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "animation"), "set_animation", "get_animation"); ADD_PROPERTYNZ(PropertyInfo(Variant::INT, "frame", PROPERTY_HINT_SPRITE_FRAME), "set_frame", "get_frame"); + ADD_PROPERTYNO(PropertyInfo(Variant::REAL, "speed_scale"), "set_speed_scale", "get_speed_scale"); ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "playing"), "_set_playing", "_is_playing"); ADD_PROPERTYNO(PropertyInfo(Variant::BOOL, "centered"), "set_centered", "is_centered"); ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2, "offset"), "set_offset", "get_offset"); @@ -658,6 +672,7 @@ AnimatedSprite::AnimatedSprite() { vflip = false; frame = 0; + speed_scale = 1.0f; playing = false; animation = "default"; timeout = 0; diff --git a/scene/2d/animated_sprite.h b/scene/2d/animated_sprite.h index c7606d88aa..7b91a1faef 100644 --- a/scene/2d/animated_sprite.h +++ b/scene/2d/animated_sprite.h @@ -129,6 +129,7 @@ class AnimatedSprite : public Node2D { bool playing; StringName animation; int frame; + float speed_scale; bool centered; Point2 offset; @@ -172,6 +173,9 @@ public: void set_frame(int p_frame); int get_frame() const; + void set_speed_scale(float p_speed_scale); + float get_speed_scale() const; + void set_centered(bool p_center); bool is_centered() const; diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp index 3d3f43d5c6..60766862cc 100644 --- a/scene/2d/tile_map.cpp +++ b/scene/2d/tile_map.cpp @@ -845,13 +845,13 @@ void TileMap::update_cell_bitmask(int p_x, int p_y) { mask |= TileSet::BIND_BOTTOMRIGHT; } } else if (tile_set->autotile_get_bitmask_mode(id) == TileSet::BITMASK_3X3) { - if (tile_set->is_tile_bound(id, get_cell(p_x - 1, p_y - 1)) && tile_set->is_tile_bound(id, get_cell(p_x, p_y - 1)) && tile_set->is_tile_bound(id, get_cell(p_x - 1, p_y))) { + if (tile_set->is_tile_bound(id, get_cell(p_x - 1, p_y - 1))) { mask |= TileSet::BIND_TOPLEFT; } if (tile_set->is_tile_bound(id, get_cell(p_x, p_y - 1))) { mask |= TileSet::BIND_TOP; } - if (tile_set->is_tile_bound(id, get_cell(p_x + 1, p_y - 1)) && tile_set->is_tile_bound(id, get_cell(p_x, p_y - 1)) && tile_set->is_tile_bound(id, get_cell(p_x + 1, p_y))) { + if (tile_set->is_tile_bound(id, get_cell(p_x + 1, p_y - 1))) { mask |= TileSet::BIND_TOPRIGHT; } if (tile_set->is_tile_bound(id, get_cell(p_x - 1, p_y))) { @@ -861,13 +861,13 @@ void TileMap::update_cell_bitmask(int p_x, int p_y) { if (tile_set->is_tile_bound(id, get_cell(p_x + 1, p_y))) { mask |= TileSet::BIND_RIGHT; } - if (tile_set->is_tile_bound(id, get_cell(p_x - 1, p_y + 1)) && tile_set->is_tile_bound(id, get_cell(p_x, p_y + 1)) && tile_set->is_tile_bound(id, get_cell(p_x - 1, p_y))) { + if (tile_set->is_tile_bound(id, get_cell(p_x - 1, p_y + 1))) { mask |= TileSet::BIND_BOTTOMLEFT; } if (tile_set->is_tile_bound(id, get_cell(p_x, p_y + 1))) { mask |= TileSet::BIND_BOTTOM; } - if (tile_set->is_tile_bound(id, get_cell(p_x + 1, p_y + 1)) && tile_set->is_tile_bound(id, get_cell(p_x, p_y + 1)) && tile_set->is_tile_bound(id, get_cell(p_x + 1, p_y))) { + if (tile_set->is_tile_bound(id, get_cell(p_x + 1, p_y + 1))) { mask |= TileSet::BIND_BOTTOMRIGHT; } } diff --git a/scene/3d/physics_joint.cpp b/scene/3d/physics_joint.cpp index 2e9f1a241a..b2d10006f7 100644 --- a/scene/3d/physics_joint.cpp +++ b/scene/3d/physics_joint.cpp @@ -716,6 +716,9 @@ void Generic6DOFJoint::_bind_methods() { ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_limit_x/softness", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_x", "get_param_x", PARAM_LINEAR_LIMIT_SOFTNESS); ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_limit_x/restitution", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_x", "get_param_x", PARAM_LINEAR_RESTITUTION); ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_limit_x/damping", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_x", "get_param_x", PARAM_LINEAR_DAMPING); + ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "linear_motor_x/enabled"), "set_flag_x", "get_flag_x", FLAG_ENABLE_LINEAR_MOTOR); + ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_motor_x/target_velocity"), "set_param_x", "get_param_x", PARAM_LINEAR_MOTOR_TARGET_VELOCITY); + ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_motor_x/force_limit"), "set_param_x", "get_param_x", PARAM_LINEAR_MOTOR_FORCE_LIMIT); ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "angular_limit_x/enabled"), "set_flag_x", "get_flag_x", FLAG_ENABLE_ANGULAR_LIMIT); ADD_PROPERTY(PropertyInfo(Variant::REAL, "angular_limit_x/upper_angle", PROPERTY_HINT_RANGE, "-180,180,0.01"), "_set_angular_hi_limit_x", "_get_angular_hi_limit_x"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "angular_limit_x/lower_angle", PROPERTY_HINT_RANGE, "-180,180,0.01"), "_set_angular_lo_limit_x", "_get_angular_lo_limit_x"); @@ -734,6 +737,9 @@ void Generic6DOFJoint::_bind_methods() { ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_limit_y/softness", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_y", "get_param_y", PARAM_LINEAR_LIMIT_SOFTNESS); ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_limit_y/restitution", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_y", "get_param_y", PARAM_LINEAR_RESTITUTION); ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_limit_y/damping", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_y", "get_param_y", PARAM_LINEAR_DAMPING); + ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "linear_motor_y/enabled"), "set_flag_y", "get_flag_y", FLAG_ENABLE_LINEAR_MOTOR); + ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_motor_y/target_velocity"), "set_param_y", "get_param_y", PARAM_LINEAR_MOTOR_TARGET_VELOCITY); + ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_motor_y/force_limit"), "set_param_y", "get_param_y", PARAM_LINEAR_MOTOR_FORCE_LIMIT); ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "angular_limit_y/enabled"), "set_flag_y", "get_flag_y", FLAG_ENABLE_ANGULAR_LIMIT); ADD_PROPERTY(PropertyInfo(Variant::REAL, "angular_limit_y/upper_angle", PROPERTY_HINT_RANGE, "-180,180,0.01"), "_set_angular_hi_limit_y", "_get_angular_hi_limit_y"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "angular_limit_y/lower_angle", PROPERTY_HINT_RANGE, "-180,180,0.01"), "_set_angular_lo_limit_y", "_get_angular_lo_limit_y"); @@ -752,6 +758,9 @@ void Generic6DOFJoint::_bind_methods() { ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_limit_z/softness", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_z", "get_param_z", PARAM_LINEAR_LIMIT_SOFTNESS); ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_limit_z/restitution", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_z", "get_param_z", PARAM_LINEAR_RESTITUTION); ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_limit_z/damping", PROPERTY_HINT_RANGE, "0.01,16,0.01"), "set_param_z", "get_param_z", PARAM_LINEAR_DAMPING); + ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "linear_motor_z/enabled"), "set_flag_z", "get_flag_z", FLAG_ENABLE_LINEAR_MOTOR); + ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_motor_z/target_velocity"), "set_param_z", "get_param_z", PARAM_LINEAR_MOTOR_TARGET_VELOCITY); + ADD_PROPERTYI(PropertyInfo(Variant::REAL, "linear_motor_z/force_limit"), "set_param_z", "get_param_z", PARAM_LINEAR_MOTOR_FORCE_LIMIT); ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "angular_limit_z/enabled"), "set_flag_z", "get_flag_z", FLAG_ENABLE_ANGULAR_LIMIT); ADD_PROPERTY(PropertyInfo(Variant::REAL, "angular_limit_z/upper_angle", PROPERTY_HINT_RANGE, "-180,180,0.01"), "_set_angular_hi_limit_z", "_get_angular_hi_limit_z"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "angular_limit_z/lower_angle", PROPERTY_HINT_RANGE, "-180,180,0.01"), "_set_angular_lo_limit_z", "_get_angular_lo_limit_z"); @@ -769,6 +778,8 @@ void Generic6DOFJoint::_bind_methods() { BIND_ENUM_CONSTANT(PARAM_LINEAR_LIMIT_SOFTNESS); BIND_ENUM_CONSTANT(PARAM_LINEAR_RESTITUTION); BIND_ENUM_CONSTANT(PARAM_LINEAR_DAMPING); + BIND_ENUM_CONSTANT(PARAM_LINEAR_MOTOR_TARGET_VELOCITY); + BIND_ENUM_CONSTANT(PARAM_LINEAR_MOTOR_FORCE_LIMIT); BIND_ENUM_CONSTANT(PARAM_ANGULAR_LOWER_LIMIT); BIND_ENUM_CONSTANT(PARAM_ANGULAR_UPPER_LIMIT); BIND_ENUM_CONSTANT(PARAM_ANGULAR_LIMIT_SOFTNESS); @@ -783,6 +794,7 @@ void Generic6DOFJoint::_bind_methods() { BIND_ENUM_CONSTANT(FLAG_ENABLE_LINEAR_LIMIT); BIND_ENUM_CONSTANT(FLAG_ENABLE_ANGULAR_LIMIT); BIND_ENUM_CONSTANT(FLAG_ENABLE_MOTOR); + BIND_ENUM_CONSTANT(FLAG_ENABLE_LINEAR_MOTOR); BIND_ENUM_CONSTANT(FLAG_MAX); } @@ -912,6 +924,8 @@ Generic6DOFJoint::Generic6DOFJoint() { set_param_x(PARAM_LINEAR_LIMIT_SOFTNESS, 0.7); set_param_x(PARAM_LINEAR_RESTITUTION, 0.5); set_param_x(PARAM_LINEAR_DAMPING, 1.0); + set_param_x(PARAM_LINEAR_MOTOR_TARGET_VELOCITY, 0); + set_param_x(PARAM_LINEAR_MOTOR_FORCE_LIMIT, 0); set_param_x(PARAM_ANGULAR_LOWER_LIMIT, 0); set_param_x(PARAM_ANGULAR_UPPER_LIMIT, 0); set_param_x(PARAM_ANGULAR_LIMIT_SOFTNESS, 0.5f); @@ -925,12 +939,15 @@ Generic6DOFJoint::Generic6DOFJoint() { set_flag_x(FLAG_ENABLE_ANGULAR_LIMIT, true); set_flag_x(FLAG_ENABLE_LINEAR_LIMIT, true); set_flag_x(FLAG_ENABLE_MOTOR, false); + set_flag_x(FLAG_ENABLE_LINEAR_MOTOR, false); set_param_y(PARAM_LINEAR_LOWER_LIMIT, 0); set_param_y(PARAM_LINEAR_UPPER_LIMIT, 0); set_param_y(PARAM_LINEAR_LIMIT_SOFTNESS, 0.7); set_param_y(PARAM_LINEAR_RESTITUTION, 0.5); set_param_y(PARAM_LINEAR_DAMPING, 1.0); + set_param_y(PARAM_LINEAR_MOTOR_TARGET_VELOCITY, 0); + set_param_y(PARAM_LINEAR_MOTOR_FORCE_LIMIT, 0); set_param_y(PARAM_ANGULAR_LOWER_LIMIT, 0); set_param_y(PARAM_ANGULAR_UPPER_LIMIT, 0); set_param_y(PARAM_ANGULAR_LIMIT_SOFTNESS, 0.5f); @@ -944,12 +961,15 @@ Generic6DOFJoint::Generic6DOFJoint() { set_flag_y(FLAG_ENABLE_ANGULAR_LIMIT, true); set_flag_y(FLAG_ENABLE_LINEAR_LIMIT, true); set_flag_y(FLAG_ENABLE_MOTOR, false); + set_flag_y(FLAG_ENABLE_LINEAR_MOTOR, false); set_param_z(PARAM_LINEAR_LOWER_LIMIT, 0); set_param_z(PARAM_LINEAR_UPPER_LIMIT, 0); set_param_z(PARAM_LINEAR_LIMIT_SOFTNESS, 0.7); set_param_z(PARAM_LINEAR_RESTITUTION, 0.5); set_param_z(PARAM_LINEAR_DAMPING, 1.0); + set_param_z(PARAM_LINEAR_MOTOR_TARGET_VELOCITY, 0); + set_param_z(PARAM_LINEAR_MOTOR_FORCE_LIMIT, 0); set_param_z(PARAM_ANGULAR_LOWER_LIMIT, 0); set_param_z(PARAM_ANGULAR_UPPER_LIMIT, 0); set_param_z(PARAM_ANGULAR_LIMIT_SOFTNESS, 0.5f); @@ -963,4 +983,5 @@ Generic6DOFJoint::Generic6DOFJoint() { set_flag_z(FLAG_ENABLE_ANGULAR_LIMIT, true); set_flag_z(FLAG_ENABLE_LINEAR_LIMIT, true); set_flag_z(FLAG_ENABLE_MOTOR, false); + set_flag_z(FLAG_ENABLE_LINEAR_MOTOR, false); } diff --git a/scene/3d/physics_joint.h b/scene/3d/physics_joint.h index 000109ac55..37870d6f30 100644 --- a/scene/3d/physics_joint.h +++ b/scene/3d/physics_joint.h @@ -249,6 +249,8 @@ public: PARAM_LINEAR_LIMIT_SOFTNESS = PhysicsServer::G6DOF_JOINT_LINEAR_LIMIT_SOFTNESS, PARAM_LINEAR_RESTITUTION = PhysicsServer::G6DOF_JOINT_LINEAR_RESTITUTION, PARAM_LINEAR_DAMPING = PhysicsServer::G6DOF_JOINT_LINEAR_DAMPING, + PARAM_LINEAR_MOTOR_TARGET_VELOCITY = PhysicsServer::G6DOF_JOINT_LINEAR_MOTOR_TARGET_VELOCITY, + PARAM_LINEAR_MOTOR_FORCE_LIMIT = PhysicsServer::G6DOF_JOINT_LINEAR_MOTOR_FORCE_LIMIT, PARAM_ANGULAR_LOWER_LIMIT = PhysicsServer::G6DOF_JOINT_ANGULAR_LOWER_LIMIT, PARAM_ANGULAR_UPPER_LIMIT = PhysicsServer::G6DOF_JOINT_ANGULAR_UPPER_LIMIT, PARAM_ANGULAR_LIMIT_SOFTNESS = PhysicsServer::G6DOF_JOINT_ANGULAR_LIMIT_SOFTNESS, @@ -265,6 +267,7 @@ public: FLAG_ENABLE_LINEAR_LIMIT = PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_LINEAR_LIMIT, FLAG_ENABLE_ANGULAR_LIMIT = PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_ANGULAR_LIMIT, FLAG_ENABLE_MOTOR = PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_MOTOR, + FLAG_ENABLE_LINEAR_MOTOR = PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_LINEAR_MOTOR, FLAG_MAX = PhysicsServer::G6DOF_JOINT_FLAG_MAX }; diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp index 511dc248a0..57b9a9a11b 100644 --- a/scene/gui/item_list.cpp +++ b/scene/gui/item_list.cpp @@ -1121,6 +1121,7 @@ void ItemList::_notification(int p_what) { text_ofs += base_ofs; text_ofs += items[i].rect_cache.position; + FontDrawer drawer(font, Color(1, 1, 1)); for (int j = 0; j < ss; j++) { if (j == line_limit_cache[line]) { @@ -1129,7 +1130,7 @@ void ItemList::_notification(int p_what) { if (line >= max_text_lines) break; } - ofs += font->draw_char(get_canvas_item(), text_ofs + Vector2(ofs + (max_len - line_size_cache[line]) / 2, line * (font_height + line_separation)).floor(), items[i].text[j], items[i].text[j + 1], modulate); + ofs += drawer.draw_char(get_canvas_item(), text_ofs + Vector2(ofs + (max_len - line_size_cache[line]) / 2, line * (font_height + line_separation)).floor(), items[i].text[j], items[i].text[j + 1], modulate); } //special multiline mode @@ -1243,7 +1244,7 @@ bool ItemList::is_pos_at_end_of_items(const Point2 &p_pos) const { String ItemList::get_tooltip(const Point2 &p_pos) const { - int closest = get_item_at_position(p_pos); + int closest = get_item_at_position(p_pos, true); if (closest != -1) { if (!items[closest].tooltip_enabled) { diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp index 830f724b3c..f1b0d36f32 100644 --- a/scene/gui/label.cpp +++ b/scene/gui/label.cpp @@ -93,6 +93,7 @@ void Label::_notification(int p_what) { bool use_outline = get_constant("shadow_as_outline"); Point2 shadow_ofs(get_constant("shadow_offset_x"), get_constant("shadow_offset_y")); int line_spacing = get_constant("line_spacing"); + Color font_outline_modulate = get_color("font_outline_modulate"); style->draw(ci, Rect2(Point2(0, 0), get_size())); @@ -150,6 +151,7 @@ void Label::_notification(int p_what) { int line = 0; int line_to = lines_skipped + (lines_visible > 0 ? lines_visible : 1); + FontDrawer drawer(font, font_outline_modulate); while (wc) { /* handle lines not meant to be drawn quickly */ if (line >= line_to) @@ -244,11 +246,11 @@ void Label::_notification(int p_what) { n = String::char_uppercase(c); } - float move = font->draw_char(ci, Point2(x_ofs_shadow, y_ofs) + shadow_ofs, c, n, font_color_shadow); + float move = font->draw_char(ci, Point2(x_ofs_shadow, y_ofs) + shadow_ofs, c, n, font_color_shadow, false); if (use_outline) { - font->draw_char(ci, Point2(x_ofs_shadow, y_ofs) + Vector2(-shadow_ofs.x, shadow_ofs.y), c, n, font_color_shadow); - font->draw_char(ci, Point2(x_ofs_shadow, y_ofs) + Vector2(shadow_ofs.x, -shadow_ofs.y), c, n, font_color_shadow); - font->draw_char(ci, Point2(x_ofs_shadow, y_ofs) + Vector2(-shadow_ofs.x, -shadow_ofs.y), c, n, font_color_shadow); + font->draw_char(ci, Point2(x_ofs_shadow, y_ofs) + Vector2(-shadow_ofs.x, shadow_ofs.y), c, n, font_color_shadow, false); + font->draw_char(ci, Point2(x_ofs_shadow, y_ofs) + Vector2(shadow_ofs.x, -shadow_ofs.y), c, n, font_color_shadow, false); + font->draw_char(ci, Point2(x_ofs_shadow, y_ofs) + Vector2(-shadow_ofs.x, -shadow_ofs.y), c, n, font_color_shadow, false); } x_ofs_shadow += move; chars_total_shadow++; @@ -265,7 +267,7 @@ void Label::_notification(int p_what) { n = String::char_uppercase(c); } - x_ofs += font->draw_char(ci, Point2(x_ofs, y_ofs), c, n, font_color); + x_ofs += drawer.draw_char(ci, Point2(x_ofs, y_ofs), c, n, font_color); chars_total++; } } diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index 1ceb3f0a8b..e57af0a4c0 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -656,6 +656,7 @@ void LineEdit::_notification(int p_what) { } int caret_height = font->get_height() > y_area ? y_area : font->get_height(); + FontDrawer drawer(font, Color(1, 1, 1)); while (true) { //end of string, break! @@ -683,7 +684,7 @@ void LineEdit::_notification(int p_what) { VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(x_ofs, y_ofs + caret_height), Size2(im_char_width, 1)), font_color); } - font->draw_char(ci, Point2(x_ofs, y_ofs + font_ascent), cchar, next, font_color); + drawer.draw_char(ci, Point2(x_ofs, y_ofs + font_ascent), cchar, next, font_color); x_ofs += im_char_width; ofs++; @@ -704,7 +705,7 @@ void LineEdit::_notification(int p_what) { if (selected) VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(x_ofs, y_ofs), Size2(char_width, caret_height)), selection_color); - font->draw_char(ci, Point2(x_ofs, y_ofs + font_ascent), cchar, next, selected ? font_color_selected : font_color); + drawer.draw_char(ci, Point2(x_ofs, y_ofs + font_ascent), cchar, next, selected ? font_color_selected : font_color); if (char_ofs == cursor_pos && draw_caret) { if (ime_text.length() == 0) { @@ -737,7 +738,7 @@ void LineEdit::_notification(int p_what) { VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(x_ofs, y_ofs + caret_height), Size2(im_char_width, 1)), font_color); } - font->draw_char(ci, Point2(x_ofs, y_ofs + font_ascent), cchar, next, font_color); + drawer.draw_char(ci, Point2(x_ofs, y_ofs + font_ascent), cchar, next, font_color); x_ofs += im_char_width; ofs++; diff --git a/scene/gui/line_edit.h b/scene/gui/line_edit.h index 304faed9bd..e9314ba8dd 100644 --- a/scene/gui/line_edit.h +++ b/scene/gui/line_edit.h @@ -124,7 +124,6 @@ private: void shift_selection_check_post(bool); void selection_fill_at_cursor(); - void selection_delete(); void set_window_pos(int p_pos); void set_cursor_at_pixel_pos(int p_x); @@ -158,6 +157,7 @@ public: void select(int p_from = 0, int p_to = -1); void select_all(); + void selection_delete(); void deselect(); void delete_char(); diff --git a/scene/gui/option_button.cpp b/scene/gui/option_button.cpp index a9402d6404..c5e4149782 100644 --- a/scene/gui/option_button.cpp +++ b/scene/gui/option_button.cpp @@ -297,7 +297,7 @@ void OptionButton::_bind_methods() { ClassDB::bind_method(D_METHOD("_focused"), &OptionButton::_focused); ClassDB::bind_method(D_METHOD("add_item", "label", "id"), &OptionButton::add_item, DEFVAL(-1)); - ClassDB::bind_method(D_METHOD("add_icon_item", "texture", "label", "id"), &OptionButton::add_icon_item); + ClassDB::bind_method(D_METHOD("add_icon_item", "texture", "label", "id"), &OptionButton::add_icon_item, DEFVAL(-1)); ClassDB::bind_method(D_METHOD("set_item_text", "idx", "text"), &OptionButton::set_item_text); ClassDB::bind_method(D_METHOD("set_item_icon", "idx", "texture"), &OptionButton::set_item_icon); ClassDB::bind_method(D_METHOD("set_item_disabled", "idx", "disabled"), &OptionButton::set_item_disabled); diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index 34114ae7db..f34559fc8d 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -86,6 +86,54 @@ RichTextLabel::Item *RichTextLabel::_get_next_item(Item *p_item, bool p_free) { return NULL; } +RichTextLabel::Item *RichTextLabel::_get_prev_item(Item *p_item, bool p_free) { + if (p_free) { + + if (p_item->subitems.size()) { + + return p_item->subitems.back()->get(); + } else if (!p_item->parent) { + return NULL; + } else if (p_item->E->prev()) { + + return p_item->E->prev()->get(); + } else { + //go back until something with a prev is found + while (p_item->parent && !p_item->E->prev()) { + p_item = p_item->parent; + } + + if (p_item->parent) + return p_item->E->prev()->get(); + else + return NULL; + } + + } else { + if (p_item->subitems.size() && p_item->type != ITEM_TABLE) { + + return p_item->subitems.back()->get(); + } else if (p_item->type == ITEM_FRAME) { + return NULL; + } else if (p_item->E->prev()) { + + return p_item->E->prev()->get(); + } else { + //go back until something with a prev is found + while (p_item->type != ITEM_FRAME && !p_item->E->prev()) { + p_item = p_item->parent; + } + + if (p_item->type != ITEM_FRAME) + return p_item->E->prev()->get(); + else + return NULL; + } + } + + return NULL; +} + Rect2 RichTextLabel::_get_text_rect() { Ref<StyleBox> style = get_stylebox("normal"); return Rect2(style->get_offset(), get_size() - style->get_minimum_size()); @@ -286,6 +334,7 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & } rchar = 0; + FontDrawer drawer(font, Color(1, 1, 1)); while (*c) { int end = 0; @@ -395,9 +444,9 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & } if (selected) { - font->draw_char(ci, p_ofs + Point2(align_ofs + pofs, y + lh - line_descent), c[i], c[i + 1], override_selected_font_color ? selection_fg : color); + drawer.draw_char(ci, p_ofs + Point2(align_ofs + pofs, y + lh - line_descent), c[i], c[i + 1], override_selected_font_color ? selection_fg : color); } else { - cw = font->draw_char(ci, p_ofs + Point2(align_ofs + pofs, y + lh - line_descent), c[i], c[i + 1], color); + cw = drawer.draw_char(ci, p_ofs + Point2(align_ofs + pofs, y + lh - line_descent), c[i], c[i + 1], color); } } @@ -1888,7 +1937,7 @@ void RichTextLabel::set_selection_enabled(bool p_enabled) { } } -bool RichTextLabel::search(const String &p_string, bool p_from_selection) { +bool RichTextLabel::search(const String &p_string, bool p_from_selection, bool p_search_previous) { ERR_FAIL_COND_V(!selection.enabled, false); Item *it = main; @@ -1937,7 +1986,10 @@ bool RichTextLabel::search(const String &p_string, bool p_from_selection) { } } - it = _get_next_item(it, true); + if (p_search_previous) + it = _get_prev_item(it, true); + else + it = _get_next_item(it, true); charidx = 0; } diff --git a/scene/gui/rich_text_label.h b/scene/gui/rich_text_label.h index e054ce3935..d4ef735107 100644 --- a/scene/gui/rich_text_label.h +++ b/scene/gui/rich_text_label.h @@ -285,6 +285,7 @@ private: void _gui_input(Ref<InputEvent> p_event); Item *_get_next_item(Item *p_item, bool p_free = false); + Item *_get_prev_item(Item *p_item, bool p_free = false); Rect2 _get_text_rect(); @@ -334,7 +335,7 @@ public: void set_tab_size(int p_spaces); int get_tab_size() const; - bool search(const String &p_string, bool p_from_selection = false); + bool search(const String &p_string, bool p_from_selection = false, bool p_search_previous = false); void scroll_to_line(int p_line); int get_line_count() const; diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index d7f0c16d78..4c9f515ced 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -782,6 +782,7 @@ void TextEdit::_notification(int p_what) { int line = cursor.line_ofs - 1; // another row may be visible during smooth scrolling int draw_amount = visible_rows + (smooth_scroll_enabled ? 1 : 0); + FontDrawer drawer(cache.font, Color(1, 1, 1)); for (int i = 0; i < draw_amount; i++) { line++; @@ -1040,7 +1041,7 @@ void TextEdit::_notification(int p_what) { if (brace_open_mismatch) color = cache.brace_mismatch_color; - cache.font->draw_char(ci, Point2i(char_ofs + char_margin + ofs_x, ofs_y + ascent), '_', str[j + 1], in_selection && override_selected_font_color ? cache.font_selected_color : color); + drawer.draw_char(ci, Point2i(char_ofs + char_margin + ofs_x, ofs_y + ascent), '_', str[j + 1], in_selection && override_selected_font_color ? cache.font_selected_color : color); } if ( @@ -1049,7 +1050,7 @@ void TextEdit::_notification(int p_what) { if (brace_close_mismatch) color = cache.brace_mismatch_color; - cache.font->draw_char(ci, Point2i(char_ofs + char_margin + ofs_x, ofs_y + ascent), '_', str[j + 1], in_selection && override_selected_font_color ? cache.font_selected_color : color); + drawer.draw_char(ci, Point2i(char_ofs + char_margin + ofs_x, ofs_y + ascent), '_', str[j + 1], in_selection && override_selected_font_color ? cache.font_selected_color : color); } } @@ -1082,7 +1083,7 @@ void TextEdit::_notification(int p_what) { VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(char_ofs + char_margin, ofs_y + get_row_height()), Size2(im_char_width, 1)), color); } - cache.font->draw_char(ci, Point2(char_ofs + char_margin + ofs_x, ofs_y + ascent), cchar, next, color); + drawer.draw_char(ci, Point2(char_ofs + char_margin + ofs_x, ofs_y + ascent), cchar, next, color); char_ofs += im_char_width; ofs++; @@ -1109,7 +1110,7 @@ void TextEdit::_notification(int p_what) { } if (str[j] >= 32) { - int w = cache.font->draw_char(ci, Point2i(char_ofs + char_margin + ofs_x, ofs_y + ascent), str[j], str[j + 1], in_selection && override_selected_font_color ? cache.font_selected_color : color); + int w = drawer.draw_char(ci, Point2i(char_ofs + char_margin + ofs_x, ofs_y + ascent), str[j], str[j + 1], in_selection && override_selected_font_color ? cache.font_selected_color : color); if (underlined) { draw_rect(Rect2(char_ofs + char_margin + ofs_x, ofs_y + ascent + 2, w, 1), in_selection && override_selected_font_color ? cache.font_selected_color : color); } @@ -1158,7 +1159,7 @@ void TextEdit::_notification(int p_what) { VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(char_ofs + char_margin, ofs_y + get_row_height()), Size2(im_char_width, 1)), color); } - cache.font->draw_char(ci, Point2(char_ofs + char_margin + ofs_x, ofs_y + ascent), cchar, next, color); + drawer.draw_char(ci, Point2(char_ofs + char_margin + ofs_x, ofs_y + ascent), cchar, next, color); char_ofs += im_char_width; ofs++; diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 11b663e413..295f131db3 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -189,6 +189,7 @@ Viewport::GUI::GUI() { tooltip = NULL; tooltip_popup = NULL; tooltip_label = NULL; + subwindow_visibility_dirty = false; subwindow_order_dirty = false; } @@ -1251,6 +1252,24 @@ void Viewport::warp_mouse(const Vector2 &p_pos) { Input::get_singleton()->warp_mouse_position(gpos); } +void Viewport::_gui_prepare_subwindows() { + + if (gui.subwindow_visibility_dirty) { + + gui.subwindows.clear(); + for (List<Control *>::Element *E = gui.all_known_subwindows.front(); E; E = E->next()) { + if (E->get()->is_visible_in_tree()) { + gui.subwindows.push_back(E->get()); + } + } + + gui.subwindow_visibility_dirty = false; + gui.subwindow_order_dirty = true; + } + + _gui_sort_subwindows(); +} + void Viewport::_gui_sort_subwindows() { if (!gui.subwindow_order_dirty) @@ -1393,7 +1412,7 @@ void Viewport::_gui_call_input(Control *p_control, const Ref<InputEvent> &p_inpu Control *Viewport::_gui_find_control(const Point2 &p_global) { - _gui_sort_subwindows(); + _gui_prepare_subwindows(); for (List<Control *>::Element *E = gui.subwindows.back(); E; E = E->prev()) { @@ -2093,8 +2112,14 @@ List<Control *>::Element *Viewport::_gui_add_root_control(Control *p_control) { List<Control *>::Element *Viewport::_gui_add_subwindow_control(Control *p_control) { - gui.subwindow_order_dirty = true; - return gui.subwindows.push_back(p_control); + p_control->connect("visibility_changed", this, "_subwindow_visibility_changed"); + + if (p_control->is_visible_in_tree()) { + gui.subwindow_order_dirty = true; + gui.subwindows.push_back(p_control); + } + + return gui.all_known_subwindows.push_back(p_control); } void Viewport::_gui_set_subwindow_order_dirty() { @@ -2168,9 +2193,7 @@ void Viewport::_gui_set_drag_preview(Control *p_base, Control *p_control) { p_control->set_position(gui.last_mouse_pos); p_base->get_root_parent_control()->add_child(p_control); //add as child of viewport p_control->raise(); - if (gui.drag_preview) { - memdelete(gui.drag_preview); - } + gui.drag_preview = p_control; } @@ -2181,7 +2204,17 @@ void Viewport::_gui_remove_root_control(List<Control *>::Element *RI) { void Viewport::_gui_remove_subwindow_control(List<Control *>::Element *SI) { - gui.subwindows.erase(SI); + ERR_FAIL_COND(!SI); + + Control *control = SI->get(); + + control->disconnect("visibility_changed", this, "_subwindow_visibility_changed"); + + List<Control *>::Element *E = gui.subwindows.find(control); + if (E) + gui.subwindows.erase(E); + + gui.all_known_subwindows.erase(SI); } void Viewport::_gui_unfocus_control(Control *p_control) { @@ -2208,7 +2241,7 @@ void Viewport::_gui_hid_control(Control *p_control) { */ if (gui.key_focus == p_control) - gui.key_focus = NULL; + _gui_remove_focus(); if (gui.mouse_over == p_control) gui.mouse_over = NULL; if (gui.tooltip == p_control) @@ -2686,6 +2719,8 @@ void Viewport::_bind_methods() { ClassDB::bind_method(D_METHOD("set_shadow_atlas_quadrant_subdiv", "quadrant", "subdiv"), &Viewport::set_shadow_atlas_quadrant_subdiv); ClassDB::bind_method(D_METHOD("get_shadow_atlas_quadrant_subdiv", "quadrant"), &Viewport::get_shadow_atlas_quadrant_subdiv); + ClassDB::bind_method(D_METHOD("_subwindow_visibility_changed"), &Viewport::_subwindow_visibility_changed); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "arvr"), "set_use_arvr", "use_arvr"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "size"), "set_size", "get_size"); @@ -2766,6 +2801,13 @@ void Viewport::_bind_methods() { BIND_ENUM_CONSTANT(CLEAR_MODE_ONLY_NEXT_FRAME); } +void Viewport::_subwindow_visibility_changed() { + + // unfortunately, we don't know the sender, i.e. which subwindow changed; + // so we have to check them all. + gui.subwindow_visibility_dirty = true; +} + Viewport::Viewport() { world_2d = Ref<World2D>(memnew(World2D)); diff --git a/scene/main/viewport.h b/scene/main/viewport.h index 162a902c8a..363414bbad 100644 --- a/scene/main/viewport.h +++ b/scene/main/viewport.h @@ -267,7 +267,9 @@ private: List<Control *> modal_stack; Transform2D focus_inv_xform; bool subwindow_order_dirty; - List<Control *> subwindows; + bool subwindow_visibility_dirty; + List<Control *> subwindows; // visible subwindows + List<Control *> all_known_subwindows; bool roots_order_dirty; List<Control *> roots; int canvas_sort_index; //for sorting items with canvas as root @@ -278,6 +280,7 @@ private: bool disable_input; void _gui_call_input(Control *p_control, const Ref<InputEvent> &p_input); + void _gui_prepare_subwindows(); void _gui_sort_subwindows(); void _gui_sort_roots(); void _gui_sort_modal_stack(); @@ -467,6 +470,8 @@ public: void set_snap_controls_to_pixels(bool p_enable); bool is_snap_controls_to_pixels_enabled() const; + void _subwindow_visibility_changed(); + Viewport(); ~Viewport(); }; diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp index 2e652a00f9..5ac9344f31 100644 --- a/scene/resources/default_theme/default_theme.cpp +++ b/scene/resources/default_theme/default_theme.cpp @@ -415,6 +415,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const theme->set_color("font_color", "Label", Color(1, 1, 1)); theme->set_color("font_color_shadow", "Label", Color(0, 0, 0, 0)); + theme->set_color("font_outline_modulate", "Label", Color(1, 1, 1)); theme->set_constant("shadow_offset_x", "Label", 1 * scale); theme->set_constant("shadow_offset_y", "Label", 1 * scale); diff --git a/scene/resources/dynamic_font.cpp b/scene/resources/dynamic_font.cpp index 3d825b5a27..f41a26a680 100644 --- a/scene/resources/dynamic_font.cpp +++ b/scene/resources/dynamic_font.cpp @@ -33,8 +33,12 @@ #include "os/file_access.h" #include "os/os.h" -bool DynamicFontData::CacheID::operator<(CacheID right) const { +#include FT_STROKER_H + +#define __STDC_LIMIT_MACROS +#include <stdint.h> +bool DynamicFontData::CacheID::operator<(CacheID right) const { return key < right.key; } @@ -212,8 +216,8 @@ Error DynamicFontAtSize::_load() { error = FT_Set_Pixel_Sizes(face, 0, id.size * oversampling); } - ascent = (face->size->metrics.ascender >> 6) / oversampling * scale_color_font; - descent = (-face->size->metrics.descender >> 6) / oversampling * scale_color_font; + ascent = (face->size->metrics.ascender / 64.0) / oversampling * scale_color_font; + descent = (-face->size->metrics.descender / 64.0) / oversampling * scale_color_font; linegap = 0; texture_flags = 0; if (id.mipmaps) @@ -241,18 +245,11 @@ float DynamicFontAtSize::get_descent() const { return descent; } -Size2 DynamicFontAtSize::get_char_size(CharType p_char, CharType p_next, const Vector<Ref<DynamicFontAtSize> > &p_fallbacks) const { +const Pair<const DynamicFontAtSize::Character *, DynamicFontAtSize *> DynamicFontAtSize::_find_char_with_font(CharType p_char, const Vector<Ref<DynamicFontAtSize> > &p_fallbacks) const { + const Character *chr = char_map.getptr(p_char); + ERR_FAIL_COND_V(!chr, (Pair<const Character *, DynamicFontAtSize *>(NULL, NULL))); - if (!valid) - return Size2(1, 1); - const_cast<DynamicFontAtSize *>(this)->_update_char(p_char); - - const Character *c = char_map.getptr(p_char); - ERR_FAIL_COND_V(!c, Size2()); - - Size2 ret(0, get_height()); - - if (!c->found) { + if (!chr->found) { //not found, try in fallbacks for (int i = 0; i < p_fallbacks.size(); i++) { @@ -262,52 +259,53 @@ Size2 DynamicFontAtSize::get_char_size(CharType p_char, CharType p_next, const V continue; fb->_update_char(p_char); - const Character *ch = fb->char_map.getptr(p_char); - ERR_CONTINUE(!ch); + const Character *fallback_chr = fb->char_map.getptr(p_char); + ERR_CONTINUE(!fallback_chr); - if (!ch->found) + if (!fallback_chr->found) continue; - c = ch; - break; + return Pair<const Character *, DynamicFontAtSize *>(fallback_chr, fb); } - //not found, try 0xFFFD to display 'not found'. - if (!c->found) { - - const_cast<DynamicFontAtSize *>(this)->_update_char(0xFFFD); - c = char_map.getptr(0xFFFD); - ERR_FAIL_COND_V(!c, Size2()); - } + //not found, try 0xFFFD to display 'not found'. + const_cast<DynamicFontAtSize *>(this)->_update_char(0xFFFD); + chr = char_map.getptr(0xFFFD); + ERR_FAIL_COND_V(!chr, (Pair<const Character *, DynamicFontAtSize *>(NULL, NULL))); } - if (c->found) { - ret.x = c->advance; - } + return Pair<const Character *, DynamicFontAtSize *>(chr, const_cast<DynamicFontAtSize *>(this)); +} + +float DynamicFontAtSize::_get_kerning_advance(const DynamicFontAtSize *font, CharType p_char, CharType p_next) const { + float advance = 0.0; if (p_next) { FT_Vector delta; - FT_Get_Kerning(face, p_char, p_next, FT_KERNING_DEFAULT, &delta); + FT_Get_Kerning(font->face, p_char, p_next, FT_KERNING_DEFAULT, &delta); + advance = (delta.x / 64.0) / oversampling; + } - if (delta.x == 0) { - for (int i = 0; i < p_fallbacks.size(); i++) { + return advance; +} - DynamicFontAtSize *fb = const_cast<DynamicFontAtSize *>(p_fallbacks[i].ptr()); - if (!fb->valid) - continue; +Size2 DynamicFontAtSize::get_char_size(CharType p_char, CharType p_next, const Vector<Ref<DynamicFontAtSize> > &p_fallbacks) const { - FT_Get_Kerning(fb->face, p_char, p_next, FT_KERNING_DEFAULT, &delta); + if (!valid) + return Size2(1, 1); + const_cast<DynamicFontAtSize *>(this)->_update_char(p_char); - if (delta.x == 0) - continue; + Pair<const Character *, DynamicFontAtSize *> char_pair_with_font = _find_char_with_font(p_char, p_fallbacks); + const Character *ch = char_pair_with_font.first; + DynamicFontAtSize *font = char_pair_with_font.second; + ERR_FAIL_COND_V(!ch, Size2()); - ret.x += (delta.x >> 6) / oversampling; - break; - } - } else { - ret.x += (delta.x >> 6) / oversampling; - } + Size2 ret(0, get_height()); + + if (ch->found) { + ret.x = ch->advance; } + ret.x += _get_kerning_advance(font, p_char, p_next); // ensures oversampled glyphs will have enough space when this value is used by clipping/wrapping algorithms ret.x = Math::ceil(ret.x); @@ -324,102 +322,42 @@ void DynamicFontAtSize::set_texture_flags(uint32_t p_flags) { } } -float DynamicFontAtSize::draw_char(RID p_canvas_item, const Point2 &p_pos, CharType p_char, CharType p_next, const Color &p_modulate, const Vector<Ref<DynamicFontAtSize> > &p_fallbacks) const { +float DynamicFontAtSize::draw_char(RID p_canvas_item, const Point2 &p_pos, CharType p_char, CharType p_next, const Color &p_modulate, const Vector<Ref<DynamicFontAtSize> > &p_fallbacks, bool p_advance_only) const { if (!valid) return 0; const_cast<DynamicFontAtSize *>(this)->_update_char(p_char); - const Character *c = char_map.getptr(p_char); + Pair<const Character *, DynamicFontAtSize *> char_pair_with_font = _find_char_with_font(p_char, p_fallbacks); + const Character *ch = char_pair_with_font.first; + DynamicFontAtSize *font = char_pair_with_font.second; - float advance = 0; + ERR_FAIL_COND_V(!ch, 0.0); - if (!c->found) { - - //not found, try in fallbacks - bool used_fallback = false; - - for (int i = 0; i < p_fallbacks.size(); i++) { - - DynamicFontAtSize *fb = const_cast<DynamicFontAtSize *>(p_fallbacks[i].ptr()); - if (!fb->valid) - continue; + float advance = 0.0; - fb->_update_char(p_char); - const Character *ch = fb->char_map.getptr(p_char); - ERR_CONTINUE(!ch); + if (ch->found) { + ERR_FAIL_COND_V(ch->texture_idx < -1 || ch->texture_idx >= font->textures.size(), 0); - if (!ch->found) - continue; + if (!p_advance_only && ch->texture_idx != -1) { Point2 cpos = p_pos; cpos.x += ch->h_align; - cpos.y -= fb->get_ascent(); + cpos.y -= font->get_ascent(); cpos.y += ch->v_align; - ERR_FAIL_COND_V(ch->texture_idx < -1 || ch->texture_idx >= fb->textures.size(), 0); - if (ch->texture_idx != -1) { - Color modulate = p_modulate; - if (FT_HAS_COLOR(fb->face)) { - modulate.r = modulate.g = modulate.b = 1; - } - VisualServer::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, Rect2(cpos, ch->rect.size * Vector2(fb->scale_color_font, fb->scale_color_font)), fb->textures[ch->texture_idx].texture->get_rid(), ch->rect_uv, modulate, false, RID(), false); - } - advance = ch->advance; - used_fallback = true; - break; - } - //not found, try 0xFFFD to display 'not found'. - - if (!used_fallback) { - - const_cast<DynamicFontAtSize *>(this)->_update_char(0xFFFD); - c = char_map.getptr(0xFFFD); - } - } - - if (c->found) { - - Point2 cpos = p_pos; - cpos.x += c->h_align; - cpos.y -= get_ascent(); - cpos.y += c->v_align; - ERR_FAIL_COND_V(c->texture_idx < -1 || c->texture_idx >= textures.size(), 0); - if (c->texture_idx != -1) { Color modulate = p_modulate; if (FT_HAS_COLOR(face)) { - modulate.r = modulate.g = modulate.b = 1; + modulate.r = modulate.g = modulate.b = 1.0; } - VisualServer::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, Rect2(cpos, c->rect.size * Vector2(scale_color_font, scale_color_font)), textures[c->texture_idx].texture->get_rid(), c->rect_uv, modulate, false, RID(), false); + RID texture = font->textures[ch->texture_idx].texture->get_rid(); + VisualServer::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, Rect2(cpos, ch->rect.size * Vector2(font->scale_color_font, font->scale_color_font)), texture, ch->rect_uv, modulate, false, RID(), false); } - advance = c->advance; - //textures[c->texture_idx].texture->draw(p_canvas_item,Vector2()); - } - if (p_next) { - - FT_Vector delta; - FT_Get_Kerning(face, p_char, p_next, FT_KERNING_DEFAULT, &delta); - - if (delta.x == 0) { - for (int i = 0; i < p_fallbacks.size(); i++) { - - DynamicFontAtSize *fb = const_cast<DynamicFontAtSize *>(p_fallbacks[i].ptr()); - if (!fb->valid) - continue; - - FT_Get_Kerning(fb->face, p_char, p_next, FT_KERNING_DEFAULT, &delta); - - if (delta.x == 0) - continue; - - advance += (delta.x >> 6) / oversampling; - break; - } - } else { - advance += (delta.x >> 6) / oversampling; - } + advance = ch->advance; } + advance += _get_kerning_advance(font, p_char, p_next); + return advance; } @@ -443,96 +381,37 @@ void DynamicFontAtSize::_ft_stream_close(FT_Stream stream) { memdelete(f); } -void DynamicFontAtSize::_update_char(CharType p_char) { - - if (char_map.has(p_char)) - return; - - _THREAD_SAFE_METHOD_ - - FT_GlyphSlot slot = face->glyph; - - if (FT_Get_Char_Index(face, p_char) == 0) { - //not found - Character ch; - ch.texture_idx = -1; - ch.advance = 0; - ch.h_align = 0; - ch.v_align = 0; - ch.found = false; - - char_map[p_char] = ch; - return; - } - - int ft_hinting; - - switch (font->hinting) { - case DynamicFontData::HINTING_NONE: - ft_hinting = FT_LOAD_NO_HINTING; - break; - case DynamicFontData::HINTING_LIGHT: - ft_hinting = FT_LOAD_TARGET_LIGHT; - break; - default: - ft_hinting = FT_LOAD_TARGET_NORMAL; - break; - } - - int error = FT_Load_Char(face, p_char, FT_HAS_COLOR(face) ? FT_LOAD_COLOR : FT_LOAD_DEFAULT | (font->force_autohinter ? FT_LOAD_FORCE_AUTOHINT : 0) | ft_hinting); - if (!error) { - error = FT_Render_Glyph(face->glyph, FT_RENDER_MODE_NORMAL); - } - if (error) { - - int advance = 0; - Character ch; - ch.texture_idx = -1; - ch.advance = advance; - ch.h_align = 0; - ch.v_align = 0; - ch.found = false; - - char_map[p_char] = ch; - - return; - } - - int w = slot->bitmap.width; - int h = slot->bitmap.rows; - int yofs = slot->bitmap_top; - int xofs = slot->bitmap_left; - int advance = slot->advance.x >> 6; - - int mw = w + rect_margin * 2; - int mh = h + rect_margin * 2; - - if (mw > 4096 || mh > 4096) { - - ERR_FAIL_COND(mw > 4096); - ERR_FAIL_COND(mh > 4096); - } +DynamicFontAtSize::Character DynamicFontAtSize::Character::not_found() { + Character ch; + ch.texture_idx = -1; + ch.advance = 0; + ch.h_align = 0; + ch.v_align = 0; + ch.found = false; + return ch; +} - //find a texture to fit this... +DynamicFontAtSize::TexturePosition DynamicFontAtSize::_find_texture_pos_for_glyph(int p_color_size, Image::Format p_image_format, int p_width, int p_height) { + TexturePosition ret; + ret.index = -1; + ret.x = 0; + ret.y = 0; - int color_size = slot->bitmap.pixel_mode == FT_PIXEL_MODE_BGRA ? 4 : 2; - Image::Format require_format = color_size == 4 ? Image::FORMAT_RGBA8 : Image::FORMAT_LA8; - int tex_index = -1; - int tex_x = 0; - int tex_y = 0; + int mw = p_width; + int mh = p_height; for (int i = 0; i < textures.size(); i++) { CharTexture &ct = textures[i]; - if (ct.texture->get_format() != require_format) + if (ct.texture->get_format() != p_image_format) continue; if (mw > ct.texture_size || mh > ct.texture_size) //too big for this texture continue; - tex_y = 0x7FFFFFFF; - tex_x = 0; + ret.y = 0x7FFFFFFF; + ret.x = 0; for (int j = 0; j < ct.texture_size - mw; j++) { @@ -545,25 +424,27 @@ void DynamicFontAtSize::_update_char(CharType p_char) { max_y = y; } - if (max_y < tex_y) { - tex_y = max_y; - tex_x = j; + if (max_y < ret.y) { + ret.y = max_y; + ret.x = j; } } - if (tex_y == 0x7FFFFFFF || tex_y + mh > ct.texture_size) + if (ret.y == 0x7FFFFFFF || ret.y + mh > ct.texture_size) continue; //fail, could not fit it here - tex_index = i; + ret.index = i; break; } - if (tex_index == -1) { + //print_line("CHAR: "+String::chr(p_char)+" TEX INDEX: "+itos(tex_index)+" X: "+itos(tex_x)+" Y: "+itos(tex_y)); + + if (ret.index == -1) { //could not find texture to fit, create one - tex_x = 0; - tex_y = 0; + ret.x = 0; + ret.y = 0; - int texsize = MAX(id.size * 8, 256); + int texsize = MAX(id.size * oversampling * 8, 256); if (mw > texsize) texsize = mw; //special case, adapt to it? if (mh > texsize) @@ -575,13 +456,13 @@ void DynamicFontAtSize::_update_char(CharType p_char) { CharTexture tex; tex.texture_size = texsize; - tex.imgdata.resize(texsize * texsize * color_size); + tex.imgdata.resize(texsize * texsize * p_color_size); //grayscale alpha { //zero texture PoolVector<uint8_t>::Write w = tex.imgdata.write(); - ERR_FAIL_COND(texsize * texsize * color_size > tex.imgdata.size()); - for (int i = 0; i < texsize * texsize * color_size; i++) { + ERR_FAIL_COND_V(texsize * texsize * p_color_size > tex.imgdata.size(), ret); + for (int i = 0; i < texsize * texsize * p_color_size; i++) { w[i] = 0; } } @@ -590,12 +471,31 @@ void DynamicFontAtSize::_update_char(CharType p_char) { tex.offsets[i] = 0; textures.push_back(tex); - tex_index = textures.size() - 1; + ret.index = textures.size() - 1; } + return ret; +} + +DynamicFontAtSize::Character DynamicFontAtSize::_bitmap_to_character(FT_Bitmap bitmap, int yofs, int xofs, float advance) { + int w = bitmap.width; + int h = bitmap.rows; + + int mw = w + rect_margin * 2; + int mh = h + rect_margin * 2; + + ERR_FAIL_COND_V(mw > 4096, Character::not_found()); + ERR_FAIL_COND_V(mh > 4096, Character::not_found()); + + int color_size = bitmap.pixel_mode == FT_PIXEL_MODE_BGRA ? 4 : 2; + Image::Format require_format = color_size == 4 ? Image::FORMAT_RGBA8 : Image::FORMAT_LA8; + + TexturePosition tex_pos = _find_texture_pos_for_glyph(color_size, require_format, mw, mh); + ERR_FAIL_COND_V(tex_pos.index < 0, Character::not_found()); + //fit character in char texture - CharTexture &tex = textures[tex_index]; + CharTexture &tex = textures[tex_pos.index]; { PoolVector<uint8_t>::Write wr = tex.imgdata.write(); @@ -603,30 +503,30 @@ void DynamicFontAtSize::_update_char(CharType p_char) { for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { - int ofs = ((i + tex_y + rect_margin) * tex.texture_size + j + tex_x + rect_margin) * color_size; - ERR_FAIL_COND(ofs >= tex.imgdata.size()); - switch (slot->bitmap.pixel_mode) { + int ofs = ((i + tex_pos.y + rect_margin) * tex.texture_size + j + tex_pos.x + rect_margin) * color_size; + ERR_FAIL_COND_V(ofs >= tex.imgdata.size(), Character::not_found()); + switch (bitmap.pixel_mode) { case FT_PIXEL_MODE_MONO: { - int byte = i * slot->bitmap.pitch + (j >> 3); + int byte = i * bitmap.pitch + (j >> 3); int bit = 1 << (7 - (j % 8)); wr[ofs + 0] = 255; //grayscale as 1 - wr[ofs + 1] = slot->bitmap.buffer[byte] & bit ? 255 : 0; + wr[ofs + 1] = bitmap.buffer[byte] & bit ? 255 : 0; } break; case FT_PIXEL_MODE_GRAY: wr[ofs + 0] = 255; //grayscale as 1 - wr[ofs + 1] = slot->bitmap.buffer[i * slot->bitmap.pitch + j]; + wr[ofs + 1] = bitmap.buffer[i * bitmap.pitch + j]; break; case FT_PIXEL_MODE_BGRA: { - int ofs_color = i * slot->bitmap.pitch + (j << 2); - wr[ofs + 2] = slot->bitmap.buffer[ofs_color + 0]; - wr[ofs + 1] = slot->bitmap.buffer[ofs_color + 1]; - wr[ofs + 0] = slot->bitmap.buffer[ofs_color + 2]; - wr[ofs + 3] = slot->bitmap.buffer[ofs_color + 3]; + int ofs_color = i * bitmap.pitch + (j << 2); + wr[ofs + 2] = bitmap.buffer[ofs_color + 0]; + wr[ofs + 1] = bitmap.buffer[ofs_color + 1]; + wr[ofs + 0] = bitmap.buffer[ofs_color + 2]; + wr[ofs + 3] = bitmap.buffer[ofs_color + 3]; } break; // TODO: FT_PIXEL_MODE_LCD default: - ERR_EXPLAIN("Font uses unsupported pixel format: " + itos(slot->bitmap.pixel_mode)); - ERR_FAIL(); + ERR_EXPLAIN("Font uses unsupported pixel format: " + itos(bitmap.pixel_mode)); + ERR_FAIL_V(Character::not_found()); break; } } @@ -648,31 +548,105 @@ void DynamicFontAtSize::_update_char(CharType p_char) { // update height array - for (int k = tex_x; k < tex_x + mw; k++) { - - tex.offsets[k] = tex_y + mh; + for (int k = tex_pos.x; k < tex_pos.x + mw; k++) { + tex.offsets[k] = tex_pos.y + mh; } Character chr; chr.h_align = xofs * scale_color_font / oversampling; chr.v_align = ascent - (yofs * scale_color_font / oversampling); // + ascent - descent; chr.advance = advance * scale_color_font / oversampling; - chr.texture_idx = tex_index; + chr.texture_idx = tex_pos.index; chr.found = true; - chr.rect_uv = Rect2(tex_x + rect_margin, tex_y + rect_margin, w, h); + chr.rect_uv = Rect2(tex_pos.x + rect_margin, tex_pos.y + rect_margin, w, h); chr.rect = chr.rect_uv; chr.rect.position /= oversampling; - chr.rect.size /= oversampling; + chr.rect.size = chr.rect.size * scale_color_font / oversampling; + return chr; +} - char_map[p_char] = chr; +DynamicFontAtSize::Character DynamicFontAtSize::_make_outline_char(CharType p_char) { + Character ret = Character::not_found(); + + if (FT_Load_Char(face, p_char, FT_LOAD_NO_BITMAP | (font->force_autohinter ? FT_LOAD_FORCE_AUTOHINT : 0)) != 0) + return ret; + + FT_Stroker stroker; + if (FT_Stroker_New(library, &stroker) != 0) + return ret; + + FT_Stroker_Set(stroker, (int)(id.outline_size * oversampling * 64.0), FT_STROKER_LINECAP_BUTT, FT_STROKER_LINEJOIN_ROUND, 0); + FT_Glyph glyph; + FT_BitmapGlyph glyph_bitmap; + + if (FT_Get_Glyph(face->glyph, &glyph) != 0) + goto cleanup_stroker; + if (FT_Glyph_Stroke(&glyph, stroker, 1) != 0) + goto cleanup_glyph; + if (FT_Glyph_To_Bitmap(&glyph, FT_RENDER_MODE_NORMAL, 0, 1) != 0) + goto cleanup_glyph; + + glyph_bitmap = (FT_BitmapGlyph)glyph; + ret = _bitmap_to_character(glyph_bitmap->bitmap, glyph_bitmap->top, glyph_bitmap->left, glyph->advance.x / 65536.0); + +cleanup_glyph: + FT_Done_Glyph(glyph); +cleanup_stroker: + FT_Stroker_Done(stroker); + return ret; } -bool DynamicFontAtSize::update_oversampling() { - if (oversampling == font_oversampling) - return false; - if (!valid) - return false; +void DynamicFontAtSize::_update_char(CharType p_char) { + + if (char_map.has(p_char)) + return; + + _THREAD_SAFE_METHOD_ + + Character character = Character::not_found(); + + FT_GlyphSlot slot = face->glyph; + + if (FT_Get_Char_Index(face, p_char) == 0) { + char_map[p_char] = character; + return; + } + + int ft_hinting; + + switch (font->hinting) { + case DynamicFontData::HINTING_NONE: + ft_hinting = FT_LOAD_NO_HINTING; + break; + case DynamicFontData::HINTING_LIGHT: + ft_hinting = FT_LOAD_TARGET_LIGHT; + break; + default: + ft_hinting = FT_LOAD_TARGET_NORMAL; + break; + } + + int error = FT_Load_Char(face, p_char, FT_HAS_COLOR(face) ? FT_LOAD_COLOR : FT_LOAD_DEFAULT | (font->force_autohinter ? FT_LOAD_FORCE_AUTOHINT : 0)); + if (error) { + char_map[p_char] = character; + return; + } + + if (id.outline_size > 0) { + character = _make_outline_char(p_char); + } else { + error = FT_Render_Glyph(face->glyph, FT_RENDER_MODE_NORMAL); + if (!error) + character = _bitmap_to_character(slot->bitmap, slot->bitmap_top, slot->bitmap_left, slot->advance.x / 64.0); + } + + char_map[p_char] = character; +} + +void DynamicFontAtSize::update_oversampling() { + if (oversampling == font_oversampling || !valid) + return; FT_Done_FreeType(library); textures.clear(); @@ -680,8 +654,6 @@ bool DynamicFontAtSize::update_oversampling() { oversampling = font_oversampling; valid = false; _load(); - - return true; } DynamicFontAtSize::DynamicFontAtSize() { @@ -710,11 +682,27 @@ DynamicFontAtSize::~DynamicFontAtSize() { void DynamicFont::_reload_cache() { ERR_FAIL_COND(cache_id.size < 1); - if (!data.is_valid()) + if (!data.is_valid()) { + data_at_size.unref(); + outline_data_at_size.unref(); + fallback_data_at_size.resize(0); + fallback_outline_data_at_size.resize(0); return; + } + data_at_size = data->_get_dynamic_font_at_size(cache_id); + if (outline_cache_id.outline_size > 0) { + outline_data_at_size = data->_get_dynamic_font_at_size(outline_cache_id); + fallback_outline_data_at_size.resize(fallback_data_at_size.size()); + } else { + outline_data_at_size.unref(); + fallback_outline_data_at_size.resize(0); + } + for (int i = 0; i < fallbacks.size(); i++) { fallback_data_at_size[i] = fallbacks[i]->_get_dynamic_font_at_size(cache_id); + if (outline_cache_id.outline_size > 0) + fallback_outline_data_at_size[i] = fallbacks[i]->_get_dynamic_font_at_size(outline_cache_id); } emit_changed(); @@ -724,12 +712,10 @@ void DynamicFont::_reload_cache() { void DynamicFont::set_font_data(const Ref<DynamicFontData> &p_data) { data = p_data; - if (data.is_valid()) - data_at_size = data->_get_dynamic_font_at_size(cache_id); - else - data_at_size = Ref<DynamicFontAtSize>(); + _reload_cache(); emit_changed(); + _change_notify(); } Ref<DynamicFontData> DynamicFont::get_font_data() const { @@ -742,6 +728,7 @@ void DynamicFont::set_size(int p_size) { if (cache_id.size == p_size) return; cache_id.size = p_size; + outline_cache_id.size = p_size; _reload_cache(); } @@ -750,6 +737,30 @@ int DynamicFont::get_size() const { return cache_id.size; } +void DynamicFont::set_outline_size(int p_size) { + if (outline_cache_id.outline_size == p_size) + return; + ERR_FAIL_COND(p_size < 0 || p_size > UINT8_MAX); + outline_cache_id.outline_size = p_size; + _reload_cache(); +} + +int DynamicFont::get_outline_size() const { + return outline_cache_id.outline_size; +} + +void DynamicFont::set_outline_color(Color p_color) { + if (p_color != outline_color) { + outline_color = p_color; + emit_changed(); + _change_notify(); + } +} + +Color DynamicFont::get_outline_color() const { + return outline_color; +} + bool DynamicFont::get_use_mipmaps() const { return cache_id.mipmaps; @@ -760,6 +771,7 @@ void DynamicFont::set_use_mipmaps(bool p_enable) { if (cache_id.mipmaps == p_enable) return; cache_id.mipmaps = p_enable; + outline_cache_id.mipmaps = p_enable; _reload_cache(); } @@ -773,6 +785,7 @@ void DynamicFont::set_use_filter(bool p_enable) { if (cache_id.filter == p_enable) return; cache_id.filter = p_enable; + outline_cache_id.filter = p_enable; _reload_cache(); } @@ -862,13 +875,24 @@ bool DynamicFont::is_distance_field_hint() const { return false; } -float DynamicFont::draw_char(RID p_canvas_item, const Point2 &p_pos, CharType p_char, CharType p_next, const Color &p_modulate) const { +bool DynamicFont::has_outline() const { + return outline_cache_id.outline_size > 0; +} + +float DynamicFont::draw_char(RID p_canvas_item, const Point2 &p_pos, CharType p_char, CharType p_next, const Color &p_modulate, bool p_outline) const { + const Ref<DynamicFontAtSize> &font_at_size = p_outline && outline_cache_id.outline_size > 0 ? outline_data_at_size : data_at_size; - if (!data_at_size.is_valid()) + if (!font_at_size.is_valid()) return 0; - return data_at_size->draw_char(p_canvas_item, p_pos, p_char, p_next, p_modulate, fallback_data_at_size) + spacing_char; + const Vector<Ref<DynamicFontAtSize> > &fallbacks = p_outline && outline_cache_id.outline_size > 0 ? fallback_outline_data_at_size : fallback_data_at_size; + Color color = p_outline && outline_cache_id.outline_size > 0 ? p_modulate * outline_color : p_modulate; + + // If requested outline draw, but no outline is present, simply return advance without drawing anything + bool advance_only = p_outline && outline_cache_id.outline_size == 0; + return font_at_size->draw_char(p_canvas_item, p_pos, p_char, p_next, color, fallbacks, advance_only) + spacing_char; } + void DynamicFont::set_fallback(int p_idx, const Ref<DynamicFontData> &p_data) { ERR_FAIL_COND(p_data.is_null()); @@ -882,6 +906,8 @@ void DynamicFont::add_fallback(const Ref<DynamicFontData> &p_data) { ERR_FAIL_COND(p_data.is_null()); fallbacks.push_back(p_data); fallback_data_at_size.push_back(fallbacks[fallbacks.size() - 1]->_get_dynamic_font_at_size(cache_id)); //const.. + if (outline_cache_id.outline_size > 0) + fallback_outline_data_at_size.push_back(fallbacks[fallbacks.size() - 1]->_get_dynamic_font_at_size(outline_cache_id)); _change_notify(); emit_changed(); @@ -966,6 +992,12 @@ void DynamicFont::_bind_methods() { ClassDB::bind_method(D_METHOD("set_size", "data"), &DynamicFont::set_size); ClassDB::bind_method(D_METHOD("get_size"), &DynamicFont::get_size); + ClassDB::bind_method(D_METHOD("set_outline_size", "size"), &DynamicFont::set_outline_size); + ClassDB::bind_method(D_METHOD("get_outline_size"), &DynamicFont::get_outline_size); + + ClassDB::bind_method(D_METHOD("set_outline_color", "color"), &DynamicFont::set_outline_color); + ClassDB::bind_method(D_METHOD("get_outline_color"), &DynamicFont::get_outline_color); + ClassDB::bind_method(D_METHOD("set_use_mipmaps", "enable"), &DynamicFont::set_use_mipmaps); ClassDB::bind_method(D_METHOD("get_use_mipmaps"), &DynamicFont::get_use_mipmaps); ClassDB::bind_method(D_METHOD("set_use_filter", "enable"), &DynamicFont::set_use_filter); @@ -981,6 +1013,8 @@ void DynamicFont::_bind_methods() { ADD_GROUP("Settings", ""); ADD_PROPERTY(PropertyInfo(Variant::INT, "size"), "set_size", "get_size"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "outline_size"), "set_outline_size", "get_outline_size"); + ADD_PROPERTY(PropertyInfo(Variant::COLOR, "outline_color"), "set_outline_color", "get_outline_color"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_mipmaps"), "set_use_mipmaps", "get_use_mipmaps"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_filter"), "set_use_filter", "get_use_filter"); ADD_GROUP("Extra Spacing", "extra_spacing"); @@ -1008,6 +1042,7 @@ DynamicFont::DynamicFont() : spacing_bottom = 0; spacing_char = 0; spacing_space = 0; + outline_color = Color(1, 1, 1); if (dynamic_font_mutex) dynamic_font_mutex->lock(); dynamic_fonts.add(&font_list); @@ -1043,7 +1078,8 @@ void DynamicFont::update_oversampling() { SelfList<DynamicFont> *E = dynamic_fonts.first(); while (E) { - if (E->self()->data_at_size.is_valid() && E->self()->data_at_size->update_oversampling()) { + if (E->self()->data_at_size.is_valid()) { + E->self()->data_at_size->update_oversampling(); changed.push_back(Ref<DynamicFont>(E->self())); } E = E->next(); diff --git a/scene/resources/dynamic_font.h b/scene/resources/dynamic_font.h index db8bd87587..f460bca2d4 100644 --- a/scene/resources/dynamic_font.h +++ b/scene/resources/dynamic_font.h @@ -35,6 +35,7 @@ #include "io/resource_loader.h" #include "os/mutex.h" #include "os/thread_safe.h" +#include "pair.h" #include "scene/resources/font.h" #include <ft2build.h> @@ -49,10 +50,10 @@ class DynamicFontData : public Resource { public: struct CacheID { - union { struct { uint32_t size : 16; + uint32_t outline_size : 8; bool mipmaps : 1; bool filter : 1; }; @@ -148,8 +149,22 @@ class DynamicFontAtSize : public Reference { texture_idx = 0; v_align = 0; } + + static Character not_found(); }; + struct TexturePosition { + int index; + int x; + int y; + }; + + const Pair<const Character *, DynamicFontAtSize *> _find_char_with_font(CharType p_char, const Vector<Ref<DynamicFontAtSize> > &p_fallbacks) const; + Character _make_outline_char(CharType p_char); + float _get_kerning_advance(const DynamicFontAtSize *font, CharType p_char, CharType p_next) const; + TexturePosition _find_texture_pos_for_glyph(int p_color_size, Image::Format p_image_format, int p_width, int p_height); + Character _bitmap_to_character(FT_Bitmap bitmap, int yofs, int xofs, float advance); + static unsigned long _ft_stream_io(FT_Stream stream, unsigned long offset, unsigned char *buffer, unsigned long count); static void _ft_stream_close(FT_Stream stream); @@ -174,10 +189,10 @@ public: Size2 get_char_size(CharType p_char, CharType p_next, const Vector<Ref<DynamicFontAtSize> > &p_fallbacks) const; - float draw_char(RID p_canvas_item, const Point2 &p_pos, CharType p_char, CharType p_next, const Color &p_modulate, const Vector<Ref<DynamicFontAtSize> > &p_fallbacks) const; + float draw_char(RID p_canvas_item, const Point2 &p_pos, CharType p_char, CharType p_next, const Color &p_modulate, const Vector<Ref<DynamicFontAtSize> > &p_fallbacks, bool p_advance_only = false) const; void set_texture_flags(uint32_t p_flags); - bool update_oversampling(); + void update_oversampling(); DynamicFontAtSize(); ~DynamicFontAtSize(); @@ -200,17 +215,23 @@ public: private: Ref<DynamicFontData> data; Ref<DynamicFontAtSize> data_at_size; + Ref<DynamicFontAtSize> outline_data_at_size; Vector<Ref<DynamicFontData> > fallbacks; Vector<Ref<DynamicFontAtSize> > fallback_data_at_size; + Vector<Ref<DynamicFontAtSize> > fallback_outline_data_at_size; DynamicFontData::CacheID cache_id; + DynamicFontData::CacheID outline_cache_id; + bool valid; int spacing_top; int spacing_bottom; int spacing_char; int spacing_space; + Color outline_color; + protected: void _reload_cache(); @@ -227,6 +248,12 @@ public: void set_size(int p_size); int get_size() const; + void set_outline_size(int p_size); + int get_outline_size() const; + + void set_outline_color(Color p_color); + Color get_outline_color() const; + bool get_use_mipmaps() const; void set_use_mipmaps(bool p_enable); @@ -251,7 +278,9 @@ public: virtual bool is_distance_field_hint() const; - virtual float draw_char(RID p_canvas_item, const Point2 &p_pos, CharType p_char, CharType p_next = 0, const Color &p_modulate = Color(1, 1, 1)) const; + virtual bool has_outline() const; + + virtual float draw_char(RID p_canvas_item, const Point2 &p_pos, CharType p_char, CharType p_next = 0, const Color &p_modulate = Color(1, 1, 1), bool p_outline = false) const; SelfList<DynamicFont> font_list; diff --git a/scene/resources/dynamic_font_stb.cpp b/scene/resources/dynamic_font_stb.cpp index 098b794a95..29f1106d16 100644 --- a/scene/resources/dynamic_font_stb.cpp +++ b/scene/resources/dynamic_font_stb.cpp @@ -162,7 +162,7 @@ Size2 DynamicFontAtSize::get_char_size(CharType p_char, CharType p_next) const { return ret; } -float DynamicFontAtSize::draw_char(RID p_canvas_item, const Point2 &p_pos, CharType p_char, CharType p_next, const Color &p_modulate) const { +float DynamicFontAtSize::draw_char(RID p_canvas_item, const Point2 &p_pos, CharType p_char, CharType p_next, const Color &p_modulate, bool p_outline) const { const_cast<DynamicFontAtSize *>(this)->_update_char(p_char); @@ -172,13 +172,15 @@ float DynamicFontAtSize::draw_char(RID p_canvas_item, const Point2 &p_pos, CharT return 0; } - Point2 cpos = p_pos; - cpos.x += c->h_align; - cpos.y -= get_ascent(); - cpos.y += c->v_align; - ERR_FAIL_COND_V(c->texture_idx < -1 || c->texture_idx >= textures.size(), 0); - if (c->texture_idx != -1) - VisualServer::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, Rect2(cpos, c->rect.size), textures[c->texture_idx].texture->get_rid(), c->rect, p_modulate); + if (!p_outline) { + Point2 cpos = p_pos; + cpos.x += c->h_align; + cpos.y -= get_ascent(); + cpos.y += c->v_align; + ERR_FAIL_COND_V(c->texture_idx < -1 || c->texture_idx >= textures.size(), 0); + if (c->texture_idx != -1) + VisualServer::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, Rect2(cpos, c->rect.size), textures[c->texture_idx].texture->get_rid(), c->rect, p_modulate); + } //textures[c->texture_idx].texture->draw(p_canvas_item,Vector2()); @@ -459,12 +461,12 @@ bool DynamicFont::is_distance_field_hint() const { return false; } -float DynamicFont::draw_char(RID p_canvas_item, const Point2 &p_pos, CharType p_char, CharType p_next, const Color &p_modulate) const { +float DynamicFont::draw_char(RID p_canvas_item, const Point2 &p_pos, CharType p_char, CharType p_next, const Color &p_modulate, bool p_outline) const { if (!data_at_size.is_valid()) return 0; - return data_at_size->draw_char(p_canvas_item, p_pos, p_char, p_next, p_modulate); + return data_at_size->draw_char(p_canvas_item, p_pos, p_char, p_next, p_modulate, p_outline); } DynamicFont::DynamicFont() { diff --git a/scene/resources/dynamic_font_stb.h b/scene/resources/dynamic_font_stb.h index 4c1097d28b..feae29c0c2 100644 --- a/scene/resources/dynamic_font_stb.h +++ b/scene/resources/dynamic_font_stb.h @@ -136,7 +136,7 @@ public: Size2 get_char_size(CharType p_char, CharType p_next = 0) const; - float draw_char(RID p_canvas_item, const Point2 &p_pos, CharType p_char, CharType p_next = 0, const Color &p_modulate = Color(1, 1, 1)) const; + float draw_char(RID p_canvas_item, const Point2 &p_pos, CharType p_char, CharType p_next = 0, const Color &p_modulate = Color(1, 1, 1), bool p_outline = false) const; DynamicFontAtSize(); ~DynamicFontAtSize(); @@ -171,7 +171,7 @@ public: virtual bool is_distance_field_hint() const; - virtual float draw_char(RID p_canvas_item, const Point2 &p_pos, CharType p_char, CharType p_next = 0, const Color &p_modulate = Color(1, 1, 1)) const; + virtual float draw_char(RID p_canvas_item, const Point2 &p_pos, CharType p_char, CharType p_next = 0, const Color &p_modulate = Color(1, 1, 1), bool p_outline = false) const; DynamicFont(); ~DynamicFont(); diff --git a/scene/resources/font.cpp b/scene/resources/font.cpp index 6fc5778dd8..0bae9d9b2d 100644 --- a/scene/resources/font.cpp +++ b/scene/resources/font.cpp @@ -32,12 +32,12 @@ #include "core/io/resource_loader.h" #include "core/os/file_access.h" +#include "method_bind_ext.gen.inc" -void Font::draw_halign(RID p_canvas_item, const Point2 &p_pos, HAlign p_align, float p_width, const String &p_text, const Color &p_modulate) const { - +void Font::draw_halign(RID p_canvas_item, const Point2 &p_pos, HAlign p_align, float p_width, const String &p_text, const Color &p_modulate, const Color &p_outline_modulate) const { float length = get_string_size(p_text).width; if (length >= p_width) { - draw(p_canvas_item, p_pos, p_text, p_modulate, p_width); + draw(p_canvas_item, p_pos, p_text, p_modulate, p_width, p_outline_modulate); return; } @@ -56,13 +56,14 @@ void Font::draw_halign(RID p_canvas_item, const Point2 &p_pos, HAlign p_align, f ERR_PRINT("Unknown halignment type"); } break; } - draw(p_canvas_item, p_pos + Point2(ofs, 0), p_text, p_modulate, p_width); + draw(p_canvas_item, p_pos + Point2(ofs, 0), p_text, p_modulate, p_width, p_outline_modulate); } -void Font::draw(RID p_canvas_item, const Point2 &p_pos, const String &p_text, const Color &p_modulate, int p_clip_w) const { - +void Font::draw(RID p_canvas_item, const Point2 &p_pos, const String &p_text, const Color &p_modulate, int p_clip_w, const Color &p_outline_modulate) const { Vector2 ofs; + int chars_drawn = 0; + bool with_outline = has_outline(); for (int i = 0; i < p_text.length(); i++) { int width = get_char_size(p_text[i]).width; @@ -70,7 +71,15 @@ void Font::draw(RID p_canvas_item, const Point2 &p_pos, const String &p_text, co if (p_clip_w >= 0 && (ofs.x + width) > p_clip_w) break; //clip - ofs.x += draw_char(p_canvas_item, p_pos + ofs, p_text[i], p_text[i + 1], p_modulate); + ofs.x += draw_char(p_canvas_item, p_pos + ofs, p_text[i], p_text[i + 1], with_outline ? p_outline_modulate : p_modulate, with_outline); + ++chars_drawn; + } + + if (has_outline()) { + ofs = Vector2(0, 0); + for (int i = 0; i < chars_drawn; i++) { + ofs.x += draw_char(p_canvas_item, p_pos + ofs, p_text[i], p_text[i + 1], p_modulate, false); + } } } @@ -81,13 +90,14 @@ void Font::update_changes() { void Font::_bind_methods() { - ClassDB::bind_method(D_METHOD("draw", "canvas_item", "position", "string", "modulate", "clip_w"), &Font::draw, DEFVAL(Color(1, 1, 1)), DEFVAL(-1)); + ClassDB::bind_method(D_METHOD("draw", "canvas_item", "position", "string", "modulate", "clip_w", "outline_modulate"), &Font::draw, DEFVAL(Color(1, 1, 1)), DEFVAL(-1), DEFVAL(Color(1, 1, 1))); ClassDB::bind_method(D_METHOD("get_ascent"), &Font::get_ascent); ClassDB::bind_method(D_METHOD("get_descent"), &Font::get_descent); ClassDB::bind_method(D_METHOD("get_height"), &Font::get_height); ClassDB::bind_method(D_METHOD("is_distance_field_hint"), &Font::is_distance_field_hint); ClassDB::bind_method(D_METHOD("get_string_size", "string"), &Font::get_string_size); - ClassDB::bind_method(D_METHOD("draw_char", "canvas_item", "position", "char", "next", "modulate"), &Font::draw_char, DEFVAL(-1), DEFVAL(Color(1, 1, 1))); + ClassDB::bind_method(D_METHOD("has_outline"), &Font::has_outline); + ClassDB::bind_method(D_METHOD("draw_char", "canvas_item", "position", "char", "next", "modulate", "outline"), &Font::draw_char, DEFVAL(-1), DEFVAL(Color(1, 1, 1)), DEFVAL(false)); ClassDB::bind_method(D_METHOD("update_changes"), &Font::update_changes); } @@ -494,23 +504,24 @@ Ref<BitmapFont> BitmapFont::get_fallback() const { return fallback; } -float BitmapFont::draw_char(RID p_canvas_item, const Point2 &p_pos, CharType p_char, CharType p_next, const Color &p_modulate) const { +float BitmapFont::draw_char(RID p_canvas_item, const Point2 &p_pos, CharType p_char, CharType p_next, const Color &p_modulate, bool p_outline) const { const Character *c = char_map.getptr(p_char); if (!c) { if (fallback.is_valid()) - return fallback->draw_char(p_canvas_item, p_pos, p_char, p_next, p_modulate); + return fallback->draw_char(p_canvas_item, p_pos, p_char, p_next, p_modulate, p_outline); return 0; } - Point2 cpos = p_pos; - cpos.x += c->h_align; - cpos.y -= ascent; - cpos.y += c->v_align; ERR_FAIL_COND_V(c->texture_idx < -1 || c->texture_idx >= textures.size(), 0); - if (c->texture_idx != -1) + if (!p_outline && c->texture_idx != -1) { + Point2 cpos = p_pos; + cpos.x += c->h_align; + cpos.y -= ascent; + cpos.y += c->v_align; VisualServer::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, Rect2(cpos, c->rect.size), textures[c->texture_idx]->get_rid(), c->rect, p_modulate, false, RID(), false); + } return get_char_size(p_char, p_next).width; } diff --git a/scene/resources/font.h b/scene/resources/font.h index ae08890be3..4e295b6035 100644 --- a/scene/resources/font.h +++ b/scene/resources/font.h @@ -56,14 +56,55 @@ public: virtual bool is_distance_field_hint() const = 0; - void draw(RID p_canvas_item, const Point2 &p_pos, const String &p_text, const Color &p_modulate = Color(1, 1, 1), int p_clip_w = -1) const; - void draw_halign(RID p_canvas_item, const Point2 &p_pos, HAlign p_align, float p_width, const String &p_text, const Color &p_modulate = Color(1, 1, 1)) const; - virtual float draw_char(RID p_canvas_item, const Point2 &p_pos, CharType p_char, CharType p_next = 0, const Color &p_modulate = Color(1, 1, 1)) const = 0; + void draw(RID p_canvas_item, const Point2 &p_pos, const String &p_text, const Color &p_modulate = Color(1, 1, 1), int p_clip_w = -1, const Color &p_outline_modulate = Color(1, 1, 1)) const; + void draw_halign(RID p_canvas_item, const Point2 &p_pos, HAlign p_align, float p_width, const String &p_text, const Color &p_modulate = Color(1, 1, 1), const Color &p_outline_modulate = Color(1, 1, 1)) const; + + virtual bool has_outline() const { return false; } + virtual float draw_char(RID p_canvas_item, const Point2 &p_pos, CharType p_char, CharType p_next = 0, const Color &p_modulate = Color(1, 1, 1), bool p_outline = false) const = 0; void update_changes(); Font(); }; +// Helper class to that draws outlines immediately and draws characters in its destructor. +class FontDrawer { + const Ref<Font> &font; + Color outline_color; + bool has_outline; + + struct PendingDraw { + RID canvas_item; + Point2 pos; + CharType chr; + CharType next; + Color modulate; + }; + + Vector<PendingDraw> pending_draws; + +public: + FontDrawer(const Ref<Font> &p_font, const Color &p_outline_color) : + font(p_font), + outline_color(p_outline_color) { + has_outline = p_font->has_outline(); + } + + float draw_char(RID p_canvas_item, const Point2 &p_pos, CharType p_char, CharType p_next = 0, const Color &p_modulate = Color(1, 1, 1)) { + if (has_outline) { + PendingDraw draw = { p_canvas_item, p_pos, p_char, p_next, p_modulate }; + pending_draws.push_back(draw); + } + return font->draw_char(p_canvas_item, p_pos, p_char, p_next, has_outline ? outline_color : p_modulate, has_outline); + } + + ~FontDrawer() { + for (int i = 0; i < pending_draws.size(); ++i) { + const PendingDraw &draw = pending_draws[i]; + font->draw_char(draw.canvas_item, draw.pos, draw.chr, draw.next, draw.modulate, false); + } + } +}; + class BitmapFont : public Font { GDCLASS(BitmapFont, Font); @@ -153,7 +194,7 @@ public: void set_distance_field_hint(bool p_distance_field); bool is_distance_field_hint() const; - float draw_char(RID p_canvas_item, const Point2 &p_pos, CharType p_char, CharType p_next = 0, const Color &p_modulate = Color(1, 1, 1)) const; + float draw_char(RID p_canvas_item, const Point2 &p_pos, CharType p_char, CharType p_next = 0, const Color &p_modulate = Color(1, 1, 1), bool p_outline = false) const; BitmapFont(); ~BitmapFont(); diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp index 1282ce767a..5e7569586a 100644 --- a/scene/resources/material.cpp +++ b/scene/resources/material.cpp @@ -552,7 +552,7 @@ void SpatialMaterial::_update_shader() { //handle animation code += "\tint particle_total_frames = particles_anim_h_frames * particles_anim_v_frames;\n"; - code += "\tint particle_frame = int(INSTANCE_CUSTOM.y * float(particle_total_frames));\n"; + code += "\tint particle_frame = int(INSTANCE_CUSTOM.z * float(particle_total_frames));\n"; code += "\tif (particles_anim_loop) particle_frame=clamp(particle_frame,0,particle_total_frames-1); else particle_frame=abs(particle_frame)%particle_total_frames;\n"; code += "\tUV /= vec2(float(particles_anim_h_frames),float(particles_anim_v_frames));\n"; code += "\tUV += vec2(float(particle_frame % particles_anim_h_frames) / float(particles_anim_h_frames),float(particle_frame / particles_anim_h_frames) / float(particles_anim_v_frames));\n"; diff --git a/servers/physics_server.cpp b/servers/physics_server.cpp index f01a4c2f64..08af26c24b 100644 --- a/servers/physics_server.cpp +++ b/servers/physics_server.cpp @@ -603,6 +603,8 @@ void PhysicsServer::_bind_methods() { BIND_ENUM_CONSTANT(G6DOF_JOINT_LINEAR_LIMIT_SOFTNESS); BIND_ENUM_CONSTANT(G6DOF_JOINT_LINEAR_RESTITUTION); BIND_ENUM_CONSTANT(G6DOF_JOINT_LINEAR_DAMPING); + BIND_ENUM_CONSTANT(G6DOF_JOINT_LINEAR_MOTOR_TARGET_VELOCITY); + BIND_ENUM_CONSTANT(G6DOF_JOINT_LINEAR_MOTOR_FORCE_LIMIT); BIND_ENUM_CONSTANT(G6DOF_JOINT_ANGULAR_LOWER_LIMIT); BIND_ENUM_CONSTANT(G6DOF_JOINT_ANGULAR_UPPER_LIMIT); BIND_ENUM_CONSTANT(G6DOF_JOINT_ANGULAR_LIMIT_SOFTNESS); @@ -616,6 +618,7 @@ void PhysicsServer::_bind_methods() { BIND_ENUM_CONSTANT(G6DOF_JOINT_FLAG_ENABLE_LINEAR_LIMIT); BIND_ENUM_CONSTANT(G6DOF_JOINT_FLAG_ENABLE_ANGULAR_LIMIT); BIND_ENUM_CONSTANT(G6DOF_JOINT_FLAG_ENABLE_MOTOR); + BIND_ENUM_CONSTANT(G6DOF_JOINT_FLAG_ENABLE_LINEAR_MOTOR); ClassDB::bind_method(D_METHOD("joint_get_type", "joint"), &PhysicsServer::joint_get_type); diff --git a/servers/physics_server.h b/servers/physics_server.h index 6a342b36d4..6712bee8dc 100644 --- a/servers/physics_server.h +++ b/servers/physics_server.h @@ -594,6 +594,8 @@ public: G6DOF_JOINT_LINEAR_LIMIT_SOFTNESS, G6DOF_JOINT_LINEAR_RESTITUTION, G6DOF_JOINT_LINEAR_DAMPING, + G6DOF_JOINT_LINEAR_MOTOR_TARGET_VELOCITY, + G6DOF_JOINT_LINEAR_MOTOR_FORCE_LIMIT, G6DOF_JOINT_ANGULAR_LOWER_LIMIT, G6DOF_JOINT_ANGULAR_UPPER_LIMIT, G6DOF_JOINT_ANGULAR_LIMIT_SOFTNESS, @@ -611,6 +613,7 @@ public: G6DOF_JOINT_FLAG_ENABLE_LINEAR_LIMIT, G6DOF_JOINT_FLAG_ENABLE_ANGULAR_LIMIT, G6DOF_JOINT_FLAG_ENABLE_MOTOR, + G6DOF_JOINT_FLAG_ENABLE_LINEAR_MOTOR, G6DOF_JOINT_FLAG_MAX }; |