X-Git-Url: http://git.mutantstargoat.com?a=blobdiff_plain;f=src%2Fwindow.cc;h=f5b1ada01d28afb1eef6f4220ca05ba2ffbb7057;hb=a43297a61d69ca5fa5bb7ae8407757da978b4dd4;hp=76c51773ac66fd900a0db1cbe013283ef0bd1320;hpb=8a92836b3af157fd47c657cfe546887e5f5683a8;p=winnie diff --git a/src/window.cc b/src/window.cc index 76c5177..f5b1ada 100644 --- a/src/window.cc +++ b/src/window.cc @@ -1,4 +1,6 @@ +#include #include + #include "gfx.h" #include "window.h" #include "wm.h" @@ -10,10 +12,16 @@ Window::Window() rect.width = rect.height = 128; memset(&callbacks, 0, sizeof callbacks); dirty = true; + managed = true; } Window::~Window() { + for(size_t i=0; iremove_window(children[i]); + delete children[i]; + } + delete [] title; } @@ -22,6 +30,12 @@ const Rect &Window::get_rect() const return rect; } +bool Window::contains_point(int ptr_x, int ptr_y) +{ + return ptr_x >= rect.x && ptr_x < rect.x + rect.width && + ptr_y >= rect.y && ptr_y < rect.y + rect.height; +} + void Window::move(int x, int y) { invalidate(); // moved, should redraw, MUST BE CALLED FIRST @@ -55,10 +69,27 @@ void Window::invalidate() wm->invalidate_region(rect); } -void Window::draw() +void Window::draw(const Rect &dirty_region) { - callbacks.display(this); - dirty = false; + //TODO + //titlebar, frame + + 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() @@ -71,3 +102,82 @@ 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_display_callback(DisplayFuncType func) +{ + callbacks.display = func; +} + +void Window::set_keyboard_callback(KeyboardFuncType func) +{ + callbacks.keyboard = func; +} + +void Window::set_mouse_button_callback(MouseButtonFuncType func) +{ + callbacks.button = func; +} + +void Window::set_mouse_motion_callback(MouseMotionFuncType func) +{ + callbacks.motion = func; +} + +const DisplayFuncType Window::get_display_callback() const +{ + return callbacks.display; +} + +const KeyboardFuncType Window::get_keyboard_callback() const +{ + return callbacks.keyboard; +} + +const MouseButtonFuncType Window::get_mouse_button_callback() const +{ + return callbacks.button; +} + +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; + } +} + +const Window *Window::get_parent() const +{ + return parent; +} + +Window *Window::get_parent() +{ + return parent; +}