Recent Posts

Pages: 1 2 [3] 4 5 ... 10
21
Help requests / Re: SFML drawing into a child window
« Last post by RitoonL on 27 May 2020, 14:45:21 »
i might be wrong as i am myself a bit not sure of what i'm doing, but you might try to give a size to your canva. It should be because you canvas size is 0
22
Help requests / Re: SFML drawing into a child window
« Last post by Kvaz1r on 27 May 2020, 14:10:42 »
Interesting topic, I (too?) not understand how to draw on tgui::Canvas.

I thought this code :

Code: [Select]
#include <TGUI/TGUI.hpp>

sf::VertexArray test_draw()
{
    sf::VertexArray test(sf::Quads, 4);
   
    test[0].position = sf::Vector2f(0, 0);
    test[0].color = sf::Color::Red;
    test[1].position = sf::Vector2f(50, 0);
    test[1].color = sf::Color::Red;
    test[2].position = sf::Vector2f(50, 70);
    test[2].color = sf::Color::Red;
    test[3].position = sf::Vector2f(0, 70);
    test[3].color = sf::Color::Red;
    return test;
}

int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "TGUI window");
tgui::Gui gui(window);

    auto panel = tgui::Panel::create();

    auto canvas = tgui::Canvas::create();
    canvas->clear();
    canvas->draw(test_draw());
    canvas->display();
    panel->add(canvas);

    gui.add(panel);

while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();

gui.handleEvent(event); // Pass the event to the widgets
}

window.clear();
gui.draw(); // Draw all widgets
        //window.draw(test_draw()); //draw fine
window.display();
}
}

will draw red square but it doesn't draw anything. What am I missing?
Drawing via window (commented line) works fine. 
23
Help requests / Re: SFML drawing into a child window
« Last post by RitoonL on 27 May 2020, 12:23:58 »
Hello Texus,

Many thanks for this, once again very accurate answer, you were right i did not understood what a renderTarget is.

last question before i'm done with this thread, because i now have a better view of what i can do :

My final objective is to render what i have in my class

Drawing section of my class :

void Channel::draw_channel(sf::RenderWindow &window,uint16_t x,uint16_t y)
//void Channel::draw_channel(sf::RenderTarget &Canvas,uint16_t x,uint16_t y)

