Main Menu

Questions

Started by Law, 10 August 2014, 14:47:07

Law

Hello,

So TGUI seems to be running perfectly on my computer now, which is already great. I was compiling the examples shown on the website, and one question arises... Where can I download Black.conf ?

Also, I was wondering if that was possible to make a chatbox or listbox with buttons in every line? Though this is not what I want to do, an example would be to make two buttons per line, one whose goal is to move the line one rank higher, and the other one one rank lower.

Thanks!

texus

QuoteWhere can I download Black.conf ?
It is provided inside the TGUI download, inside the "widgets" folder.

QuoteAlso, I was wondering if that was possible to make a chatbox or listbox with buttons in every line?
You should have a look at the Grid widget:
https://tgui.eu/tutorials/v06/grid/
https://tgui.eu/documentation/v0.6/classtgui_1_1Grid.html

Law

Thanks for Black.conf.

As for grid, I tried the examples but I couldn't make it work. You did not seem to bother declaring a grid in your tutorials (or maybe I didn't search too well?), and the line

tgui::EditBox::Ptr edittBox(*grid);

gets an error on my computer. :(

texus

All widgets are created in the same way.

In order to create the grid, just do:
tgui::Grid::Ptr grid(gui);

That will add the grid widget to the gui and after that you can start adding stuff to the grid.

It may have been a bit unclear in the tutorial, since I don't specify what the grid variable is.

(if this is not your problem, the you should post the error message so that I don't have to guess)

Law

Everything compiles perfectly now, thanks :)

texus

Ok, I have also added the line to the tutorial.

It feels a bit weird for me to write the line though, since I have been working on v0.7 for some time already and creating a widget is completely different there. I even had to look up myself whether grid had a load function or not :).

Law

#6
Hello, is there a simple way to create a square button (I can't do it with Black.conf, it is only rectangular, and I'm not sure I understand the lines inside Black.conf) with a different image?

My goal is to create a listbox where each line contains
- a text
- next to the text, a dozen buttons with no text on them, instead they each have their own image so that the user can easily guess what each button actually does.

Is this doable? Sorry to be such a pain :-[

texus

It sure is possible, but not with the default Black theme. One of the limitations of v0.6 is that you can't use a size for which the image was intended for (e.g. the black button isn't intended to be square).

But do you really need a button? The theme files are still limited to one button per file, so you would be needing a theme file for every button image. This limitation even still exists on my private v0.7-dev branch, although I plan to fix that next week or so.

So it would be easier if a simple image was enough (if not then I'll happily explain how to write the theme files). If you don't need a different hover or down image, then you can just use the Picture class. It is also capable of sending click callbacks.

QuoteMy goal is to create a listbox where each line contains
- a text
- next to the text, a dozen buttons with no text on them, instead they each have their own image so that the user can easily guess what each button actually does.
Out of my head (i.e. untested code), it would look like this: (it assumes that each column has the same button images)
void addLine(tgui::Grid::Ptr grid, const std::string& text)
{
    // There is no function that returns the amount of columns or rows it seems
    // I guess I'll have to fix that, but for now rows = amountOfWidgets / widgetsPerRow
    unsigned int rows = grid->getWidgets().size() / 3;  // 3 because we add a label and two pictures
   
    tgui::Label::Ptr label(*grid);
    // change stuff like label color and text size
    label->setText(text);
   
    tgui::Picture::Ptr first(*grid);
    first->load("FirstButton.png");
   
    tgui::Picture::Ptr second(*grid);
    second->load("SecondButton.png");
   
    grid->addWidget(label, rows, 0);
    first->addWidget(label, rows, 1);
    second->addWidget(label, rows, 2);
}

int main()
{
    // Obviously some other code is in this function as well
   
    tgui::Grid::Ptr grid(gui);
   
    // Whenever you need a new line you just call addLine(grid, "Text")
}


How you handle the callback is up to you, but just for the sake of giving an example, here the callback function will be called with the row and column number of the grid (since label is in column 0, the first button has column number 1, the next 2, and so on)
void func(unsigned int row, unsigned int col);
first->bindCallback(std::bind(func, rows, 1), tgui::Picture::LeftMouseClicked);
second->bindCallback(std::bind(func, rows, 2), tgui::Picture::LeftMouseClicked);


QuoteSorry to be such a pain
Its ok to ask questions, especially about complex stuff like this. Plus it prevents me from feeling like nobody is using my library :).

Law

#8
Hello texus,

Well I sort of plan to make a (free) software whose goal is to play cards. Usually, when you play a card game on the Internet, you hover over the card and a list of options appears nearby (flip, move, etc.). I want to offer a lot of options, but as a result the list would be much longer than the card! So I fancy buttons with pictures on the card instead of a list nearby, each button having an explicit picture for what they do.

