示例#1
0
        private void OnMouseMove(float scaleX, float scaleY)
        {
            int x1, y1, x2, y2;

            GetBorders(out x1, out y1, out x2, out y2);

            bool mouseMove =
                (_mouseX != (_mouseX = (int)((Mouse.X - x1) / scaleX))) |
                (_mouseY != (_mouseY = (int)((Mouse.Y - y1) / scaleY)));

            if (mouseMove)
            {
                MouseButton  buttons = MouseButton.None;
                TkMouseState mouse   = Mouse.GetState();

                if (mouse.IsButtonDown(TkMouseButton.Left))
                {
                    buttons |= MouseButton.Left;
                }
                if (mouse.IsButtonDown(TkMouseButton.Right))
                {
                    buttons |= MouseButton.Right;
                }
                if (buttons != MouseButton.None)
                {
                    TopScreen?.MouseDrag(new ScreenEventArgs(_mouseX, _mouseY, buttons));
                }

                TopScreen?.MouseMove(new ScreenEventArgs(_mouseX, _mouseY, buttons));
            }
        }
示例#2
0
        private void OnKeyboardDown(object sender, KeyboardEventArgs args)
        {
            if (args[KeyModifier.Control, Key.F5])
            {
                string filename = Common.CaptureFilename;
                using (GifFile file = new GifFile(Runtime.Bitmap))
                    using (FileStream fs = new FileStream(filename, FileMode.Create, FileAccess.Write))
                    {
                        byte[] output = file.GetBytes();
                        fs.Write(output, 0, output.Length);
                        Runtime.Log($"Screenshot saved: {filename}");
                    }
                return;
            }

            if (args[KeyModifier.Control, Key.F6] && Game.Started)
            {
                string filename = Common.CaptureFilename;
                using (IBitmap tilesPicture = Map.Instance[0, 0, Map.WIDTH, Map.HEIGHT].ToBitmap())
                    using (GifFile file = new GifFile(tilesPicture))
                        using (FileStream fs = new FileStream(filename, FileMode.Create, FileAccess.Write))
                        {
                            byte[] output = file.GetBytes();
                            fs.Write(output, 0, output.Length);
                            Runtime.Log($"Screenshot saved: {filename}");
                        }
                return;
            }

            TopScreen?.KeyDown(args);
        }
示例#3
0
 private void OnMouseMove(object sender, ScreenEventArgs args)
 {
     if (args.Buttons != MouseButton.None)
     {
         TopScreen?.MouseDrag(args);
     }
     TopScreen?.MouseMove(args);
 }
示例#4
0
        private void OnKeyDown(object sender, TkKeyArgs args)
        {
            _keyModifier = KeyModifier.None;
            if (args.Control)
            {
                _keyModifier |= KeyModifier.Control;
            }
            if (args.Shift)
            {
                _keyModifier |= KeyModifier.Shift;
            }
            if (args.Alt)
            {
                _keyModifier |= KeyModifier.Alt;
            }

            if (_keyModifier == KeyModifier.Alt && args.Key == TkKey.Enter)
            {
                if (WindowState == TkWinState.Fullscreen)
                {
                    Console.WriteLine("Windowed mode");
                    WindowState = _previousState;
                    return;
                }
                Console.WriteLine("Fullscreen mode");
                _previousState = WindowState;
                WindowState    = TkWinState.Fullscreen;
                return;
            }

            if (_keyModifier == KeyModifier.Control && args.Key == TkKey.F5)
            {
                string filename = Common.CaptureFilename;
                using (CivOne.GFX.ImageFormats.GifFile file = new CivOne.GFX.ImageFormats.GifFile(_canvas))
                    using (FileStream fs = new FileStream(filename, FileMode.Create, FileAccess.Write))
                    {
                        byte[] output = file.GetBytes();
                        fs.Write(output, 0, output.Length);
                        Console.WriteLine($"Screenshot saved: {filename}");
                    }
                return;
            }

            if (TopScreen == null)
            {
                return;
            }
            KeyboardEventArgs KeyboardEventArgs = ConvertKeyboardEvents(args);

            if (KeyboardEventArgs == null)
            {
                return;
            }
            TopScreen.KeyDown(KeyboardEventArgs);
        }
