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 Rect prev_clip = get_clipping_rect();
100 set_clipping_rect(abs_rect);
102 if(callbacks.display) {
103 callbacks.display(this);
107 draw_children(abs_rect);
109 *dirty_region = rect_union(*dirty_region, abs_rect);
110 set_clipping_rect(prev_clip);
114 void Window::draw_children(const Rect &dirty_region)
116 Rect drect = dirty_region;
117 for(size_t i=0; i<children.size(); i++) {
118 children[i]->draw(&drect);
122 unsigned char *Window::get_win_start_on_fb()
124 unsigned char *fb = get_framebuffer();
125 Rect abs_rect = get_absolute_rect();
126 return fb + get_color_depth() * (get_screen_size().x * abs_rect.y + abs_rect.x) / 8;
129 int Window::get_scanline_width()
131 return get_screen_size().x;
134 void Window::set_managed(bool managed)
136 this->managed = managed;
139 bool Window::get_managed() const
144 void Window::set_focusable(bool focusable)
146 this->focusable = focusable;
149 bool Window::get_focusable() const
154 bool Window::get_dirty() const
159 void Window::set_display_callback(DisplayFuncType func)
161 callbacks.display = func;
164 void Window::set_keyboard_callback(KeyboardFuncType func)
166 callbacks.keyboard = func;
169 void Window::set_mouse_button_callback(MouseButtonFuncType func)
171 callbacks.button = func;
174 void Window::set_mouse_motion_callback(MouseMotionFuncType func)
176 callbacks.motion = func;
179 const DisplayFuncType Window::get_display_callback() const
181 return callbacks.display;
184 const KeyboardFuncType Window::get_keyboard_callback() const
186 return callbacks.keyboard;
189 const MouseButtonFuncType Window::get_mouse_button_callback() const
191 return callbacks.button;
194 const MouseMotionFuncType Window::get_mouse_motion_callback() const
196 return callbacks.motion;
199 void Window::add_child(Window *win)
201 children.push_back(win);
203 win->parent->remove_child(win);
208 void Window::remove_child(Window *win)
210 std::vector<Window*>::iterator it;
211 it = std::find(children.begin(), children.end(), win);
212 if(it != children.end()) {
218 Window **Window::get_children()
220 if(children.empty()) {
226 int Window::get_children_count() const
228 return (int)children.size();
231 const Window *Window::get_parent() const
236 Window *Window::get_parent()