Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Topics - EngineerBread

#1
Hi I hope you all are doing well.
The title didn't let me put the complete string so here it comes: "Gui-builder: Being able to move items inside/outside another items hierarchy using the hierarchy tree"
So the title pretty much says it all, I want to be able to move items inside/outside of another items hierarchy if they are allowed, like in the example that I show in the image, for example if we have on tgui::TreeView inside of a tgui::ChildWindow and I want to remove that tree from that childWindow to put it inside someone else. I think that could really be useful.
I tried to do that but I don't think its the right approach, here is what I did:

image_2024-07-17_114104568.png

1. I made the tgui::TreeView inherit from tgui::ClickableWidget instead of Widget
2. I created to new internal methods for tgui::TreeView

    std::vector<String> TreeView::getItemAtPosition(const Vector2f & position) const
    {
        Vector2f pos(position);
        const float itemHeight = getItemHeight();

        // Adjust position for the scrollbar
        if (m_verticalScrollbar->isShown())
        {
            pos.y += m_verticalScrollbar->getValue();
        }

        std::vector<String> itemPath;
        float currentY = 0;
        findItemAtPosition(m_nodes, pos, itemHeight, currentY, itemPath);
        return itemPath;
    }

    bool TreeView::findItemAtPosition(const std::vector<std::shared_ptr<Node>> &nodes, Vector2f pos, float itemHeight,
        float &currentY, std::vector<String> &path) const
    {
        for (const auto& node : nodes)
        {
            // Check if the current item is at the mouse position
            if (pos.y >= currentY && pos.y < currentY + itemHeight)
            {
                path.push_back(node->text.getString());
                return true;
            }
            currentY += itemHeight;

            // Check children nodes
            if (!node->nodes.empty())
            {
                if (findItemAtPosition(node->nodes, pos, itemHeight, currentY, path))
                {
                    path.insert(path.begin(), node->text.getString()); // Insert parent at the beginning
                    return true;
                }
            }
        }
        return false;
    }

3. Then I modified GuiBuilder.cpp to add:

    m_widgetHierarchyTree->onMousePress([=, this](const tgui::Vector2f& pos) {
        draggingItem = m_widgetHierarchyTree->getItemAtPosition(pos);
        std::cout<<draggingItem.back().toStdString()<<std::endl;
        if(!draggingItem.empty())
        {
            isDragging = true;
        }
    });

    m_widgetHierarchyTree->onMouseRelease([=, this](const tgui::Vector2f& pos) {
       if(isDragging)
       {
           auto targetItem(m_widgetHierarchyTree->getItemAtPosition(pos));
           if(!targetItem.empty())
           {
               targetItem.push_back(draggingItem.back());
               m_widgetHierarchyTree->removeItem(draggingItem);

               m_widgetHierarchyTree->addItem(targetItem);
               isDragging = false;
           }
       }
    });

It only moves move element from the treeview to another branch of it, and it doesn't even work properly, but Its an example of what I'm proposing. Like it said it would be pretty good to have this feature.
#2
Hi community I hope you are doing well.
My problem is the following one: I have a custom ListBox type in order to add a "onRightClick" signal, here is the code:

class ImprovedListBox : public tgui::ListBox
{
private:
    float getItemHeight();
public:
    typedef std::shared_ptr<ImprovedListBox> Ptr; ///< Shared widget pointer
    typedef std::shared_ptr<const ImprovedListBox> ConstPtr; ///< Shared constant widget pointer

    // Signal for left-click events
    tgui::Signal onRightClick = { "rightClick" };

    // Factory function to create the custom list box
    static ImprovedListBox::Ptr create();
    static ImprovedListBox::Ptr copy(const tgui::ListBox::Ptr &);
protected:
    void rightMousePressed(tgui::Vector2f pos) override;
};

No problems so far, I have a tgui::ListBox added to my form using the tool gui-builder, the problem comes when trying to cast that previously added ListBox into my own type, here is the code:

auto vanillaList(gui->get<tgui::ListBox>("EntitiesList"));
auto entitiesList=vanillaList->cast<ImprovedListBox>();

I've tried everything, I tried std::dynamic_cast and std::static_cast but the problem persist, so I wanted to ask.
Which's the right way to do this?
What I'm trying to do is even correct?

