2 #include <stdio.h> //TODO
14 rect.width = rect.height = 128;
15 memset(&callbacks, 0, sizeof callbacks);
23 for(size_t i=0; i<children.size(); i++) {
24 wm->remove_window(children[i]);
31 const Rect &Window::get_rect() const
36 Rect Window::get_absolute_rect() const
43 absolute_rect = parent->get_absolute_rect();
45 absolute_rect.x += rect.x;
46 absolute_rect.y += rect.y;
47 absolute_rect.width = rect.width;
48 absolute_rect.height = rect.height;
53 bool Window::contains_point(int ptr_x, int ptr_y)
55 Rect abs_rect = get_absolute_rect();
56 return ptr_x >= abs_rect.x && ptr_x < abs_rect.x + abs_rect.width &&
57 ptr_y >= abs_rect.y && ptr_y < abs_rect.y + abs_rect.height;
60 void Window::move(int x, int y)
62 invalidate(); // moved, should redraw, MUST BE CALLED FIRST
67 void Window::resize(int x, int y)
69 invalidate(); // resized, should redraw, MUST BE CALLED FIRST
74 void Window::set_title(const char *s)
78 title = new char[strlen(s) + 1];
82 const char *Window::get_title() const
87 void Window::invalidate()
90 Rect abs_rect = get_absolute_rect();
91 wm->invalidate_region(abs_rect);
94 void Window::draw(Rect *dirty_region)
96 Rect abs_rect = get_absolute_rect();
97 Rect intersect = rect_intersection(abs_rect, *dirty_region);
98 if(intersect.width && intersect.height) {
99 if(callbacks.display) {
100 callbacks.display(this);
104 draw_children(abs_rect);
105 *dirty_region = rect_union(*dirty_region, abs_rect);
109 void Window::draw_children(const Rect &dirty_region)
111 Rect drect = dirty_region;
112 for(size_t i=0; i<children.size(); i++) {
113 children[i]->draw(&drect);
117 unsigned char *Window::get_win_start_on_fb()
119 unsigned char *fb = get_framebuffer();
120 Rect abs_rect = get_absolute_rect();
121 return fb + get_color_depth() * (get_screen_size().x * abs_rect.y + abs_rect.x) / 8;
124 int Window::get_scanline_width()
126 return get_screen_size().x;
129 void Window::set_managed(bool managed)
131 this->managed = managed;
134 bool Window::get_managed() const
139 void Window::set_focusable(bool focusable)
141 this->focusable = focusable;
144 bool Window::get_focusable() const
149 bool Window::get_dirty() const
154 void Window::set_display_callback(DisplayFuncType func)
156 callbacks.display = func;
159 void Window::set_keyboard_callback(KeyboardFuncType func)
161 callbacks.keyboard = func;
164 void Window::set_mouse_button_callback(MouseButtonFuncType func)
166 callbacks.button = func;
169 void Window::set_mouse_motion_callback(MouseMotionFuncType func)
171 callbacks.motion = func;
174 const DisplayFuncType Window::get_display_callback() const
176 return callbacks.display;
179 const KeyboardFuncType Window::get_keyboard_callback() const
181 return callbacks.keyboard;
184 const MouseButtonFuncType Window::get_mouse_button_callback() const
186 return callbacks.button;
189 const MouseMotionFuncType Window::get_mouse_motion_callback() const
191 return callbacks.motion;
194 void Window::add_child(Window *win)
196 children.push_back(win);
198 win->parent->remove_child(win);
203 void Window::remove_child(Window *win)
205 std::vector<Window*>::iterator it;
206 it = std::find(children.begin(), children.end(), win);
207 if(it != children.end()) {
213 Window **Window::get_children()
215 if(children.empty()) {
221 int Window::get_children_count() const
223 return (int)children.size();
226 const Window *Window::get_parent() const
231 Window *Window::get_parent()