X-Git-Url: http://git.mutantstargoat.com?a=blobdiff_plain;f=src%2Fwindow.cc;h=b5635ed856cda6afe04c1c2f9c8e05be74866d5c;hb=981f0eab2195d34f7c186a2e3e891810e14ce5b4;hp=84d1004c34a726659911dd46d5034d648aa79301;hpb=5deac1a20d178aa7d2e8bb5cbc79b6584c6287f5;p=winnie diff --git a/src/window.cc b/src/window.cc index 84d1004..b5635ed 100644 --- a/src/window.cc +++ b/src/window.cc @@ -1,19 +1,29 @@ +#include #include + #include "gfx.h" #include "window.h" #include "wm.h" Window::Window() { + parent = 0; title = 0; rect.x = rect.y = 0; rect.width = rect.height = 128; memset(&callbacks, 0, sizeof callbacks); dirty = true; + managed = true; + focusable = true; } Window::~Window() { + for(size_t i=0; iremove_window(children[i]); + delete children[i]; + } + delete [] title; } @@ -22,15 +32,28 @@ const Rect &Window::get_rect() const return rect; } -bool Window::contains_point(int ptr_x, int ptr_y) +Rect Window::get_absolute_rect() const { - if((rect.x <= ptr_x) && ((rect.x + rect.width) >= ptr_x)) { - if((rect.y <= ptr_y) && (ptr_y <= (rect.y + rect.height))) { - return true; - } + if(!parent) { + return rect; } - return false; + Rect absolute_rect; + absolute_rect = parent->get_absolute_rect(); + + absolute_rect.x += rect.x; + absolute_rect.y += rect.y; + absolute_rect.width = rect.width; + absolute_rect.height = rect.height; + + return absolute_rect; +} + +bool Window::contains_point(int ptr_x, int ptr_y) +{ + Rect abs_rect = get_absolute_rect(); + return ptr_x >= abs_rect.x && ptr_x < abs_rect.x + abs_rect.width && + ptr_y >= abs_rect.y && ptr_y < abs_rect.y + abs_rect.height; } void Window::move(int x, int y) @@ -63,21 +86,38 @@ const char *Window::get_title() const void Window::invalidate() { dirty = true; - wm->invalidate_region(rect); + Rect abs_rect = get_absolute_rect(); + wm->invalidate_region(abs_rect); } -void Window::draw() +void Window::draw(const Rect &dirty_region) { //TODO //titlebar, frame - callbacks.display(this); - dirty = false; + + Rect intersect = rect_intersection(rect, dirty_region); + if(intersect.width && intersect.height) { + if(callbacks.display) { + callbacks.display(this); + } + dirty = false; + + draw_children(rect); + } +} + +void Window::draw_children(const Rect &dirty_region) +{ + for(size_t i=0; idraw(dirty_region); + } } unsigned char *Window::get_win_start_on_fb() { unsigned char *fb = get_framebuffer(); - return fb + get_color_depth() * (get_screen_size().x * rect.y + rect.x) / 8; + Rect abs_rect = get_absolute_rect(); + return fb + get_color_depth() * (get_screen_size().x * abs_rect.y + abs_rect.x) / 8; } int Window::get_scanline_width() @@ -85,6 +125,26 @@ int Window::get_scanline_width() return get_screen_size().x; } +void Window::set_managed(bool managed) +{ + this->managed = managed; +} + +bool Window::get_managed() const +{ + return managed; +} + +void Window::set_focusable(bool focusable) +{ + this->focusable = focusable; +} + +bool Window::get_focusable() const +{ + return focusable; +} + void Window::set_display_callback(DisplayFuncType func) { callbacks.display = func; @@ -124,3 +184,45 @@ const MouseMotionFuncType Window::get_mouse_motion_callback() const { return callbacks.motion; } + +void Window::add_child(Window *win) +{ + children.push_back(win); + if(win->parent) { + win->parent->remove_child(win); + } + win->parent = this; +} + +void Window::remove_child(Window *win) +{ + std::vector::iterator it; + it = std::find(children.begin(), children.end(), win); + if(it != children.end()) { + children.erase(it); + win->parent = 0; + } +} + +Window **Window::get_children() +{ + if(children.empty()) { + return 0; + } + return &children[0]; +} + +int Window::get_children_count() const +{ + return (int)children.size(); +} + +const Window *Window::get_parent() const +{ + return parent; +} + +Window *Window::get_parent() +{ + return parent; +}