• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# CCTextAlignment类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中CCTextAlignment的典型用法代码示例。如果您正苦于以下问题:C# CCTextAlignment类的具体用法?C# CCTextAlignment怎么用?C# CCTextAlignment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



CCTextAlignment类属于命名空间,在下文中一共展示了CCTextAlignment类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: CreateNativeLabel

        internal static CCTexture2D CreateNativeLabel(string text, CCSize dimensions, CCTextAlignment hAlignment,
		                                   CCVerticalTextAlignment vAlignment, string fontName,
		                                   float fontSize, CCColor4B textColor)
		{

		    if (string.IsNullOrEmpty(text))
		    {
		        return new CCTexture2D();
		    }

		    var font = CreateFont (fontName, fontSize);

            if (dimensions.Equals(CCSize.Zero))
            {
                CreateBitmap(1, 1);

                var ms = _graphics.MeasureString(text, font);
                
                dimensions.Width = ms.Width;
                dimensions.Height = ms.Height;
            }

            CreateBitmap((int)dimensions.Width, (int)dimensions.Height);

            var stringFormat = new StringFormat();

		    switch (hAlignment)
		    {
		        case CCTextAlignment.Left:
                    stringFormat.Alignment = StringAlignment.Near;
		            break;
		        case CCTextAlignment.Center:
                    stringFormat.Alignment = StringAlignment.Center;
		            break;
		        case CCTextAlignment.Right:
                    stringFormat.Alignment = StringAlignment.Far;
		            break;
		    }

		    switch (vAlignment)
		    {
		        case CCVerticalTextAlignment.Top:
        		    stringFormat.LineAlignment = StringAlignment.Near;
		            break;
		        case CCVerticalTextAlignment.Center:
        		    stringFormat.LineAlignment = StringAlignment.Center;
		            break;
		        case CCVerticalTextAlignment.Bottom:
        		    stringFormat.LineAlignment = StringAlignment.Far;
		            break;
		    }

            _graphics.DrawString(text, font, _brush, new RectangleF(0, 0, dimensions.Width, dimensions.Height), stringFormat);
            _graphics.Flush();

			var texture = new CCTexture2D();
			texture.InitWithStream (SaveToStream(), Microsoft.Xna.Framework.Graphics.SurfaceFormat.Bgra4444);

			return texture;
		}
开发者ID:Karunp,项目名称:cocos2d-xna,代码行数:60,代码来源:CCLabelUtilities-Gdi.cs


示例2: CCTextFieldTTF

 public CCTextFieldTTF(string text, string fontName, float fontSize, CCSize dimensions, CCTextAlignment hAlignment, CCVerticalTextAlignment vAlignment)
     : base(text, fontName, fontSize, dimensions, new CCLabelFormat( CCLabelFormatFlags.Unknown ) { Alignment = hAlignment,
         LineAlignment = vAlignment})
 {
     EditTitle = "Input";
     EditDescription = "Please provide input";
 }
开发者ID:ToraiRei,项目名称:cozy,代码行数:7,代码来源:CCTextFieldTTF.cs


示例3: CCLabelTTF

        public CCLabelTTF ()
        {
            m_hAlignment = CCTextAlignment.Center;
            m_vAlignment = CCVerticalTextAlignment.Top;
            m_pFontName = string.Empty;
            m_fFontSize = 0.0f;

            Init();
        }
开发者ID:huaqiangs,项目名称:cocos2d-xna,代码行数:9,代码来源:CCLabelTTF.cs


示例4: labelWithString

        /// <summary>
        /// creates a CCLabelTTF from a fontname, alignment, dimension and font size
        /// </summary>
        public static CCLabelTTF labelWithString(string label, CCSize dimensions, CCTextAlignment alignment, string fontName, float fontSize)
        {
            CCLabelTTF pRet = new CCLabelTTF();
            if (pRet != null && pRet.initWithString(label, dimensions, alignment, fontName, fontSize))
            {
                return pRet;
            }

            return null;
        }
开发者ID:liwq-net,项目名称:cocos2d-for-xna-windows,代码行数:13,代码来源:CCLabelTTF.cs


示例5: initWithPlaceHolder

        //////////////////////////////////////////////////////////////////////////
        // initialize
        //////////////////////////////////////////////////////////////////////////

        /** initializes the CCTextFieldTTF with a font name, alignment, dimension and font size */
        public bool initWithPlaceHolder(string placeholder, CCSize dimensions, CCTextAlignment alignment, string fontName, float fontSize)
        {
            if (placeholder != null)
            {
                //CC_SAFE_DELETE(m_pPlaceHolder);
                m_pPlaceHolder = placeholder;
            }

            return cclabelttf.initWithString(m_pPlaceHolder, dimensions, alignment, fontName, fontSize);
            //throw new NotFiniteNumberException();
        }
