summaryrefslogtreecommitdiffstats
path: root/src/Authoring/Studio/Palettes/Timeline/ColorControl.cpp
blob: 71d1c392adb0f104392820ff5ef1694bed2dc993 (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
/****************************************************************************
**
** Copyright (C) 2016 NVIDIA Corporation.
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt 3D Studio.
**
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "stdafx.h"

#include "CColor.h"
#include "ColorControl.h"
#include "CoreUtils.h"
#include "BaseStateRow.h"
#include "Renderer.h"
#include "StudioPreferences.h"
#include "HotKeys.h"
#include "Dispatch.h"
#include "ResourceCache.h"
#include "Bindings/ITimelineItem.h"

//==============================================================================
/**
 *	The control (of each row) to the left of the tree view, where it indicates if there are
 *actions associated with this row.
 */
CColorControl::CColorControl(CBaseStateRow *inRow)
    : m_Shaded(true)
    , m_Selected(false)
    , m_HasAction(false)
    , m_HasMasterAction(false)
    , m_ChildHasAction(false)
    , m_ChildHasMasterAction(false)
    , m_ComponentHasAction(false)
    , m_ComponentHasMasterAction(false)
{
    m_ParentRow = inRow;
    m_BackgroundColor = m_ParentRow->GetTimebarBackgroundColor(m_ParentRow->GetObjectType());

    UpdateIconStatus();
}

CColorControl::~CColorControl()
{
}

void CColorControl::SetShaded(bool inIsShaded)
{
    m_Shaded = inIsShaded;
}

//==============================================================================
/**
 *	Draw
 *
 *  draws this object
 *
 *	@param	inRenderer	 a renderer object
 */
void CColorControl::Draw(CRenderer *inRenderer)
{
    CRct theRect(GetSize());

    inRenderer->FillSolidRect(theRect, m_BackgroundColor);
    //
    inRenderer->PushPen(CStudioPreferences::GetPropertyFloorColor());
    // bottom
    inRenderer->MoveTo(CPt(1, theRect.size.y - 1));
    inRenderer->LineTo(CPt(theRect.size.x - 1, theRect.size.y - 1));
    // left
    inRenderer->MoveTo(CPt(0, 1));
    inRenderer->LineTo(CPt(0, theRect.size.y - 1));
    // right
    inRenderer->MoveTo(CPt(theRect.size.x - 1, 1));
    inRenderer->LineTo(CPt(theRect.size.x - 1, theRect.size.y - 1));
    //
    inRenderer->PopPen();

    CPt thePos(0, 0);
    if (m_HasMasterAction) {
        if (m_ActionImages[IMAGETYPE_MASTERACTION].isNull())
            m_ActionImages[IMAGETYPE_MASTERACTION] =
                CResourceCache::GetInstance()->GetBitmap("Action-MasterAction.png");

        inRenderer->DrawBitmap(thePos, m_ActionImages[IMAGETYPE_MASTERACTION]);
    } else if (m_HasAction) {
        if (m_ActionImages[IMAGETYPE_ACTION].isNull())
            m_ActionImages[IMAGETYPE_ACTION] =
                CResourceCache::GetInstance()->GetBitmap("Action-Action.png");

        inRenderer->DrawBitmap(thePos, m_ActionImages[IMAGETYPE_ACTION]);
    }
    if (m_ChildHasMasterAction) {
        if (m_ActionImages[IMAGETYPE_CHILDMASTERACTION].isNull())
            m_ActionImages[IMAGETYPE_CHILDMASTERACTION] =
                CResourceCache::GetInstance()->GetBitmap("Action-ChildMasterAction.png");

        inRenderer->DrawBitmap(thePos, m_ActionImages[IMAGETYPE_CHILDMASTERACTION]);
    } else if (m_ChildHasAction) {
        if (m_ActionImages[IMAGETYPE_CHILDACTION].isNull())
            m_ActionImages[IMAGETYPE_CHILDACTION] =
                CResourceCache::GetInstance()->GetBitmap("Action-ChildAction.png");

        inRenderer->DrawBitmap(thePos, m_ActionImages[IMAGETYPE_CHILDACTION]);
    }
    if (m_ComponentHasMasterAction) {
        if (m_ActionImages[IMAGETYPE_COMPONENTMASTERACTION].isNull())
            m_ActionImages[IMAGETYPE_COMPONENTMASTERACTION] =
                CResourceCache::GetInstance()->GetBitmap("Action-ComponentMasterAction.png");

        inRenderer->DrawBitmap(thePos, m_ActionImages[IMAGETYPE_COMPONENTMASTERACTION]);
    } else if (m_ComponentHasAction) {
        if (m_ActionImages[IMAGETYPE_COMPONENTACTION].isNull())
            m_ActionImages[IMAGETYPE_COMPONENTACTION] =
                CResourceCache::GetInstance()->GetBitmap("Action-ComponentAction.png");

        inRenderer->DrawBitmap(thePos, m_ActionImages[IMAGETYPE_COMPONENTACTION]);
    }

    // the old code with selection

    // inRenderer->DrawGradientBitmap( theRect, m_ParentRow->GetAsset( )->GetTimebarColor( ), false
    // );
    // if ( m_Selected )
    //{
    //	long theXSize = theRect.size.x / 2;
    //	long theYSize = theRect.size.y / 2;
    //	inRenderer->FillSolidRect( CRct( CPt( theXSize / 2, theYSize / 2 ), CPt( theXSize, theYSize)
    //), CalculateSelectedColor( m_ParentRow->GetAsset( )->GetTimebarColor( ) ) );
    //}

    // if this is selected then do something special
    // if ( m_Shaded )
    //{
    //	// This is used for the left line of the color control
    //	CColor theNonGradiantHighlight = m_ParentRow->GetAsset( )->GetTimebarColor( );
    //	float theLuminance = theNonGradiantHighlight.GetLuminance( );
    //	theLuminance = theLuminance * (float)1.15;
    //	if ( theLuminance > 1.0 )
    //	{
    //		theLuminance = (float)1.0;
    //	}
    //
    //	// Highlight on left edge
    //	theNonGradiantHighlight.SetLuminance( theLuminance );
    //	inRenderer->PushPen( theNonGradiantHighlight );
    //	inRenderer->MoveTo( CPt( 1, 0 ) );
    //	inRenderer->LineTo( CPt( 1, theRect.size.y - 1 ) );
    //	inRenderer->PopPen( );

    //	// Dark line on far left edge
    //	inRenderer->PushPen( CStudioPreferences::GetRowTopColor( ) );
    //	inRenderer->MoveTo( CPt( 0, 0 ) );
    //	inRenderer->LineTo( CPt( 0, theRect.size.y - 1 ) );
    //	inRenderer->PopPen( );
    //
    //	inRenderer->PushPen( CStudioPreferences::GetRowTopColor( ) );
    //	inRenderer->MoveTo( CPt( 0,theRect.size.y - 1 ) );
    //	inRenderer->LineTo( CPt( theRect.size.x, theRect.size.y - 1 ) );
    //	inRenderer->MoveTo( CPt( theRect.size.x - 1, 0 ) );
    //	inRenderer->LineTo( CPt( theRect.size.x - 1, theRect.size.y - 1 ) );
    //	inRenderer->PopPen( );
    //}

    // inRenderer->Draw3dRect( CRct( theRect.position, CPt( theRect.size.x, theRect.size.y + 1 ) ),
    // CColor( 0, 255, 0 ), CColor( 0, 255, 0 ) );
}

//==============================================================================
/**
 *	CalculateNonGradiantHighlight
 *
 *  calculates the highlight for this color
 *
 *	@param	inColor	 color to multiply
 */
CColor CColorControl::CalculateNonGradiantHighlight(CColor inColor)
{
    double theNonGradiantHighlightR = inColor.GetRed() * 1.15;
    double theNonGradiantHighlightG = inColor.GetGreen() * 1.15;
    double theNonGradiantHighlightB = inColor.GetBlue() * 1.15;
    if (theNonGradiantHighlightR > 255) {
        theNonGradiantHighlightR = 255;
    }
    if (theNonGradiantHighlightG > 255) {
        theNonGradiantHighlightG = 255;
    }
    if (theNonGradiantHighlightB > 255) {
        theNonGradiantHighlightB = 255;
    }
    return CColor(::dtol(theNonGradiantHighlightR), ::dtol(theNonGradiantHighlightG),
                  ::dtol(theNonGradiantHighlightB));
}

//==============================================================================
/**
 *	CalculateNonGradiantHighlight
 *
 *  calculates the highlight for this color
 *
 *	@param	inColor	 color to multiply
 */
CColor CColorControl::CalculateSelectedColor(CColor inColor)
{
    double theNonGradiantHighlightR = inColor.GetRed() * 0.65;
    double theNonGradiantHighlightG = inColor.GetGreen() * 0.65;
    double theNonGradiantHighlightB = inColor.GetBlue() * 0.65;
    if (theNonGradiantHighlightR > 255) {
        theNonGradiantHighlightR = 255;
    }
    if (theNonGradiantHighlightG > 255) {
        theNonGradiantHighlightG = 255;
    }
    if (theNonGradiantHighlightB > 255) {
        theNonGradiantHighlightB = 255;
    }
    return CColor(::dtol(theNonGradiantHighlightR), ::dtol(theNonGradiantHighlightG),
                  ::dtol(theNonGradiantHighlightB));
}

//==============================================================================
/**
 *	Handles the OnMouseDownEvent
 */
bool CColorControl::OnMouseDown(CPt inPoint, Qt::KeyboardModifiers inFlags)
{
    Q_UNUSED(inPoint);
    Q_UNUSED(inFlags);
    return true;
}

//==============================================================================
/**
 * Called when this row becomes selected
 */
void CColorControl::OnSelect()
{
    m_Selected = true;
    this->Invalidate();
}

//==============================================================================
/**
 * Called when this row becomes deselected
 */
void CColorControl::OnDeselect()
{
    m_Selected = false;
    this->Invalidate();
}

//==============================================================================
/**
 *	Updates the icon used for display based on the following logic:
 * 1. Self has actions
 * 2. Descendents have actions
 * Results in 4 states.
 */
void CColorControl::UpdateIconStatus()
{
    ITimelineItem *theTimelineItem = m_ParentRow->GetTimelineItem();

    if (!theTimelineItem)
        return;

    // Master 'supersede' non-master
    m_HasMasterAction = theTimelineItem->HasAction(true);
    if (!m_HasMasterAction)
        m_HasAction = theTimelineItem->HasAction(false);

    // no descendent info if current row is expanded
    if (!m_ParentRow->IsExpanded()) {
        m_ChildHasMasterAction = theTimelineItem->ChildrenHasAction(true);
        if (!m_ChildHasMasterAction)
            m_ChildHasAction = theTimelineItem->ChildrenHasAction(false);
    } else {
        m_ChildHasMasterAction = false;
        m_ChildHasAction = false;
    }

    m_ComponentHasMasterAction = theTimelineItem->ComponentHasAction(true);
    if (!m_ComponentHasMasterAction)
        m_ComponentHasAction = theTimelineItem->ComponentHasAction(false);

    this->Invalidate();
}