public AnimationData(string name, List<FrameData> frames, PixelPoint animSize, PixelRect hitbox, LoopMode loopMode)
 {
     this.name = name;
     this.frames = frames;
     this.animSize = animSize;
     this.hitbox = hitbox;
     this.loopMode = loopMode;
 }
    public Box(int x, int y, Scene scene)
    {
        pixelPos = new PixelPoint(x, y);
        this.scene = scene;
        SetSprite("box");
        sprite.PlayAnimation("idle");
        tags.Add("box");

        layer = Globals.LAYER_BOX;
    }
 void ScanVertLineDown(int x, PixelPoint pixelInside, PixelPoint a, PixelPoint perp, int halfInterval) {
     var y = pixelInside.Y;
     var proj = perp*(pixelInside - a);
     Debug.Assert(Math.Abs(proj) <= halfInterval);
     do {
         Plot(x, y);
         proj -= perp.Y;
         if (proj < - halfInterval) break;
         y--;
     } while (y >= 0);
 }
    // returns true if was successfully pushed
    public bool Move(PixelPoint movement)
    {
        PixelPoint newPos = pixelPos + movement;
        if(IsInBounds(newPos) &&
           !Collide("box", newPos))
        {
            pixelPos = newPos;
            return true;
        }

        return false;
    }
 internal void DrawFatSegByX(PixelPoint a, PixelPoint b, int insertRectHalfSize) {
     var perp = new PixelPoint(-(b.Y - a.Y), b.X - a.X);
     if (perp.Y == 0) {
         FillRectangle(a.X, a.Y - insertRectHalfSize, b.X - a.X, 2*insertRectHalfSize);
         return;
     }
     if (perp.Y < 0) perp = -perp;
     var pixelInside = a;
     double perpLen = Math.Sqrt(perp*perp);
     // pixel p is inside if and only if (p-a)*perp belongs to the interval [-halfInterval, halfInterval]
     int halfInterval = (int) (perpLen*insertRectHalfSize);
     for (int x = a.X; x <= b.X; x++)
         ScanVertLine(x, ref pixelInside, a, b, perp, halfInterval);
 }
Exemple #6
0
        public static Mock <IWindowImpl> CreateWindowMock(Func <IPopupImpl> popupImpl = null)
        {
            var win  = Mock.Of <IWindowImpl>(x => x.Scaling == 1);
            var mock = Mock.Get(win);

            mock.Setup(x => x.CreatePopup()).Returns(() =>
            {
                if (popupImpl != null)
                {
                    return(popupImpl());
                }
                return(CreatePopupMock().Object);
            });
            PixelPoint pos = default;

            mock.SetupGet(x => x.Position).Returns(() => pos);
            mock.Setup(x => x.Move(It.IsAny <PixelPoint>())).Callback(new Action <PixelPoint>(np => pos = np));
            SetupToplevel(mock);
            return(mock);
        }
Exemple #7
0
        async void Loaded(object sender, EventArgs e)
        {
            Position = new PixelPoint(Position.X, Math.Max(0, Position.Y));

            if (Launchpad.CFWIncompatible == CFWIncompatibleState.Show)
            {
                Launchpad.CFWError(this);
            }

            if (Program.Args?.Length > 0)
            {
                ReadFile(Program.Args[0]);
            }

            Program.Args = null;

            UpdateBlogpost();
            UpdateRelease();

            if (IsVisible && !openDialog && await Github.ShouldUpdate())
            {
                Window[] windows = Application.Current.Windows.ToArray();

                foreach (Window window in windows)
                {
                    if (window.GetType() != typeof(MessageWindow))
                    {
                        window.Close();
                    }
                }

                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    Program.LaunchAdmin = true;
                }
                else
                {
                    UpdateWindow.Create(this);
                }
            }
        }
        void Loaded(object sender, EventArgs e)
        {
            Position = new PixelPoint(Position.X, Math.Max(0, Position.Y));

            Launchpad.DisplayWarnings(this);

            if (App.Args?.Length > 0)
            {
                ReadFile(App.Args[0]);
            }

            App.Args = null;

            UpdateBlogpost();
            UpdateRelease();

            if (!Program.HadCrashed)
            {
                CheckUpdate();
            }
        }
        private void InitializeComponent()
        {
            AvaloniaXamlLoader.Load(this);

            DockControl dock = this.FindControl <DockControl>("DockControl");

            SerializedDock?serializedDock = null;

            if (fileSystem.Exists(DockSettingsFile))
            {
                try
                {
                    serializedDock = JsonConvert.DeserializeObject <SerializedDock>(fileSystem.ReadAllText(DockSettingsFile));
                } catch {}
            }

            dock.Layout = avaloniaDockAdapter.Initialize(serializedDock);

            var lastSize = userSettings.Get <WindowLastSize>();

            if (lastSize.LastX.HasValue && lastSize.LastY.HasValue && lastSize.LastWidth.HasValue &&
                lastSize.LastHeight.HasValue)
            {
                var p      = new PixelPoint(lastSize.LastX.Value + 20, lastSize.LastY.Value + 20);
                var screen = Screens.ScreenFromPoint(p);
                if (screen != null)
                {
                    Position = new PixelPoint(lastSize.LastX.Value, lastSize.LastY.Value);
                    if (!(lastSize.WasMaximized ?? false))
                    {
                        var tl = this.PointToClient(new PixelPoint(lastSize.LastX.Value, lastSize.LastY.Value));
                        var br = this.PointToClient(new PixelPoint(lastSize.LastX.Value + lastSize.LastWidth.Value, lastSize.LastY.Value + lastSize.LastHeight.Value));
                        Width  = br.X - tl.X;
                        Height = br.Y - tl.Y;
                    }
                }
            }
            WindowState = (lastSize.WasMaximized ?? false) ? WindowState.Maximized : WindowState.Normal;
        }
