/* * OpenClonk, http://www.openclonk.org * * Copyright (c) 1998-2000, Matthes Bender * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/ * Copyright (c) 2009-2016, The OpenClonk Team and contributors * * Distributed under the terms of the ISC license; see accompanying file * "COPYING" for details. * * "Clonk" is a registered trademark of Matthes Bender, used with permission. * See accompanying file "TRADEMARK" for details. * * To redistribute this file separately, substitute the full license texts * for the above references. */ /* Basic classes for rectangles and vertex outlines */ #ifndef INC_C4Rect #define INC_C4Rect #define C4D_VertexCpyPos (C4D_MaxVertex/2) struct FLOAT_RECT { float left,right,top,bottom; }; class C4Rect { public: int32_t x = 0, y = 0, Wdt = 0, Hgt = 0; public: void Set(int32_t iX, int32_t iY, int32_t iWdt, int32_t iHgt); void Default(); bool Overlap(C4Rect &rTarget); void Intersect(const C4Rect &r2); void Add(const C4Rect &r2); bool operator ==(const C4Rect &r2) const { return !((x-r2.x) | (y-r2.y) | (Wdt-r2.Wdt) | (Hgt-r2.Hgt)); } bool operator !=(const C4Rect &r2) const { return 0 != ((x-r2.x) | (y-r2.y) | (Wdt-r2.Wdt) | (Hgt-r2.Hgt)); } bool Contains(int32_t iX, int32_t iY) const { return iX>=x && iX=y && iY=x && iX+iWdt=y && iY+iHgt(rcfOuter.left); y=static_cast(rcfOuter.top); Wdt=static_cast(ceilf(rcfOuter.right)-floorf(rcfOuter.left)); Hgt=static_cast(ceilf(rcfOuter.bottom)-floorf(rcfOuter.top)); } void CompileFunc(StdCompiler *pComp); }; class C4TargetRect: public C4Rect { public: int32_t tx,ty; public: C4TargetRect(int32_t iX, int32_t iY, int32_t iWdt, int32_t iHgt, int32_t iTX, int32_t iTY) : C4Rect(iX, iY, iWdt, iHgt), tx(iTX), ty(iTY) { } C4TargetRect() = default; // default ctor; doesn't initialize void Set(int32_t iX, int32_t iY, int32_t iWdt, int32_t iHgt, int32_t iTX, int32_t iTY); void Default(); bool ClipBy(C4TargetRect &rClip); // clip this rectangle by the given one (adding target positions) - return false if they don't overlap void Set(const C4TargetFacet &rSrc); // copy contents from facet void CompileFunc(StdCompiler *pComp); }; const C4Rect Rect0(0,0,0,0); const C4TargetRect TargetRect0(0,0,0,0,0,0); // a bunch of rectangles // rects NOT including pos+size-point class C4RectList : public std::vector { public: void AddRect(const C4Rect &rNewRect) { push_back(rNewRect); } void RemoveIndexedRect(int32_t idx) { if (idx