当前位置: 首页>>代码示例>>C++>>正文


C++ GraphNode::is_selected方法代码示例

本文整理汇总了C++中GraphNode::is_selected方法的典型用法代码示例。如果您正苦于以下问题:C++ GraphNode::is_selected方法的具体用法?C++ GraphNode::is_selected怎么用?C++ GraphNode::is_selected使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GraphNode的用法示例。


在下文中一共展示了GraphNode::is_selected方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: _input_event

void GraphEdit::_input_event(const InputEvent& p_ev) {

	if (p_ev.type==InputEvent::MOUSE_MOTION && (p_ev.mouse_motion.button_mask&BUTTON_MASK_MIDDLE || (p_ev.mouse_motion.button_mask&BUTTON_MASK_LEFT && Input::get_singleton()->is_key_pressed(KEY_SPACE)))) {
		h_scroll->set_val( h_scroll->get_val() - p_ev.mouse_motion.relative_x );
		v_scroll->set_val( v_scroll->get_val() - p_ev.mouse_motion.relative_y );
	}

	if (p_ev.type==InputEvent::MOUSE_MOTION && dragging) {

		just_selected=true;
		drag_accum+=Vector2(p_ev.mouse_motion.relative_x,p_ev.mouse_motion.relative_y);
		for(int i=get_child_count()-1;i>=0;i--) {
			GraphNode *gn=get_child(i)->cast_to<GraphNode>();
			if (gn && gn->is_selected())
				gn->set_offset(gn->get_drag_from()+drag_accum);
		}
	}

	if (p_ev.type==InputEvent::MOUSE_MOTION && box_selecting) {
		box_selecting_to = get_local_mouse_pos();

		box_selecting_rect = Rect2(MIN(box_selecting_from.x,box_selecting_to.x),
								   MIN(box_selecting_from.y,box_selecting_to.y),
								   ABS(box_selecting_from.x-box_selecting_to.x),
								   ABS(box_selecting_from.y-box_selecting_to.y));

		for(int i=get_child_count()-1;i>=0;i--) {

			GraphNode *gn=get_child(i)->cast_to<GraphNode>();
			if (!gn)
				continue;

			bool in_box = gn->get_rect().intersects(box_selecting_rect);

			if (in_box)
				gn->set_selected(box_selection_mode_aditive);
			else
				gn->set_selected(previus_selected.find(gn)!=NULL);
		}

		top_layer->update();
	}

	if (p_ev.type==InputEvent::MOUSE_BUTTON) {

		const InputEventMouseButton &b=p_ev.mouse_button;

		if (b.button_index==BUTTON_RIGHT && b.pressed)
		{
			if (box_selecting) {
				box_selecting = false;
				for(int i=get_child_count()-1;i>=0;i--) {

					GraphNode *gn=get_child(i)->cast_to<GraphNode>();
					if (!gn)
						continue;

					gn->set_selected(previus_selected.find(gn)!=NULL);
				}
				top_layer->update();
			} else {
				emit_signal("popup_request", Vector2(b.global_x, b.global_y));
			}
		}

		if (b.button_index==BUTTON_LEFT && !b.pressed && dragging) {
			if (!just_selected && drag_accum==Vector2() && Input::get_singleton()->is_key_pressed(KEY_CONTROL)) {
				//deselect current node
				for(int i=get_child_count()-1;i>=0;i--) {
					GraphNode *gn=get_child(i)->cast_to<GraphNode>();

					if (gn && gn->get_rect().has_point(get_local_mouse_pos()))
						gn->set_selected(false);
				}
			}

			if (drag_accum!=Vector2()) {

				emit_signal("_begin_node_move");

				for(int i=get_child_count()-1;i>=0;i--) {
					GraphNode *gn=get_child(i)->cast_to<GraphNode>();
					if (gn && gn->is_selected())
						gn->set_drag(false);
				}

				emit_signal("_end_node_move");
			}

			dragging = false;

			top_layer->update();
		}

		if (b.button_index==BUTTON_LEFT && b.pressed) {

			GraphNode *gn;
			for(int i=get_child_count()-1;i>=0;i--) {

				gn=get_child(i)->cast_to<GraphNode>();
//.........这里部分代码省略.........
开发者ID:Scrik,项目名称:godot,代码行数:101,代码来源:graph_edit.cpp

示例2: _gui_input

void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {

	Ref<InputEventMouseMotion> mm = p_ev;
	if (mm.is_valid() && (mm->get_button_mask() & BUTTON_MASK_MIDDLE || (mm->get_button_mask() & BUTTON_MASK_LEFT && Input::get_singleton()->is_key_pressed(KEY_SPACE)))) {
		h_scroll->set_value(h_scroll->get_value() - mm->get_relative().x);
		v_scroll->set_value(v_scroll->get_value() - mm->get_relative().y);
	}

	if (mm.is_valid() && dragging) {

		just_selected = true;
		// TODO: Remove local mouse pos hack if/when InputEventMouseMotion is fixed to support floats
		//drag_accum+=Vector2(mm->get_relative().x,mm->get_relative().y);
		drag_accum = get_local_mouse_position() - drag_origin;
		for (int i = get_child_count() - 1; i >= 0; i--) {
			GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
			if (gn && gn->is_selected()) {

				Vector2 pos = (gn->get_drag_from() * zoom + drag_accum) / zoom;
				if (is_using_snap()) {
					int snap = get_snap();
					pos = pos.snapped(Vector2(snap, snap));
				}

				gn->set_offset(pos);
			}
		}
	}

	if (mm.is_valid() && box_selecting) {
		box_selecting_to = get_local_mouse_position();

		box_selecting_rect = Rect2(MIN(box_selecting_from.x, box_selecting_to.x),
				MIN(box_selecting_from.y, box_selecting_to.y),
				ABS(box_selecting_from.x - box_selecting_to.x),
				ABS(box_selecting_from.y - box_selecting_to.y));

		for (int i = get_child_count() - 1; i >= 0; i--) {

			GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
			if (!gn)
				continue;

			Rect2 r = gn->get_rect();
			r.size *= zoom;
			bool in_box = r.intersects(box_selecting_rect);

			if (in_box)
				gn->set_selected(box_selection_mode_aditive);
			else
				gn->set_selected(previus_selected.find(gn) != NULL);
		}

		top_layer->update();
	}

	Ref<InputEventMouseButton> b = p_ev;
	if (b.is_valid()) {

		if (b->get_button_index() == BUTTON_RIGHT && b->is_pressed()) {
			if (box_selecting) {
				box_selecting = false;
				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(previus_selected.find(gn) != NULL);
				}
				top_layer->update();
			} else {
				if (connecting) {
					connecting = false;
					top_layer->update();
				} else {
					emit_signal("popup_request", b->get_global_position());
				}
			}
		}

		if (b->get_button_index() == BUTTON_LEFT && !b->is_pressed() && dragging) {
			if (!just_selected && drag_accum == Vector2() && Input::get_singleton()->is_key_pressed(KEY_CONTROL)) {
				//deselect current node
				for (int i = get_child_count() - 1; i >= 0; i--) {
					GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));

					if (gn) {
						Rect2 r = gn->get_rect();
						r.size *= zoom;
						if (r.has_point(get_local_mouse_position()))
							gn->set_selected(false);
					}
				}
			}

			if (drag_accum != Vector2()) {

				emit_signal("_begin_node_move");

//.........这里部分代码省略.........
开发者ID:UgisBrekis,项目名称:godot,代码行数:101,代码来源:graph_edit.cpp

示例3: _duplicate_nodes

void VisualShaderEditor::_duplicate_nodes() {

	VisualShader::Type type = VisualShader::Type(edit_type->get_selected());

	List<int> nodes;
	Set<int> excluded;

	for (int i = 0; i < graph->get_child_count(); i++) {

		GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i));
		if (gn) {
			int id = String(gn->get_name()).to_int();
			Ref<VisualShaderNode> node = visual_shader->get_node(type, id);
			Ref<VisualShaderNodeOutput> output = node;
			if (output.is_valid()) { // can't duplicate output
				excluded.insert(id);
				continue;
			}
			if (node.is_valid() && gn->is_selected()) {
				nodes.push_back(id);
			}
			excluded.insert(id);
		}
	}

	if (nodes.empty())
		return;

	undo_redo->create_action(TTR("Duplicate Nodes"));

	int base_id = visual_shader->get_valid_node_id(type);
	int id_from = base_id;
	Map<int, int> connection_remap;

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

		connection_remap[E->get()] = id_from;
		Ref<VisualShaderNode> node = visual_shader->get_node(type, E->get());

		Ref<VisualShaderNode> dupli = node->duplicate();

		undo_redo->add_do_method(visual_shader.ptr(), "add_node", type, dupli, visual_shader->get_node_position(type, E->get()) + Vector2(10, 10) * EDSCALE, id_from);
		undo_redo->add_undo_method(visual_shader.ptr(), "remove_node", type, id_from);

		id_from++;
	}

	List<VisualShader::Connection> conns;
	visual_shader->get_node_connections(type, &conns);

	for (List<VisualShader::Connection>::Element *E = conns.front(); E; E = E->next()) {
		if (connection_remap.has(E->get().from_node) && connection_remap.has(E->get().to_node)) {
			undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes", type, connection_remap[E->get().from_node], E->get().from_port, connection_remap[E->get().to_node], E->get().to_port);
		}
	}

	undo_redo->add_do_method(this, "_update_graph");
	undo_redo->add_undo_method(this, "_update_graph");
	undo_redo->commit_action();

	// reselect duplicated nodes by excluding the other ones
	for (int i = 0; i < graph->get_child_count(); i++) {

		GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i));
		if (gn) {
			int id = String(gn->get_name()).to_int();
			if (!excluded.has(id)) {
				gn->set_selected(true);
			} else {
				gn->set_selected(false);
			}
		}
	}
}
开发者ID:UgisBrekis,项目名称:godot,代码行数:74,代码来源:visual_shader_editor_plugin.cpp

