new optinized clipping code

new optimized redrawing code
changes in some handlers in ServerWindow.
other minor changes.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5355 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Adi Oanca
2003-11-14 00:15:29 +00:00
parent 57b3bc3b9c
commit 7052fe60fa
8 changed files with 1318 additions and 1084 deletions
+1 -1
View File
@@ -224,7 +224,7 @@ STRACE_SCREEN(("Screen::Screen(%s,%u)\n",gfxmodule?"driver":"NULL",workspaces));
_activeworkspace=(Workspace*)_workspacelist->ItemAt(0);
_workspacecount=workspaces;
_activeworkspace->GetRoot()->Show();
_activeworkspace->GetRoot()->RequestDraw();
// _activeworkspace->GetRoot()->RequestDraw();
}
}
}
File diff suppressed because it is too large Load Diff
+83 -77
View File
@@ -44,6 +44,7 @@ class RootLayer;
class WinBorder;
class Screen;
class ServerCursor;
class DisplayDriver;
/*!
\class Layer Layer.h
@@ -56,65 +57,66 @@ class ServerCursor;
class Layer
{
public:
Layer(BRect frame, const char *name, int32 token, uint32 resize,
uint32 flags, ServerWindow *win);
virtual ~Layer(void);
Layer(BRect frame, const char *name, int32 token, uint32 resize,
uint32 flags, ServerWindow *win);
virtual ~Layer(void);
void AddChild(Layer *child, Layer *before=NULL, bool rebuild=true);
void RemoveChild(Layer *child, bool rebuild=true);
void RemoveSelf(bool rebuild=true);
uint32 CountChildren(void);
void MakeTopChild(void);
void MakeBottomChild(void);
Layer *FindLayer(int32 token);
Layer *GetChildAt(BPoint pt, bool recursive=false);
Layer *GetUpperSibling() { return _uppersibling; }
Layer *GetLowerSibling() { return _lowersibling; }
PortLink *GetLink(void);
const char *GetName(void) { return (_name)?_name->String():NULL; }
LayerData *GetLayerData(void) { return _layerdata; }
LayerData *GetDrawData(void);
void AddChild(Layer *child, Layer *before=NULL);
void RemoveChild(Layer *child);
void RemoveSelf();
uint32 CountChildren(void) const;
void MakeTopChild(void);
void MakeBottomChild(void);
Layer* FindLayer(const int32 token);
Layer* GetLayerAt(const BPoint &pt);
Layer* GetUpperSibling() const { return _uppersibling; }
Layer* GetLowerSibling() const { return _lowersibling; }
const char* GetName(void) const { return (_name)?_name->String():NULL; }
LayerData* GetLayerData(void) const { return _layerdata; }
void SetLayerCursor(ServerCursor *csr);
ServerCursor *GetLayerCursor(void) const;
virtual void MouseTransit(uint32 transit);
void SetLayerCursor(ServerCursor *csr);
ServerCursor* GetLayerCursor(void) const;
virtual void MouseTransit(uint32 transit);
void Invalidate(const BRect &rect);
void Invalidate(BRegion& region);
void RebuildRegions(bool include_children=true);
virtual void RequestDraw(const BRect &r);
virtual void RequestDraw(void);
bool IsDirty(void) const;
void UpdateIfNeeded(bool force_update=false);
void MarkModified(BRect rect);
void UpdateRegions(bool force=false);
void Show(void);
void Hide(void);
bool IsHidden(void);
BRect Bounds(void);
BRect Frame(void);
void DoMoveTo(float x, float y);
void DoResizeTo(float newWidth, float newHeight);
virtual void MoveBy(float x, float y);
void ResizeBy(float x, float y);
BRect ConvertToParent(BRect rect);
BRegion ConvertToParent(BRegion *reg);
BRect ConvertFromParent(BRect rect);
BRegion ConvertFromParent(BRegion *reg);
BRegion ConvertToTop(BRegion *reg);
BRect ConvertToTop(BRect rect);
BRegion ConvertFromTop(BRegion *reg);
BRect ConvertFromTop(BRect rect);
void Invalidate(const BRect &rect);
void Invalidate(const BRegion &region);
void DoInvalidate(const BRegion &reg, Layer *start);
virtual void RebuildRegions( const BRect& r );
void RebuildChildRegions( const BRect &r, Layer* startFrom );
void RebuildFullRegion(void);
void MoveRegionsBy(float x, float y);
void ResizeRegionsBy(float x, float y);
void PrintToStream(void);
void PrintNode(void);
void PruneTree(void);
void PrintTree();
void RequestClientUpdate(const BRect &rect);
void RequestDraw(const BRect &r);
virtual void Draw(const BRect &r);
void Show(void);
void Hide(void);
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);
BRect ConvertFromParent(BRect rect);
BRegion ConvertFromParent(BRegion *reg);
BRegion ConvertToTop(BRegion *reg);
BRect ConvertToTop(BRect rect);
BRegion ConvertFromTop(BRegion *reg);
BRect ConvertFromTop(BRect rect);
void PruneTree(void);
void PrintToStream(void);
void PrintNode(void);
void PrintTree();
protected:
friend class RootLayer;
@@ -122,28 +124,32 @@ protected:
friend class Screen;
friend class ServerWindow;
BRect _frame;
BPoint _boundsLeftTop;
Layer *_parent,
*_uppersibling,
*_lowersibling,
*_topchild,
*_bottomchild;
BRegion *_visible,
*_invalid,
*_full;
ServerWindow *_serverwin;
BString *_name;
int32 _view_token;
int32 _level;
uint32 _flags;
uint32 _resize_mode;
bool _hidden;
bool _is_dirty;
bool _is_updating;
bool _regions_invalid;
LayerData *_layerdata;
ServerCursor *_cursor;
BRect _frame;
BPoint _boundsLeftTop;
Layer *_parent,
*_uppersibling,
*_lowersibling,
*_topchild,
*_bottomchild;
BRegion _visible,
_fullVisible,
_full;
BRegion *clipToPicture;
bool clipToPictureInverse;
ServerWindow *_serverwin;
BString *_name;
int32 _view_token;
int32 _level;
uint32 _flags;
uint32 _resize_mode;
bool _hidden;
bool _is_updating;
LayerData *_layerdata;
ServerCursor *_cursor;
DisplayDriver* fDriver;
};
#endif
+22 -95
View File
@@ -52,66 +52,25 @@ RootLayer::RootLayer(BRect rect, const char *layername, DisplayDriver *gfxdriver
: Layer(rect, layername, B_NULL_TOKEN, B_FOLLOW_NONE, 0, NULL)
{
_view_token = rlayer_token_handler.GetToken();
_driver = gfxdriver;
_is_dirty = true;
_bgcolor = new RGBColor();
_invalid->MakeEmpty();
_invalid->Include(Bounds());
fDriver = gfxdriver;
_hidden = false;
}
//! Frees all allocated heap memory (which happens to be none) ;)
RootLayer::~RootLayer()
{
delete _bgcolor;
}
/*!
\brief Requests that the layer be drawn on screen
\param r The bounding rectangle of the area given in the Layer's coordinates
\brief Draws this entire layer on screen
*/
void RootLayer::RequestDraw(const BRect &r)
void RootLayer::Draw(const BRect &r)
{
Invalidate(r);
RequestDraw();
}
/*!
\brief Requests that the layer be drawn on screen
*/
void RootLayer::RequestDraw(void)
{
if(!_is_dirty)
return;
// Redraw the base
if(_invalid)
{
#ifdef DEBUG_ROOTLAYER
printf("ROOTLAYER: ");
_invalid->PrintToStream();
printf("===========\n");
#endif
for(int32 i=0; _invalid->CountRects();i++)
{
if(_invalid->RectAt(i).IsValid())
_driver->FillRect(_invalid->RectAt(i),_layerdata, pat_solidlow);
else
break;
}
delete _invalid;
_invalid=NULL;
}
// force redraw of all dirty windows
for(Layer *lay=_topchild; lay!=NULL; lay=lay->_lowersibling)
{
if(lay->IsDirty())
lay->RequestDraw();
}
_is_dirty=false;
/* THIS method is here because of DisplayDriver testing!
* It SHOULD BE REMOVED as soon as testing is done!!!!
*/
#ifdef DISPLAYDRIVER_TEST_HACK
int8 pattern[8];
@@ -182,7 +141,7 @@ void RootLayer::RequestDraw(void)
*/
void RootLayer::SetColor(const RGBColor &col)
{
_layerdata->lowcolor=col;
_layerdata->viewcolor = col;
}
/*!
@@ -191,7 +150,7 @@ void RootLayer::SetColor(const RGBColor &col)
*/
RGBColor RootLayer::GetColor(void) const
{
return _layerdata->lowcolor;
return _layerdata->viewcolor;
}
//! Empty function to disable moving the RootLayer
@@ -199,39 +158,21 @@ void RootLayer::MoveBy(float x, float y)
{
}
//! Empty function to disable moving the RootLayer
void RootLayer::MoveBy(BPoint pt)
{
}
//! Reimplemented for RootLayer special case
void RootLayer::ResizeBy(float x, float y)
{
BRect oldframe=_frame;
_frame.right+=x;
_frame.bottom+=y;
_frame.right += x;
_frame.bottom += y;
// We'll need to rebuild the regions of the child layers
// because resizing will affect the visible regions
RebuildRegions(true);
// If we've gotten bigger, we'll need to repaint the new areas
if(x>0)
{
BRect dx(oldframe.right,oldframe.top, _frame.right, _frame.bottom);
Invalidate(dx);
}
if(y>0)
{
BRect dy(oldframe.left,oldframe.bottom, _frame.right, _frame.bottom);
Invalidate(dy);
}
}
_full.Set( _frame ); // NO ConvertTopTop !!!
//! Reimplemented for RootLayer special case
void RootLayer::ResizeBy(BPoint pt)
{
ResizeBy(pt.x,pt.y);
// We need to rebuild ALL regions because the screen is black now,
// and ALL views/Layers need redrawing.
RebuildRegions( _frame );
// Invalidate the hole screen, because we've changed resolution
// and the screen is black.
Invalidate( _frame );
}
/*!
@@ -240,19 +181,5 @@ void RootLayer::ResizeBy(BPoint pt)
*/
void RootLayer::SetDriver(DisplayDriver *driver)
{
_driver=driver;
}
/*!
\brief Rebuilds the visible and invalid layers based on the layer hierarchy
\param recursive (Defaults to false)
*/
void RootLayer::RebuildRegions(bool recursive)
{
// Unlike the other layers, RootLayers can't depend on their parent layer to reset its
// visible region, so we have to do it itself.
_visible->MakeEmpty();
_visible->Include(_full);
Layer::RebuildRegions(recursive);
fDriver = driver;
}
+13 -15
View File
@@ -43,22 +43,20 @@ class RGBColor;
class RootLayer : public Layer
{
public:
RootLayer(BRect rect, const char *layername, DisplayDriver *gfxdriver);
~RootLayer();
virtual void RequestDraw();
virtual void RequestDraw(const BRect &r);
virtual void MoveBy(float x, float y);
void MoveBy(BPoint pt);
void ResizeBy(float x, float y);
void ResizeBy(BPoint pt);
void SetDriver(DisplayDriver *driver);
void SetColor(const RGBColor &col);
RGBColor GetColor(void) const;
void RebuildRegions(bool recursive=false);
RootLayer(BRect rect, const char *layername,
DisplayDriver *gfxdriver);
virtual ~RootLayer();
virtual void Draw(const BRect &r);
virtual void MoveBy(float x, float y);
virtual void ResizeBy(float x, float y);
void SetDriver(DisplayDriver *driver);
void SetColor(const RGBColor &col);
RGBColor GetColor(void) const;
private:
DisplayDriver *_driver;
RGBColor *_bgcolor;
bool _isvisible;
};
#endif
+112 -86
View File
@@ -130,42 +130,60 @@ ServerWindow::ServerWindow(BRect rect, const char *string, uint32 wlook,
_look = wlook;
_feel = wfeel;
_handlertoken = handlerID;
cl = NULL;
winLooperPort = looperPort;
_workspace_index= index;
_workspace = NULL;
_token = win_token_handler.GetToken();
_winborder = new WinBorder(_frame,_title->String(),wlook,wfeel,wflags,this);
// _sender is the monitored window's event port
// HAVE messaging working.
// _sender is the port to which the app awaits messages from the server
_sender = winport;
_winlink = new PortLink(_sender);
_applink = (winapp)? new PortLink(winapp->_receiver) : NULL;
// _receiver is the port to which the app sends messages for the server
// _receiver is the port to which the app sends messages for the server
_receiver = create_port(30,_title->String());
ses = new BSession( _receiver, _sender );
// Send a reply to our window - it is expecting _receiver port.
ses->WriteData( &_receiver, sizeof(port_id) );
ses->Sync();
top_layer = NULL;
_active = false;
// WAIT for top_view data and create ServerWindow's top most Layer
int32 vMsg;
int32 vToken;
BRect vFrame;
uint32 vResizeMode;
uint32 vFlags;
char* vName = NULL;
// Spawn our message monitoring _monitorthread
_monitorthread = spawn_thread( MonitorWin, _title->String(),
B_NORMAL_PRIORITY, this );
if(_monitorthread != B_NO_MORE_THREADS &&
_monitorthread != B_NO_MEMORY)
ses->ReadInt32( &vMsg );
if (vMsg != AS_LAYER_CREATE_ROOT){
debugger("SERVER ERROR: ServerWindow(xxx): NO top_view data received!\n");
}
ses->ReadInt32( &vToken );
ses->ReadRect( &vFrame );
ses->ReadUInt32( &vResizeMode );
ses->ReadUInt32( &vFlags );
vName = ses->ReadString();
top_layer = new Layer( vFrame, vName, vToken, vResizeMode,
vFlags, this );
delete vName;
cl = top_layer;
// CREATE a WindoBorder object for our ServerWindow.
_winborder = new WinBorder(_frame,_title->String(),wlook,wfeel,wflags,this);
// SPAWN our message monitoring _monitorthread
_monitorthread = spawn_thread( MonitorWin, _title->String(), B_NORMAL_PRIORITY, this );
if(_monitorthread != B_NO_MORE_THREADS && _monitorthread != B_NO_MEMORY)
resume_thread( _monitorthread );
_workspace_index= index;
_workspace = NULL;
_token = win_token_handler.GetToken();
// ADD window to desktop structure.
AddWindowToDesktop(this,index,ActiveScreen());
STRACE(("ServerWindow %s:\n",_title->String() ));
STRACE(("\tFrame (%.1f,%.1f,%.1f,%.1f)\n",rect.left,rect.top,rect.right,rect.bottom));
@@ -262,7 +280,7 @@ STRACE(("ServerWindow %s: Show\n",_title->String()));
{
_winborder->Show();
_winborder->SetFocus(true);
_winborder->UpdateRegions(true);
// _winborder->UpdateRegions(true);
}
}
@@ -297,7 +315,7 @@ STRACE(("ServerWindow %s: Set Focus to %s\n",_title->String(),value?"true":"fals
{
_active=value;
_winborder->SetFocus(value);
_winborder->RequestDraw();
// _winborder->RequestDraw();
}
}
@@ -473,15 +491,7 @@ void ServerWindow::DispatchMessage( int32 code )
// there is no way of setting this, other than manual. :-)
newLayer->_hidden = hidden;
// TODO: 'before' Layer support???
// TODO: review Layer::AddChild
// newLayer's parent will invalidate the area that its new child
// occupies, here in AddChild()
cl->AddChild( newLayer );
cl->PrintTree();
// we set Layer attributes (BView's state)...
// we set Layer's attributes (BView's state)
cl = newLayer;
int32 msgCode;
@@ -490,8 +500,11 @@ void ServerWindow::DispatchMessage( int32 code )
ses->ReadInt32( &msgCode ); // this is AS_LAYER_SET_STATE
DispatchMessage( msgCode );
// attach the view to the tree structure.
oldCL->AddChild( newLayer );
// ... and attach its children.
// attach its children.
for(int i = 0; i < childCount; i++){
ses->ReadInt32( &msgCode ); // this is AS_LAYER_CREATE
DispatchMessage( msgCode );
@@ -513,7 +526,7 @@ void ServerWindow::DispatchMessage( int32 code )
parent = cl->_parent;
// here we remove current layer from list.
cl->RemoveSelf( false );
cl->RemoveSelf();
// TODO: invalidate the region occupied by this view.
// Should be done in Layer::RemoveChild() though!
cl->PruneTree();
@@ -568,11 +581,15 @@ void ServerWindow::DispatchMessage( int32 code )
ses->ReadRect( &rect );
cl->_layerdata->clippReg->Include( rect );
}
cl->RebuildFullRegion();
}
else{
if ( cl->_layerdata->clippReg ){
delete cl->_layerdata->clippReg;
cl->_layerdata->clippReg = NULL;
cl->RebuildFullRegion();
}
}
@@ -703,7 +720,7 @@ void ServerWindow::DispatchMessage( int32 code )
ses->ReadFloat( &x );
ses->ReadFloat( &y );
cl->DoMoveTo(x, y);
cl->MoveBy(x, y);
STRACE(("ServerWindow %s: Message AS_LAYER_MOVETO: Layer: %s\n",_title->String(), cl->_name->String()));
break;
@@ -717,7 +734,7 @@ void ServerWindow::DispatchMessage( int32 code )
/* TODO: check for minimum alowed. WinBorder should provide such
* a method, based on its decorator.
*/
cl->DoResizeTo( newWidth, newHeight );
cl->ResizeBy( newWidth, newHeight );
STRACE(("ServerWindow %s: Message AS_LAYER_RESIZETO: Layer: %s\n",_title->String(), cl->_name->String()));
break;
@@ -824,6 +841,8 @@ void ServerWindow::DispatchMessage( int32 code )
LayerData *ld = new LayerData();
ld->prevState = cl->_layerdata;
cl->_layerdata = ld;
cl->RebuildFullRegion();
STRACE(("ServerWindow %s: Message AS_LAYER_PUSH_STATE: Layer: %s\n",_title->String(), cl->_name->String()));
break;
@@ -838,6 +857,8 @@ void ServerWindow::DispatchMessage( int32 code )
LayerData *ld = cl->_layerdata;
cl->_layerdata = cl->_layerdata->prevState;
delete ld;
cl->RebuildFullRegion();
STRACE(("ServerWindow %s: Message AS_LAYER_POP_STATE: Layer: %s\n",_title->String(), cl->_name->String()));
break;
@@ -1004,16 +1025,27 @@ void ServerWindow::DispatchMessage( int32 code )
ses->ReadInt32( &pictureToken );
ses->ReadPoint( &where );
BRegion reg;
bool redraw = false;
// if we had a picture to clip to, include the FULL visible region(if any) in the area to be redrawn
// in other words: invalidate what ever is visible for this layer and his children.
if ( cl->clipToPicture && cl->_fullVisible.CountRects() > 0 ){
reg.Include( &cl->_fullVisible );
redraw = true;
}
// search for a picture with the specified token.
ServerPicture *sp = NULL;
int32 i = 0;
for(;;){
sp = static_cast<ServerPicture*>(cl->_serverwin->_app->_piclist->ItemAt(i++));
if (!sp)
break;
if( sp->GetToken() == pictureToken ){
cl->_layerdata->clippPicture = sp;
// cl->clipToPicture = sp;
// TODO: increase that picture's reference count.( ~ allocate a picture )
break;
}
@@ -1021,14 +1053,34 @@ void ServerWindow::DispatchMessage( int32 code )
// avoid compiler warning
i = 0;
cl->_layerdata->clippInverse = false;
// we have a new picture to clip to, so rebuild our full region
if( cl->clipToPicture ) {
cl->clipToPictureInverse = false;
cl->RebuildFullRegion();
}
// we need to rebuild the visible region, we may have a valid one.
if (cl->_parent && !(cl->_hidden) ){
cl->_parent->RebuildChildRegions(cl->_full.Frame(), cl);
}
else{
// will this happen? Maybe...
cl->RebuildRegions(cl->_full.Frame());
}
// include our full visible region in the region to be redrawn
if ( !(cl->_hidden) && (cl->_fullVisible.CountRects() > 0) ){
reg.Include( &(cl->_fullVisible) );
redraw = true;
}
// redraw if: we had OR if we NOW have a picture to clip to.
if (redraw){
cl->Invalidate( reg );
}
/* TODO: modify when you have a function that returns the clipping
* region composed by: the visible region & local clipping
* region(across states) & the picture clipping region.
*/
cl->RequestDraw( cl->_layerdata->clippReg->Frame() );
STRACE(("ServerWindow %s: Message AS_LAYER_CLIP_TO_PICTURE: Layer: %s\n",_title->String(), cl->_name->String()));
break;
}
@@ -1050,7 +1102,7 @@ void ServerWindow::DispatchMessage( int32 code )
break;
if( sp->GetToken() == pictureToken ){
cl->_layerdata->clippPicture = sp;
// cl->clipToPicture = sp;
// TODO: increase that picture's reference count.( ~ allocate a picture )
break;
}
@@ -1058,13 +1110,15 @@ void ServerWindow::DispatchMessage( int32 code )
// avoid compiler warning
i = 0;
cl->_layerdata->clippInverse = true;
// if a picture has been found...
if( cl->clipToPicture ) {
/* TODO: modify when you have a function that returns the clipping
* region composed by: the visible region & local clipping
* region(across states) & the picture clipping region.
*/
cl->RequestDraw( cl->_layerdata->clippReg->Frame() );
cl->clipToPictureInverse = true;
cl->RebuildFullRegion();
cl->RequestDraw( cl->clipToPicture->Frame() );
}
STRACE(("ServerWindow %s: Message AS_LAYER_CLIP_TO_INVERSE_PICTURE: Layer: %s\n",_title->String(), cl->_name->String()));
break;
@@ -1077,7 +1131,7 @@ void ServerWindow::DispatchMessage( int32 code )
int32 noOfRects;
ld = cl->_layerdata;
reg = cl->ConvertFromParent( cl->_visible );
reg = cl->ConvertFromParent( &(cl->_visible) );
if( ld->clippReg )
reg.IntersectWith( ld->clippReg );
@@ -1115,12 +1169,10 @@ void ServerWindow::DispatchMessage( int32 code )
ses->ReadRect( &r );
cl->_layerdata->clippReg->Include( r );
}
/* TODO: modify when you have a function that returns the clipping
* region composed by: the visible region & local clipping
* region(across states) & the picture clipping region.
*/
cl->RequestDraw( cl->_layerdata->clippReg->Frame() );
cl->RebuildFullRegion();
cl->RequestDraw( cl->clipToPicture->Frame() );
STRACE(("ServerWindow %s: Message AS_LAYER_SET_CLIP_REGION: Layer: %s\n",_title->String(), cl->_name->String()));
break;
@@ -1166,30 +1218,6 @@ void ServerWindow::DispatchMessage( int32 code )
/********** END: BView Messages ***********/
/********** BWindow Messages ***********/
case AS_LAYER_CREATE_ROOT:
{
// Received when a window creates its internal top view
int32 token;
BRect frame;
uint32 resizeMode;
uint32 flags;
char* name = NULL;
ses->ReadInt32( &token );
ses->ReadRect( &frame );
ses->ReadInt32( (int32*)&resizeMode );
ses->ReadInt32( (int32*)&flags );
name = ses->ReadString();
top_layer = new Layer( frame, name, token, resizeMode,
flags, this );
cl = top_layer;
STRACE(("ServerWindow %s: Setting currentLayer to: '%s'\n", _title->String(), name ));
STRACE(("ServerWindow %s: Message Create_Layer_Root\n",_title->String()));
delete name;
break;
}
case AS_LAYER_DELETE_ROOT:
{
// Received when a window deletes its internal top view
@@ -2150,15 +2178,13 @@ Layer* ServerWindow::FindLayer(const Layer* start, int32 token) const
//-----------------------------------------------------------------------
void ServerWindow::SendMessageToClient( const BMessage* msg ) const
{
void ServerWindow::SendMessageToClient( const BMessage* msg ) const{
ssize_t size;
char *buffer;
size = msg->FlattenedSize();
buffer = new char[size];
if ( msg->Flatten( buffer, size ) == B_OK )
{
if ( msg->Flatten( buffer, size ) == B_OK ){
write_port( winLooperPort, msg->what, buffer, size );
}
else
+413 -170
View File
@@ -97,41 +97,59 @@ WinBorder::WinBorder(const BRect &r, const char *name, const int32 look, const i
{
// unlike BViews, windows start off as hidden, so we need to tweak the hidecount
// assignment made by Layer().
_hidden = true;
_mbuttons = 0;
_kmodifiers = 0;
_win = win;
_hidden = true;
_mbuttons = 0;
_kmodifiers = 0;
_win = win;
_update = false;
_hresizewin = false;
_vresizewin = false;
_mousepos.Set(0,0);
_update = false;
_title = new BString(name);
_hresizewin = false;
_vresizewin = false;
_driver = GetGfxDriver(ActiveScreen());
_decorator = new_decorator(r,name,look,feel,flags,GetGfxDriver(ActiveScreen()));
_decorator->GetFootprint(_visible);
_decorator = NULL;
*_full = *_visible;
*_invalid = *_visible;
_frame = _visible->Frame();
// I tend to think it is not needed, so if it isn't, DW, please remove it.
_view_token = border_token_handler.GetToken();
if (feel == B_NO_BORDER_WINDOW_LOOK){
_full = _win->top_layer->_full;
fDecFull = NULL;
fDecFullVisible = NULL;
fDecVisible = NULL;
}
else{
_decorator = new_decorator(r, name, look, feel, flags, fDriver);
fDecFull = new BRegion();
fDecVisible = new BRegion();
fDecFullVisible = fDecVisible;
_decorator->SetDriver(_driver);
_decorator->SetTitle(name);
_decorator->GetFootprint( fDecFull );
STRACE(("WinBorder %s:\n",_title->String()));
STRACE(("\tFrame: (%.1f,%.1f,%.1f,%.1f)\n",r.left,r.top,r.right,r.bottom));
STRACE(("\tWindow %s\n",win?win->Title():"NULL"));
// our full region is the union between decorator's region and top_layer's region
_full = _win->top_layer->_full;
_full.Include( fDecFull );
}
// get a token
_view_token = border_token_handler.GetToken();
STRACE(("WinBorder %s:\n",_title->String()));
STRACE(("\tFrame: (%.1f,%.1f,%.1f,%.1f)\n",r.left,r.top,r.right,r.bottom));
STRACE(("\tWindow %s\n",win?win->Title():"NULL"));
}
WinBorder::~WinBorder(void)
{
STRACE(("WinBorder %s:~WinBorder()\n",_title->String()));
delete _title;
STRACE(("WinBorder %s:~WinBorder()\n",_title->String()));
if (_decorator) {
delete _decorator;
_decorator = NULL;
delete fDecFull;
fDecFull = NULL;
delete fDecFullVisible; // NOTE: fDecFullVisible == fDecVisible
fDecFullVisible = NULL;
fDecVisible = NULL;
}
}
void WinBorder::MouseDown(int8 *buffer)
@@ -143,94 +161,88 @@ void WinBorder::MouseDown(int8 *buffer)
// 4) int32 - modifier keys down
// 5) int32 - buttons down
// 6) int32 - clicks
int8 *index=buffer; index+=sizeof(int64);
float x=*((float*)index); index+=sizeof(float);
float y=*((float*)index); index+=sizeof(float);
int32 modifiers=*((int32*)index); index+=sizeof(int32);
int32 buttons=*((int32*)index);
int8 *index = buffer; index+=sizeof(int64);
float x = *((float*)index); index+=sizeof(float);
float y = *((float*)index); index+=sizeof(float);
int32 modifiers = *((int32*)index); index+=sizeof(int32);
int32 buttons = *((int32*)index);
BPoint pt(x,y);
_mbuttons=buttons;
_kmodifiers=modifiers;
click_type click=_decorator->Clicked(pt, _mbuttons, _kmodifiers);
_mousepos=pt;
switch(click)
{
case CLICK_MOVETOBACK:
{
STRACE_CLICK(("Click: MoveToBack\n"));
MakeTopChild();
break;
}
case CLICK_MOVETOFRONT:
{
STRACE_CLICK(("Click: MoveToFront\n"));
MakeBottomChild();
break;
}
case CLICK_CLOSE:
{
STRACE_CLICK(("Click: Close\n"));
_decorator->SetClose(true);
_decorator->DrawClose();
break;
}
case CLICK_ZOOM:
{
STRACE_CLICK(("Click: Zoom\n"));
_decorator->SetZoom(true);
_decorator->DrawZoom();
break;
}
case CLICK_MINIMIZE:
{
STRACE_CLICK(("Click: Minimize\n"));
_decorator->SetMinimize(true);
_decorator->DrawMinimize();
break;
}
case CLICK_DRAG:
{
if(buttons==B_PRIMARY_MOUSE_BUTTON)
{
STRACE_CLICK(("Click: Drag\n"));
MakeBottomChild();
set_is_moving_window(true);
}
if(buttons==B_SECONDARY_MOUSE_BUTTON)
// user clicked on decorator
if (fDecFullVisible->Contains(pt)){
click_type click;
click = _decorator->Clicked(pt, buttons, modifiers);
switch(click){
case CLICK_MOVETOBACK:
{
STRACE_CLICK(("Click: MoveToBack\n"));
MakeTopChild();
MoveToBack();
break;
}
break;
}
case CLICK_SLIDETAB:
{
STRACE_CLICK(("Click: Slide Tab\n"));
set_is_sliding_tab(true);
break;
}
case CLICK_RESIZE:
{
if(buttons==B_PRIMARY_MOUSE_BUTTON)
case CLICK_MOVETOFRONT:
{
STRACE_CLICK(("Click: MoveToFront\n"));
MoveToFront();
break;
}
case CLICK_CLOSE:
{
STRACE_CLICK(("Click: Close\n"));
RemoveSelf();
break;
}
case CLICK_ZOOM:
{
STRACE_CLICK(("Click: Zoom\n"));
// TODO: implement
// if (actual_coods != max_zoom_coords)
// MoveBy(X, Y);
// ResizeBy(X, Y);
break;
}
case CLICK_MINIMIZE:
{
STRACE_CLICK(("Click: Minimize\n"));
if ( !IsHidden() ){
Hide();
}
break;
}
case CLICK_DRAG:
{
STRACE_CLICK(("Click: Drag\n"));
set_is_moving_window(true);
break;
}
case CLICK_SLIDETAB:
{
STRACE_CLICK(("Click: Slide Tab\n"));
set_is_sliding_tab(true);
break;
}
case CLICK_RESIZE:
{
STRACE_CLICK(("Click: Resize\n"));
set_is_resizing_window(true);
break;
}
case CLICK_NONE:
default:
{
break;
}
break;
}
case CLICK_NONE:
{
break;
}
default:
{
break;
}
}
// user clicked in window's area
else{
/*
TODO: implement!!!
NOTE: send that message to BViews registered for receiving mouse&keyboard events.
SendMouseMessage( B_MOUSE_DOWN );
*/
}
}
void WinBorder::MouseMoved(int8 *buffer)
@@ -268,7 +280,7 @@ void WinBorder::MouseMoved(int8 *buffer)
if(is_sliding_tab())
{
STRACE_CLICK(("ClickMove: Slide Tab\n"));
STRACE_CLICK(("ClickMove: Slide Tab\n"));
float dx=pt.x-_mousepos.x;
float dy=pt.y-_mousepos.y;
@@ -279,7 +291,7 @@ void WinBorder::MouseMoved(int8 *buffer)
// we can invalidate the proper area.
lock_layers();
_parent->Invalidate(_decorator->SlideTab(dx,dy));
_parent->RequestDraw();
// _parent->RequestDraw();
// _decorator->DrawTab();
unlock_layers();
}
@@ -291,7 +303,7 @@ void WinBorder::MouseMoved(int8 *buffer)
// We are moving the window. Because speed is of the essence, we need to handle a lot
// of stuff which we might otherwise not need to.
STRACE_CLICK(("ClickMove: Drag\n"));
STRACE_CLICK(("ClickMove: Drag\n"));
float dx = pt.x - _mousepos.x,
dy = pt.y - _mousepos.y;
if(buttons!=0 && (dx!=0 || dy!=0))
@@ -320,7 +332,7 @@ void WinBorder::MouseMoved(int8 *buffer)
_decorator->MoveBy(BPoint(dx, dy));
// 3) quickly move the window
_driver->CopyRegion(&reg,reg2.Frame().LeftTop());
// _driver->CopyRegion(&reg,reg2.Frame().LeftTop());
// 4) Invalidate only the areas which we can't redraw directly
for(int32 i=0; i<reg2.CountRects();i++)
@@ -342,8 +354,8 @@ void WinBorder::MouseMoved(int8 *buffer)
_parent->Invalidate(reg);
_parent->RebuildRegions();
_parent->RequestDraw();
// _parent->RebuildRegions();
// _parent->RequestDraw();
unlock_layers();
}
@@ -352,7 +364,7 @@ void WinBorder::MouseMoved(int8 *buffer)
if(is_resizing_window())
{
STRACE_CLICK(("ClickMove: Resize\n"));
STRACE_CLICK(("ClickMove: Resize\n"));
float dx = pt.x - _mousepos.x,
dy = pt.y - _mousepos.y;
if(buttons!=0 && (dx!=0 || dy!=0))
@@ -367,10 +379,10 @@ void WinBorder::MouseMoved(int8 *buffer)
lock_layers();
ResizeBy(dx,dy);
_parent->RequestDraw();
// _parent->RequestDraw();
unlock_layers();
_decorator->ResizeBy(dx,dy);
_decorator->Draw();
// _decorator->Draw();
}
}
@@ -380,8 +392,7 @@ void WinBorder::MouseMoved(int8 *buffer)
void WinBorder::MouseUp(int8 *buffer)
{
STRACE_MOUSE(("WinBorder %s: MouseUp() \n",_title->String()));
STRACE_MOUSE(("WinBorder %s: MouseUp() \n",_title->String()));
// buffer data:
// 1) int64 - time of mouse click
// 2) float - x coordinate of mouse click
@@ -446,93 +457,325 @@ void WinBorder::MouseUp(int8 *buffer)
*/
void WinBorder::SetFocus(const bool &active)
{
if(_decorator)
_decorator->SetFocus(active);
_decorator->SetFocus(active);
}
void WinBorder::RequestDraw(const BRect &r)
{
STRACE(("WinBorder %s: RequestDraw(BRect)\n",_title->String()));
#ifdef DEBUG_WINBORDER
PrintToStream();
#endif
void WinBorder::RebuildRegions( const BRect& r ){
/* WinBorder is a little bit special. It doesn't have a visible region
in witch to do its drawings. Instead the hole visible region is split
between decorator and top_layer.
*/
_decorator->Draw(r);
delete _invalid;
_invalid = NULL;
}
// if we're in the rebuild area, rebuild our v.r.
if ( _full.Intersects( r ) ){
_visible = _full;
void WinBorder::RequestDraw(void)
{
STRACE(("WinBorder %s::RequestDraw()\n",_title->String()));
#ifdef DEBUG_WINBORDER
PrintToStream();
#endif
if(_invalid)
{
for(int32 i=0;i<_invalid->CountRects();i++)
_decorator->Draw(_invalid->RectAt(i));
delete _invalid;
_invalid = NULL;
if (_parent){
_visible.IntersectWith( &(_parent->_visible) );
// exclude from parent's visible area.
if ( !(_hidden) )
_parent->_visible.Exclude( &(_visible) );
}
_fullVisible = _visible;
}
else{
// our visible region will stay the same
// exclude our FULL visible region from parent's visible region.
if ( !(_hidden) && _parent )
_parent->_visible.Exclude( &(_fullVisible) );
// we're not in the rebuild area so our children's v.r.s are OK.
return;
}
// rebuild top_layer:
if ( _win->top_layer->_full.Intersects( r ) ){
// build top_layer's visible region by intersecting its _full with winborder's _visible region.
_win->top_layer->_visible = _win->top_layer->_full;
_win->top_layer->_visible.IntersectWith( &(_visible) );
// then exclude it from winborder's _visible...
_visible.Exclude( &(_win->top_layer->_visible) );
_win->top_layer->_fullVisible = _win->top_layer->_visible;
// Rebuild regions for children...
for(Layer *lay = _win->top_layer->_bottomchild; lay != NULL; lay = lay->_uppersibling){
if ( !(lay->_hidden) ){
lay->RebuildRegions( r );
}
}
}
else{
_visible.Exclude( &(_win->top_layer->_fullVisible) );
}
// rebuild decorator.
if (_decorator){
if ( fDecFull->Intersects( r ) ){
*fDecVisible = *fDecFull;
fDecVisible->IntersectWith( &(_visible) );
_visible.Exclude( fDecVisible );
// !!!! Pointer assignement !!!!
fDecFullVisible = fDecVisible;
}
else{
_visible.Exclude( fDecFullVisible );
}
}
else
_decorator->Draw();
}
/*
void WinBorder::MoveBy(BPoint pt)
void WinBorder::Draw(const BRect &r)
{
// draw the decorator
BRegion reg(r);
if (_decorator){
reg.IntersectWith( fDecVisible );
if (reg.CountRects() > 0){
_decorator->Draw( reg.Frame() );
}
}
// draw the top_layer
reg.Set( r );
reg.IntersectWith( &(_win->top_layer->_visible) );
if (reg.CountRects() > 0){
_win->top_layer->RequestClientUpdate( reg.Frame() );
}
}
void WinBorder::MoveBy(float x, float y)
{
}
BRegion oldFullVisible( _fullVisible );
// BPoint oldFullVisibleOrigin( _fullVisible.Frame().LeftTop() );
void WinBorder::ResizeBy(BPoint pt)
{
_frame.OffsetBy(x, y);
_full.OffsetBy(x, y);
_win->top_layer->_frame.OffsetBy(x, y);
_win->top_layer->MoveRegionsBy(x, y);
if (_decorator){
// allow decorator to make its internal calculations.
_decorator->MoveBy(x, y);
fDecFull->OffsetBy(x, y);
}
if ( !_hidden ){
// to clear the area occupied on its parent _visible
if (_fullVisible.CountRects() > 0){
_hidden = true;
_parent->RebuildChildRegions( _fullVisible.Frame(), this );
_hidden = false;
}
_parent->RebuildChildRegions( _full.Frame(), this );
}
// REDRAWING CODE:
if ( !(_hidden) )
{
/* The region(on screen) that will be invalidated.
* It is composed by:
* the regions that were visible, and now they aren't +
* the regions that are now visible, and they were not visible before.
* (oldFullVisible - _fullVisible) + (_fullVisible - oldFullVisible)
*/
BRegion clipReg;
// first offset the old region so we can do the correct operations.
oldFullVisible.OffsetBy(x, y);
// + (oldFullVisible - _fullVisible)
if ( oldFullVisible.CountRects() > 0 ){
BRegion tempReg( oldFullVisible );
tempReg.Exclude( &_fullVisible );
if (tempReg.CountRects() > 0){
clipReg.Include( &tempReg );
}
}
// + (_fullVisible - oldFullVisible)
if ( _fullVisible.CountRects() > 0 ){
BRegion tempReg( _fullVisible );
tempReg.Exclude( &oldFullVisible );
if (tempReg.CountRects() > 0){
clipReg.Include( &tempReg );
}
}
// there is no point in redrawing what already is visible. So just copy
// on-screen pixels to layer's new location.
if ( (oldFullVisible.CountRects() > 0) && (_fullVisible.CountRects() > 0) ){
BRegion tempReg( oldFullVisible );
tempReg.IntersectWith( &_fullVisible );
if (tempReg.CountRects() > 0){
// TODO: when you have such a method in DisplayDriver/Clipper, uncomment!
//fDriver->CopyBits( &tempReg, oldFullVisibleOrigin, oldFullVisibleOrigin.OffsetByCopy(x,y) );
}
}
// invalidate 'clipReg' so we can see the results of this move.
if (clipReg.CountRects() > 0){
Invalidate( clipReg );
}
}
}
void WinBorder::ResizeBy(float x, float y)
{
BRegion oldFullVisible( _fullVisible );
_frame.right = _frame.right + x;
_frame.bottom = _frame.bottom + y;
_win->top_layer->ResizeRegionsBy(x, y);
_full = _win->top_layer->_full;
if (_decorator){
// allow decorator to make its internal calculations.
_decorator->ResizeBy(x, y);
_decorator->GetFootprint( fDecFull );
_full.Include( fDecFull );
}
if ( !_hidden ){
_parent->RebuildChildRegions( _full.Frame(), this );
}
// REDRAWING CODE:
if ( !(_hidden) )
{
/* The region(on screen) that will be invalidated.
* It is composed by:
* the regions that were visible, and now they aren't +
* the regions that are now visible, and they were not visible before.
* (oldFullVisible - _fullVisible) + (_fullVisible - oldFullVisible)
*/
BRegion clipReg;
// + (oldFullVisible - _fullVisible)
if ( oldFullVisible.CountRects() > 0 ){
BRegion tempReg( oldFullVisible );
tempReg.Exclude( &_fullVisible );
if (tempReg.CountRects() > 0){
clipReg.Include( &tempReg );
}
}
// + (_fullVisible - oldFullVisible)
if ( _fullVisible.CountRects() > 0 ){
BRegion tempReg( _fullVisible );
tempReg.Exclude( &oldFullVisible );
if (tempReg.CountRects() > 0){
clipReg.Include( &tempReg );
}
}
// invalidate 'clipReg' so we can see the results of this resize operation.
if (clipReg.CountRects() > 0){
Invalidate( clipReg );
}
}
}
*/
void WinBorder::MoveToBack(){
if (this == _parent->_topchild)
return;
if (_uppersibling){
_uppersibling->_lowersibling = _lowersibling;
}
else{
_parent->_topchild = _lowersibling;
}
if (_lowersibling){
_lowersibling->_uppersibling = _uppersibling;
}
else{
_parent->_bottomchild = _uppersibling;
}
this->_lowersibling = _parent->_topchild;
this->_uppersibling = NULL;
_parent->_topchild = this;
// cache WinBorder's fullVisible region for use later
BRegion cachedFullVisible = _fullVisible;
// rebuild only that area the encloses the full visible part of this layer.
_parent->RebuildChildRegions(_fullVisible.Frame(), this);
// we now have <= fullVisible region, so invalidate the parts that are not common.
cachedFullVisible.Exclude(&_fullVisible);
Invalidate( cachedFullVisible );
}
void WinBorder::MoveToFront(){
if (this == _parent->_bottomchild)
return;
if (_uppersibling){
_uppersibling->_lowersibling = _lowersibling;
}
else{
_parent->_topchild = _lowersibling;
}
if (_lowersibling){
_lowersibling->_uppersibling = _uppersibling;
}
else{
_parent->_bottomchild = _uppersibling;
}
this->_lowersibling = NULL;
this->_uppersibling = _parent->_bottomchild;
_parent->_bottomchild = this;
// cache WinBorder's fullVisible region for use later
BRegion cachedFullVisible = _fullVisible;
// rebuild the area that this WinBorder will occupy.
_parent->RebuildChildRegions(_full.Frame(), this);
// make a copy of the fullVisible region because it needs
// to be modified for invalidating a minimum area.
BRegion tempFullVisible = _fullVisible;
// invalidate only the difference between the present and
// the old fullVisible regions. We only need to update that area.
tempFullVisible.Exclude(&cachedFullVisible);
Invalidate( tempFullVisible );
}
void WinBorder::UpdateColors(void)
{
gui_colorset.Lock();
_decorator->SetColors(gui_colorset);
gui_colorset.Unlock();
// Tell the decorator to update all visible regions of the window border
if(_visible)
for(int32 i=0; i<_visible->CountRects(); i++)
_decorator->Draw(_visible->RectAt(i));
STRACE(("WinBorder %s: UpdateColors unimplemented\n",_title->String()));
}
void WinBorder::UpdateDecorator(void)
{
STRACE(("WinBorder %s: UpdateDecorator unimplemented\n",_title->String()));
// TODO: Implement
// What needs done here is to delete the current decorator and do a lot of the
// decorator-related setup done in the constructor. This definitely needs to be
// done *after* all the silliness with figuring out the clipping code is taken care of
STRACE(("WinBorder %s: UpdateDecorator unimplemented\n",_title->String()));
}
void WinBorder::UpdateFont(void)
{
STRACE(("WinBorder %s: UpdateFont unimplemented\n",_title->String()));
// TODO: Implement
// What needs done here is to first call _decorator->SetFont(). Following that,
// GetFootprint() will need to be called to obtain changes in the decorator's size due to
// changes in the font, whether they are face, size, or whatever. Thus, the WinBorder will
// need to do some region-related recalculation, as well.
STRACE(("WinBorder %s: UpdateFont unimplemented\n",_title->String()));
}
void WinBorder::UpdateScreen(void)
{
STRACE(("WinBorder %s: UpdateScreen unimplemented\n",_title->String()));
STRACE(("WinBorder %s: UpdateScreen unimplemented\n",_title->String()));
}
+49 -39
View File
@@ -38,47 +38,57 @@ class DisplayDriver;
class WinBorder : public Layer
{
public:
WinBorder(const BRect &r, const char *name, const int32 look, const int32 feel,
const int32 flags, ServerWindow *win);
virtual ~WinBorder(void);
virtual void RequestDraw(void);
virtual void RequestDraw(const BRect &r);
// void MoveBy(BPoint pt);
// void MoveBy(float x, float y);
// void ResizeBy(BPoint pt);
// void ResizeBy(float x, float y);
void MouseDown(int8 *buffer);
void MouseMoved(int8 *buffer);
void MouseUp(int8 *buffer);
void UpdateColors(void);
void UpdateDecorator(void);
void UpdateFont(void);
void UpdateScreen(void);
void RebuildRegions(const bool &recursive=true);
void SetFocus(const bool &active=false);
ServerWindow *Window(void) { return _win; }
Decorator *GetDecorator(void) { return _decorator; }
WinBorder(const BRect &r, const char *name, const int32 look,
const int32 feel, const int32 flags, ServerWindow *win);
virtual ~WinBorder(void);
virtual void RebuildRegions( const BRect& r );
virtual void Draw(const BRect &r);
virtual void MoveBy(float x, float y);
virtual void ResizeBy(float x, float y);
void MoveToBack();
void MoveToFront();
void MouseDown(int8 *buffer);
void MouseMoved(int8 *buffer);
void MouseUp(int8 *buffer);
void UpdateColors(void);
void UpdateDecorator(void);
void UpdateFont(void);
void UpdateScreen(void);
void SetFocus(const bool &active);
ServerWindow* Window(void) const { return _win; }
Decorator* GetDecorator(void) const { return _decorator; }
protected:
ServerWindow *_win;
BString *_title;
Decorator *_decorator;
int32 _flags;
BRect _clientframe;
int32 _mbuttons,_kmodifiers;
BPoint _mousepos;
bool _update;
bool _hresizewin,_vresizewin;
DisplayDriver *_driver;
ServerWindow *_win;
//BString *_title;
Decorator *_decorator;
int32 _flags;
BRect _clientframe;
int32 _mbuttons,
_kmodifiers;
BPoint _mousepos;
bool _update;
bool _hresizewin,_vresizewin;
BRegion *fDecFull,
*fDecFullVisible,
*fDecVisible;
};
bool is_moving_window(void);
void set_is_moving_window(bool state);
bool is_resizing_window(void);
void set_is_resizing_window(bool state);
void set_active_winborder(WinBorder *win);
WinBorder * get_active_winborder(void);
void set_is_resizing_window(bool state);
void set_is_sliding_tab(bool state);
bool is_sliding_tab(void);
bool is_moving_window(void);
void set_is_moving_window(bool state);
bool is_resizing_window(void);
void set_is_resizing_window(bool state);
void set_active_winborder(WinBorder *win);
WinBorder* get_active_winborder(void);
void set_is_resizing_window(bool state);
void set_is_sliding_tab(bool state);
bool is_sliding_tab(void);
#endif