Thanks and regards!! (^-^)/
#3
Hi, I hope everyone is doing well.
I'm here so to expose a problem that I encountered while I was coding a pseudo context menu, the problem comes when trying to remove the afore mentioned menu, I get the following exception (I attached the screenshot)
1.png
image_2024-05-17_210506550.png
This is the code, I do not really know if I'm doing something wrong or if its a problem with TGUI library itself
   
auto resourceFileTree(gui->get<tgui::TreeView>("ProjectTree"));

    resourceFileTree->onRightClick([=, this](const tgui::String& elem){

        std::string pathyding(getFullPath(elem));

        if(pathyding.empty())
        {
            return;
        }

        if(!activeContextMenu)
        {
            auto contextMenu(tgui::Panel::create());
            auto mousePos(sf::Mouse::getPosition(mgr->getContext()->window->getHandle()));
            contextMenu->setPosition(mousePos.x, mousePos.y);
            contextMenu->setSize(100, 150);
            contextMenu->getRenderer()->setBackgroundColor(sf::Color::White);
            contextMenu->getRenderer()->setBorderColor(sf::Color::Black);

            gui->add(contextMenu);

            contextMenu->onMouseLeave([=, this] {
                gui->remove(contextMenu);
                activeContextMenu = false;
            });

            auto viewButton(tgui::Label::create("View"));
            viewButton->getRenderer()->setTextColor(sf::Color::Black);
            viewButton->setTextSize(12);

            viewButton->onClick([=, this] {
                //auto windowsPos(mgr->getContext()->window->getSize());
                //auto windowsSize(mgr->getContext()->window->getSize());

                auto viewWindow(tgui::ChildWindow::create("Preview"));

                if (isImage(pathyding))
                {
                    loadImg(viewWindow, pathyding);
                }
                else
                {
                    loadText(viewWindow, pathyding);
                }

                gui->add(viewWindow);
                gui->remove(contextMenu);
                activeContextMenu = false;

            });

            contextMenu->add(viewButton);

            auto deleteButton(tgui::Label::create("Delete"));
            deleteButton->setPosition(deleteButton->getPosition().x, viewButton->getSize().y);
            deleteButton->getRenderer()->setTextColor(sf::Color::Black);
            deleteButton->setTextSize(12);
            deleteButton->onClick([=, this]{
                resourceFileTree->removeItem(resourceFileTree->getSelectedItem());
                auto assetToBeRemoved(assetManager->queryAsset(elem.toStdString()));
                if(assetToBeRemoved)
                {
                    switch (assetToBeRemoved->getType())
                    {
                        case Bread::ResourceType::RESOURCE_GRAPHIC:
                            assetManager->removeAsset<Bread::TextureAsset>(assetToBeRemoved->getId());
                            break;
                        case Bread::ResourceType::RESOURCE_TEXT:
                            assetManager->removeAsset<Bread::FontAsset>(assetToBeRemoved->getId());
                            break;
                        case Bread::ResourceType::RESOURCE_SOUND:
                            assetManager->removeAsset<Bread::SoundAsset>(assetToBeRemoved->getId());
                            break;
                        case Bread::ResourceType::RESOURCE_MUSIC:
                            assetManager->removeAsset<Bread::MusicAsset>(assetToBeRemoved->getId());
                            break;
                    }
                    logger->log(LEVEL::LOG, "The asset: "+elem.toStdString()+" has been deleted");
                }

                gui->remove(contextMenu);
            });
            contextMenu->add(deleteButton);


            activeContextMenu = true;
        }
    });


Here is the call stack:

Capture.PNG
Capture.PNG
#4
Hi, I hope everybody is doing well.
I've been trying to create a context menu whenever I right click in one of the elements of a TreeView, since TGUI does not have a ContextMenu per se, I created my own using a tgui::Panel, anyway as I was trying to use the function onItemSelect from the TreeView I noticed that the Panel is not being generated, I've tried passing the function a tgui::Vector2f, a tgui::String and even a std::vector<tgui::String> but to no avail, here is my code, if somebody could help me to solve it, I will greatly appreciate it.

