    //
//  UIElementContainer.cpp
//  emptyExample
//
//  Created by Robert Tubb on 22/05/2013.
//
//

#include "UIElementContainer.h"
#include "ButtronXY.h"
#include "ButtronSlider.h"

//-----------------------------------------------------------------------------
UIElementContainer::UIElementContainer(float ax,
                                       float ay,
                                       float awidth,
                                       float aheight,
                                       const UIProps& aprops) :
UIElement(ax,ay,awidth,aheight,aprops.generalBackground)
{
    cout << "UIElementContainer contructor\n";
    
    myProps = aprops;
    cthickness = 0.;

}

//-----------------------------------------------------------------------------
int UIElementContainer::getNumberOfControls(){
    return subElements.size();
}


//-----------------------------------------------------------------------------

void UIElementContainer::removeAllSubelements(){
    vector<UIElement *>::iterator UIitr;
    for(UIitr = subElements.begin(); UIitr < subElements.end(); UIitr++){
        delete (*UIitr);
    }
    subElements.clear();
}
//-------------------------------------------------------------------
void UIElementContainer::draw(){
    if(hidden) return;
    //cout << "DRAWING CONTAINER"<< endl;
    UIElement::draw();
    // draw me
    if(cthickness != 0.){
        // doh, duplicate code from buttron?
        drawBorder();
    }
    
    // draw my subelems
    vector<UIElement *>::iterator UIitr;
    for(UIitr = subElements.begin(); UIitr < subElements.end(); UIitr++){
        (*UIitr)->draw();
    }
};
//-------------------------------------------------------------------
void UIElementContainer::drawBorder(){
    ofSetLineWidth(cthickness);
    ofSetColor(myProps.borderColor);
    // top
    ofLine(x,y,x+width,y);
    // left
    ofLine(x,y,x,y+height);
    //right
    ofLine(x+width-cthickness,y,x+width-cthickness,y+height);
    // bottom
    ofLine(x-cthickness,y+height,x+width-cthickness,y+height);
}
//-------------------------------------------------------------------