开发者ID:Ratel13,项目名称:cocos2d-x-for-xna,代码行数:16,代码来源:CCTextFieldTTF+.cs


示例6: initWithString

        /// <summary>
        /// initializes the CCLabelTTF with a font name, alignment, dimension and font size
        /// </summary>
        public bool initWithString(string label, CCSize dimensions, CCTextAlignment alignment, string fontName, float fontSize)
        {
            Debug.Assert(label != null);
            if (init())
            {
                m_tDimensions = new CCSize(dimensions.width * CCDirector.sharedDirector().ContentScaleFactor, dimensions.height * CCDirector.sharedDirector().ContentScaleFactor);
                m_eAlignment = alignment;

                m_pFontName = fontName;

                m_fFontSize = fontSize * CCDirector.sharedDirector().ContentScaleFactor;
                this.setString(label);
                return true;
            }
            return false;
        }
开发者ID:Ratel13,项目名称:cocos2d-x-for-xna,代码行数:19,代码来源:CCLabelTTF.cs


示例7: textFieldWithPlaceHolder

        //char * description();

        //////////////////////////////////////////////////////////////////////////
        // static constructor
        //////////////////////////////////////////////////////////////////////////

        /** creates a CCTextFieldTTF from a fontname, alignment, dimension and font size */
        public static CCTextFieldTTF textFieldWithPlaceHolder(string placeholder, CCSize dimensions, CCTextAlignment alignment, string fontName, float fontSize)
        {
            CCTextFieldTTF pRet = new CCTextFieldTTF();
            if (pRet != null && pRet.initWithPlaceHolder("", dimensions, alignment, fontName, fontSize))
            {
                //pRet->autorelease();
                if (placeholder != null)
                {
                    pRet.PlaceHolder = placeholder;
                }
                return pRet;
            }
            //CC_SAFE_DELETE(pRet);
            return null;
            throw new NotFiniteNumberException();
        }
开发者ID:Ratel13,项目名称:cocos2d-x-for-xna,代码行数:23,代码来源:CCTextFieldTTF+.cs


示例8: OnEnter

        public override void OnEnter()
        {
            base.OnEnter();

            var s = VisibleBoundsWorldspace.Size;

            menuLeft.Position = new CCPoint(50, s.Height / 2 - 20);
            menuRight.Position = new CCPoint(s.Width - 50, s.Height / 2 - 20);


            alignmentLabel = null;
            horizontalAlign = CCTextAlignment.Left;
            verticalAlign = CCVerticalTextAlignment.Top;


            blockSize = new CCSize(s.Width / 3, s.Height / 2);

            var leftPanel = new AlignmentPanel(blockSize, new CCColor4B(100, 100, 100, 255));
            var centerPanel = new AlignmentPanel(blockSize, new CCColor4B(200, 100, 100, 255));
            var rightPanel = new AlignmentPanel(blockSize, new CCColor4B(100, 100, 200, 255));

            leftPanel.IgnoreAnchorPointForPosition = false;
            centerPanel.IgnoreAnchorPointForPosition = false;
            rightPanel.IgnoreAnchorPointForPosition = false;

            leftPanel.AnchorPoint = CCPoint.AnchorMiddleLeft;
            centerPanel.AnchorPoint = CCPoint.AnchorMiddleLeft;
            rightPanel.AnchorPoint = CCPoint.AnchorMiddleLeft;

            leftPanel.Position = new CCPoint(0, s.Height / 2);
            centerPanel.Position = new CCPoint(blockSize.Width, s.Height / 2);
            rightPanel.Position = new CCPoint(blockSize.Width * 2, s.Height / 2);

            AddChild(leftPanel, -1);
            AddChild(rightPanel, -1);
            AddChild(centerPanel, -1);

            updateAlignment();
        }
开发者ID:KevinHeyer,项目名称:CocosSharp,代码行数:39,代码来源:LabelSystemFontAlignmentTest.cs