In game, I could sometimes need up to 20 different buttons that would display on one single card. Ideally , they would appear progressively on the card when you hover over it (From 100% transparent to 0% transparent, though I want this to be fast, so something like 100% -> 0% in 4-5 frames). Ideally still, these buttons would move along with the card when it is moving slowly or moving close to the initial location.

Now, I am bothering you with lists with buttons at every line because the game would need different card piles. I plan to pop up a window when you click on a card pile, and in that window, the names of all the cards located in that pile appear in a list, along with the option buttons. Ideally, under the list would also be a text box, and for whatever string you type in it, the list of cards is shortened to the cards that each have that string in their name.

Unfortunately, depending on the card, some buttons might not be displayed (be it in game or in the list). (For example, there is no need to offer the option "move to pile 5" if the card already is in pile 5.) Also, depending on the card, some buttons may share the same location, but are never displayed at the same time (like, the third button is ButtonA for all cards of type A, but is ButtonB for all cards of type B)

On top of that, I would very much like all buttons to have their own hover and down image, yes.  :D

Sooooo, as you can see, there is a lot of work for me!  :'( So thanks a lot for your input, I'm going to use what you wrote now and see if I can code something remotely close to my goal with that. I know this will take me weeks (months?) anyway. I will try to handle all the different buttons by using the same code you wrote in Black.conf.

Thanks for reading :)

texus

#9
If you do need hover and down images then you will have to use buttons instead of normal pictures.

Unlike the Black theme, your images probably will never get stretched in one direction and you thus don't need to split them in 3 parts.
So you can use NormalImage, HoverImage and DownImage properties (instead of all combinations with _L, _M and _R).
The value is the filename of the image in quotes, optionally followed by which part of the image to load (defined as (left, top, width, height)). It the part rectangle is not specified, the entire file will be loaded.

As said, you will need one theme file per button. So they will look like:
Button:
NormalImage = "..."
HoverImage = "..."
DownImage = "..."
SeparateHoverImage = true



Some of the work you have to do could be easier in v0.7.
Two examples:
- You can have multiple buttons in a single config file (I very recently added this feature)
- You can specify a relative position. You can make the buttons relative to the card (if this is a tgui::Picture widget and not a sf::Sprite) and then the buttons will automatically move when the position of the card changes.

However, since v0.7 is still under serious changes (the big rewrite is almost finished though), the new parts are not very well tested and the api will not remain stable. But if you want to try this version (most features can be found by looking at the post on the blog), then just let me know.

The project indeed sounds like a lot of work. I would love to see it when it finished.

Law

Well unless it will take you several months to finish your latest version, I think I can wait a bit. I have other things to code anyway (like... the database) I'd rather wait and use a stable version than take the current one as it is and experience problems.

As for the cards, they are all sf::Sprite.

Thanks a lot for your help.

texus

QuoteAs for the cards, they are all sf::Sprite.
In that case the automatic relative positioning won't help much.

QuoteWell unless it will take you several months to finish your latest version, I think I can wait a bit.
I can't predict how long it will take, but I don't expect it to be finished this year. I'll have a little over one month left to work on it every day and then I will have a lot less time. So its hard to predict how far I can get by next month. Hopefully there will be an alpha version by then which will bring some stability.

QuoteI'd rather wait and use a stable version than take the current one as it is and experience problems.
I guess you can still make a decision in a month or so, to see what the status is at that point. There will be tons of new features in v0.7, but I don't think I will get the same stability as in v0.6 soon.
If v0.6 already has what you need then that should probably be the version to go with.

Law

Alright I see.

Quick question, I couldn't find that piece of information. When you display an EditBox, it is easy to put an automatic text in it (like "Enter your username"). But I would like this text to disappear as soon as I click inside the EditBox. Also, I would like this text to be in italic grey, so that one could easily notice that it's only an automatic text. Is there any easy way to do this?

texus

#13
I have added something similar in v0.7, with the difference that it isn't italic and only disappears when you start typing. Making it italic is not such a bad idea, I guess I'm going to change my code to do that too.

Without changing the code in edit box, you could write some functions that make changes to the edit box at the right time, but you can't make the text italic.
With the code that I'm going to have for v0.7 (and which can possibly be ported back to v0.6 if you want), it won't disappear when just clicking on the edit box. Although you could intercept the focus callback to remove the default text, and the unfocused callback to add it again.

Law

I think it might be best using the code you prepared for v0.7 then, because this way I won't have to change anything when upgrading. Tell me what to add where please. :)

texus

There will still be quite some changes in the next month to the v0.7 code though.
But the big rewrite to all the widgets is almost over (just MessageBox has been temporarily disabled and TextBox still has to be rewritten). Most of these changes will be improvements to specific widgets so they shouldn't bring too much incompatibilities.

There aren't tutorials yet, but the post in the last month on the facebook page show most of the new features.
The example code that is included with the download will be the best place to learn though.

