//----------------------------------------------------------------//
void MOAIAnim::Apply ( float t0, float t1 ) {
	
	if ( t0 == t1 ) {
		this->Apply ( t0 );
		return;
	}
	
	MOAIAttrOp adder;
	
	u32 total = this->mLinks.Size ();
	for ( u32 i = 0; i < total; ++i ) {
		
		MOAIAnimLink& link = this->mLinks [ i ];
		MOAIAnimCurve* curve = link.mCurve;
		MOAINode* target = link.mTarget;
		
		if ( curve && target ) {
			
			if ( link.mRelative ) {
				float value = curve->GetFloatDelta ( t0, t1 );
				adder.SetValue ( value );
				target->ApplyAttrOp ( link.mAttrID, adder, MOAIAttrOp::ADD );
			}
			else {
				float value = curve->GetFloatValue ( t1 );
				target->SetAttributeValue < float >( link.mAttrID, value );
			}
			target->ScheduleUpdate ();
		}
	}
}
//----------------------------------------------------------------//
void MOAIAnim::Apply ( float t ) {
	
	u32 total = this->mLinks.Size ();
	for ( u32 i = 0; i < total; ++i ) {
		
		MOAIAnimLink& link = this->mLinks [ i ];
		MOAIAnimCurve* curve = link.mCurve;
		MOAINode* target = link.mTarget;
		
		if ( curve && target ) {
			
			if ( !link.mRelative ) {
				float value = curve->GetFloatValue ( t );
				target->SetAttributeValue < float >( link.mAttrID, value );
			}
			target->ScheduleUpdate ();
		}
	}
}
Exemple #3
0
//----------------------------------------------------------------//
void MOAITextDesigner::BuildLayout ( MOAITextBox& textBox ) {
	
	if ( !textBox.mStyleMap.GetTop ()) return;
	
	this->mStr = textBox.mText;
	this->mIdx = textBox.mCurrentPageIdx;
	this->mStyleSpan = 0;
	this->mStyle = 0;
	
	int tokenIdx = this->mIdx;
	int lineIdx = this->mIdx;
	
	float width = textBox.mFrame.Width ();
	float height = textBox.mFrame.Height ();
	
	u32 lineStart = 0;
	u32 lineSize = 0;
	
	u32 tokenStart = 0;
	u32 tokenSize = 0;
	
	USRect lineRect;
	lineRect.Init ( 0.0f, 0.0f, 0.0f, 0.0f );
	
	USRect tokenRect;
	tokenRect.Init ( 0.0f, 0.0f, 0.0f, 0.0f );
	
	float tokenAscent = 0.0f;
	float lineAscent = 0.0f;

	USVec2D pen;
	pen.Init ( 0.0f, 0.0f );
	
	MOAIGlyph* glyph = 0;
	MOAIGlyph* prevGlyph = 0;
	
	textBox.mMore = true;
	
	bool more = true;
	while ( more ) {
	
		u32 c = this->NextChar ( textBox );
		
		float scale = textBox.mGlyphScale * ( this->mStyle ? this->mStyle->mScale : 1.0f );
		
		bool acceptToken = false;
		bool acceptLine = false;
		
		if ( MOAIFont::IsControl ( c )) {
		
			if ( c == '\n' ) {
				
				tokenIdx = this->mIdx - 1;
				tokenStart = textBox.mSprites.GetTop ();
				acceptToken = true;
				acceptLine = true;
				
				if ( !tokenRect.Height ()) {
					tokenRect.mYMax += this->mDeck->mHeight * scale;
				}	
			}
			else if ( c == 0 ) {
				textBox.mMore = false;
				
				tokenIdx = this->mIdx - 1;
				tokenStart = textBox.mSprites.GetTop ();
				acceptToken = true;
				acceptLine = true;
				more = false;
			}
		}
		else {
			
			glyph = this->mDeck->GetGlyph ( c );
			
			if ( !glyph ) continue;
			if ( glyph->mAdvanceX == 0.0f ) continue;
			
			// apply kerning
			if ( prevGlyph ) {
				MOAIKernVec kernVec = prevGlyph->GetKerning ( glyph->mCode );
				pen.mX += kernVec.mX * scale;
			}
			
			prevGlyph = glyph;
			
			if ( MOAIFont::IsWhitespace ( c )) {
				if ( tokenSize ) {
					acceptToken = true;
				}
			}
			else {
				
				float glyphBottom = pen.mY + ( this->mDeck->mHeight * scale );
				
				// handle new token
				if ( !tokenSize ) {
					tokenIdx = this->mIdx - 1;
					tokenStart = textBox.mSprites.GetTop ();
					tokenRect.Init ( pen.mX, pen.mY, pen.mX, glyphBottom );
					tokenAscent = this->mDeck->mAscent * scale;
				}
				
				// check for overrun
				float glyphRight = pen.mX + (( glyph->mBearingX + glyph->mWidth ) * scale );
				bool overrun = glyphRight > width;
				acceptLine = ( lineSize && overrun );
				
				if ( acceptLine || !overrun ) {
					textBox.PushSprite ( this->mIdx - 1, *glyph, *this->mStyle, pen.mX, pen.mY, scale );
					tokenRect.mXMax = glyphRight;
					tokenSize++;
				}
			}
			
			pen.mX += glyph->mAdvanceX * scale;
		}
		
		if ( acceptToken ) {
			
			lineRect.Grow ( tokenRect );
			lineSize += tokenSize;
			lineAscent = tokenAscent > lineAscent ? tokenAscent : lineAscent;
			tokenSize = 0;
		}
		
		if ( acceptLine ) {
			
			textBox.PushLine ( lineStart, lineSize, lineRect, lineAscent );
			
			// end line
			pen.mY += lineRect.Height () + textBox.mLineSpacing;
			lineRect.Init ( 0.0f, pen.mY, 0.0f, pen.mY );
			
			// next line
			lineIdx = tokenIdx;
			lineStart = tokenStart;
			lineSize = 0;
			lineAscent = 0.0f;
			
			prevGlyph = 0;
			
			if ( tokenSize ){
				
				// slide the current token (if any) back to the origin
				for ( u32 i = 0; i < tokenSize; ++i ) {
					MOAITextSprite& sprite = textBox.mSprites [ tokenStart + i ];
					sprite.mX -= tokenRect.mXMin;
					sprite.mY = pen.mY;
				}
				
				pen.mX -= tokenRect.mXMin;
				tokenRect.Init ( 0.0f, pen.mY, tokenRect.Width (), pen.mY + tokenRect.Height ());
			}
			else {
				pen.mX = 0.0f;
				tokenRect.Init ( 0.0f, pen.mY, 0.0f, pen.mY + this->mDeck->mHeight );
			}
		}
		
		// if we overrun height, then back up to the start of the current line
		if ( tokenRect.mYMax > height ) {
			textBox.mSprites.SetTop ( lineStart );
			textBox.mNextPageIdx = lineIdx;
			more = false;
		}
	}
	
	if ( textBox.mSprites.GetTop () == 0 ) {
		textBox.mMore = false;
		return;
	}
		
	float yOff = textBox.mFrame.mYMin;
	float layoutHeight = lineRect.mYMax;

	switch ( textBox.mVAlign ) {
		
		case MOAITextBox::CENTER_JUSTIFY:
			yOff = ( yOff + ( height * 0.5f )) - ( layoutHeight * 0.5f );
			
		case MOAITextBox::LEFT_JUSTIFY:
			break;

		case MOAITextBox::RIGHT_JUSTIFY:
			yOff = textBox.mFrame.mYMax - layoutHeight;
	}
	
	u32 totalLines = textBox.mLines.GetTop ();
	for ( u32 i = 0; i < totalLines; ++i ) {
		MOAITextLine& line = textBox.mLines [ i ];
		
		float xOff = textBox.mFrame.mXMin;
		float lineWidth = line.mRect.Width ();
		
		switch ( textBox.mHAlign ) {
		
			case MOAITextBox::CENTER_JUSTIFY:
				xOff = ( xOff + ( width * 0.5f )) - ( lineWidth * 0.5f );
				
			case MOAITextBox::LEFT_JUSTIFY:
				break;

			case MOAITextBox::RIGHT_JUSTIFY:
				xOff = textBox.mFrame.mXMax - lineWidth;
		}
		
		line.mRect.Offset ( xOff, yOff );
		float spriteYOff = yOff + line.mAscent;
		
		MOAIAnimCurve* curve = 0;
		if ( textBox.mCurves ) {
			curve = textBox.mCurves [ i % textBox.mCurves.Size ()];
		}
		
		for ( u32 j = 0; j < line.mSize; ++j ) {
			
			MOAITextSprite& sprite = textBox.mSprites [ line.mStart + j ];
			
			sprite.mX += xOff;
			
			if ( curve ) {
				sprite.mY += spriteYOff + curve->GetFloatValue (( sprite.mX - textBox.mFrame.mXMin ) / width );
			}
			else {
				sprite.mY += spriteYOff;
			}
		}
	}
}
Exemple #4
0
//----------------------------------------------------------------//
void MOAITextFrame::FlushLine () {

	if ( this->mLineCount >= this->mTotalLines ) return;

	float x = this->mFrame.mXMin;
	float width = this->mFrame.Width ();
	
	float lineWidth = this->mRightToLeft ? -this->mLineXMax : this->mLineXMax;
	float lineHeight = this->mFont->GetLineSpacing () * this->mPoints * this->mLineSpacing;

	switch ( this->mJustify ) {
		
		case CENTER_JUSTIFY:
			x = ( x + ( width * 0.5f )) - ( lineWidth * 0.5f );
			
		case LEFT_JUSTIFY:
			break;

		case RIGHT_JUSTIFY:
			x = this->mFrame.mXMax - lineWidth;
	}
	
	MOAIAnimCurve* curve = 0;
	if ( this->mCurves ) {
		curve = this->mCurves [ this->mLineCount % this->mTotalCurves ];
	}
	
	if ( this->mRightToLeft ) {
		x -= this->mLineXMax;
	}
	
	for ( u32 i = this->mLineBottom; i < this->mLineTop; ++i ) {
		
		MOAITextSprite& sprite = ( *this->mLayout )[ i ];
		
		float yOff = 0.0f;
		if ( curve ) {
			yOff = curve->GetFloatValue ( sprite.mX / width );
		}

		sprite.mX += x;
		sprite.mY = this->mPen.mY + yOff;
	}
	
	this->mLineBottom = this->mLineTop;
	this->mLineXMax = 0.0f;
	this->mPen.mY += lineHeight;
	this->mLineCount++;
	this->mGlyph = 0;
	
	// move token to origin
	u32 tokenTop = this->mLayout->GetTop ();
	for ( u32 i = this->mLineTop; i < tokenTop; ++i ) {
		
		MOAITextSprite& sprite = ( *this->mLayout )[ i ];
		sprite.mX -= this->mTokenXMin;
	}

	this->mPen.mX -= this->mTokenXMin;
	this->mTokenXMax -= this->mTokenXMin;
	this->mTokenXMin = 0.0f;
}