13 rect.width = rect.height = 128;
14 memset(&callbacks, 0, sizeof callbacks);
22 for(size_t i=0; i<children.size(); i++) {
23 wm->remove_window(children[i]);
30 const Rect &Window::get_rect() const
35 Rect Window::get_absolute_rect() const
42 absolute_rect = parent->get_absolute_rect();
44 absolute_rect.x += rect.x;
45 absolute_rect.y += rect.y;
46 absolute_rect.width = rect.width;
47 absolute_rect.height = rect.height;
52 bool Window::contains_point(int ptr_x, int ptr_y)
54 Rect abs_rect = get_absolute_rect();
55 return ptr_x >= abs_rect.x && ptr_x < abs_rect.x + abs_rect.width &&
56 ptr_y >= abs_rect.y && ptr_y < abs_rect.y + abs_rect.height;
59 void Window::move(int x, int y)
61 invalidate(); // moved, should redraw, MUST BE CALLED FIRST
66 void Window::resize(int x, int y)
68 invalidate(); // resized, should redraw, MUST BE CALLED FIRST
73 void Window::set_title(const char *s)
77 title = new char[strlen(s) + 1];
81 const char *Window::get_title() const
86 void Window::invalidate()
89 Rect abs_rect = get_absolute_rect();
90 wm->invalidate_region(abs_rect);
93 void Window::draw(const Rect &dirty_region)
98 Rect intersect = rect_intersection(rect, dirty_region);
99 if(intersect.width && intersect.height) {
100 if(callbacks.display) {
101 callbacks.display(this);
109 void Window::draw_children(const Rect &dirty_region)
111 for(size_t i=0; i<children.size(); i++) {
112 children[i]->draw(dirty_region);
116 unsigned char *Window::get_win_start_on_fb()
118 unsigned char *fb = get_framebuffer();
119 Rect abs_rect = get_absolute_rect();
120 return fb + get_color_depth() * (get_screen_size().x * abs_rect.y + abs_rect.x) / 8;
123 int Window::get_scanline_width()
125 return get_screen_size().x;
128 void Window::set_managed(bool managed)
130 this->managed = managed;
133 bool Window::get_managed() const
138 void Window::set_focusable(bool focusable)
140 this->focusable = focusable;
143 bool Window::get_focusable() const
148 void Window::set_display_callback(DisplayFuncType func)
150 callbacks.display = func;
153 void Window::set_keyboard_callback(KeyboardFuncType func)
155 callbacks.keyboard = func;
158 void Window::set_mouse_button_callback(MouseButtonFuncType func)
160 callbacks.button = func;
163 void Window::set_mouse_motion_callback(MouseMotionFuncType func)
165 callbacks.motion = func;
168 const DisplayFuncType Window::get_display_callback() const
170 return callbacks.display;
173 const KeyboardFuncType Window::get_keyboard_callback() const
175 return callbacks.keyboard;
178 const MouseButtonFuncType Window::get_mouse_button_callback() const
180 return callbacks.button;
183 const MouseMotionFuncType Window::get_mouse_motion_callback() const
185 return callbacks.motion;
188 void Window::add_child(Window *win)
190 children.push_back(win);
192 win->parent->remove_child(win);
197 void Window::remove_child(Window *win)
199 std::vector<Window*>::iterator it;
200 it = std::find(children.begin(), children.end(), win);
201 if(it != children.end()) {
207 Window **Window::get_children()
209 if(children.empty()) {
215 int Window::get_children_count() const
217 return (int)children.size();
220 const Window *Window::get_parent() const
225 Window *Window::get_parent()