Note: if I use a tgui::Vector2f I get the following warning: "TGUI warning: Failed to parse Vector2 'mainWindow.txt'. Expected numbers separated with a comma."

void EditorScene::loadResources()
{
    auto resourceFileTree(gui->get<tgui::TreeView>("Resources"));
    populateTree(resourcesPath, resourceFileTree, nullptr);
    resourceFileTree->onItemSelect([&](const tgui::Vector2f& elem){

        auto contextMenu(tgui::Panel::create());
        contextMenu->setPosition(sf::Mouse::getPosition().x, sf::Mouse::getPosition().y);
        contextMenu->setSize(100, 150);
        contextMenu->getRenderer()->setBackgroundColor(sf::Color::White);
        contextMenu->getRenderer()->setBorderColor(sf::Color::Black);

        auto viewButton(tgui::Label::create("View"));
        viewButton->getRenderer()->setTextColor(sf::Color::Black);
        viewButton->setTextSize(12);
        contextMenu->add(viewButton);

        auto deleteButton(tgui::Label::create("Delete"));
        deleteButton->getRenderer()->setTextColor(sf::Color::Black);
        deleteButton->setTextSize(12);
        contextMenu->add(deleteButton);

        contextMenu->onMouseLeave([&]{
           gui->remove(contextMenu);
        });

        gui->add(contextMenu);
    });

}
#5
Hello everyone, I hope you are doing well.
I recently downloaded the TGUI library and tried to link it statically to my project, but when I try to compile it, I'm getting the following linking errors:

tgui-s-d.lib(unity_WINDOW_BACKEND_SFML_cxx.obj) : error LNK2019: unresolved external symbol "public: bool __cdecl sf::WindowBase::isOpen(void)const " (?isOpen@WindowBase@sf@@QEBA_NXZ) referenced in function "public: virtual void __cdecl tgui::BackendGuiSFML::mainLoop(class tgui::Color)" (?mainLoop@BackendGuiSFML@tgui@@UEAAXVColor@2@@Z)
tgui-s-d.lib(unity_batch-15_cxx.obj) : error LNK2001: unresolved external symbol "public: bool __cdecl sf::WindowBase::isOpen(void)const " (?isOpen@WindowBase@sf@@QEBA_NXZ)
tgui-s-d.lib(unity_WINDOW_BACKEND_SFML_cxx.obj) : error LNK2019: unresolved external symbol "public: bool __cdecl sf::WindowBase::pollEvent(class sf::Event &)" (?pollEvent@WindowBase@sf@@QEAA_NAEAVEvent@2@@Z) referenced in function "public: virtual void __cdecl tgui::BackendGuiSFML::mainLoop(class tgui::Color)" (?mainLoop@BackendGuiSFML@tgui@@UEAAXVColor@2@@Z)
tgui-s-d.lib(unity_batch-15_cxx.obj) : error LNK2001: unresolved external symbol "public: bool __cdecl sf::WindowBase::pollEvent(class sf::Event &)" (?pollEvent@WindowBase@sf@@QEAA_NAEAVEvent@2@@Z)
tgui-s-d.lib(unity_WINDOW_BACKEND_SFML_cxx.obj) : error LNK2019: unresolved external symbol "public: class sf::Vector2<unsigned int> __cdecl sf::WindowBase::getSize(void)const " (?getSize@WindowBase@sf@@QEBA?AV?$Vector2@I@2@XZ) referenced in function "protected: virtual void __cdecl tgui::BackendGuiSFML::updateContainerSize(void)" (?updateContainerSize@BackendGuiSFML@tgui@@MEAAXXZ)
tgui-s-d.lib(unity_WINDOW_BACKEND_SFML_cxx.obj) : error LNK2019: unresolved external symbol "public: void __cdecl sf::WindowBase::setMouseCursor(class sf::Cursor const &)" (?setMouseCursor@WindowBase@sf@@QEAAXAEBVCursor@2@@Z) referenced in function "public: virtual void __cdecl tgui::BackendSFML::detatchGui(class tgui::BackendGui *)" (?detatchGui@BackendSFML@tgui@@UEAAXPEAVBackendGui@2@@Z)
tgui-s-d.lib(unity_WINDOW_BACKEND_SFML_cxx.obj) : error LNK2019: unresolved external symbol "public: struct HWND__ * __cdecl sf::WindowBase::getSystemHandle(void)const " (?getSystemHandle@WindowBase@sf@@QEBAPEAUHWND__@@XZ) referenced in function "public: virtual void __cdecl tgui::BackendGuiSFML::updateTextCursorPosition(class tgui::Rect<float>,class tgui::Vector2<float>)" (?updateTextCursorPosition@BackendGuiSFML@tgui@@UEAAXV?$Rect@M@2@V?$Vector2@M@2@@Z)
tgui-s-d.lib(BackendFontSFML.obj) : error LNK2019: unresolved external symbol "public: bool __cdecl sf::Font::hasGlyph(unsigned int)const " (?hasGlyph@Font@sf@@QEBA_NI@Z) referenced in function "public: virtual bool __cdecl tgui::BackendFontSFML::hasGlyph(char32_t)const " (?hasGlyph@BackendFontSFML@tgui@@UEBA_N_U@Z)
tgui-s-d.lib(BackendFontSFML.obj) : error LNK2019: unresolved external symbol "public: float __cdecl sf::Font::getKerning(unsigned int,unsigned int,unsigned int,bool)const " (?getKerning@Font@sf@@QEBAMIII_N@Z) referenced in function "public: virtual float __cdecl tgui::BackendFontSFML::getKerning(char32_t,char32_t,unsigned int,bool)" (?getKerning@BackendFontSFML@tgui@@UEAAM_U0I_N@Z)
tgui-s-d.lib(unity_batch-15_cxx.obj) : error LNK2019: unresolved external symbol "public: void __cdecl sf::WindowBase::setIcon(unsigned int,unsigned int,unsigned char const *)" (?setIcon@WindowBase@sf@@QEAAXIIPEBE@Z) referenced in function "public: virtual void __cdecl tgui::BackendWindowSFML::setIcon(class tgui::String const &)" (?setIcon@BackendWindowSFML@tgui@@UEAAXAEBVString@2@@Z)

