From: Eleni Maria Stea Date: Sat, 23 Feb 2013 19:42:36 +0000 (+0200) Subject: *in progress* X-Git-Url: https://eleni.mutantstargoat.com/git/?p=winnie;a=commitdiff_plain;h=026158b5ee6ffac95c3efc6eee4c155497cd8594 *in progress* fixed mouse bug still need to fix the strange win behavior (I use absol. pos somewhere I shouldn't) --- diff --git a/src/event.h b/src/event.h index e4ac286..a51113f 100644 --- a/src/event.h +++ b/src/event.h @@ -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 { diff --git a/src/main.cc b/src/main.cc index 1f4e045..f87b011 100644 --- a/src/main.cc +++ b/src/main.cc @@ -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(); diff --git a/src/sdl/mouse.cc b/src/sdl/mouse.cc index 5531707..f31c900 100644 --- a/src/sdl/mouse.cc +++ b/src/sdl/mouse.cc @@ -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); } } } diff --git a/src/window.cc b/src/window.cc index b5635ed..a0388fe 100644 --- a/src/window.cc +++ b/src/window.cc @@ -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) { diff --git a/src/wm.cc b/src/wm.cc index b4e2d79..a6e29b0 100644 --- 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); }