本文整理汇总了C++中Rect2::distance_to方法的典型用法代码示例。如果您正苦于以下问题:C++ Rect2::distance_to方法的具体用法?C++ Rect2::distance_to怎么用?C++ Rect2::distance_to使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rect2
的用法示例。
在下文中一共展示了Rect2::distance_to方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: get_item_at_pos
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;
}
示例2: _input_event
void ItemList::_input_event(const InputEvent& p_event) {
if (defer_select_single>=0 && p_event.type==InputEvent::MOUSE_MOTION) {
defer_select_single=-1;
return;
}
if (defer_select_single>=0 && p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==BUTTON_LEFT && !p_event.mouse_button.pressed) {
select(defer_select_single,true);
emit_signal("multi_selected",defer_select_single,true);
defer_select_single=-1;
return;
}
if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==BUTTON_LEFT && p_event.mouse_button.pressed) {
const InputEventMouseButton &mb = p_event.mouse_button;
search_string=""; //any mousepress cancels
Vector2 pos(mb.x,mb.y);
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;
}
}
if (closest!=-1) {
int i = closest;
if (select_mode==SELECT_MULTI && items[i].selected && mb.mod.command) {
unselect(i);
emit_signal("multi_selected",i,false);
} else if (select_mode==SELECT_MULTI && mb.mod.shift && current>=0 && current<items.size() && current!=i) {
int from = current;
int to = i;
if (i<current) {
SWAP(from,to);
}
for(int j=from;j<=to;j++) {
bool selected = !items[j].selected;
select(j,false);
if (selected)
emit_signal("multi_selected",i,true);
}
} else {
if (!mb.doubleclick && !mb.mod.command && select_mode==SELECT_MULTI && items[i].selectable && items[i].selected) {
defer_select_single=i;
return;
}
bool selected = !items[i].selected;
select(i,select_mode==SELECT_SINGLE || !mb.mod.command);
if (selected) {
if (select_mode==SELECT_SINGLE) {
emit_signal("item_selected",i);
} else
emit_signal("multi_selected",i,true);
}
if (/*select_mode==SELECT_SINGLE &&*/ mb.doubleclick) {
emit_signal("item_activated",i);
}
}
return;
}
}
if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==BUTTON_WHEEL_UP && p_event.mouse_button.pressed) {
scroll_bar->set_val( scroll_bar->get_val()-scroll_bar->get_page()/8 );
//.........这里部分代码省略.........