LayerData::prevState is now called fPreviousState and is now private. Added new method
PopState() to make this possible. When a new layer is created, the font state of the desktop will now be set: this fixes a bug I introduced when separating the font manager's default font and the desktop's default font. The scaling stuff looks pretty broken to me. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14675 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
7490bd32f1
commit
5abd5613d6
@ -1,34 +1,16 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (c) 2001-2005, Haiku, Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
// File Name: LayerData.h
|
||||
// Author: DarkWyrm <bpmagic@columbus.rr.com>
|
||||
// Adi Oanca <adioanca@mymail.ro>
|
||||
// Stephan Aßmus <superstippi@gmx.de>
|
||||
// Description: Data classes for working with BView states and draw parameters
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
* Copyright 2001-2005, Haiku.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* DarkWyrm <bpmagic@columbus.rr.com>
|
||||
* Adi Oanca <adioanca@mymail.ro>
|
||||
* Stephan Aßmus <superstippi@gmx.de>
|
||||
*/
|
||||
#ifndef LAYER_DATA_H_
|
||||
#define LAYER_DATA_H_
|
||||
|
||||
|
||||
#include <GraphicsDefs.h>
|
||||
#include <InterfaceDefs.h>
|
||||
#include <Point.h>
|
||||
@ -40,11 +22,13 @@
|
||||
#include "PatternHandler.h"
|
||||
|
||||
class BRegion;
|
||||
|
||||
namespace BPrivate {
|
||||
class LinkReceiver;
|
||||
class LinkSender;
|
||||
};
|
||||
|
||||
|
||||
class DrawData {
|
||||
public:
|
||||
DrawData();
|
||||
@ -199,9 +183,12 @@ class LayerData : public DrawData {
|
||||
void ReadFromLink(BPrivate::LinkReceiver& link);
|
||||
void WriteToLink(BPrivate::LinkSender& link) const;
|
||||
|
||||
public:
|
||||
LayerData* PreviousState() const { return fPreviousState; }
|
||||
LayerData* PopState();
|
||||
|
||||
private:
|
||||
// used for the state stack
|
||||
LayerData* prevState;
|
||||
LayerData* fPreviousState;
|
||||
};
|
||||
|
||||
// inline implementations
|
||||
|
@ -61,9 +61,10 @@
|
||||
# define RBTRACE(x) ;
|
||||
#endif
|
||||
|
||||
|
||||
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
|
||||
// fBoundsLeftTop(0.0, 0.0),
|
||||
|
||||
@ -105,7 +106,7 @@ Layer::Layer(BRect frame, const char* name, int32 token,
|
||||
fAdFlags(0),
|
||||
|
||||
fDriver(driver),
|
||||
fLayerData(new LayerData()),
|
||||
fLayerData(new LayerData),
|
||||
|
||||
fRootLayer(NULL),
|
||||
|
||||
@ -140,7 +141,7 @@ CRITICAL(helper);
|
||||
STRACE(("Layer(%s) successfuly created\n", Name()));
|
||||
}
|
||||
|
||||
//! Destructor frees all allocated heap space
|
||||
|
||||
Layer::~Layer()
|
||||
{
|
||||
delete fLayerData;
|
||||
@ -1019,16 +1020,12 @@ Layer::PushState()
|
||||
void
|
||||
Layer::PopState()
|
||||
{
|
||||
if (fLayerData->prevState == NULL) {
|
||||
if (fLayerData->PreviousState() == NULL) {
|
||||
fprintf(stderr, "WARNING: User called BView(%s)::PopState(), but there is NO state on stack!\n", Name());
|
||||
return;
|
||||
}
|
||||
|
||||
LayerData *data = fLayerData;
|
||||
fLayerData = fLayerData->prevState;
|
||||
data->prevState = NULL;
|
||||
delete data;
|
||||
|
||||
fLayerData = fLayerData->PopState();
|
||||
fLayerData->SetSubPixelPrecise(fFlags & B_SUBPIXEL_PRECISE);
|
||||
}
|
||||
|
||||
@ -1200,17 +1197,17 @@ Layer::Activated(bool active)
|
||||
// Empty
|
||||
}
|
||||
|
||||
// BoundsOrigin
|
||||
|
||||
BPoint
|
||||
Layer::BoundsOrigin() const
|
||||
{
|
||||
BPoint origin(0,0);
|
||||
float scale = Scale();
|
||||
|
||||
LayerData *ld = fLayerData;
|
||||
LayerData* layerData = fLayerData;
|
||||
do {
|
||||
origin += ld->Origin();
|
||||
} while ((ld = ld->prevState));
|
||||
origin += layerData->Origin();
|
||||
} while ((layerData = layerData->PreviousState()) != NULL);
|
||||
|
||||
origin.x *= scale;
|
||||
origin.y *= scale;
|
||||
@ -1218,19 +1215,21 @@ Layer::BoundsOrigin() const
|
||||
return origin;
|
||||
}
|
||||
|
||||
|
||||
float
|
||||
Layer::Scale() const
|
||||
{
|
||||
float scale = 1.0f;
|
||||
|
||||
LayerData *ld = fLayerData;
|
||||
LayerData* layerData = fLayerData;
|
||||
do {
|
||||
scale *= ld->Scale();
|
||||
} while ((ld = ld->prevState));
|
||||
scale *= layerData->Scale();
|
||||
} while ((layerData = layerData->PreviousState()) != NULL);
|
||||
|
||||
return scale;
|
||||
}
|
||||
|
||||
|
||||
//! Converts the passed point to parent coordinates
|
||||
BPoint
|
||||
Layer::ConvertToParent(BPoint pt)
|
||||
@ -2544,7 +2543,7 @@ Layer::_GetWantedRegion(BRegion ®)
|
||||
// reg.IntersectWith(&screenReg);
|
||||
reg.IntersectWith(stackData->ClippingRegion());
|
||||
}
|
||||
stackData = stackData->prevState;
|
||||
stackData = stackData->PreviousState();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "LinkReceiver.h"
|
||||
#include "LinkSender.h"
|
||||
|
||||
#include "DesktopSettings.h"
|
||||
#include "LayerData.h"
|
||||
|
||||
|
||||
@ -322,45 +323,43 @@ DrawData::SetMiterLimit(float limit)
|
||||
fMiterLimit = limit;
|
||||
}
|
||||
|
||||
//----------------------------LayerData----------------------
|
||||
// #pragmamark -
|
||||
|
||||
// constructpr
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
LayerData::LayerData()
|
||||
: DrawData(),
|
||||
prevState(NULL)
|
||||
fPreviousState(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
// LayerData
|
||||
|
||||
LayerData::LayerData(const LayerData& data)
|
||||
: DrawData()
|
||||
: DrawData(data),
|
||||
fPreviousState(data.fPreviousState)
|
||||
{
|
||||
fClippingRegion = NULL;
|
||||
*this = data;
|
||||
}
|
||||
|
||||
// LayerData
|
||||
|
||||
LayerData::LayerData(LayerData* data)
|
||||
: DrawData(data),
|
||||
prevState(data)
|
||||
fPreviousState(data)
|
||||
{
|
||||
}
|
||||
|
||||
// destructor
|
||||
|
||||
LayerData::~LayerData()
|
||||
{
|
||||
delete prevState;
|
||||
delete fPreviousState;
|
||||
}
|
||||
|
||||
// operator=
|
||||
|
||||
LayerData&
|
||||
LayerData::operator=(const LayerData& from)
|
||||
{
|
||||
DrawData::operator=(from);
|
||||
fPreviousState = from.PreviousState();
|
||||
|
||||
prevState = from.prevState;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -539,3 +538,15 @@ LayerData::WriteToLink(BPrivate::LinkSender& link) const
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
LayerData*
|
||||
LayerData::PopState()
|
||||
{
|
||||
LayerData* previous = PreviousState();
|
||||
|
||||
fPreviousState = NULL;
|
||||
delete this;
|
||||
|
||||
return previous;
|
||||
}
|
||||
|
||||
|
@ -446,7 +446,7 @@ ServerWindow::SetLayerState(Layer *layer, BPrivate::LinkReceiver &link)
|
||||
}
|
||||
|
||||
|
||||
inline Layer*
|
||||
Layer*
|
||||
ServerWindow::CreateLayerTree(BPrivate::LinkReceiver &link, Layer **_parent)
|
||||
{
|
||||
// NOTE: no need to check for a lock. This is a private method.
|
||||
@ -481,13 +481,16 @@ ServerWindow::CreateLayerTree(BPrivate::LinkReceiver &link, Layer **_parent)
|
||||
if (link.Code() == AS_LAYER_CREATE_ROOT
|
||||
&& (fWinBorder->WindowFlags() & kWorkspacesWindowFlag) != 0) {
|
||||
// this is a workspaces window!
|
||||
newLayer = new WorkspacesLayer(frame, name, token, resizeMask,
|
||||
flags, fWinBorder->GetDisplayDriver());
|
||||
newLayer = new (nothrow) WorkspacesLayer(frame, name, token, resizeMask,
|
||||
flags, fWinBorder->GetDisplayDriver());
|
||||
} else {
|
||||
newLayer = new Layer(frame, name, token, resizeMask,
|
||||
flags, fDesktop->GetDisplayDriver());
|
||||
newLayer = new (nothrow) Layer(frame, name, token, resizeMask, flags,
|
||||
fWinBorder->GetDisplayDriver());
|
||||
}
|
||||
|
||||
if (newLayer == NULL)
|
||||
return NULL;
|
||||
|
||||
free(name);
|
||||
|
||||
// there is no way of setting this, other than manually :-)
|
||||
@ -497,6 +500,11 @@ ServerWindow::CreateLayerTree(BPrivate::LinkReceiver &link, Layer **_parent)
|
||||
newLayer->fEventOptions = eventOptions;
|
||||
newLayer->fOwner = fWinBorder;
|
||||
|
||||
DesktopSettings settings(fDesktop);
|
||||
ServerFont font;
|
||||
settings.GetDefaultPlainFont(font);
|
||||
newLayer->fLayerData->SetFont(font);
|
||||
|
||||
// TODO: rework the clipping stuff to remove RootLayer dependency and then
|
||||
// remove this hack:
|
||||
if (fWinBorder->IsOffscreenWindow()) {
|
||||
@ -920,33 +928,31 @@ ServerWindow::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link)
|
||||
case AS_LAYER_GET_SCALE:
|
||||
{
|
||||
DTRACE(("ServerWindow %s: Message AS_LAYER_GET_SCALE: Layer: %s\n", Title(), fCurrentLayer->Name()));
|
||||
LayerData *ld = fCurrentLayer->fLayerData;
|
||||
LayerData* layerData = fCurrentLayer->fLayerData;
|
||||
|
||||
// TODO: And here, we're taking that into account, but not above
|
||||
// -> refactor put scale into Layer, or better yet, when the
|
||||
// state stack is within Layer, PushState() should multiply
|
||||
// by the previous last states scale. Would fix the problem above too.
|
||||
float scale = ld->Scale();
|
||||
|
||||
while ((ld = ld->prevState))
|
||||
scale *= ld->Scale();
|
||||
|
||||
float scale = layerData->Scale();
|
||||
|
||||
while ((layerData = layerData->PreviousState()) != NULL)
|
||||
scale *= layerData->Scale();
|
||||
|
||||
fLink.StartMessage(SERVER_TRUE);
|
||||
fLink.Attach<float>(scale);
|
||||
fLink.Flush();
|
||||
|
||||
break;
|
||||
}
|
||||
case AS_LAYER_SET_PEN_LOC:
|
||||
{
|
||||
DTRACE(("ServerWindow %s: Message AS_LAYER_SET_PEN_LOC: Layer: %s\n", Title(), fCurrentLayer->Name()));
|
||||
float x, y;
|
||||
|
||||
float x, y;
|
||||
|
||||
link.Read<float>(&x);
|
||||
link.Read<float>(&y);
|
||||
|
||||
fCurrentLayer->fLayerData->SetPenLocation(BPoint(x, y));
|
||||
|
||||
break;
|
||||
}
|
||||
case AS_LAYER_GET_PEN_LOC:
|
||||
@ -2382,7 +2388,7 @@ ServerWindow::MakeWinBorder(BRect frame, const char* name,
|
||||
{
|
||||
// The non-offscreen ServerWindow uses the DisplayDriver instance from the desktop.
|
||||
return new(nothrow) WinBorder(frame, name, look, feel, flags,
|
||||
workspace, this, fDesktop->GetDisplayDriver());
|
||||
workspace, this, fDesktop->GetDisplayDriver());
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user