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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733 | #include "fsIGuiComponent.h"
#include <fsCore/fsIFile.h>
#include <fsCore/fsIResourceNamePathAdjuster.h>
#include <fsCore/src/fsCResourceName.h>
#include <fsCore/src/fsCVariableTable.h>
#include <fsRenderer/src/components/fsCSpriteComponent.h>
#include <fsRenderer/src/components/fsCTextSpriteComponent.h>
#include <fsRenderer/src/fsCBrushManager.h>
#include "../../../fsIInputManager.h"
#include "../../../src/fsCComponentFactory.h"
#include "../../../src/fsCSoftwareCursor.h"
#include "../../../src/fsCEntityFactory.h"
#include "../../../src/fsCAppCoreMain.h"
#include "../transformation/fsITransformationComponent.h"
#include "elements/fsCModalGuiComponent.h"
#include "src/components/fsCNameComponent.h"
fsStr* fsIGuiComponent::mGuiLayoutFileName = nullptr;
std::map<fsStr, fsStr> fsIGuiComponent::mStyles;
std::vector<fsStr> fsIGuiComponent::mStylesIncluded;
void fsIGuiComponent::layoutFileProcess()
{
if (!mGuiLayoutFileName)
{
return;
}
auto layoutFilename = *mGuiLayoutFileName;
layoutFilename.erase(layoutFilename.rfind(fsIResourceNamePathAdjuster::mPathSeparator) + 1);
layoutFilename += "coords.txt";
if (!fsIFile::fileExistsGet(fsCResourceName(layoutFilename, fsCResourceName::eRES_LOCATION_ASSETS)))
{
return;
}
fsStr coordsFileData = fsIFile::strGetFromFile(fsCResourceName(layoutFilename, fsCResourceName::eRES_LOCATION_ASSETS));
fsStr entName = coordsFileData.chomp(",");
std::map<fsStr, fsPoint> coords;
while (!entName.emptyGet())
{
if (entName.find(".") != fsStr::npos)
{
entName.erase(entName.find("."));
}
#if defined fsDownCaseFilename
entName.downcase();
#endif
fsPoint entPos{coordsFileData.chomp(",").toS32(), coordsFileData.chomp("\n").toS32()};
coords.insert(std::pair<fsStr, fsPoint>(entName, entPos));
entName = coordsFileData.chomp(",");
}
std::for_each(std::begin(coords), std::end(coords),
[&](auto slot)
{
entName = slot.first;
parentGet()->forAllChildren(
[&](fsCEntity* const ent) -> void
{
if (auto* const comp = ent->firstComponentOfFamilyType<fsCSpriteComponent>())
{
auto n = fsCBrushManager::instanceGet()->brushNameGet(comp->brushGet().get());
if (fsCBrushManager::instanceGet()->brushNameGet(comp->brushGet().get()).find(entName) != fsStr::npos)
{
ent->posSet(slot.second);
}
}
});
});
}
void fsIGuiComponent::listenerComponentsRegister(fsCEntity* const pRoot) const
{
auto e1 = pRoot->childEntitiesWithComponentsOfFamilyType<fsIMessageListener>();
// reverse order so the modal component in the root gui component get's registered first, behind all the buttons etc.
std::for_each(std::rbegin(e1), std::rend(e1), [](fsCEntity* ent){ent->listenersRegister();});
}
void fsIGuiComponent::listenerComponentsDeRegister(fsCEntity* const pRoot) const
{
auto e1 = pRoot->childEntitiesWithComponentsOfFamilyType<fsIMessageListener>();
std::for_each(std::begin(e1), std::end(e1), [](fsCEntity* ent){ent->listenersDeRegister();});
}
void fsIGuiComponent::flush()
{
mStyles.clear();
mStylesIncluded.clear();
}
fsBool fsIGuiComponent::commandProcess(const fsStr& pCommand, fsStr& pCommands, std::map<fsStr, fsStr>& pStyles,
fsBool pNewGrammarMode)
{
if ("include" == pCommand)
{
if (fileContentsInclude(pCommands))
{
return true;
}
fsStr filename = pCommands.chunk();
fsAssert(0, "Failed to include %s file\n", filename.utf8Get())
}
else if ("style" == pCommand)
{
styleDefinitionAdd(pCommands, pStyles);
return true;
}
else if (pNewGrammarMode && "use" == pCommand)
{
// Explicit alternative to the legacy bare-identifier-if-recognised-
// style heuristic below - same splice (including the inline-override
// merge for `use NAME { ... }`), just an unambiguous way to say
// "this token is a style reference" instead of relying on whether it
// happens to match a defined style name.
const fsStr styleName = pCommands.chunk();
if (!styleDefinitionDecodeAndInsertIntoCommands(styleName, pCommands, pStyles))
{
fsAssert(0, "use %s: no such style defined in %s\n", styleName.utf8Get(),
mGuiLayoutFileName->utf8Get())
}
return true;
}
else if (styleDefinitionDecodeAndInsertIntoCommands(pCommand, pCommands, pStyles))
{
return true;
}
return false;
}
void fsIGuiComponent::unknownCommandProcess(const fsStr& pCommand, fsStr& pCommands)
{
if (mGuiLayoutFileName)
{
fsAssert(0, "Unknown command %s in %s layout file\n", pCommand.utf8Get(), mGuiLayoutFileName->utf8Get())
}
pCommands.leadingWhitespaceTrim();
if ('{' == pCommands[0])
{
// pCommands.chomp("}");
fsS32 numBraces = 1;
fsS32 i = 1;
while (numBraces > 0)
{
const fsChar currChar = pCommands[i++];
if ('{' == currChar)
{
++numBraces;
}
else if ('}' == currChar)
{
--numBraces;
}
}
pCommands.erase(0, i);
}
pCommands.leadingWhitespaceTrim();
}
fsBool fsIGuiComponent::newGrammarFileNameResolve(const fsStr& pLegacyFileName, fsStr& pOutResolvedFileName)
{
fsStr guiFileName = pLegacyFileName;
const fsStr::sizeT extPos = guiFileName.rfind(".");
if (fsStr::npos != extPos)
{
guiFileName.erase(extPos);
}
guiFileName += ".gui";
if (fsIFile::fileExistsGet(fsCResourceName(guiFileName, fsCResourceName::eRES_LOCATION_ASSETS)))
{
pOutResolvedFileName = guiFileName;
return true;
}
pOutResolvedFileName = pLegacyFileName;
return false;
}
fsCEntity* fsIGuiComponent::guiCreateFromFile(const fsCResourceName& pGuiLayoutFileName,
fsCEntity* pParent/* = nullptr*/, fsBool pModal/* = true */)
{
fsStr resolvedFileName;
const fsBool newGrammarMode = newGrammarFileNameResolve(pGuiLayoutFileName.nameGet(), resolvedFileName);
const fsCResourceName resolvedResource(resolvedFileName, pGuiLayoutFileName.locationGet());
if (!mGuiLayoutFileName)
{
mGuiLayoutFileName = new fsStr(resolvedFileName);
}
fsStr guiCommands = fsIFile::strGetFromFile(resolvedResource);
guiCommands.leadingWhitespaceTrim();
return guiCreateFromCommands(guiCommands, pParent, pModal, newGrammarMode);
}
fsCEntity* fsIGuiComponent::guiCreateFromCommands(fsStr& pCommands, fsCEntity* pParent/* = nullptr*/,
fsBool pModal/* = true */, fsBool pNewGrammarMode/* = false */)
{
const fsCGuiParseTree tree = parseToTree(pCommands, pNewGrammarMode);
fsCEntity* gui = constructFromTree(tree, pParent, pModal);
if (gui)
{
gui->init();
fsIInputManager::instanceGet()->priorityListenerButtonClear();
fsIInputManager::instanceGet()->messageDispatch(fsCSoftwareCursor::mResetToDefaultMsg,
fsIInputManager::mNullParam);
}
else
{
fsAssert(0, "No GUI elements created from layout file %s\n", mGuiLayoutFileName->utf8Get())
}
delete mGuiLayoutFileName;
mGuiLayoutFileName = nullptr;
return gui;
}
// New-grammar-only: read-only lexical check that `include` stays contiguous
// at the top of the file (Phase 0 corpus audit found 100% of the existing
// legacy corpus already does this, so this only ever fires on hand-authored
// .gui content going forward, never on ported legacy files).
//
// Takes pCommands *by value* deliberately - this walks a scratch copy of
// the file's own raw, pre-expansion text, called once before parseToTree's
// real loop does any include-splicing. That matters: if this were folded
// into the real loop instead, an earlier include's own spliced-in content
// (which almost always contains real statements - that's the whole point
// of including it) would itself look like "non-include content" and
// falsely flag a later, perfectly contiguous include in the outer file as
// a violation. Checking the unexpanded text sidesteps that entirely.
//
// Doesn't distinguish real component types from anything else - any token
// immediately followed by '{' has its balanced body skipped wholesale
// (mirrors unknownCommandProcess's brace-skip), since all this needs to
// know is "is the next top-level thing an include or not," not what it is.
void fsIGuiComponent::newGrammarIncludeContiguityCheck(fsStr pCommands)
{
fsBool seenNonInclude = false;
while (!pCommands.emptyGet())
{
const fsStr command = pCommands.chunk();
if (command.emptyGet())
{
break; // malformed/unexpected leading character chunk() won't consume - bail out of this best-effort scan
}
if ("include" == command)
{
fsAssert(!seenNonInclude,<--- There is an unknown macro here somewhere. Configuration is required. If fsAssert is a macro then please configure it.
"include must be contiguous at the top of the file - found a later include in %s\n",
mGuiLayoutFileName->utf8Get())
pCommands.chunk(); // skip the include's filename argument
continue;
}
seenNonInclude = true;
pCommands.leadingWhitespaceTrim();
if (!pCommands.emptyGet() && '{' == pCommands[0])
{
fsS32 numBraces = 1;
fsS32 i = 1;
while (numBraces > 0 && i <= static_cast<fsS32>(pCommands.dataSizeGet()))
{
const fsChar currChar = pCommands[i++];
if ('{' == currChar)
{
++numBraces;
}
else if ('}' == currChar)
{
--numBraces;
}
}
pCommands.erase(0, i);
}
}
}
fsCGuiParseTree fsIGuiComponent::parseToTree(fsStr& pCommands, fsBool pNewGrammarMode/* = false */)
{
if (pNewGrammarMode)
{
newGrammarIncludeContiguityCheck(pCommands);
}
fsCGuiParseTree tree;
while (!pCommands.emptyGet())
{
const fsStr command = pCommands.chunk();
const fsCUniqueId componentId(command);
if (fsCAppCoreMain::instanceGet()->componentFactoryGet()->componentTypeIsRegisteredGet(componentId))
{
tree.mRoots.push_back(guiElementParse(componentId, command, pCommands, mStyles, nullptr, pNewGrammarMode));
}
else if (!commandProcess(command, pCommands, mStyles, pNewGrammarMode))
{
unknownCommandProcess(command, pCommands);
}
}
return tree;
}
fsCEntity* fsIGuiComponent::constructFromTree(const fsCGuiParseTree& pTree, fsCEntity* pParent/* = nullptr*/,
fsBool pModal/* = true */)
{
fsCEntity* gui = nullptr;
for (const std::unique_ptr<fsCGuiParseNode>& root : pTree.mRoots)
{
gui = constructFromTree(*root, pParent, pModal);
}
return gui;
}
std::unique_ptr<fsCGuiParseNode> fsIGuiComponent::guiElementParse(const fsCUniqueId& pComponentId,
const fsStr& pComponentTypeName, fsStr& pCommands,
std::map<fsStr, fsStr>& pStyles,
fsCGuiParseNode* pParentNode,
fsBool pNewGrammarMode)
{
auto node = std::make_unique<fsCGuiParseNode>(pComponentTypeName, pParentNode);
#if !defined fsRELEASE
fsAssert( '{' == pCommands[ 0 ], "Expected a '{' after creating a new gui element in file %s\n", mGuiLayoutFileName->utf8Get() );
#endif
pCommands.erase(0, 1);
pCommands.leadingWhitespaceTrim();
fsBool finished = false;
while (!pCommands.emptyGet() && !finished)
{
// New-grammar-only: `key: value` alongside legacy `key = value`.
// chunk() (a shared primitive also used by the unrelated
// particle-emitter format, so not touched here) doesn't treat ':' as
// a terminator, so a colon key has to be recognised and extracted
// *before* calling chunk() on it - post-processing an already-over-
// consumed token loses the whitespace/newline boundary that would
// otherwise separate a colon value from the next key when nothing
// but the colon separates them (e.g. "name:value\nnextKey").
fsStr command;
const fsBool colonAssignment = pNewGrammarMode && colonKeyGet(pCommands, command);
if (!colonAssignment)
{
command = pCommands.chunk();
}
const fsCUniqueId componentId(command);
if (!colonAssignment &&
fsCAppCoreMain::instanceGet()->componentFactoryGet()->componentTypeIsRegisteredGet(componentId))
{
node->mChildren.push_back(
guiElementParse(componentId, command, pCommands, pStyles, node.get(), pNewGrammarMode));
}
else if (colonAssignment || '=' == pCommands[0])
{
variableInsertIntoTree(command, pCommands, node->mParams, pNewGrammarMode);
}
else if ("}" == command)
{
finished = true;
}
else if (!commandProcess(command, pCommands, pStyles, pNewGrammarMode))
{
unknownCommandProcess(command, pCommands);
}
pCommands.leadingWhitespaceTrim();
}
return node;
}
fsCEntity* fsIGuiComponent::constructFromTree(const fsCGuiParseNode& pNode, fsCEntity* pParent, fsBool pMakeModal)
{
const fsCUniqueId componentId(pNode.mComponentTypeName);
fsCEntity* const element = fsCEntity::mEntityFactory->entityConstructWithComponent("", componentId);
if (pMakeModal && componentId != fsCModalGuiComponent::mTypeId)
{
element->componentAdd<fsCModalGuiComponent>();
}
if (pParent)
{
pParent->childAdd(element);
}
for (const std::unique_ptr<fsCGuiParseNode>& child : pNode.mChildren)
{
constructFromTree(*child, element, false);
}
fsCVariableTable elementVars;
for (const std::pair<const fsStr, fsStr>& param : pNode.mParams)
{
elementVars.strSet(param.first, param.second);
}
auto name = elementVars.strGet("name");
if (!name.emptyGet())
{
element->nameSet(name);
element->componentAdd<fsCNameComponent>();
}
element->initialiseFromVariableTable(elementVars);
if (pParent)
{ // hack to run particle emitter finalise - gets run before emitter is created in intialiseFromVariableTable()
element->postLink();
}
return element;
}
// Scans ahead of chunk() (rather than post-processing what chunk() already
// consumed) to recognise a `key:` prefix, since chunk() doesn't treat ':' as
// a terminator and would otherwise merge the key, the colon, and (if
// nothing but the colon separates them) the value and even the following
// line's own key into a single over-consumed token.
//
// If a ':' is found before any of chunk()'s own terminators ('=', space,
// tab, newline, end of buffer), sets pOutKey to the key and erases just the
// key from pCommands, deliberately leaving the ':' itself as pCommands[0] -
// unconsumed, exactly how pCommands is left positioned at '=' for a legacy
// assignment - so variableInsertIntoTree's unconditional `erase(0, 1)` and
// subsequent chunk() correctly read the value with no information lost at
// the boundary, however tightly the source text was packed. Returns false
// (pCommands untouched) if this isn't a colon assignment, so the caller
// falls through to a normal chunk() call.
fsBool fsIGuiComponent::colonKeyGet(fsStr& pCommands, fsStr& pOutKey)
{
pCommands.leadingWhitespaceTrim();
while (!pCommands.emptyGet() && '#' == pCommands[0])
{
pCommands.chomp("\n");
pCommands.leadingWhitespaceTrim();
}
fsStr::sizeT n = 0;
while (n < pCommands.dataSizeGet() && ':' != pCommands[n] && '=' != pCommands[n] && ' ' != pCommands[n] &&
'\t' != pCommands[n] && '\n' != pCommands[n] && '\r' != pCommands[n])
{
++n;
}
if (n >= pCommands.dataSizeGet() || ':' != pCommands[n])
{
return false;
}
pOutKey.copy(pCommands.utf8Get(), 0, static_cast<fsS32>(n));
pCommands.erase(0, n);
return true;
}
// New-grammar-only typed tuple/list values: `(x, y)` and `[elem, elem, ...]`,
// self-delimiting so no key needs the transGraph-style ';'-terminator
// special case to know where its value ends - any key can use this, not
// just transGraph. Elements recurse (so a list of tuples like the
// transGraph replacement `[(0, 0.0), (250, -500.0)]` works), with plain
// numbers/identifiers/quoted strings read via the existing chunk().
//
// Deliberately flattens to the same bare comma-joined string the legacy
// wire format already uses (e.g. "0, 0.0, 250, -500.0") rather than
// preserving structure in the neutral tree - this is authoring sugar only,
// so existing consumers (e.g. fsCF32Transformation's own comma-parsing of
// a transGraph value) don't need to change at all; see the design
// discussion in GUI_GRAMMAR_MIGRATION_PLAN.md Phase 3.
fsStr fsIGuiComponent::newGrammarValueRead(fsStr& pCommands)
{
pCommands.leadingWhitespaceTrim();
if (pCommands.emptyGet() || '"' == pCommands[0])
{
// Quoted string: chunk()'s own quote handling already reads
// verbatim to the closing '"' regardless of what's inside it
// (including a literal ',', ')', or ']'), so it's safe to delegate
// to directly, unlike the bare-leaf case below.
return pCommands.chunk();
}
if ('(' != pCommands[0] && '[' != pCommands[0])
{
// Bare leaf (number/identifier). chunk() doesn't treat ',', ')', or
// ']' as terminators - they're meaningless to it outside a
// list/tuple context - so it would read straight through them here;
// scan for them explicitly instead, the same reasoning as
// colonKeyGet's pre-chunk() peek.
fsStr::sizeT n = 0;
while (n < pCommands.dataSizeGet() && '=' != pCommands[n] && ',' != pCommands[n] && ')' != pCommands[n] &&
']' != pCommands[n] && ' ' != pCommands[n] && '\t' != pCommands[n] && '\n' != pCommands[n] &&
'\r' != pCommands[n])
{
++n;
}
fsStr leaf;
if (n > 0)
{
leaf.copy(pCommands.utf8Get(), 0, static_cast<fsS32>(n));
pCommands.erase(0, n);
pCommands.leadingWhitespaceTrim();
}
return leaf;
}
const fsChar closeChar = ('(' == pCommands[0]) ? ')' : ']';
pCommands.erase(0, 1);
pCommands.leadingWhitespaceTrim();
fsStr flattened;
fsBool first = true;
while (!pCommands.emptyGet() && closeChar != pCommands[0])
{
if (!first)
{
fsAssert(',' == pCommands[0], "Expected ',' between values in a list/tuple literal in file %s\n",
mGuiLayoutFileName->utf8Get())
if (',' == pCommands[0])
{
pCommands.erase(0, 1);
pCommands.leadingWhitespaceTrim();
}
}
const fsStr element = newGrammarValueRead(pCommands);
if (!flattened.emptyGet())
{
flattened += ", ";
}
flattened += element;
pCommands.leadingWhitespaceTrim();
first = false;
}
fsAssert(!pCommands.emptyGet() && closeChar == pCommands[0],
"Missing closing '%c' in a list/tuple literal in file %s\n", closeChar, mGuiLayoutFileName->utf8Get())
if (!pCommands.emptyGet())
{
pCommands.erase(0, 1);
}
return flattened;
}
void fsIGuiComponent::variableInsertIntoTree(const fsStr& pVariable, fsStr& pCommands, std::map<fsStr, fsStr>& pParams,
fsBool pNewGrammarMode)
{
pCommands.erase(0, 1);
pCommands.leadingWhitespaceTrim();
fsStr val;
if (pNewGrammarMode && !pCommands.emptyGet() && ('(' == pCommands[0] || '[' == pCommands[0]))
{
val = newGrammarValueRead(pCommands);
}
else if (fsITransformationComponent::mGraphKey == pVariable)
{
val = pCommands.chomp(";");
}
else
{
val = pCommands.chunk();
}
// Mirrors fsCVariableTable::strSet's key normalisation so that a param
// resolved here and later fed into an fsCVariableTable collides exactly
// as it would have under the old interleaved parse+construct code.
fsStr key = pVariable;
#if defined fsDownCaseFilename
key.downcase();
#endif
pParams[key] = val;
}
fsBool fsIGuiComponent::fileContentsInclude(fsStr& pCommands)
{
const fsStr includeFileName = pCommands.chunk();
if (mStylesIncluded.end() == std::find(mStylesIncluded.begin(), mStylesIncluded.end(), includeFileName))
{
mStylesIncluded.push_back(includeFileName);
const fsCResourceName includeResource(includeFileName, fsCResourceName::eRES_LOCATION_ASSETS);
if (fsIFile::fileExistsGet(includeResource))
{
const fsStr includeFileData = fsIFile::strGetFromFile(includeResource);
pCommands = includeFileData + pCommands;
return true;
}
pCommands = includeFileName + "\n" + pCommands;
}
return true;
}
fsS32 fsIGuiComponent::styleCharacterCountGet(fsStr& pCommands)
{
fsS32 numBraces = 1;
fsS32 numCharsInStyleDef = 0;
while (numBraces > 0)
{
const fsChar currChar = pCommands[numCharsInStyleDef++];
if ('{' == currChar)
{
++numBraces;
}
else if ('}' == currChar)
{
--numBraces;
}
fsAssert(numCharsInStyleDef <= static_cast<fsS32>(pCommands.dataSizeGet()),
"Missing '}' in style definition.\n");
}
return numCharsInStyleDef;
}
void fsIGuiComponent::styleDefinitionAdd(fsStr& pCommands, std::map<fsStr, fsStr>& pStyles)
{
pCommands.leadingWhitespaceTrim();
const fsStr styleName = pCommands.chunk();
fsAssert(styleName.dataSizeGet() > 1, "Expected a longer name for a style than '%s'.\n", styleName.utf8Get());
#if !defined fsRELEASE
fsAssert( '{' == pCommands[ 0 ], "Expected a '{' to open a style definition when parsing style %s in file %s.\n", styleName.utf8Get(), mGuiLayoutFileName->utf8Get());
#endif
pCommands.erase(0, 1);
pCommands.leadingWhitespaceTrim();
#if !defined fsRELEASE
fsAssert(fsStr::npos != pCommands.find( "}" ), "Expected a '}' at the end of a style definition when parsing style %s in file %s.\n", styleName.utf8Get(), mGuiLayoutFileName->utf8Get());
#endif
const fsS32 numCharsInStyleDef = styleCharacterCountGet(pCommands);
fsStr styleData;
if (numCharsInStyleDef > 0)
{
styleData.copy(pCommands.utf8Get(), 0, numCharsInStyleDef - 1);
pCommands.erase(0, numCharsInStyleDef);
}
pCommands.leadingWhitespaceTrim();
if (pStyles.end() == pStyles.find(styleName))
{
pStyles.insert(std::pair<fsStr, fsStr>(styleName, styleData));
}
}
fsBool fsIGuiComponent::styleDefinitionDecodeAndInsertIntoCommands(const fsStr& pStyleName, fsStr& pCommands,
std::map<fsStr, fsStr>& pStyles)
{
std::map<fsStr, fsStr>::iterator style = pStyles.find(pStyleName);
if (pStyles.end() != style)
{
pCommands.leadingWhitespaceTrim();
if ('{' == pCommands[0])
{
pCommands.chomp("\n");
fsStr styleText = style->second;
styleText.leadingWhitespaceTrim();
const fsStr::sizeT matchPos = styleText.rfind("}");
fsAssert((fsStr::npos != styleText.find("{") && fsStr::npos != matchPos ),
"Expected style %s definition to include a '{' '}' section so values can be inserted into it.\n",
style->first.utf8Get());
if (fsStr::npos != matchPos)
{
styleText.erase(matchPos);
}
else
{
fsLogError("style : %s is being used with an inline style definition. This is not currently supported, so the style definition will be ignored and the style will be inserted as if there was no inline definition.\n", style->second.utf8Get());
}
pCommands = styleText + pCommands;
}
else
{
pCommands = style->second + pCommands;
}
return true;
}
return false;
}
void fsIGuiComponent::initialiseFromVariableTableDo(const fsCVariableTable& pVars)
{
fsIComponent::initialiseFromVariableTableDo(pVars);
if (false == pVars.boolGetWithDefault("modal", true) && parentGet()->componentGet<fsCModalGuiComponent>())
{
parentGet()->componentGet<fsCModalGuiComponent>()->activeSet(false);
}
layoutFileProcess();
}
fsBool fsIGuiComponent::onButtonClicked(fsCButtonComponent* pButtonComp)
{
return false;
}
fsIGuiComponent* fsIGuiComponent::guiParentGetFromComponent(const fsIComponent* const pComponent)
{
fsINode* parentGui = pComponent->parentGet()->parentGet();
while ((parentGui != nullptr) && (!entityHasGuiComponentGet(parentGui)))
{
parentGui = parentGui->parentGet();
}
if (parentGui)
{
return static_cast<fsCEntity*>(parentGui)->firstComponentOfFamilyType<fsIGuiComponent>();
}
return nullptr;
}
fsBool fsIGuiComponent::entityHasGuiComponentGet(const fsINode* const pNode)
{
const fsCEntity* const entPtr = dynamic_cast<const fsCEntity* const>(pNode);
if (entPtr)
{
return nullptr != entPtr->firstComponentOfFamilyType<fsIGuiComponent>();
}
return false;
}
fsIGuiComponent::fsIGuiComponent(fsCEntity* const pParent) :
fsIComponent(pParent)
{
}
fsIGuiComponent::~fsIGuiComponent()
{
}
|