Пример #1
0
        public Sdl2Window(string title, int x, int y, int width, int height, SDL_WindowFlags flags, bool threadedProcessing)
        {
            _threadedProcessing = threadedProcessing;
            if (threadedProcessing)
            {
                using (ManualResetEvent mre = new ManualResetEvent(false))
                {
                    WindowParams wp = new WindowParams()
                    {
                        Title       = title,
                        X           = x,
                        Y           = y,
                        Width       = width,
                        Height      = height,
                        WindowFlags = flags,
                        ResetEvent  = mre
                    };

                    Task.Factory.StartNew(WindowOwnerRoutine, wp, TaskCreationOptions.LongRunning);
                    mre.WaitOne();
                }
            }
            else
            {
                _window  = SDL_CreateWindow(title, x, y, width, height, flags);
                WindowID = SDL_GetWindowID(_window);
                Sdl2EventProcessor.RegisterWindow(this);
                PostWindowCreated(flags);
            }
        }
Пример #2
0
        private byte GetWindowMinimized(ImGuiViewportPtr vp)
        {
            VeldridImGuiWindow window = (VeldridImGuiWindow)GCHandle.FromIntPtr(vp.PlatformUserData).Target;
            SDL_WindowFlags    flags  = Sdl2Native.SDL_GetWindowFlags(window.Window.SdlWindowHandle);

            return((flags & SDL_WindowFlags.Minimized) != 0 ? (byte)1 : (byte)0);
        }
Пример #3
0
 internal Window(string title = "New SDL Window", int x = 0, int y = 0, int width = 600, int height = 600, SDL.SDL_WindowFlags flags = SDL_WindowFlags.SDL_WINDOW_SHOWN)
 {
     this.title  = title;
     this.x      = x;
     this.y      = y;
     this.width  = width;
     this.height = height;
     this.flags  = flags;
 }
Пример #4
0
        private byte GetWindowMinimized(ImGuiViewportPtr vp)
        {
            VeldridImGuiWindow?window = (VeldridImGuiWindow?)GCHandle.FromIntPtr(vp.PlatformUserData).Target;

            if (window == null)
            {
                throw new NullReferenceException();
            }
            SDL_WindowFlags flags = Sdl2Native.SDL_GetWindowFlags(window.Window.SdlWindowHandle);

            return((flags & SDL_WindowFlags.Minimized) != 0 ? (byte)1 : (byte)0);
        }
        public VeldridImGuiWindow(GraphicsDevice gd, ImGuiViewportPtr vp)
        {
            _gcHandle = GCHandle.Alloc(this);
            _gd       = gd;
            _vp       = vp;

            SDL_WindowFlags flags = SDL_WindowFlags.Hidden;

            if ((vp.Flags & ImGuiViewportFlags.NoTaskBarIcon) != 0)
            {
                flags |= SDL_WindowFlags.SkipTaskbar;
            }
            if ((vp.Flags & ImGuiViewportFlags.NoDecoration) != 0)
            {
                flags |= SDL_WindowFlags.Borderless;
            }
            else
            {
                flags |= SDL_WindowFlags.Resizable;
            }

            if ((vp.Flags & ImGuiViewportFlags.TopMost) != 0)
            {
                flags |= SDL_WindowFlags.AlwaysOnTop;
            }

            _window = new Sdl2Window(
                "No Title Yet",
                (int)vp.Pos.X, (int)vp.Pos.Y,
                (int)vp.Size.X, (int)vp.Size.Y,
                flags,
                false);
            _window.Resized += () => _vp.PlatformRequestResize = true;
            _window.Moved   += p => _vp.PlatformRequestMove = true;
            _window.Closed  += () => _vp.PlatformRequestClose = true;

            SwapchainSource      scSource = VeldridStartup.GetSwapchainSource(_window);
            SwapchainDescription scDesc   = new SwapchainDescription(scSource, (uint)_window.Width, (uint)_window.Height, null, true, false);

            _sc              = _gd.ResourceFactory.CreateSwapchain(scDesc);
            _window.Resized += () => _sc.Resize((uint)_window.Width, (uint)_window.Height);

            unsafe
            {
                ViewportDataPtr data = new ViewportDataPtr(Marshal.AllocHGlobal(Unsafe.SizeOf <ViewportDataPtr>()));
                vp.PlatformUserData = new HandleRef(data, (IntPtr)data.NativePtr).Handle;
            }
            vp.PlatformUserData = (IntPtr)_gcHandle;
        }
