X11WindowSystem: Introducing skip of DamageEvents for resized surfaces
[profile/ivi/layer-management.git] / LayerManagerBase / include / GraphicalSurface.h
1 /***************************************************************************
2 *
3 * Copyright 2010,2011 BMW Car IT GmbH
4 *
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 *        http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 ****************************************************************************/
19
20 #ifndef _GRAPHICALSURFACE_H_
21 #define _GRAPHICALSURFACE_H_
22
23 #include "GraphicalObject.h"
24 #include "OrientationType.h"
25 #include "Rectangle.h"
26 #include "Vector2.h"
27
28 /**
29  * Abstract Type representing a graphical surface.
30  */
31 class GraphicalSurface : public GraphicalObject
32 {
33 public:
34     GraphicalSurface(ObjectType type, int creatorPid);
35
36     GraphicalSurface(int externalId, ObjectType type, int creatorPid);
37
38     virtual ~GraphicalSurface() {}
39
40     /**
41      * @brief Set Orientation value
42      * @param[in] newOrientation the new value. Multiples of 90 degrees. (0->0°, 1->90°, 2->180°,3->279°)
43      * @return TRUE if the new orientation value is not equal to the current orientation value
44      *         FALSE if they are equal
45      */
46     bool setOrientation(OrientationType newOrientation);
47
48     OrientationType getOrientation() const;
49
50     /**
51      * @brief Set Source Viewport (only use portion of source graphics)
52      * @param[in] newSource Rectangle defining position and size within surface (clip from the left)
53      * @return TRUE if the new source rectangle is not equal to the current source rectangle
54      *         FALSE if they are equal
55      */
56     bool setSourceRegion(const Rectangle& newSource);
57
58     const Rectangle& getSourceRegion() const;
59
60     /**
61      * Set Destination Viewport (Scale output)
62      * @param[in] newDestination Rectangle defining destination position and size
63      * @return TRUE if the new destination rectangle is not equal to the current destination rectangle
64      *         FALSE if they are equal
65      */
66     bool setDestinationRegion(const Rectangle& newDestination);
67
68     bool setPosition(const unsigned int& x, const unsigned int& y);
69
70     Vector2 getPosition();
71     bool setDimension(const unsigned int& width, const unsigned int& height);
72
73     const Rectangle& getDestinationRegion() const;
74     Vector2 getDimension();
75
76     /**
77      * @brief Indicate if a x,y position is inside the destination region.
78      *        Attention: Graphical Surface rotation is not yet supported.
79      * @param x_DestCoordinateSyst x position in the destination coordinate system
80      * @param y_DestCoordinateSyst y position in the destination coordinate system
81      * @return TRUE if the position is inside the destination region
82      */
83     bool isInside(unsigned int x_DestCoordinateSyst, unsigned int y_DestCoordinateSyst) const;
84
85     /**
86      * @brief Transform a x,y position from destination coordinate system to
87      *              source coordinate system. Attention, to get valid result the x,y
88      *              positions given in parameter must be located within the destination
89      *              region of the GraphicalSurface
90      *
91      * @param[in]  x x position in the destination coordinate system
92      * @param[out] x x position in the source coordinate system
93      * @param[in] y y position in the destination coordinate system
94      * @param[out] y y position in the source coordinate system
95      * @param check If TRUE, a test will be done to make sure the x,y positions
96      *              given in parameter are located within the destination region.
97      *
98      * @return TRUE if the coordinates have been translated
99      *         FALSE if an error occured, exp: The position is not in the destination region
100      */
101     bool DestToSourceCoordinates(int *x, int *y, bool check) const;
102
103     int OriginalSourceWidth;
104     int OriginalSourceHeight;
105     bool m_surfaceResized;
106
107 private:
108     OrientationType m_orientation; // Rotation of the graphical content
109     Rectangle m_sourceViewport;
110     Rectangle m_destinationViewport;
111 };
112
113
114 inline GraphicalSurface::GraphicalSurface(ObjectType type, int creatorPid)
115 : GraphicalObject(type, 1.0, false, creatorPid)
116 , OriginalSourceWidth(0)
117 , OriginalSourceHeight(0)
118 , m_surfaceResized(false)
119 , m_orientation(Zero)
120 , m_sourceViewport(0, 0, 0, 0)
121 , m_destinationViewport(0, 0, 0, 0)
122 {
123 }
124
125 inline GraphicalSurface::GraphicalSurface(int externalId, ObjectType type, int creatorPid)
126 : GraphicalObject(externalId, type, 1.0, false, creatorPid)
127 , OriginalSourceWidth(0)
128 , OriginalSourceHeight(0)
129 , m_surfaceResized(false)
130 , m_orientation(Zero)
131 , m_sourceViewport(0, 0, 0, 0)
132 , m_destinationViewport(0, 0, 0, 0)
133 {
134 }
135
136 inline bool GraphicalSurface::setOrientation(OrientationType newOrientation)
137 {
138     if (m_orientation != newOrientation)
139     {
140         m_orientation = newOrientation;
141         renderPropertyChanged = true;
142         return true;
143     }
144     return false;
145 }
146
147 inline OrientationType GraphicalSurface::getOrientation() const
148 {
149     return m_orientation;
150 }
151
152 inline bool GraphicalSurface::setSourceRegion(const Rectangle& newSource)
153 {
154     if (!(m_sourceViewport == newSource))
155     {
156         m_sourceViewport = newSource;
157         renderPropertyChanged = true;
158         return true;
159     }
160     return false;
161 }
162
163 inline const Rectangle& GraphicalSurface::getSourceRegion() const
164 {
165     return m_sourceViewport;
166 }
167
168 inline bool GraphicalSurface::setDestinationRegion(const Rectangle& newDestination)
169 {
170     if (!(m_destinationViewport == newDestination))
171     {
172         m_destinationViewport = newDestination;
173         renderPropertyChanged = true;
174         return true;
175     }
176     return false;
177 }
178
179 inline bool GraphicalSurface::setPosition(const unsigned int& x, const unsigned int& y)
180 {
181     if (m_destinationViewport.x != x || m_destinationViewport.y != y)
182     {
183         m_destinationViewport.x = x;
184         m_destinationViewport.y = y;
185         renderPropertyChanged = true;
186         return true;
187     }
188     return false;
189 }
190
191 inline Vector2 GraphicalSurface::getPosition()
192 {
193     return Vector2(m_destinationViewport.x, m_destinationViewport.y);
194 }
195
196 inline bool GraphicalSurface::setDimension(const unsigned int& width, const unsigned int& height)
197 {
198     if (m_destinationViewport.width != width || m_destinationViewport.height != height)
199     {
200         m_destinationViewport.width = width;
201         m_destinationViewport.height = height;
202         renderPropertyChanged = true;
203         return true;
204     }
205     return false;
206 }
207
208 inline const Rectangle& GraphicalSurface::getDestinationRegion() const
209 {
210     return m_destinationViewport;
211 }
212
213 inline Vector2 GraphicalSurface::getDimension()
214 {
215     return Vector2(m_destinationViewport.width, m_destinationViewport.height);
216 }
217
218 #endif /* _GRAPHICALSURFACE_H_ */