summaryrefslogtreecommitdiff
path: root/script-editor/MainForm.cs
diff options
context:
space:
mode:
Diffstat (limited to 'script-editor/MainForm.cs')
-rw-r--r--script-editor/MainForm.cs534
1 files changed, 356 insertions, 178 deletions
diff --git a/script-editor/MainForm.cs b/script-editor/MainForm.cs
index 110eb61..fe1bcb0 100644
--- a/script-editor/MainForm.cs
+++ b/script-editor/MainForm.cs
@@ -6,13 +6,18 @@ using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
+using System.Xml;
+using System.Xml.Serialization;
+using tom;
namespace VPScriptEditor
{
public partial class VPScriptEditor
{
private Pointer[] inputPtr, outputPtr;
- private int currPointerNb;
+ private PointerAnnotation[] annotations;
+ private ITextDocument inDoc, outDoc;
+ private int currPointerNb, nbUndefinedPtr, nextUntranslatedPtr, nextUnsurePtr;
private string outputFileName;
private FontFile vpFont;
private Bitmap conersBmp;
@@ -26,40 +31,54 @@ namespace VPScriptEditor
dfile.Close();
Stream imgStream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("VPScriptEditor.corners.png");
- if (imgStream == null)
- throw new Exception("Can't open embedded image");
-
+ if (imgStream == null) throw new Exception("Can't open embedded image");
conersBmp = new Bitmap(imgStream);
- this.ActiveControl = txtbxOutputPtr;
+ inDoc = getDocument(richEditInputPtr);
+ outDoc = getDocument(richEditOutputPtr);
+
+ updateTitle();
+ }
+
+ [System.Runtime.InteropServices.DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
+ private extern static IntPtr SendMessage(IntPtr hWnd, int msg, int wParam, out IntPtr lParam);
+ private const int WM_USER = 0x400, EM_GETOLEINTERFACE = WM_USER + 60;
+ private ITextDocument getDocument(RichTextBox rtb)
+ {
+ IntPtr iRichEditOle = IntPtr.Zero;
+ if (SendMessage(rtb.Handle, EM_GETOLEINTERFACE, 0, out iRichEditOle) == IntPtr.Zero)
+ throw new Exception("Can't access IRichEditOle object from RichTextBox");
+
+ return (ITextDocument)System.Runtime.InteropServices.Marshal.GetTypedObjectForIUnknown(iRichEditOle, typeof(tom.ITextDocument));
}
private Pointer[] parseXML(String content)
{
Match match = Regex.Match(content.Replace("\r\n", "\n"), "^<roomscripts>\\n*((?:.|\\n)*?)(?:\\n\\n)?</roomscripts>\\n*$");
- if (!match.Success)
- throw new Exception("Bad script format!");
+ if (!match.Success) throw new Exception("Bad script format!");
MatchCollection matches = Regex.Matches(match.Groups[1].Value, "<ptr n=\"(\\d+)\" room=\"(.+?)\"/>\\n(<nowindowdetected/>|<window (type=\"fixed\"|x=\"(.+?)\" y=\"(.+?)\" width=\"(.+?)\" height=\"(.+?)\")/>)\\n((?:.|\\n)*?)(?=(?:\\n\\n<ptr n=\"\\d+\".*/>|$))");
+ if (matches.Count == 0) throw new Exception("Void script!");
Pointer[] pointers = new Pointer[matches.Count];
for (int i = 0; i < matches.Count; i++)
{
int nb = int.Parse(matches[i].Groups[1].Value);
+ if (nb <= 0 || nb > matches.Count) throw new Exception("Pointer no " + nb + " out of range!");
- if (nb <= 0 || nb > matches.Count)
- throw new Exception("Pointer no " + nb + " out of range!");
-
- if (pointers[nb - 1] != null)
- throw new Exception("Duplicate pointer no " + nb);
-
+ if (pointers[nb - 1] != null) throw new Exception("Duplicate pointer no " + nb);
pointers[nb - 1] = new Pointer(matches[i].Groups[2].Value, matches[i].Groups[5].Value.Length > 0 ? WindowType.Normal : (matches[i].Groups[4].Value.Length > 0 ? WindowType.Fixed : WindowType.None), matches[i].Groups[5].Value, matches[i].Groups[6].Value, matches[i].Groups[7].Value, matches[i].Groups[8].Value, matches[i].Groups[9].Value);
}
return pointers;
}
+ private string getAnnotationFileName(string filename)
+ {
+ return Path.GetDirectoryName(filename) + "\\" + Path.GetFileNameWithoutExtension(filename) + ".annotation.xml";
+ }
+
private void OpenMenuItem_Click(System.Object sender, System.EventArgs e)
{
StreamReader sr = null;
@@ -72,31 +91,59 @@ namespace VPScriptEditor
if (ofd.ShowDialog() != DialogResult.OK)
return;
- String origFileName = ofd.FileName;
+ String origFileName = ofd.FileName, outputFileName;
sr = new StreamReader(ofd.OpenFile());
- inputPtr = parseXML(sr.ReadToEnd());
+ Pointer[] inputPtr = parseXML(sr.ReadToEnd());
sr.Close();
ofd.Title = "Select *translated* script file";
while (true)
- {
if (ofd.ShowDialog() != DialogResult.OK)
return;
-
- if ((outputFileName = ofd.FileName) == origFileName)
- MessageBox.Show("Select a different file than the original script!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
else
- {
- sr = new StreamReader(ofd.OpenFile());
- outputPtr = parseXML(sr.ReadToEnd());
- break;
- }
+ if ((outputFileName = ofd.FileName) == origFileName)
+ MessageBox.Show("Select a different file than the original script!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
+ else
+ break;
+
+ sr = new StreamReader(ofd.OpenFile());
+ Pointer[] outputPtr = parseXML(sr.ReadToEnd());
+ sr.Close();
+ if (outputPtr.Length != inputPtr.Length) throw new Exception("The two scripts don't contain same number of pointers");
+
+ String annotationFileName = getAnnotationFileName(outputFileName);
+ PointerAnnotation[] annotations;
+ if (System.IO.File.Exists(annotationFileName))
+ {
+ XmlSerializer serializer = new XmlSerializer(typeof(PointerAnnotation[]));
+ sr = new StreamReader(annotationFileName);
+ annotations = (PointerAnnotation[])serializer.Deserialize(sr);
}
+ else
+ {
+ MessageBox.Show("No annotation file found for " + Path.GetFileName(outputFileName) + "\nA new one will be created on next save", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
+ annotations = new PointerAnnotation[inputPtr.Length];
+ for (int i = 0; i < inputPtr.Length; i++)
+ annotations[i] = new PointerAnnotation();
+ }
+
+ this.inputPtr = inputPtr;
+ this.outputPtr = outputPtr;
+ this.outputFileName = outputFileName;
+ this.annotations = annotations;
+
+ nbUndefinedPtr = 0;
+ foreach (PointerAnnotation pa in annotations)
+ if (pa.state == PointerState.Undefined)
+ nbUndefinedPtr++;
+
+ toolStripStatusLabel1.Text = Path.GetFileName(outputFileName) + " successfully loaded";
}
catch (Exception ex)
{
- MessageBox.Show(ex.Message);
+ MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
}
finally
{
@@ -106,13 +153,64 @@ namespace VPScriptEditor
initInterface();
}
- public string[] getText(string input)
+ private void saveCurrentPointer()
{
- string input_new = Regex.Replace(Regex.Replace(input, "<st rep=\"(\\d+)\"/>(.+?)<rrep/>", new MatchEvaluator(delegate(Match m) { return new String(m.Groups[2].Value[0], int.Parse(m.Groups[1].Value)); })), "<.+?/>", "");
- return Regex.Split(input_new, "\r\n");
+ outputPtr[currPointerNb].setVars(inputPtr[currPointerNb].rooms, inputPtr[currPointerNb].type, txtbxOutputX.Text, txtbxOutputY.Text, txtbxOutputWidth.Text, txtbxOutputHeight.Text, richEditOutputPtr.Text.Replace("\r\n", "\n"));
+ annotations[currPointerNb].state = chkDone.Checked ? PointerState.Done : (chkUnsure.Checked ? PointerState.Unsure : PointerState.Undefined);
+ }
+
+ private bool saveOutput(string fileName)
+ {
+ saveCurrentPointer();
+
+ StreamWriter sw = null;
+ try
+ {
+ StringBuilder str = new StringBuilder("<roomscripts>\n\n");
+
+ for (int i = 0; i < outputPtr.Length; i++)
+ {
+ Pointer p = outputPtr[i];
+
+ str.Append("<ptr n=\"" + (i + 1) + "\" room=\"" + p.rooms + "\"/>\n");
+ if (p.type == WindowType.None)
+ str.Append("<nowindowdetected/>");
+ else
+ if (p.type == WindowType.Fixed)
+ str.Append("<window type=\"fixed\"/>");
+ else
+ str.Append("<window x=\"" + p.x + "\" y=\"" + p.y + "\" width=\"" + p.width + "\" height=\"" + p.height + "\"/>");
+
+ str.Append("\n");
+ str.Append(p.content.Replace("\r\n", "\n"));
+ str.Append("\n\n");
+ }
+
+ str.Append("</roomscripts>\n");
+
+ sw = new StreamWriter(fileName);
+ sw.Write(str);
+ sw.Close();
+
+ XmlSerializer serializer = new XmlSerializer(typeof(PointerAnnotation[]));
+ sw = new StreamWriter(getAnnotationFileName(fileName));
+ serializer.Serialize(sw, annotations);
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return false;
+ }
+ finally
+ {
+ if (sw != null) sw.Close();
+ }
+
+ toolStripStatusLabel1.Text = "Last save on " + DateTime.Now.ToString();
+ return true;
}
- public void updateInputPtr()
+ private void updateInputPtr()
{
Pointer p = inputPtr[currPointerNb];
@@ -121,151 +219,141 @@ namespace VPScriptEditor
txtbxInputY.Text = p.y;
txtbxInputWidth.Text = p.width;
txtbxInputHeight.Text = p.height;
- txtbxInputPtr.Text = p.content.Replace("\n", "\r\n");
+ richEditInputPtr.Text = p.content;
}
- public void updateOutputPtr()
+ private void updateOutputPtr()
{
Pointer p = outputPtr[currPointerNb];
-
txtbxOutputX.Text = p.x;
txtbxOutputY.Text = p.y;
txtbxOutputWidth.Text = p.width;
txtbxOutputHeight.Text = p.height;
- txtbxOutputPtr.Text = p.content.Replace("\n", "\r\n");
+ richEditOutputPtr.Text = p.content;
+ txtbxOutputX.Enabled = txtbxOutputY.Enabled = txtbxOutputWidth.Enabled = txtbxOutputHeight.Enabled = bttnResize.Enabled = p.type == WindowType.Normal;
+
+ PointerState ps = annotations[currPointerNb].state;
+ chkDone.CheckedChanged -= this.chkbx_CheckedChanged;
+ chkDone.Checked = ps == PointerState.Done;
+ chkDone.CheckedChanged += this.chkbx_CheckedChanged;
+ chkUnsure.CheckedChanged -= this.chkbx_CheckedChanged;
+ chkUnsure.Checked = ps == PointerState.Unsure;
+ chkUnsure.CheckedChanged += this.chkbx_CheckedChanged;
+ }
- bttnResize.Enabled = p.type == WindowType.Normal;
+ private void updateCommentBttn()
+ {
+ bttnComment.Text = annotations[currPointerNb].comment == null ? "Add comment" : "View/Edit comment";
}
- public void updateInterface()
+ private void updateInterface()
{
+ nextUntranslatedPtr = searchPointer(PointerState.Undefined);
+ nextUnsurePtr = searchPointer(PointerState.Unsure);
+
bttnNext.Enabled = currPointerNb < inputPtr.Length - 1;
bttnPrevious.Enabled = currPointerNb > 0;
+ bttnNextUntranslated.Enabled = nextUntranslatedPtr != -1;
+ bttnNextUnsure.Enabled = nextUnsurePtr != -1;
txtbxPointerNumber.Text = Convert.ToString(currPointerNb + 1);
updateInputPtr();
updateOutputPtr();
+ updateCommentBttn();
pnlInput.Invalidate();
pnlOutput.Invalidate();
}
- public void updateTitle()
+ private void updateTitle()
{
- this.Text = "VPScriptEditor - " + Path.GetFileName(outputFileName);
+ this.Text = AboutBox.AssemblyProduct + (outputFileName != null ? " - " + Path.GetFileName(outputFileName) : "");
}
- public void initInterface()
+ private void updateStatusProgress()
+ {
+ lblStatusProgress.Text = (inputPtr.Length - nbUndefinedPtr) + "/" + inputPtr.Length;
+ }
+
+ private void initInterface()
{
currPointerNb = 0;
- txtbxPointerNumber.Enabled = true;
- bttnReset.Enabled = true;
- SaveMenuItem.Enabled = SaveAsMenuItem.Enabled = true;
+ txtbxPointerNumber.Enabled = bttnReset.Enabled = SaveMenuItem.Enabled = SaveAsMenuItem.Enabled = chkDone.Enabled = chkUnsure.Enabled = bttnComment.Enabled = richEditOutputPtr.Enabled = true;
updateInterface();
updateTitle();
- }
+ updateStatusProgress();
- private void bttnNext_Click(System.Object sender, System.EventArgs e)
- {
- saveCurrentPointer();
- ++currPointerNb;
- updateInterface();
+ ActiveControl = richEditOutputPtr;
}
- private void bttnPrevious_Click(System.Object sender, System.EventArgs e)
+ private int searchPointer(PointerState ps)
{
- saveCurrentPointer();
- --currPointerNb;
- updateInterface();
- }
+ for (int i = 1; i < annotations.Length; i++)
+ if (annotations[(currPointerNb + i) % annotations.Length].state == ps)
+ return (currPointerNb + i) % annotations.Length;
- private void bttnReset_Click(System.Object sender, System.EventArgs e)
- {
- outputPtr[currPointerNb] = new Pointer(inputPtr[currPointerNb]);
- updateOutputPtr();
+ return -1;
}
- private void ExitMenuItem_Click(System.Object sender, System.EventArgs e)
+ private void gotoPointer(int nb)
{
- Application.Exit();
+ saveCurrentPointer();
+ currPointerNb = nb;
+ updateInterface();
}
- private void gotoPointer()
+ private void txtbxPointerNumber_KeyPress(object sender, KeyPressEventArgs e)
{
- saveCurrentPointer();
-
- try
+ if (e.KeyChar == (char)Keys.Return)
{
- int nb = int.Parse(txtbxPointerNumber.Text);
- if (nb > 0 && nb <= inputPtr.Length)
- currPointerNb = nb - 1;
+ e.Handled = true;
+ int nb;
+ if (int.TryParse(txtbxPointerNumber.Text, out nb) && nb > 0 && nb <= inputPtr.Length)
+ gotoPointer(nb - 1);
else
{
MessageBox.Show("Pointer out of range. Please enter a number between 1 and " + inputPtr.Length + ".", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
- return;
+ txtbxPointerNumber.Text = System.Convert.ToString(currPointerNb + 1);
}
}
- catch (System.FormatException)
- {
- MessageBox.Show("Incorrect pointer number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
- return;
- }
- finally
- {
- txtbxPointerNumber.Text = System.Convert.ToString(currPointerNb + 1);
- }
-
- updateInterface();
}
- private bool saveOutputXML(string fileName)
+ private void bttnPrevious_Click(System.Object sender, System.EventArgs e)
{
- saveCurrentPointer();
-
- StreamWriter sw = null;
- try
- {
- StringBuilder str = new StringBuilder("<roomscripts>\n\n");
-
- for (int i = 0; i < outputPtr.Length; i++)
- {
- Pointer p = outputPtr[i];
+ gotoPointer(currPointerNb - 1);
+ }
- str.Append("<ptr n=\"" + (i + 1) + "\" room=\"" + p.rooms + "\"/>\n");
- if (p.type == WindowType.None)
- str.Append("<nowindowdetected/>");
- else
- if (p.type == WindowType.Fixed)
- str.Append("<window type=\"fixed\"/>");
- else
- str.Append("<window x=\"" + p.x + "\" y=\"" + p.y + "\" width=\"" + p.width + "\" height=\"" + p.height + "\"/>");
+ private void bttnNext_Click(System.Object sender, System.EventArgs e)
+ {
+ gotoPointer(currPointerNb + 1);
+ }
+
+ private void bttnNextUntranslated_Click(object sender, EventArgs e)
+ {
+ gotoPointer(nextUntranslatedPtr);
+ }
- str.Append("\n");
- str.Append(p.content.Replace("\r\n", "\n"));
- str.Append("\n\n");
- }
+ private void bttnNextUnsure_Click(object sender, EventArgs e)
+ {
+ gotoPointer(nextUnsurePtr);
+ }
- str.Append("</roomscripts>\n");
+ private void bttnReset_Click(System.Object sender, System.EventArgs e)
+ {
+ outputPtr[currPointerNb].copyFrom(inputPtr[currPointerNb]);
+ chkDone.Checked = chkUnsure.Checked = false;
+ updateOutputPtr();
+ }
- sw = new StreamWriter(fileName);
- sw.Write(str);
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- return false;
- }
- finally
- {
- if (sw != null) sw.Close();
- }
- return true;
+ private void ExitMenuItem_Click(System.Object sender, System.EventArgs e)
+ {
+ Application.Exit();
}
private void SaveMenuItem_Click(System.Object sender, System.EventArgs e)
{
- saveOutputXML(outputFileName);
+ saveOutput(outputFileName);
}
private void SaveAsMenuItem_Click(object sender, EventArgs e)
@@ -277,95 +365,89 @@ namespace VPScriptEditor
if (sfd.ShowDialog() != DialogResult.OK)
return;
- if (saveOutputXML(sfd.FileName))
+ if (saveOutput(sfd.FileName))
{
outputFileName = sfd.FileName;
updateTitle();
}
}
- public void saveCurrentPointer()
+ private void colorizeRichEdit(ITextDocument itd)
{
- outputPtr[currPointerNb] = new Pointer(inputPtr[currPointerNb].rooms, inputPtr[currPointerNb].type, txtbxOutputX.Text, txtbxOutputY.Text, txtbxOutputWidth.Text, txtbxOutputHeight.Text, txtbxOutputPtr.Text.Replace("\r\n", "\n"));
- }
+ itd.Freeze();
+ itd.Undo((int)tomConstants.tomSuspend);
- private void bttnResize_Click(System.Object sender, System.EventArgs e)
- {
- String[] text = getText(txtbxOutputPtr.Text);
- int w = 0, h = 0;
+ ITextRange r = itd.Range(0, 0);
+ r.MoveEnd((int)tomConstants.tomCharacter, r.StoryLength);
+ r.Font.ForeColor = 0;
- for (int j = 0; j <= text.Length - 1; j++)
+ MatchCollection matches = Regex.Matches(r.Text, "<(.*?)/>");
+ for (int i = 0; i < matches.Count; i++)
{
- int curr_w = 0;
-
- foreach (char ch in text[j])
- try
- {
- curr_w += vpFont.getSymbolWidth(ch);
- }
- catch (System.Collections.Generic.KeyNotFoundException ex) { }
-
- w = curr_w > w ? curr_w : w;
- h += 14;
+ r.Start = matches[i].Groups[0].Index;
+ r.End = r.Start + matches[i].Groups[0].Length;
+ r.Font.ForeColor = 0xFF;
}
- txtbxOutputWidth.Text = System.Convert.ToString(w);
- txtbxOutputHeight.Text = System.Convert.ToString(h);
+ itd.Undo((int)tomConstants.tomResume);
+ itd.Unfreeze();
+ }
- pnlOutput.Invalidate();
+ private void parseScriptLines(string[] input, int a, int b)
+ {
+ for (int i = a; i < b; i++)
+ input[i] = Regex.Replace(Regex.Replace(input[i], "<st rep=\"(\\d+)\"/>(.+?)<rrep/>", new MatchEvaluator(delegate(Match m) { return new String(m.Groups[2].Value[0], int.Parse(m.Groups[1].Value)); })), "<.+?/>", "");
}
- private Bitmap drawPointer(String[] text, string xStr, string yStr, string wStr, string hStr)
+ private static bool isNewTag(String s) { return s == "<new/>"; }
+
+ private Bitmap drawPointer(RichTextBox rtb, string xStr, string yStr, string wStr, string hStr)
{
+ String[] text = Regex.Split(rtb.Text, "\n");
+ int currLineNb = Regex.Matches(rtb.Text.Substring(0, rtb.SelectionStart), "\\n").Count;
+
+ int begLineNb = Array.FindLastIndex(text, currLineNb, isNewTag) + 1, endLineNb = Array.FindIndex(text, currLineNb + 1, isNewTag);
+ if (endLineNb < 0) endLineNb = text.Length;
+ parseScriptLines(text, begLineNb, endLineNb);
+
Bitmap bmp = new Bitmap(320, 240, PixelFormat.Format32bppArgb);
Graphics gBmp = Graphics.FromImage(bmp);
gBmp.CompositingMode = CompositingMode.SourceOver;
gBmp.FillRectangle(Brushes.White, 0, 0, bmp.Width, bmp.Height);
- int x_base, x_curr, y_curr;
+ int x_base, y_curr, h, w;
- try
- {
- x_base = x_curr = int.Parse(xStr);
- y_curr = int.Parse(yStr);
- }
- catch (System.FormatException e)
- {
- x_curr = x_base = y_curr = 10;
- }
+ if (!int.TryParse(xStr, out x_base) || !int.TryParse(yStr, out y_curr))
+ x_base = y_curr = 10;
- try
+ if (int.TryParse(wStr, out w) && int.TryParse(hStr, out h))
{
- int h = int.Parse(hStr), w = int.Parse(wStr);
-
SolidBrush innerBrush = new SolidBrush(Color.FromArgb(248, 216, 96)), outerBrush = new SolidBrush(Color.FromArgb(88, 64, 8));
-
- gBmp.FillRectangle(outerBrush, x_curr - 8, y_curr, 1, h);
- gBmp.FillRectangle(innerBrush, x_curr - 7, y_curr, 2, h);
- gBmp.FillRectangle(outerBrush, x_curr - 2, y_curr - 7, w + 5, 1);
- gBmp.FillRectangle(innerBrush, x_curr - 2, y_curr - 6, w + 5, 2);
- gBmp.FillRectangle(outerBrush, x_curr + w + 9, y_curr, 1, h);
- gBmp.FillRectangle(innerBrush, x_curr + w + 7, y_curr, 2, h);
- gBmp.FillRectangle(outerBrush, x_curr - 2, y_curr + h + 6, w + 5, 1);
- gBmp.FillRectangle(innerBrush, x_curr - 2, y_curr + h + 4, w + 5, 2);
-
- gBmp.DrawImage(conersBmp, x_curr - 8, y_curr - 7, new Rectangle(0, 0, 7, 7), GraphicsUnit.Pixel);
- gBmp.DrawImage(conersBmp, x_curr - 8, y_curr + h, new Rectangle(0, 7, 7, 7), GraphicsUnit.Pixel);
- gBmp.DrawImage(conersBmp, x_curr + w + 3, y_curr - 7, new Rectangle(7, 0, 7, 7), GraphicsUnit.Pixel);
- gBmp.DrawImage(conersBmp, x_curr + w + 3, y_curr + h, new Rectangle(7, 7, 7, 7), GraphicsUnit.Pixel);
+ gBmp.FillRectangle(outerBrush, x_base - 8, y_curr, 1, h);
+ gBmp.FillRectangle(innerBrush, x_base - 7, y_curr, 2, h);
+ gBmp.FillRectangle(outerBrush, x_base - 2, y_curr - 7, w + 5, 1);
+ gBmp.FillRectangle(innerBrush, x_base - 2, y_curr - 6, w + 5, 2);
+ gBmp.FillRectangle(outerBrush, x_base + w + 9, y_curr, 1, h);
+ gBmp.FillRectangle(innerBrush, x_base + w + 7, y_curr, 2, h);
+ gBmp.FillRectangle(outerBrush, x_base - 2, y_curr + h + 6, w + 5, 1);
+ gBmp.FillRectangle(innerBrush, x_base - 2, y_curr + h + 4, w + 5, 2);
+
+ gBmp.DrawImage(conersBmp, x_base - 8, y_curr - 7, new Rectangle(0, 0, 7, 7), GraphicsUnit.Pixel);
+ gBmp.DrawImage(conersBmp, x_base - 8, y_curr + h, new Rectangle(0, 7, 7, 7), GraphicsUnit.Pixel);
+ gBmp.DrawImage(conersBmp, x_base + w + 3, y_curr - 7, new Rectangle(7, 0, 7, 7), GraphicsUnit.Pixel);
+ gBmp.DrawImage(conersBmp, x_base + w + 3, y_curr + h, new Rectangle(7, 7, 7, 7), GraphicsUnit.Pixel);
}
- catch (System.FormatException e) { }
- for (int j = 0; j <= text.Length - 1; j++)
+ int x_curr = x_base;
+ for (int j = begLineNb; j < endLineNb; j++)
{
foreach (char ch in text[j])
- try
+ if (vpFont.containsSymbol(ch))
{
gBmp.DrawImage(vpFont.getBitmap(ch), x_curr, y_curr);
x_curr += vpFont.getSymbolWidth(ch);
}
- catch (System.Collections.Generic.KeyNotFoundException e) { }
x_curr = x_base;
y_curr += 14;
@@ -376,35 +458,131 @@ namespace VPScriptEditor
private void pnlInput_Paint(object sender, PaintEventArgs e)
{
- e.Graphics.DrawImage(drawPointer(getText(txtbxInputPtr.Text), txtbxInputX.Text, txtbxInputY.Text, txtbxInputWidth.Text, txtbxInputHeight.Text), 0, 0);
+ e.Graphics.DrawImage(drawPointer(richEditInputPtr, txtbxInputX.Text, txtbxInputY.Text, txtbxInputWidth.Text, txtbxInputHeight.Text), 0, 0);
}
private void pnlOutput_Paint(object sender, PaintEventArgs e)
{
- e.Graphics.DrawImage(drawPointer(getText(txtbxOutputPtr.Text), txtbxOutputX.Text, txtbxOutputY.Text, txtbxOutputWidth.Text, txtbxOutputHeight.Text), 0, 0);
+ e.Graphics.DrawImage(drawPointer(richEditOutputPtr, txtbxOutputX.Text, txtbxOutputY.Text, txtbxOutputWidth.Text, txtbxOutputHeight.Text), 0, 0);
}
- private void txtbxOutput_TextChanged(object sender, EventArgs e)
+ private void richEdit_SelectionChanged(object sender, EventArgs e)
+ {
+ ((RichTextBox)sender == richEditInputPtr ? pnlInput : pnlOutput).Invalidate();
+ }
+
+ private void richEditInputPtr_TextChanged(object sender, EventArgs e)
+ {
+ colorizeRichEdit(inDoc);
+ }
+
+ private void richEditOutputPtr_SelectionChanged(object sender, EventArgs e)
{
pnlOutput.Invalidate();
}
- private void txtbxPointerNumber_KeyPress(object sender, KeyPressEventArgs e)
+ private void richEditOutputPtr_TextChanged(object sender, EventArgs e)
{
- if (e.KeyChar == (char)Keys.Return)
+ colorizeRichEdit(outDoc);
+ // simple trick to circumvent a stupid vertical scroll bug
+ richEditOutputPtr.SelectionStart = richEditOutputPtr.SelectionStart;
+ }
+
+ private void richEditOutputPtr_KeyDown(object sender, KeyEventArgs e)
+ {
+ if ((e.Shift && e.KeyCode == Keys.Insert) || (e.Control && e.KeyCode == Keys.V))
{
+ richEditOutputPtr.Paste(DataFormats.GetFormat("Text"));
e.Handled = true;
- gotoPointer();
}
+ else
+ if ((e.Modifiers == Keys.None || e.Modifiers == Keys.Control) && e.KeyCode == Keys.Delete)
+ pnlOutput.Invalidate();
}
- private void txtbxOutputPtr_KeyPress(object sender, KeyPressEventArgs e)
+ private void richEditOutputPtr_KeyPress(object sender, KeyPressEventArgs e)
{
- if (!vpFont.containsSymbol(e.KeyChar) && e.KeyChar >= ' ')
+ if (e.KeyChar >= ' ' && e.KeyChar != (char)Keys.F16 && !vpFont.containsSymbol(e.KeyChar))
{
e.Handled = true;
System.Media.SystemSounds.Beep.Play();
}
}
+
+ private void bttnResize_Click(System.Object sender, System.EventArgs e)
+ {
+ String[] text = Regex.Split(richEditOutputPtr.Text, "\n");
+ int w = 0, h = 0, curr_h = 0;
+
+ for (int j = 0; j < text.Length; j++)
+ if (isNewTag(text[j]))
+ {
+ h = Math.Max(curr_h, h);
+ curr_h = 0;
+ }
+ else
+ {
+ int curr_w = 0;
+ parseScriptLines(text, j, j + 1);
+
+ foreach (char ch in text[j])
+ if (vpFont.containsSymbol(ch))
+ curr_w += vpFont.getSymbolWidth(ch);
+
+ w = Math.Max(curr_w, w);
+ curr_h += 14;
+ }
+
+ h = Math.Max(curr_h, h);
+
+ txtbxOutputWidth.Text = System.Convert.ToString(w);
+ txtbxOutputHeight.Text = System.Convert.ToString(h);
+
+ pnlOutput.Invalidate();
+ }
+
+ private void chkbx_CheckedChanged(object sender, EventArgs e)
+ {
+ CheckBox chk = (CheckBox)sender, chk2 = chk == chkDone ? chkUnsure : chkDone;
+ if (chk.Checked && chk2.Checked)
+ {
+ nbUndefinedPtr++;
+ chk2.Checked = false;
+ }
+ else
+ {
+ nbUndefinedPtr += (!chkDone.Checked && !chkUnsure.Checked ? 1 : -1);
+ updateStatusProgress();
+ }
+ }
+
+ private void bttnComment_Click(object sender, EventArgs e)
+ {
+ CommentForm cf = new CommentForm(currPointerNb, annotations[currPointerNb].comment);
+ cf.ShowDialog();
+ annotations[currPointerNb].comment = cf.Comment;
+ updateCommentBttn();
+ }
+
+ private void txtbxOutput_KeyPress(object sender, KeyPressEventArgs e)
+ {
+ if (e.KeyChar == (char)Keys.Return)
+ {
+ e.Handled = true;
+ pnlOutput.Invalidate();
+ }
+ }
+
+ private void wordWarpToolStripMenuItem_CheckedChanged(object sender, EventArgs e)
+ {
+ richEditInputPtr.WordWrap = richEditOutputPtr.WordWrap = ((ToolStripMenuItem)sender).Checked;
+ inDoc = getDocument(richEditInputPtr);
+ outDoc = getDocument(richEditOutputPtr);
+ }
+
+ private void aboutToolStripMenuItem1_Click(object sender, EventArgs e)
+ {
+ new AboutBox().ShowDialog();
+ }
}
} \ No newline at end of file