#include "DemoApp.hpp"
DemoApp::DemoApp(sf::RenderWindow& window) :
rw(window) {
FontManager::set(S::path::font::inconsolata, S::font::inconsolata,true);
FontManager::set(S::path::font::oxygen, S::font::oxygen);
FontManager::set(S::path::font::sansation, S::font::sansation);
TextureManager::load(S::texture::flare, S::path::texture::flare);
TextureManager::load(S::texture::wood, S::path::texture::wood);
TextureManager::load(S::texture::input, S::path::texture::input, true);
GUIManager::setMaxTooltipWidth(1000.f);
exampleBool1 = false;
showFps = true;
fpsLabelUpdate = 100.f;
initMainTabbed();
initElementsTab();
initDialogsTab();
initPanelModelsTab();
initPanelTabbedTab();
initOptionsTab();
}
DemoApp::~DemoApp() {
Configurator::save();
}
void DemoApp::events() {
sf::Event e;
while(rw.pollEvent(e)) {
defaultEventsHandle(e,rw);
switch(e.type) {
default:
break;
case sf::Event::KeyPressed:
switch(e.key.code) {
default:
break;
case sf::Keyboard::F12:
if(GUIInspector::isOpen()) {
GUIInspector::close();
} else {
GUIInspector::open();
GUIInspector::inspect(&mainPanel);
}
break;
}
break;
}
}
}
void DemoApp::update() {
mainPanel.
fitToWindow(rw);
mainPanel.
mainUpdate(rw);
if(showFps) {
fpsLabelUpdate += GlobalTimer::dtime;
if(fpsLabelUpdate > 0.5f) {
std::stringstream ss;
ss << std::fixed << std::setprecision(2) << GlobalTimer::fps;
fpsLabelUpdate = 0.f;
fpsLabel->setText(ss.str());
}
} else {
fpsLabel->setText("");
}
}
void DemoApp::draw() {
}
void DemoApp::initMainTabbed() {
mainPanel.
setName(
"mainPanel");
mainTabbed = std::make_shared<PanelTabbed>();
mainTabbed->setName("mainTabbed");
mainTabbed->addTab(S::tab::elements);
mainTabbed->addTab(S::tab::dialogs);
mainTabbed->addTab(S::tab::panelModels);
mainTabbed->addTab(S::tab::panelTabbed);
mainTabbed->addTab(S::tab::options);
mainPanel.
add(mainTabbed);
fpsLabel = std::make_shared<TextLabel>(S::label::fps, true);
fpsLabel->setColor(ColorId::FontFill, StateId::Default, sf::Color::Yellow);
fpsLabel->setColor(ColorId::FontOutline, StateId::Default, sf::Color::Black);
fpsLabel->setFontOutlineSize(2.f);
fpsLabel->setFontSize(24);
fpsLabel->setFontStyle(sf::Text::Bold);
fpsLabel->setAlign(Align::Right);
fpsLabel->setMaximized(true);
fpsLabel->setMaximizationMode(MaximizationMode::Horizontal);
}
void DemoApp::initElementsTab() {
elementsSplitted = std::make_shared<PanelSplitted>();
elementsSplitted->setName("elementsSplitted");
elementsSplitted->setOrientation(Orientation::Vertical);
mainTabbed->addToTab(S::tab::elements, elementsSplitted);
elementsLeftSplitted = std::make_shared<PanelSplittedScrolled>();
elementsLeftSplitted->setName("elementsLeftSplitted");
elementsLeftSplitted->setModelFirst(
PanelModelLine::create(
Orientation::Vertical,
Align::Center,
VAlign::Middle,
10.f,
MarginMode::Vertical
)
);
elementsLeftSplitted->setModelSecond(PanelModelList::create(32.f));
elementsLeftSplitted->getFirst().setTooltip(S::text::defaultElements);
elementsLeftSplitted->getSecond().setTooltip(S::text::customizedElements);
elementsSplitted->addToFirst(elementsLeftSplitted);
elementsRightSplitted = std::make_shared<PanelSplittedScrolled>();
elementsRightSplitted->setName("elementsRightSplitted");
elementsRightSplitted->setModelFirst(PanelModelGrid::create(2, 2));
elementsSplitted->addToSecond(elementsRightSplitted);
initFirstElements();
initSecondElements();
initThirdElements();
initFourthElements();
}
void DemoApp::initDialogInfo() {
auto btn = std::make_shared<Button>(S::button::dialogInfo,[this] {
auto dlg = std::make_shared<DialogInfo>(S::dialog::info);
GUIManager::addDialog(dlg);
dlg->getButton()->setAction([dlg,
this](
const Button& b) {
dlg->close();
info->setText(dlg->getName()+
": "+b.
getName());
});
});
btn->setSize({350, 50});
mainTabbed->addToTab(S::tab::dialogs, btn);
}
void DemoApp::initDialogInput() {
auto btn = std::make_shared<Button>(S::button::dialogInput,[this] {
auto dlg = std::make_shared<DialogInput>(S::dialog::input);
GUIManager::addDialog(dlg);
dlg->getButtonOk()->setAction([dlg,
this](
const Button& b) {
dlg->close();
auto i = dlg->getInput()->getText();
info->setText(dlg->getName()+": "+b.getName()+"\n"+i);
});
dlg->getButtonCancel()->setAction([dlg,
this](
const Button& b) {
dlg->close();
auto i = dlg->getInput()->getText();
info->setText(dlg->getName()+": "+b.getName()+"\n"+i);
});
});
btn->setSize({350, 50});
mainTabbed->addToTab(S::tab::dialogs, btn);
}
void DemoApp::InitDialogYesNo() {
auto btn = std::make_shared<Button>(S::button::dialogYesNo,[this] {
auto dlg = std::make_shared<DialogYesNo>(S::dialog::yesNo);
GUIManager::addDialog(dlg);
dlg->getButtonYes()->setAction([dlg,
this](
const Button& b) {
dlg->close();
info->setText(dlg->getName()+": "+b.getName());
});
dlg->getButtonNo()->setAction([dlg,
this](
const Button& b) {
dlg->close();
info->setText(dlg->getName()+": "+b.getName());
});
});
btn->setSize({350, 50});
mainTabbed->addToTab(S::tab::dialogs, btn);
}
void DemoApp::initDialogYesNoCancel() {
auto btn = std::make_shared<Button>(S::button::dialogYesNoCancel,[this] {
auto dlg = std::make_shared<DialogYesNoCancel>(S::dialog::yesNoCancel);
GUIManager::addDialog(dlg);
dlg->getButtonYes()->setAction([dlg,
this](
const Button& b) {
dlg->close();
info->setText(dlg->getName()+": "+b.getName());
});
dlg->getButtonNo()->setAction([dlg,
this](
const Button& b) {
dlg->close();
info->setText(dlg->getName()+": "+b.getName());
});
dlg->getButtonCancel()->setAction([dlg,
this](
const Button& b) {
dlg->close();
info->setText(dlg->getName()+": "+b.getName());
});
});
btn->setSize({350,50});
mainTabbed->addToTab(S::tab::dialogs, btn);
}
void DemoApp::initDialogCustom() {
auto btn = std::make_shared<Button>(S::button::dialogCustom,[this] {
info->setText("");
auto dlg = std::make_shared<Dialog>(S::dialog::custom);
GUIManager::addDialog(dlg);
dlg->setButtonShift(50.f);
sf::Color c(0, 100, 0);
auto& first = dlg->getPanel()->getFirst();
auto& second = dlg->getPanel()->getSecond();
first.setColor(ColorId::Background, StateId::Default, c);
second.setColor(ColorId::Background, StateId::Default, c);
first.setModel(
PanelModelLine::create(
Orientation::Vertical,
Align::Center,
VAlign::Middle,
10.f,
MarginMode::Vertical
)
);
auto i1 = std::make_shared<TextInput>();
i1->setSize({400.f,0.f});
auto i2 = std::make_shared<TextInput>();
i2->setSize({400.f,0.f});
auto i3 = std::make_shared<TextInput>();
i3->setSize({400.f,0.f});
first.add({i1,i2,i3});
second.setModel(PanelModelGrid::create(3, 1));
auto b1 = std::make_shared<Button>(S::button::custom1,[i1, dlg]{
auto ot = i1->getText();
auto nt = l(S::text::clickAgainToExit);
if(ot == nt) {
dlg->close();
}
i1->setText(nt);
});
auto b2 = std::make_shared<Button>(S::button::custom2, [i2, dlg]{
auto ot = i2->getText();
auto nt = l(S::text::clickAgainToExit);
if(ot == nt) {
dlg->close();
}
i2->setText(nt);
});
auto b3 = std::make_shared<Button>(S::button::custom3,[i3, dlg]{
auto ot = i3->getText();
auto nt = l(S::text::clickAgainToExit);
if(ot == nt) {
dlg->close();
}
i3->setText(nt);
});
second.add({b1, b2, b3});
});
btn->setSize({350, 50});
mainTabbed->addToTab(S::tab::dialogs, btn);
}
void DemoApp::initPanelModelLineHorizontal() {
auto& panel = modelsLeftSplitted->getFirst();
panel.setModel(PanelModelGrid::create(3, 3));
for(int va=0; va < 3; ++va) {
for(int a = 0; a < 3; ++a) {
auto p = std::make_shared<PanelScrolled>();
unsigned char val = 127+10*(va+1)*(a+1);
p->setColor(ColorId::Background, StateId::Default, sf::Color(val, val-10, val-10, 255));
p->setModel(
PanelModelLine::create(
Orientation::Horizontal,
static_cast<Align>(a),
static_cast<VAlign>(va),
10.f
)
);
for(size_t i = 1; i<=5; ++i) {
auto b = std::make_shared<Button>(std::to_string(i));
if(i<=3) {
b->setSize({30.f, 30.f+20.f*i});
} else {
b->setSize({30, 30+20.f*(6-i)});
}
p->add(b);
}
panel.add(p);
}
}
panel.updateArea();
auto elements = panel.getElements();
dynamic_cast<Panel*
>(elements[0].get())->setTooltip(
"PanelModelLine HORIZONTAL LEFT TOP");
dynamic_cast<Panel*
>(elements[1].get())->setTooltip(
"PanelModelLine HORIZONTAL CENTER TOP");
dynamic_cast<Panel*
>(elements[2].get())->setTooltip(
"PanelModelLine HORIZONTAL RIGHT TOP");
dynamic_cast<Panel*
>(elements[3].get())->setTooltip(
"PanelModelLine HORIZONTAL LEFT MIDDLE");
dynamic_cast<Panel*
>(elements[4].get())->setTooltip(
"PanelModelLine HORIZONTAL CENTER MIDDLE");
dynamic_cast<Panel*
>(elements[5].get())->setTooltip(
"PanelModelLine HORIZONTAL RIGHT MIDDLE");
dynamic_cast<Panel*
>(elements[6].get())->setTooltip(
"PanelModelLine HORIZONTAL LEFT BOTTOM");
dynamic_cast<Panel*
>(elements[7].get())->setTooltip(
"PanelModelLine HORIZONTAL CENTER BOTTOM");
dynamic_cast<Panel*
>(elements[8].get())->setTooltip(
"PanelModelLine HORIZONTAL RIGHT BOTTOM");
}
void DemoApp::initPanelModelLineVertical() {
auto& panel = modelsLeftSplitted->getSecond();
panel.setModel(PanelModelGrid::create(3, 3));
for(int va=0; va < 3; ++va) {
for(int a = 0; a < 3; ++a) {
auto p = std::make_shared<PanelScrolled>();
unsigned char val = 127+10*(va+1)*(a+1);
p->setColor(ColorId::Background, StateId::Default, sf::Color(val-10, val, val-10, 255));
p->setModel(
PanelModelLine::create(
Orientation::Vertical,
static_cast<Align>(a),
static_cast<VAlign>(va),
5.f
)
);
for(size_t i = 1; i<=3; ++i) {
auto b = std::make_shared<Button>(std::to_string(i));
if(i == 2) {
b->setSize({70.f, 30.f});
} else {
b->setSize({50.f, 30.f});
}
p->add(b);
}
panel.add(p);
}
}
panel.updateArea();
auto elements = panel.getElements();
dynamic_cast<Panel*
>(elements[0].get())->setTooltip(
"PanelModelLine VERTICAL LEFT TOP");
dynamic_cast<Panel*
>(elements[1].get())->setTooltip(
"PanelModelLine VERTICAL CENTER TOP");
dynamic_cast<Panel*
>(elements[2].get())->setTooltip(
"PanelModelLine VERTICAL RIGHT TOP");
dynamic_cast<Panel*
>(elements[3].get())->setTooltip(
"PanelModelLine VERTICAL LEFT MIDDLE");
dynamic_cast<Panel*
>(elements[4].get())->setTooltip(
"PanelModelLine VERTICAL CENTER MIDDLE");
dynamic_cast<Panel*
>(elements[5].get())->setTooltip(
"PanelModelLine VERTICAL RIGHT MIDDLE");
dynamic_cast<Panel*
>(elements[6].get())->setTooltip(
"PanelModelLine VERTICAL LEFT BOTTOM");
dynamic_cast<Panel*
>(elements[7].get())->setTooltip(
"PanelModelLine VERTICAL CENTER BOTTOM");
dynamic_cast<Panel*
>(elements[8].get())->setTooltip(
"PanelModelLine VERTICAL RIGHT BOTTOM");
}
void DemoApp::initPanelModelGrid() {
modelsRightSplitted->setModelFirst(
PanelModelGrid::create(
3, 3, 20.f, MarginMode::Full, MarginUnit::Absolute
)
);
modelsRightSplitted->getFirst().setTooltip("PanelModelGrid(3x3) margin = 20");
for(size_t i=1; i <= 12; ++i) {
auto b = std::make_shared<Button>(std::to_string(i));
b->setOutlineSize(1.f);
modelsRightSplitted->addToFirst(b);
}
}
void DemoApp::initPanelModelList() {
modelsRightSplitted->setModelSecond(PanelModelList::create());
modelsRightSplitted->getSecond().setTooltip("PanelModelList");
for(size_t i=1; i<=128; ++i) {
auto b = std::make_shared<Button>(std::to_string(i));
b->setSize(sf::Vector2f(20+rand()%100, 20+rand()%50));
b->setColor(ColorId::Background, StateId::Default, sf::Color(rand()%256, rand()%256, rand()%256, 32));
modelsRightSplitted->addToSecond(b);
if(i == 1) {
b->setAction([this]() {
auto& elements = modelsRightSplitted->getSecond().getElements();
for(auto& e : elements) {
e->setVisible(true);
}
});
} else {
b->setAction([b]() {
b->setVisible(false);
});
}
}
}
void DemoApp::initDialogsTab() {
auto& panel = mainTabbed->getTabPanel(S::tab::dialogs);
panel.setModel(
PanelModelLine::create(
Orientation::Vertical,
Align::Center,
VAlign::Middle,
10.f,
MarginMode::Vertical
)
);
info = std::make_shared<TextLabel>(S::label::info, " ", true);
info->setAlign(Align::Center);
info->setFontSize(20);
info->setColor(ColorId::FontFill, StateId::Default, sf::Color::White);
initDialogInfo();
initDialogInput();
InitDialogYesNo();
initDialogYesNoCancel();
initDialogCustom();
panel.add(info);
}
void DemoApp::initPanelModelsTab() {
modelsSplitted = std::make_shared<PanelSplitted>();
modelsSplitted->setName("modelsSplitted");
modelsSplitted->setOrientation(Orientation::Vertical);
mainTabbed->addToTab(S::tab::panelModels, modelsSplitted);
modelsLeftSplitted = std::make_shared<PanelSplittedScrolled>();
modelsLeftSplitted->setName("modelsLeftSplitted");
modelsSplitted->addToFirst(modelsLeftSplitted);
modelsRightSplitted = std::make_shared<PanelSplittedScrolled>();
modelsRightSplitted->setName("modelsRightSplitted");
modelsSplitted->addToSecond(modelsRightSplitted);
initPanelModelLineHorizontal();
initPanelModelLineVertical();
initPanelModelGrid();
initPanelModelList();
}
void DemoApp::initPanelTabbedTab() {
auto& panel = mainTabbed->getTabPanel(S::tab::panelTabbed);
panel.setModel(PanelModelGrid::create(2, 2));
sf::Color c(64,64,64);
sf::Color cm(16,16,16);
auto pt1 = std::make_shared<PanelTabbed>();
pt1->setTabPosition(TabPosition::Top);
pt1->addTab(S::tab::t1);
pt1->addTab(S::tab::t2);
pt1->addTab(S::tab::t3);
pt1->getTabPanel(S::tab::t1).setColor(ColorId::Background, StateId::Default, c);
pt1->getTabPanel(S::tab::t2).setColor(ColorId::Background, StateId::Default, c);
pt1->getTabPanel(S::tab::t3).setColor(ColorId::Background, StateId::Default, c);
c += cm;
auto pt2 = std::make_shared<PanelTabbed>();
pt2->setTabPosition(TabPosition::Bottom);
pt2->addTab(S::tab::t1);
pt2->addTab(S::tab::t2);
pt2->addTab(S::tab::t3);
pt2->getTabPanel(S::tab::t1).setColor(ColorId::Background, StateId::Default, c);
pt2->getTabPanel(S::tab::t2).setColor(ColorId::Background, StateId::Default, c);
pt2->getTabPanel(S::tab::t3).setColor(ColorId::Background, StateId::Default, c);
c += cm;
auto pt3 = std::make_shared<PanelTabbed>();
pt3->setTabPosition(TabPosition::Left);
pt3->addTab(S::tab::t1);
pt3->addTab(S::tab::t2);
pt3->addTab(S::tab::t3);
pt3->getTabPanel(S::tab::t1).setColor(ColorId::Background, StateId::Default, c);
pt3->getTabPanel(S::tab::t2).setColor(ColorId::Background, StateId::Default, c);
pt3->getTabPanel(S::tab::t3).setColor(ColorId::Background, StateId::Default, c);
c += cm;
auto pt4 = std::make_shared<PanelTabbed>();
pt4->setTabPosition(TabPosition::Right);
pt4->addTab(S::tab::t1);
pt4->addTab(S::tab::t2);
pt4->addTab(S::tab::t3);
pt4->getTabPanel(S::tab::t1).setColor(ColorId::Background, StateId::Default, c);
pt4->getTabPanel(S::tab::t2).setColor(ColorId::Background, StateId::Default, c);
pt4->getTabPanel(S::tab::t3).setColor(ColorId::Background, StateId::Default, c);
panel.add({pt1,pt2,pt3,pt4});
}
void DemoApp::initOptionsTab() {
sf::Vector2f gap(0.f, 10.f);
auto gap1 = std::make_shared<EmptySpace>(gap);
auto gap2 = std::make_shared<EmptySpace>(gap);
auto gap3 = std::make_shared<EmptySpace>(gap);
auto gap4 = std::make_shared<EmptySpace>(gap);
auto gap5 = std::make_shared<EmptySpace>(gap);
auto& panel = mainTabbed->getTabPanel(S::tab::options);
panel.setModel(
PanelModelLine::create(
Orientation::Vertical,
Align::Center,
VAlign::Middle,
10.f,
MarginMode::Vertical
)
);
auto langLabel = std::make_shared<TextLabel>(L::label::language, true);
langLabel->setAutoResizeParentLimit(false);
langLabel->setFontSize(20);
langLabel->setColor(ColorId::FontFill, StateId::Default, sf::Color::White);
auto windowModeLabel = std::make_shared<TextLabel>(S::label::windowMode, true);
windowModeLabel->setAutoResizeParentLimit(false);
windowModeLabel->setFontSize(20);
windowModeLabel->setColor(ColorId::FontFill, StateId::Default, sf::Color::White);
auto resolutionLabel = std::make_shared<TextLabel>(S::label::resolution, true);
resolutionLabel->setAutoResizeParentLimit(false);
resolutionLabel->setFontSize(20);
resolutionLabel->setColor(ColorId::FontFill, StateId::Default, sf::Color::White);
auto vsyncLabel = std::make_shared<TextLabel>(S::label::vsync, true);
vsyncLabel->setAutoResizeParentLimit(false);
vsyncLabel->setFontSize(20);
vsyncLabel->setColor(ColorId::FontFill, StateId::Default, sf::Color::White);
auto frameLimitLabel = std::make_shared<TextLabel>(S::label::frameLimit, true);
frameLimitLabel->setAutoResizeParentLimit(false);
frameLimitLabel->setFontSize(20);
frameLimitLabel->setColor(ColorId::FontFill, StateId::Default, sf::Color::White);
auto showFpsLabel = std::make_shared<TextLabel>(S::label::showFps, true);
showFpsLabel->setAutoResizeParentLimit(false);
showFpsLabel->setFontSize(20);
showFpsLabel->setColor(ColorId::FontFill, StateId::Default, sf::Color::White);
auto langButton = std::make_shared<Button>(L::language,[] {
Lang::next();
});
auto windowModeCheckbox = std::make_shared<Checkbox>();
auto wp = GUIManager::getParameters();
if(!wp.fullScreen) {
windowModeCheckbox->fireAssigner();
}
windowModeCheckbox->setAction([windowModeCheckbox, this] {
windowModeCheckbox->fireAssigner();
GUIManager::toggleFullscreen(rw);
}, ActionType::Press::click);
auto resolutionPanel = std::make_shared<PanelScrolled>();
resolutionPanel->setMaximized(false);
resolutionPanel->setModel(PanelModelList::create());
resolutionPanel->setColor(ColorId::Background, StateId::Default, {128, 128, 128});
resolutionPanel->setSize(sf::Vector2f(300.f, 210.f));
resolutionPanel->setScrollType(ScrollType::Solid);
resolutionPanel->setScrollButtonThick(20.f);
auto fsm = sf::VideoMode::getFullscreenModes();
auto bpp = fsm.front().bitsPerPixel;
for(auto vm : fsm) {
if(vm.bitsPerPixel != bpp) {
break;
}
sf::Vector2u res(vm.width, vm.height);
auto b = std::make_shared<Button>(std::to_string(vm.width)+"x"+std::to_string(vm.height));
b->setAction([b, resolutionPanel, res, this] {
for(auto e : resolutionPanel->getElements()) {
auto btn =
dynamic_cast<Button*
>(e.get()) ;
btn->setSelected(false);
}
GUIManager::setFullScreenResolution(&rw,res);
if(GUIManager::getParameters().fullScreen) {
GUIManager::recreateWindow(rw);
}
b->setSelected(true);
});
if(vm.width == wp.fullScreenSize.x && vm.height == wp.fullScreenSize.y) {
b->setSelected(true);
}
b->setMaximized(true);
b->setMaximizationMode(MaximizationMode::Horizontal);
b->setGradientType(GradientType::None);
b->setSize({0.f, 30.f});
b->setColorEnabled(ColorId::Background, StateId::Hover, false);
b->setColorEnabled(ColorId::Background, StateId::Focus, false);
b->setColorEnabled(ColorId::Outline, StateId::Hover, false);
b->setColorEnabled(ColorId::Outline, StateId::Focus, false);
auto& l = b->getLabel();
l.setFontOutlineSize(0.f);
l.setFontSize(16);
resolutionPanel->add(b);
}
auto vsyncCheckbox = std::make_shared<Checkbox>();
if(wp.verticalSync) {
vsyncCheckbox->fireAssigner();
}
vsyncCheckbox->setAction([this, vsyncCheckbox]() {
vsyncCheckbox->fireAssigner();
GUIManager::setVerticalSync(&rw, vsyncCheckbox->getState() == CBState::Checked);
}, ActionType::Press::click);
auto frameLimit = std::make_shared<TextInput>();
frameLimit->setSize({70.f,0.f});
frameLimit->setText(std::to_string(wp.frameLimit));
frameLimit->setCursor(-1);
frameLimit->setAction([
this](
const TextInput& i) {
if(t.isEmpty()) {
GUIManager::setFramerateLimit(&rw, 0);
} else {
GUIManager::setFramerateLimit(&rw, std::stoul(t.toAnsiString()));
}
}, ActionType::Text::update);
addConfVar(showFps);
relConfVar(showFps);
auto showFpsCheckbox = std::make_shared<Checkbox>(&showFps);
panel.add({
langLabel,
langButton,
gap1,
windowModeLabel,
windowModeCheckbox,
gap2,
resolutionLabel,
resolutionPanel,
gap3,
vsyncLabel,
vsyncCheckbox,
gap4,
frameLimitLabel,
frameLimit,
gap5,
showFpsLabel,
showFpsCheckbox
});
}
void DemoApp::initFirstElements() {
auto label = std::make_shared<TextLabel>(S::label::example1, true);
label->setTooltip("TextLabel");
label->setColor(ColorId::FontFill, StateId::Default, sf::Color::White);
label->setFontSize(20);
label->setAutoResizeParentLimit(false);
auto input = std::make_shared<TextInput>();
input->setTooltip("TextInput");
auto inputDisabled = std::make_shared<TextInput>();
inputDisabled->setTooltip("TextInput (enabled = false)");
inputDisabled->setEnabled(false);
inputDisabled->setText(l(S::text::disabled));
auto button = std::make_shared<Button>(S::button::example1,
[input]() {
if(input->getText().isEmpty()) {
input->setText("Hello SSG!");
input->setCursor(-1);
}
});
button->setTooltip("Button");
auto buttonDisabled = std::make_shared<Button>(S::button::example2);
buttonDisabled->setEnabled(false);
buttonDisabled->setTooltip("Button (enabled = false)");
auto boolLabel = std::make_shared<TextLabel>(S::label::boolLabel, true);
boolLabel->setAutoResizeParentLimit(false);
boolLabel->setFontSize(20);
boolLabel->setFont(S::font::inconsolata);
boolLabel->setColor(ColorId::FontFill, StateId::Default, sf::Color::Yellow);
auto checkbox = std::make_shared<Checkbox>(&exampleBool1);
checkbox->setTooltip("Checkbox");
checkbox->setAction([boolLabel,checkbox,this]() {
checkbox->fireAssigner();
boolLabel->setText("exampleBool = "+std::to_string(exampleBool1));
}, ActionType::Press::click);
checkbox->doAction(ActionType::Press::click);
auto checkboxDisabled = std::make_shared<Checkbox>();
checkboxDisabled->setTooltip("Checkbox (enabled = false)");
checkboxDisabled->setEnabled(false);
elementsLeftSplitted->addToFirst({label,input,inputDisabled,button,buttonDisabled,checkbox,checkboxDisabled,boolLabel});
}
void DemoApp::initSecondElements() {
auto l1 = std::make_shared<TextLabel>(S::label::example2, true);
l1->setColor(ColorId::FontFill, StateId::Default, sf::Color::Cyan);
l1->setColor(ColorId::FontFill, StateId::Hover, sf::Color::White);
l1->setColor(ColorId::FontFill, StateId::Pressed, sf::Color::Yellow);
l1->setColor(ColorId::FontOutline, StateId::Hover, {100, 100, 100});
l1->setColor(ColorId::FontOutline, StateId::Pressed, {127, 127, 0});
l1->setColorEnabled(ColorId::FontFill, StateId::Hover, true);
l1->setColorEnabled(ColorId::FontFill, StateId::Pressed, true);
l1->setColorEnabled(ColorId::FontOutline, StateId::Hover, true);
l1->setColorEnabled(ColorId::FontOutline, StateId::Pressed, true);
l1->setFontOutlineSize(8.f);
l1->setFontSize(20);
l1->setFont(S::font::inconsolata);
auto l2 = std::make_shared<TextLabel>(S::label::example3, true);
l2->setColor(ColorId::FontFill, StateId::Default, sf::Color::Green);
l2->setColor(ColorId::FontFill, StateId::Hover, sf::Color::Magenta);
l2->setColor(ColorId::FontOutline, StateId::Hover, {127, 0, 127});
l2->setColorEnabled(ColorId::FontFill, StateId::Hover, true);
l2->setColorEnabled(ColorId::FontOutline, StateId::Hover, true);
l2->setFontOutlineSize(4.f);
l2->setFontSize(30);
l2->setFont(S::font::oxygen);
auto l3 = std::make_shared<TextLabel>(S::label::example4, true);
l3->setColor(ColorId::FontFill, StateId::Default, {255, 127, 0});
l3->setColor(ColorId::FontFill, StateId::Hover, sf::Color::Red);
l3->setColor(ColorId::FontOutline, StateId::Hover, {127, 0, 0});
l3->setFontOutlineSize(2.f);
l3->setFontSize(40);
l3->setFont(S::font::sansation);
l3->setColorEnabled(ColorId::FontFill, StateId::Hover, true);
l3->setColorEnabled(ColorId::FontOutline, StateId::Hover, true);
auto b1 = std::make_shared<Button>(S::button::custom1);
b1->setTooltip("Textured Button");
b1->setBackgroundTexture(TextureManager::get(S::texture::flare));
b1->setColorEnabled(ColorId::Background, StateId::Focus, false);
b1->setColor(ColorId::Background, StateId::Default, sf::Color::White);
b1->setGradientType(GradientType::None);
b1->setOutlineSize(0.f);
b1->setSize({100, 50});
b1->getLabel().setFontSize(15);
b1->getLabel().setFontStyle(sf::Text::Bold);
auto b2 = std::make_shared<Button>(S::button::custom2);
b2->setTooltip("Textured Button");
b2->setSize({100,50});
b2->setBackgroundTexture(TextureManager::get(S::texture::wood));
b2->getLabel().setFontSize(15);
b2->getLabel().setColor(ColorId::FontFill, StateId::Default, sf::Color::White);
b2->getLabel().setColorEnabled(ColorId::FontFill, StateId::Hover, false);
b2->getLabel().setFontOutlineSize(0.f);
auto b3 = std::make_shared<Button>(L::button::ok);
b3->setTooltip("Symbol Button");
b3->setGradientType(GradientType::None);
b3->setBackgroundSymbol(SymbolManager::get(SM::triangle2));
b3->setSize({50,50});
b3->setOutlineSize(0.f);
b3->setColor(ColorId::Background, StateId::Default, sf::Color::Transparent);
b3->setColorEnabled(ColorId::Background, StateId::Hover, false);
b3->setColorEnabled(ColorId::Background, StateId::Pressed, false);
b3->setColorEnabled(ColorId::Background, StateId::Focus, false);
auto i1 = std::make_shared<TextInput>();
i1->setTooltip("Black input");
i1->setColor(ColorId::Background, StateId::Default, {100, 100, 100});
i1->setColor(ColorId::Background, StateId::Hover, {50, 50, 50});
i1->setColor(ColorId::Background, StateId::Focus, sf::Color::Black);
i1->setColor(ColorId::Outline, StateId::Hover, {0, 100, 100});
i1->setColor(ColorId::Outline, StateId::Pressed, {0, 200, 200});
i1->setColor(ColorId::Outline, StateId::Focus, sf::Color::Cyan);
i1->setColor(ColorId::FontFill, StateId::Default, sf::Color::White);
i1->setColor(ColorId::CursorFill, StateId::Default, sf::Color::Cyan);
i1->setColor(ColorId::CursorOutline, StateId::Default, sf::Color::Green);
i1->setColorEnabled(ColorId::FontFill, StateId::Focus, false);
i1->setColorEnabled(ColorId::FontFill, StateId::Hover, false);
i1->setFont(S::font::sansation);
i1->setFontSize(28);
i1->setSize({150.f, 0.f});
auto i2 = std::make_shared<TextInput>();
i2->setTooltip("Textured input");
i2->setBackgroundTexture(TextureManager::get(S::texture::input));
i2->setMargin(24);
i2->setOutlineSize(0.f);
i2->setColor(ColorId::FontFill, StateId::Default, sf::Color::White);
i2->setColor(ColorId::FontFill, StateId::Focus, sf::Color::White);
i2->setColor(ColorId::FontFill, StateId::Hover, sf::Color::Cyan);
auto cb1 = std::make_shared<Checkbox>();
cb1->setTooltip("Symbol Checkbox");
cb1->setSize({50.f,50.f});
cb1->setSymbol(CBState::Unchecked, SymbolManager::get(SM::star3));
cb1->setSymbol(CBState::Checked, SymbolManager::get(SM::star6));
cb1->setSymbolColor(CBState::Unchecked, {200, 0, 0});
cb1->setSymbolColor(CBState::Checked, {0, 255, 0});
cb1->setGradientType(GradientType::None);
elementsLeftSplitted->addToSecond({l1, l2, l3, i1, i2, b1, b2, b3, cb1});
}
void DemoApp::initThirdElements() {
sf::Color tMod(255,255,255,48);
auto p1 = std::make_shared<Panel>();
p1->setTooltip(S::text::gradient1);
p1->setGradientType(GradientType::Horizontal);
p1->setGradientPoints({sf::Color::Red,sf::Color::Green,sf::Color::Blue});
p1->setColor(ColorId::Background, StateId::Hover, sf::Color::White*tMod);
p1->setColorEnabled(ColorId::Background, StateId::Hover, true);
auto p2 = std::make_shared<Panel>();
p2->setTooltip(S::text::gradient2);
p2->setGradientType(GradientType::Vertical);
p2->setGradientPoints({sf::Color::Cyan,sf::Color::Magenta,sf::Color::Yellow});
p2->setColor(ColorId::Background, StateId::Hover, sf::Color::Black*tMod);
p2->setColorEnabled(ColorId::Background, StateId::Hover, true);
auto p3 = std::make_shared<Panel>();
p3->setTooltip(S::text::gradient3);
p3->setGradientType(GradientType::Horizontal);
p3->setGradientPoints({{sf::Color::Black, 0.f},{sf::Color::White, 10.f},{sf::Color::Black, 50.f}, {sf::Color::White, 90.f},{sf::Color::Black, 100.f}});
p3->setColor(ColorId::Background, StateId::Hover, sf::Color::Red*tMod);
p3->setColorEnabled(ColorId::Background, StateId::Hover, true);
auto p4 = std::make_shared<Panel>();
p4->setTooltip(S::text::gradient4);
p4->setGradientType(GradientType::Vertical);
p4->setGradientModifier({
sf::Color::Red*tMod,
sf::Color::Green*tMod,
sf::Color::Blue*tMod,
sf::Color::Yellow*tMod
});
p4->setColor(ColorId::Background, StateId::Hover, sf::Color::Green*tMod);
p4->setColorEnabled(ColorId::Background, StateId::Hover, true);
elementsRightSplitted->addToFirst({p1, p2, p3, p4});
}
void DemoApp::initFourthElements() {
auto splitted = std::make_shared<PanelSplitted>();
splitted->setOrientation(Orientation::Vertical);
auto left = std::make_shared<PanelSplittedScrolled>();
auto right = std::make_shared<PanelSplittedScrolled>();
left->getFirst().setColor(ColorId::Background, StateId::Default, sf::Color::White);
left->getFirst().setScrollType(ScrollType::Solid);
left->getFirst().setScrollEnable(ScrollEnable::Vertical);
right->getFirst().setColor(ColorId::Background, StateId::Default, sf::Color::White);
right->getFirst().setScrollType(ScrollType::Solid);
right->getFirst().setScrollEnable(ScrollEnable::Vertical);
left->getSecond().setColor(ColorId::Background, StateId::Default, sf::Color::White);
left->getSecond().setScrollType(ScrollType::Solid);
left->getSecond().setScrollEnable(ScrollEnable::Vertical);
right->getSecond().setColor(ColorId::Background, StateId::Default, sf::Color::White);
right->getSecond().setScrollType(ScrollType::Solid);
right->getSecond().setScrollEnable(ScrollEnable::Vertical);
splitted->addToFirst(left);
splitted->addToSecond(right);
auto l1 = std::make_shared<TextLabel>();
l1->setAutoResize(true);
l1->setAlign(Align::Justify);
l1->setMargin(32.f);
left->addToFirst(l1);
auto l2 = std::make_shared<TextLabel>();
l2->setAutoResize(true);
l2->setAlign(Align::Center);
l2->setMargin(32.f);
right->addToFirst(l2);
auto l3 = std::make_shared<TextLabel>();
l3->setAutoResize(true);
l3->setAlign(Align::Left);
l3->setMargin(32.f);
left->addToSecond(l3);
auto l4 = std::make_shared<TextLabel>();
l4->setAutoResize(true);
l4->setAlign(Align::Right);
l4->setMargin(32.f);
right->addToSecond(l4);
sf::String titleStyle = sf::String(L::style::center) + "{line-size:200;font-size:20}";
l1->setText(
titleStyle +
L::style::bold +
l(S::text::lorem) + " " +
l(S::text::alignJustify) + "\n" +
l(S::text::loremIpsum) + "\n" +
"{color-fill:#900}" + l(S::text::loremIpsum) + "\n" +
"{color-fill:#090}" + l(S::text::loremIpsum) + "\n" +
"{color-fill:#009}" + l(S::text::loremIpsum) + "\n" +
"{color-fill:#990}" + l(S::text::loremIpsum) + "\n" +
"{color-fill:#099}" + l(S::text::loremIpsum) + "\n" +
"{color-fill:#909}" + l(S::text::loremIpsum) + "\n"
);
l2->setText(
titleStyle +
L::style::underline +
l(S::text::lorem) + " " +
l(S::text::alignCenter) + "\n" +
l(S::text::loremIpsum)
);
l3->setText(
titleStyle +
L::style::italic +
l(S::text::lorem) + " " +
l(S::text::alignLeft) + "\n" +
l(S::text::loremIpsum)
);
l4->setText(
titleStyle +
L::style::strikethrough +
l(S::text::lorem) + " " +
l(S::text::alignRight) + "\n" +
l(S::text::loremIpsum)
);
elementsRightSplitted->addToSecond(splitted);
}