コード例 #1
0
            public void DrawRatio(float operand, float dividend, bool reverse = false)
            {
                float    ratio         = dividend == 0 ? 1 : Math.Min(1, Math.Max(0, operand / dividend));
                int      numberSquares = (int)Math.Round(ratio * COLOR_LINE_LENGTH);
                int      colorIndex    = Math.Min((int)Math.Floor(ratio * RATIO_COLORS.Count()), RATIO_COLORS.Count() - 1);
                LCDColor color         = reverse ? RATIO_COLORS[RATIO_COLORS.Count() - colorIndex - 1] : RATIO_COLORS[colorIndex];

                _displayText
                .Append(color.ToChar(), numberSquares)
                .Append(LCDColor.DarkGrey.ToChar(), COLOR_LINE_LENGTH - numberSquares)
                .Append('\n');
            }
コード例 #2
0
 public void WriteCentered(String text, LCDColor color = null)
 {
     if (text.Count() >= LINE_LENGTH)
     {
         _displayText.Append(text);
     }
     else if (text.Count() >= LINE_LENGTH - 2)
     {
         _displayText.Append(" ").Append(text);
     }
     else
     {
         int remaingColorChars = (int)Math.Round((float)(LINE_LENGTH - text.Count() - 2) * CHAR_COLOR_RATIO / 2);
         _displayText
         .Append(color == null ? LCDColor.Black.ToChar() : color.ToChar(), remaingColorChars)
         .Append(" ").Append(text).Append(" ")
         .Append(color == null ? LCDColor.Black.ToChar() : color.ToChar(), remaingColorChars + 1);
     }
     _displayText.Append("\n");
 }