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


C++ Rect2类代码示例

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


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

示例1: get_stylebox

int ItemList::get_item_at_pos(const Point2& p_pos) const {

	Vector2 pos=p_pos;
	Ref<StyleBox> bg = get_stylebox("bg");
	pos-=bg->get_offset();
	pos.y+=scroll_bar->get_val();

	int closest = -1;
	int closest_dist=0x7FFFFFFF;

	for(int i=0;i<items.size();i++) {

		Rect2 rc = items[i].rect_cache;
		if (i%current_columns==current_columns-1) {
			rc.size.width=get_size().width; //not right but works
		}

		if (rc.has_point(pos)) {
			closest=i;
			break;
		}

		float dist = rc.distance_to(pos);
		if (dist<closest_dist) {
			closest=i;
			closest_dist=dist;
		}
	}

	return closest;
}
开发者ID:HaoDrang,项目名称:godot,代码行数:31,代码来源:item_list.cpp

示例2: is_in_hot_zone

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;
}
开发者ID:UgisBrekis,项目名称:godot,代码行数:28,代码来源:graph_edit.cpp

示例3: ep

void Particles2DEditorPlugin::_generate_visibility_rect() {

	float time = generate_seconds->get_value();

	float running = 0.0;

	EditorProgress ep("gen_aabb", TTR("Generating AABB"), int(time));

	Rect2 rect;
	while (running < time) {

		uint64_t ticks = OS::get_singleton()->get_ticks_usec();
		ep.step("Generating..", int(running), true);
		OS::get_singleton()->delay_usec(1000);

		Rect2 capture = particles->capture_rect();
		if (rect == Rect2())
			rect = capture;
		else
			rect = rect.merge(capture);

		running += (OS::get_singleton()->get_ticks_usec() - ticks) / 1000000.0;
	}

	particles->set_visibility_rect(rect);
}
开发者ID:Ranakhamis,项目名称:godot,代码行数:26,代码来源:particles_2d_editor_plugin.cpp

示例4: _draw_cos_line

void GraphEdit::_draw_cos_line(const Vector2& p_from, const Vector2& p_to,const Color& p_color) {

	static const int steps = 20;

	Rect2 r;
	r.pos=p_from;
	r.expand_to(p_to);
	Vector2 sign=Vector2((p_from.x < p_to.x) ? 1 : -1,(p_from.y < p_to.y) ? 1 : -1);
	bool flip = sign.x * sign.y < 0;

	Vector2 prev;
	for(int i=0;i<=steps;i++) {

		float d = i/float(steps);
		float c=-Math::cos(d*Math_PI) * 0.5+0.5;
		if (flip)
			c=1.0-c;
		Vector2 p = r.pos+Vector2(d*r.size.width,c*r.size.height);

		if (i>0) {

			top_layer->draw_line(prev,p,p_color,2);
		}

		prev=p;
	}
}
开发者ID:Scrik,项目名称:godot,代码行数:27,代码来源:graph_edit.cpp

示例5: get_selected_tile

void TileMapEditor::_update_palette() {

	if (!node)
		return;

	int selected = get_selected_tile();
	palette->clear();

	Ref<TileSet> tileset=node->get_tileset();
	if (tileset.is_null())
		return;

	List<int> tiles;
	tileset->get_tile_list(&tiles);

	if (tiles.empty())
		return;

	palette->set_max_columns(0);
	palette->set_icon_mode(ItemList::ICON_MODE_TOP);
	palette->set_max_text_lines(2);

	String filter = search_box->get_text().strip_edges();

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

		String name;

		if (tileset->tile_get_name(E->get())!="") {
			name = tileset->tile_get_name(E->get());
		} else {
			name = "#"+itos(E->get());
		}

		if (filter != "" && name.findn(filter) == -1)
			continue;

		palette->add_item(name);

		Ref<Texture> tex = tileset->tile_get_texture(E->get());

		if (tex.is_valid()) {
			Rect2 region = tileset->tile_get_region(E->get());

			if (!region.has_no_area())
				palette->set_item_icon_region(palette->get_item_count()-1, region);

			palette->set_item_icon(palette->get_item_count()-1, tex);
		}

		palette->set_item_metadata(palette->get_item_count()-1, E->get());
	}

	if (selected != -1)
		set_selected_tile(selected);
	else
		palette->select(0, true);
}
开发者ID:baifang,项目名称:godot,代码行数:58,代码来源:tile_map_editor_plugin.cpp

示例6: ERR_FAIL_COND_V