I'm just recreating the Black theme. After that I'll send you the v0.7 code.
Do you have a bitbucket account by any chance?

Law

Sorry I don't. But I don't mind copy/pasting.

Thanks a lot :)

texus

#17
You can download it here: https://www.dropbox.com/s/ay4trebp4j1ehqr/texus-tgui-devel-af81ec0bcefb.zip?dl=1
Installation is the same as v0.6. You do need to have the latest sfml version for it though, it won't work with sfml 2.1.

Have a look at the examples/login_screen folder. That example will probably teach you most things.

I noticed that there is still a small bug with how slider stretches. I'll fix that tomorrow.
In order to solve it, the Slider section in Black.conf should look like this:
Slider:
    TrackNormalImage = "Black.png" Part(203, 150, 20, 45) Middle(0, 15, 20, 15)
    TrackHoverImage  = "Black.png" Part(223, 150, 20, 45) Middle(0, 15, 20, 15)
    ThumbNormalImage = "Black.png" Part(243, 150, 30, 30)

I even just realized that in v0.6 it always stretched that bad. So its not even a bug fix, changing this code is a feature :).

Law

Scanning dependencies of target tgui
[  2%] [  5%] [  8%] [ 11%] Building CXX object src/TGUI/CMakeFiles/tgui.dir/Gui.cpp.o
Building CXX object src/TGUI/CMakeFiles/tgui.dir/EditBox.cpp.o
Building CXX object src/TGUI/CMakeFiles/tgui.dir/Container.cpp.o
Building CXX object src/TGUI/CMakeFiles/tgui.dir/Layout.cpp.o
/home/lol/texus-tgui-devel-af81ec0bcefb/src/TGUI/Layout.cpp: In constructor 'tgui::LayoutGroup::LayoutGroup(tgui::Layout1d&, const tgui::Layout1d&, tgui::LayoutGroup::Selector)':
/home/lol/texus-tgui-devel-af81ec0bcefb/src/TGUI/Layout.cpp:276:28: error: invalid initialization of non-const reference of type 'tgui::Layout1d&' from an rvalue of type '<brace-enclosed initializer list>'
         m_selector{selector}
                            ^
/home/lol/texus-tgui-devel-af81ec0bcefb/src/TGUI/Layout.cpp: In constructor 'tgui::LayoutGroup::LayoutGroup(tgui::LayoutGroup&&)':
/home/lol/texus-tgui-devel-af81ec0bcefb/src/TGUI/Layout.cpp:286:36: error: invalid initialization of non-const reference of type 'tgui::Layout1d&' from an rvalue of type '<brace-enclosed initializer list>'
         m_selector{group.m_selector}
                                    ^
make[2]: *** [src/TGUI/CMakeFiles/tgui.dir/Layout.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [src/TGUI/CMakeFiles/tgui.dir/all] Error 2
make: *** [all] Error 2


Didn't you make me install the latest SFML ?

texus

Yes, but I was just mentioning it in case you also develop on another computer.

What compiler version do you have? (type "g++ --version" in the terminal)

Law

g++ (Ubuntu 4.8.2-19ubuntu1) 4.8.2

Here it is.

texus

I think we may have a serious problem here, this may not be easy to fix.
But before I can try to fix it I have to reproduce it. I have 4.9.1 installed on all my linuxes so I'm going to check on windows with 4.7.1.

In worst case I will have to completely rewrite the layout system (which I'm planning to do someday anyway since it has become a mess), but then it will take another week before you can use this version.

Law

Okay, anyway I was only asking you that for a minor thing, I can wait. Don't feel urged to fix that right now. I have lots of other things to do anyway.

Law

Also I was wondering.

    NormalImage_L  = "Black.png" (  0,  25,  50, 50)
    NormalImage_M  = "Black.png" ( 50,  25, 100, 50)
    NormalImage_R  = "Black.png" (150,  25,  50, 50)
    HoverImage_L   = "Black.png" (  0,  75,  50, 50)
    HoverImage_M   = "Black.png" ( 50,  75, 100, 50)
    HoverImage_R   = "Black.png" (150,  75,  50, 50)
    DownImage_L    = "Black.png" (  0, 125,  50, 50)
    DownImage_M    = "Black.png" ( 50, 125, 100, 50)
    DownImage_R    = "Black.png" (150, 125,  50, 50)


What do L, M and R stand for?

texus

#24
Left, Middle and Right.

The Left and Right parts would keep their ratio, while the Middle part gets stretched.
E.g. the EditBox image in the black theme is only 120 pixels width, but it still looks good when giving it a width of 1000 pixels.

But this has been replaced in v0.7 where you can even use 9-slice scaling. You would specify the entire button image there, and then set the middle rect to (50, 0, 100, 50) to split the image (with a width of 200 and a height of 50) into 3 parts (these rects are always left,top,width,height).