Swap position/point names
A point is a 2D vector. A position represent a point relative to the screen size.
This commit is contained in:
@@ -11,16 +11,16 @@ struct size {
|
||||
Uint16 height;
|
||||
};
|
||||
|
||||
struct position {
|
||||
struct point {
|
||||
Uint16 x;
|
||||
Uint16 y;
|
||||
};
|
||||
|
||||
struct point {
|
||||
struct position {
|
||||
// The video screen size may be different from the real device screen size,
|
||||
// so store to which size the absolute position apply, to scale it accordingly.
|
||||
struct size screen_size;
|
||||
struct position position;
|
||||
struct point point;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -17,11 +17,11 @@ static inline void write32(Uint8 *buf, Uint32 value) {
|
||||
buf[3] = value;
|
||||
}
|
||||
|
||||
static void write_point(Uint8 *buf, const struct point *point) {
|
||||
write16(&buf[0], point->position.x);
|
||||
write16(&buf[2], point->position.y);
|
||||
write16(&buf[4], point->screen_size.width);
|
||||
write16(&buf[6], point->screen_size.height);
|
||||
static void write_position(Uint8 *buf, const struct position *position) {
|
||||
write16(&buf[0], position->point.x);
|
||||
write16(&buf[2], position->point.y);
|
||||
write16(&buf[4], position->screen_size.width);
|
||||
write16(&buf[6], position->screen_size.height);
|
||||
}
|
||||
|
||||
int control_event_serialize(const struct control_event *event, unsigned char *buf) {
|
||||
@@ -45,10 +45,10 @@ int control_event_serialize(const struct control_event *event, unsigned char *bu
|
||||
case CONTROL_EVENT_TYPE_MOUSE:
|
||||
buf[1] = event->mouse_event.action;
|
||||
write32(&buf[2], event->mouse_event.buttons);
|
||||
write_point(&buf[6], &event->mouse_event.point);
|
||||
write_position(&buf[6], &event->mouse_event.position);
|
||||
return 14;
|
||||
case CONTROL_EVENT_TYPE_SCROLL:
|
||||
write_point(&buf[1], &event->scroll_event.point);
|
||||
write_position(&buf[1], &event->scroll_event.position);
|
||||
write32(&buf[9], (Uint32) event->scroll_event.hscroll);
|
||||
write32(&buf[13], (Uint32) event->scroll_event.vscroll);
|
||||
return 17;
|
||||
|
||||
@@ -33,10 +33,10 @@ struct control_event {
|
||||
struct {
|
||||
enum android_motionevent_action action;
|
||||
enum android_motionevent_buttons buttons;
|
||||
struct point point;
|
||||
struct position position;
|
||||
} mouse_event;
|
||||
struct {
|
||||
struct point point;
|
||||
struct position position;
|
||||
Sint32 hscroll;
|
||||
Sint32 vscroll;
|
||||
} scroll_event;
|
||||
|
||||
@@ -144,32 +144,32 @@ SDL_bool mouse_button_from_sdl_to_android(const SDL_MouseButtonEvent *from,
|
||||
}
|
||||
|
||||
to->mouse_event.buttons = convert_mouse_buttons(SDL_BUTTON(from->button));
|
||||
to->mouse_event.point.screen_size = screen_size;
|
||||
to->mouse_event.point.position.x = (Uint16) from->x;
|
||||
to->mouse_event.point.position.y = (Uint16) from->y;
|
||||
to->mouse_event.position.screen_size = screen_size;
|
||||
to->mouse_event.position.point.x = (Uint16) from->x;
|
||||
to->mouse_event.position.point.y = (Uint16) from->y;
|
||||
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
SDL_bool mouse_motion_from_sdl_to_android(const SDL_MouseMotionEvent *from,
|
||||
const struct size screen_size,
|
||||
struct size screen_size,
|
||||
struct control_event *to) {
|
||||
to->type = CONTROL_EVENT_TYPE_MOUSE;
|
||||
to->mouse_event.action = AMOTION_EVENT_ACTION_MOVE;
|
||||
to->mouse_event.buttons = convert_mouse_buttons(from->state);
|
||||
to->mouse_event.point.screen_size = screen_size;
|
||||
to->mouse_event.point.position.x = from->x;
|
||||
to->mouse_event.point.position.y = from->y;
|
||||
to->mouse_event.position.screen_size = screen_size;
|
||||
to->mouse_event.position.point.x = from->x;
|
||||
to->mouse_event.position.point.y = from->y;
|
||||
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
SDL_bool mouse_wheel_from_sdl_to_android(const SDL_MouseWheelEvent *from,
|
||||
const struct point point,
|
||||
struct position position,
|
||||
struct control_event *to) {
|
||||
to->type = CONTROL_EVENT_TYPE_SCROLL;
|
||||
|
||||
to->scroll_event.point = point;
|
||||
to->scroll_event.position = position;
|
||||
|
||||
int mul = from->direction == SDL_MOUSEWHEEL_NORMAL ? 1 : -1;
|
||||
to->scroll_event.hscroll = mul * from->x;
|
||||
|
||||
@@ -29,7 +29,7 @@ SDL_bool mouse_motion_from_sdl_to_android(const SDL_MouseMotionEvent *from,
|
||||
|
||||
// on Android, a scroll event requires the current mouse position
|
||||
SDL_bool mouse_wheel_from_sdl_to_android(const SDL_MouseWheelEvent *from,
|
||||
struct point point,
|
||||
struct position position,
|
||||
struct control_event *to);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -104,12 +104,12 @@ static inline struct size get_window_size(SDL_Window *window) {
|
||||
return size;
|
||||
}
|
||||
|
||||
static inline struct position get_mouse_position() {
|
||||
static inline struct point get_mouse_point() {
|
||||
int x;
|
||||
int y;
|
||||
SDL_GetMouseState(&x, &y);
|
||||
SDL_assert_release(x >= 0 && x < 0x10000 && y >= 0 && y < 0x10000);
|
||||
return (struct position) {
|
||||
return (struct point) {
|
||||
.x = (Uint16) x,
|
||||
.y = (Uint16) y,
|
||||
};
|
||||
@@ -322,9 +322,9 @@ static void handle_mouse_button(const SDL_MouseButtonEvent *event, struct size s
|
||||
}
|
||||
}
|
||||
|
||||
static void handle_mouse_wheel(const SDL_MouseWheelEvent *event, struct point point) {
|
||||
static void handle_mouse_wheel(const SDL_MouseWheelEvent *event, struct position position) {
|
||||
struct control_event control_event;
|
||||
if (mouse_wheel_from_sdl_to_android(event, point, &control_event)) {
|
||||
if (mouse_wheel_from_sdl_to_android(event, position, &control_event)) {
|
||||
if (!controller_push_event(&controller, &control_event)) {
|
||||
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Cannot send wheel button event");
|
||||
}
|
||||
@@ -366,11 +366,11 @@ void event_loop(void) {
|
||||
handle_mouse_motion(&event.motion, frame_size);
|
||||
break;
|
||||
case SDL_MOUSEWHEEL: {
|
||||
struct point point = {
|
||||
struct position position = {
|
||||
.screen_size = frame_size,
|
||||
.position = get_mouse_position(),
|
||||
.point = get_mouse_point(),
|
||||
};
|
||||
handle_mouse_wheel(&event.wheel, point);
|
||||
handle_mouse_wheel(&event.wheel, position);
|
||||
break;
|
||||
}
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
|
||||
Reference in New Issue
Block a user