-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathMessageBoxExample.hs
More file actions
76 lines (65 loc) · 2.43 KB
/
MessageBoxExample.hs
File metadata and controls
76 lines (65 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
module Main where
import Control.Monad (unless)
import Data.Bits (zeroBits)
import Foreign.C.Types (CInt)
import SDL3
import System.Exit (exitFailure, exitSuccess)
main :: IO ()
main = do
-- Initialize SDL
initSuccess <- sdlInit [SDL_INIT_VIDEO]
unless initSuccess $ do
sdlLog "Failed to initialize SDL!"
exitFailure
-- Create a window for our dialog
maybeWindow <-
sdlCreateWindow
"SDL Dialog Example"
800
600
[SDL_WINDOW_RESIZABLE]
sdlLog "SDL Initialized. Testing message boxes..."
-- Simple information message box
res1 <- showMessageBox "Info" "This is an information message box." maybeWindow [SDL_MESSAGEBOX_INFORMATION]
sdlLog $ "User clicked: " ++ show res1
-- Warning message box
res2 <- showMessageBox "Warning" "This is a warning message box." maybeWindow [SDL_MESSAGEBOX_WARNING]
sdlLog $ "User clicked: " ++ show res2
-- Error message box
res3 <- showMessageBox "Error" "This is an error message box." maybeWindow [SDL_MESSAGEBOX_ERROR]
sdlLog $ "User clicked: " ++ show res3
-- Message box with custom buttons
res4 <- showCustomMessageBox "Custom" "Choose an option:" maybeWindow [("OK", 1), ("Cancel", 2)]
sdlLog $ "User clicked: " ++ show res4
-- Shutdown SDL
sdlLog "Shutting down SDL..."
sdlQuit
sdlLog "Test completed."
exitSuccess
-- Function to show a standard message box
showMessageBox :: String -> String -> Maybe SDLWindow -> [SDLMessageBoxFlags] -> IO (Maybe Int)
showMessageBox title msg window msgType = do
let msgBoxData =
SDLMessageBoxData
{ messageBoxFlags = msgType,
messageBoxWindow = window,
messageBoxTitle = title,
messageBoxMessage = msg,
messageBoxButtons = [],
messageBoxColorScheme = Nothing
}
sdlShowMessageBox msgBoxData
-- Function to show a custom message box with buttons
showCustomMessageBox :: String -> String -> Maybe SDLWindow -> [(String, CInt)] -> IO (Maybe Int)
showCustomMessageBox title msg window buttons = do
let buttonData = [SDLMessageBoxButtonData zeroBits bid txt | (txt, bid) <- buttons]
msgBoxData =
SDLMessageBoxData
{ messageBoxFlags = [SDL_MESSAGEBOX_INFORMATION],
messageBoxWindow = window,
messageBoxTitle = title,
messageBoxMessage = msg,
messageBoxButtons = buttonData,
messageBoxColorScheme = Nothing
}
sdlShowMessageBox msgBoxData