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;
 }
예제 #2
0
        private new void NewWindowOnOpened(object?sender, EventArgs e)
        {
            Screens    screens = new Window().Screens;
            PixelRect  pr      = screens.Primary.Bounds;
            PixelPoint pp      = new PixelPoint(pr.BottomRight.X / 5, pr.BottomRight.Y / 5);

            Position = pp;
        }
 public static Mock<IScreenImpl> CreateScreenMock()
 {
     var screenImpl = new Mock<IScreenImpl>();
     var bounds = new PixelRect(0, 0, (int)s_screenSize.Width, (int)s_screenSize.Height);
     var screen = new Screen(96, bounds, bounds, true);
     screenImpl.Setup(x => x.AllScreens).Returns(new[] { screen });
     screenImpl.Setup(x => x.ScreenCount).Returns(1);
     return screenImpl;
 }
예제 #4
0
 private static int GetYForNotification(IPlatform platform, PixelRect outer, Rect inner)
 {
     switch (platform)
     {
     //case WindowsPlatform _:
     //    return outer.Height - inner.Height;
     default:
         return(0);
     }
 }
예제 #5
0
 private void DrawRect(PixelRect pr, Color color)
 {
     for (int i = pr.x; i < pr.xx; i++)
     {
         for (int j = pr.y; j < pr.yy; j++)
         {
             m_texture.SetPixel(i, j, color);
         }
     }
 }
예제 #6
0
        private PixelRect ConvertUVRectToPixelRect(Rect atlasRect)
        {
            PixelRect pixelRect = new PixelRect();

            pixelRect.x  = GetPixelCoorFromAtlasRatio(atlasRect.x);
            pixelRect.y  = GetPixelCoorFromAtlasRatio(atlasRect.y);
            pixelRect.xx = GetPixelCoorFromAtlasRatio(atlasRect.x + atlasRect.width);
            pixelRect.yy = GetPixelCoorFromAtlasRatio(atlasRect.y + atlasRect.height);
            return(pixelRect);
        }
예제 #7
0
    public override bool Equals(object other)
    {
        if (!(other is PixelRect))
        {
            return(false);
        }
        PixelRect rect = (PixelRect)other;

        return(this.left.Equals(rect.left) && this.bottom.Equals(rect.bottom) && this.width.Equals(rect.width) && this.height.Equals(rect.height));
    }
예제 #8
0
 private static int GetXForNotification(IPlatform platform, PixelRect outer, Rect inner)
 {
     switch (platform)
     {
     //case WindowsPlatform _:
     //    return outer.Width - inner.Width;
     default:
         return(outer.Width - (int)inner.Width);
     }
 }
예제 #9
0
 void UpdateHitbox()
 {
     if (_alignment == TextDisplayAlignment.LeftToRight)
     {
         hitbox = new PixelRect(0, 0, ((_letterWidth * _text.Length) + (_spacing * _text.Length - 1)) * _scale, _letterHeight * _scale);
     }
     else
     {
         hitbox = new PixelRect(0, 0, _letterWidth * _scale, (((_letterHeight + _spacing) * _text.Length) - 1) * _scale);
     }
 }
예제 #10
0
 public static void RenderPlottables(SKSurface surface, PixelRect dataRect, Plot plot)
 {
     foreach (var plottable in plot.Plottables.Where(x => x.IsVisible))
     {
         plottable.Axes.DataRect = dataRect;
         surface.Canvas.Save();
         surface.Canvas.ClipRect(dataRect.ToSKRect());
         plottable.Render(surface);
         surface.Canvas.Restore();
     }
 }
예제 #11
0
        public ScreenImpl()
        {
            var game = AvaloniaLocator.Current.GetService <IGame>();

            ScreenCount = 1;
            var size = new PixelRect(0, 0, game.GraphicsDevice.Presenter.BackBuffer.Width, game.GraphicsDevice.Presenter.BackBuffer.Height);

            screens = new List <Screen>
            {
                new Screen(96, size, size, true)
            };
        }
    public bool IsInScreenBounds(PixelRect rect)
    {
        if ((rect.xMin < PixelScreen.shared.cameraPos.x) ||
            (rect.xMax > PixelScreen.shared.cameraPos.x + PixelScreen.shared.GetScreenWidth() - 1) ||
            (rect.yMin < PixelScreen.shared.cameraPos.y) ||
            (rect.yMax > PixelScreen.shared.cameraPos.y + PixelScreen.shared.GetScreenHeight() - 1))
        {
            return(false);
        }

        return(true);
    }
예제 #13
0
    public bool IsInBounds(Entity entity, int x, int y)
    {
        PixelRect hitbox = entity.GetOffsetHitbox(x, y);

        if (hitbox.xMax >= PixelScreen.shared.GetScreenWidth() ||
            hitbox.xMin < 0 ||
            hitbox.yMax >= PixelScreen.shared.GetScreenHeight() ||
            hitbox.yMin < 0)
        {
            return(false);
        }

        return(true);
    }
    // takes into account the camera position
    public bool IsInScreenBounds(int x, int y)
    {
        PixelRect rect = GetOffsetHitbox(x, y);

        if ((rect.xMin < PixelScreen.shared.cameraPos.x) ||
            (rect.xMax > PixelScreen.shared.cameraPos.x + PixelScreen.shared.GetScreenWidth() - 1) ||
            (rect.yMin < PixelScreen.shared.cameraPos.y) ||
            (rect.yMax > PixelScreen.shared.cameraPos.y + PixelScreen.shared.GetScreenHeight() - 1))
        {
            return(false);
        }

        return(true);
    }
    public void DrawHitboxes()
    {
        if (Globals.shared.DEBUG_HITBOXES)
        {
            PixelRect hitbox = offsetHitbox;

            for (int y = hitbox.bottom; y < hitbox.bottom + hitbox.height; y++)
            {
                for (int x = hitbox.left; x < hitbox.left + hitbox.width; x++)
                {
                    PixelScreen.shared.AddPixel(x, y, Globals.shared.DebugHitboxColor);
                }
            }
        }
    }
    public Entity Collide(Entity entity, string tag, PixelRect rect)
    {
        foreach(Entity other in _entities)
        {
            if(!other.tags.Contains(tag) || !other.collideable || other == entity)
                continue;

            if(rect.Overlaps(other.offsetHitbox))
            {
                return other;
            }
        }

        return null;
    }
