static void get_meta_bam_hdr( vdb_info_bam_hdr * bam_hdr, const KMetadata * meta ) { const KMDataNode * node; rc_t rc = KMetadataOpenNodeRead ( meta, &node, "BAM_HEADER" ); bam_hdr -> present = ( rc == 0 ); if ( bam_hdr -> present ) { bam_hdr->hdr_bytes = get_node_size( node ); if ( bam_hdr->hdr_bytes > 0 ) { char * buffer = malloc( bam_hdr->hdr_bytes ); if ( buffer != NULL ) { size_t num_read, remaining; rc = KMDataNodeRead( node, 0, buffer, bam_hdr->hdr_bytes, &num_read, &remaining ); if ( rc == 0 ) { parse_buffer( bam_hdr, buffer, bam_hdr->hdr_bytes ); } free( buffer ); } } KMDataNodeRelease ( node ); } }
int kowhai_get_node_count(const struct kowhai_node_t *node, int *count) { int size, ret; ret = get_node_size(node, &size, count); (*count)++; return ret; }
Point2 ShaderEditor::_get_slot_pos(int p_node_id,bool p_input,int p_slot) { Ref<StyleBox> style = get_stylebox("panel","PopupMenu"); float w = get_node_size(p_node_id).width; Ref<Font> font = get_font("font","PopupMenu"); float h = font->get_height()+get_constant("vseparation","PopupMenu"); Ref<Texture> vec_icon = get_icon("NodeVecSlot","EditorIcons"); Point2 pos = Point2( shader_graph.node_get_pos_x(p_node_id), shader_graph.node_get_pos_y(p_node_id) )-offset; pos+=style->get_offset(); pos.y+=h; if(p_input) { pos.y+=p_slot*h; pos+=Point2( -vec_icon->get_width()/2.0, h/2.0).floor(); return pos; } else { pos.y+=VisualServer::shader_get_input_count( shader_graph.node_get_type(p_node_id ) )*h; } pos.y+=p_slot*h; pos+=Point2( w-style->get_minimum_size().width+vec_icon->get_width()/2.0, h/2.0).floor(); return pos; }
ShaderEditor::ClickType ShaderEditor::_locate_click(const Point2& p_click,int *p_node_id,int *p_slot_index) const { Ref<StyleBox> style = get_stylebox("panel","PopupMenu"); Ref<Texture> real_icon = get_icon("NodeRealSlot","EditorIcons"); Ref<Font> font = get_font("font","PopupMenu"); float h = font->get_height()+get_constant("vseparation","PopupMenu"); float extra_left=MAX( real_icon->get_width()-style->get_margin(MARGIN_LEFT), 0 ); float extra_right=MAX( real_icon->get_width()-style->get_margin(MARGIN_RIGHT), 0 ); for(const List<int>::Element *E=order.back();E;E=E->prev()) { Size2 size=get_node_size(E->get()); size.width+=extra_left+extra_right; Point2 pos = Point2( shader_graph.node_get_pos_x(E->get()), shader_graph.node_get_pos_y(E->get()) )-offset; pos.x-=extra_left; Rect2 rect( pos, size ); if (!rect.has_point(p_click)) continue; VisualServer::ShaderNodeType type=shader_graph.node_get_type(E->get()); if (p_node_id) *p_node_id=E->get(); float y=p_click.y-(pos.y+style->get_margin(MARGIN_TOP)); if (y<h) return CLICK_NODE; y-=h; for(int i=0;i<VisualServer::shader_get_input_count(type);i++) { if (y<h) { if (p_slot_index) *p_slot_index=i; return CLICK_INPUT_SLOT; } y-=h; } for(int i=0;i<VisualServer::shader_get_output_count(type);i++) { if (y<h) { if (p_slot_index) *p_slot_index=i; return CLICK_OUTPUT_SLOT; } y-=h; } if (p_click.y<(rect.pos.y+rect.size.height-style->get_margin(MARGIN_BOTTOM))) return CLICK_PARAMETER; else return CLICK_NODE; } return CLICK_NONE; }
int get_node_size(node_t cur_node) { int cond_size = 0; int true_size = 0; if (cur_node == NULL) return 0; if (cur_node->conditional_expr != NULL) { if (!cur_node->cond_executed) { cur_node->cond_executed = 1; cond_size = get_node_size(cur_node->conditional_expr); } else { cur_node->cond_executed = 0; return 0; } } if (cur_node->instruction_process->instruction_type->type == WHILE){ if (!cur_node->while_executed) { cur_node->while_executed = 1; true_size = get_node_size(cur_node->true_node); return get_node_size(cur_node->false_node) + cond_size + true_size + sizeof(graph_node) + get_instr_size(cur_node->instruction_process); } else { cur_node->while_executed = 0; return 0; } } return get_node_size(cur_node->true_node) + cond_size + sizeof(graph_node) + get_instr_size(cur_node->instruction_process); }
Point2 AnimationTreeEditor::_get_slot_pos(const StringName& p_node,bool p_input,int p_slot) { Ref<StyleBox> style = get_stylebox("panel","PopupMenu"); Ref<Font> font = get_font("font","PopupMenu"); Ref<Texture> slot_icon = get_icon("NodeRealSlot","EditorIcons"); Size2 size=get_node_size(p_node); Point2 pos = anim_tree->node_get_pos(p_node); if (click_type==CLICK_NODE && click_node==p_node) { pos+=click_motion-click_pos; if (pos.x<5) pos.x=5; if (pos.y<5) pos.y=5; } pos-=Point2(h_scroll->get_val(),v_scroll->get_val()); float w = size.width-style->get_minimum_size().width; float h = font->get_height()+get_constant("vseparation","PopupMenu"); pos+=style->get_offset(); pos.y+=h*2; pos.y+=h*p_slot; pos+=Point2( -slot_icon->get_width()/2.0, h/2.0).floor(); if(!p_input) { pos.x+=w+slot_icon->get_width(); } return pos; }
Size2 ShaderEditor::_get_maximum_size() { Size2 max; for(List<int>::Element *E=order.front();E;E=E->next()) { Point2 pos = Point2( shader_graph.node_get_pos_x(E->get()), shader_graph.node_get_pos_y(E->get()) ); if (click_type==CLICK_NODE && click_node==E->get()) { pos+=click_motion-click_pos; } pos+=get_node_size(E->get()); if (pos.x>max.x) max.x=pos.x; if (pos.y>max.y) max.y=pos.y; } return max; }
Size2 AnimationTreeEditor::_get_maximum_size() { Size2 max; for(List<StringName>::Element *E=order.front();E;E=E->next()) { Point2 pos = anim_tree->node_get_pos(E->get()); if (click_type==CLICK_NODE && click_node==E->get()) { pos+=click_motion-click_pos; } pos+=get_node_size(E->get()); if (pos.x>max.x) max.x=pos.x; if (pos.y>max.y) max.y=pos.y; } return max; }
void AnimationTreeEditor::_node_edit_property(const StringName& p_node) { Ref<StyleBox> style = get_stylebox("panel","PopupMenu"); Size2 size = get_node_size(p_node); Point2 pos = Point2( anim_tree->node_get_pos_x(p_node), anim_tree->node_get_pos_y(p_node) )-offset; VisualServer::AnimationTreeNodeType type=anim_tree->node_get_type(p_node); PropertyInfo ph = VisualServer::get_singleton()->anim_tree_node_get_type_info(type); if (ph.type==Variant::NIL) return; if (ph.type==Variant::_RID) ph.type=Variant::RESOURCE; property_editor->edit(NULL,ph.name,ph.type,anim_tree->node_get_param(p_node),ph.hint,ph.hint_string); Point2 popup_pos=Point2( pos.x+(size.width-property_editor->get_size().width)/2.0,pos.y+(size.y-style->get_margin(MARGIN_BOTTOM))).floor(); popup_pos+=get_global_pos(); property_editor->set_pos(popup_pos); property_editor->popup(); }
void ShaderEditor::_node_edit_property(int p_node) { Ref<StyleBox> style = get_stylebox("panel","PopupMenu"); Size2 size = get_node_size(p_node); Point2 pos = Point2( shader_graph.node_get_pos_x(p_node), shader_graph.node_get_pos_y(p_node) )-offset; VisualServer::ShaderNodeType type=shader_graph.node_get_type(p_node); PropertyInfo ph = VisualServer::get_singleton()->shader_node_get_type_info(type); if (ph.type==Variant::NIL) return; if (ph.type==Variant::_RID) ph.type=Variant::OBJECT; property_editor->edit(NULL,ph.name,ph.type,shader_graph.node_get_param(p_node),ph.hint,ph.hint_string); Point2 popup_pos=Point2( pos.x+(size.width-property_editor->get_size().width)/2.0,pos.y+(size.y-style->get_margin(MARGIN_BOTTOM))).floor(); popup_pos+=get_global_pos(); property_editor->set_pos(popup_pos); property_editor->popup(); }
AnimationTreeEditor::ClickType AnimationTreeEditor::_locate_click(const Point2& p_click,StringName *p_node_id,int *p_slot_index) const { Ref<StyleBox> style = get_stylebox("panel","PopupMenu"); Ref<Font> font = get_font("font","PopupMenu"); Color font_color = get_color("font_color","PopupMenu"); float h = (font->get_height()+get_constant("vseparation","PopupMenu")); for(const List<StringName>::Element *E=order.back();E;E=E->prev()) { StringName node = E->get(); AnimationTreePlayer::NodeType type=anim_tree->node_get_type(node); Point2 pos = anim_tree->node_get_pos(node); Size2 size = get_node_size(node); pos-=Point2(h_scroll->get_val(),v_scroll->get_val()); if (!Rect2(pos,size).has_point(p_click)) continue; if (p_node_id) *p_node_id=node; pos=p_click-pos; float y = pos.y-style->get_offset().height; if (y<h) return CLICK_NODE; y-=h; if (y<h) return CLICK_NODE; y-=h; int count=0; // title and name int inputs = anim_tree->node_get_input_count(node); count += inputs?inputs:1; for(int i=0;i<count;i++) { if (y<h) { if (inputs==0 || ( type!=AnimationTreePlayer::NODE_OUTPUT && pos.x > size.width/2)) { if (p_slot_index) *p_slot_index=0; return CLICK_OUTPUT_SLOT; } else { if (p_slot_index) *p_slot_index=i; return CLICK_INPUT_SLOT; } } y-=h; } return (type!=AnimationTreePlayer::NODE_OUTPUT && type!=AnimationTreePlayer::NODE_TIMESEEK)?CLICK_PARAMETER:CLICK_NODE; } return CLICK_NONE; }
// calculate the complete size of a node including all the sub-elements and array items. static int get_node_size(const struct kowhai_node_t *node, int *size, int *num_nodes_processed) { int _size = 0; int i = 0; *num_nodes_processed = 0; switch (node->type) { case KOW_BRANCH_START: case KOW_BRANCH_U_START: // this is a branch so look through all the elements in this branch and accumulate the sizes while (1) { i++; *num_nodes_processed = i; switch ((enum kowhai_node_type)node[i].type) { // navigate the hierarchy info case KOW_BRANCH_START: case KOW_BRANCH_U_START: { int child_branch_size = 0; int _num_child_nodes_processed; int ret; ret = get_node_size(node + i, &child_branch_size, &_num_child_nodes_processed); if (ret != KOW_STATUS_OK) return ret; // accumulate the branches size if (node->type == KOW_BRANCH_START) _size += child_branch_size; else if (child_branch_size > _size) _size = child_branch_size; // skip the already processed nodes i += _num_child_nodes_processed; break; } case KOW_BRANCH_END: // accumulate the whole array _size *= node->count; goto done; // accumulate the size of all the other node_count default: { int child_node_size = kowhai_get_node_type_size(node[i].type) * node[i].count; if (node->type == KOW_BRANCH_START) _size += child_node_size; else if (child_node_size > _size) _size = child_node_size; break; } } } break; default: // if this is not a branch then just return the size of the node item (otherwise we need to drill baby) _size = kowhai_get_node_type_size(node->type) * node->count; *num_nodes_processed = 0; break; } done: // update caller with size information if (size != NULL) *size = _size; return KOW_STATUS_OK; }
/** * @brief find a item in the tree given its path * @param node to start searching from for the given item * @param num_symbols number of items in the path (@todo should we just terminate the path instead) * @param symbols the path of the item to seek * @param offset set to number of bytes from the current node to the requested symbol * @param target_node placeholder for the result of the node search * @param num_nodes_processed how many nodes were iterated over during this function call * @return < 0 on failure * @todo find the correct index (always 0 atm) */ int get_node(const struct kowhai_node_t *node, int num_symbols, const union kowhai_symbol_t *symbols, int *offset, struct kowhai_node_t **target_node, int initial_branch, int branch_union) { int i = 0; int _offset = 0; int ret; // look through all the items in the node list while (1) { int skip_size; int skip_nodes; switch (node[i].type) { case KOW_BRANCH_END: // if we got a branch end then we didn't find it on this path return KOW_STATUS_INVALID_SYMBOL_PATH; default: // if the path symbols match and the node array count is large enough to contain our index this could be the target node if ((symbols->parts.name == node[i].symbol) && (node[i].count > symbols->parts.array_index)) { if (num_symbols == 1) { // the symbol paths fully match in values and length so this is the node we are looking for ret = KOW_STATUS_OK; if (target_node != NULL) *target_node = (struct kowhai_node_t*)node + i; goto done; } if (node[i].type == KOW_BRANCH_START || node[i].type == KOW_BRANCH_U_START) { int branch_offset = 0; // this is not the target node but it is possibly in this branch so drill baby drill ret = get_node(node + i + 1, num_symbols - 1, symbols + 1, &branch_offset, target_node, 0, node[i].type == KOW_BRANCH_U_START); if (ret == KOW_STATUS_INVALID_SYMBOL_PATH) // branch ended without finding our target node so goto next break; // add the branch offset to current total _offset += branch_offset; goto done; } } break; } if (initial_branch) return KOW_STATUS_INVALID_SYMBOL_PATH; // this item is not a match so skip it (find out how many bytes and nodes to skip) ret = get_node_size(node + i, &skip_size, &skip_nodes); if (ret != KOW_STATUS_OK) // propagate the error return ret; if (!branch_union) _offset += skip_size; i += skip_nodes + 1; } done: // update offset return parameter if (offset != NULL) { // we have the index of the target node // the offset is: (the size of this node / its count) * symbol array index int size; ret = kowhai_get_node_size(node + i, &size); if (ret != KOW_STATUS_OK) return ret; _offset += (size / node[i].count) * symbols->parts.array_index; *offset = _offset; } return ret; }
int kowhai_get_node_size(const struct kowhai_node_t *node, int *size) { int num_nodes_processed; return get_node_size(node, size, &num_nodes_processed); }
/* - updates sizes, names, etc */ static gint canvas_node_update(node_id_t * node_id, canvas_node_t * canvas_node, GList **delete_list) { node_t *node; gdouble node_size; static clock_t start = 0; clock_t end; gdouble cpu_time_used; char *nametmp = NULL; node = nodes_catalog_find(node_id); /* Remove node if node is too old or if capture is stopped */ if (!node || !display_node (node)) { /* adds current to list of canvas nodes to delete */ *delete_list = g_list_prepend( *delete_list, node_id); g_my_debug ("Queing canvas node to remove."); need_reposition = TRUE; return FALSE; } switch (pref.node_size_variable) { case INST_TOTAL: node_size = get_node_size (node->node_stats.stats.average); break; case INST_INBOUND: node_size = get_node_size (node->node_stats.stats_in.average); break; case INST_OUTBOUND: node_size = get_node_size (node->node_stats.stats_out.average); break; case INST_PACKETS: node_size = get_node_size (node->node_stats.pkt_list.length); break; case ACCU_TOTAL: node_size = get_node_size (node->node_stats.stats.accumulated); break; case ACCU_INBOUND: node_size = get_node_size (node->node_stats.stats_in.accumulated); break; case ACCU_OUTBOUND: node_size = get_node_size (node->node_stats.stats_out.accumulated); break; case ACCU_PACKETS: node_size = get_node_size (node->node_stats.stats.accu_packets); break; case ACCU_AVG_SIZE: node_size = get_node_size (node->node_stats.stats.avg_size); break; default: node_size = get_node_size (node->node_stats.stats_out.average); g_warning (_("Unknown value or node_size_variable")); } /* limit the maximum size to avoid overload */ if (node_size > MAX_NODE_SIZE) node_size = MAX_NODE_SIZE; if (node->main_prot[pref.stack_level]) { canvas_node->color = protohash_color(node->main_prot[pref.stack_level]); gnome_canvas_item_set (canvas_node->node_item, "x1", -node_size / 2, "x2", node_size / 2, "y1", -node_size / 2, "y2", node_size / 2, "fill_color_gdk", &(canvas_node->color), NULL); } else { guint32 black = 0x000000ff; gnome_canvas_item_set (canvas_node->node_item, "x1", -node_size / 2, "x2", node_size / 2, "y1", -node_size / 2, "y2", node_size / 2, "fill_color_rgba", black, NULL); } /* We check the name of the node, and update the canvas node name * if it has changed (useful for non blocking dns resolving) */ /*TODO why is it exactly that sometimes it is NULL? */ if (canvas_node->text_item) { g_object_get (G_OBJECT (canvas_node->text_item), "text", &nametmp, NULL); if (strcmp (nametmp, node->name->str)) { gnome_canvas_item_set (canvas_node->text_item, "text", node->name->str, NULL); gnome_canvas_item_request_update (canvas_node->text_item); } g_free (nametmp); } /* Processor time check. If too much time has passed, update the GUI */ end = clock (); cpu_time_used = ((gdouble) (end - start)) / CLOCKS_PER_SEC; if (cpu_time_used > 0.05) { /* Force redraw */ while (gtk_events_pending ()) gtk_main_iteration (); start = end; } return FALSE; /* False means keep on calling the function */ } /* update_canvas_nodes */
void AnimationTreeEditor::_popup_edit_dialog() { updating_edit=true; for(int i=0;i<2;i++) edit_scroll[i]->hide(); for(int i=0;i<4;i++) { edit_line[i]->hide(); edit_label[i]->hide(); } edit_option->hide(); edit_button->hide();; filter_button->hide(); edit_check->hide();; Point2 pos = anim_tree->node_get_pos(edited_node)-Point2(h_scroll->get_val(),v_scroll->get_val()); Ref<StyleBox> style = get_stylebox("panel","PopupMenu"); Size2 size = get_node_size(edited_node); Point2 popup_pos( pos.x+style->get_margin(MARGIN_LEFT), pos.y+size.y-style->get_margin(MARGIN_BOTTOM)); popup_pos+=get_global_pos(); if (renaming_edit) { edit_label[0]->set_text("New name:"); edit_label[0]->set_pos(Point2(5,5)); edit_label[0]->show(); edit_line[0]->set_begin(Point2(15,25)); edit_line[0]->set_text(edited_node); edit_line[0]->show(); edit_dialog->set_size(Size2(150,50)); } else { AnimationTreePlayer::NodeType type=anim_tree->node_get_type(edited_node); switch(type) { case AnimationTreePlayer::NODE_ANIMATION: if (anim_tree->get_master_player()!=NodePath() && anim_tree->has_node(anim_tree->get_master_player()) && anim_tree->get_node(anim_tree->get_master_player())->cast_to<AnimationPlayer>()) { AnimationPlayer *ap = anim_tree->get_node(anim_tree->get_master_player())->cast_to<AnimationPlayer>(); master_anim_popup->clear(); List<StringName> sn; ap->get_animation_list(&sn); sn.sort_custom<StringName::AlphCompare>(); for (List<StringName>::Element *E=sn.front();E;E=E->next()) { master_anim_popup->add_item(E->get()); } master_anim_popup->set_pos(popup_pos); master_anim_popup->popup(); } else { property_editor->edit(this,"",Variant::OBJECT,anim_tree->animation_node_get_animation(edited_node),PROPERTY_HINT_RESOURCE_TYPE,"Animation"); property_editor->set_pos(popup_pos); property_editor->popup(); updating_edit=false; } return; case AnimationTreePlayer::NODE_TIMESCALE: edit_label[0]->set_text("Scale:"); edit_label[0]->set_pos(Point2(5,5)); edit_label[0]->show(); edit_line[0]->set_begin(Point2(15,25)); edit_line[0]->set_text(rtos(anim_tree->timescale_node_get_scale(edited_node))); edit_line[0]->show(); edit_dialog->set_size(Size2(150,50)); break; case AnimationTreePlayer::NODE_ONESHOT: edit_label[0]->set_text("Fade In (s):"); edit_label[0]->set_pos(Point2(5,5)); edit_label[0]->show(); edit_line[0]->set_begin(Point2(15,25)); edit_line[0]->set_text(rtos(anim_tree->oneshot_node_get_fadein_time(edited_node))); edit_line[0]->show(); edit_label[1]->set_text("Fade Out (s):"); edit_label[1]->set_pos(Point2(5,55)); edit_label[1]->show(); edit_line[1]->set_begin(Point2(15,75)); edit_line[1]->set_text(rtos(anim_tree->oneshot_node_get_fadeout_time(edited_node))); edit_line[1]->show(); edit_option->clear(); edit_option->add_item("Blend",0); edit_option->add_item("Mix",1); edit_option->set_begin(Point2(15,105)); edit_option->select( anim_tree->oneshot_node_get_mix_mode(edited_node)); edit_option->show(); edit_check->set_text("Auto Restart:"); edit_check->set_begin(Point2(15,125)); edit_check->set_pressed(anim_tree->oneshot_node_has_autorestart(edited_node)); edit_check->show(); edit_label[2]->set_text("Restart (s):"); edit_label[2]->set_pos(Point2(5,145)); edit_label[2]->show(); edit_line[2]->set_begin(Point2(15,165)); edit_line[2]->set_text(rtos(anim_tree->oneshot_node_get_autorestart_delay(edited_node))); edit_line[2]->show(); edit_label[3]->set_text("Random Restart (s):"); edit_label[3]->set_pos(Point2(5,195)); edit_label[3]->show(); edit_line[3]->set_begin(Point2(15,215)); edit_line[3]->set_text(rtos(anim_tree->oneshot_node_get_autorestart_random_delay(edited_node))); edit_line[3]->show(); filter_button->set_begin(Point2(10,245)); filter_button->show(); edit_button->set_begin(Point2(10,268)); edit_button->set_text("Start!"); edit_button->show(); edit_dialog->set_size(Size2(180,293)); break; case AnimationTreePlayer::NODE_MIX: edit_label[0]->set_text("Amount:"); edit_label[0]->set_pos(Point2(5,5)); edit_label[0]->show(); edit_scroll[0]->set_min(0); edit_scroll[0]->set_max(1); edit_scroll[0]->set_val(anim_tree->mix_node_get_amount(edited_node)); edit_scroll[0]->set_begin(Point2(15,25)); edit_scroll[0]->show(); edit_dialog->set_size(Size2(150,50)); break; case AnimationTreePlayer::NODE_BLEND2: edit_label[0]->set_text("Blend:"); edit_label[0]->set_pos(Point2(5,5)); edit_label[0]->show(); edit_scroll[0]->set_min(0); edit_scroll[0]->set_max(1); edit_scroll[0]->set_val(anim_tree->blend2_node_get_amount(edited_node)); edit_scroll[0]->set_begin(Point2(15,25)); edit_scroll[0]->show(); filter_button->set_begin(Point2(10,47)); filter_button->show(); edit_dialog->set_size(Size2(150,74)); break; case AnimationTreePlayer::NODE_BLEND3: edit_label[0]->set_text("Blend:"); edit_label[0]->set_pos(Point2(5,5)); edit_label[0]->show(); edit_scroll[0]->set_min(-1); edit_scroll[0]->set_max(1); edit_scroll[0]->set_val(anim_tree->blend3_node_get_amount(edited_node)); edit_scroll[0]->set_begin(Point2(15,25)); edit_scroll[0]->show(); edit_dialog->set_size(Size2(150,50)); break; case AnimationTreePlayer::NODE_BLEND4: edit_label[0]->set_text("Blend 0:"); edit_label[0]->set_pos(Point2(5,5)); edit_label[0]->show(); edit_scroll[0]->set_min(0); edit_scroll[0]->set_max(1); edit_scroll[0]->set_val(anim_tree->blend4_node_get_amount(edited_node).x); edit_scroll[0]->set_begin(Point2(15,25)); edit_scroll[0]->show(); edit_label[1]->set_text("Blend 1:"); edit_label[1]->set_pos(Point2(5,55)); edit_label[1]->show(); edit_scroll[1]->set_min(0); edit_scroll[1]->set_max(1); edit_scroll[1]->set_val(anim_tree->blend4_node_get_amount(edited_node).y); edit_scroll[1]->set_begin(Point2(15,75)); edit_scroll[1]->show(); edit_dialog->set_size(Size2(150,100)); break; case AnimationTreePlayer::NODE_TRANSITION: { edit_label[0]->set_text("X-Fade Time (s):"); edit_label[0]->set_pos(Point2(5,5)); edit_label[0]->show(); edit_line[0]->set_begin(Point2(15,25)); edit_line[0]->set_text(rtos(anim_tree->transition_node_get_xfade_time(edited_node))); edit_line[0]->show(); edit_label[1]->set_text("Current:"); edit_label[1]->set_pos(Point2(5,55)); edit_label[1]->show(); edit_option->set_begin(Point2(15,75)); edit_option->clear();; for(int i=0;i<anim_tree->transition_node_get_input_count(edited_node);i++) { edit_option->add_item(itos(i),i); } edit_option->select(anim_tree->transition_node_get_current(edited_node)); edit_option->show(); edit_dialog->set_size(Size2(150,100)); } break; default: {} } } edit_dialog->set_pos(popup_pos); edit_dialog->popup(); updating_edit=false; }
int get_graph_size(graph_t c_graph) { return get_node_size(c_graph->first) + sizeof(graph); }
void AnimationTreeEditor::_draw_node(const StringName& p_node) { RID ci = get_canvas_item(); AnimationTreePlayer::NodeType type=anim_tree->node_get_type(p_node); Ref<StyleBox> style = get_stylebox("panel","PopupMenu"); Ref<Font> font = get_font("font","PopupMenu"); Color font_color = get_color("font_color","PopupMenu"); Color font_color_title = get_color("font_color_hover","PopupMenu"); font_color_title.a*=0.8; Ref<Texture> slot_icon = get_icon("NodeRealSlot","EditorIcons"); Size2 size=get_node_size(p_node); Point2 pos = anim_tree->node_get_pos(p_node); if (click_type==CLICK_NODE && click_node==p_node) { pos+=click_motion-click_pos; if (pos.x<5) pos.x=5; if (pos.y<5) pos.y=5; } pos-=Point2(h_scroll->get_val(),v_scroll->get_val()); style->draw(ci,Rect2(pos,size)); float w = size.width-style->get_minimum_size().width; float h = font->get_height()+get_constant("vseparation","PopupMenu"); Point2 ofs=style->get_offset()+pos; Point2 ascofs(0,font->get_ascent()); Color bx = font_color_title; bx.a*=0.1; draw_rect(Rect2(ofs,Size2(size.width-style->get_minimum_size().width,font->get_height())),bx); font->draw_halign(ci,ofs+ascofs,HALIGN_CENTER,w,String(_node_type_names[type]),font_color_title); ofs.y+=h; font->draw_halign(ci,ofs+ascofs,HALIGN_CENTER,w,p_node,font_color); ofs.y+=h; int count=2; // title and name int inputs = anim_tree->node_get_input_count(p_node); count += inputs?inputs:1; float icon_h_ofs = Math::floor(( font->get_height()-slot_icon->get_height())/2.0 )+1; if (type!=AnimationTreePlayer::NODE_OUTPUT) slot_icon->draw(ci,ofs+Point2(w,icon_h_ofs)); //output if (inputs) { for(int i=0;i<inputs;i++) { slot_icon->draw(ci,ofs+Point2(-slot_icon->get_width(),icon_h_ofs)); String text; switch(type) { case AnimationTreePlayer::NODE_TIMESCALE: case AnimationTreePlayer::NODE_TIMESEEK: text="in"; break; case AnimationTreePlayer::NODE_OUTPUT: text="out"; break; case AnimationTreePlayer::NODE_ANIMATION: break; case AnimationTreePlayer::NODE_ONESHOT: text=(i==0?"in":"add"); break; case AnimationTreePlayer::NODE_BLEND2: case AnimationTreePlayer::NODE_MIX: text=(i==0?"a":"b"); break; case AnimationTreePlayer::NODE_BLEND3: switch(i) { case 0: text="b-"; break; case 1: text="a"; break; case 2: text="b+"; break; } break; case AnimationTreePlayer::NODE_BLEND4: switch(i) { case 0: text="a0"; break; case 1: text="b0"; break; case 2: text="a1"; break; case 3: text="b1"; break; } break; case AnimationTreePlayer::NODE_TRANSITION: text=itos(i); if (anim_tree->transition_node_has_input_auto_advance(p_node,i)) text+="->"; break; default: {} } font->draw(ci,ofs+ascofs+Point2(3,0),text,font_color); ofs.y+=h; } } else { ofs.y+=h; } Ref<StyleBox> pg_bg=get_stylebox("bg","ProgressBar"); Ref<StyleBox> pg_fill=get_stylebox("fill","ProgressBar"); Rect2 pg_rect(ofs,Size2(w,h)); bool editable=true; switch(type) { case AnimationTreePlayer::NODE_ANIMATION: { Ref<Animation> anim = anim_tree->animation_node_get_animation(p_node); String text; if (anim_tree->animation_node_get_master_animation(p_node)!="") text=anim_tree->animation_node_get_master_animation(p_node); else if (anim.is_null()) text="load.."; else text=anim->get_name(); font->draw_halign(ci,ofs+ascofs,HALIGN_CENTER,w,text,font_color_title); } break; case AnimationTreePlayer::NODE_ONESHOT: case AnimationTreePlayer::NODE_MIX: case AnimationTreePlayer::NODE_BLEND2: case AnimationTreePlayer::NODE_BLEND3: case AnimationTreePlayer::NODE_BLEND4: case AnimationTreePlayer::NODE_TIMESCALE: case AnimationTreePlayer::NODE_TRANSITION: { font->draw_halign(ci,ofs+ascofs,HALIGN_CENTER,w,"edit..",font_color_title); } break; default: editable=false; } if (editable) { Ref<Texture> arrow = get_icon("arrow","Tree"); Point2 arrow_ofs( w-arrow->get_width(),Math::floor( (h-arrow->get_height())/2) ); arrow->draw(ci,ofs+arrow_ofs); } }
static int grub_iso9660_iterate_dir (grub_fshelp_node_t dir, grub_fshelp_iterate_dir_hook_t hook, void *hook_data) { struct grub_iso9660_dir dirent; grub_off_t offset = 0; grub_off_t len; struct iterate_dir_ctx ctx; len = get_node_size (dir); for (; offset < len; offset += dirent.len) { ctx.symlink = 0; ctx.was_continue = 0; if (read_node (dir, offset, sizeof (dirent), (char *) &dirent)) return 0; /* The end of the block, skip to the next one. */ if (!dirent.len) { offset = (offset / GRUB_ISO9660_BLKSZ + 1) * GRUB_ISO9660_BLKSZ; continue; } { char name[MAX_NAMELEN + 1]; int nameoffset = offset + sizeof (dirent); struct grub_fshelp_node *node; int sua_off = (sizeof (dirent) + dirent.namelen + 1 - (dirent.namelen % 2)); int sua_size = dirent.len - sua_off; sua_off += offset + dir->data->susp_skip; ctx.filename = 0; ctx.filename_alloc = 0; ctx.type = GRUB_FSHELP_UNKNOWN; if (dir->data->rockridge && grub_iso9660_susp_iterate (dir, sua_off, sua_size, susp_iterate_dir, &ctx)) return 0; /* Read the name. */ if (read_node (dir, nameoffset, dirent.namelen, (char *) name)) return 0; node = grub_malloc (sizeof (struct grub_fshelp_node)); if (!node) return 0; node->alloc_dirents = ARRAY_SIZE (node->dirents); node->have_dirents = 1; /* Setup a new node. */ node->data = dir->data; node->have_symlink = 0; /* If the filetype was not stored using rockridge, use whatever is stored in the iso9660 filesystem. */ if (ctx.type == GRUB_FSHELP_UNKNOWN) { if ((dirent.flags & FLAG_TYPE) == FLAG_TYPE_DIR) ctx.type = GRUB_FSHELP_DIR; else ctx.type = GRUB_FSHELP_REG; } /* . and .. */ if (!ctx.filename && dirent.namelen == 1 && name[0] == 0) ctx.filename = (char *) "."; if (!ctx.filename && dirent.namelen == 1 && name[0] == 1) ctx.filename = (char *) ".."; /* The filename was not stored in a rock ridge entry. Read it from the iso9660 filesystem. */ if (!dir->data->joliet && !ctx.filename) { char *ptr; name[dirent.namelen] = '\0'; ctx.filename = grub_strrchr (name, ';'); if (ctx.filename) *ctx.filename = '\0'; /* ISO9660 names are not case-preserving. */ ctx.type |= GRUB_FSHELP_CASE_INSENSITIVE; for (ptr = name; *ptr; ptr++) *ptr = grub_tolower (*ptr); if (ptr != name && *(ptr - 1) == '.') *(ptr - 1) = 0; ctx.filename = name; } if (dir->data->joliet && !ctx.filename) { char *semicolon; ctx.filename = grub_iso9660_convert_string ((grub_uint8_t *) name, dirent.namelen >> 1); semicolon = grub_strrchr (ctx.filename, ';'); if (semicolon) *semicolon = '\0'; ctx.filename_alloc = 1; } node->dirents[0] = dirent; while (dirent.flags & FLAG_MORE_EXTENTS) { offset += dirent.len; if (read_node (dir, offset, sizeof (dirent), (char *) &dirent)) { if (ctx.filename_alloc) grub_free (ctx.filename); grub_free (node); return 0; } if (node->have_dirents >= node->alloc_dirents) { struct grub_fshelp_node *new_node; node->alloc_dirents *= 2; new_node = grub_realloc (node, sizeof (struct grub_fshelp_node) + ((node->alloc_dirents - ARRAY_SIZE (node->dirents)) * sizeof (node->dirents[0]))); if (!new_node) { if (ctx.filename_alloc) grub_free (ctx.filename); grub_free (node); return 0; } node = new_node; } node->dirents[node->have_dirents++] = dirent; } if (ctx.symlink) { if ((node->alloc_dirents - node->have_dirents) * sizeof (node->dirents[0]) < grub_strlen (ctx.symlink) + 1) { struct grub_fshelp_node *new_node; new_node = grub_realloc (node, sizeof (struct grub_fshelp_node) + ((node->alloc_dirents - ARRAY_SIZE (node->dirents)) * sizeof (node->dirents[0])) + grub_strlen (ctx.symlink) + 1); if (!new_node) { if (ctx.filename_alloc) grub_free (ctx.filename); grub_free (node); return 0; } node = new_node; } node->have_symlink = 1; grub_strcpy (node->symlink + node->have_dirents * sizeof (node->dirents[0]) - sizeof (node->dirents), ctx.symlink); grub_free (ctx.symlink); ctx.symlink = 0; ctx.was_continue = 0; } if (hook (ctx.filename, ctx.type, node, hook_data)) { if (ctx.filename_alloc) grub_free (ctx.filename); return 1; } if (ctx.filename_alloc) grub_free (ctx.filename); } }
void ShaderEditor::_draw_node(int p_node) { VisualServer::ShaderNodeType type=shader_graph.node_get_type(p_node); Ref<StyleBox> style = active_nodes.has(p_node)?get_stylebox("panel","PopupMenu"):get_stylebox("panel_disabled","PopupMenu"); Ref<Font> font = get_font("font","PopupMenu"); Color font_color = get_color("font_color","PopupMenu"); Color font_color_title = get_color("font_color_hover","PopupMenu"); Size2 size=get_node_size(p_node); Point2 pos = Point2( shader_graph.node_get_pos_x(p_node), shader_graph.node_get_pos_y(p_node) )-offset; if (click_type==CLICK_NODE && click_node==p_node) { pos+=click_motion-click_pos; } RID ci = get_canvas_item(); style->draw(ci,Rect2(pos,size)); Point2 ofs=style->get_offset()+pos; Point2 ascent=Point2(0,font->get_ascent()); float w = size.width-style->get_minimum_size().width; float h = font->get_height()+get_constant("vseparation","PopupMenu"); font->draw_halign( ci, ofs+ascent, HALIGN_CENTER,w, VisualServer::shader_node_get_type_info(type).name,font_color_title); ofs.y+=h; Ref<Texture> vec_icon = get_icon("NodeVecSlot","EditorIcons"); Ref<Texture> real_icon = get_icon("NodeRealSlot","EditorIcons"); float icon_h_ofs = Math::floor(( font->get_height()-vec_icon->get_height())/2.0 )+1; for(int i=0;i<VisualServer::shader_get_input_count(type);i++) { String name = VisualServer::shader_get_input_name(type,i); font->draw_halign( ci, ofs+ascent, HALIGN_LEFT,w, name,font_color); Ref<Texture> icon = VisualServer::shader_is_input_vector(type,i)?vec_icon:real_icon; icon->draw(ci,ofs+Point2(-real_icon->get_width(),icon_h_ofs)); ofs.y+=h; } for(int i=0;i<VisualServer::shader_get_output_count(type);i++) { String name = VisualServer::shader_get_output_name(type,i); font->draw_halign( ci, ofs+ascent, HALIGN_RIGHT,w, name,font_color); Ref<Texture> icon = VisualServer::shader_is_output_vector(type,i)?vec_icon:real_icon; icon->draw(ci,ofs+Point2(w,icon_h_ofs)); ofs.y+=h; } switch(type) { case VS::NODE_IN: case VS::NODE_OUT: case VS::NODE_PARAMETER: case VS::NODE_VEC_IN: case VS::NODE_COLOR_PARAMETER: case VS::NODE_VEC_OUT: case VS::NODE_TEXTURE_PARAMETER: case VS::NODE_TEXTURE_2D_PARAMETER: case VS::NODE_TEXTURE_CUBE_PARAMETER: case VS::NODE_TRANSFORM_CONSTANT: case VS::NODE_TRANSFORM_PARAMETER: case VS::NODE_VEC_PARAMETER: case VS::NODE_LABEL: { String text = shader_graph.node_get_param(p_node); font->draw_halign( ci, ofs+ascent, HALIGN_CENTER,w, text,font_color); } break; case VS::NODE_TIME: case VS::NODE_CONSTANT: { String text = rtos(shader_graph.node_get_param(p_node)); font->draw_halign( ci, ofs+ascent, HALIGN_CENTER,w, text,font_color); } break; case VS::NODE_VEC_CONSTANT: { String text = Vector3(shader_graph.node_get_param(p_node)); font->draw_halign( ci, ofs+ascent, HALIGN_CENTER,w, text,font_color); } break; case VS::NODE_COLOR_CONSTANT: { Color color = shader_graph.node_get_param(p_node); Rect2 r(ofs,Size2(w,h)); VisualServer::get_singleton()->canvas_item_add_rect(ci,r,color); } break; case VS::NODE_TEXTURE: case VS::NODE_VEC_TEXTURE_2D: case VS::NODE_VEC_TEXTURE_CUBE: { Rect2 r(ofs,Size2(w,(pos.y+size.y-style->get_margin(MARGIN_BOTTOM))-ofs.y)); Vector<Point2> points; Vector<Point2> uvs; points.resize(4); uvs.resize(4); points[0]=r.pos; points[1]=r.pos+Point2(r.size.x,0); points[2]=r.pos+r.size; points[3]=r.pos+Point2(0,r.size.y); uvs[0]=Point2(0,0); uvs[1]=Point2(1,0); uvs[2]=Point2(1,1); uvs[3]=Point2(0,1); Ref<Texture> texture = shader_graph.node_get_param(p_node).operator RefPtr(); if (texture.is_null() || texture->get_width()==0) { texture=get_icon("Click2Edit","EditorIcons"); } VisualServer::get_singleton()->canvas_item_add_primitive(ci,points,Vector<Color>(),uvs,texture->get_rid()); } break; default: {} } }