예제 #1
0
 private static unsafe void RenderWithClipMask(Effect effect, EffectConfigToken token, RenderArgs dstArgs, RenderArgs srcArgs, Rectangle[] rois, IRenderer <ColorAlpha8> clipMaskRenderer)
 {
     effect.Render(token, dstArgs, srcArgs, rois);
     if (!effect.IsCancelRequested && (clipMaskRenderer != null))
     {
         RectInt32 bounds = RectangleUtil.Bounds(rois).ToRectInt32();
         if (bounds.HasPositiveArea)
         {
             using (ISurface <ColorAlpha8> surface = clipMaskRenderer.UseTileOrToSurface(bounds))
             {
                 int        width        = bounds.Width;
                 int        height       = bounds.Height;
                 int        left         = bounds.Left;
                 int        top          = bounds.Top;
                 int        bottom       = bounds.Bottom;
                 int        stride       = dstArgs.Surface.Stride;
                 int        num8         = srcArgs.Surface.Stride;
                 int        num9         = surface.Stride;
                 ColorBgra *pointAddress = dstArgs.Surface.GetPointAddress(left, top);
                 ColorBgra *bgraPtr2     = srcArgs.Surface.GetPointAddress(left, top);
                 byte *     numPtr       = (byte *)surface.Scan0;
                 for (int i = height; i > 0; i--)
                 {
                     ColorBgra.Underwrite(bgraPtr2, pointAddress, numPtr, width);
                     pointAddress += stride;
                     bgraPtr2     += num8;
                     numPtr       += num9;
                 }
             }
         }
     }
 }
예제 #2
0
        private void AddPlayer(int i, float playerWidth, float playerHeight, float offset)
        {
            Rectangle  r      = RectangleUtil.Float(50 + ((playerWidth + offset) * i), 100, playerWidth, playerHeight);
            PlayerInfo player = new PlayerInfo();

            player.EditBounds = r;
            profile.PlayerData.Add(player);
        }
예제 #3
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);

            mousePos = e.Location;

            if (dragging)
            {
                var players = profile.PlayerData;

                PlayerInfo player = players[draggingIndex];
                Rectangle  p      = player.EditBounds;
                if (draggingScreen == -1)
                {
                    for (int i = 0; i < screens.Length; i++)
                    {
                        UserScreen screen = screens[i];
                        Rectangle  s      = screen.UIBounds;
                        float      pc     = RectangleUtil.PcInside(p, s);

                        // bigger than 60% = major part inside this screen
                        if (pc > 0.6f)
                        {
                            float offset = s.Width * 0.05f;

                            // check if there's space available on this screen
                            var       playas = profile.PlayerData;
                            Rectangle?editor;
                            Rectangle?monitor;
                            GetFreeSpace(i, out editor, out monitor);

                            if (editor != null)
                            {
                                draggingScreenRec    = editor.Value;
                                draggingScreenBounds = monitor.Value;
                                draggingScreen       = i;
                            }
                            break;
                        }
                    }
                }
                else
                {
                    Rectangle s  = screens[draggingScreen].UIBounds;
                    float     pc = RectangleUtil.PcInside(p, s);
                    if (pc < 0.6f)
                    {
                        draggingScreen = -1;
                    }
                }

                p = new Rectangle(mousePos.X + draggingOffset.X, mousePos.Y + draggingOffset.Y, p.Width, p.Height);
                players[draggingIndex].EditBounds = p;

                Invalidate();
            }
        }
예제 #4
0
 public void Execute(ref Canvas canvas, PaintTool paintTool)
 {
     using (var graphics = Graphics.FromImage(canvas.Bitmap))
     {
         _rectangle.Location = RectangleUtil.GetLocation(paintTool.StartPoint, paintTool.EndPoint);
         _rectangle.Size     = RectangleUtil.GetSize(paintTool.StartPoint, paintTool.EndPoint);
         graphics.DrawRectangle(paintTool.Pen, _rectangle);
     }
 }
