Exemple #1
0
 /// <summary>
 /// Full constructor with per-instance alignment modes.
 /// </summary>
 public UITextInstance( UIText parentText, string text, float xPos, float yPos, float scale, int depth, Color[] colors, UITextAlignMode alignMode, UITextVerticalAlignMode verticalAlignMode )
 {
     this.alignMode = alignMode;
     this.verticalAlignMode = verticalAlignMode;
     _parentText = parentText;
     _text = text;
     this.xPos = xPos;
     this.yPos = yPos;
     this.scale = scale;
     this.depth = depth;
     this.textIndex = -1;
     this.colors = colors;
     _hidden = false;
 }
Exemple #2
0
    /// <summary>
    /// Full constructor with per-instance alignment modes.
    /// </summary>
    public UITextInstance(UIText parentText, string text, float xPos, float yPos, float scale, int depth, Color[] colors, UITextAlignMode alignMode, UITextVerticalAlignMode verticalAlignMode) : base()
    {
        _parentText = parentText;
        _text       = text;
        _scale      = scale;
        this.colors = colors;
        position    = new Vector3(xPos, -yPos, depth);
        _hidden     = false;

        // Set anchor alignment
        _alignMode = alignMode;
        switch (alignMode)
        {
        case UITextAlignMode.Left:
            _anchorInfo.OriginUIxAnchor = UIxAnchor.Left;
            break;

        case UITextAlignMode.Center:
            _anchorInfo.OriginUIxAnchor = UIxAnchor.Center;
            break;

        case UITextAlignMode.Right:
            _anchorInfo.OriginUIxAnchor = UIxAnchor.Right;
            break;
        }

        // Set anchor vertical alignment
        _verticalAlignMode = verticalAlignMode;
        switch (verticalAlignMode)
        {
        case UITextVerticalAlignMode.Top:
            _anchorInfo.OriginUIyAnchor = UIyAnchor.Top;
            break;

        case UITextVerticalAlignMode.Middle:
            _anchorInfo.OriginUIyAnchor = UIyAnchor.Center;
            break;

        case UITextVerticalAlignMode.Bottom:
            _anchorInfo.OriginUIyAnchor = UIyAnchor.Bottom;
            break;
        }

        _anchorInfo.OffsetX = xPos;
        _anchorInfo.OffsetY = yPos;

        updateSize();
    }