Пример #6
0
        public void SetWindowBorderless(bool borderless)
        {
            SDL_WindowFlags flags = (SDL_WindowFlags)SDL_GetWindowFlags(Window.Handle);

            if ((flags & SDL_WindowFlags.SDL_WINDOW_BORDERLESS) != 0 && borderless)
            {
                return;
            }

            if ((flags & SDL_WindowFlags.SDL_WINDOW_BORDERLESS) == 0 && !borderless)
            {
                return;
            }

            SDL_SetWindowBordered(Window.Handle, borderless ? SDL_bool.SDL_FALSE : SDL_bool.SDL_TRUE);
            SDL_GetCurrentDisplayMode(0, out SDL_DisplayMode displayMode);

            int width  = displayMode.w;
            int height = displayMode.h;

            if (borderless)
            {
                SetWindowSize(width, height);
                SDL_SetWindowPosition(Window.Handle, 0, 0);
            }
            else
            {
                SDL_GetWindowBordersSize
                (
                    Window.Handle,
                    out int top,
                    out _,
                    out int bottom,
                    out _
                );

                SetWindowSize(width, height - (top - bottom));
                SetWindowPositionBySettings();
            }

            WorldViewportGump viewport = UIManager.GetGump <WorldViewportGump>();

            if (viewport != null && ProfileManager.CurrentProfile.GameWindowFullSize)
            {
                viewport.ResizeGameWindow(new Point(width, height));
                viewport.X = -5;
                viewport.Y = -5;
            }
        }
Пример #7
0
        public Sdl2Window(string title, int x, int y, int width, int height, SDL_WindowFlags flags, bool threadedProcessing)
        {
            _threadedProcessing = threadedProcessing;

            wp = new WindowParams()
            {
                Title       = title,
                X           = x,
                Y           = y,
                Width       = width,
                Height      = height,
                WindowFlags = flags,
                //ResetEvent = mre
            };
        }
Пример #8
0
        public Window(string title, int weight, int height, bool fullscreen = true)
        {
            //Set windows information to private var
            Title        = title;
            Weight       = weight;
            Height       = height;
            isFullScreen = fullscreen;
            // Alow SDL to use OpenGL and Window RESIZABLE
            Flags = SDL_WindowFlags.SDL_WINDOW_OPENGL | SDL_WindowFlags.SDL_WINDOW_SHOWN | SDL_WindowFlags.SDL_WINDOW_RESIZABLE | SDL_WindowFlags.SDL_WINDOW_ALLOW_HIGHDPI;
            // Insert flag to make window FullSceen
            if (fullscreen)
            {
                Flags |= SDL_WindowFlags.SDL_WINDOW_FULLSCREEN;
            }

            Init();
        }
Пример #9
0
        public static Sdl2Window CreateWindow(ref WindowCreateInfo windowCI)
        {
            SDL_WindowFlags flags = SDL_WindowFlags.OpenGL | SDL_WindowFlags.Resizable
                                    | GetWindowFlags(windowCI.WindowInitialState);

            if (windowCI.WindowInitialState != WindowState.Hidden)
            {
                flags |= SDL_WindowFlags.Shown;
            }
            Sdl2Window window = new Sdl2Window(
                windowCI.WindowTitle,
                windowCI.X,
                windowCI.Y,
                windowCI.WindowWidth,
                windowCI.WindowHeight,
                flags,
                false);

            return(window);
        }
Пример #10
0
 public static IntPtr SDL_CreateWindow(String title, Int32 x, Int32 y, Int32 w, Int32 h, SDL_WindowFlags flags) => impl.SDL_CreateWindow(title, x, y, w, h, flags);
Пример #11
0
 public static extern int SetWindowFullscreen(IntPtr window, SDL_WindowFlags flags);
Пример #12
0
 public static extern IntPtr CreateWindow(string title, int x, int y, int w, int h, SDL_WindowFlags flags);
