-//static void mouse(Window *win, int key, bool pressed);
-//static void motion(Window *win, int x, int y);
+static int prev_x = -1, prev_y;
+
+static void mouse(Window *win, int bn, bool pressed)
+{
+ printf("mouse callback (%d, %s)\n", bn, pressed ? "pressed" : "released");
+ if(bn == 0) {
+ if(pressed) {
+ get_pointer_pos(&prev_x, &prev_y);
+ } else {
+ prev_x = -1;
+ }
+ }
+}
+
+static void motion(Window *win, int x, int y)
+{
+ int left_bn = get_button(0);
+ if(left_bn && prev_x != -1) {
+ int dx = x - prev_x;
+ int dy = y - prev_y;
+ prev_x = x;
+ prev_y = y;
+
+ Rect rect = win->get_rect();
+ win->move(rect.x + dx, rect.y + dy);
+ }
+}