Exemple #10
0
        /// <summary>
        /// Computes the minimum value of multiple images.
        /// </summary>
        /// <param name="Inputs">Input data.</param>
        /// <param name="Output">Output data.</param>
        /// <param name="InputPositions">Input alignments.</param>
        /// <param name="OutputPosition">Output alignment.</param>
        /// <param name="empty">Dummy argument.</param>
        static void MiniFilter(double[][,] Inputs, double[,] Output, SchedCore.ImageSegmentPosition[] InputPositions, SchedCore.ImageSegmentPosition OutputPosition, object empty)
        {
            PixelPoint[] InputAlignments = InputPositions.Select((x) => x.Alignment).ToArray();
            PixelPoint   OutputAlignment = OutputPosition.Alignment;

            IWCSProjection[] InputImagesTransforms = InputPositions.Select((x) => x.WCS).ToArray();
            IWCSProjection   OutputImageTransform  = OutputPosition.WCS;

            int        OW = Output.GetLength(1);
            int        OH = Output.GetLength(0);
            int        i, j, k;
            PixelPoint pxp = new PixelPoint();

            for (i = 0; i < OH; i++)
            {
                for (j = 0; j < OW; j++)
                {
                    double Min = double.MaxValue;
                    pxp.X = j + OutputAlignment.X; pxp.Y = i + OutputAlignment.Y;
                    EquatorialPoint eqp = OutputImageTransform.GetEquatorialPoint(pxp);
                    for (k = 0; k < Inputs.Length; k++)
                    {
                        PixelPoint pyp = InputImagesTransforms[k].GetPixelPoint(eqp);
                        pyp.X = Math.Round(pyp.X - InputAlignments[k].X); pyp.Y = Math.Round(pyp.Y - InputAlignments[k].Y);
                        if (pyp.X < 0 || pyp.X >= Inputs[k].GetLength(1))
                        {
                            continue;
                        }
                        if (pyp.Y < 0 || pyp.Y >= Inputs[k].GetLength(0))
                        {
                            continue;
                        }
                        double dex = Inputs[k][(int)pyp.Y, (int)pyp.X];
                        Min = dex < Min ? dex : Min;
                    }
                    Output[i, j] = Min;
                }
            }
        }
        //------------------------------------------------------------------------------
        List <PixelPoint> NeighboursForBrush(int brushSize, PixelPoint pixel)
        {
            List <PixelPoint> neighboursForThisBrsuh = new List <PixelPoint>();

            // Here we go through all positions within +-brush distance
            // from the x, y coordinates of the current pixel.
            for (int neighbourX = pixel.x - brushSize;
                 neighbourX < pixel.x + brushSize + 1; ++neighbourX)
            {
                for (int neighbourY = pixel.y - brushSize;
                     neighbourY < pixel.y + brushSize + 1; ++neighbourY)
                {
                    PixelPoint neighbourCandidate = new PixelPoint(neighbourX, neighbourY);

                    if (TestIfNeighbour(pixel, neighbourCandidate, brushSize))
                    {
                        neighboursForThisBrsuh.Add(neighbourCandidate);
                    }
                }
            }
            return(neighboursForThisBrsuh);
        }
        private void Window_Opened(object?sender, EventArgs e)
        {
            if (DataContext is TaskBarWindowViewModel vm)
            {
                //if (vm.SizePosition.X > 0 && vm.SizePosition.Y > 0)
                //{
                //    this.Position = new PixelPoint(vm.SizePosition.X, vm.SizePosition.Y - (int)this.Height);
                //}

                vm.WhenAnyValue(x => x.SizePosition.X, x => x.SizePosition.Y)
                .Subscribe(x =>
                {
                    var screen      = Screens.ScreenFromPoint(new PixelPoint(x.Item1, x.Item2));
                    var heightPoint = x.Item2 - (int)(Height * screen.PixelDensity);

                    if (heightPoint < 0)
                    {
                        Position = new PixelPoint(x.Item1, x.Item2);
                    }
                    else if ((x.Item1 + (int)Width + 30) > screen.WorkingArea.Width)
                    {
                        Position = new PixelPoint(x.Item1 - (int)(Width * screen.PixelDensity), heightPoint);
                    }
                    else
                    {
                        Position = new PixelPoint(x.Item1, heightPoint);
                    }
                });
            }

            if (OperatingSystem2.IsWindows)
            {
                //INativeWindowApiService.Instance!.SetActiveWindow(new() { Handle = PlatformImpl.Handle.Handle });
                Topmost = false;
                Topmost = true;
                IAvaloniaApplication.Instance.SetTopmostOneTime();
            }
        }
Exemple #13
0
        private void FluentWindow_Opened(object?sender, EventArgs e)
        {
            _isOpenWindow = true;
            if (this.DataContext is WindowViewModel vm)
            {
                if (vm.SizePosition.X > 0 && vm.SizePosition.Y > 0)
                {
                    var point = new PixelPoint(vm.SizePosition.X, vm.SizePosition.Y);
                    if (Screens.Primary.WorkingArea.Contains(point))
                    {
                        this.Position = point;
                    }
                }

                if (vm.SizePosition.Width > 0 &&
                    Screens.Primary.WorkingArea.Width >= vm.SizePosition.Width)
                {
                    this.Width = vm.SizePosition.Width;
                }

                if (vm.SizePosition.Height > 0 &&
                    Screens.Primary.WorkingArea.Height >= vm.SizePosition.Height)
                {
                    this.Height = vm.SizePosition.Height;
                }

                HandleResized(new Size(this.Width, this.Height));

                this.GetObservable(WidthProperty).Subscribe(v =>
                {
                    vm.SizePosition.Width = v;
                });
                this.GetObservable(HeightProperty).Subscribe(v =>
                {
                    vm.SizePosition.Height = v;
                });
            }
        }
Exemple #14
0
        /// <summary>
        /// Masks the input image with a given mask. Masked pixels are set to -1 standard deviation.
        /// </summary>
        /// <param name="Input">Input image data.</param>
        /// <param name="Output">Output image data.</param>
        /// <param name="InputPosition">Input data position.</param>
        /// <param name="OutputPosition">Output data position.</param>
        /// <param name="Properties">Mask data.</param>
        static void MaskImage(double[,] Input, double[,] Output, ImageSegmentPosition InputPosition, ImageSegmentPosition OutputPosition, MaskProperties Properties)
        {
            int Width = Output.GetLength(1);
            int Height = Output.GetLength(0);
            int i, j;

            PixelPoint pxp = new PixelPoint();

            for (i = 0; i < Height; i++)
            {
                for (j = 0; j < Width; j++)
                {
                    pxp.X = j + OutputPosition.Alignment.X; pxp.Y = i + OutputPosition.Alignment.Y;
                    EquatorialPoint ep  = OutputPosition.WCS.GetEquatorialPoint(pxp);
                    PixelPoint      mpt = Properties.MaskTransform.GetPixelPoint(ep);
                    mpt.X = Math.Round(mpt.X); mpt.Y = Math.Round(mpt.Y);
                    if (mpt.X < 0 || mpt.X >= Properties.MaskData[0].Length)
                    {
                        continue;
                    }
                    if (mpt.Y < 0 || mpt.Y >= Properties.MaskData.Length)
                    {
                        continue;
                    }
                    PixelPoint ipt = InputPosition.WCS.GetPixelPoint(ep);
                    ipt.X = Math.Round(ipt.X - InputPosition.Alignment.X); ipt.Y = Math.Round(ipt.Y - InputPosition.Alignment.Y);

                    if (Properties.MaskData[(int)mpt.Y][(int)mpt.X])
                    {
                        Output[i, j] = -Properties.StDev;
                    }
                    else
                    {
                        Output[i, j] = Input[(int)ipt.Y, (int)ipt.X] - Properties.Mean;
                    }
                }
            }
        }
Exemple #15
0
        /// <summary>Creates the property.</summary>
        public SkyBotImageData(Image Image) : base(Image)
        {
            PixelPoint CPP = new PixelPoint()
            {
                X = Image.Width / 2, Y = Image.Height / 2
            };
            PixelPoint Corner1 = new PixelPoint()
            {
                X = 0, Y = 0
            };
            PixelPoint Corner2 = new PixelPoint()
            {
                X = Image.Width, Y = Image.Height
            };

            ImageCenter = Image.Transform.GetEquatorialPoint(CPP);
            Radius      = Image.Transform.GetEquatorialPoint(Corner1) ^ Image.Transform.GetEquatorialPoint(Corner2);
            Radius     *= 0.55;

            ShotTime        = Image.GetProperty <ObservationTime>().Time;
            Exposure        = Image.GetProperty <ObservationTime>().Exposure;
            AssociatedImage = Image;
        }
        internal void DrawFatSegByX(PixelPoint a, PixelPoint b, int insertRectHalfSize)
        {
            var perp = new PixelPoint(-(b.Y - a.Y), b.X - a.X);

            if (perp.Y == 0)
            {
                FillRectangle(a.X, a.Y - insertRectHalfSize, b.X - a.X, 2 * insertRectHalfSize);
                return;
            }
            if (perp.Y < 0)
            {
                perp = -perp;
            }
            var    pixelInside = a;
            double perpLen     = Math.Sqrt(perp * perp);
            // pixel p is inside if and only if (p-a)*perp belongs to the interval [-halfInterval, halfInterval]
            int halfInterval = (int)(perpLen * insertRectHalfSize);

            for (int x = a.X; x <= b.X; x++)
            {
                ScanVertLine(x, ref pixelInside, a, b, perp, halfInterval);
            }
        }
        public static bool TryParse(string?s, out WindowRestoreState result)
        {
            result = Undefined;

            if (string.IsNullOrEmpty(s))
            {
                return(false);
            }
            if (string.Equals(s, nameof(Undefined), StringComparison.OrdinalIgnoreCase))
            {
                return(true);
            }

            var parts = s.Split(';');

            if (parts.Length != 4)
            {
                return(false);
            }

            int[] bounds = new int[4];
            for (int i = 0; i < bounds.Length; i++)
            {
                if (!int.TryParse(parts[i], out int val))
                {
                    return(false);
                }

                bounds[i] = val;
            }

            var pos  = new PixelPoint(bounds[0], bounds[1]);
            var size = new Size(bounds[2], bounds[3]);

            result = new WindowRestoreState(pos, size);
            return(true);
        }
