Skip to content

Commit

Permalink
Rename event converter functions
Browse files Browse the repository at this point in the history
Rename "XXX_from_sdl_to_android" to "convert_XXX", to avoid huge
function names.
  • Loading branch information
rom1v committed Sep 15, 2019
1 parent 9463850 commit ffdbf59
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 31 deletions.
19 changes: 7 additions & 12 deletions app/src/event_converter.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ autocomplete_metastate(enum android_metastate metastate) {
return metastate;
}


static enum android_metastate
convert_meta_state(SDL_Keymod mod) {
enum android_metastate metastate = 0;
Expand Down Expand Up @@ -158,8 +157,7 @@ convert_mouse_buttons(uint32_t state) {
}

bool
input_key_from_sdl_to_android(const SDL_KeyboardEvent *from,
struct control_msg *to) {
convert_input_key(const SDL_KeyboardEvent *from, struct control_msg *to) {
to->type = CONTROL_MSG_TYPE_INJECT_KEYCODE;

if (!convert_keycode_action(from->type, &to->inject_keycode.action)) {
Expand All @@ -177,9 +175,8 @@ input_key_from_sdl_to_android(const SDL_KeyboardEvent *from,
}

bool
mouse_button_from_sdl_to_android(const SDL_MouseButtonEvent *from,
struct size screen_size,
struct control_msg *to) {
convert_mouse_button(const SDL_MouseButtonEvent *from, struct size screen_size,
struct control_msg *to) {
to->type = CONTROL_MSG_TYPE_INJECT_MOUSE_EVENT;

if (!convert_mouse_action(from->type, &to->inject_mouse_event.action)) {
Expand All @@ -196,9 +193,8 @@ mouse_button_from_sdl_to_android(const SDL_MouseButtonEvent *from,
}

bool
mouse_motion_from_sdl_to_android(const SDL_MouseMotionEvent *from,
struct size screen_size,
struct control_msg *to) {
convert_mouse_motion(const SDL_MouseMotionEvent *from, struct size screen_size,
struct control_msg *to) {
to->type = CONTROL_MSG_TYPE_INJECT_MOUSE_EVENT;
to->inject_mouse_event.action = AMOTION_EVENT_ACTION_MOVE;
to->inject_mouse_event.buttons = convert_mouse_buttons(from->state);
Expand All @@ -210,9 +206,8 @@ mouse_motion_from_sdl_to_android(const SDL_MouseMotionEvent *from,
}

bool
mouse_wheel_from_sdl_to_android(const SDL_MouseWheelEvent *from,
struct position position,
struct control_msg *to) {
convert_mouse_wheel(const SDL_MouseWheelEvent *from, struct position position,
struct control_msg *to) {
to->type = CONTROL_MSG_TYPE_INJECT_SCROLL_EVENT;

to->inject_scroll_event.position = position;
Expand Down
18 changes: 7 additions & 11 deletions app/src/event_converter.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,21 @@ struct complete_mouse_wheel_event {
};

bool
input_key_from_sdl_to_android(const SDL_KeyboardEvent *from,
struct control_msg *to);
convert_input_key(const SDL_KeyboardEvent *from, struct control_msg *to);

bool
mouse_button_from_sdl_to_android(const SDL_MouseButtonEvent *from,
struct size screen_size,
struct control_msg *to);
convert_mouse_button(const SDL_MouseButtonEvent *from, struct size screen_size,
struct control_msg *to);

// the video size may be different from the real device size, so we need the
// size to which the absolute position apply, to scale it accordingly
bool
mouse_motion_from_sdl_to_android(const SDL_MouseMotionEvent *from,
struct size screen_size,
struct control_msg *to);
convert_mouse_motion(const SDL_MouseMotionEvent *from, struct size screen_size,
struct control_msg *to);

// on Android, a scroll event requires the current mouse position
bool
mouse_wheel_from_sdl_to_android(const SDL_MouseWheelEvent *from,
struct position position,
struct control_msg *to);
convert_mouse_wheel(const SDL_MouseWheelEvent *from, struct position position,
struct control_msg *to);

#endif
12 changes: 4 additions & 8 deletions app/src/input_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ input_manager_process_key(struct input_manager *input_manager,
}

struct control_msg msg;
if (input_key_from_sdl_to_android(event, &msg)) {
if (convert_input_key(event, &msg)) {
if (!controller_push_msg(controller, &msg)) {
LOGW("Could not request 'inject keycode'");
}
Expand All @@ -388,9 +388,7 @@ input_manager_process_mouse_motion(struct input_manager *input_manager,
return;
}
struct control_msg msg;
if (mouse_motion_from_sdl_to_android(event,
input_manager->screen->frame_size,
&msg)) {
if (convert_mouse_motion(event, input_manager->screen->frame_size, &msg)) {
if (!controller_push_msg(input_manager->controller, &msg)) {
LOGW("Could not request 'inject mouse motion event'");
}
Expand Down Expand Up @@ -434,9 +432,7 @@ input_manager_process_mouse_button(struct input_manager *input_manager,
}

struct control_msg msg;
if (mouse_button_from_sdl_to_android(event,
input_manager->screen->frame_size,
&msg)) {
if (convert_mouse_button(event, input_manager->screen->frame_size, &msg)) {
if (!controller_push_msg(input_manager->controller, &msg)) {
LOGW("Could not request 'inject mouse button event'");
}
Expand All @@ -451,7 +447,7 @@ input_manager_process_mouse_wheel(struct input_manager *input_manager,
.point = get_mouse_point(input_manager->screen),
};
struct control_msg msg;
if (mouse_wheel_from_sdl_to_android(event, position, &msg)) {
if (convert_mouse_wheel(event, position, &msg)) {
if (!controller_push_msg(input_manager->controller, &msg)) {
LOGW("Could not request 'inject mouse wheel event'");
}
Expand Down

0 comments on commit ffdbf59

Please sign in to comment.