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

Messages - Nafffen

#1
Hey, I am trying to have a SFML Canvas in which I can navigate with 1 or 2 fingers.
I want to zoom in the view by pinching 2 fingers, but I need to keep track of each finger down and their position.
I know touch events are translated to mouse events for most cases. So I can't handle zooming with the information leftMousePressed is giving me.
Is there a trick to have a better fingers handle, or can I just cancel all tgui events for this widget and transmit SFML's ones ?
thank you
#2
"4 * (nrCornerPoints - 1)"
Oooh that's where I was wrong, I didn't see this -1 my bad  ;D
Thanks for the reply
#3
Hey, I'm not sure about this, but I looked in your drawRoundedRectHelperGetPoints code to help myself with a project, and I think your computation for Bottom left corner and Bottom right corner is slighty offset.
Instead of:
// Bottom left corner
        for (unsigned int i = 0; i < nrCornerPoints; ++i)
        {
            points.emplace_back(offset + radius + (radius * std::cos(twoPi * (2*(nrCornerPoints - 1) + i) / nrPointsInCircle)),
                                offset + size.y - radius - (radius * std::sin(twoPi * (2*(nrCornerPoints - 1) + i) / nrPointsInCircle)));
        }

        // Bottom right corner
        for (unsigned int i = 0; i < nrCornerPoints; ++i)
        {
            points.emplace_back(offset + size.x - radius + (radius * std::cos(twoPi * (3*(nrCornerPoints - 1) + i) / nrPointsInCircle)),
                                offset + size.y - radius - (radius * std::sin(twoPi * (3*(nrCornerPoints - 1) + i) / nrPointsInCircle)));
        }
The following will give more accurate result:
// Bottom left corner
        for (unsigned int i = 0; i < nrCornerPoints; ++i)
        {
            points.emplace_back(offset + radius + (radius * std::cos(twoPi * ((2*nrCornerPoints - 1) + i) / nrPointsInCircle)),
                                offset + size.y - radius - (radius * std::sin(twoPi * ((2*nrCornerPoints - 1) + i) / nrPointsInCircle)));
        }

        // Bottom right corner
        for (unsigned int i = 0; i < nrCornerPoints; ++i)
        {
            points.emplace_back(offset + size.x - radius + (radius * std::cos(twoPi * ((3*nrCornerPoints - 1) + i) / nrPointsInCircle)),
                                offset + size.y - radius - (radius * std::sin(twoPi * ((3*nrCornerPoints - 1) + i) / nrPointsInCircle)));
        }

The problem was removing 1 before multiplied by 2 (or 3 for the next corner), we need to remove it after the multiplication.

Tell me if I am wrong.
#4
Help requests / Re: behavior on phone
08 October 2023, 14:32:25
Two finger scrolling is working !
I was trying to implement the one finger scroll with your above code,
but I have a linker error on this function widgetBelowMouse->isDraggableWidget()isDraggableWidget's implementation seems to be missing in Widget.cpp ?
#5
padding is a float
m_label->setAutoSize(true);
m_label->setPosition("50%", tgui::bindWidth(m_group)*padding);

Then later in the same function :
m_group->setSize("25%", tgui::bindBottom(lastPtr)+tgui::bindWidth(m_group)*padding);

Indeed if m_label has a fixed pos, no warning. But I don't understand the dependency cycle here.

Everything is binded to the known width of m_group (25% of screen), then height of m_group is computed from last widget in the layout