Exemple #18
0
        /// <summary>
        /// Attempts to recover a detection on an image.
        /// </summary>
        /// <returns>The recovered object.</returns>
        /// <param name="Location">Location which to check.</param>
        /// <param name="Radius">Maximum radius of the detection.</param>
        /// <param name="RecoveryImage">Image on which to perform the recovery.</param>
        private DotDetector.DotDetection Recover(PixelPoint Location, double Radius, Image RecoveryImage)
        {
            /* Area in the image to retrieve */
            System.Drawing.Rectangle r = new System.Drawing.Rectangle((int)Math.Round(Location.X) - HalfLength, (int)Math.Round(Location.Y) - HalfLength,
                                                                      2 * HalfLength, 2 * HalfLength);

            bool[,] Mask = new bool[2 * HalfLength, 2 * HalfLength];
            /* Mask areas outside Radius */
            for (int i = 0; i < 2 * HalfLength; i++)
            {
                for (int j = 0; j < 2 * HalfLength; j++)
                {
                    if (!InDisk(i, j, Radius))
                    {
                        Mask[i, j] = true;
                    }
                }
            }

            ImageData dt = RecoveryImage.LockData(r, true);

            /* Compute background level of the area */
            var sts = RecoveryImage.GetProperty <ImageStatistics>();

            ComputeSmartStats(dt.Data, 10 * sts.StDev, out double Median, out double MedSigma);

            /* Perform recovery */
            DotDetector.IntPoint Position = new DotDetector.IntPoint()
            {
                X = HalfLength, Y = HalfLength
            };
            var det = DotDetector.BitmapFill(dt.Data, Position, Mask, ThresholdMultiplier * MedSigma, r.X, r.Y);

            RecoveryImage.ExitLock(dt);

            return(det);
        }
Exemple #19
0
        /// <summary>
        /// handels movement on dragging
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPointerMoved(PointerEventArgs e)
        {
            base.OnPointerMoved(e);

            if (!this.IsDragging)
            {
                return;
            }

            if (oldDragScreenPoint.HasValue)
            {
                Point currentDragPoint = e.GetPosition(this);
                // Get client point and convert it to screen point
                PixelPoint currentDragScreenPoint = this.PointToScreen(currentDragPoint);
                if (currentDragScreenPoint != this.oldDragScreenPoint)
                {
                    this.oldDragScreenPoint = currentDragScreenPoint;
                    e.Handled = true;
                    var horizontalChange = currentDragPoint.X - this.startDragPoint.X;
                    var verticalChange   = currentDragPoint.Y - this.startDragPoint.Y;

                    var ev = new VectorEventArgs
                    {
                        RoutedEvent = DragDeltaEvent,
                        Vector      = new Vector(horizontalChange, verticalChange)
                    };

                    this.RaiseEvent(ev);
                }
            }
            else
            {
                this.ClearValue(IsDraggingProperty);
                this.startDragPoint = new Point(0, 0);
            }
        }
        internal void DrawFatSegByY(PixelPoint a, PixelPoint b, int halfDistInPixels)
        {
            Debug.Assert(a.Y <= b.Y);
            var perp = new PixelPoint(-b.Y + a.Y, b.X - a.X);

            if (perp.X == 0)
            {
                FillRectangle(a.X - halfDistInPixels, a.Y, 2 * halfDistInPixels, b.Y - a.Y);
                return;
            }
            if (perp.X < 0)
            {
                perp = -perp;
            }
            var    pixelInside = a;
            double perpLen     = Math.Sqrt(perp * perp);
            // pixel p is inside if and only if (p-a)*perp belongs to the interval [-halfInterval, halfInterval]
            int halfInterval = (int)(perpLen * halfDistInPixels);

            for (int y = a.Y; y <= b.Y; y++)
            {
                ScanHorizontalLine(y, ref pixelInside, a, b, perp, halfInterval);
            }
        }
        /// <summary>${mapping_HeatMapLayer_method_GetImageSource_D}</summary>
        protected override void GetImageSource(DynamicLayer.OnImageSourceCompleted onCompleted)
        {
            if (!IsInitialized)
            {
                onCompleted(null);
            }
            else
            {
                if (worker != null && worker.IsBusy)
                {
                    worker.CancelAsync();
                    while (worker.IsBusy)
                    {
                        Thread.Sleep(10);
                    }
                }
            }
            List<ThreadSafeGradientStop> stops = new List<ThreadSafeGradientStop>();
            foreach (GradientStop item in GradientStops)
            {
                stops.Add(new ThreadSafeGradientStop { Color = item.Color, Offset = item.Offset });
            }
            //stops.Sort((ThreadSafeGradientStop g1, ThreadSafeGradientStop g2) => { return g1.Offset.CompareTo(g2.Offset); });

            stops.Sort((Comparison<ThreadSafeGradientStop>)((g1, g2) => g1.Offset.CompareTo(g2.Offset)));

            List<PixelPoint> pps = new List<PixelPoint>(this.GradientStops.Count);

            foreach (HeatPoint point in this.heatPoints)
            {
                if (ViewBounds.Contains(new Point2D(point.X, point.Y)) && point.Value > 0)
                {

                    PixelPoint pp = new PixelPoint
                    {
                        X = (int)Math.Round((point.X - ViewBounds.Left) / Resolution * Intensity),
                        Y = (int)Math.Round((ViewBounds.Top - point.Y) / Resolution * Intensity),
                        Value = (int)Math.Round(point.Value),
                        //判断给定的地理半径是否小于0,小于0则设置成0
                        GeoRadius = point.GeoRadius < 0 ? 0 : point.GeoRadius,
                    };
                    pps.Add(pp);
                }
            }

            //在视图范围内的转换为像素空间坐标
            //for (int i = 0; i < heatPoints.Count; i++)
            //{
            //    if (ViewBounds.Contains(new Point2D(heatPoints[i].X, heatPoints[i].Y)) && heatPoints[i].Value > 0)
            //    {
            //        PixelPoint point = new PixelPoint
            //        {
            //            X = (int)Math.Round((heatPoints[i].X - ViewBounds.Left) / Resolution * Intensity),
            //            Y = (int)Math.Round((ViewBounds.Top - heatPoints[i].Y) / Resolution * Intensity),
            //            Value = (int)Math.Round(heatPoints[i].Value)
            //        };
            //        pps.Add(point);
            //        //按照权重多加value遍;
            //        ////int sum = (int)Math.Round(heatPoints[i].Value);
            //        ////for (int k = 0; k < sum; k++)
            //        ////{
            //        ////    hps.Add(point);
            //        ////}
            //    }
            //}

            int width = (int)Math.Round(ViewSize.Width);
            int height = (int)Math.Round(ViewSize.Height);
            //调用 RunWorkerAsync 方法时将引发DoWork事件。这里就是您启动耗时操作的地方
            worker.RunWorkerAsync(new object[] { pps, width, height, Radius, Intensity, stops, onCompleted, this.Map.Resolution });
        }
Exemple #22
0
 void Loaded(object sender, EventArgs e) => Position = new PixelPoint(Position.X, Math.Max(0, Position.Y));
