From 8c1a98d8d4d9a90690fbb91df0151a51705c6123 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Sun, 12 Aug 2007 09:52:25 +0000 Subject: [PATCH] * there was a complete mixup of "drawing origin" and "scrolling offset" in the BView implementation (client side) * introduced some private methods for _Convert*(BPoint*) methods which avoid doing the check_lock() thing in the recursion, also Origin() would likely have communicated with the app_server all the time, since the origin bit was needlessly invalidated, so some speedup should be achieved * this should fix ticket #98 git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21900 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/os/interface/View.h | 7 ++ src/kits/interface/View.cpp | 126 ++++++++++++++++++------------- src/servers/app/ServerWindow.cpp | 8 +- 3 files changed, 82 insertions(+), 59 deletions(-) diff --git a/headers/os/interface/View.h b/headers/os/interface/View.h index eaf96bc88a..6b55feb653 100644 --- a/headers/os/interface/View.h +++ b/headers/os/interface/View.h @@ -599,6 +599,13 @@ private: void _ResizeBy(int32 deltaWidth, int32 deltaHeight); void _ParentResizedBy(int32 x, int32 y); + void _ConvertToScreen(BPoint* pt, bool checkLock) const; + void _ConvertFromScreen(BPoint* pt, bool checkLock) const; + + void _ConvertToParent(BPoint* pt, bool checkLock) const; + void _ConvertFromParent(BPoint* pt, bool checkLock) const; + + void _Activate(bool state); void _Attach(); void _Detach(); diff --git a/src/kits/interface/View.cpp b/src/kits/interface/View.cpp index 75f32de91d..ffa19ffacc 100644 --- a/src/kits/interface/View.cpp +++ b/src/kits/interface/View.cpp @@ -628,20 +628,24 @@ BView::Bounds() const void -BView::ConvertToParent(BPoint *point) const +BView::_ConvertToParent(BPoint *point, bool checkLock) const { if (!fParent) return; - check_lock_no_pick(); + if (checkLock) + check_lock_no_pick(); - // TODO: handle scale + // - our scrolling offset + // + our bounds location within the parent + point->x += -fBounds.left + fParentOffset.x; + point->y += -fBounds.top + fParentOffset.y; +} - // our local coordinate transformation - *point -= Origin(); - - // our bounds location within the parent - *point += fParentOffset; +void +BView::ConvertToParent(BPoint *point) const +{ + _ConvertToParent(point, true); } @@ -655,20 +659,24 @@ BView::ConvertToParent(BPoint point) const void -BView::ConvertFromParent(BPoint *point) const +BView::_ConvertFromParent(BPoint *point, bool checkLock) const { if (!fParent) return; - check_lock_no_pick(); + if (checkLock) + check_lock_no_pick(); - // TODO: handle scale + // - our bounds location within the parent + // + our scrolling offset + point->x += -fParentOffset.x + fBounds.left; + point->y += -fParentOffset.y + fBounds.top; +} - // our bounds location within the parent - *point -= fParentOffset; - - // our local coordinate transformation - *point += Origin(); +void +BView::ConvertFromParent(BPoint *point) const +{ + _ConvertFromParent(point, true); } @@ -689,15 +697,10 @@ BView::ConvertToParent(BRect *rect) const check_lock_no_pick(); - // TODO: handle scale - - BPoint origin = Origin(); - - // our local coordinate transformation - rect->OffsetBy(-origin.x, -origin.y); - - // our bounds location within the parent - rect->OffsetBy(fParentOffset); + // - our scrolling offset + // + our bounds location within the parent + rect->OffsetBy(-fBounds.left + fParentOffset.x, + -fBounds.top + fParentOffset.y); } @@ -718,13 +721,10 @@ BView::ConvertFromParent(BRect *rect) const check_lock_no_pick(); - // TODO: handle scale - - // our bounds location within the parent - rect->OffsetBy(-fParentOffset.x, -fParentOffset.y); - - // our local coordinate transformation - rect->OffsetBy(Origin()); + // - our bounds location within the parent + // + our scrolling offset + rect->OffsetBy(-fParentOffset.x + fBounds.left, + -fParentOffset.y + fBounds.top); } @@ -738,7 +738,7 @@ BView::ConvertFromParent(BRect rect) const void -BView::ConvertToScreen(BPoint *pt) const +BView::_ConvertToScreen(BPoint *pt, bool checkLock) const { if (!fParent) { if (fOwner) @@ -747,10 +747,18 @@ BView::ConvertToScreen(BPoint *pt) const return; } - do_owner_check_no_pick(); + if (checkLock) + do_owner_check_no_pick(); - ConvertToParent(pt); - fParent->ConvertToScreen(pt); + _ConvertToParent(pt, false); + fParent->_ConvertToScreen(pt, false); +} + + +void +BView::ConvertToScreen(BPoint *pt) const +{ + _ConvertToScreen(pt, true); } @@ -764,7 +772,7 @@ BView::ConvertToScreen(BPoint pt) const void -BView::ConvertFromScreen(BPoint *pt) const +BView::_ConvertFromScreen(BPoint *pt, bool checkLock) const { if (!fParent) { if (fOwner) @@ -773,10 +781,17 @@ BView::ConvertFromScreen(BPoint *pt) const return; } - do_owner_check_no_pick(); + if (checkLock) + do_owner_check_no_pick(); - ConvertFromParent(pt); - fParent->ConvertFromScreen(pt); + _ConvertFromParent(pt, false); + fParent->_ConvertFromScreen(pt, false); +} + +void +BView::ConvertFromScreen(BPoint *pt) const +{ + _ConvertFromScreen(pt, true); } @@ -976,6 +991,9 @@ BView::SetOrigin(float x, float y) && x == fState->origin.x && y == fState->origin.y) return; + fState->origin.x = x; + fState->origin.y = y; + if (do_owner_check()) { fOwner->fLink->StartMessage(AS_LAYER_SET_ORIGIN); fOwner->fLink->Attach(x); @@ -1539,7 +1557,7 @@ BView::ScrollBy(float deltaX, float deltaY) fOwner->fLink->Flush(); - fState->valid_flags &= ~(B_VIEW_FRAME_BIT | B_VIEW_ORIGIN_BIT); +// fState->valid_flags &= ~B_VIEW_FRAME_BIT; } // we modify our bounds rectangle by deltaX/deltaY coord units hor/ver. @@ -3572,7 +3590,7 @@ BView::MoveTo(float x, float y) fOwner->fLink->Attach(x); fOwner->fLink->Attach(y); - fState->valid_flags |= B_VIEW_FRAME_BIT; +// fState->valid_flags |= B_VIEW_FRAME_BIT; _FlushIfNotInTransaction(); } @@ -3600,7 +3618,7 @@ BView::ResizeBy(float deltaWidth, float deltaHeight) fOwner->fLink->Attach(fBounds.right + deltaWidth); fOwner->fLink->Attach(fBounds.bottom + deltaHeight); - fState->valid_flags |= B_VIEW_FRAME_BIT; +// fState->valid_flags |= B_VIEW_FRAME_BIT; _FlushIfNotInTransaction(); } @@ -4652,17 +4670,17 @@ BView::_UpdateStateForRemove() return; fState->UpdateFrom(*fOwner->fLink); - if (!fState->IsValid(B_VIEW_FRAME_BIT)) { - fOwner->fLink->StartMessage(AS_LAYER_GET_COORD); - - status_t code; - if (fOwner->fLink->FlushWithReply(code) == B_OK - && code == B_OK) { - fOwner->fLink->Read(&fParentOffset); - fOwner->fLink->Read(&fBounds); - fState->valid_flags |= B_VIEW_FRAME_BIT; - } - } +// if (!fState->IsValid(B_VIEW_FRAME_BIT)) { +// fOwner->fLink->StartMessage(AS_LAYER_GET_COORD); +// +// status_t code; +// if (fOwner->fLink->FlushWithReply(code) == B_OK +// && code == B_OK) { +// fOwner->fLink->Read(&fParentOffset); +// fOwner->fLink->Read(&fBounds); +// fState->valid_flags |= B_VIEW_FRAME_BIT; +// } +// } // update children as well diff --git a/src/servers/app/ServerWindow.cpp b/src/servers/app/ServerWindow.cpp index 1ff089e4ce..89b9579f28 100644 --- a/src/servers/app/ServerWindow.cpp +++ b/src/servers/app/ServerWindow.cpp @@ -1381,8 +1381,8 @@ ServerWindow::_DispatchViewMessage(int32 code, STRACE(("ServerWindow %s: Message AS_LAYER_GET_COORD: ViewLayer: %s\n", Title(), fCurrentLayer->Name())); fLink.StartMessage(B_OK); // our offset in the parent -> will be originX and originY in BView - fLink.Attach(fCurrentLayer->Frame().left); - fLink.Attach(fCurrentLayer->Frame().top); + BPoint parentOffset = fCurrentLayer->Frame().LeftTop(); + fLink.Attach(parentOffset); fLink.Attach(fCurrentLayer->Bounds()); fLink.Flush(); break; @@ -1403,9 +1403,7 @@ ServerWindow::_DispatchViewMessage(int32 code, { STRACE(("ServerWindow %s: Message AS_LAYER_GET_ORIGIN: ViewLayer: %s\n", Title(), fCurrentLayer->Name())); fLink.StartMessage(B_OK); - // TODO: rename this where it is used in the BView code! - // (it wants to know scrolling offset, not drawing origin) - fLink.Attach(fCurrentLayer->ScrollingOffset()); + fLink.Attach(fCurrentLayer->DrawingOrigin()); fLink.Flush(); break; }