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;
105 bool m_surfaceResized;
108 OrientationType m_orientation; // Rotation of the graphical content
109 Rectangle m_sourceViewport;
110 Rectangle m_destinationViewport;
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)
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)
136 inline bool GraphicalSurface::setOrientation(OrientationType newOrientation)
138 if (m_orientation != newOrientation)
140 m_orientation = newOrientation;
141 renderPropertyChanged = true;
147 inline OrientationType GraphicalSurface::getOrientation() const
149 return m_orientation;
152 inline bool GraphicalSurface::setSourceRegion(const Rectangle& newSource)
154 if (!(m_sourceViewport == newSource))
156 m_sourceViewport = newSource;
157 renderPropertyChanged = true;
163 inline const Rectangle& GraphicalSurface::getSourceRegion() const
165 return m_sourceViewport;
168 inline bool GraphicalSurface::setDestinationRegion(const Rectangle& newDestination)
170 if (!(m_destinationViewport == newDestination))
172 m_destinationViewport = newDestination;
173 renderPropertyChanged = true;
179 inline bool GraphicalSurface::setPosition(const unsigned int& x, const unsigned int& y)
181 if (m_destinationViewport.x != x || m_destinationViewport.y != y)
183 m_destinationViewport.x = x;
184 m_destinationViewport.y = y;
185 renderPropertyChanged = true;
191 inline Vector2 GraphicalSurface::getPosition()
193 return Vector2(m_destinationViewport.x, m_destinationViewport.y);
196 inline bool GraphicalSurface::setDimension(const unsigned int& width, const unsigned int& height)
198 if (m_destinationViewport.width != width || m_destinationViewport.height != height)
200 m_destinationViewport.width = width;
201 m_destinationViewport.height = height;
202 renderPropertyChanged = true;
208 inline const Rectangle& GraphicalSurface::getDestinationRegion() const
210 return m_destinationViewport;
213 inline Vector2 GraphicalSurface::getDimension()
215 return Vector2(m_destinationViewport.width, m_destinationViewport.height);
218 #endif /* _GRAPHICALSURFACE_H_ */