Exemple #3
0
    /// <summary>
    /// Full constructor with per-instance alignment modes.
    /// </summary>
    public UITextInstance( UIText parentText, string text, float xPos, float yPos, float scale, int depth, Color[] colors, UITextAlignMode alignMode, UITextVerticalAlignMode verticalAlignMode )
        : base()
    {
        client.transform.position = new Vector3( xPos, yPos, depth );

        this.alignMode = alignMode;
        this.verticalAlignMode = verticalAlignMode;
        _parentText = parentText;
        _text = text;
        this.xPos = xPos;
        this.yPos = yPos;
        this.scale = scale;
        this.depth = depth;
        this.colors = colors;
        _hidden = false;
    }
    /// <summary>
    /// Full constructor with per-instance alignment modes.
    /// </summary>
    public UITextInstance( UIText parentText, string text, float xPos, float yPos, float scale, int depth, Color[] colors, UITextAlignMode alignMode, UITextVerticalAlignMode verticalAlignMode )
        : base()
    {
        _parentText = parentText;
        _text = text;
        _scale = scale;
        this.colors = colors;
        position = new Vector3( xPos, -yPos, depth );
        _hidden = false;

        // Set anchor alignment
        _alignMode = alignMode;
        switch( alignMode )
        {
            case UITextAlignMode.Left:
                _anchorInfo.OriginUIxAnchor = UIxAnchor.Left;
                break;
            case UITextAlignMode.Center:
                _anchorInfo.OriginUIxAnchor = UIxAnchor.Center;
                break;
            case UITextAlignMode.Right:
                _anchorInfo.OriginUIxAnchor = UIxAnchor.Right;
                break;
        }

        // Set anchor vertical alignment
        _verticalAlignMode = verticalAlignMode;
        switch( verticalAlignMode )
        {
            case UITextVerticalAlignMode.Top:
                _anchorInfo.OriginUIyAnchor = UIyAnchor.Top;
                break;
            case UITextVerticalAlignMode.Middle:
                _anchorInfo.OriginUIyAnchor = UIyAnchor.Center;
                break;
            case UITextVerticalAlignMode.Bottom:
                _anchorInfo.OriginUIyAnchor = UIyAnchor.Bottom;
                break;
        }

        _anchorInfo.OffsetX = xPos;
        _anchorInfo.OffsetY = yPos;

        updateSize();
    }
    public UITextInstance addTextInstance(string text, float xPos, float yPos, float scale, int depth, Color[] colors, UITextAlignMode alignMode, UITextVerticalAlignMode verticalAlignMode)
    {
        if (forceLowAscii)
        {
            forceLowAsciiString(ref text);
        }

        var textInstance = new UITextInstance(this, text, xPos, yPos, scale, depth, colors, alignMode, verticalAlignMode);

        textInstance.parent = _manager.transform;
        drawText(textInstance, textInstance.xPos, textInstance.yPos, textInstance.textScale, textInstance.depth, colors, textInstance.alignMode, textInstance.verticalAlignMode);

        return(textInstance);
    }
 public UITextInstance addTextInstance(string text, float xPos, float yPos, float scale, int depth, Color color, UITextAlignMode alignMode, UITextVerticalAlignMode verticalAlignMode)
 {
     return(addTextInstance(text, xPos, yPos, scale, depth, new Color[] { color }, alignMode, verticalAlignMode));
 }
    /// <summary>
    /// Performs horizontal alignment of each line independently.
    /// </summary>
    private void alignLine(List <UISprite> sprites, int lineStartChar, int lineEndChar, float lineWidth, UITextAlignMode instanceAlignMode)
    {
        if (instanceAlignMode == UITextAlignMode.Left)
        {
            return;
        }


        if (instanceAlignMode == UITextAlignMode.Center)
        {
            // Go from start character to end character, INCLUSIVE.
            for (var i = lineStartChar; i <= lineEndChar; i++)
            {
                // HACK: Gabo edit. Changed the if statement from sprites[i] != null because it was causing an error when the
                // text changed and the number of lines increased.
                if (i < sprites.Count && sprites[i] != null)
                {
                    sprites[i].position = new Vector3(sprites[i].position.x - lineWidth / 2.0f, sprites[i].position.y, sprites[i].position.z);
                }
            }
        }
        else if (instanceAlignMode == UITextAlignMode.Right)
        {
            // Go from start character to end character, INCLUSIVE.
            for (var i = lineStartChar; i <= lineEndChar + 1; i++)
            {
                if (i < sprites.Count && sprites[i] != null)
                {
                    sprites[i].position = new Vector3(sprites[i].position.x - lineWidth, sprites[i].position.y, sprites[i].position.z);
                }
            }
        }
    }
    /// <summary>
    /// Draw text on screen, create each quad and send it to the manager
    /// </summary>
    private void drawText(UITextInstance textInstance, float xPos, float yPos, float scale, int depth, Color[] color, UITextAlignMode instanceAlignMode, UITextVerticalAlignMode instanceVerticalAlignMode)
    {
        // Start by resetting textInstance position
        textInstance.position = Vector3.zero;
        bool  hidden = textInstance.hidden;
        float dx     = 0;
        float dy     = 0;
        float offsetY;
        int   fontLineSkip = 0;
        int   charId       = 0;


        // Perform word wrapping ahead of sprite allocation!
        var text = textInstance.text;

        text = wrapText(text, scale);

        int lineStartChar = 0;
        int lineEndChar   = 0;

        float totalHeight = (_fontDetails[ASCII_LINEHEIGHT_REFERENCE].h * scale * lineSpacing);

        // HACK: Gabo edit
        int newLinesTotal = 0;

        for (var i = 0; i < text.Length; i++)
        {
            charId = System.Convert.ToInt32(text[i]);

            if (charId == ASCII_NEWLINE)
            {
                // calculate the size to center text on Y axis, based on its scale
                // 77 is the "M" char usually big enough to get a proper spaced
                // lineskip, use any other char if you want
                fontLineSkip += (int)(_fontDetails[ASCII_LINEHEIGHT_REFERENCE].h * scale * lineSpacing);
                totalHeight  += (int)(_fontDetails[ASCII_LINEHEIGHT_REFERENCE].h * scale * lineSpacing);
                alignLine(textInstance.textSprites, lineStartChar, lineEndChar, dx, instanceAlignMode);

                lineStartChar = i - newLinesTotal;
                if (this.Language == UITextLanguage.Arabic)
                {
                    newLinesTotal++;
                }
                if (this.Language == UITextLanguage.Hebrew)
                {
                    newLinesTotal++;
                }

                dx = 0;
            }
            else
            {
                // calculate the size to center text on Y axis, based on its scale
                offsetY = _fontDetails[charId].offsety * scale;
                dy      = offsetY + fontLineSkip;
            }

            // Extend end of line
            lineEndChar = i;

            if (charId != ASCII_NEWLINE)
            {
                // add quads for each char
                // Use curpos instead of i to compensate for line wrapping hyphenation
                // reuse a UISprite if we have one. if we don't, we need to set it's parent and add it to the textInstance's list
                var currentTextSprite   = textInstance.textSpriteAtIndex(i);
                var addingNewTextSprite = (currentTextSprite == null);

                currentTextSprite = configureSpriteForCharId(currentTextSprite, charId, dx, dy, scale, 0);

                if (addingNewTextSprite)
                {
                    currentTextSprite.color          = color.Length == 1 ? color[0] : color[i];
                    currentTextSprite.parentUIObject = textInstance;
                    textInstance.textSprites.Add(currentTextSprite);
                }

                // Ensure the sprite is hidden if the textInstance is
                currentTextSprite.hidden = hidden;

                // See below @NOTE re: offsetx vs. xadvance bugfix.
                // advance the position to draw the next letter
                dx += _fontDetails[charId].xadvance * scale;
            }
        }

        alignLine(textInstance.textSprites, lineStartChar, lineEndChar, dx, instanceAlignMode);
        verticalAlignText(textInstance.textSprites, totalHeight, _fontDetails[ASCII_LINEHEIGHT_REFERENCE].offsety * scale * lineSpacing, instanceVerticalAlignMode);

        // Re-position textInstance
        textInstance.position = new Vector3(xPos, yPos, depth);
    }
