From 12aa597dc6295ab8a275df5ee8dd340dd39a7e22 Mon Sep 17 00:00:00 2001 From: Adi Oanca Date: Sun, 27 Nov 2005 17:08:57 +0000 Subject: [PATCH] Played a bit :-) * Introduced WindowLayer::Hide/Show/IsHidden() * Made ViewLayer::IsHidden() more robust. * Same with ::TopLayer() * modified a little ViewLayer::MoveBy() - prepared it to work with hidden/shown code that will come soon; only calculate dirty regions if a ViewLayer has a parent, otherwise the move action is pointless. * Did the same thing with ::MoveBy() except for the parent stuff - no need for a parent on resizing. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15193 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../servers/app/newerClipping/ViewLayer.cpp | 149 ++++++++++-------- .../servers/app/newerClipping/ViewLayer.h | 2 +- .../servers/app/newerClipping/WindowLayer.cpp | 30 ++++ .../servers/app/newerClipping/WindowLayer.h | 7 + 4 files changed, 119 insertions(+), 69 deletions(-) diff --git a/src/tests/servers/app/newerClipping/ViewLayer.cpp b/src/tests/servers/app/newerClipping/ViewLayer.cpp index e62bd51213..61490957c6 100644 --- a/src/tests/servers/app/newerClipping/ViewLayer.cpp +++ b/src/tests/servers/app/newerClipping/ViewLayer.cpp @@ -25,7 +25,9 @@ ViewLayer::ViewLayer(BRect frame, const char* name, fResizeMode(resizeMode), fFlags(flags), - fShowLevel(1), + + // ViewLayers start visible by default + fHidden(false), fWindow(NULL), fParent(NULL), @@ -209,10 +211,13 @@ ViewLayer::LastChild() const ViewLayer* ViewLayer::TopLayer() { + if (fIsTopLayer) + return this; + if (fParent) return fParent->TopLayer(); - - return this; + else + return NULL; } // CountChildren @@ -407,29 +412,23 @@ ViewLayer::MoveBy(int32 x, int32 y, BRegion* dirtyRegion) fFrame.OffsetBy(x, y); InvalidateScreenClipping(true); - if (!fIsTopLayer && dirtyRegion) { - if (fParent) { - // clip to parent - BRect oldScreenRect(Bounds()); - oldScreenRect.OffsetByCopy(-x, -y); - ConvertToParent(&oldScreenRect); + // to move on screen, we must not be hidden and we must have a parent + if (!IsHidden() && fParent && !fIsTopLayer && dirtyRegion) { + // clip to parent + BRect oldScreenRect(Bounds()); + oldScreenRect.OffsetByCopy(-x, -y); + ConvertToParent(&oldScreenRect); - BRect screenRect(Bounds()); - ConvertToParent(&screenRect); + BRect screenRect(Bounds()); + ConvertToParent(&screenRect); - // TODO: see AddLayer - BRect dirty = oldScreenRect | screenRect; - dirty = dirty & fParent->Bounds(); - fParent->ConvertToTop(&dirty); + // TODO: see AddChild + // TODO: shouldn't we use regions? + BRect dirty = oldScreenRect | screenRect; + dirty = dirty & fParent->Bounds(); + fParent->ConvertToTop(&dirty); - dirtyRegion->Include(dirty); - } else { - BRect screenRect(Bounds()); - screenRect = screenRect | screenRect.OffsetByCopy(-x, -y); - ConvertToTop(&screenRect); - - dirtyRegion->Include(screenRect); - } + dirtyRegion->Include(dirty); } } #endif // 0 @@ -441,54 +440,51 @@ ViewLayer::ResizeBy(int32 x, int32 y, BRegion* dirtyRegion) if (x == 0 && y == 0) return; - BRect oldBounds(Bounds()); - fFrame.right += x; fFrame.bottom += y; - BRegion dirty(Bounds()); - dirty.Include(oldBounds); - if (!(fFlags & B_FULL_UPDATE_ON_RESIZE)) { - // the dirty region is just the difference of - // old and new bounds - dirty.Exclude(oldBounds & Bounds()); - } + if (!IsHidden() && dirtyRegion) { + BRect oldBounds(Bounds()); + oldBounds.right -= x; + oldBounds.bottom -= y; - InvalidateScreenClipping(true); + BRegion dirty(Bounds()); + dirty.Include(oldBounds); - if (dirty.CountRects() > 0) { - // exclude children, they are expected to - // include their own dirty regions in ParentResized() - for (ViewLayer* child = FirstChild(); child; child = NextChild()) { - BRect previousChildVisible(child->Frame() & oldBounds & Bounds()); - if (dirty.Frame().Intersects(previousChildVisible)) { - dirty.Exclude(previousChildVisible); - } + if (!(fFlags & B_FULL_UPDATE_ON_RESIZE)) { + // the dirty region is just the difference of + // old and new bounds + dirty.Exclude(oldBounds & Bounds()); } - ConvertToTop(&dirty); - dirtyRegion->Include(&dirty); + InvalidateScreenClipping(true); + + if (dirty.CountRects() > 0) { + // exclude children, they are expected to + // include their own dirty regions in ParentResized() + for (ViewLayer* child = FirstChild(); child; child = NextChild()) { + BRect previousChildVisible(child->Frame() & oldBounds & Bounds()); + if (dirty.Frame().Intersects(previousChildVisible)) { + dirty.Exclude(previousChildVisible); + } + } + + ConvertToTop(&dirty); + dirtyRegion->Include(&dirty); + } + + // layout the children + for (ViewLayer* child = FirstChild(); child; child = NextChild()) + child->ParentResized(x, y, dirtyRegion); + + // at this point, children are at their new locations, + // so we can rebuild the clipping + RebuildClipping(false); + } else { + // just layout the children + for (ViewLayer* child = FirstChild(); child; child = NextChild()) + child->ParentResized(x, y, NULL); } - - // layout the children - for (ViewLayer* child = FirstChild(); child; child = NextChild()) - child->ParentResized(x, y, dirtyRegion); - - // at this point, children are at their new locations, - // so we can rebuild the clipping - RebuildClipping(false); -} - -// ScrollBy -void -ViewLayer::ScrollBy(int32 x, int32 y, BRegion* dirtyRegion) -{ - fScrollingOffset.x += x; - fScrollingOffset.y += y; - // TODO: CopyRegion... - // TODO: ... - - InvalidateScreenClipping(true); } // ParentResized @@ -534,6 +530,18 @@ ViewLayer::ParentResized(int32 x, int32 y, BRegion* dirtyRegion) } } +// ScrollBy +void +ViewLayer::ScrollBy(int32 x, int32 y, BRegion* dirtyRegion) +{ + fScrollingOffset.x += x; + fScrollingOffset.y += y; + // TODO: CopyRegion... + // TODO: ... + + InvalidateScreenClipping(true); +} + // Draw void ViewLayer::Draw(DrawingEngine* drawingEngine, BRegion* effectiveClipping, @@ -602,11 +610,16 @@ ViewLayer::ClientDraw(DrawingEngine* drawingEngine, BRegion* effectiveClipping) bool ViewLayer::IsHidden() const { - // if we're explicitely hidden, then we're hidden... - if (fShowLevel < 1) + // if we're explicitely hidden... + if (fHidden) return true; - // ...but if we're not hidden, we might still be hidden if our parent is + // if we don't have a window, or our window is hidden, + // then yes, we're hidden too + if (fWindow == NULL || (fWindow && fWindow->IsHidden())) + return true; + + // if we're not hidden yet, we might still be hidden if our parent is if (fParent) return fParent->IsHidden(); @@ -618,7 +631,7 @@ ViewLayer::IsHidden() const void ViewLayer::Hide() { - fShowLevel--; + fHidden = true; // TODO: track regions } @@ -627,7 +640,7 @@ ViewLayer::Hide() void ViewLayer::Show() { - fShowLevel++; + fHidden = false; // TODO: track regions } diff --git a/src/tests/servers/app/newerClipping/ViewLayer.h b/src/tests/servers/app/newerClipping/ViewLayer.h index 675d7855cb..cc4bcbc6b3 100644 --- a/src/tests/servers/app/newerClipping/ViewLayer.h +++ b/src/tests/servers/app/newerClipping/ViewLayer.h @@ -116,7 +116,7 @@ private: uint32 fResizeMode; uint32 fFlags; - int32 fShowLevel; + bool fHidden; WindowLayer* fWindow; ViewLayer* fParent; diff --git a/src/tests/servers/app/newerClipping/WindowLayer.cpp b/src/tests/servers/app/newerClipping/WindowLayer.cpp index 0b33c10d8f..4eeaafbd02 100644 --- a/src/tests/servers/app/newerClipping/WindowLayer.cpp +++ b/src/tests/servers/app/newerClipping/WindowLayer.cpp @@ -33,6 +33,11 @@ WindowLayer::WindowLayer(BRect frame, const char* name, fTopLayer(NULL), +// TODO: windows must start hidden! + fHidden(false), + // windows start hidden +// fHidden(true), + fDrawingEngine(drawingEngine), fDesktop(desktop), @@ -273,6 +278,31 @@ WindowLayer::AddChild(ViewLayer* layer) // TODO: trigger redraw for dirty regions } +void +WindowLayer::Hide() +{ + if (fHidden) + return; + + fHidden = true; + + // TODO: notify window manager + // TODO: call RevealNewWMState +} + +void +WindowLayer::Show() +{ + if (!fHidden) + return; + + fHidden = false; + + // TODO: notify window manager + // TODO: call RevealNewWMState + +} + // MarkDirty void WindowLayer::MarkDirty(BRegion* regionOnScreen) diff --git a/src/tests/servers/app/newerClipping/WindowLayer.h b/src/tests/servers/app/newerClipping/WindowLayer.h index 9a78648c98..8b4682c917 100644 --- a/src/tests/servers/app/newerClipping/WindowLayer.h +++ b/src/tests/servers/app/newerClipping/WindowLayer.h @@ -63,6 +63,11 @@ class WindowLayer : public BLooper { void AddChild(ViewLayer* layer); + inline bool IsHidden() const + { return fHidden; } + void Hide(); + void Show(); + void MarkDirty(BRegion* regionOnScreen); void MarkContentDirty(BRegion* regionOnScreen); @@ -100,6 +105,8 @@ class WindowLayer : public BLooper { ViewLayer* fTopLayer; + bool fHidden; + DrawingEngine* fDrawingEngine; Desktop* fDesktop;