Exemple #1
0
        public override void Tap(SKPointI point)
        {
            base.Tap(point);

            // if we aren't scrolling, then it is game over
            if (scrolling)
            {
                // start the flapping if this is the first time tapping
                if (!interactiveMode)
                {
                    interactiveMode = true;

                    // take the current bob and add it to the position
                    // before turing off bobbing
                    playerPos.Y          += bobbingBird.BobOffset;
                    bobbingBird.BobOffset = 0f;

                    tutorial.Hide();
                }

                // flap those wings!
                bobbingBird.StartFlapping();

                // apply flap force
                if (playerPos.Y > 0)
                {
                    // a flap cancels all downward momentum
                    speed             = BobbingBird.FlapStrength;
                    acceleration      = BobbingBird.Gravity;
                    angleChange       = BobbingBird.InitialRotationAcceleration;
                    angleAcceleration = BobbingBird.RotationAcceleration;
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Update the Zoom Window with a new mouse position. This means mouse have been moved and
        /// the Zoom Window needs to refresh its contents.
        /// </summary>
        /// <param name="p">New mouse position to zoom in at</param>
        private void UpdateZoomWindow(SKPoint p)
        {
            // Do we need to update at all?
            if (!windowZoom.Visible)
            {
                return;
            }

            // Get bounds of screen area to capture
            var w    = windowZoom.Bounds.Width / WindowZoomFactor;
            var h    = windowZoom.Bounds.Height / WindowZoomFactor;
            var x    = (int)(p.X - w / 2f);
            var y    = (int)(p.Y - h / 2f);
            var rect = new SKRectI(x, y, x + (int)w, y + (int)h);

            // Perform the capture and update zoom window with it
            var screenshot = screenService.Capture(rect);

            windowZoom.UpdateZoom(screenshot, WindowZoomFactor);

            // Request repaint of zoom window by using any point within it
            var invalidateAtPos = new SKPointI((int)ZoomWindowLocation.X + 1, (int)ZoomWindowLocation.Y + 1);

            screenService.Invalidate(invalidateAtPos);
        }
Exemple #3
0
        public static Rectangle gridRecAroundTouch(SKPoint touch, int angle, int numFrames, int boundsWidth, int boundsHeight)
        {
            var rotGrid = createGridTransformation(angle, boundsWidth, boundsHeight, numFrames);

            var gridCoords = new SKPointI();

            rotGrid.CellCoordsFromOriginPoint(ref gridCoords, touch);

            var A = new SKPoint(gridCoords.X * rotGrid.CellWidth, gridCoords.Y * rotGrid.CellHeight);

            var B = new SKPoint(A.X, A.Y);

            B.Offset(rotGrid.CellWidth, 0);

            var C = new SKPoint(A.X, A.Y);

            C.Offset(rotGrid.CellWidth, rotGrid.CellHeight);

            var D = new SKPoint(A.X, A.Y);

            D.Offset(0, rotGrid.CellHeight);

            return(new Rectangle(rotGrid.ToOriginCoords(A), rotGrid.ToOriginCoords(B),
                                 rotGrid.ToOriginCoords(C), rotGrid.ToOriginCoords(D)));
        }
Exemple #4
0
        // seperates the internal points into a logical grid of cells
        internal void seperatePointsIntoGridCells(List <DelaunayTriangulator.Vertex> points, int angle)
        {
            GridRotation = Geometry.createGridTransformation(angle, BoundsWidth, BoundsHeight, NumFrames);

            SeperatedPoints = new Dictionary <SKPointI, HashSet <SKPoint> >();

            SKPointI gridIndex = new SKPointI();

            var newPoint = new SKPoint();

            foreach (var point in points)
            {
                newPoint.X = point.x;
                newPoint.Y = point.y;

                GridRotation.CellCoordsFromOriginPoint(ref gridIndex, newPoint);

                //if the SeperatedPoints distionary does not have a point already, initialize the list at that key
                if (!SeperatedPoints.ContainsKey(gridIndex))
                {
                    SeperatedPoints[gridIndex] = new HashSet <SKPoint>();
                }
                SeperatedPoints[gridIndex].Add(newPoint);
            }
        }
Exemple #5
0
        public override void SetupAnimation()
        {
            base.SetupAnimation();
            //visible rec so that the start of the anim is from a point visible on screen
            var visibleRecX = Random.Rand.Next(NumFrames);
            var visibleRecY = Random.Rand.Next(NumFrames);

            var recIndex = new SKPointI(visibleRecX, visibleRecY);

            //keep geting a random index until one exists
            while (!SeperatedPoints.ContainsKey(recIndex))
            {
                visibleRecX = Random.Rand.Next(NumFrames);
                visibleRecY = Random.Rand.Next(NumFrames);
                recIndex    = new SKPointI(visibleRecX, visibleRecY);
            }

            //index of a randoom point on the random visible rec
            var index = Random.Rand.Next(SeperatedPoints[recIndex].Count);
            //pointF version of the point
            var pointT = SeperatedPoints[recIndex].ToArray()[index];
            //vertex version of the point
            var point = new Vertex(pointT.X, pointT.Y);
            //index of the chosen point in the overall points list
            var indexT = InternalPoints.IndexOf(point);

            //set the first point as used
            _pointUsed[indexT] = true;

            _animateList = new Queue <Vertex>();
            _animateList.Enqueue(point);

            IsSetup = true;
        }
        public void TestProcessChipResults()
        {
            var offset       = new SKPointI(300, 600);
            var observations = new[]
            {
                new Observation(_categoryManager.GetOrCreate(1, "Car"), 0.9, new SKRect(0.1f, 0.2f, 0.3f, 0.4f)),
                new Observation(_categoryManager.GetOrCreate(2, "Building"), 0.78, new SKRect(.2f, 0.3f, 0.5f, 0.8f))
            };

            PostProcessingService.ProcessChipResults(offset, observations);

            AssertUtils.AreEqualIEnumerable(new[]
            {
                new Observation(
                    _categoryManager.GetOrCreate(1, "Car"),
                    0.9,
                    new SKRect(offset.X + 0.1f * SharedConstants.DefaultChipWidth,
                               offset.Y + 0.2f * SharedConstants.DefaultChipHeight,
                               offset.X + 0.3f * SharedConstants.DefaultChipWidth,
                               offset.Y + 0.4f * SharedConstants.DefaultChipHeight)),
                new Observation(
                    _categoryManager.GetOrCreate(2, "Building"),
                    0.78,
                    new SKRect(offset.X + 0.2f * SharedConstants.DefaultChipWidth,
                               offset.Y + 0.3f * SharedConstants.DefaultChipHeight,
                               offset.X + 0.5f * SharedConstants.DefaultChipWidth,
                               offset.Y + 0.8f * SharedConstants.DefaultChipHeight)),
            },
                                            observations,
                                            AssertUtils.AreEqualObservation);
        }
        /// <summary>
        /// Scales this <see cref="Observation"/> by the specified size and translates it by the specified offset.
        /// </summary>
        /// <param name="size">The size of the corresponding <see cref="Chip"/>.</param>
        /// <param name="offset">The offset of the corresponding <see cref="Chip"/>.</param>
        public void ScaleAndTranslate(SKSizeI size, SKPointI offset)
        {
            var result = BoundingBox.Scale(size)
                         .Translate(offset);

            BoundingBox = result;
        }
Exemple #8
0
        public override void TouchUp(SKPointI point)
        {
            base.TouchUp(point);

            playButton.TouchUp(point);
            scoresButton.TouchUp(point);
            rateButton.TouchUp(point);
        }
Exemple #9
0
 public void Invalidate(SKPointI pos)
 {
     BeginInvokeOnMainThread(() =>
     {
         var aPoint        = pos.ToCGPointFlipY();
         var view          = PhiddleWindow.ContentView.HitTest(aPoint);
         view.NeedsDisplay = true;
     });
 }
Exemple #10
0
        /// <summary>
        /// Update the Info Window with new mouse position (and state of current tool).
        /// </summary>
        /// <param name="p">New mouse position to show</param>
        private void UpdateInfoWindow(SKPoint p)
        {
            windowInfo.ReportSelectedTool(appTools.ActiveTool);
            windowInfo.ReportMousePosition(p);
            windowInfo.ReportLabelPlacement(appTools.ActiveTool);
            windowInfo.ReportMeasurements(appTools.ActiveTool);
            var invalidateAtPos = new SKPointI((int)InfoWindowLocation.X + 1, (int)InfoWindowLocation.Y + 1);

            screenService.Invalidate(invalidateAtPos);
        }
Exemple #11
0
        public override void TouchUp(SKPointI point)
        {
            base.TouchUp(point);

            if (ShowButtons)
            {
                playButton.TouchUp(point);
                scoresButton.TouchUp(point);
            }
        }
Exemple #12
0
 public ShapeO(SKPointI point)
 {
     Points = new SKPointI[]
     {
         new SKPointI(point.X, point.Y),
         new SKPointI(point.X + 1, point.Y),
         new SKPointI(point.X, point.Y + 1),
         new SKPointI(point.X + 1, point.Y + 1)
     };
     Color = SKColors.Cyan;
 }
Exemple #13
0
 public ShapeS(SKPointI point)
 {
     Points = new SKPointI[]
     {
         new SKPointI(point.X, point.Y),
         new SKPointI(point.X + 1, point.Y),
         new SKPointI(point.X - 1, point.Y + 1),
         new SKPointI(point.X, point.Y + 1)
     };
     CenterIndex = 3;
     Color       = SKColors.Green;
 }
Exemple #14
0
 public ShapeL(SKPointI point)
 {
     Points = new SKPointI[]
     {
         new SKPointI(point.X, point.Y),
         new SKPointI(point.X + 1, point.Y),
         new SKPointI(point.X + 2, point.Y),
         new SKPointI(point.X, point.Y + 1)
     };
     CenterIndex = 0;
     Color       = SKColors.Brown;
 }
Exemple #15
0
        private SKPointI IncrementPosition(SKPointI pos, int max)
        {
            pos.X++;

            if (pos.X >= max)
            {
                pos.X = 0;
                pos.Y++;
            }

            return(pos);
        }
Exemple #16
0
 public ShapeJ(SKPointI point)
 {
     Points = new SKPointI[]
     {
         new SKPointI(point.X, point.Y),
         new SKPointI(point.X + 1, point.Y),
         new SKPointI(point.X + 2, point.Y),
         new SKPointI(point.X + 2, point.Y + 1)
     };
     CenterIndex = 2;
     Color       = SKColors.Magenta;
 }
Exemple #17
0
 public ShapeT(SKPointI point)
 {
     Points = new SKPointI[]
     {
         new SKPointI(point.X, point.Y),
         new SKPointI(point.X + 1, point.Y),
         new SKPointI(point.X + 2, point.Y + 1),
         new SKPointI(point.X + 1, point.Y + 1)
     };
     CenterIndex = 1;
     Color       = SKColors.Blue;
 }
Exemple #18
0
 public ShapeI(SKPointI point)
 {
     Points = new SKPointI[]
     {
         new SKPointI(point.X, point.Y),
         new SKPointI(point.X + 1, point.Y),
         new SKPointI(point.X + 2, point.Y),
         new SKPointI(point.X + 3, point.Y)
     };
     CenterIndex = 1;
     Color       = SKColors.Red;
 }
Exemple #19
0
        /// <summary>
        /// Scales and translates <see cref="Observation"/>s from a <see cref="Chip"/>.
        /// </summary>
        /// <param name="offset">The size of the specified <see cref="Chip"/>.</param>
        /// <param name="observations">The specified <see cref="Observation"/>s from a <see cref="Chip"/>.</param>
        public static void ProcessChipResults(SKPointI offset, IEnumerable <Observation> observations)
        {
            if (observations == null)
            {
                throw new ArgumentNullException();
            }

            var size = new SKSizeI(SharedConstants.DefaultChipWidth, SharedConstants.DefaultChipHeight);

            foreach (var observation in observations)
            {
                observation.ScaleAndTranslate(size, offset);
            }
        }
Exemple #20
0
        public void TestScaleAndTranslate(int offsetX, int offsetY)
        {
            var offset = new SKPointI(offsetX, offsetY);

            _observation.ScaleAndTranslate(
                new SKSizeI(SharedConstants.DefaultChipWidth, SharedConstants.DefaultChipHeight), offset);
            var expectedBoundingBox = new SKRect(
                _rect.Left * SharedConstants.DefaultChipWidth + offsetX,
                _rect.Top * SharedConstants.DefaultChipHeight + offsetY,
                _rect.Right * SharedConstants.DefaultChipWidth + offsetX,
                _rect.Bottom * SharedConstants.DefaultChipHeight + offsetY);

            Assert.AreEqual(_category, _observation.Category);
            Assert.AreEqual(_confidence, _observation.Confidence);
            AssertUtils.AreEqualSKRect(expectedBoundingBox, _observation.BoundingBox);
        }
Exemple #21
0
        public override void Tap(SKPointI point)
        {
            base.Tap(point);

            if (rateButton.HitTest(point))
            {
                RatingsTapped?.Invoke(this, EventArgs.Empty);
            }
            else if (playButton.HitTest(point))
            {
                PlayTapped?.Invoke(this, EventArgs.Empty);
            }
            else if (scoresButton.HitTest(point))
            {
                ScoresTapped?.Invoke(this, EventArgs.Empty);
            }
        }
Exemple #22
0
        [Arguments("t.jpg", "t2.jpg")] // SkiaSharp doesn't have TIFF support
        public void SkiaSharp(string input, string output)
        {
            using (var bitmap = SKBitmap.Decode(input))
            {
                bitmap.ExtractSubset(bitmap, SKRectI.Create(100, 100, bitmap.Width - 200, bitmap.Height - 200));

                var targetWidth  = (int)Math.Round(bitmap.Width * .9F);
                var targetHeight = (int)Math.Round(bitmap.Height * .9F);

                // bitmap.Resize(new SKImageInfo(targetWidth, targetHeight), SKBitmapResizeMethod.Triangle)
                // is deprecated, so we use `SKFilterQuality.Low` instead, see:
                // https://github.com/mono/SkiaSharp/blob/1527bf392ebc7b4b57c992ef8bfe14c9899f76a3/binding/Binding/SKBitmap.cs#L24
                using (var resized = bitmap.Resize(new SKImageInfo(targetWidth, targetHeight), SKFilterQuality.Low))
                {
                    using (var surface = SKSurface.Create(new SKImageInfo(targetWidth, targetHeight, bitmap.ColorType,
                                                                          bitmap.AlphaType)))
                        using (var canvas = surface.Canvas)
                            using (var paint = new SKPaint {
                                FilterQuality = SKFilterQuality.High
                            })
                            {
                                var kernel = new[]
                                {
                                    -1f, -1f, -1f,
                                    -1f, 16f, -1f,
                                    -1f, -1f, -1f
                                };
                                var kernelSize   = new SKSizeI(3, 3);
                                var kernelOffset = new SKPointI(1, 1);

                                paint.ImageFilter = SKImageFilter.CreateMatrixConvolution(kernelSize, kernel, 0.125f, 0f,
                                                                                          kernelOffset, SKMatrixConvolutionTileMode.Repeat, false);

                                canvas.DrawBitmap(resized, 0, 0, paint);
                                canvas.Flush();

                                using (var fileStream = File.OpenWrite(output))
                                {
                                    surface.Snapshot()
                                    .Encode(SKEncodedImageFormat.Jpeg, Quality)
                                    .SaveTo(fileStream);
                                }
                            }
                }
            }
        }
Exemple #23
0
        /// <inheritdoc />
        public override void Render(SKCanvas canvas, SKPointI basePosition)
        {
            if (Disposed)
            {
                throw new ObjectDisposedException("Folder");
            }

            // Ensure the folder is ready
            if (!Enabled || Path == null)
            {
                return;
            }

            // No point rendering if all children are disabled
            if (!Children.Any(c => c is RenderProfileElement {
                Enabled: true
            }))
Exemple #24
0
        public override HitTestResults HitTest(SKPointI point)
        {
            if (!ScreenRect.Contains(point))
            {
                return(null);
            }

            for (int i = 0; i < MaxNumberOfSkills; ++i)
            {
                SKRect buttonRect = RectForSkill(i);
                buttonRect.Offset(Position.X, Position.Y);
                if (buttonRect.Contains(point))
                {
                    return(new HitTestResults(this, i));
                }
            }
            return(null);
        }
        public void PrepareField(GameplayGameState state, IStateOwner pOwner)
        {
            //likely will need to have stats and stuff abstracted to each Handler.
            state.PlayField.Reset();

            HashSet <SKPointI> usedPositions = new HashSet <SKPointI>();
            //primary count is based on our level.
            int numPrimaries = (int)((Level * 1.33f) + 4);

            for (int i = 0; i < numPrimaries; i++)
            {
                //choose a random primary type.
                var chosentype = TetrisGame.Choose(GetValidPrimaryCombiningTypes());
                LineSeriesPrimaryBlock lsmb = new LineSeriesPrimaryBlock()
                {
                    CombiningIndex = chosentype
                };
                var Dummino = new Nomino()
                {
                };
                Dummino.AddBlock(new Point[] { new Point(0, 0) }, lsmb);
                state.PlayField.Theme.ApplyTheme(Dummino, this, state.PlayField, NominoTheme.ThemeApplicationReason.Normal);
                lsmb.CriticalMass = 4; //TODO: should this be changed?

                int      RandomXPos = TetrisGame.rgen.Next(state.PlayField.ColCount);
                int      RandomYPos = state.PlayField.RowCount - 1 - TetrisGame.rgen.Next(state.PlayField.RowCount / 2);
                SKPointI randomPos  = new SKPointI(RandomXPos, RandomYPos);
                while (usedPositions.Contains(randomPos))
                {
                    int rndXPos = TetrisGame.rgen.Next(state.PlayField.ColCount);
                    int rndYPos = state.PlayField.RowCount - 1 - TetrisGame.rgen.Next(state.PlayField.RowCount / 2);
                    randomPos = new SKPointI(rndXPos, rndYPos);
                }
                state.PlayField.Contents[RandomYPos][RandomXPos] = lsmb;
                PrimaryBlockCount++;
            }
            PrimaryBlockAppearanceState appearstate = new PrimaryBlockAppearanceState(state);

            pOwner.CurrentState = appearstate;
        }
Exemple #26
0
        public static Shape CreateShape(SKPointI point)
        {
            Shape shape;
            int   i = new Random().Next(7);

            if (i == 0)
            {
                shape = new ShapeI(point);
            }
            else if (i == 1)
            {
                shape = new ShapeJ(point);
            }
            else if (i == 2)
            {
                shape = new ShapeL(point);
            }
            else if (i == 3)
            {
                shape = new ShapeO(point);
            }
            else if (i == 4)
            {
                shape = new ShapeS(point);
            }
            else if (i == 5)
            {
                shape = new ShapeT(point);
            }
            else if (i == 6)
            {
                shape = new ShapeZ(point);
            }
            else
            {
                shape = new ShapeJ(point);
            }
            return(shape);
        }
Exemple #27
0
        private SKBitmap CreateBitmap(byte[] design, byte[] colorPalette)
        {
            //Data pata consists from above color palette, 0 - 15 indexed number, 4bits per pixel.
            const int size   = 32;
            var       bitmap = new SKBitmap(size, size, true);

            var pos = new SKPointI(0, 0);

            foreach (var designByte in design)
            {
                // 2 colors per byte, 4 bits per color
                var color1 = CalculateColor(designByte >> 4, colorPalette);   // first 4-bits
                var color2 = CalculateColor(designByte & 0x0F, colorPalette); // last 4-bits

                bitmap.SetPixel(pos.X, pos.Y, color2);
                pos = IncrementPosition(pos, size);

                bitmap.SetPixel(pos.X, pos.Y, color1);
                pos = IncrementPosition(pos, size);
            }

            return(bitmap);
        }
Exemple #28
0
        //saves
        internal HashSet <SKPoint> getTouchAreaRecPoints()
        {
            var touch = new HashSet <SKPoint>();

            var BL = new SKPoint(TouchLocation.X - TouchRadius, TouchLocation.Y - TouchRadius);
            var TR = new SKPoint(TouchLocation.X + TouchRadius, TouchLocation.Y + TouchRadius);

            var BLindex = new SKPointI();
            var TRindex = new SKPointI();

            GridRotation.CellCoordsFromOriginPoint(ref BLindex, BL);
            GridRotation.CellCoordsFromOriginPoint(ref TRindex, TR);

            var upperX = TRindex.X > BLindex.X ? TRindex.X : BLindex.X;
            var lowerX = TRindex.X < BLindex.X ? TRindex.X : BLindex.X;

            var upperY = TRindex.Y > BLindex.Y ? TRindex.Y : BLindex.Y;
            var lowerY = TRindex.Y < BLindex.Y ? TRindex.Y : BLindex.Y;

            var p = new SKPointI();

            for (var i = lowerX; i <= upperX; i++)
            {
                for (var j = lowerY; j <= upperY; j++)
                {
                    p.X = i;
                    p.Y = j;

                    if (SeperatedPoints.ContainsKey(p))
                    {
                        touch.UnionWith(SeperatedPoints[p]);
                    }
                }
            }

            return(touch);
        }
Exemple #29
0
        /// <summary>
        /// Invalidate screen at current position, which in this case means the Windows Forms control that is
        /// at the given position.
        /// </summary>
        /// <param name="pos">Position to invalidate</param>
        public void Invalidate(SKPointI pos)
        {
            if (PhiddleForm.IsDisposed)
            {
                PhiddleForm.Log.Warning("ScreenServiceForms.Invalidate", "Form is allready disposed");
            }

            try
            {
                PhiddleForm.InvokeIfRequired(() =>
                {
                    var control = PhiddleForm.GetChildAtPoint(pos.ToDrawingPoint());

                    if (control != null)
                    {
                        control.Invalidate();
                    }
                });
            }
            catch (System.Exception ex)
            {
                PhiddleForm.Log.Error("ScreenServiceForms.Invalidate", "Failed to invoke control", ex);
            }
        }
Exemple #30
0
        /// <inheritdoc />
        public override void Render(SKCanvas canvas, SKPointI basePosition)
        {
            if (Disposed)
            {
                throw new ObjectDisposedException("Folder");
            }

            // Ensure the folder is ready
            if (!Enabled || !Children.Any(c => c.Enabled) || Path == null)
            {
                return;
            }

            // No point rendering if none of the children are going to render
            if (!Children.Any(c => c is RenderProfileElement renderElement && !renderElement.Timeline.IsFinished))
            {
                return;
            }

            lock (Timeline)
            {
                foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => e.Enabled))
                {
                    baseLayerEffect.BaseProperties?.Update(Timeline);
                    baseLayerEffect.Update(Timeline.Delta.TotalSeconds);
                }

                SKPaint layerPaint = new();
                try
                {
                    SKRectI rendererBounds = SKRectI.Create(0, 0, Bounds.Width, Bounds.Height);
                    foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => e.Enabled))
                    {
                        baseLayerEffect.PreProcess(canvas, rendererBounds, layerPaint);
                    }

                    canvas.SaveLayer(layerPaint);
                    canvas.Translate(Bounds.Left - basePosition.X, Bounds.Top - basePosition.Y);

                    // If required, apply the opacity override of the module to the root folder
                    if (IsRootFolder && Profile.Module.OpacityOverride < 1)
                    {
                        double multiplier = Easings.SineEaseInOut(Profile.Module.OpacityOverride);
                        layerPaint.Color = layerPaint.Color.WithAlpha((byte)(layerPaint.Color.Alpha * multiplier));
                    }

                    // No point rendering if the alpha was set to zero by one of the effects
                    if (layerPaint.Color.Alpha == 0)
                    {
                        return;
                    }

                    // Iterate the children in reverse because the first layer must be rendered last to end up on top
                    for (int index = Children.Count - 1; index > -1; index--)
                    {
                        Children[index].Render(canvas, new SKPointI(Bounds.Left, Bounds.Top));
                    }

                    foreach (BaseLayerEffect baseLayerEffect in LayerEffects.Where(e => e.Enabled))
                    {
                        baseLayerEffect.PostProcess(canvas, rendererBounds, layerPaint);
                    }
                }
                finally
                {
                    canvas.Restore();
                    layerPaint.DisposeSelfAndProperties();
                }

                Timeline.ClearDelta();
            }
        }