diff options
Diffstat (limited to 'core/bind')
-rw-r--r-- | core/bind/core_bind.cpp | 151 | ||||
-rw-r--r-- | core/bind/core_bind.h | 41 |
2 files changed, 177 insertions, 15 deletions
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index addc26525e..4e815d044d 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -1,3 +1,31 @@ +/*************************************************************************/ +/* core_bind.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_bind.h" #include "os/os.h" #include "geometry.h" @@ -407,6 +435,18 @@ String _OS::get_locale() const { return OS::get_singleton()->get_locale(); } +String _OS::get_latin_keyboard_variant() const { + switch( OS::get_singleton()->get_latin_keyboard_variant() ) { + case OS::LATIN_KEYBOARD_QWERTY: return "QWERTY"; + case OS::LATIN_KEYBOARD_QWERTZ: return "QWERTZ"; + case OS::LATIN_KEYBOARD_AZERTY: return "AZERTY"; + case OS::LATIN_KEYBOARD_QZERTY: return "QZERTY"; + case OS::LATIN_KEYBOARD_DVORAK: return "DVORAK"; + case OS::LATIN_KEYBOARD_NEO : return "NEO"; + default: return "ERROR"; + } +} + String _OS::get_model_name() const { return OS::get_singleton()->get_model_name(); @@ -436,6 +476,15 @@ Error _OS::set_thread_name(const String& p_name) { return Thread::set_name(p_name); }; +void _OS::set_use_vsync(bool p_enable) { + OS::get_singleton()->set_use_vsync(p_enable); +} + +bool _OS::is_vsnc_enabled() const { + + return OS::get_singleton()->is_vsnc_enabled(); +} + /* enum Weekday { @@ -808,7 +857,6 @@ void _OS::print_all_textures_by_size() { for(List<_OSCoreBindImg>::Element *E=imgs.front();E;E=E->next()) { - print_line(E->get().path+" - "+String::humanize_size(E->get().vram)+" ("+E->get().size+") - total:"+String::humanize_size(total) ); total-=E->get().vram; } } @@ -842,23 +890,21 @@ void _OS::print_resources_by_type(const Vector<String>& p_types) { type_count[r->get_type()]++; - - print_line(r->get_type()+": "+r->get_path()); - - List<String> metas; - r->get_meta_list(&metas); - for (List<String>::Element* me = metas.front(); me; me = me->next()) { - print_line(" "+String(me->get()) + ": " + r->get_meta(me->get())); - }; } - for(Map<String,int>::Element *E=type_count.front();E;E=E->next()) { +}; - print_line(E->key()+" count: "+itos(E->get())); - } +bool _OS::has_virtual_keyboard() const { + return OS::get_singleton()->has_virtual_keyboard(); +} -}; +void _OS::show_virtual_keyboard(const String& p_existing_text) { + OS::get_singleton()->show_virtual_keyboard(p_existing_text, Rect2()); +} +void _OS::hide_virtual_keyboard() { + OS::get_singleton()->hide_virtual_keyboard(); +} void _OS::print_all_resources(const String& p_to_file ) { @@ -909,6 +955,11 @@ void _OS::native_video_stop() { OS::get_singleton()->native_video_stop(); }; +void _OS::request_attention() { + + OS::get_singleton()->request_attention(); +} + bool _OS::is_debug_build() const { #ifdef DEBUG_ENABLED @@ -967,6 +1018,11 @@ void _OS::alert(const String& p_alert,const String& p_title) { OS::get_singleton()->alert(p_alert,p_title); } +Dictionary _OS::get_engine_version() const { + + return OS::get_singleton()->get_engine_version(); +} + _OS *_OS::singleton=NULL; void _OS::_bind_methods() { @@ -1002,6 +1058,7 @@ void _OS::_bind_methods() { ObjectTypeDB::bind_method(_MD("is_window_minimized"),&_OS::is_window_minimized); ObjectTypeDB::bind_method(_MD("set_window_maximized", "enabled"),&_OS::set_window_maximized); ObjectTypeDB::bind_method(_MD("is_window_maximized"),&_OS::is_window_maximized); + ObjectTypeDB::bind_method(_MD("request_attention"), &_OS::request_attention); ObjectTypeDB::bind_method(_MD("set_borderless_window", "borderless"), &_OS::set_borderless_window); ObjectTypeDB::bind_method(_MD("get_borderless_window"), &_OS::get_borderless_window); @@ -1060,6 +1117,7 @@ void _OS::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_ticks_msec"),&_OS::get_ticks_msec); ObjectTypeDB::bind_method(_MD("get_splash_tick_msec"),&_OS::get_splash_tick_msec); ObjectTypeDB::bind_method(_MD("get_locale"),&_OS::get_locale); + ObjectTypeDB::bind_method(_MD("get_latin_keyboard_variant"),&_OS::get_latin_keyboard_variant); ObjectTypeDB::bind_method(_MD("get_model_name"),&_OS::get_model_name); ObjectTypeDB::bind_method(_MD("get_custom_level"),&_OS::get_custom_level); @@ -1076,6 +1134,9 @@ void _OS::_bind_methods() { ObjectTypeDB::bind_method(_MD("dump_memory_to_file","file"),&_OS::dump_memory_to_file); ObjectTypeDB::bind_method(_MD("dump_resources_to_file","file"),&_OS::dump_resources_to_file); + ObjectTypeDB::bind_method(_MD("has_virtual_keyboard"),&_OS::has_virtual_keyboard); + ObjectTypeDB::bind_method(_MD("show_virtual_keyboard", "existing_text"),&_OS::show_virtual_keyboard,DEFVAL("")); + ObjectTypeDB::bind_method(_MD("hide_virtual_keyboard"),&_OS::hide_virtual_keyboard); ObjectTypeDB::bind_method(_MD("print_resources_in_use","short"),&_OS::print_resources_in_use,DEFVAL(false)); ObjectTypeDB::bind_method(_MD("print_all_resources","tofile"),&_OS::print_all_resources,DEFVAL("")); @@ -1110,6 +1171,10 @@ void _OS::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_thread_name","name"),&_OS::set_thread_name); + ObjectTypeDB::bind_method(_MD("set_use_vsync","enable"),&_OS::set_use_vsync); + ObjectTypeDB::bind_method(_MD("is_vsnc_enabled"),&_OS::is_vsnc_enabled); + + ObjectTypeDB::bind_method(_MD("get_engine_version"),&_OS::get_engine_version); BIND_CONSTANT( DAY_SUNDAY ); BIND_CONSTANT( DAY_MONDAY ); @@ -1527,7 +1592,12 @@ DVector<uint8_t> _File::get_buffer(int p_length) const{ String _File::get_as_text() const { + ERR_FAIL_COND_V(!f, String()); + String text; + size_t original_pos = f->get_pos(); + f->seek(0); + String l = get_line(); while(!eof_reached()) { text+=l+"\n"; @@ -1535,6 +1605,8 @@ String _File::get_as_text() const { } text+=l; + f->seek(original_pos); + return text; @@ -1547,6 +1619,12 @@ String _File::get_md5(const String& p_path) const { } +String _File::get_sha256(const String& p_path) const { + + return FileAccess::get_sha256(p_path); + +} + String _File::get_line() const{ @@ -1737,6 +1815,7 @@ void _File::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_line"),&_File::get_line); ObjectTypeDB::bind_method(_MD("get_as_text"),&_File::get_as_text); ObjectTypeDB::bind_method(_MD("get_md5","path"),&_File::get_md5); + ObjectTypeDB::bind_method(_MD("get_sha256","path"),&_File::get_sha256); ObjectTypeDB::bind_method(_MD("get_endian_swap"),&_File::get_endian_swap); ObjectTypeDB::bind_method(_MD("set_endian_swap","enable"),&_File::set_endian_swap); ObjectTypeDB::bind_method(_MD("get_error:Error"),&_File::get_error); @@ -1845,29 +1924,57 @@ String _Directory::get_current_dir() { Error _Directory::make_dir(String p_dir){ ERR_FAIL_COND_V(!d,ERR_UNCONFIGURED); + if (!p_dir.is_rel_path()) { + DirAccess *d = DirAccess::create_for_path(p_dir); + Error err = d->make_dir(p_dir); + memdelete(d); + return err; + + } return d->make_dir(p_dir); } Error _Directory::make_dir_recursive(String p_dir){ ERR_FAIL_COND_V(!d,ERR_UNCONFIGURED); + if (!p_dir.is_rel_path()) { + DirAccess *d = DirAccess::create_for_path(p_dir); + Error err = d->make_dir_recursive(p_dir); + memdelete(d); + return err; + + } return d->make_dir_recursive(p_dir); } bool _Directory::file_exists(String p_file){ ERR_FAIL_COND_V(!d,false); + + if (!p_file.is_rel_path()) { + return FileAccess::exists(p_file); + } + return d->file_exists(p_file); } bool _Directory::dir_exists(String p_dir) { ERR_FAIL_COND_V(!d,false); - return d->dir_exists(p_dir); + if (!p_dir.is_rel_path()) { + + DirAccess *d = DirAccess::create_for_path(p_dir); + bool exists = d->dir_exists(p_dir); + memdelete(d); + return exists; + + } else { + return d->dir_exists(p_dir); + } } int _Directory::get_space_left(){ ERR_FAIL_COND_V(!d,0); - return d->get_space_left(); + return d->get_space_left()/1024*1024; //return value in megabytes, given binding is int } Error _Directory::copy(String p_from,String p_to){ @@ -1878,12 +1985,26 @@ Error _Directory::copy(String p_from,String p_to){ Error _Directory::rename(String p_from, String p_to){ ERR_FAIL_COND_V(!d,ERR_UNCONFIGURED); + if (!p_from.is_rel_path()) { + DirAccess *d = DirAccess::create_for_path(p_from); + Error err = d->rename(p_from,p_to); + memdelete(d); + return err; + } + return d->rename(p_from,p_to); } Error _Directory::remove(String p_name){ ERR_FAIL_COND_V(!d,ERR_UNCONFIGURED); + if (!p_name.is_rel_path()) { + DirAccess *d = DirAccess::create_for_path(p_name); + Error err = d->remove(p_name); + memdelete(d); + return err; + } + return d->remove(p_name); } diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index af89536c45..14203ae863 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -1,3 +1,31 @@ +/*************************************************************************/ +/* core_bind.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_BIND_H #define CORE_BIND_H @@ -130,6 +158,7 @@ public: virtual bool is_window_minimized() const; virtual void set_window_maximized(bool p_enabled); virtual bool is_window_maximized() const; + virtual void request_attention(); virtual void set_borderless_window(bool p_borderless); virtual bool get_borderless_window() const; @@ -164,6 +193,8 @@ public: Vector<String> get_cmdline_args(); String get_locale() const; + String get_latin_keyboard_variant() const; + String get_model_name() const; MainLoop *get_main_loop() const; @@ -174,6 +205,10 @@ public: void dump_memory_to_file(const String& p_file); void dump_resources_to_file(const String& p_file); + bool has_virtual_keyboard() const; + void show_virtual_keyboard(const String& p_existing_text=""); + void hide_virtual_keyboard(); + void print_resources_in_use(bool p_short=false); void print_all_resources(const String& p_to_file); void print_all_textures_by_size(); @@ -282,6 +317,11 @@ public: Error set_thread_name(const String& p_name); + void set_use_vsync(bool p_enable); + bool is_vsnc_enabled() const; + + Dictionary get_engine_version() const; + static _OS *get_singleton() { return singleton; } _OS(); @@ -377,6 +417,7 @@ public: String get_line() const; String get_as_text() const; String get_md5(const String& p_path) const; + String get_sha256(const String& p_path) const; /**< use this for files WRITTEN in _big_ endian machines (ie, amiga/mac) * It's not about the current CPU type but file formats. |