本文整理汇总了C++中gfx::Rect::contains方法的典型用法代码示例。如果您正苦于以下问题:C++ Rect::contains方法的具体用法?C++ Rect::contains怎么用?C++ Rect::contains使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gfx::Rect
的用法示例。
在下文中一共展示了Rect::contains方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: modify_selection
// TODO create morphological operators/functions in "doc" namespace
// TODO the impl is not optimal, but is good enough as a first version
void modify_selection(const SelectionModifier modifier,
const Mask* srcMask,
Mask* dstMask,
const int radius,
const doc::BrushType brush)
{
const doc::Image* srcImage = srcMask->bitmap();
doc::Image* dstImage = dstMask->bitmap();
const gfx::Point offset =
srcMask->bounds().origin() -
dstMask->bounds().origin();
// Image bounds to clip get/put pixels
const gfx::Rect srcBounds = srcImage->bounds();
// Create a kernel
const int size = 2*radius+1;
std::unique_ptr<doc::Image> kernel(doc::Image::create(IMAGE_BITMAP, size, size));
doc::clear_image(kernel.get(), 0);
if (brush == doc::kCircleBrushType)
doc::fill_ellipse(kernel.get(), 0, 0, size-1, size-1, 1);
else
doc::fill_rect(kernel.get(), 0, 0, size-1, size-1, 1);
doc::put_pixel(kernel.get(), radius, radius, 0);
int total = 0; // Number of 1s in the kernel image
for (int v=0; v<size; ++v)
for (int u=0; u<size; ++u)
total += kernel->getPixel(u, v);
for (int y=-radius; y<srcBounds.h+radius; ++y) {
for (int x=-radius; x<srcBounds.w+radius; ++x) {
doc::color_t c;
if (srcBounds.contains(x, y))
c = srcImage->getPixel(x, y);
else
c = 0;
int accum = 0;
for (int v=0; v<size; ++v) {
for (int u=0; u<size; ++u) {
if (kernel->getPixel(u, v)) {
if (srcBounds.contains(x+u-radius, y+v-radius))
accum += srcImage->getPixel(x-radius+u, y-radius+v);
}
}
}
switch (modifier) {
case SelectionModifier::Border: {
c = (c && accum < total) ? 1: 0;
break;
}
case SelectionModifier::Expand: {
c = (c || accum > 0) ? 1: 0;
break;
}
case SelectionModifier::Contract: {
c = (c && accum == total) ? 1: 0;
break;
}
}
if (c)
doc::put_pixel(dstImage,
offset.x+x,
offset.y+y, 1);
}
}
}