Merge pull request #791 from jpcima/about-info

UI: About dialog with sysinfo
This commit is contained in:
JP Cimalando 2021-04-07 03:05:05 +02:00 committed by GitHub
commit ccefc07fb0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 151 additions and 56 deletions

View file

@ -3,48 +3,66 @@ version 1.0305
header_name {.h}
code_name {.cxx}
widget_class aboutView {
label {About sfizz} open selected
label {About sfizz} open
xywh {527 165 800 475} type Double visible
} {
Fl_Box lblHover_ {
xywh {200 80 400 25} labelsize 10
class HoverBox
}
Fl_Button {} {
comment {tag=kTagButtonSfztools}
xywh {235 45 35 35} labelsize 30
class ButtonSfztools
}
Fl_Button {} {
comment {tag=kTagButtonGithub}
xywh {305 45 35 35} labelsize 30
class ButtonGithub
}
Fl_Button {} {
comment {tag=kTagButtonDiscord}
xywh {375 45 35 35} labelsize 30
class ButtonDiscord
}
Fl_Button {} {
comment {tag=kTagButtonOpencollective}
xywh {445 45 35 35} labelsize 30
class ButtonOpencollective
}
Fl_Button {} {
comment {tag=kTagButtonSfzformat}
xywh {515 45 35 35} labelsize 30
class ButtonSfzformat
}
Fl_Box {} {
image {../resources/logo_orange.png} xywh {200 90 400 180}
image {../resources/logo_orange.png} xywh {200 0 400 180}
class Logo
}
Fl_Box {} {
xywh {260 270 280 80}
xywh {260 180 280 80}
class InfoBox
}
Fl_Box {} {
xywh {200 350 400 100}
xywh {200 260 400 100}
class DescriptionBox
}
Fl_Box lblHover_ {selected
xywh {465 435 315 25} labelsize 12 hide
class HoverBox
}
Fl_Button {} {
comment {tag=kTagButtonSfztools} selected
xywh {465 405 40 40} labelsize 30
class ButtonSfztools
}
Fl_Button {} {
comment {tag=kTagButtonGithub} selected
xywh {535 405 40 40} labelsize 30
class ButtonGithub
}
Fl_Button {} {
comment {tag=kTagButtonDiscord} selected
xywh {605 405 40 40} labelsize 30
class ButtonDiscord
}
Fl_Button {} {
comment {tag=kTagButtonOpencollective} selected
xywh {675 405 40 40} labelsize 30
class ButtonOpencollective
}
Fl_Button {} {
comment {tag=kTagButtonSfzformat} selected
xywh {745 405 40 40} labelsize 30
class ButtonSfzformat
}
Fl_Box {} {
label {Format
Host
Processor
Address
System}
xywh {15 375 90 90} align 20
class SysInfoKeyBox
}
Fl_Box lblSysInfoValue_ {
label {%PluginFormat%
%HostProgram%
%HostCPU%
%HostBits% bits
%HostOS%}
xywh {105 375 345 90} align 20
class SysInfoValueBox
}
}

View file

