Exemplo n.º 1
0
 public static int ShowMessageBoxEx(MessageBoxFlags flags, string title, string message, string[] buttons, SDLWindow window = null, int btnEnter = -1, int btnEscape = -1)
 {
     SDL.SDL_MessageBoxData data = new SDL.SDL_MessageBoxData();
     data.title   = title;
     data.message = message;
     if (window != null)
     {
         data.window = window.GetPointer();
     }
     else
     {
         data.window = IntPtr.Zero;
     }
     data.numbuttons = buttons.Length;
     data.flags      = (SDL.SDL_MessageBoxFlags)flags;
     SDL.SDL_MessageBoxButtonData[] buttonStructs = new SDL.SDL_MessageBoxButtonData[buttons.Length];
     for (var i = 0; i < buttons.Length; i++)
     {
         buttonStructs[i].buttonid = i;
         buttonStructs[i].text     = buttons[i];
         if (i == btnEnter)
         {
             buttonStructs[i].flags = SDL.SDL_MessageBoxButtonFlags.SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT;
         }
         else if (i == btnEscape)
         {
             buttonStructs[i].flags = SDL.SDL_MessageBoxButtonFlags.SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT;
         }
     }
     data.buttons = buttonStructs;
     if (SDL.SDL_ShowMessageBox(ref data, out int btnClicked) != 0)
     {
         throw new SDLException();
     }
     return(btnClicked);
 }
Exemplo n.º 2
0
        static void ShowErrorDialog()
        {
            var viewLogs = new SDL.SDL_MessageBoxButtonData
            {
                buttonid = 2,
                text     = "View Logs",
                flags    = SDL.SDL_MessageBoxButtonFlags.SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT
            };

            var viewFaq = new SDL.SDL_MessageBoxButtonData
            {
                buttonid = 1,
                text     = "View FAQ"
            };

            var quit = new SDL.SDL_MessageBoxButtonData
            {
                buttonid = 0,
                text     = "Quit",
                flags    = SDL.SDL_MessageBoxButtonFlags.SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT
            };

            var dialog = new SDL.SDL_MessageBoxData
            {
                flags      = SDL.SDL_MessageBoxFlags.SDL_MESSAGEBOX_ERROR,
                title      = "Fatal Error",
                message    = displayName + " has encountered a fatal error and must close.\nRefer to the crash logs and FAQ for more information.",
                buttons    = new[] { quit, viewFaq, viewLogs },
                numbuttons = 3
            };

            // SDL_ShowMessageBox may create the error dialog behind other windows.
            // We want to bring it to the foreground, but can't do it from the main thread
            // because SDL_ShowMessageBox blocks until the user presses a button.
            // HACK: Spawn a thread to raise it to the foreground after a short delay.
            Task.Run(() =>
            {
                Thread.Sleep(1000);
                SetForegroundWindow(Process.GetCurrentProcess().MainWindowHandle);
            });

            if (SDL.SDL_ShowMessageBox(ref dialog, out var buttonid) < 0)
            {
                Exit();
            }

            switch (buttonid)
            {
            case 0: Exit(); break;

            case 1:
            {
                try
                {
                    Process.Start(faqUrl);
                }
                catch { }
                break;
            }

            case 2:
            {
                try
                {
                    Process.Start(Path.Combine(Platform.SupportDir, "Logs"));
                }
                catch { }
                break;
            }
            }
        }
Exemplo n.º 3
0
        public static bool ShowMessageBox(Cv_MessageBoxParams mBoxParams, out Cv_ButtonType result)
        {
            var colorScheme = new SDL.SDL_MessageBoxColorScheme();

            var sdlBgColor = new SDL.SDL_MessageBoxColor();

            sdlBgColor.r = mBoxParams.bgColor.R;
            sdlBgColor.g = mBoxParams.bgColor.G;
            sdlBgColor.b = mBoxParams.bgColor.B;

            var sdlTextColor = new SDL.SDL_MessageBoxColor();

            sdlTextColor.r = mBoxParams.textColor.R;
            sdlTextColor.g = mBoxParams.textColor.G;
            sdlTextColor.b = mBoxParams.textColor.B;

            var sdlBorderColor = new SDL.SDL_MessageBoxColor();

            sdlBorderColor.r = mBoxParams.btBorderColor.R;
            sdlBorderColor.g = mBoxParams.btBorderColor.G;
            sdlBorderColor.b = mBoxParams.btBorderColor.B;

            var sdlBtBgColor = new SDL.SDL_MessageBoxColor();

            sdlBtBgColor.r = mBoxParams.btBgColor.R;
            sdlBtBgColor.g = mBoxParams.btBgColor.G;
            sdlBtBgColor.b = mBoxParams.btBgColor.B;

            var sdlBtSelectedColor = new SDL.SDL_MessageBoxColor();

            sdlBtSelectedColor.r = mBoxParams.btSelectedColor.R;
            sdlBtSelectedColor.g = mBoxParams.btSelectedColor.G;
            sdlBtSelectedColor.b = mBoxParams.btSelectedColor.B;

            colorScheme.colors = new SDL.SDL_MessageBoxColor[] {
                sdlBgColor, sdlTextColor, sdlBorderColor, sdlBtBgColor, sdlBtSelectedColor
            };

            SDL.SDL_MessageBoxFlags flags;

            switch (mBoxParams.messageType)
            {
            case Cv_MessageType.CV_MESSAGE_ERROR:
                flags = SDL.SDL_MessageBoxFlags.SDL_MESSAGEBOX_ERROR;
                break;

            case Cv_MessageType.CV_MESSAGE_WARNING:
                flags = SDL.SDL_MessageBoxFlags.SDL_MESSAGEBOX_WARNING;
                break;

            default:
                flags = SDL.SDL_MessageBoxFlags.SDL_MESSAGEBOX_INFORMATION;
                break;
            }

            var btArray = new SDL.SDL_MessageBoxButtonData[mBoxParams.buttons.Length];

            for (var i = 0; i < mBoxParams.buttons.Length; i++)
            {
                btArray[i] = new SDL.SDL_MessageBoxButtonData();
                if (mBoxParams.buttons[i] == mBoxParams.defaultButton)
                {
                    btArray[i].flags = SDL.SDL_MessageBoxButtonFlags.SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT;
                }
                else
                {
                    btArray[i].flags = 0;
                }

                btArray[i].text     = GetButtonText(mBoxParams.buttons[i]);
                btArray[i].buttonid = (int)mBoxParams.buttons[i];
            }

            var messageBoxData = new SDL.SDL_MessageBoxData();

            messageBoxData.flags       = flags;
            messageBoxData.window      = IntPtr.Zero;
            messageBoxData.title       = mBoxParams.title;
            messageBoxData.message     = mBoxParams.message;
            messageBoxData.numbuttons  = mBoxParams.buttons.Length;
            messageBoxData.buttons     = btArray;
            messageBoxData.colorScheme = colorScheme;

            // show the dialog box
            int sdlResult;

            if (SDL.SDL_ShowMessageBox(ref messageBoxData, out sdlResult) < 0)
            {
                result = Cv_ButtonType.CV_BUTTON_ABORT;
                return(false);
            }

            result = (Cv_ButtonType)sdlResult;
            return(true);
        }