Recent Posts

Pages: 1 ... 8 9 [10]
91
Themes / Re: [Tool] TGUI Theme Preprocessor
« Last post by rubenwardy on 10 May 2020, 20:01:32 »
Use in Continuous Integration

This code will download this tools source code, and build a given theme's source code

Code: [Select]
git clone https://gitlab.com/rubenwardy/tgui-theme-builder
tgui-theme-builder/build_archive.sh nanogui.style
mv build/theme.zip theme.zip

Here's an example .gitlab-ci.yml:

Code: [Select]
image: python:3.7

before_script:
  - apt-get update
  - apt-get install zip

build:
  stage: build
  script:
    - git clone https://gitlab.com/rubenwardy/tgui-theme-builder
    - tgui-theme-builder/build_archive.sh nanogui.style
    - mv build/theme.zip theme.zip
  artifacts:
    paths:
    - theme.zip
  only:
    - master

Use in CMake

Code: [Select]
file(GLOB GUISources ${CMAKE_SOURCE_DIR}/assets/gui/source/*)
add_custom_target(prebuild ALL
COMMAND utils/prebuild.sh
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
DEPENDS ${GUISources}
BYPRODUCTS ${CMAKE_SOURCE_DIR}/assets/gui/rvwp.style ${CMAKE_SOURCE_DIR}/assets/gui/rvwp.png)

where `prebuild.sh` may be something similar to:

Code: [Select]
#!/bin/bash

set -e

python3 -mvenv /tmp/rvwpenv
source /tmp/rvwpenv/bin/activate
pip install PyTexturePacker

pack=$PWD/utils/pack.py

pushd assets/gui/source
python $pack rvwp.style
mv build/*.{png,style} ..
rm -r build
popd

92
Themes / [Tool] TGUI Theme Preprocessor and Spritesheet Generator
« Last post by rubenwardy on 10 May 2020, 19:55:23 »
This tool supports building GUI sprite sheets from individual source images, and contains syntactic sugar to make 9-slices easier

Required images are defined using the following syntax:

Code: [Select]
Texture = ${imagename};
// Define a 9-slice just by a margin from the edge of the image
TextureHover = ${imagename:7};

The image by that name will be found and added to the sprite sheet. The same image can be referenced multiple times and only appear once. The output of the tool will look like this:

Code: [Select]
Texture = "themename.png" Part(2, 2, 21, 60);
// Define a 9-slice just by a margin from the edge of the image
TextureHover = "themename.png" Part(2, 2, 21, 60) Middle(7, 7, 7, 46);

Full specification

  • Texture = ${name}; will find the texture called name.png and then add it to the sprite sheet.
  • Texture = ${name:10}; will create a 9-slice with an inner padding of 10.
  • Texture = ${panel:10o+10}; will create a 9-slice with an inner padding of 10, but offset by 10 from the top (see the main body of the child window in the second screenshot).
  • Texture = ${titlebar:10o-10}; will create a 9-slice with an inner padding of 10, but offset by 10 from the bottom (see the main title of the child window in the second screenshot).
  • It allows you to import other theme files using #include "aaa.style".

License: Zlib
Source code: https://gitlab.com/rubenwardy/tgui-theme-builder/
93
Themes / NanoGUI Theme [WIP]
« Last post by rubenwardy on 10 May 2020, 00:48:04 »
This is a Work In Progress theme based on NanoGUI's default theme

License: BSD 3-clause

Source code: https://gitlab.com/rubenwardy/tgui-nanogui-theme
Downloads: https://gitlab.com/rubenwardy/tgui-nanogui-theme/pipelines

Supported widgets:
  • ChildWindow
  • Panel
  • ListBox
  • EditText
  • CheckBox
  • Button

94
Help requests / Re: Double free or corruption error on removeAllWidgets()
« Last post by texus on 06 May 2020, 08:15:16 »
It seems like TGUI links to some SFML libraries installed on your pc, but you are using different SFML libraries in your project. I'm guessing you installed TGUI from the PPA?
If you don't need SFML 2.5 and would be able to use SFML 2.4 then maybe it is enough to uninstall the 2.5 libraries.
Alternatively, you should probably uninstall the TGUI package and build TGUI yourself (so that it uses the same SFML libraries as you use in your project)
95
Help requests / Double free or corruption error on removeAllWidgets()
« Last post by SpaceKotik on 06 May 2020, 01:17:01 »
Hi there, I'm getting "double free or corruption (out)" error after trying to call removeAllWidgets() or close the program. The code is absolutely like the minimal code in tutorial with adding a single button.
Also I get these warning while compiling:
/usr/bin/ld: warning: libsfml-graphics.so.2.4, needed by /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libtgui.so, may conflict with libsfml-graphics.so.2.5
/usr/bin/ld: warning: libsfml-window.so.2.4, needed by /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libtgui.so, may conflict with libsfml-window.so.2.5
/usr/bin/ld: warning: libsfml-system.so.2.4, needed by /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libtgui.so, may conflict with libsfml-system.so.2.5
96
Help requests / Re: Updating Real Time
« Last post by RamblingBaba on 01 May 2020, 21:18:25 »
[SOLVED] I just retrieved from the gui and it worked correctly.  Thank you.




Here is the code, I posted it all for clarity. So the "red" slider starts off just a tad past zero. But the others start at zero. I checked for calls of setValue and it's only called on the sliders. I have 3 comments // Red, // Green, // Blue for where I initialize the Sliders. Thanks

tgui::Theme theme{ "themes/Black.txt" };

                gui.add(tgui::Picture::create("RedBackground.jpg"));

                auto r = 0.f, g = 0.f, b = 0.f;
                auto r2 = 0.f, g2 = 0.f, b2 = 0.f;


                auto menu = tgui::MenuBar::create();
                menu->setRenderer(theme.getRenderer("MenuBar"));
                menu->setSize(static_cast<float>(window.getSize().x), 22.f);
                menu->addMenu("File");
                menu->addMenuItem("Load");
                menu->addMenuItem("Save");
                menu->addMenuItem("Exit");
                menu->addMenu("Edit");
                menu->addMenuItem("Copy");
                menu->addMenuItem("Paste");
                menu->addMenu("Help");
                menu->addMenuItem("About");
                menu->connectMenuItem("File", "Exit", [&]() {window.close(); });
                gui.add(menu, "menu");

                auto child = tgui::ChildWindow::create();
                child->setRenderer(theme.getRenderer("ChildWindow"));
                child->setSize(250, 120);
                child->setPosition(420, 80);
                child->setTitle("Child window");
                gui.add(child, "child");

                auto label = tgui::Label::create();
                label->setRenderer(theme.getRenderer("Label"));
                label->setText("Hi! I'm a child window.");
                label->setPosition(30, 30);
                label->setTextSize(15);
                child->add(label, "child_label");

                auto editBox = tgui::EditBox::create();
                editBox->setRenderer(theme.getRenderer("EditBox"));
                editBox->setSize(200, 25);
                editBox->setTextSize(18);
                editBox->setPosition(10, 270);
                editBox->setDefaultText("Click to edit text...");
       
                editBox->onReturnKeyPress( [&]() {
                        gui.get("child")->setVisible(true);
                        auto lbl = gui.get<tgui::ChildWindow>("child")->get<tgui::Label>("child_label");
                        lbl->setText(gui.get<tgui::EditBox>("editbox")->getText());
                        });
                gui.add(editBox, "editbox");

                auto button = tgui::Button::create();
                button->setRenderer(theme.getRenderer("Button"));
                button->setPosition("editbox.left + editbox.width + 5", "editbox.top");
                button->setText("Show Popup");
                button->setSize(100, 30);
                button->onPress( [&]() {
                        gui.get<tgui::ChildWindow>("child")->setVisible(
                                !gui.get<tgui::ChildWindow>("child")->isVisible());
                        if (gui.get<tgui::ChildWindow>("child")->isVisible())
                                gui.get<tgui::Button>("toggleChildButton")->setText("Hide Child");
                        else
                                gui.get<tgui::Button>("toggleChildButton")->setText("Show Child");

                        });
                gui.add(button, "toggleChildButton");


                [b]// Red
                auto slider = tgui::Slider::create();
                slider->setRenderer(theme.getRenderer("Slider"));
                slider->setPosition(55, 360);
                slider->setSize(200, 18);
                slider->setValue(150);
                slider->setMaximum(255);
                slider->setMinimum(0);
                slider->setStep(1);
                slider->getRenderer()->setThumbWithinTrack(true);
                slider->onValueChange( [&]() {[/b]
                        const auto checkBG = gui.get<tgui::RadioButton>("rBGColor");
                        const auto checkTC = gui.get<tgui::RadioButton>("rTextColor");
                        if (checkBG->isChecked())
                        {
                                r = gui.get<tgui::Slider>("red")->getValue();
                                child->getRenderer()->setBackgroundColor({ static_cast<sf::Uint8>(r), static_cast<sf::Uint8>(g), static_cast<sf::Uint8>(b) });
                                gui.get<tgui::Label>("red_value")->setText(std::to_string(static_cast<int>(gui.get<tgui::Slider>("red").get()->getValue())));
                        }
                        else if (checkTC->isChecked()) {
                                r2 = gui.get<tgui::Slider>("red")->getValue();
                                auto lb = gui.get<tgui::ChildWindow>("child")->get<tgui::Label>("child_label");
                                lb->getRenderer()->setTextColor({ static_cast<sf::Uint8>(r2), static_cast<sf::Uint8>(g2), static_cast<sf::Uint8>(b2) });
                                gui.get<tgui::Label>("red_value")->setText(std::to_string(static_cast<int>(gui.get<tgui::Slider>("red").get()->getValue())));
                        }
                        });
                gui.add(slider, "red");

                label = tgui::Label::create();
                label->setRenderer(theme.getRenderer("Label"));
                label->setText("Red");
                label->setPosition("red.left - width - 10", "red.top");
                label->setTextSize(14);
                gui.add(label, "red_label");

                label = tgui::Label::create();
                label->setRenderer(theme.getRenderer("Label"));
                label->setText(std::to_string(r));
                label->setPosition("red.left + red.width + 10", "red.top");
                label->setTextSize(14);
                gui.add(label, "red_value");

                [b]// Green
                slider = tgui::Slider::create();
                slider->setRenderer(theme.getRenderer("Slider"));
                slider->setPosition("red.left", "red.top + 35");
                slider->setSize(200, 18);
                slider->setValue(150);
                slider->setMaximum(255);
                slider->setMinimum(0);
                slider->setStep(1);
                slider->onValueChange([&]() {[/b]
                        auto checkBG = gui.get<tgui::RadioButton>("rBGColor");
                        auto checkTC = gui.get<tgui::RadioButton>("rTextColor");
                        if (checkBG->isChecked())
                        {
                                g = gui.get<tgui::Slider>("green")->getValue();
                                child->getRenderer()->setBackgroundColor({ static_cast<sf::Uint8>(r), static_cast<sf::Uint8>(g), static_cast<sf::Uint8>(b) });
                                gui.get<tgui::Label>("green_value")->setText(std::to_string(static_cast<int>(gui.get<tgui::Slider>("green").get()->getValue())));
                        }
                        else if (checkTC->isChecked()) {
                                g2 = gui.get<tgui::Slider>("green")->getValue();
                                auto lb = gui.get<tgui::ChildWindow>("child")->get<tgui::Label>("child_label");
                                lb->getRenderer()->setTextColor({ static_cast<sf::Uint8>(r2), static_cast<sf::Uint8>(g2), static_cast<sf::Uint8>(b2) });
                                gui.get<tgui::Label>("green_value")->setText(std::to_string(static_cast<int>(gui.get<tgui::Slider>("green").get()->getValue())));
                        }
                        });
                gui.add(slider, "green");

                label = tgui::Label::create();
                label->setRenderer(theme.getRenderer("Label"));
                label->setText(std::to_string(g));
                label->setPosition("green.left + green.width + 10", "green.top");
                label->setTextSize(14);
                gui.add(label, "green_value");

                label = tgui::Label::create();
                label->setRenderer(theme.getRenderer("Label"));
                label->setText("Green");
                label->setPosition("green.left - width - 10", "green.top");
                label->setTextSize(14);
                gui.add(label, "green_label");

                [b]// Blue
                slider = tgui::Slider::create();
                slider->setRenderer(theme.getRenderer("Slider"));
                slider->setPosition("green.left", "green.top + 35");
                slider->setSize(200, 18);
                slider->setValue(150);
                slider->setMaximum(255);
                slider->setMinimum(0);
                slider->setStep(1);
       
                slider->onValueChange([&]() {[/b]
                        auto checkBG = gui.get<tgui::RadioButton>("rBGColor");
                        auto checkTC = gui.get<tgui::RadioButton>("rTextColor");
                        if (checkBG->isChecked())
                        {
                                b = gui.get<tgui::Slider>("blue")->getValue();
                                child->getRenderer()->setBackgroundColor({ static_cast<sf::Uint8>(r), static_cast<sf::Uint8>(g), static_cast<sf::Uint8>(b) });
                                gui.get<tgui::Label>("blue_value")->setText(std::to_string(static_cast<int>(gui.get<tgui::Slider>("blue").get()->getValue())));
                        }
                        else if (checkTC->isChecked()) {
                                b2 = gui.get<tgui::Slider>("blue")->getValue();
                                auto lb = gui.get<tgui::ChildWindow>("child")->get<tgui::Label>("child_label");
                                lb->getRenderer()->setTextColor({ static_cast<sf::Uint8>(r2), static_cast<sf::Uint8>(g2), static_cast<sf::Uint8>(b2) });
                                gui.get<tgui::Label>("blue_value")->setText(std::to_string(static_cast<int>(gui.get<tgui::Slider>("blue").get()->getValue())));
                        }
                        });

                gui.add(slider, "blue");

                label = tgui::Label::create();
                label->setRenderer(theme.getRenderer("Label"));
                label->setText("Blue");
                label->setPosition("blue.left - width - 10", "blue.top");
                label->setTextSize(14);
                gui.add(label, "blue_label");

                label = tgui::Label::create();
                label->setRenderer(theme.getRenderer("Label"));
                label->setText(std::to_string(b));
                label->setPosition("blue.left + blue.width + 10", "blue.top");
                label->setTextSize(14);
                gui.add(label, "blue_value");

                auto radioButton = tgui::RadioButton::create();
                radioButton->setRenderer(theme.getRenderer("RadioButton"));
                radioButton->setPosition(20, 140);
                radioButton->setText("Background Color");
                radioButton->setSize(25, 25);
               
                gui.add(radioButton, "rBGColor");

                radioButton = tgui::RadioButton::create();
                radioButton->setRenderer(theme.getRenderer("RadioButton"));
                radioButton->setPosition(20, "rBGColor.top - 27");
                radioButton->setText("Text Color");
                radioButton->setSize(25, 25);
                gui.add(radioButton, "rTextColor");

The reason I wanted to call a function manually is that when I change the radio button to "background" or "text color" the color doesn't update unless I click each individual slider again. Which was why I was curious of what update does. I guess I was just being lazy and didn't want to call the same color change inside the radio.onCheck() again. But it works when I do that, I was just hoping I could call the functions of the sliders to accomplish for me. Thanks
97
Installation help / Re: 0.9 Errors
« Last post by RamblingBaba on 01 May 2020, 21:10:56 »
Hey Texus,

I want to say thanks for the information in my original question about making the color sliders (answered yesterday). I actually got that to all work as intended. When I was trying to find a way to place the starting slider position I came across 0.9 and realized I had 0.8. So I tried to run the same program that worked in 0.8 and changed the connect to the type needed and got this. It does work when I start over, so it does compile, just not the same program.

As I was pasting my code, I was conveniently spotted with the problem. I had button->onPress("pressed",[]...). It works!
98
Help requests / Re: Updating Real Time
« Last post by texus on 01 May 2020, 09:39:10 »
Quote
1st Question: How can I change the position of the slider at startup? It always starts at 0 (it's at zero now as I tried to fix), yet I assumed setValue would position it to the value correctly.
Calling setSlider->setValue(x) after creating the slider does change the value and will set the thumb on a different position. If not then you are probably calling setValue(0) somewhere afterwards.

Quote
2nd Question:   (SOLVED, I FIGURED IT OUT, HAD TO GET FROM GUI. I STILL HAVE TO CLICK EACH SLIDER FOR IT TO UPDATE THE VALUES FOR THE CHILD BACKGROUND)
The "ValueChanged" callback is only going to be called when you actually change the value, either by clicking on it or by calling setValue(). So if you don't give your window the right background color initially then it of course won't be set until the first time you change the slider.

Quote
3rd: What does the method update actually do? (Besides the obvious) What is being updated and when would I want to manually call update? Also, what is updateTime() method in the Gui suppose to do?
The update function is an internal function which should never be called manually. It is used to inform widgets that time has passed. Only a few widgets do something with this information, e.g. edit box will blink its caret. The updateTime function in Gui (also meant for internal use and called from inside Gui::draw()), is the function that will call the update() function on all widgets in the gui.
I guess I should rename update() to updateTime() as well to make it more clear what is being updated.

Quote
4th: How do I manually call a Widgets connect callback?
You aren't meant to do this. If you really must, you could use slider->onValueChange.emit(slider.get(), slider->getValue());

Edit:
Quote
but I realized the color of the background is definitely not accurate.
You are using "[&]" as lambda capture. Is the "slider" object still alive when the lambda is executed (when the value is changed)? It not then you are causing undefined behavior. Widgets in TGUI are stored as pointers, so you can copy them inside the lambda by value:
slider->connect("ValueChanged", [&,slider]() { ... });
99
Installation help / Re: 0.9 Errors
« Last post by texus on 01 May 2020, 08:56:53 »
What line in your code is causing this error? I would have to see how you are calling the connect function (or the operator() function) on the signal to see what is wrong.

Maybe your function using std::string or sf::String as unbound parameter? That would have to be changed to tgui::String.

Edit: out of interest, which features were it that you wanted?
100
Installation help / 0.9 Errors
« Last post by RamblingBaba on 01 May 2020, 06:57:02 »
Hello,

I've just switched to 0.9 since I saw it had some features I really wanted. I'm getting these errors though,

Severity        Code    Description     Project File    Line    Suppression State
Error   C2672   'tgui::SignalTyped<const tgui::String &>::connect': no matching overloaded function found       TGUI    E:\Libaries\TGUI-0.9-dev\include\TGUI\Signal.hpp        468    
 

Severity        Code    Description     Project File    Line    Suppression State
Error   C2783   'unsigned int tgui::SignalTyped<const tgui::String &>::connect(const Func &,const BoundArgs &...)': could not deduce template argument for '__formal'  
TGUI    E:\Libaries\TGUI-0.9-dev\include\TGUI\Signal.hpp        467    
 

I know connect was replaced with a more direct version (like onPress()). But I'm not sure how to repair this.

Thanks
Pages: 1 ... 8 9 [10]