{
    ostringstream chnbr; // channel number into a string
    chnbr<<_channel_number;
    ostringstream lvlstr; // channel level into a string (can't be uint_8t)
    lvlstr<< _display_level;

    sf::Vertex vertex;
    //vertex.position = sf::Vector2f(0, 0);
    sf::VertexArray ch_quad(sf::Quads, 16);

    bool selected=false;
    for(uint16_t i=0; i<selected_chan.size() ;i++)
    {
        if(selected_chan[i]==_channel_number)
        {
            selected=true;
        }
    }

    // Draws under quad supposed to be outline (draw order)
    ch_quad[0].position = sf::Vector2f(0, 0);
    ch_quad[1].position = sf::Vector2f(50, 0);
    ch_quad[2].position = sf::Vector2f(50, 70);
    ch_quad[3].position = sf::Vector2f(0, 70);

    if(selected == false) //color of outline for selection
    {
        ch_quad[0].color = sf::Color(20, 30, 60);
        ch_quad[1].color = sf::Color(20, 30, 60);
        ch_quad[2].color = sf::Color(20, 30, 60);
        ch_quad[3].color = sf::Color(20, 30, 60);
    }
    if(selected == true)
    {
        ch_quad[0].color = sf::Color(255, 255, 255, 255);
        ch_quad[1].color = sf::Color(255, 255, 255, 255);
        ch_quad[2].color = sf::Color(255, 255, 255, 255);
        ch_quad[3].color = sf::Color(255, 255, 255, 255);
    }

    //draws the inside under quad ad sets the color (black)
    ch_quad[4].position = sf::Vector2f(1,1);
    ch_quad[5].position = sf::Vector2f(49,1);
    ch_quad[6].position = sf::Vector2f(49,69);
    ch_quad[7].position = sf::Vector2f(1,69);
    ch_quad[4].color = sf::Color(0, 0, 0);
    ch_quad[5].color = sf::Color(0, 0, 0);
    ch_quad[6].color = sf::Color(0, 0, 0);
    ch_quad[7].color = sf::Color(0, 0, 0);
    //draws the channel strip
    ch_quad[8].position = sf::Vector2f(1,1);
    ch_quad[9].position = sf::Vector2f(49,1);
    ch_quad[10].position = sf::Vector2f(49,17);
    ch_quad[11].position = sf::Vector2f(1,17);
    ch_quad[8].color = sf::Color(20, 30, 60);
    ch_quad[9].color = sf::Color(20, 30, 60);
    ch_quad[10].color = sf::Color(20, 30, 60);
    ch_quad[11].color = sf::Color(20, 30, 60);
    //draws the info strip
    ch_quad[12].position = sf::Vector2f(1,50);
    ch_quad[13].position = sf::Vector2f(49,50);
    ch_quad[14].position = sf::Vector2f(49,69);
    ch_quad[15].position = sf::Vector2f(1,69);
    ch_quad[12].color = sf::Color(20, 30, 60);
    ch_quad[13].color = sf::Color(20, 30, 60);
    ch_quad[14].color = sf::Color(20, 30, 60);
    ch_quad[15].color = sf::Color(20, 30, 60);

    sf::Transform pos;
    pos.translate(x, y);

    //window.draw(ch_quad, pos);
    window.draw(ch_quad, pos);

    // Channel number text
    ch.setFont(font);
    //ch.setString(std::string("ch ") + chnbr.str());
    ch.setString(chnbr.str());
    ch.setCharacterSize(12);
    ch.setLetterSpacing(0.3);
    ch.setFillColor(sf::Color(255, 255, 255));
    ch.setPosition(x+2, y+2);
    window.draw(ch);
    // Level Text
    if(_level>0)
    {
        lvl.setFont(font);
        lvl.setString(std::string("") + lvlstr.str());
        lvl.setCharacterSize(18);
        lvl.setLetterSpacing(0.3);
        if(_channel_mode == false)
            lvl.setFillColor(sf::Color(255, 255, 255));
        else
            lvl.setFillColor(sf::Color(255, 255, 100));
        lvl.setPosition(x+4, y+8);
        window.draw(lvl);
    }

}

I was passing this directly to the sf::renderWindow, but it's not anymore what i want to do.
As you can see, these graphics are made of 1 vertex array of 16 vertexes, and some text that is dynamically updating.

do you think i shall pass each of the component of my drawing and draw them in the function where i create the canva, or pre-rendering it direcly in the class (in a renderTexture, if i did understand well what you said before) and passing the texture to my function. Does it makes sense to do this? What would be better for display performance ? ... you maybe want to know that the class can have several instances (might be between 1 to 4000 instances).

***EDIT*** Or Even maybe making a sprite in the class and pass it ?

Thanks by advance,

RitoonL
24
Help requests / Re: SFML drawing into a child window
« Last post by texus 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.

Quote
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&"?

Quote
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).

Quote
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
test_draw(arr);
canva->draw(arr);

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();
canva->draw(arr);
25
Help requests / Re: SFML drawing into a child window
« Last post by RitoonL on 27 May 2020, 00:09:46 »
Well,

in facts there is a class ready with the drawings that i've created before, this can be displayed in sf::rendererWindow, but now that i'm constructing the GUI, i want it displayed in the canva. I'm just trying to do it step by step because there is already a lot of code ready that i don't want to breack, that's why i want to know how to pass this renderTarget by reference.

I might be wrong but if  i can do from function to function,  i can do  from class to function the same way. The funny thing is that it should be like using the renderWindow, but i don't know why, i'm stalling on this one.

