Exemplo n.º 1
0
        private double _GetValue1D()
        {
            if (this._Keys.Count == 1)
            {
                return(this._GetPressed(0) ? 1 : 0);
            }
            else if (this._Keys.Count == 2)
            {
                return((this._GetPressed(0) ? -1 : 0) + (this._GetPressed(1) ? 1 : 0));
            }
            else if (this._InputType == 1)
            {
                double d;

                if (this._Vertical.HasValue)
                {
                    Vector v = this._GamePad.Inputs2D[this._Stick];
                    d = this._Vertical.Value ? v.Y : v.X;
                }
                else
                {
                    d = this._GamePad.Inputs1D[this._Trigger];
                }

                if (Meth.Abs(d) < this._Threshold)
                {
                    d = 0;
                }
                return(d);
            }
            else
            {
                throw new Exception("The specified input type doesn't support 1D values.");
            }
        }
Exemplo n.º 2
0
        public override void Update()
        {
            double v = Meth.Limit(0, LocalMousePosition.X / Size.X * Sections, Sections);

            if (this.MouseArea.IsClicked)
            {
                this._Value = v;
            }

            this.Progress += ((this.MouseArea.IsHovered && !this.MouseArea.IsClicked ? 1 : 0) - this.Progress) * 0.3;

            this.Text.Color   ^= (byte)((255 - this.Progress * 255) * (this.MouseArea.IsClicked ? 1 : 0));
            this.Text.Origin   = new Vector(this.Value, 1);
            this.Text.Position = new Vector(this.Value * this.Size.X, this.Size.Y - this.Value * this.Size.Y - 6 + this.Value * 3);
            this.Text.Content  = this.ValueDisplay(this.Value);

            for (int i = 0; i < Sections; i++)
            {
                Progresses[i] += ((this._Value > i ? 1 : 0) - Progresses[i]) * 0.4;
            }

            this.VertexArray.Vertices.Clear();
            this.VertexArray.Add(0);
            this.VertexArray.Add(new Vector(Size.X, 0));
            for (int i = 0; i < Sections; i++)
            {
                double d = Meth.Abs((v - i) / Sections * Size.X);
                double f = (d <= Size.X / 4) ? 1 - Meth.RSmooth(d / (Size.X / 4)) * 0.2 * this.Progress : 1;

                VertexArray.Add(new Vector((i + 0.5) / (double)Sections * Size.X, -1));
                VertexArray.Add(new Vector((i + 0.5) / (double)Sections * Size.X, (Progresses[i] + (i > this._Value ? 1 - f : 0)) * i / Sections * -(Size.Y - 2) * f - 3));
            }
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        internal void _Update()
        {
            if (this._Keys.Count == 1)
            {
                bool b = this._GetPressed(0);
                if (b != this._LastPressed)
                {
                    this._LastPressed = b;
                    if (b)
                    {
                        this._GotPressed  = true;
                        this._GotReleased = false;
                    }
                    else
                    {
                        this._GotReleased = true;
                        this._GotPressed  = false;
                    }
                }
                else
                {
                    this._GotPressed  = false;
                    this._GotReleased = false;
                }
            }

            if (this._Keys.Count == 4)
            {
                Vector v = this._GetValue2D();
                this._Value2D += (v - this._Value2D) * (1 - this._Fluidity);
                if ((this._Value2D - v).Length < 0.01)
                {
                    this._Value2D = v;
                }
            }
            else if (this._InputType != 2)
            {
                double d = this._GetValue1D();
                this._Value1D += (d - this._Value1D) * (1 - this._Fluidity);
                if (Meth.Abs(this._Value1D - d) < 0.01)
                {
                    this._Value1D = d;
                }
            }
        }
Exemplo n.º 5
0
        public static Color FromHsv(double _hue, double _saturation, double _value)
        {
            double c = _value * _saturation;
            double h = Meth.RMod(_hue, 1) * 6;
            double x = c * (1 - Meth.Abs(h % 2 - 1));

            double r = 0, g = 0, b = 0;

            if (0 <= h && h < 1)
            {
                r = c;
                g = x;
            }
            else if (1 <= h && h < 2)
            {
                r = x;
                g = c;
            }
            else if (2 <= h && h < 3)
            {
                g = c;
                b = x;
            }
            else if (3 <= h && h < 4)
            {
                g = x;
                b = c;
            }
            else if (4 <= h && h < 5)
            {
                b = c;
                r = x;
            }
            else if (5 <= h && h < 6)
            {
                b = x;
                r = c;
            }

            double m = _value - c;

            return(new Color((byte)((r + m) * 255), (byte)((g + m) * 255), (byte)((b + m) * 255)));
        }
Exemplo n.º 6
0
        public static double GetRadialDifference(Vector _one, Vector _two)
        {
            Bunch <double> diffs = new Bunch <double>()
            {
                _two.Angle - _one.Angle - Meth.Tau, _two.Angle - _one.Angle, _two.Angle - _one.Angle + Meth.Tau
            };
            double min = double.MaxValue;

            foreach (double diff in diffs)
            {
                if (Meth.Abs(diff) < Meth.Abs(min))
                {
                    min = diff;
                }
            }
            if (min == Meth.Tau / -2)
            {
                return(Meth.Tau / 2);
            }
            return(min);
        }
Exemplo n.º 7
0
        public static string CreateTempFile(byte[] _bytes, string _name = "", string _extension = "")
        {
            if (!File.Exists(GameBase.TempPath))
            {
                File.CreateFolder(GameBase.TempPath);
            }

            if (_extension != "")
            {
                _extension = "." + _extension;
            }

            string n    = _name;
            string path = GameBase.TempPath + _name + _extension;

            while (File.Exists(path) || n == "")
            {
                path = GameBase.TempPath + (n = _name + Meth.Abs(Meth.RandomInt).ToString()) + _extension;
            }

            File.Write(path, _bytes);
            return(path);
        }
Exemplo n.º 8
0
        public override void Update()
        {
            bool rebind = (this.Progress != 0 && this.Progress != 1);

            this.Progress += ((this.Opened ? 1 : 0) - this.Progress) / 3;
            if (Meth.Abs(this.Progress - (this.Opened ? 1 : 0)) < 0.01)
            {
                this.Progress = this.Opened ? 1 : 0;
            }

            this.Text.Position.Y   = BarHeight / 2 + this.InnerHeight * this.Progress - this.Text.Height / 2;
            this.Bar.Position.Y    = this.InnerHeight * this.Progress;
            this.Triangle.Position = new Vector(this.Width - this.BarHeight / 2, this.BarHeight / 2 + this.InnerHeight * this.Progress);

            this.ChildArea.Scale = new Vector(1, this.Progress);

            if (rebind)
            {
                this.BarArea.Shape = this.Bar;
            }

            this.Triangle.Scale = new Vector(1, (this.Progress * 2 - 1) * -1);
        }
Exemplo n.º 9
0
 public static double InfToOne(double _number)
 {
     return((1 - 1 / (Meth.Abs(_number) + 1)) * Meth.Sign(_number));
 }
Exemplo n.º 10
0
        public override void Update()
        {
            if (this.Scrolling && (this.LocalMousePosition - this.ScrollStart).Length >= 2)
            {
                this.Scrolling = false;
            }
            //if (this.Scrolling)
            //	Parent.CursorVisible = false;

            this.Index     += (this.TargetIndex - this.Index) / 5;
            this.Expansion += ((this.MouseArea.IsHovered ? 1 : 0) - this.Expansion) / 5;

            this.Quad.Rotation += ((this.TargetQuadRot * Meth.Tau / -4) - this.Quad.Rotation) / 5;
            if (Meth.Abs(this.Quad.Rotation - this.TargetQuadRot * Meth.Tau / -4) < 0.1)
            {
                this.Quad.Rotation = this.TargetQuadRot * Meth.Tau / -4;
            }

            this.Quad.Scale = new Vector(1, 2 / 3.0 + this.Expansion / 3.0);
            if (Meth.Abs(this.TargetQuadRot % 2) == 1)
            {
                this.Quad.Scale.Angle += Meth.Tau / 4;
            }

            if (this.LastHovered != this.MouseArea.IsHovered)
            {
                this.LastHovered = this.MouseArea.IsHovered;

                if (!this.MouseArea.IsHovered)
                {
                    this.MouseArea.Shape = new Rectangle(this.Labels[this.TargetIndex].Position, this.Labels[this.TargetIndex].Size);
                }
            }

            if (Meth.Abs(this.TargetIndex - this.Index) < 0.05)
            {
                this.Index = this.TargetIndex;
            }

            for (int i = 0; i < this.Labels.Count; i++)
            {
                byte a = (byte)(Meth.Pow(Meth.Limit(0, 3 - Meth.Abs(i - this.Index), 3) / 3.0 * ((i == this.TargetIndex) ? 1 : this.Expansion), 0.4) * 255);

                //if (a != 0 && !this.Labels[i].Visible)
                //{
                //	this.Labels[i].Visible = true;
                //	//this.Labels[i].Shader = Shader.TextOutline;
                //	//this.Labels[i].Shader["Color"] = Color.Red;

                //	//this.Labels[i].RenderIntermediately = true;
                //	//this.Labels[i].RenderGraphicsIntermediately = true;
                //	//this.Labels[i].IntermediateSize = this.Labels[i].Size;
                //	//this.Labels[i].IntermediateShader = Shader.TextOutline;
                //}

                //if (this.Labels[i].Visible)
                //{
                double dis = Meth.Limit(0, Meth.Abs(i - this.Index) - 2, 1);

                this.Labels[i].Color ^= (byte)(((i == this.TargetIndex) ? 255 : this.Expansion * 255) * (1 - dis));
                //this.Labels[i].Shader["Alpha"] = (a / 255.0);

                this.Labels[i].Z = a / 255.0 * this.Expansion;

                Vector p = this.GetPosition(i - this.Index);
                double r = p.Angle.ToHalfTau() / 4;
                this.Labels[i].Rotation = r;
                this.Labels[i].Position = p;
                //}
            }
        }
Exemplo n.º 11
0
        public override void Update()
        {
            double         y        = this.Spacing;
            Bunch <double> pos      = new Bunch <double>();
            Bunch <double> threshes = new Bunch <double>();
            Bunch <double> middles  = new Bunch <double>();

            foreach (T item in this.Items)
            {
                pos.Add(y);
                threshes.Add(y + item.GetHeight() + this.Spacing / 2);
                middles.Add(y + item.GetHeight() / 2);
                y += item.GetHeight() + this.Spacing;
            }

            double lheight = 0;

            if (this.Items.Count > 0)
            {
                middles.Add(y + this.Items.Last.GetHeight() / 2);

                T d = this.Items.First(item => item._BeingDragged);
                if (d != null)
                {
                    int    index = d._ListIndex;
                    double p     = d.Y + d.GetHeight() / 2;

                    if (p < threshes[0])
                    {
                        index = 0;
                    }
                    else if (p > threshes.Last)
                    {
                        index = threshes.Count - 1;
                    }
                    else
                    {
                        for (int i = 0; i < threshes.Count; i++)
                        {
                            if (p < threshes[i])
                            {
                                index = i;
                                break;
                            }
                        }
                    }

                    T[] items = this.Items.ToArray();

                    int dif = index - d._ListIndex;
                    if (dif > 0)
                    {
                        for (int i = d._ListIndex + 1; i <= index; i++)
                        {
                            items[i]._ListIndex--;
                        }
                    }
                    else if (dif < 0)
                    {
                        for (int i = index; i < d._ListIndex; i++)
                        {
                            items[i]._ListIndex++;
                        }
                    }

                    d._ListIndex = index;

                    if (dif != 0)
                    {
                        this.OnOrderChange();
                    }
                }

                foreach (T item in this.Items)
                {
                    if (!item._BeingDragged)
                    {
                        item.Y += (pos[item._ListIndex] - item.Y) / 2;
                        if (Meth.Abs(item.Y - pos[item._ListIndex]) < 1)
                        {
                            item.Y            = pos[item._ListIndex];
                            item._NeedsUpdate = false;
                        }
                    }
                    else
                    {
                        item.Y += item.LocalMousePosition.Y - item._DragStart.Y;
                    }

                    item.Y = Meth.Limit(0, item.Y, this.Height - item.GetHeight());
                    item.Z = item._BeingDragged ? 1 : 0;
                }

                lheight = this.Items.Last.GetHeight();
            }
            else
            {
                pos.Add(0);
                middles.Add(double.MaxValue);
            }

            if (this.LocalMousePosition.X >= 0 && this.LocalMousePosition.X < this.Width && this.LocalMousePosition.Y >= 0 && this.LocalMousePosition.Y < pos.Last + lheight + this.Spacing && !this.Items.Any(item => item._BeingDragged))
            {
                this._MousePos = threshes.IndexOf((this.Spacing / 2 + threshes).Last(t => t < middles.First(m => m > this.LocalMousePosition.Y))) + 1;
                Vector v = new Vector(this.Width / 2, (this.Spacing / 2 + threshes)[this._MousePos]);
                if (this.Plus.Position != v)
                {
                    this.Plus.Position  = v;
                    this.PlusArea.Shape = new Rectangle(this.Plus.Position - this.Spacing / 2, this.Spacing);
                }
                this.Plus.Visible = true;
            }
            else
            {
                this.Plus.Visible = false;
            }

            this.Plus.Color = this.PlusArea.IsHovered ? Color.White * 0.5 : Color.Black;
        }