summaryrefslogtreecommitdiffstats
path: root/src/Authoring/Studio/Palettes/Timeline/ToggleToolbar.cpp
blob: 7dadde197f321f21de91f6bf82e12c49d39ef1e2 (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
/****************************************************************************
**
** Copyright (C) 2002 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$
**
****************************************************************************/

//==============================================================================
//	Prefix
//==============================================================================

#include "stdafx.h"
#include "Strings.h"
#include "StringLoader.h"

//==============================================================================
//	Includes
//==============================================================================

#include "ToggleToolbar.h"
#include "SIcon.h"
#include "Renderer.h"
#include "StudioPreferences.h"
#include "TimelineTreeLayout.h"

//=============================================================================
/**
 * Constructor
 */
CToggleToolbar::CToggleToolbar(CTimelineTreeLayout *inTreeLayout)
    : CFlowLayout(new CBlankControl(CStudioPreferences::GetTopRowColor()))
{
    m_TreeLayout = inTreeLayout;

    m_Color = CStudioPreferences::GetBaseColor();

    SetFlowDirection(FLOW_HORIZONTAL);
    SetAlignment(ALIGN_TOP, ALIGN_LEFT);
    SetLeftMargin(1);

    CProceduralButton<CToggleButton>::SBorderOptions theBorderOptions(false, true, true, true);

    m_FltrShyBtn = new CProceduralButton<CToggleButton>();
    m_FltrShyBtn->SetUpImage("Toggle-Shy.png");
    m_FltrShyBtn->SetDownImage("Toggle-Shy.png");
    m_FltrShyBtn->SetBorderVisibilityAll(theBorderOptions);
    m_FltrShyBtn->SetAbsoluteSize(m_FltrShyBtn->GetSize());
    m_FltrShyBtn->SetTooltipText(::LoadResourceString(IDS_FLTR_TOOLTIP_SHY2));
    m_FltrShyBtn->SigToggle.connect(std::bind(&CToggleToolbar::OnButtonToggled, this,
                                              std::placeholders::_1, std::placeholders::_2));
    AddChild(m_FltrShyBtn);
    m_FltrShyBtn->SetToggleState(false);

    m_FltrVisibleBtn = new CProceduralButton<CToggleButton>();
    m_FltrVisibleBtn->SetUpImage("filter-toggle-eye-up.png");
    m_FltrVisibleBtn->SetDownImage("filter-toggle-eye-down.png");
    m_FltrVisibleBtn->SetBorderVisibilityAll(theBorderOptions);
    m_FltrVisibleBtn->SetAbsoluteSize(m_FltrVisibleBtn->GetSize());
    m_FltrVisibleBtn->SetTooltipText(::LoadResourceString(IDS_FLTR_TOOLTIP_VISIBLE2));
    m_FltrVisibleBtn->SigToggle.connect(std::bind(&CToggleToolbar::OnButtonToggled, this,
                                                  std::placeholders::_1, std::placeholders::_2));
    AddChild(m_FltrVisibleBtn);
    m_FltrVisibleBtn->SetToggleState(false);

    m_FltrLockBtn = new CProceduralButton<CToggleButton>();
    m_FltrLockBtn->SetUpImage("Toggle-Lock.png");
    m_FltrLockBtn->SetDownImage("Toggle-Lock.png");
    m_FltrLockBtn->SetBorderVisibilityAll(theBorderOptions);
    m_FltrLockBtn->SetAbsoluteSize(m_FltrLockBtn->GetSize());
    m_FltrLockBtn->SetTooltipText(::LoadResourceString(IDS_FLTR_TOOLTIP_LOCK2));
    m_FltrLockBtn->SigToggle.connect(std::bind(&CToggleToolbar::OnButtonToggled, this,
                                               std::placeholders::_1, std::placeholders::_2));
    AddChild(m_FltrLockBtn);
    m_FltrLockBtn->SetToggleState(false);
}

//=============================================================================
/**
 * Destructor
 */
CToggleToolbar::~CToggleToolbar()
{
    delete m_FltrShyBtn;
    delete m_FltrVisibleBtn;
    delete m_FltrLockBtn;
}

//=============================================================================
/**
 * Fills in the background color and highlighting for this control.
 */
void CToggleToolbar::Draw(CRenderer *inRenderer)
{
    CRct theRect(0, 0, GetSize().x, GetSize().y - 1);
    inRenderer->FillSolidRect(theRect, m_Color);
    CFlowLayout::Draw(inRenderer);
    inRenderer->Draw3dRect(theRect, CStudioPreferences::GetButtonShadowColor(),
                           CStudioPreferences::GetButtonShadowColor());

    // Draw the highlight at the bottom
    inRenderer->PushPen(CStudioPreferences::GetButtonHighlightColor());
    inRenderer->MoveTo(CPt(0, theRect.size.y));
    inRenderer->LineTo(CPt(theRect.size.x - 1, theRect.size.y));
    inRenderer->PopPen();

    // Draw the one pixel on the end of the highlight that has to be dark
    // Apparently there's some problems trying to draw one pixel, so clip the excess
    inRenderer->PushClippingRect(QRect(0, 0, GetSize().x, GetSize().y));
    inRenderer->PushPen(CStudioPreferences::GetButtonShadowColor());
    inRenderer->MoveTo(CPt(theRect.size.x, theRect.size.y));
    inRenderer->LineTo(CPt(theRect.size.x - 1, theRect.size.y));
    inRenderer->PopPen();
    inRenderer->PopClippingRect();
}

//=============================================================================
/**
 * Handles turning a filter on or off in response to a button being pressed.
 * @param inButton button that generated the event
 * @param inState new state of the button after being toggled
 */
void CToggleToolbar::OnButtonToggled(CToggleButton *inButton, CButtonControl::EButtonState inState)
{
    bool theFilterNeedsApplied = (inState == CButtonControl::EBUTTONSTATE_UP);

    if (inButton == m_FltrShyBtn)
        FilterShy(theFilterNeedsApplied);
    else if (inButton == m_FltrVisibleBtn)
        FilterVisible(theFilterNeedsApplied);
    else if (inButton == m_FltrLockBtn)
        FilterLocked(theFilterNeedsApplied);
}

//=============================================================================
/**
 * Turns filtering on and off for shy objects.
 * @param inFilter true to filter shy objects out of the timeline, false to show
 * shy objects in the timeline.
 */
void CToggleToolbar::FilterShy(bool inFilter)
{
    if (inFilter)
        m_FltrShyBtn->SetTooltipText(::LoadResourceString(IDS_FLTR_TOOLTIP_SHY2));
    else
        m_FltrShyBtn->SetTooltipText(::LoadResourceString(IDS_FLTR_TOOLTIP_SHY1));

    m_TreeLayout->GetFilter()->SetShy(inFilter);
    m_TreeLayout->Filter();
}

//=============================================================================
/**
 * Turns filtering on and off for visible objects.
 * @param inFilter true to filter visible objects out of the timeline, false to show
 * visible objects in the timeline.
 */
void CToggleToolbar::FilterVisible(bool inFilter)
{
    if (inFilter)
        m_FltrVisibleBtn->SetTooltipText(::LoadResourceString(IDS_FLTR_TOOLTIP_VISIBLE2));
    else
        m_FltrVisibleBtn->SetTooltipText(::LoadResourceString(IDS_FLTR_TOOLTIP_VISIBLE1));

    m_TreeLayout->GetFilter()->SetVisible(inFilter);
    m_TreeLayout->Filter();
}

//=============================================================================
/**
 * Turns filtering on and off for locked objects.
 * @param inFilter true to filter locked objects out of the timeline, false to show
 * locked objects in the timeline.
 */
void CToggleToolbar::FilterLocked(bool inFilter)
{
    if (inFilter)
        m_FltrLockBtn->SetTooltipText(::LoadResourceString(IDS_FLTR_TOOLTIP_LOCK2));
    else
        m_FltrLockBtn->SetTooltipText(::LoadResourceString(IDS_FLTR_TOOLTIP_LOCK1));

    m_TreeLayout->GetFilter()->SetLocked(inFilter);
    m_TreeLayout->Filter();
}