Пример #13
0
        /// <summary>
        /// Called to actually create the window and renderer.
        /// </summary>
        public virtual void Initialize(bool HardwareAcceleration = true, bool VSync = false, bool Borderless = false, bool ForceOpenGL = false)
        {
            if (Graphics.Windows.Contains(this))
            {
                return;
            }
            _StartTime = DateTime.Now;
            if (ForceOpenGL)
            {
                SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl");
            }

            SDL_WindowFlags flags = SDL_WindowFlags.SDL_WINDOW_HIDDEN | SDL_WindowFlags.SDL_WINDOW_ALLOW_HIGHDPI;

            if (Borderless)
            {
                flags |= SDL_WindowFlags.SDL_WINDOW_BORDERLESS;
            }
            this.SDL_Window = SDL_CreateWindow(this.Text, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
                                               this.Width, this.Height, flags);
            int WX;
            int WY;

            SDL_GetWindowPosition(this.SDL_Window, out WX, out WY);
            this.X = WX;
            this.Y = WY;
            SDL_SetWindowResizable(this.SDL_Window, Resizable ? SDL_bool.SDL_TRUE : SDL_bool.SDL_FALSE);
            if (this.Icon != null)
            {
                SDL_SetWindowIcon(this.SDL_Window, this.Icon.Surface);
            }
            SDL_RendererFlags renderflags = 0;

            if (HardwareAcceleration)
            {
                renderflags |= SDL_RendererFlags.SDL_RENDERER_ACCELERATED;
            }
            if (VSync)
            {
                renderflags |= SDL_RendererFlags.SDL_RENDERER_PRESENTVSYNC;
            }
            this.Renderer = new Renderer(SDL_CreateRenderer(this.SDL_Window, -1, renderflags));

            if (Graphics.MaxTextureSize == null)
            {
                SDL_RendererInfo info;
                SDL_GetRendererInfo(this.Renderer.SDL_Renderer, out info);
                Graphics.MaxTextureSize = new Size(info.max_texture_width, info.max_texture_height);
                Console.WriteLine($"Maximum Texture Size: {info.max_texture_width}x{info.max_texture_height}");
            }

            this.Viewport      = new Viewport(this, 0, 0, this.Width, this.Height);
            this.Viewport.Name = "Main Viewport";
            if (Viewport.DefaultWindow == null)
            {
                Viewport.DefaultWindow = this;
            }
            if (Sprite.DefaultViewport == null)
            {
                Sprite.DefaultViewport = this.Viewport;
            }

            BackgroundViewport      = new Viewport(this, 0, 0, this.Width, this.Height);
            BackgroundViewport.Name = "Background Viewport";
            BackgroundViewport.Z    = -999999999;
            BackgroundSprite        = new Sprite(BackgroundViewport);
            BackgroundSprite.Name   = "Background";
            BackgroundSprite.Z      = -999999999;
            BackgroundSprite.Bitmap = new SolidBitmap(this.Width, this.Height, this.BackgroundColor);

            TopViewport       = new Viewport(this, 0, 0, this.Width, this.Height);
            TopViewport.Z     = -1;
            TopViewport.Name  = "Top Viewport";
            TopSprite         = new Sprite(TopViewport, new SolidBitmap(this.Width, this.Height, Color.BLACK));
            TopSprite.Z       = 999999999;
            TopSprite.Opacity = 0;

            Graphics.AddWindow(this);

            if (MinimumSize != null)
            {
                SDL_SetWindowMinimumSize(SDL_Window, MinimumSize.Width, MinimumSize.Height);
            }

            Init = true;
            if (this.GetType() == typeof(Window))
            {
                Start();
            }
        }
Пример #14
0
 public Window(string title, int xPosition, int yPosition, int width, int height, SDL_WindowFlags flags = 0)
 {
     _sdlWindowPtr = SDL_CreateWindow(title, xPosition, yPosition, width, height, flags);
 }
Пример #15
0
        public static Sdl2Window CreateNewWindow(string title, int xPosition = 50, int yPosition = 50, int width = 600, int height = 400, SDL_WindowFlags flags = SDL_WindowFlags.Resizable | SDL_WindowFlags.Shown, bool threadedProcessing = false)
        {
            var window = new Sdl2Window(title, xPosition, yPosition, width, height, flags, threadedProcessing);

            windows.Add(window);

            return(window);
        }