예제 #5
0
        private static unsafe void RenderWithClipMask(
            Effect effect,
            EffectConfigToken token,
            RenderArgs dstArgs,
            RenderArgs srcArgs,
            Rectangle[] rois,
            IRenderer <ColorAlpha8> clipMaskRenderer)
        {
            // Render the effect
            effect.Render(token, dstArgs, srcArgs, rois);

            if (effect.IsCancelRequested)
            {
                return;
            }

            if (clipMaskRenderer != null)
            {
                RectInt32 bounds = RectangleUtil.Bounds(rois).ToRectInt32();

                if (bounds.HasPositiveArea)
                {
                    // dstArgs = (srcArgs * (1 - clipMask)) + (dstArgs * clipMask)
                    // TODO: optimize, or at least refactor into its own method
                    using (ISurface <ColorAlpha8> clipMask = clipMaskRenderer.UseTileOrToSurface(bounds))
                    {
                        int width  = bounds.Width;
                        int height = bounds.Height;
                        int left   = bounds.Left;
                        int top    = bounds.Top;
                        int bottom = bounds.Bottom;

                        int dstStride      = dstArgs.Surface.Stride;
                        int srcStride      = srcArgs.Surface.Stride;
                        int clipMaskStride = clipMask.Stride;

                        ColorBgra *dstNextRowPtr      = dstArgs.Surface.GetPointAddress(left, top);
                        ColorBgra *srcNextRowPtr      = srcArgs.Surface.GetPointAddress(left, top);
                        byte *     clipMaskNextRowPtr = (byte *)clipMask.Scan0;

                        int rows = height;
                        while (rows > 0)
                        {
                            ColorBgra.Underwrite(srcNextRowPtr, dstNextRowPtr, clipMaskNextRowPtr, width);

                            dstNextRowPtr      = (ColorBgra *)((byte *)dstNextRowPtr + dstStride);
                            srcNextRowPtr      = (ColorBgra *)((byte *)srcNextRowPtr + srcStride);
                            clipMaskNextRowPtr = clipMaskNextRowPtr + clipMaskStride;
                            --rows;
                        }
                    }
                }
            }
        }
예제 #6
0
        private void UpdateScreens()
        {
            if (screens == null)
            {
                screens     = ScreensUtil.AllScreens();
                totalBounds = RectangleUtil.Union(screens);
            }
            else
            {
                UserScreen[] newScreens = ScreensUtil.AllScreens();
                Rectangle    newBounds  = RectangleUtil.Union(newScreens);
                if (newBounds.Equals(totalBounds))
                {
                    return;
                }

                // screens got updated, need to reflect in our window
                screens     = newScreens;
                totalBounds = newBounds;

                // remove all players screens
                List <PlayerInfo> playerData = profile.PlayerData;
                if (playerData != null)
                {
                    for (int i = 0; i < playerData.Count; i++)
                    {
                        PlayerInfo player = playerData[i];
                        player.EditBounds  = GetDefaultBounds(draggingIndex);
                        player.ScreenIndex = -1;
                    }
                }
            }

            screensArea = new RectangleF(10, 50 + Height * 0.2f + 10, Width - 20, Height * 0.5f);
            if (totalBounds.Width > totalBounds.Height)
            {
                // horizontal monitor setup
                scale = screensArea.Width / (float)totalBounds.Width;
                if (totalBounds.Height * scale > screensArea.Height)
                {
                    scale = screensArea.Height / (float)totalBounds.Height;
                }
            }
            else
            {
                // vertical monitor setup
                scale = screensArea.Height / (float)totalBounds.Height;
                if (totalBounds.Width * scale > screensArea.Width)
                {
                    scale = screensArea.Width / (float)totalBounds.Width;
                }
            }

            Rectangle scaledBounds = RectangleUtil.Scale(totalBounds, scale);

            scaledBounds.X = (int)screensArea.X;
            scaledBounds.Y = (int)screensArea.Y;
            //scaledBounds = RectangleUtil.Center(scaledBounds, RectangleUtil.Float(0, this.Height * 0.25f, this.Width, this.Height * 0.7f));

            int minY = 0;

            for (int i = 0; i < screens.Length; i++)
            {
                UserScreen screen = screens[i];

                Rectangle bounds   = RectangleUtil.Scale(screen.MonitorBounds, scale);
                Rectangle uiBounds = new Rectangle(bounds.X, bounds.Y + scaledBounds.Y, bounds.Width, bounds.Height);
                screen.UIBounds = uiBounds;

                minY = Math.Min(minY, uiBounds.X);
            }

            // remove negative monitors
            minY = -minY;
            for (int i = 0; i < screens.Length; i++)
            {
                UserScreen screen = screens[i];

                Rectangle uiBounds = screen.UIBounds;
                uiBounds.X           += minY + scaledBounds.X;
                screen.UIBounds       = uiBounds;
                screen.SwapTypeBounds = RectangleUtil.Float(uiBounds.X, uiBounds.Y, uiBounds.Width * 0.1f, uiBounds.Width * 0.1f);
            }
        }