Exemple #23
0
 public Screen ScreenFromPoint(PixelPoint point)
 {
     return(All.FirstOrDefault(x => x.Bounds.Contains(point)));
 }
 public virtual PixelPoint PointToScreen(Point point) => PixelPoint.FromPoint(point, 1);
 bool GetFreePixelInRadius(ref PixelPoint source, int rad) {
     for (int x = source.X - rad; x <= source.X + rad; x++) {
         PixelPoint p1 = new PixelPoint(x, source.Y - rad);
         if (IsFree(p1)) {
             source = p1;
             return true;
         }
         PixelPoint p2 = new PixelPoint(x, source.Y + rad);
         if (rad != 0 && IsFree(p2)) {
             source = p2;
             return true;
         }
     }
     for (int y = source.Y - rad + 1; y < source.Y + rad; y++) {
         PixelPoint p1 = new PixelPoint(source.X - rad, y);
         if (IsFree(p1)) {
             source = p1;
             return true;
         }
         PixelPoint p2 = new PixelPoint(source.X + rad, y);
         if (IsFree(p2)) {
             source = p2;
             return true;
         }
     }
     return false;
 }
Exemple #26
0
 /// <inheritdoc/>
 Point IRenderRoot.PointToClient(PixelPoint p)
 {
     return(PlatformImpl?.PointToClient(p) ?? default);
 }
