workspace.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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 "workspace.hpp"
  17. #include <ClanLib/Display/display.h>
  18. #include <ClanLib/Display/display_window.h>
  19. #include <ClanLib/Display/keys.h>
  20. #include <assert.h>
  21. #include <iostream>
  22. #include <map>
  23. #include "gui/editor_map_component.hpp"
  24. #include "editor_map.hpp"
  25. #include "editor_names.hpp"
  26. #include "tools/tool.hpp"
  27. #include "tileset.hpp"
  28. Workspace Workspace::current_(false);
  29. class WorkspaceImpl
  30. {
  31. public:
  32. EditorMap editor_map;
  33. typedef std::map<int, Tool> Tools;
  34. Tools tools;
  35. };
  36. Workspace::Workspace(bool create) :
  37. impl()
  38. {
  39. if (create)
  40. {
  41. impl.reset(new WorkspaceImpl());
  42. current_ = *this;
  43. std::cout << "Workspace()" << std::endl;
  44. }
  45. }
  46. void
  47. Workspace::draw(const GraphicContextState& state, CL_GraphicContext* gc)
  48. {
  49. assert(impl.get());
  50. CL_Display::clear(CL_Color(100, 0, 100));
  51. impl->editor_map.draw_gui(CL_Display::get_current_window()->get_gc());
  52. impl->editor_map.draw(EditorMapComponent::current()->get_gc_state(), CL_Display::get_current_window()->get_gc());
  53. // FIXME: Only draw active tool?!
  54. for(WorkspaceImpl::Tools::iterator it = impl->tools.begin();
  55. it != impl->tools.end(); ++it)
  56. it->second.draw();
  57. CL_Display::flush();
  58. }
  59. void
  60. Workspace::mouse_up(const CL_InputEvent& event)
  61. {
  62. assert(impl.get());
  63. WorkspaceImpl::Tools::iterator it = impl->tools.find(event.id);
  64. if (it != impl->tools.end())
  65. it->second.on_mouse_up(event);
  66. }
  67. void
  68. Workspace::mouse_move(const CL_InputEvent& event)
  69. {
  70. assert(impl.get());
  71. for(WorkspaceImpl::Tools::iterator it = impl->tools.begin();
  72. it != impl->tools.end(); ++it)
  73. {
  74. it->second.on_mouse_move(event);
  75. }
  76. }
  77. void
  78. Workspace::mouse_down(const CL_InputEvent& event)
  79. {
  80. assert(impl.get());
  81. WorkspaceImpl::Tools::iterator it = impl->tools.find(event.id);
  82. if (it != impl->tools.end())
  83. it->second.on_mouse_down(event);
  84. switch (event.id)
  85. {
  86. case CL_MOUSE_WHEEL_UP:
  87. EditorMapComponent::current()->zoom_in(event.mouse_pos);
  88. break;
  89. case CL_MOUSE_WHEEL_DOWN:
  90. EditorMapComponent::current()->zoom_out(event.mouse_pos);
  91. break;
  92. }
  93. }
  94. void
  95. Workspace::key_up(const CL_InputEvent& event)
  96. {
  97. assert(impl.get());
  98. WorkspaceImpl::Tools::iterator it = impl->tools.find(event.id);
  99. if (it != impl->tools.end())
  100. it->second.on_mouse_up(event);
  101. }
  102. void
  103. Workspace::key_down(const CL_InputEvent& event)
  104. {
  105. assert(impl.get());
  106. WorkspaceImpl::Tools::iterator it = impl->tools.find(event.id);
  107. if (it != impl->tools.end())
  108. it->second.on_mouse_down(event);
  109. else
  110. std::cout << "Workspace: " << event.id << std::endl;
  111. }
  112. EditorMap
  113. Workspace::get_map()
  114. {
  115. assert(impl.get());
  116. return impl->editor_map;
  117. }
  118. void
  119. Workspace::set_map(const EditorMap& m)
  120. {
  121. assert(impl.get());
  122. impl->editor_map = m;
  123. std::cout << "Workspace:set_map" << std::endl;
  124. }
  125. void
  126. Workspace::set_tool(int button, const Tool& tool)
  127. {
  128. assert(impl.get());
  129. impl->tools[button] = tool;
  130. }
  131. /* EOF */