Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/WolfireGames/overgrowth.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'Source/GUI/IMUI/im_divider.cpp')
-rw-r--r--Source/GUI/IMUI/im_divider.cpp410
1 files changed, 181 insertions, 229 deletions
diff --git a/Source/GUI/IMUI/im_divider.cpp b/Source/GUI/IMUI/im_divider.cpp
index c34523c0..527d9cf5 100644
--- a/Source/GUI/IMUI/im_divider.cpp
+++ b/Source/GUI/IMUI/im_divider.cpp
@@ -1,8 +1,8 @@
//-----------------------------------------------------------------------------
// Name: im_divider.cpp
// Developer: Wolfire Games LLC
-// Description: Specialized container element class for creating adhoc GUIs
-// as part of the UI tools
+// Description: Specialized container element class for creating adhoc GUIs
+// as part of the UI tools
// License: Read below
//-----------------------------------------------------------------------------
//
@@ -34,14 +34,13 @@
* @param _orientation The orientation of the container
*
*/
-IMDivider::IMDivider( std::string const& name, DividerOrientation _orientation ) :
- IMElement(name),
- contentsNum(0),
- contentsXAlignment(CACenter),
- contentsYAlignment(CACenter),
- orientation(DOVertical) // vertical by default
+IMDivider::IMDivider(std::string const& name, DividerOrientation _orientation) : IMElement(name),
+ contentsNum(0),
+ contentsXAlignment(CACenter),
+ contentsYAlignment(CACenter),
+ orientation(DOVertical) // vertical by default
{
- IMrefCountTracker.addRefCountObject( getElementTypeName() );
+ IMrefCountTracker.addRefCountObject(getElementTypeName());
orientation = _orientation;
}
@@ -53,14 +52,13 @@ IMDivider::IMDivider( std::string const& name, DividerOrientation _orientation )
* @param _orientation The orientation of the container
*
*/
-IMDivider::IMDivider( DividerOrientation _orientation ) :
- IMElement(),
- contentsNum(0),
- contentsXAlignment(CACenter),
- contentsYAlignment(CACenter),
- orientation(DOVertical) // vertical by default
+IMDivider::IMDivider(DividerOrientation _orientation) : IMElement(),
+ contentsNum(0),
+ contentsXAlignment(CACenter),
+ contentsYAlignment(CACenter),
+ orientation(DOVertical) // vertical by default
{
- IMrefCountTracker.addRefCountObject( getElementTypeName() );
+ IMrefCountTracker.addRefCountObject(getElementTypeName());
orientation = _orientation;
}
@@ -82,13 +80,13 @@ std::string IMDivider::getElementTypeName() {
* @param _parent New parent
*
*/
-void IMDivider::setOwnerParent( IMGUI* _owner, IMElement* _parent ) {
+void IMDivider::setOwnerParent(IMGUI* _owner, IMElement* _parent) {
owner = _owner;
parent = _parent;
-
+
// Simply pass this on to the children
- for(auto & container : containers) {
- container->setOwnerParent( owner, this );
+ for (auto& container : containers) {
+ container->setOwnerParent(owner, this);
}
}
@@ -101,17 +99,15 @@ void IMDivider::setOwnerParent( IMGUI* _owner, IMElement* _parent ) {
* @param reposition should we go through and reposition existing objects
*
*/
-void IMDivider::setAlignment( ContainerAlignment xAlignment, ContainerAlignment yAlignment, bool reposition ) {
-
+void IMDivider::setAlignment(ContainerAlignment xAlignment, ContainerAlignment yAlignment, bool reposition) {
contentsXAlignment = xAlignment;
contentsYAlignment = yAlignment;
-
- if( reposition ) {
- for(auto & container : containers) {
- container->setAlignment( xAlignment, yAlignment );
+
+ if (reposition) {
+ for (auto& container : containers) {
+ container->setAlignment(xAlignment, yAlignment);
}
}
-
}
/*******************************************************************************************/
@@ -121,8 +117,8 @@ void IMDivider::setAlignment( ContainerAlignment xAlignment, ContainerAlignment
*/
void IMDivider::clear() {
std::vector<IMContainer*> containers_copy = containers;
- for(auto & iter : containers_copy) {
- iter->Release();
+ for (auto& iter : containers_copy) {
+ iter->Release();
}
containers.resize(0);
onRelayout();
@@ -137,35 +133,30 @@ void IMDivider::clear() {
* @param guistate The state of the GUI at this update
*
*/
-void IMDivider::update( uint64_t delta, vec2 drawOffset, GUIState& guistate ) {
-
+void IMDivider::update(uint64_t delta, vec2 drawOffset, GUIState& guistate) {
bool mouseOverState = guistate.inheritedMouseOver;
bool mouseDownState = guistate.inheritedMouseDown;
IMUIContext::ButtonState currentMouseState = guistate.inheritedMouseState;
-
+
// Do whatever the superclass wants
- IMElement::update( delta, drawOffset, guistate );
-
+ IMElement::update(delta, drawOffset, guistate);
+
vec2 currentDrawOffset = drawOffset + drawDisplacement;
-
+
// Simply pass this on to the children
- for(auto & container : containers) {
-
- container->update( delta, currentDrawOffset, guistate );
-
- if( orientation == DOVertical ) {
+ for (auto& container : containers) {
+ container->update(delta, currentDrawOffset, guistate);
+
+ if (orientation == DOVertical) {
currentDrawOffset.y() += container->getSizeY();
- }
- else {
+ } else {
currentDrawOffset.x() += container->getSizeX();
}
}
-
+
guistate.inheritedMouseOver = mouseOverState;
guistate.inheritedMouseDown = mouseDownState;
guistate.inheritedMouseState = currentMouseState;
-
-
}
/*******************************************************************************************/
@@ -177,42 +168,35 @@ void IMDivider::update( uint64_t delta, vec2 drawOffset, GUIState& guistate ) {
* @param clipSize size of clipping region
*
*/
-void IMDivider::render( vec2 drawOffset, vec2 clipPos, vec2 clipSize ) {
-
+void IMDivider::render(vec2 drawOffset, vec2 clipPos, vec2 clipSize) {
// See if we need to adjust clip for this container
vec2 currentClipPos = drawOffset + drawDisplacement;
vec2 currentClipSize;
-
- if( getSizeX() == UNDEFINEDSIZE || getSizeY() == UNDEFINEDSIZE ) {
+
+ if (getSizeX() == UNDEFINEDSIZE || getSizeY() == UNDEFINEDSIZE) {
currentClipSize = clipSize;
- }
- else {
+ } else {
currentClipSize = getSize();
}
-
+
// See if the superclass wants to do anything
- IMElement::render( drawOffset, currentClipPos, currentClipSize );
-
+ IMElement::render(drawOffset, currentClipPos, currentClipSize);
+
// Simply pass this on to the children
vec2 currentDrawOffset = drawOffset + drawDisplacement;
- for(auto & container : containers) {
-
- container->render( currentDrawOffset, currentClipPos, currentClipSize );
-
- if( orientation == DOVertical ) {
-
- if( container->getSizeY() > 0 ) {
+ for (auto& container : containers) {
+ container->render(currentDrawOffset, currentClipPos, currentClipSize);
+
+ if (orientation == DOVertical) {
+ if (container->getSizeY() > 0) {
currentDrawOffset.y() += container->getSizeY();
}
- }
- else {
-
- if( container->getSizeX() > 0 ) {
+ } else {
+ if (container->getSizeX() > 0) {
currentDrawOffset.x() += container->getSizeX();
}
}
}
-
}
/*******************************************************************************************/
@@ -221,127 +205,116 @@ void IMDivider::render( vec2 drawOffset, vec2 clipPos, vec2 clipSize ) {
*
*/
void IMDivider::checkRegions() {
-
// keep track of the dynamic spacers so we can resize them when we're done
std::vector<IMSpacer*> dynamicSpacers;
float totalSize = 0;
-
- if( orientation == DOVertical ) {
-
+
+ if (orientation == DOVertical) {
// First calculate the height
- for(auto & container : containers) {
-
+ for (auto& container : containers) {
// see if this element is a dynamic spacer
// first check if there is an element in this container
- if( container->contents != NULL ) {
+ if (container->contents != NULL) {
// now see if we can cast it
- if( IMSpacer* spacer = dynamic_cast<IMSpacer*>( container->contents ) ) {
- if( spacer != NULL && spacer->isStatic == false ) {
+ if (IMSpacer* spacer = dynamic_cast<IMSpacer*>(container->contents)) {
+ if (spacer != NULL && spacer->isStatic == false) {
// queue this up
- dynamicSpacers.push_back( spacer );
+ dynamicSpacers.push_back(spacer);
// skip the rest of the loop so we don't add this to the total
continue;
}
}
}
-
+
// add to our total
totalSize += container->getSizeY();
-
}
-
+
float addedSpace = 0;
// see if we've got dynamic spacers and spare space
- if( dynamicSpacers.size() > 0 && totalSize < parent->getSizeY() ) {
- float spacerSize = (parent->getSizeY() - totalSize )/((float) dynamicSpacers.size() );
- for(auto & dynamicSpacer : dynamicSpacers) {
- dynamicSpacer->setSizeY( spacerSize );
+ if (dynamicSpacers.size() > 0 && totalSize < parent->getSizeY()) {
+ float spacerSize = (parent->getSizeY() - totalSize) / ((float)dynamicSpacers.size());
+ for (auto& dynamicSpacer : dynamicSpacers) {
+ dynamicSpacer->setSizeY(spacerSize);
addedSpace += spacerSize;
}
}
-
+
totalSize += addedSpace;
-
- setSizeY( totalSize );
-
+
+ setSizeY(totalSize);
+
// Now just fit the divider to the widest element
float maxSize = UNDEFINEDSIZE;
- for(auto & container : containers) {
- if( container->getSizeX() > maxSize ) {
+ for (auto& container : containers) {
+ if (container->getSizeX() > maxSize) {
maxSize = container->getSizeX();
}
}
-
+
// if we've grown then resize the container and its elements
- for(auto & container : containers) {
- if( container->getSizeX() != maxSize ) {
- container->setSizeX( maxSize );
+ for (auto& container : containers) {
+ if (container->getSizeX() != maxSize) {
+ container->setSizeX(maxSize);
}
}
-
+
// finally, set our own dimensions
- setSizeX( maxSize );
-
-
- }
- else {
-
+ setSizeX(maxSize);
+
+ } else {
// First calculate the height
- for(auto & container : containers) {
-
+ for (auto& container : containers) {
// see if this element is a dynamic spacer
// first check if there is an element in this container
- if( container->contents != NULL ) {
+ if (container->contents != NULL) {
// now see if we can cast it
- IMSpacer* spacer = dynamic_cast<IMSpacer*>( container->contents );
-
- if( spacer != NULL && spacer->isStatic == false ) {
+ IMSpacer* spacer = dynamic_cast<IMSpacer*>(container->contents);
+
+ if (spacer != NULL && spacer->isStatic == false) {
// queue this up
- dynamicSpacers.push_back( spacer );
+ dynamicSpacers.push_back(spacer);
// skip the rest of the loop so we don't add this to the total
continue;
}
}
-
+
// add to our total
totalSize += container->getSizeX();
-
}
-
+
float addedSpace = 0;
// see if we've got dynamic spacers and spare space
- if( dynamicSpacers.size() > 0 && totalSize < parent->getSizeX() ) {
- float spacerSize = (parent->getSizeX() - totalSize )/((float)dynamicSpacers.size() );
- for(auto & dynamicSpacer : dynamicSpacers) {
- dynamicSpacer->setSizeX( spacerSize );
+ if (dynamicSpacers.size() > 0 && totalSize < parent->getSizeX()) {
+ float spacerSize = (parent->getSizeX() - totalSize) / ((float)dynamicSpacers.size());
+ for (auto& dynamicSpacer : dynamicSpacers) {
+ dynamicSpacer->setSizeX(spacerSize);
addedSpace += spacerSize;
}
}
-
+
totalSize += addedSpace;
-
- setSizeX( totalSize );
-
+
+ setSizeX(totalSize);
+
// Now just fit the divider to the widest element
float maxSize = UNDEFINEDSIZE;
- for(auto & container : containers) {
- if( container->getSizeY() > maxSize ) {
+ for (auto& container : containers) {
+ if (container->getSizeY() > maxSize) {
maxSize = container->getSizeY();
}
}
-
+
// if we've grown then resize the container and its elements
- for(auto & container : containers) {
- if( container->getSizeY() != maxSize ) {
- container->setSizeY( maxSize );
+ for (auto& container : containers) {
+ if (container->getSizeY() != maxSize) {
+ container->setSizeY(maxSize);
}
}
-
+
// finally, set our own dimensions
- setSizeY( maxSize );
-
+ setSizeY(maxSize);
}
-
}
/*******************************************************************************************/
@@ -350,17 +323,15 @@ void IMDivider::checkRegions() {
*
*/
void IMDivider::doRelayout() {
-
// Invoke the parents relayout
IMElement::doRelayout();
-
+
// First pass this down to the children
- for(auto & container : containers) {
+ for (auto& container : containers) {
container->doRelayout();
}
-
+
checkRegions();
-
}
/*******************************************************************************************/
@@ -368,21 +339,18 @@ void IMDivider::doRelayout() {
* @brief Do whatever is necessary when the resolution changes
*
*/
-void IMDivider::doScreenResize() {
-
+void IMDivider::doScreenResize() {
// Invoke the superclass's method
IMElement::doScreenResize();
-
+
// Pass this down to the children
- for(auto & container : containers) {
+ for (auto& container : containers) {
container->doScreenResize();
}
-
+
onRelayout();
-
}
-
/*******************************************************************************************/
/**
* @brief Convenience function to add a spacer element to this divider
@@ -392,21 +360,19 @@ void IMDivider::doScreenResize() {
* @returns the space object created, just in case you need it
*
*/
-IMSpacer* IMDivider::appendSpacer( float _size ) {
-
+IMSpacer* IMDivider::appendSpacer(float _size) {
// Create a new spacer object
- IMSpacer* newSpacer = new IMSpacer( orientation, _size );
-
+ IMSpacer* newSpacer = new IMSpacer(orientation, _size);
+
// Add this to the divider (with a referene)
newSpacer->AddRef();
-
- IMContainer* newContainer = append( newSpacer );
+
+ IMContainer* newContainer = append(newSpacer);
newContainer->Release();
-
+
// return a reference to this object in case the
// user needs to reference it (get the name, etc)
return newSpacer;
-
}
/*******************************************************************************************/
@@ -421,11 +387,11 @@ IMSpacer* IMDivider::appendSpacer( float _size ) {
*/
IMSpacer* IMDivider::appendDynamicSpacer() {
// Create a new spacer object
- IMSpacer* newSpacer = new IMSpacer( orientation );
-
+ IMSpacer* newSpacer = new IMSpacer(orientation);
+
// Add this to the divider
- append( newSpacer );
-
+ append(newSpacer);
+
// return a reference to this object in case the
// user needs to reference it (get the name, etc)
return newSpacer;
@@ -450,11 +416,10 @@ unsigned int IMDivider::getContainerCount() {
* @param i index of the container
*
*/
-IMContainer* IMDivider::getContainerAt( unsigned int i ) {
- if( i >= containers.size() ) {
+IMContainer* IMDivider::getContainerAt(unsigned int i) {
+ if (i >= containers.size()) {
return NULL;
- }
- else {
+ } else {
containers[i]->AddRef();
return containers[i];
}
@@ -469,10 +434,9 @@ IMContainer* IMDivider::getContainerAt( unsigned int i ) {
* @returns container of the element (NULL if none)
*
*/
-IMContainer* IMDivider::getContainerOf( std::string const& _name ) {
- for(auto & container : containers) {
-
- if( container->contents != NULL && container->contents->getName() == _name ) {
+IMContainer* IMDivider::getContainerOf(std::string const& _name) {
+ for (auto& container : containers) {
+ if (container->contents != NULL && container->contents->getName() == _name) {
return container;
}
}
@@ -487,19 +451,18 @@ IMContainer* IMDivider::getContainerOf( std::string const& _name ) {
* @param direction Portion of the divider to add to (default top/left)
*
*/
-IMContainer* IMDivider::append( IMElement* newElement, float containerSize ) {
-
+IMContainer* IMDivider::append(IMElement* newElement, float containerSize) {
// Link to this element/owning GUI
- newElement->setOwnerParent( owner, this );
-
+ newElement->setOwnerParent(owner, this);
+
// Make sure it's in front of us
- newElement->setZOrdering( getZOrdering() + 1 );
-
+ newElement->setZOrdering(getZOrdering() + 1);
+
// Make sure the element has a name
- if( newElement->getName() == "" ) {
+ if (newElement->getName() == "") {
// build a new name
contentsNum++;
-
+
std::ostringstream oss;
oss << name << "_container_" << contentsNum;
newElement->name = oss.str();
@@ -507,105 +470,96 @@ IMContainer* IMDivider::append( IMElement* newElement, float containerSize ) {
// Make a new container for it
IMContainer* newContainer;
-
- if( orientation == DOVertical ) {
- newContainer = new IMContainer( SizePolicy( UNDEFINEDSIZE ).expand().overflowClip(true),
- SizePolicy( containerSize ).expand().overflowClip(true) );
- }
- else {
- newContainer = new IMContainer( SizePolicy( containerSize ).expand().overflowClip(true),
- SizePolicy( UNDEFINEDSIZE ).expand().overflowClip(true) );
+
+ if (orientation == DOVertical) {
+ newContainer = new IMContainer(SizePolicy(UNDEFINEDSIZE).expand().overflowClip(true),
+ SizePolicy(containerSize).expand().overflowClip(true));
+ } else {
+ newContainer = new IMContainer(SizePolicy(containerSize).expand().overflowClip(true),
+ SizePolicy(UNDEFINEDSIZE).expand().overflowClip(true));
}
-
+
// Add a reference as setElement is expecting it
newElement->AddRef();
- newContainer->setElement( newElement );
- newContainer->setZOrdering( getZOrdering() );
-
+ newContainer->setElement(newElement);
+ newContainer->setZOrdering(getZOrdering());
+
// Link to this element/owning GUI
- newContainer->setOwnerParent( owner, this );
-
+ newContainer->setOwnerParent(owner, this);
+
vec2 newSize;
-
- if( orientation == DOHorizontal ) {
+
+ if (orientation == DOHorizontal) {
// If we're not given a size, fit to the element size
- if( containerSize == UNDEFINEDSIZE ) {
+ if (containerSize == UNDEFINEDSIZE) {
newSize.x() = newElement->getSizeX();
- }
- else {
+ } else {
newSize.x() = containerSize;
}
-
+
// Base the height on our current one
newSize.y() = getSizeY();
- }
- else {
+ } else {
// If we're not given a size, fit to the element size
- if( containerSize == UNDEFINEDSIZE ) {
+ if (containerSize == UNDEFINEDSIZE) {
newSize.y() = newElement->getSizeY();
- }
- else {
+ } else {
newSize.y() = containerSize;
}
-
+
// Base the width on our current one
newSize.x() = getSizeX();
}
-
- newContainer->setSize( newSize );
- newContainer->setAlignment( contentsXAlignment, contentsYAlignment );
-
+
+ newContainer->setSize(newSize);
+ newContainer->setAlignment(contentsXAlignment, contentsYAlignment);
+
// Make sure we keep a reference to this
newContainer->AddRef();
- containers.push_back( newContainer );
-
+ containers.push_back(newContainer);
+
// Signal that something new has changed
onRelayout();
- // get rid of the reference we were given
+ // get rid of the reference we were given
newElement->Release();
-
+
return newContainer;
-
}
-
/*******************************************************************************************/
/**
* @brief Find an element by name — called internally
*
*
*/
-IMElement* IMDivider::findElement( std::string const& elementName ) {
-
+IMElement* IMDivider::findElement(std::string const& elementName) {
// Check if this is the droid we're looking for
- if( name == elementName ) {
+ if (name == elementName) {
// Up our reference count
AddRef();
return this;
- }
- else {
+ } else {
// If not, pass the request onto the children
-
- for(auto & container : containers) {
-
- IMElement* results = container->findElement( elementName );
-
- if( results != NULL ) {
+
+ for (auto& container : containers) {
+ IMElement* results = container->findElement(elementName);
+
+ if (results != NULL) {
return results;
}
}
-
+
// if we've got this, far we don't have it and so report
return NULL;
}
}
-void IMDivider::setPauseBehaviors( bool pause ) {
- IMElement::setPauseBehaviors( pause );
- for(auto & container : containers) {
- container->setPauseBehaviors( pause );
+void IMDivider::setPauseBehaviors(bool pause) {
+ IMElement::setPauseBehaviors(pause);
+ for (auto& container : containers) {
+ container->setPauseBehaviors(pause);
}
}
@@ -617,7 +571,6 @@ void IMDivider::setPauseBehaviors( bool pause ) {
void IMDivider::clense() {
IMElement::clense();
containers.clear();
-
}
/*******************************************************************************************/
@@ -626,27 +579,26 @@ void IMDivider::clense() {
*
*/
IMDivider::~IMDivider() {
- IMrefCountTracker.removeRefCountObject( getElementTypeName() );
+ IMrefCountTracker.removeRefCountObject(getElementTypeName());
std::vector<IMContainer*> deletelist = containers;
containers.clear();
- for(auto & it : deletelist) {
+ for (auto& it : deletelist) {
it->Release();
}
}
-void IMDivider::DestroyedIMElement( IMElement* element ) {
- for( int i = containers.size()-1; i >= 0; i-- ) {
- if( containers[i] == element ) {
- containers.erase(containers.begin()+i);
+void IMDivider::DestroyedIMElement(IMElement* element) {
+ for (int i = containers.size() - 1; i >= 0; i--) {
+ if (containers[i] == element) {
+ containers.erase(containers.begin() + i);
}
}
IMElement::DestroyedIMElement(element);
}
-void IMDivider::DestroyedIMGUI( IMGUI* imgui ) {
-
+void IMDivider::DestroyedIMGUI(IMGUI* imgui) {
IMElement::DestroyedIMGUI(imgui);
}