@@ -1,82 +1,146 @@
#include "Container.h"

/**
* Initializes a container
*
* @date 2015-02-26
*
* @revisions
*
* @designer
*
* @programmer Jonathan Chu
*
* @return initializer
*/
Container::Container(BGO* parent, BGO* firstBGO, BGO* secondBGO, sf::Vector2f theScale, bool theOrientation)
{
parent.add(this);
A = firstBGO;
B = secondBGO;
scale = theScale;
orientation = theOrientation
}

/**
* Sets the separator for the containers
*
* @date 2015-02-26
*
* @revisions
*
* @designer
*
* @programmer Jonathan Chu
*
* @return void
*/
void Container::setSeperator(SGO* theSeparator)
namespace GUI
{
separator = theSeparator
}
/**
* Initializes a container
*
* @date 2015-02-26
*
* @revisions
*
* @designer
*
* @programmer Jonathan Chu
*
* @return initializer
*/
Container::Container(BGO* parent, SGO* firstSGO, SGO* secondSGO, sf::Vector2f theScale, orientation theOrientation)
{
parent->add(*this);
A = firstSGO;
B = secondSGO;
scale = theScale;
orient = theOrientation;
ratio = 0.5f;
separator = NULL;

add(*A);
add(*B);
}

/**
* Sets the ratio of the container
*
* @date 2015-02-26
*
* @revisions
*
* @designer
*
* @programmer Jonathan Chu
*
* @return void
*/
void Container::setRatio(int theRatio)
{
ratio = theRatio;
}
/**
* Sets the separator for the containers
*
* @date 2015-02-26
*
* @revisions
*
* @designer
*
* @programmer Jonathan Chu
*
* @return void
*/
void Container::setSeperator(SGO* theSeparator)
{
separator = theSeparator;
}

/**
* Sets the orientation of the container
*
* @date 2015-02-26
*
* @revisions
*
* @designer
*
* @programmer Jonathan Chu
*
* @return void
*/
void Container::setOrientation(bool theOrientation)
{
orientation = theOrientation;
}
/**
* Sets the ratio of the container
*
* @date 2015-02-26
*
* @revisions
*
* @designer
*
* @programmer Jonathan Chu
*
* @return void
*/
void Container::setRatio(float theRatio)
{
ratio = theRatio;
}

void Container::pack()
{
//dont know what this is suppose to do
/**
* Sets the orientation of the container
*
* @date 2015-02-26
*
* @revisions
*
* @designer
*
* @programmer Jonathan Chu
*
* @return void
*/
void Container::setOrientation(orientation theOrientation)
{
orient = theOrientation;
}

/**
* Sets the position of the container
*
* @date 2015-03-11
*
* @revisions
*
* @designer
*
* @programmer Lewis Scott
*
* @return void
*/
void Container::setPosition(sf::Vector2f newpos)
{
pos = newpos;
}

/**
* Sets the orientation of the container
*
* @date 2015-03-11
*
* @revisions
*
* @designer
*
* @programmer Lewis Scott
*
* @return void
*/
void Container::pack()
{
bool side = (orient==HORIZONTAL);
float sep_size = 0.0f;

if(separator != NULL)
sep_size = side?separator->operator()().getScale().x:separator->operator()().getScale().y;

float total = (side?scale.x:scale.y) - sep_size;
float side_size = total*(ratio);

// Scale and position A
sf::Vector2f size_a((side?side_size:A->operator()().getScale().x), (side?A->operator()().getScale().y:side_size));
A->operator()().setScale(size_a);
A->operator()().setPosition(pos);

// Position separator
sf::Vector2f offset = pos;
offset += sf::Vector2f(side?side_size:0.0f, side?0.0f:side_size);
separator->operator()().setPosition(offset);

// Scale and position B
side_size = total-side_size;
sf::Vector2f size_b(side?side_size:B->operator()().getScale().x, side?B->operator()().getScale().y:side_size);
offset += sf::Vector2f(side?(separator->operator()().getScale().x):0.0f, side?0.0f:(separator->operator()().getScale().y));
B->operator()().setScale(size_b);
B->operator()().setPosition(offset);
}
}
@@ -1,23 +1,31 @@
#ifndef GUI_CONTAINER
#define GUI_CONTAINER