Exemple #27
0
 public Point PointToClient(PixelPoint p) => throw new NotImplementedException();
    AnimationData ParseAnimationString(string animString)
    {
        Stack<ParseAnimState> animStates = new Stack<ParseAnimState>();
        string currentString = "";

        // ANIMATION DATA
        string name = "";
        List<FrameData> frames = new List<FrameData>();
        LoopMode loopMode = LoopMode.Loops;

        // CURRENT FRAME DATA
        Color32 currentColor = new Color32(0, 0, 0, 0);
        List<PixelData> currentPixels = new List<PixelData>();
        List<PixelData> previousFramePixels = new List<PixelData>();
        PixelPoint animSize = new PixelPoint(0, 0);
        PixelRect hitbox = new PixelRect(0, 0, 0, 0);
        float currentAnimTime = 0.0f;
        int currentPixelYPos = 0;

        bool differencesMode = false;

        foreach(char c in animString)
        {
            if(animStates.Count > 0 && animStates.Peek() == ParseAnimState.DifferencesMode)
            {
                if(c == '^')
                    differencesMode = true;
                else
                    differencesMode = false;

                animStates.Pop();
                animStates.Push(ParseAnimState.Frame);
            }
            else
            {
                if(c == '*')
                {
                    if(animStates.Count > 0 && animStates.Peek() == ParseAnimState.Name)
                    {
                        name = currentString;
                        currentString = "";
                        animStates.Pop();
                    }
                    else
                    {
                        animStates.Push(ParseAnimState.Name);
                        currentString = "";
                    }
                }
                else if(c == '!')
                {
                    if(animStates.Count > 0 && animStates.Peek() == ParseAnimState.Size)
                    {
                        // parse current string for animation rect and save it
                        string[] vals = currentString.Split(',');
                        if(vals.Length == 2)
                        {
                            int xSize = 0;
                            int ySize = 0;
                            if(!(int.TryParse(vals[0], out xSize) && int.TryParse(vals[1], out ySize)))
                            {
                                ShowConsoleText(currentString + " is not properly formatted anim size data!");
                                return null;
                            }
                            animSize = new PixelPoint(xSize, ySize);
                        }
                        else
                        {
                            ShowConsoleText(currentString + " is not properly formatted anim size data!");
                            return null;
                        }

                        currentString = "";
                        animStates.Pop();
                    }
                    else
                    {
                        animStates.Push(ParseAnimState.Size);
                    }
                }
                else if(c == '<')
                {
                    animStates.Push(ParseAnimState.Hitbox);
                }
                else if(c == '>')
                {
                    if(animStates.Count > 0 && animStates.Peek() == ParseAnimState.Hitbox)
                    {
                        // parse current string for hitbox info and save it
                        string[] vals = currentString.Split(',');
                        if(vals.Length == 4)
                        {
                            int left = 0;
                            int bottom = 0;
                            int width = 0;
                            int height = 0;

                            if(!(int.TryParse(vals[0], out left) &&
                                 int.TryParse(vals[1], out bottom) &&
                                 int.TryParse(vals[2], out width) &&
                                 int.TryParse(vals[3], out height)))
                            {
                                ShowConsoleText(currentString + " is not properly formatted hitbox data!");
                                return null;
                            }

                            hitbox = new PixelRect(left, bottom, width, height);
                        }
                        else
                        {
                            ShowConsoleText(currentString + " is not properly formatted hitbox data!");
                            return null;
                        }

                        currentString = "";
                        animStates.Pop();
                    }
                }
                else if(c == '{')
                {
                    animStates.Push(ParseAnimState.DifferencesMode);
                }
                else if(c == '}')
                {
                    if(differencesMode)
                    {
                        // currentPixels holds pixels that are DIFFERENT than the previous frame
                        List<PixelData> pixels = new List<PixelData>();
                        foreach(PixelData prevPixelData in previousFramePixels)
                        {
                            // only add the previous frame pixels that AREN'T being overriden by the new frame data
                            bool allowPixel = true;
                            foreach(PixelData pixel in currentPixels)
                            {
                                if(pixel.position == prevPixelData.position)
                                {
                                    allowPixel = false;
                                    break;
                                }
                            }

                            if(allowPixel)
                                pixels.Add(new PixelData(prevPixelData.position, prevPixelData.color));
                        }

                        // add in the new, different pixels
                        foreach(PixelData newPixel in currentPixels)
                        {
                            pixels.Add(newPixel);
                        }

                        currentPixels.Clear();

                        frames.Add(new FrameData(pixels, currentAnimTime));

                        previousFramePixels.Clear();
                        previousFramePixels.AddRange(pixels);
                    }
                    else
                    {
                        // save current frame data
                        List<PixelData> pixels = new List<PixelData>();
                        pixels.AddRange(currentPixels);
                        currentPixels.Clear();

                        frames.Add(new FrameData(pixels, currentAnimTime));

                        previousFramePixels.Clear();
                        previousFramePixels.AddRange(pixels);
                    }

                    if(animStates.Count > 0 && animStates.Peek() == ParseAnimState.Frame)
                        animStates.Pop();
                }
                else if(c == '[')
                {
                    animStates.Push(ParseAnimState.PixelColor);
                }
                else if(c == ']')
                {
                    if(animStates.Count > 0 && animStates.Peek() == ParseAnimState.PixelColor)
                    {
                        // parse current string for pixel color
                        if(currentString.Length == 0)
                        {
                            currentColor = new Color32(0, 0, 0, 0);
                        }
                        else
                        {
                            string[] vals = currentString.Split(',');
                            if(vals.Length == 1)
                            {
                                byte grey = 0;
                                if(!byte.TryParse(vals[0], out grey))
                                {
                                    ShowConsoleText(currentString + " is not properly formatted color data!");
                                    return null;
                                }
                                currentColor = new Color32(grey, grey, grey, 255);
                            }
                            else if(vals.Length == 2)
                            {
                                byte grey = 0;
                                byte opacity = 0;
                                if(!(byte.TryParse(vals[0], out grey) && byte.TryParse(vals[1], out opacity)))
                                {
                                    ShowConsoleText(currentString + " is not properly formatted color data!");
                                    return null;
                                }

                                currentColor = new Color32(grey, grey, grey, opacity);
                            }
                            else if(vals.Length == 3)
                            {
                                byte red = 0;
                                byte green = 0;
                                byte blue = 0;
                                if(!(byte.TryParse(vals[0], out red) && byte.TryParse(vals[1], out green) && byte.TryParse(vals[2], out blue)))
                                {
                                    ShowConsoleText(currentString + " is not properly formatted color data!");
                                    return null;
                                }

                                currentColor = new Color32(red, green, blue, 255);
                            }
                            else if(vals.Length == 4)
                            {
                                byte red = 0;
                                byte green = 0;
                                byte blue = 0;
                                byte opacity = 0;
                                if(!(byte.TryParse(vals[0], out red) && byte.TryParse(vals[1], out green) && byte.TryParse(vals[2], out blue) && byte.TryParse(vals[3], out opacity)))
                                {
                                    ShowConsoleText(currentString + " is not properly formatted color data!");
                                    return null;
                                }

                                currentColor = new Color32(red, green, blue, opacity);
                            }
                            else
                            {
                                ShowConsoleText(currentString + " is not properly formatted color data!");
                            }
                        }

                        currentString = "";
                        animStates.Pop();
                    }
                }
                else if(c == '(')
                {
                    animStates.Push(ParseAnimState.PixelYPos);
                }
                else if(c == '-')
                {
                    if(animStates.Count > 0 && animStates.Peek() == ParseAnimState.PixelYPos)
                    {
                        if(!int.TryParse(currentString, out currentPixelYPos))
                        {
                            ShowConsoleText(currentString + " is not a properly formatted y-position!");
                            return null;
                        }

                        currentString = "";
                        animStates.Pop();

                        animStates.Push(ParseAnimState.PixelXPos);
                    }
                }
                else if(c == ')')
                {
                    if(animStates.Count > 0 && animStates.Peek() == ParseAnimState.PixelXPos)
                    {
                        // parse current string for x pixel positions (for the current pixel y pos)
                        // add a pixel of current color to a list
                        string[] vals = currentString.Split(',');
                        for(int i = 0; i < vals.Length; i++)
                        {
                            int xPos = 0;
                            if(!int.TryParse(vals[i], out xPos))
                            {
                                ShowConsoleText(currentString + " is not a properly formatted x-position!");
                                return null;
                            }

                            currentPixels.Add(new PixelData(new PixelPoint(xPos, currentPixelYPos), currentColor));
                        }

                        animStates.Pop();
                    }
                    currentString = "";
                }
                else if(c == '#')
                {
                    if(animStates.Count > 0 && animStates.Peek() == ParseAnimState.AnimTime)
                    {
                        // parse current string for animation time and save it
                        if(!float.TryParse(currentString, out currentAnimTime))
                        {
                            ShowConsoleText(currentString + " is not a properly formatted frame time!");
                            return null;
                        }

                        currentString = "";
                        animStates.Pop();
                    }
                    else
                    {
                        animStates.Push(ParseAnimState.AnimTime);
                    }
                }
                else if(c == '&')
                {
                    if(animStates.Count > 0 && animStates.Peek() == ParseAnimState.Loops)
                    {
                        // parse current string for loop mode and save it
                        int loopModeInt = 0;
                        if(!int.TryParse(currentString, out loopModeInt))
                        {
                            ShowConsoleText(currentString + " is not a properly formatted loop mode!");
                            return null;
                        }

                        loopMode = (LoopMode)loopModeInt;

                        currentString = "";
                        animStates.Pop();
                    }
                    else
                    {
                        animStates.Push(ParseAnimState.Loops);
                    }
                }
                else
                {
                    currentString += c;
                }
            }
        }

        AnimationData animData = new AnimationData(name, frames, animSize, hitbox, loopMode);
        return animData;
    }
 public PixelData(PixelPoint position, Color32 color)
 {
     this.position = position;
     this.color = color;
 }
 void ScanVertLine(int x, ref PixelPoint pixelInside, PixelPoint a, PixelPoint b, PixelPoint perp,
     int halfInterval) {
     ScanVertLineUp(x, pixelInside, a, perp, halfInterval);
     ScanVertLineDown(x, pixelInside, a, perp, halfInterval);
     UpdatePixelInsideForXCase(ref pixelInside, a, b, perp, halfInterval, Math.Sign(b.Y - a.Y));
 }
    public void UpdateCanvas()
    {
        // -------------------------------------------------
        // MOUSE INPUT
        // -------------------------------------------------
        bool leftMouse = Input.GetMouseButton(0);
        bool rightMouse = Input.GetMouseButton(1);
        bool leftMouseDown = Input.GetMouseButtonDown(0);
        bool leftMouseUp = Input.GetMouseButtonUp(0);
        bool rightMouseDown = Input.GetMouseButtonDown(1);
        bool rightMouseUp = Input.GetMouseButtonUp(1);

        bool zoomedThisFrame = false;

        // -------------------------------------------------
        // MOUSE INPUT
        // -------------------------------------------------
        RaycastHit ray = new RaycastHit();
        if(Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out ray))
        {
            Texture2D textureMap = (Texture2D)ray.transform.renderer.material.mainTexture;
            Vector2 pixelUV = ray.textureCoord;
            pixelUV.x *= textureMap.width;
            pixelUV.y *= textureMap.height;

            int x = (int)pixelUV.x;
            int y = (int)pixelUV.y;

            _editor.GridIndexString = "(" + x.ToString() + "," + y.ToString() + ")";

            // -------------------------------------------------------------------------
            // CANVAS PLANE
            // -------------------------------------------------------------------------
            if(ray.transform.gameObject == _canvasPlane)
            {
                int index = y * pixelWidth + x;
                bool pixelExists = _pixels[_editor.CurrentFrame][index].a > 0;

                if(leftMouse && !_editor.GetIsDragging())
                {
                    if(_editor.GetToolMode() == ToolMode.Brush)
                    {
                        Color32 indexColor = _pixels[_editor.CurrentFrame][index];
                        if(!indexColor.Equals(_editor.GetCurrentColor()) || indexColor.a != 255)
                        {
                            if(_editor.GetModifierKey())
                            {
                                DrawLine(_lastDrawnPoint.x, _lastDrawnPoint.y, x, y);
                                if(_mirroringMode == MirroringMode.Horizontal || _mirroringMode == MirroringMode.Both)
                                    DrawLine(pixelWidth - 1 - _lastDrawnPoint.x, _lastDrawnPoint.y, pixelWidth - 1 - x, y);
                                if(_mirroringMode == MirroringMode.Vertical || _mirroringMode == MirroringMode.Both)
                                    DrawLine(_lastDrawnPoint.x, pixelHeight - 1 - _lastDrawnPoint.y, x, pixelHeight - 1 - y);
                                if(_mirroringMode == MirroringMode.Both)
                                    DrawLine(pixelWidth - 1 - _lastDrawnPoint.x, pixelHeight - 1 - _lastDrawnPoint.y, pixelWidth - 1 - x, pixelHeight - 1 - y);
                            }
                            else
                            {
                                ToolDrawPixel(x, y);
                                if(_mirroringMode == MirroringMode.Horizontal || _mirroringMode == MirroringMode.Both)
                                    ToolDrawPixel(pixelWidth - 1 - x, y);
                                if(_mirroringMode == MirroringMode.Vertical || _mirroringMode == MirroringMode.Both)
                                    ToolDrawPixel(x, pixelHeight - 1 - y);
                                if(_mirroringMode == MirroringMode.Both)
                                    ToolDrawPixel(pixelWidth - 1 - x, pixelHeight - 1 - y);
                            }

                            _lastDrawnPoint = new PixelPoint(x, y);
                        }
                    }
                    else if(_editor.GetToolMode() == ToolMode.Eraser)
                    {
                        ToolErasePixel(x, y);
                        if(_mirroringMode == MirroringMode.Horizontal || _mirroringMode == MirroringMode.Both)
                            ToolErasePixel(pixelWidth - 1 - x, y);
                        if(_mirroringMode == MirroringMode.Vertical || _mirroringMode == MirroringMode.Both)
                            ToolErasePixel(x, pixelHeight - 1 - y);
                        if(_mirroringMode == MirroringMode.Both)
                            ToolErasePixel(pixelWidth - 1 - x, pixelHeight - 1 - y);
                    }
                    else if(_editor.GetToolMode() == ToolMode.Bucket)
                    {
                        Color32 indexColor = _pixels[_editor.CurrentFrame][index];
                        if(!indexColor.Equals(_editor.GetCurrentColor()) || indexColor.a != 255)
                        {
                            if(!_pixelsDrawnThisStroke.Contains(index))
                            {
                                _editor.AddNewCommand(new FloodFillCommand(x, y, _editor.GetCurrentColor()));
                                _pixelsDrawnThisStroke.Add(index);
                            }
                        }
                    }
                    else if(_editor.GetToolMode() == ToolMode.Dropper)
                    {
                        Color32 indexColor = _pixels[_editor.CurrentFrame][index];
                        if(!indexColor.Equals(_editor.GetCurrentColor()))
                        {
                            if(pixelExists)
                                _editor.SetCurrentColor(_canvasTexture.GetPixel(x, y));
                        }
                    }
                }
                else if(leftMouseUp && _editor.GetToolMode() == ToolMode.Dropper && !_editor.GetIsDragging())
                {
                    Color32 indexColor = _pixels[_editor.CurrentFrame][index];
                    if(pixelExists)
                    {
                        _editor.SetCurrentColor(_canvasTexture.GetPixel(x, y));
                        _editor.SetToolMode(ToolMode.Brush);
                    }
                    else
                    {
                        _editor.SetToolMode(ToolMode.Eraser);
                    }
                }
                else if(_editor.GetModifierKey() && rightMouseDown && pixelExists)
                {
                    _editor.GetPalette().AddColorToFirstEmptySpot(_canvasTexture.GetPixel(x, y));
                }
                else if(rightMouse)
                {
                    _editor.SetToolMode(ToolMode.Dropper);

                    // check to see if there is any color at this pixel
                    // if so, eyedropper it
                    if(pixelExists)
                        _editor.SetCurrentColor(_canvasTexture.GetPixel(x, y));
                }
                else if(rightMouseUp)
                {
                    if(pixelExists)
                        _editor.SetToolMode(ToolMode.Brush);
                    else
                        _editor.SetToolMode(ToolMode.Eraser);
                }

                ZoomCanvasPlane();
                zoomedThisFrame = true;
            }
            // -------------------------------------------------------------------------
            // CANVAS BORDER PLANE
            // -------------------------------------------------------------------------
            else if(ray.transform.gameObject == _canvasBorderPlane)
            {
                if(leftMouseDown && !_editor.GetIsDragging() && !CurrentlyEditingPixels)
                {
                    _draggingCanvasBorder = true;

                    Vector2 mouseWorldPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                    _borderDragWorldOffset = (Vector2)_canvasBorderPlane.transform.position - mouseWorldPos;
                }

                ZoomCanvasPlane();
                zoomedThisFrame = true;
            }
        }

        // -------------------------------------------------------------------------
        // ZOOMING
        // -------------------------------------------------------------------------
        if(!zoomedThisFrame && _zoomTimer > 0.0f)
            ZoomCanvasPlane();

        if(_draggingCanvasBorder)
        {
            if(Input.GetMouseButtonUp(0))
            {
                _draggingCanvasBorder = false;
                PlayerPrefs.SetFloat("canvasPosX", _canvasPlane.transform.position.x);
                PlayerPrefs.SetFloat("canvasPosY", _canvasPlane.transform.position.y);
            }
            else
            {
                Vector2 mouseWorldPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                _canvasPlane.transform.position = new Vector3(mouseWorldPos.x + _borderDragWorldOffset.x, mouseWorldPos.y + _borderDragWorldOffset.y, PixelEditorScreen.CANVAS_PLANE_DEPTH);
            }
        }

        // -------------------------------------------------------------------------
        // CURRENTLY EDITING STUFF
        // -------------------------------------------------------------------------
        if(Input.GetMouseButtonUp(0))
        {
            if(_isCurrentlyEditingPixels)
            {
                _isCurrentlyEditingPixels = false;

                _editor.AddNewCommand(new EditPixelsCommand(_currentlyReplacedPixels, _currentlyAddedPixels));
                _currentlyReplacedPixels.Clear();
                _currentlyAddedPixels.Clear();
            }
        }

        if(_pixelsDrawnThisStroke.Count > 0 && leftMouseUp)
            _pixelsDrawnThisStroke.Clear();

        // -------------------------------------------------
        // CLEARING FRAME
        // -------------------------------------------------
        if(!_editor.GetModifierKey() && (Input.GetKeyDown(KeyCode.Backspace) || Input.GetKeyDown(KeyCode.Q)) && !_editor.GetIsEditingPixels() && _editor.GetTextEnteringMode() == TextEnteringMode.None)
        {
            _editor.AddNewCommand(new ClearCurrentFrameCommand());
        }

        // -------------------------------------------------
        // SHIFTING PIXELS
        // -------------------------------------------------
        if(!_editor.GetModifierKey() && !_editor.GetIsEditingPixels() && _editor.GetTextEnteringMode() == TextEnteringMode.None)
        {
            if(Input.GetKeyDown(KeyCode.UpArrow))
                _editor.AddNewCommand(new ShiftCanvasCommand(Direction.Up));
            else if(Input.GetKeyDown(KeyCode.DownArrow))
                _editor.AddNewCommand(new ShiftCanvasCommand(Direction.Down));
            else if(Input.GetKeyDown(KeyCode.RightArrow))
                _editor.AddNewCommand(new ShiftCanvasCommand(Direction.Right));
            else if(Input.GetKeyDown(KeyCode.LeftArrow))
                _editor.AddNewCommand(new ShiftCanvasCommand(Direction.Left));
        }

        // -------------------------------------------------
        // FLIPPING CANVAS
        // -------------------------------------------------
        if(_editor.GetModifierKey() && !_editor.GetIsEditingPixels() && _editor.GetTextEnteringMode() == TextEnteringMode.None)
        {
            if(Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.DownArrow))
                _editor.AddNewCommand(new FlipCanvasCommand(false));
            else if(Input.GetKeyDown(KeyCode.LeftArrow) || Input.GetKeyDown(KeyCode.RightArrow))
                _editor.AddNewCommand(new FlipCanvasCommand(true));
        }

        // -------------------------------------------------
        // ONION SKIN
        // -------------------------------------------------
        if(!_editor.GetModifierKey() && Input.GetKeyDown(KeyCode.O) && !_editor.GetIsEditingPixels() && _editor.GetTextEnteringMode() == TextEnteringMode.None)
            ToggleOnionSkinMode();

        if(!_editor.GetIsEditingPixels() && _editor.GetTextEnteringMode() == TextEnteringMode.None)
        {
            if(Input.GetKeyDown(KeyCode.Minus))
                AdjustOnionSkinOpacity(false);
            else if(Input.GetKeyDown(KeyCode.Equals))
                AdjustOnionSkinOpacity(true);
        }

        // -------------------------------------------------
        // MIRRORING
        // -------------------------------------------------
        if(!_editor.GetModifierKey() && Input.GetKeyDown(KeyCode.M) && !_editor.GetIsEditingPixels() && _editor.GetTextEnteringMode() == TextEnteringMode.None)
            ToggleMirroringMode();
    }
        internal bool FindClosestFreePixel(Point p, out PixelPoint found) {
            var pPixel = PointToPixel(p);

            for (int r = 0; r < MaxSize/2; r++) {
                if (!GetFreePixelInRadius(ref pPixel, r)) continue;
                found = pPixel;
                return true;
            }

            found = new PixelPoint();
            return false;
        }
 internal Point GetWorldCoord(PixelPoint p) {
     return _mapToWorld*new Point(p.X, p.Y);
 }
 bool IsFree(PixelPoint p) {
     return _bitmap.GetPixelValue(p.X, p.Y) == 0;
 }
 public PixelPoint PointToScreen(Point p) => PixelPoint.FromPoint(p, 1);
    string GetFrameData(int frameNumber)
    {
        Color32[] currentFramePixels = _canvas.GetPixels(frameNumber);

        // figure out if we should use 'differences from last frame' mode or not
        bool differencesMode = false;
        if(frameNumber > 0)
        {
            Color32[] lastFramePixels = _canvas.GetPixels(frameNumber - 1);

            int numSamePixels = 0;
            for(int x = 0; x < _canvas.pixelWidth; x++)
            {
                for(int y = 0; y < _canvas.pixelHeight; y++)
                {
                    int index = y * _canvas.pixelWidth + x;
                    if(currentFramePixels[index].a > 0 && currentFramePixels[index].Equals(lastFramePixels[index]))
                        numSamePixels++;
                }
            }

            int numTotalPixels = _canvas.pixelWidth * _canvas.pixelHeight;
            if(numSamePixels > (int)(numTotalPixels / 2))
                differencesMode = true;
        }

        // START FRAME
        string str = "{";

        if(differencesMode)
            str += "^";
        else
            str += "-";

        // COLOR AND PIXELS
        Dictionary<Color32, List<PixelPoint>> pixels = new Dictionary<Color32, List<PixelPoint>>();
        for(int x = 0; x < _canvas.pixelWidth; x++)
        {
            for(int y = 0; y < _canvas.pixelHeight; y++)
            {
                int index = y * _canvas.pixelWidth + x;

                if(differencesMode)
                {
                    Color32[] lastFramePixels = _canvas.GetPixels(frameNumber - 1);

                    if(!currentFramePixels[index].Equals(lastFramePixels[index]))
                    {
                        Color32 color = currentFramePixels[index];
                        PixelPoint pixelPoint = new PixelPoint(x, y);

                        if(pixels.ContainsKey(color))
                            pixels[color].Add(pixelPoint);
                        else
                            pixels[color] = new List<PixelPoint>() { pixelPoint };
                    }
                }
                else
                {
                    if(_canvas.GetPixelExists(frameNumber, index))
                    {
                        Color32 color = currentFramePixels[index];
                        PixelPoint pixelPoint = new PixelPoint(x, y);

                        if(pixels.ContainsKey(color))
                            pixels[color].Add(pixelPoint);
                        else
                            pixels[color] = new List<PixelPoint>() { pixelPoint };
                    }
                }
            }
        }

        foreach(KeyValuePair<Color32, List<PixelPoint>> pair in pixels)
        {
            List<PixelPoint> pixelPoints = pair.Value;
            if(pixelPoints.Count > 0)
            {
                Dictionary<int, List<int>> coordinates = new Dictionary<int, List<int>>(); // y-value is the key, and has list of x-values (for that y) for the value
                foreach(PixelPoint point in pixelPoints)
                {
                    if(coordinates.ContainsKey(point.y))
                        coordinates[point.y].Add(point.x);
                    else
                    coordinates[point.y] = new List<int>() { point.x };
                }

                Color32 col = pair.Key;
                if(col.a == 0) // a blank pixel
                {
                    str += "[]";
                }
                else if(col.r == col.g && col.r == col.b) // a shade of grey
                {
                    if(col.a == 255)
                        str += "[" + col.r.ToString() + "]"; // solid grey
                    else
                        str += "[" + col.r.ToString() + "," + col.a.ToString() + "]";
                }
                else if(col.a == 255) // a solid color
                {
                    str += "[" + col.r.ToString() + "," + col.g.ToString() + "," + col.b.ToString() + "]";
                }
                else // a transparent color
                {
                    str += "[" + col.r.ToString() + "," + col.g.ToString() + "," + col.b.ToString() + "," + col.a.ToString() + "]";
                }

                foreach(KeyValuePair<int, List<int>> coordPair in coordinates)
                {
                    int yPos = coordPair.Key;
                    List<int> xPositions = coordPair.Value;

                    str += "(" + yPos.ToString() + "-";

                    bool first = true;
                    foreach(int xPos in xPositions)
                    {
                        if(first)
                            first = false;
                        else
                            str += ",";

                        str += xPos.ToString();
                    }

                    str += ")";
                }
            }
        }

        // FRAME TIME
        str += "#" + _framePreview.GetFrameTime(frameNumber).ToString() + "#";
        // END FRAME
        str += "}";

        return str;
    }
