123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- #include <iostream>
- #include <ClanLib/Display/display.h>
- #include "globals.hpp"
- #include "box.hpp"
- #include "icon.hpp"
- #include "helper.hpp"
- #include "titlebar.hpp"
- #include "window.hpp"
- class WindowImpl
- {
- public:
- CL_Component* client_area;
- CL_Component* parent;
- CL_Rect old_position;
- bool is_maximized;
- Titlebar* titlebar;
- Icon* close;
- Icon* minimize;
- Icon* maximize;
- std::vector<CL_Slot> slots;
- void draw();
- void do_maximize();
- void do_close();
- void on_resize(int, int);
- };
- Window::Window(const CL_Rect& rect, const std::string& title, CL_Component* parent)
- : CL_Component(rect, parent), impl(new WindowImpl())
- {
- impl->titlebar = new Titlebar(CL_Rect(CL_Point(3+16,3),
- CL_Size(get_width()-6-18-18-18, 12+3)), title,
- this);
-
- impl->close = new Icon(CL_Rect(CL_Point(3, 3), CL_Size(18,18)),
- make_sprite(datadir + "/images/window/close.png"),
- "", this);
- impl->minimize = new Icon(CL_Rect(CL_Point(get_width()-3-18-18, 3), CL_Size(18,18)),
- make_sprite(datadir + "/images/window/minimize.png"),
- "", this);
- impl->maximize = new Icon(CL_Rect(CL_Point(get_width()-3-18, 3), CL_Size(18,18)),
- make_sprite(datadir + "/images/window/maximize.png"),
- "", this);
- impl->client_area = new CL_Component(CL_Rect(CL_Point(4, 3+12+7),
- CL_Size(rect.get_width()-10,
- rect.get_height()-28)), this);
- impl->parent = this;
- impl->is_maximized = false;
- impl->slots.push_back(sig_resize().connect(impl.get(), &WindowImpl::on_resize));
- impl->slots.push_back(sig_paint().connect(impl.get(), &WindowImpl::draw));
- impl->slots.push_back(impl->maximize->sig_clicked().connect(impl.get(), &WindowImpl::do_maximize));
- impl->slots.push_back(impl->close->sig_clicked().connect(impl.get(), &WindowImpl::do_close));
- }
- Window::~Window()
- {
- std::cout << "deleting: Window" << std::endl;
- }
- void
- WindowImpl::on_resize(int, int)
- {
- titlebar->set_position(CL_Rect(CL_Point(3+16,3), CL_Size(parent->get_width()-6-18-18-18, 12+3)));
- close->set_position(3, 3);
- minimize->set_position(parent->get_width()-3-18-18, 3);
- maximize->set_position(parent->get_width()-3-18, 3);
- CL_Rect rect = parent->get_position();
- client_area->set_position(CL_Rect(CL_Point(4, 3+12+7),
- CL_Size(rect.get_width()-10,
- rect.get_height()-28)));
- }
- void
- WindowImpl::draw()
- {
- CL_Display::push_translate (parent->get_screen_x(), parent->get_screen_y());
- CL_Color highlight(255, 255, 255);
- CL_Color midtone(150, 150, 150);
- CL_Rect rect = parent->get_position() ;
- Box::draw_window(CL_Rect(CL_Point(0, 0), CL_Size(rect.get_width()-1, rect.get_height()-1)));
- Box::draw_panel_down(client_area->get_position());
-
- CL_Display::pop_modelview();
- }
- void
- WindowImpl::do_close()
- {
- parent->show(false);
- }
- void
- WindowImpl::do_maximize()
- {
-
- if (!is_maximized)
- {
- is_maximized = true;
- old_position = parent->get_position();
- parent->set_position(parent->get_parent()->get_position());
- }
- else
- {
- is_maximized = false;
- parent->set_position(old_position);
- }
- }
- CL_Component*
- Window::get_client_area()
- {
- return impl->client_area;
- }
- void
- Window::hide()
- {
- CL_Component::show(false);
- }
- void
- Window::show()
- {
- CL_Component::show(true);
- }
|