Exemple #9
0
    /// <summary>
    /// Performs horizontal alignment of each line independently.
    /// </summary>
    private void alignLine(List <UISprite> sprites, int lineStartChar, int lineEndChar, float lineWidth, UITextAlignMode instanceAlignMode)
    {
        if (instanceAlignMode == UITextAlignMode.Left)
        {
            return;
        }


        if (instanceAlignMode == UITextAlignMode.Center)
        {
            // Go from start character to end character, INCLUSIVE.
            for (var i = lineStartChar; i <= lineEndChar; i++)
            {
                if (sprites[i] != null)
                {
                    sprites[i].position = new Vector3(sprites[i].position.x - lineWidth / 2.0f, sprites[i].position.y, sprites[i].position.z);
                }
            }
        }
        else if (instanceAlignMode == UITextAlignMode.Right)
        {
            // Go from start character to end character, INCLUSIVE.
            for (var i = lineStartChar; i <= lineEndChar; i++)
            {
                if (i < sprites.Count && sprites[i] != null)
                {
                    sprites[i].position = new Vector3(sprites[i].position.x - lineWidth, sprites[i].position.y, sprites[i].position.z);
                }
            }
        }
    }
Exemple #10
0
    /// <summary>
    /// Draw text on screen, create each quad and send it to the manager
    /// </summary>
    private int drawText( string text, float xPos, float yPos, float scale, int depth, Color[] color, UITextAlignMode instanceAlignMode, UITextVerticalAlignMode instanceVerticalAlignMode )
    {
        float dx = xPos;
        float dy = 0;

        float offsetY;

        int fontLineSkip = 0;

        int charId = 0;

        UISprite[] sprites = null;

        // Perform word wrapping ahead of sprite allocation!
        text = wrapText(text, scale);

        int length = text.Length;
        sprites = new UISprite[length];

        int lineStartChar = 0;
        int lineEndChar = 0;

        float totalHeight = ( _fontDetails[ASCII_LINEHEIGHT_REFERENCE].h * scale * lineSpacing );

        for( var i = 0; i < text.Length; i++ )
        {
            charId = System.Convert.ToInt32( text[i] );

            if( charId == ASCII_NEWLINE )
            {
                // calculate the size to center text on Y axis, based on its scale
                // 77 is the "M" char usually big enough to get a proper spaced
                // lineskip, use any other char if you want
                fontLineSkip += (int)( _fontDetails[ASCII_LINEHEIGHT_REFERENCE].h * scale * lineSpacing );
                totalHeight += (int)( _fontDetails[ASCII_LINEHEIGHT_REFERENCE].h * scale * lineSpacing );

                alignLine( sprites, lineStartChar, lineEndChar, dx - xPos, instanceAlignMode );

                lineStartChar = i+1;

                dx = xPos;
            }
            else
            {
                // calculate the size to center text on Y axis, based on its scale
                offsetY = _fontDetails[charId].offsety * scale;
                dy = offsetY + fontLineSkip;
            }
            // Extend end of line
            lineEndChar = i;

            // add quads for each char
            // Use curpos instead of i to compensate for line wrapping hyphenation
            sprites[i] = spriteForCharId( charId, dx, dy + yPos, scale, depth );
            _manager.addSprite( sprites[i] );
            sprites[i].color = color.Length == 1 ? color[0] : color[i];

            // See below @NOTE re: offsetx vs. xadvance bugfix.
            // advance the position to draw the next letter
            dx += _fontDetails[charId].xadvance * scale;

        }
        alignLine( sprites, lineStartChar, lineEndChar, dx - xPos, instanceAlignMode );

        verticalAlignText( sprites, totalHeight, _fontDetails[ASCII_LINEHEIGHT_REFERENCE].offsety * scale * lineSpacing, instanceVerticalAlignMode );

        // add all sprites at once to the array, we use this later to delete the strings
        _textSprites.Add( sprites );

        return _textSprites.Count - 1;
    }