The whole function is needed :
assert(m_group);
    tgui::Widget::Ptr lastPtr = nullptr;
    //between 0 and 1, %
    float padding = 0.05f;

    auto layoutVisuStack = [this, &lastPtr, padding](std::vector<C_RecipeProcessing::ItemStackVisu> &listVisu){
        if(listVisu.size()){
            auto groupItem = tgui::Group::create();

            if(lastPtr)
                groupItem->setPosition(0,tgui::bindBottom(lastPtr)+tgui::bindWidth(groupItem)*padding);
            else
                groupItem->setPosition(0,tgui::bindWidth(groupItem)*padding);

            auto nbInt = (int)listVisu.size();
            auto nbDiv = std::max(3,nbInt);
            auto l = (tgui::bindWidth(groupItem)-(tgui::bindWidth(groupItem)*padding*(nbInt+1)))/nbDiv;
            groupItem->setSize("100%", l);

            for(auto i=0;i<listVisu.size();i++){
                auto itemWidget = PictureTextWidget::create(PictureText::fromItemStack(listVisu[i].itemStack));
                itemWidget->setOrigin(0.5f,0.f);
                itemWidget->setSize(l,l);
                itemWidget->setPosition(tgui::bindWidth(groupItem)/(nbInt+1) * (i+1),0);
                groupItem->add(itemWidget);
                listVisu[i].itemStackWidget = itemWidget;
            }

            m_group->add(groupItem);
            lastPtr = groupItem;
        }
    };


    //inputs
    layoutVisuStack(m_inputs);

    //middle
    m_label = tgui::Label::create();
    m_label->setRenderer(TextureLoader::getTheme().getRenderer("LabelInfoWindow"));
    m_label->setAutoSize(true);
    m_label->setOrigin(0.5f, 0.f);
    if(lastPtr)
        m_label->setPosition("50%", tgui::bindBottom(lastPtr)+tgui::bindWidth(m_group)*padding);
    else
        m_label->setPosition("50%", tgui::bindWidth(m_group)*padding);
    m_group->add(m_label);
    lastPtr = m_label;

    if(m_recipe){
        m_panelRecipe = getGUI(m_recipe);
        m_panelRecipe->setWidth(tgui::bindWidth(m_group)*0.8);
    }

    //WARNING
    m_timeProgressBar = TimeProgressBar::create();
    m_timeProgressBar->setOrigin(0.5f, 0.f);
    m_timeProgressBar->setPosition("50%", tgui::bindBottom(m_label));
    m_timeProgressBar->setSize("90%", 40);
    m_group->add(m_timeProgressBar);
    lastPtr = m_timeProgressBar;

    //NO WARNING
    auto test = tgui::ProgressBar::create();
    test->setOrigin(0.5f, 0.f);
    test->setPosition("50%", tgui::bindBottom(m_label));
    test->setSize("90%", 40);
    m_group->add(test);
    lastPtr = test;

    //outputs
    layoutVisuStack(m_outputs);

    if(lastPtr)
        m_group->setSize("25%", tgui::bindBottom(lastPtr)+tgui::bindWidth(m_group)*padding);
    else
        m_group->setSize("25%", 0);

    updateGUI();

    std::cout << m_timeProgressBar->getPositionLayout().toString() << std::endl;
    std::cout << m_timeProgressBar->getSizeLayout().toString() << std::endl;
#6
Help requests / Re: bindParentSize ?
08 October 2023, 12:38:15
Yep thank you !
#7
Hello,
I am facing a warning :
QuoteTGUI warning: Dependency cycle detected in layout!
with this layout:
    m_timeProgressBar = TimeProgressBar::create();
    m_timeProgressBar->setOrigin(0.5f, 0.f);
    m_timeProgressBar->setPosition("50%", tgui::bindBottom(m_label));
    m_timeProgressBar->setSize("90%", 40);
    m_group->add(m_timeProgressBar);
The warning is caused by the line m_timeProgressBar->setPosition("50%", tgui::bindBottom(m_label)); If I comment it, everything is fine.
With the embedded progress bar, everything is fine :
    auto test = tgui::ProgressBar::create();
    test->setOrigin(0.5f, 0.f);
    test->setPosition("50%", tgui::bindBottom(m_label));
    test->setSize("90%", 40);
    m_group->add(test);

The weird thing is that I don't override setPosition in my custom bar:
#pragma once

#include "../../../Utils/utils.hpp"

class TimeProgressBar : public tgui::ProgressBar
{
public:
    // Add a Ptr typedef so that "MyCustomWidget::Ptr" has the correct type
    typedef std::shared_ptr<TimeProgressBar> Ptr;
    typedef std::shared_ptr<const TimeProgressBar> ConstPtr;

    TimeProgressBar();
    static TimeProgressBar::Ptr create();
    static TimeProgressBar::Ptr copy(TimeProgressBar::ConstPtr widget);

