public static Bunch <Point> Trace(Point _start, Point _end) { Bunch <Point> @out = new Bunch <Point>(); Point dif = _end - _start; if (dif.X != 0 || dif.Y != 0) { if (Meth.Abs(dif.X) > Meth.Abs(dif.Y)) { for (int x = 0; x <= Meth.Abs(dif.X); x++) { int nx = _start.X + x * Meth.Sign(dif.X); int ny = Meth.Round(_start.Y + dif.Y * (x * Math.Sign(dif.X) / (float)dif.X)); @out.Add(new Point(nx, ny)); } } else { for (int y = 0; y <= Meth.Abs(dif.Y); y++) { int nx = Meth.Round(_start.X + dif.X * (y * Meth.Sign(dif.Y) / (float)dif.Y)); int ny = _start.Y + y * Meth.Sign(dif.Y); @out.Add(new Point(nx, ny)); } } } else { @out.Add(_start); } return(@out); }
public override void Update() { if (this.CurrentSource != null) { if (Meth.Sign(this.TimePassed - 1) != Meth.Sign(this.SpeedModifier)) { this._Stopped = false; } if (!this._Stopped) { this.TimePassed += this.SpeedModifier; if (this.TimePassed > this.CurrentSource.Speed * this.CurrentSource.Sprites.Count || (this.SpeedModifier < 0 && this.TimePassed <= 0)) { if (this.CurrentSource.Repeated) { if (this.SpeedModifier > 0) { if (this._StopSmooth) { this._StopSmooth = false; this._Stopped = true; this.TimePassed = this.CurrentSource.Speed * this.CurrentSource.Sprites.Count; } else { this.TimePassed %= (this.CurrentSource.Speed * this.CurrentSource.Sprites.Count); } } else { if (this._StopSmooth) { this._StopSmooth = false; this._Stopped = true; this.TimePassed = 0; } else { this.TimePassed = (this.TimePassed + (this.CurrentSource.Speed * this.CurrentSource.Sprites.Count)) % (this.CurrentSource.Speed * this.CurrentSource.Sprites.Count); } } } else { this.TimePassed = (this.SpeedModifier > 0) ? this.CurrentSource.Speed * this.CurrentSource.Sprites.Count : 0; this._Stopped = true; this._StopSmooth = false; } } this.CurFrame = Meth.Min(Meth.Down(this.TimePassed / this.CurrentSource.Speed), this.CurrentSource.Sprites.LastIndex); } } }
public static double InfToOne(double _number) { return((1 - 1 / (Meth.Abs(_number) + 1)) * Meth.Sign(_number)); }
public void Zoom(double _factor, Vector _position) { Vector os = this.Editor.TileEditor.Scale; Vector s = os * _factor; if (s.X < 0.125) { s = 0.125; } if (s.X > 32) { s = 32; } this.Editor.TileEditor.Scale = s; this.Editor.TileEditor.Position = this.Editor.TabListLeft.TotalSize.OnlyX + (this.Editor.TileEditor.Position - this.Editor.TabListLeft.TotalSize.OnlyX) * (s / os); this.Editor.TileEditor.Position += this.Editor.EditorSize * ((os.X < s.X) ? (os / s) : (s / os) / 2) * Meth.Sign(os.X - s.X); }
public ScriptBox(Script _script) : base(_script.ToString()) { this.TabAllowed = true; this.MultiLine = true; this.TextColor = new Color(220); this.SelectColor = new Color(220); this.Background.Color = new Color(30); this.ColorTheme = new ColorTheme ( new ColorPattern("String", ColorString, true, true, "\"", "\""), new ColorPattern("Char", ColorString, true, true, "\'", "\'"), new ColorPattern("Comment", ColorComment, true, true, "#", "#"), new ColorPattern("Script", ColorScript, true, true, "@\"", "\""), new ColorPattern("NoScopeOperator", ColorNoScopeOperator, Helper.NoScopeOperatorSymbols), new ColorPattern("ScopeOperator", ColorScopeOperator, Helper.ScopeOperatorSymbols), new ColorPattern("OneLineScopeOperator", ColorOneLineScopeOperator, Helper.OneLineScopeOperators), new ColorPattern("ObjectOperator", ColorObjectOperator, Helper.ObjectOperators), new ColorPattern("FlowOperator", ColorFlowOperator, Helper.FlowOperators), new ColorPattern("Number", ColorNumber, text => { int @out = 0; for (int i = 0; i < text.Length; i++) { if (Ext.IsDouble(text.Substring(0, i + 1)) || (i + 1 < text.Length && Ext.IsDouble(text.Substring(0, i)) && Ext.IsDouble(text.Substring(0, i + 2)))) { @out++; } else { return(@out); } } return(@out); }), new ColorPattern("Variable", new Color(220), text => { string alpha = "abcdefghijklmnopqrstuvwxyz_"; if (!alpha.Contains(text[0].ToString().ToLower()[0])) { return(0); } else { alpha += "0123456789"; int @out = 1; for (int i = 1; i < text.Length; i++) { if (alpha.Contains(text[i].ToString().ToLower()[0])) { @out++; } else { return(@out); } } return(@out); } }) ); this.SelectPatterns.Add(new TextSelectPattern.Keywords(Helper.Symbols)); this.AfterInput = input => { if (input == "\n") { int l = this.GetCharPos(this.CursorPosition).Y - 1; string line = this.Lines[l]; int tabs = Helper.GetNextIndents(line); for (int i = 0; i < tabs; i++) { this.EnterText("\t"); } } }; this.BeforeInput = input => { if (input == "\t") { bool shift = this.Parent.IsKeyPressed(Key.LShift); if (shift || (!shift && this.GetSelectedLines().Length > 1)) { int[] sl = this.GetSelectedLines(); string tx = ""; int tabs = 0; bool firsttab = !shift; for (int i = 0; i < sl[0]; i++) { tx += this.Lines[i] + "\n"; } foreach (int i in this.GetSelectedLines()) { string line = this.Lines[i]; if (shift) { if (line.StartsWith("\t")) { tx += line.Substring(1) + "\n"; tabs--; if (i == this.GetCharPos(this.GetLeft()).Y) { firsttab = true; } } else { tx += (line.StartsWith("\t") ? line.Substring(1) : line) + "\n"; } } else { tx += "\t" + line + "\n"; tabs++; } } for (int i = sl[sl.Length - 1] + 1; i < this.Lines.Length; i++) { tx += this.Lines[i] + "\n"; } int c = this.CursorPosition; tx = tx.Substring(0, tx.Length - 1); this.Content = tx; if (tabs != 0) { if (this.SelectionLength > 0) { if (firsttab) { this.CursorPosition = c + Meth.Sign(tabs); } this.SelectionLength += tabs - (firsttab ? Meth.Sign(tabs) : 0); } else if (this.SelectionLength < 0) { this.CursorPosition = c + tabs; this.SelectionLength -= tabs - (firsttab ? Meth.Sign(tabs) : 0); } else { this.CursorPosition = c - 1; } } return(false); } } return(true); }; this.BeforeBackspace = () => { if (this.SelectionLength > 0 || this.CursorPosition == 0) { return(true); } else { Point p = this.GetCharPos(this.CursorPosition); if (p.Y > 0) { int x = p.X; string l = this.Lines[this.CurrentLine]; string st = l.Substring(0, x); if (!st.Any(item => item != '\t')) { int tabs = st.Count(item => item == '\t'); int c = this.CursorPosition; this.Content = this.Content.Substring(0, this.CursorPosition - tabs - 1) + this.Content.Substring(this.CursorPosition); this.CursorPosition = c - tabs - 1; return(false); } else { return(true); } } else { return(true); } } }; //this.OnDefocus = this._TryParse; }