Branch libreoffice-6-3
[LibreOffice.git] / include / drawinglayer / primitive2d / sceneprimitive2d.hxx
blobfaac60ca50d9e3530521af92d17ac7d761aa9c35
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_DRAWINGLAYER_PRIMITIVE2D_SCENEPRIMITIVE2D_HXX
21 #define INCLUDED_DRAWINGLAYER_PRIMITIVE2D_SCENEPRIMITIVE2D_HXX
23 #include <drawinglayer/drawinglayerdllapi.h>
25 #include <drawinglayer/primitive2d/baseprimitive2d.hxx>
26 #include <drawinglayer/primitive3d/baseprimitive3d.hxx>
27 #include <drawinglayer/geometry/viewinformation3d.hxx>
28 #include <basegfx/matrix/b2dhommatrix.hxx>
29 #include <vcl/bitmapex.hxx>
30 #include <drawinglayer/attribute/sdrsceneattribute3d.hxx>
31 #include <drawinglayer/attribute/sdrlightingattribute3d.hxx>
34 namespace drawinglayer
36 namespace primitive2d
38 /** ScenePrimitive2D class
40 This primitive defines a 3D scene as a 2D primitive and is the anchor point
41 for a 3D visualisation. The decomposition is view-dependent and will try to
42 re-use already rendered 3D content.
44 The rendering is done using the default-3D renderer from basegfx which supports
45 AntiAliasing.
47 The 2D primitive's geometric range is defined completely by the
48 ObjectTransformation combined with evtl. 2D shadows from the 3D objects. The
49 shadows of 3D objects are 2D polygons, projected with the 3D transformation.
51 This is the class a renderer may process directly when he wants to implement
52 an own (e.g. system-specific) 3D renderer.
54 class DRAWINGLAYER_DLLPUBLIC ScenePrimitive2D : public BufferedDecompositionPrimitive2D
56 private:
57 /// the 3D geometry definition
58 primitive3d::Primitive3DContainer mxChildren3D;
60 /// 3D scene attribute set
61 attribute::SdrSceneAttribute maSdrSceneAttribute;
63 /// lighting attribute set
64 attribute::SdrLightingAttribute maSdrLightingAttribute;
66 /// object transformation for scene for 2D definition
67 basegfx::B2DHomMatrix maObjectTransformation;
69 /// scene transformation set and object transformation
70 geometry::ViewInformation3D maViewInformation3D;
72 /// the primitiveSequence for on-demand created shadow primitives (see mbShadow3DChecked)
73 Primitive2DContainer maShadowPrimitives;
75 /** flag if given 3D geometry is already cheched for shadow definitions and 2d shadows
76 are created in maShadowPrimitives
78 bool mbShadow3DChecked : 1;
80 /// the last used NewDiscreteSize and NewUnitVisiblePart definitions for decomposition
81 double mfOldDiscreteSizeX;
82 double mfOldDiscreteSizeY;
83 basegfx::B2DRange maOldUnitVisiblePart;
85 /** the last created BitmapEx, e.g. for fast HitTest. This does not really need
86 memory since BitmapEx is internally RefCounted
88 BitmapEx maOldRenderedBitmap;
90 /// private helpers
91 bool impGetShadow3D() const;
92 void calculateDiscreteSizes(
93 const geometry::ViewInformation2D& rViewInformation,
94 basegfx::B2DRange& rDiscreteRange,
95 basegfx::B2DRange& rVisibleDiscreteRange,
96 basegfx::B2DRange& rUnitVisibleRange) const;
98 protected:
99 /// local decomposition.
100 virtual void create2DDecomposition(Primitive2DContainer& rContainer, const geometry::ViewInformation2D& rViewInformation) const override;
102 public:
103 /// public helpers
104 /** Geometry extractor. Shadow will be added as in create2DDecomposition, but
105 the 3D content is not converted to a bitmap visualisation but to projected 2D geometry. This
106 helper is useful e.g. for Contour extraction or HitTests.
108 Primitive2DContainer getGeometry2D() const;
109 Primitive2DContainer getShadow2D() const;
111 /** Fast HitTest which uses the last buffered BitmapEx from the last
112 rendered area if available. The return value describes if the check
113 could be done with the current information, so do NOT use o_rResult
114 when it returns false. o_rResult will be changed on return true and
115 then contains a definitive answer if content of this scene is hit or
116 not. On return false, it is normally necessary to use the geometric
117 HitTest (see CutFindProcessor usages). The given HitPoint
118 has to be in logic coordinates in scene's ObjectCoordinateSystem.
120 bool tryToCheckLastVisualisationDirectHit(const basegfx::B2DPoint& rLogicHitPoint, bool& o_rResult) const;
122 /// constructor
123 ScenePrimitive2D(
124 const primitive3d::Primitive3DContainer& rxChildren3D,
125 const attribute::SdrSceneAttribute& rSdrSceneAttribute,
126 const attribute::SdrLightingAttribute& rSdrLightingAttribute,
127 const basegfx::B2DHomMatrix& rObjectTransformation,
128 const geometry::ViewInformation3D& rViewInformation3D);
130 /// data read access
131 const primitive3d::Primitive3DContainer& getChildren3D() const { return mxChildren3D; }
132 const attribute::SdrSceneAttribute& getSdrSceneAttribute() const { return maSdrSceneAttribute; }
133 const attribute::SdrLightingAttribute& getSdrLightingAttribute() const { return maSdrLightingAttribute; }
134 const basegfx::B2DHomMatrix& getObjectTransformation() const { return maObjectTransformation; }
135 const geometry::ViewInformation3D& getViewInformation3D() const { return maViewInformation3D; }
137 /// compare operator
138 virtual bool operator==(const BasePrimitive2D& rPrimitive) const override;
140 /// get range
141 virtual basegfx::B2DRange getB2DRange(const geometry::ViewInformation2D& rViewInformation) const override;
143 /// provide unique ID
144 DeclPrimitive2DIDBlock()
146 /// get local decomposition. Override since this decomposition is view-dependent
147 virtual void get2DDecomposition(Primitive2DDecompositionVisitor& rVisitor, const geometry::ViewInformation2D& rViewInformation) const override;
149 } // end of namespace primitive2d
150 } // end of namespace drawinglayer
153 #endif //INCLUDED_DRAWINGLAYER_PRIMITIVE2D_SCENEPRIMITIVE2D_HXX
155 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */