Пример #1
0
        /// <summary>
        /// Returns a single line from the cell including the paddings.
        /// </summary>
        /// <param name="lineIndex">The index of the line to be generated.</param>
        /// <param name="width">The width of the cell.</param>
        /// <returns>A <see cref="string"/> representing a single line from the cell.</returns>
        private string RenderLine(int lineIndex, int width)
        {
            int paddingLeftLength  = CalculatePaddingLeft();
            int paddingRightLength = CalculatePaddingRight();

            int cellContentWidth = width - paddingLeftLength - paddingRightLength;

            bool existsContentLine = lineIndex < Content.Size.Height;

            if (!existsContentLine)
            {
                return(new string(' ', width));
            }

            // Build inner content.

            string innerContent           = Content.Lines[lineIndex];
            HorizontalAlignment alignment = CalculateHorizontalAlignment();

            innerContent = AlignedText.QuickAlign(innerContent, alignment, cellContentWidth);

            // Build paddings.

            string paddingLeft  = new string(' ', paddingLeftLength);
            string paddingRight = new string(' ', paddingRightLength);

            // Concatenate everything.

            return(paddingLeft + innerContent + paddingRight);
        }
Пример #2
0
        private void Init(object sender, EventArgs e)
        {
            this.Shader = new StaticShader();

            this.FontLoader      = new FontLoader();
            this.TextureLoader   = new TextureLoader();
            this.FontMeshBuilder = new FontMeshBuilder();

            //this.Font = this.FontLoader.Load(this.TextureLoader, "../../../res/Montserrat_high.fnt", "../../../res/Montserrat_high.png");
            this.Font = this.FontLoader.Load(this.TextureLoader, "../../../res/Montserrat_sdf.fnt", "../../../res/Montserrat_sdf.png");



            //this.fontEntity = new Text(this.Font, new Vector3(10, this.Display.Height/2, 0), 100);
            //this.FontMeshBuilder.Build(this.fontEntity.Mesh, "ahoj uwu nuzzles");

            this.alignedText = new AlignedText(this.Font, new Vector3(0, this.Display.Height, 0), this.Display.Width, 5f, Align.Center, 100);

            this.textString = "hahahahahahahahahahaha\n\nlol";
            this.FontMeshBuilder.Build(this.alignedText, textString);



            this.projection = Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(90), (float)this.Display.Width / (float)this.Display.Height, 0.1f, 1000.0f);
            this.projection = Matrix4.CreateOrthographicOffCenter(0, this.Display.Width, 0, this.Display.Height, -1.0f, 100.0f);
        }
Пример #3
0
        /// <summary>
        /// Displays the current instance to the Console starting from the current location of the cursor.
        /// </summary>
        /// <param name="size">The size in which the current instance must be displayed.</param>
        /// <param name="highlighted">A value that specifies if the menu item must be displayed highlighted.</param>
        public void Display(Size size, bool highlighted)
        {
            HorizontalAlignment calculatedHorizontalAlignment = CalculateHorizontalAlignment();

            Location = new Location(Console.CursorLeft, Console.CursorTop);

            AlignedText alignedText = new AlignedText
            {
                Text = new string(' ', Size.Width),
                HorizontalAlignment = calculatedHorizontalAlignment,
                Width = size.Width
            };

            // Write left empty space
            CustomConsole.Write(new string(' ', alignedText.SpaceLeftCount));

            // Write content
            if (highlighted)
            {
                CustomConsole.WithInvertedColors(DisplayContent);
            }
            else
            {
                DisplayContent();
            }

            // Write right empty space
            CustomConsole.Write(new string(' ', alignedText.SpaceRightCount));
        }
        public void if_alignment_is_not_specified_return_0()
        {
            AlignedText alignedText = new AlignedText
            {
                Text  = "some text",
                Width = 15
            };

            Assert.That(alignedText.SpaceLeftCount, Is.EqualTo(0));
        }
        public void text_with_length_9_aligend_to_default_in_width_15_returns_0()
        {
            AlignedText alignedText = new AlignedText
            {
                Text = "some text",
                HorizontalAlignment = HorizontalAlignment.Default,
                Width = 15
            };

            Assert.That(alignedText.SpaceLeftCount, Is.EqualTo(0));
        }
        public void text_with_length_9_aligend_to_center_in_width_16_returns_3()
        {
            AlignedText alignedText = new AlignedText
            {
                Text = "some text",
                HorizontalAlignment = HorizontalAlignment.Center,
                Width = 16
            };

            Assert.That(alignedText.SpaceLeftCount, Is.EqualTo(3));
        }
        public void text_aligend_to_left_returns_0()
        {
            AlignedText alignedText = new AlignedText
            {
                Text = "some text",
                HorizontalAlignment = HorizontalAlignment.Left,
                Width = 15
            };

            Assert.That(alignedText.SpaceLeftCount, Is.EqualTo(0));
        }
