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

Messages - Garwin

#1
Help requests / Re: ChildWindow
18 November 2023, 11:53:23
Thanks Texus.
I would probably used inhereted class. For small example having variables outsides is easy but for anything a little more complex having all variables in one class seems to me better solution.
#2
Help requests / ChildWindow
16 November 2023, 17:14:40
I first tried to implement both minimalizing and maximizing buttons in ChildWindow Widget with TGUI 1.1, backend SFML on Windows with GCC 13.1 compiler. I got some strange behaviors (code attached at the end)

1. Movement of the widget inside a parent widget
If widget setPositionLocked(false) and setKeepInParent(true) is true then the movement of the widget is only possible on the edges of the parent widget. If setKeepInParent(false), than movement is freely available anywhere.

2. Implementing Maximize button

I have tried implemented it by lambda and it has some limitations (I will discuss later). But Maximize button does not work correctly as childWindow->setPosition(tgui::Vector2f{nonMaxPosition.x, nonMaxPosition.y}); is completely ignored. I stream the position of the widget before that and after that with information about variable nonMaxPosition to std::cout and it shows that variable nonMaxPosition is correct but the row mentioned above do not set new position of the widget so everytime maximize button is pushed when widget is already maximize, the new position is set to left top corner of parent widget ignoring setting new position of stored previous position.

3. Implementing Maximize and Minimize buttons
Using separated lambdas for each button which are not aware of status of the seconds is not ideal. Is there another way to do it?
I have only one idea and to create new widget which inherites from ChildWidget and have private members storing information about status of the widget (maximalized, minimalized), position and size before that.

#include <TGUI/Widgets/ChildWindow.hpp>
#include <TGUI/Widgets/Group.hpp>
#include <TGUI/Backend/SFML-Graphics.hpp>

#include <iostream>

int main ()
{
    sf::RenderWindow window({800, 600}, "TGUI example (SFML-Graphics)");
    tgui::Gui gui(window);

    auto group = tgui::Group::create();
    group->setSize({700,500});
    group->setPosition({50,50});
    gui.add(group);

    auto childWindow = tgui::ChildWindow::create("Settings");
    group->add(childWindow);
    childWindow->setSize({150,100});
    childWindow->setPosition(50,50);
    childWindow->setPositionLocked(false);
    childWindow->setTitleButtons(tgui::ChildWindow::TitleButton::Maximize
                                 | tgui::ChildWindow::TitleButton::Minimize
                                 | tgui::ChildWindow::TitleButton::Close);
    childWindow->setResizable(true);
    childWindow->setKeepInParent(true); // Prevents any part of the window to go outside the screen

    childWindow->onMaximize([&](){
        static bool maximized (false);
        static bool keepInParent {childWindow->isKeptInParent()};
        static tgui::Vector2f nonMaxSize {childWindow->getSize()};
        static tgui::Vector2f nonMaxPosition (childWindow->getPosition());

        if (maximized)
        {
            childWindow->setSize(nonMaxSize);
            childWindow->setPosition(tgui::Vector2f{nonMaxPosition.x, nonMaxPosition.y}); // DO NOT WORK
            childWindow->setKeepInParent(keepInParent);
            childWindow->setPositionLocked(false);
        }
        else
        {
            keepInParent = childWindow->isKeptInParent();
            nonMaxSize = childWindow->getSize();
            nonMaxPosition = childWindow->getPosition();
            childWindow->setPosition({0,0});
            childWindow->setSize(childWindow->getParent()->getSize());
            childWindow->setKeepInParent(true);
            childWindow->setPositionLocked(true);
        }
        maximized = !maximized;
    });

    childWindow->onMinimize([&](){
        static bool minimized {false};
        static tgui::Vector2f nonMinimizedSize {childWindow->getSize()};
        if (minimized)
            childWindow->setSize(nonMinimizedSize);
        else
        {
            if (childWindow->getInnerSize().y !=0 && childWindow->getMaximumSize() != childWindow->getSize())
                nonMinimizedSize = childWindow->getSize();
            childWindow->setClientSize({childWindow->getSize().x,0});
        }
        minimized = !minimized;
    });

    gui.mainLoop();

    return 0;
}

