From 98b02209a438ddd4358eda58870100287c3924d1 Mon Sep 17 00:00:00 2001 From: George Marques Date: Thu, 23 Jun 2016 13:57:45 -0300 Subject: [PATCH 1/3] Add sha256_buffer() function to String --- core/ustring.cpp | 17 +++++++++++++++++ core/ustring.h | 1 + core/variant_call.cpp | 2 ++ 3 files changed, 20 insertions(+) diff --git a/core/ustring.cpp b/core/ustring.cpp index ea9a9d903e5..43e3a9a0bdd 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -2419,6 +2419,23 @@ Vector String::md5_buffer() const { return ret; }; +Vector String::sha256_buffer() const { + CharString cs = utf8(); + unsigned char hash[32]; + sha256_context ctx; + sha256_init(&ctx); + sha256_hash(&ctx, (unsigned char*)cs.ptr(), cs.length()); + sha256_done(&ctx, hash); + + Vector ret; + ret.resize(32); + for (int i = 0; i < 32; i++) { + ret[i] = hash[i]; + } + + return ret; +} + String String::insert(int p_at_pos,String p_string) const { diff --git a/core/ustring.h b/core/ustring.h index 692cb4e37d4..bb57b11d882 100644 --- a/core/ustring.h +++ b/core/ustring.h @@ -196,6 +196,7 @@ public: String md5_text() const; String sha256_text() const; Vector md5_buffer() const; + Vector sha256_buffer() const; inline bool empty() const { return length() == 0; } diff --git a/core/variant_call.cpp b/core/variant_call.cpp index 34e5164b242..c0f8930eedf 100644 --- a/core/variant_call.cpp +++ b/core/variant_call.cpp @@ -271,6 +271,7 @@ static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Var VCALL_LOCALMEM0R(String,md5_text); VCALL_LOCALMEM0R(String,sha256_text); VCALL_LOCALMEM0R(String,md5_buffer); + VCALL_LOCALMEM0R(String,sha256_buffer); VCALL_LOCALMEM0R(String,empty); VCALL_LOCALMEM0R(String,is_abs_path); VCALL_LOCALMEM0R(String,is_rel_path); @@ -1322,6 +1323,7 @@ _VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_SCS(#m_method),VCALL(m_cl ADDFUNC0(STRING,STRING,String,md5_text,varray()); ADDFUNC0(STRING,STRING,String,sha256_text,varray()); ADDFUNC0(STRING,RAW_ARRAY,String,md5_buffer,varray()); + ADDFUNC0(STRING,RAW_ARRAY,String,sha256_buffer,varray()); ADDFUNC0(STRING,BOOL,String,empty,varray()); ADDFUNC0(STRING,BOOL,String,is_abs_path,varray()); ADDFUNC0(STRING,BOOL,String,is_rel_path,varray()); From b06d235ce8634167cc1c37814f915e06ec0fa326 Mon Sep 17 00:00:00 2001 From: George Marques Date: Thu, 23 Jun 2016 17:59:28 -0300 Subject: [PATCH 2/3] Rename CanvasItem.edit_get() to edit_get_state() This makes more sense of what it does and correlates to edit_set_state() --- scene/2d/canvas_item.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp index eb37634b24c..976a5c4f1ed 100644 --- a/scene/2d/canvas_item.cpp +++ b/scene/2d/canvas_item.cpp @@ -1023,7 +1023,7 @@ void CanvasItem::_bind_methods() { ObjectTypeDB::bind_method(_MD("_is_visible_"),&CanvasItem::_is_visible_); ObjectTypeDB::bind_method(_MD("edit_set_state","state"),&CanvasItem::edit_set_state); - ObjectTypeDB::bind_method(_MD("edit_get"),&CanvasItem::edit_get_state); + ObjectTypeDB::bind_method(_MD("edit_get_state:Variant"),&CanvasItem::edit_get_state); ObjectTypeDB::bind_method(_MD("edit_set_rect","rect"),&CanvasItem::edit_set_rect); ObjectTypeDB::bind_method(_MD("edit_rotate","degrees"),&CanvasItem::edit_rotate); From 6776fa63de4d96f043c1e970ee366a865d46da27 Mon Sep 17 00:00:00 2001 From: George Marques Date: Thu, 23 Jun 2016 18:08:41 -0300 Subject: [PATCH 3/3] Add docs for String and CanvasItem --- doc/base/classes.xml | 78 ++++++++++++++++++++++++++++++++------------ 1 file changed, 58 insertions(+), 20 deletions(-) diff --git a/doc/base/classes.xml b/doc/base/classes.xml index 808bf20c25a..5ccc540422f 100644 --- a/doc/base/classes.xml +++ b/doc/base/classes.xml @@ -7059,8 +7059,11 @@ Draw a textured rectangle region at a given position, optionally modulated by a color. Transpose swaps the x and y coordinates when reading the texture. - + + + + Used for editing, returns an opaque value representing the transform state. @@ -7080,7 +7083,7 @@ - Used for editing, returns an opaque value representing the transform state. + Set the transform state of this CanvasItem. For [Node2D], this is an [Array] with (in order) a [Vector2] for position, a float for rotation and another [Vector2] for scale. For [Control] this is a [Rect2] with the position and size. @@ -7094,6 +7097,7 @@ + Return the [RID] of the [World2D] canvas where this item is in. @@ -7107,55 +7111,63 @@ + Get the transform matrix of this item's canvas. + Get the global position of the mouse. + Get the global transform matrix of this item. + Get the global transform matrix of this item in relation to the canvas. + Get a [Rect2] with the boundaries of this item and its children. - Return a rect containing the editable contents of the item. + Return a rect containing the editable boundaries of the item. + Get this item's light mask number. + Get the mouse position relative to this item's position. + Get the material of this item. @@ -7176,30 +7188,35 @@ + Get the transform matrix of this item. + Get whether this item uses its parent's material. + Get the viewport's boundaries as a [Rect2]. + Get this item's transform in relation to the viewport. + Get the [World2D] where this item is in. @@ -7241,13 +7258,14 @@ + Takes a global input event and convert to this item's coordinate system. - Set as toplevel. This means that it will not inherit transform from parent canvas items. + Set as top level. This means that it will not inherit transform from parent canvas items. @@ -7261,25 +7279,28 @@ - Sets whether the canvas item is drawn behind its parent. + Set whether the canvas item is drawn behind its parent. + Set whether this item should be hidden or not. Note that no matter what is set here this item won't be shown if its parent or grandparents nodes are also hidden. A hidden CanvasItem make all children hidden too. + Set the ligtht mask number of this item. + Set the material of this item. @@ -7300,6 +7321,7 @@ + Set whether or not this item should use its parent's material. @@ -7309,7 +7331,7 @@ - Queue the CanvasItem for update. NOTIFICATION_DRAW will be called on idle time to request redraw. + Queue the CanvasItem for update. [code]NOTIFICATION_DRAW[/code] will be called on idle time to request redraw. @@ -37540,12 +37562,14 @@ A similar effect may be achieved moving this node's descendants. + Return a copy of the string with special characters escaped using the C language standard. + Return a copy of the string with escaped characters replaced by their meanings according to the C language standard. @@ -37577,6 +37601,7 @@ A similar effect may be achieved moving this node's descendants. + Return true if the strings ends with the given string. @@ -37585,6 +37610,7 @@ A similar effect may be achieved moving this node's descendants. + Erase [code]chars[/code] characters from the string starting from [code]pos[/code]. @@ -37684,7 +37710,7 @@ A similar effect may be achieved moving this node's descendants. - Checked whether this string is a subsequence of the given string. + Check whether this string is a subsequence of the given string. @@ -37693,7 +37719,7 @@ A similar effect may be achieved moving this node's descendants. - Checked whether this string is a subsequence of the given string, without considering case. + Check whether this string is a subsequence of the given string, without considering case. @@ -37714,6 +37740,7 @@ A similar effect may be achieved moving this node's descendants. + Check whether the string is a valid identifier. As is common in programming languages, a valid identifier may contain only letters, digits and underscores (_) and the first character may not be a digit. @@ -37734,6 +37761,7 @@ A similar effect may be achieved moving this node's descendants. + Return a copy of the string with special characters escaped using the JSON standard. @@ -37774,12 +37802,14 @@ A similar effect may be achieved moving this node's descendants. + Return the MD5 hash of the string as an array of bytes. + Return the MD5 hash of the string as a string. @@ -37797,7 +37827,7 @@ A similar effect may be achieved moving this node's descendants. - Return the character code at position "at". + Return the character code at position [code]at[/code]. @@ -37806,6 +37836,7 @@ A similar effect may be achieved moving this node's descendants. + Format a number to have an exact number of [code]digits[/code] after the decimal point. @@ -37814,18 +37845,21 @@ A similar effect may be achieved moving this node's descendants. + Format a number to have an exact number of [code]digits[/code] before the decimal point. + Decode a percent-encoded string. See [method percent_encode]. + Percent-encode a string. This is meant to encode parameters in a URL when sending a HTTP GET request and bodies of form-urlencoded POST request. @@ -37834,6 +37868,7 @@ A similar effect may be achieved moving this node's descendants. + If the string is a path, this concatenates [code]file[/code] at the end of the string as a subpath. E.g. [code]"this/is".plus_file("path") == "this/is/path"[/code]. @@ -37889,10 +37924,17 @@ A similar effect may be achieved moving this node's descendants. Return the right side of the string from a given position. + + + + + + + Return the SHA-256 hash of the string as a string. @@ -37912,7 +37954,7 @@ A similar effect may be achieved moving this node's descendants. - Split the string by a divisor string, return an array of the substrings. Example "One,Two,Three" will return \["One","Two","Three"\] if split by ",". + Split the string by a divisor string, return an array of the substrings. Example "One,Two,Three" will return ["One","Two","Three"] if split by ",". @@ -37923,7 +37965,7 @@ A similar effect may be achieved moving this node's descendants. - Split the string in floats by using a divisor string, return an array of the substrings. Example "1,2.5,3" will return \[1,2.5,3\] if split by ",". + Split the string in floats by using a divisor string, return an array of the substrings. Example "1,2.5,3" will return [1,2.5,3] if split by ",". @@ -37945,7 +37987,7 @@ A similar effect may be achieved moving this node's descendants. - Return part of the string from "from", with length "len". + Return part of the string from the position [code]from[/code], with length [code]len[/code]. @@ -37959,14 +38001,14 @@ A similar effect may be achieved moving this node's descendants. - Convert a string, containing a decimal number, into a float. + Convert a string, containing a decimal number, into a [code]float[/code]. - Convert a string, containing an integer number, into an int. + Convert a string, containing an integer number, into an [code]int[/code]. @@ -37994,14 +38036,14 @@ A similar effect may be achieved moving this node's descendants. - Perform XML escaping on the string. + Return a copy of the string with special characters escaped using the XML standard. - Perform XML un-escaping of the string. + Return a copy of the string with escaped characters replaced by their meanings according to the XML standard. @@ -39262,8 +39304,6 @@ A similar effect may be achieved moving this node's descendants. - - @@ -39272,8 +39312,6 @@ A similar effect may be achieved moving this node's descendants. - -