BehaviorNode::Status StatusBNode::_step(const Variant &target, Dictionary &env) { if (!get_behavior_enable() || get_child_count() == 0) return STATUS_FAILURE; if ((bool)call(StringName("pre_behavior"),target, Variant(env)) && get_child_count() > 0) { if (_selected < 0) { _selected = 0; }else if (_selected >= get_child_count()) { _selected = get_child_count() - 1; } BehaviorNode *b_node = get_child(_selected)->cast_to<BehaviorNode>(); Status childrenStatus = STATUS_FAILURE; if (b_node) { if (_selected != _old_selected) b_node->reset(target); childrenStatus = b_node->step(target, env); } _old_selected = _selected; Status status = (Status)((int)call(StringName("behavior"),target, Variant(env))); if (status == STATUS_DEPEND_ON_CHILDREN) return childrenStatus; else return status; }else { return STATUS_FAILURE; } }
void GraphNode::_resort() { int sep = get_constant("separation"); Ref<StyleBox> sb = get_stylebox("frame"); bool first = true; Size2 minsize; for (int i = 0; i < get_child_count(); i++) { Control *c = get_child(i)->cast_to<Control>(); if (!c) continue; if (c->is_set_as_toplevel()) continue; Size2i size = c->get_combined_minimum_size(); minsize.y += size.y; minsize.x = MAX(minsize.x, size.x); if (first) first = false; else minsize.y += sep; } int vofs = 0; int w = get_size().x - sb->get_minimum_size().x; cache_y.clear(); for (int i = 0; i < get_child_count(); i++) { Control *c = get_child(i)->cast_to<Control>(); if (!c) continue; if (c->is_set_as_toplevel()) continue; Size2i size = c->get_combined_minimum_size(); Rect2 r(sb->get_margin(MARGIN_LEFT), sb->get_margin(MARGIN_TOP) + vofs, w, size.y); fit_child_in_rect(c, r); cache_y.push_back(vofs + size.y * 0.5); if (vofs > 0) vofs += sep; vofs += size.y; } _change_notify(); update(); connpos_dirty = true; }
MYX_DBM_DATATYPES *process_xml_for_datatype(xmlDocPtr doc, MYX_LIB_ERROR *error_code) { xmlNodePtr parent, node; MYX_DBM_DATATYPES *obj; MYX_DBM_DATATYPE * type= NULL; MYX_NAME_VALUE_PAIR * pair= NULL; parent= xmlDocGetRootElement(doc); if (parent == NULL) { *error_code= MYX_XML_EMPTY_DOCUMENT; return NULL; } obj= (MYX_DBM_DATATYPES*)g_malloc0(sizeof(MYX_DBM_DATATYPES)); obj->datatypes_num= get_child_count(parent, (xmlChar*)"datatype"); obj->substitutes_num= get_child_count(parent, (xmlChar*)"substitution"); if (obj->datatypes_num > 0) { type= obj->datatypes= (MYX_DBM_DATATYPE*)g_malloc0(obj->datatypes_num * sizeof(MYX_DBM_DATATYPE)); } if (obj->substitutes_num > 0) { pair= obj->substitutes= (MYX_NAME_VALUE_PAIR*)g_malloc0(obj->substitutes_num * sizeof(MYX_NAME_VALUE_PAIR)); } for (node= parent->children; node != NULL; node= node->next) { if (!xmlStrcmp(node->name, (xmlChar*)"datatype")) { read_datatype_MYX_DBM_DATATYPE(node, type); type++; } if (!xmlStrcmp(node->name, (xmlChar*)"substitution")) { pair->name= (char*)xmlGetProp(node, (xmlChar*)"name"); pair->value= (char*)xmlGetProp(node, (xmlChar*)"value"); pair++; } } return obj; }
void SpringArm::process_spring() { // From real_t motion_delta(1); real_t motion_delta_unsafe(1); Vector3 motion; const Vector3 cast_direction(get_global_transform().basis.xform(Vector3(0, 0, 1))); if (shape.is_null()) { motion = Vector3(cast_direction * (spring_length)); PhysicsDirectSpaceState::RayResult r; bool intersected = get_world()->get_direct_space_state()->intersect_ray(get_global_transform().origin, get_global_transform().origin + motion, r, excluded_objects, mask); if (intersected) { float dist = get_global_transform().origin.distance_to(r.position); dist -= margin; motion_delta = dist / (spring_length); } } else { motion = Vector3(cast_direction * spring_length); get_world()->get_direct_space_state()->cast_motion(shape->get_rid(), get_global_transform(), motion, 0, motion_delta, motion_delta_unsafe, excluded_objects, mask); } current_spring_length = spring_length * motion_delta; Transform childs_transform; childs_transform.origin = get_global_transform().origin + cast_direction * (spring_length * motion_delta); for (int i = get_child_count() - 1; 0 <= i; --i) { Spatial *child = Object::cast_to<Spatial>(get_child(i)); if (child) { childs_transform.basis = child->get_global_transform().basis; child->set_global_transform(childs_transform); } } }
static rc_t enter_vdbcopy_node( KMetadata *dst_meta, const bool show_meta ) { rc_t rc; KMDataNode *hist_node; if ( show_meta ) KOutMsg( "--- entering Copy entry...\n" ); rc = KMetadataOpenNodeUpdate ( dst_meta, &hist_node, "HISTORY" ); DISP_RC( rc, "enter_vdbcopy_node:KMetadataOpenNodeUpdate('HISTORY') failed" ); if ( rc == 0 ) { char event_name[ 32 ]; uint32_t index = get_child_count( hist_node ) + 1; rc = string_printf ( event_name, sizeof( event_name ), NULL, "EVENT_%u", index ); DISP_RC( rc, "enter_vdbcopy_node:string_printf(EVENT_NR) failed" ); if ( rc == 0 ) { KMDataNode *event_node; rc = KMDataNodeOpenNodeUpdate ( hist_node, &event_node, event_name ); DISP_RC( rc, "enter_vdbcopy_node:KMDataNodeOpenNodeUpdate('EVENT_NR') failed" ); if ( rc == 0 ) { rc = enter_date_name_vers( event_node ); KMDataNodeRelease ( event_node ); } } KMDataNodeRelease ( hist_node ); } return rc; }
bool GraphEdit::is_in_hot_zone(const Vector2 &pos, const Vector2 &p_mouse_pos) { if (!Rect2(pos.x - port_grab_distance_horizontal, pos.y - port_grab_distance_vertical, port_grab_distance_horizontal * 2, port_grab_distance_vertical * 2).has_point(p_mouse_pos)) return false; for (int i = 0; i < get_child_count(); i++) { Control *child = Object::cast_to<Control>(get_child(i)); if (!child) continue; Rect2 rect = child->get_rect(); if (rect.has_point(p_mouse_pos)) { //check sub-controls Vector2 subpos = p_mouse_pos - rect.position; for (int j = 0; j < child->get_child_count(); j++) { Control *subchild = Object::cast_to<Control>(child->get_child(j)); if (!subchild) continue; if (_check_clickable_control(subchild, subpos - subchild->get_position())) { return false; } } } } return true; }
int TabContainer::_get_top_margin() const { Ref<StyleBox> tab_bg = get_stylebox("tab_bg"); Ref<StyleBox> tab_fg = get_stylebox("tab_fg"); Ref<Font> font = get_font("font"); int h = MAX( tab_bg->get_minimum_size().height,tab_fg->get_minimum_size().height); int ch = font->get_height();; for(int i=0; i<get_child_count(); i++) { Control *c = get_child(i)->cast_to<Control>(); if (!c) continue; if (c->is_set_as_toplevel()) continue; if (!c->has_meta("_tab_icon")) continue; Ref<Texture> tex = c->get_meta("_tab_icon"); if (!tex.is_valid()) continue; ch = MAX( ch, tex->get_size().height ); } h+=ch; return h; }
Size2 PanelContainer::get_minimum_size() const { Ref<StyleBox> style; if (has_stylebox("panel")) style=get_stylebox("panel"); else style=get_stylebox("panel","PanelContainer"); Size2 ms; for(int i=0;i<get_child_count();i++) { Control *c = get_child(i)->cast_to<Control>(); if (!c || !c->is_visible()) continue; if (c->is_set_as_toplevel()) continue; Size2 minsize = c->get_combined_minimum_size(); ms.width = MAX(ms.width , minsize.width); ms.height = MAX(ms.height , minsize.height); } if (style.is_valid()) ms+=style->get_minimum_size(); return ms; }
Size2 TabContainer::get_minimum_size() const { Size2 ms; for(int i=0; i<get_child_count(); i++) { Control *c = get_child(i)->cast_to<Control>(); if (!c) continue; if (c->is_set_as_toplevel()) continue; if (!c->is_visible()) continue; Size2 cms = c->get_combined_minimum_size(); ms.x=MAX(ms.x,cms.x); ms.y=MAX(ms.y,cms.y); } Ref<StyleBox> tab_bg = get_stylebox("tab_bg"); Ref<StyleBox> tab_fg = get_stylebox("tab_fg"); Ref<Font> font = get_font("font"); ms.y+=MAX(tab_bg->get_minimum_size().y,tab_fg->get_minimum_size().y); ms.y+=font->get_height(); Ref<StyleBox> sb = get_stylebox("panel"); ms+=sb->get_minimum_size(); return ms; }
Node *Node::duplicate_and_reown(const Map<Node*,Node*>& p_reown_map) const { ERR_FAIL_COND_V(get_filename()!="",NULL); Node *node=NULL; Object *obj = ObjectTypeDB::instance(get_type()); if (!obj) { print_line("could not duplicate: "+String(get_type())); } ERR_FAIL_COND_V(!obj,NULL); node = obj->cast_to<Node>(); if (!node) memdelete(obj); ERR_FAIL_COND_V(!node,NULL); node->set_name(get_name()); for(int i=0;i<get_child_count();i++) { get_child(i)->_duplicate_and_reown(node,p_reown_map); } return node; }
Size2 CenterContainer::get_minimum_size() const { if (use_top_left) return Size2(); Size2 ms; for(int i=0;i<get_child_count();i++) { Control *c = get_child(i)->cast_to<Control>(); if (!c) continue; if (c->is_set_as_toplevel()) continue; if (c->is_hidden()) continue; Size2 minsize = c->get_combined_minimum_size(); ms.width = MAX(ms.width , minsize.width); ms.height = MAX(ms.height , minsize.height); } return ms; }
static void read_datatype_MYX_DBM_DATATYPE(xmlNodePtr parent, MYX_DBM_DATATYPE *obj) { xmlNodePtr node; xmlDocPtr doc= parent->doc; char ** flag; obj->flags_num= get_child_count(parent, (xmlChar*)"flag"); flag= obj->flags= g_malloc0(obj->flags_num * sizeof(char *)); for (node= parent->children; node != NULL; node= node->next) { if (!xmlStrcmp(node->name, (xmlChar*)"flag")) { *flag= (char*)xmlNodeListGetString(doc, node->children, 1); flag++; } try_to_get_string_field(doc, node, "name", &obj->name); try_to_get_int_field (doc, node, "group", (int*)&obj->group); try_to_get_int_field (doc, node, "synonym_group", (int*)&obj->synonym_group); try_to_get_int_field (doc, node, "params_optional", (int*)&obj->params_optional); try_to_get_int_field (doc, node, "has_length_param", (int*)&obj->has_length_param); try_to_get_int_field (doc, node, "has_decimal_param", (int*)&obj->has_decimal_param); try_to_get_int_field (doc, node, "has_value_params", (int*)&obj->has_value_params); } }
bool GraphEdit::_filter_input(const Point2 &p_point) { Ref<Texture> port = get_icon("port", "GraphNode"); for (int i = get_child_count() - 1; i >= 0; i--) { GraphNode *gn = Object::cast_to<GraphNode>(get_child(i)); if (!gn) continue; for (int j = 0; j < gn->get_connection_output_count(); j++) { Vector2 pos = gn->get_connection_output_position(j) + gn->get_position(); if (is_in_hot_zone(pos, p_point)) return true; } for (int j = 0; j < gn->get_connection_input_count(); j++) { Vector2 pos = gn->get_connection_input_position(j) + gn->get_position(); if (is_in_hot_zone(pos, p_point)) { return true; } } } return false; }
void Node::_duplicate_signals(const Node* p_original,Node* p_copy) const { if (this!=p_original && get_owner()!=p_original) return; List<Connection> conns; get_all_signal_connections(&conns); for (List<Connection>::Element *E=conns.front();E;E=E->next()) { if (E->get().flags&CONNECT_PERSIST) { //user connected NodePath p = p_original->get_path_to(this); Node *copy = p_copy->get_node(p); Node *target = E->get().target->cast_to<Node>(); if (!target) continue; NodePath ptarget = p_original->get_path_to(target); Node *copytarget = p_copy->get_node(ptarget); if (copy && copytarget) { copy->connect(E->get().signal,copytarget,E->get().method,E->get().binds,CONNECT_PERSIST); } } } for(int i=0;i<get_child_count();i++) { get_child(i)->_duplicate_signals(p_original,p_copy); } }
bool GraphEdit::_filter_input(const Point2& p_point) { Ref<Texture> port =get_icon("port","GraphNode"); float grab_r=port->get_width()*0.5; for(int i=get_child_count()-1;i>=0;i--) { GraphNode *gn=get_child(i)->cast_to<GraphNode>(); if (!gn) continue; for(int j=0;j<gn->get_connection_output_count();j++) { Vector2 pos = gn->get_connection_output_pos(j)+gn->get_pos(); if (pos.distance_to(p_point)<grab_r) return true; } for(int j=0;j<gn->get_connection_input_count();j++) { Vector2 pos = gn->get_connection_input_pos(j)+gn->get_pos(); if (pos.distance_to(p_point)<grab_r) return true; } } return false; }
Size2 ScrollContainer::get_minimum_size() const { Size2 min_size; for(int i=0;i<get_child_count();i++) { Control *c = get_child(i)->cast_to<Control>(); if (!c) continue; if (c->is_set_as_toplevel()) continue; if (c == h_scroll || c == v_scroll) continue; Size2 minsize = c->get_combined_minimum_size(); if (!scroll_h) { min_size.x = MAX(min_size.x, minsize.x); } if (!scroll_v) { min_size.y = MAX(min_size.y, minsize.y); } } if (h_scroll->is_visible()) { min_size.y+=h_scroll->get_minimum_size().y; } if (v_scroll->is_visible()) { min_size.x+=v_scroll->get_minimum_size().x; } return min_size; };
void TabContainer::set_current_tab(int p_current) { ERR_FAIL_INDEX( p_current, get_tab_count() ); current=p_current; int idx=0; Ref<StyleBox> sb=get_stylebox("panel"); for(int i=0; i<get_child_count(); i++) { Control *c = get_child(i)->cast_to<Control>(); if (!c) continue; if (c->is_set_as_toplevel()) continue; if (idx==current) { c->show(); c->set_area_as_parent_rect(); if (tabs_visible) c->set_margin(MARGIN_TOP,_get_top_margin()); for(int i=0; i<4; i++) c->set_margin(Margin(i),c->get_margin(Margin(i))+sb->get_margin(Margin(i))); } else c->hide(); idx++; } _change_notify("current_tab"); emit_signal("tab_changed",current); update(); }
void ViewportContainer::_notification(int p_what) { if (p_what == NOTIFICATION_RESIZED) { if (!stretch) return; for (int i = 0; i < get_child_count(); i++) { Viewport *c = Object::cast_to<Viewport>(get_child(i)); if (!c) continue; c->set_size(get_size() / shrink); } } if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_VISIBILITY_CHANGED) { for (int i = 0; i < get_child_count(); i++) { Viewport *c = Object::cast_to<Viewport>(get_child(i)); if (!c) continue; if (is_visible_in_tree()) c->set_update_mode(Viewport::UPDATE_ALWAYS); else c->set_update_mode(Viewport::UPDATE_DISABLED); } } if (p_what == NOTIFICATION_DRAW) { for (int i = 0; i < get_child_count(); i++) { Viewport *c = Object::cast_to<Viewport>(get_child(i)); if (!c) continue; if (stretch) draw_texture_rect(c->get_texture(), Rect2(Vector2(), get_size() * Size2(1, -1))); else draw_texture_rect(c->get_texture(), Rect2(Vector2(), c->get_size() * Size2(1, -1))); } } }
void Node::get_owned_by(Node *p_by,List<Node*> *p_owned) { if (data.owner==p_by) p_owned->push_back(this); for (int i=0;i<get_child_count();i++) get_child(i)->get_owned_by(p_by,p_owned); }
Array Node::_get_children() const { Array arr; int cc = get_child_count(); arr.resize(cc); for(int i=0;i<cc;i++) arr[i]=get_child(i); return arr; }
void GraphNode::_connpos_update() { int edgeofs=get_constant("port_offset"); int sep=get_constant("separation"); Ref<StyleBox> sb=get_stylebox("frame"); Ref<Texture> port =get_icon("port"); conn_input_cache.clear(); conn_output_cache.clear(); int vofs=0; int idx=0; for(int i=0;i<get_child_count();i++) { Control *c=get_child(i)->cast_to<Control>(); if (!c) continue; if (c->is_set_as_toplevel()) continue; Size2i size=c->get_combined_minimum_size(); int y = sb->get_margin(MARGIN_TOP)+vofs; int h = size.y; if (slot_info.has(idx)) { if (slot_info[idx].enable_left) { ConnCache cc; cc.pos=Point2i(edgeofs,y+h/2); cc.type=slot_info[idx].type_left; cc.color=slot_info[idx].color_left; conn_input_cache.push_back(cc); } if (slot_info[idx].enable_right) { ConnCache cc; cc.pos=Point2i(get_size().width-edgeofs,y+h/2); cc.type=slot_info[idx].type_right; cc.color=slot_info[idx].color_right; conn_output_cache.push_back(cc); } } if (vofs>0) vofs+=sep; vofs+=size.y; idx++; } connpos_dirty=false; }
node* node::get_child( std::size_t index ) { if ( index >= get_child_count() ) return NULL; nodelist_type::iterator it; std::size_t n = 0; it = m_subnodes.begin(); while( n < index ) it++; return *it; }
void GraphEdit::set_selected(Node *p_child) { for (int i = get_child_count() - 1; i >= 0; i--) { GraphNode *gn = Object::cast_to<GraphNode>(get_child(i)); if (!gn) continue; gn->set_selected(gn == p_child); } }
void CollisionObject2D::_update_shapes_from_children() { shapes.clear(); for (int i = 0; i < get_child_count(); i++) { Node *n = get_child(i); n->call("_add_to_collision_object", this); } _update_shapes(); }
void BehaviorNode::reset(const Variant &target) { _reset(target); _script_reset(target); int t = get_child_count(); for (int i = 0; i < t; ++i) { BehaviorNode * child = get_child(i)->cast_to<BehaviorNode>(); if (child) { child->reset(target); } } }
Vector<Control *> TabContainer::_get_tabs() const { Vector<Control *> controls; for (int i = 0; i < get_child_count(); i++) { Control *control = get_child(i)->cast_to<Control>(); if (!control || control->is_toplevel_control()) continue; controls.push_back(control); } return controls; }
void GraphEdit::_update_scroll() { if (updating) return; updating = true; set_block_minimum_size_adjust(true); Rect2 screen; for (int i = 0; i < get_child_count(); i++) { GraphNode *gn = Object::cast_to<GraphNode>(get_child(i)); if (!gn) continue; Rect2 r; r.position = gn->get_offset() * zoom; r.size = gn->get_size() * zoom; screen = screen.merge(r); } screen.position -= get_size(); screen.size += get_size() * 2.0; h_scroll->set_min(screen.position.x); h_scroll->set_max(screen.position.x + screen.size.x); h_scroll->set_page(get_size().x); if (h_scroll->get_max() - h_scroll->get_min() <= h_scroll->get_page()) h_scroll->hide(); else h_scroll->show(); v_scroll->set_min(screen.position.y); v_scroll->set_max(screen.position.y + screen.size.y); v_scroll->set_page(get_size().y); if (v_scroll->get_max() - v_scroll->get_min() <= v_scroll->get_page()) v_scroll->hide(); else v_scroll->show(); set_block_minimum_size_adjust(false); if (!awaiting_scroll_offset_update) { call_deferred("_update_scroll_offset"); awaiting_scroll_offset_update = true; } updating = false; }
void GraphEdit::_update_scroll_offset() { for(int i=0;i<get_child_count();i++) { GraphNode *gn=get_child(i)->cast_to<GraphNode>(); if (!gn) continue; Point2 pos=gn->get_offset(); pos-=Point2(h_scroll->get_val(),v_scroll->get_val()); gn->set_pos(pos); } }
int TabContainer::get_tab_count() const { int count=0; for(int i=0; i<get_child_count(); i++) { Control *c = get_child(i)->cast_to<Control>(); if (!c) continue; count++; } return count; }
Size2 GridContainer::get_minimum_size() const { Map<int,int> col_minw; Map<int,int> row_minh; int hsep=get_constant("hseparation"); int vsep=get_constant("vseparation"); int idx=0; int max_row=0; int max_col=0; for(int i=0;i<get_child_count();i++) { Control *c = get_child(i)->cast_to<Control>(); if (!c || !c->is_visible()) continue; int row = idx / columns; int col = idx % columns; Size2i ms = c->get_combined_minimum_size(); if (col_minw.has(col)) col_minw[col] = MAX(col_minw[col],ms.width); else col_minw[col]=ms.width; if (row_minh.has(row)) row_minh[row] = MAX(row_minh[row],ms.height); else row_minh[row]=ms.height; max_col=MAX(col,max_col); max_row=MAX(row,max_row); idx++; } Size2 ms; for (Map<int,int>::Element *E=col_minw.front();E;E=E->next()) { ms.width+=E->get(); } for (Map<int,int>::Element *E=row_minh.front();E;E=E->next()) { ms.height+=E->get(); } ms.height+=vsep*max_row; ms.width+=hsep*max_col; return ms; }