You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

224 lines
8.5KB

  1. /* Copyright 2013-2019 Matt Tytel
  2. *
  3. * vital is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 3 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * vital is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with vital. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "about_section.h"
  17. #include "skin.h"
  18. #include "fonts.h"
  19. #include "load_save.h"
  20. #include "paths.h"
  21. #include "synth_gui_interface.h"
  22. #include "synth_section.h"
  23. #include "text_look_and_feel.h"
  24. namespace {
  25. void setColorRecursively(Component *component, int color_id, const Colour& color) {
  26. component->setColour(color_id, color);
  27. for (Component *child : component->getChildren())
  28. setColorRecursively(child, color_id, color);
  29. }
  30. }
  31. AboutSection::AboutSection(const String& name) : Overlay(name), body_(Shaders::kRoundedRectangleFragment) {
  32. addOpenGlComponent(&body_);
  33. logo_ = std::make_unique<AppLogo>("logo");
  34. addOpenGlComponent(logo_.get());
  35. name_text_ = std::make_unique<PlainTextComponent>("plugin name", "VITALIUM");
  36. addOpenGlComponent(name_text_.get());
  37. name_text_->setFontType(PlainTextComponent::kRegular);
  38. name_text_->setTextSize(40.0f);
  39. version_text_ = std::make_unique<PlainTextComponent>("version", String("version ") + ProjectInfo::versionString);
  40. addOpenGlComponent(version_text_.get());
  41. version_text_->setFontType(PlainTextComponent::kLight);
  42. version_text_->setTextSize(12.0f);
  43. fork_text_ = std::make_unique<PlainTextComponent>("About fork",
  44. String("Original Vital plugin by Matt Tytel\nVitalium fork by falkTX\nLogo design by unfa"));
  45. addOpenGlComponent(fork_text_.get());
  46. fork_text_->setFontType(PlainTextComponent::kLight);
  47. fork_text_->setTextSize(14.0f);
  48. fork_text_->setJustification(Justification::centredLeft);
  49. size_button_extra_small_ = std::make_unique<OpenGlToggleButton>(String(100 * kMultExtraSmall) + "%");
  50. size_button_extra_small_->setUiButton(false);
  51. addAndMakeVisible(size_button_extra_small_.get());
  52. addOpenGlComponent(size_button_extra_small_->getGlComponent());
  53. size_button_extra_small_->addListener(this);
  54. size_button_small_ = std::make_unique<OpenGlToggleButton>(String(100 * kMultSmall) + "%");
  55. size_button_small_->setUiButton(false);
  56. addAndMakeVisible(size_button_small_.get());
  57. addOpenGlComponent(size_button_small_->getGlComponent());
  58. size_button_small_->addListener(this);
  59. size_button_normal_ = std::make_unique<OpenGlToggleButton>(String("100") + "%");
  60. size_button_normal_->setUiButton(false);
  61. addAndMakeVisible(size_button_normal_.get());
  62. addOpenGlComponent(size_button_normal_->getGlComponent());
  63. size_button_normal_->addListener(this);
  64. size_button_large_ = std::make_unique<OpenGlToggleButton>(String(100 * kMultLarge) + "%");
  65. size_button_large_->setUiButton(false);
  66. addAndMakeVisible(size_button_large_.get());
  67. addOpenGlComponent(size_button_large_->getGlComponent());
  68. size_button_large_->addListener(this);
  69. size_button_double_ = std::make_unique<OpenGlToggleButton>(String(100 * kMultDouble) + "%");
  70. size_button_double_->setUiButton(false);
  71. addAndMakeVisible(size_button_double_.get());
  72. addOpenGlComponent(size_button_double_->getGlComponent());
  73. size_button_double_->addListener(this);
  74. size_button_triple_ = std::make_unique<OpenGlToggleButton>(String(100 * kMultTriple) + "%");
  75. size_button_triple_->setUiButton(false);
  76. addAndMakeVisible(size_button_triple_.get());
  77. addOpenGlComponent(size_button_triple_->getGlComponent());
  78. size_button_triple_->addListener(this);
  79. size_button_quadruple_ = std::make_unique<OpenGlToggleButton>(String(100 * kMultQuadruple) + "%");
  80. size_button_quadruple_->setUiButton(false);
  81. addAndMakeVisible(size_button_quadruple_.get());
  82. addOpenGlComponent(size_button_quadruple_->getGlComponent());
  83. size_button_quadruple_->addListener(this);
  84. }
  85. AboutSection::~AboutSection() = default;
  86. void AboutSection::setLogoBounds() {
  87. Rectangle<int> info_rect = getInfoRect();
  88. int left_buffer = kLeftLogoBuffer * size_ratio_;
  89. logo_->setBounds(info_rect.getX() + left_buffer, info_rect.getY() + (kPaddingY + 12) * size_ratio_,
  90. kLogoWidth * size_ratio_, kLogoWidth * size_ratio_);
  91. }
  92. void AboutSection::resized() {
  93. Rectangle<int> info_rect = getInfoRect();
  94. body_.setBounds(info_rect);
  95. body_.setRounding(findValue(Skin::kBodyRounding));
  96. body_.setColor(findColour(Skin::kBody, true));
  97. Colour body_text = findColour(Skin::kBodyText, true);
  98. name_text_->setColor(body_text);
  99. version_text_->setColor(body_text);
  100. fork_text_->setColor(body_text);
  101. int padding_x = size_ratio_ * kPaddingX;
  102. int padding_y = size_ratio_ * kPaddingY;
  103. int button_height = size_ratio_ * kButtonHeight;
  104. if (isVisible())
  105. setLogoBounds();
  106. int name_x = (kLogoWidth + kLeftLogoBuffer) * size_ratio_;
  107. name_text_->setBounds(info_rect.getX() + name_x, info_rect.getY() + padding_y + 40 * size_ratio_,
  108. info_rect.getWidth() - name_x - kNameRightBuffer * size_ratio_, 40 * size_ratio_);
  109. version_text_->setBounds(info_rect.getX() + name_x, info_rect.getY() + padding_y + 76 * size_ratio_,
  110. info_rect.getWidth() - name_x - kNameRightBuffer * size_ratio_, 32 * size_ratio_);
  111. fork_text_->setBounds(info_rect.getX() + name_x/2, info_rect.getY() + padding_y + 110 * size_ratio_,
  112. info_rect.getWidth() + name_x, 70 * size_ratio_);
  113. int size_padding = 5 * size_ratio_;
  114. int size_start_x = info_rect.getX() + padding_x;
  115. int size_end_x = info_rect.getRight() - padding_x + size_padding;
  116. std::vector<OpenGlToggleButton*> size_buttons = {
  117. size_button_extra_small_.get(),
  118. size_button_small_.get(),
  119. size_button_normal_.get(),
  120. size_button_large_.get(),
  121. size_button_double_.get(),
  122. size_button_triple_.get(),
  123. size_button_quadruple_.get(),
  124. };
  125. float size_width = (size_end_x - size_start_x) * 1.0f / size_buttons.size() - size_padding;
  126. int size_y = padding_y;
  127. int index = 0;
  128. for (OpenGlToggleButton* size_button : size_buttons) {
  129. int start_x = std::round(size_start_x + index * (size_width + size_padding));
  130. size_button->setBounds(start_x, size_y, size_width, button_height);
  131. index++;
  132. }
  133. name_text_->setTextSize(40.0f * size_ratio_);
  134. version_text_->setTextSize(12.0f * size_ratio_);
  135. fork_text_->setTextSize(14.0f * size_ratio_);
  136. Overlay::resized();
  137. }
  138. void AboutSection::mouseUp(const MouseEvent &e) {
  139. if (!getInfoRect().contains(e.getPosition()))
  140. setVisible(false);
  141. }
  142. void AboutSection::setVisible(bool should_be_visible) {
  143. if (should_be_visible) {
  144. setLogoBounds();
  145. Image image(Image::ARGB, 1, 1, false);
  146. Graphics g(image);
  147. paintOpenGlChildrenBackgrounds(g);
  148. }
  149. Overlay::setVisible(should_be_visible);
  150. }
  151. void AboutSection::buttonClicked(Button* clicked_button) {
  152. if (clicked_button == size_button_extra_small_.get())
  153. setGuiSize(kMultExtraSmall);
  154. else if (clicked_button == size_button_small_.get())
  155. setGuiSize(kMultSmall);
  156. else if (clicked_button == size_button_normal_.get())
  157. setGuiSize(1.0);
  158. else if (clicked_button == size_button_large_.get())
  159. setGuiSize(kMultLarge);
  160. else if (clicked_button == size_button_double_.get())
  161. setGuiSize(kMultDouble);
  162. else if (clicked_button == size_button_triple_.get())
  163. setGuiSize(kMultTriple);
  164. else if (clicked_button == size_button_quadruple_.get())
  165. setGuiSize(kMultQuadruple);
  166. }
  167. Rectangle<int> AboutSection::getInfoRect() {
  168. int info_height = kBasicInfoHeight * size_ratio_;
  169. int info_width = kInfoWidth * size_ratio_;
  170. int x = (getWidth() - info_width) / 2;
  171. int y = (getHeight() - info_width) / 2;
  172. return Rectangle<int>(x, y, info_width, info_height);
  173. }
  174. void AboutSection::setGuiSize(float multiplier) {
  175. if (Desktop::getInstance().getKioskModeComponent()) {
  176. Desktop::getInstance().setKioskModeComponent(nullptr);
  177. return;
  178. }
  179. float percent = sqrtf(multiplier);
  180. SynthGuiInterface* parent = findParentComponentOfClass<SynthGuiInterface>();
  181. if (parent)
  182. parent->setGuiSize(percent);
  183. }
  184. void AboutSection::fullScreen() {
  185. if (Desktop::getInstance().getKioskModeComponent())
  186. Desktop::getInstance().setKioskModeComponent(nullptr);
  187. else
  188. Desktop::getInstance().setKioskModeComponent(getTopLevelComponent());
  189. }