//static TBValue &TBNodeRefTree::GetValueFromTree(const char *request) { assert(*request == '@'); TBNode tmp; tmp.GetValue().SetString(request, TBValue::SET_AS_STATIC); TBNode *node = TBNodeRefTree::FollowNodeRef(&tmp); if (node != &tmp) return node->GetValue(); static TBValue nullval; return nullval; }
void IncludeRef(int line_nr, const char *refstr) { TBNode *refnode = nullptr; if (*refstr == '@') { TBNode tmp; tmp.GetValue().SetString(refstr, TBValue::SET_AS_STATIC); refnode = TBNodeRefTree::FollowNodeRef(&tmp); } else // Local look-up { // Note: If we read to a target node that already contains // nodes, we might look up nodes that's already there // instead of new nodes. refnode = m_root_node->GetNode(refstr, TBNode::GET_MISS_POLICY_NULL); // Detect cycles TBNode *cycle_detection = m_target_node; while (cycle_detection && refnode) { if (cycle_detection == refnode) refnode = nullptr; // We have a cycle, so just fail the inclusion. cycle_detection = cycle_detection->GetParent(); } } if (refnode) m_target_node->CloneChildren(refnode); else { TBStr err; err.SetFormatted("Include \"%s\" was not found!", refstr); OnError(line_nr, err); } }
void DemoWindow::LoadResource(TBNode &node) { g_widgets_reader->LoadNodeTree(this, &node); // Get title from the WindowInfo section (or use "" if not specified) SetText(node.GetValueString("WindowInfo>title", "")); const TBRect parent_rect(0, 0, GetParent()->GetRect().w, GetParent()->GetRect().h); const TBDimensionConverter *dc = g_tb_skin->GetDimensionConverter(); TBRect window_rect = GetResizeToFitContentRect(); // Use specified size or adapt to the preferred content size. TBNode *tmp = node.GetNode("WindowInfo>size"); if (tmp && tmp->GetValue().GetArrayLength() == 2) { window_rect.w = dc->GetPxFromString(tmp->GetValue().GetArray()->GetValue(0)->GetString(), window_rect.w); window_rect.h = dc->GetPxFromString(tmp->GetValue().GetArray()->GetValue(1)->GetString(), window_rect.h); } // Use the specified position or center in parent. tmp = node.GetNode("WindowInfo>position"); if (tmp && tmp->GetValue().GetArrayLength() == 2) { window_rect.x = dc->GetPxFromString(tmp->GetValue().GetArray()->GetValue(0)->GetString(), window_rect.x); window_rect.y = dc->GetPxFromString(tmp->GetValue().GetArray()->GetValue(1)->GetString(), window_rect.y); } else window_rect = window_rect.CenterIn(parent_rect); // Make sure the window is inside the parent, and not larger. window_rect = window_rect.MoveIn(parent_rect).Clip(parent_rect); SetRect(window_rect); // Ensure we have focus - now that we've filled the window with possible focusable // widgets. EnsureFocus was automatically called when the window was activated (by // adding the window to the root), but then we had nothing to focus. // Alternatively, we could add the window after setting it up properly. EnsureFocus(); }
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; }