#include "../graphics/object/BGO.h"
#include "../graphics/object/SGO.h"

namespace GUI
{
typedef enum orientation{ VERTICAL, HORIZONTAL } orientation;

class Container : BGO
{
public:
Container(BGO* parent, BGO* firstBGO, BGO* secondBGO, sf::Vector2f theScale, bool theOrientation);
Container(BGO* parent, SGO* firstSGO, SGO* secondSGO, sf::Vector2f theScale, orientation theOrientation);
void setSeperator(SGO* theSeparator);
void setRatio(int theRatio);
void setOrientation(bool theOrientation);
void setRatio(float theRatio);
void setOrientation(orientation theOrientation);
void setPosition(sf::Vector2f newpos);
void pack();
private:
BGO* A, B;
SGO* seperator;
SGO* A;
SGO* B;
SGO* separator;
sf::Vector2f scale;
int ratio;
bool orientation;
float ratio;
orientation orient;
sf::Vector2f pos;
};
}

#endif
#endif
@@ -1,59 +1,70 @@

#include "label.h"
#include "Label.h"

/**
* Initializes a label
*
* @date 2015-02-27
*
* @revisions
*
* @designer
*
* @programmer Jonathan Chu
*
* @return initializer
*/
Label::Label(BGO* parent, SGO* theBackground, std::string theText)
namespace GUI
{
parent.add(this);
theBackground = false;
background = theBackground;
data = theText;
}
/**
* Initializes a label
*
* @date 2015-02-27
*
* @revisions
*
* @designer
*
* @programmer Jonathan Chu
*
* @return initializer
*/
Label::Label(BGO* parent, SGO* theBackground, std::string theText)
{
parent->add(*this);
back_enabled = true;
background = theBackground;
add(*background);

TGO::operator()().setString(theText);
}

/**
* Toggles the background between on/off
*
* @date 2015-02-27
*
* @revisions
*
* @designer
*
* @programmer Jonathan Chu
*
* @return void
*/
void Label::toggleBackground(bool toggled)
{
theBackground = toggled;
}
/**
* Toggles the background between on/off
*
* @date 2015-02-27
*
* @revisions
*
* @designer
*
* @programmer Jonathan Chu
*
* @return void
*/
void Label::toggleBackground(bool toggled)
{
back_enabled = toggled;
}

/**
* Sets the offset based on the offset given
*
* @date 2015-02-27
*
* @revisions
*
* @designer
*
* @programmer Jonathan Chu
*
* @return void
*/
void Label::setOffset(sf::Vector2f theOffset)
{
offset = theOffset;
}
/**
* Sets the offset based on the offset given
*
* @date 2015-02-27
*
* @revisions
*
* @designer
*
* @programmer Jonathan Chu
*
* @return void
*/
void Label::setOffset(sf::Vector2f theOffset)
{
offset = theOffset;
background->operator()().move(offset);
}

void Label::setText(std::string text)
{
TGO::operator()().setString(text);
}
}
@@ -1,25 +1,23 @@
#ifndef LABEL
#define LABEL

/*
BGO - Base Game Object
SGO - Sprite Game Object
TGO - Text Game Object
*/
#include "../graphics/object/TGO.h"
#include "../graphics/object/SGO.h"


namespace GUI

{
class Label : TGO
{
public:
Label(BGO* parent, SGO* theBackground, std::string theText);
void toggleBackground(bool toggled);
void setOffset(sf::Vector2f theOffset);
void setText(std::string text);
private:
SGO* background;
sf::Vector2f offset;
bool theBackground;
bool back_enabled;
};
}