void URL::ConstructURL() const { url = ""; // Append the protocol. if (!protocol.Empty() && !host.Empty()) { url = protocol; url.Append("://"); } // Append login and password if (!login.Empty()) { url.Append( login ); if (!password.Empty()) { url.Append( ":" ); url.Append( password ); } url.Append( "@" ); } ROCKET_ASSERTMSG( password.Empty() || ( !password.Empty() && !login.Empty() ), "Can't have a password without a login!" ); // Append the host. url += host; // Only check ports if there is some host/protocol part if ( !url.Empty() ) { if (port > 0) { ROCKET_ASSERTMSG( !host.Empty(), "Can't have a port without a host!" ); char port_string[16]; sprintf(port_string, ":%d/", port); url.Append(port_string); } else { url.Append("/"); } } // Append the path. if (!path.Empty()) { url += path; } // Append the file name. url += file_name; // Append the extension. if (!extension.Empty()) { url.Append("."); url += extension; } // Append parameters if (!parameters.empty()) { url += "?"; url += GetQueryString(); } url_dirty = false; }
int main(int ROCKET_UNUSED(argc), char** ROCKET_UNUSED(argv)) #endif { // Generic OS initialisation, creates a window and attaches OpenGL. if (!Shell::Initialise("../Samples/basic/customlog/") || !Shell::OpenWindow("Custom File Handler Sample", true)) { Shell::Shutdown(); return -1; } // Rocket initialisation. ShellRenderInterfaceOpenGL opengl_renderer; Rocket::Core::SetRenderInterface(&opengl_renderer); opengl_renderer.SetViewport(1024,768); // Initialise our system interface to write the log messages to file. SystemInterface system_interface; Rocket::Core::SetSystemInterface(&system_interface); Rocket::Core::Initialise(); // Create the main Rocket context and set it on the shell's input layer. context = Rocket::Core::CreateContext("main", Rocket::Core::Vector2i(1024, 768)); if (context == NULL) { Rocket::Core::Shutdown(); Shell::Shutdown(); return -1; } Rocket::Debugger::Initialise(context); Input::SetContext(context); Shell::LoadFonts("../../assets/"); // Load a non-existent document to spawn an error message. Rocket::Core::ElementDocument* invalid_document = context->LoadDocument("../../assets/invalid.rml"); ROCKET_ASSERTMSG(invalid_document != NULL, "Testing ASSERT logging."); if (invalid_document != NULL) { invalid_document->RemoveReference(); invalid_document->Close(); } // Load and show the demo document. Rocket::Core::ElementDocument* document = context->LoadDocument("../../assets/demo.rml"); if (document != NULL) { document->Show(); document->RemoveReference(); } Shell::EventLoop(GameLoop); // Shutdown Rocket. context->RemoveReference(); Rocket::Core::Shutdown(); Shell::CloseWindow(); Shell::Shutdown(); return 0; }
// Called by Rocket when a texture is required by the library. bool ShellRenderInterfaceOpenGL::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); ROCKET_ASSERTMSG(buffer_size > sizeof(TGAHeader), "Texture file size is smaller than TGAHeader, file must be corrupt or otherwise invalid"); if(buffer_size <= sizeof(TGAHeader)) { file_interface->Close(file_handle); return false; } char* buffer = new char[buffer_size]; file_interface->Read(buffer, buffer_size, file_handle); file_interface->Close(file_handle); TGAHeader header; memcpy(&header, buffer, sizeof(TGAHeader)); int color_mode = header.bitsPerPixel / 8; int image_size = header.width * header.height * 4; // We always make 32bit textures if (header.dataType != 2) { Rocket::Core::Log::Message(Rocket::Core::Log::LT_ERROR, "Only 24/32bit uncompressed TGAs are supported."); return false; } // Ensure we have at least 3 colors if (color_mode < 3) { Rocket::Core::Log::Message(Rocket::Core::Log::LT_ERROR, "Only 24 and 32bit textures are supported"); return false; } const char* image_src = buffer + sizeof(TGAHeader); unsigned char* image_dest = new unsigned char[image_size]; // Targa is BGR, swap to RGB and flip Y axis for (long y = 0; y < header.height; y++) { long read_index = y * header.width * color_mode; long write_index = ((header.imageDescriptor & 32) != 0) ? read_index : (header.height - y - 1) * header.width * color_mode; for (long x = 0; x < header.width; x++) { image_dest[write_index] = image_src[read_index+2]; image_dest[write_index+1] = image_src[read_index+1]; image_dest[write_index+2] = image_src[read_index]; if (color_mode == 4) image_dest[write_index+3] = image_src[read_index+3]; else image_dest[write_index+3] = 255; write_index += 4; read_index += color_mode; } } texture_dimensions.x = header.width; texture_dimensions.y = header.height; bool success = GenerateTexture(texture_handle, image_dest, texture_dimensions); delete [] image_dest; delete [] buffer; return success; }