2014-02-10 02:10:30 +01:00
/*************************************************************************/
/* tree.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
2017-08-27 14:16:55 +02:00
/* https://godotengine.org */
2014-02-10 02:10:30 +01:00
/*************************************************************************/
2020-01-01 11:16:22 +01:00
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
2014-02-10 02:10:30 +01:00
/* */
/* 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. */
/*************************************************************************/
2018-01-05 00:50:27 +01:00
2014-02-10 02:10:30 +01:00
# include "tree.h"
2017-08-27 21:07:15 +02:00
2020-03-04 17:36:09 +01:00
# include "core/input/input_filter.h"
2018-09-11 18:13:45 +02:00
# include "core/math/math_funcs.h"
# include "core/os/keyboard.h"
# include "core/os/os.h"
# include "core/print_string.h"
# include "core/project_settings.h"
2020-03-04 02:51:12 +01:00
# include "scene/main/window.h"
2014-02-10 02:10:30 +01:00
2020-03-20 03:32:09 +01:00
# include "box_container.h"
2017-12-15 18:40:45 +01:00
# ifdef TOOLS_ENABLED
2019-06-12 22:35:35 +02:00
# include "editor/editor_scale.h"
2017-12-15 18:40:45 +01:00
# endif
2019-04-05 14:06:16 +02:00
# include <limits.h>
2014-02-10 02:10:30 +01:00
void TreeItem : : move_to_top ( ) {
2018-01-18 21:37:17 +01:00
if ( ! parent | | parent - > children = = this )
2014-02-10 02:10:30 +01:00
return ; //already on top
TreeItem * prev = get_prev ( ) ;
2017-03-05 16:44:50 +01:00
prev - > next = next ;
2018-01-18 21:37:17 +01:00
next = parent - > children ;
parent - > children = this ;
2014-02-10 02:10:30 +01:00
}
void TreeItem : : move_to_bottom ( ) {
if ( ! parent | | ! next )
return ;
2017-10-11 22:30:46 +02:00
TreeItem * prev = get_prev ( ) ;
TreeItem * last = next ;
while ( last - > next )
last = last - > next ;
2014-02-10 02:10:30 +01:00
2017-10-11 22:30:46 +02:00
if ( prev ) {
prev - > next = next ;
} else {
2018-01-18 21:37:17 +01:00
parent - > children = next ;
2014-02-10 02:10:30 +01:00
}
2017-10-11 22:30:46 +02:00
last - > next = this ;
2020-04-02 01:20:12 +02:00
next = nullptr ;
2014-02-10 02:10:30 +01:00
}
Size2 TreeItem : : Cell : : get_icon_size ( ) const {
if ( icon . is_null ( ) )
return Size2 ( ) ;
2017-03-05 16:44:50 +01:00
if ( icon_region = = Rect2i ( ) )
2014-02-10 02:10:30 +01:00
return icon - > get_size ( ) ;
else
return icon_region . size ;
}
2015-08-29 06:43:21 +02:00
2017-07-19 22:00:46 +02:00
void TreeItem : : Cell : : draw_icon ( const RID & p_where , const Point2 & p_pos , const Size2 & p_size , const Color & p_color ) const {
2014-02-10 02:10:30 +01:00
if ( icon . is_null ( ) )
return ;
2017-03-05 16:44:50 +01:00
Size2i dsize = ( p_size = = Size2 ( ) ) ? icon - > get_size ( ) : p_size ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
if ( icon_region = = Rect2i ( ) ) {
2014-02-10 02:10:30 +01:00
2017-07-19 22:00:46 +02:00
icon - > draw_rect_region ( p_where , Rect2 ( p_pos , dsize ) , Rect2 ( Point2 ( ) , icon - > get_size ( ) ) , p_color ) ;
2014-02-10 02:10:30 +01:00
} else {
2017-07-19 22:00:46 +02:00
icon - > draw_rect_region ( p_where , Rect2 ( p_pos , dsize ) , icon_region , p_color ) ;
2014-02-10 02:10:30 +01:00
}
}
void TreeItem : : _changed_notify ( int p_cell ) {
2017-03-05 16:44:50 +01:00
tree - > item_changed ( p_cell , this ) ;
2014-02-10 02:10:30 +01:00
}
void TreeItem : : _changed_notify ( ) {
2017-03-05 16:44:50 +01:00
tree - > item_changed ( - 1 , this ) ;
2014-02-10 02:10:30 +01:00
}
void TreeItem : : _cell_selected ( int p_cell ) {
2017-03-05 16:44:50 +01:00
tree - > item_selected ( p_cell , this ) ;
2014-02-10 02:10:30 +01:00
}
void TreeItem : : _cell_deselected ( int p_cell ) {
2017-03-05 16:44:50 +01:00
tree - > item_deselected ( p_cell , this ) ;
2014-02-10 02:10:30 +01:00
}
/* cell mode */
2017-03-05 16:44:50 +01:00
void TreeItem : : set_cell_mode ( int p_column , TreeCellMode p_mode ) {
ERR_FAIL_INDEX ( p_column , cells . size ( ) ) ;
2018-07-25 03:11:03 +02:00
Cell & c = cells . write [ p_column ] ;
2017-03-05 16:44:50 +01:00
c . mode = p_mode ;
c . min = 0 ;
c . max = 100 ;
c . step = 1 ;
c . val = 0 ;
c . checked = false ;
2019-06-11 20:43:37 +02:00
c . icon = Ref < Texture2D > ( ) ;
2017-03-05 16:44:50 +01:00
c . text = " " ;
c . icon_max_w = 0 ;
2014-02-10 02:10:30 +01:00
_changed_notify ( p_column ) ;
}
2017-03-05 16:44:50 +01:00
TreeItem : : TreeCellMode TreeItem : : get_cell_mode ( int p_column ) const {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
ERR_FAIL_INDEX_V ( p_column , cells . size ( ) , TreeItem : : CELL_MODE_STRING ) ;
2014-02-10 02:10:30 +01:00
return cells [ p_column ] . mode ;
}
/* check mode */
2017-03-05 16:44:50 +01:00
void TreeItem : : set_checked ( int p_column , bool p_checked ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
ERR_FAIL_INDEX ( p_column , cells . size ( ) ) ;
2018-07-25 03:11:03 +02:00
cells . write [ p_column ] . checked = p_checked ;
2014-02-10 02:10:30 +01:00
_changed_notify ( p_column ) ;
}
bool TreeItem : : is_checked ( int p_column ) const {
2017-03-05 16:44:50 +01:00
ERR_FAIL_INDEX_V ( p_column , cells . size ( ) , false ) ;
2014-02-10 02:10:30 +01:00
return cells [ p_column ] . checked ;
}
2017-03-05 16:44:50 +01:00
void TreeItem : : set_text ( int p_column , String p_text ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
ERR_FAIL_INDEX ( p_column , cells . size ( ) ) ;
2018-07-25 03:11:03 +02:00
cells . write [ p_column ] . text = p_text ;
2014-02-10 02:10:30 +01:00
2018-09-22 22:31:56 +02:00
if ( cells [ p_column ] . mode = = TreeItem : : CELL_MODE_RANGE ) {
2015-08-31 00:37:23 +02:00
2017-11-15 19:50:37 +01:00
Vector < String > strings = p_text . split ( " , " ) ;
2018-07-25 03:11:03 +02:00
cells . write [ p_column ] . min = INT_MAX ;
cells . write [ p_column ] . max = INT_MIN ;
2017-11-15 19:50:37 +01:00
for ( int i = 0 ; i < strings . size ( ) ; i + + ) {
int value = i ;
if ( ! strings [ i ] . get_slicec ( ' : ' , 1 ) . empty ( ) ) {
value = strings [ i ] . get_slicec ( ' : ' , 1 ) . to_int ( ) ;
}
2018-07-25 03:11:03 +02:00
cells . write [ p_column ] . min = MIN ( cells [ p_column ] . min , value ) ;
cells . write [ p_column ] . max = MAX ( cells [ p_column ] . max , value ) ;
2017-11-15 19:50:37 +01:00
}
2018-07-25 03:11:03 +02:00
cells . write [ p_column ] . step = 0 ;
2014-02-10 02:10:30 +01:00
}
_changed_notify ( p_column ) ;
}
String TreeItem : : get_text ( int p_column ) const {
2017-03-05 16:44:50 +01:00
ERR_FAIL_INDEX_V ( p_column , cells . size ( ) , " " ) ;
2014-02-10 02:10:30 +01:00
return cells [ p_column ] . text ;
}
2017-03-05 16:44:50 +01:00
void TreeItem : : set_suffix ( int p_column , String p_suffix ) {
2016-08-31 04:44:14 +02:00
2017-03-05 16:44:50 +01:00
ERR_FAIL_INDEX ( p_column , cells . size ( ) ) ;
2018-07-25 03:11:03 +02:00
cells . write [ p_column ] . suffix = p_suffix ;
2016-08-31 04:44:14 +02:00
_changed_notify ( p_column ) ;
}
String TreeItem : : get_suffix ( int p_column ) const {
2017-03-05 16:44:50 +01:00
ERR_FAIL_INDEX_V ( p_column , cells . size ( ) , " " ) ;
2016-08-31 04:44:14 +02:00
return cells [ p_column ] . suffix ;
}
2014-02-10 02:10:30 +01:00
2019-06-11 20:43:37 +02:00
void TreeItem : : set_icon ( int p_column , const Ref < Texture2D > & p_icon ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
ERR_FAIL_INDEX ( p_column , cells . size ( ) ) ;
2018-07-25 03:11:03 +02:00
cells . write [ p_column ] . icon = p_icon ;
2014-02-10 02:10:30 +01:00
_changed_notify ( p_column ) ;
}
2019-06-11 20:43:37 +02:00
Ref < Texture2D > TreeItem : : get_icon ( int p_column ) const {
2014-02-10 02:10:30 +01:00
2019-06-11 20:43:37 +02:00
ERR_FAIL_INDEX_V ( p_column , cells . size ( ) , Ref < Texture2D > ( ) ) ;
2014-02-10 02:10:30 +01:00
return cells [ p_column ] . icon ;
}
2017-03-05 16:44:50 +01:00
void TreeItem : : set_icon_region ( int p_column , const Rect2 & p_icon_region ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
ERR_FAIL_INDEX ( p_column , cells . size ( ) ) ;
2018-07-25 03:11:03 +02:00
cells . write [ p_column ] . icon_region = p_icon_region ;
2014-02-10 02:10:30 +01:00
_changed_notify ( p_column ) ;
}
Rect2 TreeItem : : get_icon_region ( int p_column ) const {
2017-03-05 16:44:50 +01:00
ERR_FAIL_INDEX_V ( p_column , cells . size ( ) , Rect2 ( ) ) ;
2014-02-10 02:10:30 +01:00
return cells [ p_column ] . icon_region ;
}
2019-08-24 17:13:48 +02:00
void TreeItem : : set_icon_modulate ( int p_column , const Color & p_modulate ) {
2017-07-19 22:00:46 +02:00
ERR_FAIL_INDEX ( p_column , cells . size ( ) ) ;
2019-08-24 17:13:48 +02:00
cells . write [ p_column ] . icon_color = p_modulate ;
2017-07-19 22:00:46 +02:00
_changed_notify ( p_column ) ;
}
2019-08-24 17:13:48 +02:00
Color TreeItem : : get_icon_modulate ( int p_column ) const {
2017-07-19 22:00:46 +02:00
ERR_FAIL_INDEX_V ( p_column , cells . size ( ) , Color ( ) ) ;
return cells [ p_column ] . icon_color ;
}
2017-03-05 16:44:50 +01:00
void TreeItem : : set_icon_max_width ( int p_column , int p_max ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
ERR_FAIL_INDEX ( p_column , cells . size ( ) ) ;
2018-07-25 03:11:03 +02:00
cells . write [ p_column ] . icon_max_w = p_max ;
2014-02-10 02:10:30 +01:00
_changed_notify ( p_column ) ;
}
int TreeItem : : get_icon_max_width ( int p_column ) const {
2017-03-05 16:44:50 +01:00
ERR_FAIL_INDEX_V ( p_column , cells . size ( ) , 0 ) ;
2014-02-10 02:10:30 +01:00
return cells [ p_column ] . icon_max_w ;
}
/* range works for mode number or mode combo */
2017-03-05 16:44:50 +01:00
void TreeItem : : set_range ( int p_column , double p_value ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
ERR_FAIL_INDEX ( p_column , cells . size ( ) ) ;
if ( cells [ p_column ] . step > 0 )
p_value = Math : : stepify ( p_value , cells [ p_column ] . step ) ;
if ( p_value < cells [ p_column ] . min )
p_value = cells [ p_column ] . min ;
if ( p_value > cells [ p_column ] . max )
p_value = cells [ p_column ] . max ;
2015-08-31 00:37:23 +02:00
2018-07-25 03:11:03 +02:00
cells . write [ p_column ] . val = p_value ;
2014-02-10 02:10:30 +01:00
_changed_notify ( p_column ) ;
}
double TreeItem : : get_range ( int p_column ) const {
2017-03-05 16:44:50 +01:00
ERR_FAIL_INDEX_V ( p_column , cells . size ( ) , 0 ) ;
2014-02-10 02:10:30 +01:00
return cells [ p_column ] . val ;
}
bool TreeItem : : is_range_exponential ( int p_column ) const {
2017-03-05 16:44:50 +01:00
ERR_FAIL_INDEX_V ( p_column , cells . size ( ) , false ) ;
2014-02-10 02:10:30 +01:00
return cells [ p_column ] . expr ;
}
2017-03-05 16:44:50 +01:00
void TreeItem : : set_range_config ( int p_column , double p_min , double p_max , double p_step , bool p_exp ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
ERR_FAIL_INDEX ( p_column , cells . size ( ) ) ;
2018-07-25 03:11:03 +02:00
cells . write [ p_column ] . min = p_min ;
cells . write [ p_column ] . max = p_max ;
cells . write [ p_column ] . step = p_step ;
cells . write [ p_column ] . expr = p_exp ;
2014-02-10 02:10:30 +01:00
_changed_notify ( p_column ) ;
}
2017-03-05 16:44:50 +01:00
void TreeItem : : get_range_config ( int p_column , double & r_min , double & r_max , double & r_step ) const {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
ERR_FAIL_INDEX ( p_column , cells . size ( ) ) ;
r_min = cells [ p_column ] . min ;
r_max = cells [ p_column ] . max ;
r_step = cells [ p_column ] . step ;
2014-02-10 02:10:30 +01:00
}
2017-03-05 16:44:50 +01:00
void TreeItem : : set_metadata ( int p_column , const Variant & p_meta ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
ERR_FAIL_INDEX ( p_column , cells . size ( ) ) ;
2018-07-25 03:11:03 +02:00
cells . write [ p_column ] . meta = p_meta ;
2014-02-10 02:10:30 +01:00
}
Variant TreeItem : : get_metadata ( int p_column ) const {
2017-03-05 16:44:50 +01:00
ERR_FAIL_INDEX_V ( p_column , cells . size ( ) , Variant ( ) ) ;
2014-02-10 02:10:30 +01:00
return cells [ p_column ] . meta ;
}
2017-03-05 16:44:50 +01:00
void TreeItem : : set_custom_draw ( int p_column , Object * p_object , const StringName & p_callback ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
ERR_FAIL_INDEX ( p_column , cells . size ( ) ) ;
2014-02-10 02:10:30 +01:00
ERR_FAIL_NULL ( p_object ) ;
2018-07-25 03:11:03 +02:00
cells . write [ p_column ] . custom_draw_obj = p_object - > get_instance_id ( ) ;
cells . write [ p_column ] . custom_draw_callback = p_callback ;
2014-02-10 02:10:30 +01:00
}
void TreeItem : : set_collapsed ( bool p_collapsed ) {
2019-06-03 21:52:50 +02:00
if ( collapsed = = p_collapsed | | ! tree )
2014-02-10 02:10:30 +01:00
return ;
2017-03-05 16:44:50 +01:00
collapsed = p_collapsed ;
2014-02-10 02:10:30 +01:00
TreeItem * ci = tree - > selected_item ;
if ( ci ) {
2017-03-05 16:44:50 +01:00
while ( ci & & ci ! = this ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
ci = ci - > parent ;
2014-02-10 02:10:30 +01:00
}
Fix misc. source comment typos
Found using `codespell -q 3 -S ./thirdparty,*.po -L ang,ba,cas,dof,doubleclick,fave,hist,leapyear,lod,nd,numer,ois,paket,seeked,sinc,switchs,te,uint -D ~/Projects/codespell/codespell_lib/data/dictionary.txt `
2019-09-19 20:36:39 +02:00
if ( ci ) { // collapsing cursor/selected, move it!
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
if ( tree - > select_mode = = Tree : : SELECT_MULTI ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
tree - > selected_item = this ;
2014-02-10 02:10:30 +01:00
emit_signal ( " cell_selected " ) ;
} else {
select ( tree - > selected_col ) ;
}
tree - > update ( ) ;
}
}
_changed_notify ( ) ;
2019-06-03 21:52:50 +02:00
tree - > emit_signal ( " item_collapsed " , this ) ;
2014-02-10 02:10:30 +01:00
}
bool TreeItem : : is_collapsed ( ) {
return collapsed ;
}
2017-09-05 14:31:07 +02:00
void TreeItem : : set_custom_minimum_height ( int p_height ) {
custom_min_height = p_height ;
_changed_notify ( ) ;
}
int TreeItem : : get_custom_minimum_height ( ) const {
return custom_min_height ;
}
2014-02-10 02:10:30 +01:00
TreeItem * TreeItem : : get_next ( ) {
return next ;
}
TreeItem * TreeItem : : get_prev ( ) {
2018-01-18 21:37:17 +01:00
if ( ! parent | | parent - > children = = this )
2020-04-02 01:20:12 +02:00
return nullptr ;
2015-08-31 00:37:23 +02:00
2018-01-18 21:37:17 +01:00
TreeItem * prev = parent - > children ;
2017-03-05 16:44:50 +01:00
while ( prev & & prev - > next ! = this )
prev = prev - > next ;
2015-08-31 00:37:23 +02:00
2014-02-10 02:10:30 +01:00
return prev ;
}
TreeItem * TreeItem : : get_parent ( ) {
return parent ;
}
TreeItem * TreeItem : : get_children ( ) {
2018-01-18 21:37:17 +01:00
return children ;
2014-02-10 02:10:30 +01:00
}
2019-05-11 18:32:53 +02:00
TreeItem * TreeItem : : get_prev_visible ( bool p_wrap ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
TreeItem * current = this ;
2014-02-10 02:10:30 +01:00
TreeItem * prev = current - > get_prev ( ) ;
if ( ! prev ) {
2017-03-05 16:44:50 +01:00
current = current - > parent ;
2019-05-11 18:32:53 +02:00
if ( current = = tree - > root & & tree - > hide_root ) {
2020-04-02 01:20:12 +02:00
return nullptr ;
2019-05-11 18:32:53 +02:00
} else if ( ! current ) {
if ( p_wrap ) {
current = this ;
TreeItem * temp = this - > get_next_visible ( ) ;
while ( temp ) {
current = temp ;
temp = temp - > get_next_visible ( ) ;
}
} else {
2020-04-02 01:20:12 +02:00
return nullptr ;
2019-05-11 18:32:53 +02:00
}
}
2014-02-10 02:10:30 +01:00
} else {
2017-03-05 16:44:50 +01:00
current = prev ;
2018-01-18 21:37:17 +01:00
while ( ! current - > collapsed & & current - > children ) {
2014-02-10 02:10:30 +01:00
//go to the very end
2018-01-18 21:37:17 +01:00
current = current - > children ;
2014-02-10 02:10:30 +01:00
while ( current - > next )
2017-03-05 16:44:50 +01:00
current = current - > next ;
2014-02-10 02:10:30 +01:00
}
}
return current ;
}
2019-05-11 18:32:53 +02:00
TreeItem * TreeItem : : get_next_visible ( bool p_wrap ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
TreeItem * current = this ;
2014-02-10 02:10:30 +01:00
2018-01-18 21:37:17 +01:00
if ( ! current - > collapsed & & current - > children ) {
2014-02-10 02:10:30 +01:00
2018-01-18 21:37:17 +01:00
current = current - > children ;
2014-02-10 02:10:30 +01:00
} else if ( current - > next ) {
2017-03-05 16:44:50 +01:00
current = current - > next ;
2014-02-10 02:10:30 +01:00
} else {
2017-03-05 16:44:50 +01:00
while ( current & & ! current - > next ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
current = current - > parent ;
2014-02-10 02:10:30 +01:00
}
2019-05-11 18:32:53 +02:00
if ( ! current ) {
if ( p_wrap )
return tree - > root ;
else
2020-04-02 01:20:12 +02:00
return nullptr ;
2019-05-11 18:32:53 +02:00
} else {
2017-03-05 16:44:50 +01:00
current = current - > next ;
2019-05-11 18:32:53 +02:00
}
2014-02-10 02:10:30 +01:00
}
return current ;
}
void TreeItem : : remove_child ( TreeItem * p_item ) {
ERR_FAIL_NULL ( p_item ) ;
2018-01-18 21:37:17 +01:00
TreeItem * * c = & children ;
2014-02-10 02:10:30 +01:00
while ( * c ) {
2017-03-05 16:44:50 +01:00
if ( ( * c ) = = p_item ) {
2014-02-10 02:10:30 +01:00
TreeItem * aux = * c ;
2017-03-05 16:44:50 +01:00
* c = ( * c ) - > next ;
2014-02-10 02:10:30 +01:00
2020-04-02 01:20:12 +02:00
aux - > parent = nullptr ;
2014-02-10 02:10:30 +01:00
return ;
}
2017-03-05 16:44:50 +01:00
c = & ( * c ) - > next ;
2014-02-10 02:10:30 +01:00
}
ERR_FAIL ( ) ;
}
2017-03-05 16:44:50 +01:00
void TreeItem : : set_selectable ( int p_column , bool p_selectable ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
ERR_FAIL_INDEX ( p_column , cells . size ( ) ) ;
2018-07-25 03:11:03 +02:00
cells . write [ p_column ] . selectable = p_selectable ;
2014-02-10 02:10:30 +01:00
}
bool TreeItem : : is_selectable ( int p_column ) const {
2017-03-05 16:44:50 +01:00
ERR_FAIL_INDEX_V ( p_column , cells . size ( ) , false ) ;
2014-02-10 02:10:30 +01:00
return cells [ p_column ] . selectable ;
}
bool TreeItem : : is_selected ( int p_column ) {
2017-03-05 16:44:50 +01:00
ERR_FAIL_INDEX_V ( p_column , cells . size ( ) , false ) ;
2014-02-10 02:10:30 +01:00
return cells [ p_column ] . selectable & & cells [ p_column ] . selected ;
}
void TreeItem : : set_as_cursor ( int p_column ) {
2017-03-05 16:44:50 +01:00
ERR_FAIL_INDEX ( p_column , cells . size ( ) ) ;
2014-02-10 02:10:30 +01:00
if ( ! tree )
return ;
2017-03-05 16:44:50 +01:00
if ( tree - > select_mode ! = Tree : : SELECT_MULTI )
2014-02-10 02:10:30 +01:00
return ;
2017-03-05 16:44:50 +01:00
tree - > selected_item = this ;
tree - > selected_col = p_column ;
2014-02-10 02:10:30 +01:00
tree - > update ( ) ;
}
void TreeItem : : select ( int p_column ) {
2017-03-05 16:44:50 +01:00
ERR_FAIL_INDEX ( p_column , cells . size ( ) ) ;
2014-02-10 02:10:30 +01:00
_cell_selected ( p_column ) ;
}
void TreeItem : : deselect ( int p_column ) {
2017-03-05 16:44:50 +01:00
ERR_FAIL_INDEX ( p_column , cells . size ( ) ) ;
2014-02-10 02:10:30 +01:00
_cell_deselected ( p_column ) ;
}
2019-06-11 20:43:37 +02:00
void TreeItem : : add_button ( int p_column , const Ref < Texture2D > & p_button , int p_id , bool p_disabled , const String & p_tooltip ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
ERR_FAIL_INDEX ( p_column , cells . size ( ) ) ;
2014-02-10 02:10:30 +01:00
ERR_FAIL_COND ( ! p_button . is_valid ( ) ) ;
TreeItem : : Cell : : Button button ;
2017-03-05 16:44:50 +01:00
button . texture = p_button ;
if ( p_id < 0 )
p_id = cells [ p_column ] . buttons . size ( ) ;
button . id = p_id ;
button . disabled = p_disabled ;
2017-04-24 21:41:17 +02:00
button . tooltip = p_tooltip ;
2018-07-25 03:11:03 +02:00
cells . write [ p_column ] . buttons . push_back ( button ) ;
2014-02-10 02:10:30 +01:00
_changed_notify ( p_column ) ;
}
int TreeItem : : get_button_count ( int p_column ) const {
2017-03-05 16:44:50 +01:00
ERR_FAIL_INDEX_V ( p_column , cells . size ( ) , - 1 ) ;
2014-02-10 02:10:30 +01:00
return cells [ p_column ] . buttons . size ( ) ;
}
2019-06-11 20:43:37 +02:00
Ref < Texture2D > TreeItem : : get_button ( int p_column , int p_idx ) const {
ERR_FAIL_INDEX_V ( p_column , cells . size ( ) , Ref < Texture2D > ( ) ) ;
ERR_FAIL_INDEX_V ( p_idx , cells [ p_column ] . buttons . size ( ) , Ref < Texture2D > ( ) ) ;
2014-02-10 02:10:30 +01:00
return cells [ p_column ] . buttons [ p_idx ] . texture ;
}
2019-09-04 16:47:47 +02:00
String TreeItem : : get_button_tooltip ( int p_column , int p_idx ) const {
ERR_FAIL_INDEX_V ( p_column , cells . size ( ) , String ( ) ) ;
ERR_FAIL_INDEX_V ( p_idx , cells [ p_column ] . buttons . size ( ) , String ( ) ) ;
return cells [ p_column ] . buttons [ p_idx ] . tooltip ;
}
2017-03-05 16:44:50 +01:00
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 ) ;
2014-02-10 02:10:30 +01:00
return cells [ p_column ] . buttons [ p_idx ] . id ;
}
2017-03-05 16:44:50 +01:00
void TreeItem : : erase_button ( int p_column , int p_idx ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
ERR_FAIL_INDEX ( p_column , cells . size ( ) ) ;
ERR_FAIL_INDEX ( p_idx , cells [ p_column ] . buttons . size ( ) ) ;
2018-07-25 03:11:03 +02:00
cells . write [ p_column ] . buttons . remove ( p_idx ) ;
2014-02-10 02:10:30 +01:00
_changed_notify ( p_column ) ;
}
2017-03-05 16:44:50 +01:00
int TreeItem : : get_button_by_id ( int p_column , int p_id ) const {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
ERR_FAIL_INDEX_V ( p_column , cells . size ( ) , - 1 ) ;
for ( int i = 0 ; i < cells [ p_column ] . buttons . size ( ) ; i + + ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
if ( cells [ p_column ] . buttons [ i ] . id = = p_id )
2014-02-10 02:10:30 +01:00
return i ;
}
return - 1 ;
}
2016-02-03 00:44:42 +01:00
2019-06-11 20:43:37 +02:00
void TreeItem : : set_button ( int p_column , int p_idx , const Ref < Texture2D > & p_button ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
ERR_FAIL_COND ( p_button . is_null ( ) ) ;
ERR_FAIL_INDEX ( p_column , cells . size ( ) ) ;
ERR_FAIL_INDEX ( p_idx , cells [ p_column ] . buttons . size ( ) ) ;
2018-07-25 03:11:03 +02:00
cells . write [ p_column ] . buttons . write [ p_idx ] . texture = p_button ;
2014-02-10 02:10:30 +01:00
_changed_notify ( p_column ) ;
}
2017-03-05 16:44:50 +01:00
void TreeItem : : set_button_color ( int p_column , int p_idx , const Color & p_color ) {
2016-12-28 14:12:08 +01:00
2017-03-05 16:44:50 +01:00
ERR_FAIL_INDEX ( p_column , cells . size ( ) ) ;
ERR_FAIL_INDEX ( p_idx , cells [ p_column ] . buttons . size ( ) ) ;
2018-07-25 03:11:03 +02:00
cells . write [ p_column ] . buttons . write [ p_idx ] . color = p_color ;
2016-12-28 14:12:08 +01:00
_changed_notify ( p_column ) ;
}
2019-07-09 09:13:00 +02:00
void TreeItem : : set_button_disabled ( int p_column , int p_idx , bool p_disabled ) {
ERR_FAIL_INDEX ( p_column , cells . size ( ) ) ;
ERR_FAIL_INDEX ( p_idx , cells [ p_column ] . buttons . size ( ) ) ;
cells . write [ p_column ] . buttons . write [ p_idx ] . disabled = p_disabled ;
_changed_notify ( p_column ) ;
}
bool TreeItem : : is_button_disabled ( int p_column , int p_idx ) const {
ERR_FAIL_INDEX_V ( p_column , cells . size ( ) , false ) ;
ERR_FAIL_INDEX_V ( p_idx , cells [ p_column ] . buttons . size ( ) , false ) ;
return cells [ p_column ] . buttons [ p_idx ] . disabled ;
}
2017-03-05 16:44:50 +01:00
void TreeItem : : set_editable ( int p_column , bool p_editable ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
ERR_FAIL_INDEX ( p_column , cells . size ( ) ) ;
2018-07-25 03:11:03 +02:00
cells . write [ p_column ] . editable = p_editable ;
2014-02-10 02:10:30 +01:00
_changed_notify ( p_column ) ;
}
bool TreeItem : : is_editable ( int p_column ) {
2017-03-05 16:44:50 +01:00
ERR_FAIL_INDEX_V ( p_column , cells . size ( ) , false ) ;
2014-02-10 02:10:30 +01:00
return cells [ p_column ] . editable ;
}
2017-03-05 16:44:50 +01:00
void TreeItem : : set_custom_color ( int p_column , const Color & p_color ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
ERR_FAIL_INDEX ( p_column , cells . size ( ) ) ;
2018-07-25 03:11:03 +02:00
cells . write [ p_column ] . custom_color = true ;
cells . write [ p_column ] . color = p_color ;
2014-02-10 02:10:30 +01:00
_changed_notify ( p_column ) ;
}
2016-03-12 14:44:12 +01:00
Color TreeItem : : get_custom_color ( int p_column ) const {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
ERR_FAIL_INDEX_V ( p_column , cells . size ( ) , Color ( ) ) ;
2016-03-12 14:44:12 +01:00
if ( ! cells [ p_column ] . custom_color )
return Color ( ) ;
return cells [ p_column ] . color ;
}
2014-02-10 02:10:30 +01:00
void TreeItem : : clear_custom_color ( int p_column ) {
2017-03-05 16:44:50 +01:00
ERR_FAIL_INDEX ( p_column , cells . size ( ) ) ;
2018-07-25 03:11:03 +02:00
cells . write [ p_column ] . custom_color = false ;
cells . write [ p_column ] . color = Color ( ) ;
2014-02-10 02:10:30 +01:00
_changed_notify ( p_column ) ;
}
2017-03-05 16:44:50 +01:00
void TreeItem : : set_tooltip ( int p_column , const String & p_tooltip ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
ERR_FAIL_INDEX ( p_column , cells . size ( ) ) ;
2018-07-25 03:11:03 +02:00
cells . write [ p_column ] . tooltip = p_tooltip ;
2014-02-10 02:10:30 +01:00
}
2017-03-05 16:44:50 +01:00
String TreeItem : : get_tooltip ( int p_column ) const {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
ERR_FAIL_INDEX_V ( p_column , cells . size ( ) , " " ) ;
2014-02-10 02:10:30 +01:00
return cells [ p_column ] . tooltip ;
}
2017-03-05 16:44:50 +01:00
void TreeItem : : set_custom_bg_color ( int p_column , const Color & p_color , bool p_bg_outline ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
ERR_FAIL_INDEX ( p_column , cells . size ( ) ) ;
2018-07-25 03:11:03 +02:00
cells . write [ p_column ] . custom_bg_color = true ;
cells . write [ p_column ] . custom_bg_outline = p_bg_outline ;
cells . write [ p_column ] . bg_color = p_color ;
2014-02-10 02:10:30 +01:00
_changed_notify ( p_column ) ;
}
void TreeItem : : clear_custom_bg_color ( int p_column ) {
2017-03-05 16:44:50 +01:00
ERR_FAIL_INDEX ( p_column , cells . size ( ) ) ;
2018-07-25 03:11:03 +02:00
cells . write [ p_column ] . custom_bg_color = false ;
cells . write [ p_column ] . bg_color = Color ( ) ;
2014-02-10 02:10:30 +01:00
_changed_notify ( p_column ) ;
}
Color TreeItem : : get_custom_bg_color ( int p_column ) const {
2017-03-05 16:44:50 +01:00
ERR_FAIL_INDEX_V ( p_column , cells . size ( ) , Color ( ) ) ;
2014-02-10 02:10:30 +01:00
if ( ! cells [ p_column ] . custom_bg_color )
return Color ( ) ;
return cells [ p_column ] . bg_color ;
}
2017-06-05 01:35:08 +02:00
void TreeItem : : set_custom_as_button ( int p_column , bool p_button ) {
ERR_FAIL_INDEX ( p_column , cells . size ( ) ) ;
2018-07-25 03:11:03 +02:00
cells . write [ p_column ] . custom_button = p_button ;
2017-06-05 01:35:08 +02:00
}
bool TreeItem : : is_custom_set_as_button ( int p_column ) const {
ERR_FAIL_INDEX_V ( p_column , cells . size ( ) , false ) ;
return cells [ p_column ] . custom_button ;
}
2017-06-25 22:30:28 +02:00
void TreeItem : : set_text_align ( int p_column , TextAlign p_align ) {
ERR_FAIL_INDEX ( p_column , cells . size ( ) ) ;
2018-07-25 03:11:03 +02:00
cells . write [ p_column ] . text_align = p_align ;
2017-06-25 22:30:28 +02:00
_changed_notify ( p_column ) ;
}
TreeItem : : TextAlign TreeItem : : get_text_align ( int p_column ) const {
ERR_FAIL_INDEX_V ( p_column , cells . size ( ) , ALIGN_LEFT ) ;
return cells [ p_column ] . text_align ;
}
void TreeItem : : set_expand_right ( int p_column , bool p_enable ) {
ERR_FAIL_INDEX ( p_column , cells . size ( ) ) ;
2018-07-25 03:11:03 +02:00
cells . write [ p_column ] . expand_right = p_enable ;
2017-06-25 22:30:28 +02:00
_changed_notify ( p_column ) ;
}
bool TreeItem : : get_expand_right ( int p_column ) const {
ERR_FAIL_INDEX_V ( p_column , cells . size ( ) , false ) ;
return cells [ p_column ] . expand_right ;
}
void TreeItem : : set_disable_folding ( bool p_disable ) {
disable_folding = p_disable ;
_changed_notify ( 0 ) ;
}
bool TreeItem : : is_folding_disabled ( ) const {
return disable_folding ;
}
2020-02-19 20:27:19 +01:00
Variant TreeItem : : _call_recursive_bind ( const Variant * * p_args , int p_argcount , Callable : : CallError & r_error ) {
2018-10-07 18:25:57 +02:00
if ( p_argcount < 1 ) {
2020-02-19 20:27:19 +01:00
r_error . error = Callable : : CallError : : CALL_ERROR_TOO_FEW_ARGUMENTS ;
2018-10-07 18:25:57 +02:00
r_error . argument = 0 ;
return Variant ( ) ;
}
2020-02-20 22:58:05 +01:00
if ( p_args [ 0 ] - > get_type ( ) ! = Variant : : STRING & & p_args [ 0 ] - > get_type ( ) ! = Variant : : STRING_NAME ) {
2020-02-19 20:27:19 +01:00
r_error . error = Callable : : CallError : : CALL_ERROR_INVALID_ARGUMENT ;
2018-10-07 18:25:57 +02:00
r_error . argument = 0 ;
2020-02-20 22:58:05 +01:00
r_error . expected = Variant : : STRING_NAME ;
2018-10-07 18:25:57 +02:00
return Variant ( ) ;
}
StringName method = * p_args [ 0 ] ;
call_recursive ( method , & p_args [ 1 ] , p_argcount - 1 , r_error ) ;
return Variant ( ) ;
}
2020-02-19 20:27:19 +01:00
void recursive_call_aux ( TreeItem * p_item , const StringName & p_method , const Variant * * p_args , int p_argcount , Callable : : CallError & r_error ) {
2018-10-07 18:25:57 +02:00
if ( ! p_item ) {
return ;
}
p_item - > call ( p_method , p_args , p_argcount , r_error ) ;
TreeItem * c = p_item - > get_children ( ) ;
while ( c ) {
recursive_call_aux ( c , p_method , p_args , p_argcount , r_error ) ;
c = c - > get_next ( ) ;
}
}
2020-02-19 20:27:19 +01:00
void TreeItem : : call_recursive ( const StringName & p_method , const Variant * * p_args , int p_argcount , Callable : : CallError & r_error ) {
2018-10-07 18:25:57 +02:00
recursive_call_aux ( this , p_method , p_args , p_argcount , r_error ) ;
}
2014-02-10 02:10:30 +01:00
void TreeItem : : _bind_methods ( ) {
2017-03-05 16:44:50 +01:00
ClassDB : : bind_method ( D_METHOD ( " set_cell_mode " , " column " , " mode " ) , & TreeItem : : set_cell_mode ) ;
ClassDB : : bind_method ( D_METHOD ( " get_cell_mode " , " column " ) , & TreeItem : : get_cell_mode ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
ClassDB : : bind_method ( D_METHOD ( " set_checked " , " column " , " checked " ) , & TreeItem : : set_checked ) ;
ClassDB : : bind_method ( D_METHOD ( " is_checked " , " column " ) , & TreeItem : : is_checked ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
ClassDB : : bind_method ( D_METHOD ( " set_text " , " column " , " text " ) , & TreeItem : : set_text ) ;
ClassDB : : bind_method ( D_METHOD ( " get_text " , " column " ) , & TreeItem : : get_text ) ;
2014-02-10 02:10:30 +01:00
2017-08-09 13:19:41 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_icon " , " column " , " texture " ) , & TreeItem : : set_icon ) ;
ClassDB : : bind_method ( D_METHOD ( " get_icon " , " column " ) , & TreeItem : : get_icon ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
ClassDB : : bind_method ( D_METHOD ( " set_icon_region " , " column " , " region " ) , & TreeItem : : set_icon_region ) ;
ClassDB : : bind_method ( D_METHOD ( " get_icon_region " , " column " ) , & TreeItem : : get_icon_region ) ;
2015-08-31 00:37:23 +02:00
2017-03-05 16:44:50 +01:00
ClassDB : : bind_method ( D_METHOD ( " set_icon_max_width " , " column " , " width " ) , & TreeItem : : set_icon_max_width ) ;
ClassDB : : bind_method ( D_METHOD ( " get_icon_max_width " , " column " ) , & TreeItem : : get_icon_max_width ) ;
2014-02-10 02:10:30 +01:00
2019-08-24 17:13:48 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_icon_modulate " , " column " , " modulate " ) , & TreeItem : : set_icon_modulate ) ;
ClassDB : : bind_method ( D_METHOD ( " get_icon_modulate " , " column " ) , & TreeItem : : get_icon_modulate ) ;
2017-03-05 16:44:50 +01:00
ClassDB : : bind_method ( D_METHOD ( " set_range " , " column " , " value " ) , & TreeItem : : set_range ) ;
ClassDB : : bind_method ( D_METHOD ( " get_range " , " column " ) , & TreeItem : : get_range ) ;
ClassDB : : bind_method ( D_METHOD ( " set_range_config " , " column " , " min " , " max " , " step " , " expr " ) , & TreeItem : : set_range_config , DEFVAL ( false ) ) ;
ClassDB : : bind_method ( D_METHOD ( " get_range_config " , " column " ) , & TreeItem : : _get_range_config ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
ClassDB : : bind_method ( D_METHOD ( " set_metadata " , " column " , " meta " ) , & TreeItem : : set_metadata ) ;
ClassDB : : bind_method ( D_METHOD ( " get_metadata " , " column " ) , & TreeItem : : get_metadata ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
ClassDB : : bind_method ( D_METHOD ( " set_custom_draw " , " column " , " object " , " callback " ) , & TreeItem : : set_custom_draw ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
ClassDB : : bind_method ( D_METHOD ( " set_collapsed " , " enable " ) , & TreeItem : : set_collapsed ) ;
ClassDB : : bind_method ( D_METHOD ( " is_collapsed " ) , & TreeItem : : is_collapsed ) ;
2014-02-10 02:10:30 +01:00
2017-09-05 14:31:07 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_custom_minimum_height " , " height " ) , & TreeItem : : set_custom_minimum_height ) ;
ClassDB : : bind_method ( D_METHOD ( " get_custom_minimum_height " ) , & TreeItem : : get_custom_minimum_height ) ;
2017-08-09 13:19:41 +02:00
ClassDB : : bind_method ( D_METHOD ( " get_next " ) , & TreeItem : : get_next ) ;
ClassDB : : bind_method ( D_METHOD ( " get_prev " ) , & TreeItem : : get_prev ) ;
ClassDB : : bind_method ( D_METHOD ( " get_parent " ) , & TreeItem : : get_parent ) ;
ClassDB : : bind_method ( D_METHOD ( " get_children " ) , & TreeItem : : get_children ) ;
2015-08-31 00:37:23 +02:00
2019-05-11 18:32:53 +02:00
ClassDB : : bind_method ( D_METHOD ( " get_next_visible " , " wrap " ) , & TreeItem : : get_next_visible , DEFVAL ( false ) ) ;
ClassDB : : bind_method ( D_METHOD ( " get_prev_visible " , " wrap " ) , & TreeItem : : get_prev_visible , DEFVAL ( false ) ) ;
2014-02-10 02:10:30 +01:00
2017-07-22 12:11:42 +02:00
ClassDB : : bind_method ( D_METHOD ( " remove_child " , " child " ) , & TreeItem : : _remove_child ) ;
2015-08-31 00:37:23 +02:00
2017-03-05 16:44:50 +01:00
ClassDB : : bind_method ( D_METHOD ( " set_selectable " , " column " , " selectable " ) , & TreeItem : : set_selectable ) ;
ClassDB : : bind_method ( D_METHOD ( " is_selectable " , " column " ) , & TreeItem : : is_selectable ) ;
2015-08-31 00:37:23 +02:00
2017-03-05 16:44:50 +01:00
ClassDB : : bind_method ( D_METHOD ( " is_selected " , " column " ) , & TreeItem : : is_selected ) ;
ClassDB : : bind_method ( D_METHOD ( " select " , " column " ) , & TreeItem : : select ) ;
ClassDB : : bind_method ( D_METHOD ( " deselect " , " column " ) , & TreeItem : : deselect ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
ClassDB : : bind_method ( D_METHOD ( " set_editable " , " column " , " enabled " ) , & TreeItem : : set_editable ) ;
ClassDB : : bind_method ( D_METHOD ( " is_editable " , " column " ) , & TreeItem : : is_editable ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
ClassDB : : bind_method ( D_METHOD ( " set_custom_color " , " column " , " color " ) , & TreeItem : : set_custom_color ) ;
ClassDB : : bind_method ( D_METHOD ( " clear_custom_color " , " column " ) , & TreeItem : : clear_custom_color ) ;
2019-10-06 22:07:50 +02:00
ClassDB : : bind_method ( D_METHOD ( " get_custom_color " , " column " ) , & TreeItem : : get_custom_color ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
ClassDB : : bind_method ( D_METHOD ( " set_custom_bg_color " , " column " , " color " , " just_outline " ) , & TreeItem : : set_custom_bg_color , DEFVAL ( false ) ) ;
ClassDB : : bind_method ( D_METHOD ( " clear_custom_bg_color " , " column " ) , & TreeItem : : clear_custom_bg_color ) ;
ClassDB : : bind_method ( D_METHOD ( " get_custom_bg_color " , " column " ) , & TreeItem : : get_custom_bg_color ) ;
2014-02-10 02:10:30 +01:00
2017-06-05 01:35:08 +02:00
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 ) ;
2017-08-09 13:19:41 +02:00
ClassDB : : bind_method ( D_METHOD ( " add_button " , " column " , " button " , " button_idx " , " disabled " , " tooltip " ) , & TreeItem : : add_button , DEFVAL ( - 1 ) , DEFVAL ( false ) , DEFVAL ( " " ) ) ;
2017-03-05 16:44:50 +01:00
ClassDB : : bind_method ( D_METHOD ( " get_button_count " , " column " ) , & TreeItem : : get_button_count ) ;
2019-09-27 22:16:32 +02:00
ClassDB : : bind_method ( D_METHOD ( " get_button_tooltip " , " column " , " button_idx " ) , & TreeItem : : get_button_tooltip ) ;
2017-08-09 13:19:41 +02:00
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 ) ;
2017-03-05 16:44:50 +01:00
ClassDB : : bind_method ( D_METHOD ( " erase_button " , " column " , " button_idx " ) , & TreeItem : : erase_button ) ;
2019-07-09 09:13:00 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_button_disabled " , " column " , " button_idx " , " disabled " ) , & TreeItem : : set_button_disabled ) ;
2017-03-05 16:44:50 +01:00
ClassDB : : bind_method ( D_METHOD ( " is_button_disabled " , " column " , " button_idx " ) , & TreeItem : : is_button_disabled ) ;
2014-02-10 02:10:30 +01:00
2017-06-25 22:30:28 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_expand_right " , " column " , " enable " ) , & TreeItem : : set_expand_right ) ;
ClassDB : : bind_method ( D_METHOD ( " get_expand_right " , " column " ) , & TreeItem : : get_expand_right ) ;
2017-03-05 16:44:50 +01:00
ClassDB : : bind_method ( D_METHOD ( " set_tooltip " , " column " , " tooltip " ) , & TreeItem : : set_tooltip ) ;
ClassDB : : bind_method ( D_METHOD ( " get_tooltip " , " column " ) , & TreeItem : : get_tooltip ) ;
2017-06-25 22:30:28 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_text_align " , " column " , " text_align " ) , & TreeItem : : set_text_align ) ;
ClassDB : : bind_method ( D_METHOD ( " get_text_align " , " column " ) , & TreeItem : : get_text_align ) ;
2017-03-05 16:44:50 +01:00
ClassDB : : bind_method ( D_METHOD ( " move_to_top " ) , & TreeItem : : move_to_top ) ;
ClassDB : : bind_method ( D_METHOD ( " move_to_bottom " ) , & TreeItem : : move_to_bottom ) ;
2014-02-10 02:10:30 +01:00
2017-06-25 22:30:28 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_disable_folding " , " disable " ) , & TreeItem : : set_disable_folding ) ;
ClassDB : : bind_method ( D_METHOD ( " is_folding_disabled " ) , & TreeItem : : is_folding_disabled ) ;
2018-10-07 18:25:57 +02:00
{
MethodInfo mi ;
mi . name = " call_recursive " ;
2020-02-20 22:58:05 +01:00
mi . arguments . push_back ( PropertyInfo ( Variant : : STRING_NAME , " method " ) ) ;
2018-10-07 18:25:57 +02:00
ClassDB : : bind_vararg_method ( METHOD_FLAGS_DEFAULT , " call_recursive " , & TreeItem : : _call_recursive_bind , mi ) ;
}
2018-01-11 23:35:12 +01:00
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " collapsed " ) , " set_collapsed " , " is_collapsed " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " disable_folding " ) , " set_disable_folding " , " is_folding_disabled " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " custom_minimum_height " , PROPERTY_HINT_RANGE , " 0,1000,1 " ) , " set_custom_minimum_height " , " get_custom_minimum_height " ) ;
2017-08-20 17:45:01 +02:00
BIND_ENUM_CONSTANT ( CELL_MODE_STRING ) ;
BIND_ENUM_CONSTANT ( CELL_MODE_CHECK ) ;
BIND_ENUM_CONSTANT ( CELL_MODE_RANGE ) ;
BIND_ENUM_CONSTANT ( CELL_MODE_ICON ) ;
BIND_ENUM_CONSTANT ( CELL_MODE_CUSTOM ) ;
2017-09-12 21:09:06 +02:00
BIND_ENUM_CONSTANT ( ALIGN_LEFT ) ;
BIND_ENUM_CONSTANT ( ALIGN_CENTER ) ;
BIND_ENUM_CONSTANT ( ALIGN_RIGHT ) ;
2014-02-10 02:10:30 +01:00
}
void TreeItem : : clear_children ( ) {
2018-01-18 21:37:17 +01:00
TreeItem * c = children ;
2014-02-10 02:10:30 +01:00
while ( c ) {
2017-03-05 16:44:50 +01:00
TreeItem * aux = c ;
c = c - > get_next ( ) ;
2020-04-02 01:20:12 +02:00
aux - > parent = nullptr ; // so it won't try to recursively autoremove from me in here
2017-03-05 16:44:50 +01:00
memdelete ( aux ) ;
2014-02-10 02:10:30 +01:00
}
2020-04-02 01:20:12 +02:00
children = nullptr ;
2014-02-10 02:10:30 +01:00
} ;
TreeItem : : TreeItem ( Tree * p_tree ) {
2017-03-05 16:44:50 +01:00
tree = p_tree ;
collapsed = false ;
2017-06-25 22:30:28 +02:00
disable_folding = false ;
2017-09-05 14:31:07 +02:00
custom_min_height = 0 ;
2014-02-10 02:10:30 +01:00
2020-04-02 01:20:12 +02:00
parent = nullptr ; // parent item
next = nullptr ; // next in list
children = nullptr ; //child items
2014-02-10 02:10:30 +01:00
}
TreeItem : : ~ TreeItem ( ) {
clear_children ( ) ;
if ( parent )
parent - > remove_child ( this ) ;
2017-03-05 16:44:50 +01:00
if ( tree & & tree - > root = = this ) {
2014-02-10 02:10:30 +01:00
2020-04-02 01:20:12 +02:00
tree - > root = nullptr ;
2014-02-10 02:10:30 +01:00
}
2017-03-05 16:44:50 +01:00
if ( tree & & tree - > popup_edited_item = = this ) {
2020-04-02 01:20:12 +02:00
tree - > popup_edited_item = nullptr ;
2017-03-05 16:44:50 +01:00
tree - > pressing_for_editor = false ;
2015-08-29 06:43:21 +02:00
}
2014-02-10 02:10:30 +01:00
2017-06-05 01:35:08 +02:00
if ( tree & & tree - > cache . hover_item = = this ) {
2020-04-02 01:20:12 +02:00
tree - > cache . hover_item = nullptr ;
2017-06-05 01:35:08 +02:00
}
2017-03-05 16:44:50 +01:00
if ( tree & & tree - > selected_item = = this )
2020-04-02 01:20:12 +02:00
tree - > selected_item = nullptr ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
if ( tree & & tree - > drop_mode_over = = this )
2020-04-02 01:20:12 +02:00
tree - > drop_mode_over = nullptr ;
2016-05-11 16:46:08 +02:00
2017-03-05 16:44:50 +01:00
if ( tree & & tree - > single_select_defer = = this )
2020-04-02 01:20:12 +02:00
tree - > single_select_defer = nullptr ;
2016-05-11 16:46:08 +02:00
2017-03-05 16:44:50 +01:00
if ( tree & & tree - > edited_item = = this ) {
2020-04-02 01:20:12 +02:00
tree - > edited_item = nullptr ;
2017-03-05 16:44:50 +01:00
tree - > pressing_for_editor = false ;
2015-08-29 06:43:21 +02:00
}
2014-02-10 02:10:30 +01:00
}
/**********************************************/
/**********************************************/
/**********************************************/
/**********************************************/
/**********************************************/
/**********************************************/
void Tree : : update_cache ( ) {
2020-03-12 13:37:40 +01:00
cache . font = get_theme_font ( " font " ) ;
cache . tb_font = get_theme_font ( " title_button_font " ) ;
cache . bg = get_theme_stylebox ( " bg " ) ;
cache . selected = get_theme_stylebox ( " selected " ) ;
cache . selected_focus = get_theme_stylebox ( " selected_focus " ) ;
cache . cursor = get_theme_stylebox ( " cursor " ) ;
cache . cursor_unfocus = get_theme_stylebox ( " cursor_unfocused " ) ;
cache . button_pressed = get_theme_stylebox ( " button_pressed " ) ;
cache . checked = get_theme_icon ( " checked " ) ;
cache . unchecked = get_theme_icon ( " unchecked " ) ;
cache . arrow_collapsed = get_theme_icon ( " arrow_collapsed " ) ;
cache . arrow = get_theme_icon ( " arrow " ) ;
cache . select_arrow = get_theme_icon ( " select_arrow " ) ;
cache . updown = get_theme_icon ( " updown " ) ;
cache . custom_button = get_theme_stylebox ( " custom_button " ) ;
cache . custom_button_hover = get_theme_stylebox ( " custom_button_hover " ) ;
cache . custom_button_pressed = get_theme_stylebox ( " custom_button_pressed " ) ;
cache . custom_button_font_highlight = get_theme_color ( " custom_button_font_highlight " ) ;
cache . font_color = get_theme_color ( " font_color " ) ;
cache . font_color_selected = get_theme_color ( " font_color_selected " ) ;
cache . guide_color = get_theme_color ( " guide_color " ) ;
cache . drop_position_color = get_theme_color ( " drop_position_color " ) ;
cache . hseparation = get_theme_constant ( " hseparation " ) ;
cache . vseparation = get_theme_constant ( " vseparation " ) ;
cache . item_margin = get_theme_constant ( " item_margin " ) ;
cache . button_margin = get_theme_constant ( " button_margin " ) ;
cache . draw_guides = get_theme_constant ( " draw_guides " ) ;
cache . draw_relationship_lines = get_theme_constant ( " draw_relationship_lines " ) ;
cache . relationship_line_color = get_theme_color ( " relationship_line_color " ) ;
cache . scroll_border = get_theme_constant ( " scroll_border " ) ;
cache . scroll_speed = get_theme_constant ( " scroll_speed " ) ;
cache . title_button = get_theme_stylebox ( " title_button_normal " ) ;
cache . title_button_pressed = get_theme_stylebox ( " title_button_pressed " ) ;
cache . title_button_hover = get_theme_stylebox ( " title_button_hover " ) ;
cache . title_button_color = get_theme_color ( " title_button_color " ) ;
2014-02-10 02:10:30 +01:00
v_scroll - > set_custom_step ( cache . font - > get_height ( ) ) ;
}
int Tree : : compute_item_height ( TreeItem * p_item ) const {
2017-03-05 16:44:50 +01:00
if ( p_item = = root & & hide_root )
2014-02-10 02:10:30 +01:00
return 0 ;
2015-08-31 00:37:23 +02:00
2018-01-06 19:48:54 +01:00
ERR_FAIL_COND_V ( cache . font . is_null ( ) , 0 ) ;
2017-03-05 16:44:50 +01:00
int height = cache . font - > get_height ( ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < columns . size ( ) ; i + + ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
for ( int j = 0 ; j < p_item - > cells [ i ] . buttons . size ( ) ; j + + ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
Size2i s ; // = cache.button_pressed->get_minimum_size();
s + = p_item - > cells [ i ] . buttons [ j ] . texture - > get_size ( ) ;
if ( s . height > height )
height = s . height ;
2014-02-10 02:10:30 +01:00
}
2017-03-05 16:44:50 +01:00
switch ( p_item - > cells [ i ] . mode ) {
2015-08-31 00:37:23 +02:00
2014-02-10 02:10:30 +01:00
case TreeItem : : CELL_MODE_CHECK : {
2015-08-31 00:37:23 +02:00
2014-02-10 02:10:30 +01:00
int check_icon_h = cache . checked - > get_height ( ) ;
2017-03-05 16:44:50 +01:00
if ( height < check_icon_h )
height = check_icon_h ;
2020-02-22 20:47:50 +01:00
[[fallthrough]] ;
2014-02-10 02:10:30 +01:00
}
case TreeItem : : CELL_MODE_STRING :
case TreeItem : : CELL_MODE_CUSTOM :
case TreeItem : : CELL_MODE_ICON : {
2015-08-31 00:37:23 +02:00
2019-06-11 20:43:37 +02:00
Ref < Texture2D > icon = p_item - > cells [ i ] . icon ;
2014-02-10 02:10:30 +01:00
if ( ! icon . is_null ( ) ) {
2015-08-31 00:37:23 +02:00
2014-02-10 02:10:30 +01:00
Size2i s = p_item - > cells [ i ] . get_icon_size ( ) ;
2017-03-05 16:44:50 +01:00
if ( p_item - > cells [ i ] . icon_max_w > 0 & & s . width > p_item - > cells [ i ] . icon_max_w ) {
s . height = s . height * p_item - > cells [ i ] . icon_max_w / s . width ;
2014-02-10 02:10:30 +01:00
}
2017-03-05 16:44:50 +01:00
if ( s . height > height )
height = s . height ;
2014-02-10 02:10:30 +01:00
}
2017-06-05 01:35:08 +02:00
if ( p_item - > cells [ i ] . mode = = TreeItem : : CELL_MODE_CUSTOM & & p_item - > cells [ i ] . custom_button ) {
height + = cache . custom_button - > get_minimum_size ( ) . height ;
}
2015-08-31 00:37:23 +02:00
2014-02-10 02:10:30 +01:00
} break ;
2019-04-09 17:08:36 +02:00
default : {
}
2014-02-10 02:10:30 +01:00
}
}
2017-09-05 14:31:07 +02:00
int item_min_height = p_item - > get_custom_minimum_height ( ) ;
if ( height < item_min_height )
height = item_min_height ;
2015-08-31 00:37:23 +02:00
2014-02-10 02:10:30 +01:00
height + = cache . vseparation ;
2015-08-31 00:37:23 +02:00
2014-02-10 02:10:30 +01:00
return height ;
}
int Tree : : get_item_height ( TreeItem * p_item ) const {
2017-03-05 16:44:50 +01:00
int height = compute_item_height ( p_item ) ;
height + = cache . vseparation ;
2014-02-10 02:10:30 +01:00
2018-01-18 21:37:17 +01:00
if ( ! p_item - > collapsed ) { /* if not collapsed, check the children */
2014-02-10 02:10:30 +01:00
2018-01-18 21:37:17 +01:00
TreeItem * c = p_item - > children ;
2014-02-10 02:10:30 +01:00
while ( c ) {
2017-03-05 16:44:50 +01:00
height + = get_item_height ( c ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
c = c - > next ;
2014-02-10 02:10:30 +01:00
}
}
return height ;
}
2017-07-19 22:00:46 +02:00
void Tree : : draw_item_rect ( const TreeItem : : Cell & p_cell , const Rect2i & p_rect , const Color & p_color , const Color & p_icon_color ) {
2014-02-10 02:10:30 +01:00
2018-01-06 19:48:54 +01:00
ERR_FAIL_COND ( cache . font . is_null ( ) ) ;
2017-03-05 16:44:50 +01:00
Rect2i rect = p_rect ;
2017-06-25 22:30:28 +02:00
Ref < Font > font = cache . font ;
String text = p_cell . text ;
if ( p_cell . suffix ! = String ( ) )
text + = " " + p_cell . suffix ;
int w = 0 ;
if ( ! p_cell . icon . is_null ( ) ) {
Size2i bmsize = p_cell . get_icon_size ( ) ;
if ( p_cell . icon_max_w > 0 & & bmsize . width > p_cell . icon_max_w ) {
bmsize . width = p_cell . icon_max_w ;
}
w + = bmsize . width + cache . hseparation ;
}
w + = font - > get_string_size ( text ) . width ;
switch ( p_cell . text_align ) {
case TreeItem : : ALIGN_LEFT :
break ; //do none
case TreeItem : : ALIGN_CENTER :
2017-12-28 11:27:57 +01:00
rect . position . x + = MAX ( 0 , ( rect . size . width - w ) / 2 ) ;
2017-06-25 22:30:28 +02:00
break ; //do none
case TreeItem : : ALIGN_RIGHT :
2017-12-28 11:27:57 +01:00
rect . position . x + = MAX ( 0 , ( rect . size . width - w ) ) ;
2017-06-25 22:30:28 +02:00
break ; //do none
}
2014-02-10 02:10:30 +01:00
RID ci = get_canvas_item ( ) ;
if ( ! p_cell . icon . is_null ( ) ) {
Size2i bmsize = p_cell . get_icon_size ( ) ;
2017-03-05 16:44:50 +01:00
if ( p_cell . icon_max_w > 0 & & bmsize . width > p_cell . icon_max_w ) {
2014-02-10 02:10:30 +01:00
bmsize . height = bmsize . height * p_cell . icon_max_w / bmsize . width ;
2017-03-05 16:44:50 +01:00
bmsize . width = p_cell . icon_max_w ;
2014-02-10 02:10:30 +01:00
}
2017-07-19 22:00:46 +02:00
p_cell . draw_icon ( ci , rect . position + Size2i ( 0 , Math : : floor ( ( real_t ) ( rect . size . y - bmsize . y ) / 2 ) ) , bmsize , p_icon_color ) ;
2017-06-04 00:25:13 +02:00
rect . position . x + = bmsize . x + cache . hseparation ;
2017-03-05 16:44:50 +01:00
rect . size . x - = bmsize . x + cache . hseparation ;
2014-02-10 02:10:30 +01:00
}
2017-06-04 00:25:13 +02:00
rect . position . y + = Math : : floor ( ( rect . size . y - font - > get_height ( ) ) / 2.0 ) + font - > get_ascent ( ) ;
2020-02-09 00:08:18 +01:00
font - > draw ( ci , rect . position , text , p_color , MAX ( 0 , rect . size . width ) ) ;
2014-02-10 02:10:30 +01:00
}
2017-03-05 16:44:50 +01:00
int Tree : : draw_item ( const Point2i & p_pos , const Point2 & p_draw_ofs , const Size2 & p_draw_size , TreeItem * p_item ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
if ( p_pos . y - cache . offset . y > ( p_draw_size . height ) )
2014-02-10 02:10:30 +01:00
return - 1 ; //draw no more!
RID ci = get_canvas_item ( ) ;
2017-03-05 16:44:50 +01:00
int htotal = 0 ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
int label_h = compute_item_height ( p_item ) ;
2014-02-10 02:10:30 +01:00
/* Calculate height of the label part */
2017-03-05 16:44:50 +01:00
label_h + = cache . vseparation ;
2014-02-10 02:10:30 +01:00
/* Draw label, if height fits */
2017-03-05 16:44:50 +01:00
bool skip = ( p_item = = root & & hide_root ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
if ( ! skip & & ( p_pos . y + label_h - cache . offset . y ) > 0 ) {
2014-02-10 02:10:30 +01:00
//draw separation.
2017-01-14 12:26:56 +01:00
//if (p_item->get_parent()!=root || !hide_root)
2014-02-10 02:10:30 +01:00
2018-01-06 19:48:54 +01:00
ERR_FAIL_COND_V ( cache . font . is_null ( ) , - 1 ) ;
2014-02-10 02:10:30 +01:00
Ref < Font > font = cache . font ;
2015-08-31 00:37:23 +02:00
2017-03-05 16:44:50 +01:00
int font_ascent = font - > get_ascent ( ) ;
2014-02-10 02:10:30 +01:00
2017-06-25 22:30:28 +02:00
int ofs = p_pos . x + ( ( p_item - > disable_folding | | hide_folding ) ? cache . hseparation : cache . item_margin ) ;
2019-02-12 21:10:08 +01:00
int skip2 = 0 ;
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < columns . size ( ) ; i + + ) {
2014-02-10 02:10:30 +01:00
2019-02-12 21:10:08 +01:00
if ( skip2 ) {
skip2 - - ;
2017-06-25 22:30:28 +02:00
continue ;
}
2014-02-10 02:10:30 +01:00
int w = get_column_width ( i ) ;
2017-03-05 16:44:50 +01:00
if ( i = = 0 ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
w - = ofs ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
if ( w < = 0 ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
ofs = get_column_width ( 0 ) ;
2014-02-10 02:10:30 +01:00
continue ;
}
} else {
2017-03-05 16:44:50 +01:00
ofs + = cache . hseparation ;
w - = cache . hseparation ;
2014-02-10 02:10:30 +01:00
}
2017-06-25 22:30:28 +02:00
if ( p_item - > cells [ i ] . expand_right ) {
int plus = 1 ;
while ( i + plus < columns . size ( ) & & ! p_item - > cells [ i + plus ] . editable & & p_item - > cells [ i + plus ] . mode = = TreeItem : : CELL_MODE_STRING & & p_item - > cells [ i + plus ] . text = = " " & & p_item - > cells [ i + plus ] . icon . is_null ( ) ) {
w + = get_column_width ( i + plus ) ;
plus + + ;
2019-02-12 21:10:08 +01:00
skip2 + + ;
2017-06-25 22:30:28 +02:00
}
}
2017-03-05 16:44:50 +01:00
int bw = 0 ;
for ( int j = p_item - > cells [ i ] . buttons . size ( ) - 1 ; j > = 0 ; j - - ) {
2019-06-11 20:43:37 +02:00
Ref < Texture2D > b = p_item - > cells [ i ] . buttons [ j ] . texture ;
2014-02-10 02:10:30 +01:00
Size2 s = b - > get_size ( ) + cache . button_pressed - > get_minimum_size ( ) ;
2019-06-23 18:06:47 +02:00
if ( s . height < label_h )
s . height = label_h ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
Point2i o = Point2i ( ofs + w - s . width , p_pos . y ) - cache . offset + p_draw_ofs ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
if ( cache . click_type = = Cache : : CLICK_BUTTON & & cache . click_item = = p_item & & cache . click_column = = i & & cache . click_index = = j & & ! p_item - > cells [ i ] . buttons [ j ] . disabled ) {
2014-02-10 02:10:30 +01:00
//being pressed
2017-03-05 16:44:50 +01:00
cache . button_pressed - > draw ( get_canvas_item ( ) , Rect2 ( o , s ) ) ;
2014-02-10 02:10:30 +01:00
}
2017-03-05 16:44:50 +01:00
o . y + = ( label_h - s . height ) / 2 ;
o + = cache . button_pressed - > get_offset ( ) ;
2016-02-03 00:44:42 +01:00
2017-03-05 16:44:50 +01:00
b - > draw ( ci , o , p_item - > cells [ i ] . buttons [ j ] . disabled ? Color ( 1 , 1 , 1 , 0.5 ) : p_item - > cells [ i ] . buttons [ j ] . color ) ;
w - = s . width + cache . button_margin ;
bw + = s . width + cache . button_margin ;
2014-02-10 02:10:30 +01:00
}
2017-03-05 16:44:50 +01:00
Rect2i item_rect = Rect2i ( Point2i ( ofs , p_pos . y ) - cache . offset + p_draw_ofs , Size2i ( w , label_h ) ) ;
Rect2i cell_rect = item_rect ;
if ( i ! = 0 ) {
2017-06-04 00:25:13 +02:00
cell_rect . position . x - = cache . hseparation ;
2017-03-05 16:44:50 +01:00
cell_rect . size . x + = cache . hseparation ;
2014-02-10 02:10:30 +01:00
}
2018-11-19 02:00:31 +01:00
if ( cache . draw_guides ) {
2020-03-27 19:21:27 +01:00
RenderingServer : : get_singleton ( ) - > canvas_item_add_line ( ci , Point2i ( cell_rect . position . x , cell_rect . position . y + cell_rect . size . height ) , cell_rect . position + cell_rect . size , cache . guide_color , 1 ) ;
2018-11-19 02:00:31 +01:00
}
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
if ( i = = 0 ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
if ( p_item - > cells [ 0 ] . selected & & select_mode = = SELECT_ROW ) {
2017-06-04 00:25:13 +02:00
Rect2i row_rect = Rect2i ( Point2i ( cache . bg - > get_margin ( MARGIN_LEFT ) , item_rect . position . y ) , Size2i ( get_size ( ) . width - cache . bg - > get_minimum_size ( ) . width , item_rect . size . y ) ) ;
2014-02-10 02:10:30 +01:00
//Rect2 r = Rect2i(row_rect.pos,row_rect.size);
//r.grow(cache.selected->get_margin(MARGIN_LEFT));
if ( has_focus ( ) )
2017-03-05 16:44:50 +01:00
cache . selected_focus - > draw ( ci , row_rect ) ;
2014-02-10 02:10:30 +01:00
else
2017-03-05 16:44:50 +01:00
cache . selected - > draw ( ci , row_rect ) ;
2014-02-10 02:10:30 +01:00
}
}
2019-11-03 16:08:07 +01:00
if ( ( select_mode = = SELECT_ROW & & selected_item = = p_item ) | | p_item - > cells [ i ] . selected ) {
2017-10-24 20:45:47 +02:00
Rect2i r ( cell_rect . position , cell_rect . size ) ;
2019-08-11 15:54:55 +02:00
2017-03-05 16:44:50 +01:00
if ( p_item - > cells [ i ] . text . size ( ) > 0 ) {
2016-08-20 18:00:25 +02:00
float icon_width = p_item - > cells [ i ] . get_icon_size ( ) . width ;
2017-06-04 00:25:13 +02:00
r . position . x + = icon_width ;
2016-08-20 18:00:25 +02:00
r . size . x - = icon_width ;
}
2019-01-16 12:44:34 +01:00
p_item - > set_meta ( " __focus_rect " , Rect2 ( r . position , r . size ) ) ;
2019-08-11 15:54:55 +02:00
if ( p_item - > cells [ i ] . selected ) {
if ( has_focus ( ) ) {
cache . selected_focus - > draw ( ci , r ) ;
} else {
cache . selected - > draw ( ci , r ) ;
}
2016-08-20 18:00:25 +02:00
}
2014-02-10 02:10:30 +01:00
}
if ( p_item - > cells [ i ] . custom_bg_color ) {
2017-03-05 16:44:50 +01:00
Rect2 r = cell_rect ;
2017-06-26 02:12:36 +02:00
if ( i = = 0 ) {
r . position . x = p_draw_ofs . x ;
r . size . x = w + ofs ;
} else {
r . position . x - = cache . hseparation ;
r . size . x + = cache . hseparation ;
}
2016-05-11 16:46:08 +02:00
if ( p_item - > cells [ i ] . custom_bg_outline ) {
2020-03-27 19:21:27 +01:00
RenderingServer : : get_singleton ( ) - > canvas_item_add_rect ( ci , Rect2 ( r . position . x , r . position . y , r . size . x , 1 ) , p_item - > cells [ i ] . bg_color ) ;
RenderingServer : : get_singleton ( ) - > canvas_item_add_rect ( ci , Rect2 ( r . position . x , r . position . y + r . size . y - 1 , r . size . x , 1 ) , p_item - > cells [ i ] . bg_color ) ;
RenderingServer : : get_singleton ( ) - > canvas_item_add_rect ( ci , Rect2 ( r . position . x , r . position . y , 1 , r . size . y ) , p_item - > cells [ i ] . bg_color ) ;
RenderingServer : : get_singleton ( ) - > canvas_item_add_rect ( ci , Rect2 ( r . position . x + r . size . x - 1 , r . position . y , 1 , r . size . y ) , p_item - > cells [ i ] . bg_color ) ;
2016-05-11 16:46:08 +02:00
} else {
2020-03-27 19:21:27 +01:00
RenderingServer : : get_singleton ( ) - > canvas_item_add_rect ( ci , r , p_item - > cells [ i ] . bg_color ) ;
2016-05-11 16:46:08 +02:00
}
}
2017-03-05 16:44:50 +01:00
if ( drop_mode_flags & & drop_mode_over = = p_item ) {
2016-05-11 16:46:08 +02:00
2017-03-05 16:44:50 +01:00
Rect2 r = cell_rect ;
2016-05-11 16:46:08 +02:00
2017-03-05 16:44:50 +01:00
if ( drop_mode_section = = - 1 | | drop_mode_section = = 0 ) {
2020-03-27 19:21:27 +01:00
RenderingServer : : get_singleton ( ) - > canvas_item_add_rect ( ci , Rect2 ( r . position . x , r . position . y , r . size . x , 1 ) , cache . drop_position_color ) ;
2016-05-11 16:46:08 +02:00
}
2017-03-05 16:44:50 +01:00
if ( drop_mode_section = = 0 ) {
2020-03-27 19:21:27 +01:00
RenderingServer : : get_singleton ( ) - > canvas_item_add_rect ( ci , Rect2 ( r . position . x , r . position . y , 1 , r . size . y ) , cache . drop_position_color ) ;
RenderingServer : : get_singleton ( ) - > canvas_item_add_rect ( ci , Rect2 ( r . position . x + r . size . x - 1 , r . position . y , 1 , r . size . y ) , cache . drop_position_color ) ;
2016-05-11 16:46:08 +02:00
}
2017-03-05 16:44:50 +01:00
if ( drop_mode_section = = 1 | | drop_mode_section = = 0 ) {
2020-03-27 19:21:27 +01:00
RenderingServer : : get_singleton ( ) - > canvas_item_add_rect ( ci , Rect2 ( r . position . x , r . position . y + r . size . y , r . size . x , 1 ) , cache . drop_position_color ) ;
2016-05-11 16:46:08 +02:00
}
2014-02-10 02:10:30 +01:00
}
2020-03-12 13:37:40 +01:00
Color col = p_item - > cells [ i ] . custom_color ? p_item - > cells [ i ] . color : get_theme_color ( p_item - > cells [ i ] . selected ? " font_color_selected " : " font_color " ) ;
2017-07-19 22:00:46 +02:00
Color icon_col = p_item - > cells [ i ] . icon_color ;
2015-08-31 00:37:23 +02:00
2017-06-04 00:25:13 +02:00
Point2i text_pos = item_rect . position ;
2017-03-05 16:44:50 +01:00
text_pos . y + = Math : : floor ( ( item_rect . size . y - font - > get_height ( ) ) / 2 ) + font_ascent ;
2014-02-10 02:10:30 +01:00
switch ( p_item - > cells [ i ] . mode ) {
case TreeItem : : CELL_MODE_STRING : {
2017-07-19 22:00:46 +02:00
draw_item_rect ( p_item - > cells [ i ] , item_rect , col , icon_col ) ;
2014-02-10 02:10:30 +01:00
} break ;
case TreeItem : : CELL_MODE_CHECK : {
2019-06-11 20:43:37 +02:00
Ref < Texture2D > checked = cache . checked ;
Ref < Texture2D > unchecked = cache . unchecked ;
2017-06-04 00:25:13 +02:00
Point2i check_ofs = item_rect . position ;
2017-03-05 16:44:50 +01:00
check_ofs . y + = Math : : floor ( ( real_t ) ( item_rect . size . y - checked - > get_height ( ) ) / 2 ) ;
2014-02-10 02:10:30 +01:00
if ( p_item - > cells [ i ] . checked ) {
2019-08-24 17:13:48 +02:00
checked - > draw ( ci , check_ofs ) ;
2014-02-10 02:10:30 +01:00
} else {
2019-08-24 17:13:48 +02:00
unchecked - > draw ( ci , check_ofs ) ;
2014-02-10 02:10:30 +01:00
}
2017-03-05 16:44:50 +01:00
int check_w = checked - > get_width ( ) + cache . hseparation ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
text_pos . x + = check_w ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
item_rect . size . x - = check_w ;
2017-06-04 00:25:13 +02:00
item_rect . position . x + = check_w ;
2014-02-10 02:10:30 +01:00
2017-07-19 22:00:46 +02:00
draw_item_rect ( p_item - > cells [ i ] , item_rect , col , icon_col ) ;
2014-02-10 02:10:30 +01:00
} break ;
2018-09-22 22:31:56 +02:00
case TreeItem : : CELL_MODE_RANGE : {
2017-03-05 16:44:50 +01:00
if ( p_item - > cells [ i ] . text ! = " " ) {
2014-02-10 02:10:30 +01:00
if ( ! p_item - > cells [ i ] . editable )
break ;
int option = ( int ) p_item - > cells [ i ] . val ;
2017-11-15 19:50:37 +01:00
String s = RTR ( " (Other) " ) ;
Vector < String > strings = p_item - > cells [ i ] . text . split ( " , " ) ;
2018-09-27 13:11:41 +02:00
for ( int j = 0 ; j < strings . size ( ) ; j + + ) {
int value = j ;
if ( ! strings [ j ] . get_slicec ( ' : ' , 1 ) . empty ( ) ) {
value = strings [ j ] . get_slicec ( ' : ' , 1 ) . to_int ( ) ;
2017-11-15 19:50:37 +01:00
}
if ( option = = value ) {
2018-09-27 13:11:41 +02:00
s = strings [ j ] . get_slicec ( ' : ' , 0 ) ;
2017-11-15 19:50:37 +01:00
break ;
}
}
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
if ( p_item - > cells [ i ] . suffix ! = String ( ) )
s + = " " + p_item - > cells [ i ] . suffix ;
2016-08-31 04:44:14 +02:00
2019-06-11 20:43:37 +02:00
Ref < Texture2D > downarrow = cache . select_arrow ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
font - > draw ( ci , text_pos , s , col , item_rect . size . x - downarrow - > get_width ( ) ) ;
2014-02-10 02:10:30 +01:00
2017-06-04 00:25:13 +02:00
Point2i arrow_pos = item_rect . position ;
2017-03-05 16:44:50 +01:00
arrow_pos . x + = item_rect . size . x - downarrow - > get_width ( ) ;
arrow_pos . y + = Math : : floor ( ( ( item_rect . size . y - downarrow - > get_height ( ) ) ) / 2.0 ) ;
2014-02-10 02:10:30 +01:00
2019-08-24 17:13:48 +02:00
downarrow - > draw ( ci , arrow_pos ) ;
2014-02-10 02:10:30 +01:00
} else {
2019-06-11 20:43:37 +02:00
Ref < Texture2D > updown = cache . updown ;
2015-08-31 00:37:23 +02:00
2019-07-23 17:27:55 +02:00
String valtext = String : : num ( p_item - > cells [ i ] . val , Math : : range_step_decimals ( p_item - > cells [ i ] . step ) ) ;
2016-08-31 04:44:14 +02:00
2017-03-05 16:44:50 +01:00
if ( p_item - > cells [ i ] . suffix ! = String ( ) )
valtext + = " " + p_item - > cells [ i ] . suffix ;
2016-08-31 04:44:14 +02:00
2017-03-05 16:44:50 +01:00
font - > draw ( ci , text_pos , valtext , col , item_rect . size . x - updown - > get_width ( ) ) ;
2014-02-10 02:10:30 +01:00
if ( ! p_item - > cells [ i ] . editable )
break ;
2017-06-04 00:25:13 +02:00
Point2i updown_pos = item_rect . position ;
2017-03-05 16:44:50 +01:00
updown_pos . x + = item_rect . size . x - updown - > get_width ( ) ;
updown_pos . y + = Math : : floor ( ( ( item_rect . size . y - updown - > get_height ( ) ) ) / 2.0 ) ;
2014-02-10 02:10:30 +01:00
2019-08-24 17:13:48 +02:00
updown - > draw ( ci , updown_pos ) ;
2014-02-10 02:10:30 +01:00
}
} break ;
case TreeItem : : CELL_MODE_ICON : {
if ( p_item - > cells [ i ] . icon . is_null ( ) )
break ;
Size2i icon_size = p_item - > cells [ i ] . get_icon_size ( ) ;
2017-03-05 16:44:50 +01:00
if ( p_item - > cells [ i ] . icon_max_w > 0 & & icon_size . width > p_item - > cells [ i ] . icon_max_w ) {
2014-02-10 02:10:30 +01:00
icon_size . height = icon_size . height * p_item - > cells [ i ] . icon_max_w / icon_size . width ;
2017-03-05 16:44:50 +01:00
icon_size . width = p_item - > cells [ i ] . icon_max_w ;
2014-02-10 02:10:30 +01:00
}
2017-03-05 16:44:50 +01:00
Point2i icon_ofs = ( item_rect . size - icon_size ) / 2 ;
2017-06-04 00:25:13 +02:00
icon_ofs + = item_rect . position ;
2014-02-10 02:10:30 +01:00
2017-07-19 22:00:46 +02:00
draw_texture_rect ( p_item - > cells [ i ] . icon , Rect2 ( icon_ofs , icon_size ) , false , icon_col ) ;
2014-02-10 02:10:30 +01:00
} break ;
case TreeItem : : CELL_MODE_CUSTOM : {
2020-02-12 18:24:06 +01:00
if ( p_item - > cells [ i ] . custom_draw_obj . is_valid ( ) ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
Object * cdo = ObjectDB : : get_instance ( p_item - > cells [ i ] . custom_draw_obj ) ;
2014-02-10 02:10:30 +01:00
if ( cdo )
2017-03-05 16:44:50 +01:00
cdo - > call ( p_item - > cells [ i ] . custom_draw_callback , p_item , Rect2 ( item_rect ) ) ;
2014-02-10 02:10:30 +01:00
}
if ( ! p_item - > cells [ i ] . editable ) {
2017-07-19 22:00:46 +02:00
draw_item_rect ( p_item - > cells [ i ] , item_rect , col , icon_col ) ;
2014-02-10 02:10:30 +01:00
break ;
}
2019-06-11 20:43:37 +02:00
Ref < Texture2D > downarrow = cache . select_arrow ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
Rect2i ir = item_rect ;
2015-08-31 00:37:23 +02:00
2017-06-04 00:25:13 +02:00
Point2i arrow_pos = item_rect . position ;
2017-03-05 16:44:50 +01:00
arrow_pos . x + = item_rect . size . x - downarrow - > get_width ( ) ;
arrow_pos . y + = Math : : floor ( ( ( item_rect . size . y - downarrow - > get_height ( ) ) ) / 2.0 ) ;
2017-06-05 01:35:08 +02:00
ir . size . width - = downarrow - > get_width ( ) ;
if ( p_item - > cells [ i ] . custom_button ) {
if ( cache . hover_item = = p_item & & cache . hover_cell = = i ) {
2020-03-04 17:36:09 +01:00
if ( InputFilter : : get_singleton ( ) - > is_mouse_button_pressed ( BUTTON_LEFT ) ) {
2017-06-05 01:35:08 +02:00
draw_style_box ( cache . custom_button_pressed , ir ) ;
} else {
draw_style_box ( cache . custom_button_hover , ir ) ;
col = cache . custom_button_font_highlight ;
}
} else {
draw_style_box ( cache . custom_button , ir ) ;
}
ir . size - = cache . custom_button - > get_minimum_size ( ) ;
2017-06-05 16:15:01 +02:00
ir . position + = cache . custom_button - > get_offset ( ) ;
2017-06-05 01:35:08 +02:00
}
2017-07-19 22:00:46 +02:00
draw_item_rect ( p_item - > cells [ i ] , ir , col , icon_col ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
downarrow - > draw ( ci , arrow_pos ) ;
2014-02-10 02:10:30 +01:00
} break ;
}
2017-03-05 16:44:50 +01:00
if ( i = = 0 ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
ofs = get_column_width ( 0 ) ;
2014-02-10 02:10:30 +01:00
} else {
2017-03-05 16:44:50 +01:00
ofs + = w + bw ;
2014-02-10 02:10:30 +01:00
}
2017-03-05 16:44:50 +01:00
if ( select_mode = = SELECT_MULTI & & selected_item = = p_item & & selected_col = = i ) {
2014-02-10 02:10:30 +01:00
if ( has_focus ( ) )
2017-03-05 16:44:50 +01:00
cache . cursor - > draw ( ci , cell_rect ) ;
2014-02-10 02:10:30 +01:00
else
2017-03-05 16:44:50 +01:00
cache . cursor_unfocus - > draw ( ci , cell_rect ) ;
2014-02-10 02:10:30 +01:00
}
}
2018-01-18 21:37:17 +01:00
if ( ! p_item - > disable_folding & & ! hide_folding & & p_item - > children ) { //has children, draw the guide box
2017-06-26 02:12:36 +02:00
2019-06-11 20:43:37 +02:00
Ref < Texture2D > arrow ;
2017-06-26 02:12:36 +02:00
if ( p_item - > collapsed ) {
arrow = cache . arrow_collapsed ;
} else {
arrow = cache . arrow ;
}
arrow - > draw ( ci , p_pos + p_draw_ofs + Point2i ( 0 , ( label_h - arrow - > get_height ( ) ) / 2 ) - cache . offset ) ;
}
2014-02-10 02:10:30 +01:00
}
2017-03-05 16:44:50 +01:00
Point2 children_pos = p_pos ;
2014-02-10 02:10:30 +01:00
if ( ! skip ) {
2017-03-05 16:44:50 +01:00
children_pos . x + = cache . item_margin ;
htotal + = label_h ;
children_pos . y + = htotal ;
2014-02-10 02:10:30 +01:00
}
2018-01-18 21:37:17 +01:00
if ( ! p_item - > collapsed ) { /* if not collapsed, check the children */
2014-02-10 02:10:30 +01:00
2018-01-18 21:37:17 +01:00
TreeItem * c = p_item - > children ;
2014-02-10 02:10:30 +01:00
2019-03-06 16:10:36 +01:00
int prev_ofs = children_pos . y - cache . offset . y + p_draw_ofs . y ;
2014-02-10 02:10:30 +01:00
while ( c ) {
2018-12-25 01:18:18 +01:00
if ( cache . draw_relationship_lines > 0 & & ( ! hide_root | | c - > parent ! = root ) ) {
2017-06-25 22:30:28 +02:00
int root_ofs = children_pos . x + ( ( p_item - > disable_folding | | hide_folding ) ? cache . hseparation : cache . item_margin ) ;
int parent_ofs = p_pos . x + ( ( p_item - > disable_folding | | hide_folding ) ? cache . hseparation : cache . item_margin ) ;
2017-03-05 16:44:50 +01:00
Point2i root_pos = Point2i ( root_ofs , children_pos . y + label_h / 2 ) - cache . offset + p_draw_ofs ;
2019-03-06 16:10:36 +01:00
2020-04-02 01:20:12 +02:00
if ( c - > get_children ( ) ! = nullptr )
2017-03-05 16:44:50 +01:00
root_pos - = Point2i ( cache . arrow - > get_width ( ) , 0 ) ;
2016-06-15 19:10:19 +02:00
2017-12-15 18:40:45 +01:00
float line_width = 1.0 ;
# ifdef TOOLS_ENABLED
line_width * = EDSCALE ;
# endif
2017-03-05 16:44:50 +01:00
Point2i parent_pos = Point2i ( parent_ofs - cache . arrow - > get_width ( ) / 2 , p_pos . y + label_h / 2 + cache . arrow - > get_height ( ) / 2 ) - cache . offset + p_draw_ofs ;
2018-01-04 10:03:46 +01:00
if ( root_pos . y + line_width > = 0 ) {
2020-03-27 19:21:27 +01:00
RenderingServer : : get_singleton ( ) - > canvas_item_add_line ( ci , root_pos , Point2i ( parent_pos . x - Math : : floor ( line_width / 2 ) , root_pos . y ) , cache . relationship_line_color , line_width ) ;
RenderingServer : : get_singleton ( ) - > canvas_item_add_line ( ci , Point2i ( parent_pos . x , root_pos . y ) , Point2i ( parent_pos . x , prev_ofs ) , cache . relationship_line_color , line_width ) ;
2018-01-04 10:03:46 +01:00
}
if ( htotal < 0 ) {
return - 1 ;
}
2019-03-06 16:10:36 +01:00
prev_ofs = root_pos . y ;
2016-06-15 19:10:19 +02:00
}
2018-01-04 10:03:46 +01:00
if ( htotal > = 0 ) {
int child_h = draw_item ( children_pos , p_draw_ofs , p_draw_size , c ) ;
2014-02-10 02:10:30 +01:00
2018-01-04 10:03:46 +01:00
if ( child_h < 0 ) {
if ( cache . draw_relationship_lines = = 0 ) {
return - 1 ; // break, stop drawing, no need to anymore
} else {
htotal = - 1 ;
children_pos . y = cache . offset . y + p_draw_size . height ;
}
} else {
htotal + = child_h ;
children_pos . y + = child_h ;
}
}
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
c = c - > next ;
2014-02-10 02:10:30 +01:00
}
}
return htotal ;
}
2017-03-05 16:44:50 +01:00
int Tree : : _count_selected_items ( TreeItem * p_from ) const {
2016-05-11 16:46:08 +02:00
2017-03-05 16:44:50 +01:00
int count = 0 ;
for ( int i = 0 ; i < columns . size ( ) ; i + + ) {
2016-05-11 16:46:08 +02:00
if ( p_from - > is_selected ( i ) )
count + + ;
}
if ( p_from - > get_children ( ) ) {
2017-03-05 16:44:50 +01:00
count + = _count_selected_items ( p_from - > get_children ( ) ) ;
2016-05-11 16:46:08 +02:00
}
if ( p_from - > get_next ( ) ) {
2017-03-05 16:44:50 +01:00
count + = _count_selected_items ( p_from - > get_next ( ) ) ;
2016-05-11 16:46:08 +02:00
}
return count ;
}
2016-07-09 18:14:46 +02:00
void Tree : : select_single_item ( TreeItem * p_selected , TreeItem * p_current , int p_col , TreeItem * p_prev , bool * r_in_range , bool p_force_deselect ) {
2014-02-10 02:10:30 +01:00
2018-07-25 03:11:03 +02:00
TreeItem : : Cell & selected_cell = p_selected - > cells . write [ p_col ] ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
bool switched = false ;
if ( r_in_range & & ! * r_in_range & & ( p_current = = p_selected | | p_current = = p_prev ) ) {
* r_in_range = true ;
switched = true ;
2014-02-10 02:10:30 +01:00
}
2017-03-05 16:44:50 +01:00
bool emitted_row = false ;
2016-06-30 22:51:45 +02:00
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < columns . size ( ) ; i + + ) {
2014-02-10 02:10:30 +01:00
2018-07-25 03:11:03 +02:00
TreeItem : : Cell & c = p_current - > cells . write [ i ] ;
2014-02-10 02:10:30 +01:00
if ( ! c . selectable )
continue ;
2017-03-05 16:44:50 +01:00
if ( select_mode = = SELECT_ROW ) {
2015-08-31 00:37:23 +02:00
2017-08-18 23:19:12 +02:00
if ( p_selected = = p_current & & ( ! c . selected | | allow_reselect ) ) {
2017-03-05 16:44:50 +01:00
c . selected = true ;
selected_item = p_selected ;
selected_col = 0 ;
if ( ! emitted_row ) {
emit_signal ( " item_selected " ) ;
emitted_row = true ;
}
/*
2017-01-14 12:26:56 +01:00
if ( p_col = = i )
p_current - > selected_signal . call ( p_col ) ;
*/
2015-08-31 00:37:23 +02:00
2016-12-20 22:47:24 +01:00
} else if ( c . selected ) {
2015-08-31 00:37:23 +02:00
2017-03-05 16:44:50 +01:00
c . selected = false ;
//p_current->deselected_signal.call(p_col);
2014-02-10 02:10:30 +01:00
}
2017-03-05 16:44:50 +01:00
} else if ( select_mode = = SELECT_SINGLE | | select_mode = = SELECT_MULTI ) {
2015-08-31 00:37:23 +02:00
2017-03-05 16:44:50 +01:00
if ( ! r_in_range & & & selected_cell = = & c ) {
2015-08-31 00:37:23 +02:00
2017-08-18 23:19:12 +02:00
if ( ! selected_cell . selected | | allow_reselect ) {
2015-08-31 00:37:23 +02:00
2017-03-05 16:44:50 +01:00
selected_cell . selected = true ;
2015-08-31 00:37:23 +02:00
2017-03-05 16:44:50 +01:00
selected_item = p_selected ;
selected_col = i ;
2015-08-30 04:46:32 +02:00
2014-02-10 02:10:30 +01:00
emit_signal ( " cell_selected " ) ;
2017-03-05 16:44:50 +01:00
if ( select_mode = = SELECT_MULTI )
emit_signal ( " multi_selected " , p_current , i , true ) ;
else if ( select_mode = = SELECT_SINGLE )
2016-12-20 22:47:24 +01:00
emit_signal ( " item_selected " ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
} else if ( select_mode = = SELECT_MULTI & & ( selected_item ! = p_selected | | selected_col ! = i ) ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
selected_item = p_selected ;
selected_col = i ;
2014-02-10 02:10:30 +01:00
emit_signal ( " cell_selected " ) ;
}
} else {
2015-08-31 00:37:23 +02:00
2016-07-09 18:14:46 +02:00
if ( r_in_range & & * r_in_range & & ! p_force_deselect ) {
2014-02-10 02:10:30 +01:00
if ( ! c . selected & & c . selectable ) {
2017-03-05 16:44:50 +01:00
c . selected = true ;
emit_signal ( " multi_selected " , p_current , i , true ) ;
2014-02-10 02:10:30 +01:00
}
2017-03-05 16:44:50 +01:00
} else if ( ! r_in_range | | p_force_deselect ) {
if ( select_mode = = SELECT_MULTI & & c . selected )
emit_signal ( " multi_selected " , p_current , i , false ) ;
c . selected = false ;
2014-02-10 02:10:30 +01:00
}
//p_current->deselected_signal.call(p_col);
}
}
}
2017-03-05 16:44:50 +01:00
if ( ! switched & & r_in_range & & * r_in_range & & ( p_current = = p_selected | | p_current = = p_prev ) ) {
* r_in_range = false ;
2014-02-10 02:10:30 +01:00
}
2018-01-18 21:37:17 +01:00
TreeItem * c = p_current - > children ;
2014-02-10 02:10:30 +01:00
while ( c ) {
2017-03-05 16:44:50 +01:00
select_single_item ( p_selected , c , p_col , p_prev , r_in_range , p_current - > is_collapsed ( ) | | p_force_deselect ) ;
c = c - > next ;
2014-02-10 02:10:30 +01:00
}
}
Rect2 Tree : : search_item_rect ( TreeItem * p_from , TreeItem * p_item ) {
return Rect2 ( ) ;
}
2015-12-08 19:04:56 +01:00
void Tree : : _range_click_timeout ( ) {
2014-02-10 02:10:30 +01:00
2020-03-04 17:36:09 +01:00
if ( range_item_last & & ! range_drag_enabled & & InputFilter : : get_singleton ( ) - > is_mouse_button_pressed ( BUTTON_LEFT ) ) {
2015-12-08 19:04:56 +01:00
2017-09-10 15:37:49 +02:00
Point2 pos = get_local_mouse_position ( ) - cache . bg - > get_offset ( ) ;
2015-12-08 19:04:56 +01:00
if ( show_column_titles ) {
2017-03-05 16:44:50 +01:00
pos . y - = _get_title_button_height ( ) ;
2015-12-08 19:04:56 +01:00
2017-03-05 16:44:50 +01:00
if ( pos . y < 0 ) {
2015-12-08 19:04:56 +01:00
range_click_timer - > stop ( ) ;
return ;
}
}
2017-03-05 16:44:50 +01:00
click_handled = false ;
2017-05-20 17:38:03 +02:00
Ref < InputEventMouseButton > mb ;
mb . instance ( ) ;
;
2015-12-08 19:04:56 +01:00
2019-02-13 09:23:29 +01:00
propagate_mouse_activated = false ; // done from outside, so signal handler can't clear the tree in the middle of emit (which is a common case)
2015-12-08 19:04:56 +01:00
blocked + + ;
2017-05-20 17:38:03 +02:00
propagate_mouse_event ( pos + cache . offset , 0 , 0 , false , root , BUTTON_LEFT , mb ) ;
2015-12-08 19:04:56 +01:00
blocked - - ;
if ( range_click_timer - > is_one_shot ( ) ) {
range_click_timer - > set_wait_time ( 0.05 ) ;
range_click_timer - > set_one_shot ( false ) ;
range_click_timer - > start ( ) ;
}
if ( ! click_handled )
range_click_timer - > stop ( ) ;
2019-01-14 21:20:33 +01:00
if ( propagate_mouse_activated ) {
emit_signal ( " item_activated " ) ;
propagate_mouse_activated = false ;
}
2015-12-08 19:04:56 +01:00
} else {
range_click_timer - > stop ( ) ;
}
}
2014-02-10 02:10:30 +01:00
2017-05-20 17:38:03 +02:00
int Tree : : propagate_mouse_event ( const Point2i & p_pos , int x_ofs , int y_ofs , bool p_doubleclick , TreeItem * p_item , int p_button , const Ref < InputEventWithModifiers > & p_mod ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
int item_h = compute_item_height ( p_item ) + cache . vseparation ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
bool skip = ( p_item = = root & & hide_root ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
if ( ! skip & & p_pos . y < item_h ) {
2014-02-10 02:10:30 +01:00
// check event!
2016-01-21 14:08:40 +01:00
if ( range_click_timer - > get_time_left ( ) > 0 & & p_item ! = range_item_last ) {
return - 1 ;
}
2017-06-25 22:30:28 +02:00
if ( ! p_item - > disable_folding & & ! hide_folding & & ( p_pos . x > = x_ofs & & p_pos . x < ( x_ofs + cache . item_margin ) ) ) {
2014-02-10 02:10:30 +01:00
2018-01-18 21:37:17 +01:00
if ( p_item - > children )
2017-03-05 16:44:50 +01:00
p_item - > set_collapsed ( ! p_item - > is_collapsed ( ) ) ;
2014-02-10 02:10:30 +01:00
return - 1 ; //handled!
}
2015-08-31 00:37:23 +02:00
2017-03-05 16:44:50 +01:00
int x = p_pos . x ;
2014-02-10 02:10:30 +01:00
/* find clicked column */
2017-03-05 16:44:50 +01:00
int col = - 1 ;
int col_ofs = 0 ;
int col_width = 0 ;
for ( int i = 0 ; i < columns . size ( ) ; i + + ) {
col_width = get_column_width ( i ) ;
2017-06-25 22:30:28 +02:00
if ( p_item - > cells [ i ] . expand_right ) {
int plus = 1 ;
while ( i + plus < columns . size ( ) & & ! p_item - > cells [ i + plus ] . editable & & p_item - > cells [ i + plus ] . mode = = TreeItem : : CELL_MODE_STRING & & p_item - > cells [ i + plus ] . text = = " " & & p_item - > cells [ i + plus ] . icon . is_null ( ) ) {
col_width + = cache . hseparation ;
col_width + = get_column_width ( i + plus ) ;
plus + + ;
}
}
2017-03-05 16:44:50 +01:00
if ( x > col_width ) {
col_ofs + = col_width ;
x - = col_width ;
2014-02-10 02:10:30 +01:00
continue ;
}
2017-03-05 16:44:50 +01:00
col = i ;
2014-02-10 02:10:30 +01:00
break ;
}
2017-03-05 16:44:50 +01:00
if ( col = = - 1 )
2014-02-10 02:10:30 +01:00
return - 1 ;
2017-03-05 16:44:50 +01:00
else if ( col = = 0 ) {
int margin = x_ofs + cache . item_margin ; //-cache.hseparation;
2014-02-10 02:10:30 +01:00
//int lm = cache.bg->get_margin(MARGIN_LEFT);
2017-03-05 16:44:50 +01:00
col_width - = margin ;
col_ofs + = margin ;
x - = margin ;
2014-02-10 02:10:30 +01:00
} else {
2017-03-05 16:44:50 +01:00
col_width - = cache . hseparation ;
x - = cache . hseparation ;
2014-02-10 02:10:30 +01:00
}
2017-06-25 22:30:28 +02:00
if ( ! p_item - > disable_folding & & ! hide_folding & & ! p_item - > cells [ col ] . editable & & ! p_item - > cells [ col ] . selectable & & p_item - > get_children ( ) ) {
p_item - > set_collapsed ( ! p_item - > is_collapsed ( ) ) ;
return - 1 ; //collapse/uncollapse because nothing can be done with item
}
2018-07-25 03:11:03 +02:00
const TreeItem : : Cell & c = p_item - > cells [ col ] ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
bool already_selected = c . selected ;
bool already_cursor = ( p_item = = selected_item ) & & col = = selected_col ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
for ( int j = c . buttons . size ( ) - 1 ; j > = 0 ; j - - ) {
2019-06-11 20:43:37 +02:00
Ref < Texture2D > b = c . buttons [ j ] . texture ;
2014-02-10 02:10:30 +01:00
int w = b - > get_size ( ) . width + cache . button_pressed - > get_minimum_size ( ) . width ;
2016-02-03 00:44:42 +01:00
2017-03-05 16:44:50 +01:00
if ( x > col_width - w ) {
2016-02-03 00:44:42 +01:00
if ( c . buttons [ j ] . disabled ) {
2017-03-05 16:44:50 +01:00
pressed_button = - 1 ;
cache . click_type = Cache : : CLICK_NONE ;
2016-02-03 00:44:42 +01:00
return - 1 ;
}
2017-03-05 16:44:50 +01:00
pressed_button = j ;
cache . click_type = Cache : : CLICK_BUTTON ;
cache . click_index = j ;
cache . click_id = c . buttons [ j ] . id ;
cache . click_item = p_item ;
cache . click_column = col ;
2017-03-29 17:29:38 +02:00
cache . click_pos = get_global_mouse_position ( ) - get_global_position ( ) ;
2014-02-10 02:10:30 +01:00
update ( ) ;
//emit_signal("button_pressed");
return - 1 ;
}
2017-03-05 16:44:50 +01:00
col_width - = w + cache . button_margin ;
2014-02-10 02:10:30 +01:00
}
2017-03-05 16:44:50 +01:00
if ( p_button = = BUTTON_LEFT | | ( p_button = = BUTTON_RIGHT & & allow_rmb_select ) ) {
2014-02-10 02:10:30 +01:00
/* process selection */
2018-09-13 03:38:39 +02:00
if ( p_doubleclick & & ( ! c . editable | | c . mode = = TreeItem : : CELL_MODE_CUSTOM | | c . mode = = TreeItem : : CELL_MODE_ICON /*|| c.mode==TreeItem::CELL_MODE_CHECK*/ ) ) { //it's confusing for check
2014-02-10 02:10:30 +01:00
2019-01-14 21:20:33 +01:00
propagate_mouse_activated = true ;
2017-05-04 22:01:26 +02:00
incr_search . clear ( ) ;
2014-02-10 02:10:30 +01:00
return - 1 ;
}
2017-05-20 17:38:03 +02:00
if ( select_mode = = SELECT_MULTI & & p_mod - > get_command ( ) & & c . selectable ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
if ( ! c . selected | | p_button = = BUTTON_RIGHT ) {
2014-02-10 02:10:30 +01:00
p_item - > select ( col ) ;
2017-03-05 16:44:50 +01:00
emit_signal ( " multi_selected " , p_item , col , true ) ;
if ( p_button = = BUTTON_RIGHT ) {
2017-09-10 15:37:49 +02:00
emit_signal ( " item_rmb_selected " , get_local_mouse_position ( ) ) ;
2016-05-16 04:41:48 +02:00
}
2014-02-10 02:10:30 +01:00
//p_item->selected_signal.call(col);
} else {
p_item - > deselect ( col ) ;
2017-03-05 16:44:50 +01:00
emit_signal ( " multi_selected " , p_item , col , false ) ;
2014-02-10 02:10:30 +01:00
//p_item->deselected_signal.call(col);
}
} else {
if ( c . selectable ) {
2017-05-20 17:38:03 +02:00
if ( select_mode = = SELECT_MULTI & & p_mod - > get_shift ( ) & & selected_item & & selected_item ! = p_item ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
bool inrange = false ;
2015-08-30 04:46:32 +02:00
2017-03-05 16:44:50 +01:00
select_single_item ( p_item , root , col , selected_item , & inrange ) ;
if ( p_button = = BUTTON_RIGHT ) {
2017-09-10 15:37:49 +02:00
emit_signal ( " item_rmb_selected " , get_local_mouse_position ( ) ) ;
2016-05-16 04:41:48 +02:00
}
2014-02-10 02:10:30 +01:00
} else {
2016-05-11 16:46:08 +02:00
int icount = _count_selected_items ( root ) ;
2017-03-05 16:44:50 +01:00
if ( select_mode = = SELECT_MULTI & & icount > 1 & & p_button ! = BUTTON_RIGHT ) {
single_select_defer = p_item ;
single_select_defer_column = col ;
2016-05-11 16:46:08 +02:00
} else {
2016-05-16 04:41:48 +02:00
2017-03-05 16:44:50 +01:00
if ( p_button ! = BUTTON_RIGHT | | ! c . selected ) {
select_single_item ( p_item , root , col ) ;
2016-05-16 04:41:48 +02:00
}
2017-03-05 16:44:50 +01:00
if ( p_button = = BUTTON_RIGHT ) {
2017-09-10 15:37:49 +02:00
emit_signal ( " item_rmb_selected " , get_local_mouse_position ( ) ) ;
2016-05-16 04:41:48 +02:00
}
2016-05-11 16:46:08 +02:00
}
2014-02-10 02:10:30 +01:00
}
2017-01-14 12:26:56 +01:00
/*
if ( ! c . selected & & select_mode = = SELECT_MULTI ) {
emit_signal ( " multi_selected " , p_item , col , true ) ;
}
*/
2014-02-10 02:10:30 +01:00
update ( ) ;
}
}
}
if ( ! c . editable )
return - 1 ; // if cell is not editable, don't bother
/* editing */
2017-08-18 23:19:12 +02:00
bool bring_up_editor = allow_reselect ? ( c . selected & & already_selected ) : c . selected ;
2017-03-05 16:44:50 +01:00
String editor_text = c . text ;
2014-02-10 02:10:30 +01:00
switch ( c . mode ) {
case TreeItem : : CELL_MODE_STRING : {
//nothing in particular
2017-12-26 13:48:50 +01:00
if ( select_mode = = SELECT_MULTI & & ( get_tree ( ) - > get_event_count ( ) = = focus_in_id | | ! already_cursor ) ) {
2017-03-05 16:44:50 +01:00
bring_up_editor = false ;
2014-02-10 02:10:30 +01:00
}
} break ;
case TreeItem : : CELL_MODE_CHECK : {
2015-08-31 00:37:23 +02:00
2017-03-05 16:44:50 +01:00
bring_up_editor = false ; //checkboxes are not edited with editor
2017-01-21 23:00:25 +01:00
if ( force_edit_checkbox_only_on_checkbox ) {
if ( x < cache . checked - > get_width ( ) ) {
p_item - > set_checked ( col , ! c . checked ) ;
item_edited ( col , p_item ) ;
}
} else {
p_item - > set_checked ( col , ! c . checked ) ;
item_edited ( col , p_item ) ;
}
2016-09-19 23:07:24 +02:00
click_handled = true ;
//p_item->edited_signal.call(col);
2014-02-10 02:10:30 +01:00
} break ;
2018-09-22 22:31:56 +02:00
case TreeItem : : CELL_MODE_RANGE : {
2017-03-05 16:44:50 +01:00
if ( c . text ! = " " ) {
2014-02-10 02:10:30 +01:00
//if (x >= (get_column_width(col)-item_h/2)) {
popup_menu - > clear ( ) ;
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < c . text . get_slice_count ( " , " ) ; i + + ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
String s = c . text . get_slicec ( ' , ' , i ) ;
2017-11-15 19:50:37 +01:00
popup_menu - > add_item ( s . get_slicec ( ' : ' , 0 ) , s . get_slicec ( ' : ' , 1 ) . empty ( ) ? i : s . get_slicec ( ' : ' , 1 ) . to_int ( ) ) ;
2014-02-10 02:10:30 +01:00
}
2017-03-05 16:44:50 +01:00
popup_menu - > set_size ( Size2 ( col_width , 0 ) ) ;
2017-03-29 17:29:38 +02:00
popup_menu - > set_position ( get_global_position ( ) + Point2i ( col_ofs , _get_title_button_height ( ) + y_ofs + item_h ) - cache . offset ) ;
2014-02-10 02:10:30 +01:00
popup_menu - > popup ( ) ;
2017-03-05 16:44:50 +01:00
popup_edited_item = p_item ;
popup_edited_item_col = col ;
2014-02-10 02:10:30 +01:00
//}
2017-03-05 16:44:50 +01:00
bring_up_editor = false ;
2014-02-10 02:10:30 +01:00
} else {
2015-08-31 00:37:23 +02:00
2017-03-05 16:44:50 +01:00
if ( x > = ( col_width - item_h / 2 ) ) {
2015-08-31 00:37:23 +02:00
2014-02-10 02:10:30 +01:00
/* touching the combo */
2017-03-05 16:44:50 +01:00
bool up = p_pos . y < ( item_h / 2 ) ;
2015-08-31 00:37:23 +02:00
2017-03-05 16:44:50 +01:00
if ( p_button = = BUTTON_LEFT ) {
2015-12-08 19:04:56 +01:00
if ( range_click_timer - > get_time_left ( ) = = 0 ) {
2017-03-05 16:44:50 +01:00
range_item_last = p_item ;
range_up_last = up ;
2015-12-08 19:04:56 +01:00
range_click_timer - > set_wait_time ( 0.6 ) ;
range_click_timer - > set_one_shot ( true ) ;
range_click_timer - > start ( ) ;
} else if ( up ! = range_up_last ) {
return - 1 ; // break. avoid changing direction on mouse held
}
2017-03-05 16:44:50 +01:00
p_item - > set_range ( col , c . val + ( up ? 1.0 : - 1.0 ) * c . step ) ;
2015-08-31 00:37:23 +02:00
2017-03-05 16:44:50 +01:00
item_edited ( col , p_item ) ;
2015-12-08 19:04:56 +01:00
2017-03-05 16:44:50 +01:00
} else if ( p_button = = BUTTON_RIGHT ) {
2015-08-31 00:37:23 +02:00
2017-03-05 16:44:50 +01:00
p_item - > set_range ( col , ( up ? c . max : c . min ) ) ;
item_edited ( col , p_item ) ;
} else if ( p_button = = BUTTON_WHEEL_UP ) {
2015-08-31 00:37:23 +02:00
2017-03-05 16:44:50 +01:00
p_item - > set_range ( col , c . val + c . step ) ;
item_edited ( col , p_item ) ;
} else if ( p_button = = BUTTON_WHEEL_DOWN ) {
2015-08-31 00:37:23 +02:00
2017-03-05 16:44:50 +01:00
p_item - > set_range ( col , c . val - c . step ) ;
item_edited ( col , p_item ) ;
2014-02-10 02:10:30 +01:00
}
2015-08-31 00:37:23 +02:00
//p_item->edited_signal.call(col);
2017-03-05 16:44:50 +01:00
bring_up_editor = false ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
} else {
2014-02-10 02:10:30 +01:00
2019-07-23 17:27:55 +02:00
editor_text = String : : num ( p_item - > cells [ col ] . val , Math : : range_step_decimals ( p_item - > cells [ col ] . step ) ) ;
2017-12-26 13:48:50 +01:00
if ( select_mode = = SELECT_MULTI & & get_tree ( ) - > get_event_count ( ) = = focus_in_id )
2017-03-05 16:44:50 +01:00
bring_up_editor = false ;
2015-08-31 00:37:23 +02:00
}
2014-02-10 02:10:30 +01:00
}
2017-03-05 16:44:50 +01:00
click_handled = true ;
2014-02-10 02:10:30 +01:00
} break ;
case TreeItem : : CELL_MODE_ICON : {
2017-03-05 16:44:50 +01:00
bring_up_editor = false ;
2014-02-10 02:10:30 +01:00
} break ;
case TreeItem : : CELL_MODE_CUSTOM : {
2017-03-05 16:44:50 +01:00
edited_item = p_item ;
edited_col = col ;
2017-06-05 01:35:08 +02:00
bool on_arrow = x > col_width - cache . select_arrow - > get_width ( ) ;
2017-03-05 16:44:50 +01:00
2017-08-10 21:02:19 +02:00
custom_popup_rect = Rect2i ( get_global_position ( ) + Point2i ( col_ofs , _get_title_button_height ( ) + y_ofs + item_h - cache . offset . y ) , Size2 ( get_column_width ( col ) , item_h ) ) ;
2017-06-05 01:35:08 +02:00
if ( on_arrow | | ! p_item - > cells [ col ] . custom_button ) {
emit_signal ( " custom_popup_edited " , ( ( bool ) ( x > = ( col_width - item_h / 2 ) ) ) ) ;
}
if ( ! p_item - > cells [ col ] . custom_button | | ! on_arrow ) {
2017-08-10 21:02:19 +02:00
item_edited ( col , p_item , p_button = = BUTTON_LEFT ) ;
2017-06-05 01:35:08 +02:00
}
2017-03-05 16:44:50 +01:00
click_handled = true ;
2014-02-10 02:10:30 +01:00
return - 1 ;
} break ;
} ;
2017-03-05 16:44:50 +01:00
if ( ! bring_up_editor | | p_button ! = BUTTON_LEFT )
2014-02-10 02:10:30 +01:00
return - 1 ;
2017-03-05 16:44:50 +01:00
click_handled = true ;
popup_edited_item = p_item ;
popup_edited_item_col = col ;
2014-02-10 02:10:30 +01:00
2017-03-29 17:29:38 +02:00
pressing_item_rect = Rect2 ( get_global_position ( ) + Point2i ( col_ofs , _get_title_button_height ( ) + y_ofs ) - cache . offset , Size2 ( col_width , item_h ) ) ;
2017-03-05 16:44:50 +01:00
pressing_for_editor_text = editor_text ;
pressing_for_editor = true ;
2014-02-10 02:10:30 +01:00
return - 1 ; //select
} else {
2017-03-05 16:44:50 +01:00
Point2i new_pos = p_pos ;
2015-08-31 00:37:23 +02:00
2014-02-10 02:10:30 +01:00
if ( ! skip ) {
2017-03-05 16:44:50 +01:00
x_ofs + = cache . item_margin ;
2014-02-10 02:10:30 +01:00
//new_pos.x-=cache.item_margin;
2017-03-05 16:44:50 +01:00
y_ofs + = item_h ;
new_pos . y - = item_h ;
2014-02-10 02:10:30 +01:00
}
2015-08-31 00:37:23 +02:00
2018-01-18 21:37:17 +01:00
if ( ! p_item - > collapsed ) { /* if not collapsed, check the children */
2014-02-10 02:10:30 +01:00
2018-01-18 21:37:17 +01:00
TreeItem * c = p_item - > children ;
2014-02-10 02:10:30 +01:00
while ( c ) {
2017-03-05 16:44:50 +01:00
int child_h = propagate_mouse_event ( new_pos , x_ofs , y_ofs , p_doubleclick , c , p_button , p_mod ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
if ( child_h < 0 )
2014-02-10 02:10:30 +01:00
return - 1 ; // break, stop propagating, no need to anymore
2017-03-05 16:44:50 +01:00
new_pos . y - = child_h ;
y_ofs + = child_h ;
c = c - > next ;
item_h + = child_h ;
2014-02-10 02:10:30 +01:00
}
}
2019-04-09 19:22:14 +02:00
if ( p_item = = root & & p_button = = BUTTON_RIGHT ) {
emit_signal ( " empty_rmb " , get_local_mouse_position ( ) ) ;
}
2014-02-10 02:10:30 +01:00
}
return item_h ; // nothing found
}
2016-01-23 15:45:36 +01:00
void Tree : : _text_editor_modal_close ( ) {
2020-03-04 17:36:09 +01:00
if ( InputFilter : : get_singleton ( ) - > is_key_pressed ( KEY_ESCAPE ) | |
InputFilter : : get_singleton ( ) - > is_key_pressed ( KEY_KP_ENTER ) | |
InputFilter : : get_singleton ( ) - > is_key_pressed ( KEY_ENTER ) ) {
2016-01-23 15:45:36 +01:00
return ;
}
2017-09-10 15:37:49 +02:00
if ( value_editor - > has_point ( value_editor - > get_local_mouse_position ( ) ) )
2016-01-27 16:24:49 +01:00
return ;
2016-01-23 15:45:36 +01:00
2020-03-20 03:32:09 +01:00
_text_editor_enter ( text_editor - > get_text ( ) ) ;
2016-01-23 15:45:36 +01:00
}
2020-03-20 03:32:09 +01:00
void Tree : : _text_editor_enter ( String p_text ) {
2014-02-10 02:10:30 +01:00
2020-03-20 03:32:09 +01:00
popup_editor - > hide ( ) ;
2014-02-10 02:10:30 +01:00
if ( ! popup_edited_item )
return ;
2017-03-05 16:44:50 +01:00
if ( popup_edited_item_col < 0 | | popup_edited_item_col > columns . size ( ) )
2014-02-10 02:10:30 +01:00
return ;
2018-07-25 03:11:03 +02:00
TreeItem : : Cell & c = popup_edited_item - > cells . write [ popup_edited_item_col ] ;
2017-03-05 16:44:50 +01:00
switch ( c . mode ) {
2014-02-10 02:10:30 +01:00
case TreeItem : : CELL_MODE_STRING : {
2017-03-05 16:44:50 +01:00
c . text = p_text ;
2014-02-10 02:10:30 +01:00
//popup_edited_item->edited_signal.call( popup_edited_item_col );
} break ;
case TreeItem : : CELL_MODE_RANGE : {
2017-03-05 16:44:50 +01:00
c . val = p_text . to_double ( ) ;
if ( c . step > 0 )
c . val = Math : : stepify ( c . val , c . step ) ;
if ( c . val < c . min )
c . val = c . min ;
else if ( c . val > c . max )
c . val = c . max ;
2014-12-07 06:04:20 +01:00
2014-02-10 02:10:30 +01:00
//popup_edited_item->edited_signal.call( popup_edited_item_col );
} break ;
2019-04-09 17:08:36 +02:00
default : {
ERR_FAIL ( ) ;
}
2014-02-10 02:10:30 +01:00
}
2017-03-05 16:44:50 +01:00
item_edited ( popup_edited_item_col , popup_edited_item ) ;
2014-02-10 02:10:30 +01:00
update ( ) ;
}
void Tree : : value_editor_changed ( double p_value ) {
if ( updating_value_editor ) {
return ;
}
if ( ! popup_edited_item ) {
return ;
}
2018-07-25 03:11:03 +02:00
TreeItem : : Cell & c = popup_edited_item - > cells . write [ popup_edited_item_col ] ;
2017-03-05 16:44:50 +01:00
c . val = p_value ;
item_edited ( popup_edited_item_col , popup_edited_item ) ;
2014-02-10 02:10:30 +01:00
update ( ) ;
}
void Tree : : popup_select ( int p_option ) {
if ( ! popup_edited_item )
return ;
2017-03-05 16:44:50 +01:00
if ( popup_edited_item_col < 0 | | popup_edited_item_col > columns . size ( ) )
2014-02-10 02:10:30 +01:00
return ;
2018-07-25 03:11:03 +02:00
popup_edited_item - > cells . write [ popup_edited_item_col ] . val = p_option ;
2014-02-10 02:10:30 +01:00
//popup_edited_item->edited_signal.call( popup_edited_item_col );
update ( ) ;
2017-03-05 16:44:50 +01:00
item_edited ( popup_edited_item_col , popup_edited_item ) ;
2014-02-10 02:10:30 +01:00
}
2017-12-31 05:56:17 +01:00
void Tree : : _go_left ( ) {
if ( selected_col = = 0 ) {
2020-04-02 01:20:12 +02:00
if ( selected_item - > get_children ( ) ! = nullptr & & ! selected_item - > is_collapsed ( ) ) {
2017-12-31 05:56:17 +01:00
selected_item - > set_collapsed ( true ) ;
} else {
if ( columns . size ( ) = = 1 ) { // goto parent with one column
TreeItem * parent = selected_item - > get_parent ( ) ;
if ( selected_item ! = get_root ( ) & & parent & & parent - > is_selectable ( selected_col ) & & ! ( hide_root & & parent = = get_root ( ) ) ) {
select_single_item ( parent , get_root ( ) , selected_col ) ;
}
} else if ( selected_item - > get_prev_visible ( ) ) {
selected_col = columns . size ( ) - 1 ;
_go_up ( ) ; // go to upper column if possible
}
}
} else {
if ( select_mode = = SELECT_MULTI ) {
selected_col - - ;
emit_signal ( " cell_selected " ) ;
} else {
2015-08-31 00:37:23 +02:00
2017-12-31 05:56:17 +01:00
selected_item - > select ( selected_col - 1 ) ;
}
}
update ( ) ;
accept_event ( ) ;
ensure_cursor_is_visible ( ) ;
}
2014-02-10 02:10:30 +01:00
2017-12-31 05:56:17 +01:00
void Tree : : _go_right ( ) {
if ( selected_col = = ( columns . size ( ) - 1 ) ) {
2020-04-02 01:20:12 +02:00
if ( selected_item - > get_children ( ) ! = nullptr & & selected_item - > is_collapsed ( ) ) {
2017-12-31 05:56:17 +01:00
selected_item - > set_collapsed ( false ) ;
} else if ( selected_item - > get_next_visible ( ) ) {
2020-01-01 10:57:40 +01:00
selected_col = 0 ;
2017-12-31 05:56:17 +01:00
_go_down ( ) ;
}
} else {
if ( select_mode = = SELECT_MULTI ) {
selected_col + + ;
emit_signal ( " cell_selected " ) ;
} else {
2014-02-10 02:10:30 +01:00
2017-12-31 05:56:17 +01:00
selected_item - > select ( selected_col + 1 ) ;
}
}
update ( ) ;
ensure_cursor_is_visible ( ) ;
accept_event ( ) ;
}
void Tree : : _go_up ( ) {
2020-04-02 01:20:12 +02:00
TreeItem * prev = nullptr ;
2017-12-31 05:56:17 +01:00
if ( ! selected_item ) {
prev = get_last_item ( ) ;
selected_col = 0 ;
} else {
prev = selected_item - > get_prev_visible ( ) ;
if ( last_keypress ! = 0 ) {
//incr search next
int col ;
prev = _search_item_text ( prev , incr_search , & col , true , true ) ;
if ( ! prev ) {
accept_event ( ) ;
return ;
}
}
}
if ( select_mode = = SELECT_MULTI ) {
if ( ! prev )
2017-05-20 17:38:03 +02:00
return ;
2017-12-31 05:56:17 +01:00
selected_item = prev ;
emit_signal ( " cell_selected " ) ;
update ( ) ;
} else {
2014-02-10 02:10:30 +01:00
2017-12-31 05:56:17 +01:00
int col = selected_col < 0 ? 0 : selected_col ;
while ( prev & & ! prev - > cells [ col ] . selectable )
prev = prev - > get_prev_visible ( ) ;
if ( ! prev )
return ; // do nothing..
prev - > select ( col ) ;
2017-03-05 16:44:50 +01:00
}
2014-02-10 02:10:30 +01:00
2017-12-31 05:56:17 +01:00
ensure_cursor_is_visible ( ) ;
accept_event ( ) ;
}
void Tree : : _go_down ( ) {
2020-04-02 01:20:12 +02:00
TreeItem * next = nullptr ;
2017-12-31 05:56:17 +01:00
if ( ! selected_item ) {
2019-11-12 08:15:29 +01:00
if ( root ) {
next = hide_root ? root - > get_next_visible ( ) : root ;
}
2017-12-31 05:56:17 +01:00
} else {
next = selected_item - > get_next_visible ( ) ;
if ( last_keypress ! = 0 ) {
//incr search next
int col ;
next = _search_item_text ( next , incr_search , & col , true ) ;
if ( ! next ) {
2017-05-20 17:38:03 +02:00
accept_event ( ) ;
2017-12-31 05:56:17 +01:00
return ;
2017-09-16 18:26:05 +02:00
}
2017-12-31 05:56:17 +01:00
}
}
2014-02-10 02:10:30 +01:00
2017-12-31 05:56:17 +01:00
if ( select_mode = = SELECT_MULTI ) {
2014-02-10 02:10:30 +01:00
2017-12-31 05:56:17 +01:00
if ( ! next ) {
return ;
}
2014-02-10 02:10:30 +01:00
2017-12-31 05:56:17 +01:00
selected_item = next ;
emit_signal ( " cell_selected " ) ;
update ( ) ;
} else {
2014-02-10 02:10:30 +01:00
2017-12-31 05:56:17 +01:00
int col = selected_col < 0 ? 0 : selected_col ;
2014-02-10 02:10:30 +01:00
2017-12-31 05:56:17 +01:00
while ( next & & ! next - > cells [ col ] . selectable )
next = next - > get_next_visible ( ) ;
if ( ! next ) {
return ; // do nothing..
}
next - > select ( col ) ;
}
2014-02-10 02:10:30 +01:00
2017-12-31 05:56:17 +01:00
ensure_cursor_is_visible ( ) ;
accept_event ( ) ;
}
2014-02-10 02:10:30 +01:00
2017-12-31 05:56:17 +01:00
void Tree : : _gui_input ( Ref < InputEvent > p_event ) {
2014-02-10 02:10:30 +01:00
2017-12-31 05:56:17 +01:00
Ref < InputEventKey > k = p_event ;
2014-02-10 02:10:30 +01:00
2018-10-07 16:22:04 +02:00
bool is_command = k . is_valid ( ) & & k - > get_command ( ) ;
2017-12-31 05:56:17 +01:00
if ( p_event - > is_action ( " ui_right " ) & & p_event - > is_pressed ( ) ) {
2014-02-10 02:10:30 +01:00
2017-12-31 05:56:17 +01:00
if ( ! cursor_can_exit_tree ) accept_event ( ) ;
2014-02-10 02:10:30 +01:00
2017-12-31 05:56:17 +01:00
if ( ! selected_item | | select_mode = = SELECT_ROW | | selected_col > ( columns . size ( ) - 1 ) ) {
return ;
}
if ( k . is_valid ( ) & & k - > get_alt ( ) ) {
selected_item - > set_collapsed ( false ) ;
TreeItem * next = selected_item - > get_children ( ) ;
while ( next & & next ! = selected_item - > next ) {
next - > set_collapsed ( false ) ;
next = next - > get_next_visible ( ) ;
}
} else {
_go_right ( ) ;
}
} else if ( p_event - > is_action ( " ui_left " ) & & p_event - > is_pressed ( ) ) {
2017-09-16 18:26:05 +02:00
2017-12-31 05:56:17 +01:00
if ( ! cursor_can_exit_tree ) accept_event ( ) ;
2017-09-16 18:26:05 +02:00
2017-12-31 05:56:17 +01:00
if ( ! selected_item | | select_mode = = SELECT_ROW | | selected_col < 0 ) {
return ;
}
if ( k . is_valid ( ) & & k - > get_alt ( ) ) {
selected_item - > set_collapsed ( true ) ;
TreeItem * next = selected_item - > get_children ( ) ;
while ( next & & next ! = selected_item - > next ) {
next - > set_collapsed ( true ) ;
next = next - > get_next_visible ( ) ;
2017-09-16 18:26:05 +02:00
}
2017-12-31 05:56:17 +01:00
} else {
_go_left ( ) ;
}
2014-02-10 02:10:30 +01:00
2018-10-07 16:22:04 +02:00
} else if ( p_event - > is_action ( " ui_up " ) & & p_event - > is_pressed ( ) & & ! is_command ) {
2014-02-10 02:10:30 +01:00
2017-12-31 05:56:17 +01:00
if ( ! cursor_can_exit_tree ) accept_event ( ) ;
2014-02-10 02:10:30 +01:00
2017-12-31 05:56:17 +01:00
_go_up ( ) ;
2014-02-10 02:10:30 +01:00
2018-10-07 16:22:04 +02:00
} else if ( p_event - > is_action ( " ui_down " ) & & p_event - > is_pressed ( ) & & ! is_command ) {
2014-02-10 02:10:30 +01:00
2017-12-31 05:56:17 +01:00
if ( ! cursor_can_exit_tree ) accept_event ( ) ;
2014-02-10 02:10:30 +01:00
2017-12-31 05:56:17 +01:00
_go_down ( ) ;
2014-02-10 02:10:30 +01:00
2017-12-31 05:56:17 +01:00
} else if ( p_event - > is_action ( " ui_page_down " ) & & p_event - > is_pressed ( ) ) {
2014-02-10 02:10:30 +01:00
2017-12-31 05:56:17 +01:00
if ( ! cursor_can_exit_tree ) accept_event ( ) ;
2014-02-10 02:10:30 +01:00
2020-04-02 01:20:12 +02:00
TreeItem * next = nullptr ;
2017-12-31 05:56:17 +01:00
if ( ! selected_item )
return ;
next = selected_item ;
2014-02-10 02:10:30 +01:00
2017-12-31 05:56:17 +01:00
for ( int i = 0 ; i < 10 ; i + + ) {
2014-02-10 02:10:30 +01:00
2017-12-31 05:56:17 +01:00
TreeItem * _n = next - > get_next_visible ( ) ;
if ( _n ) {
next = _n ;
} else {
2014-02-10 02:10:30 +01:00
2019-05-20 20:34:55 +02:00
break ;
2017-12-31 05:56:17 +01:00
}
}
if ( next = = selected_item )
return ;
2014-02-10 02:10:30 +01:00
2017-12-31 05:56:17 +01:00
if ( select_mode = = SELECT_MULTI ) {
2014-02-10 02:10:30 +01:00
2017-12-31 05:56:17 +01:00
selected_item = next ;
emit_signal ( " cell_selected " ) ;
update ( ) ;
} else {
2014-02-10 02:10:30 +01:00
2017-12-31 05:56:17 +01:00
while ( next & & ! next - > cells [ selected_col ] . selectable )
next = next - > get_next_visible ( ) ;
if ( ! next ) {
return ; // do nothing..
}
next - > select ( selected_col ) ;
}
2014-02-10 02:10:30 +01:00
2017-12-31 05:56:17 +01:00
ensure_cursor_is_visible ( ) ;
} else if ( p_event - > is_action ( " ui_page_up " ) & & p_event - > is_pressed ( ) ) {
2014-02-10 02:10:30 +01:00
2017-12-31 05:56:17 +01:00
if ( ! cursor_can_exit_tree ) accept_event ( ) ;
2014-02-10 02:10:30 +01:00
2020-04-02 01:20:12 +02:00
TreeItem * prev = nullptr ;
2017-12-31 05:56:17 +01:00
if ( ! selected_item )
return ;
prev = selected_item ;
2014-02-10 02:10:30 +01:00
2017-12-31 05:56:17 +01:00
for ( int i = 0 ; i < 10 ; i + + ) {
TreeItem * _n = prev - > get_prev_visible ( ) ;
if ( _n ) {
prev = _n ;
} else {
2014-02-10 02:10:30 +01:00
2019-05-20 20:34:55 +02:00
break ;
2017-12-31 05:56:17 +01:00
}
}
if ( prev = = selected_item )
return ;
2014-02-10 02:10:30 +01:00
2017-12-31 05:56:17 +01:00
if ( select_mode = = SELECT_MULTI ) {
2014-02-10 02:10:30 +01:00
2017-12-31 05:56:17 +01:00
selected_item = prev ;
emit_signal ( " cell_selected " ) ;
update ( ) ;
} else {
2014-02-10 02:10:30 +01:00
2017-12-31 05:56:17 +01:00
while ( prev & & ! prev - > cells [ selected_col ] . selectable )
prev = prev - > get_prev_visible ( ) ;
if ( ! prev ) {
return ; // do nothing..
}
prev - > select ( selected_col ) ;
}
ensure_cursor_is_visible ( ) ;
} else if ( p_event - > is_action ( " ui_accept " ) & & p_event - > is_pressed ( ) ) {
2014-02-10 02:10:30 +01:00
2017-12-31 05:56:17 +01:00
if ( selected_item ) {
//bring up editor if possible
if ( ! edit_selected ( ) ) {
emit_signal ( " item_activated " ) ;
incr_search . clear ( ) ;
}
}
accept_event ( ) ;
} else if ( p_event - > is_action ( " ui_select " ) & & p_event - > is_pressed ( ) ) {
2014-02-10 02:10:30 +01:00
2017-12-31 05:56:17 +01:00
if ( select_mode = = SELECT_MULTI ) {
if ( ! selected_item )
return ;
if ( selected_item - > is_selected ( selected_col ) ) {
selected_item - > deselect ( selected_col ) ;
emit_signal ( " multi_selected " , selected_item , selected_col , false ) ;
} else if ( selected_item - > is_selectable ( selected_col ) ) {
selected_item - > select ( selected_col ) ;
emit_signal ( " multi_selected " , selected_item , selected_col , true ) ;
}
}
accept_event ( ) ;
}
2014-02-10 02:10:30 +01:00
2017-12-31 05:56:17 +01:00
if ( k . is_valid ( ) ) { // Incremental search
if ( ! k - > is_pressed ( ) )
return ;
if ( k - > get_command ( ) | | ( k - > get_shift ( ) & & k - > get_unicode ( ) = = 0 ) | | k - > get_metakey ( ) )
return ;
if ( ! root )
return ;
2014-02-10 02:10:30 +01:00
2017-12-31 05:56:17 +01:00
if ( hide_root & & ! root - > get_next_visible ( ) )
return ;
2014-02-10 02:10:30 +01:00
2017-12-31 05:56:17 +01:00
if ( k - > get_unicode ( ) > 0 ) {
2014-02-10 02:10:30 +01:00
2017-12-31 05:56:17 +01:00
_do_incr_search ( String : : chr ( k - > get_unicode ( ) ) ) ;
accept_event ( ) ;
return ;
} else {
2018-04-05 19:59:35 +02:00
if ( k - > get_keycode ( ) ! = KEY_SHIFT )
2017-12-31 05:56:17 +01:00
last_keypress = 0 ;
2017-05-20 17:38:03 +02:00
}
}
2014-02-10 02:10:30 +01:00
2017-05-20 17:38:03 +02:00
Ref < InputEventMouseMotion > mm = p_event ;
2014-02-10 02:10:30 +01:00
2017-05-20 17:38:03 +02:00
if ( mm . is_valid ( ) ) {
2014-02-10 02:10:30 +01:00
2018-02-17 14:00:39 +01:00
if ( cache . font . is_null ( ) ) // avoid a strange case that may corrupt stuff
2017-05-20 17:38:03 +02:00
update_cache ( ) ;
2014-02-10 02:10:30 +01:00
2017-05-20 17:38:03 +02:00
Ref < StyleBox > bg = cache . bg ;
2014-02-10 02:10:30 +01:00
2017-06-03 10:54:24 +02:00
Point2 pos = mm - > get_position ( ) - bg - > get_offset ( ) ;
2014-02-10 02:10:30 +01:00
2017-05-20 17:38:03 +02:00
Cache : : ClickType old_hover = cache . hover_type ;
int old_index = cache . hover_index ;
2014-02-10 02:10:30 +01:00
2017-05-20 17:38:03 +02:00
cache . hover_type = Cache : : CLICK_NONE ;
cache . hover_index = 0 ;
if ( show_column_titles ) {
pos . y - = _get_title_button_height ( ) ;
if ( pos . y < 0 ) {
pos . x + = cache . offset . x ;
int len = 0 ;
for ( int i = 0 ; i < columns . size ( ) ; i + + ) {
2014-02-10 02:10:30 +01:00
2017-05-20 17:38:03 +02:00
len + = get_column_width ( i ) ;
if ( pos . x < len ) {
2014-02-10 02:10:30 +01:00
2017-05-20 17:38:03 +02:00
cache . hover_type = Cache : : CLICK_TITLE ;
cache . hover_index = i ;
update ( ) ;
break ;
2014-02-10 02:10:30 +01:00
}
}
}
2017-05-20 17:38:03 +02:00
}
2014-02-10 02:10:30 +01:00
2017-06-05 01:35:08 +02:00
if ( root ) {
2016-05-11 16:46:08 +02:00
2017-06-03 10:54:24 +02:00
Point2 mpos = mm - > get_position ( ) ;
2017-05-20 17:38:03 +02:00
mpos - = cache . bg - > get_offset ( ) ;
mpos . y - = _get_title_button_height ( ) ;
if ( mpos . y > = 0 ) {
2016-05-11 16:46:08 +02:00
2017-05-20 17:38:03 +02:00
if ( h_scroll - > is_visible_in_tree ( ) )
mpos . x + = h_scroll - > get_value ( ) ;
if ( v_scroll - > is_visible_in_tree ( ) )
mpos . y + = v_scroll - > get_value ( ) ;
2016-05-11 16:46:08 +02:00
2017-05-20 17:38:03 +02:00
int col , h , section ;
TreeItem * it = _find_item_at_pos ( root , mpos , col , h , section ) ;
2016-05-11 16:46:08 +02:00
2018-07-13 15:00:10 +02:00
if ( drop_mode_flags ) {
if ( it ! = drop_mode_over ) {
drop_mode_over = it ;
update ( ) ;
}
if ( it & & section ! = drop_mode_section ) {
drop_mode_section = section ;
update ( ) ;
}
2016-05-11 16:46:08 +02:00
}
2017-06-05 01:35:08 +02:00
2018-07-13 15:00:10 +02:00
if ( it ! = cache . hover_item ) {
2017-06-05 01:35:08 +02:00
cache . hover_item = it ;
2018-07-13 15:00:10 +02:00
update ( ) ;
}
if ( it & & col ! = cache . hover_cell ) {
2017-06-05 01:35:08 +02:00
cache . hover_cell = col ;
update ( ) ;
}
2016-05-11 16:46:08 +02:00
}
2017-05-20 17:38:03 +02:00
}
2016-05-11 16:46:08 +02:00
2017-05-20 17:38:03 +02:00
if ( cache . hover_type ! = old_hover | | cache . hover_index ! = old_index ) {
update ( ) ;
}
2015-08-29 06:43:21 +02:00
2018-09-22 22:31:56 +02:00
if ( pressing_for_editor & & popup_edited_item & & ( popup_edited_item - > get_cell_mode ( popup_edited_item_col ) = = TreeItem : : CELL_MODE_RANGE ) ) {
2017-05-20 17:38:03 +02:00
//range drag
2015-08-29 06:43:21 +02:00
2017-05-20 17:38:03 +02:00
if ( ! range_drag_enabled ) {
2015-08-29 06:43:21 +02:00
2017-06-03 10:54:24 +02:00
Vector2 cpos = mm - > get_position ( ) ;
2017-05-20 17:38:03 +02:00
if ( cpos . distance_to ( pressing_pos ) > 2 ) {
range_drag_enabled = true ;
range_drag_capture_pos = cpos ;
range_drag_base = popup_edited_item - > get_range ( popup_edited_item_col ) ;
2020-03-04 17:36:09 +01:00
InputFilter : : get_singleton ( ) - > set_mouse_mode ( InputFilter : : MOUSE_MODE_CAPTURED ) ;
2015-08-29 06:43:21 +02:00
}
2017-05-20 17:38:03 +02:00
} else {
2018-07-25 03:11:03 +02:00
const TreeItem : : Cell & c = popup_edited_item - > cells [ popup_edited_item_col ] ;
2017-05-20 17:38:03 +02:00
float diff_y = - mm - > get_relative ( ) . y ;
diff_y = Math : : pow ( ABS ( diff_y ) , 1.8f ) * SGN ( diff_y ) ;
diff_y * = 0.1 ;
range_drag_base = CLAMP ( range_drag_base + c . step * diff_y , c . min , c . max ) ;
popup_edited_item - > set_range ( popup_edited_item_col , range_drag_base ) ;
item_edited ( popup_edited_item_col , popup_edited_item ) ;
2015-08-29 06:43:21 +02:00
}
2017-05-20 17:38:03 +02:00
}
2015-08-29 06:43:21 +02:00
2017-05-20 17:38:03 +02:00
if ( drag_touching & & ! drag_touching_deaccel ) {
2014-02-10 02:10:30 +01:00
2017-05-20 17:38:03 +02:00
drag_accum - = mm - > get_relative ( ) . y ;
v_scroll - > set_value ( drag_from + drag_accum ) ;
drag_speed = - mm - > get_speed ( ) . y ;
}
}
2015-08-31 00:37:23 +02:00
2017-05-20 17:38:03 +02:00
Ref < InputEventMouseButton > b = p_event ;
2014-02-10 02:10:30 +01:00
2017-05-20 17:38:03 +02:00
if ( b . is_valid ( ) ) {
2018-02-17 14:00:39 +01:00
if ( cache . font . is_null ( ) ) // avoid a strange case that may corrupt stuff
2017-05-20 17:38:03 +02:00
update_cache ( ) ;
2014-02-10 02:10:30 +01:00
2017-05-20 17:38:03 +02:00
if ( ! b - > is_pressed ( ) ) {
2016-05-11 16:46:08 +02:00
2017-05-20 17:38:03 +02:00
if ( b - > get_button_index ( ) = = BUTTON_LEFT ) {
2017-05-17 12:55:55 +02:00
2017-06-03 10:54:24 +02:00
Point2 pos = b - > get_position ( ) - cache . bg - > get_offset ( ) ;
2017-05-20 17:38:03 +02:00
if ( show_column_titles ) {
pos . y - = _get_title_button_height ( ) ;
2017-05-17 12:55:55 +02:00
2017-05-20 17:38:03 +02:00
if ( pos . y < 0 ) {
pos . x + = cache . offset . x ;
int len = 0 ;
for ( int i = 0 ; i < columns . size ( ) ; i + + ) {
2017-05-17 12:55:55 +02:00
2017-05-20 17:38:03 +02:00
len + = get_column_width ( i ) ;
if ( pos . x < len ) {
emit_signal ( " column_title_pressed " , i ) ;
break ;
2017-05-17 12:55:55 +02:00
}
}
}
2017-05-20 17:38:03 +02:00
}
2017-05-17 12:55:55 +02:00
2017-05-20 17:38:03 +02:00
if ( single_select_defer ) {
select_single_item ( single_select_defer , root , single_select_defer_column ) ;
2020-04-02 01:20:12 +02:00
single_select_defer = nullptr ;
2017-05-20 17:38:03 +02:00
}
2016-05-11 16:46:08 +02:00
2017-05-20 17:38:03 +02:00
range_click_timer - > stop ( ) ;
2015-12-08 19:04:56 +01:00
2017-05-20 17:38:03 +02:00
if ( pressing_for_editor ) {
2015-08-29 06:43:21 +02:00
2017-05-20 17:38:03 +02:00
if ( range_drag_enabled ) {
2015-08-29 06:43:21 +02:00
2017-05-20 17:38:03 +02:00
range_drag_enabled = false ;
2020-03-04 17:36:09 +01:00
InputFilter : : get_singleton ( ) - > set_mouse_mode ( InputFilter : : MOUSE_MODE_VISIBLE ) ;
2017-05-20 17:38:03 +02:00
warp_mouse ( range_drag_capture_pos ) ;
} else {
Rect2 rect = get_selected ( ) - > get_meta ( " __focus_rect " ) ;
2017-06-03 10:54:24 +02:00
if ( rect . has_point ( Point2 ( b - > get_position ( ) . x , b - > get_position ( ) . y ) ) ) {
2019-09-13 21:14:12 +02:00
if ( ! edit_selected ( ) ) {
emit_signal ( " item_double_clicked " ) ;
}
2016-07-28 21:37:52 +02:00
} else {
2017-05-20 17:38:03 +02:00
emit_signal ( " item_double_clicked " ) ;
2016-07-28 21:37:52 +02:00
}
2015-08-29 06:43:21 +02:00
}
2017-05-20 17:38:03 +02:00
pressing_for_editor = false ;
}
2015-08-29 06:43:21 +02:00
2020-04-02 01:20:12 +02:00
if ( cache . click_type = = Cache : : CLICK_BUTTON & & cache . click_item ! = nullptr ) {
2017-05-20 17:38:03 +02:00
// make sure in case of wrong reference after reconstructing whole TreeItems
2017-09-10 15:37:49 +02:00
cache . click_item = get_item_at_position ( cache . click_pos ) ;
2017-05-20 17:38:03 +02:00
emit_signal ( " button_pressed " , cache . click_item , cache . click_column , cache . click_id ) ;
}
cache . click_type = Cache : : CLICK_NONE ;
cache . click_index = - 1 ;
cache . click_id = - 1 ;
2020-04-02 01:20:12 +02:00
cache . click_item = nullptr ;
2017-05-20 17:38:03 +02:00
cache . click_column = 0 ;
2014-02-10 02:10:30 +01:00
2017-05-20 17:38:03 +02:00
if ( drag_touching ) {
2014-02-10 02:10:30 +01:00
2017-05-20 17:38:03 +02:00
if ( drag_speed = = 0 ) {
drag_touching_deaccel = false ;
drag_touching = false ;
2018-04-11 09:28:14 +02:00
set_physics_process_internal ( false ) ;
2017-05-20 17:38:03 +02:00
} else {
2014-02-10 02:10:30 +01:00
2017-05-20 17:38:03 +02:00
drag_touching_deaccel = true ;
2014-02-10 02:10:30 +01:00
}
}
2017-05-20 17:38:03 +02:00
update ( ) ;
2014-02-10 02:10:30 +01:00
}
2017-05-20 17:38:03 +02:00
return ;
}
2014-02-10 02:10:30 +01:00
2017-05-20 17:38:03 +02:00
if ( range_drag_enabled )
return ;
2015-08-31 00:37:23 +02:00
2017-05-20 17:38:03 +02:00
switch ( b - > get_button_index ( ) ) {
case BUTTON_RIGHT :
case BUTTON_LEFT : {
Ref < StyleBox > bg = cache . bg ;
2017-06-03 10:54:24 +02:00
Point2 pos = b - > get_position ( ) - bg - > get_offset ( ) ;
2017-05-20 17:38:03 +02:00
cache . click_type = Cache : : CLICK_NONE ;
2017-08-26 18:55:43 +02:00
if ( show_column_titles ) {
2017-05-20 17:38:03 +02:00
pos . y - = _get_title_button_height ( ) ;
if ( pos . y < 0 ) {
2017-08-26 18:55:43 +02:00
if ( b - > get_button_index ( ) = = BUTTON_LEFT ) {
pos . x + = cache . offset . x ;
int len = 0 ;
for ( int i = 0 ; i < columns . size ( ) ; i + + ) {
len + = get_column_width ( i ) ;
if ( pos . x < len ) {
cache . click_type = Cache : : CLICK_TITLE ;
cache . click_index = i ;
//cache.click_id=;
update ( ) ;
break ;
}
2014-02-10 02:10:30 +01:00
}
2016-05-16 17:23:40 +02:00
}
2014-02-10 02:10:30 +01:00
break ;
2016-05-16 17:23:40 +02:00
}
2017-05-20 17:38:03 +02:00
}
if ( ! root | | ( ! root - > get_children ( ) & & hide_root ) ) {
if ( b - > get_button_index ( ) = = BUTTON_RIGHT & & allow_rmb_select ) {
2017-09-10 15:37:49 +02:00
emit_signal ( " empty_tree_rmb_selected " , get_local_mouse_position ( ) ) ;
2017-05-20 17:38:03 +02:00
}
break ;
}
2014-02-10 02:10:30 +01:00
2017-05-20 17:38:03 +02:00
click_handled = false ;
pressing_for_editor = false ;
2019-01-14 21:20:33 +01:00
propagate_mouse_activated = false ;
2014-02-10 02:10:30 +01:00
2017-05-20 17:38:03 +02:00
blocked + + ;
2017-09-02 22:32:31 +02:00
propagate_mouse_event ( pos + cache . offset , 0 , 0 , b - > is_doubleclick ( ) , root , b - > get_button_index ( ) , b ) ;
2017-05-20 17:38:03 +02:00
blocked - - ;
2014-02-10 02:10:30 +01:00
2017-05-20 17:38:03 +02:00
if ( pressing_for_editor ) {
2017-06-03 10:54:24 +02:00
pressing_pos = b - > get_position ( ) ;
2017-05-20 17:38:03 +02:00
}
2014-02-10 02:10:30 +01:00
2017-05-20 17:38:03 +02:00
if ( b - > get_button_index ( ) = = BUTTON_RIGHT )
break ;
2016-05-16 04:41:48 +02:00
2017-05-20 17:38:03 +02:00
if ( drag_touching ) {
2018-04-11 09:28:14 +02:00
set_physics_process_internal ( false ) ;
2017-05-20 17:38:03 +02:00
drag_touching_deaccel = false ;
drag_touching = false ;
drag_speed = 0 ;
drag_from = 0 ;
}
2014-02-10 02:10:30 +01:00
2017-05-20 17:38:03 +02:00
if ( ! click_handled ) {
drag_speed = 0 ;
drag_accum = 0 ;
//last_drag_accum=0;
drag_from = v_scroll - > get_value ( ) ;
2020-03-03 14:36:29 +01:00
drag_touching = ! DisplayServer : : get_singleton ( ) - > screen_is_touchscreen ( DisplayServer : : get_singleton ( ) - > window_get_current_screen ( get_viewport ( ) - > get_window_id ( ) ) ) ;
2017-05-20 17:38:03 +02:00
drag_touching_deaccel = false ;
if ( drag_touching ) {
2018-04-11 09:28:14 +02:00
set_physics_process_internal ( true ) ;
2014-02-10 02:10:30 +01:00
}
2017-11-27 16:58:28 +01:00
if ( b - > get_button_index ( ) = = BUTTON_LEFT ) {
2020-04-02 01:20:12 +02:00
if ( get_item_at_position ( b - > get_position ( ) ) = = nullptr & & ! b - > get_shift ( ) & & ! b - > get_control ( ) & & ! b - > get_command ( ) )
2017-11-27 16:58:28 +01:00
emit_signal ( " nothing_selected " ) ;
}
2017-05-20 17:38:03 +02:00
}
2014-02-10 02:10:30 +01:00
2019-01-14 21:20:33 +01:00
if ( propagate_mouse_activated ) {
emit_signal ( " item_activated " ) ;
propagate_mouse_activated = false ;
}
2017-05-20 17:38:03 +02:00
} break ;
case BUTTON_WHEEL_UP : {
2015-08-31 00:37:23 +02:00
2019-10-02 12:34:04 +02:00
double prev_value = v_scroll - > get_value ( ) ;
2017-05-20 17:38:03 +02:00
v_scroll - > set_value ( v_scroll - > get_value ( ) - v_scroll - > get_page ( ) * b - > get_factor ( ) / 8 ) ;
2019-10-02 12:34:04 +02:00
if ( v_scroll - > get_value ( ) ! = prev_value ) {
accept_event ( ) ;
}
2017-05-20 17:38:03 +02:00
} break ;
case BUTTON_WHEEL_DOWN : {
2015-08-31 00:37:23 +02:00
2019-10-02 12:34:04 +02:00
double prev_value = v_scroll - > get_value ( ) ;
2017-05-20 17:38:03 +02:00
v_scroll - > set_value ( v_scroll - > get_value ( ) + v_scroll - > get_page ( ) * b - > get_factor ( ) / 8 ) ;
2019-10-02 12:34:04 +02:00
if ( v_scroll - > get_value ( ) ! = prev_value ) {
accept_event ( ) ;
}
2017-05-20 17:38:03 +02:00
} break ;
}
2014-02-10 02:10:30 +01:00
}
2017-11-01 21:49:39 +01:00
Ref < InputEventPanGesture > pan_gesture = p_event ;
if ( pan_gesture . is_valid ( ) ) {
2020-01-03 11:29:22 +01:00
double prev_v = v_scroll - > get_value ( ) ;
2017-11-01 21:49:39 +01:00
v_scroll - > set_value ( v_scroll - > get_value ( ) + v_scroll - > get_page ( ) * pan_gesture - > get_delta ( ) . y / 8 ) ;
2020-01-03 11:29:22 +01:00
double prev_h = h_scroll - > get_value ( ) ;
h_scroll - > set_value ( h_scroll - > get_value ( ) + h_scroll - > get_page ( ) * pan_gesture - > get_delta ( ) . x / 8 ) ;
if ( v_scroll - > get_value ( ) ! = prev_v | | h_scroll - > get_value ( ) ! = prev_h ) {
2019-10-02 12:34:04 +02:00
accept_event ( ) ;
}
2017-11-01 21:49:39 +01:00
}
2014-02-10 02:10:30 +01:00
}
bool Tree : : edit_selected ( ) {
TreeItem * s = get_selected ( ) ;
2019-08-08 22:11:48 +02:00
ERR_FAIL_COND_V_MSG ( ! s , false , " No item selected. " ) ;
2014-02-10 02:10:30 +01:00
ensure_cursor_is_visible ( ) ;
int col = get_selected_column ( ) ;
2019-08-08 22:11:48 +02:00
ERR_FAIL_INDEX_V_MSG ( col , columns . size ( ) , false , " No item column selected. " ) ;
2014-02-10 02:10:30 +01:00
if ( ! s - > cells [ col ] . editable )
return false ;
2016-08-20 18:00:25 +02:00
Rect2 rect = s - > get_meta ( " __focus_rect " ) ;
2017-03-05 16:44:50 +01:00
popup_edited_item = s ;
popup_edited_item_col = col ;
2014-02-10 02:10:30 +01:00
2018-07-25 03:11:03 +02:00
const TreeItem : : Cell & c = s - > cells [ col ] ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
if ( c . mode = = TreeItem : : CELL_MODE_CHECK ) {
2014-02-10 02:10:30 +01:00
2015-11-05 16:20:45 +01:00
s - > set_checked ( col , ! c . checked ) ;
2017-03-05 16:44:50 +01:00
item_edited ( col , s ) ;
2015-11-05 16:20:45 +01:00
return true ;
2017-03-05 16:44:50 +01:00
} else if ( c . mode = = TreeItem : : CELL_MODE_CUSTOM ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
edited_item = s ;
edited_col = col ;
2017-06-04 00:25:13 +02:00
custom_popup_rect = Rect2i ( get_global_position ( ) + rect . position , rect . size ) ;
2017-03-05 16:44:50 +01:00
emit_signal ( " custom_popup_edited " , false ) ;
item_edited ( col , s ) ;
2014-02-10 02:10:30 +01:00
return true ;
2018-09-22 22:31:56 +02:00
} else if ( c . mode = = TreeItem : : CELL_MODE_RANGE & & c . text ! = " " ) {
2014-02-10 02:10:30 +01:00
popup_menu - > clear ( ) ;
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < c . text . get_slice_count ( " , " ) ; i + + ) {
2014-02-10 02:10:30 +01:00
2019-02-12 21:10:08 +01:00
String s2 = c . text . get_slicec ( ' , ' , i ) ;
popup_menu - > add_item ( s2 . get_slicec ( ' : ' , 0 ) , s2 . get_slicec ( ' : ' , 1 ) . empty ( ) ? i : s2 . get_slicec ( ' : ' , 1 ) . to_int ( ) ) ;
2014-02-10 02:10:30 +01:00
}
2017-03-05 16:44:50 +01:00
popup_menu - > set_size ( Size2 ( rect . size . width , 0 ) ) ;
2017-06-04 00:25:13 +02:00
popup_menu - > set_position ( get_global_position ( ) + rect . position + Point2i ( 0 , rect . size . height ) ) ;
2014-02-10 02:10:30 +01:00
popup_menu - > popup ( ) ;
2017-03-05 16:44:50 +01:00
popup_edited_item = s ;
popup_edited_item_col = col ;
2014-02-10 02:10:30 +01:00
return true ;
2018-09-22 22:31:56 +02:00
} else if ( c . mode = = TreeItem : : CELL_MODE_STRING | | c . mode = = TreeItem : : CELL_MODE_RANGE ) {
2014-02-10 02:10:30 +01:00
2020-03-20 03:32:09 +01:00
Rect2 popup_rect ;
2017-09-03 05:56:25 +02:00
Vector2 ofs ( 0 , ( text_editor - > get_size ( ) . height - rect . size . height ) / 2 ) ;
2020-03-20 03:32:09 +01:00
Point2i textedpos = get_screen_position ( ) + rect . position - ofs ;
2018-10-04 19:33:34 +02:00
cache . text_editor_position = textedpos ;
2020-03-20 03:32:09 +01:00
popup_rect . position = textedpos ;
popup_rect . size = rect . size ;
2014-02-10 02:10:30 +01:00
text_editor - > clear ( ) ;
2019-07-23 17:27:55 +02:00
text_editor - > set_text ( c . mode = = TreeItem : : CELL_MODE_STRING ? c . text : String : : num ( c . val , Math : : range_step_decimals ( c . step ) ) ) ;
2014-02-10 02:10:30 +01:00
text_editor - > select_all ( ) ;
2018-09-22 22:31:56 +02:00
if ( c . mode = = TreeItem : : CELL_MODE_RANGE ) {
2014-02-10 02:10:30 +01:00
2020-03-20 03:32:09 +01:00
popup_rect . size . y + = value_editor - > get_minimum_size ( ) . height ;
2020-03-14 17:06:39 +01:00
value_editor - > show ( ) ;
2017-03-05 16:44:50 +01:00
updating_value_editor = true ;
value_editor - > set_min ( c . min ) ;
value_editor - > set_max ( c . max ) ;
value_editor - > set_step ( c . step ) ;
value_editor - > set_value ( c . val ) ;
value_editor - > set_exp_ratio ( c . expr ) ;
updating_value_editor = false ;
2020-03-20 03:32:09 +01:00
} else {
value_editor - > hide ( ) ;
2014-02-10 02:10:30 +01:00
}
2020-03-20 03:32:09 +01:00
popup_editor - > set_position ( popup_rect . position ) ;
popup_editor - > set_size ( popup_rect . size ) ;
popup_editor - > popup ( ) ;
popup_editor - > child_controls_changed ( ) ;
2014-02-10 02:10:30 +01:00
text_editor - > grab_focus ( ) ;
2020-03-20 03:32:09 +01:00
2014-02-10 02:10:30 +01:00
return true ;
}
return false ;
}
Size2 Tree : : get_internal_min_size ( ) const {
2017-03-05 16:44:50 +01:00
Size2i size = cache . bg - > get_offset ( ) ;
2014-02-10 02:10:30 +01:00
if ( root )
2017-03-05 16:44:50 +01:00
size . height + = get_item_height ( root ) ;
for ( int i = 0 ; i < columns . size ( ) ; i + + ) {
2015-08-31 00:37:23 +02:00
2017-03-05 16:44:50 +01:00
size . width + = columns [ i ] . min_width ;
2014-02-10 02:10:30 +01:00
}
2015-08-31 00:37:23 +02:00
2014-02-10 02:10:30 +01:00
return size ;
}
void Tree : : update_scrollbars ( ) {
Size2 size = get_size ( ) ;
int tbh ;
if ( show_column_titles ) {
2017-03-05 16:44:50 +01:00
tbh = _get_title_button_height ( ) ;
2014-02-10 02:10:30 +01:00
} else {
2017-03-05 16:44:50 +01:00
tbh = 0 ;
2014-02-10 02:10:30 +01:00
}
Size2 hmin = h_scroll - > get_combined_minimum_size ( ) ;
Size2 vmin = v_scroll - > get_combined_minimum_size ( ) ;
2017-03-05 16:44:50 +01:00
v_scroll - > set_begin ( Point2 ( size . width - vmin . width , cache . bg - > get_margin ( MARGIN_TOP ) ) ) ;
v_scroll - > set_end ( Point2 ( size . width , size . height - cache . bg - > get_margin ( MARGIN_TOP ) - cache . bg - > get_margin ( MARGIN_BOTTOM ) ) ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
h_scroll - > set_begin ( Point2 ( 0 , size . height - hmin . height ) ) ;
h_scroll - > set_end ( Point2 ( size . width - vmin . width , size . height ) ) ;
2015-08-31 00:37:23 +02:00
2014-02-10 02:10:30 +01:00
Size2 min = get_internal_min_size ( ) ;
2015-08-31 00:37:23 +02:00
2014-02-10 02:10:30 +01:00
if ( min . height < size . height - hmin . height ) {
2015-08-31 00:37:23 +02:00
2014-02-10 02:10:30 +01:00
v_scroll - > hide ( ) ;
2017-03-05 16:44:50 +01:00
cache . offset . y = 0 ;
2014-02-10 02:10:30 +01:00
} else {
2015-08-31 00:37:23 +02:00
2014-02-10 02:10:30 +01:00
v_scroll - > show ( ) ;
v_scroll - > set_max ( min . height ) ;
v_scroll - > set_page ( size . height - hmin . height - tbh ) ;
2017-03-05 16:44:50 +01:00
cache . offset . y = v_scroll - > get_value ( ) ;
2014-02-10 02:10:30 +01:00
}
2015-08-31 00:37:23 +02:00
2014-02-10 02:10:30 +01:00
if ( min . width < size . width - vmin . width ) {
2015-08-31 00:37:23 +02:00
2014-02-10 02:10:30 +01:00
h_scroll - > hide ( ) ;
2017-03-05 16:44:50 +01:00
cache . offset . x = 0 ;
2014-02-10 02:10:30 +01:00
} else {
2015-08-31 00:37:23 +02:00
2014-02-10 02:10:30 +01:00
h_scroll - > show ( ) ;
h_scroll - > set_max ( min . width ) ;
h_scroll - > set_page ( size . width - vmin . width ) ;
2017-03-05 16:44:50 +01:00
cache . offset . x = h_scroll - > get_value ( ) ;
2015-08-31 00:37:23 +02:00
}
2014-02-10 02:10:30 +01:00
}
int Tree : : _get_title_button_height ( ) const {
2018-01-06 19:48:54 +01:00
ERR_FAIL_COND_V ( cache . font . is_null ( ) | | cache . title_button . is_null ( ) , 0 ) ;
2017-03-05 16:44:50 +01:00
return show_column_titles ? cache . font - > get_height ( ) + cache . title_button - > get_minimum_size ( ) . height : 0 ;
2014-02-10 02:10:30 +01:00
}
void Tree : : _notification ( int p_what ) {
2017-03-05 16:44:50 +01:00
if ( p_what = = NOTIFICATION_FOCUS_ENTER ) {
2014-02-10 02:10:30 +01:00
2017-12-26 13:48:50 +01:00
focus_in_id = get_tree ( ) - > get_event_count ( ) ;
2014-02-10 02:10:30 +01:00
}
2017-03-05 16:44:50 +01:00
if ( p_what = = NOTIFICATION_MOUSE_EXIT ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
if ( cache . hover_type ! = Cache : : CLICK_NONE ) {
cache . hover_type = Cache : : CLICK_NONE ;
2014-02-10 02:10:30 +01:00
update ( ) ;
}
}
2017-03-05 16:44:50 +01:00
if ( p_what = = NOTIFICATION_VISIBILITY_CHANGED ) {
2015-08-24 01:15:56 +02:00
2017-03-05 16:44:50 +01:00
drag_touching = false ;
2015-08-24 01:15:56 +02:00
}
2017-03-05 16:44:50 +01:00
if ( p_what = = NOTIFICATION_ENTER_TREE ) {
2014-02-10 02:10:30 +01:00
2017-01-14 18:03:38 +01:00
update_cache ( ) ;
2014-02-10 02:10:30 +01:00
}
2017-03-05 16:44:50 +01:00
if ( p_what = = NOTIFICATION_DRAG_END ) {
2016-05-11 16:46:08 +02:00
2017-03-05 16:44:50 +01:00
drop_mode_flags = 0 ;
2016-09-17 21:29:55 +02:00
scrolling = false ;
2018-04-11 09:28:14 +02:00
set_physics_process_internal ( false ) ;
2016-05-11 16:46:08 +02:00
update ( ) ;
}
2017-03-05 16:44:50 +01:00
if ( p_what = = NOTIFICATION_DRAG_BEGIN ) {
2016-05-11 16:46:08 +02:00
2020-04-02 01:20:12 +02:00
single_select_defer = nullptr ;
2018-12-29 15:41:31 +01:00
if ( cache . scroll_speed > 0 ) {
2016-09-17 21:29:55 +02:00
scrolling = true ;
2018-04-11 09:28:14 +02:00
set_physics_process_internal ( true ) ;
2016-09-17 21:29:55 +02:00
}
2016-05-11 16:46:08 +02:00
}
2018-04-11 09:28:14 +02:00
if ( p_what = = NOTIFICATION_INTERNAL_PHYSICS_PROCESS ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
if ( drag_touching ) {
2014-02-10 02:10:30 +01:00
if ( drag_touching_deaccel ) {
2017-01-04 05:16:14 +01:00
float pos = v_scroll - > get_value ( ) ;
2017-09-30 16:19:07 +02:00
pos + = drag_speed * get_physics_process_delta_time ( ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
bool turnoff = false ;
if ( pos < 0 ) {
pos = 0 ;
turnoff = true ;
2018-04-11 09:28:14 +02:00
set_physics_process_internal ( false ) ;
2017-03-05 16:44:50 +01:00
drag_touching = false ;
drag_touching_deaccel = false ;
2014-02-10 02:10:30 +01:00
}
2017-03-05 16:44:50 +01:00
if ( pos > ( v_scroll - > get_max ( ) - v_scroll - > get_page ( ) ) ) {
pos = v_scroll - > get_max ( ) - v_scroll - > get_page ( ) ;
turnoff = true ;
2014-02-10 02:10:30 +01:00
}
2017-01-04 05:16:14 +01:00
v_scroll - > set_value ( pos ) ;
2017-03-05 16:44:50 +01:00
float sgn = drag_speed < 0 ? - 1 : 1 ;
2014-02-10 02:10:30 +01:00
float val = Math : : abs ( drag_speed ) ;
2017-09-30 16:19:07 +02:00
val - = 1000 * get_physics_process_delta_time ( ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
if ( val < 0 ) {
turnoff = true ;
2014-02-10 02:10:30 +01:00
}
2017-03-05 16:44:50 +01:00
drag_speed = sgn * val ;
2014-02-10 02:10:30 +01:00
if ( turnoff ) {
2018-04-11 09:28:14 +02:00
set_physics_process_internal ( false ) ;
2017-03-05 16:44:50 +01:00
drag_touching = false ;
drag_touching_deaccel = false ;
2014-02-10 02:10:30 +01:00
}
}
}
2017-03-05 16:44:50 +01:00
2018-12-29 15:41:31 +01:00
Point2 mouse_position = get_viewport ( ) - > get_mouse_position ( ) - get_global_position ( ) ;
if ( scrolling & & get_rect ( ) . grow ( cache . scroll_border ) . has_point ( mouse_position ) ) {
Point2 point ;
if ( ( ABS ( mouse_position . x ) < ABS ( mouse_position . x - get_size ( ) . width ) ) & & ( ABS ( mouse_position . x ) < cache . scroll_border ) ) {
point . x = mouse_position . x - cache . scroll_border ;
} else if ( ABS ( mouse_position . x - get_size ( ) . width ) < cache . scroll_border ) {
point . x = mouse_position . x - ( get_size ( ) . width - cache . scroll_border ) ;
2016-09-17 21:29:55 +02:00
}
2018-12-29 15:41:31 +01:00
if ( ( ABS ( mouse_position . y ) < ABS ( mouse_position . y - get_size ( ) . height ) ) & & ( ABS ( mouse_position . y ) < cache . scroll_border ) ) {
point . y = mouse_position . y - cache . scroll_border ;
} else if ( ABS ( mouse_position . y - get_size ( ) . height ) < cache . scroll_border ) {
point . y = mouse_position . y - ( get_size ( ) . height - cache . scroll_border ) ;
2016-09-17 21:29:55 +02:00
}
2018-12-29 15:41:31 +01:00
2017-09-30 16:19:07 +02:00
point * = cache . scroll_speed * get_physics_process_delta_time ( ) ;
2016-09-17 21:29:55 +02:00
point + = get_scroll ( ) ;
2017-01-04 05:16:14 +01:00
h_scroll - > set_value ( point . x ) ;
v_scroll - > set_value ( point . y ) ;
2016-09-17 21:29:55 +02:00
}
2014-02-10 02:10:30 +01:00
}
2017-03-05 16:44:50 +01:00
if ( p_what = = NOTIFICATION_DRAW ) {
2015-08-31 00:37:23 +02:00
2014-02-10 02:10:30 +01:00
update_cache ( ) ;
update_scrollbars ( ) ;
2015-08-31 00:37:23 +02:00
RID ci = get_canvas_item ( ) ;
2014-02-10 02:10:30 +01:00
Ref < StyleBox > bg = cache . bg ;
2020-03-12 13:37:40 +01:00
Ref < StyleBox > bg_focus = get_theme_stylebox ( " bg_focus " ) ;
2015-08-31 00:37:23 +02:00
2014-02-10 02:10:30 +01:00
Point2 draw_ofs ;
2017-03-05 16:44:50 +01:00
draw_ofs + = bg - > get_offset ( ) ;
Size2 draw_size = get_size ( ) - bg - > get_minimum_size ( ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
bg - > draw ( ci , Rect2 ( Point2 ( ) , get_size ( ) ) ) ;
2014-02-10 02:10:30 +01:00
if ( has_focus ( ) ) {
2020-03-27 19:21:27 +01:00
RenderingServer : : get_singleton ( ) - > canvas_item_add_clip_ignore ( ci , true ) ;
2017-03-05 16:44:50 +01:00
bg_focus - > draw ( ci , Rect2 ( Point2 ( ) , get_size ( ) ) ) ;
2020-03-27 19:21:27 +01:00
RenderingServer : : get_singleton ( ) - > canvas_item_add_clip_ignore ( ci , false ) ;
2014-02-10 02:10:30 +01:00
}
int tbh = _get_title_button_height ( ) ;
2017-03-05 16:44:50 +01:00
draw_ofs . y + = tbh ;
draw_size . y - = tbh ;
2014-02-10 02:10:30 +01:00
if ( root ) {
2015-08-31 00:37:23 +02:00
2017-03-05 16:44:50 +01:00
draw_item ( Point2 ( ) , draw_ofs , draw_size , root ) ;
2014-02-10 02:10:30 +01:00
}
2017-03-05 16:44:50 +01:00
int ofs = 0 ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < ( columns . size ( ) - 1 - 1 ) ; i + + ) {
2015-08-31 00:37:23 +02:00
2017-03-05 16:44:50 +01:00
ofs + = get_column_width ( i ) ;
2015-08-31 00:37:23 +02:00
}
2014-02-10 02:10:30 +01:00
if ( show_column_titles ) {
2018-10-13 12:34:57 +02:00
//title buttons
2019-02-12 21:10:08 +01:00
int ofs2 = cache . bg - > get_margin ( MARGIN_LEFT ) ;
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < columns . size ( ) ; i + + ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
Ref < StyleBox > sb = ( cache . click_type = = Cache : : CLICK_TITLE & & cache . click_index = = i ) ? cache . title_button_pressed : ( ( cache . hover_type = = Cache : : CLICK_TITLE & & cache . hover_index = = i ) ? cache . title_button_hover : cache . title_button ) ;
2014-02-10 02:10:30 +01:00
Ref < Font > f = cache . tb_font ;
2019-02-12 21:10:08 +01:00
Rect2 tbrect = Rect2 ( ofs2 - cache . offset . x , bg - > get_margin ( MARGIN_TOP ) , get_column_width ( i ) , tbh ) ;
2017-03-05 16:44:50 +01:00
sb - > draw ( ci , tbrect ) ;
2019-02-12 21:10:08 +01:00
ofs2 + = tbrect . size . width ;
2014-02-10 02:10:30 +01:00
//text
int clip_w = tbrect . size . width - sb - > get_minimum_size ( ) . width ;
2017-06-04 00:25:13 +02:00
f - > draw_halign ( ci , tbrect . position + Point2i ( sb - > get_offset ( ) . x , ( tbrect . size . height - f - > get_height ( ) ) / 2 + f - > get_ascent ( ) ) , HALIGN_CENTER , clip_w , columns [ i ] . title , cache . title_button_color ) ;
2014-02-10 02:10:30 +01:00
}
}
}
2017-03-05 16:44:50 +01:00
if ( p_what = = NOTIFICATION_THEME_CHANGED ) {
2015-01-22 15:07:16 +01:00
update_cache ( ) ;
}
2018-10-04 19:33:34 +02:00
if ( p_what = = NOTIFICATION_RESIZED | | p_what = = NOTIFICATION_TRANSFORM_CHANGED ) {
2020-04-02 01:20:12 +02:00
if ( popup_edited_item ! = nullptr ) {
2018-10-04 19:33:34 +02:00
Rect2 rect = popup_edited_item - > get_meta ( " __focus_rect " ) ;
Vector2 ofs ( 0 , ( text_editor - > get_size ( ) . height - rect . size . height ) / 2 ) ;
Point2i textedpos = get_global_position ( ) + rect . position - ofs ;
if ( cache . text_editor_position ! = textedpos ) {
cache . text_editor_position = textedpos ;
text_editor - > set_position ( textedpos ) ;
value_editor - > set_position ( textedpos + Point2i ( 0 , text_editor - > get_size ( ) . height ) ) ;
}
}
}
2014-02-10 02:10:30 +01:00
}
Size2 Tree : : get_minimum_size ( ) const {
2017-03-05 16:44:50 +01:00
return Size2 ( 1 , 1 ) ;
2014-02-10 02:10:30 +01:00
}
2017-12-14 22:13:48 +01:00
TreeItem * Tree : : create_item ( TreeItem * p_parent , int p_idx ) {
2014-02-10 02:10:30 +01:00
2020-04-02 01:20:12 +02:00
ERR_FAIL_COND_V ( blocked > 0 , nullptr ) ;
2014-02-10 02:10:30 +01:00
2020-04-02 01:20:12 +02:00
TreeItem * ti = nullptr ;
2014-02-10 02:10:30 +01:00
if ( p_parent ) {
2017-12-14 22:13:48 +01:00
// Append or insert a new item to the given parent.
ti = memnew ( TreeItem ( this ) ) ;
2020-04-02 01:20:12 +02:00
ERR_FAIL_COND_V ( ! ti , nullptr ) ;
2017-12-14 22:13:48 +01:00
ti - > cells . resize ( columns . size ( ) ) ;
2014-02-10 02:10:30 +01:00
2020-04-02 01:20:12 +02:00
TreeItem * prev = nullptr ;
2018-01-18 21:37:17 +01:00
TreeItem * c = p_parent - > children ;
2017-12-14 22:13:48 +01:00
int idx = 0 ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
while ( c ) {
2017-12-14 22:13:48 +01:00
if ( idx + + = = p_idx ) {
ti - > next = c ;
break ;
}
prev = c ;
2017-03-05 16:44:50 +01:00
c = c - > next ;
2014-02-10 02:10:30 +01:00
}
2017-12-14 22:13:48 +01:00
if ( prev )
prev - > next = ti ;
else
2018-01-18 21:37:17 +01:00
p_parent - > children = ti ;
2017-03-05 16:44:50 +01:00
ti - > parent = p_parent ;
2014-02-10 02:10:30 +01:00
} else {
2017-12-14 22:13:48 +01:00
if ( ! root ) {
// No root exists, make the given item the new root.
ti = memnew ( TreeItem ( this ) ) ;
2020-04-02 01:20:12 +02:00
ERR_FAIL_COND_V ( ! ti , nullptr ) ;
2017-12-14 22:13:48 +01:00
ti - > cells . resize ( columns . size ( ) ) ;
2014-02-10 02:10:30 +01:00
2017-12-14 22:13:48 +01:00
root = ti ;
} else {
// Root exists, append or insert to root.
ti = create_item ( root , p_idx ) ;
}
2014-02-10 02:10:30 +01:00
}
return ti ;
}
2017-03-05 16:44:50 +01:00
TreeItem * Tree : : get_root ( ) {
2014-02-10 02:10:30 +01:00
return root ;
}
2017-03-05 16:44:50 +01:00
TreeItem * Tree : : get_last_item ( ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
TreeItem * last = root ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
while ( last ) {
2014-02-10 02:10:30 +01:00
if ( last - > next )
2017-03-05 16:44:50 +01:00
last = last - > next ;
2018-01-18 21:37:17 +01:00
else if ( last - > children )
last = last - > children ;
2014-02-10 02:10:30 +01:00
else
break ;
}
return last ;
}
2017-08-10 21:02:19 +02:00
void Tree : : item_edited ( int p_column , TreeItem * p_item , bool p_lmb ) {
2015-08-31 00:37:23 +02:00
2017-03-05 16:44:50 +01:00
edited_item = p_item ;
edited_col = p_column ;
2017-08-10 21:02:19 +02:00
if ( p_lmb )
emit_signal ( " item_edited " ) ;
else
emit_signal ( " item_rmb_edited " ) ;
2014-02-10 02:10:30 +01:00
}
2017-03-05 16:44:50 +01:00
void Tree : : item_changed ( int p_column , TreeItem * p_item ) {
2014-02-10 02:10:30 +01:00
2015-08-31 00:37:23 +02:00
update ( ) ;
2014-02-10 02:10:30 +01:00
}
2017-03-05 16:44:50 +01:00
void Tree : : item_selected ( int p_column , TreeItem * p_item ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
if ( select_mode = = SELECT_MULTI ) {
2015-08-31 00:37:23 +02:00
2014-02-10 02:10:30 +01:00
if ( ! p_item - > cells [ p_column ] . selectable )
return ;
2018-07-25 03:11:03 +02:00
p_item - > cells . write [ p_column ] . selected = true ;
2014-02-10 02:10:30 +01:00
//emit_signal("multi_selected",p_item,p_column,true); - NO this is for TreeItem::select
2018-01-13 17:27:32 +01:00
selected_col = p_column ;
2014-02-10 02:10:30 +01:00
} else {
2016-07-28 21:37:52 +02:00
2017-03-05 16:44:50 +01:00
select_single_item ( p_item , root , p_column ) ;
2014-02-10 02:10:30 +01:00
}
update ( ) ;
}
2017-03-05 16:44:50 +01:00
void Tree : : item_deselected ( int p_column , TreeItem * p_item ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
if ( select_mode = = SELECT_MULTI | | select_mode = = SELECT_SINGLE ) {
2018-07-25 03:11:03 +02:00
p_item - > cells . write [ p_column ] . selected = false ;
2015-08-31 00:37:23 +02:00
}
2014-02-10 02:10:30 +01:00
update ( ) ;
}
void Tree : : set_select_mode ( SelectMode p_mode ) {
2017-03-05 16:44:50 +01:00
select_mode = p_mode ;
2014-02-10 02:10:30 +01:00
}
2018-01-11 23:35:12 +01:00
Tree : : SelectMode Tree : : get_select_mode ( ) const {
return select_mode ;
}
2017-11-27 16:58:28 +01:00
void Tree : : deselect_all ( ) {
TreeItem * item = get_next_selected ( get_root ( ) ) ;
while ( item ) {
item - > deselect ( selected_col ) ;
2018-01-13 17:27:32 +01:00
TreeItem * prev_item = item ;
2017-11-27 16:58:28 +01:00
item = get_next_selected ( get_root ( ) ) ;
2018-01-13 17:27:32 +01:00
ERR_FAIL_COND ( item = = prev_item ) ;
2017-11-27 16:58:28 +01:00
}
2020-04-02 01:20:12 +02:00
selected_item = nullptr ;
2017-11-27 16:58:28 +01:00
selected_col = - 1 ;
update ( ) ;
}
bool Tree : : is_anything_selected ( ) {
2020-04-02 01:20:12 +02:00
return ( selected_item ! = nullptr ) ;
2017-11-27 16:58:28 +01:00
}
2014-02-10 02:10:30 +01:00
void Tree : : clear ( ) {
2019-06-20 16:59:48 +02:00
ERR_FAIL_COND ( blocked > 0 ) ;
2014-02-10 02:10:30 +01:00
2016-03-18 00:10:09 +01:00
if ( pressing_for_editor ) {
if ( range_drag_enabled ) {
range_drag_enabled = false ;
2020-03-04 17:36:09 +01:00
InputFilter : : get_singleton ( ) - > set_mouse_mode ( InputFilter : : MOUSE_MODE_VISIBLE ) ;
2016-03-18 00:10:09 +01:00
warp_mouse ( range_drag_capture_pos ) ;
}
pressing_for_editor = false ;
}
2014-02-10 02:10:30 +01:00
if ( root ) {
2017-03-05 16:44:50 +01:00
memdelete ( root ) ;
2020-04-02 01:20:12 +02:00
root = nullptr ;
2014-02-10 02:10:30 +01:00
} ;
2020-04-02 01:20:12 +02:00
selected_item = nullptr ;
edited_item = nullptr ;
popup_edited_item = nullptr ;
2014-02-10 02:10:30 +01:00
update ( ) ;
} ;
void Tree : : set_hide_root ( bool p_enabled ) {
2017-03-05 16:44:50 +01:00
hide_root = p_enabled ;
2015-08-31 00:37:23 +02:00
update ( ) ;
2014-02-10 02:10:30 +01:00
}
2018-01-11 23:35:12 +01:00
bool Tree : : is_root_hidden ( ) const {
return hide_root ;
}
2017-03-05 16:44:50 +01:00
void Tree : : set_column_min_width ( int p_column , int p_min_width ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
ERR_FAIL_INDEX ( p_column , columns . size ( ) ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
if ( p_min_width < 1 )
2014-02-10 02:10:30 +01:00
return ;
2018-07-25 03:11:03 +02:00
columns . write [ p_column ] . min_width = p_min_width ;
2014-02-10 02:10:30 +01:00
update ( ) ;
}
2017-03-05 16:44:50 +01:00
void Tree : : set_column_expand ( int p_column , bool p_expand ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
ERR_FAIL_INDEX ( p_column , columns . size ( ) ) ;
2015-08-31 00:37:23 +02:00
2018-07-25 03:11:03 +02:00
columns . write [ p_column ] . expand = p_expand ;
2014-02-10 02:10:30 +01:00
update ( ) ;
}
TreeItem * Tree : : get_selected ( ) const {
return selected_item ;
}
int Tree : : get_selected_column ( ) const {
return selected_col ;
}
TreeItem * Tree : : get_edited ( ) const {
2015-08-31 00:37:23 +02:00
2014-02-10 02:10:30 +01:00
return edited_item ;
}
int Tree : : get_edited_column ( ) const {
2015-08-31 00:37:23 +02:00
2014-02-10 02:10:30 +01:00
return edited_col ;
}
2017-03-05 16:44:50 +01:00
TreeItem * Tree : : get_next_selected ( TreeItem * p_item ) {
2015-08-31 00:37:23 +02:00
2017-01-14 12:26:56 +01:00
/*
if ( ! p_item )
2020-04-02 01:20:12 +02:00
return nullptr ;
2017-01-14 12:26:56 +01:00
*/
2014-02-10 02:10:30 +01:00
if ( ! root )
2020-04-02 01:20:12 +02:00
return nullptr ;
2015-08-31 00:37:23 +02:00
2017-03-05 16:44:50 +01:00
while ( true ) {
2015-08-31 00:37:23 +02:00
2014-02-10 02:10:30 +01:00
if ( ! p_item ) {
2017-03-05 16:44:50 +01:00
p_item = root ;
2014-02-10 02:10:30 +01:00
} else {
2015-08-31 00:37:23 +02:00
2018-01-18 21:37:17 +01:00
if ( p_item - > children ) {
2015-08-31 00:37:23 +02:00
2018-01-18 21:37:17 +01:00
p_item = p_item - > children ;
2015-08-31 00:37:23 +02:00
2014-02-10 02:10:30 +01:00
} else if ( p_item - > next ) {
2015-08-31 00:37:23 +02:00
2017-03-05 16:44:50 +01:00
p_item = p_item - > next ;
2014-02-10 02:10:30 +01:00
} else {
2015-08-31 00:37:23 +02:00
2017-03-05 16:44:50 +01:00
while ( ! p_item - > next ) {
2015-08-31 00:37:23 +02:00
2017-03-05 16:44:50 +01:00
p_item = p_item - > parent ;
2020-04-02 01:20:12 +02:00
if ( p_item = = nullptr )
return nullptr ;
2014-02-10 02:10:30 +01:00
}
2015-08-31 00:37:23 +02:00
2017-03-05 16:44:50 +01:00
p_item = p_item - > next ;
2014-02-10 02:10:30 +01:00
}
}
2015-08-31 00:37:23 +02:00
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < columns . size ( ) ; i + + )
2014-02-10 02:10:30 +01:00
if ( p_item - > cells [ i ] . selected )
return p_item ;
}
2015-08-31 00:37:23 +02:00
2020-04-02 01:20:12 +02:00
return nullptr ;
2014-02-10 02:10:30 +01:00
}
int Tree : : get_column_width ( int p_column ) const {
2015-08-31 00:37:23 +02:00
2017-03-05 16:44:50 +01:00
ERR_FAIL_INDEX_V ( p_column , columns . size ( ) , - 1 ) ;
2015-08-31 00:37:23 +02:00
2014-02-10 02:10:30 +01:00
if ( ! columns [ p_column ] . expand )
return columns [ p_column ] . min_width ;
2015-08-31 00:37:23 +02:00
2014-02-10 02:10:30 +01:00
Ref < StyleBox > bg = cache . bg ;
2015-08-31 00:37:23 +02:00
2017-03-05 16:44:50 +01:00
int expand_area = get_size ( ) . width - ( bg - > get_margin ( MARGIN_LEFT ) + bg - > get_margin ( MARGIN_RIGHT ) ) ;
2015-08-31 00:37:23 +02:00
2017-01-13 14:45:50 +01:00
if ( v_scroll - > is_visible_in_tree ( ) )
2017-03-05 16:44:50 +01:00
expand_area - = v_scroll - > get_combined_minimum_size ( ) . width ;
2015-08-31 00:37:23 +02:00
2017-03-05 16:44:50 +01:00
int expanding_columns = 0 ;
int expanding_total = 0 ;
2015-08-31 00:37:23 +02:00
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < columns . size ( ) ; i + + ) {
2015-08-31 00:37:23 +02:00
2014-02-10 02:10:30 +01:00
if ( ! columns [ i ] . expand ) {
2017-03-05 16:44:50 +01:00
expand_area - = columns [ i ] . min_width ;
2014-02-10 02:10:30 +01:00
} else {
2017-03-05 16:44:50 +01:00
expanding_total + = columns [ i ] . min_width ;
2014-02-10 02:10:30 +01:00
expanding_columns + + ;
}
}
2017-03-05 16:44:50 +01:00
if ( expand_area < expanding_total )
2014-02-10 02:10:30 +01:00
return columns [ p_column ] . min_width ;
2015-08-31 00:37:23 +02:00
2017-03-24 21:45:31 +01:00
ERR_FAIL_COND_V ( expanding_columns = = 0 , - 1 ) ; // shouldn't happen
2015-08-31 00:37:23 +02:00
2014-02-10 02:10:30 +01:00
return expand_area * columns [ p_column ] . min_width / expanding_total ;
}
void Tree : : propagate_set_columns ( TreeItem * p_item ) {
2015-08-31 00:37:23 +02:00
2017-03-05 16:44:50 +01:00
p_item - > cells . resize ( columns . size ( ) ) ;
2015-08-31 00:37:23 +02:00
2014-02-10 02:10:30 +01:00
TreeItem * c = p_item - > get_children ( ) ;
2017-03-05 16:44:50 +01:00
while ( c ) {
2015-08-31 00:37:23 +02:00
2014-02-10 02:10:30 +01:00
propagate_set_columns ( c ) ;
2017-03-05 16:44:50 +01:00
c = c - > get_next ( ) ;
2014-02-10 02:10:30 +01:00
}
}
void Tree : : set_columns ( int p_columns ) {
2015-08-31 00:37:23 +02:00
2017-03-05 16:44:50 +01:00
ERR_FAIL_COND ( p_columns < 1 ) ;
ERR_FAIL_COND ( blocked > 0 ) ;
2014-02-10 02:10:30 +01:00
columns . resize ( p_columns ) ;
2015-08-31 00:37:23 +02:00
2014-02-10 02:10:30 +01:00
if ( root )
propagate_set_columns ( root ) ;
2017-03-05 16:44:50 +01:00
if ( selected_col > = p_columns )
selected_col = p_columns - 1 ;
2014-02-10 02:10:30 +01:00
update ( ) ;
}
int Tree : : get_columns ( ) const {
2015-08-31 00:37:23 +02:00
2014-02-10 02:10:30 +01:00
return columns . size ( ) ;
}
void Tree : : _scroll_moved ( float ) {
2015-08-31 00:37:23 +02:00
2014-02-10 02:10:30 +01:00
update ( ) ;
}
Rect2 Tree : : get_custom_popup_rect ( ) const {
2015-08-31 00:37:23 +02:00
2014-02-10 02:10:30 +01:00
return custom_popup_rect ;
}
int Tree : : get_item_offset ( TreeItem * p_item ) const {
2017-03-05 16:44:50 +01:00
TreeItem * it = root ;
int ofs = _get_title_button_height ( ) ;
2014-02-10 02:10:30 +01:00
if ( ! it )
return 0 ;
2017-03-05 16:44:50 +01:00
while ( true ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
if ( it = = p_item )
2014-02-10 02:10:30 +01:00
return ofs ;
2020-01-02 02:20:43 +01:00
ofs + = compute_item_height ( it ) ;
if ( it ! = root | | ! hide_root ) {
ofs + = cache . vseparation ;
}
2014-02-10 02:10:30 +01:00
2018-01-18 21:37:17 +01:00
if ( it - > children & & ! it - > collapsed ) {
2014-02-10 02:10:30 +01:00
2018-01-18 21:37:17 +01:00
it = it - > children ;
2014-02-10 02:10:30 +01:00
} else if ( it - > next ) {
2017-03-05 16:44:50 +01:00
it = it - > next ;
2014-02-10 02:10:30 +01:00
} else {
2017-03-05 16:44:50 +01:00
while ( ! it - > next ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
it = it - > parent ;
2020-04-02 01:20:12 +02:00
if ( it = = nullptr )
2014-02-10 02:10:30 +01:00
return 0 ;
}
2017-03-05 16:44:50 +01:00
it = it - > next ;
2014-02-10 02:10:30 +01:00
}
}
return - 1 ; //not found
}
void Tree : : ensure_cursor_is_visible ( ) {
2020-01-03 11:29:22 +01:00
if ( ! is_inside_tree ( ) ) {
2014-02-10 02:10:30 +01:00
return ;
2020-01-03 11:29:22 +01:00
}
if ( ! selected_item | | ( selected_col = = - 1 ) ) {
return ; // Nothing under cursor.
}
2014-02-10 02:10:30 +01:00
2020-01-03 11:29:22 +01:00
const Size2 area_size = get_size ( ) - cache . bg - > get_minimum_size ( ) ;
2020-01-01 15:20:12 +01:00
2020-01-03 11:29:22 +01:00
int y_offset = get_item_offset ( selected_item ) ;
if ( y_offset ! = - 1 ) {
const int tbh = _get_title_button_height ( ) ;
y_offset - = tbh ;
2020-01-01 15:20:12 +01:00
2020-01-03 11:29:22 +01:00
const int cell_h = compute_item_height ( selected_item ) + cache . vseparation ;
const int screen_h = area_size . height - h_scroll - > get_combined_minimum_size ( ) . height - tbh ;
2014-02-10 02:10:30 +01:00
2020-01-03 11:29:22 +01:00
if ( cell_h > screen_h ) { // Screen size is too small, maybe it was not resized yet.
v_scroll - > set_value ( y_offset ) ;
} else if ( y_offset + cell_h > v_scroll - > get_value ( ) + screen_h ) {
v_scroll - > call_deferred ( " set_value " , y_offset - screen_h + cell_h ) ;
} else if ( y_offset < v_scroll - > get_value ( ) ) {
v_scroll - > set_value ( y_offset ) ;
}
}
if ( select_mode ! = SELECT_ROW ) { // Cursor always at col 0 in this mode.
int x_offset = 0 ;
for ( int i = 0 ; i < selected_col ; i + + ) {
x_offset + = get_column_width ( i ) ;
}
const int cell_w = get_column_width ( selected_col ) ;
const int screen_w = area_size . width - v_scroll - > get_combined_minimum_size ( ) . width ;
if ( cell_w > screen_w ) {
h_scroll - > set_value ( x_offset ) ;
} else if ( x_offset + cell_w > h_scroll - > get_value ( ) + screen_w ) {
h_scroll - > call_deferred ( " set_value " , x_offset - screen_w + cell_w ) ;
} else if ( x_offset < h_scroll - > get_value ( ) ) {
h_scroll - > set_value ( x_offset ) ;
}
2019-04-12 04:21:48 +02:00
}
2014-02-10 02:10:30 +01:00
}
int Tree : : get_pressed_button ( ) const {
return pressed_button ;
}
2017-03-05 16:44:50 +01:00
Rect2 Tree : : get_item_rect ( TreeItem * p_item , int p_column ) const {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
ERR_FAIL_NULL_V ( p_item , Rect2 ( ) ) ;
ERR_FAIL_COND_V ( p_item - > tree ! = this , Rect2 ( ) ) ;
if ( p_column ! = - 1 ) {
ERR_FAIL_INDEX_V ( p_column , columns . size ( ) , Rect2 ( ) ) ;
2014-02-10 02:10:30 +01:00
}
int ofs = get_item_offset ( p_item ) ;
int height = compute_item_height ( p_item ) ;
Rect2 r ;
2017-06-04 00:25:13 +02:00
r . position . y = ofs ;
2017-03-05 16:44:50 +01:00
r . size . height = height ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
if ( p_column = = - 1 ) {
2017-06-04 00:25:13 +02:00
r . position . x = 0 ;
2017-03-05 16:44:50 +01:00
r . size . x = get_size ( ) . width ;
2014-02-10 02:10:30 +01:00
} else {
2017-03-05 16:44:50 +01:00
int accum = 0 ;
for ( int i = 0 ; i < p_column ; i + + ) {
accum + = get_column_width ( i ) ;
2014-02-10 02:10:30 +01:00
}
2017-06-04 00:25:13 +02:00
r . position . x = accum ;
2017-03-05 16:44:50 +01:00
r . size . x = get_column_width ( p_column ) ;
2014-02-10 02:10:30 +01:00
}
return r ;
}
void Tree : : set_column_titles_visible ( bool p_show ) {
2017-03-05 16:44:50 +01:00
show_column_titles = p_show ;
2014-02-10 02:10:30 +01:00
update ( ) ;
}
bool Tree : : are_column_titles_visible ( ) const {
return show_column_titles ;
}
2017-03-05 16:44:50 +01:00
void Tree : : set_column_title ( int p_column , const String & p_title ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
ERR_FAIL_INDEX ( p_column , columns . size ( ) ) ;
2018-07-25 03:11:03 +02:00
columns . write [ p_column ] . title = p_title ;
2014-02-10 02:10:30 +01:00
update ( ) ;
}
String Tree : : get_column_title ( int p_column ) const {
2017-03-05 16:44:50 +01:00
ERR_FAIL_INDEX_V ( p_column , columns . size ( ) , " " ) ;
2014-02-10 02:10:30 +01:00
return columns [ p_column ] . title ;
}
Point2 Tree : : get_scroll ( ) const {
Point2 ofs ;
2017-01-13 14:45:50 +01:00
if ( h_scroll - > is_visible_in_tree ( ) )
2017-03-05 16:44:50 +01:00
ofs . x = h_scroll - > get_value ( ) ;
2017-01-13 14:45:50 +01:00
if ( v_scroll - > is_visible_in_tree ( ) )
2017-03-05 16:44:50 +01:00
ofs . y = v_scroll - > get_value ( ) ;
2014-02-10 02:10:30 +01:00
return ofs ;
}
2017-11-04 20:21:41 +01:00
void Tree : : scroll_to_item ( TreeItem * p_item ) {
if ( ! is_visible_in_tree ( ) ) {
// hack to work around crash in get_item_rect() if Tree is not in tree.
return ;
}
// make sure the scrollbar min and max are up to date with latest changes.
update_scrollbars ( ) ;
const Rect2 r = get_item_rect ( p_item ) ;
if ( r . position . y < v_scroll - > get_value ( ) ) {
v_scroll - > set_value ( r . position . y ) ;
} else if ( r . position . y + r . size . y + 2 * cache . vseparation > v_scroll - > get_value ( ) + get_size ( ) . y ) {
v_scroll - > set_value ( r . position . y + r . size . y + 2 * cache . vseparation - get_size ( ) . y ) ;
}
}
2017-03-05 16:44:50 +01:00
TreeItem * Tree : : _search_item_text ( TreeItem * p_at , const String & p_find , int * r_col , bool p_selectable , bool p_backwards ) {
2014-02-10 02:10:30 +01:00
2019-05-11 18:32:53 +02:00
TreeItem * from = p_at ;
2017-03-05 16:44:50 +01:00
while ( p_at ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < columns . size ( ) ; i + + ) {
if ( p_at - > get_text ( i ) . findn ( p_find ) = = 0 & & ( ! p_selectable | | p_at - > is_selectable ( i ) ) ) {
2014-02-10 02:10:30 +01:00
if ( r_col )
2017-03-05 16:44:50 +01:00
* r_col = i ;
2014-02-10 02:10:30 +01:00
return p_at ;
}
}
if ( p_backwards )
2019-05-11 18:32:53 +02:00
p_at = p_at - > get_prev_visible ( true ) ;
2014-02-10 02:10:30 +01:00
else
2019-05-11 18:32:53 +02:00
p_at = p_at - > get_next_visible ( true ) ;
if ( ( p_at ) = = from )
break ;
2014-02-10 02:10:30 +01:00
}
2020-04-02 01:20:12 +02:00
return nullptr ;
2014-02-10 02:10:30 +01:00
}
2017-03-05 16:44:50 +01:00
TreeItem * Tree : : search_item_text ( const String & p_find , int * r_col , bool p_selectable ) {
2014-02-10 02:10:30 +01:00
2019-06-04 01:50:50 +02:00
TreeItem * from = get_selected ( ) ;
2019-05-11 18:32:53 +02:00
2019-06-04 01:50:50 +02:00
if ( ! from )
2019-05-11 18:32:53 +02:00
from = root ;
if ( ! from )
2020-04-02 01:20:12 +02:00
return nullptr ;
2014-02-10 02:10:30 +01:00
2019-06-04 01:50:50 +02:00
return _search_item_text ( from - > get_next_visible ( true ) , p_find , r_col , p_selectable ) ;
2014-02-10 02:10:30 +01:00
}
2020-02-02 04:07:01 +01:00
TreeItem * Tree : : get_item_with_text ( const String & p_find ) const {
for ( TreeItem * current = root ; current ; current = current - > get_next_visible ( ) ) {
for ( int i = 0 ; i < columns . size ( ) ; i + + ) {
if ( current - > get_text ( i ) = = p_find ) {
return current ;
}
}
}
2020-04-02 01:20:12 +02:00
return nullptr ;
2020-02-02 04:07:01 +01:00
}
2017-03-05 16:44:50 +01:00
void Tree : : _do_incr_search ( const String & p_add ) {
2014-02-10 02:10:30 +01:00
uint64_t time = OS : : get_singleton ( ) - > get_ticks_usec ( ) / 1000 ; // convert to msec
uint64_t diff = time - last_keypress ;
2017-03-05 16:44:50 +01:00
if ( diff > uint64_t ( GLOBAL_DEF ( " gui/timers/incremental_search_max_interval_msec " , 2000 ) ) )
incr_search = p_add ;
2019-05-11 18:32:53 +02:00
else if ( incr_search ! = p_add )
2017-03-05 16:44:50 +01:00
incr_search + = p_add ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
last_keypress = time ;
2014-02-10 02:10:30 +01:00
int col ;
2017-03-05 16:44:50 +01:00
TreeItem * item = search_item_text ( incr_search , & col , true ) ;
2014-02-10 02:10:30 +01:00
if ( ! item )
return ;
item - > select ( col ) ;
ensure_cursor_is_visible ( ) ;
}
2017-03-05 16:44:50 +01:00
TreeItem * Tree : : _find_item_at_pos ( TreeItem * p_item , const Point2 & p_pos , int & r_column , int & h , int & section ) const {
2014-02-10 02:10:30 +01:00
Point2 pos = p_pos ;
2017-03-05 16:44:50 +01:00
if ( root ! = p_item | | ! hide_root ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
h = compute_item_height ( p_item ) + cache . vseparation ;
if ( pos . y < h ) {
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
if ( drop_mode_flags = = DROP_MODE_ON_ITEM ) {
section = 0 ;
} else if ( drop_mode_flags = = DROP_MODE_INBETWEEN ) {
section = pos . y < h / 2 ? - 1 : 1 ;
} else if ( pos . y < h / 4 ) {
section = - 1 ;
} else if ( pos . y > = ( h * 3 / 4 ) ) {
section = 1 ;
2016-05-11 16:46:08 +02:00
} else {
2017-03-05 16:44:50 +01:00
section = 0 ;
2016-05-11 16:46:08 +02:00
}
2017-03-05 16:44:50 +01:00
for ( int i = 0 ; i < columns . size ( ) ; i + + ) {
2014-02-10 02:10:30 +01:00
int w = get_column_width ( i ) ;
if ( pos . x < w ) {
2017-03-05 16:44:50 +01:00
r_column = i ;
2016-05-11 16:46:08 +02:00
2014-02-10 02:10:30 +01:00
return p_item ;
}
2017-03-05 16:44:50 +01:00
pos . x - = w ;
2014-02-10 02:10:30 +01:00
}
2016-05-11 16:46:08 +02:00
2020-04-02 01:20:12 +02:00
return nullptr ;
2014-02-10 02:10:30 +01:00
} else {
2017-03-05 16:44:50 +01:00
pos . y - = h ;
2014-02-10 02:10:30 +01:00
}
} else {
2017-03-05 16:44:50 +01:00
h = 0 ;
2014-02-10 02:10:30 +01:00
}
if ( p_item - > is_collapsed ( ) )
2020-04-02 01:20:12 +02:00
return nullptr ; // do not try children, it's collapsed
2014-02-10 02:10:30 +01:00
TreeItem * n = p_item - > get_children ( ) ;
2017-03-05 16:44:50 +01:00
while ( n ) {
2014-02-10 02:10:30 +01:00
int ch ;
2017-03-05 16:44:50 +01:00
TreeItem * r = _find_item_at_pos ( n , pos , r_column , ch , section ) ;
pos . y - = ch ;
h + = ch ;
2014-02-10 02:10:30 +01:00
if ( r )
return r ;
2017-03-05 16:44:50 +01:00
n = n - > get_next ( ) ;
2014-02-10 02:10:30 +01:00
}
2020-04-02 01:20:12 +02:00
return nullptr ;
2014-02-10 02:10:30 +01:00
}
2017-09-10 15:37:49 +02:00
int Tree : : get_column_at_position ( const Point2 & p_pos ) const {
2016-05-11 16:46:08 +02:00
if ( root ) {
2017-03-05 16:44:50 +01:00
Point2 pos = p_pos ;
2016-05-11 16:46:08 +02:00
pos - = cache . bg - > get_offset ( ) ;
2017-03-05 16:44:50 +01:00
pos . y - = _get_title_button_height ( ) ;
if ( pos . y < 0 )
2016-05-11 16:46:08 +02:00
return - 1 ;
2017-01-13 14:45:50 +01:00
if ( h_scroll - > is_visible_in_tree ( ) )
2017-03-05 16:44:50 +01:00
pos . x + = h_scroll - > get_value ( ) ;
2017-01-13 14:45:50 +01:00
if ( v_scroll - > is_visible_in_tree ( ) )
2017-03-05 16:44:50 +01:00
pos . y + = v_scroll - > get_value ( ) ;
2016-05-11 16:46:08 +02:00
2017-03-05 16:44:50 +01:00
int col , h , section ;
TreeItem * it = _find_item_at_pos ( root , pos , col , h , section ) ;
2016-05-11 16:46:08 +02:00
if ( it ) {
return col ;
}
}
return - 1 ;
}
2017-09-10 15:37:49 +02:00
int Tree : : get_drop_section_at_position ( const Point2 & p_pos ) const {
2016-05-11 16:46:08 +02:00
if ( root ) {
2017-03-05 16:44:50 +01:00
Point2 pos = p_pos ;
2016-05-11 16:46:08 +02:00
pos - = cache . bg - > get_offset ( ) ;
2017-03-05 16:44:50 +01:00
pos . y - = _get_title_button_height ( ) ;
if ( pos . y < 0 )
2016-05-11 16:46:08 +02:00
return - 100 ;
2017-01-13 14:45:50 +01:00
if ( h_scroll - > is_visible_in_tree ( ) )
2017-03-05 16:44:50 +01:00
pos . x + = h_scroll - > get_value ( ) ;
2017-01-13 14:45:50 +01:00
if ( v_scroll - > is_visible_in_tree ( ) )
2017-03-05 16:44:50 +01:00
pos . y + = v_scroll - > get_value ( ) ;
2016-05-11 16:46:08 +02:00
2017-03-05 16:44:50 +01:00
int col , h , section ;
TreeItem * it = _find_item_at_pos ( root , pos , col , h , section ) ;
2016-05-11 16:46:08 +02:00
if ( it ) {
return section ;
}
}
return - 100 ;
}
2017-09-10 15:37:49 +02:00
TreeItem * Tree : : get_item_at_position ( const Point2 & p_pos ) const {
2016-05-11 16:46:08 +02:00
if ( root ) {
2017-03-05 16:44:50 +01:00
Point2 pos = p_pos ;
2016-05-11 16:46:08 +02:00
pos - = cache . bg - > get_offset ( ) ;
2017-03-05 16:44:50 +01:00
pos . y - = _get_title_button_height ( ) ;
if ( pos . y < 0 )
2020-04-02 01:20:12 +02:00
return nullptr ;
2016-05-11 16:46:08 +02:00
2017-01-13 14:45:50 +01:00
if ( h_scroll - > is_visible_in_tree ( ) )
2017-03-05 16:44:50 +01:00
pos . x + = h_scroll - > get_value ( ) ;
2017-01-13 14:45:50 +01:00
if ( v_scroll - > is_visible_in_tree ( ) )
2017-03-05 16:44:50 +01:00
pos . y + = v_scroll - > get_value ( ) ;
2016-05-11 16:46:08 +02:00
2017-03-05 16:44:50 +01:00
int col , h , section ;
TreeItem * it = _find_item_at_pos ( root , pos , col , h , section ) ;
2016-05-11 16:46:08 +02:00
if ( it ) {
return it ;
}
}
2020-04-02 01:20:12 +02:00
return nullptr ;
2016-05-11 16:46:08 +02:00
}
2017-03-05 16:44:50 +01:00
String Tree : : get_tooltip ( const Point2 & p_pos ) const {
2014-02-10 02:10:30 +01:00
if ( root ) {
2014-09-21 06:43:42 +02:00
2017-03-05 16:44:50 +01:00
Point2 pos = p_pos ;
2014-02-10 02:10:30 +01:00
pos - = cache . bg - > get_offset ( ) ;
2017-03-05 16:44:50 +01:00
pos . y - = _get_title_button_height ( ) ;
if ( pos . y < 0 )
2014-02-10 02:10:30 +01:00
return Control : : get_tooltip ( p_pos ) ;
2017-01-13 14:45:50 +01:00
if ( h_scroll - > is_visible_in_tree ( ) )
2017-03-05 16:44:50 +01:00
pos . x + = h_scroll - > get_value ( ) ;
2017-01-13 14:45:50 +01:00
if ( v_scroll - > is_visible_in_tree ( ) )
2017-03-05 16:44:50 +01:00
pos . y + = v_scroll - > get_value ( ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
int col , h , section ;
TreeItem * it = _find_item_at_pos ( root , pos , col , h , section ) ;
2014-02-10 02:10:30 +01:00
2014-09-21 06:43:42 +02:00
if ( it ) {
2014-02-10 02:10:30 +01:00
2018-07-25 03:11:03 +02:00
const TreeItem : : Cell & c = it - > cells [ col ] ;
2017-04-24 21:41:17 +02:00
int col_width = get_column_width ( col ) ;
2019-06-10 05:33:47 +02:00
for ( int i = 0 ; i < col ; i + + )
pos . x - = get_column_width ( i ) ;
2017-04-24 21:41:17 +02:00
for ( int j = c . buttons . size ( ) - 1 ; j > = 0 ; j - - ) {
2019-06-11 20:43:37 +02:00
Ref < Texture2D > b = c . buttons [ j ] . texture ;
2017-04-24 21:41:17 +02:00
Size2 size = b - > get_size ( ) + cache . button_pressed - > get_minimum_size ( ) ;
if ( pos . x > col_width - size . width ) {
String tooltip = c . buttons [ j ] . tooltip ;
if ( tooltip ! = " " ) {
return tooltip ;
}
}
col_width - = size . width ;
}
2014-02-10 02:10:30 +01:00
String ret ;
2017-03-05 16:44:50 +01:00
if ( it - > get_tooltip ( col ) = = " " )
ret = it - > get_text ( col ) ;
2014-02-10 02:10:30 +01:00
else
2017-03-05 16:44:50 +01:00
ret = it - > get_tooltip ( col ) ;
2014-02-10 02:10:30 +01:00
return ret ;
}
}
return Control : : get_tooltip ( p_pos ) ;
}
void Tree : : set_cursor_can_exit_tree ( bool p_enable ) {
2017-03-05 16:44:50 +01:00
cursor_can_exit_tree = p_enable ;
2014-02-10 02:10:30 +01:00
}
bool Tree : : can_cursor_exit_tree ( ) const {
return cursor_can_exit_tree ;
}
2015-11-14 00:56:44 +01:00
void Tree : : set_hide_folding ( bool p_hide ) {
2017-03-05 16:44:50 +01:00
hide_folding = p_hide ;
2015-11-14 00:56:44 +01:00
update ( ) ;
}
bool Tree : : is_folding_hidden ( ) const {
return hide_folding ;
}
2016-05-11 16:46:08 +02:00
void Tree : : set_drop_mode_flags ( int p_flags ) {
2017-03-05 16:44:50 +01:00
if ( drop_mode_flags = = p_flags )
2016-05-12 01:57:52 +02:00
return ;
2017-03-05 16:44:50 +01:00
drop_mode_flags = p_flags ;
if ( drop_mode_flags = = 0 ) {
2020-04-02 01:20:12 +02:00
drop_mode_over = nullptr ;
2016-05-11 16:46:08 +02:00
}
update ( ) ;
}
int Tree : : get_drop_mode_flags ( ) const {
return drop_mode_flags ;
}
2017-01-21 23:00:25 +01:00
void Tree : : set_edit_checkbox_cell_only_when_checkbox_is_pressed ( bool p_enable ) {
2017-03-05 16:44:50 +01:00
force_edit_checkbox_only_on_checkbox = p_enable ;
2017-01-21 23:00:25 +01:00
}
bool Tree : : get_edit_checkbox_cell_only_when_checkbox_is_pressed ( ) const {
return force_edit_checkbox_only_on_checkbox ;
}
2016-05-16 04:41:48 +02:00
void Tree : : set_allow_rmb_select ( bool p_allow ) {
2017-03-05 16:44:50 +01:00
allow_rmb_select = p_allow ;
2016-05-16 04:41:48 +02:00
}
2017-03-05 16:44:50 +01:00
bool Tree : : get_allow_rmb_select ( ) const {
2016-05-16 04:41:48 +02:00
return allow_rmb_select ;
}
2017-08-18 23:19:12 +02:00
void Tree : : set_allow_reselect ( bool p_allow ) {
allow_reselect = p_allow ;
}
bool Tree : : get_allow_reselect ( ) const {
return allow_reselect ;
}
2014-02-10 02:10:30 +01:00
void Tree : : _bind_methods ( ) {
2015-08-31 00:37:23 +02:00
2017-03-05 16:44:50 +01:00
ClassDB : : bind_method ( D_METHOD ( " _gui_input " ) , & Tree : : _gui_input ) ;
ClassDB : : bind_method ( D_METHOD ( " clear " ) , & Tree : : clear ) ;
2017-12-14 22:13:48 +01:00
ClassDB : : bind_method ( D_METHOD ( " create_item " , " parent " , " idx " ) , & Tree : : _create_item , DEFVAL ( Variant ( ) ) , DEFVAL ( - 1 ) ) ;
2017-03-05 16:44:50 +01:00
2017-08-09 13:19:41 +02:00
ClassDB : : bind_method ( D_METHOD ( " get_root " ) , & Tree : : get_root ) ;
2017-03-05 16:44:50 +01:00
ClassDB : : bind_method ( D_METHOD ( " set_column_min_width " , " column " , " min_width " ) , & Tree : : set_column_min_width ) ;
ClassDB : : bind_method ( D_METHOD ( " set_column_expand " , " column " , " expand " ) , & Tree : : set_column_expand ) ;
ClassDB : : bind_method ( D_METHOD ( " get_column_width " , " column " ) , & Tree : : get_column_width ) ;
ClassDB : : bind_method ( D_METHOD ( " set_hide_root " , " enable " ) , & Tree : : set_hide_root ) ;
2018-01-11 23:35:12 +01:00
ClassDB : : bind_method ( D_METHOD ( " is_root_hidden " ) , & Tree : : is_root_hidden ) ;
2017-08-09 13:19:41 +02:00
ClassDB : : bind_method ( D_METHOD ( " get_next_selected " , " from " ) , & Tree : : _get_next_selected ) ;
ClassDB : : bind_method ( D_METHOD ( " get_selected " ) , & Tree : : get_selected ) ;
2017-03-05 16:44:50 +01:00
ClassDB : : bind_method ( D_METHOD ( " get_selected_column " ) , & Tree : : get_selected_column ) ;
ClassDB : : bind_method ( D_METHOD ( " get_pressed_button " ) , & Tree : : get_pressed_button ) ;
ClassDB : : bind_method ( D_METHOD ( " set_select_mode " , " mode " ) , & Tree : : set_select_mode ) ;
2018-01-11 23:35:12 +01:00
ClassDB : : bind_method ( D_METHOD ( " get_select_mode " ) , & Tree : : get_select_mode ) ;
2017-03-05 16:44:50 +01:00
ClassDB : : bind_method ( D_METHOD ( " set_columns " , " amount " ) , & Tree : : set_columns ) ;
ClassDB : : bind_method ( D_METHOD ( " get_columns " ) , & Tree : : get_columns ) ;
2017-08-09 13:19:41 +02:00
ClassDB : : bind_method ( D_METHOD ( " get_edited " ) , & Tree : : get_edited ) ;
2017-03-05 16:44:50 +01:00
ClassDB : : bind_method ( D_METHOD ( " get_edited_column " ) , & Tree : : get_edited_column ) ;
ClassDB : : bind_method ( D_METHOD ( " get_custom_popup_rect " ) , & Tree : : get_custom_popup_rect ) ;
2017-08-09 13:19:41 +02:00
ClassDB : : bind_method ( D_METHOD ( " get_item_area_rect " , " item " , " column " ) , & Tree : : _get_item_rect , DEFVAL ( - 1 ) ) ;
2017-09-10 15:37:49 +02:00
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 ) ;
2017-03-05 16:44:50 +01:00
ClassDB : : bind_method ( D_METHOD ( " ensure_cursor_is_visible " ) , & Tree : : ensure_cursor_is_visible ) ;
ClassDB : : bind_method ( D_METHOD ( " set_column_titles_visible " , " visible " ) , & Tree : : set_column_titles_visible ) ;
ClassDB : : bind_method ( D_METHOD ( " are_column_titles_visible " ) , & Tree : : are_column_titles_visible ) ;
ClassDB : : bind_method ( D_METHOD ( " set_column_title " , " column " , " title " ) , & Tree : : set_column_title ) ;
ClassDB : : bind_method ( D_METHOD ( " get_column_title " , " column " ) , & Tree : : get_column_title ) ;
ClassDB : : bind_method ( D_METHOD ( " get_scroll " ) , & Tree : : get_scroll ) ;
ClassDB : : bind_method ( D_METHOD ( " set_hide_folding " , " hide " ) , & Tree : : set_hide_folding ) ;
ClassDB : : bind_method ( D_METHOD ( " is_folding_hidden " ) , & Tree : : is_folding_hidden ) ;
ClassDB : : bind_method ( D_METHOD ( " set_drop_mode_flags " , " flags " ) , & Tree : : set_drop_mode_flags ) ;
ClassDB : : bind_method ( D_METHOD ( " get_drop_mode_flags " ) , & Tree : : get_drop_mode_flags ) ;
ClassDB : : bind_method ( D_METHOD ( " set_allow_rmb_select " , " allow " ) , & Tree : : set_allow_rmb_select ) ;
ClassDB : : bind_method ( D_METHOD ( " get_allow_rmb_select " ) , & Tree : : get_allow_rmb_select ) ;
2017-08-18 23:19:12 +02:00
ClassDB : : bind_method ( D_METHOD ( " set_allow_reselect " , " allow " ) , & Tree : : set_allow_reselect ) ;
ClassDB : : bind_method ( D_METHOD ( " get_allow_reselect " ) , & Tree : : get_allow_reselect ) ;
2017-03-05 16:44:50 +01:00
2018-01-11 23:35:12 +01:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " columns " ) , " set_columns " , " get_columns " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " allow_reselect " ) , " set_allow_reselect " , " get_allow_reselect " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " allow_rmb_select " ) , " set_allow_rmb_select " , " get_allow_rmb_select " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " hide_folding " ) , " set_hide_folding " , " is_folding_hidden " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " hide_root " ) , " set_hide_root " , " is_root_hidden " ) ;
2018-01-18 21:37:17 +01:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " drop_mode_flags " , PROPERTY_HINT_FLAGS , " On Item,In between " ) , " set_drop_mode_flags " , " get_drop_mode_flags " ) ;
2018-01-11 23:35:12 +01:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " select_mode " , PROPERTY_HINT_ENUM , " Single,Row,Multi " ) , " set_select_mode " , " get_select_mode " ) ;
2017-03-05 16:44:50 +01:00
ADD_SIGNAL ( MethodInfo ( " item_selected " ) ) ;
ADD_SIGNAL ( MethodInfo ( " cell_selected " ) ) ;
2018-09-01 12:05:51 +02:00
ADD_SIGNAL ( MethodInfo ( " multi_selected " , PropertyInfo ( Variant : : OBJECT , " item " , PROPERTY_HINT_RESOURCE_TYPE , " TreeItem " ) , PropertyInfo ( Variant : : INT , " column " ) , PropertyInfo ( Variant : : BOOL , " selected " ) ) ) ;
2017-09-10 15:37:49 +02:00
ADD_SIGNAL ( MethodInfo ( " item_rmb_selected " , PropertyInfo ( Variant : : VECTOR2 , " position " ) ) ) ;
2019-04-09 19:22:14 +02:00
ADD_SIGNAL ( MethodInfo ( " empty_rmb " , PropertyInfo ( Variant : : VECTOR2 , " position " ) ) ) ;
2017-09-10 15:37:49 +02:00
ADD_SIGNAL ( MethodInfo ( " empty_tree_rmb_selected " , PropertyInfo ( Variant : : VECTOR2 , " position " ) ) ) ;
2017-03-05 16:44:50 +01:00
ADD_SIGNAL ( MethodInfo ( " item_edited " ) ) ;
2017-08-10 21:02:19 +02:00
ADD_SIGNAL ( MethodInfo ( " item_rmb_edited " ) ) ;
2017-06-05 01:35:08 +02:00
ADD_SIGNAL ( MethodInfo ( " item_custom_button_pressed " ) ) ;
2017-03-05 16:44:50 +01:00
ADD_SIGNAL ( MethodInfo ( " item_double_clicked " ) ) ;
2018-09-01 12:05:51 +02:00
ADD_SIGNAL ( MethodInfo ( " item_collapsed " , PropertyInfo ( Variant : : OBJECT , " item " , PROPERTY_HINT_RESOURCE_TYPE , " TreeItem " ) ) ) ;
2014-02-10 02:10:30 +01:00
//ADD_SIGNAL( MethodInfo("item_doubleclicked" ) );
2018-09-01 12:05:51 +02:00
ADD_SIGNAL ( MethodInfo ( " button_pressed " , PropertyInfo ( Variant : : OBJECT , " item " , PROPERTY_HINT_RESOURCE_TYPE , " TreeItem " ) , PropertyInfo ( Variant : : INT , " column " ) , PropertyInfo ( Variant : : INT , " id " ) ) ) ;
2017-03-05 16:44:50 +01:00
ADD_SIGNAL ( MethodInfo ( " custom_popup_edited " , PropertyInfo ( Variant : : BOOL , " arrow_clicked " ) ) ) ;
ADD_SIGNAL ( MethodInfo ( " item_activated " ) ) ;
2017-05-17 12:55:55 +02:00
ADD_SIGNAL ( MethodInfo ( " column_title_pressed " , PropertyInfo ( Variant : : INT , " column " ) ) ) ;
2017-11-26 12:49:21 +01:00
ADD_SIGNAL ( MethodInfo ( " nothing_selected " ) ) ;
2014-02-10 02:10:30 +01:00
2017-08-20 17:45:01 +02:00
BIND_ENUM_CONSTANT ( SELECT_SINGLE ) ;
BIND_ENUM_CONSTANT ( SELECT_ROW ) ;
BIND_ENUM_CONSTANT ( SELECT_MULTI ) ;
2016-05-11 16:46:08 +02:00
2017-08-20 17:45:01 +02:00
BIND_ENUM_CONSTANT ( DROP_MODE_DISABLED ) ;
BIND_ENUM_CONSTANT ( DROP_MODE_ON_ITEM ) ;
BIND_ENUM_CONSTANT ( DROP_MODE_INBETWEEN ) ;
2014-02-10 02:10:30 +01:00
}
Tree : : Tree ( ) {
2017-03-05 16:44:50 +01:00
selected_col = 0 ;
2014-02-10 02:10:30 +01:00
columns . resize ( 1 ) ;
2020-04-02 01:20:12 +02:00
selected_item = nullptr ;
edited_item = nullptr ;
2017-03-05 16:44:50 +01:00
selected_col = - 1 ;
edited_col = - 1 ;
hide_root = false ;
select_mode = SELECT_SINGLE ;
2020-04-02 01:20:12 +02:00
root = nullptr ;
popup_menu = nullptr ;
popup_edited_item = nullptr ;
text_editor = nullptr ;
2014-02-10 02:10:30 +01:00
set_focus_mode ( FOCUS_ALL ) ;
2015-08-31 00:37:23 +02:00
2017-03-05 16:44:50 +01:00
popup_menu = memnew ( PopupMenu ) ;
2014-02-10 02:10:30 +01:00
popup_menu - > hide ( ) ;
add_child ( popup_menu ) ;
2020-03-12 13:37:40 +01:00
// popup_menu->set_as_toplevel(true);
2020-03-20 03:32:09 +01:00
popup_editor = memnew ( PopupPanel ) ;
popup_editor - > set_wrap_controls ( true ) ;
add_child ( popup_editor ) ;
popup_editor_vb = memnew ( VBoxContainer ) ;
popup_editor - > add_child ( popup_editor_vb ) ;
popup_editor_vb - > add_theme_constant_override ( " separation " , 0 ) ;
popup_editor_vb - > set_anchors_and_margins_preset ( PRESET_WIDE ) ;
2017-03-05 16:44:50 +01:00
text_editor = memnew ( LineEdit ) ;
2020-03-20 03:32:09 +01:00
popup_editor_vb - > add_child ( text_editor ) ;
text_editor - > set_v_size_flags ( SIZE_EXPAND_FILL ) ;
text_editor - > set_h_size_flags ( SIZE_EXPAND_FILL ) ;
2017-03-05 16:44:50 +01:00
value_editor = memnew ( HSlider ) ;
2020-03-20 03:32:09 +01:00
value_editor - > set_v_size_flags ( SIZE_EXPAND_FILL ) ;
value_editor - > set_h_size_flags ( SIZE_EXPAND_FILL ) ;
popup_editor_vb - > add_child ( value_editor ) ;
2014-02-10 02:10:30 +01:00
value_editor - > hide ( ) ;
2017-03-05 16:44:50 +01:00
h_scroll = memnew ( HScrollBar ) ;
v_scroll = memnew ( VScrollBar ) ;
2015-08-31 00:37:23 +02:00
2014-02-10 02:10:30 +01:00
add_child ( h_scroll ) ;
add_child ( v_scroll ) ;
2017-03-05 16:44:50 +01:00
range_click_timer = memnew ( Timer ) ;
2020-02-21 18:28:45 +01:00
range_click_timer - > connect ( " timeout " , callable_mp ( this , & Tree : : _range_click_timeout ) ) ;
2015-12-08 19:04:56 +01:00
add_child ( range_click_timer ) ;
2020-02-21 18:28:45 +01:00
h_scroll - > connect ( " value_changed " , callable_mp ( this , & Tree : : _scroll_moved ) ) ;
v_scroll - > connect ( " value_changed " , callable_mp ( this , & Tree : : _scroll_moved ) ) ;
2020-03-20 03:32:09 +01:00
text_editor - > connect ( " text_entered " , callable_mp ( this , & Tree : : _text_editor_enter ) ) ;
popup_editor - > connect ( " popup_hide " , callable_mp ( this , & Tree : : _text_editor_modal_close ) ) ;
2020-02-21 18:28:45 +01:00
popup_menu - > connect ( " id_pressed " , callable_mp ( this , & Tree : : popup_select ) ) ;
value_editor - > connect ( " value_changed " , callable_mp ( this , & Tree : : value_editor_changed ) ) ;
2014-02-10 02:10:30 +01:00
2018-10-04 19:33:34 +02:00
set_notify_transform ( true ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
updating_value_editor = false ;
pressed_button = - 1 ;
show_column_titles = false ;
2014-02-10 02:10:30 +01:00
cache . click_type = Cache : : CLICK_NONE ;
cache . hover_type = Cache : : CLICK_NONE ;
cache . hover_index = - 1 ;
2017-03-05 16:44:50 +01:00
cache . click_index = - 1 ;
cache . click_id = - 1 ;
2020-04-02 01:20:12 +02:00
cache . click_item = nullptr ;
2017-03-05 16:44:50 +01:00
cache . click_column = 0 ;
2018-02-28 21:55:13 +01:00
cache . hover_cell = - 1 ;
2017-03-05 16:44:50 +01:00
last_keypress = 0 ;
focus_in_id = 0 ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
blocked = 0 ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
cursor_can_exit_tree = true ;
2017-01-08 23:54:19 +01:00
set_mouse_filter ( MOUSE_FILTER_STOP ) ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
drag_speed = 0 ;
drag_touching = false ;
drag_touching_deaccel = false ;
pressing_for_editor = false ;
range_drag_enabled = false ;
2014-02-10 02:10:30 +01:00
2017-03-05 16:44:50 +01:00
hide_folding = false ;
2015-11-14 00:56:44 +01:00
2017-03-05 16:44:50 +01:00
drop_mode_flags = 0 ;
2020-04-02 01:20:12 +02:00
drop_mode_over = nullptr ;
2017-03-05 16:44:50 +01:00
drop_mode_section = 0 ;
2020-04-02 01:20:12 +02:00
single_select_defer = nullptr ;
2016-05-16 04:41:48 +02:00
2019-11-10 09:49:13 +01:00
scrolling = false ;
2017-03-05 16:44:50 +01:00
allow_rmb_select = false ;
force_edit_checkbox_only_on_checkbox = false ;
2017-01-09 19:50:08 +01:00
set_clip_contents ( true ) ;
2017-06-05 01:35:08 +02:00
2020-04-02 01:20:12 +02:00
cache . hover_item = nullptr ;
2017-06-05 01:35:08 +02:00
cache . hover_cell = - 1 ;
2017-08-18 23:19:12 +02:00
allow_reselect = false ;
2019-01-14 21:20:33 +01:00
propagate_mouse_activated = false ;
2014-02-10 02:10:30 +01:00
}
Tree : : ~ Tree ( ) {
if ( root ) {
2017-03-05 16:44:50 +01:00
memdelete ( root ) ;
2014-02-10 02:10:30 +01:00
}
}