*in progress*
authorEleni Maria Stea <elene.mst@gmail.com>
Sat, 23 Feb 2013 19:42:36 +0000 (21:42 +0200)
committerEleni Maria Stea <elene.mst@gmail.com>
Sat, 23 Feb 2013 19:42:36 +0000 (21:42 +0200)
fixed mouse bug
still need to fix the strange win behavior
(I use absol. pos somewhere I shouldn't)

src/event.h
src/main.cc
src/sdl/mouse.cc
src/window.cc
src/wm.cc

index e4ac286..a51113f 100644 (file)
@@ -5,7 +5,7 @@ class Window;
 
 typedef void (*DisplayFuncType)(Window* win);
 typedef void (*KeyboardFuncType)(Window* win, int key, bool pressed);
-typedef void (*MouseButtonFuncType)(Window *win, int bn, bool pressed);
+typedef void (*MouseButtonFuncType)(Window *win, int bn, bool pressed, int x, int y);
 typedef void (*MouseMotionFuncType)(Window *win, int x, int y);
 
 struct Callbacks {
index 1f4e045..f87b011 100644 (file)
@@ -5,6 +5,8 @@
 
 static void display(Window *win);
 static void keyboard(Window *win, int key, bool pressed);
+static void button(Window *win, int bn, bool pressed, int x, int y);
+static void motion(Window *win, int x, int y);
 static void cleanup();
 
 int main()
@@ -18,6 +20,8 @@ int main()
        win1->resize(200, 300);
        win1->set_display_callback(display);
        win1->set_keyboard_callback(keyboard);
+       win1->set_mouse_button_callback(button);
+       win1->set_mouse_motion_callback(motion);
 
        wm->add_window(win1);
 
@@ -44,6 +48,16 @@ static void keyboard(Window *win, int key, bool pressed)
        }
 }
 
+static void button(Window *win, int bn, bool pressed, int x, int y)
+{
+       printf("WINDOW(%p) button %d %s\n", (void*)win, bn, pressed ? "press" : "release");
+}
+
+static void motion(Window *win, int x, int y)
+{
+       printf("WINDOW(%p) motion %d %d\n", (void*)win, x, y);
+}
+
 static void cleanup()
 {
        winnie_shutdown();
index 5531707..f31c900 100644 (file)
@@ -63,7 +63,8 @@ void process_mouse_event()
                        bnstate &= ~(1 << bn);
                }
                if(top && (button_callback = top->get_mouse_button_callback())) {
-                       button_callback(top, bn, sdl_event.button.state);
+                       Rect rect = top->get_absolute_rect();
+                       button_callback(top, bn, sdl_event.button.state, pointer_x - rect.x, pointer_y - rect.y);
                }
        }
 }
index b5635ed..a0388fe 100644 (file)
@@ -86,15 +86,12 @@ const char *Window::get_title() const
 void Window::invalidate()
 {
        dirty = true;
-       Rect abs_rect = get_absolute_rect(); 
+       Rect abs_rect = get_absolute_rect();
        wm->invalidate_region(abs_rect);
 }
 
 void Window::draw(const Rect &dirty_region)
 {
-       //TODO
-       //titlebar, frame
-
        Rect intersect = rect_intersection(rect, dirty_region);
        if(intersect.width && intersect.height) {
                if(callbacks.display) {
index b4e2d79..a6e29b0 100644 (file)
--- a/src/wm.cc
+++ b/src/wm.cc
@@ -12,7 +12,7 @@ WindowManager *wm;
 static WindowManager wminst;
 
 static void display(Window *win);
-static void mouse(Window *win, int bn, bool pressed);
+static void mouse(Window *win, int bn, bool pressed, int x, int y);
 static void motion(Window *win, int x, int y);
 
 void WindowManager::create_frame(Window *win)
@@ -30,9 +30,9 @@ void WindowManager::create_frame(Window *win)
        windows.push_back(frame);
 
        Rect win_rect = win->get_rect();
-       frame->move(win_rect.x - frame_thickness, 
+       frame->move(win_rect.x - frame_thickness,
                        win_rect.y - frame_thickness - titlebar_thickness);
-       frame->resize(win_rect.width + frame_thickness * 2, 
+       frame->resize(win_rect.width + frame_thickness * 2,
                        win_rect.height + frame_thickness * 2 + titlebar_thickness);
 
        win->move(frame_thickness, frame_thickness + titlebar_thickness);
@@ -231,14 +231,12 @@ static void display(Window *win)
 
 static int prev_x, prev_y;
 
-static void mouse(Window *win, int bn, bool pressed)
+static void mouse(Window *win, int bn, bool pressed, int x, int y)
 {
        if(bn == 0) {
                if(pressed) {
-                       get_pointer_pos(&prev_x, &prev_y);
-                       printf("pressed: %d\n", prev_x);
-               } else {
-                       printf("released\n");
+                       prev_x = x;
+                       prev_y = y;
                }
        }
 }
@@ -252,7 +250,6 @@ static void motion(Window *win, int x, int 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);
        }