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;
		}
 public static void DrawPoints(CCPoint[] points, int numberOfPoints, float size, CCColor4B color)
 {
     for (int i = 0; i < numberOfPoints; i++)
     {
         DrawPoint(points[i], size, color);
     }
 }
        public static void DrawLine(CCPoint origin, CCPoint destination, CCColor4B color)
        {
            var c = new Color(color.R, color.G, color.B, color.A);

            m_Batch.AddVertex(new Vector2(origin.X, origin.Y), c, PrimitiveType.LineList);
            m_Batch.AddVertex(new Vector2(destination.X, destination.Y), c, PrimitiveType.LineList);
        }
 /// <summary>
 /// initializes the transition with a duration and with an RGB color 
 /// </summary>
 protected virtual bool InitWithDuration(float duration, CCScene scene, CCColor3B color)
 {
     if (base.InitWithDuration(duration, scene))
     {
         m_tColor = new CCColor4B {R = color.R, G = color.G, B = color.B, A = 0};
     }
     return true;
 }
 public static CCColor4F CCC4FFromCCC4B(CCColor4B byteColor)
 {
     CCColor4F color;
     color.R = CCColorFloatFromByte(byteColor.R);
     color.G = CCColorFloatFromByte(byteColor.G);
     color.B = CCColorFloatFromByte(byteColor.B);
     color.A = CCColorFloatFromByte(byteColor.A);
     return color;
 }
 public static void DrawPoints(b2Vec2[] points, int numberOfPoints, float size, b2Color color)
 {
     CCColor4B ccolor = new CCColor4B(color.r, color.g, color.b, 255);
     CCPoint pt = CCPoint.Zero;
     for (int i = 0; i < numberOfPoints; i++)
     {
         pt.X = points[i].x;
         pt.Y = points[i].y;
         DrawPoint(pt, size, ccolor);
     }
 }
        public static void DrawRect(CCRect rect, CCColor4B color)
        {
            float x1 = rect.MinX;
            float y1 = rect.MinY;
            float x2 = rect.MaxX;
            float y2 = rect.MaxY;

            DrawLine(new CCPoint(x1, y1), new CCPoint(x2, y1), color);
            DrawLine(new CCPoint(x2, y1), new CCPoint(x2, y2), color);
            DrawLine(new CCPoint(x2, y2), new CCPoint(x1, y2), color);
            DrawLine(new CCPoint(x1, y2), new CCPoint(x1, y1), color);
        }
		private void CreateBitmap(int width, int height)
		{
//			if (_bitmap == null || (_bitmap.Width < width || _bitmap.Height < height))
//			{

				_bitmap = CCLabelUtilities.CreateBitmap (width, height);
			//}

			//if (_brush == null)
			//{
				_brush = new CCColor4B(Microsoft.Xna.Framework.Color.White);
			//}
		}
        public static void DrawPoint(CCPoint p, float size, CCColor4B color)
        {
            var verts = new CCPoint[4];

            float hs = size / 2.0f;

            verts[0] = p + new CCPoint(-hs, -hs);
            verts[1] = p + new CCPoint(hs, -hs);
            verts[2] = p + new CCPoint(hs, hs);
            verts[3] = p + new CCPoint(-hs, hs);

            DrawPoly(verts, 4, false, true, color);
        }
Exemple #10
0
        public void DrawCircle(CCPoint center, float radius, float angle, int segments, CCColor4B color)
        {
            float increment = MathHelper.Pi * 2.0f / segments;
            double theta = 0.0;

            CCPoint v1;
            CCPoint v2 = CCPoint.Zero;
            List<CCPoint> verts = new List<CCPoint>();

            for (int i = 0; i < segments; i++)
            {
                v1 = center + new CCPoint((float)Math.Cos(theta), (float)Math.Sin(theta)) * radius;
                v2 = center + new CCPoint((float)Math.Cos(theta + increment), (float)Math.Sin(theta + increment)) * radius;
                verts.Add(v1);
                theta += increment;
            }
            CCColor4F cf = new CCColor4F(color.R/255f, color.G/255f, color.B/255f, color.A/255f);
            DrawPolygon(verts.ToArray(), verts.Count, cf, 0, new CCColor4F(0f, 0f, 0f, 0f));
        }
Exemple #11
0
 /// <summary>
 /// initializes a CCLayer with color
 /// </summary>
 public virtual bool InitWithColor(CCColor4B color)
 {
     CCSize s = CCDirector.SharedDirector.WinSize;
     return InitWithColor(color, s.Width, s.Height);
 }