示例#5
0
        private void OnKeyboardDown(object sender, KeyboardEventArgs args)
        {
            if (args[KeyModifier.Control, Key.F5])
            {
                string filename = Common.CaptureFilename;
                if (Runtime.Layers == null)
                {
                    return;
                }
                using (IBitmap bitmap = new Picture(CanvasWidth, CanvasHeight, Common.TopScreen.Palette.Copy()))
                {
                    bitmap.Palette[0] = Colour.Black;
                    if (Common.HasAttribute <Modal>(TopScreen))
                    {
                        bitmap.AddLayer(TopScreen);
                    }
                    else
                    {
                        Runtime.Layers.ToList().ForEach(x => bitmap.AddLayer(x));
                    }

                    using (GifFile file = new GifFile(bitmap))
                        using (FileStream fs = new FileStream(filename, FileMode.Create, FileAccess.Write))
                        {
                            byte[] output = file.GetBytes();
                            fs.Write(output, 0, output.Length);
                            Runtime.Log($"Screenshot saved: {filename}");
                        }
                }
                return;
            }

            if (args[KeyModifier.Control, Key.F6] && Game.Started)
            {
                string filename = Common.CaptureFilename;
                using (IBitmap tilesPicture = Map.Instance[0, 0, Map.WIDTH, Map.HEIGHT].ToBitmap())
                    using (GifFile file = new GifFile(tilesPicture))
                        using (FileStream fs = new FileStream(filename, FileMode.Create, FileAccess.Write))
                        {
                            byte[] output = file.GetBytes();
                            fs.Write(output, 0, output.Length);
                            Runtime.Log($"Screenshot saved: {filename}");
                        }
                return;
            }

            TopScreen?.KeyDown(args);
        }
示例#6
0
        protected override void OnKeyPress(TkKeyPressArgs args)
        {
            if (TopScreen == null)
            {
                return;
            }
            char keyChar = (char)args.KeyChar;

            if (keyChar == '.' || keyChar == ',')
            {
                TopScreen.KeyDown(new KeyboardEventArgs(keyChar));
            }
            if (char.IsLetter(keyChar))
            {
                TopScreen.KeyDown(new KeyboardEventArgs(char.ToUpper((char)args.KeyChar), _keyModifier));
            }
        }
示例#7
0
        private void OnMouseUp(object sender, TkMouseArgs args)
        {
            if (TopScreen == null)
            {
                return;
            }

            MouseButton buttons = MouseButton.None;

            if (args.Mouse.IsButtonUp(TkMouseButton.Left) && (_mouseButtons & MouseButton.Left) > 0)
            {
                buttons |= MouseButton.Left;
            }
            if (args.Mouse.IsButtonUp(TkMouseButton.Right) && (_mouseButtons & MouseButton.Right) > 0)
            {
                buttons |= MouseButton.Right;
            }
            TopScreen.MouseUp(new ScreenEventArgs(_mouseX, _mouseY, buttons));
        }
示例#8
0
        private void OnMouseDown(object sender, TkMouseArgs args)
        {
            if (TopScreen == null)
            {
                return;
            }

            MouseButton buttons = MouseButton.None;

            if (args.Mouse.IsButtonDown(TkMouseButton.Left))
            {
                buttons |= MouseButton.Left;
            }
            if (args.Mouse.IsButtonDown(TkMouseButton.Right))
            {
                buttons = MouseButton.Right;
            }
            _mouseButtons = buttons;
            TopScreen.MouseDown(new ScreenEventArgs(_mouseX, _mouseY, buttons));
        }
示例#9
0
 private void OnMouseDown(object sender, ScreenEventArgs args) => TopScreen?.MouseDown(args);
示例#10
0
 private void OnMouseUp(object sender, ScreenEventArgs args)
 {
     TopScreen?.MouseUp(args);
 }