corrected and cleaned up coordinate conversion. conversion from or to parent coords doesn't actually require a parent, directly using fScrollingOffset, uses less stack memory now and should be faster (especially when converting regions, because those were offsetted twice)
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15136 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+50
-86
@@ -588,8 +588,7 @@ Layer::MoveBy(float x, float y)
|
|||||||
GetRootLayer()->TriggerRedraw();
|
GetRootLayer()->TriggerRedraw();
|
||||||
|
|
||||||
GetRootLayer()->Unlock();
|
GetRootLayer()->Unlock();
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// just offset to the new position
|
// just offset to the new position
|
||||||
fFrame.OffsetBy(x, y);
|
fFrame.OffsetBy(x, y);
|
||||||
}
|
}
|
||||||
@@ -669,9 +668,8 @@ Layer::ResizeBy(float x, float y)
|
|||||||
GetRootLayer()->TriggerRedraw();
|
GetRootLayer()->TriggerRedraw();
|
||||||
|
|
||||||
GetRootLayer()->Unlock();
|
GetRootLayer()->Unlock();
|
||||||
}
|
} else {
|
||||||
// just resize our frame and those of out descendants if their resize mask says so
|
// just resize our frame and those of out descendants if their resize mask says so
|
||||||
else {
|
|
||||||
fFrame.Set(fFrame.left, fFrame.top, fFrame.right+x, fFrame.bottom+y);
|
fFrame.Set(fFrame.left, fFrame.top, fFrame.right+x, fFrame.bottom+y);
|
||||||
|
|
||||||
// TODO: you should call this hook function AFTER all region rebuilding
|
// TODO: you should call this hook function AFTER all region rebuilding
|
||||||
@@ -930,181 +928,146 @@ Layer::ScrolledByHook(float dx, float dy)
|
|||||||
void
|
void
|
||||||
Layer::ConvertToParent(BPoint* pt) const
|
Layer::ConvertToParent(BPoint* pt) const
|
||||||
{
|
{
|
||||||
if (fParent) {
|
pt->x += fFrame.left - fScrollingOffset.x;
|
||||||
BPoint origin = ScrollingOffset();
|
pt->y += fFrame.top - fScrollingOffset.y;
|
||||||
pt->x -= origin.x;
|
|
||||||
pt->y -= origin.y;
|
|
||||||
pt->x += fFrame.left;
|
|
||||||
pt->y += fFrame.top;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//! converts a rect from local to parent's coordinate system
|
//! converts a rect from local to parent's coordinate system
|
||||||
void
|
void
|
||||||
Layer::ConvertToParent(BRect* rect) const
|
Layer::ConvertToParent(BRect* rect) const
|
||||||
{
|
{
|
||||||
if (fParent) {
|
rect->OffsetBy(fFrame.left - fScrollingOffset.x,
|
||||||
BPoint origin = ScrollingOffset();
|
fFrame.top - fScrollingOffset.y);
|
||||||
rect->OffsetBy(-origin.x, -origin.y);
|
|
||||||
rect->OffsetBy(fFrame.left, fFrame.top);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//! converts a region from local to parent's coordinate system
|
//! converts a region from local to parent's coordinate system
|
||||||
void
|
void
|
||||||
Layer::ConvertToParent(BRegion* reg) const
|
Layer::ConvertToParent(BRegion* reg) const
|
||||||
{
|
{
|
||||||
if (fParent) {
|
reg->OffsetBy(fFrame.left - fScrollingOffset.x,
|
||||||
BPoint origin = ScrollingOffset();
|
fFrame.top - fScrollingOffset.y);
|
||||||
reg->OffsetBy(-origin.x, -origin.y);
|
|
||||||
reg->OffsetBy(fFrame.left, fFrame.top);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//! converts a point from parent's to local coordinate system
|
//! converts a point from parent's to local coordinate system
|
||||||
void
|
void
|
||||||
Layer::ConvertFromParent(BPoint* pt) const
|
Layer::ConvertFromParent(BPoint* pt) const
|
||||||
{
|
{
|
||||||
if (fParent) {
|
pt->x += fScrollingOffset.x - fFrame.left;
|
||||||
BPoint origin = ScrollingOffset();
|
pt->y += fScrollingOffset.y - fFrame.top;
|
||||||
pt->x += origin.x;
|
|
||||||
pt->y += origin.y;
|
|
||||||
pt->x -= fFrame.left;
|
|
||||||
pt->y -= fFrame.top;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//! converts a rect from parent's to local coordinate system
|
//! converts a rect from parent's to local coordinate system
|
||||||
void
|
void
|
||||||
Layer::ConvertFromParent(BRect* rect) const
|
Layer::ConvertFromParent(BRect* rect) const
|
||||||
{
|
{
|
||||||
if (fParent) {
|
rect->OffsetBy(fScrollingOffset.x - fFrame.left,
|
||||||
BPoint origin = ScrollingOffset();
|
fScrollingOffset.y - fFrame.top);
|
||||||
rect->OffsetBy(origin.x, origin.y);
|
|
||||||
rect->OffsetBy(-fFrame.left, -fFrame.top);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//! converts a region from parent's to local coordinate system
|
//! converts a region from parent's to local coordinate system
|
||||||
void
|
void
|
||||||
Layer::ConvertFromParent(BRegion* reg) const
|
Layer::ConvertFromParent(BRegion* reg) const
|
||||||
{
|
{
|
||||||
if (fParent) {
|
reg->OffsetBy(fScrollingOffset.x - fFrame.left,
|
||||||
BPoint origin = ScrollingOffset();
|
fScrollingOffset.y - fFrame.top);
|
||||||
reg->OffsetBy(origin.x, origin.y);
|
|
||||||
reg->OffsetBy(-fFrame.left, -fFrame.top);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//! converts a point from local to screen coordinate system
|
//! converts a point from local to screen coordinate system
|
||||||
void
|
void
|
||||||
Layer::ConvertToScreen(BPoint* pt) const
|
Layer::ConvertToScreen(BPoint* pt) const
|
||||||
{
|
{
|
||||||
if (fParent) {
|
ConvertToParent(pt);
|
||||||
ConvertToParent(pt);
|
|
||||||
|
if (fParent)
|
||||||
fParent->ConvertToScreen(pt);
|
fParent->ConvertToScreen(pt);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//! converts a rect from local to screen coordinate system
|
//! converts a rect from local to screen coordinate system
|
||||||
void
|
void
|
||||||
Layer::ConvertToScreen(BRect* rect) const
|
Layer::ConvertToScreen(BRect* rect) const
|
||||||
{
|
{
|
||||||
if (fParent) {
|
ConvertToParent(rect);
|
||||||
ConvertToParent(rect);
|
|
||||||
|
if (fParent)
|
||||||
fParent->ConvertToScreen(rect);
|
fParent->ConvertToScreen(rect);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//! converts a region from local to screen coordinate system
|
//! converts a region from local to screen coordinate system
|
||||||
void
|
void
|
||||||
Layer::ConvertToScreen(BRegion* reg) const
|
Layer::ConvertToScreen(BRegion* reg) const
|
||||||
{
|
{
|
||||||
if (fParent) {
|
ConvertToParent(reg);
|
||||||
ConvertToParent(reg);
|
|
||||||
|
if (fParent)
|
||||||
fParent->ConvertToScreen(reg);
|
fParent->ConvertToScreen(reg);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//! converts a point from screen to local coordinate system
|
//! converts a point from screen to local coordinate system
|
||||||
void
|
void
|
||||||
Layer::ConvertFromScreen(BPoint* pt) const
|
Layer::ConvertFromScreen(BPoint* pt) const
|
||||||
{
|
{
|
||||||
if (fParent) {
|
ConvertFromParent(pt);
|
||||||
ConvertFromParent(pt);
|
|
||||||
|
if (fParent)
|
||||||
fParent->ConvertFromScreen(pt);
|
fParent->ConvertFromScreen(pt);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//! converts a rect from screen to local coordinate system
|
//! converts a rect from screen to local coordinate system
|
||||||
void
|
void
|
||||||
Layer::ConvertFromScreen(BRect* rect) const
|
Layer::ConvertFromScreen(BRect* rect) const
|
||||||
{
|
{
|
||||||
if (fParent) {
|
ConvertFromParent(rect);
|
||||||
ConvertFromParent(rect);
|
|
||||||
|
if (fParent)
|
||||||
fParent->ConvertFromScreen(rect);
|
fParent->ConvertFromScreen(rect);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//! converts a region from screen to local coordinate system
|
//! converts a region from screen to local coordinate system
|
||||||
void
|
void
|
||||||
Layer::ConvertFromScreen(BRegion* reg) const
|
Layer::ConvertFromScreen(BRegion* reg) const
|
||||||
{
|
{
|
||||||
if (fParent) {
|
ConvertFromParent(reg);
|
||||||
ConvertFromParent(reg);
|
|
||||||
|
if (fParent)
|
||||||
fParent->ConvertFromScreen(reg);
|
fParent->ConvertFromScreen(reg);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//! converts a point from local *drawing* to screen coordinate system
|
//! converts a point from local *drawing* to screen coordinate system
|
||||||
void
|
void
|
||||||
Layer::ConvertToScreenForDrawing(BPoint* pt) const
|
Layer::ConvertToScreenForDrawing(BPoint* pt) const
|
||||||
{
|
{
|
||||||
if (fParent) {
|
fDrawState->Transform(pt);
|
||||||
fDrawState->Transform(pt);
|
// NOTE: from here on, don't use the
|
||||||
// NOTE: from here on, don't use the
|
// "*ForDrawing()" versions of the parent!
|
||||||
// "*ForDrawing()" versions of the parent!
|
ConvertToScreen(pt);
|
||||||
ConvertToParent(pt);
|
|
||||||
fParent->ConvertToScreen(pt);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//! converts a rect from local *drawing* to screen coordinate system
|
//! converts a rect from local *drawing* to screen coordinate system
|
||||||
void
|
void
|
||||||
Layer::ConvertToScreenForDrawing(BRect* rect) const
|
Layer::ConvertToScreenForDrawing(BRect* rect) const
|
||||||
{
|
{
|
||||||
if (fParent) {
|
fDrawState->Transform(rect);
|
||||||
fDrawState->Transform(rect);
|
// NOTE: from here on, don't use the
|
||||||
// NOTE: from here on, don't use the
|
// "*ForDrawing()" versions of the parent!
|
||||||
// "*ForDrawing()" versions of the parent!
|
ConvertToScreen(rect);
|
||||||
ConvertToParent(rect);
|
|
||||||
fParent->ConvertToScreen(rect);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//! converts a region from local *drawing* to screen coordinate system
|
//! converts a region from local *drawing* to screen coordinate system
|
||||||
void
|
void
|
||||||
Layer::ConvertToScreenForDrawing(BRegion* region) const
|
Layer::ConvertToScreenForDrawing(BRegion* region) const
|
||||||
{
|
{
|
||||||
if (fParent) {
|
fDrawState->Transform(region);
|
||||||
fDrawState->Transform(region);
|
// NOTE: from here on, don't use the
|
||||||
// NOTE: from here on, don't use the
|
// "*ForDrawing()" versions of the parent!
|
||||||
// "*ForDrawing()" versions of the parent!
|
ConvertToScreen(region);
|
||||||
ConvertToParent(region);
|
|
||||||
fParent->ConvertToScreen(region);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//! converts a point from screen to local coordinate system
|
//! converts a point from screen to local coordinate system
|
||||||
void
|
void
|
||||||
Layer::ConvertFromScreenForDrawing(BPoint* pt) const
|
Layer::ConvertFromScreenForDrawing(BPoint* pt) const
|
||||||
{
|
{
|
||||||
if (fParent) {
|
ConvertFromScreen(pt);
|
||||||
ConvertFromParent(pt);
|
fDrawState->InverseTransform(pt);
|
||||||
fParent->ConvertFromScreen(pt);
|
|
||||||
|
|
||||||
fDrawState->InverseTransform(pt);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -1176,14 +1139,15 @@ Layer::_RezizeLayerRedrawMore(BRegion ®, float dx, float dy)
|
|||||||
for (Layer* child = LastChild(); child; child = child->PreviousLayer()) {
|
for (Layer* child = LastChild(); child; child = child->PreviousLayer()) {
|
||||||
uint16 rm = child->fResizeMode & 0x0000FFFF;
|
uint16 rm = child->fResizeMode & 0x0000FFFF;
|
||||||
|
|
||||||
if ((rm & 0x0F0F) == (uint16)B_FOLLOW_LEFT_RIGHT || (rm & 0xF0F0) == (uint16)B_FOLLOW_TOP_BOTTOM) {
|
if ((rm & 0x0F0F) == (uint16)B_FOLLOW_LEFT_RIGHT ||
|
||||||
|
(rm & 0xF0F0) == (uint16)B_FOLLOW_TOP_BOTTOM) {
|
||||||
// NOTE: this is not exactly corect, but it works :-)
|
// NOTE: this is not exactly corect, but it works :-)
|
||||||
// Normaly we shoud've used the child's old, required region - the one returned
|
// Normaly we shoud've used the child's old, required region - the one returned
|
||||||
// from get_user_region() with the old frame, and the current one. child->Bounds()
|
// from get_user_region() with the old frame, and the current one. child->Bounds()
|
||||||
// works for the moment so we leave it like this.
|
// works for the moment so we leave it like this.
|
||||||
|
|
||||||
// calculate the old bounds.
|
// calculate the old bounds.
|
||||||
BRect oldBounds(child->Bounds());
|
BRect oldBounds(child->Bounds());
|
||||||
if ((rm & 0x0F0F) == (uint16)B_FOLLOW_LEFT_RIGHT)
|
if ((rm & 0x0F0F) == (uint16)B_FOLLOW_LEFT_RIGHT)
|
||||||
oldBounds.right -=dx;
|
oldBounds.right -=dx;
|
||||||
if ((rm & 0xF0F0) == (uint16)B_FOLLOW_TOP_BOTTOM)
|
if ((rm & 0xF0F0) == (uint16)B_FOLLOW_TOP_BOTTOM)
|
||||||
|
|||||||
Reference in New Issue
Block a user