示例9: LabelTTFTest

        public LabelTTFTest()
        {
            var blockSize = new CCSize(200, 160);
			var s = Layer.VisibleBoundsWorldspace.Size;

			var colorLayer = new CCLayerColor(new CCColor4B(100, 100, 100, 255));
			colorLayer.AnchorPoint = CCPoint.Zero;
            colorLayer.Position = new CCPoint((s.Width - blockSize.Width) / 2, (s.Height - blockSize.Height) / 2);

            AddChild(colorLayer);

			CCMenuItemFont.FontSize = 32;
			CCMenuItemFont.FontName = "MarkerFelt";

			var menu = new CCMenu(
				new CCMenuItemFont("Left", setAlignmentLeft),
				new CCMenuItemFont("Center", setAlignmentCenter),
				new CCMenuItemFont("Right", setAlignmentRight)
                );
            menu.AlignItemsVertically(4);
            menu.Position = new CCPoint(50, s.Height / 2 - 20);
            AddChild(menu);

            menu = new CCMenu(
				new CCMenuItemFont("Top", setAlignmentTop),
				new CCMenuItemFont("Middle", setAlignmentMiddle),
				new CCMenuItemFont("Bottom", setAlignmentBottom)
                );
            menu.AlignItemsVertically(4);
            menu.Position = new CCPoint(s.Width - 50, s.Height / 2 - 20);
            AddChild(menu);

            m_plabel = null;
            m_eHorizAlign = CCTextAlignment.Left;
            m_eVertAlign = CCVerticalTextAlignment.Top;

            updateAlignment();
        }
开发者ID:netonjm,项目名称:CocosSharp,代码行数:38,代码来源:LabelTTFTest.cs


示例10: LabelTTFTest

        public LabelTTFTest()
        {
            var blockSize = new CCSize(200, 160);
            CCSize s = CCDirector.SharedDirector.WinSize;

            CCLayerColor colorLayer = new CCLayerColor(new CCColor4B(100, 100, 100, 255), blockSize.Width, blockSize.Height);
            colorLayer.AnchorPoint = new CCPoint(0, 0);
            colorLayer.Position = new CCPoint((s.Width - blockSize.Width) / 2, (s.Height - blockSize.Height) / 2);

            AddChild(colorLayer);

            CCMenuItemFont.FontSize = 30;
            CCMenu menu = new CCMenu(
                new CCMenuItemFont("Left", setAlignmentLeft),
                new CCMenuItemFont("Center", setAlignmentCenter),
                new CCMenuItemFont("Right", setAlignmentRight)
                );
            menu.AlignItemsVerticallyWithPadding(4);
            menu.Position = new CCPoint(50, s.Height / 2 - 20);
            AddChild(menu);

            menu = new CCMenu(
                new CCMenuItemFont("Top", setAlignmentTop),
                new CCMenuItemFont("Middle", setAlignmentMiddle),
                new CCMenuItemFont("Bottom", setAlignmentBottom)
                );
            menu.AlignItemsVerticallyWithPadding(4);
            menu.Position = new CCPoint(s.Width - 50, s.Height / 2 - 20);
            AddChild(menu);

            m_plabel = null;
            m_eHorizAlign = CCTextAlignment.CCTextAlignmentLeft;
            m_eVertAlign = CCVerticalTextAlignment.CCVerticalTextAlignmentTop;

            updateAlignment();
        }
开发者ID:CartBlanche,项目名称:cocos2d-xna,代码行数:36,代码来源:LabelTTFTest.cs


示例11: CCLabelTTF

 public CCLabelTTF (string text, string fontName, float fontSize, CCSize dimensions, CCTextAlignment hAlignment) :
     this (text, fontName, fontSize, dimensions, hAlignment, CCVerticalTextAlignment.Top)
 { }
开发者ID:pekayatt,项目名称:cocos2d-xna,代码行数:3,代码来源:CCLabelTTF.cs


示例12: InitWithString

 public bool InitWithString(string label, string fontName, float fontSize, CCSize dimensions, CCTextAlignment alignment)
 {
     return InitWithString(label, fontName, fontSize, dimensions, alignment, CCVerticalTextAlignment.Top);
 }
开发者ID:pekayatt,项目名称:cocos2d-xna,代码行数:4,代码来源:CCLabelTTF.cs


示例13: CCLabelBMFont

 public CCLabelBMFont(string str, string fntFile, float width, CCTextAlignment alignment, CCPoint imageOffset)
 {
     InitWithString(str, fntFile, new CCSize(width, 0), alignment, CCVerticalTextAlignment.Top, imageOffset, null);
 }
开发者ID:huaqiangs,项目名称:cocos2d-xna,代码行数:4,代码来源:CCLabelBMFont.cs


