コード例 #1
0
void CEGUILuaBindScriptModule::executeScriptFile(const CEGUI::String &filename, const CEGUI::String &resourceGroup)
{
	// load file
	CEGUI::RawDataContainer raw;
	CEGUI::System::getSingleton().getResourceProvider()->loadRawDataContainer(filename,
        raw, resourceGroup.empty() ? d_defaultResourceGroup : resourceGroup);

	lua_State * lua_vm = LuaScript::Instance( ).GetLuaVM( );

	// load code into lua
	int top = lua_gettop( lua_vm );
	int loaderr = luaL_loadbuffer( lua_vm, (char*)raw.getDataPtr(), raw.getSize(), filename.c_str());
	CEGUI::System::getSingleton().getResourceProvider()->unloadRawDataContainer( raw );
	if (loaderr)
	{
		CEGUI::String errMsg = lua_tostring(lua_vm,-1);
		lua_settop(lua_vm,top);
		throw CEGUI::ScriptException("Unable to execute Lua script file: '"+filename+"'\n\n"+errMsg+"\n");
	}

    // call it
	if (lua_pcall(lua_vm,0,0,0))
	{
	    CEGUI::String errMsg = lua_tostring(lua_vm,-1);
		lua_settop(lua_vm,top);
		throw CEGUI::ScriptException("Unable to execute Lua script file: '"+filename+"'\n\n"+errMsg+"\n");
	}

	lua_settop(lua_vm,top); // just in case :P
}
コード例 #2
0
void LibxmlParser::parseXMLFile(XMLHandler& handler, const String& filename, const String&, const String& resourceGroup)
{
    // load xml file data into buffer using resource provider
    CEGUI::RawDataContainer rawXMLData;
    CEGUI::System::getSingleton().getResourceProvider()->loadRawDataContainer(filename, rawXMLData, resourceGroup);

    xmlDocPtr doc = xmlParseMemory(
        reinterpret_cast<char*>(rawXMLData.getDataPtr()),
        rawXMLData.getSize());

    // release loaded xml data.
    System::getSingleton().getResourceProvider()->
        unloadRawDataContainer(rawXMLData);

    if (!doc)
    {
        xmlError* err = xmlGetLastError();

        throw GenericException(
            String("LibxmlParser::parseXMLFile - xmlParseMemory failed in file: '") +
            err->file + "' at line number" +
            PropertyHelper::uintToString(err->line) + ".  Error is:" +
            err->message);
    }

    // get root element
    xmlNode* root = xmlDocGetRootElement(doc);

    // process all elements from root to end of doc
    processXMLElement(handler, root);

    // release the xmlDoc 
    xmlFreeDoc(doc);
}
コード例 #3
0
ファイル: CEGUIExpatParser.cpp プロジェクト: brock7/TianLong
void ExpatParser::parseXMLFile(CEGUI::XMLHandler& handler, const CEGUI::String& filename, const CEGUI::String& schemaName, const CEGUI::String& resourceGroup)
{
    // All stuff goes here
    XML_Parser parser = XML_ParserCreate(0); // Create a parser

    if (! parser)
    {
        throw CEGUI::GenericException("ExpatParser::parseXMLFile - Unable to create a new Expat Parser");
    }

    XML_SetUserData(parser, (void*)&handler); // Initialise user data
    XML_SetElementHandler(parser, startElement, endElement); // Register callback for elements

    // Aquire resource using CEGUI ResourceProvider
    CEGUI::RawDataContainer rawXMLData;
    CEGUI::System::getSingleton().getResourceProvider()->loadRawDataContainer(filename, rawXMLData, resourceGroup);

    // Parse the data (note that the last true parameter tels Expat that this is the last chunk of the document
    if ( ! XML_Parse(parser, reinterpret_cast<const char*>(rawXMLData.getDataPtr()), rawXMLData.getSize(), true))
    {
        CEGUI::System::getSingleton().getResourceProvider()->unloadRawDataContainer(rawXMLData);
        throw CEGUI::GenericException(CEGUI::String((CEGUI::utf8*)"ExpatParser::parseXMLFile( ") + 
									CEGUI::String(filename)+
									CEGUI::String((CEGUI::utf8*)" )  - XML Parsing error '\r\n") +
                                    CEGUI::String((CEGUI::utf8*)XML_ErrorString(XML_GetErrorCode(parser))) +
                                    CEGUI::String((CEGUI::utf8*)"' at line ")  + XML_GetCurrentLineNumber(parser));
    }

    // Release resource
    CEGUI::System::getSingleton().getResourceProvider()->unloadRawDataContainer(rawXMLData);

	// Free parser
	XML_ParserFree(parser);
}
コード例 #4
0
bool
CFormBackendImp::LoadLayout( GUCEF::CORE::CIOAccess& layoutStorage )
{GUCEF_TRACE;
    
    CEGUI::Window* rootWindow = NULL;
    CEGUI::WindowManager* wmgr = CEGUI::WindowManager::getSingletonPtr();
    
    GUCEF_DEBUG_LOG( 0, "Starting layout load for a GUI Form" );
    
    try
    {
        CORE::CDynamicBuffer memBuffer( layoutStorage );
        CEGUI::RawDataContainer container;

        container.setData( (CEGUI::uint8*) memBuffer.GetBufferPtr() );
        container.setSize( (size_t) memBuffer.GetDataSize() );

        rootWindow = wmgr->loadLayoutFromContainer( container );

        container.setData( (CEGUI::uint8*) NULL );
        container.setSize( (size_t) 0 );
    }
    catch ( CEGUI::Exception& e )
    {
        GUCEF_ERROR_LOG( 0, CString( "CEGUI Exception while attempting to load form layout: " ) + e.what() );
        return false;
    }
    
    // Now that we completed loading lets see what we got from CEGUI
    if ( NULL != rootWindow )
    {
        // Begin by providing a wrapper for the root window
        m_rootWindow = CreateAndHookWrapperForWindow( rootWindow );
        if ( NULL != m_rootWindow )
        {
            CString localWidgetName = m_rootWindow->GetName().SubstrToChar( '/', false );
            m_widgetMap[ localWidgetName ] = m_rootWindow;
            WrapAndHookChildWindows( rootWindow );
            
            // We will directly add the form as a child of the root for now
            // Note: This assumes that you have a GUISheet already set, otherwise this will result in a segfault!
            CEGUI::Window* globalRootWindow = CEGUI::System::getSingleton().getDefaultGUIContext().getRootWindow();
            if ( NULL != globalRootWindow )
            {
                globalRootWindow->addChild( rootWindow );
                
                GUCEF_DEBUG_LOG( 0, "Successfully loaded a GUI Form layout" );
                return true;                
            }
            else
            {
                GUCEF_ERROR_LOG( 0, "Failed to add form as a child to the global \"root\" window" );    
            }
        }
        rootWindow->hide();
    }

    GUCEF_DEBUG_LOG( 0, "Failed to load a GUI Form layout" );
    return false; 
}
コード例 #5
0
void CLuaManager::executeScriptFile(const CEGUI::String& filename, const CEGUI::String& resourceGroup)
{
    // load file
    CEGUI::RawDataContainer raw;
    CEGUI::System::getSingleton().getResourceProvider()->loadRawDataContainer(filename,
          raw, resourceGroup.empty() ? d_defaultResourceGroup : resourceGroup);

    // load code into lua
    int loaderr = luaL_loadbuffer(m_luaVM, (char*)raw.getDataPtr(), raw.getSize(), filename.c_str());
    CEGUI::System::getSingleton().getResourceProvider()->unloadRawDataContainer(raw);

    // call it
    if (loaderr==0) { // run the file
        int result = lua_pcall(m_luaVM,0,0,0);
        switch (result) {
            case LUA_ERRRUN:
                CLog::getInstance()->error("Runtime error in %s", filename.c_str());
                break;
            case LUA_ERRMEM:
                CLog::getInstance()->error("Memory alocation error in %s", filename.c_str());
                break;
            case LUA_ERRERR:
                CLog::getInstance()->error("Error handler error in %s", filename.c_str());
                break;
            default:
                break;
        }
    } else {
        CLog::getInstance()->error("Unable to load %s", filename.c_str());
    }
}
コード例 #6
0
void
VfsResourceProvider::loadRawDataContainer( const CEGUI::String& filename      , 
                                           CEGUI::RawDataContainer& output    , 
                                           const CEGUI::String& resourceGroup )
{GUCEF_TRACE;
    
    // everything in CEGUI works based on resource groups
    // make sure we dont use an empty one
    const CEGUI::String* rscGroup = &resourceGroup;
    if ( resourceGroup.empty() )
    {
        rscGroup = &m_defaultResourceGroup;
    }

    CORE::CString filePath;
    CORE::CString fileName = filename;
    TCEStringMap::iterator i = m_groupMap.find( *rscGroup );
    if ( i != m_groupMap.end() )
    {
        filePath = (*i).second;
    }

    filePath = CORE::CombinePath( filePath, fileName );

    VFS::CVFS& vfs = VFS::CVfsGlobal::Instance()->GetVfs();

    VFS::CVFS::CVFSHandlePtr file = vfs.GetFile( filePath, "rb", false );
    if ( !file.IsNULL() )
    {
        CORE::CIOAccess* fileAccess = file->GetAccess();
        if ( NULL != fileAccess )
        {
            CORE::CDynamicBuffer memBuffer( *fileAccess );
             
            void* buffer = NULL;
            UInt32 dataSize = 0; 
            memBuffer.RelinquishDataOwnership( buffer, dataSize );

            output.setData( (CEGUI::uint8*) buffer );
            output.setSize( dataSize );

            DataContainerInfoPtr info = new TDataContainerInfo;
            info->fileHandle = file;
            info->requestFilename = fileName;
            info->requestresourceGroup = resourceGroup;
            info->ceContainer = output;

            m_containerMap[ buffer ] = info;
        }
        else
        {
            GUCEF_ERROR_LOG( CORE::LOGLEVEL_NORMAL, "VfsResourceProvider:loadRawDataContainer: Unable to load resource from path: " + filePath );
        } 
    }
}
コード例 #7
0
void
VfsResourceProvider::unloadRawDataContainer( CEGUI::RawDataContainer& data )
{GUCEF_TRACE;
    
    TContainerMap::iterator i = m_containerMap.find( (void*) data.getDataPtr() );
    if ( i != m_containerMap.end() )
    {
        (*i).second->ceContainer.setData( (CEGUI::uint8*) nullptr );
        (*i).second->ceContainer.setSize( 0 );
        m_containerMap.erase( i );
    }
    
    delete[] data.getDataPtr();
    data.setData( (CEGUI::uint8*) nullptr );
    data.setSize( 0 );
}
コード例 #8
0
ファイル: ZCEGui.cpp プロジェクト: pulkomandy/.theRush-
	virtual void 	loadRawDataContainer (const CEGUI::String &filename,
		CEGUI::RawDataContainer &output, const CEGUI::String &resourceGroup)
	{

		ZFile file;
		if (file.Open(filename.c_str()))
		{
			int fn = file.GetSize();
			char *ptr = new char [fn+1];
			file.Read(ptr, fn);
			ptr[fn] = 0;
			output.setData((CEGUI::uint8*)ptr);
			output.setSize(fn);
		}

	}
