@@ -21,12 +21,14 @@ module DearImGui.SDL (
21
21
, sdl2Shutdown
22
22
, pollEventWithImGui
23
23
, pollEventsWithImGui
24
+ -- *** Raw
25
+ , dispatchRawEvent
24
26
)
25
27
where
26
28
27
29
-- base
28
30
import Control.Monad
29
- ( when )
31
+ ( void , when )
30
32
import Foreign.Marshal.Alloc
31
33
( alloca )
32
34
import Foreign.Ptr
@@ -42,6 +44,7 @@ import qualified Language.C.Inline.Cpp as Cpp
42
44
import SDL
43
45
import SDL.Raw.Enum as Raw
44
46
import qualified SDL.Raw.Event as Raw
47
+ import qualified SDL.Raw.Types as Raw
45
48
46
49
-- transformers
47
50
import Control.Monad.IO.Class
@@ -77,11 +80,24 @@ pollEventWithImGui = liftIO do
77
80
nEvents <- Raw. peepEvents evPtr 1 Raw. SDL_PEEKEVENT Raw. SDL_FIRSTEVENT Raw. SDL_LASTEVENT
78
81
79
82
when (nEvents > 0 ) do
80
- let evPtr' = castPtr evPtr :: Ptr ()
81
- [C. exp | void { ImGui_ImplSDL2_ProcessEvent((SDL_Event*) $(void* evPtr')) } |]
83
+ void $ dispatchRawEvent evPtr
82
84
83
85
pollEvent
84
86
87
+ -- | Dispatch a raw 'Raw.Event' value to Dear ImGui.
88
+ --
89
+ -- You may want this function instead of 'pollEventWithImGui' if you do not use
90
+ -- @sdl2@'s higher-level 'Event' type (e.g. your application has its own polling
91
+ -- mechanism).
92
+ --
93
+ -- __It is your application's responsibility to both manage the input__
94
+ -- __pointer's memory and to fill the memory location with a raw 'Raw.Event'__
95
+ -- __value.__
96
+ dispatchRawEvent :: MonadIO m => Ptr Raw. Event -> m Bool
97
+ dispatchRawEvent evPtr = liftIO do
98
+ let evPtr' = castPtr evPtr :: Ptr ()
99
+ (0 /= ) <$> [C. exp | bool { ImGui_ImplSDL2_ProcessEvent((const SDL_Event*) $(void* evPtr')) } |]
100
+
85
101
-- | Like the SDL2 'pollEvents' function, while also dispatching the events to
86
102
-- Dear ImGui. See 'pollEventWithImGui'.
87
103
pollEventsWithImGui :: MonadIO m => m [Event ]
0 commit comments