GuiBuilder: window to change properties of type Outline
parent
eb208ac4ad
commit
d97519d4f7
|
@ -44,6 +44,9 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
using PropertyValuePair = std::pair<std::string, std::pair<std::string, std::string>>;
|
||||||
|
using OnValueChangeFunc = std::function<void(const sf::String& value)>;
|
||||||
|
|
||||||
void loadStartScreen();
|
void loadStartScreen();
|
||||||
void loadEditingScreen(const std::string& filename);
|
void loadEditingScreen(const std::string& filename);
|
||||||
void loadToolbox();
|
void loadToolbox();
|
||||||
|
@ -52,7 +55,8 @@ private:
|
||||||
void copyWidget(std::shared_ptr<WidgetInfo> widgetInfo);
|
void copyWidget(std::shared_ptr<WidgetInfo> widgetInfo);
|
||||||
void updateWidgetProperty(const std::string& property, const std::string& value);
|
void updateWidgetProperty(const std::string& property, const std::string& value);
|
||||||
void initProperties();
|
void initProperties();
|
||||||
void addPropertyValueEditBoxes(float& topPosition, const std::pair<std::string, std::pair<std::string, std::string>>& propertyValuePair, const std::function<void(const sf::String& value)>& onChange);
|
tgui::EditBox::Ptr addPropertyValueEditBox(const std::string& property, const sf::String& value, const OnValueChangeFunc& onChange, float topPosition, float rightPadding);
|
||||||
|
void addPropertyValueWidgets(float& topPosition, const PropertyValuePair& propertyValuePair, const OnValueChangeFunc& onChange);
|
||||||
void changeWidgetName(const std::string& name);
|
void changeWidgetName(const std::string& name);
|
||||||
void initSelectedWidgetComboBoxAfterLoad();
|
void initSelectedWidgetComboBoxAfterLoad();
|
||||||
void removeSelectedWidget();
|
void removeSelectedWidget();
|
||||||
|
@ -60,6 +64,12 @@ private:
|
||||||
void menuBarItemClicked(const std::string& item);
|
void menuBarItemClicked(const std::string& item);
|
||||||
tgui::ChildWindow::Ptr openWindowWithFocus();
|
tgui::ChildWindow::Ptr openWindowWithFocus();
|
||||||
|
|
||||||
|
void addPropertyValueBool(const std::string& property, const sf::String& value, const OnValueChangeFunc& onChange, float topPosition);
|
||||||
|
void addPropertyValueColor(const std::string& property, const sf::String& value, const OnValueChangeFunc& onChange, float topPosition);
|
||||||
|
void addPropertyValueTextStyle(const std::string& property, const sf::String& value, const OnValueChangeFunc& onChange, float topPosition);
|
||||||
|
void addPropertyValueOutline(const std::string& property, const sf::String& value, const OnValueChangeFunc& onChange, float topPosition);
|
||||||
|
void addPropertyValueEnum(const std::string& property, const sf::String& value, const OnValueChangeFunc& onChange, float topPosition, const std::vector<std::string>& enumValues);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
std::string m_lastOpenedFile;
|
std::string m_lastOpenedFile;
|
||||||
|
|
|
@ -0,0 +1,100 @@
|
||||||
|
Renderer.1 {
|
||||||
|
backgroundcolor = #F5F5F5;
|
||||||
|
backgroundcolordisabled = #E6E6E6;
|
||||||
|
backgroundcolorhover = white;
|
||||||
|
bordercolor = #3C3C3C;
|
||||||
|
bordercolordisabled = #7D7D7D;
|
||||||
|
bordercolorhover = black;
|
||||||
|
borders = (1, 1, 1, 1);
|
||||||
|
caretcolor = black;
|
||||||
|
caretwidth = 1;
|
||||||
|
defaulttextcolor = #A0A0A0;
|
||||||
|
padding = (0, 0, 0, 0);
|
||||||
|
selectedtextbackgroundcolor = #006EFF;
|
||||||
|
selectedtextcolor = white;
|
||||||
|
textcolor = #3C3C3C;
|
||||||
|
textcolordisabled = #7D7D7D;
|
||||||
|
texture = None;
|
||||||
|
texturedisabled = None;
|
||||||
|
texturefocused = None;
|
||||||
|
texturehover = None;
|
||||||
|
}
|
||||||
|
|
||||||
|
Renderer.2 {
|
||||||
|
backgroundcolor = transparent;
|
||||||
|
bordercolor = #3C3C3C;
|
||||||
|
borders = (0, 0, 0, 0);
|
||||||
|
textcolor = #3C3C3C;
|
||||||
|
}
|
||||||
|
|
||||||
|
Label."Widget1" {
|
||||||
|
AutoSize = true;
|
||||||
|
Position = (20, 20);
|
||||||
|
ScrollbarPolicy = Never;
|
||||||
|
Size = (33.2, 18);
|
||||||
|
Text = "Left:";
|
||||||
|
TextSize = 13;
|
||||||
|
renderer = &2;
|
||||||
|
}
|
||||||
|
|
||||||
|
Label."Widget2" {
|
||||||
|
AutoSize = true;
|
||||||
|
Position = (20, 50);
|
||||||
|
ScrollbarPolicy = Never;
|
||||||
|
Size = (31.2, 18);
|
||||||
|
Text = "Top:";
|
||||||
|
TextSize = 13;
|
||||||
|
renderer = &2;
|
||||||
|
}
|
||||||
|
|
||||||
|
Label."Widget3" {
|
||||||
|
AutoSize = true;
|
||||||
|
Position = (20, 80);
|
||||||
|
ScrollbarPolicy = Never;
|
||||||
|
Size = (41.2, 18);
|
||||||
|
Text = "Right;";
|
||||||
|
TextSize = 13;
|
||||||
|
renderer = &2;
|
||||||
|
}
|
||||||
|
|
||||||
|
Label."Widget4" {
|
||||||
|
AutoSize = true;
|
||||||
|
Position = (20, 110);
|
||||||
|
ScrollbarPolicy = Never;
|
||||||
|
Size = (55.2, 18);
|
||||||
|
Text = "Bottom:";
|
||||||
|
TextSize = 13;
|
||||||
|
renderer = &2;
|
||||||
|
}
|
||||||
|
|
||||||
|
EditBox."EditLeft" {
|
||||||
|
InputValidator = "[0-9]*%?";
|
||||||
|
Position = (85, 17);
|
||||||
|
Size = (40, 22);
|
||||||
|
TextSize = 13;
|
||||||
|
renderer = &1;
|
||||||
|
}
|
||||||
|
|
||||||
|
EditBox."EditTop" {
|
||||||
|
InputValidator = "[0-9]*%?";
|
||||||
|
Position = (85, 47);
|
||||||
|
Size = (40, 22);
|
||||||
|
TextSize = 13;
|
||||||
|
renderer = &1;
|
||||||
|
}
|
||||||
|
|
||||||
|
EditBox."EditRight" {
|
||||||
|
InputValidator = "[0-9]*%?";
|
||||||
|
Position = (85, 77);
|
||||||
|
Size = (40, 22);
|
||||||
|
TextSize = 13;
|
||||||
|
renderer = &1;
|
||||||
|
}
|
||||||
|
|
||||||
|
EditBox."EditBottom" {
|
||||||
|
InputValidator = "[0-9]*%?";
|
||||||
|
Position = (85, 107);
|
||||||
|
Size = (40, 22);
|
||||||
|
TextSize = 13;
|
||||||
|
renderer = &1;
|
||||||
|
}
|
|
@ -319,7 +319,7 @@ void GuiBuilder::reloadProperties()
|
||||||
if (selectedWidget)
|
if (selectedWidget)
|
||||||
{
|
{
|
||||||
topPosition += 35;
|
topPosition += 35;
|
||||||
addPropertyValueEditBoxes(topPosition, {"Name", {"String", selectedWidget->name}},
|
addPropertyValueWidgets(topPosition, {"Name", {"String", selectedWidget->name}},
|
||||||
[=](const sf::String& value){
|
[=](const sf::String& value){
|
||||||
if (selectedWidget->name != value)
|
if (selectedWidget->name != value)
|
||||||
{
|
{
|
||||||
|
@ -332,7 +332,7 @@ void GuiBuilder::reloadProperties()
|
||||||
m_propertyValuePairs = m_widgetProperties.at(selectedWidget->ptr->getWidgetType())->initProperties(selectedWidget->ptr);
|
m_propertyValuePairs = m_widgetProperties.at(selectedWidget->ptr->getWidgetType())->initProperties(selectedWidget->ptr);
|
||||||
for (const auto& property : m_propertyValuePairs.first)
|
for (const auto& property : m_propertyValuePairs.first)
|
||||||
{
|
{
|
||||||
addPropertyValueEditBoxes(topPosition, property,
|
addPropertyValueWidgets(topPosition, property,
|
||||||
[=](const sf::String& value){
|
[=](const sf::String& value){
|
||||||
if (property.second.second != value)
|
if (property.second.second != value)
|
||||||
{
|
{
|
||||||
|
@ -351,7 +351,7 @@ void GuiBuilder::reloadProperties()
|
||||||
topPosition += rendererComboBox->getSize().y + 10;
|
topPosition += rendererComboBox->getSize().y + 10;
|
||||||
for (const auto& property : m_propertyValuePairs.second)
|
for (const auto& property : m_propertyValuePairs.second)
|
||||||
{
|
{
|
||||||
addPropertyValueEditBoxes(topPosition, property,
|
addPropertyValueWidgets(topPosition, property,
|
||||||
[=](const sf::String& value){
|
[=](const sf::String& value){
|
||||||
if (property.second.second != value)
|
if (property.second.second != value)
|
||||||
{
|
{
|
||||||
|
@ -371,7 +371,7 @@ void GuiBuilder::reloadProperties()
|
||||||
}
|
}
|
||||||
else // The form itself was selected
|
else // The form itself was selected
|
||||||
{
|
{
|
||||||
addPropertyValueEditBoxes(topPosition, {"Filename", {"String", m_selectedForm->getFilename()}},
|
addPropertyValueWidgets(topPosition, {"Filename", {"String", m_selectedForm->getFilename()}},
|
||||||
[=](const sf::String& value){
|
[=](const sf::String& value){
|
||||||
if (m_selectedForm->getFilename() != value)
|
if (m_selectedForm->getFilename() != value)
|
||||||
{
|
{
|
||||||
|
@ -381,7 +381,7 @@ void GuiBuilder::reloadProperties()
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
addPropertyValueEditBoxes(topPosition, {"Width", {"UInt", tgui::to_string(m_selectedForm->getSize().x)}},
|
addPropertyValueWidgets(topPosition, {"Width", {"UInt", tgui::to_string(m_selectedForm->getSize().x)}},
|
||||||
[=](const sf::String& value){
|
[=](const sf::String& value){
|
||||||
if (tgui::to_string(m_selectedForm->getSize().x) != value)
|
if (tgui::to_string(m_selectedForm->getSize().x) != value)
|
||||||
{
|
{
|
||||||
|
@ -390,7 +390,7 @@ void GuiBuilder::reloadProperties()
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
addPropertyValueEditBoxes(topPosition, {"Height", {"UInt", tgui::to_string(m_selectedForm->getSize().y)}},
|
addPropertyValueWidgets(topPosition, {"Height", {"UInt", tgui::to_string(m_selectedForm->getSize().y)}},
|
||||||
[=](const sf::String& value){
|
[=](const sf::String& value){
|
||||||
if (tgui::to_string(m_selectedForm->getSize().y) != value)
|
if (tgui::to_string(m_selectedForm->getSize().y) != value)
|
||||||
{
|
{
|
||||||
|
@ -493,7 +493,7 @@ void GuiBuilder::loadStartScreen()
|
||||||
m_selectedWidgetComboBox = nullptr;
|
m_selectedWidgetComboBox = nullptr;
|
||||||
|
|
||||||
m_gui.removeAllWidgets();
|
m_gui.removeAllWidgets();
|
||||||
m_gui.loadWidgetsFromFile("resources/StartScreen.txt");
|
m_gui.loadWidgetsFromFile("resources/forms/StartScreen.txt");
|
||||||
|
|
||||||
auto filenameEditBox = m_gui.get<tgui::Panel>("MainPanel")->get<tgui::EditBox>("FilenameEditBox");
|
auto filenameEditBox = m_gui.get<tgui::Panel>("MainPanel")->get<tgui::EditBox>("FilenameEditBox");
|
||||||
filenameEditBox->setText(m_lastOpenedFile);
|
filenameEditBox->setText(m_lastOpenedFile);
|
||||||
|
@ -510,7 +510,7 @@ void GuiBuilder::loadEditingScreen(const std::string& filename)
|
||||||
m_lastOpenedFile = filename;
|
m_lastOpenedFile = filename;
|
||||||
|
|
||||||
m_gui.removeAllWidgets();
|
m_gui.removeAllWidgets();
|
||||||
m_gui.loadWidgetsFromFile("resources/EditingScreen.txt");
|
m_gui.loadWidgetsFromFile("resources/forms/EditingScreen.txt");
|
||||||
|
|
||||||
m_forms.push_back(std::make_unique<Form>(this, filename, m_gui.get<tgui::ChildWindow>("Form")));
|
m_forms.push_back(std::make_unique<Form>(this, filename, m_gui.get<tgui::ChildWindow>("Form")));
|
||||||
m_selectedForm = m_forms[0].get();
|
m_selectedForm = m_forms[0].get();
|
||||||
|
@ -753,15 +753,10 @@ void GuiBuilder::initProperties()
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void GuiBuilder::addPropertyValueEditBoxes(float& topPosition, const std::pair<std::string, std::pair<std::string, std::string>>& propertyValuePair, const std::function<void(const sf::String& value)>& onChange)
|
tgui::EditBox::Ptr GuiBuilder::addPropertyValueEditBox(const std::string& property, const sf::String& value, const OnValueChangeFunc& onChange, float topPosition, float rightPadding)
|
||||||
{
|
{
|
||||||
const auto& property = propertyValuePair.first;
|
|
||||||
const auto& type = propertyValuePair.second.first;
|
|
||||||
const auto& value = propertyValuePair.second.second;
|
|
||||||
const float scrollbarWidth = m_propertiesContainer->getScrollbarWidth();
|
const float scrollbarWidth = m_propertiesContainer->getScrollbarWidth();
|
||||||
|
|
||||||
auto createValueEditBox = [&](float rightPadding)
|
|
||||||
{
|
|
||||||
auto valueEditBox = m_propertiesContainer->get<tgui::EditBox>("Value" + property);
|
auto valueEditBox = m_propertiesContainer->get<tgui::EditBox>("Value" + property);
|
||||||
if (!valueEditBox)
|
if (!valueEditBox)
|
||||||
{
|
{
|
||||||
|
@ -778,7 +773,16 @@ void GuiBuilder::addPropertyValueEditBoxes(float& topPosition, const std::pair<s
|
||||||
|
|
||||||
valueEditBox->connect({"ReturnKeyPressed", "Unfocused"}, [=]{ onChange(valueEditBox->getText()); });
|
valueEditBox->connect({"ReturnKeyPressed", "Unfocused"}, [=]{ onChange(valueEditBox->getText()); });
|
||||||
return valueEditBox;
|
return valueEditBox;
|
||||||
};
|
}
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
void GuiBuilder::addPropertyValueWidgets(float& topPosition, const PropertyValuePair& propertyValuePair, const OnValueChangeFunc& onChange)
|
||||||
|
{
|
||||||
|
const auto& property = propertyValuePair.first;
|
||||||
|
const auto& type = propertyValuePair.second.first;
|
||||||
|
const auto& value = propertyValuePair.second.second;
|
||||||
|
const float scrollbarWidth = m_propertiesContainer->getScrollbarWidth();
|
||||||
|
|
||||||
auto propertyEditBox = m_propertiesContainer->get<tgui::EditBox>("Property" + property);
|
auto propertyEditBox = m_propertiesContainer->get<tgui::EditBox>("Property" + property);
|
||||||
if (!propertyEditBox)
|
if (!propertyEditBox)
|
||||||
|
@ -794,137 +798,24 @@ void GuiBuilder::addPropertyValueEditBoxes(float& topPosition, const std::pair<s
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type == "Bool")
|
if (type == "Bool")
|
||||||
{
|
addPropertyValueBool(property, value, onChange, topPosition);
|
||||||
auto valueComboBox = m_propertiesContainer->get<tgui::ComboBox>("ValueComboBox" + property);
|
|
||||||
if (!valueComboBox)
|
|
||||||
{
|
|
||||||
valueComboBox = tgui::ComboBox::create();
|
|
||||||
valueComboBox->setExpandDirection(tgui::ComboBox::ExpandDirection::Automatic);
|
|
||||||
valueComboBox->addItem("False");
|
|
||||||
valueComboBox->addItem("True");
|
|
||||||
m_propertiesContainer->add(valueComboBox, "ValueComboBox" + property);
|
|
||||||
}
|
|
||||||
|
|
||||||
valueComboBox->disconnectAll("ItemSelected");
|
|
||||||
valueComboBox->setPosition({(bindWidth(m_propertiesContainer) - scrollbarWidth) / 2.f, topPosition});
|
|
||||||
valueComboBox->setSize({(bindWidth(m_propertiesContainer) - scrollbarWidth) / 2.f, EDIT_BOX_HEIGHT});
|
|
||||||
|
|
||||||
std::string str = tgui::toLower(value);
|
|
||||||
if (str == "true" || str == "yes" || str == "on" || str == "y" || str == "t" || str == "1")
|
|
||||||
valueComboBox->setSelectedItemByIndex(1);
|
|
||||||
else
|
|
||||||
valueComboBox->setSelectedItemByIndex(0);
|
|
||||||
|
|
||||||
valueComboBox->connect("ItemSelected", [=]{ onChange(valueComboBox->getSelectedItem()); });
|
|
||||||
}
|
|
||||||
else if (type == "Color")
|
else if (type == "Color")
|
||||||
{
|
addPropertyValueColor(property, value, onChange, topPosition);
|
||||||
auto transparentPicture = m_propertiesContainer->get<tgui::Picture>("ValueTransparentPicture" + property);
|
else if (type == "TextStyle")
|
||||||
auto colorPreviewPanel = m_propertiesContainer->get<tgui::Panel>("ValueColorPanel" + property);
|
addPropertyValueTextStyle(property, value, onChange, topPosition);
|
||||||
if (!transparentPicture)
|
else if (type == "Outline")
|
||||||
{
|
addPropertyValueOutline(property, value, onChange, topPosition);
|
||||||
transparentPicture = tgui::Picture::create("resources/Transparent.png");
|
|
||||||
m_propertiesContainer->add(transparentPicture, "ValueTransparentPicture" + property);
|
|
||||||
|
|
||||||
colorPreviewPanel = tgui::Panel::create();
|
|
||||||
colorPreviewPanel->getRenderer()->setBorders(1);
|
|
||||||
colorPreviewPanel->getRenderer()->setBorderColor(sf::Color::Black);
|
|
||||||
m_propertiesContainer->add(colorPreviewPanel, "ValueColorPanel" + property);
|
|
||||||
}
|
|
||||||
|
|
||||||
createValueEditBox(EDIT_BOX_HEIGHT - 1);
|
|
||||||
transparentPicture->setSize({EDIT_BOX_HEIGHT, EDIT_BOX_HEIGHT});
|
|
||||||
transparentPicture->setPosition({bindWidth(m_propertiesContainer) - scrollbarWidth - EDIT_BOX_HEIGHT, topPosition});
|
|
||||||
|
|
||||||
colorPreviewPanel->setSize({EDIT_BOX_HEIGHT, EDIT_BOX_HEIGHT});
|
|
||||||
colorPreviewPanel->setPosition({bindWidth(m_propertiesContainer) - scrollbarWidth - EDIT_BOX_HEIGHT, topPosition});
|
|
||||||
if (value != "None")
|
|
||||||
colorPreviewPanel->getRenderer()->setBackgroundColor(value);
|
|
||||||
else
|
|
||||||
colorPreviewPanel->getRenderer()->setBackgroundColor(sf::Color::Transparent);
|
|
||||||
}
|
|
||||||
else if (type.substr(0, 5) == "Enum{")
|
else if (type.substr(0, 5) == "Enum{")
|
||||||
{
|
{
|
||||||
std::vector<std::string> enumValues = tgui::Deserializer::split(type.substr(5, type.size() - 6), ',');
|
const std::vector<std::string> enumValues = tgui::Deserializer::split(type.substr(5, type.size() - 6), ',');
|
||||||
|
addPropertyValueEnum(property, value, onChange, topPosition, enumValues);
|
||||||
auto valueComboBox = m_propertiesContainer->get<tgui::ComboBox>("ValueComboBox" + property);
|
|
||||||
if (!valueComboBox)
|
|
||||||
{
|
|
||||||
valueComboBox = tgui::ComboBox::create();
|
|
||||||
valueComboBox->setExpandDirection(tgui::ComboBox::ExpandDirection::Automatic);
|
|
||||||
m_propertiesContainer->add(valueComboBox, "ValueComboBox" + property);
|
|
||||||
|
|
||||||
for (const auto& enumValue : enumValues)
|
|
||||||
valueComboBox->addItem(enumValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
valueComboBox->disconnectAll("ItemSelected");
|
|
||||||
valueComboBox->setPosition({(bindWidth(m_propertiesContainer) - scrollbarWidth) / 2.f, topPosition});
|
|
||||||
valueComboBox->setSize({(bindWidth(m_propertiesContainer) - scrollbarWidth) / 2.f, EDIT_BOX_HEIGHT});
|
|
||||||
|
|
||||||
std::string valueLower = tgui::toLower(value);
|
|
||||||
for (unsigned int i = 0; i < enumValues.size(); ++i)
|
|
||||||
{
|
|
||||||
if (tgui::toLower(enumValues[i]) == valueLower)
|
|
||||||
valueComboBox->setSelectedItemByIndex(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
valueComboBox->connect("ItemSelected", [=]{ onChange(valueComboBox->getSelectedItem()); });
|
|
||||||
}
|
|
||||||
else if (type == "TextStyle")
|
|
||||||
{
|
|
||||||
auto buttonMore = m_propertiesContainer->get<tgui::Button>("ValueButton" + property);
|
|
||||||
if (!buttonMore)
|
|
||||||
{
|
|
||||||
buttonMore = tgui::Button::create();
|
|
||||||
buttonMore->setText(L"\u22EF");
|
|
||||||
buttonMore->setTextSize(18);
|
|
||||||
m_propertiesContainer->add(buttonMore, "ValueButton" + property);
|
|
||||||
}
|
|
||||||
|
|
||||||
createValueEditBox(EDIT_BOX_HEIGHT - 1);
|
|
||||||
|
|
||||||
buttonMore->disconnectAll("pressed");
|
|
||||||
buttonMore->setSize({EDIT_BOX_HEIGHT, EDIT_BOX_HEIGHT});
|
|
||||||
buttonMore->setPosition({bindWidth(m_propertiesContainer) - scrollbarWidth - EDIT_BOX_HEIGHT, topPosition});
|
|
||||||
|
|
||||||
buttonMore->connect("pressed", [=]{
|
|
||||||
auto textStyleWindow = openWindowWithFocus();
|
|
||||||
textStyleWindow->setTitle("Choose text style");
|
|
||||||
textStyleWindow->setSize(180, 160);
|
|
||||||
textStyleWindow->loadWidgetsFromFile("resources/SelectTextStyleWindow.txt");
|
|
||||||
|
|
||||||
auto checkBoxBold = textStyleWindow->get<tgui::CheckBox>("CheckBoxBold");
|
|
||||||
auto checkBoxItalic = textStyleWindow->get<tgui::CheckBox>("CheckBoxItalic");
|
|
||||||
auto checkBoxUnderlined = textStyleWindow->get<tgui::CheckBox>("CheckBoxUnderlined");
|
|
||||||
auto checkBoxStrikeThrough = textStyleWindow->get<tgui::CheckBox>("CheckBoxStrikeThrough");
|
|
||||||
|
|
||||||
unsigned int style = tgui::Deserializer::deserialize(tgui::ObjectConverter::Type::TextStyle, value).getTextStyle();
|
|
||||||
checkBoxBold->setChecked(style & sf::Text::Style::Bold);
|
|
||||||
checkBoxItalic->setChecked(style & sf::Text::Style::Italic);
|
|
||||||
checkBoxUnderlined->setChecked(style & sf::Text::Style::Underlined);
|
|
||||||
checkBoxStrikeThrough->setChecked(style & sf::Text::Style::StrikeThrough);
|
|
||||||
|
|
||||||
auto updateTextStyleProperty = [=]{
|
|
||||||
unsigned int newStyle = 0;
|
|
||||||
newStyle |= (checkBoxBold->isChecked() ? sf::Text::Style::Bold : 0);
|
|
||||||
newStyle |= (checkBoxItalic->isChecked() ? sf::Text::Style::Italic : 0);
|
|
||||||
newStyle |= (checkBoxUnderlined->isChecked() ? sf::Text::Style::Underlined : 0);
|
|
||||||
newStyle |= (checkBoxStrikeThrough->isChecked() ? sf::Text::Style::StrikeThrough : 0);
|
|
||||||
updateWidgetProperty(property, tgui::Serializer::serialize(tgui::TextStyle{newStyle}));
|
|
||||||
};
|
|
||||||
checkBoxBold->connect("changed", updateTextStyleProperty);
|
|
||||||
checkBoxItalic->connect("changed", updateTextStyleProperty);
|
|
||||||
checkBoxUnderlined->connect("changed", updateTextStyleProperty);
|
|
||||||
checkBoxStrikeThrough->connect("changed", updateTextStyleProperty);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const bool valueEditBoxExists = (m_propertiesContainer->get<tgui::EditBox>("Value" + property) != nullptr);
|
const bool valueEditBoxExists = (m_propertiesContainer->get<tgui::EditBox>("Value" + property) != nullptr);
|
||||||
auto valueEditBox = createValueEditBox(0);
|
auto valueEditBox = addPropertyValueEditBox(property, value, onChange, topPosition, 0);
|
||||||
|
|
||||||
if (valueEditBoxExists)
|
if (!valueEditBoxExists)
|
||||||
{
|
{
|
||||||
if (type == "UInt")
|
if (type == "UInt")
|
||||||
valueEditBox->setInputValidator(tgui::EditBox::Validator::UInt);
|
valueEditBox->setInputValidator(tgui::EditBox::Validator::UInt);
|
||||||
|
@ -1039,7 +930,7 @@ void GuiBuilder::menuBarItemClicked(const std::string& menuItem)
|
||||||
auto editThemesWindow = openWindowWithFocus();
|
auto editThemesWindow = openWindowWithFocus();
|
||||||
editThemesWindow->setTitle("Edit themes");
|
editThemesWindow->setTitle("Edit themes");
|
||||||
editThemesWindow->setSize({320, 280});
|
editThemesWindow->setSize({320, 280});
|
||||||
editThemesWindow->loadWidgetsFromFile("resources/EditThemesWindow.txt");
|
editThemesWindow->loadWidgetsFromFile("resources/forms/EditThemes.txt");
|
||||||
|
|
||||||
auto buttonAdd = editThemesWindow->get<tgui::Button>("ButtonAdd");
|
auto buttonAdd = editThemesWindow->get<tgui::Button>("ButtonAdd");
|
||||||
auto buttonDelete = editThemesWindow->get<tgui::Button>("ButtonDelete");
|
auto buttonDelete = editThemesWindow->get<tgui::Button>("ButtonDelete");
|
||||||
|
@ -1124,3 +1015,201 @@ tgui::ChildWindow::Ptr GuiBuilder::openWindowWithFocus()
|
||||||
|
|
||||||
return window;
|
return window;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
void GuiBuilder::addPropertyValueBool(const std::string& property, const sf::String& value, const OnValueChangeFunc& onChange, float topPosition)
|
||||||
|
{
|
||||||
|
const float scrollbarWidth = m_propertiesContainer->getScrollbarWidth();
|
||||||
|
|
||||||
|
auto valueComboBox = m_propertiesContainer->get<tgui::ComboBox>("ValueComboBox" + property);
|
||||||
|
if (!valueComboBox)
|
||||||
|
{
|
||||||
|
valueComboBox = tgui::ComboBox::create();
|
||||||
|
valueComboBox->setExpandDirection(tgui::ComboBox::ExpandDirection::Automatic);
|
||||||
|
valueComboBox->addItem("False");
|
||||||
|
valueComboBox->addItem("True");
|
||||||
|
m_propertiesContainer->add(valueComboBox, "ValueComboBox" + property);
|
||||||
|
}
|
||||||
|
|
||||||
|
valueComboBox->disconnectAll("ItemSelected");
|
||||||
|
valueComboBox->setPosition({(bindWidth(m_propertiesContainer) - scrollbarWidth) / 2.f, topPosition});
|
||||||
|
valueComboBox->setSize({(bindWidth(m_propertiesContainer) - scrollbarWidth) / 2.f, EDIT_BOX_HEIGHT});
|
||||||
|
|
||||||
|
std::string str = tgui::toLower(value);
|
||||||
|
if (str == "true" || str == "yes" || str == "on" || str == "y" || str == "t" || str == "1")
|
||||||
|
valueComboBox->setSelectedItemByIndex(1);
|
||||||
|
else
|
||||||
|
valueComboBox->setSelectedItemByIndex(0);
|
||||||
|
|
||||||
|
valueComboBox->connect("ItemSelected", [=]{ onChange(valueComboBox->getSelectedItem()); });
|
||||||
|
}
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
void GuiBuilder::addPropertyValueColor(const std::string& property, const sf::String& value, const OnValueChangeFunc& onChange, float topPosition)
|
||||||
|
{
|
||||||
|
const float scrollbarWidth = m_propertiesContainer->getScrollbarWidth();
|
||||||
|
|
||||||
|
auto transparentPicture = m_propertiesContainer->get<tgui::Picture>("ValueTransparentPicture" + property);
|
||||||
|
auto colorPreviewPanel = m_propertiesContainer->get<tgui::Panel>("ValueColorPanel" + property);
|
||||||
|
if (!transparentPicture)
|
||||||
|
{
|
||||||
|
transparentPicture = tgui::Picture::create("resources/Transparent.png");
|
||||||
|
m_propertiesContainer->add(transparentPicture, "ValueTransparentPicture" + property);
|
||||||
|
|
||||||
|
colorPreviewPanel = tgui::Panel::create();
|
||||||
|
colorPreviewPanel->getRenderer()->setBorders(1);
|
||||||
|
colorPreviewPanel->getRenderer()->setBorderColor(sf::Color::Black);
|
||||||
|
m_propertiesContainer->add(colorPreviewPanel, "ValueColorPanel" + property);
|
||||||
|
}
|
||||||
|
|
||||||
|
addPropertyValueEditBox(property, value, onChange, topPosition, EDIT_BOX_HEIGHT - 1);
|
||||||
|
transparentPicture->setSize({EDIT_BOX_HEIGHT, EDIT_BOX_HEIGHT});
|
||||||
|
transparentPicture->setPosition({bindWidth(m_propertiesContainer) - scrollbarWidth - EDIT_BOX_HEIGHT, topPosition});
|
||||||
|
|
||||||
|
colorPreviewPanel->setSize({EDIT_BOX_HEIGHT, EDIT_BOX_HEIGHT});
|
||||||
|
colorPreviewPanel->setPosition({bindWidth(m_propertiesContainer) - scrollbarWidth - EDIT_BOX_HEIGHT, topPosition});
|
||||||
|
if (value != "None")
|
||||||
|
colorPreviewPanel->getRenderer()->setBackgroundColor(value);
|
||||||
|
else
|
||||||
|
colorPreviewPanel->getRenderer()->setBackgroundColor(sf::Color::Transparent);
|
||||||
|
}
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
void GuiBuilder::addPropertyValueTextStyle(const std::string& property, const sf::String& value, const OnValueChangeFunc& onChange, float topPosition)
|
||||||
|
{
|
||||||
|
const float scrollbarWidth = m_propertiesContainer->getScrollbarWidth();
|
||||||
|
|
||||||
|
auto buttonMore = m_propertiesContainer->get<tgui::Button>("ValueButton" + property);
|
||||||
|
if (!buttonMore)
|
||||||
|
{
|
||||||
|
buttonMore = tgui::Button::create();
|
||||||
|
buttonMore->setText(L"\u22EF");
|
||||||
|
buttonMore->setTextSize(18);
|
||||||
|
m_propertiesContainer->add(buttonMore, "ValueButton" + property);
|
||||||
|
}
|
||||||
|
|
||||||
|
addPropertyValueEditBox(property, value, onChange, topPosition, EDIT_BOX_HEIGHT - 1);
|
||||||
|
|
||||||
|
buttonMore->disconnectAll("pressed");
|
||||||
|
buttonMore->setSize({EDIT_BOX_HEIGHT, EDIT_BOX_HEIGHT});
|
||||||
|
buttonMore->setPosition({bindWidth(m_propertiesContainer) - scrollbarWidth - EDIT_BOX_HEIGHT, topPosition});
|
||||||
|
|
||||||
|
buttonMore->connect("pressed", [=]{
|
||||||
|
auto textStyleWindow = openWindowWithFocus();
|
||||||
|
textStyleWindow->setTitle("Set text style");
|
||||||
|
textStyleWindow->setSize(180, 160);
|
||||||
|
textStyleWindow->loadWidgetsFromFile("resources/forms/SetTextStyle.txt");
|
||||||
|
|
||||||
|
auto checkBoxBold = textStyleWindow->get<tgui::CheckBox>("CheckBoxBold");
|
||||||
|
auto checkBoxItalic = textStyleWindow->get<tgui::CheckBox>("CheckBoxItalic");
|
||||||
|
auto checkBoxUnderlined = textStyleWindow->get<tgui::CheckBox>("CheckBoxUnderlined");
|
||||||
|
auto checkBoxStrikeThrough = textStyleWindow->get<tgui::CheckBox>("CheckBoxStrikeThrough");
|
||||||
|
|
||||||
|
unsigned int style = tgui::Deserializer::deserialize(tgui::ObjectConverter::Type::TextStyle, value).getTextStyle();
|
||||||
|
checkBoxBold->setChecked(style & sf::Text::Style::Bold);
|
||||||
|
checkBoxItalic->setChecked(style & sf::Text::Style::Italic);
|
||||||
|
checkBoxUnderlined->setChecked(style & sf::Text::Style::Underlined);
|
||||||
|
checkBoxStrikeThrough->setChecked(style & sf::Text::Style::StrikeThrough);
|
||||||
|
|
||||||
|
auto updateTextStyleProperty = [=]{
|
||||||
|
unsigned int newStyle = 0;
|
||||||
|
newStyle |= (checkBoxBold->isChecked() ? sf::Text::Style::Bold : 0);
|
||||||
|
newStyle |= (checkBoxItalic->isChecked() ? sf::Text::Style::Italic : 0);
|
||||||
|
newStyle |= (checkBoxUnderlined->isChecked() ? sf::Text::Style::Underlined : 0);
|
||||||
|
newStyle |= (checkBoxStrikeThrough->isChecked() ? sf::Text::Style::StrikeThrough : 0);
|
||||||
|
updateWidgetProperty(property, tgui::Serializer::serialize(tgui::TextStyle{newStyle}));
|
||||||
|
};
|
||||||
|
checkBoxBold->connect("changed", updateTextStyleProperty);
|
||||||
|
checkBoxItalic->connect("changed", updateTextStyleProperty);
|
||||||
|
checkBoxUnderlined->connect("changed", updateTextStyleProperty);
|
||||||
|
checkBoxStrikeThrough->connect("changed", updateTextStyleProperty);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
void GuiBuilder::addPropertyValueOutline(const std::string& property, const sf::String& value, const OnValueChangeFunc& onChange, float topPosition)
|
||||||
|
{
|
||||||
|
const float scrollbarWidth = m_propertiesContainer->getScrollbarWidth();
|
||||||
|
|
||||||
|
auto buttonMore = m_propertiesContainer->get<tgui::Button>("ValueButton" + property);
|
||||||
|
if (!buttonMore)
|
||||||
|
{
|
||||||
|
buttonMore = tgui::Button::create();
|
||||||
|
buttonMore->setText(L"\u22EF");
|
||||||
|
buttonMore->setTextSize(18);
|
||||||
|
m_propertiesContainer->add(buttonMore, "ValueButton" + property);
|
||||||
|
}
|
||||||
|
|
||||||
|
addPropertyValueEditBox(property, value, onChange, topPosition, EDIT_BOX_HEIGHT - 1);
|
||||||
|
|
||||||
|
buttonMore->disconnectAll("pressed");
|
||||||
|
buttonMore->setSize({EDIT_BOX_HEIGHT, EDIT_BOX_HEIGHT});
|
||||||
|
buttonMore->setPosition({bindWidth(m_propertiesContainer) - scrollbarWidth - EDIT_BOX_HEIGHT, topPosition});
|
||||||
|
|
||||||
|
buttonMore->connect("pressed", [=]{
|
||||||
|
auto outlineWindow = openWindowWithFocus();
|
||||||
|
outlineWindow->setTitle("Set outline");
|
||||||
|
outlineWindow->setSize(150, 150);
|
||||||
|
outlineWindow->loadWidgetsFromFile("resources/forms/SetOutline.txt");
|
||||||
|
|
||||||
|
auto editLeft = outlineWindow->get<tgui::EditBox>("EditLeft");
|
||||||
|
auto editTop = outlineWindow->get<tgui::EditBox>("EditTop");
|
||||||
|
auto editRight = outlineWindow->get<tgui::EditBox>("EditRight");
|
||||||
|
auto editBottom = outlineWindow->get<tgui::EditBox>("EditBottom");
|
||||||
|
|
||||||
|
tgui::Outline outline = tgui::Deserializer::deserialize(tgui::ObjectConverter::Type::Outline, value).getOutline();
|
||||||
|
editLeft->setText(tgui::to_string(outline.getLeft()));
|
||||||
|
editTop->setText(tgui::to_string(outline.getTop()));
|
||||||
|
editRight->setText(tgui::to_string(outline.getRight()));
|
||||||
|
editBottom->setText(tgui::to_string(outline.getBottom()));
|
||||||
|
|
||||||
|
auto updateOutlineProperty = [=]{
|
||||||
|
const tgui::Outline newOutline{
|
||||||
|
tgui::AbsoluteOrRelativeValue{editLeft->getText()},
|
||||||
|
tgui::AbsoluteOrRelativeValue{editTop->getText()},
|
||||||
|
tgui::AbsoluteOrRelativeValue{editRight->getText()},
|
||||||
|
tgui::AbsoluteOrRelativeValue{editBottom->getText()},
|
||||||
|
};
|
||||||
|
updateWidgetProperty(property, tgui::Serializer::serialize(newOutline));
|
||||||
|
};
|
||||||
|
editLeft->connect({"ReturnKeyPressed", "Unfocused"}, updateOutlineProperty);
|
||||||
|
editTop->connect({"ReturnKeyPressed", "Unfocused"}, updateOutlineProperty);
|
||||||
|
editRight->connect({"ReturnKeyPressed", "Unfocused"}, updateOutlineProperty);
|
||||||
|
editBottom->connect({"ReturnKeyPressed", "Unfocused"}, updateOutlineProperty);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
void GuiBuilder::addPropertyValueEnum(const std::string& property, const sf::String& value, const OnValueChangeFunc& onChange, float topPosition, const std::vector<std::string>& enumValues)
|
||||||
|
{
|
||||||
|
const float scrollbarWidth = m_propertiesContainer->getScrollbarWidth();
|
||||||
|
|
||||||
|
auto valueComboBox = m_propertiesContainer->get<tgui::ComboBox>("ValueComboBox" + property);
|
||||||
|
if (!valueComboBox)
|
||||||
|
{
|
||||||
|
valueComboBox = tgui::ComboBox::create();
|
||||||
|
valueComboBox->setExpandDirection(tgui::ComboBox::ExpandDirection::Automatic);
|
||||||
|
m_propertiesContainer->add(valueComboBox, "ValueComboBox" + property);
|
||||||
|
|
||||||
|
for (const auto& enumValue : enumValues)
|
||||||
|
valueComboBox->addItem(enumValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
valueComboBox->disconnectAll("ItemSelected");
|
||||||
|
valueComboBox->setPosition({(bindWidth(m_propertiesContainer) - scrollbarWidth) / 2.f, topPosition});
|
||||||
|
valueComboBox->setSize({(bindWidth(m_propertiesContainer) - scrollbarWidth) / 2.f, EDIT_BOX_HEIGHT});
|
||||||
|
|
||||||
|
std::string valueLower = tgui::toLower(value);
|
||||||
|
for (unsigned int i = 0; i < enumValues.size(); ++i)
|
||||||
|
{
|
||||||
|
if (tgui::toLower(enumValues[i]) == valueLower)
|
||||||
|
valueComboBox->setSelectedItemByIndex(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
valueComboBox->connect("ItemSelected", [=]{ onChange(valueComboBox->getSelectedItem()); });
|
||||||
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
|
|
||||||
#include <TGUI/Config.hpp>
|
#include <TGUI/Config.hpp>
|
||||||
#include <SFML/Graphics/Color.hpp>
|
#include <SFML/Graphics/Color.hpp>
|
||||||
|
#include <SFML/System/String.hpp>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
@ -97,6 +98,16 @@ namespace tgui
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief Creates the object from a string
|
||||||
|
///
|
||||||
|
/// @param string String to be deserialized as color
|
||||||
|
///
|
||||||
|
/// The Deserializer class is used to convert the string into a color.
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
Color(const sf::String& string);
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief Creates the object from a string
|
/// @brief Creates the object from a string
|
||||||
///
|
///
|
||||||
|
|
|
@ -57,15 +57,22 @@ namespace tgui
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
Color::Color(const std::string& string) :
|
Color::Color(const sf::String& string) :
|
||||||
Color{Deserializer::deserialize(ObjectConverter::Type::Color, string).getColor()}
|
Color{Deserializer::deserialize(ObjectConverter::Type::Color, string).getColor()}
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Color::Color(const std::string& string) :
|
||||||
|
Color{sf::String{string}}
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
Color::Color(const char* string) :
|
Color::Color(const char* string) :
|
||||||
Color{std::string{string}}
|
Color{sf::String{string}}
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,4 +38,5 @@ TEST_CASE("[Color]")
|
||||||
REQUIRE(sf::Color(tgui::Color("#10204080")) == color);
|
REQUIRE(sf::Color(tgui::Color("#10204080")) == color);
|
||||||
REQUIRE(sf::Color(tgui::Color(std::string("#10204080"))) == color);
|
REQUIRE(sf::Color(tgui::Color(std::string("#10204080"))) == color);
|
||||||
REQUIRE(sf::Color(tgui::Color(std::string("Red"))) == sf::Color::Red);
|
REQUIRE(sf::Color(tgui::Color(std::string("Red"))) == sf::Color::Red);
|
||||||
|
REQUIRE(sf::Color(tgui::Color(sf::String("blue"))) == sf::Color::Blue);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue