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 - Garwin

#1
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;
}

#2
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?
#3
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
#4
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.
#5
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.
#6
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()?
#7
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.
#8
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.

#9
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.
#10
Help requests / Compiling time
01 May 2022, 02:39:46
Finally adding TGUI code to my first game.
However, I am quite surprised that it change compiling time significantly.

Before adding TGUI, it takes 3-4 seconds to compile.
After adding just declaration of tgui to one of my classes:

#include <TGUI/Core.hpp>
#include <TGUI/Backend/SFML-Graphics.hpp>
#include <TGUI/Widgets/Button.hpp>

tgui::Gui m_gui;


And the compilation time increased to 79 seconds even with commenting out all other TGUI staff.
Is it OK such increase of compilation time? Especially with the notes below?

note1: Codeblock GCC 7.3.0
static linking of SFML and TGUI

note2: for my previous testing I used dynamic linking of SFML and TGUI and it takes only 3 seconds to compile.
#11
I am in the middle of the first simple game and start thinking about something more complex.

I am still thinking about how to merge TGUI which I would like to use for GUI and game graphics itself. I have some ideas however I do not know if there are good ones so some feedback is welcome.

1. Use TGUI as the base graphical engine and use canvas for drawing the game itself
I can see some advantages and disadvantages:
advantages:
- as the canvas is defined, everything inside can be drawn there and can have a separate handling
disadvantages:
- having canvas as fullscreen and GUI as widget over it seems more difficult, bat probably achievable?

2. Game graphic integrate with TGUI as widgets
advantages:
- can use features of TGUI having same theme (eg. tooltips, rightclick menu etc.)
disadvantages:
- quite complex to make widget for graphic entities and unknown if this is possible and reasonable
#12
Help requests / Edit box - key ENTER pressed
18 April 2022, 12:09:13
I find out that if the Edit box is active (cursor blinks) and ENTER is pressed, it does not unfocus Editbox / does not end editing. The only possible way is to click by mouse somewhere else.
It is quite strange as I look into code of the widget and  there is:

    void EditBox::keyPressed(const Event::KeyEvent& event)
    {
        if (event.code == Event::KeyboardKey::Enter)
        {
            onReturnKeyPress.emit(this, m_text);
            onReturnOrUnfocus.emit(this, m_text);
        }


However I cannot find "emit" anywhere (implementation).


OS: Windows 10
Codeblock 20.03
MinGW 7.3.0
SFML 2.5.1
TGUI 0.1 beta - MinGW 64 version
- both libraries linked dynamically
#13
Installation help / Codeblock and TGUI
12 April 2022, 09:30:19
I have tried to install TGUI libraries on Codeblock and so far without success. Firstly I tried development version 1.0, than final stable 0.9, both without success. I am doing probably something wrong. I will try to repeat what I did for version 0.9.

Release 20.03 rev 11983 (2020-03-12 18:24:30) gcc 8.1.0 Windows/unicode - 64 bit
SFML 2.5.1 (it works standalone)

1. downloaded precompiled TGUI 0.9.3 for MinGW 7.3.0 (SEH) - 64-bit
2. setting codeblock as described in tutorial - using static link of libraries (both TGUI and SFML)
3. paths to TGUI is set not relative

Enclosed is error report trying to build simple test program:
Issues is that it seems they are some strange paths

#include <TGUI/TGUI.hpp>


int main()
{
    sf::RenderWindow window{ {800, 600}, "TGUI example - SFML_GRAPHICS backend" };

    tgui::Gui gui{window};
    gui.mainLoop();
}


Any help appretiated.