コード例 #1
0
Rocket::Core::FileHandle UI_FileInterface::Open(const Rocket::Core::String & path)
{
	int filenum = 0;
	int length = -1;
	Rocket::Core::URL url( path );
	Rocket::Core::String protocol = url.GetProtocol();

	// local
	if( protocol.Empty() || protocol == "file" ) {
		Rocket::Core::String path2( url.GetPathedFileName() );
		if( path2[0] == '/' ) {
			path2.Erase( 0, 1 );
		}
		length = trap::FS_FOpenFile( path2.CString(), &filenum, FS_READ );
	}
	else if( protocol == "http" ) {
		// allow blocking download of remote resources
		length = trap::FS_FOpenFile( path.CString(), &filenum, FS_READ );
	}

	if( length == -1 )
		return 0;

	// cache file length
	fileSizeMap[filenum] = length;

	// Com_Printf("UI_FileInterface opened %s\n", path2.CString() );
	return static_cast<Rocket::Core::FileHandle>( filenum );
}
コード例 #2
0
DataFormatter::DataFormatter(const Rocket::Core::String& _name)
{
	if (!_name.Empty())
	{
		name = _name;
	}
	else
	{
		name.FormatString(64, "%x", this);
	}
	data_formatters[name] = this;
}
コード例 #3
0
// Submits the form.
void ElementForm::Submit(const Rocket::Core::String& name, const Rocket::Core::String& submit_value)
{
	Rocket::Core::Dictionary values;
	if (name.Empty())
		values.Set("submit", submit_value);
	else
		values.Set(name, submit_value);

	Core::ElementList form_controls;
	Core::ElementUtilities::GetElementsByTagName(form_controls, this, "input");
	Core::ElementUtilities::GetElementsByTagName(form_controls, this, "textarea");
	Core::ElementUtilities::GetElementsByTagName(form_controls, this, "select");
	Core::ElementUtilities::GetElementsByTagName(form_controls, this, "dataselect");

	for (size_t i = 0; i < form_controls.size(); i++)
	{
		ElementFormControl* control = rocket_dynamic_cast< ElementFormControl* >(form_controls[i]);
		if (!control)
			continue;

		// Skip disabled controls.
		if (control->IsDisabled())
			continue;

		// Only process controls that should be submitted.
		if (!control->IsSubmitted())
			continue;

		Rocket::Core::String control_name = control->GetName();
		Rocket::Core::String control_value = control->GetValue();

		// Skip over unnamed form controls.
		if (control_name.Empty())
			continue;

		// If the item already exists, append to it.
		Rocket::Core::Variant* value = values.Get(control_name);
		if (value != NULL)
			value->Set(value->Get< Rocket::Core::String >() + ", " + control_value);
		else
			values.Set< Rocket::Core::String >(control_name, control_value);					
	}

	DispatchEvent("submit", values);
}
コード例 #4
0
ファイル: DataQuery.cpp プロジェクト: Aggroo/nebula-trifid
void DataQuery::ExecuteQuery(DataSource* _data_source, const Rocket::Core::String& _table, const Rocket::Core::String& _fields, int _offset, int _limit, const Rocket::Core::String& order)
{
	data_source = _data_source;
	table = _table;
	offset = _offset;
	limit = _limit;

	// Set up the field list and field index cache.
	Rocket::Core::StringUtilities::ExpandString(fields, _fields);
	for (size_t i = 0; i < fields.size(); i++)
	{
		field_indices[fields[i]] = i;
	}

	// Initialise the row pointer.
	current_row = -1;

	// If limit is -1, then we fetch to the end of the data source.
	if (limit == -1)
	{
		limit = data_source->GetNumRows(table) - offset;
	}

	if (!order.Empty())
	{
		// Fetch the rows from offset to limit.
		rows.resize(limit);
		for (int i = 0; i < limit; i++)
		{
			data_source->GetRow(rows[i], table, offset + i, fields);
		}

		// Now sort the rows, based on the ordering requirements.
		Rocket::Core::StringList order_parameters;
		Rocket::Core::StringUtilities::ExpandString(order_parameters, order);
		sort(rows.begin(), rows.end(), DataQuerySort(order_parameters));
	}
}
コード例 #5
0
void ElementDocumentWrapper::LoadScript(Rocket::Core::Stream* stream, const Rocket::Core::String& source_name)
{	
	// If theres a source, check if the code is already loaded and just reuse it
	if (!source_name.Empty())
	{		
		Rocket::Core::String module_name = Rocket::Core::String(source_name).Replace("/", "_");
		module_name = module_name.Replace("\\", "_");
		module_name = module_name.Replace(".py", "");

		PyObject* modules = PyImport_GetModuleDict();
		PyObject* merge_module = PyDict_GetItemString(modules, module_name.CString());

#ifdef ROCKET_DEBUG
		// In debug builds, force module to NULL so that scripts are always reloaded
		merge_module = NULL;
#else
		if (merge_module)
		{
			Py_INCREF(merge_module);
		}
#endif

		if (!merge_module)
		{
			// Compile the code as a python module
			Rocket::Core::String source_buffer;
			PreprocessCode(source_buffer, stream);		
		
			PyObject* code = Py_CompileString(source_buffer.CString(), source_name.CString(), Py_file_input);
			if (code)
			{
				merge_module = PyImport_ExecCodeModule((char*)module_name.CString(), code);
				Py_DECREF(code);
			}			
		}

		if (merge_module)
		{
			PyObject* dict = PyModule_GetDict(merge_module);
			PyDict_Merge(module_namespace, dict, 0);
			Py_DECREF(merge_module);
		}
		else
		{
			Rocket::Core::Python::Utilities::PrintError();			
		}
	}
	else
	{
		// Compile directly onto the python module
		Rocket::Core::String source_buffer;
		PreprocessCode(source_buffer, stream);
		
		PyObject* result = PyRun_String(source_buffer.CString(), Py_file_input, module_namespace, module_namespace);
		if ( !result )
		{
			Rocket::Core::Python::Utilities::PrintError();
		}
		else
		{
			Py_DECREF(result);
		}	
	}
}
コード例 #6
0
ファイル: rocket.cpp プロジェクト: Kangz/Unvanquished
Rocket::Core::String Rocket_QuakeToRML(const char* in, int parseFlags = 0) {
    const char* p;
    Rocket::Core::String out;
    Rocket::Core::String spanstr;
    bool span = false;
    bool spanHasContent = false;

    if (!*in) {
        return "";
    }

    for (p = in; p && *p; ++p) {
        if (*p == '<') {
            if (span && !spanHasContent) {
                spanHasContent = true;
                out.Append(spanstr);
            }
            out.Append("&lt;");
        } else if (*p == '>') {
            if (span && !spanHasContent) {
                spanHasContent = true;
                out.Append(spanstr);
            }
            out.Append("&gt;");
        } else if (*p == '&') {
            if (span && !spanHasContent) {
                spanHasContent = true;
                out.Append(spanstr);
            }
            out.Append("&amp;");
        } else if (*p == '\n') {
            out.Append(span && spanHasContent ? "</span><br />" : "<br />");
            span = false;
            spanHasContent = false;
        } else if (Q_IsColorString(p)) {
            if (span && spanHasContent) {
                out.Append("</span>");
                span = false;
                spanHasContent = false;
            }

            char rgb[32];
            int code = ColorIndex(*++p);

            Com_sprintf(rgb, sizeof(rgb), "<span style='color: #%02X%02X%02X;'>", (int) (g_color_table[code][0] * 255), (int) (g_color_table[code][1] * 255), (int) (g_color_table[code][2] * 255));

            // don't add the span yet, because it might be empty
            spanstr = rgb;

            span = true;
            spanHasContent = false;
        } else {
            if (span && !spanHasContent) {
                out.Append(spanstr);
                spanHasContent = true;
            }
            out.Append(*p);
        }
    }

    if (span && spanHasContent) {
        out.Append("</span>");
    }

    // ^^ -> ^
    while (out.Find("^^") != Rocket::Core::String::npos) {
        out = out.Replace("^^", "^");
    }

    if (parseFlags & RP_EMOTICONS) {
        // Parse emoticons
        size_t openBracket = 0;
        size_t closeBracket = 0;
        size_t currentPosition = 0;

        while (1) {
            Rocket::Core::String emoticon;
            const char* path;

            openBracket = out.Find("[", currentPosition);
            if (openBracket == Rocket::Core::String::npos) {
                break;
            }

            closeBracket = out.Find("]", openBracket);
            if (closeBracket == Rocket::Core::String::npos) {
                break;
            }

            emoticon = out.Substring(openBracket + 1, closeBracket - openBracket - 1);

            // Certain characters are invalid
            if (emoticon.Empty() || IsInvalidEmoticon(emoticon)) {
                currentPosition = closeBracket + 1;
                continue;
            }

            // TODO: Dont hardcode the extension.
            path = va("emoticons/%s.crn", emoticon.CString());
            if (FS_FOpenFileRead(path, nullptr, true)) {
                out.Erase(openBracket, closeBracket - openBracket + 1);
                path = va("<img class='trem-emoticon' src='/emoticons/%s' />",
                          emoticon.CString());
                out.Insert(openBracket, path);
                currentPosition = openBracket + strlen(path) + 1;
            } else {
                currentPosition = closeBracket + 1;
            }
        }
    }

    return out;
}