    /**
     * @brief Set the Percentage, between 0 and 1 or will be truncated
     *
     * @param percentage between 0 and 1
     */
    void setPercentage(float percentage);

    /**
     * @brief Set the Current Time, between 0 and maxTime or will be clamped
     *
     * @param time between 0 and maxTime
     */
    void setCurrentTime(sf::Time time);

    void setMaxTime(sf::Time time);
    void setReverse(bool act);


private:
    Widget::Ptr clone() const override;

    void updateText();
    void updateValue();

    /**
     * @brief the time is display with raw value currentTime / timeMax
     */
    bool m_rawValue;

    /**
     * @brief time will start from 0 to maxTime, or maxTime to 0
     */
    bool m_reverse;

    sf::Time m_currentTime;
    sf::Time m_maxTime;
};
#8
Help requests / bindParentSize ?
07 October 2023, 18:43:04
I there a way to define a size binding to a parent size without actually knowing it ?
I would like to do something like this :
    auto min = tgui::bindMin(tgui::bindParentWidth(ptr), tgui::bindParentHeight(ptr));
    ptr->setSize(min*0.16, min*0.16);
    //...somewhere else in the code...
    gui.add(ptr)
#9
Help requests / Strange crash since new build
04 October 2023, 19:44:11
I face a crash bug since I went from build baf9c5e73935453e357a9e8bda8df86bb83ed3e0 to last build (789aca88603268af99a416af6c0f11be1d03a7b8)
I cant manage to see where the bug is, this is the callstack :
libtgui-d.so.1.0.0!tgui::Container::processKeyPressEvent(tgui::Container * const this, tgui::Event::KeyEvent event) (/home/user/Desktop/dev/fc/external_deps/TGUI/src/Container.cpp:1252)
libtgui-d.so.1.0.0!tgui::BackendGui::handleEvent(tgui::BackendGui * const this, tgui::Event event) (/home/user/Desktop/dev/fc/external_deps/TGUI/src/Backend/Window/BackendGui.cpp:181)
libtgui-d.so.1.0.0!tgui::BackendGuiSFML::handleEvent(tgui::BackendGuiSFML * const this, sf::Event sfmlEvent) (/home/user/Desktop/dev/fc/external_deps/TGUI/src/Backend/Window/SFML/BackendGuiSFML.cpp:219)
GuiManager::event(GuiManager * const this, const sf::Event & event) (/home/user/Desktop/dev/fc/fc_game/src/Graphics/GuiManager.cpp:88)
SceneLogin::loop(SceneLogin * const this) (/home/user/Desktop/dev/fc/fc_game/src/Scenes/SceneLogin.cpp:169)
Application::run(Application * const this) (/home/user/Desktop/dev/fc/fc_game/src/Core/Application.cpp:259)
main() (/home/user/Desktop/dev/fc/fc_game/src/Core/Application.cpp:56)

And vsc debugger told me there is a segmentation fault in the line :
            const bool bHandled = m_focusedWidget->canHandleKeyPress(event); // TGUI_NEXT: Have keyPressed return a bool
m_focusedWidget seems to be nullptr (I dont understand that because there is a checking if just before)

The idea of my code was to lunch a callback when user presses enter when focusing an editbox.
In the Constructor of my object :
    m_editBoxEmailSignIn->onReturnKeyPress(&SceneLogin::trySignIn, this);
    m_editBoxEmailSignIn->setFocused(true);

