apicici / cimgui-love

LÖVE module for Dear ImGui obtained by wrapping cimgui with LuaJIT FFI.
MIT License
76 stars 6 forks source link

ImGui.GetCursorScreenPos() returns wrong data (very close to 0) #18

Closed touchmaker closed 9 months ago

touchmaker commented 1 year ago

Version 1.89.7 love 11.4 Given the following code

    imgui.Begin( self.txt ,nil)
    local sp = imgui.GetCursorScreenPos()
    local sc = imgui.GetContentRegionAvail()
    local mp = imgui.GetMousePos()

    if sc.x<50.0 then sc.x = 50 end
    if sc.y<50.0 then sc.y = 50 end
   imgui.InvisibleButton("canvas",sc,bit.bor(imgui.ImGuiButtonFlags_MouseButtonLeft,imgui.ImGuiButtonFlags_MouseButtonRight))
    local is_hovered = imgui.IsItemHovered()
    local is_active = imgui.IsItemActive()

    if imgui.IsMouseDown(0) then 
        mouse_down = true
    end

    if imgui.IsMouseReleased(0) and mouse_down  and is_hovered then
        mouse_down = false
        points[#points+1] = { x= mp.x-sp.x,y= mp.y-sp.y }
    end

    local dl = imgui.GetWindowDrawList()
    dl:AddRect(
        self.wp, 
        imgui.ImVec2_Float(sp.x+sc.x, sp.y+sc.y), 
        0xFFFF00FF
    )

    for j,v in ipairs(points) do
        dl:AddCircleFilled(
             imgui.ImVec2_Float(sp.x+v.x,sp.y+v.y),
             5.0,
             0xFFFF00FF,--color key error
             12
        )
    end
    imgui.End()
end

So the resulting is always (very close to) 0, basically. even when the drawinglist leng>5000 it will cause flicks

apicici commented 1 year ago

Can you show me a picture of what the output look like for you? I tried to run your example and the sp vector return the right coordinates for me, and I see points being drawn at the location where I clicked. I did notice that after a certain amount of points are added there is some flickering, but that seems to be a different thing (looking into it!)

touchmaker commented 1 year ago
    thanks for reply sample code and screen snap followed below,

---- Replied Message ----

     From 

        Giuseppe ***@***.***>

     Date 

    9/6/2023 02:02

     To 

        ***@***.***>

     Cc 

        ***@***.***>
        ,

        ***@***.***>

     Subject 

          Re: [apicici/cimgui-love] ImGui.GetCursorScreenPos() returns wrong data (very close to 0) (Issue #18)

Can you show me a picture of what the output look like for you? I tried to run your example and the sp vector return the right coordinates for me, and I see points being drawn at the location where I clicked. I did notice that after a certain amount of points are added there is some flickering, but that seems to be a different thing (looking into it!)

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>

apicici commented 1 year ago

thanks for reply sample code and screen snap followed below,

I don't see any image.

touchmaker commented 1 year ago

Image attach here, GIF

this code purpose is for bone/skin editing just use love2d and pure lua code

code run quite well in default love2d routine , no matter how many triangles gen it runs smooth. but in imgui-version , when put some vertexs and triangles editing and display funtions in "canvas-like" widget like imgui-demo's canvas , that does't work as desired.

After 1-2 days of searching on google & github ,found locaimgui.GetCursorScreenPos() something return NOT the exact value especially when the windowDrawList is BIGGER. cimgui-quad.zip

below is sample code that should execute in window system or slight modified in other OS.

apicici commented 9 months ago

Sorry for the long delay. I finally found some time to look at this issue and I figured out the the problem is due to the outputs of imgui.GetCursorScreenPos(), imgui.GetContentRegionAvail(), imgui.GetMousePos() being garbage collected. I'm looking into fixing things so this doesn't happen anymore, but in the meantime this can be fixed by explicitly creating the ImVec2 vectors and assigning to them the output of those functions, so for example

local _sp = imgui.GetCursorScreenPos()
local sp = imgui.ImVec2_Float(_sp.x, _sp.y)
apicici commented 9 months ago

Resolved in the latest release (16a8126).