示例14: InitWithString

        protected virtual bool InitWithString(string theString, string fntFile, CCSize dimentions, CCTextAlignment hAlignment, CCVerticalTextAlignment vAlignment,
                                              CCPoint imageOffset, CCTexture2D texture)
        {
            Debug.Assert(m_pConfiguration == null, "re-init is no longer supported");
            Debug.Assert((theString == null && fntFile == null) || (theString != null && fntFile != null),
                         "Invalid params for CCLabelBMFont");

            if (!String.IsNullOrEmpty(fntFile))
            {
                CCBMFontConfiguration newConf = FNTConfigLoadFile(fntFile);
                if (newConf == null)
                {
                    CCLog.Log("CCLabelBMFont: Impossible to create font. Please check file: '{0}'", fntFile);
                    return false;
                }

                m_pConfiguration = newConf;

                m_sFntFile = fntFile;

                if (texture == null)
                {
                    try
                    {
                        texture = CCTextureCache.SharedTextureCache.AddImage(m_pConfiguration.AtlasName);
                    }
                    catch (Exception)
                    {
                        // Try the 'images' ref location just in case.
                        try
                        {
                            texture =
                                CCTextureCache.SharedTextureCache.AddImage(System.IO.Path.Combine("images",
                                                                                                  m_pConfiguration
                                                                                                      .AtlasName));
                        }
                        catch (Exception)
                        {
                            // Lastly, try <font_path>/images/<font_name>
                            string dir = System.IO.Path.GetDirectoryName(m_pConfiguration.AtlasName);
                            string fname = System.IO.Path.GetFileName(m_pConfiguration.AtlasName);
                            string newName = System.IO.Path.Combine(System.IO.Path.Combine(dir, "images"), fname);
                            texture = CCTextureCache.SharedTextureCache.AddImage(newName);
                        }
                    }
                }
            }
            else
            {
                texture = new CCTexture2D();
            }

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

            if (base.InitWithTexture(texture, theString.Length))
            {
                m_tDimensions = dimentions;

                m_pHAlignment = hAlignment;
                m_pVAlignment = vAlignment;

                m_cDisplayedOpacity = m_cRealOpacity = 255;
                m_tDisplayedColor = m_tRealColor = CCTypes.CCWhite;
                m_bCascadeOpacityEnabled = true;
                m_bCascadeColorEnabled = true;

                m_obContentSize = CCSize.Zero;

                m_bIsOpacityModifyRGB = m_pobTextureAtlas.Texture.HasPremultipliedAlpha;
                AnchorPoint = new CCPoint(0.5f, 0.5f);

                m_tImageOffset = imageOffset;

                m_pReusedChar = new CCSprite();
                m_pReusedChar.InitWithTexture(m_pobTextureAtlas.Texture, CCRect.Zero, false);
                m_pReusedChar.BatchNode = this;

                SetString(theString, true);

                return true;
            }
            return false;
        }
开发者ID:huaqiangs,项目名称:cocos2d-xna,代码行数:86,代码来源:CCLabelBMFont.cs


示例15: InitBMFont

        protected void InitBMFont(string theString, string fntFile, CCSize dimensions, CCTextAlignment hAlignment, CCVerticalTextAlignment vAlignment, 
            CCPoint imageOffset, CCTexture2D texture)
        {
            Debug.Assert(FontConfiguration == null, "re-init is no longer supported");
            Debug.Assert((theString == null && fntFile == null) || (theString != null && fntFile != null),
                "Invalid params for CCLabelBMFont");

            if (!String.IsNullOrEmpty(fntFile))
            {
                try
                {
                    FontAtlas = CCFontAtlasCache.GetFontAtlasFNT(fntFile, imageOffset);
                }
                catch {}

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

            }

            AnchorPoint = CCPoint.AnchorMiddle;

            FontConfiguration = CCBMFontConfiguration.FontConfigurationWithFile(fntFile);

            LabelType = CCLabelType.BitMapFont;

            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 = hAlignment;
            vertAlignment = vAlignment;

            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 = imageOffset;

            Text = theString;
        }
开发者ID:haithemaraissia,项目名称:CocosSharp,代码行数:67,代码来源:CCLabel.cs


