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_SVX_SDR_OVERLAY_OVERLAYOBJECT_HXX
21 #define INCLUDED_SVX_SDR_OVERLAY_OVERLAYOBJECT_HXX
22 
23 #include <basegfx/point/b2dpoint.hxx>
24 #include <basegfx/range/b2drange.hxx>
25 #include <tools/color.hxx>
26 #include <svx/sdr/animation/scheduler.hxx>
27 #include <svx/svxdllapi.h>
28 #include <drawinglayer/primitive2d/baseprimitive2d.hxx>
29 
30 #include <vector>
31 
32 class OutputDevice;
33 
34 namespace sdr
35 {
36     namespace overlay
37     {
38         class OverlayManager;
39     } // end of namespace overlay
40 }
41 
42 namespace basegfx
43 {
44     class B2DPolygon;
45     class B2DPolyPolygon;
46     class B2DRange;
47 }
48 
49 namespace sdr
50 {
51     namespace overlay
52     {
53         class SVX_DLLPUBLIC OverlayObject : public sdr::animation::Event
54         {
55         private:
56             OverlayObject(const OverlayObject&) = delete;
57             OverlayObject& operator=(const OverlayObject&) = delete;
58 
59             // Manager is allowed access to private Member mpOverlayManager
60             friend class                                    OverlayManager;
61 
62             // pointer to OverlayManager, if object is added. Changed by
63             // OverlayManager, do not change Yourself.
64             OverlayManager*                                 mpOverlayManager;
65 
66             // Primitive2DContainer of the OverlayObject
67             drawinglayer::primitive2d::Primitive2DContainer maPrimitive2DSequence;
68 
69             // Possible Offset added to the geometry (automatically in
70             // createOverlayObjectPrimitive2DSequence()). Usually zero, may
71             // be used e.g. from calc when GridOffset is needed
72             basegfx::B2DVector                              maOffset;
73 
74         protected:
75             // access methods to maPrimitive2DSequence. The usage of this methods may allow
76             // later thread-safe stuff to be added if needed. Only to be used by getPrimitive2DSequence()
77             // implementations for buffering the last decomposition.
78             // Resetting is allowed e.g. in ::getOverlayObjectPrimitive2DSequence() implementations
79             // if the conditions have changed to force a re-creation in calling the base implementation.
80             // The only allowed setter of maPrimitive2DSequence is
81             // OverlayObject::getOverlayObjectPrimitive2DSequence() which should be called by calling
82             // the base implementation in derived functions. That one will use the result of
83             // createOverlayObjectPrimitive2DSequence() to provide the geometry.
getPrimitive2DSequence() const84             const drawinglayer::primitive2d::Primitive2DContainer& getPrimitive2DSequence() const { return maPrimitive2DSequence; }
resetPrimitive2DSequence()85             void resetPrimitive2DSequence() { maPrimitive2DSequence.clear(); }
86 
87             // the creation method for Primitive2DContainer. Called when getPrimitive2DSequence()
88             // sees that maPrimitive2DSequence is empty. Needs to be supported by all
89             // OverlayObject implementations. Default implementation will assert
90             // a missing implementation
91             virtual drawinglayer::primitive2d::Primitive2DContainer createOverlayObjectPrimitive2DSequence();
92 
93             // #i53216# check blink time value range (currently 25 < mnBlinkTime < 10000)
94             static sal_uInt32 impCheckBlinkTimeValueRange(sal_uInt64 nBlinkTime);
95 
96             // region in logical coordinates
97             basegfx::B2DRange                               maBaseRange;
98 
99             // base color of this OverlayObject
100             Color                                           maBaseColor;
101 
102             // Flag for visibility
103             bool                                            mbIsVisible : 1;
104 
105             // Flag to control hittability
106             bool                                            mbIsHittable : 1;
107 
108             // Flag to hold info if this objects supports animation. Default is
109             // false. If true, the Trigger() method should be overridden
110             // to implement the animation effect and to re-initiate the event.
111             bool                                            mbAllowsAnimation : 1;
112 
113             // Flag to control if this OverlayObject allows AntiAliased visualisation.
114             // Default is true, but e.g. for selection visualisation in SC and SW,
115             // it is switched to false
116             bool                                            mbAllowsAntiAliase : 1;
117 
118             // set changed flag. Call after change, since the old range is invalidated
119             // and then the new one is calculated and invalidated, too. This will only
120             // work after the change.
121             void objectChange();
122 
123             // write access to AntiAliase flag. This is protected since
124             // only implementations are allowed to change this, preferably in their
125             // constructor
126             void allowAntiAliase(bool bNew);
127 
128         public:
129             explicit OverlayObject(Color aBaseColor);
130             virtual ~OverlayObject() override;
131 
132             // get OverlayManager
getOverlayManager() const133             OverlayManager* getOverlayManager() const { return mpOverlayManager; }
134 
135             // the access method for Primitive2DContainer. Will use createPrimitive2DSequence and
136             // setPrimitive2DSequence if needed. Overriding may be used to allow disposal of last
137             // created primitives to react on changed circumstances and to re-create primitives
138             virtual drawinglayer::primitive2d::Primitive2DContainer getOverlayObjectPrimitive2DSequence() const;
139 
140             // access to visibility state
isVisible() const141             bool isVisible() const { return mbIsVisible; }
142             void setVisible(bool bNew);
143 
144             // access to hittable flag
isHittable() const145             bool isHittable() const { return mbIsHittable; }
146             void setHittable(bool bNew);
147 
148             // read access to AntiAliase flag
allowsAntiAliase() const149             bool allowsAntiAliase() const { return mbAllowsAntiAliase; }
150 
151             // read access to baseRange. This may trigger createBaseRange() if
152             // object is changed.
153             const basegfx::B2DRange& getBaseRange() const;
154 
155             // access to baseColor
getBaseColor() const156             const Color& getBaseColor() const { return maBaseColor; }
157             void setBaseColor(Color aNew);
158 
159             // access to Offset
getOffset() const160             const basegfx::B2DVector& getOffset() const { return maOffset; }
161             void setOffset(const basegfx::B2DVector& rOffset);
162 
163             // execute event from base class sdr::animation::Event. Default
164             // implementation does nothing and does not create a new event.
165             virtual void Trigger(sal_uInt32 nTime) override;
166 
167             // access to AllowsAnimation flag
allowsAnimation() const168             bool allowsAnimation() const { return mbAllowsAnimation; }
169 
170             // stripe definition has changed. The OverlayManager does have
171             // support data to draw graphics in two colors striped. This
172             // method notifies the OverlayObject if that change takes place.
173             // Default implementation does nothing.
174             virtual void stripeDefinitionHasChanged();
175         };
176 
177         // typedefs for a vector of OverlayObjects
178         typedef ::std::vector< OverlayObject* > OverlayObjectVector;
179 
180     } // end of namespace overlay
181 } // end of namespace sdr
182 
183 namespace sdr
184 {
185     namespace overlay
186     {
187         class SVX_DLLPUBLIC OverlayObjectWithBasePosition : public OverlayObject
188         {
189         protected:
190             // base position in logical coordinates
191             basegfx::B2DPoint                       maBasePosition;
192 
193         public:
194             OverlayObjectWithBasePosition(const basegfx::B2DPoint& rBasePos, Color aBaseColor);
195             virtual ~OverlayObjectWithBasePosition() override;
196 
197             // access to basePosition
getBasePosition() const198             const basegfx::B2DPoint& getBasePosition() const { return maBasePosition; }
199             void setBasePosition(const basegfx::B2DPoint& rNew);
200         };
201     } // end of namespace overlay
202 } // end of namespace sdr
203 
204 #endif // INCLUDED_SVX_SDR_OVERLAY_OVERLAYOBJECT_HXX
205 
206 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
207