bool Physics2DDirectSpaceStateSW::rest_info(RID p_shape, const Matrix32& p_shape_xform,const Vector2& p_motion,float p_margin,ShapeRestInfo *r_info, const Set<RID>& p_exclude,uint32_t p_layer_mask,uint32_t p_object_type_mask) {


	Shape2DSW *shape = static_cast<Physics2DServerSW*>(Physics2DServer::get_singleton())->shape_owner.get(p_shape);
	ERR_FAIL_COND_V(!shape,0);

	Rect2 aabb = p_shape_xform.xform(shape->get_aabb());
	aabb=aabb.merge(Rect2(aabb.pos+p_motion,aabb.size)); //motion
	aabb=aabb.grow(p_margin);

	int amount = space->broadphase->cull_aabb(aabb,space->intersection_query_results,Space2DSW::INTERSECTION_QUERY_MAX,space->intersection_query_subindex_results);

	_RestCallbackData rcd;
	rcd.best_len=0;
	rcd.best_object=NULL;
	rcd.best_shape=0;

	for(int i=0;i<amount;i++) {


		if (!_match_object_type_query(space->intersection_query_results[i],p_layer_mask,p_object_type_mask))
			continue;

		const CollisionObject2DSW *col_obj=space->intersection_query_results[i];
		int shape_idx=space->intersection_query_subindex_results[i];

		if (p_exclude.has( col_obj->get_self() ))
			continue;

		rcd.object=col_obj;
		rcd.shape=shape_idx;
		bool sc = CollisionSolver2DSW::solve(shape,p_shape_xform,p_motion,col_obj->get_shape(shape_idx),col_obj->get_transform() * col_obj->get_shape_transform(shape_idx),Vector2() ,_rest_cbk_result,&rcd,NULL,p_margin);
		if (!sc)
			continue;


	}

	if (rcd.best_len==0)
		return false;

	r_info->collider_id=rcd.best_object->get_instance_id();
	r_info->shape=rcd.best_shape;
	r_info->normal=rcd.best_normal;
	r_info->point=rcd.best_contact;
	r_info->rid=rcd.best_object->get_self();
	if (rcd.best_object->get_type()==CollisionObject2DSW::TYPE_BODY) {

		const Body2DSW *body = static_cast<const Body2DSW*>(rcd.best_object);
		Vector2 rel_vec = r_info->point-body->get_transform().get_origin();
		r_info->linear_velocity = Vector2(-body->get_angular_velocity() * rel_vec.y, body->get_angular_velocity() * rel_vec.x) + body->get_linear_velocity();

	} else {
		r_info->linear_velocity=Vector2();
	}

	return true;
}
开发者ID:9cat,项目名称:godot,代码行数:58,代码来源:space_2d_sw.cpp

示例7: ERR_FAIL_COND

void ConvexPolygonShape2DSW::set_data(const Variant& p_data) {

	ERR_FAIL_COND(p_data.get_type()!=Variant::VECTOR2_ARRAY && p_data.get_type()!=Variant::REAL_ARRAY);


	if (points)
		memdelete_arr(points);
	points=NULL;
	point_count=0;

	if (p_data.get_type()==Variant::VECTOR2_ARRAY) {
		DVector<Vector2> arr=p_data;
		ERR_FAIL_COND(arr.size()==0);
		point_count=arr.size();
		points = memnew_arr(Point,point_count);
		DVector<Vector2>::Read r = arr.read();

		for(int i=0;i<point_count;i++) {
			points[i].pos=r[i];
		}

		for(int i=0;i<point_count;i++) {

			Vector2 p = points[i].pos;
			Vector2 pn = points[(i+1)%point_count].pos;
			points[i].normal=(pn-p).tangent().normalized();
		}
	} else {

		DVector<real_t> dvr = p_data;
		point_count=dvr.size()/4;
		ERR_FAIL_COND(point_count==0);

		points = memnew_arr(Point,point_count);
		DVector<real_t>::Read r = dvr.read();

		for(int i=0;i<point_count;i++) {

			int idx=i<<2;
			points[i].pos.x=r[idx+0];
			points[i].pos.y=r[idx+1];
			points[i].normal.x=r[idx+2];
			points[i].normal.y=r[idx+3];

		}
	}


	ERR_FAIL_COND(point_count==0);
	Rect2 aabb;
	aabb.pos=points[0].pos;
	for(int i=1;i<point_count;i++)
		aabb.expand_to(points[i].pos);

	configure(aabb);
}
开发者ID:19Staceys,项目名称:godot,代码行数:56,代码来源:shape_2d_sw.cpp

示例8: handleMouse

void handleMouse(const Rect2& view, int viewportWidth, int viewportHeight)
{
  int x, y;
  ubyte state = SDL_GetMouseState(&x, &y);
  real vx = x;
  real vy = viewportHeight-y;
  gMouseX = (vx/viewportWidth)*view.width()+view.left();
  gMouseY = (vy/viewportHeight)*view.height()+view.bottom();         
  gMouseButton = state & SDL_BUTTON(1);    
}
开发者ID:ordovician,项目名称:LusionEngine,代码行数:10,代码来源:EngineSDL.cpp