예제 #7
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            Graphics g = e.Graphics;

#if DEBUG
            //g.FillRectangle(Brushes.Green, playersArea);
            //g.FillRectangle(Brushes.CornflowerBlue, screensArea);
            //g.FillRectangle(Brushes.CornflowerBlue, new RectangleF(0, 0, Width, Height));
#endif

            UpdateScreens();

            for (int i = 0; i < screens.Length; i++)
            {
                UserScreen s = screens[i];
                g.DrawRectangle(Pens.White, s.UIBounds);
                g.DrawRectangle(Pens.White, s.SwapTypeBounds);

                switch (s.Type)
                {
                case UserScreenType.FullScreen:
                    g.DrawImage(Resources.fullscreen, s.SwapTypeBounds);
                    break;

                case UserScreenType.DualHorizontal:
                    g.DrawImage(Resources.horizontal, s.SwapTypeBounds);
                    break;

                case UserScreenType.DualVertical:
                    g.DrawImage(Resources.vertical, s.SwapTypeBounds);
                    break;

                case UserScreenType.FourPlayers:
                    g.DrawImage(Resources._4players, s.SwapTypeBounds);
                    break;

                case UserScreenType.SixteenPlayers:
                    g.DrawImage(Resources._16players, s.SwapTypeBounds);
                    break;
                }
            }

            var players = profile.PlayerData;
            if (players.Count == 0)
            {
                g.DrawString("No Gamepads connected", playerTextFont, Brushes.Red, new PointF(20, 40));
            }
            else
            {
                for (int i = 0; i < players.Count; i++)
                {
                    PlayerInfo info = players[i];
                    Rectangle  s    = info.EditBounds;
                    g.ResetClip();
                    g.Clip = new Region(new RectangleF(s.X, s.Y, s.Width + 1, s.Height + 1));

                    Rectangle gamepadRect = RectangleUtil.ScaleAndCenter(gamepadImg.Size, s);

                    string str  = (i + 1).ToString();
                    SizeF  size = g.MeasureString(str, playerFont);
                    PointF loc  = RectangleUtil.Center(size, s);
                    if (info.IsXInput)
                    {
                        loc.Y -= gamepadRect.Height * 0.1f;
                        GamepadButtonFlags flags = (GamepadButtonFlags)info.GamepadMask;
                        //g.DrawString(flags.ToString(), smallTextFont, Brushes.White, new PointF(loc.X, loc.Y + gamepadRect.Height * 0.01f));

                        g.DrawString((info.GamepadId + 1).ToString(), playerFont, Brushes.White, loc);
                        g.DrawImage(gamepadImg, gamepadRect);
                    }
                    else if (info.IsKeyboardPlayer)
                    {
                        g.DrawImage(keyboardImg, gamepadRect);
                    }
                    else
                    {
                        loc.X = s.X;
                        g.DrawString(info.GamepadName, playerTextFont, Brushes.White, loc);
                        g.DrawImage(genericImg, gamepadRect);
                    }

                    if (info.ScreenIndex != -1)
                    {
                        UserScreen screen = screens[info.ScreenIndex];
                        if ((s.Height + s.Y) - (screen.UIBounds.Height + screen.UIBounds.Y) == -1)
                        {
                            s.Height += 1;
                        }
                        g.Clip = new Region(new RectangleF(s.X, s.Y, s.Width + 1, s.Height + 1));
                        g.DrawRectangle(Pens.Green, s);
                    }
                }
            }
            g.ResetClip();

            if (dragging && draggingScreen != -1)
            {
                g.DrawRectangle(Pens.Red, draggingScreenRec);
            }

            g.DrawString("Gamepads", playerTextFont, Brushes.White, new PointF(10, 10));

            SizeF  dragEachGamepadSize;
            string dragEachGamepad = "Drag each gamepad to a screen";
            dragEachGamepad = StringUtil.WrapString(Width * 0.6f, dragEachGamepad, g, playerTextFont, out dragEachGamepadSize);
            g.DrawString(dragEachGamepad, playerTextFont, Brushes.White, new PointF(Width - dragEachGamepadSize.Width, playersArea.Y));

            SizeF  bottomTextSize;
            string bottomText = "Click on screen's top-left corner to change players on that screen. (4-player only) Right click player to change size";
            bottomText = StringUtil.WrapString(Width - 20, bottomText, g, playerTextFont, out bottomTextSize);
            g.DrawString(bottomText, playerTextFont, Brushes.White, new PointF(10, Height - bottomTextSize.Height - 10));
        }