예제 #17
0
    public static void RenderAxes(SKSurface surface, PixelRect dataRect, Plot plot)
    {
        // draw frame around data area
        using SKPaint paint = new()
              {
                  IsAntialias = true,
                  StrokeWidth = 1,
                  Style       = SKPaintStyle.Stroke,
              };
        paint.Color = SKColors.Black;
        surface.Canvas.DrawRect(dataRect.ToSKRect(), paint);

        // draw each axis view
        plot.XAxis.Render(surface, dataRect);
        plot.YAxis.Render(surface, dataRect);
    }
예제 #18
0
        protected void NewWindowOnOpened(object?sender, EventArgs e)
        {
            Screens    screens = new Window().Screens;
            PixelRect  pr      = screens.Primary.Bounds;
            PixelPoint pp      = new PixelPoint(pr.BottomRight.X / 5, pr.BottomRight.Y / 5);

            Position = pp;

            RectangleBoundWindow = this.FindControl <Rectangle>("RectangleBound");
            GridMain             = this.FindControl <Grid>("GridMain");

            ColumnDefinition column2 = GridMain.ColumnDefinitions[0];

            column2.MaxWidth = 500;
            column2.MinWidth = 200;
        }
예제 #19
0
    private void RenderGridLines(SKSurface surface, PixelRect dataRect, IAxis axis)
    {
        // TODO: restrict to visible ticks and max 1000?
        Tick[]  ticks  = axis.TickGenerator.Ticks;
        Pixel[] starts = new Pixel[ticks.Length];
        Pixel[] ends   = new Pixel[ticks.Length];

        for (int i = 0; i < ticks.Length; i++)
        {
            float px = axis.GetPixel(ticks[i].Position, dataRect);
            starts[i] = axis.Edge.IsHorizontal() ? new Pixel(px, dataRect.Bottom) : new Pixel(dataRect.Left, px);
            ends[i]   = axis.Edge.IsHorizontal() ? new Pixel(px, dataRect.Top) : new Pixel(dataRect.Right, px);
        }

        Drawing.DrawLines(surface, starts, ends, LineColor, LineWidth);
    }
예제 #20
0
        private new void NewWindowOnOpened(object?sender, EventArgs e)
        {
            Screens    screens = new Window().Screens;
            PixelRect  pr      = screens.Primary.Bounds;
            PixelPoint pp      = new PixelPoint(pr.BottomRight.X / 5, pr.BottomRight.Y / 5);

            Position = pp;

            GridMain   = this.FindControl <Grid>("GridMain");
            LBSolution = this.FindControl <ListBox>("LBSolution");

            ColumnDefinition column2 = GridMain.ColumnDefinitions[0];

            column2.MaxWidth = 600;
            column2.MinWidth = 200;

            InvalidChars = new char[] { '"', '/', '\\', '<', '>', '?', '*', '|', ':' };

            SolutionNameLength = 70;

            CollectionLBSolution = new List <string>();
            TBSolutionName       = new TextBox();

            LMessage = new Label();

            Border border = new Border();

            border.Background = Brushes.Red;
            border.Child      = LMessage;

            PopupMessage = new Popup();
            PopupMessage.IsLightDismissEnabled = true;
            PopupMessage.PlacementAnchor       = PopupAnchor.Bottom;
            PopupMessage.PlacementTarget       = TBSolutionName;
            PopupMessage.Child = border;

            GridMain.Children.Add(PopupMessage);

            CollectionLBSolution.Add("Empty solution");

            Binding bLBSolution = new Binding();

            bLBSolution.Source = CollectionLBSolution;

            LBSolution.Bind(ListBox.ItemsProperty, bLBSolution);
            LBSolution.SelectedIndex = 0;
        }
예제 #21
0
        public unsafe override BitmapBase Apply(RenderTask renderTask, BitmapBase layer)
        {
            Tank tank   = renderTask.Tank;
            var  bounds =
                Mode == ClipMode.ByPixels
                    ? layer.PreciseSize(PixelAlphaThreshold)
                : Mode == ClipMode.ByLayerBounds
                    ? PixelRect.FromMixed(0, 0, layer.Width, layer.Height)
                    : PixelRect.FromMixed(0, 0, Layer.ParentStyle.IconWidth, Layer.ParentStyle.IconHeight);

            using (layer.UseWrite())
            {
                int   count;
                byte *ptr;
                // Clip Top
                for (int y = 0; y < bounds.Top + ClipTop && y < layer.Height; y++)
                {
                    Ut.MemSet(layer.Data + y * layer.Stride, 0, layer.Width * 4);
                }
                // Clip Bottom
                for (int y = layer.Height - 1; y > bounds.Bottom - ClipBottom && y >= 0; y--)
                {
                    Ut.MemSet(layer.Data + y * layer.Stride, 0, layer.Width * 4);
                }
                // Clip Left
                count = Math.Min(bounds.Left + ClipLeft, layer.Width) * 4;
                ptr   = layer.Data;
                if (count > 0)
                {
                    for (int y = 0; y < layer.Height; y++, ptr += layer.Stride)
                    {
                        Ut.MemSet(ptr, 0, count);
                    }
                }
                // Clip Right
                count = Math.Min(layer.Width - 1 - bounds.Right + ClipRight, layer.Width) * 4;
                ptr   = layer.Data + layer.Width * 4 - count;
                if (count > 0)
                {
                    for (int y = 0; y < layer.Height; y++, ptr += layer.Stride)
                    {
                        Ut.MemSet(ptr, 0, count);
                    }
                }
            }
            return(layer);
        }
