ChatList.cpp 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /*\
  2. |*| Copyright 2015 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 Lesser 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 Lesser General Public License for more details.
  14. |*|
  15. |*| You should have received a copy of the GNU Lesser 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 "AvCaster.h"
  20. #include "Trace/TraceChat.h"
  21. //[/Headers]
  22. #include "ChatList.h"
  23. //[MiscUserDefs] You can add your own user definitions and misc code here...
  24. //[/MiscUserDefs]
  25. //==============================================================================
  26. ChatList::ChatList (ValueTree chatters_store)
  27. : chattersStore(chatters_store)
  28. {
  29. addAndMakeVisible (chattersGroup = new GroupComponent ("chattersGroup",
  30. TRANS("(connecting)")));
  31. chattersGroup->setColour (GroupComponent::outlineColourId, Colours::white);
  32. chattersGroup->setColour (GroupComponent::textColourId, Colours::white);
  33. addAndMakeVisible (dummyChatListItem = new ChatListItem (ValueTree::invalid));
  34. dummyChatListItem->setName ("dummyChatListItem");
  35. //[UserPreSize]
  36. //[/UserPreSize]
  37. setSize (128, 48);
  38. //[Constructor] You can add your own custom stuff here..
  39. chattersGroup->setTextLabelPosition(Justification::horizontallyCentred) ;
  40. // hide GUI designer placeholder
  41. this->dummyChatListItem->setVisible(false) ;
  42. // register interest in join/parts
  43. this->chattersStore.addListener(this) ;
  44. //[/Constructor]
  45. }
  46. ChatList::~ChatList()
  47. {
  48. //[Destructor_pre]. You can add your own custom destruction code here..
  49. //[/Destructor_pre]
  50. chattersGroup = nullptr;
  51. dummyChatListItem = nullptr;
  52. //[Destructor]. You can add your own custom destruction code here..
  53. deleteAllChildren() ;
  54. //[/Destructor]
  55. }
  56. //==============================================================================
  57. void ChatList::paint (Graphics& g)
  58. {
  59. //[UserPrePaint] Add your own custom painting code here..
  60. //[/UserPrePaint]
  61. g.setColour (Colour (0xff202020));
  62. g.fillRoundedRectangle (4.0f, 10.0f, 120.0f, 34.0f, 4.000f);
  63. //[UserPaint] Add your own custom painting code here..
  64. g.fillRoundedRectangle(4.0f , 10.0f , getWidth() - 8.0f , getHeight() - 14.0f , 4.000f) ;
  65. //[/UserPaint]
  66. }
  67. void ChatList::resized()
  68. {
  69. //[UserPreResize] Add your own custom resize code here..
  70. //[/UserPreResize]
  71. chattersGroup->setBounds (0, 0, 128, 48);
  72. dummyChatListItem->setBounds (12, 16, 104, 24);
  73. //[UserResized] Add your own custom resize handling here..
  74. this->chattersGroup->setSize(getWidth() , getHeight()) ;
  75. //[/UserResized]
  76. }
  77. //[MiscUserCode] You can add your own definitions of your custom methods or any other code here...
  78. void ChatList::valueTreeChildAdded(ValueTree& chatters_store , ValueTree& chatter_store)
  79. {
  80. int item_idx = sortedChildIdx(chatters_store , chatter_store) ;
  81. ChatListItem* a_list_item = new ChatListItem(chatter_store) ;
  82. DEBUG_TRACE_ADD_CHAT_LIST_ITEM
  83. const MessageManagerLock mmLock ; addAndMakeVisible(a_list_item , item_idx) ;
  84. refresh() ;
  85. }
  86. void ChatList::valueTreeChildRemoved(ValueTree& chatters_store , ValueTree& chatter_store)
  87. {
  88. int item_idx = sortedChildIdx(chatters_store , chatter_store) ;
  89. Component* a_list_item = getChildComponent(item_idx) ;
  90. DEBUG_TRACE_REMOVE_CHAT_LIST_ITEM
  91. const MessageManagerLock mmLock ; delete a_list_item ;
  92. refresh() ;
  93. }
  94. int ChatList::sortedChildIdx(ValueTree& chatters_store , ValueTree& chatter_store)
  95. {
  96. StringArray nicks = AvCaster::GetChatNicks(chatters_store) ;
  97. String nick = STRING(chatter_store[CONFIG::CHAT_NICK_ID]) ;
  98. int item_idx = nicks.indexOf(nick) + GUI::N_STATIC_CHATLIST_CHILDREN ;
  99. DEBUG_TRACE_LOCATE_SORTED_CHILD
  100. return item_idx ;
  101. }
  102. void ChatList::refresh()
  103. {
  104. String server_id = String(this->chattersStore.getParent().getType()) ;
  105. chattersGroup->setText(server_id) ;
  106. int n_list_items = getNumChildComponents() - GUI::N_STATIC_CHATLIST_CHILDREN ;
  107. int list_h = GUI::EMPTY_CHATLIST_H + (n_list_items * GUI::PADDED_CHATLIST_ITEM_H) ;
  108. int list_item_x = GUI::PAD3 ;
  109. int list_item_y = GUI::PAD4 ;
  110. DEBUG_TRACE_RESIZE_CHAT_LIST
  111. setSize(GUI::CHATLIST_W , list_h) ;
  112. // arrange list entries
  113. for (int item_n = 0 ; item_n < n_list_items ; ++item_n)
  114. {
  115. int child_n = item_n + GUI::N_STATIC_CHATLIST_CHILDREN ;
  116. Component* list_item = getChildComponent(child_n) ;
  117. DEBUG_TRACE_MOVE_CHAT_LIST_ITEM
  118. list_item->setTopLeftPosition(list_item_x , list_item_y) ;
  119. list_item_y += GUI::PADDED_CHATLIST_ITEM_H ;
  120. }
  121. (static_cast<Chat*>(getParentComponent()))->refresh() ;
  122. }
  123. //[/MiscUserCode]
  124. //==============================================================================
  125. #if 0
  126. /* -- Introjucer information section --
  127. This is where the Introjucer stores the metadata that describe this GUI layout, so
  128. make changes in here at your peril!
  129. BEGIN_JUCER_METADATA
  130. <JUCER_COMPONENT documentType="Component" className="ChatList" componentName=""
  131. parentClasses="public Component, public ValueTree::Listener"
  132. constructorParams="ValueTree chatters_store" variableInitialisers="chattersStore(chatters_store)"
  133. snapPixels="4" snapActive="1" snapShown="1" overlayOpacity="0.330"
  134. fixedSize="0" initialWidth="128" initialHeight="48">
  135. <BACKGROUND backgroundColour="0">
  136. <ROUNDRECT pos="4 10 120 34" cornerSize="4" fill="solid: ff202020" hasStroke="0"/>
  137. </BACKGROUND>
  138. <GROUPCOMPONENT name="chattersGroup" id="49d2cfd1b8779149" memberName="chattersGroup"
  139. virtualName="" explicitFocusOrder="0" pos="0 0 128 48" outlinecol="ffffffff"
  140. textcol="ffffffff" title="(connecting)"/>
  141. <GENERICCOMPONENT name="dummyChatListItem" id="56b906e64be2f4b6" memberName="dummyChatListItem"
  142. virtualName="" explicitFocusOrder="0" pos="12 16 104 24" class="ChatListItem"
  143. params="ValueTree::invalid"/>
  144. </JUCER_COMPONENT>
  145. END_JUCER_METADATA
  146. */
  147. #endif
  148. //[EndFile] You can add extra defines here...
  149. //[/EndFile]