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 void Window::set_display_callback(DisplayFuncType func)
148 callbacks.display = func;
151 void Window::set_keyboard_callback(KeyboardFuncType func)
153 callbacks.keyboard = func;
156 void Window::set_mouse_button_callback(MouseButtonFuncType func)
158 callbacks.button = func;
161 void Window::set_mouse_motion_callback(MouseMotionFuncType func)
163 callbacks.motion = func;
166 const DisplayFuncType Window::get_display_callback() const
168 return callbacks.display;
171 const KeyboardFuncType Window::get_keyboard_callback() const
173 return callbacks.keyboard;
176 const MouseButtonFuncType Window::get_mouse_button_callback() const
178 return callbacks.button;
181 const MouseMotionFuncType Window::get_mouse_motion_callback() const
183 return callbacks.motion;
186 void Window::add_child(Window *win)
188 children.push_back(win);
190 win->parent->remove_child(win);
195 void Window::remove_child(Window *win)
197 std::vector<Window*>::iterator it;
198 it = std::find(children.begin(), children.end(), win);
199 if(it != children.end()) {
205 Window **Window::get_children()
207 if(children.empty()) {
213 int Window::get_children_count() const
215 return (int)children.size();
218 const Window *Window::get_parent() const
223 Window *Window::get_parent()