Exemple #37
0
 /// <summary>
 /// Create a cursor from png/svg and hotspot position
 /// </summary>
 public CssCursor(string url, PixelPoint hotSpot, StandardCursorType fallback)
 {
     Value = $"url('{url}') {hotSpot.X} {hotSpot.Y}, {ToKeyword(fallback)}";
 }
 internal void DrawFatSeg(PixelPoint a, PixelPoint b, int insertRectHalfSizeInPixels) {
     double dx = b.X - a.X;
     double dy = b.Y - a.Y;
     FillRectangle(a.X - insertRectHalfSizeInPixels, a.Y - insertRectHalfSizeInPixels,
         2*insertRectHalfSizeInPixels,
         2*insertRectHalfSizeInPixels);
     FillRectangle(b.X - insertRectHalfSizeInPixels, b.Y - insertRectHalfSizeInPixels,
         2*insertRectHalfSizeInPixels,
         2*insertRectHalfSizeInPixels);
     if (Math.Abs(dx) > Math.Abs(dy)) {
         if (dx > 0)
             DrawFatSegByX(a, b, insertRectHalfSizeInPixels);
         else
             DrawFatSegByX(b, a, insertRectHalfSizeInPixels);
     }
     else {
         if (dy > 0)
             DrawFatSegByY(a, b, insertRectHalfSizeInPixels);
         else
             DrawFatSegByY(b, a, insertRectHalfSizeInPixels);
     }
 }
        void ScanVertLineUp(int x, PixelPoint pixelInside, PixelPoint a, PixelPoint perp, int halfInterval) {
            Debug.Assert(perp.Y > 0);
            var y = pixelInside.Y;
            var proj = perp*(pixelInside - a);
            Debug.Assert(Math.Abs(proj) <= halfInterval);
            do {
                Plot(x, y);
                proj += perp.Y;
                if (proj > halfInterval) break;
                y++;
            } while (y < _height);

        }
 public void DrawLine(PixelPoint a, PixelPoint b, Color color)
 {
     DrawLine(a.x, a.y, b.x, b.y, color);
 }
 public virtual Point PointToClient(PixelPoint point) => point.ToPoint(1);
    public void ShiftPixels(PixelPoint offset)
    {
        offset = new PixelPoint(-offset.x, -offset.y);
        Color32[] tempPixels = new Color32[pixelWidth * pixelHeight];

        _pixels.CopyTo(tempPixels, 0);

        for(int x = 0; x < pixelWidth; x++)
        {
            for(int y = 0; y < pixelHeight; y++)
            {
                int currentIndex = y * pixelWidth + x;

                int newY = y + offset.y;
                while(newY > pixelHeight - 1)
                    newY -= pixelHeight;
                while(newY < 0)
                    newY += pixelHeight;

                int newX = x + offset.x;
                while(newX > pixelWidth - 1)
                    newX -= pixelWidth;
                while(newX < 0)
                    newX += pixelWidth;

                int copyIndex = newY * pixelWidth + newX;

                _pixels[currentIndex] = tempPixels[copyIndex];
                if(_pixels[currentIndex].a == 0)
                    _pixels[currentIndex] = new Color32(0, 0, 0, 0);
            }
        }
    }
 public void AddPixel(PixelPoint point, Color newColor)
 {
     AddPixel(point.x, point.y, newColor);
 }
    public override void UpdateEntity(float deltaTime)
    {
        base.UpdateEntity(deltaTime);

        int newPixelX = pixelX;
        int newPixelY = pixelY;

        if(Input.GetKeyDown(KeyCode.LeftArrow) ||
           Input.GetKey(KeyCode.LeftArrow) && _keyRepeatTimer <= 0.0f)
        {
            newPixelX = pixelX - 1;
        }
        else if(Input.GetKeyDown(KeyCode.RightArrow) ||
                Input.GetKey(KeyCode.RightArrow) && _keyRepeatTimer <= 0.0f)
        {
            newPixelX = pixelX + 1;
        }

        if(Input.GetKeyDown(KeyCode.UpArrow) ||
           Input.GetKey(KeyCode.UpArrow) && _keyRepeatTimer <= 0.0f)
        {
            newPixelY = pixelY + 1;
        }
        else if(Input.GetKeyDown(KeyCode.DownArrow) ||
                Input.GetKey(KeyCode.DownArrow) && _keyRepeatTimer <= 0.0f)
        {
            newPixelY = pixelY - 1;
        }

        // X-MOVEMENT
        if(newPixelX != pixelX && IsInBounds(newPixelX, pixelY))
        {
            bool valid = true;

            List<Entity> entities = CollideWithAll("box", newPixelX, pixelY);
            foreach(Entity entity in entities)
            {
                if(entity != null)
                {
                    Box box = (Box)entity;
                    PixelPoint movement = new PixelPoint(newPixelX - pixelX, 0);
                    if(!box.Move(movement))
                    {
                        valid = false;
                        break;
                    }
                }
            }

            if(valid)
                pixelX = newPixelX;

            _keyRepeatTimer = KEY_REPEAT_DELAY;
        }

        // Y-MOVEMENT
        if(newPixelY != pixelY && IsInBounds(pixelX, newPixelY))
        {
            bool valid = true;

            List<Entity> entities = CollideWithAll("box", pixelX, newPixelY);
            foreach(Entity entity in entities)
            {
                if(entity != null)
                {
                    Box box = (Box)entity;
                    PixelPoint movement = new PixelPoint(0, newPixelY - pixelY);
                    if(!box.Move(movement))
                    {
                        valid = false;
                        break;
                    }
                }
            }

            if(valid)
                pixelY = newPixelY;

            _keyRepeatTimer = KEY_REPEAT_DELAY;
        }

        if(_keyRepeatTimer > 0.0f)
            _keyRepeatTimer -= deltaTime;
    }
 public void SetPixel(PixelPoint point, Color color)
 {
     SetPixel(point.x, point.y, color);
 }
        void ScanHorizontalLineLeft(int y, PixelPoint pixelInside, PixelPoint a, PixelPoint perp, int halfInterval) {
            Debug.Assert(perp.X > 0);
            var x = pixelInside.X;
            var proj = perp*(pixelInside - a);
            Debug.Assert(Math.Abs(proj) <= halfInterval);
            do {
                Plot(x, y);
                proj -= perp.X;
                if (proj < - halfInterval) break;
                x--;
            } while (x >= 0);

        }
