summaryrefslogtreecommitdiff
path: root/LayerManagerBase/include/GraphicalSurface.h
blob: 454ce00a5a6967307c2a982a2e27b384b38a87df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/***************************************************************************
*
* Copyright 2010,2011 BMW Car IT GmbH
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*        http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
****************************************************************************/

#ifndef _GRAPHICALSURFACE_H_
#define _GRAPHICALSURFACE_H_

#include "GraphicalObject.h"
#include "OrientationType.h"
#include "Rectangle.h"
#include "Vector2.h"

/**
 * Abstract Type representing a graphical surface.
 */
class GraphicalSurface : public GraphicalObject
{
public:
    GraphicalSurface(ObjectType type, int creatorPid);

    GraphicalSurface(int externalId, ObjectType type, int creatorPid);

    virtual ~GraphicalSurface() {}

    /**
     * @brief Set Orientation value
     * @param[in] newOrientation the new value. Multiples of 90 degrees. (0->0°, 1->90°, 2->180°,3->279°)
     * @return TRUE if the new orientation value is not equal to the current orientation value
     *         FALSE if they are equal
     */
    bool setOrientation(OrientationType newOrientation);

    OrientationType getOrientation() const;

    /**
     * @brief Set Source Viewport (only use portion of source graphics)
     * @param[in] newSource Rectangle defining position and size within surface (clip from the left)
     * @return TRUE if the new source rectangle is not equal to the current source rectangle
     *         FALSE if they are equal
     */
    bool setSourceRegion(const Rectangle& newSource);

    const Rectangle& getSourceRegion() const;

    /**
     * Set Destination Viewport (Scale output)
     * @param[in] newDestination Rectangle defining destination position and size
     * @return TRUE if the new destination rectangle is not equal to the current destination rectangle
     *         FALSE if they are equal
     */
    bool setDestinationRegion(const Rectangle& newDestination);

    bool setPosition(const unsigned int& x, const unsigned int& y);

    Vector2 getPosition();
    bool setDimension(const unsigned int& width, const unsigned int& height);

    const Rectangle& getDestinationRegion() const;
    Vector2 getDimension();

    /**
     * @brief Indicate if a x,y position is inside the destination region.
     *        Attention: Graphical Surface rotation is not yet supported.
     * @param x_DestCoordinateSyst x position in the destination coordinate system
     * @param y_DestCoordinateSyst y position in the destination coordinate system
     * @return TRUE if the position is inside the destination region
     */
    bool isInside(unsigned int x_DestCoordinateSyst, unsigned int y_DestCoordinateSyst) const;

    /**
     * @brief Transform a x,y position from destination coordinate system to
     *              source coordinate system. Attention, to get valid result the x,y
     *              positions given in parameter must be located within the destination
     *              region of the GraphicalSurface
     *
     * @param[in]  x x position in the destination coordinate system
     * @param[out] x x position in the source coordinate system
     * @param[in] y y position in the destination coordinate system
     * @param[out] y y position in the source coordinate system
     * @param check If TRUE, a test will be done to make sure the x,y positions
     *              given in parameter are located within the destination region.
     *
     * @return TRUE if the coordinates have been translated
     *         FALSE if an error occured, exp: The position is not in the destination region
     */
    bool DestToSourceCoordinates(int *x, int *y, bool check) const;

    int OriginalSourceWidth;
    int OriginalSourceHeight;
    bool m_surfaceResized;
    bool m_resizesync;

private:
    OrientationType m_orientation; // Rotation of the graphical content
    Rectangle m_sourceViewport;
    Rectangle m_destinationViewport;
};


inline GraphicalSurface::GraphicalSurface(ObjectType type, int creatorPid)
: GraphicalObject(type, 1.0, false, creatorPid)
, OriginalSourceWidth(0)
, OriginalSourceHeight(0)
, m_surfaceResized(false)
, m_resizesync(false)
, m_orientation(Zero)
, m_sourceViewport(0, 0, 0, 0)
, m_destinationViewport(0, 0, 0, 0)
{
}

inline GraphicalSurface::GraphicalSurface(int externalId, ObjectType type, int creatorPid)
: GraphicalObject(externalId, type, 1.0, false, creatorPid)
, OriginalSourceWidth(0)
, OriginalSourceHeight(0)
, m_surfaceResized(false)
, m_resizesync(false)
, m_orientation(Zero)
, m_sourceViewport(0, 0, 0, 0)
, m_destinationViewport(0, 0, 0, 0)
{
}

inline bool GraphicalSurface::setOrientation(OrientationType newOrientation)
{
    if (m_orientation != newOrientation)
    {
        m_orientation = newOrientation;
        renderPropertyChanged = true;
        return true;
    }
    return false;
}

inline OrientationType GraphicalSurface::getOrientation() const
{
    return m_orientation;
}

inline bool GraphicalSurface::setSourceRegion(const Rectangle& newSource)
{
    if (!(m_sourceViewport == newSource))
    {
        m_sourceViewport = newSource;
        renderPropertyChanged = true;
        return true;
    }
    return false;
}

inline const Rectangle& GraphicalSurface::getSourceRegion() const
{
    return m_sourceViewport;
}

inline bool GraphicalSurface::setDestinationRegion(const Rectangle& newDestination)
{
    if (!(m_destinationViewport == newDestination))
    {
        m_destinationViewport = newDestination;
        renderPropertyChanged = true;
        return true;
    }
    return false;
}

inline bool GraphicalSurface::setPosition(const unsigned int& x, const unsigned int& y)
{
    if (m_destinationViewport.x != x || m_destinationViewport.y != y)
    {
        m_destinationViewport.x = x;
        m_destinationViewport.y = y;
        renderPropertyChanged = true;
        return true;
    }
    return false;
}

inline Vector2 GraphicalSurface::getPosition()
{
    return Vector2(m_destinationViewport.x, m_destinationViewport.y);
}

inline bool GraphicalSurface::setDimension(const unsigned int& width, const unsigned int& height)
{
    if (m_destinationViewport.width != width || m_destinationViewport.height != height)
    {
        m_destinationViewport.width = width;
        m_destinationViewport.height = height;
        renderPropertyChanged = true;
        return true;
    }
    return false;
}

inline const Rectangle& GraphicalSurface::getDestinationRegion() const
{
    return m_destinationViewport;
}

inline Vector2 GraphicalSurface::getDimension()
{
    return Vector2(m_destinationViewport.width, m_destinationViewport.height);
}

#endif /* _GRAPHICALSURFACE_H_ */