예제 #8
0
        public void Initialize(UserGameInfo game, GameProfile profile)
        {
            this.profile = profile;
            profile.PlayerData.Clear();// reset profile

            playerFont     = new Font("Segoe UI", 40);
            playerTextFont = new Font("Segoe UI", 18);

            RemoveFlicker();

            float playersWidth = this.Width * 0.5f;

            int   playerCount  = profile.PlayerCount;
            float playerWidth  = (playersWidth * 0.9f) / (float)playerCount;
            float playerHeight = playerWidth * 0.5625f;
            float offset       = (playersWidth * 0.1f) / (float)playerCount;

            playersArea = new RectangleF(50, 100, playersWidth, playerHeight);

            for (int i = 0; i < playerCount; i++)
            {
                Rectangle  r     = new Rectangle((int)(50 + ((playerWidth + offset) * i)), 100, (int)playerWidth, (int)playerHeight);
                PlayerInfo playa = new PlayerInfo();
                playa.editBounds = r;
                profile.PlayerData.Add(playa);
            }

            screens = ScreensUtil.AllScreens();
            Rectangle totalBounds = RectangleUtil.Union(ScreensUtil.AllScreensRec());

            // see if most screens are either vertical or horizontal
            int vertical   = 0;
            int horizontal = 0;

            for (int i = 0; i < screens.Length; i++)
            {
                UserScreen s = screens[i];
                if (s.bounds.Width > s.bounds.Height)
                {
                    horizontal++;
                }
                else
                {
                    vertical++;
                }
            }


            if (horizontal > vertical)
            {
                // horizontal setup
                scale = (this.Width * 0.9f) / (float)totalBounds.Width;
            }
            else
            {
                // vertical setup
                scale = (this.Height * 0.6f) / (float)totalBounds.Height;
                //scale = (this.Width * 0.9f) / (float)totalBounds.Width;
            }

            totalBounds = new Rectangle(
                (int)(totalBounds.X * scale),
                (int)(totalBounds.Y * scale),
                (int)(totalBounds.Width * scale),
                (int)(totalBounds.Height * scale));
            int offsetViewsX = totalBounds.X;
            int offsetViewsY = totalBounds.Y;

            totalBounds = RectangleUtil.Center(totalBounds, new Rectangle(0, (int)(this.Height * 0.25f), this.Width, (int)(this.Height * 0.7f)));

            for (int i = 0; i < screens.Length; i++)
            {
                UserScreen screen = screens[i];

                Rectangle s      = screen.bounds;
                int       width  = (int)(s.Width * scale);
                int       height = (int)(s.Height * scale);
                int       x      = (int)(s.X * scale);
                int       y      = (int)(s.Y * scale);
                screen.bounds       = new Rectangle(x + totalBounds.X - offsetViewsX, y + totalBounds.Y - offsetViewsY, width, height);
                screen.swapTypeRect = new Rectangle(screen.bounds.X, screen.bounds.Y, (int)(screen.bounds.Width * 0.1f), (int)(screen.bounds.Width * 0.1f));
            }
        }
