raise works
authorEleni Maria Stea <elene.mst@gmail.com>
Mon, 25 Feb 2013 20:29:04 +0000 (22:29 +0200)
committerEleni Maria Stea <elene.mst@gmail.com>
Mon, 25 Feb 2013 20:29:04 +0000 (22:29 +0200)
src/sdl/mouse.cc
src/window.cc
src/window.h
src/wm.cc
src/wm.h

index 51cceb3..c5663f6 100644 (file)
@@ -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);
                }
        }
 }
index 59302d4..ab1e3e7 100644 (file)
@@ -1,4 +1,5 @@
 #include <algorithm>
+#include <stdio.h> //TODO
 #include <string.h>
 
 #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; i<children.size(); i++) {
-               children[i]->draw(dirty_region);
+               children[i]->draw(&drect);
        }
 }
 
index 028343e..ee9c7a0 100644 (file)
@@ -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();
index fd86d1d..c9b8959 100644 (file)
--- 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<Window*>::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;
index fb60b24..b675539 100644 (file)
--- 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;