Implemented some support for moving and reziving Layers. It works too. :-)
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@12701 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Binary file not shown.
@@ -1,20 +1,21 @@
|
|||||||
#include <OS.h>
|
#include <OS.h>
|
||||||
#include <View.h>
|
|
||||||
#include <Window.h>
|
|
||||||
#include <Looper.h>
|
|
||||||
#include <Region.h>
|
#include <Region.h>
|
||||||
#include <Rect.h>
|
#include <Rect.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
|
|
||||||
|
#include <Window.h>
|
||||||
|
|
||||||
#include "Layer.h"
|
#include "Layer.h"
|
||||||
|
#include "MyView.h"
|
||||||
|
|
||||||
extern BWindow* wind;
|
extern BWindow* wind;
|
||||||
|
|
||||||
Layer::Layer(BRect frame, const char* name, uint32 rm, rgb_color c)
|
Layer::Layer(BRect frame, const char* name, uint32 rm, rgb_color c)
|
||||||
{
|
{
|
||||||
fFrame = frame;
|
fFrame = frame;
|
||||||
fRM = rm;
|
fOrigin.Set(0.0f, 0.0f);
|
||||||
|
fResizeMode = rm;
|
||||||
fColor = c;
|
fColor = c;
|
||||||
|
|
||||||
fBottom = NULL;
|
fBottom = NULL;
|
||||||
@@ -41,7 +42,7 @@ Layer::~Layer()
|
|||||||
|
|
||||||
void Layer::ConvertToScreen2(BRect* rect)
|
void Layer::ConvertToScreen2(BRect* rect)
|
||||||
{
|
{
|
||||||
BView *view = GetRootLayer();
|
MyView *view = GetRootLayer();
|
||||||
if (view)
|
if (view)
|
||||||
if (fParent)
|
if (fParent)
|
||||||
{
|
{
|
||||||
@@ -54,7 +55,7 @@ void Layer::ConvertToScreen2(BRect* rect)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BView* Layer::GetRootLayer() const
|
MyView* Layer::GetRootLayer() const
|
||||||
{
|
{
|
||||||
if (fView)
|
if (fView)
|
||||||
return fView;
|
return fView;
|
||||||
@@ -136,6 +137,176 @@ bool Layer::RemLayer(Layer* layer)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Layer::IsVisuallyHidden() const
|
||||||
|
{
|
||||||
|
// TODO: implement
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Layer::resize_layer_frame_by(float x, float y)
|
||||||
|
{
|
||||||
|
uint16 rm = fResizeMode & 0x0000FFFF;
|
||||||
|
BRect newFrame = fFrame;
|
||||||
|
float dx, dy;
|
||||||
|
|
||||||
|
if ((rm & 0x000FU) == _VIEW_LEFT_)
|
||||||
|
{
|
||||||
|
newFrame.left += 0.0f;
|
||||||
|
newFrame.right += x;
|
||||||
|
}
|
||||||
|
else if ((rm & 0x000FU) == _VIEW_RIGHT_)
|
||||||
|
{
|
||||||
|
newFrame.left += x;
|
||||||
|
newFrame.right += x;
|
||||||
|
}
|
||||||
|
else if ((rm & 0x000FU) == _VIEW_CENTER_)
|
||||||
|
{
|
||||||
|
newFrame.left += x/2;
|
||||||
|
newFrame.right += x/2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((rm & 0x00F0U) == _VIEW_TOP_)
|
||||||
|
{
|
||||||
|
newFrame.top += 0.0f;
|
||||||
|
newFrame.bottom += y;
|
||||||
|
}
|
||||||
|
else if ((rm & 0x00F0U) == _VIEW_BOTTOM_)
|
||||||
|
{
|
||||||
|
newFrame.top += y;
|
||||||
|
newFrame.bottom += y;
|
||||||
|
}
|
||||||
|
else if ((rm & 0x00F0U) == _VIEW_CENTER_)
|
||||||
|
{
|
||||||
|
newFrame.top += y/2;
|
||||||
|
newFrame.bottom += y/2;
|
||||||
|
}
|
||||||
|
|
||||||
|
dx = newFrame.Width() - fFrame.Width();
|
||||||
|
dy = newFrame.Height() - fFrame.Height();
|
||||||
|
|
||||||
|
fFrame = newFrame;
|
||||||
|
|
||||||
|
for (Layer *lay = VirtualBottomChild(); lay ; lay = VirtualUpperSibling())
|
||||||
|
{
|
||||||
|
lay->resize_layer_frame_by(dx, dy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Layer::ResizeBy(float dx, float dy)
|
||||||
|
{
|
||||||
|
// TODO: add support for B_FULL_UPDATE_ON_RESIZE
|
||||||
|
// TODO: center and right alligned view must be full redrawn
|
||||||
|
|
||||||
|
fFrame.Set(fFrame.left, fFrame.top, fFrame.right+dx, fFrame.bottom+dy);
|
||||||
|
|
||||||
|
// resize children using their resize_mask.
|
||||||
|
for (Layer *lay = fParent->VirtualBottomChild();
|
||||||
|
lay; lay = fParent->VirtualUpperSibling())
|
||||||
|
lay->resize_layer_frame_by(dx, dy);
|
||||||
|
|
||||||
|
if (!IsVisuallyHidden() && GetRootLayer())
|
||||||
|
{
|
||||||
|
BRegion oldFullVisible(fFullVisible);
|
||||||
|
|
||||||
|
// we'll invalidate the old position and the new, maxmial, one (bounds in screen coords).
|
||||||
|
BRegion invalid(fFullVisible);
|
||||||
|
BRect r(Bounds());
|
||||||
|
ConvertToScreen2(&r);
|
||||||
|
invalid.Include(r);
|
||||||
|
|
||||||
|
clear_visible_regions();
|
||||||
|
|
||||||
|
fParent->RebuildVisibleRegions(invalid, this);
|
||||||
|
|
||||||
|
// done rebuilding regions, now redraw regions that became visible
|
||||||
|
|
||||||
|
// what's invalid, are the differences between to old and the new fullVisible region
|
||||||
|
// 1) in case we grow.
|
||||||
|
BRegion redrawReg(fFullVisible);
|
||||||
|
redrawReg.Exclude(&oldFullVisible);
|
||||||
|
// 2) in case we shrink
|
||||||
|
BRegion redrawReg2(oldFullVisible);
|
||||||
|
redrawReg2.Exclude(&fFullVisible);
|
||||||
|
// 3) combine.
|
||||||
|
redrawReg.Include(&redrawReg2);
|
||||||
|
|
||||||
|
// add redrawReg to our RootLayer's redraw region.
|
||||||
|
GetRootLayer()->fRedrawReg.Include(&redrawReg);
|
||||||
|
GetRootLayer()->RequestRedraw(); // TODO: what if we pass (fParent, startFromTHIS, &redrawReg)?
|
||||||
|
}
|
||||||
|
|
||||||
|
// call hook function
|
||||||
|
if (dx != 0.0f || dy != 0.0f)
|
||||||
|
ResizedByHook(dx, dy);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Layer::MoveBy(float dx, float dy)
|
||||||
|
{
|
||||||
|
fFrame.Set(fFrame.left+dx, fFrame.top+dy, fFrame.right+dx, fFrame.bottom+dy);
|
||||||
|
|
||||||
|
if (!IsVisuallyHidden() && GetRootLayer())
|
||||||
|
{
|
||||||
|
BRegion oldFullVisible(fFullVisible);
|
||||||
|
|
||||||
|
// we'll invalidate the old position and the new, maxmial, one (bounds in screen coords).
|
||||||
|
BRegion invalid(fFullVisible);
|
||||||
|
BRect r(Bounds());
|
||||||
|
ConvertToScreen2(&r);
|
||||||
|
invalid.Include(r);
|
||||||
|
|
||||||
|
clear_visible_regions();
|
||||||
|
|
||||||
|
fParent->RebuildVisibleRegions(invalid, this);
|
||||||
|
|
||||||
|
// done rebuilding regions, now copy common parts and redraw regions that became visible
|
||||||
|
|
||||||
|
// include the actual and the old fullVisible regions. later, we'll exclude the common parts.
|
||||||
|
BRegion redrawReg(fFullVisible);
|
||||||
|
redrawReg.Include(&oldFullVisible);
|
||||||
|
|
||||||
|
// offset to layer's new location so that we can calculate the common region.
|
||||||
|
oldFullVisible.OffsetBy(dx, dy);
|
||||||
|
|
||||||
|
// finally we have the region that needs to be redrawn.
|
||||||
|
redrawReg.Exclude(&oldFullVisible);
|
||||||
|
|
||||||
|
// by intersecting the old fullVisible offseted to layer's new location, with the current
|
||||||
|
// fullVisible, we'll have the common region which can be copied using HW acceleration.
|
||||||
|
oldFullVisible.IntersectWith(&fFullVisible);
|
||||||
|
|
||||||
|
// offset back and instruct the HW to do the actual copying.
|
||||||
|
oldFullVisible.OffsetBy(-dx, -dy);
|
||||||
|
// TODO: HACK this!
|
||||||
|
// GetDisplayDriver()->CopyRegion(&oldFullVisible, dx, dy);
|
||||||
|
|
||||||
|
// add redrawReg to our RootLayer's redraw region.
|
||||||
|
GetRootLayer()->fRedrawReg.Include(&redrawReg);
|
||||||
|
GetRootLayer()->RequestRedraw(); // TODO: what if we pass (fParent, startFromTHIS, &redrawReg)?
|
||||||
|
}
|
||||||
|
|
||||||
|
// call hook function
|
||||||
|
if (dx != 0.0f || dy != 0.0f)
|
||||||
|
MovedByHook(dx, dy);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Layer::ScrollBy(float dx, float dy)
|
||||||
|
{
|
||||||
|
fOrigin.Set(fOrigin.x + dx, fOrigin.y + dy);
|
||||||
|
|
||||||
|
if (!IsVisuallyHidden() && GetRootLayer())
|
||||||
|
{
|
||||||
|
clear_visible_regions();
|
||||||
|
|
||||||
|
RebuildVisibleRegions(fFullVisible, VirtualBottomChild());
|
||||||
|
|
||||||
|
// TODO: continue
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dx != 0.0f || dy != 0.0f)
|
||||||
|
ScrolledByHook(dx, dy);
|
||||||
|
}
|
||||||
|
|
||||||
void Layer::set_user_regions(BRegion ®)
|
void Layer::set_user_regions(BRegion ®)
|
||||||
{
|
{
|
||||||
// OPT: maybe we should have all these cached in a 'fFull' member
|
// OPT: maybe we should have all these cached in a 'fFull' member
|
||||||
@@ -149,8 +320,6 @@ void Layer::set_user_regions(BRegion ®)
|
|||||||
// 2) intersect with screen region
|
// 2) intersect with screen region
|
||||||
// TODO: remove locking when for real
|
// TODO: remove locking when for real
|
||||||
wind->Lock();
|
wind->Lock();
|
||||||
printf("Adi: RL: %p\n", wind);
|
|
||||||
printf("Adi: RL: %s\n", wind->Name());
|
|
||||||
BRegion screenReg(GetRootLayer()->Bounds());
|
BRegion screenReg(GetRootLayer()->Bounds());
|
||||||
wind->Unlock();
|
wind->Unlock();
|
||||||
reg.IntersectWith(&screenReg);
|
reg.IntersectWith(&screenReg);
|
||||||
@@ -193,8 +362,7 @@ void Layer::rebuild_visible_regions(const BRegion &invalid,
|
|||||||
|
|
||||||
// now intersect with parent's visible part of the region that was/is invalidated
|
// now intersect with parent's visible part of the region that was/is invalidated
|
||||||
common.IntersectWith(&parentLocalVisible);
|
common.IntersectWith(&parentLocalVisible);
|
||||||
//printf("\t%s: For this layer we invalidate:\n", fName);
|
|
||||||
//common.PrintToStream();
|
|
||||||
if (common.Frame().IsValid())
|
if (common.Frame().IsValid())
|
||||||
{
|
{
|
||||||
// we have something to include to our fullVisible. It may already be in
|
// we have something to include to our fullVisible. It may already be in
|
||||||
@@ -226,7 +394,7 @@ void Layer::rebuild_visible_regions(const BRegion &invalid,
|
|||||||
lay->rebuild_visible_regions(invalid, common, lay->VirtualBottomChild());
|
lay->rebuild_visible_regions(invalid, common, lay->VirtualBottomChild());
|
||||||
|
|
||||||
common.Exclude(&lay->fFullVisible);
|
common.Exclude(&lay->fFullVisible);
|
||||||
fVisible.Exclude(&lay->fFullVisible);
|
fVisible.Exclude(&lay->fFullVisible);
|
||||||
}
|
}
|
||||||
|
|
||||||
// the visible region of this layer is what left after all its children took
|
// the visible region of this layer is what left after all its children took
|
||||||
@@ -238,11 +406,11 @@ void Layer::clear_visible_regions()
|
|||||||
{
|
{
|
||||||
fVisible.MakeEmpty();
|
fVisible.MakeEmpty();
|
||||||
fFullVisible.MakeEmpty();
|
fFullVisible.MakeEmpty();
|
||||||
Layer *child = fBottom;
|
Layer *child = VirtualBottomChild();
|
||||||
while (child)
|
while (child)
|
||||||
{
|
{
|
||||||
child->clear_visible_regions();
|
child->clear_visible_regions();
|
||||||
child = child->fUpper;
|
child = child->VirtualUpperSibling();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
#include <Rect.h>
|
#include <Rect.h>
|
||||||
#include <GraphicsDefs.h>
|
#include <GraphicsDefs.h>
|
||||||
|
|
||||||
class BView;
|
class MyView;
|
||||||
|
|
||||||
class Layer
|
class Layer
|
||||||
{
|
{
|
||||||
@@ -14,6 +14,14 @@ public:
|
|||||||
void AddLayer(Layer* layer);
|
void AddLayer(Layer* layer);
|
||||||
bool RemLayer(Layer* layer);
|
bool RemLayer(Layer* layer);
|
||||||
|
|
||||||
|
void MoveBy(float dx, float dy);
|
||||||
|
void ResizeBy(float dx, float dy);
|
||||||
|
void ScrollBy(float dx, float dy);
|
||||||
|
|
||||||
|
virtual void MovedByHook(float dx, float dy) { }
|
||||||
|
virtual void ResizedByHook(float dx, float dy) { }
|
||||||
|
virtual void ScrolledByHook(float dx, float dy) { }
|
||||||
|
|
||||||
Layer* VirtualBottomChild() const;
|
Layer* VirtualBottomChild() const;
|
||||||
Layer* VirtualTopChild() const;
|
Layer* VirtualTopChild() const;
|
||||||
Layer* VirtualUpperSibling() const;
|
Layer* VirtualUpperSibling() const;
|
||||||
@@ -22,15 +30,16 @@ public:
|
|||||||
void RebuildVisibleRegions( const BRegion &invalid,
|
void RebuildVisibleRegions( const BRegion &invalid,
|
||||||
const Layer *startFrom);
|
const Layer *startFrom);
|
||||||
void ConvertToScreen2(BRect* rect);
|
void ConvertToScreen2(BRect* rect);
|
||||||
BView* GetRootLayer() const;
|
MyView* GetRootLayer() const;
|
||||||
void SetRootLayer(BView* view) { fView = view; }
|
void SetRootLayer(MyView* view) { fView = view; }
|
||||||
|
bool IsVisuallyHidden() const;
|
||||||
|
|
||||||
BRegion* Visible() { return &fVisible; }
|
BRegion* Visible() { return &fVisible; }
|
||||||
BRegion* FullVisible() { return &fFullVisible; }
|
BRegion* FullVisible() { return &fFullVisible; }
|
||||||
|
|
||||||
BRect Frame() const { return fFrame; }
|
BRect Frame() const { return fFrame; }
|
||||||
BRect Bounds() const { BRect r(fFrame);
|
BRect Bounds() const { BRect r(fFrame);
|
||||||
r.OffsetTo(0,0);
|
r.OffsetTo(fOrigin);
|
||||||
return r; }
|
return r; }
|
||||||
const char* Name() const { return fName; }
|
const char* Name() const { return fName; }
|
||||||
Layer* Parent() const { return fParent; }
|
Layer* Parent() const { return fParent; }
|
||||||
@@ -44,13 +53,15 @@ public:
|
|||||||
private:
|
private:
|
||||||
void set_user_regions(BRegion ®);
|
void set_user_regions(BRegion ®);
|
||||||
void clear_visible_regions();
|
void clear_visible_regions();
|
||||||
|
void resize_layer_frame_by(float x, float y);
|
||||||
|
|
||||||
char fName[50];
|
char fName[50];
|
||||||
BRegion fVisible;
|
BRegion fVisible;
|
||||||
BRegion fFullVisible;
|
BRegion fFullVisible;
|
||||||
|
|
||||||
BRect fFrame;
|
BRect fFrame;
|
||||||
uint32 fRM;
|
BPoint fOrigin;
|
||||||
|
uint32 fResizeMode;
|
||||||
rgb_color fColor;
|
rgb_color fColor;
|
||||||
|
|
||||||
Layer* fBottom;
|
Layer* fBottom;
|
||||||
@@ -59,5 +70,5 @@ private:
|
|||||||
Layer* fTop;
|
Layer* fTop;
|
||||||
Layer* fParent;
|
Layer* fParent;
|
||||||
|
|
||||||
BView* fView;
|
MyView* fView;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
#include <Message.h>
|
#include <Message.h>
|
||||||
#include <Messenger.h>
|
#include <Messenger.h>
|
||||||
|
#include <Window.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "MyView.h"
|
#include "MyView.h"
|
||||||
#include "Layer.h"
|
#include "Layer.h"
|
||||||
|
|
||||||
|
extern BWindow *wind;
|
||||||
|
|
||||||
MyView::MyView(BRect frame, const char *name, uint32 resizingMode, uint32 flags)
|
MyView::MyView(BRect frame, const char *name, uint32 resizingMode, uint32 flags)
|
||||||
: BView(frame, name, resizingMode, flags)
|
: BView(frame, name, resizingMode, flags)
|
||||||
{
|
{
|
||||||
@@ -45,6 +48,14 @@ Layer* MyView::FindLayer(Layer *lay, const char *bytes) const
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MyView::RequestRedraw()
|
||||||
|
{
|
||||||
|
// TODO: implement
|
||||||
|
wind->Lock();
|
||||||
|
Invalidate();
|
||||||
|
wind->Unlock();
|
||||||
|
}
|
||||||
|
|
||||||
void MyView::Draw(BRect area)
|
void MyView::Draw(BRect area)
|
||||||
{
|
{
|
||||||
DrawSubTree(topLayer);
|
DrawSubTree(topLayer);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include <OS.h>
|
#include <OS.h>
|
||||||
#include <View.h>
|
#include <View.h>
|
||||||
|
#include <Region.h>
|
||||||
|
|
||||||
class Layer;
|
class Layer;
|
||||||
|
|
||||||
@@ -11,9 +12,12 @@ public:
|
|||||||
|
|
||||||
virtual void Draw(BRect area);
|
virtual void Draw(BRect area);
|
||||||
|
|
||||||
|
void RequestRedraw();
|
||||||
|
|
||||||
Layer* FindLayer(Layer *lay, const char *bytes) const;
|
Layer* FindLayer(Layer *lay, const char *bytes) const;
|
||||||
|
|
||||||
Layer *topLayer;
|
Layer *topLayer;
|
||||||
|
BRegion fRedrawReg;
|
||||||
private:
|
private:
|
||||||
void DrawSubTree(Layer* lay);
|
void DrawSubTree(Layer* lay);
|
||||||
};
|
};
|
||||||
@@ -80,7 +80,7 @@ bool clsMainWindow::QuitRequested()
|
|||||||
void clsMainWindow::test1()
|
void clsMainWindow::test1()
|
||||||
{
|
{
|
||||||
Layer *topLayer = fView->topLayer;
|
Layer *topLayer = fView->topLayer;
|
||||||
Layer *parent;
|
// Layer *parent;
|
||||||
|
|
||||||
rgb_color c;
|
rgb_color c;
|
||||||
BRect temp;
|
BRect temp;
|
||||||
@@ -110,7 +110,7 @@ void clsMainWindow::test1()
|
|||||||
wind->Lock();
|
wind->Lock();
|
||||||
fView->Invalidate();
|
fView->Invalidate();
|
||||||
wind->Unlock();
|
wind->Unlock();
|
||||||
|
/*
|
||||||
snooze(2000000);
|
snooze(2000000);
|
||||||
|
|
||||||
temp = lay2->Bounds();
|
temp = lay2->Bounds();
|
||||||
@@ -125,6 +125,14 @@ void clsMainWindow::test1()
|
|||||||
wind->Lock();
|
wind->Lock();
|
||||||
fView->Invalidate();
|
fView->Invalidate();
|
||||||
wind->Unlock();
|
wind->Unlock();
|
||||||
|
*/
|
||||||
|
snooze(2000000);
|
||||||
|
|
||||||
|
lay2->MoveBy(25,35);
|
||||||
|
|
||||||
|
snooze(2000000);
|
||||||
|
|
||||||
|
lay2->ResizeBy(45,55);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user