void ReadItems(TBWidgetsReader *reader, TBNode *node, TBGenericStringItemSource *target_source) { // If there is a items node, loop through all its children and add // items to the target item source. if (TBNode *items = node->GetNode("items")) { for (TBNode *n = items->GetFirstChild(); n; n = n->GetNext()) { if (strcmp(n->GetName(), "item") != 0) continue; const char *item_str = n->GetValueString("text", ""); TBID item_id; if (TBNode *n_id = n->GetNode("id")) reader->SetIDFromNode(item_id, n_id); TBGenericStringItem *item = new TBGenericStringItem(item_str, item_id); if (!item || !target_source->AddItem(item)) { // Out of memory delete item; break; } } } }
//static void TBNodeRefTree::ResolveConditions(TBNode *parent_node) { bool condition_ret = false; TBNode *node = parent_node->GetFirstChild(); while (node) { bool delete_node = false; bool move_children = false; if (strcmp(node->GetName(), "@if") == 0) { condition_ret = node->GetValueFollowRef().GetInt() ? true : false; if (condition_ret) move_children = true; delete_node = true; } else if (strcmp(node->GetName(), "@else") == 0) { condition_ret = !condition_ret; if (condition_ret) move_children = true; delete_node = true; } // Make sure we'll skip any nodes added from a conditional branch. TBNode *node_next = node->GetNext(); if (move_children) { // Resolve the branch first, since we'll skip it. ResolveConditions(node); while (TBNode *content = node->GetLastChild()) { node->Remove(content); parent_node->AddAfter(content, node); } } if (delete_node) parent_node->Delete(node); else ResolveConditions(node); node = node_next; } }
bool TBBFRenderer::Load(const char *filename, int size) { m_size = size; if (!m_node.ReadFile(filename)) return false; // Check for size nodes and get the one closest to the size we want. TBNode *size_node = nullptr; for (TBNode *n = m_node.GetFirstChild(); n; n = n->GetNext()) { if (strcmp(n->GetName(), "size") == 0) { if (!size_node || ABS(m_size - n->GetValue().GetInt()) < ABS(m_size - size_node->GetValue().GetInt())) size_node = n; } } if (!size_node) return false; // Metrics m_metrics.ascent = size_node->GetValueInt("ascent", 0); m_metrics.descent = size_node->GetValueInt("descent", 0); m_metrics.height = m_metrics.ascent + m_metrics.descent; // Other data m_advance_delta = size_node->GetValueInt("advance_delta", 0); m_space_advance = size_node->GetValueInt("space_advance", 0); m_x_ofs = size_node->GetValueInt("x_ofs", 0); // Info m_rgb = m_node.GetValueInt("info>rgb", 0); // Get the path for the bitmap file. TBTempBuffer bitmap_filename; if (!bitmap_filename.AppendPath(filename)) return false; // Append the bitmap filename for the given size. bitmap_filename.AppendString(size_node->GetValueString("bitmap", "")); m_img = TBImageLoader::CreateFromFile(bitmap_filename.GetData()); return FindGlyphs(); }
bool TBLanguage::Load(const char *filename) { // Read the file into a node tree (even though it's only a flat list) TBNode node; if (!node.ReadFile(filename)) return false; // Go through all nodes and add to the strings hash table TBNode *n = node.GetFirstChild(); while (n) { const char *str = n->GetValue().GetString(); TBStr *new_str = new TBStr(str); if (!new_str || !strings.Add(TBID(n->GetName()), new_str)) { delete new_str; return false; } n = n->GetNext(); } return true; }