This is my cmake file:

add_library("BreadEngineCore" STATIC
  "BreadEngineCore/src/BreadEngine.h"
      "BreadEngineCore/src/Core/Application/application.cpp"
      "BreadEngineCore/src/Core/Application/application.h"
      "BreadEngineCore/src/Core/Application/entrypoint.h"
      "BreadEngineCore/src/Core/Application/sharedcontext.h"
      "BreadEngineCore/src/Core/AssetManager/assetmanager.cpp"
      "BreadEngineCore/src/Core/AssetManager/assetmanager.h"
      "BreadEngineCore/src/Core/Audio/audiohandler.cpp"
      "BreadEngineCore/src/Core/Audio/audiohandler.h"
      "BreadEngineCore/src/Core/Containers/typelist.h"
        "BreadEngineCore/src/Core/ECS/Base/Types.h"
        "BreadEngineCore/src/Core/ECS/Base/classiccomponents.h"
        "BreadEngineCore/src/Core/ECS/Base/ecs.cpp"
        "BreadEngineCore/src/Core/ECS/Base/ecs.h"
        "BreadEngineCore/src/Core/ECS/Base/vetterctor.h"
        "BreadEngineCore/src/Core/ECS/Components/animationcomponent.h"
        "BreadEngineCore/src/Core/ECS/Components/scriptcomponent.h"
        "BreadEngineCore/src/Core/ECS/Components/textlabelcomponent.h"
          "BreadEngineCore/src/Core/ECS/Systems/Animation/animationsystem.cpp"
          "BreadEngineCore/src/Core/ECS/Systems/Animation/animationsystem.h"
          "BreadEngineCore/src/Core/ECS/Systems/Camera/cameramovementsystem.cpp"
          "BreadEngineCore/src/Core/ECS/Systems/Camera/cameramovementsystem.h"
          "BreadEngineCore/src/Core/ECS/Systems/Movement/movementsystem.cpp"
          "BreadEngineCore/src/Core/ECS/Systems/Movement/movementsystem.h"
          "BreadEngineCore/src/Core/ECS/Systems/Physics/physicssystem.cpp"
          "BreadEngineCore/src/Core/ECS/Systems/Physics/physicssystem.h"
          "BreadEngineCore/src/Core/ECS/Systems/Rendering/rendercollidersystem.cpp"
          "BreadEngineCore/src/Core/ECS/Systems/Rendering/rendercollidersystem.h"
          "BreadEngineCore/src/Core/ECS/Systems/Rendering/rendersystem.cpp"
          "BreadEngineCore/src/Core/ECS/Systems/Rendering/rendersystem.h"
          "BreadEngineCore/src/Core/ECS/Systems/Rendering/rendertextsystem.cpp"
          "BreadEngineCore/src/Core/ECS/Systems/Rendering/rendertextsystem.h"
          "BreadEngineCore/src/Core/ECS/Systems/Script/scriptsystem.cpp"
          "BreadEngineCore/src/Core/ECS/Systems/Script/scriptsystem.h"
      "BreadEngineCore/src/Core/EventBus/event.h"
      "BreadEngineCore/src/Core/EventBus/eventbus.h"
      "BreadEngineCore/src/Core/Logger/Logger.cpp"
      "BreadEngineCore/src/Core/Logger/Logger.h"
        "BreadEngineCore/src/Core/Render/PhysicsRenderer/SFMLDebugDraw.cpp"
        "BreadEngineCore/src/Core/Render/PhysicsRenderer/SFMLDebugDraw.h"
        "BreadEngineCore/src/Core/Render/Window/Window.cpp"
        "BreadEngineCore/src/Core/Render/Window/Window.h"
      "BreadEngineCore/src/Core/Scene/scenemanager.cpp"
      "BreadEngineCore/src/Core/Scene/scenemanager.h"
      "BreadEngineCore/src/Core/Serializer/XMLSerializator.cpp"
      "BreadEngineCore/src/Core/Serializer/XMLSerializator.h"
      "BreadEngineCore/src/Core/Serializer/serializer.cpp"
      "BreadEngineCore/src/Core/Serializer/serializer.h"
      "BreadEngineCore/src/Core/Serializer/tmxmapparser.cpp"
      "BreadEngineCore/src/Core/Serializer/tmxmapparser.h"
      "BreadEngineCore/src/Core/Util/util.cpp"
      "BreadEngineCore/src/Core/Util/util.h"
)
if(CMAKE_BUILD_TYPE STREQUAL Debug)
  set_target_properties("BreadEngineCore" PROPERTIES
    OUTPUT_NAME "BreadEngineCore"
    ARCHIVE_OUTPUT_DIRECTORY "D:/Ingenieria/Programas, proyectos y otros/C++/SFML/BreadEngineCmake/BreadEngine/bin/Debug-windows-x86_64/BreadEngineCore"
    LIBRARY_OUTPUT_DIRECTORY "D:/Ingenieria/Programas, proyectos y otros/C++/SFML/BreadEngineCmake/BreadEngine/bin/Debug-windows-x86_64/BreadEngineCore"
    RUNTIME_OUTPUT_DIRECTORY "D:/Ingenieria/Programas, proyectos y otros/C++/SFML/BreadEngineCmake/BreadEngine/bin/Debug-windows-x86_64/BreadEngineCore"
  )
