diff options
77 files changed, 2768 insertions, 184 deletions
diff --git a/core/SCsub b/core/SCsub index a9721a1052..77c8288846 100644 --- a/core/SCsub +++ b/core/SCsub @@ -61,6 +61,7 @@ SConscript('os/SCsub') SConscript('math/SCsub') SConscript('io/SCsub') SConscript('bind/SCsub') +SConscript('helper/SCsub') lib = env.Library("core", env.core_sources) diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index 24992d6337..08e1a311fa 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -450,6 +450,17 @@ bool _OS::is_vsync_enabled() const { return OS::get_singleton()->is_vsync_enabled(); } +PowerState _OS::get_power_state() { + return OS::get_singleton()->get_power_state(); +} + +int _OS::get_power_seconds_left() { + return OS::get_singleton()->get_power_seconds_left(); +} + +int _OS::get_power_percent_left() { + return OS::get_singleton()->get_power_percent_left(); +} /* enum Weekday { @@ -1113,6 +1124,10 @@ void _OS::_bind_methods() { ClassDB::bind_method(D_METHOD("set_use_vsync","enable"),&_OS::set_use_vsync); ClassDB::bind_method(D_METHOD("is_vsync_enabled"),&_OS::is_vsync_enabled); + ClassDB::bind_method(D_METHOD("get_power_state"),&_OS::get_power_state); + ClassDB::bind_method(D_METHOD("get_power_seconds_left"),&_OS::get_power_seconds_left); + ClassDB::bind_method(D_METHOD("get_power_percent_left"),&_OS::get_power_percent_left); + BIND_CONSTANT( DAY_SUNDAY ); BIND_CONSTANT( DAY_MONDAY ); BIND_CONSTANT( DAY_TUESDAY ); @@ -1150,6 +1165,12 @@ void _OS::_bind_methods() { BIND_CONSTANT( SYSTEM_DIR_MUSIC ); BIND_CONSTANT( SYSTEM_DIR_PICTURES ); BIND_CONSTANT( SYSTEM_DIR_RINGTONES ); + + BIND_CONSTANT( POWERSTATE_UNKNOWN ); + BIND_CONSTANT( POWERSTATE_ON_BATTERY ); + BIND_CONSTANT( POWERSTATE_NO_BATTERY ); + BIND_CONSTANT( POWERSTATE_CHARGING ); + BIND_CONSTANT( POWERSTATE_CHARGED ); } @@ -1221,6 +1242,11 @@ PoolVector<Vector3> _Geometry::get_closest_points_between_segments(const Vector3 return r; } +Vector2 _Geometry::get_closest_point_to_segment_2d(const Vector2& p_point, const Vector2& p_a,const Vector2& p_b) { + + Vector2 s[2]={p_a,p_b}; + return Geometry::get_closest_point_to_segment_2d(p_point,s); +} Vector3 _Geometry::get_closest_point_to_segment(const Vector3& p_point, const Vector3& p_a,const Vector3& p_b) { Vector3 s[2]={p_a,p_b}; @@ -1352,6 +1378,7 @@ void _Geometry::_bind_methods() { ClassDB::bind_method(D_METHOD("get_closest_points_between_segments_2d","p1","q1","p2","q2"),&_Geometry::get_closest_points_between_segments_2d); ClassDB::bind_method(D_METHOD("get_closest_points_between_segments","p1","p2","q1","q2"),&_Geometry::get_closest_points_between_segments); + ClassDB::bind_method(D_METHOD("get_closest_point_to_segment_2d","point","s1","s2"),&_Geometry::get_closest_point_to_segment_2d); ClassDB::bind_method(D_METHOD("get_closest_point_to_segment","point","s1","s2"),&_Geometry::get_closest_point_to_segment); ClassDB::bind_method(D_METHOD("get_closest_point_to_segment_uncapped_2d","point","s1","s2"),&_Geometry::get_closest_point_to_segment_uncapped_2d); diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index 2bc6ae2fe0..6b9ae198ef 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -35,6 +35,7 @@ #include "os/dir_access.h" #include "os/thread.h" #include "os/semaphore.h" +#include "os/power.h" class _ResourceLoader : public Object { @@ -308,6 +309,10 @@ public: void set_use_vsync(bool p_enable); bool is_vsync_enabled() const; + PowerState get_power_state(); + int get_power_seconds_left(); + int get_power_percent_left(); + static _OS *get_singleton() { return singleton; } _OS(); @@ -334,6 +339,7 @@ public: Variant segment_intersects_segment_2d(const Vector2& p_from_a,const Vector2& p_to_a,const Vector2& p_from_b,const Vector2& p_to_b); PoolVector<Vector2> get_closest_points_between_segments_2d( const Vector2& p1,const Vector2& q1, const Vector2& p2,const Vector2& q2); PoolVector<Vector3> get_closest_points_between_segments(const Vector3& p1,const Vector3& p2,const Vector3& q1,const Vector3& q2); + Vector2 get_closest_point_to_segment_2d(const Vector2& p_point, const Vector2& p_a,const Vector2& p_b); Vector3 get_closest_point_to_segment(const Vector3& p_point, const Vector3& p_a,const Vector3& p_b); Vector2 get_closest_point_to_segment_uncapped_2d(const Vector2& p_point, const Vector2& p_a,const Vector2& p_b); Vector3 get_closest_point_to_segment_uncapped(const Vector3& p_point, const Vector3& p_a,const Vector3& p_b); diff --git a/core/helper/SCsub b/core/helper/SCsub new file mode 100644 index 0000000000..4efc902717 --- /dev/null +++ b/core/helper/SCsub @@ -0,0 +1,7 @@ +#!/usr/bin/env python + +Import('env') + +env.add_source_files(env.core_sources, "*.cpp") + +Export('env') diff --git a/core/helper/math_fieldwise.cpp b/core/helper/math_fieldwise.cpp new file mode 100644 index 0000000000..204c431e1d --- /dev/null +++ b/core/helper/math_fieldwise.cpp @@ -0,0 +1,171 @@ +/*************************************************************************/ +/* fieldwise.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifdef TOOLS_ENABLED + +#include "core/helper/math_fieldwise.h" + +#define SETUP_TYPE(m_type) m_type source=p_source; m_type target=p_target; +#define TRY_TRANSFER_FIELD(m_name,m_member) if (p_field==m_name) { target.m_member=source.m_member; } + +Variant fieldwise_assign(const Variant& p_target, const Variant& p_source, const String& p_field) { + + ERR_FAIL_COND_V(p_target.get_type()!=p_source.get_type(),p_target); + + switch (p_source.get_type()) { + + case Variant::VECTOR2: { + + SETUP_TYPE(Vector2) + + /**/ TRY_TRANSFER_FIELD("x",x) + else TRY_TRANSFER_FIELD("y",y) + + return target; + } + + case Variant::RECT2: { + + SETUP_TYPE(Rect2) + + /**/ TRY_TRANSFER_FIELD("x",pos.x) + else TRY_TRANSFER_FIELD("y",pos.y) + else TRY_TRANSFER_FIELD("w",size.x) + else TRY_TRANSFER_FIELD("h",size.y) + + return target; + } + + case Variant::VECTOR3: { + + SETUP_TYPE(Vector3) + + /**/ TRY_TRANSFER_FIELD("x",x) + else TRY_TRANSFER_FIELD("y",y) + else TRY_TRANSFER_FIELD("z",z) + + return target; + } + + case Variant::PLANE: { + + SETUP_TYPE(Plane) + + /**/ TRY_TRANSFER_FIELD("x",normal.x) + else TRY_TRANSFER_FIELD("y",normal.y) + else TRY_TRANSFER_FIELD("z",normal.z) + else TRY_TRANSFER_FIELD("d",d) + + return target; + } + + case Variant::QUAT: { + + SETUP_TYPE(Quat) + + /**/ TRY_TRANSFER_FIELD("x",x) + else TRY_TRANSFER_FIELD("y",y) + else TRY_TRANSFER_FIELD("z",z) + else TRY_TRANSFER_FIELD("w",w) + + return target; + } + + case Variant::RECT3: { + + SETUP_TYPE(Rect3) + + /**/ TRY_TRANSFER_FIELD("px",pos.x) + else TRY_TRANSFER_FIELD("py",pos.y) + else TRY_TRANSFER_FIELD("pz",pos.z) + else TRY_TRANSFER_FIELD("sx",size.x) + else TRY_TRANSFER_FIELD("sy",size.y) + else TRY_TRANSFER_FIELD("sz",size.z) + + return target; + } + + case Variant::TRANSFORM2D: { + + SETUP_TYPE(Transform2D) + + /**/ TRY_TRANSFER_FIELD("xx",elements[0][0]) + else TRY_TRANSFER_FIELD("xy",elements[0][1]) + else TRY_TRANSFER_FIELD("yx",elements[1][0]) + else TRY_TRANSFER_FIELD("yy",elements[1][1]) + else TRY_TRANSFER_FIELD("ox",elements[2][0]) + else TRY_TRANSFER_FIELD("oy",elements[2][1]) + + return target; + } + + case Variant::BASIS: { + + SETUP_TYPE(Basis) + + /**/ TRY_TRANSFER_FIELD("xx",elements[0][0]) + else TRY_TRANSFER_FIELD("xy",elements[0][1]) + else TRY_TRANSFER_FIELD("xz",elements[0][2]) + else TRY_TRANSFER_FIELD("yx",elements[1][0]) + else TRY_TRANSFER_FIELD("yy",elements[1][1]) + else TRY_TRANSFER_FIELD("yz",elements[1][2]) + else TRY_TRANSFER_FIELD("zx",elements[2][0]) + else TRY_TRANSFER_FIELD("zy",elements[2][1]) + else TRY_TRANSFER_FIELD("zz",elements[2][2]) + + return target; + } + + case Variant::TRANSFORM: { + + SETUP_TYPE(Transform) + + /**/ TRY_TRANSFER_FIELD("xx",basis.elements[0][0]) + else TRY_TRANSFER_FIELD("xy",basis.elements[0][1]) + else TRY_TRANSFER_FIELD("xz",basis.elements[0][2]) + else TRY_TRANSFER_FIELD("yx",basis.elements[1][0]) + else TRY_TRANSFER_FIELD("yy",basis.elements[1][1]) + else TRY_TRANSFER_FIELD("yz",basis.elements[1][2]) + else TRY_TRANSFER_FIELD("zx",basis.elements[2][0]) + else TRY_TRANSFER_FIELD("zy",basis.elements[2][1]) + else TRY_TRANSFER_FIELD("zz",basis.elements[2][2]) + else TRY_TRANSFER_FIELD("xo",origin.x) + else TRY_TRANSFER_FIELD("yo",origin.y) + else TRY_TRANSFER_FIELD("zo",origin.z) + + return target; + } + + default: { + ERR_FAIL_V(p_target); + } + } +} + +#endif // TOOLS_ENABLED diff --git a/core/helper/math_fieldwise.h b/core/helper/math_fieldwise.h new file mode 100644 index 0000000000..31f9af8d0b --- /dev/null +++ b/core/helper/math_fieldwise.h @@ -0,0 +1,40 @@ +/*************************************************************************/ +/* fieldwise.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#ifndef MATH_FIELDWISE_H +#define MATH_FIELDWISE_H + +#ifdef TOOLS_ENABLED + +#include "core/variant.h" + +Variant fieldwise_assign(const Variant& p_target, const Variant& p_source, const String& p_field); + +#endif // TOOLS_ENABLED + +#endif // MATH_FIELDWISE_H diff --git a/core/os/os.cpp b/core/os/os.cpp index 912f7f0b0f..1d670b4466 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -513,6 +513,16 @@ bool OS::is_vsync_enabled() const{ } +PowerState OS::get_power_state() { + return POWERSTATE_UNKNOWN; +} +int OS::get_power_seconds_left() { + return -1; +} +int OS::get_power_percent_left() { + return -1; +} + OS::OS() { last_error=NULL; singleton=this; diff --git a/core/os/os.h b/core/os/os.h index e179b82dae..7c8100679a 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -34,8 +34,10 @@ #include "vector.h" #include "engine.h" #include "os/main_loop.h" +#include "power.h" #include <stdarg.h> + /** @author Juan Linietsky <reduzio@gmail.com> */ @@ -402,6 +404,10 @@ public: virtual void set_use_vsync(bool p_enable); virtual bool is_vsync_enabled() const; + + virtual PowerState get_power_state(); + virtual int get_power_seconds_left(); + virtual int get_power_percent_left(); virtual bool check_feature_support(const String& p_feature)=0; diff --git a/core/os/power.h b/core/os/power.h new file mode 100644 index 0000000000..c858d391a1 --- /dev/null +++ b/core/os/power.h @@ -0,0 +1,44 @@ +/*************************************************************************/ +/* power.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef CORE_OS_POWER_H_ +#define CORE_OS_POWER_H_ + + +typedef enum +{ + POWERSTATE_UNKNOWN, /**< cannot determine power status */ + POWERSTATE_ON_BATTERY, /**< Not plugged in, running on the battery */ + POWERSTATE_NO_BATTERY, /**< Plugged in, no battery available */ + POWERSTATE_CHARGING, /**< Plugged in, charging battery */ + POWERSTATE_CHARGED /**< Plugged in, battery charged */ +} PowerState; + + +#endif /* CORE_OS_POWER_H_ */ diff --git a/doc/base/classes.xml b/doc/base/classes.xml index 4e4fb3cd23..71594887fc 100644 --- a/doc/base/classes.xml +++ b/doc/base/classes.xml @@ -35451,6 +35451,13 @@ Returns true if this SceneTree's [NetworkedMultiplayerPeer] is in server mode (listening for connections). </description> </method> + <method name="has_network_peer" qualifiers="const"> + <return type="bool"> + </return> + <description> + Returns true if there is a [NetworkedMultiplayerPeer] set (with [method SceneTree.set_network_peer]). + </description> + </method> <method name="is_paused" qualifiers="const"> <return type="bool"> </return> @@ -40626,9 +40633,16 @@ <return type="int"> </return> <description> - Return the current tab that is being showed. + Return the current tab index that is being shown. </description> </method> + <method name="get_previous_tab" qualifiers="const"> + <return type="int"> + </return> + <description> + Return the previous tab index that was being shown. + </description> + </method> <method name="get_current_tab_control" qualifiers="const"> <return type="Control"> </return> @@ -40654,6 +40668,7 @@ <argument index="0" name="idx" type="int"> </argument> <description> + Return the current tab control that is being shown. </description> </method> <method name="get_tab_count" qualifiers="const"> @@ -40735,7 +40750,14 @@ <argument index="0" name="tab" type="int"> </argument> <description> - Emitted when the current tab changes. + Emitted only when the current tab changes. + </description> + </signal> + <signal name="tab_selected"> + <argument index="0" name="tab" type="int"> + </argument> + <description> + Emitted when a tab is being selected, even if it is the same tab. </description> </signal> </signals> diff --git a/drivers/gles3/rasterizer_scene_gles3.cpp b/drivers/gles3/rasterizer_scene_gles3.cpp index 73adeaf723..03a5834ca7 100644 --- a/drivers/gles3/rasterizer_scene_gles3.cpp +++ b/drivers/gles3/rasterizer_scene_gles3.cpp @@ -2806,7 +2806,7 @@ void RasterizerSceneGLES3::_copy_to_front_buffer(Environment *env) { //no environment, simply convert from linear to srgb storage->shaders.copy.set_conditional(CopyShaderGLES3::LINEAR_TO_SRGB,true); } else { - /* Why are both statements equal? */ + /* FIXME: Why are both statements equal? */ storage->shaders.copy.set_conditional(CopyShaderGLES3::LINEAR_TO_SRGB,true); } diff --git a/main/main.cpp b/main/main.cpp index 9be77c31b6..fb7f2ebceb 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -1063,6 +1063,7 @@ bool Main::start() { bool editor=false; String doc_tool; + List<String> removal_docs; bool doc_base=true; String game_path; String script; @@ -1093,6 +1094,8 @@ bool Main::start() { bool parsed_pair=true; if (args[i]=="-doctool") { doc_tool=args[i+1]; + for(int j=i+2; j<args.size();j++) + removal_docs.push_back(args[j]); } else if (args[i]=="-script" || args[i]=="-s") { script=args[i+1]; } else if (args[i]=="-level" || args[i]=="-l") { @@ -1141,6 +1144,14 @@ bool Main::start() { } + for(List<String>::Element* E= removal_docs.front(); E; E=E->next()) { + DocData rmdoc; + if (rmdoc.load(E->get()) == OK) { + print_line(String("Removing classes in ") + E->get()); + doc.remove_from(rmdoc); + } + } + doc.save(doc_tool); return false; diff --git a/misc/dist/appimage/AppRun b/misc/dist/appimage/AppRun new file mode 100755 index 0000000000..db3398a92a --- /dev/null +++ b/misc/dist/appimage/AppRun @@ -0,0 +1,3 @@ +#!/bin/sh +HERE="$(dirname "$(readlink -f "${0}")")" +"${HERE}"/godot $@ diff --git a/misc/dist/appimage/godot.desktop b/misc/dist/appimage/godot.desktop new file mode 100644 index 0000000000..545c491256 --- /dev/null +++ b/misc/dist/appimage/godot.desktop @@ -0,0 +1,9 @@ +[Desktop Entry] +Name=Godot Engine +GenericName=Libre game engine +Comment=Multi-platform 2D and 3D game engine with a feature rich editor +Exec=godot -pm +Icon=godot +Terminal=false +Type=Application +Categories=Development;IDE; diff --git a/misc/dist/appimage/godot.png b/misc/dist/appimage/godot.png Binary files differnew file mode 100644 index 0000000000..e334f5fa78 --- /dev/null +++ b/misc/dist/appimage/godot.png diff --git a/modules/visual_script/visual_script_builtin_funcs.cpp b/modules/visual_script/visual_script_builtin_funcs.cpp index 1acd5bff8d..f9780400d8 100644 --- a/modules/visual_script/visual_script_builtin_funcs.cpp +++ b/modules/visual_script/visual_script_builtin_funcs.cpp @@ -329,7 +329,7 @@ PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const case LOGIC_CLAMP: { if (p_idx==0) return PropertyInfo(Variant::REAL,"a"); - else if (p_idx==0) // is it ok to test p_idx == 0 twice? + else if (p_idx==0) // FIXME: is it ok to test p_idx == 0 twice? return PropertyInfo(Variant::REAL,"min"); else return PropertyInfo(Variant::REAL,"max"); diff --git a/platform/android/SCsub b/platform/android/SCsub index 146f7c25a3..86f8c40f83 100644 --- a/platform/android/SCsub +++ b/platform/android/SCsub @@ -20,6 +20,7 @@ android_files = [ 'java_glue.cpp', 'cpu-features.c', 'java_class_wrapper.cpp' + 'power_android.cpp' ] # env.Depends('#core/math/vector3.h', 'vector3_psp.h') diff --git a/platform/android/java/src/org/godotengine/godot/input/GodotTextInputWrapper.java b/platform/android/java/src/org/godotengine/godot/input/GodotTextInputWrapper.java index 80cded6fb5..3c8207fae1 100644 --- a/platform/android/java/src/org/godotengine/godot/input/GodotTextInputWrapper.java +++ b/platform/android/java/src/org/godotengine/godot/input/GodotTextInputWrapper.java @@ -49,7 +49,6 @@ public class GodotTextInputWrapper implements TextWatcher, OnEditorActionListene // =========================================================== private final GodotView mView; private final GodotEditText mEdit; - private String mText; private String mOriginText; // =========================================================== @@ -81,52 +80,28 @@ public class GodotTextInputWrapper implements TextWatcher, OnEditorActionListene @Override public void afterTextChanged(final Editable s) { - if (this.isFullScreenEdit()) { - return; - } - //if (BuildConfig.DEBUG) { - //Log.d(TAG, "afterTextChanged: " + s); - //} - int nModified = s.length() - this.mText.length(); - if (nModified > 0) { - final String insertText = s.subSequence(this.mText.length(), s.length()).toString(); - for(int i = 0; i < insertText.length(); i++) { - int ch = insertText.codePointAt(i); - GodotLib.key(0, ch, true); - GodotLib.key(0, ch, false); - } - /* - if (BuildConfig.DEBUG) { - Log.d(TAG, "insertText(" + insertText + ")"); - } - */ - } else { - for (; nModified < 0; ++nModified) { - GodotLib.key(KeyEvent.KEYCODE_DEL, 0, true); - GodotLib.key(KeyEvent.KEYCODE_DEL, 0, false); - /* - if (BuildConfig.DEBUG) { - Log.d(TAG, "deleteBackward"); - } - */ - } - } - this.mText = s.toString(); } @Override public void beforeTextChanged(final CharSequence pCharSequence, final int start, final int count, final int after) { - /* - if (BuildConfig.DEBUG) { - Log.d(TAG, "beforeTextChanged(" + pCharSequence + ")start: " + start + ",count: " + count + ",after: " + after); + //Log.d(TAG, "beforeTextChanged(" + pCharSequence + ")start: " + start + ",count: " + count + ",after: " + after); + + for (int i=0;i<count;i++){ + GodotLib.key(KeyEvent.KEYCODE_DEL, 0, true); + GodotLib.key(KeyEvent.KEYCODE_DEL, 0, false); } - */ - this.mText = pCharSequence.toString(); } @Override public void onTextChanged(final CharSequence pCharSequence, final int start, final int before, final int count) { + //Log.d(TAG, "onTextChanged(" + pCharSequence + ")start: " + start + ",count: " + count + ",before: " + before); + + for (int i=start;i<start+count;i++){ + int ch = pCharSequence.charAt(i); + GodotLib.key(0, ch, true); + GodotLib.key(0, ch, false); + } } diff --git a/platform/android/os_android.cpp b/platform/android/os_android.cpp index 2290571735..a10f27424c 100644 --- a/platform/android/os_android.cpp +++ b/platform/android/os_android.cpp @@ -159,6 +159,8 @@ void OS_Android::initialize(const VideoMode& p_desired,int p_video_driver,int p_ input = memnew( InputDefault ); input->set_fallback_mapping("Default Android Gamepad"); + + power_manager = memnew( power_android ); } void OS_Android::set_main_loop( MainLoop * p_main_loop ) { diff --git a/platform/android/os_android.h b/platform/android/os_android.h index bf1db57ba5..ead3969744 100644 --- a/platform/android/os_android.h +++ b/platform/android/os_android.h @@ -32,6 +32,7 @@ #include "os/input.h" #include "drivers/unix/os_unix.h" #include "os/main_loop.h" +#include "power_android.h" #include "servers/physics/physics_server_sw.h" #include "servers/audio_server.h" #include "servers/physics_2d/physics_2d_server_sw.h" @@ -142,6 +143,8 @@ private: SetKeepScreenOnFunc set_keep_screen_on_func; AlertFunc alert_func; + power_android *power_manager; + public: // functions used by main to initialize/deintialize the OS diff --git a/platform/android/power_android.cpp b/platform/android/power_android.cpp new file mode 100644 index 0000000000..8cd5cb1397 --- /dev/null +++ b/platform/android/power_android.cpp @@ -0,0 +1,238 @@ +/*************************************************************************/ +/* power_android.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "core/error_macros.h" + +#include "power_android.h" + +static void LocalReferenceHolder_Cleanup(struct LocalReferenceHolder *refholder) { + if (refholder->m_env) { + JNIEnv* env = refholder->m_env; + (*env)->PopLocalFrame(env, NULL); + --s_active; + } +} + +static struct LocalReferenceHolder LocalReferenceHolder_Setup(const char *func) +{ + struct LocalReferenceHolder refholder; + refholder.m_env = NULL; + refholder.m_func = func; + return refholder; +} + +static bool LocalReferenceHolder_Init(struct LocalReferenceHolder *refholder, JNIEnv *env) +{ + const int capacity = 16; + if ((*env)->PushLocalFrame(env, capacity) < 0) { + return false; + } + ++s_active; + refholder->m_env = env; + return true; +} + + +static SDL_bool LocalReferenceHolder_IsActive(void) +{ + return s_active > 0; +} + +ANativeWindow* Android_JNI_GetNativeWindow(void) +{ + ANativeWindow* anw; + jobject s; + JNIEnv *env = Android_JNI_GetEnv(); + + s = (*env)->CallStaticObjectMethod(env, mActivityClass, midGetNativeSurface); + anw = ANativeWindow_fromSurface(env, s); + (*env)->DeleteLocalRef(env, s); + + return anw; +} + + +/* + * CODE CHUNK IMPORTED FROM SDL 2.0 + * returns 0 on success or -1 on error (others undefined then) + * returns truthy or falsy value in plugged, charged and battery + * returns the value in seconds and percent or -1 if not available + */ +int Android_JNI_GetPowerInfo(int* plugged, int* charged, int* battery, int* seconds, int* percent) +{ + env = Android_JNI_GetEnv(); + refs = LocalReferenceHolder_Setup(__FUNCTION__); + + if (!LocalReferenceHolder_Init(&refs, env)) { + LocalReferenceHolder_Cleanup(&refs); + return -1; + } + mid = (*env)->GetStaticMethodID(env, mActivityClass, "getContext", "()Landroid/content/Context;"); + context = (*env)->CallStaticObjectMethod(env, mActivityClass, mid); + action = (*env)->NewStringUTF(env, "android.intent.action.BATTERY_CHANGED"); + cls = (*env)->FindClass(env, "android/content/IntentFilter"); + mid = (*env)->GetMethodID(env, cls, "<init>", "(Ljava/lang/String;)V"); + filter = (*env)->NewObject(env, cls, mid, action); + (*env)->DeleteLocalRef(env, action); + mid = (*env)->GetMethodID(env, mActivityClass, "registerReceiver", "(Landroid/content/BroadcastReceiver;Landroid/content/IntentFilter;)Landroid/content/Intent;"); + intent = (*env)->CallObjectMethod(env, context, mid, NULL, filter); + (*env)->DeleteLocalRef(env, filter); + cls = (*env)->GetObjectClass(env, intent); + imid = (*env)->GetMethodID(env, cls, "getIntExtra", "(Ljava/lang/String;I)I"); + // Watch out for C89 scoping rules because of the macro +#define GET_INT_EXTRA(var, key) \ + int var; \ + iname = (*env)->NewStringUTF(env, key); \ + var = (*env)->CallIntMethod(env, intent, imid, iname, -1); \ + (*env)->DeleteLocalRef(env, iname); + bmid = (*env)->GetMethodID(env, cls, "getBooleanExtra", "(Ljava/lang/String;Z)Z"); + // Watch out for C89 scoping rules because of the macro +#define GET_BOOL_EXTRA(var, key) \ + int var; \ + bname = (*env)->NewStringUTF(env, key); \ + var = (*env)->CallBooleanMethod(env, intent, bmid, bname, JNI_FALSE); \ + (*env)->DeleteLocalRef(env, bname); + if (plugged) { + // Watch out for C89 scoping rules because of the macro + GET_INT_EXTRA(plug, "plugged") // == BatteryManager.EXTRA_PLUGGED (API 5) + if (plug == -1) { + LocalReferenceHolder_Cleanup(&refs); + return -1; + } + // 1 == BatteryManager.BATTERY_PLUGGED_AC + // 2 == BatteryManager.BATTERY_PLUGGED_USB + *plugged = (0 < plug) ? 1 : 0; + } + if (charged) { + // Watch out for C89 scoping rules because of the macro + GET_INT_EXTRA(status, "status") // == BatteryManager.EXTRA_STATUS (API 5) + if (status == -1) { + LocalReferenceHolder_Cleanup(&refs); + return -1; + } + // 5 == BatteryManager.BATTERY_STATUS_FULL + *charged = (status == 5) ? 1 : 0; + } + if (battery) { + GET_BOOL_EXTRA(present, "present") // == BatteryManager.EXTRA_PRESENT (API 5) + *battery = present ? 1 : 0; + } + if (seconds) { + *seconds = -1; // not possible + } + if (percent) { + int level; + int scale; + // Watch out for C89 scoping rules because of the macro + { + GET_INT_EXTRA(level_temp, "level") // == BatteryManager.EXTRA_LEVEL (API 5) + level = level_temp; + } + // Watch out for C89 scoping rules because of the macro + { + GET_INT_EXTRA(scale_temp, "scale") // == BatteryManager.EXTRA_SCALE (API 5) + scale = scale_temp; + } + if ((level == -1) || (scale == -1)) { + LocalReferenceHolder_Cleanup(&refs); + return -1; + } + *percent = level * 100 / scale; + } + (*env)->DeleteLocalRef(env, intent); + LocalReferenceHolder_Cleanup(&refs); + + return 0; +} + + +bool power_android::GetPowerInfo_Android() { + int battery; + int plugged; + int charged; + + if (Android_JNI_GetPowerInfo(&plugged, &charged, &battery, &this->nsecs_left, &this->percent_left) != -1) { + if (plugged) { + if (charged) { + this->power_state = POWERSTATE_CHARGED; + } else if (battery) { + this->power_state = POWERSTATE_CHARGING; + } else { + this->power_state = POWERSTATE_NO_BATTERY; + this->nsecs_left = -1; + this->percent_left = -1; + } + } else { + this->power_state = POWERSTATE_ON_BATTERY; + } + } else { + this->power_state = POWERSTATE_UNKNOWN; + this->nsecs_left = -1; + this->percent_left = -1; + } + + return true; +} + +PowerState power_android::get_power_state() { + if (GetPowerInfo_Android()) { + return power_state; + } + else { + WARN_PRINT("Power management is not implemented on this platform, defaulting to POWERSTATE_UNKNOWN"); + return POWERSTATE_UNKNOWN; + } +} + +int power_android::get_power_seconds_left() { + if (GetPowerInfo_Android()) { + return nsecs_left; + } + else { + WARN_PRINT("Power management is not implemented on this platform, defaulting to -1"); + return -1; + } +} + +int power_android::get_power_percent_left() { + if (GetPowerInfo_Android()) { + return percent_left; + } + else { + WARN_PRINT("Power management is not implemented on this platform, defaulting to -1"); + return -1; + } +} + +power_android::power_android() : nsecs_left(-1), percent_left(-1), power_state(POWERSTATE_UNKNOWN) { + +} + +power_android::~power_android() { +} diff --git a/platform/android/power_android.h b/platform/android/power_android.h new file mode 100644 index 0000000000..873f06de1d --- /dev/null +++ b/platform/android/power_android.h @@ -0,0 +1,82 @@ +/*************************************************************************/ +/* power_android.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef PLATFORM_ANDROID_POWER_ANDROID_H_ +#define PLATFORM_ANDROID_POWER_ANDROID_H_ + +#include "os/power.h" +#include <android/native_window_jni.h> + +class power_android { + +struct LocalReferenceHolder +{ + JNIEnv *m_env; + const char *m_func; +}; + +private: + static struct LocalReferenceHolder refs; + static JNIEnv* env; + static jmethodID mid; + static jobject context; + static jstring action; + static jclass cls; + static jobject filter; + static jobject intent; + static jstring iname; + static jmethodID imid; + static jstring bname; + static jmethodID bmid; + + + int nsecs_left; + int percent_left; + PowerState power_state; + + bool GetPowerInfo_Android(); + bool UpdatePowerInfo(); + +public: + + static int s_active; + + + power_android(); + virtual ~power_android(); + static bool LocalReferenceHolder_Init(struct LocalReferenceHolder *refholder, JNIEnv *env); + static struct LocalReferenceHolder LocalReferenceHolder_Setup(const char *func); + static void LocalReferenceHolder_Cleanup(struct LocalReferenceHolder *refholder); + + PowerState get_power_state(); + int get_power_seconds_left(); + int get_power_percent_left(); +}; + +#endif /* PLATFORM_ANDROID_POWER_ANDROID_H_ */
\ No newline at end of file diff --git a/platform/bb10/os_bb10.cpp b/platform/bb10/os_bb10.cpp index 728707628b..bf7bfb6909 100644 --- a/platform/bb10/os_bb10.cpp +++ b/platform/bb10/os_bb10.cpp @@ -146,6 +146,8 @@ void OSBB10::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi physics_2d_server->init(); input = memnew( InputDefault ); + + power_manager = memnew( PowerBB10 ); #ifdef PAYMENT_SERVICE_ENABLED payment_service = memnew(PaymentService); @@ -587,6 +589,18 @@ Size2 OSBB10::get_window_size() const { return Vector2(default_videomode.width, default_videomode.height); } +PowerState OSBB10::get_power_state() { + return power_manager->get_power_state(); +} + +int OSBB10::get_power_seconds_left() { + return power_manager->get_power_seconds_left(); +} + +int OSBB10::get_power_percent_left() { + return power_manager->get_power_percent_left(); +} + OSBB10::OSBB10() { main_loop=NULL; diff --git a/platform/bb10/os_bb10.h b/platform/bb10/os_bb10.h index 9cf2091d49..678b8c9fc2 100644 --- a/platform/bb10/os_bb10.h +++ b/platform/bb10/os_bb10.h @@ -39,6 +39,7 @@ #include "servers/visual/rasterizer.h" #include "audio_driver_bb10.h" #include "payment_service.h" +#include "power_bb10.h" #include <screen/screen.h> #include <sys/platform.h> @@ -58,6 +59,7 @@ class OSBB10 : public OS_Unix { PhysicsServer *physics_server; Physics2DServer *physics_2d_server; AudioDriverBB10* audio_driver; + PowerBB10 *power_manager; #ifdef PAYMENT_SERVICE_ENABLED PaymentService* payment_service; @@ -142,6 +144,10 @@ public: void run(); + virtual PowerState get_power_state(); + virtual int get_power_seconds_left(); + virtual int get_power_percent_left(); + OSBB10(); ~OSBB10(); diff --git a/platform/bb10/power_bb10.cpp b/platform/bb10/power_bb10.cpp new file mode 100644 index 0000000000..ef4a59d5d0 --- /dev/null +++ b/platform/bb10/power_bb10.cpp @@ -0,0 +1,76 @@ +/*************************************************************************/ +/* power_bb10.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "power_bb10.h" + +#include "core/error_macros.h" + + +bool PowerBB10::UpdatePowerInfo() { + + return false; +} + +PowerState PowerBB10::get_power_state() { + if (UpdatePowerInfo()) { + return power_state; + } + else { + WARN_PRINT("Power management is not implemented on this platform, defaulting to POWERSTATE_UNKNOWN"); + return POWERSTATE_UNKNOWN; + } +} + +int PowerBB10::get_power_seconds_left() { + if (UpdatePowerInfo()) { + return nsecs_left; + } + else { + WARN_PRINT("Power management is not implemented on this platform, defaulting to -1"); + return -1; + } +} + +int PowerBB10::get_power_percent_left() { + if (UpdatePowerInfo()) { + return percent_left; + } + else { + WARN_PRINT("Power management is not implemented on this platform, defaulting to -1"); + return -1; + } +} + +PowerBB10::PowerBB10() : nsecs_left(-1), percent_left(-1), power_state(POWERSTATE_UNKNOWN) { + +} + +PowerBB10::~PowerBB10() { +} + diff --git a/platform/bb10/power_bb10.h b/platform/bb10/power_bb10.h new file mode 100644 index 0000000000..156dd31df7 --- /dev/null +++ b/platform/bb10/power_bb10.h @@ -0,0 +1,49 @@ +/*************************************************************************/ +/* power_bb10.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef PLATFORM_BB10_POWER_BB10_H_ +#define PLATFORM_BB10_POWER_BB10_H_ + +class PowerBB10 { +private: + int nsecs_left; + int percent_left; + PowerState power_state; + + bool UpdatePowerInfo(); +public: + PowerBB10(); + virtual ~PowerBB10(); + + PowerState get_power_state(); + int get_power_seconds_left(); + int get_power_percent_left(); +}; + +#endif /* PLATFORM_BB10_POWER_BB10_H_ */
\ No newline at end of file diff --git a/platform/haiku/os_haiku.cpp b/platform/haiku/os_haiku.cpp index 9f218aeff4..b9b95ddacd 100644 --- a/platform/haiku/os_haiku.cpp +++ b/platform/haiku/os_haiku.cpp @@ -143,6 +143,8 @@ void OS_Haiku::initialize(const VideoMode& p_desired, int p_video_driver, int p_ if (AudioDriverManager::get_driver(p_audio_driver)->init() != OK) { ERR_PRINT("Initializing audio failed."); } + + power_manager = memnew( PowerHaiku ); } void OS_Haiku::finalize() { diff --git a/platform/haiku/os_haiku.h b/platform/haiku/os_haiku.h index 531c7a56c3..2c84e95ac3 100644 --- a/platform/haiku/os_haiku.h +++ b/platform/haiku/os_haiku.h @@ -40,6 +40,7 @@ #include "context_gl_haiku.h" #include "haiku_application.h" #include "haiku_direct_window.h" +#include "power_haiku.h" class OS_Haiku : public OS_Unix { @@ -53,6 +54,7 @@ private: VideoMode current_video_mode; PhysicsServer* physics_server; Physics2DServer* physics_2d_server; + PowerHaiku* power_manager; #ifdef MEDIA_KIT_ENABLED AudioDriverMediaKit driver_media_kit; @@ -114,6 +116,10 @@ public: virtual VideoMode get_video_mode(int p_screen=0) const; virtual void get_fullscreen_mode_list(List<VideoMode> *p_list, int p_screen=0) const; virtual String get_executable_path() const; + + virtual PowerState get_power_state(); + virtual int get_power_seconds_left(); + virtual int get_power_percent_left(); }; #endif diff --git a/platform/haiku/power_haiku.cpp b/platform/haiku/power_haiku.cpp new file mode 100644 index 0000000000..ecedc46500 --- /dev/null +++ b/platform/haiku/power_haiku.cpp @@ -0,0 +1,74 @@ +/*************************************************************************/ +/* power_haiku.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "core/error_macros.h" + +#include "power_haiku.h" + +bool PowerHaiku::UpdatePowerInfo() { + + return false; +} + +PowerState PowerHaiku::get_power_state() { + if (UpdatePowerInfo()) { + return power_state; + } + else { + WARN_PRINT("Power management is not implemented on this platform, defaulting to POWERSTATE_UNKNOWN"); + return POWERSTATE_UNKNOWN; + } +} + +int PowerX11::get_power_seconds_left() { + if (UpdatePowerInfo()) { + return nsecs_left; + } + else { + WARN_PRINT("Power management is not implemented on this platform, defaulting to -1"); + return -1; + } +} + +int PowerX11::get_power_percent_left() { + if (UpdatePowerInfo()) { + return percent_left; + } + else { + WARN_PRINT("Power management is not implemented on this platform, defaulting to -1"); + return -1; + } +} + +PowerHaiku::PowerHaiku() : nsecs_left(-1), percent_left(-1), power_state(POWERSTATE_UNKNOWN) { + +} + +PowerHaiku::~PowerHaiku() { +}
\ No newline at end of file diff --git a/platform/haiku/power_haiku.h b/platform/haiku/power_haiku.h new file mode 100644 index 0000000000..0889e5880c --- /dev/null +++ b/platform/haiku/power_haiku.h @@ -0,0 +1,49 @@ +/*************************************************************************/ +/* power_haiku.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef PLATFORM_HAIKU_POWER_HAIKU_H_ +#define PLATFORM_HAIKU_POWER_HAIKU_H_ + +class PowerHaiku { +private: + int nsecs_left; + int percent_left; + PowerState power_state; + + bool UpdatePowerInfo(); +public: + PowerHaiku(); + virtual ~PowerHaiku(); + + PowerState get_power_state(); + int get_power_seconds_left(); + int get_power_percent_left(); +}; + +#endif /* PLATFORM_HAIKU_POWER_HAIKU_H_ */
\ No newline at end of file diff --git a/platform/iphone/power_iphone.cpp b/platform/iphone/power_iphone.cpp new file mode 100644 index 0000000000..44013794ad --- /dev/null +++ b/platform/iphone/power_iphone.cpp @@ -0,0 +1,71 @@ +/*************************************************************************/ +/* power_iphone.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "power_iphone.h" + +bool PowerState::UpdatePowerInfo() { + return false; +} + + +PowerState PowerIphone::get_power_state() { + if (UpdatePowerInfo()) { + return power_state; + } + else { + return POWERSTATE_UNKNOWN; + } +} + +int PowerIphone::get_power_seconds_left() { + if (UpdatePowerInfo()) { + return nsecs_left; + } + else { + return -1; + } +} + +int PowerIphone::get_power_percent_left() { + if (UpdatePowerInfo()) { + return percent_left; + } + else { + return -1; + } +} + +PowerIphone::PowerIphone() : nsecs_left(-1), percent_left(-1), power_state(POWERSTATE_UNKNOWN) { + // TODO Auto-generated constructor stub + +} + +PowerIphone::~PowerIphone() { + // TODO Auto-generated destructor stub +}
\ No newline at end of file diff --git a/platform/iphone/power_iphone.h b/platform/iphone/power_iphone.h new file mode 100644 index 0000000000..5ab2a6c27f --- /dev/null +++ b/platform/iphone/power_iphone.h @@ -0,0 +1,50 @@ +/*************************************************************************/ +/* power_iphone.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef PLATFORM_IPHONE_POWER_IPHONE_H_ +#define PLATFORM_IPHONE_POWER_IPHONE_H_ + +class PowerIphone { +private: + int nsecs_left; + int percent_left; + PowerState power_state; + + bool UpdatePowerInfo(); + +public: + PowerIphone(); + virtual ~PowerIphone(); + + PowerState get_power_state(); + int get_power_seconds_left(); + int get_power_percent_left(); +}; + +#endif /* PLATFORM_IPHONE_POWER_IPHONE_H_ */
\ No newline at end of file diff --git a/platform/javascript/os_javascript.cpp b/platform/javascript/os_javascript.cpp index 201008b1db..d570d64acf 100644 --- a/platform/javascript/os_javascript.cpp +++ b/platform/javascript/os_javascript.cpp @@ -259,6 +259,8 @@ void OS_JavaScript::initialize(const VideoMode& p_desired,int p_video_driver,int physics_2d_server->init(); input = memnew( InputDefault ); + + power_manager = memnew( PowerJavascript ); #define EM_CHECK(ev) if (result!=EMSCRIPTEN_RESULT_SUCCESS)\ ERR_PRINTS("Error while setting " #ev " callback: Code " + itos(result)) @@ -853,8 +855,19 @@ String OS_JavaScript::get_joy_guid(int p_device) const { return input->get_joy_guid_remapped(p_device); } -OS_JavaScript::OS_JavaScript(GFXInitFunc p_gfx_init_func,void*p_gfx_init_ud, GetDataDirFunc p_get_data_dir_func) { +PowerState OS_JavaScript::get_power_state() { + return power_manager->get_power_state(); +} + +int OS_JavaScript::get_power_seconds_left() { + return power_manager->get_power_seconds_left(); +} +int OS_JavaScript::get_power_percent_left() { + return power_manager->get_power_percent_left(); +} + +OS_JavaScript::OS_JavaScript(GFXInitFunc p_gfx_init_func,void*p_gfx_init_ud, GetDataDirFunc p_get_data_dir_func) { gfx_init_func=p_gfx_init_func; gfx_init_ud=p_gfx_init_ud; last_button_mask=0; diff --git a/platform/javascript/os_javascript.h b/platform/javascript/os_javascript.h index 582f128ce8..5f6051bedb 100644 --- a/platform/javascript/os_javascript.h +++ b/platform/javascript/os_javascript.h @@ -32,6 +32,7 @@ #include "os/input.h" #include "drivers/unix/os_unix.h" #include "os/main_loop.h" +#include "power_javascript.h" #include "servers/physics/physics_server_sw.h" #include "servers/audio_server.h" #include "servers/physics_2d/physics_2d_server_sw.h" @@ -81,6 +82,8 @@ private: GetDataDirFunc get_data_dir_func; + PowerJavascript *power_manager; + #ifdef JAVASCRIPT_EVAL_ENABLED JavaScript* javascript_eval; #endif @@ -174,6 +177,10 @@ public: virtual bool is_joy_known(int p_device); virtual String get_joy_guid(int p_device) const; bool joy_connection_changed(int p_type, const EmscriptenGamepadEvent *p_event); + + virtual PowerState get_power_state(); + virtual int get_power_seconds_left(); + virtual int get_power_percent_left(); OS_JavaScript(GFXInitFunc p_gfx_init_func,void*p_gfx_init_ud, GetDataDirFunc p_get_data_dir_func); ~OS_JavaScript(); diff --git a/platform/javascript/power_javascript.cpp b/platform/javascript/power_javascript.cpp new file mode 100644 index 0000000000..d535ea4a5a --- /dev/null +++ b/platform/javascript/power_javascript.cpp @@ -0,0 +1,76 @@ +/*************************************************************************/ +/* power_javascript.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + + +#include "core/error_macros.h" +#include "power_javascript.h" + + +bool PowerJavascript::UpdatePowerInfo() { + // TODO Javascript implementation + return false; +} + +PowerState PowerJavascript::get_power_state() { + if (UpdatePowerInfo()) { + return power_state; + } + else { + WARN_PRINT("Power management is not implemented on this platform, defaulting to POWERSTATE_UNKNOWN"); + return POWERSTATE_UNKNOWN; + } +} + +int PowerJavascript::get_power_seconds_left() { + if (UpdatePowerInfo()) { + return nsecs_left; + } + else { + WARN_PRINT("Power management is not implemented on this platform, defaulting to -1"); + return -1; + } +} + +int PowerJavascript::get_power_percent_left() { + if (UpdatePowerInfo()) { + return percent_left; + } + else { + WARN_PRINT("Power management is not implemented on this platform, defaulting to -1"); + return -1; + } +} + + +PowerJavascript::PowerJavascript() : nsecs_left(-1), percent_left(-1), power_state(POWERSTATE_UNKNOWN) { + +} + +PowerJavascript::~PowerJavascript() { +}
\ No newline at end of file diff --git a/platform/javascript/power_javascript.h b/platform/javascript/power_javascript.h new file mode 100644 index 0000000000..e93737f98a --- /dev/null +++ b/platform/javascript/power_javascript.h @@ -0,0 +1,51 @@ +/*************************************************************************/ +/* power_javascript.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + + +#ifndef PLATFORM_JAVASCRIPT_POWER_JAVASCRIPT_H_ +#define PLATFORM_JAVASCRIPT_POWER_JAVASCRIPT_H_ + +class PowerJavascript { +private: + int nsecs_left; + int percent_left; + PowerState power_state; + + bool UpdatePowerInfo(); + +public: + PowerJavascript(); + virtual ~PowerJavascript(); + + PowerState get_power_state(); + int get_power_seconds_left(); + int get_power_percent_left(); +}; + +#endif /* PLATFORM_JAVASCRIPT_POWER_JAVASCRIPT_H_ */
\ No newline at end of file diff --git a/platform/osx/SCsub b/platform/osx/SCsub index 00f23687cf..1427c2e00d 100644 --- a/platform/osx/SCsub +++ b/platform/osx/SCsub @@ -10,6 +10,7 @@ files = [ # 'context_gl_osx.cpp', 'dir_access_osx.mm', 'joypad_osx.cpp', + 'power_osx.cpp', ] env.Program('#bin/godot', files) diff --git a/platform/osx/detect.py b/platform/osx/detect.py index ccd86177ab..b59dfe1afb 100644 --- a/platform/osx/detect.py +++ b/platform/osx/detect.py @@ -100,3 +100,4 @@ def configure(env): #env.Append( BUILDERS = { 'HLSL9' : env.Builder(action = methods.build_hlsl_dx9_headers, suffix = 'hlsl.h',src_suffix = '.hlsl') } ) env["x86_libtheora_opt_gcc"] = True + diff --git a/platform/osx/os_osx.h b/platform/osx/os_osx.h index d8c35472f2..9941774b40 100644 --- a/platform/osx/os_osx.h +++ b/platform/osx/os_osx.h @@ -32,6 +32,7 @@ #include "os/input.h" #include "joypad_osx.h" +#include "power_osx.h" #include "drivers/unix/os_unix.h" #include "main/input_default.h" #include "servers/visual_server.h" @@ -107,6 +108,8 @@ public: Size2 window_size; int current_screen; Rect2 restore_rect; + + power_osx *power_manager; float _mouse_scale(float p_scale) { if (display_scale>1.0) @@ -200,6 +203,10 @@ public: virtual bool is_window_maximized() const; virtual void request_attention(); virtual String get_joy_guid(int p_device) const; + + virtual PowerState get_power_state(); + virtual int get_power_seconds_left(); + virtual int get_power_percent_left(); void run(); diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm index 7108d94b5b..0699978caf 100644 --- a/platform/osx/os_osx.mm +++ b/platform/osx/os_osx.mm @@ -1119,6 +1119,8 @@ void OS_OSX::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi input = memnew( InputDefault ); joypad_osx = memnew( JoypadOSX ); + power_manager = memnew( power_osx ); + _ensure_data_dir(); NSArray *screenArray = [NSScreen screens]; @@ -1758,10 +1760,23 @@ OS::MouseMode OS_OSX::get_mouse_mode() const { return mouse_mode; } + String OS_OSX::get_joy_guid(int p_device) const { return input->get_joy_guid_remapped(p_device); } +PowerState OS_OSX::get_power_state() { + return power_manager->get_power_state(); +} + +int OS_OSX::get_power_seconds_left() { + return power_manager->get_power_seconds_left(); +} + +int OS_OSX::get_power_percent_left() { + return power_manager->get_power_percent_left(); +} + OS_OSX* OS_OSX::singleton=NULL; OS_OSX::OS_OSX() { diff --git a/platform/osx/power_osx.cpp b/platform/osx/power_osx.cpp new file mode 100644 index 0000000000..0b20a78b92 --- /dev/null +++ b/platform/osx/power_osx.cpp @@ -0,0 +1,233 @@ +/*************************************************************************/ +/* power_osx.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "power_osx.h" + +#include <CoreFoundation/CoreFoundation.h> +#include <IOKit/ps/IOPowerSources.h> +#include <IOKit/ps/IOPSKeys.h> + +// CODE CHUNK IMPORTED FROM SDL 2.0 + +/* CoreFoundation is so verbose... */ +#define STRMATCH(a,b) (CFStringCompare(a, b, 0) == kCFCompareEqualTo) +#define GETVAL(k,v) \ + CFDictionaryGetValueIfPresent(dict, CFSTR(k), (const void **) v) + +/* Note that AC power sources also include a laptop battery it is charging. */ +void power_osx::checkps(CFDictionaryRef dict, bool * have_ac, bool * have_battery, bool * charging) +{ + CFStringRef strval; /* don't CFRelease() this. */ + CFBooleanRef bval; + CFNumberRef numval; + bool charge = false; + bool choose = false; + bool is_ac = false; + int secs = -1; + int maxpct = -1; + int pct = -1; + + if ((GETVAL(kIOPSIsPresentKey, &bval)) && (bval == kCFBooleanFalse)) { + return; /* nothing to see here. */ + } + + if (!GETVAL(kIOPSPowerSourceStateKey, &strval)) { + return; + } + + if (STRMATCH(strval, CFSTR(kIOPSACPowerValue))) { + is_ac = *have_ac = true; + } else if (!STRMATCH(strval, CFSTR(kIOPSBatteryPowerValue))) { + return; /* not a battery? */ + } + + if ((GETVAL(kIOPSIsChargingKey, &bval)) && (bval == kCFBooleanTrue)) { + charge = true; + } + + if (GETVAL(kIOPSMaxCapacityKey, &numval)) { + SInt32 val = -1; + CFNumberGetValue(numval, kCFNumberSInt32Type, &val); + if (val > 0) { + *have_battery = true; + maxpct = (int) val; + } + } + + if (GETVAL(kIOPSMaxCapacityKey, &numval)) { + SInt32 val = -1; + CFNumberGetValue(numval, kCFNumberSInt32Type, &val); + if (val > 0) { + *have_battery = true; + maxpct = (int) val; + } + } + + if (GETVAL(kIOPSTimeToEmptyKey, &numval)) { + SInt32 val = -1; + CFNumberGetValue(numval, kCFNumberSInt32Type, &val); + + /* Mac OS X reports 0 minutes until empty if you're plugged in. :( */ + if ((val == 0) && (is_ac)) { + val = -1; /* !!! FIXME: calc from timeToFull and capacity? */ + } + + secs = (int) val; + if (secs > 0) { + secs *= 60; /* value is in minutes, so convert to seconds. */ + } + } + + if (GETVAL(kIOPSCurrentCapacityKey, &numval)) { + SInt32 val = -1; + CFNumberGetValue(numval, kCFNumberSInt32Type, &val); + pct = (int) val; + } + + if ((pct > 0) && (maxpct > 0)) { + pct = (int) ((((double) pct) / ((double) maxpct)) * 100.0); + } + + if (pct > 100) { + pct = 100; + } + + /* + * We pick the battery that claims to have the most minutes left. + * (failing a report of minutes, we'll take the highest percent.) + */ + if ((secs < 0) && (nsecs_left < 0)) { + if ((pct < 0) && (percent_left < 0)) { + choose = true; /* at least we know there's a battery. */ + } + if (pct > percent_left) { + choose = true; + } + } else if (secs > nsecs_left) { + choose = true; + } + + if (choose) { + nsecs_left = secs; + percent_left = pct; + *charging = charge; + } +} + +#undef GETVAL +#undef STRMATCH + +// CODE CHUNK IMPORTED FROM SDL 2.0 +bool power_osx::GetPowerInfo_MacOSX() +{ + CFTypeRef blob = IOPSCopyPowerSourcesInfo(); + + nsecs_left = -1; + percent_left = -1; + power_state = POWERSTATE_UNKNOWN; + + if (blob != NULL) { + CFArrayRef list = IOPSCopyPowerSourcesList(blob); + if (list != NULL) { + /* don't CFRelease() the list items, or dictionaries! */ + bool have_ac = false; + bool have_battery = false; + bool charging = false; + const CFIndex total = CFArrayGetCount(list); + CFIndex i; + for (i = 0; i < total; i++) { + CFTypeRef ps = (CFTypeRef) CFArrayGetValueAtIndex(list, i); + CFDictionaryRef dict = IOPSGetPowerSourceDescription(blob, ps); + if (dict != NULL) { + checkps(dict, &have_ac, &have_battery, &charging); + } + } + + if (!have_battery) { + power_state = POWERSTATE_NO_BATTERY; + } else if (charging) { + power_state = POWERSTATE_CHARGING; + } else if (have_ac) { + power_state = POWERSTATE_CHARGED; + } else { + power_state = POWERSTATE_ON_BATTERY; + } + + CFRelease(list); + } + CFRelease(blob); + } + + return true; /* always the definitive answer on Mac OS X. */ +} + + + +bool power_osx::UpdatePowerInfo() { + if (GetPowerInfo_MacOSX()) { + return true; + } + return false; +} + + +PowerState power_osx::get_power_state() { + if (UpdatePowerInfo()) { + return power_state; + } + else { + return POWERSTATE_UNKNOWN; + } +} + +int power_osx::get_power_seconds_left() { + if (UpdatePowerInfo()) { + return nsecs_left; + } + else { + return -1; + } +} + +int power_osx::get_power_percent_left() { + if (UpdatePowerInfo()) { + return percent_left; + } + else { + return -1; + } +} + + +power_osx::power_osx() : nsecs_left(-1), percent_left(-1), power_state(POWERSTATE_UNKNOWN) { + +} + +power_osx::~power_osx() { + +}
\ No newline at end of file diff --git a/platform/osx/power_osx.h b/platform/osx/power_osx.h new file mode 100644 index 0000000000..a8ab50d9f2 --- /dev/null +++ b/platform/osx/power_osx.h @@ -0,0 +1,57 @@ +/*************************************************************************/ +/* power_osx.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef PLATFORM_OSX_POWER_OSX_H_ +#define PLATFORM_OSX_POWER_OSX_H_ + +#include "dir_access_osx.h" +#include "os/file_access.h" +#include "os/power.h" +#include <CoreFoundation/CoreFoundation.h> + +class power_osx { + +private: + int nsecs_left; + int percent_left; + PowerState power_state; + void checkps(CFDictionaryRef dict, bool * have_ac, bool * have_battery, bool * charging); + bool GetPowerInfo_MacOSX(/*PowerState * state, int *seconds, int *percent*/); + bool UpdatePowerInfo(); + +public: + power_osx(); + virtual ~power_osx(); + + PowerState get_power_state(); + int get_power_seconds_left(); + int get_power_percent_left(); +}; + +#endif /* PLATFORM_OSX_POWER_OSX_H_ */
\ No newline at end of file diff --git a/platform/server/os_server.cpp b/platform/server/os_server.cpp index d691ae35bd..ee80080b4e 100644 --- a/platform/server/os_server.cpp +++ b/platform/server/os_server.cpp @@ -217,6 +217,18 @@ void OS_Server::set_cursor_shape(CursorShape p_shape) { } +PowerState OS_Server::get_power_state() { + return power_manager->get_power_state(); +} + +int OS_Server::get_power_seconds_left() { + return power_manager->get_power_seconds_left(); +} + +int OS_Server::get_power_percent_left() { + return power_manager->get_power_percent_left(); +} + void OS_Server::run() { force_quit = false; diff --git a/platform/server/os_server.h b/platform/server/os_server.h index 2b6225c48d..a035076726 100644 --- a/platform/server/os_server.h +++ b/platform/server/os_server.h @@ -38,6 +38,7 @@ #include "servers/audio_server.h" #include "drivers/rtaudio/audio_driver_rtaudio.h" #include "servers/physics_2d/physics_2d_server_sw.h" +#include "../x11/power_x11.h" //bitch #undef CursorShape @@ -65,6 +66,8 @@ class OS_Server : public OS_Unix { bool force_quit; InputDefault *input; + + PowerX11 *power_manager; @@ -105,6 +108,10 @@ public: virtual void move_window_to_foreground(); void run(); + + virtual PowerState get_power_state(); + virtual int get_power_seconds_left(); + virtual int get_power_percent_left(); OS_Server(); }; diff --git a/platform/uwp/os_uwp.cpp b/platform/uwp/os_uwp.cpp index 61b8a1c240..f2a99fe62c 100644 --- a/platform/uwp/os_uwp.cpp +++ b/platform/uwp/os_uwp.cpp @@ -292,6 +292,8 @@ void OSUWP::initialize(const VideoMode& p_desired,int p_video_driver,int p_audio ERR_PRINT("Initializing audio failed."); } + power_manager = memnew ( PowerWinRT ); + managed_object->update_clipboard(); Clipboard::ContentChanged += ref new EventHandler<Platform::Object^>(managed_object, &ManagedType::on_clipboard_changed); @@ -919,6 +921,18 @@ String OSUWP::get_data_dir() const { return String(data_folder->Path->Data()).replace("\\", "/"); } +PowerState OSWinrt::get_power_state() { + return power_manager->get_power_state(); +} + +int OSWinrt::get_power_seconds_left() { + return power_manager->get_power_seconds_left(); +} + +int OSWinrt::get_power_percent_left() { + return power_manager->get_power_percent_left(); +} + OSUWP::OSUWP() { diff --git a/platform/uwp/os_uwp.h b/platform/uwp/os_uwp.h index f65aa2d8d9..72cc8a7854 100644 --- a/platform/uwp/os_uwp.h +++ b/platform/uwp/os_uwp.h @@ -42,12 +42,14 @@ #include "core/ustring.h" #include "main/input_default.h" #include "joypad_uwp.h" +#include "power_winrt.h" #include <windows.h> #include <io.h> #include <fcntl.h> #include <stdio.h> + /** @author Juan Linietsky <reduzio@gmail.com> */ @@ -111,6 +113,8 @@ private: AudioDriverXAudio2 audio_driver; + PowerWinRT *power_manager; + MouseMode mouse_mode; bool alt_mem; bool gr_mem; @@ -260,6 +264,10 @@ public: virtual bool get_swap_ok_cancel() { return true; } void input_event(InputEvent &p_event); + + virtual PowerState get_power_state(); + virtual int get_power_seconds_left(); + virtual int get_power_percent_left(); void queue_key_event(KeyEvent &p_event); diff --git a/platform/windows/SCsub b/platform/windows/SCsub index ae8c07384f..befbe00183 100644 --- a/platform/windows/SCsub +++ b/platform/windows/SCsub @@ -12,6 +12,7 @@ common_win = [ "packet_peer_udp_winsock.cpp", "stream_peer_winsock.cpp", "joypad.cpp", + "power_windows.cpp", ] restarget = "godot_res" + env["OBJSUFFIX"] diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index 0ef964522b..8a347e5f32 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -1134,6 +1134,8 @@ void OS_Windows::initialize(const VideoMode& p_desired,int p_video_driver,int p_ input = memnew( InputDefault ); joypad = memnew (JoypadWindows(input, &hWnd)); + power_manager = memnew( PowerWindows ); + AudioDriverManager::get_driver(p_audio_driver)->set_singleton(); if (AudioDriverManager::get_driver(p_audio_driver)->init()!=OK) { @@ -2393,6 +2395,18 @@ bool OS_Windows::is_vsync_enabled() const{ return true; } +PowerState OS_Windows::get_power_state() { + return power_manager->get_power_state(); +} + +int OS_Windows::get_power_seconds_left() { + return power_manager->get_power_seconds_left(); +} + +int OS_Windows::get_power_percent_left() { + return power_manager->get_power_percent_left(); +} + bool OS_Windows::check_feature_support(const String& p_feature) { return VisualServer::get_singleton()->has_os_feature(p_feature); diff --git a/platform/windows/os_windows.h b/platform/windows/os_windows.h index 73a2d5f451..c8cacac7a2 100644 --- a/platform/windows/os_windows.h +++ b/platform/windows/os_windows.h @@ -31,6 +31,7 @@ #include "os/input.h" #include "os/os.h" +#include "power_windows.h" #include "context_gl_win.h" #include "servers/visual_server.h" #include "servers/visual/rasterizer.h" @@ -125,6 +126,8 @@ class OS_Windows : public OS { InputDefault *input; JoypadWindows *joypad; + PowerWindows *power_manager; + #ifdef RTAUDIO_ENABLED AudioDriverRtAudio driver_rtaudio; #endif @@ -285,6 +288,10 @@ public: virtual void set_use_vsync(bool p_enable); virtual bool is_vsync_enabled() const; + virtual PowerState get_power_state(); + virtual int get_power_seconds_left(); + virtual int get_power_percent_left(); + virtual bool check_feature_support(const String& p_feature); OS_Windows(HINSTANCE _hInstance); diff --git a/platform/windows/power_windows.cpp b/platform/windows/power_windows.cpp new file mode 100644 index 0000000000..a19472ab8f --- /dev/null +++ b/platform/windows/power_windows.cpp @@ -0,0 +1,108 @@ +/*************************************************************************/ +/* power_windows.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "power_windows.h" + +// CODE CHUNK IMPORTED FROM SDL 2.0 + +bool PowerWindows::GetPowerInfo_Windows() +{ + SYSTEM_POWER_STATUS status; + bool need_details = FALSE; + + /* This API should exist back to Win95. */ + if (!GetSystemPowerStatus(&status)) + { + /* !!! FIXME: push GetLastError() into GetError() */ + power_state = POWERSTATE_UNKNOWN; + } else if (status.BatteryFlag == 0xFF) { /* unknown state */ + power_state = POWERSTATE_UNKNOWN; + } else if (status.BatteryFlag & (1 << 7)) { /* no battery */ + power_state = POWERSTATE_NO_BATTERY; + } else if (status.BatteryFlag & (1 << 3)) { /* charging */ + power_state = POWERSTATE_CHARGING; + need_details = TRUE; + } else if (status.ACLineStatus == 1) { + power_state = POWERSTATE_CHARGED; /* on AC, not charging. */ + need_details = TRUE; + } else { + power_state = POWERSTATE_ON_BATTERY; /* not on AC. */ + need_details = TRUE; + } + + percent_left = -1; + nsecs_left = -1; + if (need_details) { + const int pct = (int) status.BatteryLifePercent; + const int secs = (int) status.BatteryLifeTime; + + if (pct != 255) { /* 255 == unknown */ + percent_left = (pct > 100) ? 100 : pct; /* clamp between 0%, 100% */ + } + if (secs != 0xFFFFFFFF) { /* ((DWORD)-1) == unknown */ + nsecs_left = secs; + } + } + + return TRUE; /* always the definitive answer on Windows. */ +} + +PowerState PowerWindows::get_power_state() { + if (GetPowerInfo_Windows()) { + return power_state; + } + else { + return POWERSTATE_UNKNOWN; + } +} + +int PowerWindows::get_power_seconds_left() { + if (GetPowerInfo_Windows()) { + return nsecs_left; + } + else { + return -1; + } +} + +int PowerWindows::get_power_percent_left() { + if (GetPowerInfo_Windows()) { + return percent_left; + } + else { + return -1; + } +} + +PowerWindows::PowerWindows() : nsecs_left(-1), percent_left(-1), power_state(POWERSTATE_UNKNOWN) { + +} + +PowerWindows::~PowerWindows() { +}
\ No newline at end of file diff --git a/platform/windows/power_windows.h b/platform/windows/power_windows.h new file mode 100644 index 0000000000..a3a0b9568f --- /dev/null +++ b/platform/windows/power_windows.h @@ -0,0 +1,57 @@ +/*************************************************************************/ +/* power_windows.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef PLATFORM_WINDOWS_POWER_WINDOWS_H_ +#define PLATFORM_WINDOWS_POWER_WINDOWS_H_ + +#include "os/dir_access.h" +#include "os/file_access.h" +#include "os/power.h" + +#include <windows.h> + +class PowerWindows { + +private: + int nsecs_left; + int percent_left; + PowerState power_state; + + bool GetPowerInfo_Windows(); + +public: + PowerWindows(); + virtual ~PowerWindows(); + + PowerState get_power_state(); + int get_power_seconds_left(); + int get_power_percent_left(); +}; + +#endif /* PLATFORM_WINDOWS_POWER_WINDOWS_H_ */
\ No newline at end of file diff --git a/platform/x11/SCsub b/platform/x11/SCsub index 4ae8ac07f7..fc9208c563 100644 --- a/platform/x11/SCsub +++ b/platform/x11/SCsub @@ -8,6 +8,7 @@ common_x11 = [\ "os_x11.cpp",\ "key_mapping_x11.cpp",\ "joypad_linux.cpp",\ + "power_x11.cpp",\ ] env.Program('#bin/godot', ['godot_x11.cpp'] + common_x11) diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index a4ed08f330..689fe076f1 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -2007,6 +2007,18 @@ void OS_X11::set_context(int p_context) { } } +PowerState OS_X11::get_power_state() { + return power_manager->get_power_state(); +} + +int OS_X11::get_power_seconds_left() { + return power_manager->get_power_seconds_left(); +} + +int OS_X11::get_power_percent_left() { + return power_manager->get_power_percent_left(); +} + OS_X11::OS_X11() { #ifdef RTAUDIO_ENABLED diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h index 3ec358f103..ce2e2df6e9 100644 --- a/platform/x11/os_x11.h +++ b/platform/x11/os_x11.h @@ -46,6 +46,7 @@ #include "servers/physics_2d/physics_2d_server_wrap_mt.h" #include "main/input_default.h" #include "joypad_linux.h" +#include "power_x11.h" #include <X11/keysym.h> #include <X11/Xlib.h> @@ -164,6 +165,8 @@ class OS_X11 : public OS_Unix { AudioDriverDummy driver_dummy; Atom net_wm_icon; + + PowerX11 *power_manager; int audio_driver_index; unsigned int capture_idle; @@ -260,6 +263,10 @@ public: virtual void set_use_vsync(bool p_enable); virtual bool is_vsync_enabled() const; + virtual PowerState get_power_state(); + virtual int get_power_seconds_left(); + virtual int get_power_percent_left(); + void run(); OS_X11(); diff --git a/platform/x11/power_x11.cpp b/platform/x11/power_x11.cpp new file mode 100644 index 0000000000..f6966124b6 --- /dev/null +++ b/platform/x11/power_x11.cpp @@ -0,0 +1,575 @@ +/*************************************************************************/ +/* power_x11.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "power_x11.h" + +#include <stdio.h> +#include <unistd.h> + +#include <sys/types.h> +#include <sys/stat.h> +#include <dirent.h> +#include <fcntl.h> + +// CODE CHUNK IMPORTED FROM SDL 2.0 + +static const char* proc_apm_path = "/proc/apm"; +static const char* proc_acpi_battery_path = "/proc/acpi/battery"; +static const char* proc_acpi_ac_adapter_path = "/proc/acpi/ac_adapter"; +static const char* sys_class_power_supply_path = "/sys/class/power_supply"; + +FileAccessRef PowerX11::open_power_file(const char* base, const char* node, const char* key) +{ + String path = String(base) + String("/") + String(node) + String("/") + String(key); + FileAccessRef f = FileAccess::open(path,FileAccess::READ); + return f; +} + + +bool PowerX11::read_power_file(const char* base, const char* node, const char* key, char* buf, size_t buflen) +{ + ssize_t br = 0; + FileAccessRef fd = open_power_file(base, node, key); + if (!fd) { + return false; + } + br = fd->get_buffer(reinterpret_cast<uint8_t*>(buf), buflen-1); + fd->close(); + if (br < 0) { + return false; + } + buf[br] = '\0'; // null-terminate the string + return true; +} + + +bool PowerX11::make_proc_acpi_key_val(char **_ptr, char **_key, char **_val) +{ + char *ptr = *_ptr; + + while (*ptr == ' ') { + ptr++; /* skip whitespace. */ + } + + if (*ptr == '\0') { + return false; /* EOF. */ + } + + *_key = ptr; + + while ((*ptr != ':') && (*ptr != '\0')) { + ptr++; + } + + if (*ptr == '\0') { + return false; /* (unexpected) EOF. */ + } + + *(ptr++) = '\0'; /* terminate the key. */ + + while ((*ptr == ' ') && (*ptr != '\0')) { + ptr++; /* skip whitespace. */ + } + + if (*ptr == '\0') { + return false; /* (unexpected) EOF. */ + } + + *_val = ptr; + + while ((*ptr != '\n') && (*ptr != '\0')) { + ptr++; + } + + if (*ptr != '\0') { + *(ptr++) = '\0'; /* terminate the value. */ + } + + *_ptr = ptr; /* store for next time. */ + return true; +} + +void +PowerX11::check_proc_acpi_battery(const char * node, bool * have_battery, bool * charging) +{ + const char *base = proc_acpi_battery_path; + char info[1024]; + char state[1024]; + char *ptr = NULL; + char *key = NULL; + char *val = NULL; + bool charge = false; + bool choose = false; + int maximum = -1; + int remaining = -1; + int secs = -1; + int pct = -1; + + if (!read_power_file(base, node, "state", state, sizeof (state))) { + return; + } else { + if (!read_power_file(base, node, "info", info, sizeof (info))) + return; + } + + ptr = &state[0]; + while (make_proc_acpi_key_val(&ptr, &key, &val)) { + if (String(key) == "present") { + if (String(val) == "yes") { + *have_battery = true; + } + } else if (String(key) == "charging state") { + /* !!! FIXME: what exactly _does_ charging/discharging mean? */ + if (String(val) == "charging/discharging") { + charge = true; + } else if (String(val) == "charging") { + charge = true; + } + } else if (String(key) == "remaining capacity") { + char *endptr = NULL; + //const int cvt = (int) strtol(val, &endptr, 10); + String sval = val; + const int cvt = sval.to_int(); + if (*endptr == ' ') { + remaining = cvt; + } + } + } + + ptr = &info[0]; + while (make_proc_acpi_key_val(&ptr, &key, &val)) { + if (String(key) == "design capacity") { + char *endptr = NULL; + String sval = val; + const int cvt = sval.to_int(); + if (*endptr == ' ') { + maximum = cvt; + } + } + } + + if ((maximum >= 0) && (remaining >= 0)) { + pct = (int) ((((float) remaining) / ((float) maximum)) * 100.0f); + if (pct < 0) { + pct = 0; + } else if (pct > 100) { + pct = 100; + } + } + + /* !!! FIXME: calculate (secs). */ + + /* + * We pick the battery that claims to have the most minutes left. + * (failing a report of minutes, we'll take the highest percent.) + */ + if ((secs < 0) && (this->nsecs_left < 0)) { + if ((pct < 0) && (this->percent_left < 0)) { + choose = true; /* at least we know there's a battery. */ + } + if (pct > this->percent_left) { + choose = true; + } + } else if (secs > this->nsecs_left) { + choose = true; + } + + if (choose) { + this->nsecs_left = secs; + this->percent_left = pct; + *charging = charge; + } +} + +void PowerX11::check_proc_acpi_ac_adapter(const char * node, bool * have_ac) +{ + const char *base = proc_acpi_ac_adapter_path; + char state[256]; + char *ptr = NULL; + char *key = NULL; + char *val = NULL; + + if (!read_power_file(base, node, "state", state, sizeof (state))) { + return; + } + + ptr = &state[0]; + while (make_proc_acpi_key_val(&ptr, &key, &val)) { + String skey = key; + if (skey == "state") { + String sval = val; + if (sval == "on-line") { + *have_ac = true; + } + } + } +} + + +bool PowerX11::GetPowerInfo_Linux_proc_acpi() +{ + String node; + DirAccess *dirp = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); + bool have_battery = false; + bool have_ac = false; + bool charging = false; + + this->nsecs_left = -1; + this->percent_left = -1; + this->power_state = POWERSTATE_UNKNOWN; + + + dirp->change_dir(proc_acpi_battery_path); + dirp->list_dir_begin(); + + if (dirp == NULL) { + return false; /* can't use this interface. */ + } else { + node = dirp->get_next(); + while (node != "") { + check_proc_acpi_battery(node.utf8().get_data(), &have_battery, &charging/*, seconds, percent*/); + node = dirp->get_next(); + } + memdelete(dirp); + } + + dirp->change_dir(proc_acpi_ac_adapter_path); + dirp->list_dir_begin(); + if (dirp == NULL) { + return false; /* can't use this interface. */ + } else { + node = dirp->get_next(); + while (node != "") { + check_proc_acpi_ac_adapter(node.utf8().get_data(), &have_ac); + node = dirp->get_next(); + } + memdelete(dirp); + } + + if (!have_battery) { + this->power_state = POWERSTATE_NO_BATTERY; + } else if (charging) { + this->power_state = POWERSTATE_CHARGING; + } else if (have_ac) { + this->power_state = POWERSTATE_CHARGED; + } else { + this->power_state = POWERSTATE_ON_BATTERY; + } + + return true; /* definitive answer. */ +} + + +bool PowerX11::next_string(char **_ptr, char **_str) +{ + char *ptr = *_ptr; + char *str = *_str; + + while (*ptr == ' ') { /* skip any spaces... */ + ptr++; + } + + if (*ptr == '\0') { + return false; + } + + str = ptr; + while ((*ptr != ' ') && (*ptr != '\n') && (*ptr != '\0')) + ptr++; + + if (*ptr != '\0') + *(ptr++) = '\0'; + + *_str = str; + *_ptr = ptr; + return true; +} + +bool PowerX11::int_string(char *str, int *val) +{ + String sval = str; + *val = sval.to_int(); + return (*str != '\0'); +} + +/* http://lxr.linux.no/linux+v2.6.29/drivers/char/apm-emulation.c */ +bool PowerX11::GetPowerInfo_Linux_proc_apm() +{ + bool need_details = false; + int ac_status = 0; + int battery_status = 0; + int battery_flag = 0; + int battery_percent = 0; + int battery_time = 0; + FileAccessRef fd = FileAccess::open(proc_apm_path,FileAccess::READ); + char buf[128]; + char *ptr = &buf[0]; + char *str = NULL; + ssize_t br; + + if (!fd) { + return false; /* can't use this interface. */ + } + + br = fd->get_buffer(reinterpret_cast<uint8_t*>(buf), sizeof (buf) - 1); + fd->close(); + + if (br < 0) { + return false; + } + + buf[br] = '\0'; /* null-terminate the string. */ + if (!next_string(&ptr, &str)) { /* driver version */ + return false; + } + if (!next_string(&ptr, &str)) { /* BIOS version */ + return false; + } + if (!next_string(&ptr, &str)) { /* APM flags */ + return false; + } + + if (!next_string(&ptr, &str)) { /* AC line status */ + return false; + } else if (!int_string(str, &ac_status)) { + return false; + } + + if (!next_string(&ptr, &str)) { /* battery status */ + return false; + } else if (!int_string(str, &battery_status)) { + return false; + } + if (!next_string(&ptr, &str)) { /* battery flag */ + return false; + } else if (!int_string(str, &battery_flag)) { + return false; + } + if (!next_string(&ptr, &str)) { /* remaining battery life percent */ + return false; + } + String sstr = str; + if (sstr[sstr.length() - 1] == '%') { + sstr[sstr.length() - 1] = '\0'; + } + if (!int_string(str, &battery_percent)) { + return false; + } + + if (!next_string(&ptr, &str)) { /* remaining battery life time */ + return false; + } else if (!int_string(str, &battery_time)) { + return false; + } + + if (!next_string(&ptr, &str)) { /* remaining battery life time units */ + return false; + } else if (String(str) == "min") { + battery_time *= 60; + } + + if (battery_flag == 0xFF) { /* unknown state */ + this->power_state = POWERSTATE_UNKNOWN; + } else if (battery_flag & (1 << 7)) { /* no battery */ + this->power_state = POWERSTATE_NO_BATTERY; + } else if (battery_flag & (1 << 3)) { /* charging */ + this->power_state = POWERSTATE_CHARGING; + need_details = true; + } else if (ac_status == 1) { + this->power_state = POWERSTATE_CHARGED; /* on AC, not charging. */ + need_details = true; + } else { + this->power_state = POWERSTATE_ON_BATTERY; + need_details = true; + } + + this->percent_left = -1; + this->nsecs_left = -1; + if (need_details) { + const int pct = battery_percent; + const int secs = battery_time; + + if (pct >= 0) { /* -1 == unknown */ + this->percent_left = (pct > 100) ? 100 : pct; /* clamp between 0%, 100% */ + } + if (secs >= 0) { /* -1 == unknown */ + this->nsecs_left = secs; + } + } + + return true; +} + +/* !!! FIXME: implement d-bus queries to org.freedesktop.UPower. */ + +bool PowerX11::GetPowerInfo_Linux_sys_class_power_supply(/*PowerState *state, int *seconds, int *percent*/) +{ + const char* base = sys_class_power_supply_path; + String name; + + DirAccess *dirp = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); + dirp->change_dir(base); + dirp->list_dir_begin(); + + if (!dirp) { + return false; + } + + this->power_state = POWERSTATE_NO_BATTERY; /* assume we're just plugged in. */ + this->nsecs_left = -1; + this->percent_left = -1; + + name = dirp->get_next(); + + while (name != "") { + bool choose = false; + char str[64]; + PowerState st; + int secs; + int pct; + + if ((name == ".") || (name == "..")) { + name = dirp->get_next(); + continue; //skip these, of course. + } else { + if (!read_power_file(base, name.utf8().get_data(), "type", str, sizeof (str))) { + name = dirp->get_next(); + continue; // Don't know _what_ we're looking at. Give up on it. + } else { + if (String(str) != "Battery\n") { + name = dirp->get_next(); + continue; // we don't care about UPS and such. + } + } + } + + /* some drivers don't offer this, so if it's not explicitly reported assume it's present. */ + if (read_power_file(base, name.utf8().get_data(), "present", str, sizeof (str)) && (String(str) == "0\n")) { + st = POWERSTATE_NO_BATTERY; + } else if (!read_power_file(base, name.utf8().get_data(), "status", str, sizeof (str))) { + st = POWERSTATE_UNKNOWN; /* uh oh */ + } else if (String(str) == "Charging\n") { + st = POWERSTATE_CHARGING; + } else if (String(str) == "Discharging\n") { + st = POWERSTATE_ON_BATTERY; + } else if ((String(str) == "Full\n") || (String(str) == "Not charging\n")) { + st = POWERSTATE_CHARGED; + } else { + st = POWERSTATE_UNKNOWN; /* uh oh */ + } + + if (!read_power_file(base, name.utf8().get_data(), "capacity", str, sizeof (str))) { + pct = -1; + } else { + pct = String(str).to_int(); + pct = (pct > 100) ? 100 : pct; /* clamp between 0%, 100% */ + } + + if (!read_power_file(base, name.utf8().get_data(), "time_to_empty_now", str, sizeof (str))) { + secs = -1; + } else { + secs = String(str).to_int(); + secs = (secs <= 0) ? -1 : secs; /* 0 == unknown */ + } + + /* + * We pick the battery that claims to have the most minutes left. + * (failing a report of minutes, we'll take the highest percent.) + */ + if ((secs < 0) && (this->nsecs_left < 0)) { + if ((pct < 0) && (this->percent_left < 0)) { + choose = true; /* at least we know there's a battery. */ + } else if (pct > this->percent_left) { + choose = true; + } + } else if (secs > this->nsecs_left) { + choose = true; + } + + if (choose) { + this->nsecs_left = secs; + this->percent_left = pct; + this->power_state = st; + } + + name = dirp->get_next(); + } + + memdelete(dirp); + return true; /* don't look any further*/ +} + + + +bool PowerX11::UpdatePowerInfo() +{ + if (GetPowerInfo_Linux_sys_class_power_supply()) { // try method 1 + return true; + } + if (GetPowerInfo_Linux_proc_acpi()) { // try further + return true; + } + if (GetPowerInfo_Linux_proc_apm()) { // try even further + return true; + } + return false; +} + +PowerX11::PowerX11() : nsecs_left(-1), percent_left(-1), power_state(POWERSTATE_UNKNOWN) { +} + +PowerX11::~PowerX11() { +} + +PowerState PowerX11::get_power_state() { + if (UpdatePowerInfo()) { + return power_state; + } + else { + return POWERSTATE_UNKNOWN; + } +} + +int PowerX11::get_power_seconds_left() { + if (UpdatePowerInfo()) { + return nsecs_left; + } + else { + return -1; + } +} + +int PowerX11::get_power_percent_left() { + if (UpdatePowerInfo()) { + return percent_left; + } + else { + return -1; + } +}
\ No newline at end of file diff --git a/platform/x11/power_x11.h b/platform/x11/power_x11.h new file mode 100644 index 0000000000..5d03cac394 --- /dev/null +++ b/platform/x11/power_x11.h @@ -0,0 +1,68 @@ +/*************************************************************************/ +/* power_x11.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef X11_POWER_H_ +#define X11_POWER_H_ + +#include "os/dir_access.h" +#include "os/file_access.h" +#include "os/power.h" + + +class PowerX11 { + +private: + int nsecs_left; + int percent_left; + PowerState power_state; + + + FileAccessRef open_power_file(const char* base, const char* node, const char* key); + bool read_power_file(const char* base, const char* node, const char* key, char* buf, size_t buflen); + bool make_proc_acpi_key_val(char **_ptr, char **_key, char **_val); + void check_proc_acpi_battery(const char * node, bool * have_battery, bool * charging); + void check_proc_acpi_ac_adapter(const char * node, bool * have_ac); + bool GetPowerInfo_Linux_proc_acpi(); + bool next_string(char **_ptr, char **_str); + bool int_string(char *str, int *val); + bool GetPowerInfo_Linux_proc_apm(); + bool GetPowerInfo_Linux_sys_class_power_supply(); + bool UpdatePowerInfo(); + + +public: + PowerX11(); + virtual ~PowerX11(); + + PowerState get_power_state(); + int get_power_seconds_left(); + int get_power_percent_left(); +}; + +#endif /* X11_POWER_H_ */
\ No newline at end of file diff --git a/scene/2d/area_2d.cpp b/scene/2d/area_2d.cpp index 68228520b3..55c7716b6b 100644 --- a/scene/2d/area_2d.cpp +++ b/scene/2d/area_2d.cpp @@ -357,6 +357,10 @@ void Area2D::_clear_monitoring() { Object *obj = ObjectDB::get_instance(E->key()); Node *node = obj ? obj->cast_to<Node>() : NULL; ERR_CONTINUE(!node); + + node->disconnect(SceneStringNames::get_singleton()->tree_entered,this,SceneStringNames::get_singleton()->_body_enter_tree); + node->disconnect(SceneStringNames::get_singleton()->tree_exited,this,SceneStringNames::get_singleton()->_body_exit_tree); + if (!E->get().in_tree) continue; @@ -366,9 +370,6 @@ void Area2D::_clear_monitoring() { } emit_signal(SceneStringNames::get_singleton()->body_exited,obj); - - node->disconnect(SceneStringNames::get_singleton()->tree_entered,this,SceneStringNames::get_singleton()->_body_enter_tree); - node->disconnect(SceneStringNames::get_singleton()->tree_exited,this,SceneStringNames::get_singleton()->_body_exit_tree); } } @@ -388,6 +389,9 @@ void Area2D::_clear_monitoring() { continue; //ERR_CONTINUE(!node); + node->disconnect(SceneStringNames::get_singleton()->tree_entered,this,SceneStringNames::get_singleton()->_area_enter_tree); + node->disconnect(SceneStringNames::get_singleton()->tree_exited,this,SceneStringNames::get_singleton()->_area_exit_tree); + if (!E->get().in_tree) continue; @@ -397,9 +401,6 @@ void Area2D::_clear_monitoring() { } emit_signal(SceneStringNames::get_singleton()->area_exited,obj); - - node->disconnect(SceneStringNames::get_singleton()->tree_entered,this,SceneStringNames::get_singleton()->_area_enter_tree); - node->disconnect(SceneStringNames::get_singleton()->tree_exited,this,SceneStringNames::get_singleton()->_area_exit_tree); } } diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp index e889d1acd3..6d06f8c59c 100644 --- a/scene/gui/dialogs.cpp +++ b/scene/gui/dialogs.cpp @@ -36,6 +36,34 @@ void WindowDialog::_post_popup() { drag_type = DRAG_NONE; // just in case } +void WindowDialog::_fix_size() { + + // Perhaps this should be called when the viewport resizes aswell or windows go out of bounds... + + // Ensure the whole window is visible. + Point2i pos = get_global_pos(); + Size2i size = get_size(); + Size2i viewport_size = get_viewport_rect().size; + + // Windows require additional padding to keep the window chrome visible. + Ref<StyleBox> panel = get_stylebox("panel", "WindowDialog"); + float top = panel->get_margin(MARGIN_TOP); + float left = panel->get_margin(MARGIN_LEFT); + float bottom = panel->get_margin(MARGIN_BOTTOM); + float right = panel->get_margin(MARGIN_RIGHT); + + pos.x = MAX(left, MIN(pos.x, viewport_size.x - size.x - right)); + pos.y = MAX(top, MIN(pos.y, viewport_size.y - size.y - bottom)); + set_global_pos(pos); + + // Also resize the window to fit if a resize should be possible at all. + if (resizable) { + size.x = MIN(size.x, viewport_size.x - left - right); + size.y = MIN(size.y, viewport_size.y - top - bottom); + set_size(size); + } +} + bool WindowDialog::has_point(const Point2& p_point) const { Rect2 r(Point2(), get_size()); diff --git a/scene/gui/dialogs.h b/scene/gui/dialogs.h index 845ac69cd5..dd75b76c8e 100644 --- a/scene/gui/dialogs.h +++ b/scene/gui/dialogs.h @@ -66,7 +66,7 @@ class WindowDialog : public Popup { protected: virtual void _post_popup(); - + virtual void _fix_size(); virtual void _close_pressed() {} virtual bool has_point(const Point2& p_point) const; void _notification(int p_what); diff --git a/scene/gui/popup.cpp b/scene/gui/popup.cpp index 60ecd775f7..1f0daa99ba 100644 --- a/scene/gui/popup.cpp +++ b/scene/gui/popup.cpp @@ -226,12 +226,16 @@ void Popup::popup_centered_ratio(float p_screen_ratio) { } -void Popup::popup() { +void Popup::popup(const Rect2& bounds) { emit_signal("about_to_show"); show_modal(exclusive); - + // Fit the popup into the optionally provided bounds. + if (!bounds.has_no_area()) { + set_pos(bounds.pos); + set_size(bounds.size); + } _fix_size(); Control *focusable = find_next_valid_focus(); @@ -260,7 +264,7 @@ void Popup::_bind_methods() { ClassDB::bind_method(D_METHOD("popup_centered","size"),&Popup::popup_centered,DEFVAL(Size2())); ClassDB::bind_method(D_METHOD("popup_centered_ratio","ratio"),&Popup::popup_centered_ratio,DEFVAL(0.75)); ClassDB::bind_method(D_METHOD("popup_centered_minsize","minsize"),&Popup::popup_centered_minsize,DEFVAL(Size2())); - ClassDB::bind_method(D_METHOD("popup"),&Popup::popup); + ClassDB::bind_method(D_METHOD("popup","bounds"),&Popup::popup,DEFVAL(Rect2())); ClassDB::bind_method(D_METHOD("set_exclusive","enable"),&Popup::set_exclusive); ClassDB::bind_method(D_METHOD("is_exclusive"),&Popup::is_exclusive); ADD_SIGNAL( MethodInfo("about_to_show") ); diff --git a/scene/gui/popup.h b/scene/gui/popup.h index 17ae4a938a..4e4c8b0292 100644 --- a/scene/gui/popup.h +++ b/scene/gui/popup.h @@ -47,7 +47,7 @@ protected: void _gui_input(InputEvent p_event); void _notification(int p_what); - void _fix_size(); + virtual void _fix_size(); static void _bind_methods(); public: @@ -63,7 +63,7 @@ public: void popup_centered(const Size2& p_size=Size2()); void popup_centered_minsize(const Size2& p_minsize=Size2()); void set_as_minsize(); - virtual void popup(); + virtual void popup(const Rect2& p_bounds=Rect2()); virtual String get_configuration_warning() const; diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp index 1707676da2..fc25b68db9 100644 --- a/scene/gui/tab_container.cpp +++ b/scene/gui/tab_container.cpp @@ -371,6 +371,7 @@ void TabContainer::add_child_notify(Node *p_child) { //call_deferred("set_current_tab",0); first = true; current = 0; + previous = 0; } c->set_area_as_parent_rect(); if (tabs_visible) @@ -396,6 +397,7 @@ void TabContainer::set_current_tab(int p_current) { ERR_FAIL_INDEX(p_current, get_tab_count()); + int pending_previous = current; current = p_current; Ref<StyleBox> sb = get_stylebox("panel"); @@ -412,12 +414,21 @@ void TabContainer::set_current_tab(int p_current) { c->set_margin(Margin(i), c->get_margin(Margin(i)) + sb->get_margin(Margin(i))); - } else + } + else c->hide(); } _change_notify("current_tab"); - emit_signal("tab_changed", current); + + if (pending_previous == current) + emit_signal("tab_selected", current); + else { + previous = pending_previous; + emit_signal("tab_selected", current); + emit_signal("tab_changed", current); + } + update(); } @@ -426,6 +437,11 @@ int TabContainer::get_current_tab() const { return current; } +int TabContainer::get_previous_tab() const { + + return previous; +} + Control* TabContainer::get_tab_control(int p_idx) const { Vector<Control*> tabs = _get_tabs(); @@ -434,6 +450,7 @@ Control* TabContainer::get_tab_control(int p_idx) const { else return NULL; } + Control* TabContainer::get_current_tab_control() const { Vector<Control*> tabs = _get_tabs(); @@ -501,7 +518,6 @@ bool TabContainer::are_tabs_visible() const { } - Control *TabContainer::_get_tab(int p_idx) const { return get_tab_control(p_idx); @@ -551,6 +567,7 @@ void TabContainer::set_tab_disabled(int p_tab, bool p_enabled) { child->set_meta("_tab_disabled", p_enabled); update(); } + bool TabContainer::get_tab_disabled(int p_tab) const { Control *child = _get_tab(p_tab); @@ -578,7 +595,6 @@ void TabContainer::get_translatable_strings(List<String> *p_strings) const { } } - Size2 TabContainer::get_minimum_size() const { Size2 ms; @@ -620,13 +636,13 @@ Popup* TabContainer::get_popup() const { return popup; } - void TabContainer::_bind_methods() { ClassDB::bind_method(D_METHOD("_gui_input"), &TabContainer::_gui_input); ClassDB::bind_method(D_METHOD("get_tab_count"), &TabContainer::get_tab_count); ClassDB::bind_method(D_METHOD("set_current_tab", "tab_idx"), &TabContainer::set_current_tab); ClassDB::bind_method(D_METHOD("get_current_tab"), &TabContainer::get_current_tab); + ClassDB::bind_method(D_METHOD("get_previous_tab"), &TabContainer::get_previous_tab); ClassDB::bind_method(D_METHOD("get_current_tab_control:Control"), &TabContainer::get_current_tab_control); ClassDB::bind_method(D_METHOD("get_tab_control:Control", "idx"), &TabContainer::get_tab_control); ClassDB::bind_method(D_METHOD("set_tab_align", "align"), &TabContainer::set_tab_align); @@ -645,6 +661,7 @@ void TabContainer::_bind_methods() { ClassDB::bind_method(D_METHOD("_child_renamed_callback"), &TabContainer::_child_renamed_callback); ADD_SIGNAL(MethodInfo("tab_changed", PropertyInfo(Variant::INT, "tab"))); + ADD_SIGNAL(MethodInfo("tab_selected", PropertyInfo(Variant::INT, "tab"))); ADD_SIGNAL(MethodInfo("pre_popup_pressed")); ADD_PROPERTY(PropertyInfo(Variant::INT, "tab_align", PROPERTY_HINT_ENUM, "Left,Center,Right"), "set_tab_align", "get_tab_align"); @@ -659,6 +676,7 @@ TabContainer::TabContainer() { buttons_visible_cache = false; tabs_ofs_cache = 0; current = 0; + previous = 0; mouse_x_cache = 0; align = ALIGN_CENTER; tabs_visible = true; diff --git a/scene/gui/tab_container.h b/scene/gui/tab_container.h index 67f631f866..d5a2801bbe 100644 --- a/scene/gui/tab_container.h +++ b/scene/gui/tab_container.h @@ -50,6 +50,7 @@ private: int tabs_ofs_cache; int last_tab_cache; int current; + int previous; bool tabs_visible; bool buttons_visible_cache; TabAlign align; @@ -91,6 +92,7 @@ public: int get_tab_count() const; void set_current_tab(int p_current); int get_current_tab() const; + int get_previous_tab() const; Control* get_tab_control(int p_idx) const; Control* get_current_tab_control() const; diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index cd93c13c99..292efdcc01 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -848,7 +848,6 @@ void Tree::update_cache() { cache.title_button_color = get_color("title_button_color"); v_scroll->set_custom_step(cache.font->get_height()); - cache.click_item=get_selected(); } @@ -1611,6 +1610,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos,int x_ofs,int y_ofs,bool p_ cache.click_id=c.buttons[j].id; cache.click_item=p_item; cache.click_column=col; + cache.click_pos=get_global_mouse_pos()-get_global_pos(); update(); //emit_signal("button_pressed"); return -1; @@ -2391,6 +2391,8 @@ void Tree::_gui_input(InputEvent p_event) { if (cache.click_type==Cache::CLICK_BUTTON) { + // make sure in case of wrong reference after reconstructing whole TreeItems + cache.click_item=get_item_at_pos(cache.click_pos); emit_signal("button_pressed",cache.click_item,cache.click_column,cache.click_id); } @@ -2971,7 +2973,6 @@ void Tree::clear() { selected_item=NULL; edited_item=NULL; popup_edited_item=NULL; - selected_item=NULL; update(); }; diff --git a/scene/gui/tree.h b/scene/gui/tree.h index 351cc4cb50..14bd2efbaa 100644 --- a/scene/gui/tree.h +++ b/scene/gui/tree.h @@ -409,6 +409,7 @@ friend class TreeItem; TreeItem *click_item; int click_column; int hover_index; + Point2 click_pos; } cache; diff --git a/scene/main/scene_main_loop.cpp b/scene/main/scene_main_loop.cpp index 418eb92ee2..093359ab16 100644 --- a/scene/main/scene_main_loop.cpp +++ b/scene/main/scene_main_loop.cpp @@ -1803,6 +1803,10 @@ bool SceneTree::is_network_server() const { } +bool SceneTree::has_network_peer() const { + return network_peer.is_valid(); +} + int SceneTree::get_network_unique_id() const { ERR_FAIL_COND_V(!network_peer.is_valid(),0); @@ -2310,6 +2314,7 @@ void SceneTree::_bind_methods() { ClassDB::bind_method(D_METHOD("set_network_peer","peer:NetworkedMultiplayerPeer"),&SceneTree::set_network_peer); ClassDB::bind_method(D_METHOD("is_network_server"),&SceneTree::is_network_server); + ClassDB::bind_method(D_METHOD("has_network_peer"),&SceneTree::has_network_peer); ClassDB::bind_method(D_METHOD("get_network_unique_id"),&SceneTree::get_network_unique_id); ClassDB::bind_method(D_METHOD("set_refuse_new_network_connections","refuse"),&SceneTree::set_refuse_new_network_connections); ClassDB::bind_method(D_METHOD("is_refusing_new_network_connections"),&SceneTree::is_refusing_new_network_connections); diff --git a/scene/main/scene_main_loop.h b/scene/main/scene_main_loop.h index fec8534b40..7f69f5eef7 100644 --- a/scene/main/scene_main_loop.h +++ b/scene/main/scene_main_loop.h @@ -447,6 +447,7 @@ public: void set_network_peer(const Ref<NetworkedMultiplayerPeer>& p_network_peer); bool is_network_server() const; + bool has_network_peer() const; int get_network_unique_id() const; void set_refuse_new_network_connections(bool p_refuse); diff --git a/tools/editor/SCsub b/tools/editor/SCsub index 76eb65748a..c9b2392eb2 100644 --- a/tools/editor/SCsub +++ b/tools/editor/SCsub @@ -3,6 +3,8 @@ Import('env') env.editor_sources = [] +import os + def make_certs_header(target, source, env): @@ -29,11 +31,21 @@ def make_certs_header(target, source, env): def make_doc_header(target, source, env): - src = source[0].srcnode().abspath dst = target[0].srcnode().abspath - f = open(src, "rb") g = open(dst, "wb") - buf = f.read() + buf = "" + docbegin = "" + docend = "" + for s in source: + src = s.srcnode().abspath + f = open(src, "rb") + content = f.read() + buf += content[content.find("<class"): content.rfind("</doc>")] + if len(docbegin) == 0: + docbegin = content[0: content.find("<class")] + if len(docend) == 0: + docend = content[content.rfind("</doc>"): len(buf)] + buf = docbegin + buf + docend decomp_size = len(buf) import zlib buf = zlib.compress(buf) @@ -146,8 +158,15 @@ if (env["tools"] == "yes"): f.close() # API documentation - env.Depends("#tools/editor/doc_data_compressed.h", "#doc/base/classes.xml") - env.Command("#tools/editor/doc_data_compressed.h", "#doc/base/classes.xml", make_doc_header) + docs = ["#doc/base/classes.xml"] + moduledir = os.path.join(os.getcwd(), "..", "..", "modules") + for m in os.listdir(moduledir): + curmodle = os.path.join(moduledir, m) + docfile = os.path.join(curmodle, "classes.xml") + if os.path.isdir(curmodle) and os.path.isfile(docfile): + docs.append(docfile) + env.Depends("#tools/editor/doc_data_compressed.h", docs) + env.Command("#tools/editor/doc_data_compressed.h", docs, make_doc_header) # Certificates env.Depends("#tools/editor/certs_compressed.h", "#thirdparty/certs/ca-certificates.crt") diff --git a/tools/editor/doc/doc_data.cpp b/tools/editor/doc/doc_data.cpp index e0a4750862..47b8edfa04 100644 --- a/tools/editor/doc/doc_data.cpp +++ b/tools/editor/doc/doc_data.cpp @@ -158,6 +158,13 @@ void DocData::merge_from(const DocData& p_data) { } +void DocData::remove_from(const DocData &p_data) { + for(Map<String,ClassDoc>::Element* E=p_data.class_list.front(); E; E=E->next()) { + if(class_list.has(E->key())) + class_list.erase(E->key()); + } +} + void DocData::generate(bool p_basic_types) { diff --git a/tools/editor/doc/doc_data.h b/tools/editor/doc/doc_data.h index fead1da510..7601013979 100644 --- a/tools/editor/doc/doc_data.h +++ b/tools/editor/doc/doc_data.h @@ -98,6 +98,7 @@ public: public: void merge_from(const DocData& p_data); + void remove_from(const DocData& p_data); void generate(bool p_basic_types=false); Error load(const String& p_path); Error save(const String& p_path); diff --git a/tools/editor/multi_node_edit.cpp b/tools/editor/multi_node_edit.cpp index 27bb6d66fc..0428d7ef30 100644 --- a/tools/editor/multi_node_edit.cpp +++ b/tools/editor/multi_node_edit.cpp @@ -29,9 +29,15 @@ #include "multi_node_edit.h" #include "editor_node.h" +#include "core/helper/math_fieldwise.h" bool MultiNodeEdit::_set(const StringName& p_name, const Variant& p_value){ + return _set_impl(p_name, p_value, ""); +} + +bool MultiNodeEdit::_set_impl(const StringName& p_name, const Variant& p_value, const String& p_field) { + Node *es = EditorNode::get_singleton()->get_edited_scene(); if (!es) return false; @@ -59,7 +65,15 @@ bool MultiNodeEdit::_set(const StringName& p_name, const Variant& p_value){ NodePath p_path = n->get_path_to(tonode); ur->add_do_property(n,name,p_path); } else { - ur->add_do_property(n,name,p_value); + Variant new_value; + if (p_field=="") { + // whole value + new_value=p_value; + } else { + // only one field + new_value=fieldwise_assign(n->get(name),p_value,p_field); + } + ur->add_do_property(n,name,new_value); } ur->add_undo_property(n,name,n->get(name)); @@ -167,6 +181,11 @@ void MultiNodeEdit::add_node(const NodePath& p_node){ nodes.push_back(p_node); } +void MultiNodeEdit::set_property_field(const StringName& p_property, const Variant& p_value, const String& p_field) { + + _set_impl(p_property, p_value, p_field); +} + MultiNodeEdit::MultiNodeEdit() { } diff --git a/tools/editor/multi_node_edit.h b/tools/editor/multi_node_edit.h index 290c529d48..26e557c1cb 100644 --- a/tools/editor/multi_node_edit.h +++ b/tools/editor/multi_node_edit.h @@ -41,6 +41,8 @@ class MultiNodeEdit : public Reference { PropertyInfo info; }; + bool _set_impl(const StringName& p_name, const Variant& p_value, const String& p_field); + protected: @@ -55,6 +57,8 @@ public: void clear_nodes(); void add_node(const NodePath& p_node); + void set_property_field(const StringName& p_property, const Variant& p_value, const String& p_field); + MultiNodeEdit(); }; diff --git a/tools/editor/project_export.cpp b/tools/editor/project_export.cpp index f6593a4895..fc6d8793d8 100644 --- a/tools/editor/project_export.cpp +++ b/tools/editor/project_export.cpp @@ -46,10 +46,14 @@ void ProjectExportDialog::_notification(int p_what) { - if (p_what==NOTIFICATION_READY) { - delete_preset->set_icon(get_icon("Del","EditorIcons")); - connect("confirmed",this,"_export_pck_zip"); - + switch (p_what) { + case NOTIFICATION_READY: { + delete_preset->set_icon(get_icon("Del","EditorIcons")); + connect("confirmed",this,"_export_pck_zip"); + } break; + case NOTIFICATION_POPUP_HIDE: { + EditorSettings::get_singleton()->set("interface/dialogs/export_bounds", get_rect()); + } break; } } @@ -66,7 +70,13 @@ void ProjectExportDialog::popup_export() { } _update_presets(); - popup_centered_ratio(); + + // Restore valid window bounds or pop up at default size. + if (EditorSettings::get_singleton()->has("interface/dialogs/export_bounds")) { + popup(EditorSettings::get_singleton()->get("interface/dialogs/export_bounds")); + } else { + popup_centered_ratio(); + } } void ProjectExportDialog::_add_preset(int p_platform) { @@ -664,6 +674,9 @@ void ProjectExportDialog::_bind_methods() { } ProjectExportDialog::ProjectExportDialog() { + set_title(TTR("Export")); + set_resizable(true); + HBoxContainer *hbox = memnew( HBoxContainer ); add_child(hbox); diff --git a/tools/editor/project_settings.cpp b/tools/editor/project_settings.cpp index ed3c59cc4a..15019b8ca8 100644 --- a/tools/editor/project_settings.cpp +++ b/tools/editor/project_settings.cpp @@ -73,34 +73,38 @@ static const char* _axis_names[JOY_AXIS_MAX*2] = { void ProjectSettings::_notification(int p_what) { - if (p_what==NOTIFICATION_ENTER_TREE) { + switch (p_what) { + case NOTIFICATION_ENTER_TREE: { + globals_editor->edit(GlobalConfig::get_singleton()); - globals_editor->edit(GlobalConfig::get_singleton()); + search_button->set_icon(get_icon("Zoom","EditorIcons")); + clear_button->set_icon(get_icon("Close","EditorIcons")); - search_button->set_icon(get_icon("Zoom","EditorIcons")); - clear_button->set_icon(get_icon("Close","EditorIcons")); + translation_list->connect("button_pressed",this,"_translation_delete"); + _update_actions(); + popup_add->add_icon_item(get_icon("Keyboard","EditorIcons"),TTR("Key "),InputEvent::KEY);//"Key " - because the word 'key' has already been used as a key animation + popup_add->add_icon_item(get_icon("JoyButton","EditorIcons"),TTR("Joy Button"),InputEvent::JOYPAD_BUTTON); + popup_add->add_icon_item(get_icon("JoyAxis","EditorIcons"),TTR("Joy Axis"),InputEvent::JOYPAD_MOTION); + popup_add->add_icon_item(get_icon("Mouse","EditorIcons"),TTR("Mouse Button"),InputEvent::MOUSE_BUTTON); - translation_list->connect("button_pressed",this,"_translation_delete"); - _update_actions(); - popup_add->add_icon_item(get_icon("Keyboard","EditorIcons"),TTR("Key "),InputEvent::KEY);//"Key " - because the word 'key' has already been used as a key animation - popup_add->add_icon_item(get_icon("JoyButton","EditorIcons"),TTR("Joy Button"),InputEvent::JOYPAD_BUTTON); - popup_add->add_icon_item(get_icon("JoyAxis","EditorIcons"),TTR("Joy Axis"),InputEvent::JOYPAD_MOTION); - popup_add->add_icon_item(get_icon("Mouse","EditorIcons"),TTR("Mouse Button"),InputEvent::MOUSE_BUTTON); + List<String> tfn; + ResourceLoader::get_recognized_extensions_for_type("Translation",&tfn); + for (List<String>::Element *E=tfn.front();E;E=E->next()) { - List<String> tfn; - ResourceLoader::get_recognized_extensions_for_type("Translation",&tfn); - for (List<String>::Element *E=tfn.front();E;E=E->next()) { - - translation_file_open->add_filter("*."+E->get()); - } + translation_file_open->add_filter("*."+E->get()); + } - List<String> rfn; - ResourceLoader::get_recognized_extensions_for_type("Resource",&rfn); - for (List<String>::Element *E=rfn.front();E;E=E->next()) { + List<String> rfn; + ResourceLoader::get_recognized_extensions_for_type("Resource",&rfn); + for (List<String>::Element *E=rfn.front();E;E=E->next()) { - translation_res_file_open->add_filter("*."+E->get()); - translation_res_option_file_open->add_filter("*."+E->get()); - } + translation_res_file_open->add_filter("*."+E->get()); + translation_res_option_file_open->add_filter("*."+E->get()); + } + } break; + case NOTIFICATION_POPUP_HIDE: { + EditorSettings::get_singleton()->set("interface/dialogs/project_settings_bounds", get_rect()); + } break; } } @@ -579,8 +583,12 @@ void ProjectSettings::_update_actions() { void ProjectSettings::popup_project_settings() { - //popup_centered(Size2(500,400)); - popup_centered_ratio(); + // Restore valid window bounds or pop up at default size. + if (EditorSettings::get_singleton()->has("interface/dialogs/project_settings_bounds")) { + popup(EditorSettings::get_singleton()->get("interface/dialogs/project_settings_bounds")); + } else { + popup_centered_ratio(); + } globals_editor->update_category_list(); _update_translations(); autoload_settings->update_autoload(); @@ -1224,6 +1232,7 @@ ProjectSettings::ProjectSettings(EditorData *p_data) { singleton=this; set_title(TTR("Project Settings (godot.cfg)")); + set_resizable(true); undo_redo=&p_data->get_undo_redo(); data=p_data; diff --git a/tools/editor/property_editor.cpp b/tools/editor/property_editor.cpp index ec1de03bd6..533a5b156b 100644 --- a/tools/editor/property_editor.cpp +++ b/tools/editor/property_editor.cpp @@ -31,6 +31,8 @@ #include "scene/gui/label.h" #include "io/resource_loader.h" #include "io/image_loader.h" +#include "os/input.h" +#include "os/keyboard.h" #include "class_db.h" #include "print_string.h" #include "global_config.h" @@ -280,6 +282,7 @@ Variant CustomPropertyEditor::get_variant() const { return v; } + String CustomPropertyEditor::get_name() const { return name; @@ -291,6 +294,7 @@ bool CustomPropertyEditor::edit(Object* p_owner,const String& p_name,Variant::Ty updating=true; name=p_name; v=p_variant; + field_names.clear(); hint=p_hint; hint_text=p_hint_text; type_button->hide(); @@ -667,22 +671,20 @@ bool CustomPropertyEditor::edit(Object* p_owner,const String& p_name,Variant::Ty } break; case Variant::VECTOR2: { - List<String> names; - names.push_back("x"); - names.push_back("y"); - config_value_editors(2,2,10,names); + field_names.push_back("x"); + field_names.push_back("y"); + config_value_editors(2,2,10,field_names); Vector2 vec=v; value_editor[0]->set_text( String::num( vec.x) ); value_editor[1]->set_text( String::num( vec.y) ); } break; case Variant::RECT2: { - List<String> names; - names.push_back("x"); - names.push_back("y"); - names.push_back("w"); - names.push_back("h"); - config_value_editors(4,4,10,names); + field_names.push_back("x"); + field_names.push_back("y"); + field_names.push_back("w"); + field_names.push_back("h"); + config_value_editors(4,4,10,field_names); Rect2 r=v; value_editor[0]->set_text( String::num( r.pos.x) ); value_editor[1]->set_text( String::num( r.pos.y) ); @@ -691,11 +693,10 @@ bool CustomPropertyEditor::edit(Object* p_owner,const String& p_name,Variant::Ty } break; case Variant::VECTOR3: { - List<String> names; - names.push_back("x"); - names.push_back("y"); - names.push_back("z"); - config_value_editors(3,3,10,names); + field_names.push_back("x"); + field_names.push_back("y"); + field_names.push_back("z"); + config_value_editors(3,3,10,field_names); Vector3 vec=v; value_editor[0]->set_text( String::num( vec.x) ); value_editor[1]->set_text( String::num( vec.y) ); @@ -703,12 +704,11 @@ bool CustomPropertyEditor::edit(Object* p_owner,const String& p_name,Variant::Ty } break; case Variant::PLANE: { - List<String> names; - names.push_back("x"); - names.push_back("y"); - names.push_back("z"); - names.push_back("d"); - config_value_editors(4,4,10,names); + field_names.push_back("x"); + field_names.push_back("y"); + field_names.push_back("z"); + field_names.push_back("d"); + config_value_editors(4,4,10,field_names); Plane plane=v; value_editor[0]->set_text( String::num( plane.normal.x ) ); value_editor[1]->set_text( String::num( plane.normal.y ) ); @@ -718,12 +718,11 @@ bool CustomPropertyEditor::edit(Object* p_owner,const String& p_name,Variant::Ty } break; case Variant::QUAT: { - List<String> names; - names.push_back("x"); - names.push_back("y"); - names.push_back("z"); - names.push_back("w"); - config_value_editors(4,4,10,names); + field_names.push_back("x"); + field_names.push_back("y"); + field_names.push_back("z"); + field_names.push_back("w"); + config_value_editors(4,4,10,field_names); Quat q=v; value_editor[0]->set_text( String::num( q.x ) ); value_editor[1]->set_text( String::num( q.y ) ); @@ -733,14 +732,13 @@ bool CustomPropertyEditor::edit(Object* p_owner,const String& p_name,Variant::Ty } break; case Variant::RECT3: { - List<String> names; - names.push_back("px"); - names.push_back("py"); - names.push_back("pz"); - names.push_back("sx"); - names.push_back("sy"); - names.push_back("sz"); - config_value_editors(6,3,16,names); + field_names.push_back("px"); + field_names.push_back("py"); + field_names.push_back("pz"); + field_names.push_back("sx"); + field_names.push_back("sy"); + field_names.push_back("sz"); + config_value_editors(6,3,16,field_names); Rect3 aabb=v; value_editor[0]->set_text( String::num( aabb.pos.x ) ); @@ -753,14 +751,13 @@ bool CustomPropertyEditor::edit(Object* p_owner,const String& p_name,Variant::Ty } break; case Variant::TRANSFORM2D: { - List<String> names; - names.push_back("xx"); - names.push_back("xy"); - names.push_back("yx"); - names.push_back("yy"); - names.push_back("ox"); - names.push_back("oy"); - config_value_editors(6,2,16,names); + field_names.push_back("xx"); + field_names.push_back("xy"); + field_names.push_back("yx"); + field_names.push_back("yy"); + field_names.push_back("ox"); + field_names.push_back("oy"); + config_value_editors(6,2,16,field_names); Transform2D basis=v; for(int i=0;i<6;i++) { @@ -771,17 +768,16 @@ bool CustomPropertyEditor::edit(Object* p_owner,const String& p_name,Variant::Ty } break; case Variant::BASIS: { - List<String> names; - names.push_back("xx"); - names.push_back("xy"); - names.push_back("xz"); - names.push_back("yx"); - names.push_back("yy"); - names.push_back("yz"); - names.push_back("zx"); - names.push_back("zy"); - names.push_back("zz"); - config_value_editors(9,3,16,names); + field_names.push_back("xx"); + field_names.push_back("xy"); + field_names.push_back("xz"); + field_names.push_back("yx"); + field_names.push_back("yy"); + field_names.push_back("yz"); + field_names.push_back("zx"); + field_names.push_back("zy"); + field_names.push_back("zz"); + config_value_editors(9,3,16,field_names); Basis basis=v; for(int i=0;i<9;i++) { @@ -793,20 +789,19 @@ bool CustomPropertyEditor::edit(Object* p_owner,const String& p_name,Variant::Ty case Variant::TRANSFORM: { - List<String> names; - names.push_back("xx"); - names.push_back("xy"); - names.push_back("xz"); - names.push_back("xo"); - names.push_back("yx"); - names.push_back("yy"); - names.push_back("yz"); - names.push_back("yo"); - names.push_back("zx"); - names.push_back("zy"); - names.push_back("zz"); - names.push_back("zo"); - config_value_editors(12,4,16,names); + field_names.push_back("xx"); + field_names.push_back("xy"); + field_names.push_back("xz"); + field_names.push_back("xo"); + field_names.push_back("yx"); + field_names.push_back("yy"); + field_names.push_back("yz"); + field_names.push_back("yo"); + field_names.push_back("zx"); + field_names.push_back("zy"); + field_names.push_back("zz"); + field_names.push_back("zo"); + config_value_editors(12,4,16,field_names); Transform tr=v; for(int i=0;i<9;i++) { @@ -1050,6 +1045,14 @@ bool CustomPropertyEditor::edit(Object* p_owner,const String& p_name,Variant::Ty return true; } +////void CustomPropertyEditor::_save_properties_values(List<String> p_names) { +//// +//// field_names=p_names; +//// for (int i=0;i<p_names.size();i++) { +//// field_values.push_back(v.get(p_names[i])); +//// } +////} + void CustomPropertyEditor::_file_selected(String p_file) { switch(type) { @@ -1643,7 +1646,7 @@ void CustomPropertyEditor::_modified(String p_string) { vec.y=value_editor[1]->get_text().to_double(); } v=vec; - emit_signal("variant_changed"); + _emit_changed_whole_or_field(); } break; case Variant::RECT2: { @@ -1661,7 +1664,7 @@ void CustomPropertyEditor::_modified(String p_string) { r2.size.y=value_editor[3]->get_text().to_double(); } v=r2; - emit_signal("variant_changed"); + _emit_changed_whole_or_field(); } break; @@ -1678,7 +1681,7 @@ void CustomPropertyEditor::_modified(String p_string) { vec.z=value_editor[2]->get_text().to_double(); } v=vec; - emit_signal("variant_changed"); + _emit_changed_whole_or_field(); } break; case Variant::PLANE: { @@ -1696,7 +1699,7 @@ void CustomPropertyEditor::_modified(String p_string) { pl.d=value_editor[3]->get_text().to_double(); } v=pl; - emit_signal("variant_changed"); + _emit_changed_whole_or_field(); } break; case Variant::QUAT: { @@ -1714,7 +1717,7 @@ void CustomPropertyEditor::_modified(String p_string) { q.w=value_editor[3]->get_text().to_double(); } v=q; - emit_signal("variant_changed"); + _emit_changed_whole_or_field(); } break; case Variant::RECT3: { @@ -1738,7 +1741,7 @@ void CustomPropertyEditor::_modified(String p_string) { size.z=value_editor[5]->get_text().to_double(); } v=Rect3(pos,size); - emit_signal("variant_changed"); + _emit_changed_whole_or_field(); } break; case Variant::TRANSFORM2D: { @@ -1753,7 +1756,7 @@ void CustomPropertyEditor::_modified(String p_string) { } v=m; - emit_signal("variant_changed"); + _emit_changed_whole_or_field(); } break; case Variant::BASIS: { @@ -1769,7 +1772,7 @@ void CustomPropertyEditor::_modified(String p_string) { } v=m; - emit_signal("variant_changed"); + _emit_changed_whole_or_field(); } break; case Variant::TRANSFORM: { @@ -1797,7 +1800,7 @@ void CustomPropertyEditor::_modified(String p_string) { } v=Transform(basis,origin); - emit_signal("variant_changed"); + _emit_changed_whole_or_field(); } break; @@ -1864,6 +1867,15 @@ void CustomPropertyEditor::_modified(String p_string) { updating=false; } +void CustomPropertyEditor::_emit_changed_whole_or_field() { + + if (!Input::get_singleton()->is_key_pressed(KEY_SHIFT)) { + emit_signal("variant_changed"); + } else { + emit_signal("variant_field_changed",field_names[focused_value_editor]); + } +} + void CustomPropertyEditor::_range_modified(double p_value) { v=p_value; @@ -1885,6 +1897,7 @@ void CustomPropertyEditor::_focus_enter() { case Variant::TRANSFORM: { for (int i=0;i<MAX_VALUE_EDITORS;++i) { if (value_editor[i]->has_focus()) { + focused_value_editor=i; value_editor[i]->select_all(); break; } @@ -1997,6 +2010,7 @@ void CustomPropertyEditor::_bind_methods() { ADD_SIGNAL( MethodInfo("variant_changed") ); + ADD_SIGNAL( MethodInfo("variant_field_changed",PropertyInfo(Variant::STRING,"field")) ); ADD_SIGNAL( MethodInfo("resource_edit_request") ); } CustomPropertyEditor::CustomPropertyEditor() { @@ -2017,6 +2031,7 @@ CustomPropertyEditor::CustomPropertyEditor() { value_editor[i]->connect("focus_entered", this, "_focus_enter"); value_editor[i]->connect("focus_exited", this, "_focus_exit"); } + focused_value_editor=-1; for(int i=0;i<4;i++) { @@ -3904,7 +3919,7 @@ void PropertyEditor::_item_selected() { } -void PropertyEditor::_edit_set(const String& p_name, const Variant& p_value, bool p_refresh_all) { +void PropertyEditor::_edit_set(const String& p_name, const Variant& p_value, bool p_refresh_all, const String& p_changed_field) { if (autoclear) { TreeItem *item = tree->get_selected(); @@ -3914,7 +3929,7 @@ void PropertyEditor::_edit_set(const String& p_name, const Variant& p_value, boo } } - if (!undo_redo || obj->cast_to<MultiNodeEdit>() || obj->cast_to<ArrayPropertyEdit>()) { //kind of hacky + if (!undo_redo|| obj->cast_to<ArrayPropertyEdit>()) { //kind of hacky obj->set(p_name,p_value); if (p_refresh_all) @@ -3924,7 +3939,11 @@ void PropertyEditor::_edit_set(const String& p_name, const Variant& p_value, boo emit_signal(_prop_edited,p_name); + } else if (obj->cast_to<MultiNodeEdit>()) { + obj->cast_to<MultiNodeEdit>()->set_property_field(p_name,p_value,p_changed_field); + _changed_callbacks(obj,p_name); + emit_signal(_prop_edited,p_name); } else { undo_redo->create_action(TTR("Set")+" "+p_name,UndoRedo::MERGE_ENDS); @@ -4129,10 +4148,19 @@ void PropertyEditor::_custom_editor_edited() { if (!obj) return; - _edit_set(custom_editor->get_name(), custom_editor->get_variant()); } +void PropertyEditor::_custom_editor_edited_field(const String& p_field_name) { + + ERR_FAIL_COND(p_field_name==""); + + if (!obj) + return; + + _edit_set(custom_editor->get_name(), custom_editor->get_variant(), false, p_field_name); +} + void PropertyEditor::_custom_editor_request(bool p_arrow) { TreeItem * item = tree->get_edited(); @@ -4405,6 +4433,7 @@ void PropertyEditor::_bind_methods() { ClassDB::bind_method( "_item_selected",&PropertyEditor::_item_selected); ClassDB::bind_method( "_custom_editor_request",&PropertyEditor::_custom_editor_request); ClassDB::bind_method( "_custom_editor_edited",&PropertyEditor::_custom_editor_edited); + ClassDB::bind_method( "_custom_editor_edited_field",&PropertyEditor::_custom_editor_edited_field,DEFVAL("")); ClassDB::bind_method( "_resource_edit_request",&PropertyEditor::_resource_edit_request); ClassDB::bind_method( "_node_removed",&PropertyEditor::_node_removed); ClassDB::bind_method( "_edit_button",&PropertyEditor::_edit_button); @@ -4551,6 +4580,7 @@ PropertyEditor::PropertyEditor() { tree->connect("custom_popup_edited", this,"_custom_editor_request"); tree->connect("button_pressed", this,"_edit_button"); custom_editor->connect("variant_changed", this,"_custom_editor_edited"); + custom_editor->connect("variant_field_changed", this,"_custom_editor_edited_field"); custom_editor->connect("resource_edit_request", this,"_resource_edit_request",make_binds(),CONNECT_DEFERRED); tree->set_hide_folding(true); diff --git a/tools/editor/property_editor.h b/tools/editor/property_editor.h index 817b2716f0..e31a3313c1 100644 --- a/tools/editor/property_editor.h +++ b/tools/editor/property_editor.h @@ -88,9 +88,11 @@ class CustomPropertyEditor : public Popup { String name; Variant::Type type; Variant v; + List<String> field_names; int hint; String hint_text; LineEdit *value_editor[MAX_VALUE_EDITORS]; + int focused_value_editor; Label *value_label[MAX_VALUE_EDITORS]; HScrollBar *scroll[4]; Button *action_buttons[MAX_ACTION_BUTTONS]; @@ -141,6 +143,8 @@ class CustomPropertyEditor : public Popup { void config_value_editors(int p_amount, int p_columns,int p_label_w,const List<String>& p_strings); void config_action_buttons(const List<String>& p_strings); + void _emit_changed_whole_or_field(); + protected: @@ -204,6 +208,7 @@ class PropertyEditor : public Control { void _resource_edit_request(); void _custom_editor_edited(); + void _custom_editor_edited_field(const String& p_field_name); void _custom_editor_request(bool p_arrow); void _item_selected(); @@ -225,7 +230,7 @@ class PropertyEditor : public Control { void _node_removed(Node *p_node); friend class ProjectExportDialog; - void _edit_set(const String& p_name, const Variant& p_value,bool p_refresh_all=false); + void _edit_set(const String& p_name, const Variant& p_value,bool p_refresh_all=false, const String& p_changed_field=""); void _draw_flags(Object *ti,const Rect2& p_rect); bool _might_be_in_instance(); diff --git a/tools/editor/settings_config_dialog.cpp b/tools/editor/settings_config_dialog.cpp index 6a62e035ec..7d8d6ffcec 100644 --- a/tools/editor/settings_config_dialog.cpp +++ b/tools/editor/settings_config_dialog.cpp @@ -93,10 +93,14 @@ void EditorSettingsDialog::popup_edit_settings() { search_box->grab_focus(); _update_shortcuts(); - popup_centered_ratio(0.7); -} - + // Restore valid window bounds or pop up at default size. + if (EditorSettings::get_singleton()->has("interface/dialogs/editor_settings_bounds")) { + popup(EditorSettings::get_singleton()->get("interface/dialogs/editor_settings_bounds")); + } else { + popup_centered_ratio(0.7); + } +} void EditorSettingsDialog::_clear_search_box() { @@ -121,10 +125,14 @@ void EditorSettingsDialog::_filter_shortcuts(const String& p_filter) { void EditorSettingsDialog::_notification(int p_what) { - if (p_what==NOTIFICATION_ENTER_TREE) { - - clear_button->set_icon(get_icon("Close","EditorIcons")); - shortcut_clear_button->set_icon(get_icon("Close","EditorIcons")); + switch (p_what) { + case NOTIFICATION_ENTER_TREE: { + clear_button->set_icon(get_icon("Close", "EditorIcons")); + shortcut_clear_button->set_icon(get_icon("Close", "EditorIcons")); + } break; + case NOTIFICATION_POPUP_HIDE: { + EditorSettings::get_singleton()->set("interface/dialogs/editor_settings_bounds", get_rect()); + } break; } } @@ -305,6 +313,7 @@ void EditorSettingsDialog::_bind_methods() { EditorSettingsDialog::EditorSettingsDialog() { set_title(TTR("Editor Settings")); + set_resizable(true); tabs = memnew( TabContainer ); add_child(tabs); |