@ -77,7 +77,7 @@ SAboutDialog::SAboutDialog(const CRect& bounds)
auto createHoverBox = [](const CRect& bounds, int, const char* label, CHoriTxtAlign align, int fontsize) {
CTextLabel* lbl = new CTextLabel(bounds, label);
auto font = makeOwned<CFontDesc>("Roboto", fontsize);
lbl->setFontColor(CColor(0xff, 0xff, 0xff, 0xff));
lbl->setFontColor(CColor(0xfd, 0x98, 0x00, 0xff));
lbl->setFrameColor(CColor(0x00, 0x00, 0x00, 0x00));
lbl->setBackColor(CColor(0x00, 0x00, 0x00, 0x00));
lbl->setHoriAlign(align);
@ -85,6 +85,30 @@ SAboutDialog::SAboutDialog(const CRect& bounds)
return lbl;
};
auto createSysInfoKeyBox = [](const CRect& bounds, int, const char* label, CHoriTxtAlign align, int fontsize) {
CMultiLineTextLabel* lbl = new CMultiLineTextLabel(bounds);
auto font = makeOwned<CFontDesc>("Roboto", fontsize, kBoldFace);
lbl->setFont(font);
lbl->setFontColor(CColor(0xfd, 0x98, 0x00, 0xff));
lbl->setFrameColor(CColor(0x00, 0x00, 0x00, 0x00));
lbl->setBackColor(CColor(0x00, 0x00, 0x00, 0x00));
lbl->setHoriAlign(align);
lbl->setText(label);
return lbl;
};
auto createSysInfoValueBox = [](const CRect& bounds, int, const char* label, CHoriTxtAlign align, int fontsize) {
CMultiLineTextLabel* lbl = new CMultiLineTextLabel(bounds);
auto font = makeOwned<CFontDesc>("Roboto", fontsize);
lbl->setFont(font);
lbl->setFontColor(CColor(0xff, 0xff, 0xff, 0xff));
lbl->setFrameColor(CColor(0x00, 0x00, 0x00, 0x00));
lbl->setBackColor(CColor(0x00, 0x00, 0x00, 0x00));
lbl->setHoriAlign(align);
lbl->setText(label);
return lbl;
};
auto createGlyphButton = [this](UTF8StringPtr glyph, const CRect& bounds, int tag, int fontsize) {
STextButton* btn = new STextButton(bounds, this, tag, glyph);
btn->setFont(makeOwned<CFontDesc>("Sfizz Misc Icons", fontsize));
@ -98,32 +122,32 @@ SAboutDialog::SAboutDialog(const CRect& bounds)
};
auto createButtonSfztools = [this, &createGlyphButton](const CRect& bounds, int tag, const char*, CHoriTxtAlign, int fontsize) {
STextButton* btn = createGlyphButton(u8"\ue000", bounds, tag, fontsize);
btn->OnHoverEnter = [this]() { lblHover_->setText("SFZTools Website"); };
btn->OnHoverLeave = [this]() { lblHover_->setText(""); };
btn->OnHoverEnter = [this, btn]() { buttonHoverEnter(btn, "SFZ Tools"); };
btn->OnHoverLeave = [this, btn]() { buttonHoverLeave(btn); };
return btn;
};
auto createButtonGithub = [this, &createGlyphButton](const CRect& bounds, int tag, const char*, CHoriTxtAlign, int fontsize) {
STextButton* btn = createGlyphButton(u8"\ue001", bounds, tag, fontsize);
btn->OnHoverEnter = [this]() { lblHover_->setText("GitHub Repository"); };
btn->OnHoverLeave = [this]() { lblHover_->setText(""); };
btn->OnHoverEnter = [this, btn]() { buttonHoverEnter(btn, "Source code"); };
btn->OnHoverLeave = [this, btn]() { buttonHoverLeave(btn); };
return btn;
};
auto createButtonDiscord = [this, &createGlyphButton](const CRect& bounds, int tag, const char*, CHoriTxtAlign, int fontsize) {
STextButton* btn = createGlyphButton(u8"\ue002", bounds, tag, fontsize);
btn->OnHoverEnter = [this]() { lblHover_->setText("Discord Chat"); };
btn->OnHoverLeave = [this]() { lblHover_->setText(""); };
btn->OnHoverEnter = [this, btn]() { buttonHoverEnter(btn, "Community chat"); };
btn->OnHoverLeave = [this, btn]() { buttonHoverLeave(btn); };
return btn;
};
auto createButtonOpencollective = [this, &createGlyphButton](const CRect& bounds, int tag, const char*, CHoriTxtAlign, int fontsize) {
STextButton* btn = createGlyphButton(u8"\ue003", bounds, tag, fontsize);
btn->OnHoverEnter = [this]() { lblHover_->setText("Support Us"); };
btn->OnHoverLeave = [this]() { lblHover_->setText(""); };
btn->OnHoverEnter = [this, btn]() { buttonHoverEnter(btn, "Support us"); };
btn->OnHoverLeave = [this, btn]() { buttonHoverLeave(btn); };
return btn;
};
auto createButtonSfzformat = [this, &createGlyphButton](const CRect& bounds, int tag, const char*, CHoriTxtAlign, int fontsize) {
STextButton* btn = createGlyphButton(u8"\ue004", bounds, tag, fontsize);
btn->OnHoverEnter = [this]() { lblHover_->setText("SFZFormat Documentation"); };
btn->OnHoverLeave = [this]() { lblHover_->setText(""); };
btn->OnHoverEnter = [this, btn]() { buttonHoverEnter(btn, "SFZ Format"); };
btn->OnHoverLeave = [this, btn]() { buttonHoverLeave(btn); };
return btn;
};
@ -134,16 +158,54 @@ SAboutDialog::SAboutDialog(const CRect& bounds)
CRect aboutBounds = aboutView->getViewSize();
aboutBounds.centerInside(CRect(bounds).originize());
aboutView->setViewSize(aboutBounds);
///
sysInfoTemplate_ = lblSysInfoValue_->getText();
sysInfoVariables_["%HostOS%"] = getOperatingSystemName();
sysInfoVariables_["%HostCPU%"] = getProcessorName();
sysInfoVariables_["%HostBits%"] = std::to_string(8 * sizeof(void*));
}
void SAboutDialog::setPluginFormat(const std::string& pluginFormat)
{
// TODO
sysInfoVariables_["%PluginFormat%"] = pluginFormat;
updateSysInfo();
}
void SAboutDialog::setPluginHost(const std::string& pluginHost)
{
// TODO
sysInfoVariables_["%HostProgram%"] = pluginHost;
updateSysInfo();
}
void SAboutDialog::updateSysInfo()
{
std::string text = sysInfoTemplate_;
for (const auto& infoKeyValue : sysInfoVariables_) {
size_t pos = text.find(infoKeyValue.first);
if (pos != text.npos)
text.replace(pos, infoKeyValue.first.size(), infoKeyValue.second);
}
lblSysInfoValue_->setText(UTF8String(text));
}
void SAboutDialog::buttonHoverEnter(CControl* btn, const char* text)
{
CRect rect = lblHover_->getViewSize();
CRect btnRect = btn->getViewSize();
rect.left = btnRect.left - 100;
rect.right = btnRect.right + 100;
lblHover_->setViewSize(rect);
lblHover_->setText(text);
lblHover_->setVisible(true);
lblHover_->invalid();
}
void SAboutDialog::buttonHoverLeave(CControl* btn)
{
(void)btn;
lblHover_->setVisible(false);
}
CMouseEventResult SAboutDialog::onMouseDown(CPoint& where, const CButtonState& buttons)

