gui_manager.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. // Flexlay - A Generic 2D Game Editor
  2. // Copyright (C) 2002 Ingo Ruhnke <grumbel@gmx.de>
  3. //
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. #include <ClanLib/gui.h>
  17. #include <ClanLib/guistylesilver.h>
  18. #include <ClanLib/core.h>
  19. #include "globals.hpp"
  20. #include "gui_manager.hpp"
  21. GUIManager* GUIManager::current_ = 0;
  22. class GUIManagerImpl
  23. {
  24. public:
  25. std::stack<CL_Component*> components;
  26. CL_GUIManager* manager;
  27. CL_StyleManager* style;
  28. CL_ResourceManager* resources;
  29. CL_SlotContainer* slot_container;
  30. };
  31. GUIManager::GUIManager()
  32. : impl(new GUIManagerImpl())
  33. {
  34. std::cout << "Creating GUIManager: " << datadir + "/gui/gui.xml" << std::endl;
  35. impl->slot_container = new CL_SlotContainer();
  36. impl->resources = new CL_ResourceManager(datadir + "/gui/gui.xml");
  37. impl->style = new CL_StyleManager_Silver(impl->resources);
  38. impl->manager = new CL_GUIManager(impl->style);
  39. current_ = this;
  40. // Make the manager the first component on the stack
  41. push_component(impl->manager);
  42. }
  43. GUIManager::~GUIManager()
  44. {
  45. pop_component();
  46. delete impl->manager;
  47. //delete style; FIXME: Memory hole?!
  48. //delete resources; FIXME: Memory hole?!
  49. delete impl->slot_container;
  50. }
  51. void
  52. GUIManager::draw()
  53. {
  54. if (impl->manager->is_input_enabled())
  55. impl->manager->show();
  56. }
  57. void
  58. GUIManager::update()
  59. {
  60. // nothing to do
  61. }
  62. void
  63. GUIManager::run()
  64. {
  65. impl->manager->run();
  66. }
  67. CL_Component*
  68. GUIManager::get_component()
  69. {
  70. return impl->components.top();
  71. }
  72. CL_SlotContainer*
  73. GUIManager::get_slot_container()
  74. {
  75. return impl->slot_container;
  76. }
  77. void
  78. GUIManager::hide()
  79. {
  80. if (impl->manager->is_input_enabled())
  81. impl->manager->disable_input();
  82. }
  83. void
  84. GUIManager::show()
  85. {
  86. if (!impl->manager->is_input_enabled())
  87. impl->manager->enable_input();
  88. }
  89. bool
  90. GUIManager::is_visible()
  91. {
  92. return impl->manager->is_input_enabled();
  93. }
  94. void
  95. GUIManager::quit()
  96. {
  97. impl->manager->quit();
  98. }
  99. void
  100. GUIManager::push_component(CL_Component* c)
  101. {
  102. impl->components.push(c);
  103. }
  104. void
  105. GUIManager::pop_component()
  106. {
  107. impl->components.pop();
  108. }
  109. /* EOF */