MainContent.cpp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. #include "LinJam.h"
  2. MainContent::MainContent(DocumentWindow* main_window , TextButton* config_button)
  3. {
  4. // MainWindow (parent)
  5. this->mainWindow = main_window ;
  6. this->configButton = config_button ;
  7. this->configButton->setButtonText(TRANS("?")) ;
  8. this->configButton->setColour(TextButton::buttonColourId , Colour(0xff404000)) ;
  9. this->configButton->setColour(TextButton::buttonOnColourId , Colours::olive) ;
  10. this->configButton->setColour(TextButton::textColourOnId , Colours::yellow) ;
  11. this->configButton->setColour(TextButton::textColourOffId , Colours::yellow) ;
  12. this->configButton->addListener(this) ;
  13. // MainContent (this)
  14. setName("MainContent") ;
  15. setSize(GUI::CONTENT_W , GUI::CONTENT_H) ;
  16. }
  17. MainContent::~MainContent()
  18. {
  19. this->background = nullptr ;
  20. this->login = nullptr ;
  21. this->license = nullptr ;
  22. this->chat = nullptr ;
  23. this->mixer = nullptr ;
  24. this->statusbar = nullptr ;
  25. this->loop = nullptr ;
  26. this->config = nullptr ;
  27. }
  28. void MainContent::paint(Graphics& g)
  29. {
  30. g.fillAll (Colour (0xff202020));
  31. g.setFont (Font (16.0f));
  32. g.setColour (Colours::black);
  33. }
  34. void MainContent::resized()
  35. {
  36. if (this->configButton == nullptr ||
  37. this->background == nullptr || this->chat == nullptr ||
  38. this->mixer == nullptr || this->statusbar == nullptr ||
  39. this->loop == nullptr || this->login == nullptr ||
  40. this->license == nullptr || this->config == nullptr ) return ;
  41. int window_w = getWidth() ;
  42. int window_h = getHeight() ;
  43. // config button
  44. #ifdef _MAC
  45. int cfg_btn_x = window_w - GUI::CONFIG_BTN_X - GUI::CONFIG_BTN_W ;
  46. #else // _MAC
  47. int cfg_btn_x = GUI::CONFIG_BTN_X ;
  48. #endif // _MAC
  49. int cfg_btn_y = GUI::CONFIG_BTN_Y ;
  50. int cfg_btn_w = GUI::CONFIG_BTN_W ;
  51. int cfg_btn_h = GUI::CONFIG_BTN_H ;
  52. // main content
  53. int content_w = window_w - GUI::PAD2 ;
  54. int content_h = window_h - GUI::STATUSBAR_H - GUI::PAD3 ;
  55. // bg
  56. int bg_x = 0 ;
  57. int bg_y = 0 ;
  58. int bg_w = window_w ;
  59. int bg_h = window_h ;
  60. // login
  61. int login_x = GUI::PAD ;
  62. int login_y = GUI::PAD ;
  63. int login_w = content_w ;
  64. int login_h = content_h ;
  65. // license
  66. int license_x = GUI::PAD ;
  67. int license_y = GUI::PAD ;
  68. int license_w = content_w ;
  69. int license_h = content_h ;
  70. // mixer div
  71. int mixer_x = GUI::PAD ;
  72. int mixer_y = window_h - GUI::STATUSBAR_H - GUI::MIXER_H - GUI::PAD2 ;
  73. int mixer_w = content_w ;
  74. int mixer_h = GUI::MIXER_H ;
  75. // chat
  76. int chat_x = GUI::PAD ;
  77. int chat_y = GUI::PAD ;
  78. int chat_w = content_w ;
  79. int chat_h = content_h - GUI::MIXER_H - GUI::PAD ;
  80. // statusbar
  81. int status_x = GUI::PAD ;
  82. int status_y = window_h - GUI::STATUSBAR_H - GUI::PAD ;
  83. int status_w = content_w ;
  84. int status_h = GUI::STATUSBAR_H ;
  85. // loop
  86. int loop_x = GUI::LOOP_X ;
  87. int loop_y = status_y + GUI::PAD ;
  88. int loop_w = content_w - GUI::PAD4 - (GUI::STATUS_W * 2) ;
  89. int loop_h = GUI::LOOP_H ;
  90. // config
  91. int config_x = GUI::PAD ;
  92. int config_y = GUI::PAD ;
  93. int config_w = content_w ;
  94. int config_h = content_h ;
  95. this->configButton->setBounds(cfg_btn_x , cfg_btn_y , cfg_btn_w , cfg_btn_h) ;
  96. this->background ->setBounds(bg_x , bg_y , bg_w , bg_h ) ;
  97. this->login ->setBounds(login_x , login_y , login_w , login_h ) ;
  98. this->license ->setBounds(license_x , license_y , license_w , license_h) ;
  99. this->chat ->setBounds(chat_x , chat_y , chat_w , chat_h ) ;
  100. this->mixer ->setBounds(mixer_x , mixer_y , mixer_w , mixer_h ) ;
  101. this->statusbar ->setBounds(status_x , status_y , status_w , status_h ) ;
  102. this->loop ->setBounds(loop_x , loop_y , loop_w , loop_h ) ;
  103. this->config ->setBounds(config_x , config_y , config_w , config_h ) ;
  104. }
  105. void MainContent::instantiate(ValueTree gui_store , ValueTree client_store ,
  106. ValueTree blacklist_store , ValueTree audio_store ,
  107. ValueTree login_store , ValueTree servers_store ,
  108. Value linjam_status )
  109. {
  110. // extract specific values for components that do not require an entire store
  111. Value agreed_value = LinJamConfig::GetValueHolder(login_store , CONFIG::IS_AGREED_ID ) ;
  112. Value agree_value = LinJamConfig::GetValueHolder(login_store , CONFIG::SHOULD_AGREE_ID) ;
  113. Value fontsize_value = LinJamConfig::GetValueHolder(gui_store , CONFIG::FONT_SIZE_ID ) ;
  114. // instantiate components requiring model hooks
  115. this->background = new Background( ) ;
  116. this->config = new Config (audio_store , client_store , gui_store ,
  117. blacklist_store , linjam_status ) ;
  118. this->login = new Login (login_store , servers_store ) ;
  119. this->license = new License (agreed_value , agree_value ) ;
  120. this->chat = new Chat (fontsize_value ) ;
  121. this->mixer = new Mixer (blacklist_store ) ;
  122. this->statusbar = new StatusBar ( ) ;
  123. this->loop = new Loop ( ) ;
  124. this->addChildAndSetID(this->background , GUI::BACKGROUND_GUI_ID) ;
  125. this->addChildAndSetID(this->config , GUI::CONFIG_GUI_ID ) ;
  126. this->addChildAndSetID(this->login , GUI::LOGIN_GUI_ID ) ;
  127. this->addChildAndSetID(this->license , GUI::LICENSE_GUI_ID ) ;
  128. this->addChildAndSetID(this->chat , GUI::CHAT_GUI_ID ) ;
  129. this->addChildAndSetID(this->mixer , GUI::MIXER_GUI_ID ) ;
  130. this->addChildAndSetID(this->statusbar , GUI::STATUS_GUI_ID ) ;
  131. this->addChildAndSetID(this->loop , GUI::LOOP_GUI_ID ) ;
  132. this->background->toFront(true) ;
  133. this->config ->toBack() ;
  134. this->login ->toBack() ;
  135. this->license ->toBack() ;
  136. this->chat ->toBack() ;
  137. this->mixer ->toBack() ;
  138. this->loop ->toFront(false) ;
  139. this->statusbar->setAlwaysOnTop(true) ;
  140. this->loop ->setAlwaysOnTop(true) ;
  141. this->statusbar->setStatusL(GUI::DISCONNECTED_TEXT) ;
  142. this->linjamStatus.referTo(linjam_status) ;
  143. resized() ;
  144. }
  145. void MainContent::setTitle(String title_text)
  146. {
  147. this->mainWindow->setName(GUI::APP_NAME + " - " + title_text) ;
  148. }
  149. void MainContent::buttonClicked(Button* a_button)
  150. {
  151. if (a_button == this->configButton)
  152. this->linjamStatus = APP::LINJAM_STATUS_CONFIGPENDING ;
  153. }