예제 #22
0
    public PixelRect GetDataAreaRect(PixelRect figureRect, IEnumerable <Axis.IXAxis> xAxes, IEnumerable <Axis.IYAxis> yAxes)
    {
        PixelPadding padding = new();

        foreach (Axis.IXAxis xAxis in xAxes)
        {
            xAxis.TickGenerator.Regenerate(xAxis.Range, figureRect.Width);
            float yPx = xAxis.Measure();

            if (xAxis.Edge == Edge.Bottom)
            {
                padding.Bottom += yPx;
            }
            else if (xAxis.Edge == Edge.Top)
            {
                padding.Top += yPx;
            }
            else
            {
                throw new InvalidOperationException($"Unsupported edge: {xAxis.Edge}");
            }
        }

        foreach (Axis.IYAxis yAxis in yAxes)
        {
            yAxis.TickGenerator.Regenerate(yAxis.Range, figureRect.Height);
            float xPx = yAxis.Measure();

            if (yAxis.Edge == Edge.Left)
            {
                padding.Left += xPx;
            }
            else if (yAxis.Edge == Edge.Right)
            {
                padding.Right += xPx;
            }
            else
            {
                throw new InvalidOperationException($"Unsupported edge: {yAxis.Edge}");
            }
        }

        padding.Right += 20;
        padding.Top   += 20;

        return(figureRect.Contract(padding));
    }
예제 #23
0
        static unsafe X11Screen[] UpdateWorkArea(X11Info info, X11Screen[] screens)
        {
            var rect = default(PixelRect);

            foreach (var s in screens)
            {
                rect = rect.Union(s.Bounds);
                //Fallback value
                s.WorkingArea = s.Bounds;
            }

            var res = XGetWindowProperty(info.Display,
                                         info.RootWindow,
                                         info.Atoms._NET_WORKAREA,
                                         IntPtr.Zero,
                                         new IntPtr(128),
                                         false,
                                         info.Atoms.AnyPropertyType,
                                         out var type,
                                         out var format,
                                         out var count,
                                         out var bytesAfter,
                                         out var prop);

            if (res != (int)Status.Success || type == IntPtr.Zero ||
                format == 0 || bytesAfter.ToInt64() != 0 || count.ToInt64() % 4 != 0)
            {
                return(screens);
            }

            var pwa = (IntPtr *)prop;
            var wa  = new PixelRect(pwa[0].ToInt32(), pwa[1].ToInt32(), pwa[2].ToInt32(), pwa[3].ToInt32());


            foreach (var s in screens)
            {
                s.WorkingArea = s.Bounds.Intersect(wa);
                if (s.WorkingArea.Width <= 0 || s.WorkingArea.Height <= 0)
                {
                    s.WorkingArea = s.Bounds;
                }
            }

            XFree(prop);
            return(screens);
        }
예제 #24
0
    public Entity Collide(Entity entity, string tag, PixelRect rect)
    {
        foreach (Entity other in _entities)
        {
            if (!other.tags.Contains(tag) || !other.collideable || other == entity)
            {
                continue;
            }

            if (rect.Overlaps(other.offsetHitbox))
            {
                return(other);
            }
        }

        return(null);
    }
예제 #25
0
 public X11Screen(PixelRect bounds, bool primary,
                  string name, Size?physicalSize, double?pixelDensity)
 {
     Primary = primary;
     Name    = name;
     Bounds  = bounds;
     if (physicalSize == null && pixelDensity == null)
     {
         PixelDensity = 1;
     }
     else if (pixelDensity == null)
     {
         PixelDensity = GuessPixelDensity(bounds.Width, physicalSize.Value.Width);
     }
     else
     {
         PixelDensity = pixelDensity.Value;
         PhysicalSize = physicalSize;
     }
 }
예제 #26
0
        private IDisposable Application()
        {
            var screen = new PixelRect(new PixelPoint(), new PixelSize(100, 100));
            var screenImpl = new Mock<IScreenImpl>();
            screenImpl.Setup(x => x.ScreenCount).Returns(1);
            screenImpl.Setup(X => X.AllScreens).Returns( new[] { new Screen(1, screen, screen, true) });

            popupImpl = MockWindowingPlatform.CreatePopupMock();
            popupImpl.SetupGet(x => x.Scaling).Returns(1);

            var windowImpl = MockWindowingPlatform.CreateWindowMock(() => popupImpl.Object);
            windowImpl.Setup(x => x.Screen).Returns(screenImpl.Object);

            var services = TestServices.StyledWindow.With(
                                        inputManager: new InputManager(),
                                        windowImpl: windowImpl.Object,
                                        windowingPlatform: new MockWindowingPlatform(() => windowImpl.Object, () => popupImpl.Object));

            return UnitTestApplication.Start(services);
        }
