git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13162 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Adi Oanca
2005-06-15 20:39:28 +00:00
parent d41a1e80b8
commit 8dbc637219
4 changed files with 81 additions and 90 deletions
Binary file not shown.
+72 -81
View File
@@ -35,20 +35,18 @@ Layer::~Layer()
{ {
Layer *c = fBottom; Layer *c = fBottom;
Layer *toast; Layer *toast;
while (c) while (c) {
{
toast = c; toast = c;
c = c->fUpper; c = c->fUpper;
delete toast; delete toast;
} }
} }
void Layer::ConvertToScreen2(BRect* rect) const void
Layer::ConvertToScreen2(BRect* rect) const
{ {
MyView *view = GetRootLayer(); if (GetRootLayer())
if (view) if (fParent) {
if (fParent)
{
rect->OffsetBy(-fOrigin.x, -fOrigin.y); rect->OffsetBy(-fOrigin.x, -fOrigin.y);
rect->OffsetBy(fFrame.left, fFrame.top); rect->OffsetBy(fFrame.left, fFrame.top);
@@ -56,12 +54,11 @@ void Layer::ConvertToScreen2(BRect* rect) const
} }
} }
void Layer::ConvertToScreen2(BRegion* reg) const void
Layer::ConvertToScreen2(BRegion* reg) const
{ {
MyView *view = GetRootLayer(); if (GetRootLayer())
if (view) if (fParent) {
if (fParent)
{
reg->OffsetBy(-fOrigin.x, -fOrigin.y); reg->OffsetBy(-fOrigin.x, -fOrigin.y);
reg->OffsetBy(fFrame.left, fFrame.top); reg->OffsetBy(fFrame.left, fFrame.top);
@@ -69,7 +66,8 @@ void Layer::ConvertToScreen2(BRegion* reg) const
} }
} }
MyView* Layer::GetRootLayer() const MyView*
Layer::GetRootLayer() const // we already have
{ {
if (fView) if (fView)
return fView; return fView;
@@ -80,42 +78,45 @@ MyView* Layer::GetRootLayer() const
return NULL; return NULL;
} }
Layer* Layer::VirtualBottomChild() const Layer*
Layer::BottomChild() const // we already have
{ {
fCurrent = fBottom; fCurrent = fBottom;
return fCurrent; return fCurrent;
} }
Layer* Layer::VirtualTopChild() const Layer*
Layer::TopChild() const// we already have
{ {
fCurrent = fTop; fCurrent = fTop;
return fCurrent; return fCurrent;
} }
Layer* Layer::VirtualUpperSibling() const Layer*
Layer::UpperSibling() const// we already have
{ {
fCurrent = fCurrent->fUpper; fCurrent = fCurrent->fUpper;
return fCurrent; return fCurrent;
} }
Layer* Layer::VirtualLowerSibling() const Layer*
Layer::LowerSibling() const// we already have
{ {
fCurrent = fCurrent->fLower; fCurrent = fCurrent->fLower;
return fCurrent; return fCurrent;
} }
void Layer::AddLayer(Layer* layer) void
Layer::AddLayer(Layer* layer)// we already have
{ {
if( layer->fParent != NULL ) if( layer->fParent != NULL ) {
{
printf("ERROR: Layer already has a parent\n"); printf("ERROR: Layer already has a parent\n");
return; return;
} }
layer->fParent = this; layer->fParent = this;
if (!fBottom) if (!fBottom) {
{
fBottom = layer; fBottom = layer;
fTop = layer; fTop = layer;
return; return;
@@ -125,10 +126,10 @@ void Layer::AddLayer(Layer* layer)
fBottom = layer; fBottom = layer;
} }
bool Layer::RemLayer(Layer* layer) bool
Layer::RemLayer(Layer* layer)// we already have
{ {
if(!layer->fParent || layer->fParent != this) if(!layer->fParent || layer->fParent != this) {
{
printf("ERROR: Rem: Layer doesn't have a fParent or !=this\n"); printf("ERROR: Rem: Layer doesn't have a fParent or !=this\n");
return false; return false;
} }
@@ -150,13 +151,13 @@ bool Layer::RemLayer(Layer* layer)
layer->fUpper = NULL; layer->fUpper = NULL;
layer->fLower = NULL; layer->fLower = NULL;
layer->clear_visible_regions(); layer->clear_visible_regions(); // TAKE
return true; return true;
} }
bool bool
Layer::IsVisuallyHidden() const Layer::IsHidden() const
{ {
if (fHidden) if (fHidden)
return true; return true;
@@ -166,7 +167,7 @@ Layer::IsVisuallyHidden() const
return false; return false;
if (fParent) if (fParent)
return fParent->IsVisuallyHidden(); return fParent->IsHidden();
return fHidden; return fHidden;
} }
@@ -176,8 +177,7 @@ Layer::Hide()
{ {
fHidden = true; fHidden = true;
if (fParent && !fParent->IsVisuallyHidden() && GetRootLayer()) if (fParent && !fParent->IsHidden() && GetRootLayer()) {
{
// save fullVisible so we know what to invalidate // save fullVisible so we know what to invalidate
BRegion invalid(fFullVisible); BRegion invalid(fFullVisible);
@@ -193,8 +193,7 @@ Layer::Show()
{ {
fHidden = false; fHidden = false;
if (fParent && !fParent->IsVisuallyHidden() && GetRootLayer()) if (fParent && !fParent->IsHidden() && GetRootLayer()) {
{
BRegion invalid; BRegion invalid;
get_user_regions(invalid); get_user_regions(invalid);
@@ -210,14 +209,14 @@ Layer::Invalidate(const BRegion &invalid, const Layer *startFrom)
BRegion localVisible(fFullVisible); BRegion localVisible(fFullVisible);
localVisible.IntersectWith(&invalid); localVisible.IntersectWith(&invalid);
rebuild_visible_regions(invalid, localVisible, rebuild_visible_regions(invalid, localVisible,
startFrom? startFrom: VirtualBottomChild()); startFrom? startFrom: BottomChild());
// add localVisible to our RootLayer's redraw region. // add localVisible to our RootLayer's redraw region.
GetRootLayer()->fRedrawReg.Include(&localVisible); GetRootLayer()->fRedrawReg.Include(&localVisible);
GetRootLayer()->RequestRedraw(); // TODO: what if we pass (fParent, startFromTHIS, &redrawReg)? GetRootLayer()->RequestRedraw(); // TODO: what if we pass (fParent, startFromTHIS, &redrawReg)?
} }
void inline void
Layer::resize_layer_frame_by(float x, float y) Layer::resize_layer_frame_by(float x, float y)
{ {
uint16 rm = fResizeMode & 0x0000FFFF; uint16 rm = fResizeMode & 0x0000FFFF;
@@ -251,8 +250,7 @@ Layer::resize_layer_frame_by(float x, float y)
else if ((rm & 0x00F0U) == _VIEW_CENTER_ << 4) else if ((rm & 0x00F0U) == _VIEW_CENTER_ << 4)
newFrame.bottom += y/2; newFrame.bottom += y/2;
if (newFrame != fFrame) if (newFrame != fFrame) {
{
float dx, dy; float dx, dy;
dx = newFrame.Width() - fFrame.Width(); dx = newFrame.Width() - fFrame.Width();
@@ -260,17 +258,13 @@ Layer::resize_layer_frame_by(float x, float y)
fFrame = newFrame; fFrame = newFrame;
if (dx != 0.0f || dy != 0.0f) if (dx != 0.0f || dy != 0.0f) {
{
// call hook function // call hook function
ResizedByHook(dx, dy, true); // automatic ResizedByHook(dx, dy, true); // automatic
for (Layer *lay = VirtualBottomChild(); for (Layer *lay = BottomChild(); lay; lay = UpperSibling())
lay ; lay = VirtualUpperSibling())
{
lay->resize_layer_frame_by(dx, dy); lay->resize_layer_frame_by(dx, dy);
} }
}
else else
MovedByHook(dx, dy); MovedByHook(dx, dy);
} }
@@ -282,13 +276,10 @@ Layer::rezize_layer_redraw_more(BRegion &reg, float dx, float dy)
if (dx == 0 && dy == 0) if (dx == 0 && dy == 0)
return; return;
for (Layer *lay = VirtualBottomChild(); for (Layer *lay = BottomChild(); lay; lay = UpperSibling()) {
lay; lay = VirtualUpperSibling())
{
uint16 rm = lay->fResizeMode & 0x0000FFFF; uint16 rm = lay->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 lay's old, required region - the one returned // Normaly we shoud've used the lay's old, required region - the one returned
// from get_user_region() with the old frame, and the current one. lay->Bounds() // from get_user_region() with the old frame, and the current one. lay->Bounds()
@@ -336,12 +327,10 @@ Layer::resize_layer_full_update_on_resize(BRegion &reg, float dx, float dy)
if (dx == 0 && dy == 0) if (dx == 0 && dy == 0)
return; return;
for (Layer *lay = VirtualBottomChild(); lay; lay = VirtualUpperSibling()) for (Layer *lay = BottomChild(); lay; lay = UpperSibling()) {
{
uint16 rm = lay->fResizeMode & 0x0000FFFF; uint16 rm = lay->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) {
{
if (lay->fFlags & B_FULL_UPDATE_ON_RESIZE && lay->fVisible.CountRects() > 0) if (lay->fFlags & B_FULL_UPDATE_ON_RESIZE && lay->fVisible.CountRects() > 0)
reg.Include(&lay->fVisible); reg.Include(&lay->fVisible);
@@ -358,16 +347,14 @@ Layer::ResizeBy(float dx, float dy)
fFrame.Set(fFrame.left, fFrame.top, fFrame.right+dx, fFrame.bottom+dy); fFrame.Set(fFrame.left, fFrame.top, fFrame.right+dx, fFrame.bottom+dy);
// resize children using their resize_mask. // resize children using their resize_mask.
for (Layer *lay = VirtualBottomChild(); for (Layer *lay = BottomChild(); lay; lay = UpperSibling())
lay; lay = VirtualUpperSibling())
lay->resize_layer_frame_by(dx, dy); lay->resize_layer_frame_by(dx, dy);
// call hook function // call hook function
if (dx != 0.0f || dy != 0.0f) if (dx != 0.0f || dy != 0.0f)
ResizedByHook(dx, dy, false); // manual ResizedByHook(dx, dy, false); // manual
if (!IsVisuallyHidden() && GetRootLayer()) if (!IsHidden() && GetRootLayer()) {
{
BRegion oldFullVisible(fFullVisible); BRegion oldFullVisible(fFullVisible);
// this is required to invalidate the old border // this is required to invalidate the old border
BRegion oldVisible(fVisible); BRegion oldVisible(fVisible);
@@ -406,8 +393,7 @@ Layer::ResizeBy(float dx, float dy)
// add redrawReg to our RootLayer's redraw region. // add redrawReg to our RootLayer's redraw region.
GetRootLayer()->fRedrawReg.Include(&redrawReg); GetRootLayer()->fRedrawReg.Include(&redrawReg);
// include layer's visible region in case we want a full update on resize // include layer's visible region in case we want a full update on resize
if (fFlags & B_FULL_UPDATE_ON_RESIZE && fVisible.Frame().IsValid()) if (fFlags & B_FULL_UPDATE_ON_RESIZE && fVisible.Frame().IsValid()) {
{
resize_layer_full_update_on_resize(GetRootLayer()->fRedrawReg, dx, dy); resize_layer_full_update_on_resize(GetRootLayer()->fRedrawReg, dx, dy);
GetRootLayer()->fRedrawReg.Include(&fVisible); GetRootLayer()->fRedrawReg.Include(&fVisible);
@@ -429,8 +415,7 @@ void Layer::MoveBy(float dx, float dy)
// call hook function // call hook function
MovedByHook(dx, dy); MovedByHook(dx, dy);
if (!IsVisuallyHidden() && GetRootLayer()) if (!IsHidden() && GetRootLayer()) {
{
BRegion oldFullVisible(fFullVisible); BRegion oldFullVisible(fFullVisible);
// we'll invalidate the old position and the new, maxmial one. // we'll invalidate the old position and the new, maxmial one.
@@ -468,18 +453,18 @@ void Layer::MoveBy(float dx, float dy)
} }
} }
void Layer::ScrollBy(float dx, float dy) void
Layer::ScrollBy(float dx, float dy)
{ {
fOrigin.Set(fOrigin.x + dx, fOrigin.y + dy); fOrigin.Set(fOrigin.x + dx, fOrigin.y + dy);
if (!IsVisuallyHidden() && GetRootLayer()) if (!IsHidden() && GetRootLayer()) {
{
// set the region to be invalidated. // set the region to be invalidated.
BRegion invalid(fFullVisible); BRegion invalid(fFullVisible);
clear_visible_regions(); clear_visible_regions();
rebuild_visible_regions(invalid, invalid, VirtualBottomChild()); rebuild_visible_regions(invalid, invalid, BottomChild());
// for the moment we say that the whole surface needs to be redraw. // for the moment we say that the whole surface needs to be redraw.
BRegion redrawReg(fFullVisible); BRegion redrawReg(fFullVisible);
@@ -504,15 +489,19 @@ void Layer::ScrollBy(float dx, float dy)
ScrolledByHook(dx, dy); ScrolledByHook(dx, dy);
} }
void Layer::GetWantedRegion(BRegion &reg)
void
Layer::GetWantedRegion(BRegion &reg) // TAKE?
{ {
get_user_regions(reg); get_user_regions(reg);
} }
void Layer::get_user_regions(BRegion &reg) void
Layer::get_user_regions(BRegion &reg)
{ {
// OPT: maybe we should have all these cached in a 'fFull' member
// 1) set to frame in screen coords // 1) set to frame in screen coords
BRect screenFrame(Bounds()); BRect screenFrame(Bounds());
ConvertToScreen2(&screenFrame); ConvertToScreen2(&screenFrame);
@@ -540,14 +529,16 @@ wind->Unlock();
*/ */
} }
void Layer::RebuildVisibleRegions(const BRegion &invalid, const Layer *startFrom) void
Layer::RebuildVisibleRegions(const BRegion &invalid, const Layer *startFrom)
{ {
BRegion localVisible(fFullVisible); BRegion localVisible(fFullVisible);
localVisible.IntersectWith(&invalid); localVisible.IntersectWith(&invalid);
rebuild_visible_regions(invalid, localVisible, startFrom); rebuild_visible_regions(invalid, localVisible, startFrom);
} }
void Layer::rebuild_visible_regions(const BRegion &invalid, void
Layer::rebuild_visible_regions(const BRegion &invalid,
const BRegion &parentLocalVisible, const BRegion &parentLocalVisible,
const Layer *startFrom) const Layer *startFrom)
{ {
@@ -588,13 +579,12 @@ void Layer::rebuild_visible_regions(const BRegion &invalid,
BRegion unalteredVisible(common); BRegion unalteredVisible(common);
bool altered = alter_visible_for_children(common); bool altered = alter_visible_for_children(common);
for (Layer *lay = VirtualBottomChild(); lay ; lay = VirtualUpperSibling()) for (Layer *lay = BottomChild(); lay; lay = UpperSibling()) {
{
if (lay == startFrom) if (lay == startFrom)
fullRebuild = true; fullRebuild = true;
if (fullRebuild) if (fullRebuild)
lay->rebuild_visible_regions(invalid, common, lay->VirtualBottomChild()); lay->rebuild_visible_regions(invalid, common, lay->BottomChild());
// to let children know much they can take from parent's visible region // to let children know much they can take from parent's visible region
common.Exclude(&lay->fFullVisible); common.Exclude(&lay->fFullVisible);
@@ -612,31 +602,32 @@ void Layer::rebuild_visible_regions(const BRegion &invalid,
fVisible.Include(&common); fVisible.Include(&common);
} }
bool Layer::alter_visible_for_children(BRegion &reg) bool
Layer::alter_visible_for_children(BRegion &reg)
{ {
// Empty Hook function // Empty Hook function
return false; return false;
} }
void Layer::clear_visible_regions() void
Layer::clear_visible_regions()
{ {
// OPT: maybe we should uncomment these lines for performance // OPT: maybe we should uncomment these lines for performance
// if (fFullVisible.CountRects() <= 0) //if (fFullVisible.CountRects() <= 0)
// return; // return;
fVisible.MakeEmpty(); fVisible.MakeEmpty();
fFullVisible.MakeEmpty(); fFullVisible.MakeEmpty();
for (Layer *child = VirtualBottomChild(); child; for (Layer *child = BottomChild(); child; child = UpperSibling())
child = VirtualUpperSibling())
child->clear_visible_regions(); child->clear_visible_regions();
} }
void Layer::PrintToStream() const void
Layer::PrintToStream() const
{ {
printf("-> %s\n", fName); printf("-> %s\n", fName);
fVisible.PrintToStream(); fVisible.PrintToStream();
fFullVisible.PrintToStream(); fFullVisible.PrintToStream();
for (Layer *child = VirtualBottomChild(); child; for (Layer *child = BottomChild(); child; child = UpperSibling())
child = VirtualUpperSibling())
child->PrintToStream(); child->PrintToStream();
} }
+5 -5
View File
@@ -22,7 +22,7 @@ public:
void ResizeBy(float dx, float dy); void ResizeBy(float dx, float dy);
void ScrollBy(float dx, float dy); void ScrollBy(float dx, float dy);
bool IsVisuallyHidden() const; bool IsHidden() const;
void Hide(); void Hide();
void Show(); void Show();
@@ -33,10 +33,10 @@ public:
virtual void ResizedByHook(float dx, float dy, bool automatic) { } virtual void ResizedByHook(float dx, float dy, bool automatic) { }
virtual void ScrolledByHook(float dx, float dy) { } virtual void ScrolledByHook(float dx, float dy) { }
Layer* VirtualBottomChild() const; Layer* BottomChild() const;
Layer* VirtualTopChild() const; Layer* TopChild() const;
Layer* VirtualUpperSibling() const; Layer* UpperSibling() const;
Layer* VirtualLowerSibling() const; Layer* LowerSibling() const;
void RebuildVisibleRegions( const BRegion &invalid, void RebuildVisibleRegions( const BRegion &invalid,
const Layer *startFrom); const Layer *startFrom);
+2 -2
View File
@@ -94,7 +94,7 @@ Layer* MyView::FindLayer(Layer *lay, BPoint &where) const
if (lay->Visible()->Contains(where)) if (lay->Visible()->Contains(where))
return lay; return lay;
else else
for (Layer *child = lay->VirtualBottomChild(); child; child = lay->VirtualUpperSibling()) for (Layer *child = lay->BottomChild(); child; child = lay->UpperSibling())
{ {
Layer *found = FindLayer(child, where); Layer *found = FindLayer(child, where);
if (found) if (found)
@@ -302,7 +302,7 @@ void MyView::DrawSubTree(Layer* lay)
//printf("======== %s =======\n", lay->Name()); //printf("======== %s =======\n", lay->Name());
// lay->Visible()->PrintToStream(); // lay->Visible()->PrintToStream();
// lay->FullVisible()->PrintToStream(); // lay->FullVisible()->PrintToStream();
for (Layer *child = lay->VirtualBottomChild(); child; child = lay->VirtualUpperSibling()) for (Layer *child = lay->BottomChild(); child; child = lay->UpperSibling())
DrawSubTree(child); DrawSubTree(child);
ConstrainClippingRegion(lay->Visible()); ConstrainClippingRegion(lay->Visible());