Make X11 and Wayland ProcessHitTest() code less verbose.

This commit is contained in:
Ryan C. Gordon 2015-04-12 20:59:48 -04:00
parent d10201be08
commit c539b3f9e9
2 changed files with 47 additions and 98 deletions

View File

@ -137,63 +137,37 @@ ProcessHitTest(struct SDL_WaylandInput *input, uint32_t serial)
{ {
SDL_WindowData *window_data = input->pointer_focus; SDL_WindowData *window_data = input->pointer_focus;
SDL_Window *window = window_data->sdlwindow; SDL_Window *window = window_data->sdlwindow;
SDL_bool ret = SDL_FALSE;
if (window->hit_test) { if (window->hit_test) {
const SDL_Point point = { wl_fixed_to_int(input->sx_w), wl_fixed_to_int(input->sy_w) }; const SDL_Point point = { wl_fixed_to_int(input->sx_w), wl_fixed_to_int(input->sy_w) };
const SDL_HitTestResult rc = window->hit_test(window, &point, window->hit_test_data); const SDL_HitTestResult rc = window->hit_test(window, &point, window->hit_test_data);
static const uint32_t directions[] = {
WL_SHELL_SURFACE_RESIZE_TOP_LEFT, WL_SHELL_SURFACE_RESIZE_TOP,
WL_SHELL_SURFACE_RESIZE_TOP_RIGHT, WL_SHELL_SURFACE_RESIZE_RIGHT,
WL_SHELL_SURFACE_RESIZE_BOTTOM_RIGHT, WL_SHELL_SURFACE_RESIZE_BOTTOM,
WL_SHELL_SURFACE_RESIZE_BOTTOM_LEFT, WL_SHELL_SURFACE_RESIZE_LEFT
};
switch (rc) { switch (rc) {
case SDL_HITTEST_DRAGGABLE: { case SDL_HITTEST_DRAGGABLE:
wl_shell_surface_move(window_data->shell_surface, input->seat, serial); wl_shell_surface_move(window_data->shell_surface, input->seat, serial);
ret = SDL_TRUE; return SDL_TRUE;
}
break; case SDL_HITTEST_RESIZE_TOPLEFT:
case SDL_HITTEST_RESIZE_TOPLEFT: { case SDL_HITTEST_RESIZE_TOP:
wl_shell_surface_resize(window_data->shell_surface, input->seat, serial, WL_SHELL_SURFACE_RESIZE_TOP_LEFT); case SDL_HITTEST_RESIZE_TOPRIGHT:
ret = SDL_TRUE; case SDL_HITTEST_RESIZE_RIGHT:
} case SDL_HITTEST_RESIZE_BOTTOMRIGHT:
break; case SDL_HITTEST_RESIZE_BOTTOM:
case SDL_HITTEST_RESIZE_TOP: { case SDL_HITTEST_RESIZE_BOTTOMLEFT:
wl_shell_surface_resize(window_data->shell_surface, input->seat, serial, WL_SHELL_SURFACE_RESIZE_TOP); case SDL_HITTEST_RESIZE_LEFT:
ret = SDL_TRUE; wl_shell_surface_resize(window_data->shell_surface, input->seat, serial, directions[rc - SDL_HITTEST_RESIZE_TOPLEFT]);
} return SDL_TRUE;
break;
case SDL_HITTEST_RESIZE_TOPRIGHT: { default: return SDL_FALSE;
wl_shell_surface_resize(window_data->shell_surface, input->seat, serial, WL_SHELL_SURFACE_RESIZE_TOP_RIGHT);
ret = SDL_TRUE;
}
break;
case SDL_HITTEST_RESIZE_RIGHT: {
wl_shell_surface_resize(window_data->shell_surface, input->seat, serial, WL_SHELL_SURFACE_RESIZE_RIGHT);
ret = SDL_TRUE;
}
break;
case SDL_HITTEST_RESIZE_BOTTOMRIGHT: {
wl_shell_surface_resize(window_data->shell_surface, input->seat, serial, WL_SHELL_SURFACE_RESIZE_BOTTOM_RIGHT);
ret = SDL_TRUE;
}
break;
case SDL_HITTEST_RESIZE_BOTTOM: {
wl_shell_surface_resize(window_data->shell_surface, input->seat, serial, WL_SHELL_SURFACE_RESIZE_BOTTOM);
ret = SDL_TRUE;
}
break;
case SDL_HITTEST_RESIZE_BOTTOMLEFT: {
wl_shell_surface_resize(window_data->shell_surface, input->seat, serial, WL_SHELL_SURFACE_RESIZE_BOTTOM_LEFT);
ret = SDL_TRUE;
}
break;
case SDL_HITTEST_RESIZE_LEFT: {
wl_shell_surface_resize(window_data->shell_surface, input->seat, serial, WL_SHELL_SURFACE_RESIZE_LEFT);
ret = SDL_TRUE;
}
break;
default:
break;
} }
} }
return ret; return SDL_FALSE;
} }
static void static void

