simplified coordinate conversion from/to screen by removing duplicated code, Adi was there a reason to check for RootLayer before conversion or was this left-over?

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14709 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2005-11-04 19:51:38 +00:00
parent d79939116c
commit b2f2cb6203
+10 -37
View File
@@ -1199,7 +1199,7 @@ Layer::Activated(bool active)
BPoint BPoint
Layer::BoundsOrigin() const Layer::BoundsOrigin() const
{ {
BPoint origin(0,0); BPoint origin(0, 0);
float scale = Scale(); float scale = Scale();
DrawState* layerData = fDrawState; DrawState* layerData = fDrawState;
@@ -1242,7 +1242,8 @@ Layer::ConvertToParent(BRect rect)
#ifndef NEW_CLIPPING #ifndef NEW_CLIPPING
// rect.OffsetBy(fFrame.LeftTop()); // rect.OffsetBy(fFrame.LeftTop());
// return rect; // return rect;
rect.OffsetBy(-BoundsOrigin().x, -BoundsOrigin().y); BPoint origin = BoundsOrigin();
rect.OffsetBy(-origin.x, -origin.y);
rect.OffsetBy(fFrame.LeftTop()); rect.OffsetBy(fFrame.LeftTop());
return rect; return rect;
#else #else
@@ -2052,14 +2053,8 @@ Layer::ConvertFromParent2(BRegion* reg) const
void void
Layer::ConvertToScreen2(BPoint* pt) const Layer::ConvertToScreen2(BPoint* pt) const
{ {
if (GetRootLayer())
if (fParent) { if (fParent) {
BPoint origin = BoundsOrigin(); ConvertToParent2(pt);
pt->x -= origin.x;
pt->y -= origin.y;
pt->x += fFrame.left;
pt->y += fFrame.top;
fParent->ConvertToScreen2(pt); fParent->ConvertToScreen2(pt);
} }
} }
@@ -2068,12 +2063,8 @@ Layer::ConvertToScreen2(BPoint* pt) const
void void
Layer::ConvertToScreen2(BRect* rect) const Layer::ConvertToScreen2(BRect* rect) const
{ {
if (GetRootLayer())
if (fParent) { if (fParent) {
BPoint origin = BoundsOrigin(); ConvertToParent2(rect);
rect->OffsetBy(-origin.x, -origin.y);
rect->OffsetBy(fFrame.left, fFrame.top);
fParent->ConvertToScreen2(rect); fParent->ConvertToScreen2(rect);
} }
} }
@@ -2082,12 +2073,8 @@ Layer::ConvertToScreen2(BRect* rect) const
void void
Layer::ConvertToScreen2(BRegion* reg) const Layer::ConvertToScreen2(BRegion* reg) const
{ {
if (GetRootLayer())
if (fParent) { if (fParent) {
BPoint origin = BoundsOrigin(); ConvertToParent2(reg);
reg->OffsetBy(-origin.x, -origin.y);
reg->OffsetBy(fFrame.left, fFrame.top);
fParent->ConvertToScreen2(reg); fParent->ConvertToScreen2(reg);
} }
} }
@@ -2096,15 +2083,9 @@ Layer::ConvertToScreen2(BRegion* reg) const
void void
Layer::ConvertFromScreen2(BPoint* pt) const Layer::ConvertFromScreen2(BPoint* pt) const
{ {
if (GetRootLayer())
if (fParent) { if (fParent) {
BPoint origin = BoundsOrigin(); ConvertFromParent2(pt);
pt->x += origin.x; fParent->ConvertFromScreen2(pt);
pt->y += origin.y;
pt->x -= fFrame.left;
pt->y -= fFrame.top;
fParent->ConvertToScreen2(pt);
} }
} }
@@ -2112,12 +2093,8 @@ Layer::ConvertFromScreen2(BPoint* pt) const
void void
Layer::ConvertFromScreen2(BRect* rect) const Layer::ConvertFromScreen2(BRect* rect) const
{ {
if (GetRootLayer())
if (fParent) { if (fParent) {
BPoint origin = BoundsOrigin(); ConvertFromParent2(rect);
rect->OffsetBy(origin.x, origin.y);
rect->OffsetBy(-fFrame.left, -fFrame.top);
fParent->ConvertFromScreen2(rect); fParent->ConvertFromScreen2(rect);
} }
} }
@@ -2126,12 +2103,8 @@ Layer::ConvertFromScreen2(BRect* rect) const
void void
Layer::ConvertFromScreen2(BRegion* reg) const Layer::ConvertFromScreen2(BRegion* reg) const
{ {
if (GetRootLayer())
if (fParent) { if (fParent) {
BPoint origin = BoundsOrigin(); ConvertFromParent2(reg);
reg->OffsetBy(origin.x, origin.y);
reg->OffsetBy(-fFrame.left, -fFrame.top);
fParent->ConvertFromScreen2(reg); fParent->ConvertFromScreen2(reg);
} }
} }