summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/image.cpp60
-rw-r--r--core/image.h1
-rw-r--r--core/translation.cpp16
-rw-r--r--core/translation.h4
-rw-r--r--core/ustring.cpp11
-rw-r--r--core/ustring.h2
6 files changed, 94 insertions, 0 deletions
diff --git a/core/image.cpp b/core/image.cpp
index 52946bbb85..8635aa1b29 100644
--- a/core/image.cpp
+++ b/core/image.cpp
@@ -901,6 +901,66 @@ static void _generate_po2_mipmap(const uint8_t* p_src, uint8_t* p_dst, uint32_t
}
+void Image::shrink_x2() {
+
+ ERR_FAIL_COND(format==FORMAT_INDEXED || format==FORMAT_INDEXED_ALPHA);
+ ERR_FAIL_COND( data.size()==0 );
+
+
+
+ if (mipmaps) {
+
+ //just use the lower mipmap as base and copy all
+ DVector<uint8_t> new_img;
+
+ int ofs = get_mipmap_offset(1);
+
+ int new_size = data.size()-ofs;
+ new_img.resize(new_size);
+
+
+ {
+ DVector<uint8_t>::Write w=new_img.write();
+ DVector<uint8_t>::Read r=data.read();
+
+ copymem(w.ptr(),&r[ofs],new_size);
+ }
+
+ mipmaps--;
+ width/=2;
+ height/=2;
+ data=new_img;
+
+ } else {
+
+ DVector<uint8_t> new_img;
+
+ ERR_FAIL_COND( format>=FORMAT_INDEXED );
+ int ps = get_format_pixel_size(format);
+ new_img.resize((width/2)*(height/2)*ps);
+
+ {
+ DVector<uint8_t>::Write w=new_img.write();
+ DVector<uint8_t>::Read r=data.read();
+
+ switch(format) {
+
+ case FORMAT_GRAYSCALE:
+ case FORMAT_INTENSITY: _generate_po2_mipmap<1>(r.ptr(), w.ptr(), width,height); break;
+ case FORMAT_GRAYSCALE_ALPHA: _generate_po2_mipmap<2>(r.ptr(), w.ptr(), width,height); break;
+ case FORMAT_RGB: _generate_po2_mipmap<3>(r.ptr(), w.ptr(), width,height); break;
+ case FORMAT_RGBA: _generate_po2_mipmap<4>(r.ptr(), w.ptr(), width,height); break;
+ default: {}
+ }
+ }
+
+ width/=2;
+ height/=2;
+ data=new_img;
+
+ }
+}
+
Error Image::generate_mipmaps(int p_mipmaps,bool p_keep_existing) {
if (!_can_modify(format)) {
diff --git a/core/image.h b/core/image.h
index fe1822f661..35bbd1a684 100644
--- a/core/image.h
+++ b/core/image.h
@@ -249,6 +249,7 @@ public:
void resize_to_po2(bool p_square=false);
void resize( int p_width, int p_height, Interpolation p_interpolation=INTERPOLATE_BILINEAR );
Image resized( int p_width, int p_height, int p_interpolation=INTERPOLATE_BILINEAR );
+ void shrink_x2();
/**
* Crop the image to a specific size, if larger, then the image is filled by black
*/
diff --git a/core/translation.cpp b/core/translation.cpp
index e4dad8d8de..85e207e08d 100644
--- a/core/translation.cpp
+++ b/core/translation.cpp
@@ -665,6 +665,22 @@ void TranslationServer::setup() {
}
+void TranslationServer::set_tool_translation(const Ref<Translation>& p_translation) {
+ tool_translation=p_translation;
+}
+
+StringName TranslationServer::tool_translate(const StringName& p_message) const {
+
+ if (tool_translation.is_valid()) {
+ StringName r = tool_translation->tr(p_message);
+ if (r)
+ return r;
+ }
+
+ return p_message;
+}
+
+
void TranslationServer::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_locale","locale"),&TranslationServer::set_locale);
diff --git a/core/translation.h b/core/translation.h
index 5be6b8913a..cdb22bfeca 100644
--- a/core/translation.h
+++ b/core/translation.h
@@ -75,6 +75,7 @@ class TranslationServer : public Object {
Set< Ref<Translation> > translations;
+ Ref<Translation> tool_translation;
bool enabled;
@@ -102,6 +103,9 @@ public:
static Vector<String> get_all_locales();
static Vector<String> get_all_locale_names();
+ void set_tool_translation(const Ref<Translation>& p_translation);
+ StringName tool_translate(const StringName& p_message) const;
+
void setup();
void clear();
diff --git a/core/ustring.cpp b/core/ustring.cpp
index a9d0012ebe..573c362389 100644
--- a/core/ustring.cpp
+++ b/core/ustring.cpp
@@ -3955,3 +3955,14 @@ String String::sprintf(const Array& values, bool* error) const {
*error = false;
return formatted;
}
+
+#include "translation.h"
+
+String TTR(const String& p_text) {
+
+ if (TranslationServer::get_singleton()) {
+ return TranslationServer::get_singleton()->translate(p_text);
+ }
+
+ return p_text;
+}
diff --git a/core/ustring.h b/core/ustring.h
index 6310d0a854..ec0932e54d 100644
--- a/core/ustring.h
+++ b/core/ustring.h
@@ -256,5 +256,7 @@ struct NoCaseComparator {
/* end of namespace */
+//tool translate
+String TTR(const String&);
#endif