*in progress*
authorEleni Maria Stea <elene.mst@gmail.com>
Sat, 23 Feb 2013 17:49:43 +0000 (19:49 +0200)
committerEleni Maria Stea <elene.mst@gmail.com>
Sat, 23 Feb 2013 17:49:43 +0000 (19:49 +0200)
absolute positions
(still doesn't work)

src/main.cc
src/window.cc
src/window.h
src/wm.cc

index 6697506..1f4e045 100644 (file)
@@ -29,10 +29,10 @@ int main()
 static void display(Window *win)
 {
        if(wm->get_focused_window() != win) {
-               fill_rect(win->get_rect(), 106, 106, 250);
+               fill_rect(win->get_absolute_rect(), 106, 106, 250);
        }
        else {
-               fill_rect(win->get_rect(), 0, 0, 255);
+               fill_rect(win->get_absolute_rect(), 0, 0, 255);
        }
 }
 
index 46528b7..b5635ed 100644 (file)
@@ -32,15 +32,28 @@ const Rect &Window::get_rect() const
        return rect;
 }
 
-const Rect &Window::get_absolute_rect() const
+Rect Window::get_absolute_rect() const
 {
-       return rect;    // TODO implement absolute rectangle thingy
+       if(!parent) {
+               return rect;
+       }
+
+       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)
 {
-       return ptr_x >= rect.x && ptr_x < rect.x + rect.width &&
-                       ptr_y >= rect.y && ptr_y < rect.y + rect.height;
+       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)
@@ -73,7 +86,8 @@ 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(const Rect &dirty_region)
@@ -102,7 +116,8 @@ void Window::draw_children(const Rect &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()
index 3db8ec8..25a12f7 100644 (file)
@@ -24,7 +24,7 @@ public:
        ~Window();
 
        const Rect &get_rect() const;
-       const Rect &get_absolute_rect() const;
+       Rect get_absolute_rect() const;
        bool contains_point(int ptr_x, int ptr_y);
 
        void move(int x, int y);
index 7aa112b..b4e2d79 100644 (file)
--- a/src/wm.cc
+++ b/src/wm.cc
@@ -35,6 +35,7 @@ void WindowManager::create_frame(Window *win)
        frame->resize(win_rect.width + frame_thickness * 2, 
                        win_rect.height + frame_thickness * 2 + titlebar_thickness);
 
+       win->move(frame_thickness, frame_thickness + titlebar_thickness);
        parent->add_child(frame);
 }
 
@@ -225,18 +226,19 @@ Window *WindowManager::get_window_at_pos(int pointer_x, int pointer_y)
 
 static void display(Window *win)
 {
-       fill_rect(win->get_rect(), 255, 211, 5);
+       fill_rect(win->get_absolute_rect(), 255, 211, 5);
 }
 
-static int prev_x = -1, prev_y;
+static int prev_x, prev_y;
 
 static void mouse(Window *win, int bn, bool pressed)
 {
        if(bn == 0) {
                if(pressed) {
                        get_pointer_pos(&prev_x, &prev_y);
+                       printf("pressed: %d\n", prev_x);
                } else {
-                       prev_x = -1;
+                       printf("released\n");
                }
        }
 }
@@ -244,12 +246,13 @@ static void mouse(Window *win, int bn, bool pressed)
 static void motion(Window *win, int x, int y)
 {
        int left_bn = get_button(0);
-       if(left_bn && prev_x != -1) {
+       if(left_bn) {
                int dx = x - prev_x;
                int dy = y - prev_y;
                prev_x = x - dx;
                prev_y = y - dy;
 
+               printf("dx: %d dy: %d\n", dx, dy);
                Rect rect = win->get_rect();
                win->move(rect.x + dx, rect.y + dy);
        }