Lua Writer - faster drawing
This commit is contained in:
parent
f45238132e
commit
e56de584e3
|
@ -357,6 +357,9 @@
|
|||
<Compile Include="tools\LuaWriter.designer.cs">
|
||||
<DependentUpon>LuaWriter.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="tools\LuaWriterBox.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="tools\WatchCommon.cs" />
|
||||
<EmbeddedResource Include="AVOut\FFmpegWriterForm.resx">
|
||||
<DependentUpon>FFmpegWriterForm.cs</DependentUpon>
|
||||
|
|
|
@ -28,43 +28,44 @@
|
|||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.components = new System.ComponentModel.Container();
|
||||
this.LuaText = new System.Windows.Forms.RichTextBox();
|
||||
this.timer = new System.Windows.Forms.Timer(this.components);
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// LuaText
|
||||
//
|
||||
this.LuaText.AcceptsTab = true;
|
||||
this.LuaText.Location = new System.Drawing.Point(12, 12);
|
||||
this.LuaText.Name = "LuaText";
|
||||
this.LuaText.Size = new System.Drawing.Size(819, 417);
|
||||
this.LuaText.TabIndex = 0;
|
||||
this.LuaText.Text = "";
|
||||
this.LuaText.WordWrap = false;
|
||||
this.LuaText.ZoomFactor = 2F;
|
||||
//
|
||||
// timer
|
||||
//
|
||||
this.timer.Enabled = true;
|
||||
this.timer.Interval = 1000;
|
||||
this.timer.Tick += new System.EventHandler(this.timer_Tick);
|
||||
//
|
||||
// LuaWriter
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(843, 441);
|
||||
this.Controls.Add(this.LuaText);
|
||||
this.Name = "LuaWriter";
|
||||
this.Text = "LuaWriter";
|
||||
this.ResumeLayout(false);
|
||||
this.components = new System.ComponentModel.Container();
|
||||
this.LuaText = new LuaWriterBox();
|
||||
this.timer = new System.Windows.Forms.Timer(this.components);
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// LuaText
|
||||
//
|
||||
this.LuaText.AcceptsTab = true;
|
||||
this.LuaText.Location = new System.Drawing.Point(12, 12);
|
||||
this.LuaText.Name = "LuaText";
|
||||
this.LuaText.Size = new System.Drawing.Size(819, 417);
|
||||
this.LuaText.TabIndex = 0;
|
||||
this.LuaText.Text = "";
|
||||
this.LuaText.WordWrap = false;
|
||||
this.LuaText.ZoomFactor = 2F;
|
||||
//
|
||||
// timer
|
||||
//
|
||||
this.timer.Enabled = true;
|
||||
this.timer.Interval = 1000;
|
||||
this.timer.Tick += new System.EventHandler(this.timer_Tick);
|
||||
//
|
||||
// LuaWriter
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(843, 441);
|
||||
this.Controls.Add(this.LuaText);
|
||||
this.Name = "LuaWriter";
|
||||
this.Text = "LuaWriter";
|
||||
this.Load += new System.EventHandler(this.LuaWriter_Load);
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.RichTextBox LuaText;
|
||||
private LuaWriterBox LuaText;
|
||||
private System.Windows.Forms.Timer timer;
|
||||
}
|
||||
}
|
|
@ -10,156 +10,160 @@ using System.Text.RegularExpressions;
|
|||
|
||||
namespace BizHawk.MultiClient
|
||||
{
|
||||
public partial class LuaWriter : Form
|
||||
{
|
||||
public Regex keyWords = new Regex("and|break|do|else|if|end|false|for|function|in|local|nil|not|or|repeat|return|then|true|until|while|elseif");
|
||||
public LuaWriter()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
public partial class LuaWriter : Form
|
||||
{
|
||||
public Regex keyWords = new Regex("and|break|do|else|if|end|false|for|function|in|local|nil|not|or|repeat|return|then|true|until|while|elseif");
|
||||
public LuaWriter()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void timer_Tick(object sender, EventArgs e)
|
||||
{
|
||||
int selPos = LuaText.SelectionStart;
|
||||
int selChars = LuaText.SelectedText.Length;
|
||||
private void timer_Tick(object sender, EventArgs e)
|
||||
{
|
||||
int selPos = LuaText.SelectionStart;
|
||||
int selChars = LuaText.SelectedText.Length;
|
||||
|
||||
LuaText.SelectAll();
|
||||
LuaText.SelectionColor = Color.Black;
|
||||
|
||||
ColorReservedWords();
|
||||
ColorReservedWords();
|
||||
|
||||
ColorComments();
|
||||
ColorComments();
|
||||
|
||||
ColorStrings();
|
||||
ColorStrings();
|
||||
|
||||
LuaText.Select(selPos, selChars);
|
||||
}
|
||||
LuaText.Select(selPos, selChars);
|
||||
}
|
||||
|
||||
private void ColorStrings()
|
||||
{
|
||||
int firstMark, opening, ending, endLine;
|
||||
private void ColorStrings()
|
||||
{
|
||||
int firstMark, opening, ending, endLine;
|
||||
|
||||
char[] chars = { '"', '\'' };
|
||||
foreach (char mark in chars)
|
||||
{
|
||||
firstMark = LuaText.Find(mark.ToString());
|
||||
while (firstMark > 0)
|
||||
{
|
||||
opening = firstMark;
|
||||
if (LuaText.GetLineFromCharIndex(opening) + 1 == LuaText.Lines.Count())
|
||||
endLine = LuaText.Text.Length - 1;
|
||||
else
|
||||
endLine = LuaText.GetFirstCharIndexFromLine(LuaText.GetLineFromCharIndex(opening) + 1) - 1;
|
||||
|
||||
ending = 0;
|
||||
char[] chars = { '"', '\'' };
|
||||
foreach (char mark in chars)
|
||||
{
|
||||
firstMark = LuaText.Find(mark.ToString());
|
||||
while (firstMark > 0)
|
||||
{
|
||||
opening = firstMark;
|
||||
if (LuaText.GetLineFromCharIndex(opening) + 1 == LuaText.Lines.Count())
|
||||
endLine = LuaText.Text.Length - 1;
|
||||
else
|
||||
endLine = LuaText.GetFirstCharIndexFromLine(LuaText.GetLineFromCharIndex(opening) + 1) - 1;
|
||||
|
||||
if (opening != LuaText.Text.Length - 1)
|
||||
{
|
||||
if (opening + 1 != endLine)
|
||||
{
|
||||
ending = LuaText.Find(mark.ToString(), opening + 1, endLine, RichTextBoxFinds.MatchCase);
|
||||
if (ending > 0)
|
||||
{
|
||||
while (ending > 0)
|
||||
{
|
||||
if (!IsThisPartOfTheString(LuaText.Text.Substring(opening, ending - opening + 1)))
|
||||
break;
|
||||
else
|
||||
ending++;
|
||||
ending = 0;
|
||||
|
||||
ending = LuaText.Find(mark.ToString(), ending, endLine, RichTextBoxFinds.MatchCase);
|
||||
}
|
||||
}
|
||||
else
|
||||
ending = endLine;
|
||||
}
|
||||
else
|
||||
ending = endLine;
|
||||
}
|
||||
else
|
||||
ending = endLine;
|
||||
if (opening != LuaText.Text.Length - 1)
|
||||
{
|
||||
if (opening + 1 != endLine)
|
||||
{
|
||||
ending = LuaText.Find(mark.ToString(), opening + 1, endLine, RichTextBoxFinds.MatchCase);
|
||||
if (ending > 0)
|
||||
{
|
||||
while (ending > 0)
|
||||
{
|
||||
if (!IsThisPartOfTheString(LuaText.Text.Substring(opening, ending - opening + 1)))
|
||||
break;
|
||||
else
|
||||
ending++;
|
||||
|
||||
if (opening != LuaText.Text.Length)
|
||||
{
|
||||
LuaText.Select(opening, ending - opening + 1);
|
||||
LuaText.SelectionColor = Color.FromArgb(Global.Config.LuaStringColor);
|
||||
if (ending >= LuaText.Text.Length)
|
||||
ending++;
|
||||
else
|
||||
break;
|
||||
ending = LuaText.Find(mark.ToString(), ending, endLine, RichTextBoxFinds.MatchCase);
|
||||
}
|
||||
}
|
||||
else
|
||||
ending = endLine;
|
||||
}
|
||||
else
|
||||
ending = endLine;
|
||||
}
|
||||
else
|
||||
ending = endLine;
|
||||
|
||||
firstMark = LuaText.Find(mark.ToString(), ending + 1, LuaText.Text.Length, RichTextBoxFinds.MatchCase);
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (opening != LuaText.Text.Length)
|
||||
{
|
||||
LuaText.Select(opening, ending - opening + 1);
|
||||
LuaText.SelectionColor = Color.FromArgb(Global.Config.LuaStringColor);
|
||||
if (ending >= LuaText.Text.Length)
|
||||
ending++;
|
||||
else
|
||||
break;
|
||||
|
||||
private bool IsThisPartOfTheString(string wholestring)
|
||||
{
|
||||
int ammount = 0;
|
||||
for (int x = wholestring.Length - 2; x > -1; x--)
|
||||
{
|
||||
if (wholestring[x] == '\\')
|
||||
ammount++;
|
||||
else
|
||||
break;
|
||||
}
|
||||
firstMark = LuaText.Find(mark.ToString(), ending + 1, LuaText.Text.Length, RichTextBoxFinds.MatchCase);
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return !(ammount % 2 == 0);
|
||||
}
|
||||
private bool IsThisPartOfTheString(string wholestring)
|
||||
{
|
||||
int ammount = 0;
|
||||
for (int x = wholestring.Length - 2; x > -1; x--)
|
||||
{
|
||||
if (wholestring[x] == '\\')
|
||||
ammount++;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
private void ColorComments()
|
||||
{
|
||||
foreach (Match CommentMatch in new Regex("--").Matches(LuaText.Text))
|
||||
{
|
||||
int endComment;
|
||||
return !(ammount % 2 == 0);
|
||||
}
|
||||
|
||||
if (LuaText.Text.Substring(CommentMatch.Index, 4) == "--[[")
|
||||
{
|
||||
if (LuaText.Find("]]", RichTextBoxFinds.MatchCase) > 0)
|
||||
endComment = LuaText.SelectionStart - CommentMatch.Index + 2;
|
||||
else
|
||||
endComment = LuaText.Text.Length;
|
||||
private void ColorComments()
|
||||
{
|
||||
foreach (Match CommentMatch in new Regex("--").Matches(LuaText.Text))
|
||||
{
|
||||
int endComment;
|
||||
|
||||
LuaText.Select(CommentMatch.Index, endComment);
|
||||
if (LuaText.Text.Substring(CommentMatch.Index, 4) == "--[[")
|
||||
{
|
||||
if (LuaText.Find("]]", RichTextBoxFinds.MatchCase) > 0)
|
||||
endComment = LuaText.SelectionStart - CommentMatch.Index + 2;
|
||||
else
|
||||
endComment = LuaText.Text.Length;
|
||||
|
||||
LuaText.Select(CommentMatch.Index, endComment);
|
||||
LuaText.SelectionColor = Color.FromArgb(Global.Config.LuaCommentColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (LuaText.GetLineFromCharIndex(CommentMatch.Index) + 1 == LuaText.Lines.Count())
|
||||
endComment = LuaText.Text.Length - CommentMatch.Index;
|
||||
else
|
||||
endComment = LuaText.GetFirstCharIndexFromLine(LuaText.GetLineFromCharIndex(CommentMatch.Index) + 1) - CommentMatch.Index;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (LuaText.GetLineFromCharIndex(CommentMatch.Index) + 1 == LuaText.Lines.Count())
|
||||
endComment = LuaText.Text.Length - CommentMatch.Index;
|
||||
else
|
||||
endComment = LuaText.GetFirstCharIndexFromLine(LuaText.GetLineFromCharIndex(CommentMatch.Index) + 1) - CommentMatch.Index;
|
||||
|
||||
LuaText.Select(CommentMatch.Index, endComment);
|
||||
LuaText.Select(CommentMatch.Index, endComment);
|
||||
LuaText.SelectionColor = Color.FromArgb(Global.Config.LuaCommentColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ColorReservedWords()
|
||||
{
|
||||
foreach (Match keyWordMatch in keyWords.Matches(LuaText.Text))
|
||||
{
|
||||
char before = ' ', after = ' ';
|
||||
private void ColorReservedWords()
|
||||
{
|
||||
foreach (Match keyWordMatch in keyWords.Matches(LuaText.Text))
|
||||
{
|
||||
char before = ' ', after = ' ';
|
||||
|
||||
if (keyWordMatch.Index > 0)
|
||||
if(keyWordMatch.Index > 5 && keyWordMatch.Value != "if" && LuaText.Text.Substring(keyWordMatch.Index - 4, 4) != "else")
|
||||
before = LuaText.Text[keyWordMatch.Index - 1];
|
||||
if (keyWordMatch.Index > 0)
|
||||
if (keyWordMatch.Index > 5 && keyWordMatch.Value != "if" && LuaText.Text.Substring(keyWordMatch.Index - 4, 4) != "else")
|
||||
before = LuaText.Text[keyWordMatch.Index - 1];
|
||||
|
||||
if (keyWordMatch.Index + keyWordMatch.Length != LuaText.Text.Length)
|
||||
if (keyWordMatch.Value != "else" && LuaText.Text.Substring(keyWordMatch.Index, 2) != "if")
|
||||
after = LuaText.Text[keyWordMatch.Index + keyWordMatch.Length];
|
||||
if (keyWordMatch.Index + keyWordMatch.Length != LuaText.Text.Length)
|
||||
if (keyWordMatch.Value != "else" && LuaText.Text.Substring(keyWordMatch.Index, 2) != "if")
|
||||
after = LuaText.Text[keyWordMatch.Index + keyWordMatch.Length];
|
||||
|
||||
if (!char.IsLetterOrDigit(before) && !char.IsLetterOrDigit(after))
|
||||
{
|
||||
LuaText.Select(keyWordMatch.Index, keyWordMatch.Length);
|
||||
if (!char.IsLetterOrDigit(before) && !char.IsLetterOrDigit(after))
|
||||
{
|
||||
LuaText.Select(keyWordMatch.Index, keyWordMatch.Length);
|
||||
LuaText.SelectionColor = Color.FromArgb(Global.Config.LuaKeyWordColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
private void LuaWriter_Load(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace BizHawk.MultiClient
|
||||
{
|
||||
class LuaWriterBox : RichTextBox
|
||||
{
|
||||
public LuaWriterBox()
|
||||
{
|
||||
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
|
||||
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue