diff options
Diffstat (limited to 'core')
| -rw-r--r-- | core/bind/core_bind.cpp | 21 | ||||
| -rw-r--r-- | core/bind/core_bind.h | 5 | ||||
| -rw-r--r-- | core/os/os.cpp | 10 | ||||
| -rw-r--r-- | core/os/os.h | 6 | ||||
| -rw-r--r-- | core/os/power.h | 44 |
5 files changed, 86 insertions, 0 deletions
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index 79cfae0a3a..e4348cc406 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 ); } diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index 4241912ddd..b6aa873767 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(); 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_ */ |