Exemple #11
0
    /// <summary>
    /// Performs horizontal alignment of each line independently.
    /// </summary>
    void alignLine( UISprite[] sprites, int lineStartChar, int lineEndChar, float lineWidth, UITextAlignMode instanceAlignMode )
    {
        if ( instanceAlignMode == UITextAlignMode.Left )
            return;

        if ( instanceAlignMode == UITextAlignMode.Center )
        {

            // Go from start character to end character, INCLUSIVE.

            for ( var i=lineStartChar; i<=lineEndChar; i++ )
            {
                if ( i < sprites.Length && sprites[i] != null )
                {
                    sprites[i].position = new Vector3(sprites[i].position.x - lineWidth/2.0f, sprites[i].position.y, sprites[i].position.z);
                }
            }
        }
        else if ( instanceAlignMode == UITextAlignMode.Right )
        {
            // Go from start character to end character, INCLUSIVE.

            for ( var i=lineStartChar; i<=lineEndChar; i++ )
            {
                if ( i < sprites.Length && sprites[i] != null )
                {
                    sprites[i].position = new Vector3(sprites[i].position.x - lineWidth, sprites[i].position.y, sprites[i].position.z);
                }
            }

        }
    }
Exemple #12
0
    public UITextInstance addTextInstance( string text, float xPos, float yPos, float scale, int depth, Color[] colors, UITextAlignMode alignMode, UITextVerticalAlignMode verticalAlignMode )
    {
        if( forceLowAscii )
            forceLowAsciiString( ref text );

        var textInstance = new UITextInstance( this, text, xPos, yPos, scale, depth, colors, alignMode, verticalAlignMode );
        textInstance.textIndex = drawText( text, xPos, yPos, scale, depth, colors, textInstance.alignMode, textInstance.verticalAlignMode );

        return textInstance;
    }
