MainContent.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. /*\
  2. |*| Copyright 2015-2016 bill-auger <https://github.com/bill-auger/av-caster/issues>
  3. |*|
  4. |*| This file is part of the AvCaster program.
  5. |*|
  6. |*| AvCaster is free software: you can redistribute it and/or modify
  7. |*| it under the terms of the GNU General Public License version 3
  8. |*| as published by the Free Software Foundation.
  9. |*|
  10. |*| AvCaster is distributed in the hope that it will be useful,
  11. |*| but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. |*| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. |*| GNU General Public License for more details.
  14. |*|
  15. |*| You should have received a copy of the GNU General Public License
  16. |*| along with AvCaster. If not, see <http://www.gnu.org/licenses/>.
  17. \*/
  18. //[Headers] You can add your own extra header files here...
  19. #include "../Controllers/AvCaster.h"
  20. #include "../Trace/Trace.h"
  21. //[/Headers]
  22. #include "MainContent.h"
  23. //[MiscUserDefs] You can add your own user definitions and misc code here...
  24. //[/MiscUserDefs]
  25. //==============================================================================
  26. MainContent::MainContent ()
  27. {
  28. addAndMakeVisible (background = new Background());
  29. background->setName ("background");
  30. addAndMakeVisible (controls = new Controls (this));
  31. controls->setName ("controls");
  32. addAndMakeVisible (chat = new Chat (this));
  33. chat->setName ("chat");
  34. addAndMakeVisible (preview = new Preview());
  35. preview->setName ("preview");
  36. addAndMakeVisible (presets = new Presets (this));
  37. presets->setName ("presets");
  38. addAndMakeVisible (config = new Config (this));
  39. config->setName ("config");
  40. addAndMakeVisible (statusbar = new Statusbar());
  41. statusbar->setName ("statusbar");
  42. //[UserPreSize]
  43. //[/UserPreSize]
  44. setSize (758, 762);
  45. //[Constructor] You can add your own custom stuff here..
  46. setSize(GUI::WINDOW_W , GUI::WINDOW_H) ;
  47. this->mainWindow = static_cast<DocumentWindow*>(getTopLevelComponent()) ;
  48. #ifdef TRAY_ICON
  49. this->trayIcon = new AvCasterTrayIconComponent(this->mainWindow) ;
  50. #endif // TRAY_ICON
  51. this->background->toFront(true) ;
  52. this->statusbar ->setAlwaysOnTop(true) ;
  53. this->statusbar ->setStatusL(GUI::INIT_STATUS_TEXT) ;
  54. //[/Constructor]
  55. }
  56. MainContent::~MainContent()
  57. {
  58. //[Destructor_pre]. You can add your own custom destruction code here..
  59. //[/Destructor_pre]
  60. background = nullptr;
  61. controls = nullptr;
  62. chat = nullptr;
  63. preview = nullptr;
  64. presets = nullptr;
  65. config = nullptr;
  66. statusbar = nullptr;
  67. //[Destructor]. You can add your own custom destruction code here..
  68. //[/Destructor]
  69. }
  70. //==============================================================================
  71. void MainContent::paint (Graphics& g)
  72. {
  73. //[UserPrePaint] Add your own custom painting code here..
  74. //[/UserPrePaint]
  75. g.fillAll (Colour (0xff101010));
  76. //[UserPaint] Add your own custom painting code here..
  77. //[/UserPaint]
  78. }
  79. void MainContent::resized()
  80. {
  81. //[UserPreResize] Add your own custom resize code here..
  82. //[/UserPreResize]
  83. background->setBounds (0, 0, getWidth() - 0, getHeight() - 0);
  84. controls->setBounds (0, 0, getWidth() - 0, 76);
  85. chat->setBounds (0, 76, getWidth() - 0, getHeight() - 100);
  86. preview->setBounds (0, 76, getWidth() - 0, getHeight() - 100);
  87. presets->setBounds (0, 0, getWidth() - 0, 76);
  88. config->setBounds (0, 76, getWidth() - 0, getHeight() - 100);
  89. statusbar->setBounds (0, getHeight() - 24, getWidth() - 0, 24);
  90. //[UserResized] Add your own custom resize handling here..
  91. //[/UserResized]
  92. }
  93. //[MiscUserCode] You can add your own definitions of your custom methods or any other code here...
  94. void MainContent::configureButton(Button* a_button , Button::Listener* a_button_listener)
  95. {
  96. a_button->addListener(a_button_listener) ;
  97. }
  98. void MainContent::configureSlider(Slider* a_slider , Slider::Listener* a_slider_listener ,
  99. double min_val , double max_val ,
  100. double step )
  101. {
  102. a_slider->setColour(Slider::textBoxBackgroundColourId , GUI::TEXT_BG_COLOR ) ;
  103. a_slider->setColour(Slider::textBoxTextColourId , GUI::TEXT_NORMAL_COLOR ) ;
  104. a_slider->setColour(CaretComponent::caretColourId , GUI::TEXT_CARET_COLOR ) ;
  105. a_slider->setColour(TextEditor::highlightColourId , GUI::TEXT_HILITEBG_COLOR) ;
  106. a_slider->setColour(TextEditor::highlightedTextColourId , GUI::TEXT_HILITE_COLOR ) ;
  107. a_slider->setRange(min_val , max_val , step) ;
  108. a_slider->addListener(a_slider_listener) ;
  109. }
  110. void MainContent::configureTextEditor(TextEditor* a_text_editor ,
  111. TextEditor::Listener* a_text_listener ,
  112. int max_n_chars ,
  113. const String allowed_chars )
  114. {
  115. a_text_editor->setSelectAllWhenFocused(true) ;
  116. a_text_editor->setInputRestrictions(max_n_chars , allowed_chars) ;
  117. a_text_editor->setColour(CaretComponent::caretColourId , GUI::TEXT_CARET_COLOR ) ;
  118. a_text_editor->setColour(TextEditor::backgroundColourId , GUI::TEXT_BG_COLOR ) ;
  119. a_text_editor->setColour(TextEditor::textColourId , GUI::TEXT_NORMAL_COLOR ) ;
  120. a_text_editor->setColour(TextEditor::highlightColourId , GUI::TEXT_HILITEBG_COLOR) ;
  121. a_text_editor->setColour(TextEditor::highlightedTextColourId , GUI::TEXT_HILITE_COLOR ) ;
  122. a_text_editor->setColour(TextEditor::outlineColourId , GUI::TEXT_BG_COLOR ) ;
  123. a_text_editor->setColour(TextEditor::focusedOutlineColourId , GUI::TEXT_FOCUS_COLOR ) ;
  124. a_text_editor->setColour(TextEditor::shadowColourId , GUI::TEXT_SHADOW_COLOR ) ;
  125. a_text_editor->addListener(a_text_listener) ;
  126. }
  127. void MainContent::configureCombobox(ComboBox* a_combobox ,
  128. ComboBox::Listener* a_combobox_listener)
  129. {
  130. a_combobox->setColour(ComboBox::textColourId , GUI::TEXT_NORMAL_COLOR ) ;
  131. a_combobox->setColour(ComboBox::backgroundColourId , GUI::TEXT_BG_COLOR ) ;
  132. a_combobox->setColour(TextEditor::highlightColourId , GUI::TEXT_HILITEBG_COLOR) ;
  133. a_combobox->setColour(TextEditor::highlightedTextColourId , GUI::TEXT_HILITE_COLOR ) ;
  134. a_combobox->setColour(CaretComponent::caretColourId , GUI::TEXT_CARET_COLOR ) ;
  135. if (a_combobox_listener == nullptr) return ;
  136. a_combobox->addListener(a_combobox_listener) ;
  137. }
  138. void MainContent::loadPresetsCombo(ComboBox* a_combobox)
  139. {
  140. StringArray preset_names = AvCaster::GetPresetsNames() ;
  141. int preset_idx = AvCaster::GetPresetIdx() ;
  142. a_combobox->clear (juce::dontSendNotification) ;
  143. a_combobox->addItemList (preset_names , 1) ;
  144. a_combobox->setSelectedItemIndex(preset_idx , juce::dontSendNotification) ;
  145. }
  146. Colour MainContent::btnTickColor(bool is_active)
  147. {
  148. return (is_active) ? Colours::green : Colours::white ;
  149. }
  150. Colour MainContent::btnTextColor(bool is_active)
  151. {
  152. return (is_active) ? Colours::lime : Colours::white ;
  153. }
  154. void MainContent::initialize(ValueTree config_store , ValueTree network_store ,
  155. ValueTree chatters_store , NamedValueSet& disabled_features)
  156. {
  157. this->controls ->initialize(config_store , disabled_features) ;
  158. this->config ->initialize(config_store , network_store ) ;
  159. this->chat->chatList->initialize(network_store , chatters_store ) ;
  160. }
  161. void MainContent::warning(String message_text)
  162. {
  163. if (JUCEApplicationBase::getInstance()->isInitialising()) return ;
  164. AlertWindow::showMessageBoxAsync(AlertWindow::InfoIcon , GUI::MODAL_WARNING_TITLE ,
  165. message_text , String::empty ,
  166. nullptr , AvCaster::GetModalCb() ) ;
  167. }
  168. void MainContent::error(String message_text)
  169. {
  170. if (JUCEApplicationBase::getInstance()->isInitialising()) return ;
  171. AlertWindow::showMessageBoxAsync(AlertWindow::WarningIcon , GUI::MODAL_ERROR_TITLE ,
  172. message_text , String::empty ,
  173. nullptr , AvCaster::GetModalCb() ) ;
  174. }
  175. Rectangle<int> MainContent::getPreviewBounds()
  176. {
  177. Rectangle<int> preview_bounds = this->preview->getBounds() ;
  178. Rectangle<int> group_bounds = this->preview->getChildComponent(0)->getBounds() ;
  179. preview_bounds.setX (group_bounds .getX() + GUI::PAD4) ;
  180. preview_bounds.setY (preview_bounds.getY() + GUI::PAD4 + GUI::PAD8) ;
  181. preview_bounds.setWidth (group_bounds .getWidth() - GUI::PAD8) ;
  182. preview_bounds.setHeight(group_bounds .getHeight() - GUI::PAD8) ;
  183. return preview_bounds ;
  184. }
  185. #ifdef TRAY_ICON
  186. void AvCasterTrayIconComponent::mouseDown(const MouseEvent& mouse_event)
  187. {
  188. if (mouse_event.mods.isLeftButtonDown())
  189. this->mainWindow->setMinimised(!this->mainWindow->isMinimised()) ;
  190. else if (mouse_event.mods.isRightButtonDown()) ;
  191. // Juce Note: that for detecting popupmenu clicks, you should be using isPopupMenu()
  192. }
  193. #endif // TRAY_ICON
  194. //[/MiscUserCode]
  195. //==============================================================================
  196. #if 0
  197. /* -- Introjucer information section --
  198. This is where the Introjucer stores the metadata that describe this GUI layout, so
  199. make changes in here at your peril!
  200. BEGIN_JUCER_METADATA
  201. <JUCER_COMPONENT documentType="Component" className="MainContent" componentName=""
  202. parentClasses="public Component" constructorParams="" variableInitialisers=""
  203. snapPixels="8" snapActive="1" snapShown="1" overlayOpacity="0.330"
  204. fixedSize="1" initialWidth="758" initialHeight="762">
  205. <BACKGROUND backgroundColour="ff101010"/>
  206. <GENERICCOMPONENT name="background" id="4d43eef09b00fdf4" memberName="background"
  207. virtualName="" explicitFocusOrder="0" pos="0 0 0M 0M" class="Background"
  208. params=""/>
  209. <GENERICCOMPONENT name="controls" id="7a0ffc87dbd1f2a3" memberName="controls" virtualName=""
  210. explicitFocusOrder="0" pos="0 0 0M 76" class="Controls" params="this"/>
  211. <GENERICCOMPONENT name="chat" id="ac9a4042c98734e2" memberName="chat" virtualName=""
  212. explicitFocusOrder="0" pos="0 76 0M 100M" class="Chat" params="this"/>
  213. <GENERICCOMPONENT name="preview" id="75e8b11c95e2efaf" memberName="preview" virtualName=""
  214. explicitFocusOrder="0" pos="0 76 0M 100M" class="Preview" params=""/>
  215. <GENERICCOMPONENT name="presets" id="c3256eaa517d34eb" memberName="presets" virtualName=""
  216. explicitFocusOrder="0" pos="0 0 0M 76" class="Presets" params="this"/>
  217. <GENERICCOMPONENT name="config" id="4f3cab5613666ef6" memberName="config" virtualName=""
  218. explicitFocusOrder="0" pos="0 76 0M 100M" class="Config" params="this"/>
  219. <GENERICCOMPONENT name="statusbar" id="2dc0514b582b96cb" memberName="statusbar"
  220. virtualName="" explicitFocusOrder="0" pos="0 0Rr 0M 24" class="Statusbar"
  221. params=""/>
  222. </JUCER_COMPONENT>
  223. END_JUCER_METADATA
  224. */
  225. #endif
  226. //[EndFile] You can add extra defines here...
  227. //[/EndFile]