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