some bugfixing

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15299 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini
2005-12-03 14:12:53 +00:00
parent a410e190a4
commit 2b3861d601
3 changed files with 44 additions and 16 deletions
@@ -3,6 +3,7 @@
#include "clipping.h" #include "clipping.h"
#include "ClipRegion.h" #include "ClipRegion.h"
//#include <ServerLink.h>
#include <Debug.h> #include <Debug.h>
@@ -196,10 +197,7 @@ ClipRegion::Include(const clipping_rect &rect)
{ {
// The easy case first: if the rectangle completely contains // The easy case first: if the rectangle completely contains
// ourself, the union is the rectangle itself. // ourself, the union is the rectangle itself.
if (rect.top <= fBound.top if (rect_contains(fBound, rect))
&& rect.bottom >= fBound.bottom
&& rect.left <= fBound.left
&& rect.right >= fBound.right)
Set(rect); Set(rect);
else { else {
const ClipRegion region(rect); const ClipRegion region(rect);
@@ -290,6 +288,25 @@ ClipRegion::operator=(const ClipRegion &region)
return *this; return *this;
} }
#if 0
status_t
ClipRegion::ReadFromLink(BPrivate::ServerLink &link)
{
link.Read(&fCount, sizeof(fCount));
link.Read(&fBound, sizeof(fBound));
_Resize(fCount + 1);
return link.Read(fData, fCount * sizeof(clipping_rect));
}
status_t
ClipRegion::WriteToLink(BPrivate::ServerLink &link)
{
link.Attach(&fCount, sizeof(fCount));
link.Attach(&fBound, sizeof(fBound));
return link.Attach(fData, fCount * sizeof(clipping_rect));
}
#endif
// private methods // private methods
void void
@@ -321,8 +338,7 @@ ClipRegion::_IntersectWith(const clipping_rect &rect)
// with the passed rect, so we check if the rect completely contains // with the passed rect, so we check if the rect completely contains
// the region. // the region.
// If it's the case, the intersection is exactly the region itself. // If it's the case, the intersection is exactly the region itself.
if (rect.top <= fBound.top && rect.bottom >= fBound.bottom if (rect_contains(rect, fBound))
&& rect.left <= fBound.left && rect.right >= fBound.right)
return; return;
// Otherwise, we add the intersections of the region's rects // Otherwise, we add the intersections of the region's rects
@@ -388,8 +404,7 @@ ClipRegion::_IncludeComplex(const ClipRegion &region)
rects[0].bottom = bottom; rects[0].bottom = bottom;
int32 rectsCount = _ExtractStripRects(top, bottom, rects, &a) int32 rectsCount = _ExtractStripRects(top, bottom, rects, &a)
+ region._ExtractStripRects(top, bottom, + region._ExtractStripRects(top, bottom, &rects[rectsCount], &b);
(clipping_rect *)(rects + rectsCount * sizeof(clipping_rect)), &b);
if (rectsCount > 0) { if (rectsCount > 0) {
//if (rectsCount > 1) //if (rectsCount > 1)
@@ -398,8 +413,9 @@ ClipRegion::_IncludeComplex(const ClipRegion &region)
} }
} }
dest._Coalesce();
_Adopt(dest); _Adopt(dest);
//CleanupRegion()
} }
@@ -614,9 +630,11 @@ ClipRegion::_MergeAndInclude(clipping_rect *rects, const int32 &count)
inline void inline void
ClipRegion::_Coalesce() ClipRegion::_Coalesce()
{ {
if (fCount > 1) {
while (_CoalesceVertical() || _CoalesceHorizontal()) while (_CoalesceVertical() || _CoalesceHorizontal())
; ;
} }
}
bool bool
@@ -643,7 +661,7 @@ ClipRegion::_CoalesceVertical()
fCount = newCount + 1; fCount = newCount + 1;
return fCount == oldCount; return fCount < oldCount;
} }
@@ -670,7 +688,7 @@ ClipRegion::_CoalesceHorizontal()
fCount = newCount + 1; fCount = newCount + 1;
return fCount == oldCount; return fCount < oldCount;
} }
@@ -3,7 +3,9 @@
#include "Region.h" // for clipping_rect #include "Region.h" // for clipping_rect
namespace BPrivate {
class ServerLink; class ServerLink;
};
class ClipRegion { class ClipRegion {
public: public:
@@ -48,8 +50,8 @@ public:
ClipRegion &operator=(const ClipRegion &region); ClipRegion &operator=(const ClipRegion &region);
status_t ReadFromLink(ServerLink &link); status_t ReadFromLink(BPrivate::ServerLink &link);
status_t WriteToLink(ServerLink &link); status_t WriteToLink(BPrivate::ServerLink &link);
private: private:
int32 fCount; int32 fCount;
@@ -126,6 +126,14 @@ point_in(const clipping_rect &rect, const BPoint &pt)
} }
static inline bool
rect_contains(const clipping_rect &rect, const clipping_rect &testRect)
{
return rect.top <= testRect.top && rect.bottom >= testRect.bottom
&& rect.left <= testRect.left && rect.right >= testRect.right;
}
// Checks if the rect is valid // Checks if the rect is valid
static inline bool static inline bool
valid_rect(const clipping_rect &rect) valid_rect(const clipping_rect &rect)