haiku/headers/private/servers/app/LayerData.h
Stephan Aßmus 359c905c57 offscreen bitmaps work, tested on Haiku as well, supports all colorspaces that BBitmap::ImportBits() supports. It uses a fallback for non-B_RGB(A)32 bitmaps. Added support for B_SUB_PIXEL_PRECISION view flags, though it is a bit hacky, since I had to add it to LayerData, even though it is not a true part of stack data. Added Layer::SetFlags() to enforce code path and update fLayerData. Cleaned up DisplayDriverPainter and DisplayDriver API (changed some const BRect& rect to simply BRect rect in order to be able to reuse it in the code), moved Painter.h, the test environment only draws the changed part of the frame buffer again - this causes a lot less CPU overhead, Painter special cases stroke width of 1.0 to use square caps, which is similar to R5 implementation and removes a lot of problems with non-straight line drawing, ServerWindow uses the DisplayDriver from it's WinBorder instead of the one from the Desktop (needed for offscreen windows, which have their own DisplayDriverPainter), it also checks for GetRootLayer() == NULL, because offscreen layers are not attached to a RootLayer, there was a fix for scrolling which worked at least in the test environment, it is now defunced, because Adi moved _CopyBits to Layer... I need to reenable it later, LayerData has no more fEscapementDelta, also fixed fFontAliasing (which was thought to overriding the font flags, and now works as such again), Desktop initialises the menu_info and scroll_bar_info stuff, which makes ScrollBars work actually... hope I didn't forget something.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13448 a95241bf-73f2-0310-859d-f6bbb57e9c96
2005-07-05 16:17:16 +00:00

240 lines
6.9 KiB
C++

//------------------------------------------------------------------------------
// 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
//
//------------------------------------------------------------------------------
#ifndef LAYER_DATA_H_
#define LAYER_DATA_H_
#include <GraphicsDefs.h>
#include <InterfaceDefs.h>
#include <Point.h>
#include <View.h> // for B_FONT_ALL
#include "RGBColor.h"
#include "FontServer.h"
#include "ServerFont.h"
#include "PatternHandler.h"
class BRegion;
namespace BPrivate {
class LinkReceiver;
class LinkSender;
};
class DrawData {
public:
DrawData();
DrawData(const DrawData& from);
// used for the State stack, no
// true 1:1 copy!
DrawData(const DrawData* from);
virtual ~DrawData();
DrawData& operator=(const DrawData& from);
// coordinate transformation
void SetOrigin(const BPoint& origin);
void OffsetOrigin(const BPoint& offset);
inline const BPoint& Origin() const
{ return fOrigin; }
void SetScale(float scale);
inline float Scale() const
{ return fScale; }
// additional clipping as requested by client
void SetClippingRegion(const BRegion& region);
inline const BRegion* ClippingRegion() const
{ return fClippingRegion; }
/* inline int32 CountClippingRects() const
{ return fClippingRegion ? fClippingRegion.CountRects() : 0; }
inline BRect ClippingRectAt(int32 index) const;*/
// color
void SetHighColor(const RGBColor& color);
inline const RGBColor& HighColor() const
{ return fHighColor; }
void SetLowColor(const RGBColor& color);
inline const RGBColor& LowColor() const
{ return fLowColor; }
void SetPattern(const Pattern& pattern);
inline const Pattern& GetPattern() const
{ return fPattern; }
// drawing/blending mode
void SetDrawingMode(drawing_mode mode);
inline drawing_mode GetDrawingMode() const
{ return fDrawingMode; }
void SetBlendingMode(source_alpha srcMode,
alpha_function fncMode);
inline source_alpha AlphaSrcMode() const
{ return fAlphaSrcMode; }
inline alpha_function AlphaFncMode() const
{ return fAlphaFncMode; }
// pen
void SetPenLocation(const BPoint& location);
const BPoint& PenLocation() const;
void SetPenSize(float size);
float PenSize() const;
// font
void SetFont(const ServerFont& font,
uint32 flags = B_FONT_ALL);
inline const ServerFont& Font() const
{ return fFont; }
// overrides aliasing flag contained in SeverFont::Flags())
void SetForceFontAliasing(bool aliasing);
inline bool ForceFontAliasing() const
{ return fFontAliasing; }
// postscript style settings
void SetLineCapMode(cap_mode mode);
inline cap_mode LineCapMode() const
{ return fLineCapMode; }
void SetLineJoinMode(join_mode mode);
inline join_mode LineJoinMode() const
{ return fLineJoinMode; }
void SetMiterLimit(float limit);
inline float MiterLimit() const
{ return fMiterLimit; }
// convenience functions
inline BPoint Transform(const BPoint& point) const;
inline BRect Transform(const BRect& rect) const;
void SetSubPixelPrecise(bool precise);
inline bool SubPixelPrecise() const
{ return fSubPixelPrecise; }
protected:
BPoint fOrigin;
float fScale;
BRegion* fClippingRegion;
RGBColor fHighColor;
RGBColor fLowColor;
Pattern fPattern;
drawing_mode fDrawingMode;
source_alpha fAlphaSrcMode;
alpha_function fAlphaFncMode;
BPoint fPenLocation;
float fPenSize;
ServerFont fFont;
// overrides font aliasing flag
bool fFontAliasing;
// This is not part of the normal state stack.
// Layer will update it in PushState/PopState.
// A BView can have a flag "B_SUBPIXEL_PRECISE",
// I never knew what it does on R5, but I can use
// it in Painter to actually draw stuff with
// sub-pixel coordinates. It means
// StrokeLine(BPoint(10, 5), BPoint(20, 9));
// will look different from
// StrokeLine(BPoint(10.3, 5.8), BPoint(20.6, 9.5));
bool fSubPixelPrecise;
cap_mode fLineCapMode;
join_mode fLineJoinMode;
float fMiterLimit;
// "internal", used to calculate the size
// of the font (again) when the scale changes
float fUnscaledFontSize;
};
class LayerData : public DrawData {
public:
LayerData();
LayerData(const LayerData& data);
// this version used for the state
// stack, sets prevState to data too
LayerData(LayerData* data);
virtual ~LayerData();
LayerData& operator=(const LayerData &from);
// convenience functions
virtual void PrintToStream() const;
void ReadFontFromLink(BPrivate::LinkReceiver& link);
// NOTE: ReadFromLink() does not read Font state!!
// It was separate in ServerWindow, and I didn't
// want to change it without knowing implications.
void ReadFromLink(BPrivate::LinkReceiver& link);
void WriteToLink(BPrivate::LinkSender& link) const;
public:
// used for the state stack
LayerData* prevState;
};
// inline implementations
// Transform
BPoint
DrawData::Transform(const BPoint& point) const
{
BPoint p(point);
p += fOrigin;
p.x *= fScale;
p.y *= fScale;
return p;
}
// Transform
BRect
DrawData::Transform(const BRect& rect) const
{
return BRect(Transform(rect.LeftTop()),
Transform(rect.LeftBottom()));
}
/*
// ClippingRectAt
BRect
DrawData::ClippingRectAt(int32 index) const
{
BRect r;
if (fClippingRegion) {
r = fClippingRegion.RectAt(index);
}
return r;
}*/
#endif // LAYER_DATA_H_