From c219f8eb4f27ecbfe61258420cf3628e87f3e006 Mon Sep 17 00:00:00 2001 From: Alexander Bondarenko <486682+dpwiz@users.noreply.github.com> Date: Sun, 12 Sep 2021 13:23:23 +0300 Subject: [PATCH] Wrap GetCurrentContext and SetCurrentContext (#94) --- src/DearImGui.hs | 2 ++ src/DearImGui/Context.hs | 1 + src/DearImGui/Raw.hs | 19 ++++++++++++++++--- src/DearImGui/Structs.hs | 5 +++++ 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/DearImGui.hs b/src/DearImGui.hs index 79722fe..d1aaedd 100644 --- a/src/DearImGui.hs +++ b/src/DearImGui.hs @@ -20,6 +20,8 @@ module DearImGui Raw.Context(..) , Raw.createContext , Raw.destroyContext + , Raw.getCurrentContext + , Raw.setCurrentContext -- * Main , Raw.newFrame diff --git a/src/DearImGui/Context.hs b/src/DearImGui/Context.hs index f8e47cf..2302bc0 100644 --- a/src/DearImGui/Context.hs +++ b/src/DearImGui/Context.hs @@ -33,5 +33,6 @@ imguiContext = mempty [ ( TypeName "ImVec2", [t| ImVec2 |] ) , ( TypeName "ImVec3", [t| ImVec3 |] ) , ( TypeName "ImVec4", [t| ImVec4 |] ) + , ( TypeName "ImGuiContext", [t| ImGuiContext |] ) ] } diff --git a/src/DearImGui/Raw.hs b/src/DearImGui/Raw.hs index 4db28be..99ad177 100644 --- a/src/DearImGui/Raw.hs +++ b/src/DearImGui/Raw.hs @@ -20,6 +20,8 @@ module DearImGui.Raw Context(..) , createContext , destroyContext + , getCurrentContext + , setCurrentContext -- * Main , newFrame @@ -234,19 +236,30 @@ Cpp.using "namespace ImGui" -- | Wraps @ImGuiContext*@. -newtype Context = Context (Ptr ()) +newtype Context = Context (Ptr ImGuiContext) -- | Wraps @ImGui::CreateContext()@. createContext :: (MonadIO m) => m Context createContext = liftIO do - Context <$> [C.exp| void* { CreateContext() } |] + Context <$> [C.exp| ImGuiContext* { CreateContext() } |] -- | Wraps @ImGui::DestroyContext()@. destroyContext :: (MonadIO m) => Context -> m () destroyContext (Context contextPtr) = liftIO do - [C.exp| void { DestroyContext((ImGuiContext*)$(void* contextPtr)); } |] + [C.exp| void { DestroyContext($(ImGuiContext* contextPtr)); } |] + +-- | Wraps @ImGui::GetCurrentContext()@. +getCurrentContext :: MonadIO m => m Context +getCurrentContext = liftIO do + Context <$> [C.exp| ImGuiContext* { GetCurrentContext() } |] + + +-- | Wraps @ImGui::SetCurrentContext()@. +setCurrentContext :: MonadIO m => Context -> m () +setCurrentContext (Context contextPtr) = liftIO do + [C.exp| void { SetCurrentContext($(ImGuiContext* contextPtr)) } |] -- | Start a new Dear ImGui frame, you can submit any command from this point diff --git a/src/DearImGui/Structs.hs b/src/DearImGui/Structs.hs index cdd5c3c..302f56f 100644 --- a/src/DearImGui/Structs.hs +++ b/src/DearImGui/Structs.hs @@ -69,3 +69,8 @@ instance Storable ImVec4 where z <- peek (castPtr ptr `plusPtr` (sizeOf x * 2)) w <- peek (castPtr ptr `plusPtr` (sizeOf x * 3)) return ImVec4{ x, y, z, w } + +-------------------------------------------------------------------------------- + +-- | DearImGui context handle. +data ImGuiContext