summaryrefslogtreecommitdiffstats
path: root/src/Authoring/Studio/Palettes/Master/MasterControl.cpp
blob: 922b6d02e12076f0fd4fd0262da29486cd3a2484 (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
/****************************************************************************
**
** 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"

//==============================================================================
//	Includes
//==============================================================================
#include "MasterControl.h"
#include "Renderer.h"
#include "StudioPreferences.h"
#include "StudioApp.h"
#include "Doc.h"
#include "InspectorControl.h"
#include "ActionControl.h"
#include "GenericTabControl.h"

//===============================================================================
/**
 * Constructor
 * @param inStudioApp
 */
CMasterControl::CMasterControl(IMasterControlProvider *inProvider)
    : m_Provider(inProvider)
    , m_TabMenu(nullptr)
    , m_RenderDevice(nullptr)
{
    // Create the tab control
    m_TabControl = new CGenericTabControl();
    AddChild(m_TabControl);
    m_TabControl->SigTabSelected.connect(std::bind(&CMasterControl::OnTabSelected, this,
                                                   std::placeholders::_1, std::placeholders::_2));

    // Add the drop-down menu
    m_MenuButton = new CProceduralButton<CButtonControl>();
    m_MenuButton->SetUpImage("Storage-Dropdown-Normal.png");
    m_MenuButton->SetDisabledImage("Tab-Menu-Disabled.png");
    m_MenuButton->SetAbsoluteSize(m_MenuButton->GetImageSize());
    m_MenuButton->SetFillColorUp(CStudioPreferences::GetDarkBaseColor());
    m_MenuButton->SetFillColorDown(CStudioPreferences::GetDarkBaseColor());
    m_MenuButton->SetFillColorOver(CStudioPreferences::GetDarkBaseColor());
    m_MenuButton->SetFillColorDisabled(CStudioPreferences::GetDarkBaseColor());
    m_MenuButton->SetFillStyleAll(CProceduralButton<CButtonControl>::EFILLSTYLE_FLOOD);
    CProceduralButton<CButtonControl>::SBorderOptions theBorders(false, false, false, false);
    m_MenuButton->SetBorderVisibilityAll(theBorders);
    m_MenuButton->SigButtonDown.connect(std::bind(&CMasterControl::OnMenuButtonDown, this,
                                                  std::placeholders::_1));
    m_TabControl->SetTabBarSibling(m_MenuButton);
}

//===============================================================================
/**
 * Destructor
 */
CMasterControl::~CMasterControl()
{
    RemoveChild(m_TabControl);
}

//===============================================================================
/**
 * Display the context menu for this control
 */
void CMasterControl::DisplayContextMenu(CPt inPosition)
{
    ASSERT(m_Provider != nullptr);
    m_Provider->OnContextMenu(this, inPosition, m_TabMenu);
}

//=============================================================================
/**
 *	Callback when the menu button is selected
 */
void CMasterControl::AddControl(const Q3DStudio::CString &inName, long inType, CControl *inControl)
{
    inControl->SetName(inName);
    m_ControlList.insert(std::make_pair(inControl, inType));
    m_TabControl->AddTab(inName, inControl);
}

//=============================================================================
/**
 *	Callback when the menu button is selected
 */
void CMasterControl::RemoveControl(CControl *inControl)
{
    TControlMap::iterator theIterator = m_ControlList.begin();
    TControlMap::iterator theEndIterator = m_ControlList.end();
    for (; theIterator != theEndIterator; ++theIterator) {
        if (inControl == theIterator->first) {
            m_ControlList.erase(theIterator);
            break;
        }
    }

    if (m_ControlList.size())
        m_TabControl->SelectTab((long)0);

    m_TabControl->RemoveTab(inControl);
}

//=============================================================================
/**
 *	Callback when the menu button is selected
 */
void CMasterControl::SelectControl(long inIndex)
{
    m_TabControl->SelectTab(inIndex);
}

//=============================================================================
/**
 *	Callback when the menu button is selected
 */
void CMasterControl::SelectControl(CControl *inControl)
{
    m_TabControl->SelectTab(inControl);
}

//=============================================================================
/**
 *	Return the number of controls
 */
long CMasterControl::GetControlCount()
{
    return m_TabControl->GetTabCount();
}

//=============================================================================
/**
 *	Return the control for the specified type
 */
CControl *CMasterControl::FindControl(long inType)
{
    CControl *theControl = nullptr;
    TControlMap::iterator theIterator = m_ControlList.begin();
    TControlMap::iterator theEndIterator = m_ControlList.end();
    for (; theIterator != theEndIterator; ++theIterator) {
        if (inType == theIterator->second) {
            theControl = theIterator->first;
            break;
        }
    }
    return theControl;
}

//=============================================================================
/**
 *	Return the active control
 */
CControl *CMasterControl::GetActiveControl()
{
    return m_TabControl->GetSelectedTab();
}

//=============================================================================
/**
 *	Return the index of the active tab
 */
long CMasterControl::GetActiveIndex()
{
    return m_TabControl->GetSelectedTabIndex();
}

//=============================================================================
/**
 *	Return the active type
 */
long CMasterControl::GetActiveType()
{
    return m_ControlList[GetActiveControl()];
}

//=============================================================================
/**
 *	Callback when the menu button is selected
 */
void CMasterControl::OnMenuButtonDown(CControl *)
{
    CPt thePosition(GetSize().x, GetPosition().y + m_MenuButton->GetSize().y);
    DisplayContextMenu(thePosition);
}

//=============================================================================
/**
 *	Callback when a tab changes
 */
void CMasterControl::OnTabSelected(CControl *, CControl *inNewControl)
{
    // Notify the provider that the selection changed
    m_Provider->OnControlSelected(this, inNewControl, m_ControlList[inNewControl]);

    // Set the enabled state of the menu item
    m_MenuButton->SetEnabled((m_TabControl->GetTabCount() != 0));
}

//==============================================================================
//	 CControl
//==============================================================================

Q3DStudio::CString CMasterControl::GetName()
{
    CControl *theActiveControl = GetActiveControl();
    if (theActiveControl)
        return theActiveControl->GetName();
    return L"< Empty >";
}

//=============================================================================
/**
 * Fills the whole control with the base (gray) color, then other controls will
 * draw on top of that.
 * @param inRenderer renderer to draw to
 */
void CMasterControl::Draw(CRenderer *inRenderer)
{
    inRenderer->FillSolidRect(GetSize(), CStudioPreferences::GetDarkBaseColor());
}

//=============================================================================
/**
 *	Set the size of the tree control
 */
void CMasterControl::SetSize(CPt inSize)
{
    CControl::SetSize(inSize);
    m_TabControl->SetSize(inSize);
}

//=============================================================================
/**
 *	Check to see if the right mouse down occurred on the tab control
 */
bool CMasterControl::OnMouseRDown(CPt inPoint, Qt::KeyboardModifiers inFlags)
{
    if (m_TabControl->IsInTabBar(inPoint)) {
        DisplayContextMenu(inPoint);
        return true;
    }

    return CControl::OnMouseRDown(inPoint, inFlags); // not handled
}

//=============================================================================
/**
 *	Return the window handle to the master view
 */
UICRenderDevice CMasterControl::GetPlatformDevice()
{
    return m_RenderDevice;
}

//=============================================================================
/**
 *	Overriden from CControl. Since this control's parent is the CWnd, ensure
 *	that it gets the keyboard focus if this function is called.
 *	@see CControl::SetFocus
 */
void CMasterControl::GrabFocus(CControl *inControl)
{
    if (m_RenderDevice) {
        ::SetFocus(m_RenderDevice);
    }

    CControl::GrabFocus(inControl);
}