예제 #27
0
        public Screen ScreenFromBounds(PixelRect bounds)
        {
            Screen currMaxScreen = null;
            double maxAreaSize   = 0;

            foreach (Screen screen in All)
            {
                double left   = MathUtilities.Clamp(bounds.X, screen.Bounds.X, screen.Bounds.X + screen.Bounds.Width);
                double top    = MathUtilities.Clamp(bounds.Y, screen.Bounds.Y, screen.Bounds.Y + screen.Bounds.Height);
                double right  = MathUtilities.Clamp(bounds.X + bounds.Width, screen.Bounds.X, screen.Bounds.X + screen.Bounds.Width);
                double bottom = MathUtilities.Clamp(bounds.Y + bounds.Height, screen.Bounds.Y, screen.Bounds.Y + screen.Bounds.Height);
                double area   = (right - left) * (bottom - top);
                if (area > maxAreaSize)
                {
                    maxAreaSize   = area;
                    currMaxScreen = screen;
                }
            }

            return(currMaxScreen);
        }
예제 #28
0
        private void DrawDebugCross(PixelRect pr)
        {
            int centerX = (pr.x + pr.xx) / 2;
            int centerY = (pr.y + pr.yy) / 2;

            m_texture.SetPixel(centerX, centerY, Color.black);

            for (int x = pr.x; x < pr.xx; x++)
            {
                m_texture.SetPixel(x, centerY, Color.black);
                m_texture.SetPixel(x, centerY - 1, Color.black);
                m_texture.SetPixel(x, centerY + 1, Color.black);
            }

            for (int y = pr.y; y < pr.yy; y++)
            {
                m_texture.SetPixel(centerX, y, Color.black);
                m_texture.SetPixel(centerX - 1, y, Color.black);
                m_texture.SetPixel(centerX + 1, y, Color.black);
            }
        }
예제 #29
0
        /// <summary>
        /// Moves the Popups position so that it doesnt overlap screen edges.
        /// This method can be called immediately after Show has been called.
        /// </summary>
        public void SnapInsideScreenEdges()
        {
            var screen = Application.Current.MainWindow?.Screens.ScreenFromPoint(Position);

            if (screen != null)
            {
                var scaling = VisualRoot.RenderScaling;
                var bounds  = PixelRect.FromRect(Bounds, scaling);
                var screenX = Position.X + bounds.Width - screen.Bounds.X;
                var screenY = Position.Y + bounds.Height - screen.Bounds.Y;

                if (screenX > screen.Bounds.Width)
                {
                    Position = Position.WithX(Position.X - (screenX - screen.Bounds.Width));
                }

                if (screenY > screen.Bounds.Height)
                {
                    Position = Position.WithY(Position.Y - (screenY - screen.Bounds.Height));
                }
            }
        }
 protected Entity Collide(string type, PixelRect rect)
 {
     return scene.Collide(this, type, rect);
 }