View File

@ -448,63 +448,38 @@ static SDL_bool
ProcessHitTest(_THIS, const SDL_WindowData *data, const XEvent *xev) ProcessHitTest(_THIS, const SDL_WindowData *data, const XEvent *xev)
{ {
SDL_Window *window = data->window; SDL_Window *window = data->window;
SDL_bool ret = SDL_FALSE;
if (window->hit_test) { if (window->hit_test) {
const SDL_Point point = { xev->xbutton.x, xev->xbutton.y }; const SDL_Point point = { xev->xbutton.x, xev->xbutton.y };
const SDL_HitTestResult rc = window->hit_test(window, &point, window->hit_test_data); const SDL_HitTestResult rc = window->hit_test(window, &point, window->hit_test_data);
static const int directions[] = {
_NET_WM_MOVERESIZE_SIZE_TOPLEFT, _NET_WM_MOVERESIZE_SIZE_TOP,
_NET_WM_MOVERESIZE_SIZE_TOPRIGHT, _NET_WM_MOVERESIZE_SIZE_RIGHT,
_NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT, _NET_WM_MOVERESIZE_SIZE_BOTTOM,
_NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT, _NET_WM_MOVERESIZE_SIZE_LEFT
};
switch (rc) { switch (rc) {
case SDL_HITTEST_DRAGGABLE: { case SDL_HITTEST_DRAGGABLE:
InitiateWindowMove(_this, data, &point); InitiateWindowMove(_this, data, &point);
ret = SDL_TRUE; return SDL_TRUE;
}
break; case SDL_HITTEST_RESIZE_TOPLEFT:
case SDL_HITTEST_RESIZE_TOPLEFT: { case SDL_HITTEST_RESIZE_TOP:
InitiateWindowResize(_this, data, &point, _NET_WM_MOVERESIZE_SIZE_TOPLEFT); case SDL_HITTEST_RESIZE_TOPRIGHT:
ret = SDL_TRUE; case SDL_HITTEST_RESIZE_RIGHT:
} case SDL_HITTEST_RESIZE_BOTTOMRIGHT:
break; case SDL_HITTEST_RESIZE_BOTTOM:
case SDL_HITTEST_RESIZE_TOP: { case SDL_HITTEST_RESIZE_BOTTOMLEFT:
InitiateWindowResize(_this, data, &point, _NET_WM_MOVERESIZE_SIZE_TOP); case SDL_HITTEST_RESIZE_LEFT:
ret = SDL_TRUE; InitiateWindowResize(_this, data, &point, directions[rc - SDL_HITTEST_RESIZE_TOPLEFT]);
} return SDL_TRUE;
break;
case SDL_HITTEST_RESIZE_TOPRIGHT: { default: return SDL_FALSE;
InitiateWindowResize(_this, data, &point, _NET_WM_MOVERESIZE_SIZE_TOPRIGHT);
ret = SDL_TRUE;
}
break;
case SDL_HITTEST_RESIZE_RIGHT: {
InitiateWindowResize(_this, data, &point, _NET_WM_MOVERESIZE_SIZE_RIGHT);
ret = SDL_TRUE;
}
break;
case SDL_HITTEST_RESIZE_BOTTOMRIGHT: {
InitiateWindowResize(_this, data, &point, _NET_WM_MOVERESIZE_SIZE_BOTTOMRIGHT);
ret = SDL_TRUE;
}
break;
case SDL_HITTEST_RESIZE_BOTTOM: {
InitiateWindowResize(_this, data, &point, _NET_WM_MOVERESIZE_SIZE_BOTTOM);
ret = SDL_TRUE;
}
break;
case SDL_HITTEST_RESIZE_BOTTOMLEFT: {
InitiateWindowResize(_this, data, &point, _NET_WM_MOVERESIZE_SIZE_BOTTOMLEFT);
ret = SDL_TRUE;
}
break;
case SDL_HITTEST_RESIZE_LEFT: {
InitiateWindowResize(_this, data, &point, _NET_WM_MOVERESIZE_SIZE_LEFT);
ret = SDL_TRUE;
}
break;
default:
break;
} }
} }
return ret; return SDL_FALSE;
} }
static void static void