Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
imGui bindings - Page 15 — Gideros Forum

imGui bindings

191011121315»

Comments

  • SinisterSoftSinisterSoft Maintainer
    edited January 2021
    If the dimensions of the 'stage' change (the main window is resized) - how do you update imgui to reflect this? It seems to clip to the original dimensions.
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • rrraptorrrraptor Member
    edited January 2021

    If the dimensions of the 'stage' change (the main window is resized) - how do you update imgui to reflect this? It seems to clip to the original dimensions.

    In short:
    local IO = imgui:getIO()
    IO:setDisplaySize(1280, 720)
    Or something like this:
     -- if scale mode is "noScale"
    local minX, minY, maxX, maxY = application:getLogicalBounds()
    imgui:setPosition(minX, minY)
    local IO = self.imgui:getIO()
    IO:setDisplaySize(maxX - minX, maxY - minY)
    -- if scale mode is not "noScale", but you want to ignore built-in scaling:
    local minX, minY, maxX, maxY = application:getLogicalBounds()
    local sx = application:getLogicalScaleX()
    local sy = application:getLogicalScaleY()
     
    imgui:setScale(1 / sx, 1 / sy)
    imgui:setPosition(minX, minY)
     
    local IO = imgui:getIO()
    IO:setDisplaySize((maxX - minX) * sx, (maxY - minY) * sy)
    Font scaling:
    IO:setFontGlobalScale(number)
    Actually, there is a hidden listener for window resize that suppose to set correct imgui display size but... It does not work for whatever reason. You can remove it using
    imgui:removeEventListener("applicationResize")
    or
    imgui = ImGui.new(true, true, false)
    +1 -1 (+2 / -0 )Share on Facebook
  • Thanks for the info - from that I was able to sort it out. I use my own way to scale that works for autorotating (portrait<->landscape), etc...




    I noticed that I had to add 1 to the max width in order to make it perfect...




    Here is my code:


    2021-01-11_12-04-19.png
    1622 x 1076 - 105K
    2021-01-11_12-05-05.png
    801 x 498 - 27K
    2021-01-11_12-06-14.png
    1234 x 876 - 117K

    Likes: MoKaLux

    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
    +1 -1 (+1 / -0 )Share on Facebook
  • SinisterSoftSinisterSoft Maintainer
    edited January 2021
    When I send to Android, if I touch the screen then it crashes (that's without my resize code) - is this a known issue?

    (desktop and html5 work fine)
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • Chatted to @hgy29 about it, he suggests it is 'Probably touch handling issue, but mouse ok' - what do you think @rrraptor ?
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • When I send to Android, if I touch the screen then it crashes (that's without my resize code) - is this a known issue?

    (desktop and html5 work fine)

    I have not tested on android. But its strange... Can you remove listeners from imgui instance and test again?
    imgui:removeAllListeners()
    -- OR 
    ImGui.new(false, false, false)
  • SinisterSoftSinisterSoft Maintainer
    edited January 2021
    Tried ImGui.new(false, false, false) and then it works.

    Also tried imgui:removeAllListeners() and that also works.
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • I'll let you know once @hgy29 makes a new build... :)
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • It's odd though that removing the existing listeners fixed the problem? You would think that it would have worked previously, but touch would just be missing?
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • rrraptorrrraptor Member
    edited January 2021
    I need to create a pull request, so he dont need to copy pasta my code :)

    Also you can use this useful feature:
    local IO = ui:getIO()
    IO:addConfigFlags(ImGui.ConfigFlags_IsTouchScreen) -- enable touch padding
     
    -- set padding
    local Style = ImGui:getStyle()
    Style:setTouchExtraPadding(10, 10) -- expands all hitboxes, I guess

    I noticed that I had to add 1 to the max width in order to make it perfect...

    I think its because of "fit width" scale mode.

    Likes: SinisterSoft

    +1 -1 (+1 / -0 )Share on Facebook
  • SinisterSoftSinisterSoft Maintainer
    edited January 2021
    @rrraptor I tested the new version (kindly built by @hgy29)...

    With imgui, on android, when the screen is touched, it says:

    "Incorrect button index
    stack traceback:"

    Then resent back to the player, waiting for a new upload - which would be a pretty nice thing to add as a API function @hgy29 ...
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • hgy29hgy29 Maintainer
    @rrraptor, I just had a look at your changes and I spotted two issues:
    - First if the project has 'touch to mouse' or 'mouse to touch' enabled, they you'll end up handling the events twice. Since you handle touch natively, you should check if the event was a 'converted' one or not
    - Second, and maybe Android specific, it can happen that some touch move events are reported without any finger (weird!), and Gideros translates this to mouse_move event without buttons, which causes the crash @SinisterSoft is experiencing.

    I think both issues can be fixed at the same time, by disregarding converted events. Trouble is there doesn't seem to be a way to distinguish them currently, so maybe do one of the following things:
    - Add a flag to tell if touch or mouse should be listened to (and let the developer decide)
    - Do what is appropriate automatically based on the platform
    - Handle the case where a button value of 0 (GINPUT_NO_BUTTONS) is given in MOUSE_MOVE, maybe processing it as it to a MOUSE_HOVER instead

    What do you think ?

    Likes: SinisterSoft

    +1 -1 (+1 / -0 )Share on Facebook
  • SinisterSoftSinisterSoft Maintainer
    edited January 2021
    Yes, it happened on a Samsung phone - maybe they have some kind of proximity detection for gestures? So hover would be the correct response?

    https://stackoverflow.com/questions/16649830/proximity-sensor-on-galaxy-s4-air-gestures
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • So the problem with converting gideros buttons to ImGui I guess ?)
    https://github.com/gideros/gideros/blob/5fa2ea68f0cee907e5271359a36e010e261c4939/plugins/imgui/source/Common/imgui_bindings.cpp#L144

    In order to tell ImGui which mouse button is pressed you need to set MouseDown value. Gideros buttons are:
    - 0: none
    - 1: left
    - 2: right
    - 4: middle
    - 8: extra button
    - 16: extra button

    ImGui:
    - 0: left
    - 1: right
    - 2: middle
    - 3: extra button (unused in my binding)
    - 4: extra button (unused in my binding)
    hgy29 said:

    - Add a flag to tell if touch or mouse should be listened to (and let the developer decide)

    Already there :smiley: :
    https://github.com/gideros/gideros/blob/5fa2ea68f0cee907e5271359a36e010e261c4939/plugins/imgui/source/Common/imgui_bindings.cpp#L1185
    Just pass true/false to ImGui.new() to enable/disable listeners.
  • probably it does not matter, but don't forget about pen behaviour to work well too.
  • rrraptorrrraptor Member
    edited January 2021
    keszegh said:

    probably it does not matter, but don't forget about pen behaviour to work well too.

    Which event type is that?)

    I can add custom function, so you can fill correct values for ImGui on your own. And if something went wrong, you can debug the issue without recompiling the plugin :smile:
  • whatever, i don't exactly understand your idea but probably it's useful.

    in any case i just remember this issue still being open:
    https://github.com/gideros/gideros/issues/228
    and sounds like the current issue with imgui might somehow breed another problem related to pen events, so i thought i shall warn you.
  • hgy29hgy29 Maintainer
    rrraptor said:


    hgy29 said:

    - Add a flag to tell if touch or mouse should be listened to (and let the developer decide)

    Already there :smiley: :
    https://github.com/gideros/gideros/blob/5fa2ea68f0cee907e5271359a36e010e261c4939/plugins/imgui/source/Common/imgui_bindings.cpp#L1185
    Just pass true/false to ImGui.new() to enable/disable listeners.
    Ahh, great, so @SinisterSoft could already enable either touch or mouse (and not both) depending on the platform that way.

    Likes: SinisterSoft

    +1 -1 (+1 / -0 )Share on Facebook
  • Ideally, both should work - as you can plug a mouse into Android - or they may be running on Chrome. You could also have touch on Windows.
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • rrraptorrrraptor Member
    edited January 2021
    https://github.com/gideros/gideros/pull/501

    Idk if problem is fixed, but I have added new functions, so you can use them to handle mouse/touch inputs by yourself.

    Example:
    local ui = ImGui.new(false, false, false) -- disable all events
    --ui:setResetTouchPosOnEnd(true) -- if enabled resets touch pos to INF on "touchesEnd" event.
    IO:setMouseDrawCursor(true, false) -- draw cursor, without hiding system cursor (second arg)
    local IO = ui:getIO()
    stage:addChild(ui)
     
    stage:addEventListener("enterFrame", function(e)
    	ui:newFrame(e)
     
    	ui:showDemoWindow()
     
    	ui:render()
    	ui:endFrame()
    end)
     
    -- imgui_button_index: 0 to 4 (int)
    -- state: bool
    -- IO:setMouseDown(imgui_button_index, state)
    -- IO:setMousePos(x, y)
    -- IO:setMouseWheel(value)
     
    stage:addEventListener("touchesBegin", function(e)
    	local x, y = e.touch.x, e.touch.y
    	IO:setMouseDown(0, true)
    	IO:setMousePos(x, y)
    end)
     
    stage:addEventListener("touchesMove", function(e)
    	local x, y = e.touch.x, e.touch.y
    	IO:setMouseDown(0, true)
    	IO:setMousePos(x, y)
    end)
     
    stage:addEventListener("touchesEnd", function(e)
    	local x, y = e.touch.x, e.touch.y
    	IO:setMouseDown(0, false)
    	IO:setMousePos(x, y)
    end)
    P.S.

    imGui constructor is changed

    to
    ImGui.new([mouseEvents = true, keyboardEvent = true, touchEvents = false])
    +1 -1 (+2 / -0 )Share on Facebook
  • If @hgy29 gets time to make a test built, I'll test it asap. :)
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • rrraptorrrraptor Member
    edited January 2021
    @hgy29 hm...seems like you cant render ImGui to RenderTarget or Viewport. Is it possible to fix?)
  • hgy29hgy29 Maintainer
    I don't understand why it wouldn't work, what happens ?
  • hgy29 said:

    I don't understand why it wouldn't work, what happens ?

    Nevermind xD

    Works this way:
    UI:newFrame(e)
    UI:showDemoWindow()
    local needToRender = UI:button("HIT ME")
    UI:render()
    if (needToRender) then 
    	RT:clear(0,0) 
    	RT:draw(UI) 
    end
    UI:endFrame()
    But does not this way (because Im trying to render GUI to RT before ImGui:render() call):
    UI:newFrame(e)
    UI:showDemoWindow()
    if (UI:button("HIT ME")) then 
    	RT:clear(0,0) 
    	RT:draw(UI) 
    end
    UI:render()
    UI:endFrame()

    Likes: MoKaLux

    +1 -1 (+1 / -0 )Share on Facebook
  • @hgy29 I have a problem with something (sound weird, sorry :D )
    Ive changed fonts API a little bit to be able to add custom glyph ranges.

    Im using MaterialIcons font for icons (you can check glyphs here: https://fontdrop.info/). In order to add specific icons to ImGui I decided to stick with this structure:
    local FontAtlas = io:getFonts()
    local icons = FontAtlas:addFont("MaterialIcons-Regular.ttf", 16, {
    	glyphs = {
    		ranges = { -- multiple ranges
    			{0xE3A2,0xE3A5},
    			--ImGui.GlyphRanges_XXX -- any set of available constants
    		},
    		chars = { -- single char codes
    			0xE872, -- trash
    			0xE8F4, -- on
    			0xE8F5, -- off
    			0xE3C9, -- pen
    			0xE161, -- save
    			0xE05E, -- new
    			0xE3A5, -- particles
    			0xE14C, -- X
    		},
    	},
    	oversampleH = 2,
    	oversampleV = 1,
    	glyphOffsetX = -1,
    	glyphOffsetY = 4,
    	pixelSnapH = true,
    	mergeMode = true,
    })
    FontAtlas:bake()
     
    -- ranges structure is a table where if value is a table then it is a custom range, if number then it is GlyphRanges_XXX constant, otherwise - error.
    The problem is that my code SOMETIMES works and sometimes it doesn't. For example, I launch a project and see "?" Instead of icons, and sometimes everything is fine. Maybe there is a problem somewhere in the loading of glyphs? Or that "ImGui" is a static library and when restarting the project, you need to clear the memory, but I do not quite understand where in the code it should be done.

    So, can you please check the binding for this function?) Especially table parsing: https://github.com/MultiPain/Gideros_ImGui/blob/bd8b290fcecc43dbc6627590fcfe1d9b2b2e9583/main.cpp#L7700
    "ranges" table parse:
    https://github.com/MultiPain/Gideros_ImGui/blob/bd8b290fcecc43dbc6627590fcfe1d9b2b2e9583/main.cpp#L7651
    Maybe its me, who messed up with lua stack :smiley:

    Here it works:

    Here, it does not:
    GParticles2.png
    409 x 575 - 20K
    GParticles3.png
    365 x 585 - 6K
  • hgy29hgy29 Maintainer
    I had a quick llok and didn't find any defect in your code that could explain the problem. The checks on lines 7634 and 7654, don't test the right index (should be -1), but that's not the problem. Maybe, like you say, an initialization issue. I will check a bit deeper, but you know the code better than me :)
Sign In or Register to comment.