Main Menu
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 - 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
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.
#3
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;
};
#4
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)
#5
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 ?
#6
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 ?
#7
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
#8
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
#9
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
#10
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 ?
#11
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
#12
Hello,
I want to create a custom widget to make navigation easier for big picture.
I first think about a widget that has two scrollbars and draw simply a sprite the user can shrink or expand with mouseScroll.
I have trouble with clipping in draw function. I helped myself with your Label.cpp
bool NavPicture::mouseWheelScrolled(float delta, tgui::Vector2f pos){
    m_sprite.setSize(m_sprite.getSize()+delta*m_sprite.getSize()/20.f);

    m_scrollbar->setSize(16, static_cast<unsigned int>(getSize().y));
    m_scrollbar->setViewportSize(static_cast<unsigned int>(getSize().y));
    m_scrollbar->setMaximum(static_cast<unsigned int>(m_sprite.getSize().y));
    m_scrollbar->setPosition({getSize().x - m_scrollbar->getSize().x, 0});
    m_scrollbar->setScrollAmount(2.f);

    return true;
}

void NavPicture::draw(tgui::BackendRenderTarget& target, tgui::RenderStates states) const
{
    const tgui::RenderStates statesForScrollbar = states;

    // Draw the scrollbar
    if (m_scrollbar->isVisible())
        m_scrollbar->draw(target, statesForScrollbar);

    target.drawBorders(states, {1}, getSize(), tgui::Color::Black);

    target.addClippingLayer(states, {getPosition().x, getPosition().y, getSize().x, getSize().y});

    if (m_scrollbar->isShown())
        states.transform.translate({0, -static_cast<float>(m_scrollbar->getValue())});

    target.drawSprite(states, m_sprite);

    target.removeClippingLayer();
}
With that code, the sprite behavior is very weird, I can't see it in the clipping region but when I zoom in a lot, it appears far from the clipping region, even over the widget size, where I dont want.
When I remove the clipping option "addClippingLayer", the sprite appears well but when I zoom in to much, it is taller than the widget size of course.
Did I miss something with clipping's behavior ?
#13
I'm having trouble with getAbsolutePosition() which returns a value I don't expect
My tree widget is something like:
Gui
|-->group1
       |-->VehicleManager (custom widget)
              |-->Group (= "panels")
I use panels->getAbsolutePosition() but it returns the pos in the VehicleManager reference, not in screen reference.

Capture.PNG

I used gui-builder to load the group (can it be the source of the problem ?):
    auto panels = tgui::Group::create();
    panels->setPosition(0, tgui::bindBottom(btnWarehouse)+m_spaceY);
    panels->setSize("100%", "100%"-tgui::bindHeight(btnWarehouse)-m_spaceY*2);
    panels->loadWidgetsFromFile("data/forms/vehicleManager.fc");

    m_container->add(panels,"panels");

data/forms/vehicleManager.fc only contains two scrollable panels

Did I missunderstand something ?
#14
Help requests / Custom button and container
16 March 2023, 18:16:02
I want to make a custom widget that is a clickable widget and contains other widgets.
Is this ok to inherits from ClickableWidget AND SubwidgetContainer ?
Is there a better way ?

