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

imGui bindings

1789101113»

Comments

  • SinisterSoftSinisterSoft Maintainer
    edited October 1
    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
  • that does not matter i think. it would check if it is pressed or not, that's unambiguous.
  • v1.80 should be a nice release - they are adding in the tables.
    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
  • @rrraptor , thanks. although i also decided not to use the docking features as of now as i need fixed size windows (or at least fixed minimum size, which i did not see how to make), let's see when docking becomes part of the main branch.
  • rrraptorrrraptor Member
    edited October 12
    keszegh said:

    i need fixed size windows (or at least fixed minimum size, which i did not see how to make)

    So you can do it like this:
    local function minSizeCallback(windowX, windowY, windowW, windowH, desiredW, desiredH)
    	-- do some math and return desired size
    	return desiredW, desiredH
    end
     
    local draw = true
     
    local function drawGui(e)
    	globalUI:newFrame(e)
     
    	globalUI:setNextWindowSizeConstraints(200, 100, 100000, 100000) -- min and max size
    	draw = ImGui:beginWindow("my window", nil, 0, minSizeCallback)
    	if (draw) then 
    		globalUI:text("Hello world")
    		globalUI:endWindow()
    	end
     
    	globalUI:render()
    	globalUI:endFrame()
    end

    Likes: keszegh

    +1 -1 (+1 / -0 ) Share on Facebook
  • Made it so mouse position adapts to screen coordinates.

    scaling.gif
    324 x 308 - 574K
  • i'm not sure i get what happens on the video, but looks cool. : )

    Likes: rrraptor

    +1 -1 (+1 / -0 ) Share on Facebook
  • rrraptorrrraptor Member
    edited October 20
    keszegh said:

    i'm not sure i get what happens on the video, but looks cool. : )

    Im trying to make it work with gideros scale modes (letterbox and etc). So if application window scales up or down, mouse position calculates correctly.

    @hgy29 can you help with that?)

    I did it this way:
    added event listener for "applicationResize"
    double getApplicationProperty(lua_State* L, const char* name)
    {
        lua_getglobal(L, "application"); // application
        lua_getfield(L, -1, name);       // application[name]
        lua_getglobal(L, "application"); // application[name], application
        lua_call(L,1,1);                 // application[name](application)
        double value = luaL_checknumber(L, -1); // value, application.name
        lua_pop(L, 2);
     
        return value;
    }
     
    ImVec4 getApplicationBounds(lua_State* L)
    {
        lua_getglobal(L, "application");
        lua_getfield(L, -1, "getLogicalBounds");
        lua_getglobal(L, "application");
        lua_call(L,1,4);
        double minX = luaL_checknumber(L, -4);
        double minY = luaL_checknumber(L, -3);
        double maxX = luaL_checknumber(L, -2);
        double maxY = luaL_checknumber(L, -1);
        lua_pop(L, 5);
        // top left corner and size   
        return ImVec4(minX, minY, maxX - minX, maxY - minY);
    }
     
    ImVec2 getApplicationScale(lua_State* L)
    {
        double sx = getApplicationProperty(L, "getLogicalScaleX");
        double sy = getApplicationProperty(L, "getLogicalScaleY");
     
        return ImVec2(sx, sy);
    }
    // EventListener function
    void applicationResize(Event *)
    {
        app_scale = getApplicationScale(L);
        r_app_scale.x = 1.0f / app_scale.x;
        r_app_scale.y = 1.0f / app_scale.y;
        app_bounds = getApplicationBounds(L);
    }


    And when I calculate mouse position:
    static ImVec2 getMousePos(SpriteProxy* proxy, float x, float y, ImVec2 r_app_scale, ImVec4 app_bounds)
    {
        return ImVec2(
            (x * r_app_scale.x + app_bounds.x - proxy->x()) * 1.0f / proxy->scaleX(),
            (y * r_app_scale.y + app_bounds.y - proxy->y()) * 1.0f / proxy->scaleY()
        );
    }
     
    // EventListener for mouse events:
    ImGuiIO& io = ImGui::GetIO();
    // x, y - mouse position from MouseEvent (goes from 0 to window width/height)
    io.MousePos = getMousePos(proxy, x, y, r_app_scale, app_bounds);


    Is it OK or there is a better solution?
  • rrraptorrrraptor Member
    edited October 20
    Spent whole day trying to make dockbuilder work and here is the result:

    Code:
    -- flags to emulate fullscreen window
    local window_flags = ImGui.WindowFlags_NoTitleBar | ImGui.WindowFlags_NoCollapse | ImGui.WindowFlags_NoResize | ImGui.WindowFlags_NoMove | ImGui.WindowFlags_NoBringToFrontOnFocus | ImGui.WindowFlags_NoNavFocus
     
    EditorScene = Core.class(Sprite)
     
    function EditorScene:init()
    	self.imgui = ImGui.new()
    	self:addChild(self.imgui)
     
    	local IO = self.imgui:getIO()
    	IO:setIniFilename(nil) -- disable INI file
    	IO:addConfigFlags(ImGui.ConfigFlags_DockingEnable)
     
    	self:addEventListener("enterFrame", self.drawGUI, self)
    end
    --
    function EditorScene:drawGUI(e)
    	local UI = self.imgui
     
    	UI:newFrame(e)
    	local dockspace_id = UI:getID("root")
     
    	if (not UI:dockBuilderCheckNode(dockspace_id)) then -- called once
    		self:createDock(UI, dockspace_id)
    	end
     
    	local IO = self.imgui:getIO()
    	UI:setNextWindowPos(0, 0)
    	UI:setNextWindowSize(IO:getDisplaySize())
     
    	UI:pushStyleVar(ImGui.StyleVar_WindowRounding, 0)
    	UI:pushStyleVar(ImGui.StyleVar_WindowBorderSize, 0)
    	UI:pushStyleVar(ImGui.StyleVar_WindowPadding, 0, 0)
    	UI:beginWindow("DockSpace Demo", nil, window_flags)
    	UI:popStyleVar(3)
     
    	UI:dockSpace(dockspace_id, 0, 0)
        UI:endWindow()
     
    	if (UI:beginWindow("Log", nil)) then 
    		UI:value("Random", math.random()) 
    	end
        UI:endWindow()
     
    	if (UI:beginWindow("Properties", nil)) then
    	end
        UI:endWindow()
     
    	if (UI:beginWindow("Grid", nil)) then
    	end
        UI:endWindow()
     
    	UI:render()
    	UI:endFrame()
    end
    --
    function EditorScene:createDock(UI, dockspace_id)
    	UI:dockBuilderRemoveNode(dockspace_id) -- clear existing layout
    	UI:dockBuilderAddNode(dockspace_id) -- add empty node
     
    	-- split main node into 2 (left and right node), return left panel id AND modified dockspace id
    	local dock_id_left,_,dockspace_id= UI:dockBuilderSplitNode(dockspace_id, ImGui.Dir_Left, 0.2, nil, dockspace_id)
     
    	-- split right node into 2, return bottom panel id
    	local dock_id_bottom = UI:dockBuilderSplitNode(dockspace_id, ImGui.Dir_Down, 0.2, nil, dockspace_id)
     
    	-- split right node into 2 (but in different direction), return top panel id
    	local dock_id_top = UI:dockBuilderSplitNode(dockspace_id, ImGui.Dir_Up, 0.7, nil, dockspace_id)
     
    	UI:dockBuilderDockWindow("Log", dock_id_bottom)
    	UI:dockBuilderDockWindow("Grid", dock_id_up)
    	UI:dockBuilderDockWindow("Properties", dock_id_prop)
    	UI:dockBuilderFinish(dockspace_id)
    end

    Also, Ive noticed this:

    ini file contains imgui window settings.
    You can disable it like I did ( IO:setIniFilename(nil) ). But I want to make it so it will be stored somewhere in gideros documents folder ("|D|imgui.ini" or something like that). Same for .log file ( ImGui:logToFile() )

    Likes: MoKaLux

    imgui_dockbuilder_test.png
    942 x 557 - 5K
    image.png
    188 x 106 - 4K
    +1 -1 (+1 / -0 ) Share on Facebook
  • I will play with it and see what I can do for the wiki :) thank you rrraptor for yet another great contribution to gideros <3 .
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • hgy29hgy29 Maintainer
    rrraptor said:

    Is it OK or there is a better solution?

    I guess it won't work if you put your imgui sprite inside another sprite with its own transform. Ideally you would want to retrieve mouse coordinate in logical stage space such as what Gideros reports in lua, then perform th equivalent of globalToLocal on your sprite. The latter is easy if you have a lua context, but I am not sure to get the former directly from gideros, without having to mimic it like you do.

  • rrraptorrrraptor Member
    edited October 20
    MoKaLux said:

    I will play with it and see what I can do for the wiki :)<3 .</p>

    Dockbuilder and imgui docking branch is in BETA, so idk if it worth to mention.
    hgy29 said:

    rrraptor said:

    Is it OK or there is a better solution?

    I guess it won't work if you put your imgui sprite inside another sprite with its own transform. Ideally you would want to retrieve mouse coordinate in logical stage space such as what Gideros reports in lua, then perform th equivalent of globalToLocal on your sprite. The latter is easy if you have a lua context, but I am not sure to get the former directly from gideros, without having to mimic it like you do.

    Well I can do something like
    auto curr = proxy;
    while (curr)
    {
    curr->matrix().transformPoint(x, y, newX, newY);
    curr = curr->parent();
    }
    ?
  • hgy29hgy29 Maintainer
    That would do localToGlobal transform while you want the opposite, but yes that's the idea, or just call globalToLocal lua function. Also avoid using "auto" as I am not sure all compilers (I mean for each platform) support C++11.
  • hgy29 said:

    Also avoid using "auto" as I am not sure all compilers (I mean for each platform) support C++11.

    Im not using it :) Just for this example.
    hgy29 said:

    That would do localToGlobal transform while you want the opposite, but yes that's the idea, or just call
    lua function.

    Ah, why it does not work xD

    Anyways, I can take code from here. https://github.com/gideros/gideros/blob/2e4aa2fd3550a7c4d2da9a5d9ac755bfe68d4eae/2dsg/sprite.cpp#L696


    globaltolocal.png
    446 x 125 - 11K
  • hgy29hgy29 Maintainer
    rrraptor said:


    Ah, why it does not work xD

    Because that symbol is not exported in the DLL... Welcome to the wonderful world of cross platform nightmares...

  • hgy29 said:

    That would do localToGlobal transform while you want the opposite, but yes that's the idea, or just call globalToLocal lua function.

    Done.
    static ImVec2 getMousePos(SpriteProxy* proxy, float x, float y, ImVec2 r_app_scale, ImVec4 app_bounds)
    {
        std::stack<const Sprite*> stack;
     
        x = x * r_app_scale.x + app_bounds.x;
        y = y * r_app_scale.y + app_bounds.y;
     
        const Sprite* curr = proxy;
        while (curr)
        {
            stack.push(curr);
            curr = curr->parent();
        }
     
        float z;
        while (!stack.empty())
        {
            stack.top()->matrix().inverseTransformPoint(x, y, 0, &x, &y, &z);
            stack.pop();
        }
     
        return ImVec2(x, y);
    }
Sign In or Register to comment.