From: Eleni Maria Stea Date: Mon, 25 Feb 2013 20:29:04 +0000 (+0200) Subject: raise works X-Git-Url: https://eleni.mutantstargoat.com/git/?p=winnie;a=commitdiff_plain;h=d02747c88b1df856c5531cdc4b7af5b3ac8a0dc3 raise works --- diff --git a/src/sdl/mouse.cc b/src/sdl/mouse.cc index 51cceb3..c5663f6 100644 --- a/src/sdl/mouse.cc +++ b/src/sdl/mouse.cc @@ -34,11 +34,11 @@ void process_mouse_event() MouseMotionFuncType motion_callback = 0; MouseButtonFuncType button_callback = 0; - Window *top; - if(!(top = wm->get_grab_window())) { - top = wm->get_window_at_pos(pointer_x, pointer_y); - if(top) { - wm->set_focused_window(top); + Window *win; + if(!(win = wm->get_grab_window())) { + win = wm->get_window_at_pos(pointer_x, pointer_y); + if(win) { + wm->set_focused_window(win); } else { wm->set_focused_window(0); @@ -49,9 +49,9 @@ void process_mouse_event() case SDL_MOUSEMOTION: pointer_x = sdl_event.motion.x; pointer_y = sdl_event.motion.y; - if(top && (motion_callback = top->get_mouse_motion_callback())) { - Rect rect = top->get_absolute_rect(); - motion_callback(top, pointer_x - rect.x, pointer_y - rect.y); + if(win && (motion_callback = win->get_mouse_motion_callback())) { + Rect rect = win->get_absolute_rect(); + motion_callback(win, pointer_x - rect.x, pointer_y - rect.y); } break; @@ -64,9 +64,9 @@ void process_mouse_event() else { bnstate &= ~(1 << bn); } - if(top && (button_callback = top->get_mouse_button_callback())) { - Rect rect = top->get_absolute_rect(); - button_callback(top, bn, sdl_event.button.state, pointer_x - rect.x, pointer_y - rect.y); + if(win && (button_callback = win->get_mouse_button_callback())) { + Rect rect = win->get_absolute_rect(); + button_callback(win, bn, sdl_event.button.state, pointer_x - rect.x, pointer_y - rect.y); } } } diff --git a/src/window.cc b/src/window.cc index 59302d4..ab1e3e7 100644 --- a/src/window.cc +++ b/src/window.cc @@ -1,4 +1,5 @@ #include +#include //TODO #include #include "gfx.h" @@ -90,10 +91,10 @@ void Window::invalidate() wm->invalidate_region(abs_rect); } -void Window::draw(const Rect &dirty_region) +void Window::draw(Rect *dirty_region) { Rect abs_rect = get_absolute_rect(); - Rect intersect = rect_intersection(abs_rect, dirty_region); + Rect intersect = rect_intersection(abs_rect, *dirty_region); if(intersect.width && intersect.height) { if(callbacks.display) { callbacks.display(this); @@ -101,13 +102,15 @@ void Window::draw(const Rect &dirty_region) dirty = false; draw_children(abs_rect); + *dirty_region = rect_union(*dirty_region, abs_rect); } } void Window::draw_children(const Rect &dirty_region) { + Rect drect = dirty_region; for(size_t i=0; idraw(dirty_region); + children[i]->draw(&drect); } } diff --git a/src/window.h b/src/window.h index 028343e..ee9c7a0 100644 --- a/src/window.h +++ b/src/window.h @@ -38,7 +38,7 @@ public: */ void invalidate(); - void draw(const Rect &dirty_region); + void draw(Rect *dirty_region); void draw_children(const Rect &dirty_region); unsigned char *get_win_start_on_fb(); diff --git a/src/wm.cc b/src/wm.cc index fd86d1d..c9b8959 100644 --- a/src/wm.cc +++ b/src/wm.cc @@ -270,6 +270,40 @@ void WindowManager::release_mouse() grab_win = 0; } +void WindowManager::raise_window(Window *win) +{ + if(!win) { + return; + } + + Window *parent = win->get_parent(); + if(parent != root_win) { + if(parent->get_parent() == root_win) { + win = parent; + } + else { + return; + } + } + + root_win->remove_child(win); + root_win->add_child(win); +} + +void WindowManager::sink_window(Window *win) +{ + if(!win) { + return; + } + + std::list::iterator it; + it = std::find(windows.begin(), windows.end(), win); + if(it != windows.end()) { + windows.erase(it); + windows.push_front(win); + } +} + static void display(Window *win) { //frame display: @@ -293,6 +327,7 @@ static void mouse(Window *win, int bn, bool pressed, int x, int y) if(bn == 0) { if(pressed) { wm->grab_mouse(win); + wm->raise_window(win); prev_x = x; prev_y = y; } @@ -305,6 +340,8 @@ static void mouse(Window *win, int bn, bool pressed, int x, int y) static void motion(Window *win, int x, int y) { int left_bn = get_button(0); + int right_button = get_button(2); + if(left_bn) { int dx = x - prev_x; int dy = y - prev_y; diff --git a/src/wm.h b/src/wm.h index fb60b24..b675539 100644 --- a/src/wm.h +++ b/src/wm.h @@ -54,6 +54,9 @@ public: void grab_mouse(Window *win); void release_mouse(); + + void raise_window(Window *win); + void sink_window(Window *win); }; extern WindowManager *wm;