/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
// Compute value usable as hash.
TOOLS_DLLPUBLIC size_t GetHashValue() const;
protected:
tools::Long mnA;
tools::Long mnB;
};
namespace tools::detail {
// Used to implement operator == for subclasses of Pair: inlinebool equal(Pair const & p1, Pair const & p2)
{ return p1.A() == p2.A() && p1.B() == p2.B();
}
}
// Point
class TOOLS_DLLPUBLIC PointTemplateBase : protected Pair
{ friendclass RectangleTemplateBase; public:
PointTemplateBase() = default; protected:
constexpr PointTemplateBase( tools::Long nX, tools::Long nY ) : Pair( nX, nY ) {} // Rotate parameter point using This as origin; store result back into parameter point void RotateAround( tools::Long& rX, tools::Long& rY, Degree10 nOrientation ) const; void RotateAround( PointTemplateBase&, Degree10 nOrientation ) const;
using Pair::toString; using Pair::GetHashValue;
};
class Size; class AbsoluteScreenPixelSize; class AbsoluteScreenPixelPoint; namespace tools { class Rectangle; } class AbsoluteScreenPixelRectangle;
class SAL_WARN_UNUSED Point : public PointTemplate<::Point, ::Size>
{ public:
constexpr Point() {}
constexpr Point( tools::Long nX, tools::Long nY ) : PointTemplate( nX, nY ) {} // TODO delete this to expose more problems
constexpr explicit Point(const AbsoluteScreenPixelPoint&);
};
// A point relative to top-level parent or screen, in screen pixels class SAL_WARN_UNUSED AbsoluteScreenPixelPoint : public PointTemplate<AbsoluteScreenPixelPoint, AbsoluteScreenPixelSize> { public:
constexpr AbsoluteScreenPixelPoint() {}
constexpr AbsoluteScreenPixelPoint( tools::Long nX, tools::Long nY ) : PointTemplate( nX, nY ) {}
constexpr explicit AbsoluteScreenPixelPoint(const Point & pt) : PointTemplate(pt.X(), pt.Y()) {}
};
/// Note: this class is a true marvel of engineering: because the author /// could not decide whether it's better to have a closed or half-open /// interval, they just implemented *both* in the same class! /// /// If you have the misfortune of having to use this class, don't immediately /// despair but first take note that the uppercase GetWidth() / GetHeight() /// etc. methods interpret the interval as closed. To use the half open versions, /// use GetOpenWidth() / GetOpenHeight(). /// /// If you want to work with Size, you must use the closed interval functions! /// And don't add GetOpenSize() / setSize; this will probably just introduce /// bugs, especially when used in combination with list-initialization. /// /// (Eventually you might notice, that the same engineer was also working on /// Qt at some point; see documentation on QRect::bottom / QRect::right ;-).
class TOOLS_DLLPUBLIC RectangleTemplateBase
{ public: static constexpr short RECT_EMPTY = -32767;
tools::Long getX() const { return mnLeft; }
tools::Long getY() const { return mnTop; } /// Returns the difference between right and left, assuming the range includes one end, but not the other.
tools::Long getOpenWidth() const { return Right() - Left(); } /// Returns the difference between bottom and top, assuming the range includes one end, but not the other.
tools::Long getOpenHeight() const { return Bottom() - Top(); } void setWidth( tools::Long n ) { mnRight = mnLeft + n; } void setHeight( tools::Long n ) { mnBottom = mnTop + n; }
/// Returns the difference between right and left, assuming the range is inclusive.
constexpr tools::Long GetWidth() const
{
tools::Long n = 0;
if (!IsWidthEmpty())
{
n = mnRight - mnLeft; if (n < 0)
n--; else
n++;
}
return n;
} /// Returns the difference between bottom and top, assuming the range is inclusive.
constexpr tools::Long GetHeight() const
{
tools::Long n = 0;
if (!IsHeightEmpty())
{
n = mnBottom - mnTop; if (n < 0)
n--; else
n++;
}
return n;
}
tools::Long AdjustLeft( tools::Long nHorzMoveDelta ) { mnLeft += nHorzMoveDelta; return mnLeft; }
tools::Long AdjustRight( tools::Long nHorzMoveDelta );
tools::Long AdjustTop( tools::Long nVertMoveDelta ) { mnTop += nVertMoveDelta; return mnTop; }
tools::Long AdjustBottom( tools::Long nVertMoveDelta ); /// Set the left edge of the rectangle to x, preserving the width void SetPosX(tools::Long x)
{ if (!IsWidthEmpty())
mnRight += x - mnLeft;
mnLeft = x;
} /// Set the top edge of the rectangle to y, preserving the height void SetPosY(tools::Long y)
{ if (!IsHeightEmpty())
mnBottom += y - mnTop;
mnTop = y;
}
/** * Expands the rectangle in all directions by the input value.
*/ void expand(tools::Long nExpandBy); void shrink(tools::Long nShrinkBy);
/// Move the top and left edges by a delta, preserving width and height void Move( tools::Long nHorzMoveDelta, tools::Long nVertMoveDelta )
{
mnLeft += nHorzMoveDelta;
mnTop += nVertMoveDelta; if (!IsWidthEmpty())
mnRight += nHorzMoveDelta; if (!IsHeightEmpty())
mnBottom += nVertMoveDelta;
}
/// Returns the string representation of the rectangle, format is "x, y, width, height".
rtl::OString toString() const;
template<class RectangleT, class PointT, class SizeT> class RectangleTemplate : public RectangleTemplateBase
{ friendclass ::tools::Rectangle; friendclass AbsoluteScreenPixelRectangle; public: using PointType = PointT; using SizeType = SizeT;
/** * Sanitizing variants for handling data from the outside
*/ void SaturatingSetSize(const SizeT& rSize) { RectangleTemplateBase::SaturatingSetSize(rSize); }
// Scales relative to 0,0
constexpr RectangleT scale(sal_Int64 nMulX, sal_Int64 nDivX,
sal_Int64 nMulY, sal_Int64 nDivY) const
{ // 1. Create an empty rectangle with correct left and top
RectangleT aRect(o3tl::convert(Left(), nMulX, nDivX),
o3tl::convert(Top(), nMulY, nDivY)); // 2. If source has width/height, set respective right and bottom if (!IsWidthEmpty())
aRect.SetRight(o3tl::convert(Right(), nMulX, nDivX)); if (!IsHeightEmpty())
aRect.SetBottom(o3tl::convert(Bottom(), nMulY, nDivY)); return aRect;
}
};
namespace tools
{ class SAL_WARN_UNUSED Rectangle final : public RectangleTemplate<Rectangle, Point, Size>
{ public: using RectangleTemplate::RectangleTemplate; // TODO remove this to find more issues
constexpr Rectangle(const AbsoluteScreenPixelPoint& pt, const Size& sz) : RectangleTemplate(Point(pt.X(), pt.Y()), sz) {} // TODO remove this to find more issues
constexpr Rectangle(const Point& pt, const AbsoluteScreenPixelSize& sz) : RectangleTemplate(pt, Size(sz.Width(), sz.Height())) {} // TODO remove this to find more issues
constexpr explicit Rectangle(const AbsoluteScreenPixelRectangle & r);
};
} // namespace tools
// A rectangle relative to top-level screen, in screen pixels class SAL_WARN_UNUSED AbsoluteScreenPixelRectangle : public RectangleTemplate<AbsoluteScreenPixelRectangle, AbsoluteScreenPixelPoint, AbsoluteScreenPixelSize> { public: using RectangleTemplate::RectangleTemplate; // TODO remove
constexpr explicit AbsoluteScreenPixelRectangle(const tools::Rectangle & r) : RectangleTemplate(r.mnLeft, r.mnTop, r.mnRight, r.mnBottom) {} // TODO remove
constexpr AbsoluteScreenPixelRectangle(const AbsoluteScreenPixelPoint& pt, constSize& sz) : RectangleTemplate(pt, AbsoluteScreenPixelSize(sz.Width(), sz.Height())) {}
};
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.