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.

Messages - texus

Pages: [1] 2 3 ... 104
Help requests / Re: Signals, unbound parameter
« on: Yesterday at 17:14:00 »
The problem is that _test() is a member function.
Unlike a free function (a function that isn't part of a class), a member function needs to know what object it is called on. If you access member variables or call other member functions then the code needs to know on which object it needs access these members (since you may create multiple Ch_window objects).

Although you don't write any parameters, the c++ compiler will generate a function that is equivalent to the following:
void _test(Ch_window* this);

That is where the "this" object comes from that you can use within a class, behind the scenes it is a parameter passed to all your member functions.
So the function does have a parameter, which is what the connect call is complaining about (it doesn't know what value it has to pass to your this pointer).

Since TGUI needs to know on which object to call the _test function, you have to give it a pointer to the object. Since you are calling the connect function inside a member function of Ch_window and you obviously want to call the _test function on the same object, the pointer to the object is literally your "this" value. You also have to change the function name for it to work properly:
channels->connect("SizeChanged", &Ch_window::_test, this);

Alternatively, you can use a lambda function, which is similar to what TGUI will internally do when you write the above:
channels->connect("SizeChanged", [this]{ _test(); });

Help requests / Re: SFML drawing into a child window
« on: 31 May 2020, 23:05:14 »
I see now what the problem was. It's hard to help with how you should pass data to different places because there is a lot of freedom in how to do it exactly without there always being a best way. For the simple case that you have here, returning the value like you are doing is probably the best option, but I'll provide some alternatives that you could keep in mind if you face a similar problem later.

I said earlier that tgui::Canvas::Ptr is a simple pointer and thus copying it isn't a problem. If it would have been a large object then returning it might not have been a good option, passing it by reference would have been better. In some cases you can still return a large object in such a way that it is moved instead of copied, but until you fully understand move semantics it might be a good idea to always assume that a copy would take place and pass large objects by reference parameter.
tgui::Canvas::Ptr canvas;
channels_window(window, gui, canvas);
void channels_window(sf::RenderWindow &window, tgui::Gui& gui, tgui::Canvas::Ptr& canvas)
    canvas = tgui::Canvas::create();
    // ...
Design wise it might be better to call "tgui::Canvas::create()" before calling the function, but this example is to illustrate that you can pass an uninitialized object into the function which will initialize it.

Another alternative is to use a class member. It channel_sorting and channels_window wouldn't be free functions but instead were part of the same class then you could simply give that class a tgui::Canvas::Ptr member that you initialize in channels_window and use in channel_sorting. There is no need for passing parameters and return values in such case.

Yet another alternative would be to store the tgui::Canvas::Ptr inside the Channel class itself. This might not be a very good option here because you could have many channels and you would unnecessarily be making each channel class a few bytes larger, but it would also be an option in which you wouldn't need to pass the canvas in channel_sorting and draw_channel.

If you e.g. need sf::RenderWindow, tgui::Gui and tgui::Canvas::Ptr in a lot of places then another option would even become to put those together into a class and pass an object of that class around by reference instead of passing them separately.

An alternative that is specific to TGUI widgets is letting the gui store the widget. You can pass a unique name as parameter to the add function that allows you to retrieve it later:
gui.add(canvas, "MyCanvas");
tgui::Widget::Ptr widget = gui.get("MyCanvas"); // Get the widget back, but as a base class on which you can't call Canvas-specific function
tgui::Canvas::Ptr canvas = gui.get<tgui::Canvas>("MyCanvas"); // Get the widget back, casted to the right type (might crash if widget with name "MyCanvas" wasn't a tgui::Canvas)
So as long as you have access to the tgui::Gui object, you can get access to any widget that was added to it.

So as you can see there are tons of options to get the canvas in the right place (even more than the ones I wrote), but knowing which design fits your needs best comes with experience by just trying and learning which choices didn't work well. If you are unsure which design is better, the best design is most often the one that requires you to write as little code as possible  (while makes the code as readable and understandable as possible, i.e. not focusing on the line count).

Not really related, but I wouldn't use the "ch(x)" define. It makes the code harder to read. If you really need to shorten the line (e.g. if you need to write several lines containing "tab_Channel[address_channel[x]]") then it would be better to just make a reference to the object:
auto& ch = tab_Channel[address_channel[x]];

Help requests / Re: SFML drawing into a child window
« on: 30 May 2020, 20:09:47 »
I don't have much time now, so maybe if I have more time to read your post I will understand it better, but right now I'm not sure where your problem is exactly. So I'll just quickly comment on some of the things you said.

I know that i must use canva->display() in my main or in a fuction called in the main, but i don't know how to do as the compiler wants the canvas to be declared
What exactly is the error? Is there no canvas variable (because no such object is declared there), or doesn't it know tgui::Canvas (because you wouldn't be including TGUI.hpp)?

but if i use (tgui::Canvas::Ptr &canvas) as argument of the fuction, wich prevent copying the canvas, i can't use the function in the main
Then there is something wrong about the way you call it in your main function. You need to have a reference to an existing object, it won't work if you e.g. try to create a new canvas on the same line as your function call.
That being said, TGUI widgets are wrapped in pointers. Without the "&" you are only copying the pointer, which still points to the same canvas, the canvas never gets copied. Taking the argument by reference would only be marginally faster because the Ptr is a std::shared_ptr which has to count the amount of pointers to the object: if it is copied then it has to increment the counter, if you take it by reference then it doesn't. So don't worry about passing it by value, but if the code doesn't compile when you try to use a reference then there is something wrong.

Edit : I tried to declare
tgui::Canvas::Ptr canvas;
This is equivalent of code like this:
int *p;
In the best case p would be a nullptr, in the worst case it points to a random memory address. This is why it crashes if you try to use it, you need to actually create the canvas (so that the pointer points to something):
tgui::Canvas::Ptr canvas = tgui::Canvas::create();

It might help if you created a small demo application that would show the issue (just a main function with just a few functions next to it that would actually be runnable on my pc). Only being able to see some of the code means that I would have to make assumptions about how the rest looks. I know for example that you did something wrong in main, but I can't know what. So it's a bit disorienting to follow what is going on, and right now I don't have time to really try and figure it out.

Help requests / Re: SFML drawing into a child window
« on: 29 May 2020, 19:45:21 »
we're really seeking every opportunity to refresh only what we need
we're trying to keep in mind every opportunity to optimize display
By coincidence I actually fixed an issue today related to this ability. If you were to only draw the screen after you received an event (to minimize the amount of times you need to redraw the screen) then the cursor in edit box would for example stop to blink. Since there was no way to know when the cursor appears and disappears, you would still need to regularly draw the gui even when not receiving events (and you would waste CPU usage as most of the frames nothing would change).

In the 0.8 branch on github, I just made a change that allows you to know when a widget requires the screen to be refreshed (the change was already made in 0.9-dev last week, but I just backported it now). You would need to first call the following to decouple updating time and drawing in TGUI:

Then every frame, update the time:
bool screenNeedsUpdate = gui.updateTime();

The screenNeedsUpdate variable will become true when something changes in the gui. It almost always will return false, but when an edit box or text box is focused it will return true twice per second so that you can update the screen to show the blinking cursor without having to refresh the screen more than you have to. If you use the showWithEffect or hideWithEffect functions in widget then the update function will return true the whole time while the animation plays, so you would still want to limit the amount of frames being rendered some other way if you want to use those functions.

Help requests / Re: listView and symbols
« on: 28 May 2020, 18:34:58 »
Using widestrings will require you to store the value in a std::wstring or sf::String immediately, so your code where you add it to the return of std::to_string won't compile.
You could use u8"\u20AC" if you want to store it in an std::string (but your code wouldn't work when compiling with c++20 or higher because that would return an std::u8string instead).
So the best option would probably be to put it in an sf::String immediately:
sf::String str_annual_wages = std::to_string(drivers_vector[i]->contract->getAnnualWages()) + sf::String(L"\u20AC");

Help requests / Re: listView and symbols
« on: 28 May 2020, 18:27:49 »
Unless you are an organization with more than 5 users, Visual Studio has a free community version.

Maybe you should try L"\u20AC".
Having unicode characters in your code can be tricky, because it will require the cpp files to have the right encoding (and your code thus won't compile if someone uses a different file encoding), so it might be better just to use the hex code instead.

Help requests / Re: SFML drawing into a child window
« on: 27 May 2020, 18:31:03 »
I would just treat the Canvas as you previously treated the RenderWindow: change your draw_channel function to
void Channel::draw_channel(tgui::Canvas::Ptr &canvas,uint16_t x,uint16_t y)
and replace "window.draw" with "canvas->draw" inside the function.

Pre-rendering to a RenderTexture first is going to be marginally slower since you would be doing an extra draw call. If you would use a RenderTexture then you would also have to create it somewhere. Creating it is a "slow" operation, so you wouldn't want to use a single RenderTexture for each Channel object. You would end up with a single RenderTexture that you create once and pass around everywhere in your code, but that is exactly what you would do when you just pass the Canvas everywhere (Canvas is nothing more than a widget containing a RenderTexture).

Making a sprite in the class is the same option as creating a RenderTexture. You can't draw things to a sprite and you can't draw a RenderTexture to the canvas, you need both the RenderTexture and Sprite to make a drawing buffer. The only way to use RenderTexture and Sprite is to create a RenderTexture, draw on that render texture, create a sprite from the texture and drawing the sprite to the canvas. But again, that is just doubling the effort as this is what Canvas already does (it creates a RenderTexture, lets you draw on it with the clear(), draw() and display() function, creates a sprite from the texture and later draws that sprite to the window).

Whether your object should contain a draw function so that it can draw itself, or whether you have the rendering code outside the object is a design decision that might depend on how the code is used. But you actually already made this design decision. When drawing to the RenderWindow, you chose to keep the drawing code inside the Channel object, so there is no reason why you would suddenly do it another way just because you need to render to a canvas.

Help requests / Re: SFML drawing into a child window
« on: 27 May 2020, 09:01:13 »
There is no problem in double posting if it makes sense to do so. If you asked a question for which there was no answer yet then it might be better to edit than to make many posts (I don't really care about one post more or less though, it's fine as long as you don't create 5 in a row). In this case your original response didn't contain a question though. I considered this topic close after reading your response, and editing doesn't send me a notification, so I never found out that you had another question until you posted another reply.

The issues seem to originate from not fully understanding what sf::RenderTarget is.

target = test; will not work
One is an sf::VertexArray, the other is a sf::RenderTarget, those are 2 completely different things.
The RenderTarget is what you draw on, it is a common base class of both RenderTexture and RenderWindow.
The VertexArray is a drawable. It is something you can draw on top of a RenderTarget.
If you intended to draw the vertex array to the render target then it should have been "target.draw(test)".
If you just want to pass the "sf::VertexArray" as a reference then you might be over-complicating things, why not just make the parameter "sf::VertexArray&" instead of "sf::RenderTarget&"?

sf::RenderTarget *target; // not sure if i can declare the render target like this
You cannot create a RenderTarget object, it is an abstract class. You either have to create a RenderTexture or a RenderWindow.
By making it a pointer, you have a variable that is supposed to point to a RenderTexture or RenderWindow, but if you don't set a value for the pointer then it points to a random location in memory so trying to use it will just crash (in the best case scenario).

canva->draw(target); // if the target is retrieved, it should draw fine.
Lines like these should always be in the form of "RenderTarget.draw(Drawable)". The canvas is a RenderTarget-like type, so you can call draw on it, but "target" isn't a drawable, so it cannot be passed to the draw function.

What I think you want to do is this:
void test_draw(sf::VertexArray& test)
    // Replace the contents of "test" (which was an empty vertex array until now) with a new vertex array that contains 4 points.
    // Alternatively, you could have written "test->setPrimitiveType(sf::Quads)" and "test->resize(4)".
    test = sf::VertexArray(sf::Quads, 4);

    test[0].position = sf::Vector2f(0, 0);
    test[1].position = sf::Vector2f(50, 0);
    test[2].position = sf::Vector2f(50, 70);
    test[3].position = sf::Vector2f(0, 70);

sf::VertexArray arr; // create an empty vertex array that will be initialized by test_draw

Alternatively, you can just return the VertexArray as return value:
sf::VertexArray test_draw()
    sf::VertexArray test(sf::Quads, 4);
    test[0].position = sf::Vector2f(0, 0);
    test[1].position = sf::Vector2f(50, 0);
    test[2].position = sf::Vector2f(50, 70);
    test[3].position = sf::Vector2f(0, 70);
    return test;

sf::VertexArray arr = test_draw();

The bindRight behavior is not a bug, I tested it here and having it move through the child window means you are using it wrong. If the scrollbar is added to the gui instead of to the child window then it will follow the child window around (although not at exactly the wanted pixel).

bindRight = bindLeft + bindWidth
So if you move the child window around then the left position of the window changes and thus the scrollbar will also move. But the position of the scrollbar is relative to that of the child window (since you added it to the child window), so it will moves twice (once with the child window and once because you change its position with the bind function).

Also, Bindright seems to want to bind the left side of the scrollbar on the right side of the window, wich position it out the window

would'nt bindRight just want to stick right side of the widget on left side of the childwindow ?
The position of widgets is always the top left position, so even if you use bindRight, it will position the left side of the widget on that location. The bindRight function wasn't meant for overlapping widgets, it was meant for widgets that are placed next to each other. This is why you still have to subtract the width of your scrollbar from the position to get it to the right place. In TGUI 0.9-dev there is a setOrigin function now, so you would be able to call setOrigin(1, 0) and then you no longer have to subtract the width (because the position given to the widget would be the top-right position instead of top-left).

i think that's what you're talking about with bindInnerWidth
Not really. Imagine you have a panel of size (100x100) and it has a border of 10 pixels width. The contents of that panel is only (80x80). In order to have a widget of width 20px on the right side of the panel, you must place it on left position 60. If you were to use bindSize()-20 then you would actually be placing it on position 80 (=100-20). There should be a bindInnerSize() function that returns 80 so that you can do bindInnerSize()-20.
The example that I gave uses a layout with the string "100%". This is internally translated to widget->getInnerSize() and not widget->getSize(), which is why it worked. But there currently isn't a bind function to achieve the same thing, you currently have to create the layout using a string to get the wanted behavior.

ChildWindow behaves a bit differently in TGUI 0.8, it's inner size and size are the same thing, the borders and title bar are drawn outside of its size. Since this is inconsistent with the other widgets, this was changed in 0.9-dev where there is a difference between size and inner size now.

Btw, your email provider has been blocking more than just my forum email yesterday. Before I replied on facebook I had actually send you an email, but today I received it back as undelivered. As I said in that email (which I've quoted below), was blocking the messages based on ip address (at least that was what the error claimed). Messages sent using my mail client are however send using a completely different mail provider. So either it lies in its error message and just really dislikes the "" domain name, or they had temporarily blacklisted a lot of ip addresses.
It looks like is currently blocking ip addresses from (which is where my forum emails are send from).
Sendgrid has been retrying to send the message every few minutes but it always gets a 451 error back.

I've activated you on the forum manually, you should be able to login now.

Help requests / Re: how get a widget and use it ?
« on: 26 May 2020, 18:05:31 »
Code like that exists, you just need to make the "f" a capital letter (moveToFront instead of moveTofront).

If you don't need to call any function specific to MenuBar then you can skip the cast to MenuBar and have code that works for any type of widget:
tgui::Widget::Ptr widget = gui->get("MenuBar");

The bindRight behavior sounds like a bug. Which widgets are parents to each other? Is the container inside the child window? Is the scrollbar added to the container, to the child window or to the gui?

The bindRight function was intended for sibling widgets that needed to be placed next to each other. Since it looks like you want the scrollbar on top of the container, maybe you should just add the scrollbar to the container and call
scrollbar->setPosition({"100% - width", 0})

With bind functions this would be equivalent to the following, but note that you can't use this code yet as I just realized there is no bindInnerWidth function (it's sometimes equivalent to bindWidth, but bindWidth won't work correctly if your container has borders and padding).
scrollbar->setPosition({bindInnerWidth(container) + bindWidth(scrollbar), 0})

If the scrollbar really has to be part of the container then you could consider using ScrollablePanel instead of creating a scrollbar manually.

Help requests / Re: SFML drawing into a child window
« on: 25 May 2020, 18:35:21 »
You would have to use the Canvas widget for this.

The canvas acts like a RenderTexture (it's actually just a wrapper around a RenderTexture), so you use the clear(), draw() and display() functions on it to draw your SFML stuff on the canvas.
Since the canvas is a tgui widget, you can add it to the child window and it will display the last thing you rendered to it.
You only need to update the canvas when the SFML rendering changes, so if what you render is static then you don't have to redraw to the canvas every frame.

Help requests / Re: ChatBox : Line Spacing and selection
« on: 24 May 2020, 19:27:32 »
If a RichLabel would exist then you would easily be able to build chat box functionality on top of that widget and you would have freedom as to how each line looks. When I created the ChatBox I knew that a RichLabel wasn't going to be added soon (it was too much work), so I ended up writing the ChatBox widget to provide a minimal support for such use cases. Years have passed since then and the situation hasn't really improved: ChatBox is still the only widget with multiple colored texts and RichLabel still isn't expected anywhere soon.

Although adapting the ChatBox to display the name and text in different colors would be easier than implementing a real RichLabel class (that can change its color arbitrarily in the text), it does have similar difficulties. Single lines of texts are easy to render, but to use 2 colors you need to draw each line using up to 3 text objects which have to be carefully positioned (one for the name, one for the remainder of the line and one for other rows if the text doesn't fit on a same row).
This kind of code already exists in TextBox of course (which draws the text in up to 5 parts when multiple lines are selected), but TextBox is one of the most complex classes for a reason.

Help requests / Re: ChatBox : Line Spacing and selection
« on: 24 May 2020, 17:19:19 »
1) No, the line spacing is taken from the font. The distance between 2 lines could be controlled by TGUI code, but the distance between two rows on the same line is controlled by SFML. So you will have to use a different font.

When the renderers are changed to no longer use SFML code then this would become possible, but even if this happens then it would still require a rewrite in some parts of the code, so there won't be a fix for this soon.

2) No, ChatBox is read-only. What you are asking for is essentially a RichTextBox, and that widget shouldn't be expected anywhere in the near future (unless someone would contribute it).

Bonus) To remove the background you can call the following:

Officially that currently isn't supported.
You could get it to work by faking a mouse event though:
label->connect("MouseEntered", [=]{ checkBox->mouseMoved(checkBox->getPosition()); });
label->connect("MouseLeft", [=]{ checkBox->mouseNoLongerOnWidget(); });

Pages: [1] 2 3 ... 104