Exemple #13
0
 public UITextInstance addTextInstance( string text, float xPos, float yPos, float scale, int depth, Color color, UITextAlignMode alignMode, UITextVerticalAlignMode verticalAlignMode )
 {
     return addTextInstance( text, xPos, yPos, scale, depth, new Color[] { color }, alignMode, verticalAlignMode );
 }
	/// <summary>
	/// Draw text on screen, create each quad and send it to the manager
	/// </summary>
	private void drawText( UITextInstance textInstance, float xPos, float yPos, float scale, int depth, Color[] color, UITextAlignMode instanceAlignMode, UITextVerticalAlignMode instanceVerticalAlignMode )
	{
        // Start by resetting textInstance position
        textInstance.position = Vector3.zero;
        bool hidden = textInstance.hidden;
		float dx = 0;
		float dy = 0;
		float offsetY;
		int fontLineSkip = 0;
		int charId = 0;
		

		// Perform word wrapping ahead of sprite allocation!
		var text = textInstance.text;
		text = wrapText( text, scale );
		
		int lineStartChar = 0;
		int lineEndChar = 0;
		
		float totalHeight = ( _fontDetails[ASCII_LINEHEIGHT_REFERENCE].h * scale * lineSpacing );
		
		for( var i = 0; i < text.Length; i++ )
	    {
	    	charId = System.Convert.ToInt32( text[i] );
			
			if( charId == ASCII_NEWLINE )
			{
				// calculate the size to center text on Y axis, based on its scale
				// 77 is the "M" char usually big enough to get a proper spaced
				// lineskip, use any other char if you want
				fontLineSkip += (int)( _fontDetails[ASCII_LINEHEIGHT_REFERENCE].h * scale * lineSpacing );
				totalHeight += (int)( _fontDetails[ASCII_LINEHEIGHT_REFERENCE].h * scale * lineSpacing );
				
				alignLine( textInstance.textSprites, lineStartChar, lineEndChar, dx, instanceAlignMode );
				
				lineStartChar = i + 1;
				
				dx = 0;
			}
			else
			{
				// calculate the size to center text on Y axis, based on its scale
				offsetY = _fontDetails[charId].offsety * scale;
				dy = offsetY + fontLineSkip;
			}
			
			// Extend end of line
			lineEndChar = i;

			// add quads for each char
			// Use curpos instead of i to compensate for line wrapping hyphenation
			// reuse a UISprite if we have one. if we don't, we need to set it's parent and add it to the textInstance's list
			var currentTextSprite = textInstance.textSpriteAtIndex( i );
			var addingNewTextSprite = currentTextSprite == null;
			
			currentTextSprite = configureSpriteForCharId( currentTextSprite, charId, dx, dy, scale, 0 );
			
			if( addingNewTextSprite )
			{
				currentTextSprite.color = color.Length == 1 ? color[0] : color[i];
				currentTextSprite.parentUIObject = textInstance;
				textInstance.textSprites.Add( currentTextSprite );
			}

            // Ensure the sprite is hidden if the textInstance is
            currentTextSprite.hidden = hidden;
			
			// See below @NOTE re: offsetx vs. xadvance bugfix.
			// advance the position to draw the next letter
			dx += _fontDetails[charId].xadvance * scale;
		}
		
		alignLine( textInstance.textSprites, lineStartChar, lineEndChar, dx, instanceAlignMode );
		verticalAlignText( textInstance.textSprites, totalHeight, _fontDetails[ASCII_LINEHEIGHT_REFERENCE].offsety * scale * lineSpacing, instanceVerticalAlignMode );

        // Re-position textInstance
        textInstance.position = new Vector3(xPos, yPos, depth);
	}
Exemple #15
0
    /// <summary>
    /// Performs horizontal alignment of each line independently.
    /// </summary>
    private void alignLine( List<UISprite> sprites, int lineStartChar, int lineEndChar, float lineWidth, UITextAlignMode instanceAlignMode )
    {
        if( instanceAlignMode == UITextAlignMode.Left )
            return;

        if( instanceAlignMode == UITextAlignMode.Center )
        {
            // Go from start character to end character, INCLUSIVE.
            for ( var i = lineStartChar; i <= lineEndChar; i++ )
            {
                // HACK: Gabo edit. Changed the if statement from sprites[i] != null because it was causing an error when the
                // text changed and the number of lines increased.
                if( i < sprites.Count && sprites[i] != null )
                {
                    sprites[i].position = new Vector3( sprites[i].position.x - lineWidth / 2.0f, sprites[i].position.y, sprites[i].position.z );
                }
            }
        }
        else if( instanceAlignMode == UITextAlignMode.Right )
        {
            // Go from start character to end character, INCLUSIVE.
            for ( var i = lineStartChar; i <= lineEndChar+1; i++ )
            {
                if ( i < sprites.Count && sprites[i] != null )
                    sprites[i].position = new Vector3( sprites[i].position.x - lineWidth, sprites[i].position.y, sprites[i].position.z );
            }

        }
    }