1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  *   Licensed to the Apache Software Foundation (ASF) under one or more
12  *   contributor license agreements. See the NOTICE file distributed
13  *   with this work for additional information regarding copyright
14  *   ownership. The ASF licenses this file to you under the Apache
15  *   License, Version 2.0 (the "License"); you may not use this file
16  *   except in compliance with the License. You may obtain a copy of
17  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #ifndef INCLUDED_SDEXT_SOURCE_PRESENTER_PRESENTERGEOMETRYHELPER_HXX
21 #define INCLUDED_SDEXT_SOURCE_PRESENTER_PRESENTERGEOMETRYHELPER_HXX
22 
23 #include <com/sun/star/awt/Rectangle.hpp>
24 #include <com/sun/star/rendering/XGraphicDevice.hpp>
25 #include <com/sun/star/rendering/XPolyPolygon2D.hpp>
26 #include <com/sun/star/geometry/RealRectangle2D.hpp>
27 #include <vector>
28 
29 namespace sdext::presenter {
30 
31 /** Collection of geometry related convenience functions.
32 */
33 class PresenterGeometryHelper
34 {
35 public:
36     static sal_Int32 Round (const double nValue);
37     static sal_Int32 Floor (const double nValue);
38     static sal_Int32 Ceil (const double nValue);
39 
40     /** Return the bounding box with integer coordinates of the given
41         rectangle.  Note that due to different rounding of the left/top and
42         the right/bottom border the width of the resulting rectangle may
43         differ for different positions but constant width and height.
44     */
45     static css::awt::Rectangle ConvertRectangle (
46         const css::geometry::RealRectangle2D& rBox);
47 
48     /** Convert the given rectangle to integer coordinates so that width and
49         height remain constant when only the position changes.
50     */
51     static css::awt::Rectangle ConvertRectangleWithConstantSize (
52         const css::geometry::RealRectangle2D& rBox);
53 
54     static css::geometry::RealRectangle2D ConvertRectangle (
55         const css::awt::Rectangle& rBox);
56 
57     //    static css::awt::Size ConvertSize (
58     //        const css::geometry::RealSize2D& rSize);
59 
60     static css::awt::Rectangle TranslateRectangle (
61         const css::awt::Rectangle& rBox,
62         const sal_Int32 nXOffset,
63         const sal_Int32 nYOffset);
64 
65     static css::awt::Rectangle Intersection (
66         const css::awt::Rectangle& rBox1,
67         const css::awt::Rectangle& rBox2);
68 
69     static css::geometry::RealRectangle2D Intersection (
70         const css::geometry::RealRectangle2D& rBox1,
71         const css::geometry::RealRectangle2D& rBox2);
72 
73     static bool IsInside (
74         const css::geometry::RealRectangle2D& rBox,
75         const css::geometry::RealPoint2D& rPoint);
76 
77     /** Return whether rBox1 is completely inside rBox2.
78     */
79     static bool IsInside (
80         const css::awt::Rectangle& rBox1,
81         const css::awt::Rectangle& rBox2);
82 
83     static css::geometry::RealRectangle2D Union (
84         const css::geometry::RealRectangle2D& rBox1,
85         const css::geometry::RealRectangle2D& rBox2);
86 
87     static bool AreRectanglesDisjoint (
88         const css::awt::Rectangle& rBox1,
89         const css::awt::Rectangle& rBox2);
90 
91     static css::uno::Reference<css::rendering::XPolyPolygon2D> CreatePolygon(
92         const css::awt::Rectangle& rBox,
93         const css::uno::Reference<css::rendering::XGraphicDevice>& rxDevice);
94 
95     static css::uno::Reference<css::rendering::XPolyPolygon2D> CreatePolygon(
96         const css::geometry::RealRectangle2D& rBox,
97         const css::uno::Reference<css::rendering::XGraphicDevice>& rxDevice);
98 
99     static css::uno::Reference<css::rendering::XPolyPolygon2D> CreatePolygon(
100         const ::std::vector<css::awt::Rectangle>& rBoxes,
101         const css::uno::Reference<css::rendering::XGraphicDevice>& rxDevice);
102 
103     /** Create a polygon for a rounded rectangle.
104     */
105     /*    static css::uno::Reference<css::rendering::XPolyPolygon2D> CreatePolygon(
106         const css::awt::Rectangle& rBox,
107         const double nRadius,
108         const css::uno::Reference<css::rendering::XGraphicDevice>&
109         rxDevice);
110     */
111 };
112 
113 }
114 
115 #endif
116 
117 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
118