Esempio n. 1
0
 internal Channel(Svt.Network.ServerConnection connection, int id, VideoMode videoMode)
 {
     ID = id;
     VideoMode = videoMode;
     Connection = connection;
     CG = new CGManager(this);
 }
Esempio n. 2
0
 /// <summary>
 /// Initializes a new instance of the GraphicsPresenterX class.
 /// </summary>
 /// <param name="dest">Pointer to destination bitmap.</param>
 /// <param name="videoMode">VideoMode instance describing the video mode.</param>
 public GraphicsPresenterX(IntPtr dest, VideoMode videoMode)
     : base(dest, videoMode)
 {
     unsafe
     {
         this.planes = new byte *[4];
         byte *srcPtr = (byte *)videoMode.VideoRam.ToPointer();
         this.planes[0] = srcPtr + VideoMode.PlaneSize * 0;
         this.planes[1] = srcPtr + VideoMode.PlaneSize * 1;
         this.planes[2] = srcPtr + VideoMode.PlaneSize * 2;
         this.planes[3] = srcPtr + VideoMode.PlaneSize * 3;
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Constructor method
        /// </summary>
        public GameDisplay()
        {
            VideoMode mode = new VideoMode(380, 670);

            window = new RenderWindow(mode, "Yahtzee");

            window.Closed             += Window_Closed;
            window.KeyPressed         += Window_KeyPressed;
            window.MouseButtonPressed += Window_MouseButtonPressed;

            ScoreCard = new ScoreLinkedList();
            newRound  = new Dice();
        }
Esempio n. 4
0
        private static void Initialize()
        {
            var contextSettings = new ContextSettings {
                DepthBits = 24
            };
            var vidMode = new VideoMode(640, 480);

            window = new RenderWindow(vidMode, "Map Scroller", Styles.Close | Styles.Titlebar, contextSettings);
            window.SetActive();
            window.SetKeyRepeatEnabled(false);
            window.Closed += (sender, args) => ShutDown();

            map = new MapScreen();
        }
Esempio n. 5
0
        public void Start(uint width, uint height, string title)
        {
            var mode = new VideoMode(width, height);

            this.title = title;

            Window  = new RenderWindow(mode, title, Styles.Close);
            RStates = new RenderStates(RenderStates.Default);

            Window.Closed  += Window_Closed;
            Window.Resized += Window_Resized;

            Window.SetVerticalSyncEnabled(true);

            SetActiveGameState(GameState.MainMenu);
            GameState.MainMenu.Show();

            var frametimer = new Stopwatch();

            while (Window.IsOpen())
            {
                frametimer.Restart();

                Window.DispatchEvents();

                activeGameState.Update(Frametime);
                UpdateStateTexturePos();

                Window.Clear(Color.Black);
                stateTexture.Clear(BackgroundColor);

                activeGameState.Draw(stateTexture, RStates);

                stateTexture.Display();
                var sprite = new Sprite(stateTexture.Texture);
                sprite.Position = stateTexPos;
                sprite.Origin   = stateTexOrigin;
                sprite.Scale    = stateTexScale;

                sprite.Draw(Window, RStates);

                Window.Display();

                frametimer.Stop();
                Frametime = (float)frametimer.Elapsed.TotalMilliseconds;
                Window.SetTitle(String.Format("{0} ({1:00.0} ms)", title, Frametime));
            }

            GameState.Ingame.Close();
        }
Esempio n. 6
0
        private void LoadWindow()
        {
            // Determine settings
            var vmode = new VideoMode(
                (uint)Settings.ReadInt("Video", "ResX", 1024),
                (uint)Settings.ReadInt("Video", "ResY", 600),
                24);
            bool fscreen = Settings.ReadInt("Video", "Fullscreen", 0) == 1;
            bool vsync   = Settings.ReadInt("Video", "VSync", 1) == 1;

            // Setup the new window
            window = new RenderWindow(vmode, "FTL: Overdrive", fscreen ? Styles.Fullscreen : Styles.Close, new ContextSettings(24, 8, 8));
            window.SetVisible(true);
            window.SetVerticalSyncEnabled(vsync);
            window.MouseMoved          += new EventHandler <MouseMoveEventArgs>(window_MouseMoved);
            window.Closed              += new EventHandler(window_Closed);
            window.MouseButtonPressed  += new EventHandler <MouseButtonEventArgs>(window_MouseButtonPressed);
            window.MouseButtonReleased += new EventHandler <MouseButtonEventArgs>(window_MouseButtonReleased);
            window.KeyPressed          += new EventHandler <KeyEventArgs>(window_KeyPressed);
            window.KeyReleased         += new EventHandler <KeyEventArgs>(window_KeyReleased);
            window.TextEntered         += new EventHandler <TextEventArgs>(window_TextEntered);

            // Init UI
            Canvas = new UI.Canvas();
            var screenrect = Util.ScreenRect(window.Size.X, window.Size.Y, 1.77778f);

            Canvas.X      = screenrect.Left;
            Canvas.Y      = screenrect.Top;
            Canvas.Width  = screenrect.Width;
            Canvas.Height = screenrect.Height;

            // Load icon
            using (var bmp = new System.Drawing.Bitmap(Resource("img/exe_icon.bmp")))
            {
                byte[] data = new byte[bmp.Width * bmp.Height * 4];
                int    i    = 0;
                for (int y = 0; y < bmp.Height; y++)
                {
                    for (int x = 0; x < bmp.Width; x++)
                    {
                        var c = bmp.GetPixel(x, y);
                        data[i++] = c.R;
                        data[i++] = c.G;
                        data[i++] = c.B;
                        data[i++] = c.A;
                    }
                }
                window.SetIcon((uint)bmp.Width, (uint)bmp.Height, data);
            }
        }
Esempio n. 7
0
        public virtual string GetModeString(VideoMode m)
        {
            StringBuffer sb = new StringBuffer();

            sb.Append(m.Width);
            sb.Append('x');
            sb.Append(m.Height);
            sb.Append('x');
            sb.Append(m.GetBitDepth());
            sb.Append('@');
            sb.Append(m.RefreshRate);
            sb.Append("Hz");
            return(sb.ToString());
        }
Esempio n. 8
0
        static void Main(string[] args)
        {
            int    width  = 640;
            int    height = 380;
            string image  = "Images\\MultipleFracture.png";

            VideoMode    videoMode    = new VideoMode((uint)width, (uint)height);
            RenderWindow renderWindow = new RenderWindow(videoMode, "Hull generator test");

            GameResources resources = new GameResources("C:\\Users\\Dmitry\\Documents\\GitHub\\TileEngineSfml\\TileEngineSfmlCs\\TileEngineSfmlMapEditor\\Resources");

            GameResources.Instance = resources;
            ResourceEntry entry = resources.GetEntry(image);

            Stream fs = resources.CopyStream(entry);

            Texture texture = new Texture(fs);
            Sprite  sprite  = new Sprite(texture);

            fs.Close();
            fs.Dispose();

            Icon icon = new Icon(image);

            Debug.WriteLine("Generating hulls...");

            List <Polygon> hulls = HullGenerator.GetConvexHulls(icon);

            Debug.WriteLine("Rendering loop starts");

            View view = renderWindow.GetView();

            view.Center = new Vector2f(-8, 0);
            view.Size   = new Vector2f(128, (uint)(128.0f * height / width));
            renderWindow.SetView(view);

            while (renderWindow.IsOpen)
            {
                renderWindow.DispatchEvents();
                renderWindow.Clear();
                renderWindow.Draw(sprite);

                foreach (var polygon in hulls)
                {
                    DrawPolygon(renderWindow, polygon);
                }

                renderWindow.Display();
            }
        }
Esempio n. 9
0
    public static unsafe VideoMode[] GetVideoModes(Monitor monitor)
    {
        int count;
        var array = glfwGetVideoModes(monitor.Ptr, &count);
        var modes = new VideoMode[count];
        var size  = Marshal.SizeOf(typeof(VideoMode));

        for (int i = 0; i < count; ++i)
        {
            var ptr = Marshal.ReadIntPtr(array, i * size);
            modes[i] = (VideoMode)Marshal.PtrToStructure(ptr, typeof(VideoMode));
        }
        return(modes);
    }
Esempio n. 10
0
        public Render([NotNull] Config config)
        {
            this.config = config;
            videoMode   = new VideoMode(512, 320);
            sprites     = new List <Sprite>();
            collisions  = new List <RectangleShape>();

            OnCreate  += Render_OnCreate;
            OnStart   += Render_OnStart;
            OnUpdate  += Render_OnUpdate;
            OnDestroy += Render_OnDestroy;

            current = this;
        }
Esempio n. 11
0
 /// <summary>
 /// Creates the window.
 /// </summary>
 /// <param name="mode">Video mode to use.</param>
 /// <param name="title">Title of the window.</param>
 /// <param name="style">Window style (Resize | Close by default).</param>
 /// <param name="settings">Creation parameters.</param>
 public RenderWindow(VideoMode mode, string title, Styles style, ContextSettings settings)
     : base(IntPtr.Zero, 0)
 {
     // Copy the string to a null-terminated UTF-32 byte array
     byte[] titleAsUtf32 = Encoding.UTF32.GetBytes(title + '\0');
     unsafe
     {
         fixed(byte *titlePtr = titleAsUtf32)
         {
             CPointer = sfRenderWindow_createUnicode(mode, (IntPtr)titlePtr, style, ref settings);
         }
     }
     Initialize();
 }
Esempio n. 12
0
        public virtual string GetModeString(VideoMode m)
        {
            StringBuffer sb = new StringBuffer();

            sb.Append(m.GetWidth());
            sb.Append('x');
            sb.Append(m.GetHeight());
            sb.Append('x');
            sb.Append(m.GetBitsPerPixel());
            sb.Append('@');
            sb.Append(m.GetFrequency());
            sb.Append("Hz");
            return(sb.ToString());
        }
Esempio n. 13
0
        public void Run()
        {
            var mode = new VideoMode(1600, 900);

            view = new View(new Vector2f(mode.Width / 2, mode.Height / 2), new Vector2f(mode.Width, mode.Height));

            window = new RenderWindow(mode, "Particle Simulation");

            window.SetView(view);
            window.KeyPressed += Window_KeyPressed;

            new DragDropController(view, window);
            new ZoomController(view, window);
        }
Esempio n. 14
0
        public void StartLocalVideo(VideoMode videoMode)
        {
            if (_localVideoSamplingTask != null && !_localVideoSamplingTask.IsCompleted && _localVideoSamplingCancelTokenSource != null)
            {
                _localVideoSamplingCancelTokenSource.Cancel();
            }

            var videoSampler = new MFVideoSampler();

            videoSampler.Init(videoMode.DeviceIndex, VideoSubTypesEnum.RGB24, videoMode.Width, videoMode.Height);
            //videoSampler.InitFromFile();
            //_audioChannel = new AudioChannel();

            _localVideoSamplingCancelTokenSource = new CancellationTokenSource();
            var cancellationToken = _localVideoSamplingCancelTokenSource.Token;

            _localVideoSamplingTask = Task.Run(() => SampleWebCam(videoSampler, videoMode, _localVideoSamplingCancelTokenSource));

            _localAudioSamplingTask = Task.Factory.StartNew(() =>
            {
                Thread.CurrentThread.Name = "audsampler_" + videoMode.DeviceIndex;

                while (!_stop && !cancellationToken.IsCancellationRequested)
                {
                    byte[] audioSample = null;
                    int result         = videoSampler.GetAudioSample(ref audioSample);

                    if (result == NAudio.MediaFoundation.MediaFoundationErrors.MF_E_HW_MFT_FAILED_START_STREAMING)
                    {
                        logger.Warn("An audio sample could not be acquired from the local source. Check that it is not already in use.");
                        //OnLocalVideoError("A sample could not be acquired from the local webcam. Check that it is not already in use.");
                        break;
                    }
                    else if (result != 0)
                    {
                        logger.Warn("An audio sample could not be acquired from the local source. Check that it is not already in use. Error code: " + result);
                        //OnLocalVideoError("A sample could not be acquired from the local webcam. Check that it is not already in use. Error code: " + result);
                        break;
                    }
                    else if (audioSample != null)
                    {
                        if (_audioChannel != null)
                        {
                            _audioChannel.AudioSampleReceived(audioSample, 0);
                        }
                    }
                }
            }, cancellationToken);
        }
Esempio n. 15
0
        private static void _initFrameBuffers(VideoMode mode, ushort lines, bool noFbClear)
        {
            Lines = lines;
            Width = (ushort)VideoModeHelpers.ModeWidthTable[(int)mode];

            if (noFbClear)
            {
                return;
            }

            //clean both frames with black color
            FillRect(0, 0, Width, Lines, 0xF0);
//            arvid_fill_rect(0, 0, 0, ap.fbWidth, ap.lines, 0);
//            arvid_fill_rect(1, 0, 0, ap.fbWidth, ap.lines, 0);
        }
Esempio n. 16
0
        public bool SetVideoMode(VideoMode mode)
        {
            if (mode == VideoMode)
            {
                return(false);
            }

            Clear();
            ReleaseCaches();
            FreeGraphics();

            Init(mode);

            return(true);
        }
Esempio n. 17
0
        public void Init(VideoMode mode)
        {
            VideoMode = mode;
            if (mode == VideoMode.CGA)
            {
                InitializeCGA();
            }
            else
            {
                InitializeVGA();
            }

            CreateCaches();
            CreateGraphics();
        }
Esempio n. 18
0
        public void Init()
        {
            // Window initialization
            VideoMode videoMode = new VideoMode(ScreenSize.X, ScreenSize.Y);

            window = new RenderWindow(videoMode, "P1");

            // Grid initialization
            grid = new Grid();
            grid.Init();

            // Key Binding
            window.KeyPressed         += grid.HandleKeyPressed;
            window.MouseButtonPressed += grid.MousePressed; // <- Ho he afegit jo
        }
Esempio n. 19
0
        private static IntPtr GetHandleWindow(VideoMode videoMode)
        {
            var cn = "test" + new Random().Next(0, 1000); // tmp

            var hInstance = new IntPtr(Kernel.GetModuleHandle(null));

            WNDCLASSEX wc = new WNDCLASSEX()
            {
                cbSize        = Marshal.SizeOf(typeof(WNDCLASSEX)),
                style         = 0,
                lpfnWndProc   = (int)Marshal.GetFunctionPointerForDelegate(myWndProcDelegate),
                cbClsExtra    = 0,
                cbWndExtra    = 0,
                hInstance     = hInstance,
                hIcon         = IntPtr.Zero,
                hCursor       = IntPtr.Zero,
                hbrBackground = new IntPtr(COLOR_BACKGROUND),
                lpszMenuName  = null,
                lpszClassName = cn,
                hIconSm       = IntPtr.Zero
            };

            if (RegisterClassEx(ref wc) == 0)
            {
                MessageBox(IntPtr.Zero, "Window Registration Failed!", "Error!",
                           MB_ICONEXCLAMATION | MB_OK);
                throw new Exception();
            }

            IntPtr hWnd = (IntPtr)CreateWindowEx(
                WS_EX_TOOLWINDOW, // Remove window from Alt Tab
                cn,
                null,
                WS_BORDER & ~WS_OVERLAPPEDWINDOW, // PWTD Make rather a fake fullscreen windowed (without border)s // DOLATER Remove borders without disturb good mecanism
                0, 0,
                (int)videoMode.Width, (int)videoMode.Height,
                IntPtr.Zero, IntPtr.Zero, hInstance, IntPtr.Zero);


            if (hWnd == IntPtr.Zero)
            {
                MessageBox(IntPtr.Zero, "Window Creation Failed!", "Error!",
                           MB_ICONEXCLAMATION | MB_OK);
                throw new Exception();
            }

            return(hWnd);
        }
Esempio n. 20
0
        protected override void InitVideoMemory(bool clearScreen)
        {
            base.InitVideoMemory(clearScreen);

            Console.Title = "x8086SharpEmuConsole - " + VideoMode.ToString();

            if (MainMode == MainModes.Graphics)
            {
                ResetI2A();
            }

            switch (Environment.OSVersion.Platform)
            {
            case PlatformID.Win32NT:
            case PlatformID.Win32S:
            case PlatformID.Win32Windows:
            case PlatformID.WinCE:
                break;

            default:
                if (mVideoMode != 0xFF && (Console.WindowWidth != mTextResolutionX || Console.WindowHeight != mTextResolutionY))
                {
                    ConsoleCrayon.ResetColor();
                    Console.Clear();
                    ConsoleCrayon.WriteFast("Unsupported Console Window Size", ConsoleColor.White, ConsoleColor.Red, 0, 0);
                    ConsoleCrayon.ResetColor();
                    Console.WriteLine();
                    Console.WriteLine("The window console cannot be resized on this platform, which will case the text to be rendered incorrectly");
                    Console.WriteLine();
                    Console.WriteLine("Expected Resolution for Video Mode {mVideoMode:X2}: {mTextResolution.Width}x{mTextResolution.Height}");
                    Console.WriteLine("Current console window resolution:     {Console.WindowWidth}x{Console.WindowHeight}");
                    Console.WriteLine();
                    Console.WriteLine("Manually resize the window to the appropriate resolution or press any key to continue");
                    do
                    {
                        ConsoleCrayon.WriteFast("New resolution: {Console.WindowWidth}x{Console.WindowHeight}", ConsoleColor.White, ConsoleColor.DarkRed, 0, 10);
                        Thread.Sleep(200);
                        if (Console.WindowWidth == mTextResolutionX && Console.WindowHeight == mTextResolutionY)
                        {
                            break;
                        }
                    } while (!Console.KeyAvailable);
                    ConsoleCrayon.ResetColor();
                    Console.Clear();
                }
                break;
            }
        }
Esempio n. 21
0
        public BeepLiveSfml(IMessageSender messageSender)
        {
            VideoMode mode = new VideoMode(1080, 720);

            Window = new RenderWindow(mode, "Map");

            _center   = new Vector2f(Window.Size.X / 2f, Window.Size.Y / 2f);
            _zoom     = 1;
            _rotation = 0;

            _view = new View(_center, new Vector2f(Window.Size.X, Window.Size.Y));
            Window.SetView(_view);

            Window.KeyPressed         += Window_KeyPressed;
            Window.MouseButtonPressed += Window_MousePressed;
            Window.Closed             += Window_Closed;
            Window.MouseWheelScrolled += Window_MouseWheelScrolled;

            _random     = new Random();
            _shakeTimer = new Stopwatch();

            MessageSender = messageSender;

            PlayerGuid = Guid.NewGuid();
            Secret     = Guid.NewGuid();

            Flow(PlayerFlowPacket.FlowType.Join);

            BeepGameState = new BeepLiveGameState
            {
                Connecting = true
            };

            _font           = new Font(Path.GetFullPath("BioRhymeExpanded-ExtraBold.ttf"));
            _connectingText = new Text("Connecting to Server", _font)
            {
                Position = _center
            };
            _debugText = new Text("", _font, 10)
            {
                Position = new Vector2f(10, 10)
            };

            QueuedPlayerActionPackets = new List <PlayerActionPacket>();
            QueuedPackets             = new List <Packet>();

            Window.SetActive(false);
        }
Esempio n. 22
0
        public MainWindow()
        {
            VideoMode mode = new VideoMode(600, 400);

            window = new RenderWindow(mode, "Narvel");

            window.Closed     += WindowClose;
            window.KeyPressed += key_handler;
            window.LostFocus  += WindowClose;

            while (window.IsOpen)
            {
                window.DispatchEvents();
                window.Display();
            }
        }
Esempio n. 23
0
        /// <summary>
        ///   Gets the video mode xml string.
        /// </summary>
        /// <param name="vm">
        ///   The video mode.
        /// </param>
        /// <param name="name">
        ///   Xml element name.
        /// </param>
        /// <param name="indent">
        ///   Indentation level.
        /// </param>
        /// <returns>
        ///   The given video mode as an xml string.
        /// </returns>
        public static string ToString(VideoMode vm, string name = null, uint indent = 0)
        {
            if (!Identifiable.IsValid(name))
            {
                name = nameof(VideoMode);
            }

            StringBuilder sb = new();

            sb.Append('<').Append(name).Append(' ')
            .Append(nameof(VideoMode.Width)).Append("=\"").Append(vm.Width).Append("\" ")
            .Append(nameof(VideoMode.Height)).Append("=\"").Append(vm.Height).Append("\" ")
            .Append(nameof(VideoMode.BitsPerPixel)).Append("=\"").Append(vm.BitsPerPixel).Append("\"/>");

            return(Indent(sb.ToString(), indent));
        }
        public void Deserialize(ParsedByteArray cmd)
        {
            var count = cmd.GetUInt16();

            Modes = new List <Entry>((int)count);
            cmd.Skip(2);

            for (int i = 0; i < count; i++)
            {
                VideoMode mode = (VideoMode)cmd.GetUInt8();
                cmd.Skip(5);
                VideoMode mvMode = (VideoMode)Math.Floor(Math.Log(cmd.GetUInt16(), 2));  // TODO - check this is correct
                cmd.Skip(4);
                Modes.Add(new Entry(mode, mvMode));
            }
        }
Esempio n. 25
0
        public void Deserialize(ParsedByteArray cmd)
        {
            var count = cmd.GetUInt16();

            Modes = new List <Entry>((int)count);
            cmd.Skip(2);

            for (int i = 0; i < count; i++)
            {
                VideoMode mode = (VideoMode)cmd.GetUInt8();
                cmd.Skip(3);
                VideoMode mvMode   = (VideoMode)Math.Floor(Math.Log(cmd.GetUInt32(), 2)); // TODO - should be mask
                VideoMode someMode = (VideoMode)Math.Floor(Math.Log(cmd.GetUInt32(), 2)); // TODO - should be mask
                Modes.Add(new Entry(mode, mvMode, someMode));
            }
        }
Esempio n. 26
0
 public bool StartCapture()
 {
     try
     {
         if (CaptureProvider == null)
         {
             if (Globals.DoubleCap)
             {
                 CaptureProvider = Common.CaptureL;
             }
             else
             {
                 CaptureProvider = Common.Capture;
             }
         }
         if (CaptureProvider != null)
         {
             VC1.CaptureProvider = CaptureProvider;
             if (!CaptureProvider.IsInit)
             {
                 CaptureProvider.InitDriver();
             }
             CaptureProvider.BinningMode = !Globals.HighCCD;
             if (CaptureProvider.IsRunning)
             {
                 timer.Start();
                 return(true);
             }
             if (CaptureProvider.StartCapture())
             {
                 this.showMode = VideoMode.RealTime;
                 timer.Start();
             }
             GC.Collect();
             return(CaptureProvider.IsRunning);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
         return(false);
     }
 }
Esempio n. 27
0
        public void SwitchToMode(VideoMode mode)
        {
            Log.Color("Switch to: " + mode, this);
            switch (mode)
            {
            case VideoMode.Fullscreen:
                //SetOrientation(IsPrepared);
                fullscreenHUD.Show(true);
                break;

            default:
                //SetOrientation(false);
                fullscreenHUD.Show(false);
                break;
            }
            currentMode = mode;
        }
        public void Deserialize(ParsedByteArray cmd)
        {
            var count = cmd.GetUInt16();

            Modes = new List <Entry>((int)count);
            cmd.Skip(2);

            for (int i = 0; i < count; i++)
            {
                VideoMode mode = (VideoMode)cmd.GetUInt8();
                cmd.Skip(3);
                List <VideoMode> multiviewModes   = ReadVideoModeBitmask(cmd.GetUInt32());
                List <VideoMode> downConvertModes = ReadVideoModeBitmask(cmd.GetUInt32());
                bool             requiresReconfig = cmd.GetBoolArray()[0]; // TODO this will be 8.0+ specific
                Modes.Add(new Entry(mode, multiviewModes, downConvertModes, requiresReconfig));
            }
        }
Esempio n. 29
0
        private void SwitchToFullScreen()
        {
            windowedMode = new VideoMode()
            {
                Width      = Graphics.PreferredBackBufferWidth,
                Height     = Graphics.PreferredBackBufferHeight,
                FullScreen = false
            };
            var         modes       = GraphicsDevice.Adapter.SupportedDisplayModes;
            DisplayMode displayMode = GraphicsDevice.Adapter.CurrentDisplayMode;

            Console.WriteLine(displayMode);
            Graphics.PreferredBackBufferWidth  = displayMode.Width;
            Graphics.PreferredBackBufferHeight = displayMode.Height;
            Graphics.IsFullScreen = true;
            Graphics.ApplyChanges();
        }
Esempio n. 30
0
        private void Build(string title, int width, int height, Orientation orientation)
        {
            theme          = new Theme();
            this.title     = title;
            this.size      = new Size(width, height);
            window         = new RenderWindow(new VideoMode((uint)width, (uint)height), title, Styles.Close);
            window.Closed += new EventHandler(OnClosed);
            VideoMode desktop = VideoMode.DesktopMode;

            window.Position  = new Vector2i((int)desktop.Width / 2 - (int)window.Size.X / 2, (int)desktop.Height / 2 - (int)window.Size.Y / 2);
            container        = new Container(0, 0, width, height, orientation);
            container.Window = this;
            texture          = new Texture((uint)width, (uint)height);
            pixels           = new byte[width * height * 4];
            pixelDrawer      = new PixelDrawer(pixels, width, height);
            sprite           = new Sprite(texture);
        }
Esempio n. 31
0
        public RenderManager()
        {
            TitleWindow = $"{Game.Setting.General.Name} | {Game.Setting.General.Author}";
            VideoMode   = new VideoMode((uint)Game.Setting.Window.Resolution.X, (uint)Game.Setting.Window.Resolution.Y);
            ScreenMode  = Game.Setting.Window.ScreenMode switch
            {
                Entities.ScreenMode.Default => Styles.Default,
                Entities.ScreenMode.Resize => Styles.Resize,
                _ => Styles.Fullscreen
            };

            Game.Setting.General.OnChangeName   += General_OnChangeName;
            Game.Setting.General.OnChangeAuthor += General_OnChangeAuthor;

            Game.Setting.Window.OnChangeResolution += Window_OnChangeResolution;
            Game.Setting.Window.OnChangeScreenMode += Window_OnChangeScreenMode;
        }
Esempio n. 32
0
 ////////////////////////////////////////////////////////////
 /// <summary>
 /// Create the window with default style and creation settings
 /// </summary>
 /// <param name="mode">Video mode to use</param>
 /// <param name="title">Title of the window</param>
 ////////////////////////////////////////////////////////////
 public RenderWindow(VideoMode mode, string title)
     : this(mode, title, Styles.Resize | Styles.Close, new WindowSettings(24, 8, 0))
 {
 }
Esempio n. 33
0
 private void VideoDeviceChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
 {
     if (e.AddedItems != null && e.AddedItems.Count > 0)
     {
         var selection = (KeyValuePair<string, VideoMode>)e.AddedItems[0];
         System.Diagnostics.Debug.WriteLine(selection.Key);
         _localVideoMode = selection.Value;
         _startLocalVideoButton.IsEnabled = true;
     }
 }
Esempio n. 34
0
 ////////////////////////////////////////////////////////////
 /// <summary>
 /// Create the window with default style and creation settings
 /// </summary>
 /// <param name="mode">Video mode to use</param>
 /// <param name="title">Title of the window</param>
 ////////////////////////////////////////////////////////////
 public Window(VideoMode mode, string title)
     : this(mode, title, Styles.Default, new ContextSettings(24, 8))
 {
 }
Esempio n. 35
0
 private string GetVmString(VideoMode vm)
 {
     return vm.Width.ToString() + "x" + vm.Height.ToString() + " @ " + vm.RefreshRate + " hz";
 }
Esempio n. 36
0
 ////////////////////////////////////////////////////////////
 /// <summary>
 /// Create the window with default creation settings
 /// </summary>
 /// <param name="mode">Video mode to use</param>
 /// <param name="title">Title of the window</param>
 /// <param name="style">Window style (Resize | Close by default)</param>
 ////////////////////////////////////////////////////////////
 public Window(VideoMode mode, string title, Styles style)
     : this(mode, title, style, new WindowSettings(24, 8, 0))
 {
 }
Esempio n. 37
0
 ////////////////////////////////////////////////////////////
 /// <summary>
 /// Create the window
 /// </summary>
 /// <param name="mode">Video mode to use</param>
 /// <param name="title">Title of the window</param>
 /// <param name="style">Window style (Resize | Close by default)</param>
 /// <param name="settings">Creation parameters</param>
 ////////////////////////////////////////////////////////////
 public RenderWindow(VideoMode mode, string title, Styles style, ContextSettings settings)
     : base(sfRenderWindow_Create(mode, title, style, ref settings), 0)
 {
     Initialize();
 }
Esempio n. 38
0
        public void StartLocalVideo(VideoMode videoMode)
        {
            if (_localVideoSamplingTask != null && !_localVideoSamplingTask.IsCompleted && _localVideoSamplingCancelTokenSource != null)
            {
                _localVideoSamplingCancelTokenSource.Cancel();
            }

            var videoSampler = new MFVideoSampler();
            videoSampler.Init(videoMode.DeviceIndex, videoMode.Width, videoMode.Height);
            //videoSampler.InitFromFile();
            //_audioChannel = new AudioChannel();

            _localVideoSamplingCancelTokenSource = new CancellationTokenSource();
            var cancellationToken = _localVideoSamplingCancelTokenSource.Token;

            _localVideoSamplingTask = Task.Factory.StartNew(() =>
            {
                Thread.CurrentThread.Name = "vidsampler_" + videoMode.DeviceIndex + "_" + videoMode.Width + "_" + videoMode.Height;

                var vpxEncoder = new VPXEncoder();
                vpxEncoder.InitEncoder(Convert.ToUInt32(videoMode.Width), Convert.ToUInt32(videoMode.Height));

               // var videoSampler = new MFVideoSampler();
                //videoSampler.Init(videoMode.DeviceIndex, videoMode.Width, videoMode.Height);
               // videoSampler.InitFromFile();

                while (!_stop && !cancellationToken.IsCancellationRequested)
                {
                    byte[] videoSample = null;
                    int result = videoSampler.GetSample(ref videoSample);

                    if (result == NAudio.MediaFoundation.MediaFoundationErrors.MF_E_HW_MFT_FAILED_START_STREAMING)
                    {
                        logger.Warn("A sample could not be acquired from the local webcam. Check that it is not already in use.");
                        OnLocalVideoError("A sample could not be acquired from the local webcam. Check that it is not already in use.");
                        break;
                    }
                    else if (result != 0)
                    {
                        logger.Warn("A sample could not be acquired from the local webcam. Check that it is not already in use. Error code: " + result);
                        OnLocalVideoError("A sample could not be acquired from the local webcam. Check that it is not already in use. Error code: " + result);
                        break;
                    }
                    else if (videoSample != null)
                    {
                        // This event sends the raw bitmap to the WPF UI.
                        if (OnLocalVideoSampleReady != null)
                        {
                            OnLocalVideoSampleReady(videoSample, videoSampler.Width, videoSampler.Height);
                        }

                        // This event encodes the sample and forwards it to the RTP manager for network transmission.
                        if (_rtpManager != null)
                        {
                            IntPtr rawSamplePtr = Marshal.AllocHGlobal(videoSample.Length);
                            Marshal.Copy(videoSample, 0, rawSamplePtr, videoSample.Length);

                            byte[] yuv = null;

                            unsafe
                            {
                                _imageConverter.ConvertRGBtoYUV((byte*)rawSamplePtr, Convert.ToInt32(videoMode.Width), Convert.ToInt32(videoMode.Height), ref yuv);
                            }

                            Marshal.FreeHGlobal(rawSamplePtr);

                            IntPtr yuvPtr = Marshal.AllocHGlobal(yuv.Length);
                            Marshal.Copy(yuv, 0, yuvPtr, yuv.Length);

                            byte[] encodedBuffer = null;

                            unsafe
                            {
                                vpxEncoder.Encode((byte*)yuvPtr, yuv.Length, _encodingSample++, ref encodedBuffer);
                            }

                            Marshal.FreeHGlobal(yuvPtr);

                            _rtpManager.LocalVideoSampleReady(encodedBuffer);
                        }
                    }
                }

                videoSampler.Stop();
                vpxEncoder.Dispose();
            }, cancellationToken);

            _localAudioSamplingTask = Task.Factory.StartNew(() =>
            {
                Thread.CurrentThread.Name = "audsampler_" + videoMode.DeviceIndex;

                while (!_stop && !cancellationToken.IsCancellationRequested)
                {
                    byte[] audioSample = null;
                    int result = videoSampler.GetAudioSample(ref audioSample);

                    if (result == NAudio.MediaFoundation.MediaFoundationErrors.MF_E_HW_MFT_FAILED_START_STREAMING)
                    {
                        logger.Warn("An audio sample could not be acquired from the local source. Check that it is not already in use.");
                        //OnLocalVideoError("A sample could not be acquired from the local webcam. Check that it is not already in use.");
                        break;
                    }
                    else if (result != 0)
                    {
                        logger.Warn("An audio sample could not be acquired from the local source. Check that it is not already in use. Error code: " + result);
                        //OnLocalVideoError("A sample could not be acquired from the local webcam. Check that it is not already in use. Error code: " + result);
                        break;
                    }
                    else if (audioSample != null)
                    {
                        if (_audioChannel != null)
                        {
                            _audioChannel.AudioSampleReceived(audioSample, 0);
                        }
                    }
                }
            }, cancellationToken);
        }
Esempio n. 39
0
 static extern bool sfVideoMode_IsValid(VideoMode Mode);
Esempio n. 40
0
 ////////////////////////////////////////////////////////////
 /// <summary>
 /// Create the window
 /// </summary>
 /// <param name="mode">Video mode to use</param>
 /// <param name="title">Title of the window</param>
 /// <param name="style">Window style (Resize | Close by default)</param>
 /// <param name="settings">Creation parameters</param>
 ////////////////////////////////////////////////////////////
 public Window(VideoMode mode, string title, Styles style, ContextSettings settings)
     : base(sfWindow_Create(mode, title, style, ref settings))
 {
 }
Esempio n. 41
0
        private string ToAMCPString(VideoMode mode)
        {
            string result = string.Empty;
            switch (mode)
            {
                case VideoMode.Unknown:
                case VideoMode.PAL:
                case VideoMode.NTSC:
                    result = mode.ToString();
                    break;

                default:
                    {
                        string modestr = mode.ToString();
                        result = (modestr.Length > 2) ? modestr.Substring(2) : modestr;
                        break;
                    }
            }

            return result;
        }
Esempio n. 42
0
 public void SetMode(VideoMode mode)
 {
     Connection.SendString("SET " + ID + " MODE " + ToAMCPString(mode));
 }
Esempio n. 43
0
 ////////////////////////////////////////////////////////////
 /// <summary>
 /// Create the window
 /// </summary>
 /// <param name="mode">Video mode to use</param>
 /// <param name="title">Title of the window</param>
 /// <param name="style">Window style (Resize | Close by default)</param>
 /// <param name="settings">Creation parameters</param>
 ////////////////////////////////////////////////////////////
 public Window(VideoMode mode, string title, Styles style, WindowSettings settings)
     : base(sfWindow_Create(mode, title, style, settings))
 {
     myInput = new Input(sfWindow_GetInput(This));
 }
Esempio n. 44
0
 ////////////////////////////////////////////////////////////
 /// <summary>
 /// Create the window with default creation settings
 /// </summary>
 /// <param name="mode">Video mode to use</param>
 /// <param name="title">Title of the window</param>
 /// <param name="style">Window style (Resize | Close by default)</param>
 ////////////////////////////////////////////////////////////
 public RenderWindow(VideoMode mode, string title, Styles style)
     : this(mode, title, style, new ContextSettings(24, 8))
 {
 }
Esempio n. 45
0
 private void ChangeVideoMode(VideoMode videoMode)
 {
     switch (this.currentVideoMode)
     {
         case VideoMode.Normal:
             this.panelVideo.Controls.Remove(this.videoControl);
             break;
         case VideoMode.TV:
             this.videoForm.Owner = null;
             this.currentTVModeBounds = this.videoForm.Bounds;
             this.videoForm.Controls.Remove(this.videoControl);
             break;
         case VideoMode.Fullscreen:
             Cursor.Show();
             this.videoForm.Controls.Remove(this.videoControl);
             break;
     }
     this.currentVideoMode = videoMode;
     switch (videoMode)
     {
         case VideoMode.Normal:
             this.videoForm.Hide();
             this.videoForm.FormVideoMode = videoMode;
             this.panelVideo.Controls.Add(this.videoControl);
             //Bounds = RestoreBounds;
             WindowState = FormWindowState.Normal;
             Show();
             break;
         case VideoMode.TV:
             Hide();
             this.videoForm.SuspendLayout();
             this.videoForm.FormVideoMode = videoMode;
             this.videoForm.TopMost = true;
             this.videoForm.FormBorderStyle = FormBorderStyle.SizableToolWindow;
             if (this.currentTVModeBounds.Height != 0)
                 this.videoForm.Bounds = this.currentTVModeBounds;
             else
                 this.videoForm.DesktopBounds = new Rectangle(new Point(this.DesktopLocation.X + (this.Size.Width - Form.DefaultSize.Width) / 2, this.DesktopLocation.Y + (this.Size.Height - Form.DefaultSize.Height) / 2), Form.DefaultSize);
             this.videoForm.Controls.Add(this.videoControl);
             this.videoForm.ResumeLayout(false);
             this.videoForm.UpdateSize();
             this.videoForm.Show(this);
             break;
         case VideoMode.Fullscreen:
             Hide();
             Cursor.Hide();
             this.videoForm.FormVideoMode = videoMode;
             this.videoForm.TopMost = false;
             this.videoForm.FormBorderStyle = FormBorderStyle.None;
             this.videoForm.DesktopBounds = Screen.FromControl(this).Bounds;
             this.videoForm.Controls.Add(this.videoControl);
             this.videoForm.Show();
             break;
     }
     this.videoControl.Focus();
 }
Esempio n. 46
0
 ////////////////////////////////////////////////////////////
 /// <summary>
 /// Create the window with default creation settings
 /// </summary>
 /// <param name="mode">Video mode to use</param>
 /// <param name="title">Title of the window</param>
 /// <param name="style">Window style (Resize | Close by default)</param>
 ////////////////////////////////////////////////////////////
 public Window(VideoMode mode, string title, Styles style)
     : this(mode, title, style, new ContextSettings(0, 0))
 {
 }
Esempio n. 47
0
 static extern IntPtr sfRenderWindow_Create(VideoMode Mode, string Title, Styles Style, ref ContextSettings Params);
Esempio n. 48
0
 ////////////////////////////////////////////////////////////
 /// <summary>
 /// Create the window with default style and creation settings
 /// </summary>
 /// <param name="mode">Video mode to use</param>
 /// <param name="title">Title of the window</param>
 ////////////////////////////////////////////////////////////
 public RenderWindow(VideoMode mode, string title)
     : this(mode, title, Styles.Default, new ContextSettings(0, 0))
 {
 }
Esempio n. 49
0
 public ChannelInfo(int id, VideoMode vm, ChannelStatus cs, string activeClip)
 {
     ID = id;
     VideoMode = vm;
     Status = cs;
     ActiveClip = activeClip;
 }