public void MoveToEndOfLine() { Document.Line line = textBox.document.Lines[row]; int delta = line.Length - (Position - line.startIndex) - 1; Position += delta; }
public void Set(int col, int row) { if (row < 0) { row = 0; } if (row >= textBox.document.Lines.Count) { row = textBox.document.Lines.Count - 1; } Document.Line l = textBox.document.Lines[row]; if (col < 0) { col = 0; } if (col >= l.Length) { col = Math.Max(l.Length - 1, 0); } this.row = row; position = l.startIndex + col; realcolumn = col; if (Change != null) { Change(this, null); } if (Visible) { textBox.UpdateSelection(); } }
public void Insert(Caret start, String value) { if (value.Contains('\r') || value.Contains('\n')) { Text = Text.Insert(start.Position, value.Replace("\r\n", "\n").Replace('\r', '\n')); } else { Document.Line line = Lines[start.Row]; line.Value = line.Value.Insert(start.Column, value); CalcLineIndices(); } }
public override void Chop(Document.Line line) { var N = new Document.Line.Char[line.Rawline.Length]; for (int i = 0; i < line.Rawline.Length; i++) { if (line.Rawline[i] == '\t') { N[i] = new Document.Line.Char(line.Rawline[i], Color.Aquamarine, 5 - (i % 5)); } else { N[i] = new Document.Line.Char(line.Rawline[i], Color.Aquamarine); } } line.Letters = N; }
public void SetFromXY(Vector2 documentPos) { IsSet = true; var fi = textBox.Scene.View.Content.Acquire <FontImplementation>(textBox.Font); int lineNr = (int)(documentPos.Y / fi.CharacterHeight); if (lineNr >= textBox.document.Lines.Count) { lineNr = textBox.document.Lines.Count - 1; } if (lineNr < 0) { lineNr = 0; } Document.Line line = textBox.document.Lines[lineNr]; float prevx = 0; //find the char in the line for (int i = 0; i <= line.Value.Length; i++) { String w = line.Value.Substring(0, i); float x = fi.TextWidth(w); if (x > documentPos.X) { if (x - documentPos.X < documentPos.X - prevx) { i++; } this.Position = Math.Max(0, line.startIndex + i - 1); return; } prevx = x; } this.Position = line.startIndex + line.Value.Length; }
// PL = Programming language... For most programming languages this will work. public override void Chop(Document.Line line) { try { var Words = new List <string>(); var curword = new StringBuilder(); var instring = false; var incomment = false; void endword() { if (curword.Length > 0) { Words.Add(curword.ToString()); } curword.Clear(); } for (int i = 0; i < line.Rawline.Length; i++) { if (instring) { if (line.Rawline[i] == curword[0] && line.Rawline[i - 1] != escape) { instring = false; curword.Append(line.Rawline[i]); endword(); } else { curword.Append(line.Rawline[i]); } } else if (incomment) { curword.Append(line.Rawline[i]); } else if (i + SingleComment.Length < line.Rawline.Length && qstr.Mid(line.Rawline, i + 1, SingleComment.Length) == SingleComment) { incomment = true; endword(); curword.Append(line.Rawline[i]); } else { switch (line.Rawline[i]) { case ' ': case '\t': endword(); curword.Append(line.Rawline[i]); endword(); break; // Not the cleanest method, but it works :P case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case '_': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x': case 'y': case 'z': curword.Append(line.Rawline[i]); break; case '"': if (doubquotestring) { endword(); curword.Append('"'); instring = true; } else { endword(); Words.Add($"{line.Rawline[i]}"); } break; case '\'': if (singquotestring) { endword(); curword.Append('"'); instring = true; } else { endword(); Words.Add($"{line.Rawline[i]}"); } break; default: endword(); Words.Add($"{line.Rawline[i]}"); break; } } } endword(); var Chars = new List <Document.Line.Char>(); var pl = 0; foreach (string w in Words) { var c = c_Gen; var l = 1; if ((byte)w[0] >= 48 && (byte)w[0] <= 57) { c = c_Number; } else if (KeyWords.Contains(w.Trim())) { c = c_KeyWord; } else if (qstr.Prefixed(w, SingleComment)) { c = c_Comment; } else if ((w[0] == '"' && doubquotestring) || (w[0] == '\'' && singquotestring)) { c = c_String; } for (int i = 0; i < w.Length; i++) { l = 1; if (w[i] == '\t') { l = 5 - (pl % 5); } Chars.Add(new Document.Line.Char(w[i], c, l)); pl += l; } } line.Letters = Chars.ToArray(); // Needed for display line.Words = Words.ToArray(); // Needed for outline } catch (Exception E) { #if DEBUG Void.FatalError($"{E.Message}\n\n{E.StackTrace}"); #else Void.FatalError($"{E.Message}"); #endif Environment.Exit(999); } }
abstract public void Chop(Document.Line line);
/// <summary>This method will create a single index for the primitives /// This will not work on polygons and polylist, since vcount is not taken in count there /// So you need to first run ConvexTriangulator (or equivalent) /// <para>This will make it directly usable as a index vertexArray for drawing</para> /// </summary> static public void Reindexor(Document doc) { String[] channelFlags = { "POSITION", "NORMAL", "TEXCOORD", "COLOR", "TANGENT", "BINORMAL", "UV", "TEXBINORMAL", "TEXTANGENT" }; Dictionary <string, int> channelCount = new Dictionary <string, int>(); Dictionary <string, int> maxChannelCount = new Dictionary <string, int>(); Dictionary <string, List <Document.Input> > inputs = new Dictionary <string, List <Document.Input> >();; foreach (Document.Geometry geo in doc.geometries) { // Skip geometry if there are no primitives defined if (geo.mesh.primitives.Count == 0) { continue; } foreach (string i in channelFlags) { maxChannelCount[i] = 0; } // Check if all parts have the same vertex definition bool first = true; foreach (Document.Primitive primitive in geo.mesh.primitives) { foreach (string i in channelFlags) { channelCount[i] = 0; } foreach (Document.Input input in COLLADAUtil.GetAllInputs(primitive)) { channelCount[input.semantic]++; } if (first) { foreach (string i in channelFlags) { if (maxChannelCount[i] < channelCount[i]) { maxChannelCount[i] = channelCount[i]; } } first = false; } else { foreach (string i in channelFlags) { if (maxChannelCount[i] != channelCount[i]) { throw new Exception("TODO: mesh parts have different vertex buffer definition in geometry " + geo.id); } } } } // create new float array and index List <List <int> > indexList = new List <List <int> >(); List <int> indexes; List <float> farray = new List <float>(); Dictionary <string, int> checkIndex = new Dictionary <string, int>(); int index = 0; foreach (Document.Primitive primitive in geo.mesh.primitives) { foreach (string i in channelFlags) { inputs[i] = new List <Document.Input>(); } foreach (Document.Input input in COLLADAUtil.GetAllInputs(primitive)) { inputs[input.semantic].Add(input); } indexes = new List <int>(); indexList.Add(indexes); int k = 0; string indexKey; List <float> tmpValues; try { while (true) { indexKey = ""; tmpValues = new List <float>(); foreach (string i in channelFlags) { foreach (Document.Input input in inputs[i]) { int j = COLLADAUtil.GetPValue(input, primitive, k); indexKey += j.ToString() + ","; float[] values = COLLADAUtil.GetSourceElement(doc, input, j); for (int l = 0; l < values.Length; l++) { tmpValues.Add(values[l]); } } } k++; if (checkIndex.ContainsKey(indexKey)) { indexes.Add(checkIndex[indexKey]); } else { indexes.Add(index); checkIndex[indexKey] = index++; foreach (float f in tmpValues) { farray.Add(f); } } } } catch { } // catch for index out of range. } // remove old sources and array foreach (Document.Source source in geo.mesh.sources) { if (source.array != null) { doc.dic.Remove(((Document.Array <float>)source.array).id); } doc.dic.Remove(source.id); } // create all the new source int stride = 0; foreach (Document.Source source in geo.mesh.sources) { stride += source.accessor.stride; } List <Document.Source> newSources = new List <Document.Source>(); Document.Source newSource; Document.Accessor newAccessor; Document.Array <float> newArray; int offset = 0; string positionId = ((Document.Source)inputs["POSITION"][0].source).id; foreach (Document.Source source in geo.mesh.sources) { newAccessor = new Document.Accessor(doc, farray.Count / stride, offset, stride, "#" + geo.id + "-vertexArray", source.accessor.parameters); offset += source.accessor.stride; if (source.id == positionId) { newArray = new Document.Array <float>(doc, geo.id + "-vertexArray", farray.ToArray()); } else { newArray = null; } newSource = new Document.Source(doc, source.id, newArray, newAccessor); newSources.Add(newSource); } // Create the new vertices List <Document.Input> newInputs = new List <Document.Input>(); Document.Input newInput; foreach (string i in channelFlags) { foreach (Document.Input input in inputs[i]) { // no offset, all inputs share the same index newInput = new Document.Input(doc, 0, input.semantic, input.set, ((Document.Source)input.source).id); newInputs.Add(newInput); } } Document.Vertices newVertices = new Document.Vertices(doc, geo.mesh.vertices.id, newInputs); // now create the new primitives List <Document.Primitive> newPrimitives = new List <Document.Primitive>(); Document.Primitive newPrimitive; index = 0; offset = 0; foreach (Document.Primitive primitive in geo.mesh.primitives) { newInputs = new List <Document.Input>(); newInput = new Document.Input(doc, 0, "VERTEX", -1, geo.mesh.vertices.id); newInputs.Add(newInput); if (primitive is Document.Triangle) { newPrimitive = new Document.Triangle(doc, primitive.count, newInputs, indexList[index].ToArray()); } else if (primitive is Document.Line) { newPrimitive = new Document.Line(doc, primitive.count, newInputs, indexList[index].ToArray()); } else { throw new Exception("TODO: need to take care of " + primitive.GetType().ToString()); } newPrimitive.material = primitive.material; newPrimitive.extras = primitive.extras; newPrimitive.name = primitive.name; newPrimitives.Add(newPrimitive); index++; } // change the primitive to use the new array and indexes. // 1) - remove the old sources, vertices and primitives geo.mesh.sources.Clear(); geo.mesh.vertices.inputs.Clear(); geo.mesh.primitives.Clear(); // 2) - Add all the sources, only the POSITION will have the values geo.mesh.sources = newSources; geo.mesh.primitives = newPrimitives; geo.mesh.vertices = newVertices; } // foreach geometry } // Reindexor()
/// <summary>This method will create a single index for the primitives /// This will not work on polygons and polylist, since vcount is not taken in count there /// So you need to first run ConvexTriangulator (or equivalent) /// <para>This will make it directly usable as a index vertexArray for drawing</para> /// </summary> public static void Reindexor(Document doc) { String[] channelFlags = { "POSITION", "NORMAL", "TEXCOORD", "COLOR", "TANGENT", "BINORMAL", "UV", "TEXBINORMAL", "TEXTANGENT" }; Dictionary<string,int> channelCount = new Dictionary<string,int>(); Dictionary<string, int> maxChannelCount = new Dictionary<string, int>(); Dictionary<string, List<Document.Input>> inputs = new Dictionary<string, List<Document.Input>>(); ; foreach (Document.Geometry geo in doc.geometries) { // Skip geometry if there are no primitives defined if (geo.mesh.primitives.Count == 0) continue; foreach (string i in channelFlags) maxChannelCount[i] = 0; // Check if all parts have the same vertex definition bool first=true; foreach (Document.Primitive primitive in geo.mesh.primitives) { foreach (string i in channelFlags) channelCount[i] = 0; foreach (Document.Input input in COLLADAUtil.GetAllInputs(primitive)) { channelCount[input.semantic]++; } if (first) { foreach (string i in channelFlags) if (maxChannelCount[i] < channelCount[i]) maxChannelCount[i] = channelCount[i]; first = false; } else { foreach (string i in channelFlags) if (maxChannelCount[i] != channelCount[i]) throw new Exception("TODO: mesh parts have different vertex buffer definition in geometry " + geo.id); } } // create new float array and index List<List<int>> indexList = new List<List<int>>(); List<int> indexes; List<float> farray = new List<float>(); Dictionary<string,int> checkIndex = new Dictionary<string,int>(); int index=0; foreach (Document.Primitive primitive in geo.mesh.primitives) { foreach (string i in channelFlags) inputs[i] = new List<Document.Input>(); foreach (Document.Input input in COLLADAUtil.GetAllInputs(primitive)) inputs[input.semantic].Add(input); indexes = new List<int>(); indexList.Add(indexes); int k=0; string indexKey; List<float> tmpValues; try { while (true) { indexKey = ""; tmpValues = new List<float>(); foreach (string i in channelFlags) foreach (Document.Input input in inputs[i]) { int j = COLLADAUtil.GetPValue(input, primitive, k); indexKey += j.ToString() + ","; float[] values = COLLADAUtil.GetSourceElement(doc,input, j); for (int l = 0; l < values.Length; l++) tmpValues.Add(values[l]); } k++; if (checkIndex.ContainsKey(indexKey)) indexes.Add(checkIndex[indexKey]); else { indexes.Add(index); checkIndex[indexKey] = index++; foreach (float f in tmpValues) farray.Add(f); } } } catch { } // catch for index out of range. } // remove old sources and array foreach (Document.Source source in geo.mesh.sources) { if (source.array != null) doc.dic.Remove(((Document.Array<float>)source.array).id); doc.dic.Remove(source.id); } // create all the new source int stride = 0; foreach (Document.Source source in geo.mesh.sources) { stride += source.accessor.stride; } List<Document.Source> newSources = new List<Document.Source>(); Document.Source newSource; Document.Accessor newAccessor; Document.Array<float> newArray; int offset = 0; string positionId = ((Document.Source)inputs["POSITION"][0].source).id; foreach (Document.Source source in geo.mesh.sources) { newAccessor = new Document.Accessor(doc, farray.Count / stride, offset, stride, "#"+geo.id + "-vertexArray", source.accessor.parameters); offset += source.accessor.stride; if (source.id == positionId) { newArray = new Document.Array<float>(doc, geo.id + "-vertexArray", farray.ToArray()); } else { newArray = null; } newSource = new Document.Source(doc, source.id, newArray, newAccessor); newSources.Add(newSource); } // Create the new vertices List<Document.Input> newInputs = new List<Document.Input>(); Document.Input newInput; foreach (string i in channelFlags) { foreach (Document.Input input in inputs[i]) { // no offset, all inputs share the same index newInput = new Document.Input(doc, 0, input.semantic, input.set, ((Document.Source)input.source).id); newInputs.Add(newInput); } } Document.Vertices newVertices = new Document.Vertices(doc, geo.mesh.vertices.id, newInputs); // now create the new primitives List<Document.Primitive> newPrimitives = new List<Document.Primitive>(); Document.Primitive newPrimitive; index = 0; offset = 0; foreach (Document.Primitive primitive in geo.mesh.primitives) { newInputs = new List<Document.Input>(); newInput = new Document.Input(doc, 0, "VERTEX", -1, geo.mesh.vertices.id); newInputs.Add(newInput); if (primitive is Document.Triangle) newPrimitive = new Document.Triangle(doc, primitive.count, newInputs, indexList[index].ToArray()); else if (primitive is Document.Line) newPrimitive = new Document.Line(doc, primitive.count, newInputs, indexList[index].ToArray()); else throw new Exception("TODO: need to take care of " + primitive.GetType().ToString()); newPrimitive.material = primitive.material; newPrimitive.extras = primitive.extras; newPrimitive.name = primitive.name; newPrimitives.Add(newPrimitive); index++; } // change the primitive to use the new array and indexes. // 1) - remove the old sources, vertices and primitives geo.mesh.sources.Clear(); geo.mesh.vertices.inputs.Clear(); geo.mesh.primitives.Clear(); // 2) - Add all the sources, only the POSITION will have the values geo.mesh.sources = newSources; geo.mesh.primitives = newPrimitives; geo.mesh.vertices = newVertices; } // foreach geometry }