MezzanineEngine
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
Mezzanine
src
UI
tabset.cpp
1
// © Copyright 2010 - 2014 BlackTopp Studios Inc.
2
/* This file is part of The Mezzanine Engine.
3
4
The Mezzanine Engine is free software: you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation, either version 3 of the License, or
7
(at your option) any later version.
8
9
The Mezzanine Engine is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
13
14
You should have received a copy of the GNU General Public License
15
along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16
*/
17
/* The original authors have included a copy of the license specified above in the
18
'Docs' folder. See 'gpl.txt'
19
*/
20
/* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21
Build professional software and charge for their product.
22
23
However there are some practical restrictions, so if your project involves
24
any of the following you should contact us and we will try to work something
25
out:
26
- DRM or Copy Protection of any kind(except Copyrights)
27
- Software Patents You Do Not Wish to Freely License
28
- Any Kind of Linking to Non-GPL licensed Works
29
- Are Currently In Violation of Another Copyright Holder's GPL License
30
- If You want to change our code and not add a few hundred MB of stuff to
31
your distribution
32
33
These and other limitations could cause serious legal problems if you ignore
34
them, so it is best to simply contact us or the Free Software Foundation, if
35
you have any questions.
36
37
Joseph Toppi - toppij@gmail.com
38
John Blackwood - makoenergy02@gmail.com
39
*/
40
#ifndef _uitabset_cpp
41
#define _uitabset_cpp
42
43
#include "UI/tabset.h"
44
#include "UI/screen.h"
45
#include "UI/uimanager.h"
46
#include "UI/button.h"
47
#include "Input/inputmanager.h"
48
#include "Input/mouse.h"
49
50
namespace
Mezzanine
51
{
52
namespace
UI
53
{
54
const
String
TabSet::TypeName
=
"TabSet"
;
55
56
TabSet::TabSet
(
Screen
* Parent) :
57
StackedContainer
(Parent)
58
{
59
60
}
61
62
TabSet::TabSet
(
const
String
& RendName,
Screen
* Parent) :
63
StackedContainer
(RendName,Parent)
64
{
65
66
}
67
68
TabSet::TabSet
(
const
String
& RendName,
const
UnifiedRect
& RendRect,
Screen
* Parent) :
69
StackedContainer
(RendName,RendRect,Parent)
70
{
71
72
}
73
74
TabSet::TabSet
(
const
XML::Node
& XMLNode,
Screen
* Parent) :
75
StackedContainer
(Parent)
76
{
77
78
}
79
80
TabSet::~TabSet
()
81
{
82
83
}
84
85
///////////////////////////////////////////////////////////////////////////////
86
// Utility Methods
87
88
///////////////////////////////////////////////////////////////////////////////
89
// Visibility and Priority Methods
90
91
///////////////////////////////////////////////////////////////////////////////
92
// TabSet Properties
93
94
///////////////////////////////////////////////////////////////////////////////
95
// TabSet Configuration
96
97
///////////////////////////////////////////////////////////////////////////////
98
// Serialization
99
100
///////////////////////////////////////////////////////////////////////////////
101
// Internal Event Methods
102
103
///////////////////////////////////////////////////////////////////////////////
104
// Internal Methods
105
106
107
/*TabSet::TabSet(const String& name, const Rect& SetRect, Screen* parent) :
108
Widget(name,parent),
109
SetsAdded(0),
110
VisibleSet(NULL)
111
{
112
Type = Widget::W_TabSet;
113
TemplateSetRect.Relative = false;
114
const Vector2& WinDim = ParentScreen->GetViewportDimensions();
115
if(SetRect.Relative)
116
{
117
RelPosition = SetRect.Position;
118
RelSize = SetRect.Size;
119
TemplateSetRect.Position = SetRect.Position * WinDim;
120
TemplateSetRect.Size = SetRect.Size * WinDim;
121
}else{
122
RelPosition = SetRect.Position / WinDim;
123
RelSize = SetRect.Size / WinDim;
124
TemplateSetRect = SetRect;
125
}
126
}
127
128
TabSet::~TabSet()
129
{
130
DestroyAllRenderableSets();
131
}
132
133
void TabSet::UpdateImpl(bool Force)
134
{
135
Input::ButtonState State = InputManager::GetSingletonPtr()->GetSystemMouse()->GetButtonState(1);
136
if( HoveredSubWidget && (Widget::W_Button == HoveredSubWidget->GetType()) )
137
{
138
if(Input::BUTTON_PRESSING == State)
139
{
140
RenderableSetData* ClickedSet = NULL;
141
for( std::vector<RenderableSetData*>::iterator it = Sets.begin() ; it != Sets.end() ; it++ )
142
{
143
if(HoveredSubWidget == (*it)->Accessor)
144
ClickedSet = (*it);
145
}
146
if(!ClickedSet)
147
return;
148
if(VisibleSet)
149
VisibleSet->Collection->Hide();
150
VisibleSet = ClickedSet;
151
VisibleSet->Collection->Show();
152
}
153
}
154
}
155
156
void TabSet::SetVisibleImpl(bool visible)
157
{
158
for( std::vector<RenderableSetData*>::iterator it = Sets.begin() ; it != Sets.end() ; it++ )
159
(*it)->Accessor->SetVisible(visible);
160
if(VisibleSet)
161
VisibleSet->Collection->SetVisible(visible);
162
}
163
164
bool TabSet::CheckMouseHoverImpl()
165
{
166
for( std::vector<RenderableSetData*>::iterator it = Sets.begin() ; it != Sets.end() ; it++ )
167
{
168
if((*it)->Accessor->CheckMouseHover())
169
{
170
HoveredSubWidget = (*it)->Accessor;
171
return true;
172
}
173
}
174
if(VisibleSet->Collection->CheckMouseHover())
175
{
176
HoveredSubWidget = VisibleSet->Collection;
177
return true;
178
}
179
return false;
180
}
181
182
RenderableSetData* TabSet::CreateRenderableSet(const String& Name, const Rect& AccessorRect, const Real& GlyphHeight, const String& Text)
183
{
184
const Vector2& WinDim = ParentScreen->GetViewportDimensions();
185
186
Whole ActHeight = (Whole)(GlyphHeight * WinDim.Y);
187
std::pair<Whole,Real> GlyphInfo = Manager->SuggestGlyphIndex(ActHeight,ParentScreen->GetPrimaryAtlas());
188
Button* NewAccessor = ParentScreen->CreateButton(Name+"Access",AccessorRect,GlyphInfo.first,Text);
189
if(1 != GlyphInfo.second)
190
NewAccessor->GetClickable()->SetTextScale(GlyphInfo.second);
191
NewAccessor->SetVisible(Visible);
192
RenderableCollection* NewCollection = ParentScreen->CreateEnclosedRenderableContainerWidget(Name+"Set",TemplateSetRect);
193
NewCollection->SetVisible(Visible);
194
195
RenderableSetData* NewSetData = new RenderableSetData(Name,NewAccessor,NewCollection);
196
if(0 == Sets.size()) VisibleSet = NewSetData;
197
else NewSetData->Collection->Hide();
198
Sets.push_back(NewSetData);
199
AddSubRenderable(SetsAdded,NewSetData->Collection);
200
AddSubRenderable(SetsAdded+1,NewSetData->Accessor);
201
SetsAdded+=2;
202
return NewSetData;
203
}
204
205
RenderableSetData* TabSet::GetRenderableSetData(const Whole& Index)
206
{
207
return Sets.at(Index);
208
}
209
210
RenderableSetData* TabSet::GetRenderableSetData(const String& SetDataName)
211
{
212
for( std::vector<RenderableSetData*>::iterator it = Sets.begin() ; it != Sets.end() ; it++ )
213
{
214
if(SetDataName == (*it)->Name)
215
return (*it);
216
}
217
return NULL;
218
}
219
220
RenderableCollection* TabSet::GetRenderableCollection(const Whole& Index)
221
{
222
return Sets.at(Index)->Collection;
223
}
224
225
RenderableCollection* TabSet::GetRenderableCollection(const String& SetDataName)
226
{
227
RenderableSetData* SetData = GetRenderableSetData(SetDataName);
228
if(SetData) return SetData->Collection;
229
else return NULL;
230
}
231
232
RenderableCollection* TabSet::GetRenderableCollection(Button* Accessor)
233
{
234
for( std::vector<RenderableSetData*>::iterator it = Sets.begin() ; it != Sets.end() ; it++ )
235
{
236
if(Accessor == (*it)->Accessor)
237
return (*it)->Collection;
238
}
239
return NULL;
240
}
241
242
Button* TabSet::GetAccessor(const Whole& Index)
243
{
244
return Sets.at(Index)->Accessor;
245
}
246
247
Button* TabSet::GetAccessor(const String& SetDataName)
248
{
249
RenderableSetData* SetData = GetRenderableSetData(SetDataName);
250
if(SetData) return SetData->Accessor;
251
else return NULL;
252
}
253
254
Button* TabSet::GetAccessor(RenderableCollection* Collection)
255
{
256
for( std::vector<RenderableSetData*>::iterator it = Sets.begin() ; it != Sets.end() ; it++ )
257
{
258
if(Collection == (*it)->Collection)
259
return (*it)->Accessor;
260
}
261
return NULL;
262
}
263
264
Whole TabSet::GetNumRenderableSets()
265
{
266
return Sets.size();
267
}
268
269
void TabSet::DestroyRenderableSet(RenderableSetData* ToBeDestroyed)
270
{
271
for( std::vector<RenderableSetData*>::iterator it = Sets.begin() ; it != Sets.end() ; it++ )
272
{
273
if(ToBeDestroyed == (*it))
274
{
275
if(ToBeDestroyed == VisibleSet)
276
VisibleSet = NULL;
277
Sets.erase(it);
278
break;
279
}
280
}
281
for( RenderableIterator it = SubRenderables.begin() ; it != SubRenderables.end() ; ++it )
282
{
283
if(ToBeDestroyed->Collection == (*it))
284
{
285
SubRenderables.erase(it);
286
break;
287
}
288
}
289
delete ToBeDestroyed;
290
}
291
292
void TabSet::DestroyAllRenderableSets()
293
{
294
for( std::vector<RenderableSetData*>::iterator it = Sets.begin() ; it != Sets.end() ; it++ )
295
{
296
RenderableSetData* CurrSet = (*it);
297
ParentScreen->DestroyWidget(CurrSet->Accessor);
298
ParentScreen->DestroyWidget(CurrSet->Collection);
299
delete CurrSet;
300
}
301
Sets.clear();
302
HoveredSubWidget = NULL;
303
VisibleSet = NULL;
304
SubRenderables.clear();
305
}//*/
306
}
//UI
307
}
//Mezzanine
308
309
#endif
Generated on Mon Jan 6 2014 20:58:06 for MezzanineEngine by
1.8.4