#3
Help requests / Texture class
15 November 2023, 20:13:43
I have just recently updated my old project from TGUI 0.9 to TGUI 1.1

I get some warning:
src\game_state_game.cpp|62|warning: 'tgui::Texture::Texture(const sf::Texture&, const tgui::UIntRect&, const tgui::UIntRect&)' is deprecated: Use Texture() and loadFromPixelData(texture.getSize(), texture.copyToImage().getPixelsPtr()) instead [-Wdeprecated-declarations]|

Do I get it correctly, that the change to TGUI 1.1 is depreciation of direct construction of tgui::Texture from sf::Texture and shows more clearly the intention that TGUI copy that texture internally (slow) so using function loadFromPixelData is more appropriate? And having correct non-depreciated code is than:
tgui::Texture tguiPicture;
tguiPicture.loadFromPixelData(sfPicture.getSize(), sfPicture.copyToImage().getPixelsPtr());
auto picture = tgui::Picture::create(std::move(tguiPicture));
Do I have it correct that if my texture manager using sf::Texture to store all textures, than there is no way to avoid copies from sf::Texture to tgui::Texture?
#4
Feature requests / Re: tgui::String
30 September 2023, 13:27:38
Thanks, this is exactly what I need.
#5
Feature requests / Re: tgui::String
30 September 2023, 10:15:02
operator >> especially for filestreams
#6
Feature requests / tgui::String
30 September 2023, 09:17:08
I find it an excellent class that can be used not only in TGUI but in the whole program.
Would not be good to add operator << and >> overloading for UTF8 strings as it is in line with returning UTF8 strings.

