panel_container.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*************************************************************************/
  2. /* panel_container.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #include "panel_container.h"
  30. Size2 PanelContainer::get_minimum_size() const {
  31. Ref<StyleBox> style=get_stylebox("panel");
  32. Size2 ms;
  33. for(int i=0;i<get_child_count();i++) {
  34. Control *c = get_child(i)->cast_to<Control>();
  35. if (!c || !c->is_visible())
  36. continue;
  37. if (c->is_set_as_toplevel())
  38. continue;
  39. Size2 minsize = c->get_combined_minimum_size();
  40. ms.width = MAX(ms.width , minsize.width);
  41. ms.height = MAX(ms.height , minsize.height);
  42. }
  43. if (style.is_valid())
  44. ms+=style->get_minimum_size();
  45. return ms;
  46. }
  47. void PanelContainer::_notification(int p_what) {
  48. if (p_what==NOTIFICATION_DRAW) {
  49. RID ci = get_canvas_item();
  50. Ref<StyleBox> style;
  51. if (has_stylebox("panel"))
  52. style=get_stylebox("panel");
  53. else
  54. style=get_stylebox("panel","PanelContainer");
  55. style->draw( ci, Rect2( Point2(), get_size() ) );
  56. }
  57. if (p_what==NOTIFICATION_SORT_CHILDREN) {
  58. Ref<StyleBox> style;
  59. if (has_stylebox("panel"))
  60. style=get_stylebox("panel");
  61. else
  62. style=get_stylebox("panel","PanelContainer");
  63. Size2 size = get_size();
  64. Point2 ofs;
  65. if (style.is_valid()) {
  66. size-=style->get_minimum_size();
  67. ofs+=style->get_offset();
  68. }
  69. for(int i=0;i<get_child_count();i++) {
  70. Control *c = get_child(i)->cast_to<Control>();
  71. if (!c || !c->is_visible())
  72. continue;
  73. if (c->is_set_as_toplevel())
  74. continue;
  75. fit_child_in_rect(c,Rect2(ofs,size));
  76. }
  77. }
  78. }
  79. PanelContainer::PanelContainer()
  80. {
  81. }