1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef SDEXT_PRESENTER_PRESENTER_GEOMETRY_HELPER_HXX 25 #define SDEXT_PRESENTER_PRESENTER_GEOMETRY_HELPER_HXX 26 27 #include <com/sun/star/awt/Point.hpp> 28 #include <com/sun/star/awt/Rectangle.hpp> 29 #include <com/sun/star/awt/Size.hpp> 30 #include <com/sun/star/rendering/XGraphicDevice.hpp> 31 #include <com/sun/star/rendering/XPolyPolygon2D.hpp> 32 #include <com/sun/star/geometry/RealRectangle2D.hpp> 33 #include <vector> 34 35 namespace css = ::com::sun::star; 36 37 namespace sdext { namespace presenter { 38 39 /** Collection of geometry related convenience functions. 40 */ 41 class PresenterGeometryHelper 42 { 43 public: 44 static sal_Int32 Round (const double nValue); 45 static sal_Int32 Floor (const double nValue); 46 static sal_Int32 Ceil (const double nValue); 47 48 /** Return the bounding box with integer coordinates of the given 49 rectangle. Note that due to different rounding of the left/top and 50 the right/bottom border the width of the resulting rectangle may 51 differ for different positions but constant width and height. 52 */ 53 static css::awt::Rectangle ConvertRectangle ( 54 const css::geometry::RealRectangle2D& rBox); 55 56 /** Convert the given rectangle to integer coordinates so that width and 57 height remain constant when only the position changes. 58 */ 59 static css::awt::Rectangle ConvertRectangleWithConstantSize ( 60 const css::geometry::RealRectangle2D& rBox); 61 62 static css::geometry::RealRectangle2D ConvertRectangle ( 63 const css::awt::Rectangle& rBox); 64 65 // static css::awt::Size ConvertSize ( 66 // const css::geometry::RealSize2D& rSize); 67 68 static css::awt::Rectangle TranslateRectangle ( 69 const css::awt::Rectangle& rBox, 70 const sal_Int32 nXOffset, 71 const sal_Int32 nYOffset); 72 73 static css::awt::Rectangle Intersection ( 74 const css::awt::Rectangle& rBox1, 75 const css::awt::Rectangle& rBox2); 76 77 static css::geometry::RealRectangle2D Intersection ( 78 const css::geometry::RealRectangle2D& rBox1, 79 const css::geometry::RealRectangle2D& rBox2); 80 81 static bool IsInside ( 82 const css::geometry::RealRectangle2D& rBox, 83 const css::geometry::RealPoint2D& rPoint); 84 85 /** Return whether rBox1 is completly inside rBox2. 86 */ 87 static bool IsInside ( 88 const css::awt::Rectangle& rBox1, 89 const css::awt::Rectangle& rBox2); 90 91 static css::awt::Rectangle Union ( 92 const css::awt::Rectangle& rBox1, 93 const css::awt::Rectangle& rBox2); 94 95 static css::geometry::RealRectangle2D Union ( 96 const css::geometry::RealRectangle2D& rBox1, 97 const css::geometry::RealRectangle2D& rBox2); 98 99 static bool AreRectanglesDisjoint ( 100 const css::awt::Rectangle& rBox1, 101 const css::awt::Rectangle& rBox2); 102 103 static css::uno::Reference<css::rendering::XPolyPolygon2D> CreatePolygon( 104 const css::awt::Rectangle& rBox, 105 const css::uno::Reference<css::rendering::XGraphicDevice>& rxDevice); 106 107 static css::uno::Reference<css::rendering::XPolyPolygon2D> CreatePolygon( 108 const css::geometry::RealRectangle2D& rBox, 109 const css::uno::Reference<css::rendering::XGraphicDevice>& rxDevice); 110 111 static css::uno::Reference<css::rendering::XPolyPolygon2D> CreatePolygon( 112 const ::std::vector<css::awt::Rectangle>& rBoxes, 113 const css::uno::Reference<css::rendering::XGraphicDevice>& rxDevice); 114 115 /** Create a polygon for a rounded rectangle. 116 */ 117 /* static css::uno::Reference<css::rendering::XPolyPolygon2D> CreatePolygon( 118 const css::awt::Rectangle& rBox, 119 const double nRadius, 120 const css::uno::Reference<css::rendering::XGraphicDevice>& 121 rxDevice); 122 */ 123 }; 124 125 } } 126 127 #endif 128