summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/math/vector2.h4
-rw-r--r--core/math/vector2i.h22
-rw-r--r--doc/classes/Color.xml5
-rw-r--r--doc/classes/Tree.xml7
-rw-r--r--doc/classes/TreeItem.xml20
-rw-r--r--platform/iphone/godot_view.h5
-rw-r--r--platform/iphone/godot_view.mm8
-rw-r--r--platform/iphone/godot_view_gesture_recognizer.mm31
-rw-r--r--scene/gui/tree.cpp11
-rw-r--r--scene/gui/tree.h1
10 files changed, 86 insertions, 28 deletions
diff --git a/core/math/vector2.h b/core/math/vector2.h
index 123e3dc7b6..92ac5257b0 100644
--- a/core/math/vector2.h
+++ b/core/math/vector2.h
@@ -60,10 +60,10 @@ struct _NO_DISCARD_ Vector2 {
};
_FORCE_INLINE_ real_t &operator[](int p_idx) {
- return p_idx ? y : x;
+ return coord[p_idx];
}
_FORCE_INLINE_ const real_t &operator[](int p_idx) const {
- return p_idx ? y : x;
+ return coord[p_idx];
}
_FORCE_INLINE_ void set_all(const real_t p_value) {
diff --git a/core/math/vector2i.h b/core/math/vector2i.h
index 707c8c9490..3f5f12d4dd 100644
--- a/core/math/vector2i.h
+++ b/core/math/vector2i.h
@@ -43,19 +43,25 @@ struct _NO_DISCARD_ Vector2i {
};
union {
- int32_t x = 0;
- int32_t width;
- };
- union {
- int32_t y = 0;
- int32_t height;
+ struct {
+ union {
+ int32_t x;
+ int32_t width;
+ };
+ union {
+ int32_t y;
+ int32_t height;
+ };
+ };
+
+ int32_t coord[2] = { 0 };
};
_FORCE_INLINE_ int32_t &operator[](int p_idx) {
- return p_idx ? y : x;
+ return coord[p_idx];
}
_FORCE_INLINE_ const int32_t &operator[](int p_idx) const {
- return p_idx ? y : x;
+ return coord[p_idx];
}
_FORCE_INLINE_ Vector2i::Axis min_axis_index() const {
diff --git a/doc/classes/Color.xml b/doc/classes/Color.xml
index 4e73d4d9d8..8fd01509ec 100644
--- a/doc/classes/Color.xml
+++ b/doc/classes/Color.xml
@@ -221,14 +221,15 @@
Returns a new color from [code]rgba[/code], an HTML hexadecimal color string. [code]rgba[/code] is not case sensitive, and may be prefixed with a '#' character.
[code]rgba[/code] must be a valid three-digit or six-digit hexadecimal color string, and may contain an alpha channel value. If [code]rgba[/code] does not contain an alpha channel value, an alpha channel value of 1.0 is applied.
If [code]rgba[/code] is invalid a Color(0.0, 0.0, 0.0, 1.0) is returned.
+ [b]Note:[/b] This method is not implemented in C#, but the same functionality is provided in the class constructor.
[codeblocks]
[gdscript]
var green = Color.html("#00FF00FF") # set green to Color(0.0, 1.0, 0.0, 1.0)
var blue = Color.html("#0000FF") # set blue to Color(0.0, 0.0, 1.0, 1.0)
[/gdscript]
[csharp]
- var green = Color.Html("#00FF00FF"); // set green to Color(0.0, 1.0, 0.0, 1.0)
- var blue = Color.Html("#0000FF"); // set blue to Color(0.0, 0.0, 1.0, 1.0)
+ var green = new Color("#00FF00FF"); // set green to Color(0.0, 1.0, 0.0, 1.0)
+ var blue = new Color("#0000FF"); // set blue to Color(0.0, 0.0, 1.0, 1.0)
[/csharp]
[/codeblocks]
</description>
diff --git a/doc/classes/Tree.xml b/doc/classes/Tree.xml
index 4b051c4938..35a70ae53f 100644
--- a/doc/classes/Tree.xml
+++ b/doc/classes/Tree.xml
@@ -72,6 +72,13 @@
[b]Note:[/b] Despite the name of this method, the focus cursor itself is only visible in [constant SELECT_MULTI] mode.
</description>
</method>
+ <method name="get_button_id_at_position" qualifiers="const">
+ <return type="int" />
+ <argument index="0" name="position" type="Vector2" />
+ <description>
+ Returns the button id at [code]position[/code], or -1 if no button is there.
+ </description>
+ </method>
<method name="get_column_at_position" qualifiers="const">
<return type="int" />
<argument index="0" name="position" type="Vector2" />
diff --git a/doc/classes/TreeItem.xml b/doc/classes/TreeItem.xml
index 12c91cdd10..675c534e7b 100644
--- a/doc/classes/TreeItem.xml
+++ b/doc/classes/TreeItem.xml
@@ -14,11 +14,11 @@
<return type="void" />
<argument index="0" name="column" type="int" />
<argument index="1" name="button" type="Texture2D" />
- <argument index="2" name="button_idx" type="int" default="-1" />
+ <argument index="2" name="id" type="int" default="-1" />
<argument index="3" name="disabled" type="bool" default="false" />
<argument index="4" name="tooltip" type="String" default="&quot;&quot;" />
<description>
- Adds a button with [Texture2D] [code]button[/code] at column [code]column[/code]. The [code]button_idx[/code] index is used to identify the button when calling other methods. If not specified, the next available index is used, which may be retrieved by calling [method get_button_count] immediately after this method. Optionally, the button can be [code]disabled[/code] and have a [code]tooltip[/code].
+ Adds a button with [Texture2D] [code]button[/code] at column [code]column[/code]. The [code]id[/code] is used to identify the button. If not specified, the next available index is used, which may be retrieved by calling [method get_button_count] immediately after this method. Optionally, the button can be [code]disabled[/code] and have a [code]tooltip[/code].
</description>
</method>
<method name="call_recursive" qualifiers="vararg">
@@ -80,6 +80,14 @@
Returns the [Texture2D] of the button at index [code]button_idx[/code] in column [code]column[/code].
</description>
</method>
+ <method name="get_button_by_id" qualifiers="const">
+ <return type="int" />
+ <argument index="0" name="column" type="int" />
+ <argument index="1" name="id" type="int" />
+ <description>
+ Returns the button index if there is a button with id [code]id[/code] in column [code]column[/code], otherwise returns -1.
+ </description>
+ </method>
<method name="get_button_count" qualifiers="const">
<return type="int" />
<argument index="0" name="column" type="int" />
@@ -87,6 +95,14 @@
Returns the number of buttons in column [code]column[/code]. May be used to get the most recently added button's index, if no index was specified.
</description>
</method>
+ <method name="get_button_id" qualifiers="const">
+ <return type="int" />
+ <argument index="0" name="column" type="int" />
+ <argument index="1" name="button_idx" type="int" />
+ <description>
+ Returns the id for the button at index [code]button_idx[/code] in column [code]column[/code].
+ </description>
+ </method>
<method name="get_button_tooltip" qualifiers="const">
<return type="String" />
<argument index="0" name="column" type="int" />
diff --git a/platform/iphone/godot_view.h b/platform/iphone/godot_view.h
index 1c72a26b4a..fcb97fa63a 100644
--- a/platform/iphone/godot_view.h
+++ b/platform/iphone/godot_view.h
@@ -59,4 +59,9 @@ class String;
- (void)stopRendering;
- (void)startRendering;
+- (void)godotTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
+- (void)godotTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
+- (void)godotTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
+- (void)godotTouchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;
+
@end
diff --git a/platform/iphone/godot_view.mm b/platform/iphone/godot_view.mm
index b90c10fa84..ae92f32851 100644
--- a/platform/iphone/godot_view.mm
+++ b/platform/iphone/godot_view.mm
@@ -336,7 +336,7 @@ static const float earth_gravity = 9.80665;
}
}
-- (void)touchesBegan:(NSSet *)touchesSet withEvent:(UIEvent *)event {
+- (void)godotTouchesBegan:(NSSet *)touchesSet withEvent:(UIEvent *)event {
NSArray *tlist = [event.allTouches allObjects];
for (unsigned int i = 0; i < [tlist count]; i++) {
if ([touchesSet containsObject:[tlist objectAtIndex:i]]) {
@@ -349,7 +349,7 @@ static const float earth_gravity = 9.80665;
}
}
-- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
+- (void)godotTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
NSArray *tlist = [event.allTouches allObjects];
for (unsigned int i = 0; i < [tlist count]; i++) {
if ([touches containsObject:[tlist objectAtIndex:i]]) {
@@ -363,7 +363,7 @@ static const float earth_gravity = 9.80665;
}
}
-- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
+- (void)godotTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
NSArray *tlist = [event.allTouches allObjects];
for (unsigned int i = 0; i < [tlist count]; i++) {
if ([touches containsObject:[tlist objectAtIndex:i]]) {
@@ -377,7 +377,7 @@ static const float earth_gravity = 9.80665;
}
}
-- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
+- (void)godotTouchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
NSArray *tlist = [event.allTouches allObjects];
for (unsigned int i = 0; i < [tlist count]; i++) {
if ([touches containsObject:[tlist objectAtIndex:i]]) {
diff --git a/platform/iphone/godot_view_gesture_recognizer.mm b/platform/iphone/godot_view_gesture_recognizer.mm
index b50ba5f942..a46c42765a 100644
--- a/platform/iphone/godot_view_gesture_recognizer.mm
+++ b/platform/iphone/godot_view_gesture_recognizer.mm
@@ -29,6 +29,7 @@
/*************************************************************************/
#import "godot_view_gesture_recognizer.h"
+#import "godot_view.h"
#include "core/config/project_settings.h"
@@ -58,6 +59,10 @@ const CGFloat kGLGestureMovementDistance = 0.5;
@implementation GodotViewGestureRecognizer
+- (GodotView *)godotView {
+ return (GodotView *)self.view;
+}
+
- (instancetype)init {
self = [super init];
@@ -104,7 +109,7 @@ const CGFloat kGLGestureMovementDistance = 0.5;
self.delayTimer = nil;
if (self.delayedTouches) {
- [self.view touchesBegan:self.delayedTouches withEvent:self.delayedEvent];
+ [self.godotView godotTouchesBegan:self.delayedTouches withEvent:self.delayedEvent];
}
self.delayedTouches = nil;
@@ -114,6 +119,8 @@ const CGFloat kGLGestureMovementDistance = 0.5;
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSSet *cleared = [self copyClearedTouches:touches phase:UITouchPhaseBegan];
[self delayTouches:cleared andEvent:event];
+
+ [super touchesBegan:touches withEvent:event];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
@@ -123,8 +130,8 @@ const CGFloat kGLGestureMovementDistance = 0.5;
// We should check if movement was significant enough to fire an event
// for dragging to work correctly.
for (UITouch *touch in cleared) {
- CGPoint from = [touch locationInView:self.view];
- CGPoint to = [touch previousLocationInView:self.view];
+ CGPoint from = [touch locationInView:self.godotView];
+ CGPoint to = [touch previousLocationInView:self.godotView];
CGFloat xDistance = from.x - to.x;
CGFloat yDistance = from.y - to.y;
@@ -133,7 +140,7 @@ const CGFloat kGLGestureMovementDistance = 0.5;
// Early exit, since one of touches has moved enough to fire a drag event.
if (distance > kGLGestureMovementDistance) {
[self.delayTimer fire];
- [self.view touchesMoved:cleared withEvent:event];
+ [self.godotView godotTouchesMoved:cleared withEvent:event];
return;
}
}
@@ -141,26 +148,32 @@ const CGFloat kGLGestureMovementDistance = 0.5;
return;
}
- [self.view touchesMoved:cleared withEvent:event];
+ [self.godotView touchesMoved:cleared withEvent:event];
+
+ [super touchesMoved:touches withEvent:event];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[self.delayTimer fire];
NSSet *cleared = [self copyClearedTouches:touches phase:UITouchPhaseEnded];
- [self.view touchesEnded:cleared withEvent:event];
+ [self.godotView godotTouchesEnded:cleared withEvent:event];
+
+ [super touchesEnded:touches withEvent:event];
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
[self.delayTimer fire];
- [self.view touchesCancelled:touches withEvent:event];
-};
+ [self.godotView godotTouchesCancelled:touches withEvent:event];
+
+ [super touchesCancelled:touches withEvent:event];
+}
- (NSSet *)copyClearedTouches:(NSSet *)touches phase:(UITouchPhase)phaseToSave {
NSMutableSet *cleared = [touches mutableCopy];
for (UITouch *touch in touches) {
- if (touch.phase != phaseToSave) {
+ if (touch.view != self.view || touch.phase != phaseToSave) {
[cleared removeObject:touch];
}
}
diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp
index 9a6c87276f..a36eaaa0ee 100644
--- a/scene/gui/tree.cpp
+++ b/scene/gui/tree.cpp
@@ -905,6 +905,12 @@ String TreeItem::get_button_tooltip(int p_column, int p_idx) const {
return cells[p_column].buttons[p_idx].tooltip;
}
+int TreeItem::get_button_id(int p_column, int p_idx) const {
+ ERR_FAIL_INDEX_V(p_column, cells.size(), -1);
+ ERR_FAIL_INDEX_V(p_idx, cells[p_column].buttons.size(), -1);
+ return cells[p_column].buttons[p_idx].id;
+}
+
void TreeItem::erase_button(int p_column, int p_idx) {
ERR_FAIL_INDEX(p_column, cells.size());
ERR_FAIL_INDEX(p_idx, cells[p_column].buttons.size());
@@ -1283,9 +1289,11 @@ void TreeItem::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_custom_as_button", "column", "enable"), &TreeItem::set_custom_as_button);
ClassDB::bind_method(D_METHOD("is_custom_set_as_button", "column"), &TreeItem::is_custom_set_as_button);
- ClassDB::bind_method(D_METHOD("add_button", "column", "button", "button_idx", "disabled", "tooltip"), &TreeItem::add_button, DEFVAL(-1), DEFVAL(false), DEFVAL(""));
+ ClassDB::bind_method(D_METHOD("add_button", "column", "button", "id", "disabled", "tooltip"), &TreeItem::add_button, DEFVAL(-1), DEFVAL(false), DEFVAL(""));
ClassDB::bind_method(D_METHOD("get_button_count", "column"), &TreeItem::get_button_count);
ClassDB::bind_method(D_METHOD("get_button_tooltip", "column", "button_idx"), &TreeItem::get_button_tooltip);
+ ClassDB::bind_method(D_METHOD("get_button_id", "column", "button_idx"), &TreeItem::get_button_id);
+ ClassDB::bind_method(D_METHOD("get_button_by_id", "column", "id"), &TreeItem::get_button_by_id);
ClassDB::bind_method(D_METHOD("get_button", "column", "button_idx"), &TreeItem::get_button);
ClassDB::bind_method(D_METHOD("set_button", "column", "button_idx", "button"), &TreeItem::set_button);
ClassDB::bind_method(D_METHOD("erase_button", "column", "button_idx"), &TreeItem::erase_button);
@@ -4856,6 +4864,7 @@ void Tree::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_item_at_position", "position"), &Tree::get_item_at_position);
ClassDB::bind_method(D_METHOD("get_column_at_position", "position"), &Tree::get_column_at_position);
ClassDB::bind_method(D_METHOD("get_drop_section_at_position", "position"), &Tree::get_drop_section_at_position);
+ ClassDB::bind_method(D_METHOD("get_button_id_at_position", "position"), &Tree::get_button_id_at_position);
ClassDB::bind_method(D_METHOD("ensure_cursor_is_visible"), &Tree::ensure_cursor_is_visible);
diff --git a/scene/gui/tree.h b/scene/gui/tree.h
index 255a4f0576..dc786de6dc 100644
--- a/scene/gui/tree.h
+++ b/scene/gui/tree.h
@@ -248,6 +248,7 @@ public:
int get_button_count(int p_column) const;
String get_button_tooltip(int p_column, int p_idx) const;
Ref<Texture2D> get_button(int p_column, int p_idx) const;
+ int get_button_id(int p_column, int p_idx) const;
void erase_button(int p_column, int p_idx);
int get_button_by_id(int p_column, int p_id) const;
void set_button(int p_column, int p_idx, const Ref<Texture2D> &p_button);