示例#1
0
        // Here is where the canvas and the font are available,
        // so this is where the location of both the text label
        // and the animated sprite can be properly positioned
        protected override void Init()
        {
            // Get sprite dimensions
            int spriteWidth  = AnimatedSprite.GetWidth();
            int spriteHeight = AnimatedSprite.GetHeight();

            // Get text dimensions
            int textWidth  = TextLabel.GetWidth();
            int textHeight = TextLabel.GetHeight();

            // Compute the dimensions of the MyIconLabel
            if (floatingIconPosition == Constants.FLOATING_POSITION_LEFT || floatingIconPosition == Constants.FLOATING_POSITION_RIGHT)
            {
                width  = spriteWidth + spacing + textWidth;
                height = spriteHeight > textHeight ? spriteHeight : textHeight;
            }
            else
            {
                width  = spriteWidth > textWidth ? spriteWidth : textWidth;
                height = spriteHeight + spacing + textHeight;
            }

            // Compute the horizontal positions of the icon and label
            if (floatingIconPosition == Constants.FLOATING_POSITION_LEFT)
            {
                AnimatedSprite.x = 0;
                TextLabel.x      = spriteWidth + spacing;
            }
            else if (floatingIconPosition == Constants.FLOATING_POSITION_RIGHT)
            {
                AnimatedSprite.x = width - spriteWidth;
                TextLabel.x      = AnimatedSprite.x - spacing - textWidth;
            }
            else if (floatingIconPosition == Constants.FLOATING_POSITION_TOP || floatingIconPosition == Constants.FLOATING_POSITION_BOTTOM)
            {
                AnimatedSprite.x = (width - spriteWidth) / 2;
                TextLabel.x      = (width - textWidth) / 2;
            }

            // Compute the vertical positions of the icon and label
            if (floatingIconPosition == Constants.FLOATING_POSITION_LEFT || floatingIconPosition == Constants.FLOATING_POSITION_RIGHT)
            {
                TextLabel.y      = (height - textHeight) / 2;
                AnimatedSprite.y = (height - spriteHeight) / 2;
            }
            else if (floatingIconPosition == Constants.FLOATING_POSITION_TOP)
            {
                AnimatedSprite.y = 0;
                TextLabel.y      = spriteHeight + spacing;
            }
            else if (floatingIconPosition == Constants.FLOATING_POSITION_BOTTOM)
            {
                TextLabel.y      = 0;
                AnimatedSprite.y = textHeight + spacing;
            }
        }
示例#2
0
 public override int GetHeight()
 {
     return(Sprite.GetHeight());
 }