Example #1
0
        static SDL_VideoDisplay SDL_GetDisplayForWindow(SDL_Window window)
        {
            int displayIndex = SDL_GetWindowDisplayIndex(window);

            if (displayIndex >= 0)
            {
                return(_video.displays[displayIndex]);
            }
            else
            {
                return(null);
            }
        }
Example #2
0
        static void SDL_MinimizeWindow(SDL_Window window)
        {
            if (Check_Window_Magic(window, out Exception e))
            {
                throw e;
            }

            if (CBool(window.flags & SDL_WINDOW_MINIMIZED))
            {
                return;
            }

            SDL_UpdateFullscreenMode(window, false);

            if (_video.MinimizeWindow != null)
            {
                _video.MinimizeWindow(_video, window);
            }
        }
Example #3
0
        static unsafe bool Check_Window_Magic(SDL_Window window, out Exception retval)
        {
            if (_video == null)
            {
                retval = SDL_UninitializedVideo;
                return(true);
            }

            void *magic = _video.FixedMagic.AddrOfPinnedObject().ToPointer();

            if (window == null || window.magic != magic)
            {
                retval = new NativeException("Invalid window");
                return(true);
            }

            retval = null;
            return(false);
        }
Example #4
0
        static void SDL_SetWindowFullscreen(SDL_Window window, uint flags)
        {
            if (Check_Window_Magic(window, out Exception e))
            {
                throw e;
            }

            flags &= FULLSCREEN_MASK;

            if (flags == (window.flags & FULLSCREEN_MASK))
            {
                return;
            }

            // clear the previous flags and OR in the new ones
            window.flags &= ~FULLSCREEN_MASK;
            window.flags |= flags;

            SDL_UpdateFullscreenMode(window, Fullscreen_Visible(window));
        }
Example #5
0
        static SDL_DisplayMode SDL_GetWindowDisplayMode(SDL_Window window)
        {
            SDL_DisplayMode  fullscreen_mode;
            SDL_VideoDisplay display;

            if (Check_Window_Magic(window, out Exception e))
            {
                throw e;
            }

            fullscreen_mode = window.fullscreen_mode.DeepCopy();
            if (!CBool(fullscreen_mode.w))
            {
                fullscreen_mode.w = window.w;
            }
            if (!CBool(fullscreen_mode.h))
            {
                fullscreen_mode.h = window.h;
            }

            display = SDL_GetDisplayForWindow(window);

            // if in desktop size mode, just return the size of the desktop
            if ((window.flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP)
            {
                fullscreen_mode = display.desktop_mode;
            }
            else if (SDL_GetClosestDisplayModeForDisplay(SDL_GetDisplayForWindow(window)
                                                         , fullscreen_mode
                                                         , fullscreen_mode) == null)
            {
                throw new NativeException("Couldn't find display mode match");
            }

            return(fullscreen_mode);
        }
Example #6
0
 static bool Fullscreen_Visible(SDL_Window w)
 => CBool(w.flags & SDL_WINDOW_FULLSCREEN) &&
 CBool(w.flags & SDL_WINDOW_SHOWN) &&
 !CBool(w.flags & SDL_WINDOW_MINIMIZED);
Example #7
0
        static void SDL_UpdateFullscreenMode(SDL_Window window, bool fullscreen)
        {
            SDL_VideoDisplay display = SDL_GetDisplayForWindow(window);
            SDL_Window       other;

            if (fullscreen)
            {
                // Hide any other fullscreen windows
                if (display.fullscreen_window != null &&
                    display.fullscreen_window != window)
                {
                    SDL_MinimizeWindow(window);
                }
            }

            // See if anything needs to be done now
            if ((display.fullscreen_window == window) == fullscreen)
            {
                return;
            }

            // See if there are any fullscreen windows
            for (other = _video.windows; other != null; other = other.next)
            {
                bool setDisplayMode = false;

                if (other == window)
                {
                    setDisplayMode = fullscreen;
                }
                else if (Fullscreen_Visible(other) && SDL_GetDisplayForWindow(other) == display)
                {
                    setDisplayMode = true;
                }

                if (setDisplayMode)
                {
                    SDL_DisplayMode fullscreen_mode;

                    try
                    {
                        fullscreen_mode = SDL_GetWindowDisplayMode(other);
                        bool resized = true;

                        if (other.w == fullscreen_mode.w && other.h == fullscreen_mode.h)
                        {
                            resized = false;
                        }

                        // only do the mode change if we want exclusive fullscreen
                        if ((window.flags & SDL_WINDOW_FULLSCREEN_DESKTOP) != SDL_WINDOW_FULLSCREEN_DESKTOP)
                        {
                            SDL_SetDisplayModeForDisplay(display, fullscreen_mode);
                        }
                        else
                        {
                            SDL_SetDisplayModeForDisplay(display, null);
                        }

                        if (_video.SetWindowFullscreen != null)
                        {
                            _video.SetWindowFullscreen(_video, other, display, true);
                        }
                    }
                    catch (NativeException e)
                    {
                        IgnoreInDebugWriteLine(e);
                    }
                }
            }
        }
Example #8
0
        static unsafe int SDL_GetWindowDisplayIndex(SDL_Window window)
        {
            int       displayIndex;
            int       i, dist;
            int       closest      = -1;
            int       closest_dist = 0x7FFFFFFF;
            Point     center       = Point.Empty;
            Point     delta        = Point.Empty;
            Rectangle rect;

            if (Check_Window_Magic(window, out Exception e))
            {
                throw e;
            }

            if (SDL_WindowPos_IsUndefined(window.x) ||
                SDL_WindowPos_IsCentered(window.x))
            {
                displayIndex = window.x & 0xFFFF;
                if (displayIndex >= _video.num_displays)
                {
                    displayIndex = 0;
                }
                return(displayIndex);
            }
            if (SDL_WindowPos_IsUndefined(window.y) ||
                SDL_WindowPos_IsCentered(window.y))
            {
                displayIndex = window.y & 0xFFFF;
                if (displayIndex >= _video.num_displays)
                {
                    displayIndex = 0;
                }
                return(displayIndex);
            }

            // Find the display containing the window
            for (i = 0; i < _video.num_displays; ++i)
            {
                SDL_VideoDisplay display = _video.displays[i];

                if (display.fullscreen_window == window)
                {
                    return(i);
                }
            }
            center.X = window.x + window.w / 2;
            center.Y = window.y + window.h / 2;
            for (i = 0; i < _video.num_displays; ++i)
            {
                rect = SDL_GetDisplayBounds(i);
                if (SDL_EnclosePoints(&center, 1, &rect, null))
                {
                    return(i);
                }

                // 取两个中心点距离最小的那个
                delta.X = center.X - (rect.X + rect.Width / 2);
                delta.Y = center.Y - (rect.Y + rect.Width / 2);
                dist    = delta.X * delta.X + delta.Y * delta.Y;// 确保无负数
                if (dist < closest_dist)
                {
                    closest      = i;
                    closest_dist = dist;
                }
            }
            if (closest < 0)
            {
                throw new NativeException("Couldn't find any displays");
            }
            return(closest);
        }