Added image wrapper (#74)

Raw.image and sdl2/gl example "image"

Wrappers should be backend-specific due to different handling of `userTextureIDPtr`.
This commit is contained in:
jpwidera
2021-09-12 12:35:03 +02:00
committed by GitHub
parent c7a694bce8
commit f3b85899f2
4 changed files with 168 additions and 0 deletions

View File

@ -105,6 +105,7 @@ module DearImGui.Raw
, smallButton
, invisibleButton
, arrowButton
, image
, checkbox
, progressBar
, bullet
@ -558,6 +559,31 @@ arrowButton strIdPtr dir = liftIO do
(0 /=) <$> [C.exp| bool { ArrowButton($(char* strIdPtr), $(ImGuiDir dir)) } |]
-- | Image Area to draw a texture
--
-- Wraps @ImGui::Image()
--
-- For OpenGL: The userTextureIDPtr points to the texture memory (eg. 0x0x0000000000000001), it is the number from glBindTexture.
-- Eg:
-- glBindTexture GL_TEXTURE_2D $ textureID texture
-- -- fill textureID
-- image (intPtrToPtr $ fromIntegral textureID) (ImVec2 500 500)(ImVec2 0 0)(ImVec2 1 1)(ImVec4 1 1 1 1)(ImVec4 0 0 0 0)
--
-- See https://github.com/ocornut/imgui/wiki/Image-Loading-and-Displaying-Examples#About-texture-coordinates and under examples/sdl/Image.hs
image :: (MonadIO m) => Ptr ()-> Ptr ImVec2 -> Ptr ImVec2 -> Ptr ImVec2 -> Ptr ImVec4 -> Ptr ImVec4 -> m()
image userTextureIDPtr sizePtr uv0Ptr uv1Ptr tintColPtr borderColPtr = liftIO do
[C.exp| void {
Image(
$(void* userTextureIDPtr),
*$(ImVec2* sizePtr),
*$(ImVec2* uv0Ptr),
*$(ImVec2* uv1Ptr),
*$(ImVec4* tintColPtr),
*$(ImVec4* borderColPtr)
)
} |]
-- | Wraps @ImGui::Checkbox()@.
checkbox :: (MonadIO m) => CString -> Ptr CBool -> m Bool
checkbox labelPtr boolPtr = liftIO do