summaryrefslogtreecommitdiff
path: root/LayerManagerBase/include/GraphicalObject.h
blob: 4c6775e9f89ae55744908980e14c4f1afda7837e (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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
 /***************************************************************************
 *
 * Copyright 2010,2011 BMW Car IT GmbH
 * Copyright (C) 2012 DENSO CORPORATION and Robert Bosch Car Multimedia 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 _GRAPHICALOBJECT_H_
#define _GRAPHICALOBJECT_H_

#include "ObjectType.h"
#include "ApplicationReferenceList.h"

class Shader;

/**
 * Base class of all objects representing graphical objects within the layermanagement.
 */
class GraphicalObject
{
public:

    GraphicalObject(ObjectType type, double opacity, bool visibility, int creatorPid);

    GraphicalObject(int externalId, ObjectType type, double opacity, bool visibility, int creatorPid);

    virtual ~GraphicalObject() {}

    /**
     * @brief Set alpha value
     * @param[in] newOpacity The new Alpha Value between 0.0 (full transparency) and 1.0 (fully visible)
     * @return TRUE if the new Alpha Value is not equal to the current Alpha Value
     *         FALSE if they are equal
     */
    virtual bool setOpacity(double newOpacity);

    /**
     * @brief Get alpha value
     * @return The current Alpha Value between 0.0 (full transparency) and 1.0 (fully visible)
     */
    double getOpacity() const;

    /**
     * @brief Set chroma key enabled value
     * @param[in] newEnabled The new ChromaKey enable (true) or disable (false)
     * @return TRUE if the new ChromaKey Enabled Value are not equal to the current Value
     *         FALSE if they are equal
     */
    virtual bool setChromaKeyEnabled(bool newEnabled);

    /**
     * @brief Get chroma key enabled value
     * @return The current chromakey enable (true) or disable (false)
     */
    bool getChromaKeyEnabled() const;

    /**
     * @brief Set chroma key
     * @param[in] newRed The new Red Value between 0 and 255
     * @param[in] newGreen The new Green Value between 0 and 255
     * @param[in] newBlue The new Blue Value between 0 and 255
     * @return TRUE if the new ChromaKey Values are not equal to the current ChromaKey Values
     *         FALSE if they are equal
     */
    virtual bool setChromaKey(unsigned char newRed, unsigned char newGreen, unsigned char newBlue);

    /**
     * @brief Get chroma key values
     * @param[out] red The current Red Value between 0 and 255
     * @param[out] green The current Green Value between 0 and 255
     * @param[out] blue The current Blue Value between 0 and 255
     */
    void getChromaKey(unsigned char& red, unsigned char& green, unsigned char& blue) const;

    
    /**
     * Set the synchronized compositing flag for this object.
     * Synchronized composition forces screen updates, if all synchronized objects are
     * were updated, otherwise the composition is freezed.  
     * @param[in] newSynchnronized set this object synchronized (true) or not (false)
     * @return TRUE if the new synchronized value is not equal to the current synchronized value
     *         FALSE if they are equal
     */
    bool setSynchronized(bool newSynchnronized);

    /**
     * Get the synchronized compositing flag for this object.
     * @param[in] newSynchnronized set this object synchronized (true) or not (false)
     * @return TRUE if the synchronized value is set
     *         FALSE if they synchronized value is unset
     */
    bool getSynchronized() const;

    /**
     * Set the visibility
     * @param[in] newVisibility set this object visible (true) or invisible (false)
     * @return TRUE if the new visiblity value is not equal to the current visibility value
     *         FALSE if they are equal
     */
    virtual bool setVisibility(bool newVisibility);

    bool getVisibility() const;

    /**
     * @brief Get external ID for graphical object
     * @return external id of graphical object
     */
    virtual unsigned int getID();

    /**
     * Assign custom shader for rendering
     *
     * @param[in] s Custom shader. If NULL, default shader will be used.
     * @return TRUE if the new custom shader is different from the current custom shader
     *         FALSE if they are same
     */
    bool setShader(Shader* s);

    /**
     * @brief get the currently assigned custom shader object
     * @return currently assigned custom shader object
     */
    Shader* getShader();

    /**
     * @brief add a client application to be notified on property changes of this graphical object.
     * \param[in] client handle to connected client that wants to receive notifications on changes of this object
     */
    void addNotification(t_ilm_client_handle client);

    /**
     * @brief remove a client application from the notification list on property changes of this graphical object.
     * \param[in] client handle to connected client that does not want to receive notifications on changes of this object any longer
     */
    void removeNotification(t_ilm_client_handle client);

    /**
     * @brief get list of client that registered to a notification for this object
     */
    ApplicationReferenceList& getNotificationClients();

    /**
     * @brief get process id of process that created this object
     */
    int getCreatorPid();


public:
    static const unsigned int INVALID_ID;
    ObjectType type;
    bool renderPropertyChanged;
    bool damaged;

    ///     Pointer to currently assigned shader. If NULL, a default shader will be used.
    Shader* shader;
    double opacity;
    bool visibility;
    bool synchronized;
    bool chromaKeyEnabled;
    unsigned char chromaKeyRed;
    unsigned char chromaKeyGreen;
    unsigned char chromaKeyBlue;

protected:
    unsigned int graphicInternalId;
    unsigned int graphicExternalId;
    ApplicationReferenceList applicationList;

private:
    static unsigned int nextGraphicId[TypeMax];
    int createdByPid;
};

inline GraphicalObject::GraphicalObject(ObjectType type, double opacity, bool visibility, int creatorPid)
: type(type)
, renderPropertyChanged(false)
, damaged(false)
, shader(0)
, opacity(opacity)
, visibility(visibility)
, synchronized(false)
, chromaKeyEnabled(false)
, chromaKeyRed(0)
, chromaKeyGreen(0)
, chromaKeyBlue(0)
, graphicInternalId(nextGraphicId[type]++)
, createdByPid(creatorPid)
{
    graphicExternalId = graphicInternalId;
}

inline GraphicalObject::GraphicalObject(int externalId, ObjectType type, double opacity, bool visibility, int creatorPid)
: type(type)
, renderPropertyChanged(false)
, damaged(false)
, shader(0)
, opacity(opacity)
, visibility(visibility)
, synchronized(false)
, chromaKeyEnabled(false)
, chromaKeyRed(0)
, chromaKeyGreen(0)
, chromaKeyBlue(0)
, graphicInternalId(nextGraphicId[type]++)
, graphicExternalId(externalId)
, createdByPid(creatorPid)
{
}

inline bool GraphicalObject::setOpacity(double newOpacity)
{
    if (opacity != newOpacity)
    {
        opacity = newOpacity;
        renderPropertyChanged = true;
        return true;
    }
    return false;
}

inline double GraphicalObject::getOpacity() const
{
    return opacity;
}

inline bool GraphicalObject::setVisibility(bool newVisibility)
{
    if (visibility != newVisibility)
    {
        visibility = newVisibility;
        renderPropertyChanged = true;
        return true;
    }
    return false;
}

inline bool GraphicalObject::setSynchronized(bool newSynchnronized)
{
    if (synchronized != newSynchnronized)
    {
        synchronized = newSynchnronized;
        return true;
    }
    return synchronized;
}

inline bool GraphicalObject::getSynchronized() const
{
    return synchronized;
}


inline bool GraphicalObject::getVisibility() const
{
    return visibility;
}

inline bool GraphicalObject::setChromaKeyEnabled(bool newEnabled)
{
    if (chromaKeyEnabled != newEnabled)
    {
        chromaKeyEnabled = newEnabled;
        renderPropertyChanged = true;
        return true;
    }
    return false;
}

inline bool GraphicalObject::getChromaKeyEnabled() const
{
    return chromaKeyEnabled;
}

inline bool GraphicalObject::setChromaKey(unsigned char newRed, unsigned char newGreen, unsigned char newBlue)
{
    if ((chromaKeyRed != newRed) || (chromaKeyGreen != newGreen) || (chromaKeyBlue != newBlue))
    {
        chromaKeyRed = newRed;
        chromaKeyGreen = newGreen;
        chromaKeyBlue = newBlue;
        renderPropertyChanged = true;
        return true;
    }
    return false;
}

inline void GraphicalObject::getChromaKey(unsigned char& red, unsigned char& green, unsigned char& blue) const
{
    red = chromaKeyRed;
    green = chromaKeyGreen;
    blue = chromaKeyBlue;
}

inline unsigned int GraphicalObject::getID()
{
    return graphicExternalId;
}

inline bool GraphicalObject::setShader(Shader* s)
{
    if (shader != s)
    {
        shader = s;
        renderPropertyChanged = true;
        return true;
    }
    return false;
}

inline Shader* GraphicalObject::getShader()
{
    return shader;
}

inline void GraphicalObject::addNotification(t_ilm_client_handle client)
{
    applicationList.push_back(client);
}

inline void GraphicalObject::removeNotification(t_ilm_client_handle client)
{
    applicationList.remove(client);
}

inline ApplicationReferenceList& GraphicalObject::getNotificationClients()
{
    return applicationList;
}

inline int GraphicalObject::getCreatorPid()
{
    return createdByPid;
}

#endif /* _GRAPHICALOBJECT_H_ */