// Sizes the box to the element's inherent size. bool ElementImage::GetIntrinsicDimensions(Vector2f& _dimensions) { // Check if we need to reload the texture. if (texture_dirty) LoadTexture(); // Calculate the x dimension. if (HasAttribute("width")) dimensions.x = GetAttribute< float >("width", -1); else if (using_coords) dimensions.x = (float) (coords[2] - coords[0]); else dimensions.x = (float) texture.GetDimensions(GetRenderInterface()).x; // Calculate the y dimension. if (HasAttribute("height")) dimensions.y = GetAttribute< float >("height", -1); else if (using_coords) dimensions.y = (float) (coords[3] - coords[1]); else dimensions.y = (float) texture.GetDimensions(GetRenderInterface()).y; // Return the calculated dimensions. If this changes the size of the element, it will result in // a 'resize' event which is caught below and will regenerate the geometry. _dimensions = dimensions; return true; }
// Sets the clipping region from an element and its ancestors. bool ElementUtilities::SetClippingRegion(Element* element, Context* context) { Rocket::Core::RenderInterface* render_interface = NULL; if (element) { render_interface = element->GetRenderInterface(); if (!context) context = element->GetContext(); } else if (context) { render_interface = context->GetRenderInterface(); if (!render_interface) render_interface = GetRenderInterface(); } if (!render_interface || !context) return false; Vector2i clip_origin, clip_dimensions; bool clip = element && GetClippingRegion(clip_origin, clip_dimensions, element); Vector2i current_origin; Vector2i current_dimensions; bool current_clip = context->GetActiveClipRegion(current_origin, current_dimensions); if (current_clip != clip || (clip && (clip_origin != current_origin || clip_dimensions != current_dimensions))) { context->SetActiveClipRegion(clip_origin, clip_dimensions); ApplyActiveClipRegion(context, render_interface); } return true; }
void ElementImage::GenerateGeometry() { // Release the old geometry before specifying the new vertices. geometry.Release(true); std::vector< Rocket::Core::Vertex >& vertices = geometry.GetVertices(); std::vector< int >& indices = geometry.GetIndices(); vertices.resize(4); indices.resize(6); // Generate the texture coordinates. Vector2f texcoords[2]; if (using_coords) { Vector2f texture_dimensions((float) texture.GetDimensions(GetRenderInterface()).x, (float) texture.GetDimensions(GetRenderInterface()).y); if (texture_dimensions.x == 0) texture_dimensions.x = 1; if (texture_dimensions.y == 0) texture_dimensions.y = 1; texcoords[0].x = (float) coords[0] / texture_dimensions.x; texcoords[0].y = (float) coords[1] / texture_dimensions.y; texcoords[1].x = (float) coords[2] / texture_dimensions.x; texcoords[1].y = (float) coords[3] / texture_dimensions.y; } else { texcoords[0] = Vector2f(0, 0); texcoords[1] = Vector2f(1, 1); } const Property* element_colour = GetProperty(BACKGROUND_COLOR); float opacity = GetProperty<float>(OPACITY); Colourb quad_colour = Colourb(255, 255, 255); if (element_colour) { Colourb background_colour = element_colour->Get<Colourb>(); // Should be a non-transparent background if (background_colour.alpha != 0) quad_colour = background_colour; } // Apply opacity quad_colour.alpha = (byte)(opacity * (float)quad_colour.alpha); Rocket::Core::GeometryUtilities::GenerateQuad(&vertices[0], // vertices to write to &indices[0], // indices to write to Vector2f(0, 0), // origin of the quad GetBox().GetSize(Rocket::Core::Box::CONTENT), // size of the quad quad_colour, // colour of the vertices texcoords[0], // top-left texture coordinate texcoords[1]); // top-right texture coordinate geometry_dirty = false; }
void Geometry::Render(const Vector2f& translation) { RenderInterface* render_interface = GetRenderInterface(); if (render_interface == NULL) return; // Render our compiled geometry if possible. if (compiled_geometry) { render_interface->RenderCompiledGeometry(compiled_geometry, translation); } // Otherwise, if we actually have geometry, try to compile it if we haven't already done so, otherwise render it in // immediate mode. else { if (vertices.empty() || indices.empty()) return; if (!compile_attempted) { if (!fixed_texcoords) { fixed_texcoords = true; if (!read_texel_offset) { read_texel_offset = true; texel_offset.x = render_interface->GetHorizontalTexelOffset(); texel_offset.y = render_interface->GetVerticalTexelOffset(); } // Add a half-texel offset if required. if (texel_offset.x != 0 || texel_offset.y != 0) { for (size_t i = 0; i < vertices.size(); ++i) vertices[i].position += texel_offset; } } compile_attempted = true; compiled_geometry = render_interface->CompileGeometry(&vertices[0], (int) vertices.size(), &indices[0], (int) indices.size(), texture != NULL ? texture->GetHandle(GetRenderInterface()) : NULL); // If we managed to compile the geometry, we can clear the local copy of vertices and indices and // immediately render the compiled version. if (compiled_geometry) { render_interface->RenderCompiledGeometry(compiled_geometry, translation); return; } } // Either we've attempted to compile before (and failed), or the compile we just attempted failed; either way, // render the uncompiled version. render_interface->RenderGeometry(&vertices[0], (int) vertices.size(), &indices[0], (int) indices.size(), texture != NULL ? texture->GetHandle(GetRenderInterface()) : NULL, translation); } }
void InitializeAntTweakBar() { auto& input = GetInputInterface(); input.RegisterOnInputQueueEntry(HandleInputQueueEntry); auto& render = GetRenderInterface(); render.RegisterOnFrame(OnFrameAntTweakBar); render.RegisterOnResize(OnResizeAntTweakBar); render.RegisterOnInitializeGui(OnInitializeAntTweakBarGui); render.RegisterOnCleanupGui(OnCleanupAntTweakBarGui); render.RegisterOnSetGuiVisibility(SetAllTweakBarVisibility); RegisterOnUnloadPlugins(OnUnloadPlugins); }
void ElementImage::GenerateGeometry() { // Release the old geometry before specifying the new vertices. geometry.Release(true); std::vector< Rocket::Core::Vertex >& vertices = geometry.GetVertices(); std::vector< int >& indices = geometry.GetIndices(); vertices.resize(4); indices.resize(6); // Generate the texture coordinates. Vector2f texcoords[2]; if (using_coords) { Vector2f texture_dimensions((float) texture.GetDimensions(GetRenderInterface()).x, (float) texture.GetDimensions(GetRenderInterface()).y); if (texture_dimensions.x == 0) texture_dimensions.x = 1; if (texture_dimensions.y == 0) texture_dimensions.y = 1; texcoords[0].x = (float) coords[0] / texture_dimensions.x; texcoords[0].y = (float) coords[1] / texture_dimensions.y; texcoords[1].x = (float) coords[2] / texture_dimensions.x; texcoords[1].y = (float) coords[3] / texture_dimensions.y; } else { texcoords[0] = Vector2f(0, 0); texcoords[1] = Vector2f(1, 1); } Colourb colour(255, 255,255,255); const Property* property = GetLocalProperty(COLOR); if (property) colour = property->value.Get<Colourb>(); Rocket::Core::GeometryUtilities::GenerateQuad(&vertices[0], // vertices to write to &indices[0], // indices to write to Vector2f(0, 0), // origin of the quad GetBox().GetSize(Rocket::Core::Box::CONTENT), // size of the quad colour, // colour of the vertices texcoords[0], // top-left texture coordinate texcoords[1]); // top-right texture coordinate geometry_dirty = false; }
/// Called when source texture has changed. void ElementCircularBar::LoadTexture() { Core::ElementDocument* document = GetOwnerDocument(); Core::URL source_url(document == NULL ? "" : document->GetSourceURL()); Core::String source = GetProperty< Core::String >("gauge-src"); if (!gauge_texture.Load(source, source_url.GetPath())) { gauge_geometry.SetTexture(NULL); return; } gauge_geometry.SetTexture(&gauge_texture); actual_gauge_extent = gauge_texture.GetDimensions(GetRenderInterface()); }
void Geometry::Release(bool clear_buffers) { if (compiled_geometry) { GetRenderInterface()->ReleaseCompiledGeometry(compiled_geometry); compiled_geometry = NULL; } compile_attempted = false; if (clear_buffers) { vertices.clear(); indices.clear(); fixed_texcoords = false; } }
// Returns the floating-point value of a numerical property from a dictionary of properties. float Decorator::ResolveProperty(const PropertyDictionary& properties, const String& name, float base_value) const { const Property* property = properties.GetProperty(name); if (property == NULL) { ROCKET_ERROR; return 0; } // Need to include em! if (property->unit & Property::RELATIVE_UNIT) return base_value * property->value.Get< float >() * 0.01f; if (property->unit & Property::NUMBER || property->unit & Property::PX) return property->value.Get< float >(); if (property->unit & Property::GSP) return property->value.Get< float >() * Rocket::Core::GetRenderInterface()->GetPixelScale(); // Values based on pixels-per-inch. if (property->unit & Property::PPI_UNIT) { float inch = property->value.Get< float >() * GetRenderInterface()->GetPixelsPerInch(); if (property->unit & Property::INCH) // inch return inch; if (property->unit & Property::CM) // centimeter return inch / 2.54f; if (property->unit & Property::MM) // millimeter return inch / 25.4f; if (property->unit & Property::PT) // point return inch / 72.0f; if (property->unit & Property::PC) // pica return inch / 6.0f; } ROCKET_ERROR; return 0; }