Пример #8
0
        public void if_alignment_is_not_specified_then_text_is_aligend_to_left()
        {
            AlignedText alignedText = new AlignedText
            {
                Text  = "some text",
                Width = 15
            };

            string actual = alignedText.ToString();

            Assert.That(actual, Is.EqualTo("some text      "));
        }
Пример #9
0
        public void text_aligend_to_default()
        {
            AlignedText alignedText = new AlignedText
            {
                Text = "some text",
                HorizontalAlignment = HorizontalAlignment.Default,
                Width = 15
            };

            string actual = alignedText.ToString();

            Assert.That(actual, Is.EqualTo("some text      "));
        }
Пример #10
0
        public void text_aligend_to_center_odd_empty_space()
        {
            AlignedText alignedText = new AlignedText
            {
                Text = "some text",
                HorizontalAlignment = HorizontalAlignment.Center,
                Width = 16
            };

            string actual = alignedText.ToString();

            Assert.That(actual, Is.EqualTo("   some text    "));
        }
Пример #11
0
        private string ValueToString(int calculatedValue)
        {
            string valueAsString = calculatedValue.ToString();

            if (UnitOfMeasurement != null)
            {
                valueAsString += UnitOfMeasurement;
            }

            int totalWidth = valueMaxLength + unitOfMeasurementMaxLength;

            return(AlignedText.QuickAlign(valueAsString, ValueHorizontalAlignment, totalWidth));
        }
Пример #12
0
 public void LoadTextData(AlignedText text)
 {
     this.LoadFloat(text.LineLength / (float)text.FontSize, this.lineLengthLocation);
 }
Пример #13
0
        public void Build(AlignedText alignedText, string text)
        {
            var mesh = alignedText.Mesh;
            var font = mesh.Font;

            var lineLength = alignedText.LineLength / (float)alignedText.FontSize;

            float  lineSum     = 0;
            string currentLine = String.Empty;

            List <Vector2> vertexBuffer       = new List <Vector2>();
            List <Vector2> textureCoordBuffer = new List <Vector2>();
            Vector2        cursor             = Vector2.Zero;

            for (int i = 0; i < text.Length; i++)
            {
                var character = text[i];

                var charLength = font.Data[character].LocalXadvance;

                if (lineSum + charLength < lineLength && character != '\n')
                {
                    lineSum     += charLength;
                    currentLine += character;
                    if (i != text.Length - 1)
                    {
                        continue;
                    }
                }

                switch (alignedText.Align)
                {
                case Align.Right:
                    cursor.X = lineLength - lineSum;
                    break;

                case Align.Center:
                    cursor.X = (lineLength - lineSum) / 2;
                    break;
                }

                this.BuildLine(currentLine, vertexBuffer, textureCoordBuffer, font, cursor, alignedText.LetterPadding);

                currentLine = String.Empty;
                lineSum     = 0;

                cursor.Y -= (float)font.LineHeight / (float)font.GivenSize;
            }


            float[] vertices      = new float[vertexBuffer.Count * 2];
            float[] textureCoords = new float[textureCoordBuffer.Count * 2];

            int vertexIndex = 0;

            foreach (var vertex in vertexBuffer)
            {
                vertices[vertexIndex++] = vertex.X;
                vertices[vertexIndex++] = vertex.Y;
            }

            int textureCoordIndex = 0;

            foreach (var textureCoord in textureCoordBuffer)
            {
                textureCoords[textureCoordIndex++] = textureCoord.X;
                textureCoords[textureCoordIndex++] = textureCoord.Y;
            }

            vertexBuffer.Clear();
            textureCoordBuffer.Clear();

            mesh.UpdateCoords(vertices, textureCoords);
        }