示例16: initWithString

        ///<summary>
        /// Initializes a texture from a string with dimensions, alignment, font name and font size
        /// </summary>
        public bool initWithString(string text, CCSize dimensions, CCTextAlignment alignment, string fontName, float fontSize, Color fgColor, Color bgColor)
        {
            if (dimensions.width < 0 || dimensions.height < 0)
            {
                return false;
            }

            if (string.IsNullOrEmpty(text))
            {
                return false;
            }

            SpriteFont font = null;
            try
            {
                font = CCApplication.sharedApplication().content.Load<SpriteFont>(@"fonts/" + fontName);
            }
            catch (Exception)
            {
                if (fontName.EndsWith(".spritefont", StringComparison.OrdinalIgnoreCase))
                {
                    fontName = fontName.Substring(0, fontName.Length - 11);
                    font = CCApplication.sharedApplication().content.Load<SpriteFont>(@"fonts/" + fontName);
                }
            }
            if (CCSize.CCSizeEqualToSize(dimensions, new CCSize()))
            {
                Vector2 temp = font.MeasureString(text);
                dimensions.width = temp.X;
                dimensions.height = temp.Y;
            }

            Vector2 origin;
            if (CCTextAlignment.CCTextAlignmentRight == alignment)
            {
                origin = new Vector2(-(dimensions.width - font.MeasureString(text).X), 0);
            }
            else if (CCTextAlignment.CCTextAlignmentCenter == alignment)
            {
                origin = new Vector2(-(dimensions.width - font.MeasureString(text).X) / 2.0f, 0);
            }
            else
            {
                origin = new Vector2(0, 0);
            }

            float scale = 1.0f;//need refer fontSize;
            try
            {
            CCApplication app = CCApplication.sharedApplication();

            //*  for render to texture
            RenderTarget2D renderTarget = new RenderTarget2D(app.graphics.GraphicsDevice, (int)dimensions.width, (int)dimensions.height);
            app.graphics.GraphicsDevice.SetRenderTarget(renderTarget);
                app.graphics.GraphicsDevice.Clear(bgColor);

            app.spriteBatch.Begin();
                app.spriteBatch.DrawString(font, text, new Vector2(0, 0), fgColor, 0.0f, origin, scale, SpriteEffects.None, 0.0f);
            app.spriteBatch.End();

            app.graphics.GraphicsDevice.SetRenderTarget(null);

            // to copy the rendered target data to a plain texture(to the memory)
            Color[] colors1D = new Color[renderTarget.Width * renderTarget.Height];
            renderTarget.GetData(colors1D);
            texture2D = new Texture2D(app.GraphicsDevice, renderTarget.Width, renderTarget.Height);
            texture2D.SetData(colors1D);

            return initWithTexture(texture2D);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
            }
            return (false);
        }
开发者ID:Ratel13,项目名称:cocos2d-x-for-xna,代码行数:79,代码来源:CCTexture2D.cs


示例17: setAlignmentLeft

 private void setAlignmentLeft(object pSender)
 {
     m_eHorizAlign = CCTextAlignment.Left;
     updateAlignment();
 }
开发者ID:Karunp,项目名称:cocos2d-xna,代码行数:5,代码来源:LabelTTFTest.cs


示例18: CCLabel

 /// <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="hAlignment">Horizontal alignment of the text.</param>
 /// <param name="vAlignement">Vertical alignement of the text.</param>
 /// <param name="imageOffset">Image offset.</param>
 /// <param name="texture">Texture Atlas to be used.</param>
 public CCLabel(string str, string fntFile, CCSize dimensions, CCTextAlignment hAlignment, CCVerticalTextAlignment vAlignment, 
     CCPoint imageOffset, CCTexture2D texture)
     : this (str, fntFile, dimensions, 
         new CCLabelFormat() { Alignment = hAlignment, LineAlignment = vAlignment}, 
         imageOffset, texture)
 {   }
开发者ID:haithemaraissia,项目名称:CocosSharp,代码行数:16,代码来源:CCLabel.cs


示例19: mode

        /**
        Extensions to make it easy to create a CCTexture2D object from a string of text.
        Note that the generated textures are of type A8 - use the blending mode (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA).
        */

        public bool initWithString(string text, CCSize dimensions, CCTextAlignment alignment, string fontName, float fontSize)
        {
            return (initWithString(text, dimensions, alignment, fontName, fontSize, Color.YellowGreen, g_MyBlack));
        }
开发者ID:Ratel13,项目名称:cocos2d-x-for-xna,代码行数:9,代码来源:CCTexture2D.cs


示例20: setAlignmentCenter

 private void setAlignmentCenter(object pSender)
 {
     m_eHorizAlign = CCTextAlignment.CCTextAlignmentCenter;
     updateAlignment();
 }
开发者ID:CartBlanche,项目名称:cocos2d-xna,代码行数:5,代码来源:LabelTTFTest.cs



注:本文中的CCTextAlignment类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# CCTexture2D类代码示例发布时间:2022-05-24
下一篇:
C# CCSize类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap