Пример #1
0
 /// <summary>
 /// Change line of text (string) to int content.
 /// </summary>
 /// <returns>
 /// Two dimensional int array defining states of dots on each row and column.
 /// </returns>
 /// <param name="textLine">
 /// Text to convert. If text contains linefeed characters, it will split text to multiple rows and default line spacing and text alignment will be used.
 /// </param>
 /// <param name="font">
 /// Font to be used to generate content, one of the values from enum TextCommand.Fonts
 /// </param>
 /// <param name="fixedWidth">
 /// If true, all the characters takes same amount of space. If false, different characters may take different amount of horizontal space.
 /// </param>
 /// <param name="bold">
 /// If true, resulting text characters are bold. If false, then using normal characters.
 /// </param>
 /// <param name="charSpacing">
 /// Amount of dots between each character.
 /// </param>
 public static int[,] getContent(string textLine,
                                 TextCommand.Fonts font,
                                 bool fixedWidth,
                                 bool bold,
                                 int charSpacing)
 {
     return(getContent(splitStringToStringArray(textLine), font, fixedWidth, bold, 1, 0, charSpacing, 1, TextCommand.TextAlignments.Left));
 }
Пример #2
0
 internal Controller(DotMatrix dotMatrix, DisplayModel displayModel)
 {
     this.dotMatrix            = dotMatrix;
     this.displayModel         = displayModel;
     commands                  = new List <AbsCmd>();
     rawCommand                = null;
     timeToConsume             = 0f;
     defaultSpeedDotsPerSecond = 42;
     defaultTextFont           = TextCommand.Fonts.Normal;
 }
Пример #3
0
        /// <summary>
        /// Change multiple lines of text (string) to int content.
        /// </summary>
        /// <returns>
        /// Two dimensional int array defining states of dots on each row and column.
        /// </returns>
        /// <param name="textLines">
        /// One of more lines of text.
        /// </param>
        /// <param name="font">
        /// Font to be used to generate content, one of the values from enum TextCommand.Fonts
        /// </param>
        /// <param name="fixedWidth">
        /// If true, all the characters takes same amount of space. If false, different characters may take different amount of horizontal space.
        /// </param>
        /// <param name="bold">
        /// If true, resulting text characters are bold. If false, then using normal characters.
        /// </param>
        /// <param name="textColor">
        /// Color used for any dots that should be on.
        /// </param>
        /// <param name="backColor">
        /// Color used for any dots that should be off.
        /// </param>
        /// <param name="charSpacing">
        /// Amount of dots between each character.
        /// </param>
        /// <param name="lineSpacing">
        /// Amount of dots between each line if there is multiple lines of text.
        /// </param>
        /// <param name="multiLineTextAlignment">
        /// Text alignment in case there is multiple lines of text, one of the values from enum TextCommand.TextAlignments
        /// </param>
        public static int[,] getContent(string[] textLines,
                                        TextCommand.Fonts font,
                                        bool fixedWidth,
                                        bool bold,
                                        int textColor,
                                        int backColor,
                                        int charSpacing,
                                        int lineSpacing,
                                        TextCommand.TextAlignments multiLineTextAlignment)
        {
            CharacterDef characterDef;

            if (font == TextCommand.Fonts.Large)
            {
                characterDef = new CharacterDef_9();
            }
            else if (font == TextCommand.Fonts.Small)
            {
                characterDef = new CharacterDef_5();
            }
            else
            {
                characterDef = new CharacterDef_7();
            }

            int rowCount    = textLines.Length;
            int rowHeight   = characterDef.getFontHeight();
            int totalHeight = rowHeight * rowCount + lineSpacing * (rowCount - 1);

            int[] rowWidths  = new int[rowCount];
            int   totalWidth = 0;

            for (int n = 0; n < rowCount; n++)
            {
                int charCount = textLines[n].Length;
                rowWidths[n] = Mathf.Max(charSpacing * (charCount - 1), 0);
                for (int m = 0; m < textLines[n].Length; m++)
                {
                    rowWidths[n] += characterDef.getCharWidth(textLines[n][m], fixedWidth, bold);
                    if (rowWidths[n] > totalWidth)
                    {
                        totalWidth = rowWidths[n];
                    }
                }
            }

            int[,] content = new int[totalHeight, totalWidth];
            for (int y = 0; y < totalHeight; y++)
            {
                for (int x = 0; x < totalWidth; x++)
                {
                    content[y, x] = backColor;
                }
            }

            for (int row = 0; row < rowCount; row++)
            {
                int startX = 0;
                if (multiLineTextAlignment == TextCommand.TextAlignments.Right)
                {
                    startX = totalWidth - rowWidths[row];
                }
                else if (multiLineTextAlignment == TextCommand.TextAlignments.Center)
                {
                    startX = (totalWidth - rowWidths[row]) / 2;
                }
                int x = 0;
                for (int col = 0; col < textLines[row].Length; col++)
                {
                    addCharToContent(textLines[row][col], characterDef, fixedWidth, bold, content, startX + x, (rowHeight + lineSpacing) * row, textColor, backColor);
                    x += characterDef.getCharWidth(textLines[row][col], fixedWidth, bold) + charSpacing;
                }
            }

            return(content);
        }