tgui::Texture tguiPicture;
tguiPicture.loadFromPixelData(sfPicture.getSize(), sfPicture.copyToImage().getPixelsPtr());
auto picture = tgui::Picture::create(std::move(tguiPicture));
Do I have it correct that if my texture manager using sf::Texture to store all textures, than there is no way to avoid copies from sf::Texture to tgui::Texture?QuoteThe way draggable widgets are implemented has been changed. No functionality was changed, so if you didn't write custom widgets then you don't need to care.
Draggable widgets are widgets that still receive mouse move events even when the mouse is no longer on top of them. For example, once you start dragging the thumb of a scrollbar, you can move the mouse outside the scrollbar and the thumb will continue to move up and down with the mouse.
Previously all widgets that needed such behavior would set a boolean flag in their constructor. Due to the way it was implemented, Container and all classes inheriting from it needed to be draggable as well. Custom widgets inheriting from SubwidgetContainer would act as draggable widgets (i.e. they receive no onMouseLeave callback while the left mouse button is pressed), whether they wanted this or not. In the new implementation, leftMousePressed will return a boolean based on whether the click initiated a potention drag or not.
Several breaking API changes were made to the Widget base class:
- isDraggableWidget() function and m_draggableWidget member have been removed
- Return type of leftMousePressed was changed from void to bool. True may be returned by draggable widgets, all other widgets will always return false.
- mousePressed function was removed (the function only existed for backwards-compatibility anyway, it called either leftMousePressed or rightMousePressed depending on the mouse button)
m_label->setAutoSize(true);
m_label->setPosition("50%", tgui::bindWidth(m_group)*padding);
m_group->setSize("25%", tgui::bindBottom(lastPtr)+tgui::bindWidth(m_group)*padding);
assert(m_group);
tgui::Widget::Ptr lastPtr = nullptr;
//between 0 and 1, %
float padding = 0.05f;
auto layoutVisuStack = [this, &lastPtr, padding](std::vector<C_RecipeProcessing::ItemStackVisu> &listVisu){
if(listVisu.size()){
auto groupItem = tgui::Group::create();
if(lastPtr)
groupItem->setPosition(0,tgui::bindBottom(lastPtr)+tgui::bindWidth(groupItem)*padding);
else
groupItem->setPosition(0,tgui::bindWidth(groupItem)*padding);
auto nbInt = (int)listVisu.size();
auto nbDiv = std::max(3,nbInt);
auto l = (tgui::bindWidth(groupItem)-(tgui::bindWidth(groupItem)*padding*(nbInt+1)))/nbDiv;
groupItem->setSize("100%", l);
for(auto i=0;i<listVisu.size();i++){
auto itemWidget = PictureTextWidget::create(PictureText::fromItemStack(listVisu[i].itemStack));
itemWidget->setOrigin(0.5f,0.f);
itemWidget->setSize(l,l);
itemWidget->setPosition(tgui::bindWidth(groupItem)/(nbInt+1) * (i+1),0);
groupItem->add(itemWidget);
listVisu[i].itemStackWidget = itemWidget;
}
m_group->add(groupItem);
lastPtr = groupItem;
}
};
//inputs
layoutVisuStack(m_inputs);
//middle
m_label = tgui::Label::create();
m_label->setRenderer(TextureLoader::getTheme().getRenderer("LabelInfoWindow"));
m_label->setAutoSize(true);
m_label->setOrigin(0.5f, 0.f);
if(lastPtr)
m_label->setPosition("50%", tgui::bindBottom(lastPtr)+tgui::bindWidth(m_group)*padding);
else
m_label->setPosition("50%", tgui::bindWidth(m_group)*padding);
m_group->add(m_label);
lastPtr = m_label;
if(m_recipe){
m_panelRecipe = getGUI(m_recipe);
m_panelRecipe->setWidth(tgui::bindWidth(m_group)*0.8);
}
//WARNING
m_timeProgressBar = TimeProgressBar::create();
m_timeProgressBar->setOrigin(0.5f, 0.f);
m_timeProgressBar->setPosition("50%", tgui::bindBottom(m_label));
m_timeProgressBar->setSize("90%", 40);
m_group->add(m_timeProgressBar);
lastPtr = m_timeProgressBar;
//NO WARNING
auto test = tgui::ProgressBar::create();
test->setOrigin(0.5f, 0.f);
test->setPosition("50%", tgui::bindBottom(m_label));
test->setSize("90%", 40);
m_group->add(test);
lastPtr = test;
//outputs
layoutVisuStack(m_outputs);
if(lastPtr)
m_group->setSize("25%", tgui::bindBottom(lastPtr)+tgui::bindWidth(m_group)*padding);
else
m_group->setSize("25%", 0);
updateGUI();
std::cout << m_timeProgressBar->getPositionLayout().toString() << std::endl;
std::cout << m_timeProgressBar->getSizeLayout().toString() << std::endl;
QuoteTGUI warning: Dependency cycle detected in layout!with this layout:
m_timeProgressBar = TimeProgressBar::create();
m_timeProgressBar->setOrigin(0.5f, 0.f);
m_timeProgressBar->setPosition("50%", tgui::bindBottom(m_label));
m_timeProgressBar->setSize("90%", 40);
m_group->add(m_timeProgressBar);
The warning is caused by the line m_timeProgressBar->setPosition("50%", tgui::bindBottom(m_label));
If I comment it, everything is fine. auto test = tgui::ProgressBar::create();
test->setOrigin(0.5f, 0.f);
test->setPosition("50%", tgui::bindBottom(m_label));
test->setSize("90%", 40);
m_group->add(test);
#pragma once
#include "../../../Utils/utils.hpp"
class TimeProgressBar : public tgui::ProgressBar
{
public:
// Add a Ptr typedef so that "MyCustomWidget::Ptr" has the correct type
typedef std::shared_ptr<TimeProgressBar> Ptr;
typedef std::shared_ptr<const TimeProgressBar> ConstPtr;
TimeProgressBar();
static TimeProgressBar::Ptr create();
static TimeProgressBar::Ptr copy(TimeProgressBar::ConstPtr widget);
/**
* @brief Set the Percentage, between 0 and 1 or will be truncated
*
* @param percentage between 0 and 1
*/
void setPercentage(float percentage);
/**
* @brief Set the Current Time, between 0 and maxTime or will be clamped
*
* @param time between 0 and maxTime
*/
void setCurrentTime(sf::Time time);
void setMaxTime(sf::Time time);
void setReverse(bool act);
private:
Widget::Ptr clone() const override;
void updateText();
void updateValue();
/**
* @brief the time is display with raw value currentTime / timeMax
*/
bool m_rawValue;
/**
* @brief time will start from 0 to maxTime, or maxTime to 0
*/
bool m_reverse;
sf::Time m_currentTime;
sf::Time m_maxTime;
};