I feel like i want to plug an aspirator on the kitchen sink ...

just for info, here it my class ... i'm not waiting other people do things for me but i need help for this one ... not showing the .h :

#include <SFML/Graphics.hpp>
#include <string>
#include <sstream>
#include "Channel.h"

using namespace std;
using namespace sf;
//sf::Font font;
//sf::Text ch;
//sf::Text lvl;

static sf::Font font;
extern vector <uint16_t> selected_chan;

bool Channel::Init(const std::string& fontFile)
{
    return font.loadFromFile(fontFile);
}

Channel::Channel(uint16_t channel_number):
    _channel_number(channel_number),
    _level(0),
    _channel_mode(true),
    _display_level(0)
{

}

Channel::~Channel()
{
        //a faire imperativement !
}
//-------------------------------------------------

void Channel::draw_channel(sf::RenderWindow &window,uint16_t x,uint16_t y)
//void Channel::draw_channel(sf::RenderTarget &Canvas,uint16_t x,uint16_t y)

{
    //int x=100,y=0;
    //font.loadFromFile("kimberley_bl.ttf");



    ostringstream chnbr; // channel number into a string
    chnbr<<_channel_number;
    ostringstream lvlstr; // channel level into a string (can't be uint_8t)
    lvlstr<< _display_level;

    sf::Vertex vertex;
    //vertex.position = sf::Vector2f(0, 0);
    sf::VertexArray ch_quad(sf::Quads, 16);

    bool selected=false;
    for(uint16_t i=0; i<selected_chan.size() ;i++)
    {
        if(selected_chan[i]==_channel_number)
        {
            selected=true;
        }
    }

    // Draws under quad supposed to be outline (draw order)
    ch_quad[0].position = sf::Vector2f(0, 0);
    ch_quad[1].position = sf::Vector2f(50, 0);
    ch_quad[2].position = sf::Vector2f(50, 70);
    ch_quad[3].position = sf::Vector2f(0, 70);

    if(selected == false) //color of outline for selection
    {
        ch_quad[0].color = sf::Color(20, 30, 60);
        ch_quad[1].color = sf::Color(20, 30, 60);
        ch_quad[2].color = sf::Color(20, 30, 60);
        ch_quad[3].color = sf::Color(20, 30, 60);
    }
    if(selected == true)
    {
        ch_quad[0].color = sf::Color(255, 255, 255, 255);
        ch_quad[1].color = sf::Color(255, 255, 255, 255);
        ch_quad[2].color = sf::Color(255, 255, 255, 255);
        ch_quad[3].color = sf::Color(255, 255, 255, 255);
    }

    //draws the inside under quad ad sets the color (black)
    ch_quad[4].position = sf::Vector2f(1,1);
    ch_quad[5].position = sf::Vector2f(49,1);
    ch_quad[6].position = sf::Vector2f(49,69);
    ch_quad[7].position = sf::Vector2f(1,69);
    ch_quad[4].color = sf::Color(0, 0, 0);
    ch_quad[5].color = sf::Color(0, 0, 0);
    ch_quad[6].color = sf::Color(0, 0, 0);
    ch_quad[7].color = sf::Color(0, 0, 0);
    //draws the channel strip
    ch_quad[8].position = sf::Vector2f(1,1);
    ch_quad[9].position = sf::Vector2f(49,1);
    ch_quad[10].position = sf::Vector2f(49,17);
    ch_quad[11].position = sf::Vector2f(1,17);
    ch_quad[8].color = sf::Color(20, 30, 60);
    ch_quad[9].color = sf::Color(20, 30, 60);
    ch_quad[10].color = sf::Color(20, 30, 60);
    ch_quad[11].color = sf::Color(20, 30, 60);
    //draws the info strip
    ch_quad[12].position = sf::Vector2f(1,50);
    ch_quad[13].position = sf::Vector2f(49,50);
    ch_quad[14].position = sf::Vector2f(49,69);
    ch_quad[15].position = sf::Vector2f(1,69);
    ch_quad[12].color = sf::Color(20, 30, 60);
    ch_quad[13].color = sf::Color(20, 30, 60);
    ch_quad[14].color = sf::Color(20, 30, 60);
    ch_quad[15].color = sf::Color(20, 30, 60);

    sf::Transform pos;
    pos.translate(x, y);

    //window.draw(ch_quad, pos);
    window.draw(ch_quad, pos);

    // Channel number text
    ch.setFont(font);
    //ch.setString(std::string("ch ") + chnbr.str());
    ch.setString(chnbr.str());
    ch.setCharacterSize(12);
    ch.setLetterSpacing(0.3);
    ch.setFillColor(sf::Color(255, 255, 255));
    ch.setPosition(x+2, y+2);
    window.draw(ch);
    // Level Text
    if(_level>0)
    {
        lvl.setFont(font);
        lvl.setString(std::string("") + lvlstr.str());
        lvl.setCharacterSize(18);
        lvl.setLetterSpacing(0.3);
        if(_channel_mode == false)
            lvl.setFillColor(sf::Color(255, 255, 255));
        else
            lvl.setFillColor(sf::Color(255, 255, 100));
        lvl.setPosition(x+4, y+8);
        window.draw(lvl);
    }

}
//-------------------------------------------------

