本文整理汇总了C++中rect::contains方法的典型用法代码示例。如果您正苦于以下问题:C++ rect::contains方法的具体用法?C++ rect::contains怎么用?C++ rect::contains使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rect
的用法示例。
在下文中一共展示了rect::contains方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: button
bool button(const rect & r, const std::string & label)
{
fill_rect(r, { 1, 1, 1 });
fill_rect(r.shrink(2), r.contains(cursor) ? (mouse_down ? color{ 0.3f, 0.3f, 0.3f } : color{ 0.4f, 0.4f, 0.4f }) : color{ 0.5f, 0.5f, 0.5f });
glColor3f(1, 1, 1);
draw_text(r.x0 + 4, r.y1 - 8, label.c_str());
return click && r.contains(cursor);
}
示例2: slider
bool slider(int id, const rect & r, double min, double max, double step, double & value, bool disable_dragger = false)
{
bool changed = false;
const int w = r.x1 - r.x0, h = r.y1 - r.y0;
double p = (w - h) * (value - min) / (max - min);
if (mouse_down && clicked_id == id)
{
p = std::max(0.0, std::min<double>(cursor.x - clicked_offset.x - r.x0, w - h));
double new_value = min + p * (max - min) / (w - h);
if (step) new_value = std::round((new_value - min) / step) * step + min;
changed = new_value != value;
value = new_value;
p = (w - h) * (value - min) / (max - min);
}
const rect dragger = { int(r.x0 + p), int(r.y0), int(r.x0 + p + h), int(r.y1) };
if (click && dragger.contains(cursor) && !disable_dragger)
{
clicked_offset = { cursor.x - dragger.x0, cursor.y - dragger.y0 };
clicked_id = id;
}
fill_rect(r, { 0.5, 0.5, 0.5 });
if (!disable_dragger)
fill_rect(dragger, { 1, 1, 1 });
return changed;
}
示例3: mouseup
void mouseup (point p)
{
if (box.contains (p)) {
invert ();
(*cb) ();
}
}
示例4: vscroll
void vscroll(const rect & r, int client_height, int & offset)
{
if (r.contains(cursor)) offset -= scroll_vec.y * 20;
offset = std::min(offset, client_height - (r.y1 - r.y0));
offset = std::max(offset, 0);
if (client_height <= r.y1 - r.y0) return;
auto bar = r; bar.x0 = bar.x1 - 10;
auto dragger = bar;
dragger.y0 = bar.y0 + offset * (r.y1 - r.y0) / client_height;
dragger.y1 = bar.y0 + (offset + r.y1 - r.y0) * (r.y1 - r.y0) / client_height;
fill_rect(bar, { 0.5, 0.5, 0.5 });
fill_rect(dragger, { 1, 1, 1 });
}
示例5: checkbox
bool checkbox(const rect & r, bool & value)
{
bool changed = false;
if (click && r.contains(cursor))
{
value = !value;
changed = true;
}
fill_rect(r, { 1, 1, 1 });
fill_rect(r.shrink(1), { 0.5, 0.5, 0.5 });
if (value) fill_rect(r.shrink(3), { 1, 1, 1 });
return changed;
}