예제 #9
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            Graphics g = e.Graphics;

            for (int i = 0; i < screens.Length; i++)
            {
                UserScreen s = screens[i];
                g.DrawRectangle(Pens.White, s.bounds);
                g.DrawRectangle(Pens.White, s.swapTypeRect);


                switch (s.type)
                {
                case UserScreenType.FullScreen:
                    g.DrawImage(Resources.fullscreen, s.swapTypeRect);
                    break;

                case UserScreenType.DualHorizontal:
                    g.DrawImage(Resources.horizontal, s.swapTypeRect);
                    break;

                case UserScreenType.DualVertical:
                    g.DrawImage(Resources.vertical, s.swapTypeRect);
                    break;

                case UserScreenType.FourPlayers:
                    g.DrawImage(Resources._4players, s.swapTypeRect);
                    break;
                }
            }

            var players = profile.PlayerData;

            for (int i = 0; i < players.Count; i++)
            {
                PlayerInfo info = players[i];
                Rectangle  s    = info.editBounds;

                if (info.screenIndex == -1)
                {
                    g.DrawRectangle(Pens.White, s);
                }
                else
                {
                    g.DrawRectangle(Pens.Green, s);
                }

                string str  = (i + 1).ToString();
                SizeF  size = g.MeasureString(str, playerFont);
                PointF loc  = RectangleUtil.Center(size, s);
                g.DrawString((i + 1).ToString(), playerFont, Brushes.White, loc);
            }

            if (dragging && draggingScreen != -1)
            {
                g.DrawRectangle(Pens.Red, draggingScreenRec);
            }

            g.DrawString("Drag each player to\ntheir respective screen", playerTextFont, Brushes.White, new PointF(470, 100));
            g.DrawString("Players", playerTextFont, Brushes.White, new PointF(50, 50));

            g.DrawString("Right click player to change size", playerTextFont, Brushes.White, new PointF(20, 450));
            g.DrawString("Click on screen's top-left corner to change players on that screen", playerTextFont, Brushes.White, new PointF(20, 490));
            //g.DrawRectangle(Pens.Red, playersArea.X, playersArea.Y, playersArea.Width, playersArea.Height);
        }
예제 #10
0
 public virtual void SetShape(Point from, Point to)
 {
     Container = RectangleUtil.FromPoint(from, to);
 }
예제 #11
0
        public void Update(GameTime gameTime)
        {
            var searchArea = Target.Area;
            var target     = Target.Area;

            searchArea.Inflate(target.Width, target.Height);
            var goods = new List <Rectangle>();

            foreach (var p in content.CurrnetMap.TilesInArea(searchArea))
            {
                goods.Add(p.Area);
            }
            RectangleUtil.PushBack(ref target, goods.ToArray());
            var newpos = new Vector2(target.X, target.Y);

            if (newpos != new Vector2((int)Target.Position.X, (int)Target.Position.Y))
            {
                Target.Position = newpos;
            }

            int speed = 128;
            var delta = Target.Position;

            if (content.Input["player.sprint"])
            {
                speed *= 5;
                Target.AnimationSpeed = 2.0;
            }
            else
            {
                Target.AnimationSpeed = 1.0;
            }

            if (content.Input["player.up"])
            {
                delta.Y -= speed * (float)gameTime.ElapsedGameTime.TotalSeconds;
            }

            if (content.Input["player.down"])
            {
                delta.Y += speed * (float)gameTime.ElapsedGameTime.TotalSeconds;
            }

            if (content.Input["player.left"])
            {
                delta.X -= speed * (float)gameTime.ElapsedGameTime.TotalSeconds;
            }

            if (content.Input["player.right"])
            {
                delta.X += speed * (float)gameTime.ElapsedGameTime.TotalSeconds;
            }

            var diff = Target.Position - delta;

            if (diff.X < 0)
            {
                lastDir = "right";
            }
            if (diff.X > 0)
            {
                lastDir = "left";
            }
            if (diff.Y < 0)
            {
                lastDir = "down";
            }
            if (diff.Y > 0)
            {
                lastDir = "up";
            }

            if (content.CurrnetMap.IsOnMap(new Rectangle((int)delta.X, (int)delta.Y,
                                                         Target.Area.Width, Target.Area.Height)))
            {
                if (delta != Target.Position)
                {
                    Target.Position = delta;
                    Target.SetAnimation("move_" + lastDir);
                }
                else
                {
                    Target.SetAnimation("look_" + lastDir);
                }
            }
            else
            {
                Target.SetAnimation("look_" + lastDir);
            }
        }