Пример #16
0
 public static SDL_Window SDL_CreateWindow(string title, int x, int y, int w, int h, SDL_WindowFlags flags) => s_sdl_createWindow(Utf8EncodeNullable(title), x, y, w, h, flags);
Пример #17
0
        public unsafe NativeWindow(
            GraphicsService graphicsService,
            string title,
            int x, int y,
            int width, int height,
            SDL_WindowFlags flags
            )
        {
            _width           = width;
            _height          = height;
            _graphicsService = graphicsService;
            _handle          = SDL2Native.SDL_CreateWindow(
                title,
                x, y,
                width, height,
                flags
                );

            //get sdl version
            var sysWindowInfo = new SDL_SysWMinfo();

            SDL2Native.SDL_GetVersion(&sysWindowInfo.version);
            _version = sysWindowInfo.version;
            if (SDL2Native.SDL_GetWMWindowInfo(
                    _handle,
                    &sysWindowInfo
                    ) == 0)
            {
                throw new Exception("couldn't retrive sdl window information");
            }

            VkResult     error;
            VkSurfaceKHR surface;

            if (sysWindowInfo.subsystem == SysWMType.Windows)
            {
                var processHandle = (
                    Process
                    .GetCurrentProcess()
                    .SafeHandle
                    .DangerousGetHandle()
                    );
                var win32Info   = Unsafe.Read <Win32WindowInfo>(&sysWindowInfo.info);
                var surfaceInfo = new VkWin32SurfaceCreateInfoKHR
                {
                    sType     = VkStructureType.Win32SurfaceCreateInfoKHR,
                    hinstance = processHandle,
                    hwnd      = win32Info.window
                };
                error = VulkanNative.vkCreateWin32SurfaceKHR(
                    graphicsService.Handle,
                    &surfaceInfo,
                    null,
                    &surface
                    );
            }
            else if (sysWindowInfo.subsystem == SysWMType.X11)
            {
                var x11Info     = Unsafe.Read <X11WindowInfo>(&sysWindowInfo.info);
                var surfaceInfo = new VkXlibSurfaceCreateInfoKHR
                {
                    sType  = VkStructureType.XlibSurfaceCreateInfoKHR,
                    dpy    = (Vulkan.Xlib.Display *)x11Info.display,
                    window = new Vulkan.Xlib.Window
                    {
                        Value = x11Info.window
                    }
                };
                error = VulkanNative.vkCreateXlibSurfaceKHR(
                    graphicsService.Handle,
                    &surfaceInfo,
                    null,
                    &surface
                    );
            }
            else if (sysWindowInfo.subsystem == SysWMType.Wayland)
            {
                var waylandINfo = Unsafe.Read <WaylandWindowInfo>(&sysWindowInfo.info);
                var surfaceInfo = new VkWaylandSurfaceCreateInfoKHR
                {
                    sType   = VkStructureType.WaylandSurfaceCreateInfoKHR,
                    display = (Vulkan.Wayland.wl_display *)waylandINfo.display,
                    surface = (Vulkan.Wayland.wl_surface *)waylandINfo.surface
                };
                error = VulkanNative.vkCreateWaylandSurfaceKHR(
                    graphicsService.Handle,
                    &surfaceInfo,
                    null,
                    &surface
                    );
            }
            else if (sysWindowInfo.subsystem == SysWMType.Android)
            {
                var androidInfo = Unsafe.Read <AndroidWindowInfo>(&sysWindowInfo.info);
                var surfaceInfo = new VkAndroidSurfaceCreateInfoKHR
                {
                    sType  = VkStructureType.AndroidSurfaceCreateInfoKHR,
                    window = (Vulkan.Android.ANativeWindow *)androidInfo.window
                };
                error = VulkanNative.vkCreateAndroidSurfaceKHR(
                    graphicsService.Handle,
                    &surfaceInfo,
                    null,
                    &surface
                    );
            }
            else if (sysWindowInfo.subsystem == SysWMType.Mir)
            {
                var mirInfo     = Unsafe.Read <MirWindowInfo>(&sysWindowInfo.info);
                var surfaceInfo = new VkMirSurfaceCreateInfoKHR
                {
                    sType      = VkStructureType.MirSurfaceCreateInfoKHR,
                    connection = (Vulkan.Mir.MirConnection *)mirInfo.connection,
                    mirSurface = (Vulkan.Mir.MirSurface *)mirInfo.mirSurface
                };
                error = VulkanNative.vkCreateMirSurfaceKHR(
                    graphicsService.Handle,
                    &surfaceInfo,
                    null,
                    &surface
                    );
            }
            else if (sysWindowInfo.subsystem == SysWMType.Cocoa)
            {
                var cocaInfo = Unsafe.Read <CocoaWindowInfo>(&sysWindowInfo.info);

                var nsWindow    = new NSWindow(cocaInfo.Window);
                var contentView = nsWindow.contentView;
                contentView.wantsLayer = true;
                contentView.layer      = CAMetalLayer.New().NativePtr;

                var surfaceInfo = new VkMacOSSurfaceCreateInfoMVK
                {
                    sType = VkStructureType.MacosSurfaceCreateInfoMvk,
                    pView = nsWindow.contentView.NativePtr.ToPointer()
                };
                error = VulkanNative.vkCreateMacOSSurfaceMVK(
                    graphicsService.Handle,
                    &surfaceInfo,
                    null,
                    &surface
                    );
            }
            else
            {
                throw new PlatformNotSupportedException("this platform is currently not supported");
            }

            if (error != VkResult.Success)
            {
                throw new Exception("failed to create window surface");
            }

            _surface = surface;
        }
