예제 #1
0
void GraphEdit::_connections_layer_draw() {

	Color activity_color = get_color("activity");
	//draw connections
	List<List<Connection>::Element *> to_erase;
	for (List<Connection>::Element *E = connections.front(); E; E = E->next()) {

		NodePath fromnp(E->get().from);

		Node *from = get_node(fromnp);
		if (!from) {
			to_erase.push_back(E);
			continue;
		}

		GraphNode *gfrom = Object::cast_to<GraphNode>(from);

		if (!gfrom) {
			to_erase.push_back(E);
			continue;
		}

		NodePath tonp(E->get().to);
		Node *to = get_node(tonp);
		if (!to) {
			to_erase.push_back(E);
			continue;
		}

		GraphNode *gto = Object::cast_to<GraphNode>(to);

		if (!gto) {
			to_erase.push_back(E);
			continue;
		}

		Vector2 frompos = gfrom->get_connection_output_position(E->get().from_port) + gfrom->get_offset() * zoom;
		Color color = gfrom->get_connection_output_color(E->get().from_port);
		Vector2 topos = gto->get_connection_input_position(E->get().to_port) + gto->get_offset() * zoom;
		Color tocolor = gto->get_connection_input_color(E->get().to_port);

		if (E->get().activity > 0) {
			color = color.linear_interpolate(activity_color, E->get().activity);
			tocolor = tocolor.linear_interpolate(activity_color, E->get().activity);
		}
		_draw_cos_line(connections_layer, frompos, topos, color, tocolor);
	}

	while (to_erase.size()) {
		connections.erase(to_erase.front()->get());
		to_erase.pop_front();
	}
}
예제 #2
0
void GraphEdit::_top_layer_draw() {

	_update_scroll();

	if (connecting) {

		Node *fromn = get_node(connecting_from);
		ERR_FAIL_COND(!fromn);
		GraphNode *from = Object::cast_to<GraphNode>(fromn);
		ERR_FAIL_COND(!from);
		Vector2 pos;
		if (connecting_out)
			pos = from->get_connection_output_position(connecting_index);
		else
			pos = from->get_connection_input_position(connecting_index);
		pos += from->get_position();

		Vector2 topos;
		topos = connecting_to;

		Color col = connecting_color;

		if (connecting_target) {
			col.r += 0.4;
			col.g += 0.4;
			col.b += 0.4;
		}

		if (!connecting_out) {
			SWAP(pos, topos);
		}
		_draw_cos_line(top_layer, pos, topos, col, col);
	}

	if (box_selecting)
		top_layer->draw_rect(box_selecting_rect, Color(0.7, 0.7, 1.0, 0.3));
}
예제 #3
0
파일: graph_edit.cpp 프로젝트: Scrik/godot
void GraphEdit::_top_layer_draw() {

	_update_scroll();

	if (connecting) {

		Node *fromn = get_node(connecting_from);
		ERR_FAIL_COND(!fromn);
		GraphNode *from = fromn->cast_to<GraphNode>();
		ERR_FAIL_COND(!from);
		Vector2 pos;
		if (connecting_out)
			pos=from->get_connection_output_pos(connecting_index);
		else
			pos=from->get_connection_input_pos(connecting_index);
		pos+=from->get_pos();

		Vector2 topos;
		topos=connecting_to;

		Color col=connecting_color;

		if (connecting_target) {
			col.r+=0.4;
			col.g+=0.4;
			col.b+=0.4;
		}
		_draw_cos_line(pos,topos,col);
	}

	List<List<Connection>::Element* > to_erase;
	for(List<Connection>::Element *E=connections.front();E;E=E->next()) {

		NodePath fromnp(E->get().from);

		Node * from = get_node(fromnp);
		if (!from) {
			to_erase.push_back(E);
			continue;
		}

		GraphNode *gfrom = from->cast_to<GraphNode>();

		if (!gfrom) {
			to_erase.push_back(E);
			continue;
		}

		NodePath tonp(E->get().to);
		Node * to = get_node(tonp);
		if (!to) {
			to_erase.push_back(E);
			continue;
		}

		GraphNode *gto = to->cast_to<GraphNode>();

		if (!gto) {
			to_erase.push_back(E);
			continue;
		}

		Vector2 frompos=gfrom->get_connection_output_pos(E->get().from_port)+gfrom->get_pos();
		Color color = gfrom->get_connection_output_color(E->get().from_port);
		Vector2 topos=gto->get_connection_input_pos(E->get().to_port)+gto->get_pos();
		_draw_cos_line(frompos,topos,color);

	}

	while(to_erase.size()) {
		connections.erase(to_erase.front()->get());
		to_erase.pop_front();
	}
	if (box_selecting)
		top_layer->draw_rect(box_selecting_rect,Color(0.7,0.7,1.0,0.3));
}
예제 #4
0
void AnimationTreeEditor::_notification(int p_what) {


	switch(p_what) {

		case NOTIFICATION_ENTER_TREE: {

			play_button->set_icon( get_icon("Play","EditorIcons") );
			add_menu->set_icon( get_icon("Add","EditorIcons") );
		} break;
		case NOTIFICATION_DRAW: {


			_update_scrollbars();
			//VisualServer::get_singleton()->canvas_item_add_rect(get_canvas_item(),Rect2(Point2(),get_size()),Color(0,0,0,1));
			get_stylebox("bg","Tree")->draw(get_canvas_item(),Rect2(Point2(),get_size()));
			VisualServer::get_singleton()->canvas_item_set_clip(get_canvas_item(),true);

			for(List<StringName>::Element *E=order.front();E;E=E->next()) {

				_draw_node(E->get());
			}

			if (click_type==CLICK_INPUT_SLOT || click_type==CLICK_OUTPUT_SLOT) {

				_draw_cos_line(click_pos,click_motion,Color(0.5,1,0.5,0.8));
			}

			List<AnimationTreePlayer::Connection> connections;
			anim_tree->get_connection_list(&connections);

			for(List<AnimationTreePlayer::Connection>::Element *E=connections.front();E;E=E->next()) {

				const AnimationTreePlayer::Connection &c=E->get();
				Point2 source = _get_slot_pos(c.src_node,false,0);
				Point2 dest = _get_slot_pos(c.dst_node,true,c.dst_input);
				Color col = Color(1,1,0.5,0.8);
/*
				if (click_type==CLICK_NODE && click_node==c.src_node) {

					source+=click_motion-click_pos;
				}

				if (click_type==CLICK_NODE && click_node==c.dst_node) {

					dest+=click_motion-click_pos;
				}*/

				_draw_cos_line(source,dest,col);

			}

			switch(anim_tree->get_last_error()) {

				case AnimationTreePlayer::CONNECT_OK: {

					Ref<Font> f = get_font("font","Label");
					f->draw(get_canvas_item(),Point2(5,25+f->get_ascent()),"Animation Tree is Valid.",Color(0,1,0.6,0.8));
				} break;
				default: {

					   Ref<Font> f = get_font("font","Label");
					   f->draw(get_canvas_item(),Point2(5,25+f->get_ascent()),"Animation Tree is Invalid.",Color(1,0.6,0.0,0.8));
				} break;
			}

		} break;
	}

}