2 #include <stdio.h> //TODO
14 rect.width = rect.height = 128;
15 memset(&callbacks, 0, sizeof callbacks);
24 for(size_t i=0; i<children.size(); i++) {
25 wm->remove_window(children[i]);
32 const Rect &Window::get_rect() const
37 Rect Window::get_absolute_rect() const
44 absolute_rect = parent->get_absolute_rect();
46 absolute_rect.x += rect.x;
47 absolute_rect.y += rect.y;
48 absolute_rect.width = rect.width;
49 absolute_rect.height = rect.height;
54 bool Window::contains_point(int ptr_x, int ptr_y)
56 Rect abs_rect = get_absolute_rect();
57 return ptr_x >= abs_rect.x && ptr_x < abs_rect.x + abs_rect.width &&
58 ptr_y >= abs_rect.y && ptr_y < abs_rect.y + abs_rect.height;
61 void Window::move(int x, int y)
63 invalidate(); // moved, should redraw, MUST BE CALLED FIRST
68 void Window::resize(int x, int y)
70 invalidate(); // resized, should redraw, MUST BE CALLED FIRST
75 void Window::set_title(const char *s)
79 title = new char[strlen(s) + 1];
83 const char *Window::get_title() const
88 void Window::invalidate()
91 Rect abs_rect = get_absolute_rect();
92 wm->invalidate_region(abs_rect);
95 void Window::draw(Rect *dirty_region)
97 Rect abs_rect = get_absolute_rect();
98 Rect intersect = rect_intersection(abs_rect, *dirty_region);
99 if(intersect.width && intersect.height) {
100 Rect prev_clip = get_clipping_rect();
101 set_clipping_rect(abs_rect);
103 if(callbacks.display) {
104 callbacks.display(this);
108 draw_children(abs_rect);
110 *dirty_region = rect_union(*dirty_region, abs_rect);
111 set_clipping_rect(prev_clip);
115 void Window::draw_children(const Rect &dirty_region)
117 Rect drect = dirty_region;
118 for(size_t i=0; i<children.size(); i++) {
119 children[i]->draw(&drect);
123 unsigned char *Window::get_win_start_on_fb()
125 unsigned char *fb = get_framebuffer();
126 Rect abs_rect = get_absolute_rect();
127 return fb + get_color_depth() * (get_screen_size().x * abs_rect.y + abs_rect.x) / 8;
130 int Window::get_scanline_width()
132 return get_screen_size().x;
135 void Window::set_managed(bool managed)
137 this->managed = managed;
140 bool Window::get_managed() const
145 void Window::set_focusable(bool focusable)
147 this->focusable = focusable;
150 bool Window::get_focusable() const
155 bool Window::get_dirty() const
160 void Window::set_display_callback(DisplayFuncType func)
162 callbacks.display = func;
165 void Window::set_keyboard_callback(KeyboardFuncType func)
167 callbacks.keyboard = func;
170 void Window::set_mouse_button_callback(MouseButtonFuncType func)
172 callbacks.button = func;
175 void Window::set_mouse_motion_callback(MouseMotionFuncType func)
177 callbacks.motion = func;
180 const DisplayFuncType Window::get_display_callback() const
182 return callbacks.display;
185 const KeyboardFuncType Window::get_keyboard_callback() const
187 return callbacks.keyboard;
190 const MouseButtonFuncType Window::get_mouse_button_callback() const
192 return callbacks.button;
195 const MouseMotionFuncType Window::get_mouse_motion_callback() const
197 return callbacks.motion;
200 void Window::add_child(Window *win)
202 children.push_back(win);
204 win->parent->remove_child(win);
209 void Window::remove_child(Window *win)
211 std::vector<Window*>::iterator it;
212 it = std::find(children.begin(), children.end(), win);
213 if(it != children.end()) {
219 Window **Window::get_children()
221 if(children.empty()) {
227 int Window::get_children_count() const
229 return (int)children.size();
232 const Window *Window::get_parent() const
237 Window *Window::get_parent()
242 void Window::set_state(State state)
247 Window::State Window::get_state() const