Also, what is the difference between onClick of ClickableWidget and onPress of Button class ?
#15
Help requests / Custom animation
16 March 2023, 18:10:56
Is there a tutorial somewhere to make custom animation ? Is this even possible ?
For example an animation that combines fade in from transparent and pos sliding ?
Or a more complex one ?
#16
Help requests / Wrong clipping with rotation ?
16 March 2023, 09:22:30
I use a custom widget to handle a "brace".
I draw the box and states pos of widget with the following in draw method:
target.drawBorders(states, tgui::Borders(1), getSize(), tgui::Color::Red);
target.drawCircle(states, 5, tgui::Color::Green);
displayed.PNG
The origin of widget is the middle (0.5, 0.5). I need to rotate it some times, and when I rotate it to the right with
m_embrace->setRotation(270.f);, we can see the green dot is downward, but when I move a little bit and the green dot goes below screen size Y, the whole widget isnt drawn anymore.
notDisplayed.PNG
I thought that's sort of clipping to preserve draw computation when a widget is off screen, is that actually true ?
How can I handle my issue ?
#17
Help requests / behavior on phone
05 March 2023, 13:58:08
I noticed on home page that TGUI is ok with Android/IOS (I'm with SFML backend so I didnt have a doubt about that). I haven't tested yet, before so, I have some questions to help me organize myself:
- Do TGUI have differents behavior with some events, due the usage of fingers ? For example onHover event
- How scrolling is handled ? Do we need to pinch two fingers or there is something else ?
- With scrollPanel, can we drag finger anywhere on the panel to move it or do we must drag only the bar ? If only the bar, what is the best way to have the first behavior ?
Thank you
#18
Help requests / SpriteSheet in v1.0
04 March 2023, 09:59:42
I wanted to use SpriteSheet class,
I found that there was a class here:
https://tgui.eu/documentation/v0.6/classtgui_1_1SpriteSheet.html
But I can't find a similarity in v1.0.
Therefore, I wanted to implement it myself with a custom widget.
To set the visible part of the sprite I use this function:
m_sprite.setVisibleRect(tgui::FloatRect(m_indexSpriteSheet % m_tileSizeSheet.x * m_sizeOneSprite.x, m_indexSpriteSheet / m_tileSizeSheet.x * m_sizeOneSprite.y, m_sizeOneSprite.x, m_sizeOneSprite.y));However, I can't find in the doc if the value for FloatRect object are in pixel or in range [0,1] ?
In both case, I can't get the sprite to have expected behavior although values seem correct with cout
I don't understand, does it refer to texture size or sprite size ?
For example with a sprite [100,100] and a texture [2000,2000]. If a want to draw the part [0,0,50,50] of texture on sprite, how do I do ?
Thank you
#19
Help requests / ToolTip on click
14 February 2023, 15:21:54
Hello,
I want to make a custom widget able to show a tool tip only when the mouse click is pressed under it.

What I tried:
template <typename T>
concept DerivedFromWidget = std::derived_from<T, tgui::Widget>;

template<DerivedFromWidget T>
class BubblableWidget: public T{
public:
    BubblableWidget(): T(){}

    void setBubble(tgui::Widget::Ptr widget){
        m_bubble = widget;
    }

    void leftMousePressed(tgui::Vector2f pos) override{
        T::leftMousePressed(pos);
        T::setToolTip(m_bubble);
        std::cout << "BubblableWidget::leftMousePressed" << std::endl;
    }

    void leftMouseButtonNoLongerDown() override{
        T::leftMouseButtonNoLongerDown();
        T::setToolTip(nullptr);
        std::cout << "BubblableWidget::leftMouseButtonNoLongerDown " << std::endl;
        std::cout << m_bubble << std::endl;
    }

private:
    tgui::Widget::Ptr m_bubble;
};

In the above code, I removed Ptr,create,clone to make it easier to read

Then user side:
    auto test = BubblableWidget<tgui::Label>::create();
    test->setAutoSize(true);
    test->setText("Test");

    auto testBubble = tgui::Label::create("Test2");
    testBubble->setAutoSize(true);
    test->setBubble(testBubble);

When I click on the "Test" label, I can see "BubblableWidget::leftMousePressed" as expected, same for "BubblableWidget::leftMouseButtonNoLongerDown". However, the tool tip does not appear.

I was wondering if setToolTip can't be called in those override functions? Why the tool tip isnt drawn ?
How can I manage my wanted behavior ?

Thank you
#20
Hello,

What is the best way to have a scrollPanel not dispatch the scroll event to parent when the scrollbar is at the tip ? Did I even understand well the behavior ?
Is making a custom widget subclass of scrollPanel a good idea ? with mouseWheelScrolled override

Thank you