Пример #18
0
        public bool IsWindowMaximized()
        {
            SDL_WindowFlags flags = (SDL_WindowFlags)SDL_GetWindowFlags(Window.Handle);

            return((flags & SDL_WindowFlags.SDL_WINDOW_MAXIMIZED) != 0);
        }
Пример #19
0
		public static extern IntPtr SDL_CreateWindow(
			[InAttribute()] [MarshalAsAttribute(UnmanagedType.LPStr)]
				string title,
			int x,
			int y,
			int w,
			int h,
			SDL_WindowFlags flags
		);
Пример #20
0
 public static extern IntPtr CreateWindow([MarshalAs(UnmanagedType.LPStr)] String title, Int32 x, Int32 y, Int32 w, Int32 h, SDL_WindowFlags flags);
Пример #21
0
 public static extern IntPtr CreateWindow([MarshalAs(UnmanagedType.LPStr)] String title, Int32 x, Int32 y, Int32 w, Int32 h, SDL_WindowFlags flags);
Пример #22
0
 public abstract IntPtr SDL_CreateWindow(String title, Int32 x, Int32 y, Int32 w, Int32 h, SDL_WindowFlags flags);
Пример #23
0
		public static extern int SDL_CreateWindowAndRenderer(
			int width,
			int height,
			SDL_WindowFlags window_flags,
			ref IntPtr window,
			ref IntPtr renderer
		);
Пример #24
0
 public static SDL_Window SDL_CreateWindow(string title, int x, int y, int w, int h, SDL_WindowFlags flags) => s_sdl_createWindow(title, x, y, w, h, flags);
 private static extern IntPtr INTERNAL_SDL_CreateWindow([MarshalAs(UnmanagedType.LPStr)] String title, Int32 x, Int32 y, Int32 w, Int32 h, SDL_WindowFlags flags);
Пример #26
0
        public static SDL_Window SDL_CreateWindow(string title, int x, int y, int w, int h, SDL_WindowFlags flags)
        {
            byte *utf8Bytes;

            if (title != null)
            {
                int byteCount = Encoding.UTF8.GetByteCount(title);
                if (byteCount == 0)
                {
                    byte zeroByte = 0;
                    utf8Bytes = &zeroByte;
                }
                else
                {
                    byte *utf8BytesAlloc = stackalloc byte[byteCount + 1];
                    utf8Bytes = utf8BytesAlloc;
                    fixed(char *titlePtr = title)
                    {
                        int actualBytes = Encoding.UTF8.GetBytes(titlePtr, title.Length, utf8Bytes, byteCount);

                        utf8Bytes[actualBytes] = 0;
                    }
                }
            }
            else
            {
                utf8Bytes = null;
            }

            return(s_sdl_createWindow(utf8Bytes, x, y, w, h, flags));
        }
 public override sealed IntPtr SDL_CreateWindow(String title, Int32 x, Int32 y, Int32 w, Int32 h, SDL_WindowFlags flags) => INTERNAL_SDL_CreateWindow(title, x, y, w, h, flags);