SadConsole.Input.MouseInfo.Fill C# (CSharp) Method

Fill() public method

Sets the WorldLocation and ConsoleLocation properties based on the cell size of the provided console. If absolute positioning is used on the console, then the properties will represent pixels.
This method alters the data of the mouse information based on the provided console. It
public Fill ( IConsole data ) : void
data IConsole The console to get the data from.
return void
        public void Fill(IConsole data)
        {
            if (data.UsePixelPositioning)
            {
                WorldLocation.X = ScreenLocation.X - data.Position.X;
                WorldLocation.Y = ScreenLocation.Y - data.Position.Y;
                ConsoleLocation = WorldLocation.WorldLocationToConsole(data.TextSurface.Font.Size.X, data.TextSurface.Font.Size.Y);

                if (WorldLocation.X < 0)
                    ConsoleLocation.X -= 1;
                if (WorldLocation.Y < 0)
                    ConsoleLocation.Y -= 1;
            }
            else
            {
                WorldLocation = ScreenLocation.WorldLocationToConsole(data.TextSurface.Font.Size.X, data.TextSurface.Font.Size.Y);
                ConsoleLocation = new Point(WorldLocation.X - data.Position.X, WorldLocation.Y - data.Position.Y);
            }

            //TODO: Need to translate mouse coords by the render transform used by the console!!

            // If the mouse is on a console, then we need to fill out the mouse information with the console information.
            if (ConsoleLocation.X >= 0 && ConsoleLocation.X <= data.TextSurface.RenderArea.Width - 1 &&
                ConsoleLocation.Y >= 0 && ConsoleLocation.Y <= data.TextSurface.RenderArea.Height - 1)
            {
                ConsoleLocation = new Point(ConsoleLocation.X + data.TextSurface.RenderArea.Left, ConsoleLocation.Y + data.TextSurface.RenderArea.Top);
                Cell = data.TextSurface.Cells[ConsoleLocation.Y * data.TextSurface.RenderArea.Width + ConsoleLocation.X];
                Console = data;

                // Other console previously had mouse, we'll properly tell it that it has loss it.
                if (Engine.LastMouseConsole != data)
                {
                    if (Engine.LastMouseConsole != null)
                    {
                        var info = this.Clone();
                        var oldConsole = Engine.LastMouseConsole;
                        Engine.LastMouseConsole = data;

                        if (oldConsole is Console)
                        {
                            ((Console)oldConsole).SkipMouseDataFill = true;
                            oldConsole.ProcessMouse(info);
                            ((Console)oldConsole).SkipMouseDataFill = false;
                        }
                        else
                            oldConsole.ProcessMouse(info);
                    }
                    else
                        Engine.LastMouseConsole = data;
                }
            }
        }

Usage Example

        public bool HandlerMouse(IConsole console, MouseInfo info)
        {
            if (console.IsVisible && console.CanUseMouse)
            {
                info.Fill(console);

                bool doDrag = (info.LeftButtonDown && CanMoveWithLeftButton) || (info.RightButtonDown && CanMoveWithRightButton);

                if (info.Console == console && doDrag)
                {
                    // Mouse just went down on us.
                    if (!_mouseDown)
                    {
                        _mouseDown             = true;
                        _mouseLastLocation     = new Point(info.ConsoleLocation.X, info.ConsoleLocation.Y);
                        console.ExclusiveFocus = true;
                    }
                    else
                    {
                        // Mouse has been down, still is
                        Point currentLocation = new Point(info.ConsoleLocation.X, info.ConsoleLocation.Y);

                        if (currentLocation != _mouseLastLocation)
                        {
                            Rectangle viewport = console.TextSurface.RenderArea;

#if SFML
                            viewport.Left += _mouseLastLocation.X - currentLocation.X;
                            viewport.Top  += _mouseLastLocation.Y - currentLocation.Y;
#elif MONOGAME
                            viewport.X += _mouseLastLocation.X - currentLocation.X;
                            viewport.Y += _mouseLastLocation.Y - currentLocation.Y;
#endif
                            _mouseLastLocation = currentLocation;

                            console.TextSurface.RenderArea = viewport;
                        }
                    }

                    return(true);
                }

                if (!doDrag && _mouseDown)
                {
                    console.ExclusiveFocus = false;
                    _mouseDown             = false;
                }
            }

            return(false);
        }
All Usage Examples Of SadConsole.Input.MouseInfo::Fill