本文整理汇总了C++中Rect2函数的典型用法代码示例。如果您正苦于以下问题:C++ Rect2函数的具体用法?C++ Rect2怎么用?C++ Rect2使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Rect2函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ERR_FAIL_COND_V
bool Physics2DDirectSpaceStateSW::collide_shape(RID p_shape, const Transform2D &p_shape_xform, const Vector2 &p_motion, real_t p_margin, Vector2 *r_results, int p_result_max, int &r_result_count, const Set<RID> &p_exclude, uint32_t p_collision_mask) {
if (p_result_max <= 0)
return 0;
Shape2DSW *shape = Physics2DServerSW::singletonsw->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.position + 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);
bool collided = false;
r_result_count = 0;
Physics2DServerSW::CollCbkData cbk;
cbk.max = p_result_max;
cbk.amount = 0;
cbk.ptr = r_results;
CollisionSolver2DSW::CallbackResult cbkres = NULL;
Physics2DServerSW::CollCbkData *cbkptr = NULL;
if (p_result_max > 0) {
cbkptr = &cbk;
cbkres = Physics2DServerSW::_shape_col_cbk;
}
for (int i = 0; i < amount; i++) {
if (!_can_collide_with(space->intersection_query_results[i], p_collision_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;
cbk.valid_dir = Vector2();
cbk.valid_depth = 0;
if (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(), cbkres, cbkptr, NULL, p_margin)) {
collided = p_result_max == 0 || cbk.amount > 0;
}
}
r_result_count = cbk.amount;
return collided;
}
示例2: Rect2
Rect2 AnimatedSprite3D::get_item_rect() const {
if (!frames.is_valid() || !frames->has_animation(animation) || frame < 0 || frame >= frames->get_frame_count(animation)) {
return Rect2(0, 0, 1, 1);
}
Ref<Texture> t;
if (animation)
t = frames->get_frame(animation, frame);
if (t.is_null())
return Rect2(0, 0, 1, 1);
Size2i s = t->get_size();
Point2 ofs = get_offset();
if (centered)
ofs -= s / 2;
if (s == Size2(0, 0))
s = Size2(1, 1);
return Rect2(ofs, s);
}
示例3: get_node
void PopupMenu::_activate_submenu(int over) {
Node* n = get_node(items[over].submenu);
ERR_EXPLAIN("item subnode does not exist: "+items[over].submenu);
ERR_FAIL_COND(!n);
Popup *pm = n->cast_to<Popup>();
ERR_EXPLAIN("item subnode is not a Popup: "+items[over].submenu);
ERR_FAIL_COND(!pm);
if (pm->is_visible())
return; //already visible!
Point2 p = get_global_pos();
Rect2 pr(p,get_size());
Ref<StyleBox> style = get_stylebox("panel");
Point2 pos = p+Point2(get_size().width,items[over]._ofs_cache-style->get_offset().y);
Size2 size = pm->get_size();
// fix pos
if (pos.x+size.width > get_viewport_rect().size.width)
pos.x=p.x-size.width;
pm->set_pos(pos);
pm->popup();
PopupMenu *pum = pm->cast_to<PopupMenu>();
if (pum) {
pr.pos-=pum->get_global_pos();
pum->clear_autohide_areas();
pum->add_autohide_area(Rect2(pr.pos.x,pr.pos.y,pr.size.x,items[over]._ofs_cache));
if (over<items.size()-1) {
int from = items[over+1]._ofs_cache;
pum->add_autohide_area(Rect2(pr.pos.x,pr.pos.y+from,pr.size.x,pr.size.y-from));
}
}
}
示例4: ERR_FAIL_COND
void BroadPhase2DHashGrid::remove(ID p_id) {
Map<ID,Element>::Element *E=element_map.find(p_id);
ERR_FAIL_COND(!E);
Element &e=E->get();
if (e.aabb!=Rect2())
_exit_grid(&e,e.aabb,e._static);
element_map.erase(p_id);
}
示例5:
void CollisionPolygon2D::set_polygon(const Vector<Point2>& p_polygon) {
polygon=p_polygon;
if (can_update_body) {
for(int i=0;i<polygon.size();i++) {
if (i==0)
aabb=Rect2(polygon[i],Size2());
else
aabb.expand_to(polygon[i]);
}
if (aabb==Rect2()) {
aabb=Rect2(-10,-10,20,20);
} else {
aabb.pos-=aabb.size*0.3;
aabb.size+=aabb.size*0.6;
}
_update_parent();
}
update();
}
示例6: _vp_input
void Viewport::_vp_input(const InputEvent& p_ev) {
if (render_target && to_screen_rect==Rect2())
return; //if render target, can't get input events
//this one handles system input, p_ev are in system coordinates
//they are converted to viewport coordinates
InputEvent ev = p_ev;
_make_input_local(ev);
input(ev);
}
示例7: emit_signal
void MenuButton::pressed() {
emit_signal("about_to_show");
Size2 size=get_size();
Point2 gp = get_global_pos();
popup->set_global_pos( gp + Size2( 0, size.height ) );
popup->set_size( Size2( size.width, 0) );
popup->set_parent_rect( Rect2(Point2(gp-popup->get_global_pos()),get_size()));
popup->popup();
popup->call_deferred("grab_click_focus");
}
示例8: get_icon
void Path2DEditor::forward_draw_over_canvas(Control *p_canvas) {
if (!node)
return;
if (!node->is_visible_in_tree())
return;
if (!node->get_curve().is_valid())
return;
Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform();
Ref<Texture> handle = get_icon("EditorHandle", "EditorIcons");
Size2 handle_size = handle->get_size();
Ref<Curve2D> curve = node->get_curve();
int len = curve->get_point_count();
Control *vpc = canvas_item_editor->get_viewport_control();
for (int i = 0; i < len; i++) {
Vector2 point = xform.xform(curve->get_point_position(i));
vpc->draw_texture_rect(handle, Rect2(point - handle_size * 0.5, handle_size), false, Color(1, 1, 1, 1));
if (i < len - 1) {
Vector2 pointout = xform.xform(curve->get_point_position(i) + curve->get_point_out(i));
vpc->draw_line(point, pointout, Color(0.5, 0.5, 1.0, 0.8), 1.0);
vpc->draw_texture_rect(handle, Rect2(pointout - handle_size * 0.5, handle_size), false, Color(1, 0.5, 1, 0.3));
}
if (i > 0) {
Vector2 pointin = xform.xform(curve->get_point_position(i) + curve->get_point_in(i));
vpc->draw_line(point, pointin, Color(0.5, 0.5, 1.0, 0.8), 1.0);
vpc->draw_texture_rect(handle, Rect2(pointin - handle_size * 0.5, handle_size), false, Color(1, 0.5, 1, 0.3));
}
}
}
示例9: GLOBAL_GET
void VisualServerViewport::draw_viewports() {
//sort viewports
//draw viewports
clear_color = GLOBAL_GET("rendering/viewport/default_clear_color");
active_viewports.sort_custom<ViewportSort>();
for (int i = 0; i < active_viewports.size(); i++) {
Viewport *vp = active_viewports[i];
if (vp->update_mode == VS::VIEWPORT_UPDATE_DISABLED)
continue;
ERR_CONTINUE(!vp->render_target.is_valid());
bool visible = vp->viewport_to_screen_rect != Rect2() || vp->update_mode == VS::VIEWPORT_UPDATE_ALWAYS || vp->update_mode == VS::VIEWPORT_UPDATE_ONCE;
if (!visible)
continue;
VSG::rasterizer->set_current_render_target(vp->render_target);
_draw_viewport(vp);
if (vp->viewport_to_screen_rect != Rect2()) {
//copy to screen if set as such
VSG::rasterizer->set_current_render_target(RID());
VSG::rasterizer->blit_render_target_to_screen(vp->render_target, vp->viewport_to_screen_rect, vp->viewport_to_screen);
}
if (vp->update_mode == VS::VIEWPORT_UPDATE_ONCE) {
vp->update_mode = VS::VIEWPORT_UPDATE_DISABLED;
}
}
}
示例10: get_stylebox
void ColorPickerButton::_notification(int p_what) {
if (p_what == NOTIFICATION_DRAW) {
Ref<StyleBox> normal = get_stylebox("normal");
Rect2 r = Rect2(normal->get_offset(), get_size() - normal->get_minimum_size());
draw_texture_rect(Control::get_icon("bg", "ColorPickerButton"), r, true);
draw_rect(r, color);
}
if (p_what == MainLoop::NOTIFICATION_WM_QUIT_REQUEST && popup) {
popup->hide();
}
}
示例11: draw_rect
void LargeTexture::draw_rect(RID p_canvas_item,const Rect2& p_rect, bool p_tile,const Color& p_modulate, bool p_transpose) const {
//tiling not supported for this
if (size.x==0 || size.y==0)
return;
Size2 scale = p_rect.size/size;
for(int i=0;i<pieces.size();i++) {
// TODO
pieces[i].texture->draw_rect(p_canvas_item,Rect2(pieces[i].offset*scale+p_rect.pos,pieces[i].texture->get_size()*scale),false,p_modulate,p_transpose);
}
}
示例12: switch
void VideoPlayer::_notification(int p_notification) {
switch (p_notification) {
case NOTIFICATION_ENTER_SCENE: {
//set_idle_process(false); //don't annoy
if (stream.is_valid() && autoplay && !get_scene()->is_editor_hint())
play();
} break;
case NOTIFICATION_PROCESS: {
if (stream.is_null())
return;
if (paused)
return;
while (stream->get_pending_frame_count()) {
Image img = stream->pop_frame();
if (texture->get_width() == 0) {
texture->create(img.get_width(),img.get_height(),img.get_format(),Texture::FLAG_VIDEO_SURFACE|Texture::FLAG_FILTER);
update();
minimum_size_changed();
} else {
if (stream->get_pending_frame_count() == 0)
texture->set_data(img);
};
};
} break;
case NOTIFICATION_DRAW: {
if (texture.is_null())
return;
if (texture->get_width() == 0)
return;
Size2 s=expand?get_size():texture->get_size();
RID ci = get_canvas_item();
printf("drawing with size %f, %f\n", s.x, s.y);
draw_texture_rect(texture,Rect2(Point2(),s),false);
} break;
};
};
示例13: Rect2
void StyleBoxFlat::draw(RID p_canvas_item, const Rect2 &p_rect) const {
VisualServer *vs = VisualServer::get_singleton();
Rect2i r = p_rect;
for (int i = 0; i < border_size; i++) {
Color color_upleft = light_color;
Color color_downright = dark_color;
if (blend) {
color_upleft.r = (border_size - i) * color_upleft.r / border_size + i * bg_color.r / border_size;
color_upleft.g = (border_size - i) * color_upleft.g / border_size + i * bg_color.g / border_size;
color_upleft.b = (border_size - i) * color_upleft.b / border_size + i * bg_color.b / border_size;
color_downright.r = (border_size - i) * color_downright.r / border_size + i * bg_color.r / border_size;
color_downright.g = (border_size - i) * color_downright.g / border_size + i * bg_color.g / border_size;
color_downright.b = (border_size - i) * color_downright.b / border_size + i * bg_color.b / border_size;
}
vs->canvas_item_add_rect(p_canvas_item, Rect2(Point2i(r.position.x, r.position.y + r.size.y - 1), Size2(r.size.x, 1)), color_downright);
vs->canvas_item_add_rect(p_canvas_item, Rect2(Point2i(r.position.x + r.size.x - 1, r.position.y), Size2(1, r.size.y)), color_downright);
vs->canvas_item_add_rect(p_canvas_item, Rect2(r.position, Size2(r.size.x, 1)), color_upleft);
vs->canvas_item_add_rect(p_canvas_item, Rect2(r.position, Size2(1, r.size.y)), color_upleft);
r.position.x++;
r.position.y++;
r.size.x -= 2;
r.size.y -= 2;
}
if (draw_center)
vs->canvas_item_add_rect(p_canvas_item, Rect2(r.position, r.size), bg_color);
Rect2i r_add = p_rect;
vs->canvas_item_add_rect(p_canvas_item, Rect2(Point2i(r_add.position.x - additional_border_size[MARGIN_LEFT], r_add.position.y - additional_border_size[MARGIN_TOP]), Size2(r_add.size.width + additional_border_size[MARGIN_LEFT] + additional_border_size[MARGIN_RIGHT], additional_border_size[MARGIN_TOP])), light_color);
vs->canvas_item_add_rect(p_canvas_item, Rect2(Point2i(r_add.position.x - additional_border_size[MARGIN_LEFT], r_add.position.y), Size2(additional_border_size[MARGIN_LEFT], r_add.size.height)), light_color);
vs->canvas_item_add_rect(p_canvas_item, Rect2(Point2i(r_add.position.x + r_add.size.width, r_add.position.y), Size2(additional_border_size[MARGIN_RIGHT], r_add.size.height)), dark_color);
vs->canvas_item_add_rect(p_canvas_item, Rect2(Point2i(r_add.position.x - additional_border_size[MARGIN_LEFT], r_add.position.y + r_add.size.height), Size2(r_add.size.width + additional_border_size[MARGIN_LEFT] + additional_border_size[MARGIN_RIGHT], additional_border_size[MARGIN_BOTTOM])), dark_color);
}
示例14: _map_to_world
void TileMap::_recompute_rect_cache() {
#ifdef DEBUG_ENABLED
if (!rect_cache_dirty)
return;
Rect2 r_total;
for (Map<PosKey,Quadrant>::Element *E=quadrant_map.front();E;E=E->next()) {
Rect2 r;
r.pos=_map_to_world(E->key().x*_get_quadrant_size(), E->key().y*_get_quadrant_size());
r.expand_to( _map_to_world(E->key().x*_get_quadrant_size()+_get_quadrant_size(), E->key().y*_get_quadrant_size()) );
r.expand_to( _map_to_world(E->key().x*_get_quadrant_size()+_get_quadrant_size(), E->key().y*_get_quadrant_size()+_get_quadrant_size()) );
r.expand_to( _map_to_world(E->key().x*_get_quadrant_size(), E->key().y*_get_quadrant_size()+_get_quadrant_size()) );
if (E==quadrant_map.front())
r_total=r;
else
r_total=r_total.merge(r);
}
if (r_total==Rect2()) {
rect_cache=Rect2(-10,-10,20,20);
} else {
rect_cache=r_total.grow(MAX(cell_size.x,cell_size.y)*_get_quadrant_size());
}
item_rect_changed();
rect_cache_dirty=false;
#endif
}
示例15: Rect2
Rect2 Sprite::get_rect() const {
if (texture.is_null())
return Rect2(0, 0, 1, 1);
Size2i s;
if (region) {
s = region_rect.size;
} else {
s = texture->get_size();
}
s = s / Point2(hframes, vframes);
Point2 ofs = offset;
if (centered)
ofs -= s / 2;
if (s == Size2(0, 0))
s = Size2(1, 1);
return Rect2(ofs, s);
}