コード例 #9
0
VfsResourceProvider::DataContainerInfoPtr 
VfsResourceProvider::GetInfoOnLoadedContainer( const CEGUI::RawDataContainer& container )
{GUCEF_TRACE;

    TContainerMap::iterator i = m_containerMap.find( (void*) container.getDataPtr() );
    if ( i != m_containerMap.end() )
    {
        return (*i).second;
    }
    return DataContainerInfoPtr();
}
コード例 #10
0
void GuiTexture::loadFromFile( const CEGUI::String& filename, const CEGUI::String& resourceGroup )
{
    glBindTexture( GL_TEXTURE_2D, _ogltexture );

    // load file to memory via resource provider
    CEGUI::RawDataContainer texFile;
    CEGUI::System::getSingleton().getResourceProvider()->loadRawDataContainer( filename, texFile, resourceGroup );
    if ( !texFile.getDataPtr() )
        return;

    tImageTGA*  img = LoadTGA( texFile.getDataPtr(), texFile.getSize() );
    if (img != 0)
    {
        _width = static_cast<CEGUI::ushort>(img->sizeX);
        _height = static_cast<CEGUI::ushort>(img->sizeY);

        // flip the image...
        flipImageTGA(img);

        // If the image is 32-bit (4 channels), then we need to specify GL_RGBA for an alpha, else we use GL_RGB.
        int textureType = (img->channels == 4) ? GL_RGBA : GL_RGB;

        glTexImage2D(GL_TEXTURE_2D, 0, textureType, _width, _height, 0, textureType, GL_UNSIGNED_BYTE, img->data);

        // Free texture data, we don't need it anymore
        if ( img->data )
        {
            delete[] img->data;
        }

        // Free the image structure
        delete img;
    }
    else
    {
        throw CEGUI::RendererException("GuiTexture::loadFromFile - internal Targa loader failed to load image '" + filename + "'.");
    }
}
コード例 #11
0
void CEGUIResourceProvider::unloadRawDataContainer(CEGUI::RawDataContainer& data)
{
    data.setData(NULL);
    data.setSize(0);
}
コード例 #12
0
void CEGUIResourceProvider::loadRawDataContainer(const CEGUI::String &filename,
                                              CEGUI::RawDataContainer &output,
                                              const CEGUI::String &resourceGroup)
{
    DBG(0, "%s", filename.c_str());
    if (strcmp(filename.c_str(), "TaharezLook.scheme") == 0) {
        DBG(0, "size %d", sizeof(taharez_look_schem));
         output.setData((CEGUI::uint8*)taharez_look_schem);
         output.setSize(sizeof(taharez_look_schem));
         return;
    }

    if (strcmp(filename.c_str(), "TaharezLook.imageset") == 0) {
        DBG(0, "size %d", sizeof(taharez_look_imageset));
        output.setData((CEGUI::uint8*)taharez_look_imageset);
        output.setSize(sizeof(taharez_look_imageset));
        return;
    }

    if (strcmp(filename.c_str(), "TaharezLook.tga") == 0) {
        DBG(0, "size %d", sizeof(taharez_look_tga));
        output.setData((CEGUI::uint8*)taharez_look_tga);
        output.setSize(sizeof(taharez_look_tga));
        return;
    }

    if (strcmp(filename.c_str(), "Commonwealth-10.font") == 0) {
        DBG(0, "size %d", sizeof(commonwealth_10_font));
        output.setData((CEGUI::uint8*)commonwealth_10_font);
        output.setSize(sizeof(commonwealth_10_font));
        return;
    }

    if (strcmp(filename.c_str(), "Commonv2c.ttf") == 0) {
        DBG(0, "size %d", sizeof(commonv2c_ttf));
        output.setData((CEGUI::uint8*)commonv2c_ttf);
        output.setSize(sizeof(commonv2c_ttf));
        return;
    }

    if (strcmp(filename.c_str(), "TaharezLook.looknfeel") == 0) {
        DBG(0, "size %d", sizeof(taharez_look_looknfeel));
        output.setData((CEGUI::uint8*)taharez_look_looknfeel);
        output.setSize(sizeof(taharez_look_looknfeel));
        return;
    }

    if (strcmp(filename.c_str(), "DejaVuSans-10.font") == 0) {
        DBG(0, "size %d", sizeof(dejavu_sans_10_font));
        output.setData((CEGUI::uint8*)dejavu_sans_10_font);
        output.setSize(sizeof(dejavu_sans_10_font));
        return;
    }

    if (strcmp(filename.c_str(), "DejaVuSans.ttf") == 0) {
        DBG(0, "size %d", sizeof(dejavu_sans_ttf));
        output.setData((CEGUI::uint8*)dejavu_sans_ttf);
        output.setSize(sizeof(dejavu_sans_ttf));
        return;
    }

    throw CEGUI::GenericException("failed");
}
コード例 #13
0
ファイル: ZCEGui.cpp プロジェクト: pulkomandy/.theRush-
	virtual void 	unloadRawDataContainer (CEGUI::RawDataContainer &data)
	{
		delete [] data.getDataPtr();
		data.setData(NULL);
	}