static TxtNode* TxtChildNodeWithKey(TxtNode* top, const char* keyName) { for (TxtNode* node = top->firstChild; node != nullptr; node = node->sibling) { if (node->IsTextWithKey(keyName)) { return node; } } return nullptr; }
static TxtNode *TxtChildNodeWithKey(TxtNode *top, const char *keyName) { size_t n = top->children->Count(); for (size_t i = 0; i < n; i++) { TxtNode *node = top->children->At(i); if (node->IsTextWithKey(keyName)) return node; } return NULL; }
// styles are cached globally, so we only add a style if it doesn't // exist already static void CacheStyleFromStruct(TxtNode* def) { CrashIf(!def->IsStructWithName("style")); TxtNode* nameNode = TxtChildNodeWithKey(def, "name"); CrashIf(!nameNode); // must have name or else no way to refer to it AutoFree tmp(nameNode->ValDup()); if (StyleByName(tmp)) return; Style* style = new Style(); for (TxtNode* node = def->firstChild; node != nullptr; node = node->sibling) { CrashIf(!node->IsText()); AddStyleProp(style, node); } CacheStyle(style, nullptr); }
// styles are cached globally, so we only add a style if it doesn't // exist already static void CacheStyleFromStruct(TxtNode* def) { CrashIf(!def->IsStructWithName("style")); TxtNode *nameNode = TxtChildNodeWithKey(def, "name"); CrashIf(!nameNode); // must have name or else no way to refer to it ScopedMem<char> tmp(nameNode->ValDup()); if (StyleByName(tmp)) return; Style *style = new Style(); size_t n = def->children->Count(); for (size_t i = 0; i < n; i++) { TxtNode *node = def->children->At(i); CrashIf(!node->IsText()); AddStyleProp(style, node); } CacheStyle(style, NULL); }
// TODO: create the rest of controls static void ParseMuiDefinition(TxtNode *root, ParsedMui& res) { TxtNode **n; for (n = root->children->IterStart(); n; n = root->children->IterNext()) { TxtNode *node = *n; CrashIf(!node->IsStruct()); if (node->IsStructWithName("Style")) { CacheStyleFromStruct(node); } else if (node->IsStructWithName("ButtonVector")) { ButtonVector *b = ButtonVectorFromDef(node); res.allControls.Append(b); res.vecButtons.Append(b); } else if (node->IsStructWithName("Button")) { Button *b = ButtonFromDef(node); res.allControls.Append(b); res.buttons.Append(b); } else if (node->IsStructWithName("ScrollBar")) { ScrollBar *sb = ScrollBarFromDef(node); res.allControls.Append(sb); res.scrollBars.Append(sb); } else if (node->IsStructWithName("HorizontalLayout")) { HorizontalLayout *l = HorizontalLayoutFromDef(res, node); res.layouts.Append(l); } else if (node->IsStructWithName("VerticalLayout")) { VerticalLayout *l = VerticalLayoutFromDef(res, node); res.layouts.Append(l); } else { ScopedMem<char> keyName(node->KeyDup()); ControlCreatorFunc creatorFunc = FindControlCreatorFuncFor(keyName); if (creatorFunc) { Control *c = creatorFunc(node); if (c) res.allControls.Append(c); continue; } LayoutCreatorFunc layoutCreatorFunc = FindLayoutCreatorFuncFor(keyName); CrashIf(!layoutCreatorFunc); ILayout *layout = layoutCreatorFunc(&res, node); if (layout) res.layouts.Append(layout); } } }
// TODO: create the rest of controls static void ParseMuiDefinition(TxtNode* root, ParsedMui& res) { for (TxtNode* node = root->firstChild; node != nullptr; node = node->sibling) { CrashIf(!node->IsStruct()); if (node->IsStructWithName("Style")) { CacheStyleFromStruct(node); } else if (node->IsStructWithName("ButtonVector")) { ButtonVector* b = ButtonVectorFromDef(node); res.allControls.push_back(b); res.vecButtons.push_back(b); } else if (node->IsStructWithName("Button")) { Button* b = ButtonFromDef(node); res.allControls.push_back(b); res.buttons.push_back(b); } else if (node->IsStructWithName("ScrollBar")) { ScrollBar* sb = ScrollBarFromDef(node); res.allControls.push_back(sb); res.scrollBars.push_back(sb); } else if (node->IsStructWithName("HorizontalLayout")) { HorizontalLayout* l = HorizontalLayoutFromDef(res, node); res.layouts.push_back(l); } else if (node->IsStructWithName("VerticalLayout")) { VerticalLayout* l = VerticalLayoutFromDef(res, node); res.layouts.push_back(l); } else { AutoFree keyName(node->KeyDup()); ControlCreatorFunc creatorFunc = FindControlCreatorFuncFor(keyName); if (creatorFunc) { Control* c = creatorFunc(node); if (c) { res.allControls.push_back(c); } continue; } LayoutCreatorFunc layoutCreatorFunc = FindLayoutCreatorFuncFor(keyName); CrashIf(!layoutCreatorFunc); ILayout* layout = layoutCreatorFunc(&res, node); if (layout) { res.layouts.push_back(layout); } } } }
/* Returns the number of frames loaded */ int XSI_LoadFile(const char *filename) { char *filebin=0; TxtNode *root; FILE *fp=fopen(filename,"ra"); if (!fp){ InfoBox(va("File not found: \"%s\"",filename)); return 0; } fseek(fp,0,SEEK_END); int len=ftell(fp); filebin=new char[len]; fseek(fp,0,SEEK_SET); if (fread(filebin,1,len,fp)!=(size_t)len) { fclose(fp); InfoBox(va("Bad XSI file\n",filename)); delete(filebin); return 0; } fclose(fp); char *at=filebin; char *end=filebin+len; root=new TxtNode; TxtNode **last=&root->child; char *retat; while (1) { TxtNode *t=ReadANode(at,end,&retat); if (!t) { at=end; break; } at=retat; *last=t; last=&t->sibling; } if (!root->child) { printf("Bad XSI file\n"); delete(filebin); delete root; return 0; } #if PDEB root->Print(0); #endif nsNodes=0; maxframe=-10000; minframe=10000; startframe=10000; endframe=-10000; CacheName[0]=0; int fn=FindNodes(0,root); if (!fn) { fn=FindAnims(root); } delete(filebin); delete root; if (fn==2000) { printf("XSI import failed, Missing Keys\n",fn); return 0; } if (fn) { printf("XSI import failed, code = %d",fn); return 0; } return maxframe+1; }
static TxtNode* GetRootArray(TxtParser* parser) { TxtNode* root = parser->nodes.at(0); CrashIf(!root->IsArray()); return root; }