bool TBWidgetsReader::LoadFile(TBWidget *target, const char *filename) { TBNode node; if (!node.ReadFile(filename)) return false; LoadNodeTree(target, &node); return true; }
TBConsole::TBConsole(BATB& b) : batb( b ) { using namespace tb; // read file as node tree, letting us parse custom nodes for this widget. // see tb_widgets_reader.[hc]pp TBNode node; if ( node.ReadFile( "static://batb/run/console.tb.txt" ) ) { // let TB populate this TBWindow from file g_widgets_reader->LoadNodeTree( this, &node ); // read properties for 'this' (g_widgets_reader only adds children of 'this') // (see void TBWidget::OnInflate(const INFLATE_INFO &info) in tb_widgets_reader.cpp) SetSkinBg( node.GetValueString( "skin", "TBWindow" ) ); //SetOpacity( node.GetValueFloat("opacity", GetOpacity()) ); // we can now retrieve child widgets of 'this' from ID with // - MyWidget* widget = GetWidgetByIDAndType<MyWidget>( TBIDC("my-id-name") ); // - tb::TBWidget* widget = GetWidgetById( TBIDC( "my-id-name" ) ); if ( (tb_input_ = GetWidgetByIDAndType<TBEditField>( TBIDC( "input" ) ) ) == nullptr ) { batb.log << "TBConsole: " << "no TBEditField 'input' defined :(" << std::endl; } if ( (tb_output_ = GetWidgetByIDAndType<TBEditField>( TBIDC( "output" ) ) ) == nullptr ) { batb.log << "TBConsole: " << "no TBEditField 'output' defined :(" << std::endl; } { // only input should receive focus tb_output_->SetIsFocusable( false ); // TODO: change skin of scrollbar. use TBEditField::GetScrollRoot() ? } //tb_input_->SetPlaceholderText( "enter command" ); } else { batb.log << "TBConsole: " << "could not read tbconsole.tb.txt" << std::endl; //throw std::runtime_error( "TBConsole: error reading file" ); } // settings: //SetSettings( tb::WINDOW_SETTINGS_RESIZABLE ); SetSettings( tb::WINDOW_SETTINGS_NONE ); SetText( "TBConsole" ); }
bool DemoWindow::LoadResourceFile(const char *filename) { // We could do g_widgets_reader->LoadFile(this, filename) but we want // some extra data we store under "WindowInfo", so read into node tree. TBNode node; if (!node.ReadFile(filename)) return false; LoadResource(node); return true; }
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; }
void IncludeFile(int line_nr, const char *filename) { // Read the included file into a new TBNode and then // move all the children to m_target_node. TBTempBuffer include_filename; include_filename.AppendPath(m_filename); include_filename.AppendString(filename); TBNode content; if (content.ReadFile(include_filename.GetData())) { while (TBNode *content_n = content.GetFirstChild()) { content.Remove(content_n); m_target_node->Add(content_n); } } else { TBStr err; err.SetFormatted("Referenced file \"%s\" was not found!", include_filename.GetData()); OnError(line_nr, err); } }