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)
95 Rect intersect = rect_intersection(rect, dirty_region);
96 if(intersect.width && intersect.height) {
97 if(callbacks.display) {
98 callbacks.display(this);
106 void Window::draw_children(const Rect &dirty_region)
108 for(size_t i=0; i<children.size(); i++) {
109 children[i]->draw(dirty_region);
113 unsigned char *Window::get_win_start_on_fb()
115 unsigned char *fb = get_framebuffer();
116 Rect abs_rect = get_absolute_rect();
117 return fb + get_color_depth() * (get_screen_size().x * abs_rect.y + abs_rect.x) / 8;
120 int Window::get_scanline_width()
122 return get_screen_size().x;
125 void Window::set_managed(bool managed)
127 this->managed = managed;
130 bool Window::get_managed() const
135 void Window::set_focusable(bool focusable)
137 this->focusable = focusable;
140 bool Window::get_focusable() const
145 void Window::set_display_callback(DisplayFuncType func)
147 callbacks.display = func;
150 void Window::set_keyboard_callback(KeyboardFuncType func)
152 callbacks.keyboard = func;
155 void Window::set_mouse_button_callback(MouseButtonFuncType func)
157 callbacks.button = func;
160 void Window::set_mouse_motion_callback(MouseMotionFuncType func)
162 callbacks.motion = func;
165 const DisplayFuncType Window::get_display_callback() const
167 return callbacks.display;
170 const KeyboardFuncType Window::get_keyboard_callback() const
172 return callbacks.keyboard;
175 const MouseButtonFuncType Window::get_mouse_button_callback() const
177 return callbacks.button;
180 const MouseMotionFuncType Window::get_mouse_motion_callback() const
182 return callbacks.motion;
185 void Window::add_child(Window *win)
187 children.push_back(win);
189 win->parent->remove_child(win);
194 void Window::remove_child(Window *win)
196 std::vector<Window*>::iterator it;
197 it = std::find(children.begin(), children.end(), win);
198 if(it != children.end()) {
204 Window **Window::get_children()
206 if(children.empty()) {
212 int Window::get_children_count() const
214 return (int)children.size();
217 const Window *Window::get_parent() const
222 Window *Window::get_parent()