void SceneLogin::trySignIn(){
    //TODO: remove backdoor
    if(m_editBoxEmailSignIn->getText() == "dev"){
        this->m_continueLoop = false;
        this->m_appli.launchAllLoading();
        this->m_appli.launchSceneBase({0, 0});

        return;
    }

    //bla bla bla

The strange thing is the crash only appears when the above condition if(m_editBoxEmailSignIn->getText() == "dev"){ is true, if user doesnt input "dev", then the program doesnt crash.

I am not even sure if this is about my code or something, could you give me your thoughts ?
#10
The upside down issue is no longer here !
+ Better performance
#11
Thank you very much !
#12
Yep you are right it's indeed flipped, my bad I should have looked into SFML's github issue (I just looked through forum)
I though SFML was ok because I had several other sf::RenderTexture not upside down.
I don't know where exactly SFML is broken but having a sf::Sprite directly using a sf::RenderTexture seems to be working
Thank you anyway, I'll wait the bug fix
About the performance issue, is there anything I can do to manage it ?
#13
I'm sure this is about TGUI now,
and there is also a huge FPS drop while canvas are rendered, I have not digged in into your code, but I understood that Canvas is just a sort of a wrapper around an sf::RenderTexture, with some automatic creation / resizing to fit TGUI size model
#14
Yep I use display() directly from canvas object
I have a object with :
        m_canvas->clear();
        m_sc.get().drawMapOnTarget(m_canvas->getRenderTexture(), m_viewToFocusEntity);
        m_canvas->display();
And another with:
    m_canvas->setView(m_view);
    m_canvas->clear();
    m_canvas->draw(m_spriteMiniMap);
    m_canvas->display();
Both are upside down while on Ubuntu it's ok.
Drawing in sf::RenderTexture seems to be as expected
#15
Help requests / Texture upside down with Android
03 October 2023, 11:06:49
Working with Canvas to draw some SFML stuff in a GUI.
I noticed with only Android (Ubuntu it's as expected), textures inside Canvas are rendered upside down.
I am not sure this is about TGUI or SFML though. Do you have any idea ?
#16
Hello,
Wouldn't be useful to have setTextSize of Widget take a Layout as parameter ? Now if I want to change text size when parent resize, I have to set a callback on onSizeChange signal.
Thanks
#17
Ok thank you  :)
#18
Hello, it is probably not relevant to tgui but here is my problem
I have a gRPC call in async mode, signIn asks the server and when it responds, signIn executes the given lambda, my idea was to modify tgui objects in my lambda, here m_labelStatus:
    m_labelStatus->setText("Login in...");

    m_gc.m_connectionService.signIn([this](ConnectionService::SignInReturn& signInReturn){
        if (signInReturn.status.ok()) {
            LOG_DEBUG("{}",signInReturn.data->reply.jwt());
        } else {
            LOG_DEBUG("{}: {}",(int)signInReturn.status.error_code(),signInReturn.status.error_message());
            m_labelStatus->setText("Error: "+signInReturn.status.error_message());
        }
    });

However, the program crashes when it comes to the line m_labelStatus->setText("Error: "+signInReturn.status.error_message());Here is the callstack:
ntdll.dll!ntdll!RtlRegisterSecureMemoryCacheCallback (Unknown Source:0)
ntdll.dll!ntdll!memset (Unknown Source:0)
ntdll.dll!ntdll!RtlRegisterSecureMemoryCacheCallback (Unknown Source:0)
ntdll.dll!ntdll!RtlGetCurrentServiceSessionId (Unknown Source:0)
ntdll.dll!ntdll!RtlGetCurrentServiceSessionId (Unknown Source:0)
ntdll.dll!ntdll!RtlFreeHeap (Unknown Source:0)
msvcrt.dll!msvcrt!free (Unknown Source:0)
sfml-graphics-2.dll!FT_Bitmap_Done (Unknown Source:0)
sfml-graphics-2.dll!FT_Done_Glyph (Unknown Source:0)
sfml-graphics-2.dll!sf::Font::loadGlyph(unsigned int, unsigned int, bool, float) const (Unknown Source:0)
sfml-graphics-2.dll!sf::Font::getGlyph(unsigned int, unsigned int, bool, float) const (Unknown Source:0)
sfml-graphics-2.dll!sf::Font::getKerning(unsigned int, unsigned int, unsigned int, bool) const (Unknown Source:0)
tgui.dll!tgui::BackendFontSFML::getKerning(char32_t, char32_t, unsigned int, bool) (Unknown Source:0)
tgui.dll!tgui::BackendText::updateVertices() (Unknown Source:0)
tgui.dll!tgui::BackendText::getSize() (Unknown Source:0)
tgui.dll!tgui::Label::rearrangeText() (Unknown Source:0)
operator()(const struct {...} * const __closure, ConnectionService::SignInReturn & signInReturn) (c:\FactoryCapi\app\src\main\jni\sources\Scenes\SceneLogin.cpp:210)
std::__invoke_impl<void, SceneLogin::trySignIn()::<lambda(ConnectionService::SignInReturn&)>&, ConnectionService::SignInReturn&>(std::__invoke_other, struct {...} &)(struct {...} & __f) (c:\progra~1\mingw64\include\c++\12.3.0\bits\invoke.h:61)
std::__invoke_r<void, SceneLogin::trySignIn()::<lambda(ConnectionService::SignInReturn&)>&, ConnectionService::SignInReturn&>(struct {...} &)(struct {...} & __fn) (c:\progra~1\mingw64\include\c++\12.3.0\bits\invoke.h:111)
std::_Function_handler<void(ConnectionService::SignInReturn&), SceneLogin::trySignIn()::<lambda(ConnectionService::SignInReturn&)> >::_M_invoke(const std::_Any_data &, ConnectionService::SignInReturn &)(const std::_Any_data & __functor,  __args#0) (c:\progra~1\mingw64\include\c++\12.3.0\bits\std_function.h:290)

Do you know why there is this problem ?
Previously I was handling my grpc returns in an external not async function. But it required me to have a dedicated function called once per frame... So now I am trying to directly handle grpc returns when they arrived
#19
Ok this is good with canvas, I could manage to have something cool
Quotebut if you override the isMouseOnWidget to always return false then the events should pass to the widget behind it
Yes my bad I was wrong on something,
Thank you
#20
QuoteWhich clipping? Some clipping from your own code? Because a custom widget can define a clipping region during its draw code.
Yes I was talking of my own custom clipping in my custom draw function

QuoteHave you tried drawing the sprite to a tgui::CanvasSFML (https://tgui.eu/tutorials/1.0/canvas/)?
My bad I didn't know this widget, it is quite useful indeed. Just one question, I have a canvas full screen, and most of it is transparent, but the whole canvas is triggering events so even if I click on transparent area, the event is consumed. I tried to define a custom isMouseOnWidget to return false (because I dont care about events on this widget) but the event is still consumed.

QuoteHow big an how long are you talking about?
I have a huge sf::RenderTexture somewhere, I want to do a "minimap" widget of it. I defined a custom widget to add two scrollbars and originally a tgui::sprite to draw the map. But of course the data is copied.
I should success to have something with canvasSFML
#21
Help requests / A way to avoid copying data ?
11 July 2023, 14:24:07
Is there really no way to avoid data copying when create a Sprite from sf::Texture ?
I want to have a widget that embed a huge sf::Texture, but it takes some time to copy it into a tgui::Texture and I dont like that.
I thought I could do a trick by drawing a sfml sprite in the draw function of my custom widget but the clipping doesn't work anymore obviously.
Is there a way, even tricky with custom code, to have a reference to sfml texture data ?
Thank you
#22
On nightly built,
I was using the method getTarget() from tgui::SFML_GRAPHICS::Gui object,
I've got this linker error:
ld.lld: error: undefined symbol: __declspec(dllimport) tgui::SFML_GRAPHICS::Gui::getTarget() constIn SFML_Graphics files, there is in .hpp TGUI_NODISCARD sf::RenderTarget* getTarget() const;but no implementation in .cpp, is it on purpose ?
#23
It's seems that it's due to gcc 13.1, a lot of libraries are getting this error too
#24
Hello,
I was trying to build TGUI from source with cmake:
FetchContent_Declare(
  tgui
  GIT_REPOSITORY https://github.com/texus/TGUI
  GIT_TAG v1.0-beta
)
set(TGUI_BACKEND SFML_GRAPHICS)
FetchContent_MakeAvailable(tgui)

With compiler: winlibs-x86_64-posix-seh-gcc-13.1.0-mingw-w64msvcrt-11.0.0-r5
On Windows 10 64bits
With set(CMAKE_CXX_STANDARD 20)

I have got some errors in Utf.hpp file,
error: 'uint8_t' is not a member of 'std'; did you mean 'wint_t'?     
   66 |             std::uint8_t firstByteMask;

After some research, I just added #include <cstdint> on top of the file and everything goes well

Just to let you know
#25
Thank you it is ok now