BOOL CArcView::IntersectsWithRect(const Rect& rectangle) { Point topLeft(rectangle.GetLeft(), rectangle.GetTop()); Point topRight(rectangle.GetRight(), rectangle.GetTop()); Point bottomLeft(rectangle.GetLeft(), rectangle.GetBottom()); Point bottomRight(rectangle.GetRight(), rectangle.GetBottom()); Point currentPoint(*pathPoints.begin()); for(auto it=pathPoints.begin() + 1; it != pathPoints.end(); ++it) { if(rectangle.Contains(currentPoint)) return TRUE; if(Geometry::LinesIntersect(topLeft, topRight, currentPoint, *it)) return TRUE; if(Geometry::LinesIntersect(topLeft, bottomLeft, currentPoint, *it)) return TRUE; if(Geometry::LinesIntersect(bottomLeft, bottomRight, currentPoint, *it)) return TRUE; if(Geometry::LinesIntersect(topRight, bottomRight, currentPoint, *it)) return TRUE; currentPoint = *it; } return FALSE; }
bool Rect::Intersects(Rect box) { if(right < box.GetLeft() || left > box.GetRight() || top > box.GetBottom() || bottom < box.GetTop()) return false; else return true; }
void Graphics::DrawRectangle(Pen* pen, const Rect& rc) { cairo_t* cg = reinterpret_cast<cairo_t*>(_private); cairo_save(cg); PenPrivate* pp = reinterpret_cast<PenPrivate*>(pen->_private); cairo_pattern_t* cp = pp->pattern; cairo_set_source(cg, cp); cairo_set_line_width(cg, pp->width); cairo_translate(cg, rc.GetLeft(), rc.GetTop()); cairo_rectangle(cg, 0, 0, rc.GetWidth(), rc.GetHeight()); cairo_stroke(cg); cairo_restore(cg); }
void Graphics::DrawImage(Image* image, const Rect& rc, const ImageAttributes* attr) { Gdiplus::Graphics* g = reinterpret_cast<Gdiplus::Graphics*>(_private); Gdiplus::Image* gdiImage = reinterpret_cast<Gdiplus::Image*>(image->_private); if(attr!=0) { Gdiplus::ImageAttributes* ia = reinterpret_cast<Gdiplus::ImageAttributes*>(attr->_private); g->DrawImage(gdiImage, Gdiplus::Rect(rc.GetLeft(), rc.GetTop(), rc.GetWidth(), rc.GetHeight()), 0, 0, gdiImage->GetWidth(), gdiImage->GetHeight(), Gdiplus::UnitPixel, ia); } else { g->DrawImage(gdiImage, ToGDIRect<Rect, Gdiplus::Rect>(rc)); } }
BOOL CCircleView::IntersectsWithRect(const Rect& rectangle) { Point center(position); double edgeCenterDistance = INT_MAX; std::vector<Point> rectCorners; Point topLeft(rectangle.GetLeft(), rectangle.GetTop()); Point topRight(rectangle.GetRight(), rectangle.GetTop()); Point bottomLeft(rectangle.GetLeft(), rectangle.GetBottom()); Point bottomRight(rectangle.GetRight(), rectangle.GetBottom()); rectCorners.push_back(topLeft); rectCorners.push_back(topRight); rectCorners.push_back(bottomLeft); rectCorners.push_back(bottomRight); //Le centre du cercle est-il dans le rectangle ? if(rectangle.Contains(center)) return TRUE; //Un coin du rectangle est-il dans le cercle ? for(auto it=rectCorners.begin(); it!=rectCorners.end(); ++it) if(Geometry::Distance(*it, center) < radius) return TRUE; //Un côté du rectangle coupe-t-il dans le cercle ? if(topLeft.X < center.X && center.X < topRight.X && Geometry::LinePointDistance(topLeft, topRight, center) < radius) return TRUE; if(topLeft.Y < center.Y && center.Y < bottomLeft.Y && Geometry::LinePointDistance(topLeft, bottomLeft, center) < radius) return TRUE; if(bottomLeft.X < center.X && center.X < bottomRight.X && Geometry::LinePointDistance(bottomLeft, bottomRight, center) < radius) return TRUE; if(topRight.Y < center.Y && center.Y < bottomRight.Y && Geometry::LinePointDistance(topRight, bottomRight, center) < radius) return TRUE; return FALSE; }
void Graphics::FillRectangle(Brush* brush, const Rect& rc) { cairo_t* cg = reinterpret_cast<cairo_t*>(_private); cairo_save(cg); if(cg!=0) { cairo_pattern_t* cp = reinterpret_cast<cairo_pattern_t*>(brush->_private); if(cp!=0) { cairo_set_source(cg, cp); cairo_translate(cg, rc.GetLeft(), rc.GetTop()); cairo_rectangle(cg, 0, 0, rc.GetWidth(), rc.GetHeight()); cairo_fill(cg); } } cairo_restore(cg); }
/* ** Draws a bevel inside the given area */ void Meter::DrawBevel(Graphics& graphics, const Rect& rect, const Pen& light, const Pen& dark) { int l = rect.GetLeft(); int r = rect.GetRight() - 1; int t = rect.GetTop(); int b = rect.GetBottom() - 1; graphics.DrawLine(&light, l, t, l, b); graphics.DrawLine(&light, l, t, r, t); graphics.DrawLine(&light, l + 1, t + 1, l + 1, b - 1); graphics.DrawLine(&light, l + 1, t + 1, r - 1, t + 1); graphics.DrawLine(&dark, l, b, r, b); graphics.DrawLine(&dark, r, t, r, b); graphics.DrawLine(&dark, l + 1, b - 1, r - 1, b - 1); graphics.DrawLine(&dark, r - 1, t + 1, r - 1, b - 1); }
bool Bitmap::LockBits(const Rect& rc, bool write, BitmapData* data) { Gdiplus::BitmapData* bd = reinterpret_cast<Gdiplus::BitmapData*>(data->_private); Gdiplus::Bitmap* gdiBitmap = dynamic_cast<Gdiplus::Bitmap*>(reinterpret_cast<Gdiplus::Image*>(_private)); Gdiplus::Rect gdiRect(rc.GetLeft(), rc.GetTop(), rc.GetWidth(), rc.GetHeight()); return gdiBitmap->LockBits(&gdiRect, write ? Gdiplus::ImageLockModeWrite : Gdiplus::ImageLockModeRead, PixelFormat32bppARGB, bd) == Gdiplus::Ok; }