예제 #1
0
        public Box2 GetBounds()
        {
            float posX  = transform.position.X;
            float posY  = transform.position.Y;
            float halfX = 0.5f * transform.scale.X;
            float halfY = 0.5f * transform.scale.Y;
            Box2  box   = new OpenTK.Box2(posX - halfX, posY + halfY, posX + halfX, posY - halfY);

            return(box);
        }
예제 #2
0
        public void DrawTexturedQuad(int TextureID, Box2 Box, Box2 subImageBox)
        {
            GL.Color4(1.0f, 1.0f, 1.0f, 1.0f);

            GL.Enable(EnableCap.Texture2D);
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            GL.BindTexture(TextureTarget.Texture2D, TextureID);

            GL.Begin(PrimitiveType.Quads);

            GL.TexCoord2(subImageBox.Left, subImageBox.Top); GL.Vertex2(Box.Left, Box.Bottom);
            GL.TexCoord2(subImageBox.Right, subImageBox.Top); GL.Vertex2(Box.Right, Box.Bottom);
            GL.TexCoord2(subImageBox.Right, subImageBox.Bottom); GL.Vertex2(Box.Right, Box.Top);
            GL.TexCoord2(subImageBox.Left, subImageBox.Bottom); GL.Vertex2(Box.Left, Box.Top);

            GL.End();

            GL.BindTexture(TextureTarget.Texture2D, 0);
        }
예제 #3
0
        public void DrawBox(Box2 box, Color4 fillColor, Color4 outlineColor)
        {
            if (fillColor.A > 0.0f)
            {
                SetColor(fillColor);
                GL.Begin(PrimitiveType.Quads);

                GL.Vertex2(box.Left, box.Bottom);
                GL.Vertex2(box.Right, box.Bottom);
                GL.Vertex2(box.Right, box.Top);
                GL.Vertex2(box.Left, box.Top);

                GL.End();
            }

            if (outlineColor.A > 0.0f)
            {
                SetColor(outlineColor);
                GL.Begin(PrimitiveType.LineLoop);

                GL.Vertex2(box.Left, box.Bottom);
                GL.Vertex2(box.Right, box.Bottom);
                GL.Vertex2(box.Right, box.Top);
                GL.Vertex2(box.Left, box.Top);

                GL.End();
            }
        }
예제 #4
0
 private Box2 BoundingBox()
 {
     if (!bounding_box_is_good)
     {
         boundingBox = new Box2(float.PositiveInfinity, float.NegativeInfinity, float.NegativeInfinity, float.PositiveInfinity);
         foreach (Vector2 p in Points)
         {
             if (p.X > boundingBox.Right)
             {
                 boundingBox.Right = p.X;
             }
             if (p.X < boundingBox.Left)
             {
                 boundingBox.Left = p.X;
             }
             if (p.Y > boundingBox.Top)
             {
                 boundingBox.Top = p.Y;
             }
             if (p.Y < boundingBox.Bottom)
             {
                 boundingBox.Bottom = p.Y;
             }
         }
         boundingBox.Bottom -= width / 2;
         boundingBox.Top += width / 2;
         boundingBox.Left -= width / 2;
         boundingBox.Right += width / 2;
         bounding_box_is_good = true;
     }
     return boundingBox;
 }
예제 #5
0
 public static void FillBox(Box2 b)
 {
     GL.Begin(BeginMode.Quads);
     GL.Vertex2(b.Bottom, b.Left);
     GL.Vertex2(b.Bottom, b.Right);
     GL.Vertex2(b.Top, b.Right);
     GL.Vertex2(b.Top, b.Left);
     GL.End();
 }
예제 #6
0
 public void SetBounds(Box2 bound)
 {
     m_bounds = bound;
 }
예제 #7
0
		public SizeF Measure(string text, int width, QFontAlignment alignment)
		{
			var dims = new Box2 (0, 0, width, 0);
			return Measure (text, dims, alignment);
		}
