about-dialog.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. #if defined(Hiro_AboutDialog)
  2. auto AboutDialog::setAlignment(Alignment alignment) -> type& {
  3. state.alignment = alignment;
  4. state.relativeTo = {};
  5. return *this;
  6. }
  7. auto AboutDialog::setAlignment(sWindow relativeTo, Alignment alignment) -> type& {
  8. state.alignment = alignment;
  9. state.relativeTo = relativeTo;
  10. return *this;
  11. }
  12. auto AboutDialog::setCopyright(const string& copyright) -> type& {
  13. state.copyright = copyright;
  14. return *this;
  15. }
  16. auto AboutDialog::setDescription(const string& description) -> type& {
  17. state.description = description;
  18. return *this;
  19. }
  20. auto AboutDialog::setLicense(const string& license, const string& uri) -> type& {
  21. state.license = license;
  22. state.licenseURI = uri;
  23. return *this;
  24. }
  25. auto AboutDialog::setLogo(const image& logo) -> type& {
  26. state.logo = logo;
  27. state.logo.transform();
  28. state.logo.alphaBlend(0xfffff0);
  29. return *this;
  30. }
  31. auto AboutDialog::setName(const string& name) -> type& {
  32. state.name = name;
  33. return *this;
  34. }
  35. auto AboutDialog::setVersion(const string& version) -> type& {
  36. state.version = version;
  37. return *this;
  38. }
  39. auto AboutDialog::setWebsite(const string& website, const string& uri) -> type& {
  40. state.website = website;
  41. state.websiteURI = uri;
  42. return *this;
  43. }
  44. auto AboutDialog::show() -> void {
  45. Window window;
  46. window.onClose([&] { window.setModal(false); });
  47. VerticalLayout layout{&window};
  48. layout.setPadding(5_sx, 5_sy);
  49. Label nameLabel{&layout, Size{~0, 0}};
  50. nameLabel.setCollapsible();
  51. nameLabel.setAlignment(0.5);
  52. nameLabel.setForegroundColor({0, 0, 0});
  53. nameLabel.setFont(Font().setFamily("Georgia").setBold().setSize(36.0));
  54. nameLabel.setText(state.name ? state.name : Application::name());
  55. nameLabel.setVisible((bool)state.name && !(bool)state.logo);
  56. Canvas logoCanvas{&layout, Size{~0, 0}, 5_sy};
  57. logoCanvas.setCollapsible();
  58. if(state.logo) {
  59. image logo{state.logo};
  60. logo.scale(sx(logo.width()), sy(logo.height()));
  61. logoCanvas.setIcon(logo);
  62. } else {
  63. logoCanvas.setVisible(false);
  64. }
  65. Label descriptionLabel{&layout, Size{~0, 0}};
  66. descriptionLabel.setCollapsible();
  67. descriptionLabel.setAlignment(0.5);
  68. descriptionLabel.setForegroundColor({0, 0, 0});
  69. descriptionLabel.setText(state.description);
  70. if(!state.description) descriptionLabel.setVisible(false);
  71. HorizontalLayout versionLayout{&layout, Size{~0, 0}, 0};
  72. versionLayout.setCollapsible();
  73. Label versionLabel{&versionLayout, Size{~0, 0}, 3_sx};
  74. versionLabel.setAlignment(1.0);
  75. versionLabel.setFont(Font().setBold());
  76. versionLabel.setForegroundColor({0, 0, 0});
  77. versionLabel.setText("Version:");
  78. Label versionValue{&versionLayout, Size{~0, 0}};
  79. versionValue.setAlignment(0.0);
  80. versionValue.setFont(Font().setBold());
  81. versionValue.setForegroundColor({0, 0, 0});
  82. versionValue.setText(state.version);
  83. if(!state.version) versionLayout.setVisible(false);
  84. HorizontalLayout copyrightLayout{&layout, Size{~0, 0}, 0};
  85. copyrightLayout.setCollapsible();
  86. Label copyrightLabel{&copyrightLayout, Size{~0, 0}, 3_sx};
  87. copyrightLabel.setAlignment(1.0);
  88. copyrightLabel.setFont(Font().setBold());
  89. copyrightLabel.setForegroundColor({0, 0, 0});
  90. copyrightLabel.setText("Copyright:");
  91. Label copyrightValue{&copyrightLayout, Size{~0, 0}};
  92. copyrightValue.setAlignment(0.0);
  93. copyrightValue.setFont(Font().setBold());
  94. copyrightValue.setForegroundColor({0, 0, 0});
  95. copyrightValue.setText(state.copyright);
  96. if(!state.copyright) copyrightLayout.setVisible(false);
  97. HorizontalLayout licenseLayout{&layout, Size{~0, 0}, 0};
  98. licenseLayout.setCollapsible();
  99. Label licenseLabel{&licenseLayout, Size{~0, 0}, 3_sx};
  100. licenseLabel.setAlignment(1.0);
  101. licenseLabel.setFont(Font().setBold());
  102. licenseLabel.setForegroundColor({0, 0, 0});
  103. licenseLabel.setText("License:");
  104. HorizontalLayout licenseValueLayout{&licenseLayout, Size{~0, 0}};
  105. Label licenseValue{&licenseValueLayout, Size{0, 0}};
  106. licenseValue.setAlignment(0.0);
  107. licenseValue.setFont(Font().setBold());
  108. licenseValue.setForegroundColor({0, 0, 0});
  109. licenseValue.setText(state.license);
  110. if(state.licenseURI) {
  111. licenseValue.setForegroundColor({0, 0, 240});
  112. licenseValue.setMouseCursor(MouseCursor::Hand);
  113. licenseValue.onMouseRelease([&](auto button) {
  114. if(button == Mouse::Button::Left) invoke(state.licenseURI);
  115. });
  116. }
  117. if(!state.license) licenseLayout.setVisible(false);
  118. HorizontalLayout websiteLayout{&layout, Size{~0, 0}, 0};
  119. websiteLayout.setCollapsible();
  120. Label websiteLabel{&websiteLayout, Size{~0, 0}, 3_sx};
  121. websiteLabel.setAlignment(1.0);
  122. websiteLabel.setFont(Font().setBold());
  123. websiteLabel.setForegroundColor({0, 0, 0});
  124. websiteLabel.setText("Website:");
  125. HorizontalLayout websiteValueLayout{&websiteLayout, Size{~0, 0}};
  126. Label websiteValue{&websiteValueLayout, Size{0, 0}};
  127. websiteValue.setAlignment(0.0);
  128. websiteValue.setFont(Font().setBold());
  129. websiteValue.setForegroundColor({0, 0, 0});
  130. websiteValue.setText(state.website);
  131. if(state.websiteURI) {
  132. websiteValue.setForegroundColor({0, 0, 240});
  133. websiteValue.setMouseCursor(MouseCursor::Hand);
  134. websiteValue.onMouseRelease([&](auto button) {
  135. if(button == Mouse::Button::Left) invoke(state.websiteURI);
  136. });
  137. }
  138. if(!state.website) websiteLayout.setVisible(false);
  139. window.setTitle({"About ", state.name ? state.name : Application::name(), " ..."});
  140. window.setBackgroundColor({255, 255, 240});
  141. window.setSize({max(320_sx, layout.minimumSize().width()), layout.minimumSize().height()});
  142. window.setResizable(false);
  143. window.setAlignment(state.relativeTo, state.alignment);
  144. window.setDismissable();
  145. window.setVisible();
  146. window.setModal();
  147. window.setVisible(false);
  148. }
  149. #endif