2014-02-10 01:10:30 +00:00
/*************************************************************************/
/* control.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
2017-01-01 21:01:57 +00:00
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
2017-04-07 22:11:42 +00:00
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
2014-02-10 01:10:30 +00: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. */
/*************************************************************************/
# include "control.h"
2017-07-19 20:00:46 +00:00
# include "project_settings.h"
2017-03-05 15:44:50 +00:00
# include "scene/main/canvas_layer.h"
# include "scene/main/viewport.h"
# include "servers/visual_server.h"
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
# include "message_queue.h"
2014-02-10 01:10:30 +00:00
# include "os/keyboard.h"
# include "os/os.h"
2017-03-05 15:44:50 +00:00
# include "print_string.h"
2014-02-10 01:10:30 +00:00
# include "scene/gui/label.h"
2017-03-05 15:44:50 +00:00
# include "scene/gui/panel.h"
# include "scene/scene_string_names.h"
2016-03-09 16:59:35 +00:00
# ifdef TOOLS_ENABLED
2017-03-05 13:21:25 +00:00
# include "editor/editor_settings.h"
2016-03-09 16:59:35 +00:00
# endif
2014-02-10 01:10:30 +00:00
# include <stdio.h>
Variant Control : : edit_get_state ( ) const {
2016-06-27 13:47:51 +00:00
Dictionary s ;
2017-03-05 15:44:50 +00:00
s [ " rect " ] = get_rect ( ) ;
s [ " rot " ] = get_rotation ( ) ;
s [ " scale " ] = get_scale ( ) ;
2016-06-27 13:47:51 +00:00
return s ;
2014-02-10 01:10:30 +00:00
}
2017-03-05 15:44:50 +00:00
void Control : : edit_set_state ( const Variant & p_state ) {
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
Dictionary s = p_state ;
2016-06-27 13:47:51 +00:00
2017-03-05 15:44:50 +00:00
Rect2 state = s [ " rect " ] ;
2017-06-03 22:25:13 +00:00
set_position ( state . position ) ;
2014-02-10 01:10:30 +00:00
set_size ( state . size ) ;
2016-06-27 13:47:51 +00:00
set_rotation ( s [ " rot " ] ) ;
set_scale ( s [ " scale " ] ) ;
2014-02-10 01:10:30 +00:00
}
2017-03-05 15:44:50 +00:00
void Control : : set_custom_minimum_size ( const Size2 & p_custom ) {
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
if ( p_custom = = data . custom_minimum_size )
2014-02-10 01:10:30 +00:00
return ;
2017-03-05 15:44:50 +00:00
data . custom_minimum_size = p_custom ;
2014-02-10 01:10:30 +00:00
minimum_size_changed ( ) ;
}
2017-03-05 15:44:50 +00:00
Size2 Control : : get_custom_minimum_size ( ) const {
2014-02-10 01:10:30 +00:00
return data . custom_minimum_size ;
}
Size2 Control : : get_combined_minimum_size ( ) const {
Size2 minsize = get_minimum_size ( ) ;
2017-03-05 15:44:50 +00:00
minsize . x = MAX ( minsize . x , data . custom_minimum_size . x ) ;
minsize . y = MAX ( minsize . y , data . custom_minimum_size . y ) ;
2014-02-10 01:10:30 +00:00
return minsize ;
}
Size2 Control : : edit_get_minimum_size ( ) const {
return get_combined_minimum_size ( ) ;
}
2017-07-06 20:42:44 +00:00
Transform2D Control : : _get_internal_transform ( ) const {
Transform2D rot_scale ;
rot_scale . set_rotation_and_scale ( data . rotation , data . scale ) ;
Transform2D offset ;
offset . set_origin ( - data . pivot_offset ) ;
return offset . affine_inverse ( ) * ( rot_scale * offset ) ;
}
2017-03-05 15:44:50 +00:00
void Control : : edit_set_rect ( const Rect2 & p_edit_rect ) {
2014-02-10 01:10:30 +00:00
2017-07-06 20:42:44 +00:00
Transform2D xform = _get_internal_transform ( ) ;
// xform[2] += get_position();
Vector2 new_pos = xform . basis_xform ( p_edit_rect . position ) ;
2016-02-08 14:29:32 +00:00
2017-03-29 15:29:38 +00:00
Vector2 pos = get_position ( ) + new_pos ;
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
Rect2 new_rect = get_rect ( ) ;
2017-06-03 22:25:13 +00:00
new_rect . position = pos . snapped ( Vector2 ( 1 , 1 ) ) ;
2017-03-05 15:44:50 +00:00
new_rect . size = p_edit_rect . size . snapped ( Vector2 ( 1 , 1 ) ) ;
2014-02-10 01:10:30 +00:00
2017-06-03 22:25:13 +00:00
set_position ( new_rect . position ) ;
2014-02-10 01:10:30 +00:00
set_size ( new_rect . size ) ;
}
2017-03-05 15:44:50 +00:00
bool Control : : _set ( const StringName & p_name , const Variant & p_value ) {
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
String name = p_name ;
2016-03-20 05:25:05 +00:00
if ( ! name . begins_with ( " custom " ) ) {
2017-01-08 22:11:35 +00:00
return false ;
2016-03-20 05:25:05 +00:00
}
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
if ( p_value . get_type ( ) = = Variant : : NIL ) {
2014-02-10 01:10:30 +00:00
if ( name . begins_with ( " custom_icons/ " ) ) {
2017-03-05 15:44:50 +00:00
String dname = name . get_slicec ( ' / ' , 1 ) ;
2014-02-10 01:10:30 +00:00
data . icon_override . erase ( dname ) ;
2015-04-21 19:01:58 +00:00
notification ( NOTIFICATION_THEME_CHANGED ) ;
2014-02-10 01:10:30 +00:00
update ( ) ;
2015-12-20 21:21:53 +00:00
} else if ( name . begins_with ( " custom_shaders/ " ) ) {
2017-03-05 15:44:50 +00:00
String dname = name . get_slicec ( ' / ' , 1 ) ;
2015-12-20 21:21:53 +00:00
data . shader_override . erase ( dname ) ;
notification ( NOTIFICATION_THEME_CHANGED ) ;
update ( ) ;
2014-02-10 01:10:30 +00:00
} else if ( name . begins_with ( " custom_styles/ " ) ) {
2017-03-05 15:44:50 +00:00
String dname = name . get_slicec ( ' / ' , 1 ) ;
2014-02-10 01:10:30 +00:00
data . style_override . erase ( dname ) ;
2015-04-21 19:01:58 +00:00
notification ( NOTIFICATION_THEME_CHANGED ) ;
2014-02-10 01:10:30 +00:00
update ( ) ;
} else if ( name . begins_with ( " custom_fonts/ " ) ) {
2017-03-05 15:44:50 +00:00
String dname = name . get_slicec ( ' / ' , 1 ) ;
2016-06-17 19:00:27 +00:00
if ( data . font_override . has ( dname ) ) {
_unref_font ( data . font_override [ dname ] ) ;
}
2014-02-10 01:10:30 +00:00
data . font_override . erase ( dname ) ;
2015-04-21 19:01:58 +00:00
notification ( NOTIFICATION_THEME_CHANGED ) ;
2014-02-10 01:10:30 +00:00
update ( ) ;
} else if ( name . begins_with ( " custom_colors/ " ) ) {
2017-03-05 15:44:50 +00:00
String dname = name . get_slicec ( ' / ' , 1 ) ;
2014-02-10 01:10:30 +00:00
data . color_override . erase ( dname ) ;
2015-04-21 19:01:58 +00:00
notification ( NOTIFICATION_THEME_CHANGED ) ;
2014-02-10 01:10:30 +00:00
update ( ) ;
} else if ( name . begins_with ( " custom_constants/ " ) ) {
2017-03-05 15:44:50 +00:00
String dname = name . get_slicec ( ' / ' , 1 ) ;
2014-02-10 01:10:30 +00:00
data . constant_override . erase ( dname ) ;
2015-04-21 19:01:58 +00:00
notification ( NOTIFICATION_THEME_CHANGED ) ;
2014-02-10 01:10:30 +00:00
update ( ) ;
} else
return false ;
} else {
if ( name . begins_with ( " custom_icons/ " ) ) {
2017-03-05 15:44:50 +00:00
String dname = name . get_slicec ( ' / ' , 1 ) ;
2015-04-21 19:01:58 +00:00
notification ( NOTIFICATION_THEME_CHANGED ) ;
2017-03-05 15:44:50 +00:00
add_icon_override ( dname , p_value ) ;
2015-12-20 21:21:53 +00:00
} else if ( name . begins_with ( " custom_shaders/ " ) ) {
2017-03-05 15:44:50 +00:00
String dname = name . get_slicec ( ' / ' , 1 ) ;
add_shader_override ( dname , p_value ) ;
2015-12-20 21:21:53 +00:00
notification ( NOTIFICATION_THEME_CHANGED ) ;
2014-02-10 01:10:30 +00:00
} else if ( name . begins_with ( " custom_styles/ " ) ) {
2017-03-05 15:44:50 +00:00
String dname = name . get_slicec ( ' / ' , 1 ) ;
add_style_override ( dname , p_value ) ;
2015-04-21 19:01:58 +00:00
notification ( NOTIFICATION_THEME_CHANGED ) ;
2014-02-10 01:10:30 +00:00
} else if ( name . begins_with ( " custom_fonts/ " ) ) {
2017-03-05 15:44:50 +00:00
String dname = name . get_slicec ( ' / ' , 1 ) ;
add_font_override ( dname , p_value ) ;
2015-04-21 19:01:58 +00:00
notification ( NOTIFICATION_THEME_CHANGED ) ;
2014-02-10 01:10:30 +00:00
} else if ( name . begins_with ( " custom_colors/ " ) ) {
2017-03-05 15:44:50 +00:00
String dname = name . get_slicec ( ' / ' , 1 ) ;
add_color_override ( dname , p_value ) ;
2015-04-21 19:01:58 +00:00
notification ( NOTIFICATION_THEME_CHANGED ) ;
2014-02-10 01:10:30 +00:00
} else if ( name . begins_with ( " custom_constants/ " ) ) {
2017-03-05 15:44:50 +00:00
String dname = name . get_slicec ( ' / ' , 1 ) ;
add_constant_override ( dname , p_value ) ;
2015-04-21 19:01:58 +00:00
notification ( NOTIFICATION_THEME_CHANGED ) ;
2014-02-10 01:10:30 +00:00
} else
return false ;
}
return true ;
}
void Control : : _update_minimum_size ( ) {
2014-11-06 00:20:42 +00:00
if ( ! is_inside_tree ( ) )
2014-02-10 01:10:30 +00:00
return ;
2017-03-05 15:44:50 +00:00
data . pending_min_size_update = false ;
2014-02-10 01:10:30 +00:00
Size2 minsize = get_combined_minimum_size ( ) ;
if ( minsize . x > data . size_cache . x | |
2017-03-05 15:44:50 +00:00
minsize . y > data . size_cache . y ) {
2014-02-10 01:10:30 +00:00
_size_changed ( ) ;
}
emit_signal ( SceneStringNames : : get_singleton ( ) - > minimum_size_changed ) ;
}
2017-03-05 15:44:50 +00:00
bool Control : : _get ( const StringName & p_name , Variant & r_ret ) const {
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
String sname = p_name ;
2014-02-10 01:10:30 +00:00
2016-06-12 18:31:38 +00:00
if ( ! sname . begins_with ( " custom " ) ) {
2017-01-08 22:11:35 +00:00
return false ;
2016-06-12 18:31:38 +00:00
}
2014-02-10 01:10:30 +00:00
if ( sname . begins_with ( " custom_icons/ " ) ) {
2017-03-05 15:44:50 +00:00
String name = sname . get_slicec ( ' / ' , 1 ) ;
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
r_ret = data . icon_override . has ( name ) ? Variant ( data . icon_override [ name ] ) : Variant ( ) ;
2015-12-20 21:21:53 +00:00
} else if ( sname . begins_with ( " custom_shaders/ " ) ) {
2017-03-05 15:44:50 +00:00
String name = sname . get_slicec ( ' / ' , 1 ) ;
2015-12-20 21:21:53 +00:00
2017-03-05 15:44:50 +00:00
r_ret = data . shader_override . has ( name ) ? Variant ( data . shader_override [ name ] ) : Variant ( ) ;
2014-02-10 01:10:30 +00:00
} else if ( sname . begins_with ( " custom_styles/ " ) ) {
2017-03-05 15:44:50 +00:00
String name = sname . get_slicec ( ' / ' , 1 ) ;
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
r_ret = data . style_override . has ( name ) ? Variant ( data . style_override [ name ] ) : Variant ( ) ;
2014-02-10 01:10:30 +00:00
} else if ( sname . begins_with ( " custom_fonts/ " ) ) {
2017-03-05 15:44:50 +00:00
String name = sname . get_slicec ( ' / ' , 1 ) ;
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
r_ret = data . font_override . has ( name ) ? Variant ( data . font_override [ name ] ) : Variant ( ) ;
2014-02-10 01:10:30 +00:00
} else if ( sname . begins_with ( " custom_colors/ " ) ) {
2017-03-05 15:44:50 +00:00
String name = sname . get_slicec ( ' / ' , 1 ) ;
r_ret = data . color_override . has ( name ) ? Variant ( data . color_override [ name ] ) : Variant ( ) ;
2014-02-10 01:10:30 +00:00
} else if ( sname . begins_with ( " custom_constants/ " ) ) {
2017-03-05 15:44:50 +00:00
String name = sname . get_slicec ( ' / ' , 1 ) ;
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
r_ret = data . constant_override . has ( name ) ? Variant ( data . constant_override [ name ] ) : Variant ( ) ;
2014-02-10 01:10:30 +00:00
} else
return false ;
return true ;
}
2017-03-05 15:44:50 +00:00
void Control : : _get_property_list ( List < PropertyInfo > * p_list ) const {
2014-02-10 01:10:30 +00:00
Ref < Theme > theme ;
if ( data . theme . is_valid ( ) ) {
2017-03-05 15:44:50 +00:00
theme = data . theme ;
2014-02-10 01:10:30 +00:00
} else {
2017-03-05 15:44:50 +00:00
theme = Theme : : get_default ( ) ;
2014-02-10 01:10:30 +00:00
}
{
List < StringName > names ;
2017-03-05 15:44:50 +00:00
theme - > get_icon_list ( get_class_name ( ) , & names ) ;
for ( List < StringName > : : Element * E = names . front ( ) ; E ; E = E - > next ( ) ) {
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
uint32_t hint = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE ;
2014-02-10 01:10:30 +00:00
if ( data . icon_override . has ( E - > get ( ) ) )
2017-03-05 15:44:50 +00:00
hint | = PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED ;
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
p_list - > push_back ( PropertyInfo ( Variant : : OBJECT , " custom_icons/ " + E - > get ( ) , PROPERTY_HINT_RESOURCE_TYPE , " Texture " , hint ) ) ;
2014-02-10 01:10:30 +00:00
}
}
2015-12-20 21:21:53 +00:00
{
List < StringName > names ;
2017-03-05 15:44:50 +00:00
theme - > get_shader_list ( get_class_name ( ) , & names ) ;
for ( List < StringName > : : Element * E = names . front ( ) ; E ; E = E - > next ( ) ) {
2015-12-20 21:21:53 +00:00
2017-03-05 15:44:50 +00:00
uint32_t hint = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE ;
2015-12-20 21:21:53 +00:00
if ( data . shader_override . has ( E - > get ( ) ) )
2017-03-05 15:44:50 +00:00
hint | = PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED ;
2015-12-20 21:21:53 +00:00
2017-03-05 15:44:50 +00:00
p_list - > push_back ( PropertyInfo ( Variant : : OBJECT , " custom_shaders/ " + E - > get ( ) , PROPERTY_HINT_RESOURCE_TYPE , " CanvasItemShader,CanvasItemShaderGraph " , hint ) ) ;
2015-12-20 21:21:53 +00:00
}
}
2014-02-10 01:10:30 +00:00
{
List < StringName > names ;
2017-03-05 15:44:50 +00:00
theme - > get_stylebox_list ( get_class_name ( ) , & names ) ;
for ( List < StringName > : : Element * E = names . front ( ) ; E ; E = E - > next ( ) ) {
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
uint32_t hint = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE ;
2014-02-10 01:10:30 +00:00
if ( data . style_override . has ( E - > get ( ) ) )
2017-03-05 15:44:50 +00:00
hint | = PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED ;
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
p_list - > push_back ( PropertyInfo ( Variant : : OBJECT , " custom_styles/ " + E - > get ( ) , PROPERTY_HINT_RESOURCE_TYPE , " StyleBox " , hint ) ) ;
2014-02-10 01:10:30 +00:00
}
}
{
List < StringName > names ;
2017-03-05 15:44:50 +00:00
theme - > get_font_list ( get_class_name ( ) , & names ) ;
for ( List < StringName > : : Element * E = names . front ( ) ; E ; E = E - > next ( ) ) {
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
uint32_t hint = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE ;
2014-02-10 01:10:30 +00:00
if ( data . font_override . has ( E - > get ( ) ) )
2017-03-05 15:44:50 +00:00
hint | = PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED ;
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
p_list - > push_back ( PropertyInfo ( Variant : : OBJECT , " custom_fonts/ " + E - > get ( ) , PROPERTY_HINT_RESOURCE_TYPE , " Font " , hint ) ) ;
2014-02-10 01:10:30 +00:00
}
}
{
List < StringName > names ;
2017-03-05 15:44:50 +00:00
theme - > get_color_list ( get_class_name ( ) , & names ) ;
for ( List < StringName > : : Element * E = names . front ( ) ; E ; E = E - > next ( ) ) {
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
uint32_t hint = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE ;
2014-02-10 01:10:30 +00:00
if ( data . color_override . has ( E - > get ( ) ) )
2017-03-05 15:44:50 +00:00
hint | = PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED ;
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
p_list - > push_back ( PropertyInfo ( Variant : : COLOR , " custom_colors/ " + E - > get ( ) , PROPERTY_HINT_NONE , " " , hint ) ) ;
2014-02-10 01:10:30 +00:00
}
}
{
List < StringName > names ;
2017-03-05 15:44:50 +00:00
theme - > get_constant_list ( get_class_name ( ) , & names ) ;
for ( List < StringName > : : Element * E = names . front ( ) ; E ; E = E - > next ( ) ) {
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
uint32_t hint = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE ;
2014-02-10 01:10:30 +00:00
if ( data . constant_override . has ( E - > get ( ) ) )
2017-03-05 15:44:50 +00:00
hint | = PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED ;
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
p_list - > push_back ( PropertyInfo ( Variant : : INT , " custom_constants/ " + E - > get ( ) , PROPERTY_HINT_RANGE , " -16384,16384 " , hint ) ) ;
2014-02-10 01:10:30 +00:00
}
}
}
Control * Control : : get_parent_control ( ) const {
return data . parent ;
}
2017-03-05 15:44:50 +00:00
void Control : : _resize ( const Size2 & p_size ) {
2016-03-08 23:00:52 +00:00
2014-02-10 01:10:30 +00:00
_size_changed ( ) ;
}
2016-08-06 01:46:45 +00:00
//moved theme configuration here, so controls can set up even if still not inside active scene
void Control : : add_child_notify ( Node * p_child ) {
2017-03-05 15:44:50 +00:00
Control * child_c = p_child - > cast_to < Control > ( ) ;
2016-08-06 01:46:45 +00:00
if ( ! child_c )
return ;
if ( child_c - > data . theme . is_null ( ) & & data . theme_owner ) {
2017-03-05 15:44:50 +00:00
_propagate_theme_changed ( child_c , data . theme_owner ) ; //need to propagate here, since many controls may require setting up stuff
2016-08-06 01:46:45 +00:00
}
}
void Control : : remove_child_notify ( Node * p_child ) {
2017-03-05 15:44:50 +00:00
Control * child_c = p_child - > cast_to < Control > ( ) ;
2016-08-06 01:46:45 +00:00
if ( ! child_c )
return ;
if ( child_c - > data . theme_owner & & child_c - > data . theme . is_null ( ) ) {
2017-03-05 15:44:50 +00:00
_propagate_theme_changed ( child_c , NULL ) ;
2016-08-06 01:46:45 +00:00
}
}
2014-02-10 01:10:30 +00:00
2016-08-31 02:44:14 +00:00
void Control : : _update_canvas_item_transform ( ) {
2017-07-06 20:42:44 +00:00
Transform2D xform = _get_internal_transform ( ) ;
xform [ 2 ] + = get_position ( ) ;
2017-03-05 15:44:50 +00:00
VisualServer : : get_singleton ( ) - > canvas_item_set_transform ( get_canvas_item ( ) , xform ) ;
2016-08-31 02:44:14 +00:00
}
2014-02-10 01:10:30 +00:00
void Control : : _notification ( int p_notification ) {
2017-03-05 15:44:50 +00:00
switch ( p_notification ) {
2014-02-10 01:10:30 +00:00
2014-11-06 00:20:42 +00:00
case NOTIFICATION_ENTER_TREE : {
2014-02-10 01:10:30 +00:00
_size_changed ( ) ;
} break ;
2014-11-06 00:20:42 +00:00
case NOTIFICATION_EXIT_TREE : {
2014-02-10 01:10:30 +00:00
2016-01-17 01:41:10 +00:00
get_viewport ( ) - > _gui_remove_control ( this ) ;
2014-02-10 01:10:30 +00:00
} break ;
case NOTIFICATION_ENTER_CANVAS : {
2017-03-05 15:44:50 +00:00
data . parent = get_parent ( ) - > cast_to < Control > ( ) ;
2014-02-10 01:10:30 +00:00
2016-01-17 01:41:10 +00:00
if ( is_set_as_toplevel ( ) ) {
2017-03-05 15:44:50 +00:00
data . SI = get_viewport ( ) - > _gui_add_subwindow_control ( this ) ;
2016-06-14 00:10:45 +00:00
2016-11-18 05:13:36 +00:00
if ( data . theme . is_null ( ) & & data . parent & & data . parent - > data . theme_owner ) {
2017-03-05 15:44:50 +00:00
data . theme_owner = data . parent - > data . theme_owner ;
2016-06-14 00:10:45 +00:00
notification ( NOTIFICATION_THEME_CHANGED ) ;
2016-11-18 05:13:36 +00:00
}
2016-06-14 00:10:45 +00:00
2016-01-17 01:41:10 +00:00
} else {
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
Node * parent = this ; //meh
Control * parent_control = NULL ;
bool subwindow = false ;
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
while ( parent ) {
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
parent = parent - > get_parent ( ) ;
2014-02-10 01:10:30 +00:00
2016-01-17 01:41:10 +00:00
if ( ! parent )
break ;
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
CanvasItem * ci = parent - > cast_to < CanvasItem > ( ) ;
2016-01-17 01:41:10 +00:00
if ( ci & & ci - > is_set_as_toplevel ( ) ) {
2017-03-05 15:44:50 +00:00
subwindow = true ;
2016-01-17 01:41:10 +00:00
break ;
2014-02-10 01:10:30 +00:00
}
2017-03-05 15:44:50 +00:00
parent_control = parent - > cast_to < Control > ( ) ;
2016-06-14 00:37:04 +00:00
if ( parent_control ) {
2016-01-17 01:41:10 +00:00
break ;
} else if ( ci ) {
2014-02-10 01:10:30 +00:00
2016-01-17 01:41:10 +00:00
} else {
break ;
}
2014-02-10 01:10:30 +00:00
}
2016-01-17 01:41:10 +00:00
if ( parent_control ) {
//do nothing, has a parent control
2016-11-18 05:13:36 +00:00
if ( data . theme . is_null ( ) & & parent_control - > data . theme_owner ) {
2017-03-05 15:44:50 +00:00
data . theme_owner = parent_control - > data . theme_owner ;
2016-06-14 00:10:45 +00:00
notification ( NOTIFICATION_THEME_CHANGED ) ;
2016-11-18 05:13:36 +00:00
}
2016-01-17 01:41:10 +00:00
} else if ( subwindow ) {
//is a subwindow (process input before other controls for that canvas)
2017-03-05 15:44:50 +00:00
data . SI = get_viewport ( ) - > _gui_add_subwindow_control ( this ) ;
2016-01-17 01:41:10 +00:00
} else {
//is a regular root control
2017-03-05 15:44:50 +00:00
data . RI = get_viewport ( ) - > _gui_add_root_control ( this ) ;
2014-02-10 01:10:30 +00:00
}
2017-03-05 15:44:50 +00:00
data . parent_canvas_item = get_parent_item ( ) ;
2014-02-10 01:10:30 +00:00
2016-01-17 01:41:10 +00:00
if ( data . parent_canvas_item ) {
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
data . parent_canvas_item - > connect ( " item_rect_changed " , this , " _size_changed " ) ;
} else {
2016-01-17 01:41:10 +00:00
//connect viewport
2017-03-05 15:44:50 +00:00
get_viewport ( ) - > connect ( " size_changed " , this , " _size_changed " ) ;
2016-01-17 01:41:10 +00:00
}
2014-02-10 01:10:30 +00:00
}
2017-01-14 11:26:56 +00:00
/*
if ( data . theme . is_null ( ) & & data . parent & & data . parent - > data . theme_owner ) {
data . theme_owner = data . parent - > data . theme_owner ;
notification ( NOTIFICATION_THEME_CHANGED ) ;
}
*/
2014-02-10 01:10:30 +00:00
} break ;
case NOTIFICATION_EXIT_CANVAS : {
if ( data . parent_canvas_item ) {
2017-03-05 15:44:50 +00:00
data . parent_canvas_item - > disconnect ( " item_rect_changed " , this , " _size_changed " ) ;
data . parent_canvas_item = NULL ;
2016-01-17 23:03:57 +00:00
} else if ( ! is_set_as_toplevel ( ) ) {
2016-01-17 01:41:10 +00:00
//disconnect viewport
2017-03-05 15:44:50 +00:00
get_viewport ( ) - > disconnect ( " size_changed " , this , " _size_changed " ) ;
2014-02-10 01:10:30 +00:00
}
if ( data . MI ) {
2016-01-17 01:41:10 +00:00
get_viewport ( ) - > _gui_remove_modal_control ( data . MI ) ;
2017-03-05 15:44:50 +00:00
data . MI = NULL ;
2014-02-10 01:10:30 +00:00
}
if ( data . SI ) {
2016-01-17 01:41:10 +00:00
get_viewport ( ) - > _gui_remove_subwindow_control ( data . SI ) ;
2017-03-05 15:44:50 +00:00
data . SI = NULL ;
2014-02-10 01:10:30 +00:00
}
2016-01-17 01:41:10 +00:00
if ( data . RI ) {
get_viewport ( ) - > _gui_remove_root_control ( data . RI ) ;
2017-03-05 15:44:50 +00:00
data . RI = NULL ;
2016-01-17 01:41:10 +00:00
}
2017-03-05 15:44:50 +00:00
data . parent = NULL ;
data . parent_canvas_item = NULL ;
2017-01-14 11:26:56 +00:00
/*
if ( data . theme_owner & & data . theme . is_null ( ) ) {
data . theme_owner = NULL ;
notification ( NOTIFICATION_THEME_CHANGED ) ;
}
*/
2014-02-10 01:10:30 +00:00
} break ;
2017-03-05 15:44:50 +00:00
case NOTIFICATION_MOVED_IN_PARENT : {
// some parents need to know the order of the childrens to draw (like TabContainer)
2017-03-24 20:45:31 +00:00
// update if necessary
2017-03-05 15:44:50 +00:00
if ( data . parent )
data . parent - > update ( ) ;
update ( ) ;
if ( data . SI ) {
get_viewport ( ) - > _gui_set_subwindow_order_dirty ( ) ;
}
if ( data . RI ) {
get_viewport ( ) - > _gui_set_root_order_dirty ( ) ;
}
} break ;
2014-02-10 01:10:30 +00:00
case NOTIFICATION_RESIZED : {
emit_signal ( SceneStringNames : : get_singleton ( ) - > resized ) ;
} break ;
case NOTIFICATION_DRAW : {
2016-08-31 02:44:14 +00:00
_update_canvas_item_transform ( ) ;
2017-03-05 15:44:50 +00:00
VisualServer : : get_singleton ( ) - > canvas_item_set_custom_rect ( get_canvas_item ( ) , ! data . disable_visibility_clip , Rect2 ( Point2 ( ) , get_size ( ) ) ) ;
VisualServer : : get_singleton ( ) - > canvas_item_set_clip ( get_canvas_item ( ) , data . clip_contents ) ;
2014-02-10 01:10:30 +00:00
//emit_signal(SceneStringNames::get_singleton()->draw);
} break ;
case NOTIFICATION_MOUSE_ENTER : {
2017-01-12 03:51:08 +00:00
emit_signal ( SceneStringNames : : get_singleton ( ) - > mouse_entered ) ;
2014-02-10 01:10:30 +00:00
} break ;
case NOTIFICATION_MOUSE_EXIT : {
2017-01-12 03:51:08 +00:00
emit_signal ( SceneStringNames : : get_singleton ( ) - > mouse_exited ) ;
2014-02-10 01:10:30 +00:00
} break ;
case NOTIFICATION_FOCUS_ENTER : {
2017-01-12 03:51:08 +00:00
emit_signal ( SceneStringNames : : get_singleton ( ) - > focus_entered ) ;
2014-02-10 01:10:30 +00:00
update ( ) ;
} break ;
case NOTIFICATION_FOCUS_EXIT : {
2017-01-12 03:51:08 +00:00
emit_signal ( SceneStringNames : : get_singleton ( ) - > focus_exited ) ;
2014-02-10 01:10:30 +00:00
update ( ) ;
} break ;
case NOTIFICATION_THEME_CHANGED : {
update ( ) ;
} break ;
2016-01-23 14:45:36 +00:00
case NOTIFICATION_MODAL_CLOSE : {
2017-01-12 03:51:08 +00:00
emit_signal ( " modal_closed " ) ;
2016-01-23 14:45:36 +00:00
} break ;
2014-02-10 01:10:30 +00:00
case NOTIFICATION_VISIBILITY_CHANGED : {
2017-01-13 13:45:50 +00:00
if ( ! is_visible_in_tree ( ) ) {
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
if ( get_viewport ( ) ! = NULL )
2016-03-22 04:46:33 +00:00
get_viewport ( ) - > _gui_hid_control ( this ) ;
2016-04-07 07:46:38 +00:00
2017-03-05 15:44:50 +00:00
if ( is_inside_tree ( ) ) {
2016-04-07 07:46:38 +00:00
_modal_stack_remove ( ) ;
minimum_size_changed ( ) ;
}
2014-02-10 01:10:30 +00:00
//remove key focus
//remove modalness
} else {
_size_changed ( ) ;
}
} break ;
2014-11-06 00:20:42 +00:00
case SceneTree : : NOTIFICATION_WM_UNFOCUS_REQUEST : {
2014-02-10 01:10:30 +00:00
2016-01-17 01:41:10 +00:00
get_viewport ( ) - > _gui_unfocus_control ( this ) ;
2014-02-10 01:10:30 +00:00
} break ;
}
}
bool Control : : clips_input ( ) const {
return false ;
}
2017-03-05 15:44:50 +00:00
bool Control : : has_point ( const Point2 & p_point ) const {
2014-02-10 01:10:30 +00:00
if ( get_script_instance ( ) ) {
2017-03-05 15:44:50 +00:00
Variant v = p_point ;
const Variant * p = & v ;
2014-02-10 01:10:30 +00:00
Variant : : CallError ce ;
2017-03-05 15:44:50 +00:00
Variant ret = get_script_instance ( ) - > call ( SceneStringNames : : get_singleton ( ) - > has_point , & p , 1 , ce ) ;
if ( ce . error = = Variant : : CallError : : CALL_OK ) {
2014-02-10 01:10:30 +00:00
return ret ;
}
}
/*if (has_stylebox("mask")) {
Ref < StyleBox > mask = get_stylebox ( " mask " ) ;
return mask - > test_mask ( p_point , Rect2 ( Point2 ( ) , get_size ( ) ) ) ;
} */
2017-03-05 15:44:50 +00:00
return Rect2 ( Point2 ( ) , get_size ( ) ) . has_point ( p_point ) ;
2014-02-10 01:10:30 +00:00
}
2017-03-05 15:44:50 +00:00
void Control : : set_drag_forwarding ( Control * p_target ) {
2016-05-03 14:10:28 +00:00
if ( p_target )
2017-08-07 10:17:31 +00:00
data . drag_owner = p_target - > get_instance_id ( ) ;
2016-05-03 14:10:28 +00:00
else
2017-03-05 15:44:50 +00:00
data . drag_owner = 0 ;
2016-05-03 14:10:28 +00:00
}
2017-03-05 15:44:50 +00:00
Variant Control : : get_drag_data ( const Point2 & p_point ) {
2014-02-10 01:10:30 +00:00
2016-05-03 14:10:28 +00:00
if ( data . drag_owner ) {
Object * obj = ObjectDB : : get_instance ( data . drag_owner ) ;
if ( obj ) {
Control * c = obj - > cast_to < Control > ( ) ;
2017-03-05 15:44:50 +00:00
return c - > call ( " get_drag_data_fw " , p_point , this ) ;
2016-05-03 14:10:28 +00:00
}
}
2014-02-10 01:10:30 +00:00
if ( get_script_instance ( ) ) {
2017-03-05 15:44:50 +00:00
Variant v = p_point ;
const Variant * p = & v ;
2014-02-10 01:10:30 +00:00
Variant : : CallError ce ;
2017-03-05 15:44:50 +00:00
Variant ret = get_script_instance ( ) - > call ( SceneStringNames : : get_singleton ( ) - > get_drag_data , & p , 1 , ce ) ;
if ( ce . error = = Variant : : CallError : : CALL_OK )
2014-02-10 01:10:30 +00:00
return ret ;
}
return Variant ( ) ;
}
2017-03-05 15:44:50 +00:00
bool Control : : can_drop_data ( const Point2 & p_point , const Variant & p_data ) const {
2014-02-10 01:10:30 +00:00
2016-05-03 14:10:28 +00:00
if ( data . drag_owner ) {
Object * obj = ObjectDB : : get_instance ( data . drag_owner ) ;
if ( obj ) {
Control * c = obj - > cast_to < Control > ( ) ;
2017-03-05 15:44:50 +00:00
return c - > call ( " can_drop_data_fw " , p_point , p_data , this ) ;
2016-05-03 14:10:28 +00:00
}
}
2014-02-10 01:10:30 +00:00
if ( get_script_instance ( ) ) {
2017-03-05 15:44:50 +00:00
Variant v = p_point ;
const Variant * p [ 2 ] = { & v , & p_data } ;
2014-02-10 01:10:30 +00:00
Variant : : CallError ce ;
2017-03-05 15:44:50 +00:00
Variant ret = get_script_instance ( ) - > call ( SceneStringNames : : get_singleton ( ) - > can_drop_data , p , 2 , ce ) ;
if ( ce . error = = Variant : : CallError : : CALL_OK )
2014-02-10 01:10:30 +00:00
return ret ;
}
return Variant ( ) ;
}
2017-03-05 15:44:50 +00:00
void Control : : drop_data ( const Point2 & p_point , const Variant & p_data ) {
2014-02-10 01:10:30 +00:00
2016-05-03 14:10:28 +00:00
if ( data . drag_owner ) {
Object * obj = ObjectDB : : get_instance ( data . drag_owner ) ;
if ( obj ) {
Control * c = obj - > cast_to < Control > ( ) ;
2017-03-05 15:44:50 +00:00
c - > call ( " drop_data_fw " , p_point , p_data , this ) ;
2016-05-03 14:10:28 +00:00
return ;
}
}
2014-02-10 01:10:30 +00:00
if ( get_script_instance ( ) ) {
2017-03-05 15:44:50 +00:00
Variant v = p_point ;
const Variant * p [ 2 ] = { & v , & p_data } ;
2014-02-10 01:10:30 +00:00
Variant : : CallError ce ;
2017-03-05 15:44:50 +00:00
Variant ret = get_script_instance ( ) - > call ( SceneStringNames : : get_singleton ( ) - > drop_data , p , 2 , ce ) ;
if ( ce . error = = Variant : : CallError : : CALL_OK )
2014-02-10 01:10:30 +00:00
return ;
}
}
2017-03-05 15:44:50 +00:00
void Control : : force_drag ( const Variant & p_data , Control * p_control ) {
2014-02-10 01:10:30 +00:00
2014-11-06 00:20:42 +00:00
ERR_FAIL_COND ( ! is_inside_tree ( ) ) ;
2017-03-05 15:44:50 +00:00
ERR_FAIL_COND ( p_data . get_type ( ) = = Variant : : NIL ) ;
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
get_viewport ( ) - > _gui_force_drag ( this , p_data , p_control ) ;
2014-02-10 01:10:30 +00:00
}
void Control : : set_drag_preview ( Control * p_control ) {
2016-01-17 01:41:10 +00:00
ERR_FAIL_COND ( ! is_inside_tree ( ) ) ;
2017-03-05 15:44:50 +00:00
get_viewport ( ) - > _gui_set_drag_preview ( this , p_control ) ;
2014-02-10 01:10:30 +00:00
}
2015-12-28 23:36:48 +00:00
bool Control : : is_window_modal_on_top ( ) const {
2016-01-17 01:41:10 +00:00
if ( ! is_inside_tree ( ) )
return false ;
2014-02-10 01:10:30 +00:00
2016-01-17 01:41:10 +00:00
return get_viewport ( ) - > _gui_is_modal_on_top ( this ) ;
2014-02-10 01:10:30 +00:00
}
2016-06-27 14:22:13 +00:00
uint64_t Control : : get_modal_frame ( ) const {
return data . modal_frame ;
}
2014-02-10 01:10:30 +00:00
Size2 Control : : get_minimum_size ( ) const {
2016-03-08 23:00:52 +00:00
2017-03-05 15:44:50 +00:00
ScriptInstance * si = const_cast < Control * > ( this ) - > get_script_instance ( ) ;
2014-02-10 01:10:30 +00:00
if ( si ) {
Variant : : CallError ce ;
2017-03-13 15:45:27 +00:00
Variant s = si - > call ( SceneStringNames : : get_singleton ( ) - > _get_minimum_size , NULL , 0 , ce ) ;
2017-03-05 15:44:50 +00:00
if ( ce . error = = Variant : : CallError : : CALL_OK )
2014-02-10 01:10:30 +00:00
return s ;
}
return Size2 ( ) ;
}
2017-03-05 15:44:50 +00:00
Ref < Texture > Control : : get_icon ( const StringName & p_name , const StringName & p_type ) const {
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
if ( p_type = = StringName ( ) | | p_type = = " " ) {
2014-12-17 01:31:57 +00:00
2017-03-05 15:44:50 +00:00
const Ref < Texture > * tex = data . icon_override . getptr ( p_name ) ;
2014-12-17 01:31:57 +00:00
if ( tex )
return * tex ;
}
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
StringName type = p_type ? p_type : get_class_name ( ) ;
2014-02-10 01:10:30 +00:00
// try with custom themes
Control * theme_owner = data . theme_owner ;
2017-03-05 15:44:50 +00:00
while ( theme_owner ) {
2014-02-10 01:10:30 +00:00
2017-01-11 21:29:59 +00:00
StringName class_name = type ;
2017-03-05 15:44:50 +00:00
while ( class_name ! = StringName ( ) ) {
if ( theme_owner - > data . theme - > has_icon ( p_name , class_name ) ) {
return theme_owner - > data . theme - > get_icon ( p_name , class_name ) ;
2017-01-11 21:29:59 +00:00
}
class_name = ClassDB : : get_parent_class_nocheck ( class_name ) ;
}
2017-03-05 15:44:50 +00:00
Control * parent = theme_owner - > get_parent ( ) ? theme_owner - > get_parent ( ) - > cast_to < Control > ( ) : NULL ;
2014-02-10 01:10:30 +00:00
if ( parent )
2017-03-05 15:44:50 +00:00
theme_owner = parent - > data . theme_owner ;
2014-02-10 01:10:30 +00:00
else
2017-03-05 15:44:50 +00:00
theme_owner = NULL ;
2014-02-10 01:10:30 +00:00
}
2017-03-05 15:44:50 +00:00
return Theme : : get_default ( ) - > get_icon ( p_name , type ) ;
2014-02-10 01:10:30 +00:00
}
2017-03-05 15:44:50 +00:00
Ref < Shader > Control : : get_shader ( const StringName & p_name , const StringName & p_type ) const {
if ( p_type = = StringName ( ) | | p_type = = " " ) {
2015-12-20 21:21:53 +00:00
2017-03-05 15:44:50 +00:00
const Ref < Shader > * sdr = data . shader_override . getptr ( p_name ) ;
2015-12-20 21:21:53 +00:00
if ( sdr )
return * sdr ;
}
2017-03-05 15:44:50 +00:00
StringName type = p_type ? p_type : get_class_name ( ) ;
2015-12-20 21:21:53 +00:00
// try with custom themes
Control * theme_owner = data . theme_owner ;
2017-03-05 15:44:50 +00:00
while ( theme_owner ) {
2015-12-20 21:21:53 +00:00
2017-01-11 21:29:59 +00:00
StringName class_name = type ;
2017-03-05 15:44:50 +00:00
while ( class_name ! = StringName ( ) ) {
if ( theme_owner - > data . theme - > has_shader ( p_name , class_name ) ) {
return theme_owner - > data . theme - > get_shader ( p_name , class_name ) ;
2017-01-11 21:29:59 +00:00
}
class_name = ClassDB : : get_parent_class_nocheck ( class_name ) ;
}
2017-03-05 15:44:50 +00:00
Control * parent = theme_owner - > get_parent ( ) ? theme_owner - > get_parent ( ) - > cast_to < Control > ( ) : NULL ;
2015-12-20 21:21:53 +00:00
if ( parent )
2017-03-05 15:44:50 +00:00
theme_owner = parent - > data . theme_owner ;
2015-12-20 21:21:53 +00:00
else
2017-03-05 15:44:50 +00:00
theme_owner = NULL ;
2015-12-20 21:21:53 +00:00
}
2017-03-05 15:44:50 +00:00
return Theme : : get_default ( ) - > get_shader ( p_name , type ) ;
2015-12-20 21:21:53 +00:00
}
2017-03-05 15:44:50 +00:00
Ref < StyleBox > Control : : get_stylebox ( const StringName & p_name , const StringName & p_type ) const {
2016-03-08 23:00:52 +00:00
2017-03-05 15:44:50 +00:00
if ( p_type = = StringName ( ) | | p_type = = " " ) {
const Ref < StyleBox > * style = data . style_override . getptr ( p_name ) ;
2014-12-17 01:31:57 +00:00
if ( style )
return * style ;
}
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
StringName type = p_type ? p_type : get_class_name ( ) ;
2014-02-10 01:10:30 +00:00
// try with custom themes
Control * theme_owner = data . theme_owner ;
2017-03-05 15:44:50 +00:00
while ( theme_owner ) {
2014-02-10 01:10:30 +00:00
2017-01-11 21:29:59 +00:00
StringName class_name = type ;
2017-03-05 15:44:50 +00:00
while ( class_name ! = StringName ( ) ) {
if ( theme_owner - > data . theme - > has_stylebox ( p_name , class_name ) ) {
return theme_owner - > data . theme - > get_stylebox ( p_name , class_name ) ;
2017-01-11 21:29:59 +00:00
}
class_name = ClassDB : : get_parent_class_nocheck ( class_name ) ;
2016-06-12 18:31:38 +00:00
}
2017-01-11 21:29:59 +00:00
2017-03-05 15:44:50 +00:00
Control * parent = theme_owner - > get_parent ( ) ? theme_owner - > get_parent ( ) - > cast_to < Control > ( ) : NULL ;
2014-02-10 01:10:30 +00:00
if ( parent )
2017-03-05 15:44:50 +00:00
theme_owner = parent - > data . theme_owner ;
2014-02-10 01:10:30 +00:00
else
2017-03-05 15:44:50 +00:00
theme_owner = NULL ;
2014-02-10 01:10:30 +00:00
}
2017-03-05 15:44:50 +00:00
return Theme : : get_default ( ) - > get_stylebox ( p_name , type ) ;
2014-02-10 01:10:30 +00:00
}
2017-03-05 15:44:50 +00:00
Ref < Font > Control : : get_font ( const StringName & p_name , const StringName & p_type ) const {
2014-12-17 01:31:57 +00:00
2017-03-05 15:44:50 +00:00
if ( p_type = = StringName ( ) | | p_type = = " " ) {
const Ref < Font > * font = data . font_override . getptr ( p_name ) ;
2014-12-17 01:31:57 +00:00
if ( font )
return * font ;
}
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
StringName type = p_type ? p_type : get_class_name ( ) ;
2014-02-10 01:10:30 +00:00
// try with custom themes
Control * theme_owner = data . theme_owner ;
2017-03-05 15:44:50 +00:00
while ( theme_owner ) {
2014-02-10 01:10:30 +00:00
2017-01-11 21:29:59 +00:00
StringName class_name = type ;
2017-03-05 15:44:50 +00:00
while ( class_name ! = StringName ( ) ) {
if ( theme_owner - > data . theme - > has_font ( p_name , class_name ) ) {
return theme_owner - > data . theme - > get_font ( p_name , class_name ) ;
2017-01-11 21:29:59 +00:00
}
class_name = ClassDB : : get_parent_class_nocheck ( class_name ) ;
}
2014-02-15 05:01:39 +00:00
if ( theme_owner - > data . theme - > get_default_theme_font ( ) . is_valid ( ) )
return theme_owner - > data . theme - > get_default_theme_font ( ) ;
2017-03-05 15:44:50 +00:00
Control * parent = theme_owner - > get_parent ( ) ? theme_owner - > get_parent ( ) - > cast_to < Control > ( ) : NULL ;
2014-02-10 01:10:30 +00:00
if ( parent )
2017-03-05 15:44:50 +00:00
theme_owner = parent - > data . theme_owner ;
2014-02-10 01:10:30 +00:00
else
2017-03-05 15:44:50 +00:00
theme_owner = NULL ;
2014-02-10 01:10:30 +00:00
}
2017-03-05 15:44:50 +00:00
return Theme : : get_default ( ) - > get_font ( p_name , type ) ;
2014-02-10 01:10:30 +00:00
}
2017-03-05 15:44:50 +00:00
Color Control : : get_color ( const StringName & p_name , const StringName & p_type ) const {
2014-12-17 01:31:57 +00:00
2017-03-05 15:44:50 +00:00
if ( p_type = = StringName ( ) | | p_type = = " " ) {
const Color * color = data . color_override . getptr ( p_name ) ;
2014-12-17 01:31:57 +00:00
if ( color )
return * color ;
}
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
StringName type = p_type ? p_type : get_class_name ( ) ;
2014-02-10 01:10:30 +00:00
// try with custom themes
Control * theme_owner = data . theme_owner ;
2017-03-05 15:44:50 +00:00
while ( theme_owner ) {
2014-02-10 01:10:30 +00:00
2017-01-11 21:29:59 +00:00
StringName class_name = type ;
2017-03-05 15:44:50 +00:00
while ( class_name ! = StringName ( ) ) {
if ( theme_owner - > data . theme - > has_color ( p_name , class_name ) ) {
return theme_owner - > data . theme - > get_color ( p_name , class_name ) ;
2017-01-11 21:29:59 +00:00
}
class_name = ClassDB : : get_parent_class_nocheck ( class_name ) ;
}
2017-03-05 15:44:50 +00:00
Control * parent = theme_owner - > get_parent ( ) ? theme_owner - > get_parent ( ) - > cast_to < Control > ( ) : NULL ;
2014-02-10 01:10:30 +00:00
if ( parent )
2017-03-05 15:44:50 +00:00
theme_owner = parent - > data . theme_owner ;
2014-02-10 01:10:30 +00:00
else
2017-03-05 15:44:50 +00:00
theme_owner = NULL ;
2014-02-10 01:10:30 +00:00
}
2017-03-05 15:44:50 +00:00
return Theme : : get_default ( ) - > get_color ( p_name , type ) ;
2014-02-10 01:10:30 +00:00
}
2017-03-05 15:44:50 +00:00
int Control : : get_constant ( const StringName & p_name , const StringName & p_type ) const {
2014-12-17 01:31:57 +00:00
2017-03-05 15:44:50 +00:00
if ( p_type = = StringName ( ) | | p_type = = " " ) {
const int * constant = data . constant_override . getptr ( p_name ) ;
2014-12-17 01:31:57 +00:00
if ( constant )
return * constant ;
}
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
StringName type = p_type ? p_type : get_class_name ( ) ;
// try with custom themes
2014-02-10 01:10:30 +00:00
Control * theme_owner = data . theme_owner ;
2017-03-05 15:44:50 +00:00
while ( theme_owner ) {
2014-02-10 01:10:30 +00:00
2017-01-11 21:29:59 +00:00
StringName class_name = type ;
2017-03-05 15:44:50 +00:00
while ( class_name ! = StringName ( ) ) {
if ( theme_owner - > data . theme - > has_constant ( p_name , class_name ) ) {
return theme_owner - > data . theme - > get_constant ( p_name , class_name ) ;
2017-01-11 21:29:59 +00:00
}
class_name = ClassDB : : get_parent_class_nocheck ( class_name ) ;
}
2017-03-05 15:44:50 +00:00
Control * parent = theme_owner - > get_parent ( ) ? theme_owner - > get_parent ( ) - > cast_to < Control > ( ) : NULL ;
2014-02-10 01:10:30 +00:00
if ( parent )
2017-03-05 15:44:50 +00:00
theme_owner = parent - > data . theme_owner ;
2014-02-10 01:10:30 +00:00
else
2017-03-05 15:44:50 +00:00
theme_owner = NULL ;
2014-02-10 01:10:30 +00:00
}
2017-03-05 15:44:50 +00:00
return Theme : : get_default ( ) - > get_constant ( p_name , type ) ;
2014-02-10 01:10:30 +00:00
}
2017-03-05 15:44:50 +00:00
bool Control : : has_icon_override ( const StringName & p_name ) const {
2016-06-01 14:41:25 +00:00
2017-03-05 15:44:50 +00:00
const Ref < Texture > * tex = data . icon_override . getptr ( p_name ) ;
2016-06-01 14:41:25 +00:00
if ( tex )
return true ;
else
return false ;
}
bool Control : : has_shader_override ( const StringName & p_name ) const {
2017-03-05 15:44:50 +00:00
const Ref < Shader > * sdr = data . shader_override . getptr ( p_name ) ;
2016-06-01 14:41:25 +00:00
if ( sdr )
return true ;
else
return false ;
}
2017-03-05 15:44:50 +00:00
bool Control : : has_stylebox_override ( const StringName & p_name ) const {
2016-06-01 14:41:25 +00:00
2017-03-05 15:44:50 +00:00
const Ref < StyleBox > * style = data . style_override . getptr ( p_name ) ;
2016-06-01 14:41:25 +00:00
if ( style )
return true ;
else
return false ;
}
2017-03-05 15:44:50 +00:00
bool Control : : has_font_override ( const StringName & p_name ) const {
2016-06-01 14:41:25 +00:00
2017-03-05 15:44:50 +00:00
const Ref < Font > * font = data . font_override . getptr ( p_name ) ;
2016-06-01 14:41:25 +00:00
if ( font )
return true ;
else
return false ;
}
2017-03-05 15:44:50 +00:00
bool Control : : has_color_override ( const StringName & p_name ) const {
2016-06-01 14:41:25 +00:00
2017-03-05 15:44:50 +00:00
const Color * color = data . color_override . getptr ( p_name ) ;
2016-06-01 14:41:25 +00:00
if ( color )
return true ;
else
return false ;
}
2017-03-05 15:44:50 +00:00
bool Control : : has_constant_override ( const StringName & p_name ) const {
2016-06-01 14:41:25 +00:00
2017-03-05 15:44:50 +00:00
const int * constant = data . constant_override . getptr ( p_name ) ;
2016-06-01 14:41:25 +00:00
if ( constant )
return true ;
else
return false ;
}
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
bool Control : : has_icon ( const StringName & p_name , const StringName & p_type ) const {
2016-03-08 23:00:52 +00:00
2017-03-05 15:44:50 +00:00
if ( p_type = = StringName ( ) | | p_type = = " " ) {
2016-06-01 14:41:25 +00:00
if ( has_icon_override ( p_name ) = = true )
2014-12-17 01:31:57 +00:00
return true ;
}
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
StringName type = p_type ? p_type : get_class_name ( ) ;
2014-02-10 01:10:30 +00:00
// try with custom themes
Control * theme_owner = data . theme_owner ;
2017-03-05 15:44:50 +00:00
while ( theme_owner ) {
2014-02-10 01:10:30 +00:00
2017-01-11 21:29:59 +00:00
StringName class_name = type ;
2017-03-05 15:44:50 +00:00
while ( class_name ! = StringName ( ) ) {
if ( theme_owner - > data . theme - > has_icon ( p_name , class_name ) ) {
2017-01-11 21:29:59 +00:00
return true ;
}
class_name = ClassDB : : get_parent_class_nocheck ( class_name ) ;
}
2017-03-05 15:44:50 +00:00
Control * parent = theme_owner - > get_parent ( ) ? theme_owner - > get_parent ( ) - > cast_to < Control > ( ) : NULL ;
2014-02-10 01:10:30 +00:00
if ( parent )
2017-03-05 15:44:50 +00:00
theme_owner = parent - > data . theme_owner ;
2014-02-10 01:10:30 +00:00
else
2017-03-05 15:44:50 +00:00
theme_owner = NULL ;
2014-02-10 01:10:30 +00:00
}
2017-03-05 15:44:50 +00:00
return Theme : : get_default ( ) - > has_icon ( p_name , type ) ;
2015-12-20 21:21:53 +00:00
}
2016-06-01 14:41:25 +00:00
bool Control : : has_shader ( const StringName & p_name , const StringName & p_type ) const {
2017-03-05 15:44:50 +00:00
if ( p_type = = StringName ( ) | | p_type = = " " ) {
if ( has_shader_override ( p_name ) = = true )
2015-12-20 21:21:53 +00:00
return true ;
}
2017-03-05 15:44:50 +00:00
StringName type = p_type ? p_type : get_class_name ( ) ;
2015-12-20 21:21:53 +00:00
// try with custom themes
Control * theme_owner = data . theme_owner ;
2017-03-05 15:44:50 +00:00
while ( theme_owner ) {
2014-02-10 01:10:30 +00:00
2017-01-11 21:29:59 +00:00
StringName class_name = type ;
2017-03-05 15:44:50 +00:00
while ( class_name ! = StringName ( ) ) {
if ( theme_owner - > data . theme - > has_shader ( p_name , class_name ) ) {
2017-01-11 21:29:59 +00:00
return true ;
}
class_name = ClassDB : : get_parent_class_nocheck ( class_name ) ;
}
2017-03-05 15:44:50 +00:00
Control * parent = theme_owner - > get_parent ( ) ? theme_owner - > get_parent ( ) - > cast_to < Control > ( ) : NULL ;
2015-12-20 21:21:53 +00:00
if ( parent )
2017-03-05 15:44:50 +00:00
theme_owner = parent - > data . theme_owner ;
2015-12-20 21:21:53 +00:00
else
2017-03-05 15:44:50 +00:00
theme_owner = NULL ;
2015-12-20 21:21:53 +00:00
}
2017-03-05 15:44:50 +00:00
return Theme : : get_default ( ) - > has_shader ( p_name , type ) ;
2014-02-10 01:10:30 +00:00
}
2017-03-05 15:44:50 +00:00
bool Control : : has_stylebox ( const StringName & p_name , const StringName & p_type ) const {
2016-03-08 23:00:52 +00:00
2017-03-05 15:44:50 +00:00
if ( p_type = = StringName ( ) | | p_type = = " " ) {
if ( has_stylebox_override ( p_name ) = = true )
2014-12-17 01:31:57 +00:00
return true ;
}
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
StringName type = p_type ? p_type : get_class_name ( ) ;
2014-02-10 01:10:30 +00:00
// try with custom themes
Control * theme_owner = data . theme_owner ;
2017-03-05 15:44:50 +00:00
while ( theme_owner ) {
2014-02-10 01:10:30 +00:00
2017-01-11 21:29:59 +00:00
StringName class_name = type ;
2017-03-05 15:44:50 +00:00
while ( class_name ! = StringName ( ) ) {
if ( theme_owner - > data . theme - > has_stylebox ( p_name , class_name ) ) {
2017-01-11 21:29:59 +00:00
return true ;
}
class_name = ClassDB : : get_parent_class_nocheck ( class_name ) ;
}
2017-03-05 15:44:50 +00:00
Control * parent = theme_owner - > get_parent ( ) ? theme_owner - > get_parent ( ) - > cast_to < Control > ( ) : NULL ;
2014-02-10 01:10:30 +00:00
if ( parent )
2017-03-05 15:44:50 +00:00
theme_owner = parent - > data . theme_owner ;
2014-02-10 01:10:30 +00:00
else
2017-03-05 15:44:50 +00:00
theme_owner = NULL ;
2014-02-10 01:10:30 +00:00
}
2017-03-05 15:44:50 +00:00
return Theme : : get_default ( ) - > has_stylebox ( p_name , type ) ;
2014-02-10 01:10:30 +00:00
}
2017-03-05 15:44:50 +00:00
bool Control : : has_font ( const StringName & p_name , const StringName & p_type ) const {
2016-03-08 23:00:52 +00:00
2017-03-05 15:44:50 +00:00
if ( p_type = = StringName ( ) | | p_type = = " " ) {
if ( has_font_override ( p_name ) = = true )
2014-12-17 01:31:57 +00:00
return true ;
}
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
StringName type = p_type ? p_type : get_class_name ( ) ;
2014-02-10 01:10:30 +00:00
// try with custom themes
Control * theme_owner = data . theme_owner ;
2017-03-05 15:44:50 +00:00
while ( theme_owner ) {
2014-02-10 01:10:30 +00:00
2017-01-11 21:29:59 +00:00
StringName class_name = type ;
2017-03-05 15:44:50 +00:00
while ( class_name ! = StringName ( ) ) {
if ( theme_owner - > data . theme - > has_font ( p_name , class_name ) ) {
2017-01-11 21:29:59 +00:00
return true ;
}
class_name = ClassDB : : get_parent_class_nocheck ( class_name ) ;
}
2017-03-05 15:44:50 +00:00
Control * parent = theme_owner - > get_parent ( ) ? theme_owner - > get_parent ( ) - > cast_to < Control > ( ) : NULL ;
2014-02-10 01:10:30 +00:00
if ( parent )
2017-03-05 15:44:50 +00:00
theme_owner = parent - > data . theme_owner ;
2014-02-10 01:10:30 +00:00
else
2017-03-05 15:44:50 +00:00
theme_owner = NULL ;
2014-02-10 01:10:30 +00:00
}
2017-03-05 15:44:50 +00:00
return Theme : : get_default ( ) - > has_font ( p_name , type ) ;
2014-02-10 01:10:30 +00:00
}
2016-03-08 23:00:52 +00:00
2017-03-05 15:44:50 +00:00
bool Control : : has_color ( const StringName & p_name , const StringName & p_type ) const {
2016-06-01 14:41:25 +00:00
2017-03-05 15:44:50 +00:00
if ( p_type = = StringName ( ) | | p_type = = " " ) {
if ( has_color_override ( p_name ) = = true )
2014-12-17 01:31:57 +00:00
return true ;
}
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
StringName type = p_type ? p_type : get_class_name ( ) ;
2014-02-10 01:10:30 +00:00
// try with custom themes
Control * theme_owner = data . theme_owner ;
2017-03-05 15:44:50 +00:00
while ( theme_owner ) {
2014-02-10 01:10:30 +00:00
2017-01-11 21:29:59 +00:00
StringName class_name = type ;
2017-03-05 15:44:50 +00:00
while ( class_name ! = StringName ( ) ) {
if ( theme_owner - > data . theme - > has_color ( p_name , class_name ) ) {
2017-01-11 21:29:59 +00:00
return true ;
}
class_name = ClassDB : : get_parent_class_nocheck ( class_name ) ;
}
2017-03-05 15:44:50 +00:00
Control * parent = theme_owner - > get_parent ( ) ? theme_owner - > get_parent ( ) - > cast_to < Control > ( ) : NULL ;
2014-02-10 01:10:30 +00:00
if ( parent )
2017-03-05 15:44:50 +00:00
theme_owner = parent - > data . theme_owner ;
2014-02-10 01:10:30 +00:00
else
2017-03-05 15:44:50 +00:00
theme_owner = NULL ;
2014-02-10 01:10:30 +00:00
}
2017-03-05 15:44:50 +00:00
return Theme : : get_default ( ) - > has_color ( p_name , type ) ;
2014-02-10 01:10:30 +00:00
}
2017-03-05 15:44:50 +00:00
bool Control : : has_constant ( const StringName & p_name , const StringName & p_type ) const {
2014-12-17 01:31:57 +00:00
2017-03-05 15:44:50 +00:00
if ( p_type = = StringName ( ) | | p_type = = " " ) {
2016-06-01 14:41:25 +00:00
if ( has_constant_override ( p_name ) = = true )
2014-12-17 01:31:57 +00:00
return true ;
}
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
StringName type = p_type ? p_type : get_class_name ( ) ;
2014-02-10 01:10:30 +00:00
// try with custom themes
Control * theme_owner = data . theme_owner ;
2017-03-05 15:44:50 +00:00
while ( theme_owner ) {
2014-02-10 01:10:30 +00:00
2017-01-11 21:29:59 +00:00
StringName class_name = type ;
2017-03-05 15:44:50 +00:00
while ( class_name ! = StringName ( ) ) {
if ( theme_owner - > data . theme - > has_constant ( p_name , class_name ) ) {
2017-01-11 21:29:59 +00:00
return true ;
}
class_name = ClassDB : : get_parent_class_nocheck ( class_name ) ;
}
2017-03-05 15:44:50 +00:00
Control * parent = theme_owner - > get_parent ( ) ? theme_owner - > get_parent ( ) - > cast_to < Control > ( ) : NULL ;
2014-02-10 01:10:30 +00:00
if ( parent )
2017-03-05 15:44:50 +00:00
theme_owner = parent - > data . theme_owner ;
2014-02-10 01:10:30 +00:00
else
2017-03-05 15:44:50 +00:00
theme_owner = NULL ;
2014-02-10 01:10:30 +00:00
}
2017-03-05 15:44:50 +00:00
return Theme : : get_default ( ) - > has_constant ( p_name , type ) ;
2014-02-10 01:10:30 +00:00
}
Size2 Control : : get_parent_area_size ( ) const {
2017-03-05 15:44:50 +00:00
ERR_FAIL_COND_V ( ! is_inside_tree ( ) , Size2 ( ) ) ;
2014-02-10 01:10:30 +00:00
Size2 parent_size ;
if ( data . parent_canvas_item ) {
2017-03-05 15:44:50 +00:00
parent_size = data . parent_canvas_item - > get_item_rect ( ) . size ;
2016-01-17 01:41:10 +00:00
} else {
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
parent_size = get_viewport ( ) - > get_visible_rect ( ) . size ;
2016-03-08 23:00:52 +00:00
}
2017-06-12 19:18:17 +00:00
2014-02-10 01:10:30 +00:00
return parent_size ;
}
void Control : : _size_changed ( ) {
2014-11-06 00:20:42 +00:00
if ( ! is_inside_tree ( ) )
2014-02-10 01:10:30 +00:00
return ;
Size2 parent_size = get_parent_area_size ( ) ;
float margin_pos [ 4 ] ;
2017-03-05 15:44:50 +00:00
for ( int i = 0 ; i < 4 ; i + + ) {
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
float area = parent_size [ i & 1 ] ;
switch ( data . anchor [ i ] ) {
2014-02-10 01:10:30 +00:00
case ANCHOR_BEGIN : {
2017-03-05 15:44:50 +00:00
margin_pos [ i ] = data . margin [ i ] ;
2014-02-10 01:10:30 +00:00
} break ;
case ANCHOR_END : {
2017-03-05 15:44:50 +00:00
margin_pos [ i ] = area - data . margin [ i ] ;
2014-02-10 01:10:30 +00:00
} break ;
2017-01-08 22:11:35 +00:00
case ANCHOR_CENTER : {
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
margin_pos [ i ] = ( area / 2 ) - data . margin [ i ] ;
2014-02-10 01:10:30 +00:00
} break ;
}
}
2017-07-05 21:01:26 +00:00
Point2 new_pos_cache = Point2 ( margin_pos [ 0 ] , margin_pos [ 1 ] ) ;
Size2 new_size_cache = Point2 ( margin_pos [ 2 ] , margin_pos [ 3 ] ) - new_pos_cache ;
2017-07-06 16:26:39 +00:00
2017-03-05 15:44:50 +00:00
Size2 minimum_size = get_combined_minimum_size ( ) ;
2014-02-10 01:10:30 +00:00
2017-07-06 16:26:39 +00:00
if ( data . h_grow = = GROW_DIRECTION_BEGIN ) {
if ( minimum_size . width > new_size_cache . width ) {
new_pos_cache . x = new_pos_cache . x + new_size_cache . width - minimum_size . width ;
new_size_cache . width = minimum_size . width ;
}
} else {
new_size_cache . width = MAX ( minimum_size . width , new_size_cache . width ) ;
}
if ( data . v_grow = = GROW_DIRECTION_BEGIN ) {
if ( minimum_size . height > new_size_cache . height ) {
new_pos_cache . y = new_pos_cache . y + new_size_cache . height - minimum_size . height ;
new_size_cache . height = minimum_size . height ;
}
} else {
new_size_cache . height = MAX ( minimum_size . height , new_size_cache . height ) ;
}
2014-02-10 01:10:30 +00:00
2016-08-31 02:44:14 +00:00
bool pos_changed = new_pos_cache ! = data . pos_cache ;
bool size_changed = new_size_cache ! = data . size_cache ;
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
data . pos_cache = new_pos_cache ;
data . size_cache = new_size_cache ;
2014-02-10 01:10:30 +00:00
2016-08-31 02:44:14 +00:00
if ( size_changed ) {
notification ( NOTIFICATION_RESIZED ) ;
}
if ( pos_changed | | size_changed ) {
item_rect_changed ( size_changed ) ;
_change_notify_margins ( ) ;
_notify_transform ( ) ;
}
if ( pos_changed & & ! size_changed ) {
_update_canvas_item_transform ( ) ; //move because it won't be updated
}
2014-02-10 01:10:30 +00:00
}
float Control : : _get_parent_range ( int p_idx ) const {
2016-03-08 23:00:52 +00:00
2014-11-06 00:20:42 +00:00
if ( ! is_inside_tree ( ) ) {
2016-03-08 23:00:52 +00:00
2014-02-10 01:10:30 +00:00
return 1.0 ;
2017-03-05 15:44:50 +00:00
}
if ( data . parent_canvas_item ) {
2016-03-08 23:00:52 +00:00
2017-03-05 15:44:50 +00:00
return data . parent_canvas_item - > get_item_rect ( ) . size [ p_idx & 1 ] ;
2016-01-17 01:41:10 +00:00
} else {
2017-03-05 15:44:50 +00:00
return get_viewport ( ) - > get_visible_rect ( ) . size [ p_idx & 1 ] ;
2014-02-10 01:10:30 +00:00
}
return 1.0 ;
}
float Control : : _get_range ( int p_idx ) const {
2016-03-08 23:00:52 +00:00
2017-03-05 15:44:50 +00:00
p_idx & = 1 ;
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
float parent_range = _get_parent_range ( p_idx ) ;
float from = _a2s ( data . margin [ p_idx ] , data . anchor [ p_idx ] , parent_range ) ;
float to = _a2s ( data . margin [ p_idx + 2 ] , data . anchor [ p_idx + 2 ] , parent_range ) ;
2016-03-08 23:00:52 +00:00
2017-03-05 15:44:50 +00:00
return to - from ;
2014-02-10 01:10:30 +00:00
}
2017-03-05 15:44:50 +00:00
float Control : : _s2a ( float p_val , AnchorType p_anchor , float p_range ) const {
2016-03-08 23:00:52 +00:00
2017-03-05 15:44:50 +00:00
switch ( p_anchor ) {
2016-03-08 23:00:52 +00:00
case ANCHOR_BEGIN : {
2014-02-10 01:10:30 +00:00
return p_val ;
} break ;
case ANCHOR_END : {
2017-03-05 15:44:50 +00:00
return p_range - p_val ;
2014-02-10 01:10:30 +00:00
} break ;
2017-01-08 22:11:35 +00:00
case ANCHOR_CENTER : {
2017-03-05 15:44:50 +00:00
return ( p_range / 2 ) - p_val ;
2016-03-08 23:00:52 +00:00
} break ;
}
2014-02-10 01:10:30 +00:00
return 0 ;
}
2017-03-05 15:44:50 +00:00
float Control : : _a2s ( float p_val , AnchorType p_anchor , float p_range ) const {
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
switch ( p_anchor ) {
2016-03-08 23:00:52 +00:00
case ANCHOR_BEGIN : {
2014-02-10 01:10:30 +00:00
return Math : : floor ( p_val ) ;
} break ;
case ANCHOR_END : {
2017-03-05 15:44:50 +00:00
return Math : : floor ( p_range - p_val ) ;
2014-02-10 01:10:30 +00:00
} break ;
2014-09-17 14:53:29 +00:00
case ANCHOR_CENTER : {
2017-03-05 15:44:50 +00:00
return Math : : floor ( ( p_range / 2 ) - p_val ) ;
2014-09-17 14:53:29 +00:00
} break ;
2014-02-10 01:10:30 +00:00
}
return 0 ;
}
2017-03-05 15:44:50 +00:00
void Control : : set_anchor ( Margin p_margin , AnchorType p_anchor , bool p_keep_margin ) {
2016-03-08 23:00:52 +00:00
2014-11-06 00:20:42 +00:00
if ( ! is_inside_tree ( ) ) {
2016-03-08 23:00:52 +00:00
2016-03-09 16:59:35 +00:00
data . anchor [ p_margin ] = p_anchor ;
2017-03-05 15:44:50 +00:00
} else if ( ! p_keep_margin ) {
2014-02-10 01:10:30 +00:00
float pr = _get_parent_range ( p_margin ) ;
2017-03-05 15:44:50 +00:00
float s = _a2s ( data . margin [ p_margin ] , data . anchor [ p_margin ] , pr ) ;
2016-03-09 16:59:35 +00:00
data . anchor [ p_margin ] = p_anchor ;
2017-03-05 15:44:50 +00:00
data . margin [ p_margin ] = _s2a ( s , p_anchor , pr ) ;
2016-03-09 16:59:35 +00:00
} else {
data . anchor [ p_margin ] = p_anchor ;
_size_changed ( ) ;
2014-02-10 01:10:30 +00:00
}
_change_notify ( ) ;
}
2017-03-05 15:44:50 +00:00
void Control : : _set_anchor ( Margin p_margin , AnchorType p_anchor ) {
# ifdef TOOLS_ENABLED
2016-05-10 17:20:28 +00:00
if ( is_inside_tree ( ) & & get_tree ( ) - > is_editor_hint ( ) ) {
2017-01-05 22:41:36 +00:00
set_anchor ( p_margin , p_anchor , EDITOR_DEF ( " editors/2d/keep_margins_when_changing_anchors " , false ) ) ;
2016-03-10 19:00:01 +00:00
} else {
2016-05-10 17:20:28 +00:00
set_anchor ( p_margin , p_anchor , false ) ;
2016-03-10 19:00:01 +00:00
}
2017-03-05 15:44:50 +00:00
# else
2016-05-10 17:20:28 +00:00
set_anchor ( p_margin , p_anchor , false ) ;
2017-03-05 15:44:50 +00:00
# endif
2016-03-09 16:59:35 +00:00
}
2017-03-05 15:44:50 +00:00
void Control : : set_anchor_and_margin ( Margin p_margin , AnchorType p_anchor , float p_pos ) {
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
set_anchor ( p_margin , p_anchor ) ;
set_margin ( p_margin , p_pos ) ;
2014-02-10 01:10:30 +00:00
}
Control : : AnchorType Control : : get_anchor ( Margin p_margin ) const {
2016-03-08 23:00:52 +00:00
return data . anchor [ p_margin ] ;
2014-02-10 01:10:30 +00:00
}
void Control : : _change_notify_margins ( ) {
// this avoids sending the whole object data again on a change
2017-04-01 04:07:35 +00:00
_change_notify ( " margin_left " ) ;
_change_notify ( " margin_top " ) ;
_change_notify ( " margin_right " ) ;
_change_notify ( " margin_bottom " ) ;
2017-05-28 13:38:22 +00:00
_change_notify ( " rect_position " ) ;
2017-04-01 04:07:35 +00:00
_change_notify ( " rect_size " ) ;
2014-02-10 01:10:30 +00:00
}
2017-03-05 15:44:50 +00:00
void Control : : set_margin ( Margin p_margin , float p_value ) {
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
data . margin [ p_margin ] = p_value ;
2014-02-10 01:10:30 +00:00
_size_changed ( ) ;
}
2017-03-05 15:44:50 +00:00
void Control : : set_begin ( const Size2 & p_point ) {
2016-03-08 23:00:52 +00:00
2017-03-05 15:44:50 +00:00
data . margin [ 0 ] = p_point . x ;
data . margin [ 1 ] = p_point . y ;
2014-02-10 01:10:30 +00:00
_size_changed ( ) ;
}
2017-03-05 15:44:50 +00:00
void Control : : set_end ( const Size2 & p_point ) {
2016-03-08 23:00:52 +00:00
2017-03-05 15:44:50 +00:00
data . margin [ 2 ] = p_point . x ;
data . margin [ 3 ] = p_point . y ;
2014-02-10 01:10:30 +00:00
_size_changed ( ) ;
}
float Control : : get_margin ( Margin p_margin ) const {
2016-03-08 23:00:52 +00:00
2014-02-10 01:10:30 +00:00
return data . margin [ p_margin ] ;
}
Size2 Control : : get_begin ( ) const {
2016-03-08 23:00:52 +00:00
2017-03-05 15:44:50 +00:00
return Size2 ( data . margin [ 0 ] , data . margin [ 1 ] ) ;
2014-02-10 01:10:30 +00:00
}
Size2 Control : : get_end ( ) const {
2016-03-08 23:00:52 +00:00
2017-03-05 15:44:50 +00:00
return Size2 ( data . margin [ 2 ] , data . margin [ 3 ] ) ;
2014-02-10 01:10:30 +00:00
}
2017-03-29 15:29:38 +00:00
Point2 Control : : get_global_position ( ) const {
2016-03-08 23:00:52 +00:00
2014-02-10 01:10:30 +00:00
return get_global_transform ( ) . get_origin ( ) ;
}
2017-03-29 15:29:38 +00:00
void Control : : set_global_position ( const Point2 & p_point ) {
2016-03-08 23:00:52 +00:00
2017-01-11 03:52:51 +00:00
Transform2D inv ;
2014-02-10 01:10:30 +00:00
if ( data . parent_canvas_item ) {
inv = data . parent_canvas_item - > get_global_transform ( ) . affine_inverse ( ) ;
}
2017-03-29 15:29:38 +00:00
set_position ( inv . xform ( p_point ) ) ;
2014-02-10 01:10:30 +00:00
}
2017-03-29 15:29:38 +00:00
void Control : : set_position ( const Size2 & p_point ) {
2014-02-10 01:10:30 +00:00
float pw = _get_parent_range ( 0 ) ;
float ph = _get_parent_range ( 1 ) ;
2017-03-05 15:44:50 +00:00
float x = _a2s ( data . margin [ 0 ] , data . anchor [ 0 ] , pw ) ;
float y = _a2s ( data . margin [ 1 ] , data . anchor [ 1 ] , ph ) ;
float x2 = _a2s ( data . margin [ 2 ] , data . anchor [ 2 ] , pw ) ;
float y2 = _a2s ( data . margin [ 3 ] , data . anchor [ 3 ] , ph ) ;
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
Size2 ret = Size2 ( x2 - x , y2 - y ) ;
2014-02-10 01:10:30 +00:00
Size2 min = get_combined_minimum_size ( ) ;
2017-03-05 15:44:50 +00:00
Size2 size = Size2 ( MAX ( min . width , ret . width ) , MAX ( min . height , ret . height ) ) ;
float w = size . x ;
float h = size . y ;
2016-03-08 23:00:52 +00:00
2017-03-05 15:44:50 +00:00
x = p_point . x ;
y = p_point . y ;
2016-03-08 23:00:52 +00:00
2017-03-05 15:44:50 +00:00
data . margin [ 0 ] = _s2a ( x , data . anchor [ 0 ] , pw ) ;
data . margin [ 1 ] = _s2a ( y , data . anchor [ 1 ] , ph ) ;
data . margin [ 2 ] = _s2a ( x + w , data . anchor [ 2 ] , pw ) ;
data . margin [ 3 ] = _s2a ( y + h , data . anchor [ 3 ] , ph ) ;
2014-02-10 01:10:30 +00:00
_size_changed ( ) ;
}
2017-03-05 15:44:50 +00:00
void Control : : set_size ( const Size2 & p_size ) {
2016-03-08 23:00:52 +00:00
2017-03-05 15:44:50 +00:00
Size2 new_size = p_size ;
Size2 min = get_combined_minimum_size ( ) ;
if ( new_size . x < min . x )
new_size . x = min . x ;
if ( new_size . y < min . y )
new_size . y = min . y ;
2016-03-08 23:00:52 +00:00
2014-02-10 01:10:30 +00:00
float pw = _get_parent_range ( 0 ) ;
float ph = _get_parent_range ( 1 ) ;
2016-03-08 23:00:52 +00:00
2017-03-05 15:44:50 +00:00
float x = _a2s ( data . margin [ 0 ] , data . anchor [ 0 ] , pw ) ;
float y = _a2s ( data . margin [ 1 ] , data . anchor [ 1 ] , ph ) ;
2016-03-08 23:00:52 +00:00
2017-03-05 15:44:50 +00:00
float w = new_size . width ;
float h = new_size . height ;
2016-03-08 23:00:52 +00:00
2017-03-05 15:44:50 +00:00
data . margin [ 2 ] = _s2a ( x + w , data . anchor [ 2 ] , pw ) ;
data . margin [ 3 ] = _s2a ( y + h , data . anchor [ 3 ] , ph ) ;
2016-03-08 23:00:52 +00:00
2014-02-10 01:10:30 +00:00
_size_changed ( ) ;
}
2017-03-29 15:29:38 +00:00
Size2 Control : : get_position ( ) const {
2014-02-10 01:10:30 +00:00
return data . pos_cache ;
}
Size2 Control : : get_size ( ) const {
2016-03-08 23:00:52 +00:00
2014-02-10 01:10:30 +00:00
return data . size_cache ;
}
Rect2 Control : : get_global_rect ( ) const {
2016-03-08 23:00:52 +00:00
2017-03-29 15:29:38 +00:00
return Rect2 ( get_global_position ( ) , get_size ( ) ) ;
2014-02-10 01:10:30 +00:00
}
Rect2 Control : : get_window_rect ( ) const {
2017-03-05 15:44:50 +00:00
ERR_FAIL_COND_V ( ! is_inside_tree ( ) , Rect2 ( ) ) ;
2014-02-10 01:10:30 +00:00
Rect2 gr = get_global_rect ( ) ;
2017-06-03 22:25:13 +00:00
gr . position + = get_viewport ( ) - > get_visible_rect ( ) . position ;
2014-02-10 01:10:30 +00:00
return gr ;
}
Rect2 Control : : get_rect ( ) const {
2016-03-08 23:00:52 +00:00
2017-03-29 15:29:38 +00:00
return Rect2 ( get_position ( ) , get_size ( ) ) ;
2014-02-10 01:10:30 +00:00
}
Rect2 Control : : get_item_rect ( ) const {
2017-03-05 15:44:50 +00:00
return Rect2 ( Point2 ( ) , get_size ( ) ) ;
2014-02-10 01:10:30 +00:00
}
void Control : : set_area_as_parent_rect ( int p_margin ) {
2016-03-08 23:00:52 +00:00
2017-03-05 15:44:50 +00:00
data . anchor [ MARGIN_LEFT ] = ANCHOR_BEGIN ;
data . anchor [ MARGIN_TOP ] = ANCHOR_BEGIN ;
data . anchor [ MARGIN_RIGHT ] = ANCHOR_END ;
data . anchor [ MARGIN_BOTTOM ] = ANCHOR_END ;
for ( int i = 0 ; i < 4 ; i + + )
data . margin [ i ] = p_margin ;
2014-02-10 01:10:30 +00:00
_size_changed ( ) ;
}
2017-03-05 15:44:50 +00:00
void Control : : add_icon_override ( const StringName & p_name , const Ref < Texture > & p_icon ) {
2014-02-10 01:10:30 +00:00
ERR_FAIL_COND ( p_icon . is_null ( ) ) ;
2017-03-05 15:44:50 +00:00
data . icon_override [ p_name ] = p_icon ;
2014-02-10 01:10:30 +00:00
notification ( NOTIFICATION_THEME_CHANGED ) ;
update ( ) ;
2015-12-20 21:21:53 +00:00
}
2014-02-10 01:10:30 +00:00
2015-12-20 21:21:53 +00:00
void Control : : add_shader_override ( const StringName & p_name , const Ref < Shader > & p_shader ) {
ERR_FAIL_COND ( p_shader . is_null ( ) ) ;
2017-03-05 15:44:50 +00:00
data . shader_override [ p_name ] = p_shader ;
2015-12-20 21:21:53 +00:00
notification ( NOTIFICATION_THEME_CHANGED ) ;
update ( ) ;
2014-02-10 01:10:30 +00:00
}
2017-03-05 15:44:50 +00:00
void Control : : add_style_override ( const StringName & p_name , const Ref < StyleBox > & p_style ) {
2014-02-10 01:10:30 +00:00
ERR_FAIL_COND ( p_style . is_null ( ) ) ;
2017-03-05 15:44:50 +00:00
data . style_override [ p_name ] = p_style ;
2014-02-10 01:10:30 +00:00
notification ( NOTIFICATION_THEME_CHANGED ) ;
update ( ) ;
}
2017-03-05 15:44:50 +00:00
void Control : : add_font_override ( const StringName & p_name , const Ref < Font > & p_font ) {
2014-02-10 01:10:30 +00:00
ERR_FAIL_COND ( p_font . is_null ( ) ) ;
2016-06-17 19:00:27 +00:00
if ( data . font_override . has ( p_name ) ) {
_unref_font ( data . font_override [ p_name ] ) ;
}
2017-03-05 15:44:50 +00:00
data . font_override [ p_name ] = p_font ;
2016-06-17 19:00:27 +00:00
if ( p_font . is_valid ( ) ) {
_ref_font ( p_font ) ;
}
2014-02-10 01:10:30 +00:00
notification ( NOTIFICATION_THEME_CHANGED ) ;
update ( ) ;
}
2017-03-05 15:44:50 +00:00
void Control : : add_color_override ( const StringName & p_name , const Color & p_color ) {
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
data . color_override [ p_name ] = p_color ;
2014-02-10 01:10:30 +00:00
notification ( NOTIFICATION_THEME_CHANGED ) ;
update ( ) ;
}
2017-03-05 15:44:50 +00:00
void Control : : add_constant_override ( const StringName & p_name , int p_constant ) {
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
data . constant_override [ p_name ] = p_constant ;
2014-02-10 01:10:30 +00:00
notification ( NOTIFICATION_THEME_CHANGED ) ;
update ( ) ;
}
void Control : : set_focus_mode ( FocusMode p_focus_mode ) {
2017-03-05 15:44:50 +00:00
if ( is_inside_tree ( ) & & p_focus_mode = = FOCUS_NONE & & data . focus_mode ! = FOCUS_NONE & & has_focus ( ) )
2014-02-10 01:10:30 +00:00
release_focus ( ) ;
2017-03-05 15:44:50 +00:00
data . focus_mode = p_focus_mode ;
2014-02-10 01:10:30 +00:00
}
static Control * _next_control ( Control * p_from ) {
if ( p_from - > is_set_as_toplevel ( ) )
return NULL ; // can't go above
2017-03-05 15:44:50 +00:00
Control * parent = p_from - > get_parent ( ) ? p_from - > get_parent ( ) - > cast_to < Control > ( ) : NULL ;
2014-02-10 01:10:30 +00:00
if ( ! parent ) {
return NULL ;
}
int next = p_from - > get_position_in_parent ( ) ;
2017-03-05 15:44:50 +00:00
ERR_FAIL_INDEX_V ( next , parent - > get_child_count ( ) , NULL ) ;
for ( int i = ( next + 1 ) ; i < parent - > get_child_count ( ) ; i + + ) {
2014-02-10 01:10:30 +00:00
Control * c = parent - > get_child ( i ) - > cast_to < Control > ( ) ;
2017-01-13 13:45:50 +00:00
if ( ! c | | ! c - > is_visible_in_tree ( ) | | c - > is_set_as_toplevel ( ) )
2014-02-10 01:10:30 +00:00
continue ;
return c ;
}
//no next in parent, try the same in parent
return _next_control ( parent ) ;
}
Control * Control : : find_next_valid_focus ( ) const {
2017-03-05 15:44:50 +00:00
Control * from = const_cast < Control * > ( this ) ;
2016-03-08 23:00:52 +00:00
2017-03-05 15:44:50 +00:00
while ( true ) {
2016-03-08 23:00:52 +00:00
2014-02-10 01:10:30 +00:00
// find next child
2017-03-05 15:44:50 +00:00
Control * next_child = NULL ;
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
for ( int i = 0 ; i < from - > get_child_count ( ) ; i + + ) {
2014-02-10 01:10:30 +00:00
Control * c = from - > get_child ( i ) - > cast_to < Control > ( ) ;
2017-01-13 13:45:50 +00:00
if ( ! c | | ! c - > is_visible_in_tree ( ) | | c - > is_set_as_toplevel ( ) ) {
2014-02-10 01:10:30 +00:00
continue ;
}
2017-03-05 15:44:50 +00:00
next_child = c ;
2014-02-10 01:10:30 +00:00
break ;
}
if ( next_child ) {
from = next_child ;
} else {
2017-03-05 15:44:50 +00:00
next_child = _next_control ( from ) ;
2014-02-10 01:10:30 +00:00
if ( ! next_child ) { //nothing else.. go up and find either window or subwindow
2017-03-05 15:44:50 +00:00
next_child = const_cast < Control * > ( this ) ;
while ( next_child & & ! next_child - > is_set_as_toplevel ( ) ) {
2014-02-10 01:10:30 +00:00
if ( next_child - > get_parent ( ) ) {
2017-03-05 15:44:50 +00:00
next_child = next_child - > get_parent ( ) - > cast_to < Control > ( ) ;
2014-02-10 01:10:30 +00:00
} else
2017-03-05 15:44:50 +00:00
next_child = NULL ;
2014-02-10 01:10:30 +00:00
}
if ( ! next_child ) {
2016-01-17 01:41:10 +00:00
2017-03-05 15:44:50 +00:00
next_child = const_cast < Control * > ( this ) ;
while ( next_child ) {
2016-01-17 01:41:10 +00:00
if ( next_child - > data . SI | | next_child - > data . RI )
break ;
2017-03-05 15:44:50 +00:00
next_child = next_child - > get_parent_control ( ) ;
2016-01-17 01:41:10 +00:00
}
2014-02-10 01:10:30 +00:00
}
}
}
2017-03-05 15:44:50 +00:00
if ( next_child = = this ) // no next control->
return ( get_focus_mode ( ) = = FOCUS_ALL ) ? next_child : NULL ;
2016-10-05 06:56:58 +00:00
if ( next_child ) {
2017-03-05 15:44:50 +00:00
if ( next_child - > get_focus_mode ( ) = = FOCUS_ALL )
2016-10-05 06:56:58 +00:00
return next_child ;
from = next_child ;
2017-03-05 15:44:50 +00:00
} else
break ;
2014-02-10 01:10:30 +00:00
}
2016-03-08 23:00:52 +00:00
2014-02-10 01:10:30 +00:00
return NULL ;
}
static Control * _prev_control ( Control * p_from ) {
2017-03-05 15:44:50 +00:00
Control * child = NULL ;
for ( int i = p_from - > get_child_count ( ) - 1 ; i > = 0 ; i - - ) {
2014-02-10 01:10:30 +00:00
Control * c = p_from - > get_child ( i ) - > cast_to < Control > ( ) ;
2017-01-13 13:45:50 +00:00
if ( ! c | | ! c - > is_visible_in_tree ( ) | | c - > is_set_as_toplevel ( ) )
2014-02-10 01:10:30 +00:00
continue ;
2017-03-05 15:44:50 +00:00
child = c ;
2014-02-10 01:10:30 +00:00
break ;
}
if ( ! child )
return p_from ;
//no prev in parent, try the same in parent
return _prev_control ( child ) ;
}
Control * Control : : find_prev_valid_focus ( ) const {
2017-03-05 15:44:50 +00:00
Control * from = const_cast < Control * > ( this ) ;
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
while ( true ) {
2014-02-10 01:10:30 +00:00
// find prev child
2017-03-05 15:44:50 +00:00
Control * prev_child = NULL ;
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
if ( from - > is_set_as_toplevel ( ) | | ! from - > get_parent ( ) | | ! from - > get_parent ( ) - > cast_to < Control > ( ) ) {
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
//find last of the childs
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
prev_child = _prev_control ( from ) ;
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
} else {
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
for ( int i = ( from - > get_position_in_parent ( ) - 1 ) ; i > = 0 ; i - - ) {
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
Control * c = from - > get_parent ( ) - > get_child ( i ) - > cast_to < Control > ( ) ;
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
if ( ! c | | ! c - > is_visible_in_tree ( ) | | c - > is_set_as_toplevel ( ) ) {
continue ;
2014-02-10 01:10:30 +00:00
}
2017-03-05 15:44:50 +00:00
prev_child = c ;
break ;
2014-02-10 01:10:30 +00:00
}
2017-03-05 15:44:50 +00:00
if ( ! prev_child ) {
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
prev_child = from - > get_parent ( ) - > cast_to < Control > ( ) ;
} else {
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
prev_child = _prev_control ( prev_child ) ;
}
}
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
if ( prev_child = = this ) // no prev control->
return ( get_focus_mode ( ) = = FOCUS_ALL ) ? prev_child : NULL ;
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
if ( prev_child - > get_focus_mode ( ) = = FOCUS_ALL )
return prev_child ;
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
from = prev_child ;
}
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
return NULL ;
2014-02-10 01:10:30 +00:00
return NULL ;
}
Control : : FocusMode Control : : get_focus_mode ( ) const {
return data . focus_mode ;
}
bool Control : : has_focus ( ) const {
2016-01-17 01:41:10 +00:00
return is_inside_tree ( ) & & get_viewport ( ) - > _gui_control_has_focus ( this ) ;
2014-02-10 01:10:30 +00:00
}
void Control : : grab_focus ( ) {
2017-03-05 15:44:50 +00:00
if ( ! is_inside_tree ( ) ) {
2016-02-01 22:00:19 +00:00
ERR_FAIL_COND ( ! is_inside_tree ( ) ) ;
}
2017-03-05 15:44:50 +00:00
if ( data . focus_mode = = FOCUS_NONE )
2014-02-10 01:10:30 +00:00
return ;
2016-01-17 01:41:10 +00:00
get_viewport ( ) - > _gui_control_grab_focus ( this ) ;
2016-03-08 23:00:52 +00:00
}
2014-02-10 01:10:30 +00:00
void Control : : release_focus ( ) {
2014-11-06 00:20:42 +00:00
ERR_FAIL_COND ( ! is_inside_tree ( ) ) ;
2014-02-10 01:10:30 +00:00
if ( ! has_focus ( ) )
return ;
2016-01-17 01:41:10 +00:00
get_viewport ( ) - > _gui_remove_focus ( ) ;
2014-02-10 01:10:30 +00:00
update ( ) ;
}
bool Control : : is_toplevel_control ( ) const {
2016-01-17 01:41:10 +00:00
return is_inside_tree ( ) & & ( ! data . parent_canvas_item & & ! data . RI & & is_set_as_toplevel ( ) ) ;
2014-02-10 01:10:30 +00:00
}
void Control : : show_modal ( bool p_exclusive ) {
2016-03-08 23:00:52 +00:00
2014-11-06 00:20:42 +00:00
ERR_FAIL_COND ( ! is_inside_tree ( ) ) ;
2016-01-17 01:41:10 +00:00
ERR_FAIL_COND ( ! data . SI ) ;
2014-02-10 01:10:30 +00:00
2017-01-13 13:45:50 +00:00
if ( is_visible_in_tree ( ) )
2014-02-10 01:10:30 +00:00
hide ( ) ;
2017-03-05 15:44:50 +00:00
ERR_FAIL_COND ( data . MI ! = NULL ) ;
2014-02-10 01:10:30 +00:00
show ( ) ;
raise ( ) ;
2017-03-05 15:44:50 +00:00
data . modal_exclusive = p_exclusive ;
data . MI = get_viewport ( ) - > _gui_show_modal ( this ) ;
data . modal_frame = Engine : : get_singleton ( ) - > get_frames_drawn ( ) ;
2014-02-10 01:10:30 +00:00
}
2016-01-17 01:41:10 +00:00
void Control : : _modal_set_prev_focus_owner ( ObjectID p_prev ) {
2017-03-05 15:44:50 +00:00
data . modal_prev_focus_owner = p_prev ;
2014-02-10 01:10:30 +00:00
}
void Control : : _modal_stack_remove ( ) {
2016-01-17 01:41:10 +00:00
ERR_FAIL_COND ( ! is_inside_tree ( ) ) ;
2014-02-10 01:10:30 +00:00
2016-01-17 01:41:10 +00:00
if ( ! data . MI )
return ;
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
get_viewport ( ) - > _gui_remove_from_modal_stack ( data . MI , data . modal_prev_focus_owner ) ;
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
data . MI = NULL ;
data . modal_prev_focus_owner = 0 ;
2014-02-10 01:10:30 +00:00
}
2017-03-05 15:44:50 +00:00
void Control : : _propagate_theme_changed ( CanvasItem * p_at , Control * p_owner , bool p_assign ) {
2016-06-14 00:10:45 +00:00
Control * c = p_at - > cast_to < Control > ( ) ;
2017-03-05 15:44:50 +00:00
if ( c & & c ! = p_owner & & c - > data . theme . is_valid ( ) ) // has a theme, this can't be propagated
2016-06-14 00:10:45 +00:00
return ;
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
for ( int i = 0 ; i < p_at - > get_child_count ( ) ; i + + ) {
2016-06-14 00:10:45 +00:00
CanvasItem * child = p_at - > get_child ( i ) - > cast_to < CanvasItem > ( ) ;
if ( child ) {
2017-03-05 15:44:50 +00:00
_propagate_theme_changed ( child , p_owner , p_assign ) ;
2016-06-14 00:10:45 +00:00
}
2014-02-10 01:10:30 +00:00
}
2016-06-14 00:10:45 +00:00
if ( c ) {
2016-07-18 19:41:28 +00:00
if ( p_assign ) {
2017-03-05 15:44:50 +00:00
c - > data . theme_owner = p_owner ;
2016-07-18 19:41:28 +00:00
}
2016-09-11 14:28:01 +00:00
c - > notification ( NOTIFICATION_THEME_CHANGED ) ;
2016-06-14 00:10:45 +00:00
c - > update ( ) ;
}
2014-02-10 01:10:30 +00:00
}
2016-07-18 19:41:28 +00:00
void Control : : _theme_changed ( ) {
2017-03-05 15:44:50 +00:00
_propagate_theme_changed ( this , this , false ) ;
2016-07-18 19:41:28 +00:00
}
2017-03-05 15:44:50 +00:00
void Control : : set_theme ( const Ref < Theme > & p_theme ) {
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
if ( data . theme = = p_theme )
2016-07-18 19:41:28 +00:00
return ;
if ( data . theme . is_valid ( ) ) {
2017-03-05 15:44:50 +00:00
data . theme - > disconnect ( " changed " , this , " _theme_changed " ) ;
2016-07-18 19:41:28 +00:00
}
2017-03-05 15:44:50 +00:00
data . theme = p_theme ;
2014-02-10 01:10:30 +00:00
if ( ! p_theme . is_null ( ) ) {
2017-03-05 15:44:50 +00:00
_propagate_theme_changed ( this , this ) ;
2014-02-10 01:10:30 +00:00
} else {
2017-03-05 15:44:50 +00:00
Control * parent = get_parent ( ) ? get_parent ( ) - > cast_to < Control > ( ) : NULL ;
2014-02-10 01:10:30 +00:00
if ( parent & & parent - > data . theme_owner ) {
2017-03-05 15:44:50 +00:00
_propagate_theme_changed ( this , parent - > data . theme_owner ) ;
2014-02-10 01:10:30 +00:00
} else {
2017-03-05 15:44:50 +00:00
_propagate_theme_changed ( this , NULL ) ;
2014-02-10 01:10:30 +00:00
}
}
2016-07-18 19:41:28 +00:00
if ( data . theme . is_valid ( ) ) {
2017-03-05 15:44:50 +00:00
data . theme - > connect ( " changed " , this , " _theme_changed " ) ;
2016-07-18 19:41:28 +00:00
}
2014-02-10 01:10:30 +00:00
}
2016-01-17 01:41:10 +00:00
void Control : : accept_event ( ) {
2014-02-10 01:10:30 +00:00
2014-11-06 00:20:42 +00:00
if ( is_inside_tree ( ) )
2016-01-17 01:41:10 +00:00
get_viewport ( ) - > _gui_accept_event ( ) ;
2014-02-10 01:10:30 +00:00
}
Ref < Theme > Control : : get_theme ( ) const {
return data . theme ;
}
2017-03-05 15:44:50 +00:00
void Control : : set_tooltip ( const String & p_tooltip ) {
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
data . tooltip = p_tooltip ;
2014-02-10 01:10:30 +00:00
}
2017-03-05 15:44:50 +00:00
String Control : : get_tooltip ( const Point2 & p_pos ) const {
2014-02-10 01:10:30 +00:00
return data . tooltip ;
}
void Control : : set_default_cursor_shape ( CursorShape p_shape ) {
2017-03-05 15:44:50 +00:00
data . default_cursor = p_shape ;
2014-02-10 01:10:30 +00:00
}
Control : : CursorShape Control : : get_default_cursor_shape ( ) const {
return data . default_cursor ;
}
2017-03-05 15:44:50 +00:00
Control : : CursorShape Control : : get_cursor_shape ( const Point2 & p_pos ) const {
2014-02-10 01:10:30 +00:00
return data . default_cursor ;
}
2017-01-11 03:52:51 +00:00
Transform2D Control : : get_transform ( ) const {
2014-02-10 01:10:30 +00:00
2017-07-06 20:42:44 +00:00
Transform2D xform = _get_internal_transform ( ) ;
xform [ 2 ] + = get_position ( ) ;
2015-12-12 16:54:26 +00:00
return xform ;
2014-02-10 01:10:30 +00:00
}
String Control : : _get_tooltip ( ) const {
return data . tooltip ;
}
void Control : : set_focus_neighbour ( Margin p_margin , const NodePath & p_neighbour ) {
2017-03-05 15:44:50 +00:00
ERR_FAIL_INDEX ( p_margin , 4 ) ;
data . focus_neighbour [ p_margin ] = p_neighbour ;
2014-02-10 01:10:30 +00:00
}
NodePath Control : : get_focus_neighbour ( Margin p_margin ) const {
2017-03-05 15:44:50 +00:00
ERR_FAIL_INDEX_V ( p_margin , 4 , NodePath ( ) ) ;
2014-02-10 01:10:30 +00:00
return data . focus_neighbour [ p_margin ] ;
}
# define MAX_NEIGHBOUR_SEARCH_COUNT 512
2017-03-05 15:44:50 +00:00
Control * Control : : _get_focus_neighbour ( Margin p_margin , int p_count ) {
2014-02-10 01:10:30 +00:00
if ( p_count > = MAX_NEIGHBOUR_SEARCH_COUNT )
return NULL ;
if ( ! data . focus_neighbour [ p_margin ] . is_empty ( ) ) {
2017-03-05 15:44:50 +00:00
Control * c = NULL ;
Node * n = get_node ( data . focus_neighbour [ p_margin ] ) ;
2014-02-10 01:10:30 +00:00
if ( n ) {
2017-03-05 15:44:50 +00:00
c = n - > cast_to < Control > ( ) ;
2014-02-10 01:10:30 +00:00
if ( ! c ) {
2017-03-05 15:44:50 +00:00
ERR_EXPLAIN ( " Next focus node is not a control: " + n - > get_name ( ) ) ;
2014-02-10 01:10:30 +00:00
ERR_FAIL_V ( NULL ) ;
}
} else {
return NULL ;
}
2017-03-05 15:44:50 +00:00
bool valid = true ;
2017-01-13 13:45:50 +00:00
if ( ! c - > is_visible ( ) )
2017-03-05 15:44:50 +00:00
valid = false ;
if ( c - > get_focus_mode ( ) = = FOCUS_NONE )
valid = false ;
2014-02-10 01:10:30 +00:00
if ( valid )
return c ;
2017-03-05 15:44:50 +00:00
c = c - > _get_focus_neighbour ( p_margin , p_count + 1 ) ;
2014-02-10 01:10:30 +00:00
return c ;
}
2017-03-05 15:44:50 +00:00
float dist = 1e7 ;
Control * result = NULL ;
2014-02-10 01:10:30 +00:00
Point2 points [ 4 ] ;
2017-01-11 03:52:51 +00:00
Transform2D xform = get_global_transform ( ) ;
2014-02-10 01:10:30 +00:00
Rect2 rect = get_item_rect ( ) ;
2017-06-03 22:25:13 +00:00
points [ 0 ] = xform . xform ( rect . position ) ;
points [ 1 ] = xform . xform ( rect . position + Point2 ( rect . size . x , 0 ) ) ;
points [ 2 ] = xform . xform ( rect . position + rect . size ) ;
points [ 3 ] = xform . xform ( rect . position + Point2 ( 0 , rect . size . y ) ) ;
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
const Vector2 dir [ 4 ] = {
Vector2 ( - 1 , 0 ) ,
Vector2 ( 0 , - 1 ) ,
Vector2 ( 1 , 0 ) ,
Vector2 ( 0 , 1 )
2014-02-10 01:10:30 +00:00
} ;
2017-03-05 15:44:50 +00:00
Vector2 vdir = dir [ p_margin ] ;
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
float maxd = - 1e7 ;
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
for ( int i = 0 ; i < 4 ; i + + ) {
2014-02-10 01:10:30 +00:00
float d = vdir . dot ( points [ i ] ) ;
2017-03-05 15:44:50 +00:00
if ( d > maxd )
maxd = d ;
2014-02-10 01:10:30 +00:00
}
2017-03-05 15:44:50 +00:00
Node * base = this ;
2014-02-10 01:10:30 +00:00
while ( base ) {
Control * c = base - > cast_to < Control > ( ) ;
if ( c ) {
if ( c - > data . SI )
break ;
2016-01-17 01:41:10 +00:00
if ( c - > data . RI )
2014-02-10 01:10:30 +00:00
break ;
}
2017-03-05 15:44:50 +00:00
base = base - > get_parent ( ) ;
2014-02-10 01:10:30 +00:00
}
if ( ! base )
return NULL ;
2017-03-05 15:44:50 +00:00
_window_find_focus_neighbour ( vdir , base , points , maxd , dist , & result ) ;
2014-02-10 01:10:30 +00:00
return result ;
}
2017-03-05 15:44:50 +00:00
void Control : : _window_find_focus_neighbour ( const Vector2 & p_dir , Node * p_at , const Point2 * p_points , float p_min , float & r_closest_dist , Control * * r_closest ) {
2014-02-10 01:10:30 +00:00
if ( p_at - > cast_to < Viewport > ( ) )
return ; //bye
Control * c = p_at - > cast_to < Control > ( ) ;
2017-03-05 15:44:50 +00:00
if ( c & & c ! = this & & c - > get_focus_mode ( ) = = FOCUS_ALL & & c - > is_visible_in_tree ( ) ) {
2014-02-10 01:10:30 +00:00
Point2 points [ 4 ] ;
2017-01-11 03:52:51 +00:00
Transform2D xform = c - > get_global_transform ( ) ;
2014-02-10 01:10:30 +00:00
Rect2 rect = c - > get_item_rect ( ) ;
2017-06-03 22:25:13 +00:00
points [ 0 ] = xform . xform ( rect . position ) ;
points [ 1 ] = xform . xform ( rect . position + Point2 ( rect . size . x , 0 ) ) ;
points [ 2 ] = xform . xform ( rect . position + rect . size ) ;
points [ 3 ] = xform . xform ( rect . position + Point2 ( 0 , rect . size . y ) ) ;
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
float min = 1e7 ;
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
for ( int i = 0 ; i < 4 ; i + + ) {
2014-02-10 01:10:30 +00:00
float d = p_dir . dot ( points [ i ] ) ;
if ( d < min )
2017-03-05 15:44:50 +00:00
min = d ;
2014-02-10 01:10:30 +00:00
}
2017-03-05 15:44:50 +00:00
if ( min > ( p_min - CMP_EPSILON ) ) {
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
for ( int i = 0 ; i < 4 ; i + + ) {
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
Vector2 la = p_points [ i ] ;
Vector2 lb = p_points [ ( i + 1 ) % 4 ] ;
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
for ( int j = 0 ; j < 4 ; j + + ) {
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
Vector2 fa = points [ j ] ;
Vector2 fb = points [ ( j + 1 ) % 4 ] ;
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
Vector2 pa , pb ;
float d = Geometry : : get_closest_points_between_segments ( la , lb , fa , fb , pa , pb ) ;
2014-02-10 01:10:30 +00:00
//float d = Geometry::get_closest_distance_between_segments(Vector3(la.x,la.y,0),Vector3(lb.x,lb.y,0),Vector3(fa.x,fa.y,0),Vector3(fb.x,fb.y,0));
2017-03-05 15:44:50 +00:00
if ( d < r_closest_dist ) {
r_closest_dist = d ;
* r_closest = c ;
2014-02-10 01:10:30 +00:00
}
}
}
}
}
2017-03-05 15:44:50 +00:00
for ( int i = 0 ; i < p_at - > get_child_count ( ) ; i + + ) {
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
Node * child = p_at - > get_child ( i ) ;
2014-02-10 01:10:30 +00:00
Control * childc = child - > cast_to < Control > ( ) ;
if ( childc & & childc - > data . SI )
continue ; //subwindow, ignore
2017-03-05 15:44:50 +00:00
_window_find_focus_neighbour ( p_dir , p_at - > get_child ( i ) , p_points , p_min , r_closest_dist , r_closest ) ;
2014-02-10 01:10:30 +00:00
}
}
void Control : : set_h_size_flags ( int p_flags ) {
2017-03-05 15:44:50 +00:00
if ( data . h_size_flags = = p_flags )
2014-02-10 01:10:30 +00:00
return ;
2017-03-05 15:44:50 +00:00
data . h_size_flags = p_flags ;
2014-02-10 01:10:30 +00:00
emit_signal ( SceneStringNames : : get_singleton ( ) - > size_flags_changed ) ;
}
2017-03-05 15:44:50 +00:00
int Control : : get_h_size_flags ( ) const {
2014-02-10 01:10:30 +00:00
return data . h_size_flags ;
}
void Control : : set_v_size_flags ( int p_flags ) {
2017-03-05 15:44:50 +00:00
if ( data . v_size_flags = = p_flags )
2014-02-10 01:10:30 +00:00
return ;
2017-03-05 15:44:50 +00:00
data . v_size_flags = p_flags ;
2014-02-10 01:10:30 +00:00
emit_signal ( SceneStringNames : : get_singleton ( ) - > size_flags_changed ) ;
}
void Control : : set_stretch_ratio ( float p_ratio ) {
2017-03-05 15:44:50 +00:00
if ( data . expand = = p_ratio )
2014-02-10 01:10:30 +00:00
return ;
2017-03-05 15:44:50 +00:00
data . expand = p_ratio ;
2014-02-10 01:10:30 +00:00
emit_signal ( SceneStringNames : : get_singleton ( ) - > size_flags_changed ) ;
}
float Control : : get_stretch_ratio ( ) const {
return data . expand ;
}
void Control : : grab_click_focus ( ) {
2014-11-06 00:20:42 +00:00
ERR_FAIL_COND ( ! is_inside_tree ( ) ) ;
2014-02-10 01:10:30 +00:00
2016-01-17 01:41:10 +00:00
get_viewport ( ) - > _gui_grab_click_focus ( this ) ;
2014-02-10 01:10:30 +00:00
}
void Control : : minimum_size_changed ( ) {
2016-08-25 20:45:20 +00:00
if ( ! is_inside_tree ( ) | | data . block_minimum_size_adjust )
2014-02-10 01:10:30 +00:00
return ;
if ( data . pending_min_size_update )
return ;
2017-03-05 15:44:50 +00:00
data . pending_min_size_update = true ;
MessageQueue : : get_singleton ( ) - > push_call ( this , " _update_minimum_size " ) ;
2014-02-10 01:10:30 +00:00
if ( ! is_toplevel_control ( ) ) {
Control * pc = get_parent_control ( ) ;
if ( pc )
pc - > minimum_size_changed ( ) ;
}
}
2017-03-05 15:44:50 +00:00
int Control : : get_v_size_flags ( ) const {
2014-02-10 01:10:30 +00:00
return data . v_size_flags ;
}
2017-01-08 22:54:19 +00:00
void Control : : set_mouse_filter ( MouseFilter p_filter ) {
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
ERR_FAIL_INDEX ( p_filter , 3 ) ;
data . mouse_filter = p_filter ;
2014-02-10 01:10:30 +00:00
}
2017-03-05 15:44:50 +00:00
Control : : MouseFilter Control : : get_mouse_filter ( ) const {
2014-02-10 01:10:30 +00:00
2017-01-08 22:54:19 +00:00
return data . mouse_filter ;
2014-02-10 01:10:30 +00:00
}
Control * Control : : get_focus_owner ( ) const {
2017-03-05 15:44:50 +00:00
ERR_FAIL_COND_V ( ! is_inside_tree ( ) , NULL ) ;
2016-01-17 01:41:10 +00:00
return get_viewport ( ) - > _gui_get_focus_owner ( ) ;
2014-02-10 01:10:30 +00:00
}
2017-03-05 15:44:50 +00:00
void Control : : warp_mouse ( const Point2 & p_to_pos ) {
2015-02-14 22:22:06 +00:00
ERR_FAIL_COND ( ! is_inside_tree ( ) ) ;
get_viewport ( ) - > warp_mouse ( get_global_transform ( ) . xform ( p_to_pos ) ) ;
}
2015-10-17 13:29:54 +00:00
bool Control : : is_text_field ( ) const {
2017-03-05 15:44:50 +00:00
/*
2015-10-17 13:29:54 +00:00
if ( get_script_instance ( ) ) {
Variant v = p_point ;
const Variant * p [ 2 ] = { & v , & p_data } ;
Variant : : CallError ce ;
Variant ret = get_script_instance ( ) - > call ( " is_text_field " , p , 2 , ce ) ;
if ( ce . error = = Variant : : CallError : : CALL_OK )
return ret ;
}
*/
2017-03-05 15:44:50 +00:00
return false ;
2015-10-17 13:29:54 +00:00
}
2016-05-06 21:38:08 +00:00
void Control : : set_rotation ( float p_radians ) {
2015-12-12 16:54:26 +00:00
2017-03-05 15:44:50 +00:00
data . rotation = p_radians ;
2015-12-12 16:54:26 +00:00
update ( ) ;
_notify_transform ( ) ;
2017-04-03 16:34:44 +00:00
_change_notify ( " rect_rotation " ) ;
2015-12-12 16:54:26 +00:00
}
2017-03-05 15:44:50 +00:00
float Control : : get_rotation ( ) const {
2015-12-12 16:54:26 +00:00
return data . rotation ;
}
2016-05-06 21:38:08 +00:00
void Control : : set_rotation_deg ( float p_degrees ) {
set_rotation ( Math : : deg2rad ( p_degrees ) ) ;
}
float Control : : get_rotation_deg ( ) const {
return Math : : rad2deg ( get_rotation ( ) ) ;
}
// Kept for compatibility after rename to {s,g}et_rotation_deg.
// Could be removed after a couple releases.
void Control : : _set_rotation_deg ( float p_degrees ) {
WARN_PRINT ( " Deprecated method Control._set_rotation_deg(): This method was renamed to set_rotation_deg. Please adapt your code accordingly, as the old method will be obsoleted. " ) ;
set_rotation_deg ( p_degrees ) ;
}
float Control : : _get_rotation_deg ( ) const {
WARN_PRINT ( " Deprecated method Control._get_rotation_deg(): This method was renamed to get_rotation_deg. Please adapt your code accordingly, as the old method will be obsoleted. " ) ;
return get_rotation_deg ( ) ;
}
2016-06-17 19:00:27 +00:00
//needed to update the control if the font changes..
2017-03-05 15:44:50 +00:00
void Control : : _ref_font ( Ref < Font > p_sc ) {
2016-06-17 19:00:27 +00:00
if ( ! data . font_refcount . has ( p_sc ) ) {
2017-03-05 15:44:50 +00:00
data . font_refcount [ p_sc ] = 1 ;
p_sc - > connect ( " changed " , this , " _font_changed " ) ;
2016-06-17 19:00:27 +00:00
} else {
2017-03-05 15:44:50 +00:00
data . font_refcount [ p_sc ] + = 1 ;
2016-06-17 19:00:27 +00:00
}
}
2016-06-17 19:40:40 +00:00
void Control : : _unref_font ( Ref < Font > p_sc ) {
2016-06-17 19:00:27 +00:00
ERR_FAIL_COND ( ! data . font_refcount . has ( p_sc ) ) ;
data . font_refcount [ p_sc ] - - ;
2017-03-05 15:44:50 +00:00
if ( data . font_refcount [ p_sc ] = = 0 ) {
p_sc - > disconnect ( " changed " , this , " _font_changed " ) ;
2016-06-17 19:00:27 +00:00
data . font_refcount . erase ( p_sc ) ;
}
}
2017-03-05 15:44:50 +00:00
void Control : : _font_changed ( ) {
2016-06-17 19:00:27 +00:00
update ( ) ;
notification ( NOTIFICATION_THEME_CHANGED ) ;
minimum_size_changed ( ) ; //fonts affect minimum size pretty much almost always
}
2016-05-06 21:38:08 +00:00
2017-07-06 20:42:44 +00:00
void Control : : set_pivot_offset ( const Vector2 & p_pivot ) {
data . pivot_offset = p_pivot ;
update ( ) ;
_notify_transform ( ) ;
_change_notify ( " rect_pivot_offset " ) ;
}
Vector2 Control : : get_pivot_offset ( ) const {
return data . pivot_offset ;
}
2017-03-05 15:44:50 +00:00
void Control : : set_scale ( const Vector2 & p_scale ) {
2015-12-12 16:54:26 +00:00
2017-03-05 15:44:50 +00:00
data . scale = p_scale ;
2015-12-12 16:54:26 +00:00
update ( ) ;
_notify_transform ( ) ;
}
2017-03-05 15:44:50 +00:00
Vector2 Control : : get_scale ( ) const {
2015-12-12 16:54:26 +00:00
return data . scale ;
}
2016-01-19 23:27:27 +00:00
Control * Control : : get_root_parent_control ( ) const {
2017-03-05 15:44:50 +00:00
const CanvasItem * ci = this ;
const Control * root = this ;
2016-01-19 23:27:27 +00:00
2017-03-05 15:44:50 +00:00
while ( ci ) {
2016-01-19 23:27:27 +00:00
const Control * c = ci - > cast_to < Control > ( ) ;
if ( c ) {
2017-03-05 15:44:50 +00:00
root = c ;
2016-01-19 23:27:27 +00:00
if ( c - > data . RI | | c - > data . MI | | c - > is_toplevel_control ( ) )
break ;
}
2017-03-05 15:44:50 +00:00
ci = ci - > get_parent_item ( ) ;
2016-01-19 23:27:27 +00:00
}
2017-03-05 15:44:50 +00:00
return const_cast < Control * > ( root ) ;
2016-01-19 23:27:27 +00:00
}
2015-12-12 16:54:26 +00:00
2016-08-25 20:45:20 +00:00
void Control : : set_block_minimum_size_adjust ( bool p_block ) {
2017-03-05 15:44:50 +00:00
data . block_minimum_size_adjust = p_block ;
2016-08-25 20:45:20 +00:00
}
2016-01-24 13:57:42 +00:00
2016-08-25 20:45:20 +00:00
bool Control : : is_minimum_size_adjust_blocked ( ) const {
2016-01-24 13:57:42 +00:00
2016-08-25 20:45:20 +00:00
return data . block_minimum_size_adjust ;
}
2016-08-31 02:44:14 +00:00
void Control : : set_disable_visibility_clip ( bool p_ignore ) {
2017-03-05 15:44:50 +00:00
data . disable_visibility_clip = p_ignore ;
2016-08-31 02:44:14 +00:00
update ( ) ;
}
bool Control : : is_visibility_clip_disabled ( ) const {
return data . disable_visibility_clip ;
}
2017-03-05 15:44:50 +00:00
void Control : : get_argument_options ( const StringName & p_function , int p_idx , List < String > * r_options ) const {
2016-09-11 14:48:31 +00:00
2017-03-05 15:44:50 +00:00
Node : : get_argument_options ( p_function , p_idx , r_options ) ;
2016-09-11 14:48:31 +00:00
2017-03-05 15:44:50 +00:00
if ( p_idx = = 0 ) {
2016-09-11 14:48:31 +00:00
List < StringName > sn ;
String pf = p_function ;
2017-03-05 15:44:50 +00:00
if ( pf = = " add_color_override " | | pf = = " has_color " | | pf = = " has_color_override " | | pf = = " get_color " ) {
Theme : : get_default ( ) - > get_color_list ( get_class ( ) , & sn ) ;
} else if ( pf = = " add_style_override " | | pf = = " has_style " | | pf = = " has_style_override " | | pf = = " get_style " ) {
Theme : : get_default ( ) - > get_stylebox_list ( get_class ( ) , & sn ) ;
} else if ( pf = = " add_font_override " | | pf = = " has_font " | | pf = = " has_font_override " | | pf = = " get_font " ) {
Theme : : get_default ( ) - > get_font_list ( get_class ( ) , & sn ) ;
} else if ( pf = = " add_constant_override " | | pf = = " has_constant " | | pf = = " has_constant_override " | | pf = = " get_constant " ) {
Theme : : get_default ( ) - > get_constant_list ( get_class ( ) , & sn ) ;
2016-09-11 14:48:31 +00:00
}
sn . sort_custom < StringName : : AlphCompare > ( ) ;
2017-03-05 15:44:50 +00:00
for ( List < StringName > : : Element * E = sn . front ( ) ; E ; E = E - > next ( ) ) {
r_options - > push_back ( " \" " + E - > get ( ) + " \" " ) ;
2016-09-11 14:48:31 +00:00
}
}
}
2017-01-09 18:50:08 +00:00
void Control : : set_clip_contents ( bool p_clip ) {
2017-03-05 15:44:50 +00:00
data . clip_contents = p_clip ;
2017-01-09 18:50:08 +00:00
update ( ) ;
}
bool Control : : is_clipping_contents ( ) {
return data . clip_contents ;
}
2016-09-11 14:48:31 +00:00
2017-07-06 16:26:39 +00:00
void Control : : set_h_grow_direction ( GrowDirection p_direction ) {
data . h_grow = p_direction ;
_size_changed ( ) ;
}
Control : : GrowDirection Control : : get_h_grow_direction ( ) const {
return data . h_grow ;
}
void Control : : set_v_grow_direction ( GrowDirection p_direction ) {
data . v_grow = p_direction ;
_size_changed ( ) ;
}
Control : : GrowDirection Control : : get_v_grow_direction ( ) const {
return data . v_grow ;
}
2014-02-10 01:10:30 +00:00
void Control : : _bind_methods ( ) {
2017-02-13 11:47:24 +00:00
//ClassDB::bind_method(D_METHOD("_window_resize_event"),&Control::_window_resize_event);
2017-03-05 15:44:50 +00:00
ClassDB : : bind_method ( D_METHOD ( " _size_changed " ) , & Control : : _size_changed ) ;
ClassDB : : bind_method ( D_METHOD ( " _update_minimum_size " ) , & Control : : _update_minimum_size ) ;
ClassDB : : bind_method ( D_METHOD ( " accept_event " ) , & Control : : accept_event ) ;
ClassDB : : bind_method ( D_METHOD ( " get_minimum_size " ) , & Control : : get_minimum_size ) ;
ClassDB : : bind_method ( D_METHOD ( " get_combined_minimum_size " ) , & Control : : get_combined_minimum_size ) ;
ClassDB : : bind_method ( D_METHOD ( " set_anchor " , " margin " , " anchor_mode " , " keep_margin " ) , & Control : : set_anchor , DEFVAL ( false ) ) ;
ClassDB : : bind_method ( D_METHOD ( " _set_anchor " , " margin " , " anchor_mode " ) , & Control : : _set_anchor ) ;
ClassDB : : bind_method ( D_METHOD ( " get_anchor " , " margin " ) , & Control : : get_anchor ) ;
ClassDB : : bind_method ( D_METHOD ( " set_margin " , " margin " , " offset " ) , & Control : : set_margin ) ;
ClassDB : : bind_method ( D_METHOD ( " set_anchor_and_margin " , " margin " , " anchor_mode " , " offset " ) , & Control : : set_anchor_and_margin ) ;
ClassDB : : bind_method ( D_METHOD ( " set_begin " , " pos " ) , & Control : : set_begin ) ;
ClassDB : : bind_method ( D_METHOD ( " set_end " , " pos " ) , & Control : : set_end ) ;
2017-03-29 15:29:38 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_position " , " pos " ) , & Control : : set_position ) ;
2017-03-05 15:44:50 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_size " , " size " ) , & Control : : set_size ) ;
ClassDB : : bind_method ( D_METHOD ( " set_custom_minimum_size " , " size " ) , & Control : : set_custom_minimum_size ) ;
2017-03-29 15:29:38 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_global_position " , " pos " ) , & Control : : set_global_position ) ;
2017-03-05 15:44:50 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_rotation " , " radians " ) , & Control : : set_rotation ) ;
ClassDB : : bind_method ( D_METHOD ( " set_rotation_deg " , " degrees " ) , & Control : : set_rotation_deg ) ;
2016-05-06 21:38:08 +00:00
// TODO: Obsolete this method (old name) properly (GH-4397)
2017-03-05 15:44:50 +00:00
ClassDB : : bind_method ( D_METHOD ( " _set_rotation_deg " , " degrees " ) , & Control : : _set_rotation_deg ) ;
ClassDB : : bind_method ( D_METHOD ( " set_scale " , " scale " ) , & Control : : set_scale ) ;
2017-07-06 20:42:44 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_pivot_offset " , " pivot_offset " ) , & Control : : set_pivot_offset ) ;
2017-03-05 15:44:50 +00:00
ClassDB : : bind_method ( D_METHOD ( " get_margin " , " margin " ) , & Control : : get_margin ) ;
ClassDB : : bind_method ( D_METHOD ( " get_begin " ) , & Control : : get_begin ) ;
ClassDB : : bind_method ( D_METHOD ( " get_end " ) , & Control : : get_end ) ;
2017-03-29 15:29:38 +00:00
ClassDB : : bind_method ( D_METHOD ( " get_position " ) , & Control : : get_position ) ;
2017-03-05 15:44:50 +00:00
ClassDB : : bind_method ( D_METHOD ( " get_size " ) , & Control : : get_size ) ;
ClassDB : : bind_method ( D_METHOD ( " get_rotation " ) , & Control : : get_rotation ) ;
ClassDB : : bind_method ( D_METHOD ( " get_rotation_deg " ) , & Control : : get_rotation_deg ) ;
2016-05-06 21:38:08 +00:00
// TODO: Obsolete this method (old name) properly (GH-4397)
2017-03-05 15:44:50 +00:00
ClassDB : : bind_method ( D_METHOD ( " _get_rotation_deg " ) , & Control : : _get_rotation_deg ) ;
ClassDB : : bind_method ( D_METHOD ( " get_scale " ) , & Control : : get_scale ) ;
2017-07-06 20:42:44 +00:00
ClassDB : : bind_method ( D_METHOD ( " get_pivot_offset " ) , & Control : : get_pivot_offset ) ;
2017-03-05 15:44:50 +00:00
ClassDB : : bind_method ( D_METHOD ( " get_custom_minimum_size " ) , & Control : : get_custom_minimum_size ) ;
ClassDB : : bind_method ( D_METHOD ( " get_parent_area_size " ) , & Control : : get_size ) ;
2017-03-29 15:29:38 +00:00
ClassDB : : bind_method ( D_METHOD ( " get_global_position " ) , & Control : : get_global_position ) ;
2017-03-05 15:44:50 +00:00
ClassDB : : bind_method ( D_METHOD ( " get_rect " ) , & Control : : get_rect ) ;
ClassDB : : bind_method ( D_METHOD ( " get_global_rect " ) , & Control : : get_global_rect ) ;
ClassDB : : bind_method ( D_METHOD ( " set_area_as_parent_rect " , " margin " ) , & Control : : set_area_as_parent_rect , DEFVAL ( 0 ) ) ;
ClassDB : : bind_method ( D_METHOD ( " show_modal " , " exclusive " ) , & Control : : show_modal , DEFVAL ( false ) ) ;
ClassDB : : bind_method ( D_METHOD ( " set_focus_mode " , " mode " ) , & Control : : set_focus_mode ) ;
ClassDB : : bind_method ( D_METHOD ( " get_focus_mode " ) , & Control : : get_focus_mode ) ;
ClassDB : : bind_method ( D_METHOD ( " has_focus " ) , & Control : : has_focus ) ;
ClassDB : : bind_method ( D_METHOD ( " grab_focus " ) , & Control : : grab_focus ) ;
ClassDB : : bind_method ( D_METHOD ( " release_focus " ) , & Control : : release_focus ) ;
ClassDB : : bind_method ( D_METHOD ( " get_focus_owner:Control " ) , & Control : : get_focus_owner ) ;
ClassDB : : bind_method ( D_METHOD ( " set_h_size_flags " , " flags " ) , & Control : : set_h_size_flags ) ;
ClassDB : : bind_method ( D_METHOD ( " get_h_size_flags " ) , & Control : : get_h_size_flags ) ;
ClassDB : : bind_method ( D_METHOD ( " set_stretch_ratio " , " ratio " ) , & Control : : set_stretch_ratio ) ;
ClassDB : : bind_method ( D_METHOD ( " get_stretch_ratio " ) , & Control : : get_stretch_ratio ) ;
ClassDB : : bind_method ( D_METHOD ( " set_v_size_flags " , " flags " ) , & Control : : set_v_size_flags ) ;
ClassDB : : bind_method ( D_METHOD ( " get_v_size_flags " ) , & Control : : get_v_size_flags ) ;
ClassDB : : bind_method ( D_METHOD ( " set_theme " , " theme:Theme " ) , & Control : : set_theme ) ;
ClassDB : : bind_method ( D_METHOD ( " get_theme:Theme " ) , & Control : : get_theme ) ;
ClassDB : : bind_method ( D_METHOD ( " add_icon_override " , " name " , " texture:Texture " ) , & Control : : add_icon_override ) ;
ClassDB : : bind_method ( D_METHOD ( " add_shader_override " , " name " , " shader:Shader " ) , & Control : : add_shader_override ) ;
ClassDB : : bind_method ( D_METHOD ( " add_style_override " , " name " , " stylebox:StyleBox " ) , & Control : : add_style_override ) ;
ClassDB : : bind_method ( D_METHOD ( " add_font_override " , " name " , " font:Font " ) , & Control : : add_font_override ) ;
ClassDB : : bind_method ( D_METHOD ( " add_color_override " , " name " , " color " ) , & Control : : add_color_override ) ;
ClassDB : : bind_method ( D_METHOD ( " add_constant_override " , " name " , " constant " ) , & Control : : add_constant_override ) ;
ClassDB : : bind_method ( D_METHOD ( " get_icon:Texture " , " name " , " type " ) , & Control : : get_icon , DEFVAL ( " " ) ) ;
ClassDB : : bind_method ( D_METHOD ( " get_stylebox:StyleBox " , " name " , " type " ) , & Control : : get_stylebox , DEFVAL ( " " ) ) ;
ClassDB : : bind_method ( D_METHOD ( " get_font:Font " , " name " , " type " ) , & Control : : get_font , DEFVAL ( " " ) ) ;
ClassDB : : bind_method ( D_METHOD ( " get_color " , " name " , " type " ) , & Control : : get_color , DEFVAL ( " " ) ) ;
ClassDB : : bind_method ( D_METHOD ( " get_constant " , " name " , " type " ) , & Control : : get_constant , DEFVAL ( " " ) ) ;
2014-02-10 01:10:30 +00:00
2017-02-13 11:47:24 +00:00
ClassDB : : bind_method ( D_METHOD ( " has_icon_override " , " name " ) , & Control : : has_icon_override ) ;
ClassDB : : bind_method ( D_METHOD ( " has_stylebox_override " , " name " ) , & Control : : has_stylebox_override ) ;
ClassDB : : bind_method ( D_METHOD ( " has_font_override " , " name " ) , & Control : : has_font_override ) ;
ClassDB : : bind_method ( D_METHOD ( " has_color_override " , " name " ) , & Control : : has_color_override ) ;
ClassDB : : bind_method ( D_METHOD ( " has_constant_override " , " name " ) , & Control : : has_constant_override ) ;
2016-06-01 14:41:25 +00:00
2017-02-13 11:47:24 +00:00
ClassDB : : bind_method ( D_METHOD ( " has_icon " , " name " , " type " ) , & Control : : has_icon , DEFVAL ( " " ) ) ;
ClassDB : : bind_method ( D_METHOD ( " has_stylebox " , " name " , " type " ) , & Control : : has_stylebox , DEFVAL ( " " ) ) ;
ClassDB : : bind_method ( D_METHOD ( " has_font " , " name " , " type " ) , & Control : : has_font , DEFVAL ( " " ) ) ;
ClassDB : : bind_method ( D_METHOD ( " has_color " , " name " , " type " ) , & Control : : has_color , DEFVAL ( " " ) ) ;
ClassDB : : bind_method ( D_METHOD ( " has_constant " , " name " , " type " ) , & Control : : has_constant , DEFVAL ( " " ) ) ;
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
ClassDB : : bind_method ( D_METHOD ( " get_parent_control:Control " ) , & Control : : get_parent_control ) ;
2014-02-10 01:10:30 +00:00
2017-07-06 16:26:39 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_h_grow_direction " , " direction " ) , & Control : : set_h_grow_direction ) ;
ClassDB : : bind_method ( D_METHOD ( " get_h_grow_direction " ) , & Control : : get_h_grow_direction ) ;
ClassDB : : bind_method ( D_METHOD ( " set_v_grow_direction " , " direction " ) , & Control : : set_v_grow_direction ) ;
ClassDB : : bind_method ( D_METHOD ( " get_v_grow_direction " ) , & Control : : get_v_grow_direction ) ;
2017-03-05 15:44:50 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_tooltip " , " tooltip " ) , & Control : : set_tooltip ) ;
ClassDB : : bind_method ( D_METHOD ( " get_tooltip " , " atpos " ) , & Control : : get_tooltip , DEFVAL ( Point2 ( ) ) ) ;
ClassDB : : bind_method ( D_METHOD ( " _get_tooltip " ) , & Control : : _get_tooltip ) ;
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_default_cursor_shape " , " shape " ) , & Control : : set_default_cursor_shape ) ;
ClassDB : : bind_method ( D_METHOD ( " get_default_cursor_shape " ) , & Control : : get_default_cursor_shape ) ;
ClassDB : : bind_method ( D_METHOD ( " get_cursor_shape " , " pos " ) , & Control : : get_cursor_shape , DEFVAL ( Point2 ( ) ) ) ;
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_focus_neighbour " , " margin " , " neighbour " ) , & Control : : set_focus_neighbour ) ;
ClassDB : : bind_method ( D_METHOD ( " get_focus_neighbour " , " margin " ) , & Control : : get_focus_neighbour ) ;
2014-02-10 01:10:30 +00:00
2017-07-18 19:03:34 +00:00
ClassDB : : bind_method ( D_METHOD ( " force_drag " , " data " , " preview:Control " ) , & Control : : force_drag ) ;
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_mouse_filter " , " filter " ) , & Control : : set_mouse_filter ) ;
ClassDB : : bind_method ( D_METHOD ( " get_mouse_filter " ) , & Control : : get_mouse_filter ) ;
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_clip_contents " , " enable " ) , & Control : : set_clip_contents ) ;
ClassDB : : bind_method ( D_METHOD ( " is_clipping_contents " ) , & Control : : is_clipping_contents ) ;
2017-01-09 18:50:08 +00:00
2017-03-05 15:44:50 +00:00
ClassDB : : bind_method ( D_METHOD ( " grab_click_focus " ) , & Control : : grab_click_focus ) ;
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_drag_forwarding " , " target:Control " ) , & Control : : set_drag_forwarding ) ;
ClassDB : : bind_method ( D_METHOD ( " set_drag_preview " , " control:Control " ) , & Control : : set_drag_preview ) ;
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
ClassDB : : bind_method ( D_METHOD ( " warp_mouse " , " to_pos " ) , & Control : : warp_mouse ) ;
2015-02-14 22:22:06 +00:00
2017-02-13 11:47:24 +00:00
ClassDB : : bind_method ( D_METHOD ( " minimum_size_changed " ) , & Control : : minimum_size_changed ) ;
2015-02-14 22:22:06 +00:00
2017-02-13 11:47:24 +00:00
ClassDB : : bind_method ( D_METHOD ( " _theme_changed " ) , & Control : : _theme_changed ) ;
2016-07-18 19:41:28 +00:00
2017-02-13 11:47:24 +00:00
ClassDB : : bind_method ( D_METHOD ( " _font_changed " ) , & Control : : _font_changed ) ;
2016-06-17 19:00:27 +00:00
2017-05-20 15:38:03 +00:00
BIND_VMETHOD ( MethodInfo ( " _gui_input " , PropertyInfo ( Variant : : OBJECT , " event " , PROPERTY_HINT_RESOURCE_TYPE , " InputEvent " ) ) ) ;
2017-03-13 15:45:27 +00:00
BIND_VMETHOD ( MethodInfo ( Variant : : VECTOR2 , " _get_minimum_size " ) ) ;
2017-03-05 15:44:50 +00:00
BIND_VMETHOD ( MethodInfo ( Variant : : OBJECT , " get_drag_data " , PropertyInfo ( Variant : : VECTOR2 , " pos " ) ) ) ;
BIND_VMETHOD ( MethodInfo ( Variant : : BOOL , " can_drop_data " , PropertyInfo ( Variant : : VECTOR2 , " pos " ) , PropertyInfo ( Variant : : NIL , " data " ) ) ) ;
BIND_VMETHOD ( MethodInfo ( " drop_data " , PropertyInfo ( Variant : : VECTOR2 , " pos " ) , PropertyInfo ( Variant : : NIL , " data " ) ) ) ;
ADD_GROUP ( " Anchor " , " anchor_ " ) ;
ADD_PROPERTYINZ ( PropertyInfo ( Variant : : INT , " anchor_left " , PROPERTY_HINT_ENUM , " Begin,End,Center " ) , " _set_anchor " , " get_anchor " , MARGIN_LEFT ) ;
ADD_PROPERTYINZ ( PropertyInfo ( Variant : : INT , " anchor_top " , PROPERTY_HINT_ENUM , " Begin,End,Center " ) , " _set_anchor " , " get_anchor " , MARGIN_TOP ) ;
ADD_PROPERTYINZ ( PropertyInfo ( Variant : : INT , " anchor_right " , PROPERTY_HINT_ENUM , " Begin,End,Center " ) , " _set_anchor " , " get_anchor " , MARGIN_RIGHT ) ;
ADD_PROPERTYINZ ( PropertyInfo ( Variant : : INT , " anchor_bottom " , PROPERTY_HINT_ENUM , " Begin,End,Center " ) , " _set_anchor " , " get_anchor " , MARGIN_BOTTOM ) ;
ADD_GROUP ( " Margin " , " margin_ " ) ;
ADD_PROPERTYINZ ( PropertyInfo ( Variant : : INT , " margin_left " , PROPERTY_HINT_RANGE , " -4096,4096 " ) , " set_margin " , " get_margin " , MARGIN_LEFT ) ;
ADD_PROPERTYINZ ( PropertyInfo ( Variant : : INT , " margin_top " , PROPERTY_HINT_RANGE , " -4096,4096 " ) , " set_margin " , " get_margin " , MARGIN_TOP ) ;
ADD_PROPERTYINZ ( PropertyInfo ( Variant : : INT , " margin_right " , PROPERTY_HINT_RANGE , " -4096,4096 " ) , " set_margin " , " get_margin " , MARGIN_RIGHT ) ;
ADD_PROPERTYINZ ( PropertyInfo ( Variant : : INT , " margin_bottom " , PROPERTY_HINT_RANGE , " -4096,4096 " ) , " set_margin " , " get_margin " , MARGIN_BOTTOM ) ;
2017-07-06 16:26:39 +00:00
ADD_GROUP ( " Grow Direction " , " grow_ " ) ;
ADD_PROPERTYNO ( PropertyInfo ( Variant : : INT , " grow_horizontal " , PROPERTY_HINT_ENUM , " Begin,End " ) , " set_h_grow_direction " , " get_h_grow_direction " ) ;
ADD_PROPERTYNO ( PropertyInfo ( Variant : : INT , " grow_vertical " , PROPERTY_HINT_ENUM , " Begin,End " ) , " set_v_grow_direction " , " get_v_grow_direction " ) ;
2017-03-05 15:44:50 +00:00
ADD_GROUP ( " Rect " , " rect_ " ) ;
2017-03-29 15:29:38 +00:00
ADD_PROPERTYNZ ( PropertyInfo ( Variant : : VECTOR2 , " rect_position " , PROPERTY_HINT_NONE , " " , PROPERTY_USAGE_EDITOR ) , " set_position " , " get_position " ) ;
2017-03-05 15:44:50 +00:00
ADD_PROPERTYNZ ( PropertyInfo ( Variant : : VECTOR2 , " rect_size " , PROPERTY_HINT_NONE , " " , PROPERTY_USAGE_EDITOR ) , " set_size " , " get_size " ) ;
ADD_PROPERTYNZ ( PropertyInfo ( Variant : : VECTOR2 , " rect_min_size " ) , " set_custom_minimum_size " , " get_custom_minimum_size " ) ;
ADD_PROPERTYNZ ( PropertyInfo ( Variant : : REAL , " rect_rotation " , PROPERTY_HINT_RANGE , " -1080,1080,0.01 " ) , " set_rotation_deg " , " get_rotation_deg " ) ;
ADD_PROPERTYNO ( PropertyInfo ( Variant : : VECTOR2 , " rect_scale " ) , " set_scale " , " get_scale " ) ;
2017-07-06 20:42:44 +00:00
ADD_PROPERTYNO ( PropertyInfo ( Variant : : VECTOR2 , " rect_pivot_offset " ) , " set_pivot_offset " , " get_pivot_offset " ) ;
2017-03-05 15:44:50 +00:00
ADD_PROPERTYNO ( PropertyInfo ( Variant : : BOOL , " rect_clip_content " ) , " set_clip_contents " , " is_clipping_contents " ) ;
ADD_GROUP ( " Hint " , " hint_ " ) ;
ADD_PROPERTYNZ ( PropertyInfo ( Variant : : STRING , " hint_tooltip " , PROPERTY_HINT_MULTILINE_TEXT ) , " set_tooltip " , " _get_tooltip " ) ;
ADD_GROUP ( " Focus " , " focus_ " ) ;
ADD_PROPERTYINZ ( PropertyInfo ( Variant : : NODE_PATH , " focus_neighbour_left " ) , " set_focus_neighbour " , " get_focus_neighbour " , MARGIN_LEFT ) ;
ADD_PROPERTYINZ ( PropertyInfo ( Variant : : NODE_PATH , " focus_neighbour_top " ) , " set_focus_neighbour " , " get_focus_neighbour " , MARGIN_TOP ) ;
ADD_PROPERTYINZ ( PropertyInfo ( Variant : : NODE_PATH , " focus_neighbour_right " ) , " set_focus_neighbour " , " get_focus_neighbour " , MARGIN_RIGHT ) ;
ADD_PROPERTYINZ ( PropertyInfo ( Variant : : NODE_PATH , " focus_neighbour_bottom " ) , " set_focus_neighbour " , " get_focus_neighbour " , MARGIN_BOTTOM ) ;
ADD_GROUP ( " Mouse " , " mouse_ " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " mouse_filter " , PROPERTY_HINT_ENUM , " Stop,Pass,Ignore " ) , " set_mouse_filter " , " get_mouse_filter " ) ;
ADD_GROUP ( " Size Flags " , " size_flags_ " ) ;
2017-07-13 06:50:15 +00:00
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " size_flags_horizontal " , PROPERTY_HINT_FLAGS , " Fill,Expand,Shrink Center,Shrink End " ) , " set_h_size_flags " , " get_h_size_flags " ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : INT , " size_flags_vertical " , PROPERTY_HINT_FLAGS , " Fill,Expand,Shrink Center,Shrink End " ) , " set_v_size_flags " , " get_v_size_flags " ) ;
2017-07-31 06:15:38 +00:00
ADD_PROPERTYNO ( PropertyInfo ( Variant : : REAL , " size_flags_stretch_ratio " , PROPERTY_HINT_RANGE , " 0,128,0.01 " ) , " set_stretch_ratio " , " get_stretch_ratio " ) ;
2017-03-05 15:44:50 +00:00
ADD_GROUP ( " Theme " , " " ) ;
ADD_PROPERTYNZ ( PropertyInfo ( Variant : : OBJECT , " theme " , PROPERTY_HINT_RESOURCE_TYPE , " Theme " ) , " set_theme " , " get_theme " ) ;
ADD_GROUP ( " " , " " ) ;
BIND_CONSTANT ( ANCHOR_BEGIN ) ;
BIND_CONSTANT ( ANCHOR_END ) ;
BIND_CONSTANT ( ANCHOR_CENTER ) ;
BIND_CONSTANT ( FOCUS_NONE ) ;
BIND_CONSTANT ( FOCUS_CLICK ) ;
BIND_CONSTANT ( FOCUS_ALL ) ;
BIND_CONSTANT ( NOTIFICATION_RESIZED ) ;
BIND_CONSTANT ( NOTIFICATION_MOUSE_ENTER ) ;
BIND_CONSTANT ( NOTIFICATION_MOUSE_EXIT ) ;
BIND_CONSTANT ( NOTIFICATION_FOCUS_ENTER ) ;
BIND_CONSTANT ( NOTIFICATION_FOCUS_EXIT ) ;
BIND_CONSTANT ( NOTIFICATION_THEME_CHANGED ) ;
BIND_CONSTANT ( NOTIFICATION_MODAL_CLOSE ) ;
BIND_CONSTANT ( CURSOR_ARROW ) ;
BIND_CONSTANT ( CURSOR_IBEAM ) ;
BIND_CONSTANT ( CURSOR_POINTING_HAND ) ;
BIND_CONSTANT ( CURSOR_CROSS ) ;
BIND_CONSTANT ( CURSOR_WAIT ) ;
BIND_CONSTANT ( CURSOR_BUSY ) ;
BIND_CONSTANT ( CURSOR_DRAG ) ;
BIND_CONSTANT ( CURSOR_CAN_DROP ) ;
BIND_CONSTANT ( CURSOR_FORBIDDEN ) ;
BIND_CONSTANT ( CURSOR_VSIZE ) ;
BIND_CONSTANT ( CURSOR_HSIZE ) ;
BIND_CONSTANT ( CURSOR_BDIAGSIZE ) ;
BIND_CONSTANT ( CURSOR_FDIAGSIZE ) ;
BIND_CONSTANT ( CURSOR_MOVE ) ;
BIND_CONSTANT ( CURSOR_VSPLIT ) ;
BIND_CONSTANT ( CURSOR_HSPLIT ) ;
BIND_CONSTANT ( CURSOR_HELP ) ;
BIND_CONSTANT ( SIZE_EXPAND ) ;
BIND_CONSTANT ( SIZE_FILL ) ;
BIND_CONSTANT ( SIZE_EXPAND_FILL ) ;
2017-07-06 22:06:55 +00:00
BIND_CONSTANT ( SIZE_SHRINK_CENTER ) ;
BIND_CONSTANT ( SIZE_SHRINK_END ) ;
2017-03-05 15:44:50 +00:00
BIND_CONSTANT ( MOUSE_FILTER_STOP ) ;
BIND_CONSTANT ( MOUSE_FILTER_PASS ) ;
BIND_CONSTANT ( MOUSE_FILTER_IGNORE ) ;
2017-07-06 16:26:39 +00:00
BIND_CONSTANT ( GROW_DIRECTION_BEGIN ) ;
BIND_CONSTANT ( GROW_DIRECTION_END ) ;
2017-03-05 15:44:50 +00:00
ADD_SIGNAL ( MethodInfo ( " resized " ) ) ;
2017-05-20 15:38:03 +00:00
ADD_SIGNAL ( MethodInfo ( " gui_input " , PropertyInfo ( Variant : : OBJECT , " ev " , PROPERTY_HINT_RESOURCE_TYPE , " InputEvent " ) ) ) ;
2017-03-05 15:44:50 +00:00
ADD_SIGNAL ( MethodInfo ( " mouse_entered " ) ) ;
ADD_SIGNAL ( MethodInfo ( " mouse_exited " ) ) ;
ADD_SIGNAL ( MethodInfo ( " focus_entered " ) ) ;
ADD_SIGNAL ( MethodInfo ( " focus_exited " ) ) ;
ADD_SIGNAL ( MethodInfo ( " size_flags_changed " ) ) ;
ADD_SIGNAL ( MethodInfo ( " minimum_size_changed " ) ) ;
ADD_SIGNAL ( MethodInfo ( " modal_closed " ) ) ;
2017-03-13 23:30:40 +00:00
BIND_VMETHOD ( MethodInfo ( " has_point " , PropertyInfo ( Variant : : VECTOR2 , " point " ) ) ) ;
2014-02-10 01:10:30 +00:00
}
Control : : Control ( ) {
2016-03-08 23:00:52 +00:00
2017-03-05 15:44:50 +00:00
data . parent = NULL ;
2016-01-17 01:41:10 +00:00
2017-03-05 15:44:50 +00:00
data . mouse_filter = MOUSE_FILTER_STOP ;
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
data . SI = NULL ;
data . MI = NULL ;
data . RI = NULL ;
data . modal = false ;
data . theme_owner = NULL ;
data . modal_exclusive = false ;
2014-02-10 01:10:30 +00:00
data . default_cursor = CURSOR_ARROW ;
2017-03-05 15:44:50 +00:00
data . h_size_flags = SIZE_FILL ;
data . v_size_flags = SIZE_FILL ;
data . expand = 1 ;
data . pending_min_size_update = false ;
data . rotation = 0 ;
data . parent_canvas_item = NULL ;
data . scale = Vector2 ( 1 , 1 ) ;
data . drag_owner = 0 ;
data . modal_frame = 0 ;
data . block_minimum_size_adjust = false ;
data . disable_visibility_clip = false ;
2017-07-06 16:26:39 +00:00
data . h_grow = GROW_DIRECTION_END ;
data . v_grow = GROW_DIRECTION_END ;
2017-03-05 15:44:50 +00:00
data . clip_contents = false ;
for ( int i = 0 ; i < 4 ; i + + ) {
data . anchor [ i ] = ANCHOR_BEGIN ;
data . margin [ i ] = 0 ;
}
data . focus_mode = FOCUS_NONE ;
data . modal_prev_focus_owner = 0 ;
}
Control : : ~ Control ( ) {
2014-02-10 01:10:30 +00:00
}