예제 #8
0
        /// <summary>
        /// Measures the actual width and height of the block of text.
        /// </summary>
        /// <param name="text"></param>
        /// <param name="bounds"></param>
        /// <param name="alignment"></param>
        /// <returns></returns>
		public SizeF Measure(string text, Box2 bounds, QFontAlignment alignment)
        {
			var processedText = ProcessText(text, bounds, alignment);
            return Measure(processedText);
        }
예제 #9
0
 public void PrintToVBO(string text, QFontAlignment alignment, Vector3 position, Color color, Box2 maxSize)
 {
     Options.Colour = color;
     PrintOffset = position;
     Print(text, maxSize, alignment);
 }
예제 #10
0
		public void Print(string text, Box2 maxSize, QFontAlignment alignment, Vector2 position)
        {
            position = TransformPositionToViewport(position);
            position = LockToPixel(position);
            
            GL.PushMatrix();
            GL.Translate(position.X, position.Y, 0f);
            Print(text, maxSize, alignment);
            GL.PopMatrix();
        }
예제 #11
0
		public void Print(string text, int maxSize, QFontAlignment alignment)
		{
			var dims = new Box2 (0, 0, maxSize, 0);
			Print(text, dims, alignment);
		}
예제 #12
0
        /// <summary>
        /// Creates node list object associated with the text.
        /// </summary>
        /// <param name="text"></param>
		/// <param name = "maxSize"></param>
		/// <param name = "alignment"></param>
        /// <returns></returns>
		public ProcessedText ProcessText(string text, Box2 maxSize, QFontAlignment alignment)
        {
            //TODO: bring justify and alignment calculations in here

			var width = TransformWidthToViewport(maxSize.Width);

			var nodeList = new TextNodeList(text);
            nodeList.MeasureNodes(fontData, Options);

            //we "crumble" words that are two long so that that can be split up
            var nodesToCrumble = new List<TextNode>();
            foreach (TextNode node in nodeList)
				if ((!Options.WordWrap || node.Length >= width) && node.Type == TextNodeType.Word)
                    nodesToCrumble.Add(node);

            foreach (var node in nodesToCrumble)
                nodeList.Crumble(node, 1);

            //need to measure crumbled words
            nodeList.MeasureNodes(fontData, Options);


			var processedText = new ProcessedText();
            processedText.textNodeList = nodeList;
			processedText.maxWidth = width;
            processedText.alignment = alignment;


            return processedText;
        }
예제 #13
0
        /// <summary>
        /// Prints text inside the given bounds.
        /// </summary>
        /// <param name="text"></param>
		/// <param name="maxSize"></param>
        /// <param name="alignment"></param>
        public void Print(string text, Box2 maxSize, QFontAlignment alignment)
        {
            var processedText = ProcessText(text, maxSize, alignment);
            Print(processedText);
        }
예제 #14
-1
        public void DrawTexturedQuad(int TextureID, Box2 Box, Color4 color, bool flipX)
        {
            SetColor(color);
            GL.Enable(EnableCap.Texture2D);
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            GL.BindTexture(TextureTarget.Texture2D, TextureID);

            GL.Begin(PrimitiveType.Quads);
            if (!flipX)
            {
                GL.TexCoord2(0.0f, 1.0f); GL.Vertex2(Box.Left, Box.Bottom);
                GL.TexCoord2(1.0f, 1.0f); GL.Vertex2(Box.Right, Box.Bottom);
                GL.TexCoord2(1.0f, 0.0f); GL.Vertex2(Box.Right, Box.Top);
                GL.TexCoord2(0.0f, 0.0f); GL.Vertex2(Box.Left, Box.Top);
            }
            else
            {
                GL.TexCoord2(1.0f, 1.0f); GL.Vertex2(Box.Left, Box.Bottom);
                GL.TexCoord2(0.0f, 1.0f); GL.Vertex2(Box.Right, Box.Bottom);
                GL.TexCoord2(0.0f, 0.0f); GL.Vertex2(Box.Right, Box.Top);
                GL.TexCoord2(1.0f, 0.0f); GL.Vertex2(Box.Left, Box.Top);
            }
            GL.End();

            GL.BindTexture(TextureTarget.Texture2D, 0);
        }