示例4: _gui_input

void GraphEdit::_gui_input(const InputEvent &p_ev) {

	if (p_ev.type == InputEvent::MOUSE_MOTION && (p_ev.mouse_motion.button_mask & BUTTON_MASK_MIDDLE || (p_ev.mouse_motion.button_mask & BUTTON_MASK_LEFT && Input::get_singleton()->is_key_pressed(KEY_SPACE)))) {
		h_scroll->set_value(h_scroll->get_value() - p_ev.mouse_motion.relative_x);
		v_scroll->set_value(v_scroll->get_value() - p_ev.mouse_motion.relative_y);
	}

	if (p_ev.type == InputEvent::MOUSE_MOTION && dragging) {

		just_selected = true;
		// TODO: Remove local mouse pos hack if/when InputEventMouseMotion is fixed to support floats
		//drag_accum+=Vector2(p_ev.mouse_motion.relative_x,p_ev.mouse_motion.relative_y);
		drag_accum = get_local_mouse_pos() - drag_origin;
		for (int i = get_child_count() - 1; i >= 0; i--) {
			GraphNode *gn = get_child(i)->cast_to<GraphNode>();
			if (gn && gn->is_selected()) {

				Vector2 pos = (gn->get_drag_from() * zoom + drag_accum) / zoom;
				if (is_using_snap()) {
					int snap = get_snap();
					pos = pos.snapped(Vector2(snap, snap));
				}

				gn->set_offset(pos);
			}
		}
	}

	if (p_ev.type == InputEvent::MOUSE_MOTION && box_selecting) {
		box_selecting_to = get_local_mouse_pos();

		box_selecting_rect = Rect2(MIN(box_selecting_from.x, box_selecting_to.x),
				MIN(box_selecting_from.y, box_selecting_to.y),
				ABS(box_selecting_from.x - box_selecting_to.x),
				ABS(box_selecting_from.y - box_selecting_to.y));

		for (int i = get_child_count() - 1; i >= 0; i--) {

			GraphNode *gn = get_child(i)->cast_to<GraphNode>();
			if (!gn)
				continue;

			Rect2 r = gn->get_rect();
			r.size *= zoom;
			bool in_box = r.intersects(box_selecting_rect);

			if (in_box)
				gn->set_selected(box_selection_mode_aditive);
			else
				gn->set_selected(previus_selected.find(gn) != NULL);
		}

		top_layer->update();
	}

	if (p_ev.type == InputEvent::MOUSE_BUTTON) {

		const InputEventMouseButton &b = p_ev.mouse_button;

		if (b.button_index == BUTTON_RIGHT && b.pressed) {
			if (box_selecting) {
				box_selecting = false;
				for (int i = get_child_count() - 1; i >= 0; i--) {

					GraphNode *gn = get_child(i)->cast_to<GraphNode>();
					if (!gn)
						continue;

					gn->set_selected(previus_selected.find(gn) != NULL);
				}
				top_layer->update();
			} else {
				if (connecting) {
					connecting = false;
					top_layer->update();
				} else {
					emit_signal("popup_request", Vector2(b.global_x, b.global_y));
				}
			}
		}

		if (b.button_index == BUTTON_LEFT && !b.pressed && dragging) {
			if (!just_selected && drag_accum == Vector2() && Input::get_singleton()->is_key_pressed(KEY_CONTROL)) {
				//deselect current node
				for (int i = get_child_count() - 1; i >= 0; i--) {
					GraphNode *gn = get_child(i)->cast_to<GraphNode>();

					if (gn) {
						Rect2 r = gn->get_rect();
						r.size *= zoom;
						if (r.has_point(get_local_mouse_pos()))
							gn->set_selected(false);
					}
				}
			}

			if (drag_accum != Vector2()) {

				emit_signal("_begin_node_move");

//.........这里部分代码省略.........
开发者ID:MattUV,项目名称:godot,代码行数:101,代码来源:graph_edit.cpp


注:本文中的GraphNode::is_selected方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。