void Channel::set_channel_number(uint16_t channel_number)//Channel.set_channel_number
{
    _channel_number = channel_number;
}
//-------------------------------------------------

uint16_t Channel::get_channel_number()
{
    return _channel_number;
}
//-------------------------------------------------

void Channel::set_level(uint16_t level)//devenu void
{
    _level = level;
    display_level();
}
//-------------------------------------------------

uint16_t Channel::get_level()
{
    return _level;
}
//-------------------------------------------------

void Channel::change_mode(bool channel_mode)
{
    _channel_mode=channel_mode;
}
//-------------------------------------------------

bool Channel::get_mode()
{
    return _channel_mode;
}
//-------------------------------------------------

void Channel::display_level()
{
    if (_channel_mode==false)
    {
        _display_level = (_level/2.55);
    }
    else
    _display_level = _level;
}
26
Help requests / Re: SFML drawing into a child window
« Last post by Kvaz1r on 26 May 2020, 23:52:09 »
Why not define class and keep your objects there?
27
Help requests / Re: SFML drawing into a child window
« Last post by RitoonL on 26 May 2020, 22:11:31 »
Sorry i have to !up the subject because i edited previous one ... oh yeah i hate double posts too !
28
Help requests / Re: Scrollbar in child window not staying the right place
« Last post by RitoonL on 26 May 2020, 19:13:05 »
Ok i understand now that my error is to add the scrollbar to the child window instead of adding it with gui.add and binding it to my child window. I will keep this in mind for the future of the project.

As i'm still a beginner, and self learning, i have to learn by error, even if sometimes i can be considered as stupid/or asking stupid questions. But i have no mentor or school teatcher to who i can refer ... really sorry for that.

Your really accurate answer helps me a lot and i'm grateful for this.

Sorry for the problems with my mailbox, this is really strange, i received the confirmation mail this morning, but never received your personal answer. Thanks for adding me manually.

Regards,

RitoonL
29
Help requests / Re: Scrollbar in child window not staying the right place
« Last post by texus on 26 May 2020, 18:48:46 »
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).

Quote
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).

Quote
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), free.fr 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 "tgui.eu" domain name, or they had temporarily blacklisted a lot of ip addresses.
Quote
It looks like free.fr is currently blocking ip addresses from sendgrid.com (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.
30
Help requests / Re: how get a widget and use it ?
« Last post by che2a on 26 May 2020, 18:29:38 »
Thank you it works !

And thank you for your work tgui is awesome :)
Pages: 1 2 [3] 4 5 ... 10