示例9:

real_t ConvexPolygonShape2DSW::get_moment_of_inertia(float p_mass) const {

	Rect2 aabb;
	aabb.pos=points[0].pos;
	for(int i=0;i<point_count;i++) {

		aabb.expand_to(points[i].pos);
	}

	return p_mass*aabb.size.dot(aabb.size)/12.0f;
}
开发者ID:19Staceys,项目名称:godot,代码行数:11,代码来源:shape_2d_sw.cpp

示例10:

real_t ConvexPolygonShape2DSW::get_moment_of_inertia(float p_mass,const Vector2& p_scale) const {

	Rect2 aabb;
	aabb.pos=points[0].pos*p_scale;
	for(int i=0;i<point_count;i++) {

		aabb.expand_to(points[i].pos*p_scale);
	}

	return p_mass*aabb.size.dot(aabb.size)/12.0f + p_mass * (aabb.pos+aabb.size*0.5).length_squared();
}
开发者ID:03050903,项目名称:godot,代码行数:11,代码来源:shape_2d_sw.cpp

示例11: Rect2

Rect2 Line2D::_edit_get_rect() const {

	if (_points.size() == 0)
		return Rect2(0, 0, 0, 0);
	Vector2 d = Vector2(_width, _width);
	Rect2 aabb = Rect2(_points[0] - d, 2 * d);
	for (int i = 1; i < _points.size(); i++) {
		aabb.expand_to(_points[i] - d);
		aabb.expand_to(_points[i] + d);
	}
	return aabb;
}
开发者ID:KellyThomas,项目名称:godot,代码行数:12,代码来源:line_2d.cpp

示例12:

Rect2 ConvexPolygonShape2D::get_rect() const {

	Rect2 rect;
	for (int i = 0; i < points.size(); i++) {
		if (i == 0)
			rect.position = points[i];
		else
			rect.expand_to(points[i]);
	}

	return rect;
}
开发者ID:KellyThomas,项目名称:godot,代码行数:12,代码来源:convex_polygon_shape_2d.cpp

示例13: if

void TileMapEditor::_update_palette() {

	if (!node)
		return;

	palette->clear();

	Ref<TileSet> tileset=node->get_tileset();
	if (!tileset.is_valid())
		return;

	List<int> tiles;
	tileset->get_tile_list(&tiles);

	if (display_mode == DISPLAY_THUMBNAIL) {
		palette->set_max_columns(0);
		palette->set_icon_mode(ItemList::ICON_MODE_TOP);
	} else if (display_mode == DISPLAY_LIST) {
		palette->set_max_columns(1);
		palette->set_icon_mode(ItemList::ICON_MODE_LEFT);
	}

	palette->set_max_text_lines(2);

	for(List<int>::Element *E=tiles.front();E;E=E->next()) {
		palette->add_item("");

		Ref<Texture> tex = tileset->tile_get_texture(E->get());

		if (tex.is_valid()) {
			Rect2 region = tileset->tile_get_region(E->get());

			if (!region.has_no_area()) {
				Image data = VS::get_singleton()->texture_get_data(tex->get_rid());

				Ref<ImageTexture> img = memnew( ImageTexture );
				img->create_from_image(data.get_rect(region));

				palette->set_item_icon(palette->get_item_count()-1, img);
			} else {
				palette->set_item_icon(palette->get_item_count()-1,tex);
			}
		}

		if (tileset->tile_get_name(E->get())!="") {
			palette->set_item_text(palette->get_item_count()-1, tileset->tile_get_name(E->get()));
		} else {
			palette->set_item_text(palette->get_item_count()-1, "#"+itos(E->get()));
		}

		palette->set_item_metadata(palette->get_item_count()-1, E->get());
	}
}
开发者ID:AMG194,项目名称:godot,代码行数:53,代码来源:tile_map_editor_plugin.cpp

示例14: get_d

Rect2 LineShape2D::get_rect() const {

	Vector2 point = get_d() * get_normal();

	Vector2 l1[2] = { point - get_normal().tangent() * 100, point + get_normal().tangent() * 100 };
	Vector2 l2[2] = { point, point + get_normal() * 30 };
	Rect2 rect;
	rect.pos = l1[0];
	rect.expand_to(l1[1]);
	rect.expand_to(l2[0]);
	rect.expand_to(l2[1]);
	return rect;
}
开发者ID:allkhor,项目名称:godot,代码行数:13,代码来源:shape_line_2d.cpp

示例15: set_block_minimum_size_adjust

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;
}
开发者ID:UgisBrekis,项目名称:godot,代码行数:51,代码来源:graph_edit.cpp


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