Пример #1
0
Vec2f GridLayout::layoutSize(const MFUnrecChildComponentPtr* Components, const Component* ParentComponent, SizeType TheSizeType) const
{
    if(getRows() == 0 || getColumns() == 0)
    {
        return Vec2f(1.0f,1.0f);
    }

	Real32 maxSizeX = 0.0f;
	Real32 maxSizeY = 0.0f;

    Vec2f ComponentSize;
	//set the size to the perfered sizes for the buttons
	for(UInt16 i = 0; i<Components->size(); i++){
		if ((*Components)[i] != NULL) 
		{
            ComponentSize = getComponentSize((*Components)[i],TheSizeType);
			if(ComponentSize.x()>maxSizeX)
				maxSizeX = ComponentSize.x();
			if(ComponentSize.y()>maxSizeY)
				maxSizeY = ComponentSize.y();
		}
	}

    return Vec2f(maxSizeX * static_cast<Real32>(getColumns()) + getHorizontalGap() * static_cast<Real32>(getColumns()-1),
                 maxSizeY * static_cast<Real32>(getRows()) + getVerticalGap() * static_cast<Real32>(getRows()-1));
}
Пример #2
0
void GridLayout::updateLayout(const MFUnrecComponentPtr* Components, const Component* ParentComponent) const
{
	Pnt2f borderTopLeft, borderBottomRight;
	dynamic_cast<const ComponentContainer*>(ParentComponent)->getInsideInsetsBounds(borderTopLeft, borderBottomRight);
	Vec2f borderSize(borderBottomRight-borderTopLeft);

	Real32 Xpos = 0;
	Real32 Ypos = 0;
	Real32 maxSizeX = 0;
	Real32 maxSizeY = 0;
	Real32 debug = 10;
	Int32 numComp = Components->getSize();
	Real32 buttonXSize, buttonYSize;

	//set the size to the perfered sizes for the buttons
	for(UInt16 i = 0; i<Components->size(); i++){
		if ((*Components)[i] != NULL) 
		{
			if((*Components)[i]->getPreferredSize().x()>maxSizeX)
				maxSizeX = (*Components)[i]->getPreferredSize().x();
			if((*Components)[i]->getPreferredSize().y()>maxSizeY)
				maxSizeY = (*Components)[i]->getPreferredSize().y();
		}
	}
	//set the  size of the button
	for(UInt16 i = 0; i < Components->size(); i++){
		if ((*Components)[i] != NULL) 
		{
			if(maxSizeX < (*Components)[i]->getMaxSize().x())
				buttonXSize = maxSizeX;
			else
				buttonXSize = (*Components)[i]->getMaxSize().x();
			if(maxSizeY<(*Components)[i]->getMaxSize().y())
				buttonYSize = maxSizeY;
			else
				buttonYSize = (*Components)[i]->getMaxSize().y();
			   (*Components)[i]->setSize(Vec2f(buttonXSize, buttonYSize));
		}
	}


	//position each button
	for(UInt16 i = 0; i <= getRows()&& numComp>=0; i++){
		if ((*Components)[i] != NULL) 
		{
			for(UInt16 j = 0; j < getColumns()&& numComp>0; j++){
				debug = i*getColumns()+j;
                   (*Components)[i*getColumns()+j]->setPosition(borderTopLeft + Vec2f(Xpos, Ypos));
				numComp--;
				Xpos = Xpos + (maxSizeX+getHorizontalGap());
			}
			Xpos = 0;
			Ypos += maxSizeY+getVerticalGap();
		}
	}
}
Пример #3
0
void GridLayout::updateLayout(const MFUnrecChildComponentPtr* Components, const Component* ParentComponent) const
{
	Pnt2f borderTopLeft, borderBottomRight;
	dynamic_cast<const ComponentContainer*>(ParentComponent)->getInsideInsetsBounds(borderTopLeft, borderBottomRight);
	Vec2f borderSize(borderBottomRight-borderTopLeft);

	Real32 Xpos = 0;
	Real32 Ypos = 0;
	Real32 maxSizeX = (borderSize.x()-getHorizontalGap()*(getColumns()-1)) / static_cast<Real32>(getColumns());
	Real32 maxSizeY = 0.0f;//(borderSize.y()-getVerticalGap()*getRows()) / static_cast<Real32>(getRows());
	Int32 numComp = Components->size();
	Real32 buttonXSize, buttonYSize;

	//set the size to the perfered sizes
	for(UInt16 i = 0; i<Components->size(); i++)
    {
		if ((*Components)[i] != NULL) 
		{
			if((*Components)[i]->getPreferredSize().x()>maxSizeX)
				maxSizeX = (*Components)[i]->getPreferredSize().x();
			if((*Components)[i]->getPreferredSize().y()>maxSizeY)
				maxSizeY = (*Components)[i]->getPreferredSize().y();
		}
	}
	//set the  size of the button
	for(UInt16 i = 0; i < Components->size(); i++)
    {
		if ((*Components)[i] != NULL) 
		{
			if(maxSizeX < (*Components)[i]->getMaxSize().x())
            {
				buttonXSize = maxSizeX;
            }
			else
				buttonXSize = (*Components)[i]->getMaxSize().x();
			if(maxSizeY<(*Components)[i]->getMaxSize().y())
            {
				buttonYSize = maxSizeY;
            }
			else
            {
				buttonYSize = (*Components)[i]->getMaxSize().y();
            }
            
            if((*Components)[i]->getSize() != Vec2f(buttonXSize, buttonYSize))
            {
			   (*Components)[i]->setSize(Vec2f(buttonXSize, buttonYSize));
            }
		}
	}


	//position each component
	for(UInt16 i = 0; i < osgMin(getRows(), numComp/getColumns()); i++)
    {
		if ((*Components)[i] != NULL) 
		{
            Pnt2f Pos;
			for(UInt16 j = 0; j < osgMin(getColumns(),numComp - i*getColumns()) ; j++)
            {
                Pos = borderTopLeft + Vec2f(Xpos, Ypos);
                if((*Components)[i*getColumns()+j]->getPosition() != Pos)
                {
                    (*Components)[i*getColumns()+j]->setPosition(Pos);
                }
				Xpos = Xpos + (maxSizeX+getHorizontalGap());
			}
			Xpos = 0;
			Ypos += maxSizeY+getVerticalGap();
		}
	}
}
Пример #4
0
void FlowLayout::updateLayout(const MFUnrecComponentPtr* Components, const Component* ParentComponent) const
{
    /*!
      totalMajorAxis will hold the width of its container, and cumMajorAxis
      will hold the width of all of the buttons. That way it will always know
      when to move to the next line. In addition, maxMinorAxis keeps track of
      the largest height so it knows how far down to move the next row. Also,
      oneInRow is used to make sure that it places at least one component in
      every row.
      */
    UInt32 AxisIndex(0);
    if(getOrientation() != HORIZONTAL_ORIENTATION ) AxisIndex = 1;
    Vec2f gap(getHorizontalGap(), getVerticalGap());
    UInt32 numGaps(0);
    /*!
      When finding the cumMinor Axis, the gap is included, because there is
      no count for how many stacks there are. When finding cumMajor, the
      gap isn't included because the total distance relies on how many
      components there are in that row/column.
      */

    Pnt2f borderTopLeft, borderBottomRight;
    dynamic_cast<const ComponentContainer*>(ParentComponent)->getInsideInsetsBounds(borderTopLeft, borderBottomRight);
    Vec2f borderSize(borderBottomRight-borderTopLeft);
    Real64 totalMajorAxis(borderSize[AxisIndex]);
    Real32 cumMajorAxis(0);
    Real32 maxMinorAxis(0);
    Real32 cumMinorAxis(0);
    Real32 prevComponent(0);
    Real64 offsetMajorAxis(0);
    Real64 offsetMinorAxis(0);
    Real64 offsetX(borderTopLeft.x());
    Real64 offsetY(borderTopLeft.y());
    bool firstOne = true;

    for(UInt32 i=0 ; i<Components->size(); ++i)
    {
    }

    for(UInt32 i=0 ; i<Components->size(); ++i)
    {
        // set the component to its preferred size
        (*Components)[i]->setSize(getAppropriateComponentSize((*Components)[i]));

        // if there is only one so far, then it can't draw it using cumMajorAxis
        // because it hasn't been set yet
        if (firstOne) // this one might draw it
        {
            firstOne = false;
            // if this is the last component or it is already too big for the
            // container, draw it centered on its line
            if (i == Components->size() || (*Components)[i]->getSize()[AxisIndex] >= totalMajorAxis)
            {
                // find how far to translate to make it properly aligned
                offsetMajorAxis = getMajorAxisAlignment()*(totalMajorAxis - (*Components)[i]->getSize()[AxisIndex]);

                if (AxisIndex)
                {
                    offsetY+= offsetMajorAxis;
                }
                else
                {
                    offsetX += offsetMajorAxis;
                }

                (*Components)[i]->setPosition(Pnt2f(offsetX, offsetY));

                // get to the next row
                if (AxisIndex)
                {
                    offsetX += (*Components)[i]->getSize()[(AxisIndex+1)%2]+gap[(AxisIndex+1)%2];
                    offsetY += -offsetMajorAxis;
                }
                else
                {
                    offsetX += -offsetMajorAxis;
                    offsetY += (*Components)[i]->getSize()[(AxisIndex+1)%2]+gap[(AxisIndex+1)%2];
                }
                // update cumMinorAxis, other values should still be at 0
                cumMinorAxis += (*Components)[i]->getSize()[(AxisIndex+1)%2];
                if(i < Components->size()-1)
                {
                    cumMinorAxis += gap[(AxisIndex+1)%2];
                }
                // update prevComponent
                prevComponent++;
                // next component is still just like the first one
                firstOne = true;
            }
            else
            {
                // update the maxMinorAxis
                maxMinorAxis = (*Components)[i]->getSize()[(AxisIndex+1)%2];
                // update cumMajorAxis
                cumMajorAxis += (*Components)[i]->getSize()[AxisIndex];
            }
        }
        else if (cumMajorAxis + (*Components)[i]->getSize()[AxisIndex] + gap[AxisIndex]*(i-prevComponent) > totalMajorAxis) // this one draws up to i
        {
            // The numGaps is one less than the number of components being drawn, but it
            // is actually translates once for each component, so it must be compensated
            // when returning to the next row.
            numGaps = i-prevComponent-1;

            // find how far to translate to make it properly aligned
            offsetMajorAxis = getMajorAxisAlignment()*(totalMajorAxis - (cumMajorAxis+numGaps*gap[AxisIndex]));


            if (AxisIndex){
                offsetY += offsetMajorAxis;
            }
            else
            {
                offsetX += offsetMajorAxis;
            }
            for (int j = prevComponent; j < i; j++)
            {
                // find how far to translate to make this button properly aligned
                offsetMinorAxis = (maxMinorAxis-(*Components)[j]->getSize()[(AxisIndex+1)%2])*getComponentAlignment();

                // translate to make it properly aligned
                if (AxisIndex)
                {	
                    offsetX += offsetMinorAxis;
                }
                else
                {
                    offsetY += offsetMinorAxis;
                }

                (*Components)[j]->setPosition(Pnt2f(offsetX, offsetY));

                // translate to next button
                if (AxisIndex)
                {
                    offsetX+=-(Real64)offsetMinorAxis;
                    offsetY+= (*Components)[j]->getSize()[AxisIndex] + gap[AxisIndex];
                }
                else
                {
                    offsetX+=(*Components)[j]->getSize()[AxisIndex] + gap[AxisIndex];
                    offsetY+= -offsetMinorAxis;
                }
            }
            // translate to the next row
            if (AxisIndex)
            {
                offsetX += maxMinorAxis+gap[(AxisIndex+1)%2];
                offsetY += -(offsetMajorAxis+cumMajorAxis+(numGaps+1)*gap[AxisIndex]);
            }
            else
            {
                offsetX += -(offsetMajorAxis+cumMajorAxis+(numGaps+1)*gap[AxisIndex]);
                offsetY += maxMinorAxis+gap[(AxisIndex+1)%2];
            }

            cumMinorAxis += maxMinorAxis + gap[(AxisIndex+1)%2];
            maxMinorAxis = (*Components)[i]->getSize()[(AxisIndex+1)%2];
            prevComponent = i;
            cumMajorAxis = (*Components)[i]->getSize()[AxisIndex];
        }
        else
        {
            // update the maxMinorAxis
            if ((*Components)[i]->getSize()[(AxisIndex+1)%2] > maxMinorAxis)
                maxMinorAxis = (*Components)[i]->getSize()[(AxisIndex+1)%2];
            // update cumMajorAxis
            cumMajorAxis += (*Components)[i]->getSize()[AxisIndex];
        }
        if (i+1 == Components->size() && !firstOne) // if on the last one, draw the last buttons
        {
            numGaps = i-prevComponent;

            // find how far to translate to make it properly aligned
            offsetMajorAxis = getMajorAxisAlignment()*(totalMajorAxis - (cumMajorAxis+numGaps*gap[AxisIndex]));

            if (AxisIndex)
            {
                offsetY += offsetMajorAxis;
            }
            else
            {			
                offsetX += offsetMajorAxis;
            }
            for (int j = prevComponent; j < i+1; j++)
            {
                // find how far to translate to make this button properly aligned
                offsetMinorAxis = (maxMinorAxis-(*Components)[j]->getSize()[(AxisIndex+1)%2])*getComponentAlignment();

                // translate to make it properly aligned
                if (AxisIndex)
                {
                    offsetX += offsetMinorAxis;
                }
                else
                {
                    offsetY += offsetMinorAxis;
                }
                (*Components)[j]->setPosition(Pnt2f(offsetX, offsetY));

                if (AxisIndex)
                {
                    offsetX += -(Real64)offsetMinorAxis;
                    offsetY += (*Components)[j]->getSize()[AxisIndex] + gap[AxisIndex];
                }
                else
                {
                    offsetX += (*Components)[j]->getSize()[AxisIndex] + gap[AxisIndex];
                    offsetY+= -(Real64)offsetMinorAxis;
                }
            }
            // translate to the next row
            if (AxisIndex)
            {
                offsetX += maxMinorAxis+gap[(AxisIndex+1)%2];
                offsetY += -(offsetMajorAxis+cumMajorAxis+(numGaps+1)*gap[AxisIndex]);
            }
            else
            {
                offsetX += -(offsetMajorAxis+cumMajorAxis+(numGaps+1)*gap[AxisIndex]);
                offsetY += maxMinorAxis+gap[(AxisIndex+1)%2];
            }
            cumMinorAxis += maxMinorAxis;
        }
    }
    //Minor Axis Alignment
    Real32 displacement(borderSize[(AxisIndex+1)%2]-cumMinorAxis);
    Pnt2f offset;
    displacement *= getMinorAxisAlignment(); 
    for (UInt32 i = 0; i < Components->size(); ++i)
    {
        offset = (*Components)[i]->getPosition();
        offset[(AxisIndex+1)%2] += displacement;
        (*Components)[i]->setPosition(offset);
    }

    for(UInt32 i=0 ; i<Components->size(); ++i)
    {
    }
}