Exemple #47
0
 private void MoveResize(PixelPoint position, Size size, double scaling)
 {
     Move(position);
     Resize(size);
     //TODO: We ignore the scaling override for now
 }
 void ScanHorizontalLineRight(int y, PixelPoint pixelInside, PixelPoint a, PixelPoint perp, int halfInterval) {
     Debug.Assert(perp.X > 0);
     var x = pixelInside.X;
     var proj = perp*(pixelInside - a);
     Debug.Assert(Math.Abs(proj) <= halfInterval);
     do {
         Plot(x, y);
         proj += perp.X;
         if (proj > halfInterval) break;
         x++;
     } while (x < _width);
 }
 private void Window_PositionChanged(object?sender, PixelPointEventArgs e)
 {
     prevprevPosition = previousPosition;
     previousPosition = currentPosition;
     currentPosition  = e.Point;
 }
 public static int Distance(PixelPoint a, PixelPoint b)
 {
     return Mathf.Abs(b.x - a.x) + Mathf.Abs(b.y - a.y);
 }
Exemple #51
0
 /// <summary>
 /// Handles a window position change notification from
 /// <see cref="IWindowBaseImpl.PositionChanged"/>.
 /// </summary>
 /// <param name="pos">The window position.</param>
 private void HandlePositionChanged(PixelPoint pos)
 {
     PositionChanged?.Invoke(this, new PixelPointEventArgs(pos));
 }
        void UpdatePixelInsideForYCase(ref PixelPoint pixelInside, PixelPoint a, PixelPoint b, PixelPoint perp,
            int halfInterval, int sign) {
            if (pixelInside.Y == b.Y) return;
            pixelInside.Y++;
            int proj = perp*(pixelInside - a);
            if (Math.Abs(proj) <= halfInterval) return;
            pixelInside.X += sign;
            proj += sign*perp.X;
            if (Math.Abs(proj) <= halfInterval) return;

            pixelInside.X -= 2*sign;
            proj -= 2*sign*perp.X;
            Debug.Assert(Math.Abs(proj) <= halfInterval);
        }
 public Point PointToClient(PixelPoint p) => p.ToPoint(1);
 public bool Contains(PixelPoint point)
 {
     return point.x >= left && point.x < (left + width) && point.y >= bottom && point.y < (bottom + height);
 }
