Beispiel #1
0
	void GridBox::Update(float elapsedTime)
	{
		if (mVisible)
		{
			float x_base = 0, y_base = 0;

			Rect autoRect;

			for (int i = 0; i < mGridedWidgets.Size(); ++i)
			{
				Widget * widget = mGridedWidgets[i];

				if (x_base >= mColumn * mGridWidth)
				{
					x_base = 0;
					y_base += mGridHeight + 1;
				}

				Rect rect;

				rect.x = x_base;
				rect.y = y_base;
				rect.w = mGridWidth;
				rect.h = mGridHeight;

				rect = Helper::Instance()->GetAlignRect(widget->GetRect(), rect, mGridAlign);

				x_base += mGridWidth + 1;

				autoRect.w = Max(autoRect.w, rect.x + rect.w);
				autoRect.h = Max(autoRect.h, rect.y + rect.h);

				widget->SetRect(rect);
			}

			int type = mAutoResizeType;
			Rect myRect = GetRect();

			if (type & WIDTH)
				myRect.w = autoRect.w;

			if (type & HEIGHT)
				myRect.h = autoRect.h;

			if (type != NONE)
				SetRect(myRect);
		}

		Widget::Update(elapsedTime);
	}
Beispiel #2
0
Widget* WidDispatch::GetWidPt(const std::vector<Widget*>& rgpWid)
{
	Widget* pWid = NULL;
	std::vector<Widget*>::const_iterator it = rgpWid.begin();
	if (it != rgpWid.end())
	{
		pWid = *it;
		WFX_CONDITION(pWid != NULL);
		Rect rcWid = pWid->GetRect();
		float fArea = (rcWid.right - rcWid.left) * (rcWid.bottom - rcWid.top);
		float fMinArea = fArea;
		for (; it != rgpWid.end(); ++it)
		{
			rcWid = pWid->GetRect();
			fArea = (rcWid.right - rcWid.left) * (rcWid.bottom - rcWid.top);
			if (fArea < fMinArea)
			{
				fMinArea = fArea;
			}
			pWid = (*it);
		}
	}
	return pWid;
}
Beispiel #3
0
        void VerticalContainer::UpdateContainerDimensionsImpl(const Rect& OldSelfRect, const Rect& NewSelfRect)
        {
            // Clear our old data.
            this->VisibleChildren.clear();
            this->WorkAreaSize.SetIdentity();

            // Setup any additional data for the next series of loops.
            const Real ActPadding = this->LinearPadding.CalculateActualDimension( this->ActDims.Size.Y );
            const Real HalfPadding = ActPadding * 0.5;
            std::vector< std::pair<Real,Vector2> > ChildTransformCache( this->ChildWidgets.size() );

            // To determine the visible children we need to know our view position in the work area as determined by the page provider.
            // To determine our page position we need to know our work area size, which can change when children have their dimensions updated.
            // So we first need to update the size on every child.  We can update our work area at the same time.  After that we can update our page provider and determine screen positions.
            Whole CurrIndex = 0;
            this->WorkAreaSize.Y = HalfPadding;
            for( ChildIterator SizeIt = this->ChildWidgets.begin() ; SizeIt != this->ChildWidgets.end() ; ++SizeIt )
            {
                // Enforce our sizing rules.
                if( this->ForcedSizingRules & SE_OnUpdate ) {
                    (*SizeIt)->SetSizingPolicy( this->ChildSizing );
                }

                // Calculate the sizing with our utility strat, and offset position which we will use later.
                // Since the constantly updating work area size is tracking the same information as a cursor would, we'll use it as our position cursor.
                Vector2 ChildSize = this->LayoutStrat->HandleChildSizing(OldSelfRect,NewSelfRect,(*SizeIt));

                ChildTransformCache.at(CurrIndex).first = this->WorkAreaSize.Y;
                ChildTransformCache.at(CurrIndex).second = ChildSize;

                // Update the cursor position and work area size.
                this->WorkAreaSize.Y += ( ChildSize.Y + ActPadding );
                if( this->WorkAreaSize.X < ChildSize.X )
                    this->WorkAreaSize.X = ChildSize.X;

                // Increment the index before we proceed.
                ++CurrIndex;
            }
            // Trim off half a padding at the end since we were blinding applying full padding for the space between two children.
            this->WorkAreaSize.Y -= HalfPadding;

            // Now our work area is updated, so we can update our provider and get our target work area position.
            Real YTarget = 0;
            if( this->YProvider != NULL ) {
                this->YProvider->_NotifyContainerUpdated();
                Real YTargetLimit = ( this->WorkAreaSize.Y + HalfPadding ) - NewSelfRect.Size.Y;
                YTarget = std::min( ( this->YProvider->GetCurrentYPage() - 1 ) * NewSelfRect.Size.Y, YTargetLimit );
            }

            // Set up our data for the loop (and the loop itself) that will go over all the children that will be "above" the visible children.
            // Reset the index since we are starting from the beginning again.
            CurrIndex = 0;
            ChildIterator ChildUpdateIt = this->ChildWidgets.begin();
            while( ChildUpdateIt != this->ChildWidgets.end() && ChildTransformCache.at(CurrIndex).first < YTarget )
            {
                const Rect OldChildRect = (*ChildUpdateIt)->GetRect();
                Rect NewChildRect;

                // Assign a dummy position since this will be invisible
                NewChildRect.Position = NewSelfRect.Position;
                NewChildRect.Size = ChildTransformCache.at(CurrIndex).second;

                // Perform the update
                (*ChildUpdateIt)->UpdateDimensions(OldChildRect,NewChildRect);

                // Hide the child
                (*ChildUpdateIt)->Hide();

                // Increment the iterator and index before we proceed.
                ++CurrIndex;
                ++ChildUpdateIt;
            }

            // If we've reached the end of the children, there is nothing to render.
            if( ChildUpdateIt != this->ChildWidgets.end() )
            {
                // If we're here, then we have some visible children.
                // Set our new target and create a variable that will track the total size of just the visible children.
                YTarget = NewSelfRect.Size.Y;
                Real TotalLinearSize = HalfPadding;

                // Before we start a loop that will be altering the index, we need to mark the index of the first visible child in our cache.  This will be used in the final processing step.
                // Once saved, start looping over what will be the visible children.  We can (and should) use the index from the previous loop unaltered.
                const Whole VisibleStartIndex = CurrIndex;
                while( ChildUpdateIt != this->ChildWidgets.end() )
                {
                    Vector2 ChildSize = ChildTransformCache.at(CurrIndex).second;
                    // See if our child can fit
                    if( TotalLinearSize + ChildSize.Y < YTarget ) {
                        this->VisibleChildren.push_back( (*ChildUpdateIt) );
                        TotalLinearSize += ( ChildSize.Y + ActPadding );
                        // Increment the index and iterator before we proceed.
                        ++CurrIndex;
                        ++ChildUpdateIt;
                    }else{
                        break;
                    }
                }

                // Any remaining children will be invisible, so put them in the corner with the rest.
                while( ChildUpdateIt != this->ChildWidgets.end() )
                {
                    const Rect OldChildRect = (*ChildUpdateIt)->GetRect();
                    Rect NewChildRect;

                    // Assign a dummy position since this will be invisible
                    NewChildRect.Position = NewSelfRect.Position;
                    NewChildRect.Size = ChildTransformCache.at(CurrIndex).second;

                    // Perform the update
                    (*ChildUpdateIt)->UpdateDimensions(OldChildRect,NewChildRect);

                    // Hide the child
                    (*ChildUpdateIt)->Hide();

                    // Increment the iterator and index before we proceed.
                    ++CurrIndex;
                    ++ChildUpdateIt;
                }

                // Create the cursor which will be used for visible child placement.
                Real CurrYPos = 0;
                // By now all our children have been processed, just have to focus on the last couple steps for visible children.  Start by doing our alignment stuff.
                switch( this->VisibleChildAlign )
                {
                    case UI::LA_TopLeft:      CurrYPos = ( NewSelfRect.Position.Y + HalfPadding );                                               break;
                    case UI::LA_Center:       CurrYPos = ( NewSelfRect.Position.Y + ( NewSelfRect.Size.Y * 0.5 ) ) - ( TotalLinearSize * 0.5 );  break;
                    case UI::LA_BottomRight:  CurrYPos = ( NewSelfRect.Position.Y + NewSelfRect.Size.Y ) - ( TotalLinearSize + HalfPadding );    break;
                }

                // Finally, we're at the final processing stage.  We have our visible children and enough data to determine their positions, along with their saved sizes from earlier.
                for( Whole VisIndex = 0 ; VisIndex < this->VisibleChildren.size() ; ++VisIndex )
                {
                    Widget* VisChild = this->VisibleChildren.at(VisIndex);
                    // Setup child transform data
                    const Rect OldChildRect = VisChild->GetRect();
                    Rect NewChildRect;
                    // Set the Size
                    NewChildRect.Size = ChildTransformCache.at(VisibleStartIndex + VisIndex).second;
                    // Set the Position
                    NewChildRect.Position.X = this->LayoutStrat->HandleChildHorizontalPositioning( OldSelfRect, NewSelfRect, NewChildRect.Size, VisChild );
                    NewChildRect.Position.Y = CurrYPos;
                    // Perform the update
                    VisChild->UpdateDimensions(OldChildRect,NewChildRect);
                    // Increment the cursor
                    CurrYPos += ( NewChildRect.Size.Y + ActPadding );
                    // Finally show the child
                    VisChild->SetVisible( this->GetVisible() );
                }
                ChildTransformCache.clear();
            }
        }