CPU-Heavy Scrolling

  • 20 Replies
  • 1466 Views
Re: CPU-Heavy Scrolling
« Reply #15 on: 14 January 2017, 19:19:39 »
I am not sure how to copy it, it seems like there are also Borders and Clipping classes used.

UPD: Huh, I am kinda stupid, forgot about namespace for Borders. But I don't see anything related to Clipping in tgui space.
« Last Edit: 14 January 2017, 19:25:39 by Danetta »

*

texus

  • *****
  • 1418
    • View Profile
    • Texus's Blog
Re: CPU-Heavy Scrolling
« Reply #16 on: 14 January 2017, 19:25:20 »
The Borders class should be available because you indirectly include Panel, for the Clipping class you have to add the following on top of your source file:
#include <TGUI/Clipping.hpp>

Re: CPU-Heavy Scrolling
« Reply #17 on: 14 January 2017, 19:26:13 »
Yes, realized that just one second before you answered. Sorry for these questions.

Re: CPU-Heavy Scrolling
« Reply #18 on: 14 January 2017, 19:35:56 »
I have another question. It is more about me trying to learn and not some specific problem (because I found a workaround).

Here is my current code for initialization of panel and scrollbar for it:
        CustomPanel pan;

        tgui::Scrollbar::Ptr scroll = std::make_shared <tgui::Scrollbar>();
        main_window.get_Gui()->add(scroll, "scroll_friends");
        scroll->setPosition(1060, 100);
        scroll->setSize(20, 620);
        scroll->setLowValue(620);
        scroll->setMaximum(1240);
        scroll->hide();
        pan.set_scroll(*main_window.get_Gui());

        CustomPanel::Ptr panel = std::make_shared<CustomPanel>(pan);
               
        panel->setSize(1060, 620);
        panel->setPosition(0, 100);
        //panel->setBackgroundColor(tgui::Color(0, 0, 0, 0));
        panel->getRenderer()->setBackgroundColor(tgui::Color(70, 130, 180, 255));
        panel->hide();
        main_window.get_Gui()->add(panel, "panel_friends");

As you can see, I use my "set_scroll" function (which I use to store pointer of scrollbar inside CutomPanel class) of custom panel via panel object itself. I think it's a wrong way to do so, because we use shared pointers to widgets anyway, right? However, once I do "CustomPanel::Ptr panel = std::make_shared<CustomPanel>(pan);" or something like that (just declaring new panel for example and not sharing existing one) I have'nt access to "set_scroll" anymore, so anything like "panel->set_scroll" is not possible. Where is my mistake?


CustomPanel.h code:
class CustomPanel : public tgui::Panel {
public:
        void set_scroll(tgui::Gui& gui);
        void draw(sf::RenderTarget& target, sf::RenderStates states) const;
private:
        tgui::Scrollbar::Ptr scrollbar;
};
« Last Edit: 14 January 2017, 19:41:19 by Danetta »

*

texus

  • *****
  • 1418
    • View Profile
    • Texus's Blog
Re: CPU-Heavy Scrolling
« Reply #19 on: 14 January 2017, 19:50:19 »
I really need to write a tutorial about how to write custom widgets some day, I didn't even understood why this went wrong until I saw the exact error.

You have to add the following in the declaration of your CustomPanelClass:
typedef std::shared_ptr<CustomPanel> Ptr;

*

texus

  • *****
  • 1418
    • View Profile
    • Texus's Blog
Re: CPU-Heavy Scrolling
« Reply #20 on: 18 January 2017, 15:11:53 »
Quote
Also, I noticed CPU-usage spikes even in idle
I've made a large internal change in 0.8-dev, hopefully what I changed is related to this and will have fixed it.

I can't reproduce the cpu lag though, not even with calling setPosition on every widget every time the scrollbar moves.
The scrollbar generates up to 30-50 events per seconds here when being moved and each of my 50 labels is moved when this happens.
The 570 fps I have during idle only goes down to 530 fps while scrolling.

But having a CustomPanelClass that doesn't call setPosition the whole time will of course perform better in any case.
« Last Edit: 18 January 2017, 15:23:09 by texus »