Exemple #55
0
 /// <summary>
 /// Create a cursor from base64 image
 /// </summary>
 public CssCursor(string base64, string format, PixelPoint hotspot, StandardCursorType fallback)
 {
     Value = $"url(\"data:image/{format};base64,{base64}\") {hotspot.X} {hotspot.Y}, {ToKeyword(fallback)}";
 }
        void ScanHorizontalLine(int x, ref PixelPoint pixelInside, PixelPoint a, PixelPoint b, PixelPoint perp,
            int halfInterval) {
            ScanHorizontalLineRight(x, pixelInside, a, perp, halfInterval);
            ScanHorizontalLineLeft(x, pixelInside, a, perp, halfInterval);
            UpdatePixelInsideForYCase(ref pixelInside, a, b, perp, halfInterval, Math.Sign(b.Y - a.Y));

        }
Exemple #57
0
 public EquatorialPoint GetEquatorialPoint(PixelPoint Point)
 {
     return(ProjectionTransform.GetEquatorialPoint(LinearTransform.GetProjectionPoint(Point)));
 }
 internal void DrawFatSegByY(PixelPoint a, PixelPoint b, int halfDistInPixels) {
     Debug.Assert(a.Y <= b.Y);
     var perp = new PixelPoint(-b.Y + a.Y, b.X - a.X);
     if (perp.X == 0) {
         FillRectangle(a.X - halfDistInPixels, a.Y, 2*halfDistInPixels, b.Y - a.Y);
         return;
     }
     if (perp.X < 0) perp = -perp;
     var pixelInside = a;
     double perpLen = Math.Sqrt(perp*perp);
     // pixel p is inside if and only if (p-a)*perp belongs to the interval [-halfInterval, halfInterval]
     int halfInterval = (int) (perpLen*halfDistInPixels);
     for (int y = a.Y; y <= b.Y; y++)
         ScanHorizontalLine(y, ref pixelInside, a, b, perp, halfInterval);
 }
Exemple #59
0
 Point ITopLevelImpl.PointToClient(PixelPoint point) => PointFromScreen(point.ToWpfPoint()).ToAvaloniaPoint();
 protected bool IsInBounds(PixelPoint point)
 {
     return scene.IsInBounds(this, point.x, point.y);
 }