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