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 {
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()
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);
}
}
+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();
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);
}
}
}
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) {
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)
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);
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;
}
}
}
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);
}