protected string Process(int _line)
{
if (Settings.Instance.ExtensiveLogging)
{
Log.Info("MiniDisplayPlugin.DisplayHandler.Process(): Processing line #{0}", new object[] {_line});
}
Line line;
Line line2;
string str = string.Empty;
// If we have a single line display
if (this.heightInChars == 1)
{
// Combines both lines on a single one if our display only supports one line.
line = this.lines[0];
line2 = this.lines[1];
string str1 = line.Process();
string str2 = line2.Process();
// If both lines are empty we still won't add that hyphen and the resulting string will be empty
if (string.IsNullOrEmpty(str2))
{
str = str1;
}
else if (string.IsNullOrEmpty(str1))
{
str = str2;
}
else
{
// None of our lines are empty, concatenate them then
str = str1 + " - " + str2;
}
}
else
{
// Our display has more than one line of text.
line = this.lines[_line];
str = line.Process();
}
if (Settings.Instance.ExtensiveLogging)
{
Log.Info("MiniDisplayPlugin.DisplayHandler.Process(): translated line #{0} to \"{1}\"",_line, str);
}
if ((str == null) || (str.Length == 0))
{
return new string(' ', this.widthInChars);
}
if (this.prevLines[_line] == null)
{
this.prevLines[_line] = "";
}
try
{
if (this.prevLines[_line] != str)
{
this.pos[_line] = 0;
this.posSkips[_line] = 0;
this.prevLines[_line] = str;
}
}
catch (Exception exception)
{
Log.Error("MiniDisplayPlugin.DisplayHandler.Process(): CAUGHT EXCEPTION - {0}\n\n{1}\n\n", exception.Message,
new object[] {exception.StackTrace});
}
if (str.Length <= this.widthInChars)
{
//Our line is short enough that we don't need to scroll.
//That means we will need to apply alignment.
if (Settings.Instance.AutoScroll)
{
//Display driver is going to take care of scrolling.
//No need for alignment and padding then.
return str;
}
if (Settings.Instance.ExtensiveLogging)
{
Log.Info("MiniDisplayPlugin.DisplayHandler.Process(): final processing result: \"{0}\"", new object[] {str});
}
//Once alignment is applied, we are done here since the rest of this function handling scrolling
switch (line.Alignment)
{
case Alignment.Centered:
{
int count = (this.widthInChars - str.Length) / 2;
return (new string(' ', count) + str + new string(' ', (this.widthInChars - str.Length) - count));
}
case Alignment.Right:
{
return string.Format("{0," + this.widthInChars + "}", str);
}
case Alignment.Left:
{
return string.Format("{0,-" + this.widthInChars + "}", str);
}
}
}
//Handle text scrolling
if (Settings.Instance.AutoScroll)
{
//Display driver is going to take care of scrolling.
//Just pass in the whole line of text.
return str;
}
if (this.pos[_line] > ((str.Length + this.charsToScroll) + 1))
{
this.pos[_line] = 0;
}
str = (str + " - " + str).Substring(this.pos[_line], this.widthInChars);
if (this.posSkips[_line] > 2)
{
this.pos[_line] += this.charsToScroll;
}
else
{
this.posSkips[_line]++;
}
if (this.posSkips[_line] > 10)
{
this.posSkips[_line] = 10;
}
if (Settings.Instance.ExtensiveLogging)
{
Log.Info("MiniDisplayPlugin.DisplayHandler.Process(): final processing result: \"{0}\"", new object[] {str});
}
return str;
}