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
+27 -54
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,88 +2053,60 @@ Layer::ConvertFromParent2(BRegion* reg) const
void void
Layer::ConvertToScreen2(BPoint* pt) const Layer::ConvertToScreen2(BPoint* pt) const
{ {
if (GetRootLayer()) if (fParent) {
if (fParent) { ConvertToParent2(pt);
BPoint origin = BoundsOrigin(); fParent->ConvertToScreen2(pt);
pt->x -= origin.x; }
pt->y -= origin.y;
pt->x += fFrame.left;
pt->y += fFrame.top;
fParent->ConvertToScreen2(pt);
}
} }
//! converts a rect from local to screen coordinate system //! converts a rect from local to screen coordinate system
void void
Layer::ConvertToScreen2(BRect* rect) const Layer::ConvertToScreen2(BRect* rect) const
{ {
if (GetRootLayer()) if (fParent) {
if (fParent) { ConvertToParent2(rect);
BPoint origin = BoundsOrigin(); fParent->ConvertToScreen2(rect);
rect->OffsetBy(-origin.x, -origin.y); }
rect->OffsetBy(fFrame.left, fFrame.top);
fParent->ConvertToScreen2(rect);
}
} }
//! converts a region from local to screen coordinate system //! converts a region from local to screen coordinate system
void void
Layer::ConvertToScreen2(BRegion* reg) const Layer::ConvertToScreen2(BRegion* reg) const
{ {
if (GetRootLayer()) if (fParent) {
if (fParent) { ConvertToParent2(reg);
BPoint origin = BoundsOrigin(); fParent->ConvertToScreen2(reg);
reg->OffsetBy(-origin.x, -origin.y); }
reg->OffsetBy(fFrame.left, fFrame.top);
fParent->ConvertToScreen2(reg);
}
} }
//! converts a point from screen to local coordinate system //! converts a point from screen to local coordinate system
void void
Layer::ConvertFromScreen2(BPoint* pt) const Layer::ConvertFromScreen2(BPoint* pt) const
{ {
if (GetRootLayer()) if (fParent) {
if (fParent) { ConvertFromParent2(pt);
BPoint origin = BoundsOrigin(); fParent->ConvertFromScreen2(pt);
pt->x += origin.x; }
pt->y += origin.y;
pt->x -= fFrame.left;
pt->y -= fFrame.top;
fParent->ConvertToScreen2(pt);
}
} }
//! converts a rect from screen to local coordinate system //! converts a rect from screen to local coordinate system
void void
Layer::ConvertFromScreen2(BRect* rect) const Layer::ConvertFromScreen2(BRect* rect) const
{ {
if (GetRootLayer()) if (fParent) {
if (fParent) { ConvertFromParent2(rect);
BPoint origin = BoundsOrigin(); fParent->ConvertFromScreen2(rect);
rect->OffsetBy(origin.x, origin.y); }
rect->OffsetBy(-fFrame.left, -fFrame.top);
fParent->ConvertFromScreen2(rect);
}
} }
//! converts a region from screen to local coordinate system //! converts a region from screen to local coordinate system
void void
Layer::ConvertFromScreen2(BRegion* reg) const Layer::ConvertFromScreen2(BRegion* reg) const
{ {
if (GetRootLayer()) if (fParent) {
if (fParent) { ConvertFromParent2(reg);
BPoint origin = BoundsOrigin(); fParent->ConvertFromScreen2(reg);
reg->OffsetBy(origin.x, origin.y); }
reg->OffsetBy(-fFrame.left, -fFrame.top);
fParent->ConvertFromScreen2(reg);
}
} }