Skip to content
Browse files

Add orientation to the progress bar

  • Loading branch information...
1 parent 49d0c16 commit 553cbd62b3df48fee8aded824783cd2c7f0316a7 @SilouaneJ SilouaneJ committed Jun 26, 2012
View
16 Contrib/Include/Rocket/ProgressBar/ElementProgressBar.h
@@ -15,6 +15,14 @@ namespace ProgressBar {
@author Gauthier Billot
*/
+enum ProgressBarOrientation
+{
+ ProgressBarOrientationLeft = 0,
+ ProgressBarOrientationRight,
+ ProgressBarOrientationTop,
+ ProgressBarOrientationBottom
+};
+
class ROCKETPROGRESSBAR_API ElementProgressBar : public Core::Element
{
public:
@@ -50,13 +58,17 @@ class ROCKETPROGRESSBAR_API ElementProgressBar : public Core::Element
/// Called when source texture has changed.
void LoadTexture(int index);
+ /// Generate a quad vertices and indices.
+ void GenerateQuad(Rocket::Core::Vertex* vertices, int* indices, const Core::Vector2f& origin, const Core::Vector2f& dimensions, const Core::Colourb& colour, const Core::Vector2f& top_left_texcoord, const Core::Vector2f& bottom_right_texcoord, const Core::Vector2f& bottom_left_texcoord, const Core::Vector2f& top_right_texcoord);
+
Core::Texture texture[3];
// The geometries used to render this element.
- Core::Geometry left_geometry;
+ Core::Geometry start_geometry;
Core::Geometry center_geometry;
- Core::Geometry right_geometry;
+ Core::Geometry end_geometry;
bool geometry_dirty;
+ ProgressBarOrientation progressbar_orientation;
// The current value of the progress bar.
float value;
View
188 Contrib/Source/ProgressBar/ElementProgressBar.cpp
@@ -6,7 +6,7 @@ namespace Rocket {
namespace ProgressBar {
// Constructs a new ElementProgressBar. This should not be called directly; use the Factory instead.
-ElementProgressBar::ElementProgressBar(const Rocket::Core::String& tag) : Core::Element(tag), left_geometry(this), center_geometry(this), right_geometry(this), geometry_dirty(true), value(0.0f)
+ElementProgressBar::ElementProgressBar(const Rocket::Core::String& tag) : Core::Element(tag), start_geometry(this), center_geometry(this), end_geometry(this), geometry_dirty(true), value(0.0f), progressbar_orientation(ProgressBarOrientationLeft)
{
}
@@ -37,9 +37,9 @@ void ElementProgressBar::OnRender()
if(geometry_dirty)
GenerateGeometry();
- left_geometry.Render(GetAbsoluteOffset(Rocket::Core::Box::CONTENT));
+ start_geometry.Render(GetAbsoluteOffset(Rocket::Core::Box::CONTENT));
center_geometry.Render(GetAbsoluteOffset(Rocket::Core::Box::CONTENT));
- right_geometry.Render(GetAbsoluteOffset(Rocket::Core::Box::CONTENT));
+ end_geometry.Render(GetAbsoluteOffset(Rocket::Core::Box::CONTENT));
}
// Called when attributes on the element are changed.
@@ -65,7 +65,7 @@ void ElementProgressBar::OnPropertyChange(const Core::PropertyNameList& changed_
{
Element::OnPropertyChange(changed_properties);
- if (changed_properties.find("progress-left-src") != changed_properties.end())
+ if (changed_properties.find("progress-start-src") != changed_properties.end())
{
LoadTexture(0);
}
@@ -75,88 +75,176 @@ void ElementProgressBar::OnPropertyChange(const Core::PropertyNameList& changed_
LoadTexture(1);
}
- if (changed_properties.find("progress-right-src") != changed_properties.end())
+ if (changed_properties.find("progress-end-src") != changed_properties.end())
{
LoadTexture(2);
}
+
+ if (changed_properties.find("orientation") != changed_properties.end())
+ {
+ Core::String orientation_string = GetProperty< Core::String >("orientation");
+
+ if (orientation_string == "left")
+ {
+ progressbar_orientation = ProgressBarOrientationLeft;
+ }
+ else if (orientation_string =="right")
+ {
+ progressbar_orientation = ProgressBarOrientationRight;
+ }
+ else if (orientation_string == "top")
+ {
+ progressbar_orientation = ProgressBarOrientationTop;
+ }
+ else if (orientation_string == "bottom")
+ {
+ progressbar_orientation = ProgressBarOrientationBottom;
+ }
+
+ geometry_dirty = true;
+ }
}
// Called when value has changed.
void ElementProgressBar::GenerateGeometry()
{
const Core::Vector2f complete_extent = GetBox().GetSize(Core::Box::CONTENT);
- Core::Vector2f texcoords[2];
+ Core::Vector2f texcoords[4];
Core::Vector2i initial_part_size[3];
+ Core::Vector2f final_part_position[3];
Core::Vector2f final_part_size[3];
float progress_size;
- texcoords[0] = Core::Vector2f(0, 0);
- texcoords[1] = Core::Vector2f(1, 1);
-
initial_part_size[0] = texture[0].GetDimensions(GetRenderInterface());
initial_part_size[2] = texture[2].GetDimensions(GetRenderInterface());
- progress_size = value * (complete_extent.x - initial_part_size[0].x - initial_part_size[2].x);
-
- left_geometry.Release(true);
+ start_geometry.Release(true);
center_geometry.Release(true);
- right_geometry.Release(true);
+ end_geometry.Release(true);
+
+ texcoords[0] = Core::Vector2f(0, 0);
+ texcoords[1] = Core::Vector2f(1, 0);
+ texcoords[2] = Core::Vector2f(1, 1);
+ texcoords[3] = Core::Vector2f(0, 1);
+
+ switch(progressbar_orientation)
+ {
+ case ProgressBarOrientationLeft :
+ {
+ progress_size = value * (complete_extent.x - initial_part_size[0].x - initial_part_size[2].x);
+
+ final_part_size[0].y = final_part_size[1].y = final_part_size[2].y = float(complete_extent.y);
+ final_part_size[0].x = float(initial_part_size[0].x);
+ final_part_size[2].x = float(initial_part_size[2].x);
+ final_part_size[1].x = progress_size;
+
+ final_part_position[0] = Core::Vector2f(0, 0);
+ final_part_position[1] = Core::Vector2f(final_part_size[0].x, 0);
+ final_part_position[2] = Core::Vector2f(final_part_size[0].x + final_part_size[1].x, 0);
+ } break;
+
+ case ProgressBarOrientationRight :
+ {
+ float
+ offset;
+
+ progress_size = value * (complete_extent.x - initial_part_size[0].x - initial_part_size[2].x);
+ offset = (complete_extent.x - initial_part_size[0].x - initial_part_size[2].x) - progress_size;
+
+ final_part_size[0].y = final_part_size[1].y = final_part_size[2].y = float(complete_extent.y);
+ final_part_size[0].x = float(initial_part_size[0].x);
+ final_part_size[2].x = float(initial_part_size[2].x);
+ final_part_size[1].x = progress_size;
+
+ final_part_position[0] = Core::Vector2f(offset, 0);
+ final_part_position[1] = Core::Vector2f(final_part_size[0].x + offset, 0);
+ final_part_position[2] = Core::Vector2f(final_part_size[0].x + final_part_size[1].x + offset, 0);
+ } break;
+
+ case ProgressBarOrientationTop :
+ {
+ progress_size = value * (complete_extent.y - initial_part_size[0].y - initial_part_size[2].y);
+
+ final_part_size[0].x = final_part_size[1].x = final_part_size[2].x = float(complete_extent.x);
+ final_part_size[0].y = float(initial_part_size[0].y);
+ final_part_size[2].y = float(initial_part_size[2].y);
+ final_part_size[1].y = progress_size;
+
+ final_part_position[0] = Core::Vector2f(0, 0);
+ final_part_position[1] = Core::Vector2f(0, final_part_size[0].y);
+ final_part_position[2] = Core::Vector2f(0, final_part_size[0].y + final_part_size[1].y);
+ } break;
+
+ case ProgressBarOrientationBottom :
+ {
+ float
+ offset;
- final_part_size[0].y = final_part_size[1].y = final_part_size[2].y = float(complete_extent.y);
- final_part_size[0].x = float(initial_part_size[0].x);
- final_part_size[2].x = float(initial_part_size[2].x);
- final_part_size[1].x = progress_size;
+ progress_size = value * (complete_extent.y - initial_part_size[0].y - initial_part_size[2].y);
+ offset = (complete_extent.y - initial_part_size[0].y - initial_part_size[2].y) - progress_size;
+
+ final_part_size[0].x = final_part_size[1].x = final_part_size[2].x = float(complete_extent.x);
+ final_part_size[0].y = float(initial_part_size[0].y);
+ final_part_size[2].y = float(initial_part_size[2].y);
+ final_part_size[1].y = progress_size;
+
+ final_part_position[2] = Core::Vector2f(0, offset);
+ final_part_position[1] = Core::Vector2f(0, final_part_size[2].y + offset);
+ final_part_position[0] = Core::Vector2f(0, final_part_size[2].y + final_part_size[1].y + offset);
+ } break;
+ }
+
+
- // Generate left part geometry.
+ // Generate start part geometry.
{
- std::vector< Rocket::Core::Vertex >& vertices = left_geometry.GetVertices();
- std::vector< int >& indices = left_geometry.GetIndices();
+ std::vector< Rocket::Core::Vertex >& vertices = start_geometry.GetVertices();
+ std::vector< int >& indices = start_geometry.GetIndices();
vertices.resize(4);
indices.resize(6);
- Rocket::Core::GeometryUtilities::GenerateQuad(&vertices[0],
- &indices[0],
- Core::Vector2f(0, 0),
- final_part_size[0],
- Core::Colourb(255, 255, 255, 255),
- texcoords[0],
- texcoords[1]);
+ Core::GeometryUtilities::GenerateQuad(&vertices[0],
+ &indices[0],
+ final_part_position[0],
+ final_part_size[0],
+ Core::Colourb(255, 255, 255, 255),
+ texcoords[0],
+ texcoords[1]);
}
// Generate center part geometry.
- if (final_part_size[1].x > 0.0f)
{
std::vector< Rocket::Core::Vertex >& vertices = center_geometry.GetVertices();
std::vector< int >& indices = center_geometry.GetIndices();
vertices.resize(4);
indices.resize(6);
- Rocket::Core::GeometryUtilities::GenerateQuad(&vertices[0],
- &indices[0],
- Core::Vector2f(final_part_size[0].x, 0),
- final_part_size[1],
- Core::Colourb(255, 255, 255, 255),
- texcoords[0],
- texcoords[1]);
+ Core::GeometryUtilities::GenerateQuad(&vertices[0],
+ &indices[0],
+ final_part_position[1],
+ final_part_size[1],
+ Core::Colourb(255, 255, 255, 255),
+ texcoords[0],
+ texcoords[1]);
}
// Generate center part geometry.
{
- std::vector< Rocket::Core::Vertex >& vertices = right_geometry.GetVertices();
- std::vector< int >& indices = right_geometry.GetIndices();
+ std::vector< Rocket::Core::Vertex >& vertices = end_geometry.GetVertices();
+ std::vector< int >& indices = end_geometry.GetIndices();
vertices.resize(4);
indices.resize(6);
- Rocket::Core::GeometryUtilities::GenerateQuad(&vertices[0],
- &indices[0],
- Core::Vector2f(final_part_size[0].x + final_part_size[1].x, 0),
- final_part_size[2],
- Core::Colourb(255, 255, 255, 255),
- texcoords[0],
- texcoords[1]);
+ Core::GeometryUtilities::GenerateQuad(&vertices[0],
+ &indices[0],
+ final_part_position[2],
+ final_part_size[2],
+ Core::Colourb(255, 255, 255, 255),
+ texcoords[0],
+ texcoords[1]);
}
geometry_dirty = false;
@@ -172,15 +260,15 @@ void ElementProgressBar::LoadTexture(int index)
{
case 0:
{
- Core::String source = GetProperty< Core::String >("progress-left-src");
+ Core::String source = GetProperty< Core::String >("progress-start-src");
if (!texture[0].Load(source, source_url.GetPath()))
{
- left_geometry.SetTexture(NULL);
+ start_geometry.SetTexture(NULL);
return;
}
- left_geometry.SetTexture(&texture[0]);
+ start_geometry.SetTexture(&texture[0]);
break;
}
@@ -200,15 +288,15 @@ void ElementProgressBar::LoadTexture(int index)
case 2:
{
- Core::String source = GetProperty< Core::String >("progress-right-src");
+ Core::String source = GetProperty< Core::String >("progress-end-src");
if (!texture[2].Load(source, source_url.GetPath()))
{
- right_geometry.SetTexture(NULL);
+ end_geometry.SetTexture(NULL);
return;
}
- right_geometry.SetTexture(&texture[2]);
+ end_geometry.SetTexture(&texture[2]);
break;
}
}

0 comments on commit 553cbd6

Please sign in to comment.
Something went wrong with that request. Please try again.