void ElementDocumentWrapper::PreprocessCode(Rocket::Core::String &code, Rocket::Core::Stream *stream)
{
	// Load in the script	
	Rocket::Core::String buffer;	
	stream->Read(buffer, stream->Length());	

	// Strip comments and build up code
	code = "";
	
	size_t i = 0;
	size_t line_start = 0;
	enum ParseState { START, COMMENT, DATA };
	ParseState state = START;

	while (i < buffer.Length())
	{		
		// Python doesn't like \r's, strip them
		if (buffer[i] == '\r')
		{
			buffer.Erase(i, 1);

			// Make sure we get out if there are no characters left
			if (i == buffer.Length())
				continue;
		}

		switch (state)
		{
			case START:
			{
				// Check for the start of comments or non whitespace data
				if (buffer[i] == '#')
					state = COMMENT;
				else if (!Rocket::Core::StringUtilities::IsWhitespace(buffer[i]))
					state = DATA;
			}
			break;

			default:		
			{
				// If we've hit the end of the line, process as required
				if (buffer[i] == '\n')
				{				
					if (state == DATA)
						code += buffer.Substring(line_start, i - line_start + 1);

					state = START;
					line_start = i + 1;
				}
			}
			break;
		}
		
		i++;
	}
}
// Sets up data source and table from a given string.
bool DataSourceListener::ParseDataSource(DataSource*& data_source, Rocket::Core::String& table_name, const Rocket::Core::String& data_source_name)
{
	if (data_source_name.Length() == 0)
	{
		data_source = NULL;
		table_name = "";
		return false;
	}

	Rocket::Core::StringList data_source_parts;
	Rocket::Core::StringUtilities::ExpandString(data_source_parts, data_source_name, '.');

	DataSource* new_data_source = DataSource::GetDataSource(data_source_parts[0].CString());

	if (data_source_parts.size() != 2 || !new_data_source)
	{
		Rocket::Core::Log::Message(Rocket::Core::Log::LT_ERROR, "Bad data source name %s", data_source_name.CString());
		data_source = NULL;
		table_name = "";
		return false;
	}

	data_source = new_data_source;
	table_name = data_source_parts[1];
	return true;
}
// reduces an rml string to a common format so two rml strings can be compared
static Rocket::Core::String ReduceRML( const Rocket::Core::String &rml )
{
    Rocket::Core::String ret;
    Rocket::Core::String::size_type length = rml.Length();
    ret.Reserve( length );

    for ( int i = 0; i < length; i++ )
    {
        if ( rml[ i ] == ' ' || rml[ i ] == '\n' )
        {
            continue;
        }

        if ( rml[ i ] == '"' )
        {
            ret += '\'';
        }

        else
        {
            ret += rml[ i ];
        }
    }

    return ret;
}
// Called by Rocket when a texture is required by the library.		
bool RocketSDL2Renderer::LoadTexture(Rocket::Core::TextureHandle& texture_handle, Rocket::Core::Vector2i& texture_dimensions, const Rocket::Core::String& source)
{

    Rocket::Core::FileInterface* file_interface = Rocket::Core::GetFileInterface();
    Rocket::Core::FileHandle file_handle = file_interface->Open(source);
    if (!file_handle)
        return false;

    file_interface->Seek(file_handle, 0, SEEK_END);
    size_t buffer_size = file_interface->Tell(file_handle);
    file_interface->Seek(file_handle, 0, SEEK_SET);

    char* buffer = new char[buffer_size];
    file_interface->Read(buffer, buffer_size, file_handle);
    file_interface->Close(file_handle);

    size_t i;
    for(i = source.Length() - 1; i > 0; i--)
    {
        if(source[i] == '.')
            break;
    }

    Rocket::Core::String extension = source.Substring(i+1, source.Length()-i);

    SDL_Surface* surface = IMG_LoadTyped_RW(SDL_RWFromMem(buffer, buffer_size), 1, extension.CString());

    if (surface) {
        SDL_Texture *texture = SDL_CreateTextureFromSurface(mRenderer, surface);

        if (texture) {
            texture_handle = (Rocket::Core::TextureHandle) texture;
            texture_dimensions = Rocket::Core::Vector2i(surface->w, surface->h);
            SDL_FreeSurface(surface);
        }
        else
        {
            return false;
        }

        return true;
    }

    return false;
}
Example #5
0
void Interpreter::DoString(const Rocket::Core::String& code, const Rocket::Core::String& name)
{
    if(luaL_loadbuffer(_L,code.CString(),code.Length(), name.CString()) != 0)
        Report(_L);
    else
    {
        if(lua_pcall(_L,0,0,0) != 0)
            Report(_L);
    }
}
Example #6
0
void Interpreter::LoadString(const Rocket::Core::String& code, const Rocket::Core::String& name)
{
    if(luaL_loadbuffer(_L,code.CString(),code.Length(), name.CString()) != 0)
        Report(_L);
}