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 abs_rect = get_absolute_rect();
96 Rect intersect = rect_intersection(abs_rect, dirty_region);
97 if(intersect.width && intersect.height) {
98 if(callbacks.display) {
99 callbacks.display(this);
103 draw_children(abs_rect);
107 void Window::draw_children(const Rect &dirty_region)
109 for(size_t i=0; i<children.size(); i++) {
110 children[i]->draw(dirty_region);
114 unsigned char *Window::get_win_start_on_fb()
116 unsigned char *fb = get_framebuffer();
117 Rect abs_rect = get_absolute_rect();
118 return fb + get_color_depth() * (get_screen_size().x * abs_rect.y + abs_rect.x) / 8;
121 int Window::get_scanline_width()
123 return get_screen_size().x;
126 void Window::set_managed(bool managed)
128 this->managed = managed;
131 bool Window::get_managed() const
136 void Window::set_focusable(bool focusable)
138 this->focusable = focusable;
141 bool Window::get_focusable() const
146 bool Window::get_dirty() const
151 void Window::set_display_callback(DisplayFuncType func)
153 callbacks.display = func;
156 void Window::set_keyboard_callback(KeyboardFuncType func)
158 callbacks.keyboard = func;
161 void Window::set_mouse_button_callback(MouseButtonFuncType func)
163 callbacks.button = func;
166 void Window::set_mouse_motion_callback(MouseMotionFuncType func)
168 callbacks.motion = func;
171 const DisplayFuncType Window::get_display_callback() const
173 return callbacks.display;
176 const KeyboardFuncType Window::get_keyboard_callback() const
178 return callbacks.keyboard;
181 const MouseButtonFuncType Window::get_mouse_button_callback() const
183 return callbacks.button;
186 const MouseMotionFuncType Window::get_mouse_motion_callback() const
188 return callbacks.motion;
191 void Window::add_child(Window *win)
193 children.push_back(win);
195 win->parent->remove_child(win);
200 void Window::remove_child(Window *win)
202 std::vector<Window*>::iterator it;
203 it = std::find(children.begin(), children.end(), win);
204 if(it != children.end()) {
210 Window **Window::get_children()
212 if(children.empty()) {
218 int Window::get_children_count() const
220 return (int)children.size();
223 const Window *Window::get_parent() const
228 Window *Window::get_parent()