Exemplo n.º 1
0
        public CCLabelFormat (CCLabelFormat format)
        {
            if (format == null)
                throw new ArgumentNullException ("format");

            Alignment = format.Alignment;
            LineAlignment = format.LineAlignment;
            FormatFlags = format.FormatFlags;
        }
Exemplo n.º 2
0
 public CCTextField(string text, string fontName, float fontSize, CCLabelFormat labelFormat)
     : this(text, fontName, fontSize, CCSize.Zero, CCTextAlignment.Center, CCVerticalTextAlignment.Top, labelFormat)
 {
 }
Exemplo n.º 3
0
        protected void InitSpriteFont(string theString, string fntFile, float fontSize, CCSize dimensions, CCLabelFormat labelFormat, 
            CCPoint imageOffset, CCTexture2D texture)
        {
            Debug.Assert((theString == null && fntFile == null) || (theString != null && fntFile != null),
                "Invalid params for CCLabel SpriteFont");

            if (!String.IsNullOrEmpty(fntFile))
            {
                try
                {
                    FontAtlas = CCFontAtlasCache.GetFontAtlasSpriteFont(fntFile, fontSize, imageOffset);
                    Scale = FontAtlas.Font.FontScale;
                }
                catch {}

                if (FontAtlas == null)
                {
                    CCLog.Log("SpriteFont CCLabel: Impossible to create font. Please check file: '{0}'", fntFile);
                    return;
                }

            }

            AnchorPoint = CCPoint.AnchorMiddle;

            LabelType = CCLabelType.SpriteFont;

            if (String.IsNullOrEmpty(theString))
            {
                theString = String.Empty;
            }

            // Initialize the TextureAtlas along with children.
            var capacity = theString.Length;

            BlendFunc = CCBlendFunc.AlphaBlend;

            if (capacity == 0)
            {
                capacity = defaultSpriteBatchCapacity;
            }

            UpdateBlendFunc();

            // no lazy alloc in this node
            Children = new CCRawList<CCNode>(capacity);
            Descendants = new CCRawList<CCSprite>(capacity);

            this.labelDimensions = dimensions;

            horzAlignment = labelFormat.Alignment;
            vertAlignment = labelFormat.LineAlignment;

            IsOpacityCascaded = true;

            ContentSize = CCSize.Zero;

            IsColorModifiedByOpacity = TextureAtlas.Texture.HasPremultipliedAlpha;
            AnchorPoint = CCPoint.AnchorMiddle;

            ImageOffset = imageOffset;

            Text = theString;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CocosSharp.CCLabel"/> class.
        /// </summary>
        /// <param name="str">Initial text of the label.</param>
        /// <param name="fntFile">Font definition file to use.</param>
        /// <param name="size">Font point size.</param>
        /// <param name="dimensions">Dimensions that the label should use to layout it's text.</param>
        /// <param name="labelFormat">Label format <see cref="CocosSharp.CCLabelFormat"/>.</param>
        /// <param name="imageOffset">Image offset.</param>
        /// <param name="texture">Texture atlas to be used.</param>
        public CCLabel(string str, string fntFile, float size, CCSize dimensions, CCLabelFormat labelFormat, CCPoint imageOffset, CCTexture2D texture)
        {
            quadCommand = new CCQuadCommand(str.Length);

            this.labelFormat = (size == 0 && labelFormat.FormatFlags == CCLabelFormatFlags.Unknown) 
                ? CCLabelFormat.BitMapFont 
                : labelFormat;

            if (this.labelFormat.FormatFlags == CCLabelFormatFlags.Unknown)
            {
                // First we try loading BitMapFont
                CCLog.Log("Label Format Unknown: Trying BitmapFont ...");
                InitBMFont(str, fntFile, dimensions, labelFormat.Alignment, labelFormat.LineAlignment, imageOffset, texture);
                // If we do not load a Bitmap Font then try a SpriteFont
                if (FontAtlas == null)
                {
                    CCLog.Log("Label Format Unknown: Trying SpriteFont ...");
                    InitSpriteFont(str, fntFile, size, dimensions, labelFormat, imageOffset, texture);
                }
                // If we do not load a Bitmap Font nor a SpriteFont then try the last time for a System Font
                if (FontAtlas == null)
                {
                    CCLog.Log("Label Format Unknown: Trying System Font ...");
                    LabelType = CCLabelType.SystemFont;
                    SystemFont = fntFile;
                    SystemFontSize = size;
                    Dimensions = dimensions;
                    AnchorPoint = CCPoint.AnchorMiddle;
                    BlendFunc = CCBlendFunc.AlphaBlend;
                    Text = str;
                }
            }
            else if(this.labelFormat.FormatFlags == CCLabelFormatFlags.BitmapFont)
            {
                // Initialize the BitmapFont
                InitBMFont(str, fntFile, dimensions, labelFormat.Alignment, labelFormat.LineAlignment, imageOffset, texture);
            }
            else if(this.labelFormat.FormatFlags == CCLabelFormatFlags.SpriteFont)
            {
                // Initialize the SpriteFont
                InitSpriteFont(str, fntFile, size, dimensions, labelFormat, imageOffset, texture);

            }
            else if(this.labelFormat.FormatFlags == CCLabelFormatFlags.SystemFont)
            {
                LabelType = CCLabelType.SystemFont;
                SystemFont = fntFile;
                SystemFontSize = size;
                Dimensions = dimensions;
                AnchorPoint = CCPoint.AnchorMiddle;
                BlendFunc = CCBlendFunc.AlphaBlend;
                Text = str;
            }

        }
Exemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CocosSharp.CCLabel"/> class.
        /// </summary>
        /// <param name="str">Initial text of the label.</param>
        /// <param name="fntFile">Font definition file to use.</param>
        /// <param name="size">Font point size.</param>
        /// <param name="dimensions">Dimensions that the label should use to layout it's text.</param>
        /// <param name="labelFormat">Label format <see cref="CocosSharp.CCLabelFormat"/>.</param>
        /// <param name="imageOffset">Image offset.</param>
        /// <param name="texture">Texture atlas to be used.</param>
        public CCLabel(CCFontFNT fntFontConfig, string str, CCSize dimensions, CCLabelFormat labelFormat)
        {
            quadCommand = new CCQuadCommand(str.Length);

            labelFormat.FormatFlags = CCLabelFormatFlags.BitmapFont;
            AnchorPoint = CCPoint.AnchorMiddle;

            try
            {
                FontAtlas = CCFontAtlasCache.GetFontAtlasFNT(fntFontConfig);
            }
            catch { }

            if (FontAtlas == null)
            {
                CCLog.Log("Bitmap Font CCLabel: Impossible to create font. Please check CCFontFNT file: ");
                return;
            }

            LabelType = CCLabelType.BitMapFont;
            this.labelFormat = labelFormat;

            if (String.IsNullOrEmpty(str))
            {
                str = String.Empty;
            }

            // Initialize the TextureAtlas along with children.
            var capacity = str.Length;

            BlendFunc = CCBlendFunc.AlphaBlend;

            if (capacity == 0)
            {
                capacity = defaultSpriteBatchCapacity;
            }

            UpdateBlendFunc();

            // no lazy alloc in this node
            Children = new CCRawList<CCNode>(capacity);
            Descendants = new CCRawList<CCSprite>(capacity);

            this.labelDimensions = dimensions;

            horzAlignment = labelFormat.Alignment;
            vertAlignment = labelFormat.LineAlignment;

            IsOpacityCascaded = true;

            // We use base here so we do not trigger an update internally.
            base.ContentSize = CCSize.Zero;

            IsColorModifiedByOpacity = TextureAtlas.Texture.HasPremultipliedAlpha;
            AnchorPoint = CCPoint.AnchorMiddle;

            ImageOffset = CCPoint.Zero;

            Text = str;
        }
Exemplo n.º 6
0
 public CCTextField(string text, string fontName, float fontSize, CCLabelFormat labelFormat)
     : this(text, fontName, fontSize, CCSize.Zero, CCTextAlignment.Center, CCVerticalTextAlignment.Top, labelFormat)
 {
 }
Exemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CocosSharp.CCLabel"/> class.
 /// </summary>
 /// <param name="str">Initial text of the label.</param>
 /// <param name="fntFile">Font definition file to use.</param>
 /// <param name="dimensions">Dimensions that the label should use to layout it's text.</param>
 /// <param name="labelFormat">Label format <see cref="CocosSharp.CCLabelFormat"/>.</param>
 /// <param name="imageOffset">Image offset.</param>
 /// <param name="texture">Texture atlas to be used.</param>
 public CCLabel(string str, string fntFile, CCSize dimensions, CCLabelFormat labelFormat, CCPoint imageOffset, CCTexture2D texture)
     : this (str, fntFile, 0.0f, dimensions, labelFormat, imageOffset, texture)
 {
 }
Exemplo n.º 8
0
 public CCLabel(string str, string fntFile, float size, CCSize dimensions, CCLabelFormat labelFormat)
     : this(str, fntFile, size, dimensions, labelFormat, CCPoint.Zero, null)
 {
 }
Exemplo n.º 9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CocosSharp.CCLabel"/> class.
 /// </summary>
 /// <param name="str">Initial text of the label.</param>
 /// <param name="fntFile">Font definition file to use.</param>
 /// <param name="size">Font point size.</param>
 /// <param name="labelFormat">Label format <see cref="CocosSharp.CCLabelFormat"/>.</param>
 public CCLabel(string str, string fntFile, float size, CCLabelFormat labelFormat)
     : this (str, fntFile, size, CCSize.Zero, labelFormat)
 {   }
Exemplo n.º 10
0
        protected void InitSpriteFont(string theString, string fntFile, float fontSize, CCSize dimensions, CCLabelFormat labelFormat,
                                      CCPoint imageOffset, CCTexture2D texture)
        {
            Debug.Assert((theString == null && fntFile == null) || (theString != null && fntFile != null),
                         "Invalid params for CCLabel SpriteFont");

            if (!String.IsNullOrEmpty(fntFile))
            {
                try
                {
                    FontAtlas = CCFontAtlasCache.GetFontAtlasSpriteFont(fntFile, fontSize, imageOffset);
                    Scale     = FontAtlas.Font.FontScale;
                }
                catch {}

                if (FontAtlas == null)
                {
                    CCLog.Log("SpriteFont CCLabel: Impossible to create font. Please check file: '{0}'", fntFile);
                    return;
                }
            }

            AnchorPoint = CCPoint.AnchorMiddle;

            LabelType = CCLabelType.SpriteFont;

            if (String.IsNullOrEmpty(theString))
            {
                theString = String.Empty;
            }

            // Initialize the TextureAtlas along with children.
            var capacity = theString.Length;

            BlendFunc = CCBlendFunc.AlphaBlend;

            if (capacity == 0)
            {
                capacity = defaultSpriteBatchCapacity;
            }

            UpdateBlendFunc();

            // no lazy alloc in this node
            Children    = new CCRawList <CCNode>(capacity);
            Descendants = new CCRawList <CCSprite>(capacity);

            this.labelDimensions = dimensions;

            horzAlignment = labelFormat.Alignment;
            vertAlignment = labelFormat.LineAlignment;

            IsOpacityCascaded = true;

            ContentSize = CCSize.Zero;

            IsColorModifiedByOpacity = TextureAtlas.Texture.HasPremultipliedAlpha;
            AnchorPoint = CCPoint.AnchorMiddle;

            ImageOffset = imageOffset;

            Text = theString;
        }
Exemplo n.º 11
0
 public CCLabel(string str, string fntFile, float size, CCLabelFormat labelFormat)
     : this(str, fntFile, size, CCSize.Zero, labelFormat)
 {
 }
Exemplo n.º 12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CocosSharp.CCLabel"/> class.
 /// </summary>
 /// <param name="str">Initial text of the label.</param>
 /// <param name="fntFile">Font definition file to use.</param>
 /// <param name="dimensions">Dimensions that the label should use to layout it's text.</param>
 /// <param name="labelFormat">Label format <see cref="CocosSharp.CCLabelFormat"/>.</param>
 /// <param name="imageOffset">Image offset.</param>
 /// <param name="texture">Texture atlas to be used.</param>
 public CCLabel(string str, string fntFile, CCSize dimensions, CCLabelFormat labelFormat, CCPoint imageOffset, CCTexture2D texture)
 {
     this.labelFormat = labelFormat;
     // First we try loading BitMapFont
     InitBMFont(str, fntFile, dimensions, labelFormat.Alignment, labelFormat.LineAlignment, imageOffset, texture);
 }
Exemplo n.º 13
0
 public CCTextField(string text, string fontName, float fontSize, CCSize dimensions, CCTextAlignment hAlignment, CCVerticalTextAlignment vAlignment, CCLabelFormat labelFormat)
     : base(text, fontName, fontSize, dimensions, labelFormat)
 {
     this.HorizontalAlignment = hAlignment;
     this.VerticalAlignment   = vAlignment;
     AutoRepeat      = true;
     placeHolderText = text;
     updateColors();
     TextFieldIMEImplementation = IMEKeyboardImpl.SharedInstance;
 }
Exemplo n.º 14
0
 public CCTextField(string text, string fontName, float fontSize, CCSize dimensions, CCTextAlignment hAlignment, CCLabelFormat labelFormat)
     : this(text, fontName, fontSize, dimensions, hAlignment, CCVerticalTextAlignment.Top, labelFormat)
 {
 }
Exemplo n.º 15
0
 public CCTextField(string text, string fontName, float fontSize, CCSize dimensions, CCTextAlignment hAlignment, CCLabelFormat labelFormat)
     : this(text, fontName, fontSize, dimensions, hAlignment, CCVerticalTextAlignment.Top, labelFormat)
 {
 }
Exemplo n.º 16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CocosSharp.CCLabel"/> class.
 /// </summary>
 /// <param name="str">Initial text of the label.</param>
 /// <param name="fntFile">Font definition file to use.</param>
 /// <param name="size">Font point size.</param>
 /// <param name="dimensions">Dimensions that the label should use to layout it's text.</param>
 /// <param name="labelFormat">Label format <see cref="CocosSharp.CCLabelFormat"/>.</param>
 public CCLabel(string str, string fntFile, float size, CCSize dimensions, CCLabelFormat labelFormat)
     : this (str, fntFile, size, dimensions, labelFormat, CCPoint.Zero, null)
 {   }
Exemplo n.º 17
0
        public CCTextField(string text, string fontName, float fontSize, CCSize dimensions, CCTextAlignment hAlignment, CCVerticalTextAlignment vAlignment, CCLabelFormat labelFormat)
            : base(text, fontName, fontSize, dimensions, labelFormat)
        {
            this.HorizontalAlignment = hAlignment;
            this.VerticalAlignment = vAlignment;
            AutoRepeat = true;
            placeHolderText = text;
            updateColors();
            TextFieldIMEImplementation = IMEKeyboardImpl.SharedInstance;

        }
        private void updateAlignment()
        {
			var s = VisibleBoundsWorldspace.Size;

            if (alignmentLabel != null)
            {
                alignmentLabel.RemoveFromParent(true);
            }

            var labelFormat = new CCLabelFormat(CCLabelFormatFlags.SystemFont) { Alignment = horizontalAlign, LineAlignment = verticalAlign };

            alignmentLabel = new CCLabel(getCurrentAlignment(), "Arial", 32,
                                         blockSize, labelFormat);

            alignmentLabel.AnchorPoint = CCPoint.AnchorLowerLeft;
            alignmentLabel.Position = new CCPoint((s.Width - blockSize.Width) / 2, (s.Height - blockSize.Height) / 2);

            AddChild(alignmentLabel);
        }