Exemple #12
0
        public static CCColor4B Lerp(CCColor4B value1, CCColor4B value2, float amount)
        {
            CCColor4B color;

            color.A = (byte)(value1.A + ((value2.A - value1.A) * amount));
            color.R = (byte)(value1.R + ((value2.R - value1.R) * amount));
            color.G = (byte)(value1.G + ((value2.G - value1.G) * amount));
            color.B = (byte)(value1.B + ((value2.B - value1.B) * amount));

            return color;
        }
Exemple #13
0
        public override void Draw()
        {
            var map = (CCTMXTiledMap) GetChildByTag(kTagTileMap);
            CCTMXObjectGroup group = map.ObjectGroupNamed("Object Group 1");
            
            List<Dictionary<string, string>> objects = group.Objects;
            foreach (var dict in objects)
            {
                float x = float.Parse(dict["x"]);
                float y = float.Parse(dict["y"]);
                float width = (dict.ContainsKey("width") ? float.Parse(dict["width"]) : 0f);
                float height = (dict.ContainsKey("height") ? float.Parse(dict["height"]) : 0f);

                var color = new CCColor4B(255, 255, 0, 255);

                CCDrawingPrimitives.Begin();
                CCDrawingPrimitives.DrawLine(this.NodeToWorldTransform().Transform(new CCPoint(x, y)), this.NodeToWorldTransform().Transform(new CCPoint((x + width), y)), color);
                CCDrawingPrimitives.DrawLine(this.NodeToWorldTransform().Transform(new CCPoint((x + width), y)), this.NodeToWorldTransform().Transform(new CCPoint((x + width), (y + height))), color);
                CCDrawingPrimitives.DrawLine(this.NodeToWorldTransform().Transform(new CCPoint((x + width), (y + height))), this.NodeToWorldTransform().Transform(new CCPoint(x, (y + height))), color);
                CCDrawingPrimitives.DrawLine(this.NodeToWorldTransform().Transform(new CCPoint(x, (y + height))), this.NodeToWorldTransform().Transform(new CCPoint(x, y)), color);
                CCDrawingPrimitives.End();

                //glLineWidth(1);
            }
        }
Exemple #14
0
 /// <summary>
 /// creates a CCLayer with color, width and height in Points
 /// </summary>
 public CCLayerColor (CCColor4B color, float width, float height) : this()
 {
     InitWithColor(color, width, height);
 }