예제 #31
0
        public override BitmapBase Apply(RenderTask renderTask, BitmapBase layer)
        {
            var calculator = new SizeCalculator(renderTask, layer);
            Func <string, string> describe = property =>
                                             "*{0}:* {1}\n".Fmt(EggsML.Escape(App.Translation.Calculator.ErrLabel_Layer), EggsML.Escape((string.IsNullOrEmpty(Layer.Name) ? "" : (Layer.Name + " – ")) + Layer.TypeName)) +
                                             "*{0}:* {1}\n".Fmt(EggsML.Escape(App.Translation.Calculator.ErrLabel_Effect), EggsML.Escape((string.IsNullOrEmpty(Name) ? "" : (Name + " – ")) + TypeName)) +
                                             "*{0}:* {1}".Fmt(EggsML.Escape(App.Translation.Calculator.ErrLabel_Property), EggsML.Escape(property));

            double ParsedWidth  = Math.Max(0, calculator.Parse(Width, describe(WidthTr(App.Translation).DisplayName))),
                   ParsedHeight = Math.Max(0, calculator.Parse(Height, describe(HeightTr(App.Translation).DisplayName))),
                   ParsedX      = calculator.Parse(X, describe(XTr(App.Translation).DisplayName)),
                   ParsedY      = calculator.Parse(Y, describe(YTr(App.Translation).DisplayName));

            Tank tank   = renderTask.Tank;
            var  pixels = PixelRect.FromMixed(0, 0, layer.Width, layer.Height);

            if (ShowPixelBorders || PositionByPixels || (SizeByPixels && SizeMode2 != SizeMode2.NoChange && SizeMode2 != SizeMode2.ByPercentage))
            {
                pixels = layer.PreciseSize(PixelAlphaThreshold);
            }
            bool emptyPixels = pixels.Width <= 0 || pixels.Height <= 0;

            if (emptyPixels)
            {
                pixels = PixelRect.FromMixed(0, 0, layer.Width, layer.Height);
            }

            double scaleWidth, scaleHeight;
            int    sourceWidth  = SizeByPixels ? pixels.Width : layer.Width;
            int    sourceHeight = SizeByPixels ? pixels.Height : layer.Height;

            switch (SizeMode2)
            {
            case SizeMode2.NoChange:
                scaleWidth = scaleHeight = 1;
                break;

            case SizeMode2.ByPercentage:
                scaleWidth = scaleHeight = Percentage / 100.0;
                break;

            case SizeMode2.BySizeWidthOnly:
                scaleWidth = scaleHeight = ParsedWidth / (double)sourceWidth;
                break;

            case SizeMode2.BySizeHeightOnly:
                scaleWidth = scaleHeight = ParsedHeight / (double)sourceHeight;
                break;

            case SizeMode2.BySizeFit:
                scaleWidth = scaleHeight = Math.Min(ParsedWidth / (double)sourceWidth, ParsedHeight / (double)sourceHeight);
                break;

            case SizeMode2.BySizeStretch:
                scaleWidth  = ParsedWidth / (double)sourceWidth;
                scaleHeight = ParsedHeight / (double)sourceHeight;
                break;

            default:
                throw new Exception("7924688");
            }

            if (GrowShrinkMode == GrowShrinkMode.GrowOnly)
            {
                scaleWidth  = Math.Max(1.0, scaleWidth);
                scaleHeight = Math.Max(1.0, scaleHeight);
            }
            else if (GrowShrinkMode == GrowShrinkMode.ShrinkOnly)
            {
                scaleWidth  = Math.Min(1.0, scaleWidth);
                scaleHeight = Math.Min(1.0, scaleHeight);
            }

            var anchor       = (AnchorRaw)Anchor;
            int anchorWidth  = (int)Math.Ceiling((PositionByPixels ? pixels.Width : layer.Width) * scaleWidth);
            int anchorHeight = (int)Math.Ceiling((PositionByPixels ? pixels.Height : layer.Height) * scaleHeight);
            // Location of the top left corner of the anchored rectangle
            int tgtX = (int)ParsedX - (anchor.HasFlag(AnchorRaw.Right) ? anchorWidth - 1 : anchor.HasFlag(AnchorRaw.Center) ? (anchorWidth - 1) / 2 : 0);
            int tgtY = (int)ParsedY - (anchor.HasFlag(AnchorRaw.Bottom) ? anchorHeight - 1 : anchor.HasFlag(AnchorRaw.Mid) ? (anchorHeight - 1) / 2 : 0);
            // Location of the top left corner of the whole scaled layer image
            double x       = tgtX - (PositionByPixels ? pixels.Left * scaleWidth : 0);
            double y       = tgtY - (PositionByPixels ? pixels.Top * scaleHeight : 0);
            int    offsetX = (PositionByPixels ? pixels.Left : 0);
            int    offsetY = (PositionByPixels ? pixels.Top : 0);

            if (ShowLayerBorders || ShowPixelBorders)
            {
                using (var image = layer.ToMagickImage())
                {
                    image.Settings.StrokeWidth = 1;
                    if (ShowLayerBorders)
                    {
                        image.Settings.FillColor   = ImageMagick.MagickColors.Transparent;
                        image.Settings.StrokeColor = new ImageMagick.MagickColor("aqua");
                        image.Draw(new ImageMagick.DrawableRectangle(0, 0, layer.Width - 1, layer.Height - 1));
                    }
                    if (ShowPixelBorders && !emptyPixels)
                    {
                        image.Settings.FillColor   = ImageMagick.MagickColors.Transparent;
                        image.Settings.StrokeColor = new ImageMagick.MagickColor("red");
                        image.Draw(new ImageMagick.DrawableRectangle(pixels.Left, pixels.Top, pixels.Right, pixels.Bottom));
                    }
                    layer.CopyPixelsFrom(image.ToBitmapSource());
                }
            }
            BitmapResampler.Filter filter;
            switch (Filter)
            {
            case Filter.Auto: filter = null; break;

            case Filter.Mitchell: filter = new BitmapResampler.MitchellFilter(); break;

            case Filter.Bicubic: filter = new BitmapResampler.CatmullRomFilter(); break;

            case Filter.Lanczos: filter = new BitmapResampler.LanczosFilter(); break;

            case Filter.Sinc256: filter = new BitmapResampler.LanczosFilter(8); break;

            case Filter.Sinc1024: filter = new BitmapResampler.LanczosFilter(16); break;

            default: throw new Exception("SizePosEffect.Filter 4107");
            }
            layer = BitmapResampler.SizePos(layer, scaleWidth, scaleHeight, offsetX, offsetY, tgtX, tgtY, Math.Max(layer.Width, Layer.ParentStyle.IconWidth), Math.Max(layer.Height, Layer.ParentStyle.IconHeight), filter);
            if (ShowAnchor)
            {
                using (var image = layer.ToMagickImage())
                {
                    image.Settings.StrokeWidth = 1;
                    image.Settings.StrokeColor = new ImageMagick.MagickColor(255, 255, 0, 120);
                    image.Draw(new ImageMagick.DrawableLine((int)ParsedX - 1, (int)ParsedY, (int)ParsedX + 1, (int)ParsedY));
                    image.Draw(new ImageMagick.DrawableLine((int)ParsedX, (int)ParsedY - 1, (int)ParsedX, (int)ParsedY + 1));
                    layer.CopyPixelsFrom(image.ToBitmapSource());
                }
            }
            return(layer);
        }
    public bool IsInScreenBounds(PixelRect rect)
    {
        if((rect.xMin < PixelScreen.shared.cameraPos.x) ||
           (rect.xMax > PixelScreen.shared.cameraPos.x + PixelScreen.shared.GetScreenWidth() - 1) ||
           (rect.yMin < PixelScreen.shared.cameraPos.y) ||
           (rect.yMax > PixelScreen.shared.cameraPos.y + PixelScreen.shared.GetScreenHeight() - 1))
            return false;

        return true;
    }
 public bool Overlaps(PixelRect other)
 {
     //		Debug.Log("OVERLAPS: this.xMin: " + xMin + " this.xMax: " + xMax + " this.yMin: " + yMin + " this.yMax: " + yMax +
     //		          " other.xMin: " + other.xMin + " other.xMax: " + other.xMax + " other.yMin: " + other.yMin + " other.yMax: " + other.yMax);
     return other.xMax >= this.xMin && other.xMin <= this.xMax && other.yMax >= this.yMin && other.yMin <= this.yMax;
 }
