1 /***************************************************************************
3 * Copyright 2010,2011 BMW Car IT GmbH
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 ****************************************************************************/
20 #ifndef _GRAPHICALSURFACE_H_
21 #define _GRAPHICALSURFACE_H_
23 #include "GraphicalObject.h"
24 #include "OrientationType.h"
25 #include "Rectangle.h"
29 * Abstract Type representing a graphical surface.
31 class GraphicalSurface : public GraphicalObject
34 GraphicalSurface(ObjectType type, int creatorPid);
36 GraphicalSurface(int externalId, ObjectType type, int creatorPid);
38 virtual ~GraphicalSurface() {}
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
46 bool setOrientation(OrientationType newOrientation);
48 OrientationType getOrientation() const;
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
56 bool setSourceRegion(const Rectangle& newSource);
58 const Rectangle& getSourceRegion() const;
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
66 bool setDestinationRegion(const Rectangle& newDestination);
68 bool setPosition(const unsigned int& x, const unsigned int& y);
70 Vector2 getPosition();
71 bool setDimension(const unsigned int& width, const unsigned int& height);
73 const Rectangle& getDestinationRegion() const;
74 Vector2 getDimension();
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
83 bool isInside(unsigned int x_DestCoordinateSyst, unsigned int y_DestCoordinateSyst) const;
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
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.
98 * @return TRUE if the coordinates have been translated
99 * FALSE if an error occured, exp: The position is not in the destination region
101 bool DestToSourceCoordinates(int *x, int *y, bool check) const;
103 int OriginalSourceWidth;
104 int OriginalSourceHeight;
107 OrientationType m_orientation; // Rotation of the graphical content
108 Rectangle m_sourceViewport;
109 Rectangle m_destinationViewport;
113 inline GraphicalSurface::GraphicalSurface(ObjectType type, int creatorPid)
114 : GraphicalObject(type, 1.0, false, creatorPid)
115 , OriginalSourceWidth(0)
116 , OriginalSourceHeight(0)
117 , m_orientation(Zero)
118 , m_sourceViewport(0, 0, 0, 0)
119 , m_destinationViewport(0, 0, 0, 0)
123 inline GraphicalSurface::GraphicalSurface(int externalId, ObjectType type, int creatorPid)
124 : GraphicalObject(externalId, type, 1.0, false, creatorPid)
125 , OriginalSourceWidth(0)
126 , OriginalSourceHeight(0)
127 , m_orientation(Zero)
128 , m_sourceViewport(0, 0, 0, 0)
129 , m_destinationViewport(0, 0, 0, 0)
133 inline bool GraphicalSurface::setOrientation(OrientationType newOrientation)
135 if (m_orientation != newOrientation)
137 m_orientation = newOrientation;
138 renderPropertyChanged = true;
144 inline OrientationType GraphicalSurface::getOrientation() const
146 return m_orientation;
149 inline bool GraphicalSurface::setSourceRegion(const Rectangle& newSource)
151 if (!(m_sourceViewport == newSource))
153 m_sourceViewport = newSource;
154 renderPropertyChanged = true;
160 inline const Rectangle& GraphicalSurface::getSourceRegion() const
162 return m_sourceViewport;
165 inline bool GraphicalSurface::setDestinationRegion(const Rectangle& newDestination)
167 if (!(m_destinationViewport == newDestination))
169 m_destinationViewport = newDestination;
170 renderPropertyChanged = true;
176 inline bool GraphicalSurface::setPosition(const unsigned int& x, const unsigned int& y)
178 if (m_destinationViewport.x != x || m_destinationViewport.y != y)
180 m_destinationViewport.x = x;
181 m_destinationViewport.y = y;
182 renderPropertyChanged = true;
188 inline Vector2 GraphicalSurface::getPosition()
190 return Vector2(m_destinationViewport.x, m_destinationViewport.y);
193 inline bool GraphicalSurface::setDimension(const unsigned int& width, const unsigned int& height)
195 if (m_destinationViewport.width != width || m_destinationViewport.height != height)
197 m_destinationViewport.width = width;
198 m_destinationViewport.height = height;
199 renderPropertyChanged = true;
205 inline const Rectangle& GraphicalSurface::getDestinationRegion() const
207 return m_destinationViewport;
210 inline Vector2 GraphicalSurface::getDimension()
212 return Vector2(m_destinationViewport.width, m_destinationViewport.height);
215 #endif /* _GRAPHICALSURFACE_H_ */