work in progress to get scrolling working, so Adi can have a look, no changes to existing functionality, cleanup in Layer.cpp

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@12481 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus 2005-04-27 17:26:57 +00:00
parent 28930a1240
commit db7226db9d
6 changed files with 1099 additions and 1000 deletions

View File

@ -54,6 +54,7 @@ class DrawData {
// coordinate transformation
void SetOrigin(const BPoint& origin);
void OffsetOrigin(const BPoint& offset);
inline const BPoint& Origin() const
{ return fOrigin; }

File diff suppressed because it is too large Load Diff

View File

@ -22,6 +22,7 @@
// File Name: Layer.h
// Author: DarkWyrm <bpmagic@columbus.rr.com>
// Adi Oanca <adioanca@cotty.iren.com>
// Stephan Aßmus <superstippi@gmx.de>
// Description: Class used for rendering to the frame buffer. One layer per
// view on screen and also for window decorators
//
@ -30,17 +31,17 @@
#define _LAYER_H_
#include <GraphicsDefs.h>
#include <List.h>
#include <Locker.h>
#include <OS.h>
#include <String.h>
#include <Rect.h>
#include <Region.h>
#include <List.h>
#include <String.h>
#include <OS.h>
#include <Locker.h>
#include "ServerWindow.h"
#include "RGBColor.h"
enum
{
#include "RGBColor.h"
#include "ServerWindow.h"
enum {
B_LAYER_NONE = 1,
B_LAYER_MOVE = 2,
B_LAYER_SIMPLE_MOVE = 3,
@ -48,14 +49,12 @@ enum
B_LAYER_MASK_RESIZE = 5,
};
enum
{
enum {
B_LAYER_CHILDREN_DEPENDANT = 0x1000U,
};
// easy way to determine class type
enum
{
enum {
AS_LAYER_CLASS = 1,
AS_WINBORDER_CLASS = 2,
AS_ROOTLAYER_CLASS = 3,
@ -66,90 +65,128 @@ class RootLayer;
class DisplayDriver;
class LayerData;
class Layer
{
public:
Layer(BRect frame, const char *name, int32 token, uint32 resize,
uint32 flags, DisplayDriver *driver);
virtual ~Layer(void);
class Layer {
public:
Layer(BRect frame, const char* name,
int32 token, uint32 resize,
uint32 flags, DisplayDriver* driver);
virtual ~Layer();
void AddChild(Layer *child, ServerWindow *serverWin);
void RemoveChild(Layer *child);
void RemoveSelf(void);
bool HasChild(Layer *layer);
RootLayer *GetRootLayer(void) const { return fRootLayer; }
uint32 CountChildren(void) const;
Layer *FindLayer(const int32 token);
Layer *LayerAt(const BPoint &pt);
bool IsTopLayer(void) { return fIsTopLayer; }
virtual Layer *VirtualTopChild(void) const;
virtual Layer *VirtualLowerSibling(void) const;
virtual Layer *VirtualUpperSibling(void) const;
virtual Layer *VirtualBottomChild(void) const;
const char *GetName(void) const { return (fName)?fName->String():NULL; }
virtual void RebuildFullRegion(void);
void StartRebuildRegions( const BRegion& reg, Layer *target, uint32 action, BPoint& pt);
void RebuildRegions( const BRegion& reg, uint32 action, BPoint pt, BPoint ptOffset);
uint32 ResizeOthers(float x, float y, BPoint coords[], BPoint *ptOffset);
void Redraw(const BRegion& reg, Layer *startFrom=NULL);
void EmptyGlobals(void);
virtual void Draw(const BRect &r);
void Show(bool invalidate=true);
void Hide(bool invalidate=true);
bool IsHidden(void) const;
BRect Bounds(void) const;
BRect Frame(void) const;
virtual void MoveBy(float x, float y);
virtual void ResizeBy(float x, float y);
BRect ConvertToParent(BRect rect);
BRegion ConvertToParent(BRegion *reg);
BPoint ConvertFromParent(BPoint pt);
BRect ConvertFromParent(BRect rect);
BRegion ConvertFromParent(BRegion *reg);
BPoint ConvertToTop(BPoint pt);
BRegion ConvertToTop(BRegion *reg);
BRect ConvertToTop(BRect rect);
void AddChild(Layer* child, ServerWindow* serverWin);
void RemoveChild(Layer* child);
void RemoveSelf();
bool HasChild(Layer* layer);
BPoint ConvertFromTop(BPoint pt);
BRegion ConvertFromTop(BRegion *reg);
BRect ConvertFromTop(BRect rect);
RootLayer* GetRootLayer() const
{ return fRootLayer; }
DisplayDriver *GetDisplayDriver(void) const { return fDriver; }
ServerWindow *Window(void) const { return fServerWin; }
ServerApp *App(void) const { return fServerWin? fServerWin->App(): NULL; }
virtual bool HasClient(void) { return true; }
bool IsServerLayer() const;
uint32 EventMask(void) const { return fEventMask; }
uint32 EventOptions(void) const { return fEventOptions; }
uint32 CountChildren() const;
Layer* FindLayer(const int32 token);
Layer* LayerAt(const BPoint &pt);
void PruneTree(void);
virtual Layer* VirtualTopChild() const;
virtual Layer* VirtualLowerSibling() const;
virtual Layer* VirtualUpperSibling() const;
virtual Layer* VirtualBottomChild() const;
void PrintToStream(void);
void PrintNode(void);
void PrintTree(void);
const char* GetName() const
{ return (fName) ? fName->String() : NULL; }
virtual void RebuildFullRegion();
void StartRebuildRegions(const BRegion& reg,
Layer* target,
uint32 action,
BPoint& pt);
void RebuildRegions(const BRegion& reg,
uint32 action,
BPoint pt,
BPoint ptOffset);
uint32 ResizeOthers(float x, float y,
BPoint coords[],
BPoint* ptOffset);
void Redraw(const BRegion& reg,
Layer* startFrom = NULL);
virtual void Draw(const BRect& r);
void EmptyGlobals();
void Show(bool invalidate = true);
void Hide(bool invalidate = true);
bool IsHidden() const;
// coordinate system
BRect Bounds() const;
BRect Frame() const;
virtual void MoveBy(float x, float y);
virtual void ResizeBy(float x, float y);
BPoint BoundsOrigin() const; // BoundsFrameDiff()?
BPoint ConvertToParent(BPoint pt);
BRect ConvertToParent(BRect rect);
BRegion ConvertToParent(BRegion* reg);
BPoint ConvertFromParent(BPoint pt);
BRect ConvertFromParent(BRect rect);
BRegion ConvertFromParent(BRegion* reg);
BPoint ConvertToTop(BPoint pt);
BRect ConvertToTop(BRect rect);
BRegion ConvertToTop(BRegion* reg);
BPoint ConvertFromTop(BPoint pt);
BRect ConvertFromTop(BRect rect);
BRegion ConvertFromTop(BRegion *reg);
DisplayDriver* GetDisplayDriver() const
{ return fDriver; }
ServerWindow* Window() const
{ return fServerWin; }
ServerApp* App() const
{ return fServerWin? fServerWin->App(): NULL; }
virtual bool HasClient()
{ return true; }
// bool IsServerLayer() const;
uint32 EventMask() const
{ return fEventMask; }
uint32 EventOptions() const
{ return fEventOptions; }
void PruneTree();
// debugging
void PrintToStream();
void PrintNode();
void PrintTree();
// server "private" - should not be used
void SetRootLayer(RootLayer *rl){ fRootLayer = rl; }
void SetAsTopLayer(bool option) { fIsTopLayer = option; }
bool IsTopLayer() const { return fIsTopLayer; }
void SetRootLayer(RootLayer* rl)
{ fRootLayer = rl; }
void UpdateStart();
void UpdateEnd();
BRegion* ClippingRegion() const { return fClipReg; }
void SetAsTopLayer(bool option)
{ fIsTopLayer = option; }
protected:
bool IsTopLayer() const
{ return fIsTopLayer; }
void UpdateStart();
void UpdateEnd();
BRegion* ClippingRegion() const
{ return fClipReg; }
protected:
friend class RootLayer;
friend class WinBorder;
friend class ServerWindow;
@ -157,56 +194,57 @@ protected:
void move_layer(float x, float y);
void resize_layer(float x, float y);
void FullInvalidate(const BRect &rect);
void FullInvalidate(const BRegion &region);
void Invalidate(const BRegion &region);
void FullInvalidate(const BRect& rect);
void FullInvalidate(const BRegion& region);
void Invalidate(const BRegion& region);
BRect fFrame;
BPoint fBoundsLeftTop;
WinBorder *fOwner;
Layer *fParent;
Layer *fUpperSibling;
Layer *fLowerSibling;
Layer *fTopChild;
Layer *fBottomChild;
BRect fFrame;
// BPoint fBoundsLeftTop;
WinBorder* fOwner;
Layer* fParent;
Layer* fUpperSibling;
Layer* fLowerSibling;
Layer* fTopChild;
Layer* fBottomChild;
mutable Layer *fCurrent;
mutable Layer* fCurrent;
BRegion fVisible;
BRegion fFullVisible;
BRegion fFull;
BRegion *fClipReg;
BRegion *clipToPicture;
bool clipToPictureInverse;
ServerWindow *fServerWin;
BString *fName;
int32 fViewToken;
uint32 fFlags;
uint32 fResizeMode;
uint32 fEventMask;
uint32 fEventOptions;
bool fHidden;
bool fIsTopLayer;
uint16 fAdFlags;
int8 fClassID;
int8 fFrameAction;
DisplayDriver *fDriver;
LayerData *fLayerData;
//RGBColor fBackColor;
RootLayer *fRootLayer;
BRegion fVisible;
BRegion fFullVisible;
BRegion fFull;
private:
void RequestDraw(const BRegion &reg, Layer *startFrom);
ServerWindow *SearchForServerWindow(void);
BRegion* fClipReg;
BRegion* clipToPicture;
bool clipToPictureInverse;
ServerWindow* fServerWin;
BString* fName;
int32 fViewToken;
uint32 fFlags;
uint32 fResizeMode;
uint32 fEventMask;
uint32 fEventOptions;
bool fHidden;
bool fIsTopLayer;
uint16 fAdFlags;
int8 fClassID;
int8 fFrameAction;
DisplayDriver* fDriver;
LayerData* fLayerData;
RootLayer* fRootLayer;
void SendUpdateMsg(BRegion &reg);
void SendViewMovedMsg(void);
void SendViewResizedMsg(void);
private:
void RequestDraw(const BRegion& reg,
Layer* startFrom);
ServerWindow* SearchForServerWindow();
void SendUpdateMsg(BRegion& reg);
void SendViewMovedMsg();
void SendViewResizedMsg();
};
#endif
#endif // _LAYER_H_

View File

@ -121,6 +121,13 @@ DrawData::SetOrigin(const BPoint& origin)
fOrigin = origin;
}
// OffsetOrigin
void
DrawData::OffsetOrigin(const BPoint& offset)
{
fOrigin += offset;
}
// SetScale
void
DrawData::SetScale(float scale)

View File

@ -520,21 +520,45 @@ void ServerWindow::DispatchMessage(int32 code, LinkMsgReader &link)
}
break;
}
case AS_LAYER_SCROLL:
{
printf("AS_LAYER_SCROLL\n");
float dh;
float dv;
link.Read<float>(&dh);
link.Read<float>(&dv);
// scroll visually by using the CopyBits() implementation
// this will also take care of invalidating previously invisible
// areas (areas scrolled into view)
BRect src = cl->Bounds();
BRect dst = src;
// NOTE: if we scroll down, the contents are moved *up*
dst.OffsetBy(-dh, -dv);
// TODO: Are origin and scale handled in this conversion?
src = cl->ConvertToTop(src);
dst = cl->ConvertToTop(dst);
int32 xOffset = (int32)(dst.left - src.left);
int32 yOffset = (int32)(dst.top - src.top);
// this little detail is where it differs from CopyBits()
// -> it will invalidate areas previously out of screen
dst = dst | src;
_CopyBits(myRootLayer, cl, src, dst, xOffset, yOffset);
// TODO: notify the client, no?
cl->fLayerData->OffsetOrigin(BPoint(dh, dv));
//cl->fBoundsLeftTop += BPoint(dh, dv);
//cl->fFrame.OffsetBy(BPoint(-dh, -dv));
break;
}
case AS_LAYER_COPY_BITS:
{
// NOTE: The correct behaviour is this:
// * The region that is copied is the
// src rectangle, no matter if it fits
// into the dst rectangle. It is copied
// by the offset dst.LeftTop() - src.LeftTop()
// * The dst rectangle is used for invalidation:
// Any area in the dst rectangle that could
// not be copied from src (because either the
// src rectangle was not big enough, or because there
// were parts cut off by the current layer clipping),
// are triggering BView::Draw() to be called
// and for these parts only.
BRect src;
BRect dst;
@ -544,34 +568,11 @@ void ServerWindow::DispatchMessage(int32 code, LinkMsgReader &link)
// TODO: Are origin and scale handled in this conversion?
src = cl->ConvertToTop(src);
dst = cl->ConvertToTop(dst);
int32 xOffset = (int32)(dst.left - src.left);
int32 yOffset = (int32)(dst.top - src.top);
// the region that is going to be copied
BRegion copyRegion(src);
// apply the current clipping of the layer
copyRegion.IntersectWith(&cl->fVisible);
// offset the region to the destination
// and apply the current clipping there as well
copyRegion.OffsetBy(xOffset, yOffset);
copyRegion.IntersectWith(&cl->fVisible);
// the region at the destination that needs invalidation
BRegion invalidRegion(dst);
// exclude the region drawn by the copy operation
invalidRegion.Exclude(&copyRegion);
// apply the current clipping as well
invalidRegion.IntersectWith(&cl->fVisible);
// move the region back for the actual operation
copyRegion.OffsetBy(-xOffset, -yOffset);
cl->fDriver->CopyRegion(&copyRegion, xOffset, yOffset);
// trigger the redraw
myRootLayer->GoRedraw(fWinBorder, invalidRegion);
_CopyBits(myRootLayer, cl, src, dst, xOffset, yOffset);
break;
}
@ -693,7 +694,7 @@ void ServerWindow::DispatchMessage(int32 code, LinkMsgReader &link)
fMsgSender->Attach<float>(cl->fFrame.left);
fMsgSender->Attach<float>(cl->fFrame.top);
fMsgSender->Attach<BRect>(cl->fFrame.OffsetToCopy(cl->fBoundsLeftTop));
fMsgSender->Attach<BRect>(cl->fFrame.OffsetToCopy(cl->BoundsOrigin()));
fMsgSender->Flush();
@ -728,16 +729,16 @@ void ServerWindow::DispatchMessage(int32 code, LinkMsgReader &link)
case AS_LAYER_GET_COORD:
{
STRACE(("ServerWindow %s: Message AS_LAYER_GET_COORD: Layer: %s\n",fName, cl->fName->String()));
printf("Adi: %s\n", cl->GetName());
printf("AS_LAYER_GET_COORD - Layer: %s\n", cl->GetName());
cl->fFrame.PrintToStream();
cl->fBoundsLeftTop.PrintToStream();
cl->BoundsOrigin().PrintToStream();
fMsgSender->StartMessage(SERVER_TRUE);
BPoint pt(cl->ConvertFromParent(cl->fFrame.LeftTop()));
fMsgSender->Attach<float>(pt.x);
fMsgSender->Attach<float>(pt.y);
// fMsgSender->Attach<float>(cl->fFrame.left);
// fMsgSender->Attach<float>(cl->fFrame.top);
fMsgSender->Attach<BRect>(cl->fFrame.OffsetToCopy(cl->fBoundsLeftTop));
fMsgSender->Attach<BRect>(cl->fFrame.OffsetToCopy(cl->BoundsOrigin()));
// fMsgSender->Attach<BRect>(cl->ConvertFromTop(cl->fFrame.OffsetToCopy(cl->fBoundsLeftTop)));
fMsgSender->Flush();
@ -2158,6 +2159,53 @@ int32 ServerWindow::MonitorWin(void *data)
}
return err;
}
// _CopyBits
void
ServerWindow::_CopyBits(RootLayer* rootLayer, Layer* layer,
BRect& src, BRect& dst,
int32 xOffset, int32 yOffset) const
{
// NOTE: The correct behaviour is this:
// * The region that is copied is the
// src rectangle, no matter if it fits
// into the dst rectangle. It is copied
// by the offset dst.LeftTop() - src.LeftTop()
// * The dst rectangle is used for invalidation:
// Any area in the dst rectangle that could
// not be copied from src (because either the
// src rectangle was not big enough, or because there
// were parts cut off by the current layer clipping),
// are triggering BView::Draw() to be called
// and for these parts only.
// the region that is going to be copied
BRegion copyRegion(src);
// apply the current clipping of the layer
copyRegion.IntersectWith(&layer->fVisible);
// offset the region to the destination
// and apply the current clipping there as well
copyRegion.OffsetBy(xOffset, yOffset);
copyRegion.IntersectWith(&layer->fVisible);
// the region at the destination that needs invalidation
BRegion invalidRegion(dst);
// exclude the region drawn by the copy operation
invalidRegion.Exclude(&copyRegion);
// apply the current clipping as well
invalidRegion.IntersectWith(&layer->fVisible);
// move the region back for the actual operation
copyRegion.OffsetBy(-xOffset, -yOffset);
layer->fDriver->CopyRegion(&copyRegion, xOffset, yOffset);
// trigger the redraw
rootLayer->GoRedraw(fWinBorder, invalidRegion);
}
//------------------------------------------------------------------------------
void ServerWindow::SendMessageToClient(const BMessage* msg, int32 target, bool usePreferred) const
{

View File

@ -48,6 +48,7 @@ class Decorator;
class BPortLink;
class WinBorder;
class Workspace;
class RootLayer;
class Layer;
#define AS_UPDATE_DECORATOR 'asud'
@ -121,6 +122,13 @@ private:
void DispatchGraphicsMessage(int32 code, LinkMsgReader &link);
static int32 MonitorWin(void *data);
// used by CopyBits and Scrolling
void _CopyBits(RootLayer* rootLayer,
Layer* layer,
BRect& copy,
BRect& dirty,
int32 xOffset, int32 yOffset) const;
protected:
friend class ServerApp;
friend class WinBorder;