예제 #12
0
        public override void Initialize(UserGameInfo game, GameProfile profile)
        {
            base.Initialize(game, profile);

            canProceed = false;

            playerFont     = new Font("Segoe UI", 40);
            playerTextFont = new Font("Segoe UI", 18);

            RemoveFlicker();

            float playersWidth = this.Width * 0.5f;

            int   playerCount  = profile.PlayerCount;
            float playerWidth  = (playersWidth * 0.9f) / (float)playerCount;
            float playerHeight = playerWidth * 0.5625f;
            float offset       = (playersWidth * 0.1f) / (float)playerCount;

            playersArea = new RectangleF(50, 100, playersWidth, playerHeight);

            screens = ScreensUtil.AllScreens();
            Rectangle totalBounds = RectangleUtil.Union(ScreensUtil.AllScreensRec());

            // see if most screens are either vertical or horizontal
            int vertical   = 0;
            int horizontal = 0;

            for (int i = 0; i < screens.Length; i++)
            {
                UserScreen s = screens[i];
                if (s.bounds.Width > s.bounds.Height)
                {
                    horizontal++;
                }
                else
                {
                    vertical++;
                }
            }


            if (horizontal > vertical)
            {
                // horizontal setup
                scale = (this.Width * 0.9f) / (float)totalBounds.Width;
            }
            else
            {
                // vertical setup
                scale = (this.Height * 0.6f) / (float)totalBounds.Height;
                //scale = (this.Width * 0.9f) / (float)totalBounds.Width;
            }

            totalBounds = new Rectangle(
                (int)(totalBounds.X * scale),
                (int)(totalBounds.Y * scale),
                (int)(totalBounds.Width * scale),
                (int)(totalBounds.Height * scale));
            int offsetViewsX = totalBounds.X;
            int offsetViewsY = totalBounds.Y;

            totalBounds = RectangleUtil.Center(totalBounds, new Rectangle(0, (int)(this.Height * 0.25f), this.Width, (int)(this.Height * 0.7f)));

            for (int i = 0; i < screens.Length; i++)
            {
                UserScreen screen = screens[i];

                Rectangle s      = screen.bounds;
                int       width  = (int)(s.Width * scale);
                int       height = (int)(s.Height * scale);
                int       x      = (int)(s.X * scale);
                int       y      = (int)(s.Y * scale);
                screen.bounds       = new Rectangle(x + totalBounds.X - offsetViewsX, y + totalBounds.Y - offsetViewsY, width, height);
                screen.swapTypeRect = new Rectangle(screen.bounds.X, screen.bounds.Y, (int)(screen.bounds.Width * 0.1f), (int)(screen.bounds.Width * 0.1f));
            }

            List <PlayerInfo> playerData = profile.PlayerData;

            if (playerData.Count == 0)
            {
                for (int i = 0; i < playerCount; i++)
                {
                    AddPlayer(i, playerWidth, playerHeight, offset);
                }
            }
            else
            {
                for (int i = 0; i < playerCount; i++)
                {
                    if (i >= playerData.Count)
                    {
                        // additional players
                        AddPlayer(i, playerWidth, playerHeight, offset);
                    }
                    else
                    {
                        PlayerInfo info   = playerData[i];
                        Rectangle  s      = info.MonitorBounds;
                        int        width  = (int)(s.Width * scale);
                        int        height = (int)(s.Height * scale);
                        int        x      = (int)(s.X * scale);
                        int        y      = (int)(s.Y * scale);
                        info.EditBounds = new Rectangle(x, y, width, height);
                    }
                }
            }
        }