View file

@ -35,5 +35,14 @@ protected:
// IControlListener
void valueChanged(CControl* ctl) override;
private:
void updateSysInfo();
void buttonHoverEnter(CControl* btn, const char* text);
void buttonHoverLeave(CControl* btn);
CTextLabel* lblHover_ = {};
CTextLabel* lblSysInfoValue_ = {};
std::string sysInfoTemplate_;
std::map<std::string, std::string> sysInfoVariables_;
};

View file

@ -1,22 +1,28 @@
/* This file is generated by the layout maker tool. */
auto* const view__0 = createaboutView(CRect(0, 0, 800, 475), -1, "About sfizz", kCenterText, 14);
aboutView = view__0;
auto* const view__1 = createHoverBox(CRect(200, 80, 600, 105), -1, "", kCenterText, 10);
lblHover_ = view__1;
auto* const view__1 = createLogo(CRect(200, 0, 600, 180), -1, "", kCenterText, 14);
view__0->addView(view__1);
auto* const view__2 = createButtonSfztools(CRect(235, 45, 270, 80), kTagButtonSfztools, "", kCenterText, 30);
auto* const view__2 = createInfoBox(CRect(260, 180, 540, 260), -1, "", kCenterText, 14);
view__0->addView(view__2);
auto* const view__3 = createButtonGithub(CRect(305, 45, 340, 80), kTagButtonGithub, "", kCenterText, 30);
auto* const view__3 = createDescriptionBox(CRect(200, 260, 600, 360), -1, "", kCenterText, 14);
view__0->addView(view__3);
auto* const view__4 = createButtonDiscord(CRect(375, 45, 410, 80), kTagButtonDiscord, "", kCenterText, 30);
auto* const view__4 = createHoverBox(CRect(465, 435, 780, 460), -1, "", kCenterText, 12);
lblHover_ = view__4;
view__0->addView(view__4);
auto* const view__5 = createButtonOpencollective(CRect(445, 45, 480, 80), kTagButtonOpencollective, "", kCenterText, 30);
view__4->setVisible(false);
auto* const view__5 = createButtonSfztools(CRect(465, 405, 505, 445), kTagButtonSfztools, "", kCenterText, 30);
view__0->addView(view__5);
auto* const view__6 = createButtonSfzformat(CRect(515, 45, 550, 80), kTagButtonSfzformat, "", kCenterText, 30);
auto* const view__6 = createButtonGithub(CRect(535, 405, 575, 445), kTagButtonGithub, "", kCenterText, 30);
view__0->addView(view__6);
auto* const view__7 = createLogo(CRect(200, 90, 600, 270), -1, "", kCenterText, 14);
auto* const view__7 = createButtonDiscord(CRect(605, 405, 645, 445), kTagButtonDiscord, "", kCenterText, 30);
view__0->addView(view__7);
auto* const view__8 = createInfoBox(CRect(260, 270, 540, 350), -1, "", kCenterText, 14);
auto* const view__8 = createButtonOpencollective(CRect(675, 405, 715, 445), kTagButtonOpencollective, "", kCenterText, 30);
view__0->addView(view__8);
auto* const view__9 = createDescriptionBox(CRect(200, 350, 600, 450), -1, "", kCenterText, 14);
auto* const view__9 = createButtonSfzformat(CRect(745, 405, 785, 445), kTagButtonSfzformat, "", kCenterText, 30);
view__0->addView(view__9);
auto* const view__10 = createSysInfoKeyBox(CRect(15, 375, 105, 465), -1, "Format\nHost\nProcessor\nAddress\nSystem", kLeftText, 14);
view__0->addView(view__10);
auto* const view__11 = createSysInfoValueBox(CRect(105, 375, 450, 465), -1, "%PluginFormat%\n%HostProgram%\n%HostCPU%\n%HostBits% bits\n%HostOS%", kLeftText, 14);
lblSysInfoValue_ = view__11;
view__0->addView(view__11);