endif()
target_include_directories("BreadEngineCore" PRIVATE
  $<$<CONFIG:Debug>:D:/Ingenieria/LINKER/TinyXML/include>
  $<$<CONFIG:Debug>:D:/Ingenieria/Programas,\ proyectos\ y\ otros/C++/SFML/BreadEngineCmake/BreadEngine/BreadEngineCore/libs/glm>
  $<$<CONFIG:Debug>:D:/Ingenieria/LINKER/SFML/include>
  $<$<CONFIG:Debug>:D:/Ingenieria/Programas,\ proyectos\ y\ otros/C++/SFML/BreadEngineCmake/BreadEngine/BreadEngineCore/libs/Lua/include>
  $<$<CONFIG:Debug>:D:/Ingenieria/Programas,\ proyectos\ y\ otros/C++/SFML/BreadEngineCmake/BreadEngine/BreadEngineCore/libs/sol>
  $<$<CONFIG:Debug>:D:/Ingenieria/LINKER/ImGUI/include>
  $<$<CONFIG:Debug>:D:/Ingenieria/LINKER/Box2D/include>
  $<$<CONFIG:Debug>:D:/Ingenieria/LINKER/TmxParser/include>
  $<$<CONFIG:Debug>:D:/Ingenieria/LINKER/TGUI/include>
)
target_compile_definitions("BreadEngineCore" PRIVATE
  $<$<CONFIG:Debug>:SFML_STATIC>
  $<$<CONFIG:Debug>:TGUI_STATIC>
  $<$<CONFIG:Debug>:DEBUG>
)
target_link_directories("BreadEngineCore" PUBLIC
  $<$<CONFIG:Debug>:D:/Ingenieria/LINKER/TinyXML/libs>
  $<$<CONFIG:Debug>:D:/Ingenieria/LINKER/SFML/lib>
  $<$<CONFIG:Debug>:D:/Ingenieria/Programas,\ proyectos\ y\ otros/C++/SFML/BreadEngineCmake/BreadEngine/BreadEngineCore/libs/Lua/lib>
  $<$<CONFIG:Debug>:D:/Ingenieria/LINKER/ImGUI/lib>
  $<$<CONFIG:Debug>:D:/Ingenieria/LINKER/Box2D/lib>
  $<$<CONFIG:Debug>:D:/Ingenieria/LINKER/TmxParser/libs>
  $<$<CONFIG:Debug>:D:/Ingenieria/LINKER/TGUI/lib>
)
target_link_libraries("BreadEngineCore"
  $<$<CONFIG:Debug>:opengl32>
  $<$<CONFIG:Debug>:openal32>
  $<$<CONFIG:Debug>:freetype>
  $<$<CONFIG:Debug>:winmm>
  $<$<CONFIG:Debug>:gdi32>
  $<$<CONFIG:Debug>:flac>
  $<$<CONFIG:Debug>:vorbisenc>
  $<$<CONFIG:Debug>:vorbisfile>
  $<$<CONFIG:Debug>:vorbis>
  $<$<CONFIG:Debug>:ogg>
  $<$<CONFIG:Debug>:ws2_32>
  $<$<CONFIG:Debug>:liblua53>
  $<$<CONFIG:Debug>:sfml-graphics-s-d>
  $<$<CONFIG:Debug>:sfml-window-s-d>
  $<$<CONFIG:Debug>:sfml-system-s-d>
  $<$<CONFIG:Debug>:sfml-audio-s-d>
  $<$<CONFIG:Debug>:sfml-network-s-d>
  $<$<CONFIG:Debug>:sfml-main-d>
  $<$<CONFIG:Debug>:ImGUISNR-d>
  $<$<CONFIG:Debug>:tinyxml2d>
  $<$<CONFIG:Debug>:box2dd>
  $<$<CONFIG:Debug>:TmxParser-d>
  $<$<CONFIG:Debug>:tgui-s-d>
)
target_compile_options("BreadEngineCore" PRIVATE
  $<$<AND:$<CONFIG:Debug>,$<COMPILE_LANGUAGE:C>>:/MP>
  $<$<AND:$<CONFIG:Debug>,$<COMPILE_LANGUAGE:C>>:/MDd>
  $<$<AND:$<CONFIG:Debug>,$<COMPILE_LANGUAGE:C>>:/Z7>
  $<$<AND:$<CONFIG:Debug>,$<COMPILE_LANGUAGE:CXX>>:/MP>
  $<$<AND:$<CONFIG:Debug>,$<COMPILE_LANGUAGE:CXX>>:/MDd>
  $<$<AND:$<CONFIG:Debug>,$<COMPILE_LANGUAGE:CXX>>:/Z7>
  $<$<AND:$<CONFIG:Debug>,$<COMPILE_LANGUAGE:CXX>>:/EHsc>
)
if(CMAKE_BUILD_TYPE STREQUAL Debug)
  set_target_properties("BreadEngineCore" PROPERTIES
    CXX_STANDARD 20
    CXX_STANDARD_REQUIRED YES
    CXX_EXTENSIONS NO
    POSITION_INDEPENDENT_CODE False
    INTERPROCEDURAL_OPTIMIZATION False
  )
endif()