本文整理汇总了C#中CCTextAlignment类的典型用法代码示例。如果您正苦于以下问题:C# CCTextAlignment类的具体用法?C# CCTextAlignment怎么用?C# CCTextAlignment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CCTextAlignment类属于命名空间,在下文中一共展示了CCTextAlignment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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";
}
示例3: CCLabelTTF
public CCLabelTTF ()
{
m_hAlignment = CCTextAlignment.Center;
m_vAlignment = CCVerticalTextAlignment.Top;
m_pFontName = string.Empty;
m_fFontSize = 0.0f;
Init();
}
示例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;
}
示例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();
}
示例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;
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例11: CCLabelTTF
public CCLabelTTF (string text, string fontName, float fontSize, CCSize dimensions, CCTextAlignment hAlignment) :
this (text, fontName, fontSize, dimensions, hAlignment, CCVerticalTextAlignment.Top)
{ }
示例12: InitWithString
public bool InitWithString(string label, string fontName, float fontSize, CCSize dimensions, CCTextAlignment alignment)
{
return InitWithString(label, fontName, fontSize, dimensions, alignment, CCVerticalTextAlignment.Top);
}
示例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);
}
示例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;
}
示例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;
}