Added Layer::Push/PopState() and moved their implementation from ServerWindow.cpp. We definitely need more encapsulation

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13043 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini 2005-06-10 15:28:34 +00:00
parent b00025db9c
commit e1bc5f2def
3 changed files with 67 additions and 50 deletions

View File

@ -69,7 +69,8 @@ enum {
Layer::Layer(BRect frame, const char* name, int32 token, Layer::Layer(BRect frame, const char* name, int32 token,
uint32 resize, uint32 flags, DisplayDriver* driver) uint32 resize, uint32 flags, DisplayDriver* driver)
: fFrame(frame), // in parent coordinates :
fFrame(frame), // in parent coordinates
// fBoundsLeftTop(0.0, 0.0), // fBoundsLeftTop(0.0, 0.0),
// Layer does not start out as a part of the tree // Layer does not start out as a part of the tree
@ -79,7 +80,6 @@ Layer::Layer(BRect frame, const char* name, int32 token,
fLowerSibling(NULL), fLowerSibling(NULL),
fTopChild(NULL), fTopChild(NULL),
fBottomChild(NULL), fBottomChild(NULL),
fCurrent(NULL), fCurrent(NULL),
// all regions (fVisible, fFullVisible, fFull) start empty // all regions (fVisible, fFullVisible, fFull) start empty
@ -90,7 +90,7 @@ Layer::Layer(BRect frame, const char* name, int32 token,
fClipReg(&fVisible), fClipReg(&fVisible),
fServerWin(NULL), fServerWin(NULL),
fName (new BString(name ? name : B_EMPTY_STRING)), fName(new BString(name)),
fViewToken(token), fViewToken(token),
fFlags(flags), fFlags(flags),
@ -847,15 +847,15 @@ Layer::Redraw(const BRegion& reg, Layer *startFrom)
// Draw // Draw
void void
Layer::Draw(const BRect &r) Layer::Draw(const BRect &rect)
{ {
#ifdef DEBUG_LAYER #ifdef DEBUG_LAYER
printf("Layer(%s)::Draw: ", GetName()); printf("Layer(%s)::Draw: ", GetName());
r.PrintToStream(); rect.PrintToStream();
#endif #endif
if (!fLayerData->ViewColor().IsTransparentMagic()) if (!fLayerData->ViewColor().IsTransparentMagic())
fDriver->FillRect(r, fLayerData->ViewColor()); fDriver->FillRect(rect, fLayerData->ViewColor());
} }
// EmptyGlobals // EmptyGlobals
@ -928,6 +928,31 @@ Layer::IsHidden(void) const
return false; return false;
} }
void
Layer::PushState()
{
LayerData *data = new LayerData();
data->prevState = fLayerData;
fLayerData = data;
}
void
Layer::PopState()
{
if (fLayerData->prevState == NULL) {
fprintf(stderr, "WARNING: User called BView(%s)::PopState(), but there is NO state on stack!\n", fName->String());
return;
}
LayerData *data = fLayerData;
fLayerData = fLayerData->prevState;
data->prevState = NULL;
delete data;
}
//! Matches the BView call of the same name //! Matches the BView call of the same name
BRect BRect
Layer::Bounds(void) const Layer::Bounds(void) const

View File

@ -118,6 +118,10 @@ class Layer {
void Hide(bool invalidate = true); void Hide(bool invalidate = true);
bool IsHidden() const; bool IsHidden() const;
// graphic state
void PushState();
void PopState();
// coordinate system // coordinate system
BRect Bounds() const; BRect Bounds() const;
BRect Frame() const; BRect Frame() const;

View File

@ -697,11 +697,8 @@ ServerWindow::DispatchMessage(int32 code, LinkMsgReader &link)
case AS_LAYER_PUSH_STATE: case AS_LAYER_PUSH_STATE:
{ {
DTRACE(("ServerWindow %s: Message AS_LAYER_PUSH_STATE: Layer: %s\n",fName, fCurrentLayer->fName->String())); DTRACE(("ServerWindow %s: Message AS_LAYER_PUSH_STATE: Layer: %s\n",fName, fCurrentLayer->fName->String()));
// TODO: refactor, put this in Layer
LayerData *ld = new LayerData();
ld->prevState = fCurrentLayer->fLayerData;
fCurrentLayer->fLayerData = ld;
fCurrentLayer->PushState();
fCurrentLayer->RebuildFullRegion(); fCurrentLayer->RebuildFullRegion();
break; break;
@ -709,17 +706,8 @@ ServerWindow::DispatchMessage(int32 code, LinkMsgReader &link)
case AS_LAYER_POP_STATE: case AS_LAYER_POP_STATE:
{ {
DTRACE(("ServerWindow %s: Message AS_LAYER_POP_STATE: Layer: %s\n",fName, fCurrentLayer->fName->String())); DTRACE(("ServerWindow %s: Message AS_LAYER_POP_STATE: Layer: %s\n",fName, fCurrentLayer->fName->String()));
if (!(fCurrentLayer->fLayerData->prevState))
{
DTRACE(("WARNING: SW(%s): User called BView(%s)::PopState(), but there is NO state on stack!\n", fName, fCurrentLayer->fName->String()));
break;
}
// TODO: refactor, put this in Layer
LayerData *ld = fCurrentLayer->fLayerData;
fCurrentLayer->fLayerData = fCurrentLayer->fLayerData->prevState;
ld->prevState = NULL;
delete ld;
fCurrentLayer->PopState();
fCurrentLayer->RebuildFullRegion(); fCurrentLayer->RebuildFullRegion();
break; break;