예제 #34
0
 public Screen?ScreenFromRect(PixelRect rect)
 {
     return(ScreenHelper.ScreenFromRect(rect, AllScreens));
 }
    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;
    }
    void NewCanvas()
    {
        _framePreview.NewCanvas();

        _commandUndoStack.Clear();
        _commandRedoStack.Clear();

        _canvas.NewCanvas();

        // re-init copied pixels so the array is the right size/dimensions
        if(_canvas.pixelWidth != _lastCanvasWidth || _canvas.pixelHeight != _lastCanvasHeight)
            _copiedPixels = new Color32[_canvas.pixelWidth * _canvas.pixelHeight];

        _hitbox = new PixelRect(0, 0, _canvas.pixelWidth, _canvas.pixelHeight);
        RefreshHitboxString();
        _canvas.RefreshHitbox();

        _framePreview.ResizeFramePreviews();
        _framePreview.CreateFramePlane();

        _lastCanvasWidth = _canvas.pixelWidth;
        _lastCanvasHeight = _canvas.pixelHeight;

        _patternViewer.NewCanvas();
    }
 void UpdateHitbox()
 {
     if(_alignment == TextDisplayAlignment.LeftToRight)
         hitbox = new PixelRect(0, 0, ((_letterWidth * _text.Length) + (_spacing * _text.Length - 1)) * _scale, _letterHeight * _scale);
     else
         hitbox = new PixelRect(0, 0, _letterWidth * _scale, (((_letterHeight + _spacing) * _text.Length) - 1) * _scale);
 }
    void Update()
    {
        // -------------------------------------------------
        // UNDO
        // -------------------------------------------------
        if(GetModifierKey() && Input.GetKeyDown(KeyCode.Z) && !GetIsEditingPixels())
            UndoLastCommand();

        // -------------------------------------------------
        // REDO
        // -------------------------------------------------
        if(GetModifierKey() && Input.GetKeyDown(KeyCode.Y) && !GetIsEditingPixels())
            RedoLastCommand();

        // -------------------------------------------------
        // TOGGLE SHOWING HITBOX
        // -------------------------------------------------
        if(Input.GetKeyDown(KeyCode.H) && _textEnteringMode == TextEnteringMode.None)
        {
            _showingHitbox = !_showingHitbox;
            _canvas.RefreshHitbox();
        }

        // -------------------------------------------------
        // LOADING ANIMATIONS
        // -------------------------------------------------
        if(GetModifierKey() && Input.GetKeyDown(KeyCode.O) && !GetIsEditingPixels())
        {
            _loadAnimString = "***PASTE ANIM DATA***";
            _textEnteringMode = TextEnteringMode.LoadAnimation;
        }

        // -------------------------------------------------
        // SWITCHING TOOLS
        // -------------------------------------------------
        if(_textEnteringMode == TextEnteringMode.None)
        {
            if(Input.GetKeyDown(KeyCode.B))
                SetToolMode(ToolMode.Brush);
            else if(Input.GetKeyDown(KeyCode.E))
                SetToolMode(ToolMode.Eraser);
            else if(Input.GetKeyDown(KeyCode.G))
                SetToolMode(ToolMode.Bucket);
            else if(Input.GetKeyDown(KeyCode.F))
                SetToolMode(ToolMode.Dropper);
        }

        // -------------------------------------------------
        // CANVAS
        // -------------------------------------------------
        if(GetModifierKey() && Input.GetKeyDown(KeyCode.N) && !GetIsEditingPixels() && _textEnteringMode == TextEnteringMode.None)
        {
            NewCanvas();
        }

        _canvas.UpdateCanvas();
        _swatch.UpdateSwatch();
        _palette.UpdatePalette();
        _framePreview.UpdateFramePreview();
        _patternViewer.UpdatePatternViewer();

        // -------------------------------------------------
        // COPYING FRAMES
        // -------------------------------------------------
        if(GetModifierKey() && Input.GetKeyDown(KeyCode.C) && !GetIsEditingPixels())
        {
            _canvas.GetPixels(CurrentFrame).CopyTo(_copiedPixels, 0);
            _canvas.DirtyPixels = true;

            PlayCopyEffect();
        }

        // -------------------------------------------------
        // PASTING FRAMES
        // -------------------------------------------------
        if(GetModifierKey() && Input.GetKeyDown(KeyCode.V) && !GetIsEditingPixels())
        {
            PlayPasteEffect();
        }

        // -------------------------------------------------
        // SAVING DATA
        // -------------------------------------------------
        if(GetModifierKey() && Input.GetKeyDown(KeyCode.S))
        {
            ClipboardHelper.clipBoard = GetAnimData();
            Debug.Log("clipboard: " + ClipboardHelper.clipBoard);
            ShowConsoleText(ClipboardHelper.clipBoard);
        }

        // -------------------------------------------------
        // CONSOLE TEXT
        // -------------------------------------------------
        if(_isShowingConsoleText && (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1)))
        {
            _consoleTextWrap.SetText("");
            _isShowingConsoleText = false;
        }
        // -------------------------------------------------
        // TEXT INPUT
        // -------------------------------------------------
        if(_textEnteringMode == TextEnteringMode.None)
        {
            if(Input.GetKeyDown(KeyCode.Return))
            {
                _textEnteringMode = TextEnteringMode.CurrentFrameTime;
                _firstChar = true;
            }
        }
        else
        {
            HandleInputString(Input.inputString);

            // -------------------------------------------------------------------------------------
            // ENTERING ANIM NAME
            // -------------------------------------------------------------------------------------
            if(_textEnteringMode == TextEnteringMode.AnimName)
            {
                if(Input.GetKeyDown(KeyCode.Return))
                {
                    if(_animNameTempString != "")
                    {
                        AddNewCommand(new SetAnimNameCommand(_animNameTempString));
                        _textEnteringMode = TextEnteringMode.None;
                    }
                }
                else if(Input.GetKeyDown(KeyCode.Tab))
                {
                    if(GetModifierKey())
                    {
                        // edit frame time
                        _textEnteringMode = TextEnteringMode.CurrentFrameTime;
                    }
                    else
                    {
                        // edit dimensions
                        _textEnteringMode = TextEnteringMode.PixelDimensions;
                    }

                    _animNameTempString = _animName;
                    _firstChar = true;
                }
            }
            // -------------------------------------------------------------------------------------
            // ENTERING PIXEL DIMENSTIONS
            // -------------------------------------------------------------------------------------
            else if(_textEnteringMode == TextEnteringMode.PixelDimensions)
            {
                if(Input.GetKeyDown(KeyCode.Return))
                {
                    string[] vals = _pixelDimensionsString.Split(',');
                    if(vals.Length == 2)
                    {
                        int pw = 0;
                        int.TryParse(vals[0], out pw);
                        int ph = 0;
                        int.TryParse(vals[1], out ph);
                        if((pw != 0 && ph != 0) &&
                           !(pw == _canvas.pixelWidth && ph == _canvas.pixelHeight) &&
                           (pw <= MAX_CANVAS_WIDTH && ph <= MAX_CANVAS_HEIGHT))
                        {
                            _canvas.pixelWidth = pw;
                            _canvas.pixelHeight = ph;
                            NewCanvas();
                        }

                        _pixelDimensionsString = _canvas.pixelWidth.ToString() + "," + _canvas.pixelHeight.ToString();
                        _textEnteringMode = TextEnteringMode.None;
                    }
                }
                else if(Input.GetKeyDown(KeyCode.Tab))
                {
                    if(GetModifierKey())
                    {
                        // edit anim name
                        _textEnteringMode = TextEnteringMode.AnimName;
                    }
                    else
                    {
                        // edit hitbox
                        _textEnteringMode = TextEnteringMode.Hitbox;
                    }

                    _pixelDimensionsString = _canvas.pixelWidth.ToString() + "," + _canvas.pixelHeight.ToString();
                    _firstChar = true;
                }
            }
            // -------------------------------------------------------------------------------------
            // ENTERING HITBOX
            // -------------------------------------------------------------------------------------
            else if(_textEnteringMode == TextEnteringMode.Hitbox)
            {
                if(Input.GetKeyDown(KeyCode.Return))
                {
                    string[] vals = _hitboxString.Split(',');
                    if(vals.Length == 4)
                    {
                        int left = -1;
                        int.TryParse(vals[0], out left);
                        int bottom = -1;
                        int.TryParse(vals[1], out bottom);
                        int width = -1;
                        int.TryParse(vals[2], out width);
                        int height = -1;
                        int.TryParse(vals[3], out height);
                        if(left >= 0 && bottom >= 0 && width > 0 && height > 0 &&
                           width <= _canvas.pixelWidth && height <= _canvas.pixelHeight &&
                           left + width <= _canvas.pixelWidth && bottom + height <= _canvas.pixelHeight)
                        {
                            _hitbox = new PixelRect(left, bottom, width, height);
                            _canvas.RefreshHitbox();
                        }

                        RefreshHitboxString();
                        _textEnteringMode = TextEnteringMode.None;
                    }
                }
                else if(Input.GetKeyDown(KeyCode.Tab))
                {
                    if(GetModifierKey())
                    {
                        // edit dimensions
                        _textEnteringMode = TextEnteringMode.PixelDimensions;
                    }
                    else
                    {
                        // edit frame time
                        _textEnteringMode = TextEnteringMode.CurrentFrameTime;
                    }

                    RefreshHitboxString();
                    _firstChar = true;
                }
            }
            // -------------------------------------------------------------------------------------
            // ENTERING CURRENT FRAME TIME
            // -------------------------------------------------------------------------------------
            else if(_textEnteringMode == TextEnteringMode.CurrentFrameTime)
            {
                if(Input.GetKeyDown(KeyCode.Return))
                {
                    float time = 0.0f;
                    bool valid = float.TryParse(_currentFrameTimeString, out time);

                    if(valid && time > 0.0f)
                    {
                        AddNewCommand(new SetCurrentFrameTimeCommand(time));
                        _textEnteringMode = TextEnteringMode.None;
                    }
                    else
                    {
                        _currentFrameTimeString = _framePreview.GetCurrentFrameTime().ToString();
                        _textEnteringMode = TextEnteringMode.None;
                    }
                }
                else if(Input.GetKeyDown(KeyCode.Tab))
                {
                    if(GetModifierKey())
                    {
                        // edit hitbox
                        _textEnteringMode = TextEnteringMode.Hitbox;
                    }
                    else
                    {
                        // edit anim name
                        _textEnteringMode = TextEnteringMode.AnimName;
                    }

                    _currentFrameTimeString = _framePreview.GetCurrentFrameTime().ToString();
                    _firstChar = true;
                }
            }
        }
    }
    public bool Init()
    {
        if(!_initialized)
        {
            // these seem to return 0 sometimes if we check them too early
            // so we won't consider the pixel screen initialized until we can get back a non-zero value for these
            if(Screen.width == 0 || Screen.height == 0)
                return false;

            int screenWidth = PlayerPrefs.GetInt("screenWidth", 800);
            int screenHeight = PlayerPrefs.GetInt("screenHeight", 500);
            screenWidth = Mathf.Max(screenHeight, 300);
            screenHeight = Mathf.Max(screenHeight, 300);

            Screen.SetResolution(screenWidth, screenHeight, false);

            Camera camera = GetComponent<Camera>();
            camera.orthographic = true;
            camera.orthographicSize = 1;

            // ----------------------------------------------
            // CANVAS
            // ----------------------------------------------
            _canvas = gameObject.AddComponent<Canvas>();
            _canvas.Init(this);

            _lastCanvasWidth = _canvas.pixelWidth;
            _lastCanvasHeight = _canvas.pixelHeight;

            _copiedPixels = new Color32[_canvas.pixelWidth * _canvas.pixelHeight];
            _canvas.GetPixels(CurrentFrame).CopyTo(_copiedPixels, 0);

            _pixelDimensionsString = _canvas.pixelWidth.ToString() + "," + _canvas.pixelHeight.ToString();
            _hitbox = new PixelRect(0, 0, _canvas.pixelWidth, _canvas.pixelHeight);
            RefreshHitboxString();

            // ----------------------------------------------
            // SWATCH
            // ----------------------------------------------
            _swatch = gameObject.AddComponent<Swatch>();
            _swatch.Init(this);
            SetCurrentColor(Color.black);

            // ----------------------------------------------
            // PALETTE
            // ----------------------------------------------
            _palette = gameObject.AddComponent<Palette>();
            _palette.Init(this);

            CreateEffectPlane();

            // ----------------------------------------------
            // FRAME PREVIEW
            // ----------------------------------------------
            _framePreview = gameObject.AddComponent<FramePreview>();
            _framePreview.Init(this);

            // ----------------------------------------------
            // PATTERN VIEWER
            // ----------------------------------------------
            _patternViewer = gameObject.AddComponent<PatternViewer>();
            _patternViewer.Init(this);

            _initialized = true;

            _textStyle = new GUIStyle();
            _textStyle.font = Resources.Load("Fonts/04b03") as Font;
            _textStyle.normal.textColor = new Color(0.8f, 0.8f, 0.8f);
            _textStyle.fontSize = 20;

            _textStyleRed = new GUIStyle(_textStyle);
            _textStyleRed.normal.textColor = new Color(0.8f, 0.2f, 0.2f);

            _textStyleFocused = new GUIStyle();
            _textStyleFocused.font = Resources.Load("Fonts/04b03") as Font;
            _textStyleFocused.normal.textColor = Color.white;
            Texture2D black = new Texture2D(1, 1);
            black.SetPixel(0, 0, Color.black);
            black.Apply();
            _textStyleFocused.normal.background = black;
            _textStyleFocused.fontSize = 20;

            _toolMode = ToolMode.Brush;
        //			Cursor.SetCursor(cursorBrush, Vector2.zero, CursorMode.Auto);

            _canvas.SetOnionSkinMode((OnionSkinMode)PlayerPrefs.GetInt("onionSkinMode", 0));
            _canvas.RefreshOnionSkin();

            _canvas.SetMirroringMode((MirroringMode)PlayerPrefs.GetInt("mirroringMode", 0));

            _consoleText = gameObject.AddComponent<GUIText>();
            _consoleText.color = Color.black;
            _consoleText.font = Resources.Load("Fonts/04b03") as Font;
            _consoleText.fontSize = 12;
            _consoleText.transform.position = new Vector2(0.0025f, 0);
            _consoleText.anchor = TextAnchor.LowerLeft;

            _consoleTextWrap = gameObject.AddComponent<ConsoleTextSetter>();

            string animData = PlayerPrefs.GetString("animData", "");
            Debug.Log("animData: " + animData);
            if(animData != "")
                LoadAnimationString(animData);
        }

        return _initialized;
    }