Exemple #15
0
        public bool InitWithTexture(CCTexture2D pTexture, CCRect rect, bool rotated)
        {
            base.Init();

            m_pobBatchNode = null;

            // shader program
            //setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTextureColor));

            m_bRecursiveDirty = false;
            Dirty = false;

            m_bOpacityModifyRGB = true;
            m_sBlendFunc = CCBlendFunc.AlphaBlend;

            m_bFlipX = m_bFlipY = false;

            // default transform anchor: center
            AnchorPoint = new CCPoint(0.5f, 0.5f);

            // zwoptex default values
            m_obOffsetPosition = CCPoint.Zero;

            m_bHasChildren = false;

            // clean the Quad
            m_sQuad = new CCV3F_C4B_T2F_Quad();

            // Atlas: Color
            var tmpColor = new CCColor4B(255, 255, 255, 255);
            m_sQuad.BottomLeft.Colors = tmpColor;
            m_sQuad.BottomRight.Colors = tmpColor;
            m_sQuad.TopLeft.Colors = tmpColor;
            m_sQuad.TopRight.Colors = tmpColor;

            // update texture (calls updateBlendFunc)
            Texture = pTexture;
            SetTextureRect(rect, rotated, rect.Size);

            // by default use "Self Render".
            // if the sprite is added to a batchnode, then it will automatically switch to "batchnode Render"
            BatchNode = null;

            return true;
        }
		private static NSMutableAttributedString buildAttributedString(string text, CTFont font, 
		                                                               CCColor4B? fontColor=null) 
		{

			// Create a new attributed string definition
			var ctAttributes = new CTStringAttributes ();

			// Font attribute
			ctAttributes.Font = font;
			// -- end font 

			if (fontColor.HasValue) {

				// Font color
				var fc = fontColor.Value;
                var cgColor = new CGColor(fc.R / 255f, 
                                             fc.G / 255f,
                                             fc.B / 255f,
                                             fc.A / 255f);

				ctAttributes.ForegroundColor = cgColor;
				ctAttributes.ForegroundColorFromContext = false;
				// -- end font Color
			}

			if (underLine) {
				// Underline
				#if MACOS
				int single = (int)MonoMac.AppKit.NSUnderlineStyle.Single;
				int solid = (int)MonoMac.AppKit.NSUnderlinePattern.Solid;
				var attss = single | solid;
				ctAttributes.UnderlineStyleValue = attss;
				#else
				ctAttributes.UnderlineStyleValue = 1;
				#endif
				// --- end underline
			}


			if (strikeThrough) {
				// StrikeThrough
				//				NSColor bcolor = NSColor.Blue;
				//				NSObject bcolorObject = new NSObject(bcolor.Handle);
				//				attsDic.Add(NSAttributedString.StrikethroughColorAttributeName, bcolorObject);
//				#if MACOS
//				int stsingle = (int)MonoMac.AppKit.NSUnderlineStyle.Single;
//				int stsolid = (int)MonoMac.AppKit.NSUnderlinePattern.Solid;
//				var stattss = stsingle | stsolid;
//				var stunderlineObject = NSNumber.FromInt32(stattss);
//				#else
//				var stunderlineObject = NSNumber.FromInt32 (1);
//				#endif
//
//				attsDic.Add(StrikethroughStyleAttributeName, stunderlineObject);
				// --- end underline
			}


			// Text alignment
			var alignment = CTTextAlignment.Left;
			var alignmentSettings = new CTParagraphStyleSettings();
			alignmentSettings.Alignment = alignment;
			var paragraphStyle = new CTParagraphStyle(alignmentSettings);

			ctAttributes.ParagraphStyle = paragraphStyle;
			// end text alignment

            NSMutableAttributedString atts = 
                new NSMutableAttributedString(text,ctAttributes.Dictionary);

			return atts;

		}
        internal static void NativeDrawString(CGBitmapContext bitmapContext, string s, CTFont font, CCColor4B brush, RectangleF layoutRectangle)
        {
            if (font == null)
            {
                throw new ArgumentNullException("font");
            }

            if (s == null || s.Length == 0)
            {
                return;
            }

            bitmapContext.ConcatCTM(bitmapContext.GetCTM().Invert());

            // This is not needed here since the color is set in the attributed string.
            //bitmapContext.SetFillColor(brush.R/255f, brush.G/255f, brush.B/255f, brush.A/255f);

            // I think we only Fill the text with no Stroke surrounding
            //bitmapContext.SetTextDrawingMode(CGTextDrawingMode.Fill);

            var attributedString = buildAttributedString(s, font, brush);

            // Work out the geometry
            RectangleF insetBounds = layoutRectangle;

            PointF textPosition = new PointF(insetBounds.X,
                                             insetBounds.Y);

            float boundsWidth = insetBounds.Width;

            // Calculate the lines
            int start  = 0;
            int length = attributedString.Length;

            var typesetter = new CTTypesetter(attributedString);

            float baselineOffset = 0;

            // First we need to calculate the offset for Vertical Alignment if we
            // are using anything but Top
            if (vertical != CCVerticalTextAlignment.Top)
            {
                while (start < length)
                {
                    int count = typesetter.SuggestLineBreak(start, boundsWidth);
                    var line  = typesetter.GetLine(new NSRange(start, count));

                    // Create and initialize some values from the bounds.
                    float ascent;
                    float descent;
                    float leading;
                    line.GetTypographicBounds(out ascent, out descent, out leading);
                    baselineOffset += (float)Math.Ceiling(ascent + descent + leading + 1);                      // +1 matches best to CTFramesetter's behavior
                    line.Dispose();
                    start += count;
                }
            }

            start = 0;

            while (start < length && textPosition.Y < insetBounds.Bottom)
            {
                // Now we ask the typesetter to break off a line for us.
                // This also will take into account line feeds embedded in the text.
                //  Example: "This is text \n with a line feed embedded inside it"
                int count = typesetter.SuggestLineBreak(start, boundsWidth);
                var line  = typesetter.GetLine(new NSRange(start, count));

                // Create and initialize some values from the bounds.
                float ascent;
                float descent;
                float leading;
                line.GetTypographicBounds(out ascent, out descent, out leading);

                // Calculate the string format if need be
                var penFlushness = 0.0f;

                if (horizontal == CCTextAlignment.Right)
                {
                    penFlushness = (float)line.GetPenOffsetForFlush(1.0f, boundsWidth);
                }
                else if (horizontal == CCTextAlignment.Center)
                {
                    penFlushness = (float)line.GetPenOffsetForFlush(0.5f, boundsWidth);
                }

                // initialize our Text Matrix or we could get trash in here
                var textMatrix = CGAffineTransform.MakeIdentity();

                if (vertical == CCVerticalTextAlignment.Top)
                {
                    textMatrix.Translate(penFlushness, insetBounds.Height - textPosition.Y - (float)Math.Floor(ascent - 1));
                }
                if (vertical == CCVerticalTextAlignment.Center)
                {
                    textMatrix.Translate(penFlushness, ((insetBounds.Height / 2) + (baselineOffset / 2)) - textPosition.Y - (float)Math.Floor(ascent - 1));
                }
                if (vertical == CCVerticalTextAlignment.Bottom)
                {
                    textMatrix.Translate(penFlushness, baselineOffset - textPosition.Y - (float)Math.Floor(ascent - 1));
                }

                // Set our matrix
                bitmapContext.TextMatrix = textMatrix;

                // and draw the line
                line.Draw(bitmapContext);

                // Move the index beyond the line break.
                start          += count;
                textPosition.Y += (float)Math.Ceiling(ascent + descent + leading + 1);                 // +1 matches best to CTFramesetter's behavior
                line.Dispose();
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="center"></param>
        /// <param name="radius"></param>
        /// <param name="angle">The amount of the circle to draw, in radiians</param>
        /// <param name="segments"></param>
        /// <param name="drawLineToCenter"></param>
        /// <param name="color"></param>
        public static void DrawCircle(CCPoint center, float radius, float angle, int segments, bool drawLineToCenter, CCColor4B color)
        {
            float  increment = MathHelper.Pi * 2.0f / segments;
            double theta     = 0.0;

            CCPoint v1;
            CCPoint v2 = CCPoint.Zero;

            for (int i = 0; i < segments; i++)
            {
                v1 = center + new CCPoint((float)Math.Cos(theta), (float)Math.Sin(theta)) * radius;
                v2 = center + new CCPoint((float)Math.Cos(theta + increment), (float)Math.Sin(theta + increment)) * radius;

                DrawLine(v1, v2, color);

                theta += increment;
            }

            if (drawLineToCenter)
            {
                DrawLine(center, v2, color);
            }
        }
 public static void DrawEllips(int x, int y, int width, int height, CCColor4B color)
 {
     DrawEllipticalArc(x, y, width, height, 0, 360, false, color);
 }
        /// <summary>
        /// draws a polygon given a pointer to CCPoint coordiantes and the number of vertices measured in points.
        /// The polygon can be closed or open and optionally filled with current GL color
        /// </summary>
        public static void DrawPoly(CCPoint[] vertices, int numOfVertices, bool closePolygon, bool fill, CCColor4B color)
        {
            var c = new Color(color.R, color.G, color.B, color.A);

            if (fill)
            {
                for (int i = 1; i < numOfVertices - 1; i++)
                {
                    m_Batch.AddVertex(new Vector2(vertices[0].X, vertices[0].Y), c, PrimitiveType.TriangleList);
                    m_Batch.AddVertex(new Vector2(vertices[i].X, vertices[i].Y), c, PrimitiveType.TriangleList);
                    m_Batch.AddVertex(new Vector2(vertices[i + 1].X, vertices[i + 1].Y), c, PrimitiveType.TriangleList);
                }
            }
            else
            {
                for (int i = 0; i < numOfVertices - 1; i++)
                {
                    m_Batch.AddVertex(new Vector2(vertices[i].X, vertices[i].Y), c, PrimitiveType.LineList);
                    m_Batch.AddVertex(new Vector2(vertices[i + 1].X, vertices[i + 1].Y), c, PrimitiveType.LineList);
                }

                if (closePolygon)
                {
                    m_Batch.AddVertex(new Vector2(vertices[numOfVertices - 1].X, vertices[numOfVertices - 1].Y), c, PrimitiveType.LineList);
                    m_Batch.AddVertex(new Vector2(vertices[0].X, vertices[0].Y), c, PrimitiveType.LineList);
                }
            }
        }
 public static void DrawEllipse(CCRect rect, CCColor4B color)
 {
     DrawEllipticalArc(rect, 0, 360, false, color);
 }
 public static void DrawArc(int x, int y, int width, int height, int startAngle, int sweepAngle, CCColor4B color)
 {
     DrawEllipticalArc(x, y, width, height, startAngle, sweepAngle, false, color);
 }
 public static void DrawArc(CCRect rect, int startAngle, int sweepAngle, CCColor4B color)
 {
     DrawEllipticalArc(rect, startAngle, sweepAngle, false, color);
 }
Exemple #24
0
 public CCV2F_C4B_T2F()
 {
     Vertices = new CCVertex2F();
     Colors = new CCColor4B();
     TexCoords = new CCTex2F();
 }
Exemple #25
0
        /// <summary>
        /// initializes a CCLayer with color
        /// </summary>
        public virtual bool InitWithColor(CCColor4B color)
        {
            CCSize s = CCDirector.SharedDirector.WinSize;

            return(InitWithColor(color, s.Width, s.Height));
        }
Exemple #26
0
 /** Returns a ccColor4F from a ccColor4B.
  @since v0.99.1
  */
 public static CCColor4F CreateColor(CCColor4B c)
 {
     CCColor4F c4 = new CCColor4F(c.R / 255.0f, c.G / 255.0f, c.B / 255.0f, c.A / 255.0f);
     return c4;
 }
 public static void DrawPie (CCRect rect, int startAngle, int sweepAngle, CCColor4B color)
 {
     DrawEllipticalArc(rect, startAngle, sweepAngle, true, color);
 }
Exemple #28
0
        private void UpdateColor()
        {
            var color4 = new CCColor4B(_displayedColor.R, _displayedColor.G, _displayedColor.B, _displayedOpacity);

            if (m_bOpacityModifyRGB)
            {
                color4.R = (byte)(color4.R * _displayedOpacity / 255.0f);
                color4.G = (byte)(color4.G * _displayedOpacity / 255.0f);
                color4.B = (byte)(color4.B * _displayedOpacity / 255.0f);
            }

            m_sQuad.BottomLeft.Colors = color4;
            m_sQuad.BottomRight.Colors = color4;
            m_sQuad.TopLeft.Colors = color4;
            m_sQuad.TopRight.Colors = color4;

            // renders using Sprite Manager
            if (m_pobBatchNode != null)
            {
                if (m_uAtlasIndex != CCMacros.CCSpriteIndexNotInitialized)
                {
                    m_pobTextureAtlas.UpdateQuad(ref m_sQuad, m_uAtlasIndex);
                }
                else
                {
                    // no need to set it recursively
                    // update dirty_, don't update recursiveDirty_
                    m_bDirty = true;
                }
            }

            // self render
            // do nothing
        }
 public static void DrawPie (int x, int y, int width, int height, int startAngle, int sweepAngle, CCColor4B color)
 {
     DrawEllipticalArc(x,y,width,height,startAngle,sweepAngle,true, color);
     
 }
		internal static void NativeDrawString (CGBitmapContext bitmapContext, string s, CTFont font, CCColor4B brush, CGRect layoutRectangle)
		{
			if (font == null)
				throw new ArgumentNullException ("font");

			if (s == null || s.Length == 0)
				return;

			bitmapContext.ConcatCTM (bitmapContext.GetCTM().Invert());

            // This is not needed here since the color is set in the attributed string.
			//bitmapContext.SetFillColor(brush.R/255f, brush.G/255f, brush.B/255f, brush.A/255f);

            // I think we only Fill the text with no Stroke surrounding
			//bitmapContext.SetTextDrawingMode(CGTextDrawingMode.Fill);

			var attributedString = buildAttributedString(s, font, brush);

			// Work out the geometry
			CGRect insetBounds = layoutRectangle;

			CGPoint textPosition = new CGPoint(insetBounds.X,
			                                 insetBounds.Y);

            float boundsWidth = (float)insetBounds.Width;

			// Calculate the lines
			nint start = 0;
            nint length = attributedString.Length;

			var typesetter = new CTTypesetter(attributedString);

			float baselineOffset = 0;

			// First we need to calculate the offset for Vertical Alignment if we 
			// are using anything but Top
			if (vertical != CCVerticalTextAlignment.Top) {
				while (start < length) {

                    nint count = typesetter.SuggestLineBreak((int)start, (double)boundsWidth);

                    var line = typesetter.GetLine (new NSRange(start, count));

					// Create and initialize some values from the bounds.
					nfloat ascent;
					nfloat descent;
					nfloat leading;
                    line.GetTypographicBounds(out ascent, out descent, out leading);
                    baselineOffset += (float)Math.Ceiling ((float)(ascent + descent + leading + 1)); // +1 matches best to CTFramesetter's behavior  
					line.Dispose ();
					start += count;
				}
			}

			start = 0;

			while (start < length && textPosition.Y < insetBounds.Bottom)
			{

				// Now we ask the typesetter to break off a line for us.
				// This also will take into account line feeds embedded in the text.
				//  Example: "This is text \n with a line feed embedded inside it"
                nint count = typesetter.SuggestLineBreak((int)start, (double)boundsWidth);
				var line = typesetter.GetLine(new NSRange(start, count));

				// Create and initialize some values from the bounds.
				nfloat ascent;
				nfloat descent;
				nfloat leading;
				line.GetTypographicBounds(out ascent, out descent, out leading);

				// Calculate the string format if need be
				var penFlushness = 0.0f;

				if (horizontal == CCTextAlignment.Right)
					penFlushness = (float)line.GetPenOffsetForFlush(1.0f, boundsWidth);
				else if (horizontal == CCTextAlignment.Center)
					penFlushness = (float)line.GetPenOffsetForFlush(0.5f, boundsWidth);

				// initialize our Text Matrix or we could get trash in here
				var textMatrix = CGAffineTransform.MakeIdentity();

				if (vertical == CCVerticalTextAlignment.Top)
					textMatrix.Translate(penFlushness, insetBounds.Height - textPosition.Y -(float)Math.Floor(ascent - 1));
				if (vertical == CCVerticalTextAlignment.Center)
					textMatrix.Translate(penFlushness, ((insetBounds.Height / 2) + (baselineOffset / 2)) - textPosition.Y -(float)Math.Floor(ascent - 1));
				if (vertical == CCVerticalTextAlignment.Bottom)
					textMatrix.Translate(penFlushness, baselineOffset - textPosition.Y -(float)Math.Floor(ascent - 1));

				// Set our matrix
				bitmapContext.TextMatrix = textMatrix;

				// and draw the line
				line.Draw(bitmapContext);

				// Move the index beyond the line break.
				start += count;
				textPosition.Y += (float)Math.Ceiling(ascent + descent + leading + 1); // +1 matches best to CTFramesetter's behavior  
				line.Dispose();

			}

		}	
        /// <summary>
        /// draws a cubic bezier path
        /// @since v0.8
        /// </summary>
        public static void DrawCubicBezier(CCPoint origin, CCPoint control1, CCPoint control2, CCPoint destination, int segments, CCColor4B color)
        {
            var vertices = new VertexPositionColor[segments + 1];

            float t = 0;
            for (int i = 0; i < segments; ++i)
            {
                float x = CCSplineMath.CubicBezier(origin.X, control1.X, control2.X, destination.X, t);
                float y = CCSplineMath.CubicBezier(origin.Y, control1.Y, control2.Y, destination.Y, t);

                vertices[i] = new VertexPositionColor();
                vertices[i].Position = new Vector3(x, y, 0);
                vertices[i].Color = new Color(color.R, color.G, color.B, color.A);
                t += 1.0f / segments;
            }
            vertices[segments] = new VertexPositionColor
                {
                    Color = new Color(color.R, color.G, color.B, color.A),
                    Position = new Vector3(destination.X, destination.Y, 0)
                };

            BasicEffect basicEffect = CCDrawManager.PrimitiveEffect;
            basicEffect.Projection = CCDrawManager.ProjectionMatrix;
            basicEffect.View = CCDrawManager.ViewMatrix;
            basicEffect.World = CCDrawManager.WorldMatrix;

            foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
            {
                pass.Apply();

                basicEffect.GraphicsDevice.DrawUserPrimitives(PrimitiveType.LineStrip, vertices, 0, segments);
            }
        }
Exemple #32
0
        //! helper macro that creates an ccColor4B type
        public static CCColor4B CreateColor(byte r, byte g, byte b, byte o)
        {
            CCColor4B c = new CCColor4B(r, g, b, o);

            return(c);
        }
Exemple #33
0
 public CCPointSprite()
 {
     Position = new CCVertex2F();
     Color    = new CCColor4B();
     Size     = 0.0f;
 }
Exemple #34
0
        /// <summary>
        /// initializes a CCLayer with color, width and height in Points
        /// </summary>
        public virtual bool InitWithColor(CCColor4B color, float width, float height)
        {
            base.Init();

            // default blend function
            m_tBlendFunc = CCBlendFunc.NonPremultiplied;

            _displayedColor.R = _realColor.R = color.R;
            _displayedColor.G = _realColor.G = color.G;
            _displayedColor.B = _realColor.B = color.B;
            _displayedOpacity = _realOpacity = color.A;

            for (int i = 0; i < m_pSquareVertices.Length; i++)
            {
                m_pSquareVertices[i].Position.X = 0.0f;
                m_pSquareVertices[i].Position.Y = 0.0f;
            }

            UpdateColor();
            ContentSize = new CCSize(width, height);
            
            return true;
        }
 public static void DrawPoints(CCPoint[] points, float size, CCColor4B color)
 {
     DrawPoints(points, points.Length, size, color);
 }
Exemple #36
0
 /// <summary>
 /// creates a CCLayer with color. Width and height are the window size. 
 /// </summary>
 public CCLayerColor (CCColor4B color) : this()
 {
     InitWithColor(color);
 }
Exemple #37
0
 /// <summary>
 /// creates a CCLayer with color. Width and height are the window size.
 /// </summary>
 public CCLayerColor(CCColor4B color) : this()
 {
     InitWithColor(color);
 }
Exemple #38
0
 public CCV2F_C4B_T2F()
 {
     Vertices  = new CCVertex2F();
     Colors    = new CCColor4B();
     TexCoords = new CCTex2F();
 }
Exemple #39
0
 /// <summary>
 /// creates a CCLayer with color, width and height in Points
 /// </summary>
 public CCLayerColor(CCColor4B color, float width, float height) : this()
 {
     InitWithColor(color, width, height);
 }
Exemple #40
0
 public CCPointSprite()
 {
     Position = new CCVertex2F();
     Color = new CCColor4B();
     Size = 0.0f;
 }
Exemple #41
0
        /** Returns a ccColor4F from a ccColor4B.
         * @since v0.99.1
         */
        public static CCColor4F CreateColor(CCColor4B c)
        {
            CCColor4F c4 = new CCColor4F(c.R / 255.0f, c.G / 255.0f, c.B / 255.0f, c.A / 255.0f);

            return(c4);
        }
Exemple #42
0
 //! helper macro that creates an ccColor4B type
 public static CCColor4B CreateColor(byte r, byte g, byte b, byte o)
 {
     CCColor4B c = new CCColor4B(r, g, b, o);
     return c;
 }
 /// <summary>
 /// draws a poligon given a pointer to CCPoint coordiantes and the number of vertices measured in points.
 /// The polygon can be closed or open
 /// </summary>
 public static void DrawPoly(CCPoint[] vertices, int numOfVertices, bool closePolygon, CCColor4B color)
 {
     DrawPoly(vertices, numOfVertices, closePolygon, false, color);
 }
Exemple #44
0
        public override void Draw()
        {
            var map = (CCTMXTiledMap) GetChildByTag(kTagTileMap);
            CCTMXObjectGroup group = map.ObjectGroupNamed("Object Group 1");

            List<Dictionary<string, string>> objects = group.Objects;
            foreach (var dict in objects)
            {
                int x = int.Parse(dict["x"]);
                int y = int.Parse(dict["y"]);
                int width = dict.ContainsKey("width") ? int.Parse(dict["width"]) : 0;
                int height = dict.ContainsKey("height") ? int.Parse(dict["height"]) : 0;

                //glLineWidth(3);

                var color = new CCColor4B(255, 255, 0, 255);

                CCDrawingPrimitives.Begin();
                CCDrawingPrimitives.DrawLine(new CCPoint(x, y), new CCPoint(x + width, y), color);
                CCDrawingPrimitives.DrawLine(new CCPoint(x + width, y), new CCPoint(x + width, y + height), color);
                CCDrawingPrimitives.DrawLine(new CCPoint(x + width, y + height), new CCPoint(x, y + height), color);
                CCDrawingPrimitives.DrawLine(new CCPoint(x, y + height), new CCPoint(x, y), color);
                CCDrawingPrimitives.End();

                //glLineWidth(1);
            }
        }
 public static void DrawSolidPoly(CCPoint[] vertices, int count, CCColor4B color)
 {
     DrawSolidPoly(vertices, count, color, false);
 }