There is the possibility to use functions to convert it to UTF8 but simple ability for parsing templates would be better:
out << tgui::String
in >> tgui::String
#7
Thanks. I will try. Just need to think how to setup all things in codeblock as I will have for the first time probably more compilers and more version of TGUI and SFML next to each other.
As the updated version is only for SFML 2.6.
#8
Help requests / Error compiling with gcc++
28 July 2023, 20:50:46
I have updated gcc (to new version (need std::format) from 12.1 (x86_64-win32-seh-rev3, Built by MinGW-W64 project) to 13.1 (using https://github.com/brechtsanders/winlibs_mingw/releases/download/13.1.0-16.0.5-11.0.0-msvcrt-r5/winlibs-x86_64-posix-seh-gcc-13.1.0-mingw-w64msvcrt-11.0.0-r5.7z) and later trying even 13.2 (https://github.com/brechtsanders/winlibs_mingw/releases/download/13.2.0-16.0.6-11.0.0-ucrt-r1/winlibs-x86_64-posix-seh-gcc-13.2.0-llvm-16.0.6-mingw-w64ucrt-11.0.0-r1.7z).

But in both cases I get error recompiling some my older project using SFML 2.5 and TGUI 0.10.
TGUI-0.10\include\TGUI\Utf.hpp|75|error: 'uint8_t' in namespace 'std' does not name a type; did you mean 'wint_t'?|
Similar error is with uint32_t.


Any idea what does this error mean?

note: I have tried to include <stdint.h> and <inttypes.h> but it does not help.
#9
Help requests / Global font
17 June 2022, 20:38:06
I was able to solve the issue but anyway I am insterested how it works and why it happenes.

I have several states. In each state TGUI object is created.
In one of the states (score board) I set different global font than all other states.

But what was interesting that going from this state (score board) to another, this another state previously having standard font has same font as score board state.
And even if the state is created as new object and inside that state global font is set to standard (different than score board). All created buttons has the different font. And even if they are created after the standard font is set in this state as global.

I solve it switching on score board state global font to standard as I did not used it because fonts were set per widget but I am quite interested how it was possible.
#10
Help requests / Re: Animations
15 May 2022, 16:52:50
2 - thanks, it is clear and works.
3 - It is more about understanding how it works for the future as I decided to change states that are always destroyed before the new state is applied.
The issue I had is clear, it certainly was because I had one gui object for each state and time went on even if this state was not active.

I read the tutorials and it seems that for me the best way to switch between different states that coexist together is using
tgui::Group and make gui object one level higher in hierarchy.


#11
Help requests / Re: Animations
15 May 2022, 06:54:42
Relating to point 2, I haven't found how any single button could be disabled (disable the function click) but still visible, however I did it for the whole menu just adding an invisible Picture layer on top of it. Is there some methods through a single button? I cannot find anything.

Relating to point 3, I change how states work destroying them and creating a new ones with every change. But did not find a reason why the animation did not play when on top of the stack there was a new state and after destroying this new state, functions return back to the previous stack with buttons set to play the animation.
Does have TGUI centralized time no matter of TGUI instances?
#12
Help requests / Re: RAM usage and fonts
06 May 2022, 20:07:49
Thanks for everything, it works very nicely and RAM usage does not increase.

Just it takes me time to realize that Origin is the percentage of width and height, not coordinates.  Looking at coordinates changing right to the center but button disappearing. ;D
#13
Help requests / Re: RAM usage and fonts
06 May 2022, 19:10:12
Images are on a different screen, they are not scaled.

Only one button is scaled however each time can be different as it is always the chosen button.

The original size is 30. Scaling of a button is done up to 2.5 times and scaling of text inside is done up to 3.25 times. (button scale - 1)*1,5+1

I will try setScale. I tried resizeWithAnimation but it only scales the button without text.
#14
Help requests / Re: RAM usage and fonts
06 May 2022, 18:24:39
Thanks, it gives a sense a lot. A probably better solution (I have thought about it by I tried achieved it through TGUI) is using in this case of enlarging the single remaining button sf::View.

I used task manager. I was just interested to know how much memory it uses and this behavior really surprised me.

Without this line of code (enlarging text), the memory shows constantly 40 MB with all resources loaded before the first screen. (Pictures with about 3M pixels in total and 2 fonts).

During testing of each screen, I set code to loop back to the same screen even if the button is pressed. Gui is destroyed and created again after each "leaving and reentering" same screen.
Just pressing 1 button means going from 40 to 130MB. Using everytime other button (5 in total as the last one is exit button) and task manager shows almost 600 MB used.
Pressing again same button means no change at all, exactly as you mentioned.

Just was surprised how much it increase RAM usage.

Trying to put into loop sf::sleep with 0.2s and the memory usage in same case reported by task manager decrease to 120MB as maximum.

Certainly making a lot of different font sizes is not good with SFML and TGUI. :-)

So I will use sf::View to achieve same effect.

Thanks a lot to point out about fonts being resource not being able to be released.
#15
Help requests / RAM usage and fonts
06 May 2022, 08:09:54
I have tried to find some answers on the forum and in TGUI code, I think I find some of them but not all of them.

I have 6 buttons. If one of them is chosen, there is an animation playing to move not chosen buttons to left. The remaining chosen button is moved to center and enlarged (button itself and text) and than Fade animation is played.

This done through this code:
m_chosen->getRenderer()->setTextSize (30.0f*((m_chosen->getSize().x/unchosen->getSize().x-1.0f)*1.5f+1.0f));
m_chosen ... pointer to choosen button which will enlarge
unchosen ... temporary pointer to any other button to get ratio of enlarging of buttons to use it for enlargering text


I have found that starting to enlarge RAM usage goes dramatically up, practically more than doubling.

If I understand it correctly calling getRenderer() method copy Renderer. Does it mean that it copies even the font itself? If so is it possible to setTextSize differently than calling it through getRenderer()?
#16
Help requests / Re: setGlobalFont
05 May 2022, 23:02:22
Thanks a lot. It helps.
#17
Help requests / Re: Animations
05 May 2022, 22:31:11
AD 1
I find it, it is not scaling (times original value), it is new value.
#18
Help requests / setGlobalFont
05 May 2022, 21:37:26
I tried to use different than default font.

Class Game - constructor:

tgui::Font m_tguiFont ("data/fonts/font.ttf");

Than there is another class handling menu and I would like to set global font for TGUI:

m_gui.setWindow (m_game->m_window);
tgui::Font::setGlobalFont (m_game->m_tguiFont);



Code is compiled without an issue but starting program it gives error which I have no clue why there is problem with backend.

TGUI assertion: getBackend() was called while there is no backend
Assertion failed!

Program: C:\Projects\Picture\bin\Debug\Picture.exe
File: C:/Program Files (x86)/Jenkins/workspace/TGUI-0.10/src/Backend/Window/Backend.cpp, Line 76

Expression: globalBackend != nullptr


Any help would be appretiated.

note: hideWithEffect is really nice function with abiity to give tgui::Picture a transparent layer blocking for certain time interacting with GUI. Really easy and nice.
#19
Help requests / Animations
04 May 2022, 19:46:31
I have several questions related to animation.

1. Resize with animation

I am trying different animations. It is quite nice that except showWithEffect and hideWithEffect there are couple of function that can be mixed to make our own animations quite easily. But I struggle with scaling animation.

I am trying to make animation to scale button (including text) 2 times larger trough animation.
The whole animation is that all options not choosen hideWithEffect left, only choosen option move to center and double the size.


First part (button itself):

float sizeX = m_options.at(buttonCount)->getScale().x*2;
float sizeY = m_options.at(buttonCount)->getScale().y*2;
std::cout << "Size     x: " << sizeX << "\t" << "y: " << sizeY << "\n";
tgui::Layout2d scale (sizeX,sizeY);
m_options.at(buttonCount)->resizeWithAnimation (scale,m_animationDelay);


But it does minimalize buttons, not increase it ....
I will need to ad setting origin to center of button, but it is not difficult.

Second part:
How can I do similar thing with text?
Or do I need to do my own application as TGUI supports only button resize without text?




2. temporary making button unclickable
As animations plays, buttons are still clickable. Better would be that for the time being there are not clickable. Is there something (flag) directly in TGUI?
Just a question as it would be not difficult to code through "isAnimationPlaying".

3. Reseting animation
I have different states through std::stack. The main menu is one state and after any chosen options except exit new state is pushed on stack.
Than when some of new states finished their state is destroyed and previous state (main manu) is on top. This means main loop works like:
peekState()->handleInput();
peekState()->update(dt);
m_window.clear (sf::Color::Black);
peekState()->draw(dt);
fps.draw(dt,m_window);
m_window.display();


There is state related to main menu. And when this state is going to exit there is:
setDefaultButtons ();
This function just recreate all buttons including starting animations (it is not most efficient way but it was fast to code as constructor of the state is just "setDefaultButtons();" with just small add-on.
But strange part is that when code is running and some other state is destroyed and everything is going back to main menu, everything is not drawn as set-up by setDefaultButtons, but all animations are finished directly meaning no buttons with showWithEffect.

#20
Just finding that in source files xxxproperties are all properties that can be set to xxx widget in the theme or directly in code.

I think it would be good to mention it in the theme tutorial.
#21
Thanks for help, I have just tried it in simple test program and it works.

Same thing is in case you change theme during runtime. Changing shared pointer this way works.
#22
Not at all, all code is mentioned above.

All I have is members in the class:
tgui::Gui m_gui;

tgui::Button::Ptr m_newGame;
tgui::Button::Ptr m_difficulty;
tgui::Button::Ptr m_picture;
tgui::Button::Ptr m_score;
tgui::Button::Ptr m_exit;



and in draw function have:
m_gui.draw();

#23
This is exactly what I was looking for however it does not work.

Adding line:
tgui::DefaultThemeLoader::flushCache()

just before reloading:
tgui::Theme::setDefault("data/TGUI/theme.txt");

does not work. I have no idea why.
#24
First, I would like to thank you for finding time to answer my questions. Your TGUI is very nice and complex.

I have another question. I want to create my theme for my simple game and the best way is to have an immediately updated theme in the program.
For such reason, I added that function into the prototype of the menu (using buttons).

However it does not work.

I have this code as part of constructor of "GameStateOptions" class.

tgui::Theme::setDefault ("data/TGUI/theme.txt");

m_gui.setWindow (m_game->m_window);
m_newGame = tgui::Button::create();
m_difficulty = tgui::Button::create();
m_picture = tgui::Button::create();
m_score = tgui::Button::create();
m_exit = tgui::Button::create();

using namespace tgui;
m_gui.add (m_newGame);
m_gui.add (m_difficulty);
m_gui.add (m_picture);
m_gui.add (m_score);
m_gui.add (m_exit);

m_newGame-> setPosition(300,100);
m_difficulty-> setPosition(300,200);
m_picture-> setPosition(300,300);
m_score-> setPosition(300,400);
m_exit-> setPosition(300,500);

m_newGame-> setText("NEW GAME");
m_difficulty-> setText("DIFFICULTY");
m_picture-> setText("PICTURE");
m_score-> setText("HIGHEST SCORE");
m_exit-> setText("EXIT");


On top of that I have function "handleInput" which handles all input (keys, mouse) and if F9 is pressed it should reread theme from file. Part of the code is:
         case sf::Event::KeyPressed:
{
if (event.key.code == sf::Keyboard::Escape) m_game->m_window.close();
else if (event.key.code == sf::Keyboard::F9)
{
tgui::Theme::setDefault("data/TGUI/theme.txt");
Log::log ("Pressing F9 key.");
}
break;
}


Then my procedure (expected) is:
1. start the program
2. look at menu ==> decided theme adjustment
3. edit the theme file and change it
4. press F9 key in-game to update the theme
5. going to point 2. till I am satisfied with the look of the theme

However during point 4. after pressing F9 theme is not updated in the buttons.
Looking at my log file, F9 was pressed so the added tgui::Theme::setDefault("data/TGUI/theme.txt") was called but does not update default theme.
#25
Help requests / Re: Compiling time
01 May 2022, 10:46:33
QuoteDid you build SFML and TGUI yourself using the "SFML_USE_STATIC_STD_LIBS=TRUE" and "TGUI_USE_STATIC_STD_LIBS=TRUE" options?
Because the default static SFML and TGUI versions link dynamically to libgcc and you thus shouldn't have "-static", "-static-libgcc" and "-static-libstdc++" in your linker settings.

No, I used the ones on the TGUI page only trying to change dynamic linking to static linking as I wanted to evade having all libraries in 2 folders (debug and release).
I will try to switch it off. Quite strange is that before adding TGUI to the project I have already SFML with static linking and it works fine which is contradict to what you say that both SFML and TGUI libraries are linked dynamically to libgcc.
I will probably switch back to dynamic linking it seems so far the easiest solution as a newbie I do not want to go through all the compiling issues with cmake yet, but probably after finishing my first simple game.

QuoteAt the end of the build log it states "Process terminated with status 1", which means it FAILED
It can be as I was trying different thing and I may copy there the wrong log.


EDIT:
I used this linker setting on top all settings:
..\CodeBlocks\MinGW\lib\gcc\x86_64-w64-mingw32\7.3.0\libstdc++fs.a

I use experimental filesystem as I found out that in this version of gcc this c++17 feature is implemented only as experimental as I use generic approach of loading textures as whole directory with logging it to log file without specifically mentioning name of textures.