window.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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 <iostream>
  17. #include <ClanLib/Display/display.h>
  18. #include "globals.hpp"
  19. #include "box.hpp"
  20. #include "icon.hpp"
  21. #include "helper.hpp"
  22. #include "titlebar.hpp"
  23. #include "window.hpp"
  24. class WindowImpl
  25. {
  26. public:
  27. CL_Component* client_area;
  28. CL_Component* parent;
  29. CL_Rect old_position;
  30. bool is_maximized;
  31. Titlebar* titlebar;
  32. Icon* close;
  33. Icon* minimize;
  34. Icon* maximize;
  35. std::vector<CL_Slot> slots;
  36. void draw();
  37. void do_maximize();
  38. void do_close();
  39. void on_resize(int, int);
  40. };
  41. Window::Window(const CL_Rect& rect, const std::string& title, CL_Component* parent)
  42. : CL_Component(rect, parent), impl(new WindowImpl())
  43. {
  44. impl->titlebar = new Titlebar(CL_Rect(CL_Point(3+16,3),
  45. CL_Size(get_width()-6-18-18-18, 12+3)), title,
  46. this);
  47. //Fonts::verdana11.draw(8+15, 3, title);
  48. impl->close = new Icon(CL_Rect(CL_Point(3, 3), CL_Size(18,18)),
  49. make_sprite(datadir + "/images/window/close.png"),
  50. "", this);
  51. impl->minimize = new Icon(CL_Rect(CL_Point(get_width()-3-18-18, 3), CL_Size(18,18)),
  52. make_sprite(datadir + "/images/window/minimize.png"),
  53. "", this);
  54. impl->maximize = new Icon(CL_Rect(CL_Point(get_width()-3-18, 3), CL_Size(18,18)),
  55. make_sprite(datadir + "/images/window/maximize.png"),
  56. "", this);
  57. impl->client_area = new CL_Component(CL_Rect(CL_Point(4, 3+12+7),
  58. CL_Size(rect.get_width()-10,
  59. rect.get_height()-28)), this);
  60. impl->parent = this;
  61. impl->is_maximized = false;
  62. impl->slots.push_back(sig_resize().connect(impl.get(), &WindowImpl::on_resize));
  63. impl->slots.push_back(sig_paint().connect(impl.get(), &WindowImpl::draw));
  64. impl->slots.push_back(impl->maximize->sig_clicked().connect(impl.get(), &WindowImpl::do_maximize));
  65. impl->slots.push_back(impl->close->sig_clicked().connect(impl.get(), &WindowImpl::do_close));
  66. }
  67. Window::~Window()
  68. {
  69. std::cout << "deleting: Window" << std::endl;
  70. }
  71. void
  72. WindowImpl::on_resize(int, int)
  73. {
  74. titlebar->set_position(CL_Rect(CL_Point(3+16,3), CL_Size(parent->get_width()-6-18-18-18, 12+3)));
  75. close->set_position(3, 3);
  76. minimize->set_position(parent->get_width()-3-18-18, 3);
  77. maximize->set_position(parent->get_width()-3-18, 3);
  78. CL_Rect rect = parent->get_position();
  79. client_area->set_position(CL_Rect(CL_Point(4, 3+12+7),
  80. CL_Size(rect.get_width()-10,
  81. rect.get_height()-28)));
  82. }
  83. void
  84. WindowImpl::draw()
  85. {
  86. CL_Display::push_translate (parent->get_screen_x(), parent->get_screen_y());
  87. CL_Color highlight(255, 255, 255);
  88. CL_Color midtone(150, 150, 150);
  89. CL_Rect rect = parent->get_position() ;
  90. Box::draw_window(CL_Rect(CL_Point(0, 0), CL_Size(rect.get_width()-1, rect.get_height()-1)));
  91. Box::draw_panel_down(client_area->get_position());
  92. /*
  93. CL_Display::fill_rect(CL_Rect(CL_Point(0, 0), rect.get_size()), CL_Color(220, 220, 220));
  94. CL_Display::draw_rect(CL_Rect(CL_Point(0, 0), rect.get_size()), CL_Color(0, 0, 0));
  95. CL_Display::draw_line(1, rect.get_height()-2,
  96. rect.get_width()-2, rect.get_height()-2, midtone);
  97. CL_Display::draw_line(rect.get_width()-2, 1,
  98. rect.get_width()-2, rect.get_height()-2, midtone);
  99. CL_Display::draw_line(1, 1,
  100. rect.get_width()-2, 1, highlight);
  101. CL_Display::draw_line(1, 1,
  102. 1, rect.get_height()-2, highlight);
  103. */
  104. CL_Display::pop_modelview();
  105. }
  106. void
  107. WindowImpl::do_close()
  108. {
  109. parent->show(false);
  110. }
  111. void
  112. WindowImpl::do_maximize()
  113. {
  114. // FIXME: Move this to scripting language
  115. if (!is_maximized)
  116. {
  117. is_maximized = true;
  118. old_position = parent->get_position();
  119. parent->set_position(parent->get_parent()->get_position());
  120. }
  121. else
  122. {
  123. is_maximized = false;
  124. parent->set_position(old_position);
  125. }
  126. }
  127. CL_Component*
  128. Window::get_client_area()
  129. {
  130. return impl->client_area;
  131. }
  132. void
  133. Window::hide()
  134. {
  135. CL_Component::show(false);
  136. }
  137. void
  138. Window::show()
  139. {
  140. CL_Component::show(true);
  141. }
  142. /* EOF */