// 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; }
// 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; }
void UI_Main::M_Menu_Open_Cmd_f_( bool modal ) { int i; if( !self ) { return; } if( trap::Cmd_Argc() < 2 ) { return; } Rocket::Core::URL url; url.SetFileName( trap::Cmd_Argv( 1 ) ); url.SetExtension( "rml" ); for( i = 2; i < trap::Cmd_Argc() - 1; i += 2 ) { url.SetParameter( trap::Cmd_Argv( i ), trap::Cmd_Argv( i + 1 ) ); } Rocket::Core::String urlString = url.GetURL(); //Com_Printf( "UI_Main::M_Menu_Open_f %s\n", urlString.CString() ); NavigationStack *nav = self->navigations[UI_CONTEXT_MAIN].front(); if( !nav ) { return; } nav->pushDocument( urlString.CString(), modal ); self->showUI( true ); }
// Gets the markup and content of the element. void ElementDataGrid::GetInnerRML(Rocket::Core::String& content) const { // The only content we have is the columns, and inside them the header elements. for (size_t i = 0; i < columns.size(); i++) { Core::Element* header_element = header->GetChild((int)i); Rocket::Core::String column_fields; for (size_t j = 0; j < columns[i].fields.size(); j++) { if (j != columns[i].fields.size() - 1) { column_fields.Append(","); } column_fields.Append(columns[i].fields[j]); } Rocket::Core::String width_attribute = header_element->GetAttribute<Rocket::Core::String>("width", ""); content.Append(Rocket::Core::String(column_fields.Length() + 32, "<col fields=\"%s\"", column_fields.CString())); if (!width_attribute.Empty()) content.Append(Rocket::Core::String(width_attribute.Length() + 32, " width=\"%s\"", width_attribute.CString())); content.Append(">"); header_element->GetInnerRML(content); content.Append("</col>"); } }
void ElementStyleProxy::SetAttr(const char* _key, const char* value) { // Switch underscores to dashes, as the script interface can't use -'s Rocket::Core::String key = Rocket::Core::String(_key).Replace("_", "-"); element->SetProperty(key.CString(), value); }
void UI_Main::M_Menu_Open_f( void ) { int i; if( !self ) return; if( trap::Cmd_Argc() < 2 ) return; Rocket::Core::URL url; url.SetFileName( trap::Cmd_Argv( 1 ) ); url.SetExtension( "rml" ); for( i = 2; i < trap::Cmd_Argc() - 1; i += 2 ) { url.SetParameter( trap::Cmd_Argv( i ), trap::Cmd_Argv( i+1 ) ); } Rocket::Core::String urlString = url.GetURL(); //Com_Printf( "UI_Main::M_Menu_Open_f %s\n", urlString.CString() ); NavigationStack *nav = self->getNavigator(); if( !nav ) return; nav->pushDocument( urlString.CString() ); self->showUI( true ); }
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 ); }
bool ShellSystemInterface::LogMessage(Rocket::Core::Log::Type type, const Rocket::Core::String& message) { #ifdef _WIN32 OutputDebugStringA(message.CString()); OutputDebugStringA("\n"); #endif printf("[ROCK] %s\n", message.CString()); return true; }
virtual void GetParameter(const char* parameter, char* buffer, size_t buffer_size ) const { Rocket::Core::String strvalue = ""; if( m_Event.GetParameters() ) { m_Event.GetParameters()->GetInto( parameter, strvalue ); } strcpy_s( buffer, buffer_size, strvalue.CString() ); }
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++; } }
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); } }
unsigned short UiObjectQuantityPicker::GetQuantity(void) const { Rocket::Controls::ElementFormControl* control = reinterpret_cast<Rocket::Controls::ElementFormControl*>(_line_edit); Rocket::Core::String string = control->GetValue(); std::stringstream stream; unsigned short amount; stream << string.CString(); stream >> amount; return (amount); }
void* GetElementUserData(Rocket::Core::Element *element, const Rocket::Core::String& key) { void *result = NULL; if (element != NULL) { Rocket::Core::Variant *value = element->GetAttribute(key); if (value != NULL) { Rocket::Core::String strval; value->GetInto(strval); sscanf(strval.CString(), "%x", &result); } } return result; }
void MainMenu::processSingleplayerCreate(Rocket::Core::Event& event) { const Rocket::Core::String& id = event.GetCurrentElement()->GetId(); if (id == "back") { m_mainMenuSingleplayerCreate->Hide(); } else if (id == "start") { Rocket::Core::Element* playerNameInput = m_mainMenuSingleplayerCreate->GetElementById("playerName"); Rocket::Core::String playerName = playerNameInput->GetAttribute("value")->Get<Rocket::Core::String>(); hideSubmenus(); m_client->startSinglePlayer(playerName.CString()); } }
void FormSignalListener::ProcessEvent(Rocket::Core::Event& event) { const Rocket::Core::Dictionary *d = event.GetParameters(); UISignalData *data = new UISignalData(); Rocket::Core::String s; Rocket::Core::Variant *v; int n; while (d->Iterate(n, s, v)) { Rocket::Core::String val = v->Get<Rocket::Core::String>(); data->set(string(s.CString()), string(val.CString())); } PyScripting::getInstance()->broadcast(signal_name,{data}, true, true); }
Rocket::Core::String ElementStyleProxy::GetAttr(const char* _key) { // Switch underscores to dashes, as the script interface can't use -'s Rocket::Core::String key = Rocket::Core::String(_key).Replace("_", "-"); const Property* property = element->GetProperty(key.CString()); if ( !property ) { Rocket::Core::String message(128, "Invalid style property %s", _key); PyErr_SetString(PyExc_KeyError, message.CString()); python::throw_error_already_set(); } return property->ToString(); }
void GUIElement::GetAttribute(const char* attribute, char* buffer, size_t buffer_size ) const { if( buffer_size && buffer ) { buffer[0] = 0; Rocket::Core::Variant* pVar = m_pElement->GetAttribute(attribute); if( pVar ) { Rocket::Core::String strvalue; pVar->GetInto( strvalue ); strcpy_s( buffer, buffer_size, strvalue.CString() ); } } }
virtual void GetParameter(const char* parameter, char* buffer, size_t buffer_size ) const { Rocket::Core::String strvalue = ""; if( m_Event.GetParameters() ) { m_Event.GetParameters()->GetInto( parameter, strvalue ); } #ifdef _WIN32 strcpy_s( buffer, buffer_size, strvalue.CString() ); #else strncpy( buffer, strvalue.CString(), buffer_size); //not quite the same, but similar safe effect. #endif }
void UiObjectQuantityPicker::Accepted(Rocket::Core::Event&) { Rocket::Controls::ElementFormControl* control = reinterpret_cast<Rocket::Controls::ElementFormControl*>(_line_edit); Rocket::Core::String string = control->GetValue(); std::stringstream stream; unsigned short amount; stream << string.CString(); stream >> amount; if (amount <= _max_quantity) { QuantityPicked.Emit(amount); Hide(); } }
bool RocketSFMLSystemInterface::LogMessage(Rocket::Core::Log::Type type, const Rocket::Core::String& message) { std::string Type; switch(type) { case Rocket::Core::Log::LT_ALWAYS: Type = "[Always]"; break; case Rocket::Core::Log::LT_ERROR: Type = "[Error]"; break; case Rocket::Core::Log::LT_ASSERT: Type = "[Assert]"; break; case Rocket::Core::Log::LT_WARNING: Type = "[Warning]"; break; case Rocket::Core::Log::LT_INFO: Type = "[Info]"; break; case Rocket::Core::Log::LT_DEBUG: Type = "[Debug]"; break; }; printf("%s - %s\n", Type.c_str(), message.CString()); return true; };
/// Fetches the contents of one row of a table within the data source. /// @param[out] row The list of values in the table. /// @param[in] table The name of the table to query. /// @param[in] row_index The index of the desired row. /// @param[in] columns The list of desired columns within the row. void LuaDataSource::GetRow(Rocket::Core::StringList& row, const Rocket::Core::String& table, int row_index, const Rocket::Core::StringList& columns) { if(getRowRef == LUA_NOREF || getRowRef == LUA_REFNIL) return; //setup the call Interpreter::BeginCall(getRowRef); lua_State* L = Interpreter::GetLuaState(); lua_pushstring(L,table.CString()); lua_pushinteger(L,row_index); lua_newtable(L); int index = 0; for(Rocket::Core::StringList::const_iterator itr = columns.begin(); itr != columns.end(); ++itr) { lua_pushstring(L,itr->CString()); lua_rawseti(L,-2,index++); } Interpreter::ExecuteCall(3,1); //3 parameters, 1 return. After here, the top of the stack contains the return value int res = lua_gettop(L); if(lua_type(L,res) == LUA_TTABLE) { lua_pushnil(L); while(lua_next(L,res) != 0) { //key at -2, value at -1 row.push_back(luaL_checkstring(L,-1)); lua_pop(L,1); //pops value, leaves key for next iteration } lua_pop(L,1); //pop key } else Log::Message(Log::LT_WARNING, "Lua: DataSource.GetRow must return a table, the function it called returned a %s", lua_typename(L,res)); Interpreter::EndCall(1); }
bool UI_RenderInterface::LoadTexture(Rocket::Core::TextureHandle & texture_handle, Rocket::Core::Vector2i & texture_dimensions, const Rocket::Core::String & source) { shader_t *shader; Rocket::Core::String source2( source ); if( source2[0] == '/' ) source2.Erase( 0, 1 ); shader = trap::R_RegisterPic( source2.CString() ); if( !shader ) { Com_Printf(S_COLOR_RED"Warning: RenderInterface couldnt load pic %s!\n", source.CString() ); return false; } trap::R_GetShaderDimensions( shader, &texture_dimensions.x, &texture_dimensions.y ); AddShaderToCache( source2 ); texture_handle = TextureHandle( shader ); // Com_Printf( "RenderInterface::LoadTexture %s successful (dimensions %dx%d\n", source.CString(), texture_dimensions.x, texture_dimensions.y ); return true; }
void MainMenu::processMultiplayerHost(Rocket::Core::Event& event) { const Rocket::Core::String& id = event.GetCurrentElement()->GetId(); if (id == "back") { m_mainMenuMultiplayerHost->Hide(); } if (id == "host") { Rocket::Core::Element* playerNameInput = m_mainMenuMultiplayerHost->GetElementById("playerName"); Rocket::Core::String playerName = playerNameInput->GetAttribute("value")->Get<Rocket::Core::String>(); Rocket::Core::Element* portInput = m_mainMenuMultiplayerHost->GetElementById("port"); Rocket::Core::String port = portInput->GetAttribute("value")->Get<Rocket::Core::String>(); hideSubmenus(); m_client->startMultiplayerHost(playerName.CString(), atoi(port.CString())); } }
void RocketMenuPlugin::DoItemAction(ItemAction action, Rocket::Core::ElementDocument *document, const Rocket::Core::String& id) { Rocket::Core::Element *element = document->GetElementById(id); if (element != NULL) { DoItemAction(action, element); } else { printf("[ROCK] RocketMenuPlugin::DoItemAction: element not found: %s\n", id.CString()); } }
void RocketMenuPlugin::DoItemAction(ItemAction action, Rocket::Core::Context *context, const Rocket::Core::String& docId, const Rocket::Core::String& elementId) { Rocket::Core::ElementDocument *doc = context->GetDocument(docId); if (doc != NULL) { DoItemAction(action, doc, elementId); } else { printf("[ROCK] RocketMenuPlugin::DoItemAction: document not found: %s\n", docId.CString()); } }
Rocket::Core::FileHandle FileInterfaceOgre3D::Open(const Rocket::Core::String& path) { DataStreamPtr stream = ResourceGroupManager::getSingleton().openResource(path.CString()); if (stream.isNull()) return 0; return (Rocket::Core::FileHandle)(new DataStreamPtr(stream)); }
Rocket::Core::FileHandle FileSystemInterface::Open(const Rocket::Core::String& path) { std::string npath = GameState::GetInstance().GetSkinFile(path.CString()); FILE* F = fopen(npath.c_str(), "r"); return (Rocket::Core::FileHandle) F; }
// 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; }
int RocketSystemInterface::TranslateString(Rocket::Core::String& translated, const Rocket::Core::String& input) { SCP_string lcl_translated; lcl_ext_localize(input.CString(), lcl_translated); translated = lcl_translated.c_str(); return 0; // Everything is translated now }
void GUIElement::GetAttribute(const char* attribute, char* buffer, size_t buffer_size ) const { if( buffer_size && buffer ) { buffer[0] = 0; Rocket::Core::Variant* pVar = m_pElement->GetAttribute(attribute); if( pVar ) { Rocket::Core::String strvalue; pVar->GetInto( strvalue ); #ifdef _WIN32 strcpy_s( buffer, buffer_size, strvalue.CString() ); #else strncpy( buffer, strvalue.CString(), buffer_size); //not quite the same, but similar safe effect. #endif } } }