예제 #40
0
 public virtual bool IsHit(Vector2 point)
 {
     return(PixelRect.IsPointInRect(point));
 }
    // ** name
    // !! size
    // {} frame
    // [] color
    // () pixel
    // <> hitbox
    // ## time
    // && loops
    void LoadAnimationString(string animString)
    {
        AnimationData animData = ParseAnimationString(animString);
        if(animData == null)
            return;

        _animName = animData.name;
        _framePreview.SetLoopMode(animData.loopMode);
        _canvas.pixelWidth = animData.animSize.x;
        _canvas.pixelHeight = animData.animSize.y;

        NewCanvas();

        int frameNumber = 0;
        foreach(FrameData frameData in animData.frames)
        {
            // create a new frame
            if(frameNumber >= _framePreview.GetNumFrames())
                _framePreview.AddNewBlankFrame();

            _framePreview.SetFrameTime(frameData.animTime, frameNumber);

            foreach(PixelData pixelData in frameData.pixels)
                _canvas.SetPixelForFrame(frameNumber, pixelData.position.x, pixelData.position.y, pixelData.color);

            frameNumber++;
        }

        // NewCanvas() resets hitbox to anim size so gotta set it again
        _hitbox = animData.hitbox;
        RefreshHitboxString();

        _canvas.DirtyPixels = true;
    }