2018-02-08 20:47:31 +08:00
|
|
|
#ifndef CONTROLEVENT_H
|
|
|
|
#define CONTROLEVENT_H
|
2017-12-14 18:38:44 +08:00
|
|
|
|
|
|
|
#include <SDL2/SDL_mutex.h>
|
|
|
|
#include <SDL2/SDL_stdinc.h>
|
|
|
|
|
|
|
|
#include "android/input.h"
|
|
|
|
#include "android/keycodes.h"
|
2018-01-22 23:50:08 +08:00
|
|
|
#include "common.h"
|
2017-12-14 18:38:44 +08:00
|
|
|
|
|
|
|
#define CONTROL_EVENT_QUEUE_SIZE 64
|
|
|
|
#define SERIALIZED_EVENT_MAX_SIZE 33
|
|
|
|
#define TEXT_MAX_LENGTH 31
|
|
|
|
|
|
|
|
enum control_event_type {
|
|
|
|
CONTROL_EVENT_TYPE_KEYCODE,
|
|
|
|
CONTROL_EVENT_TYPE_TEXT,
|
|
|
|
CONTROL_EVENT_TYPE_MOUSE,
|
|
|
|
CONTROL_EVENT_TYPE_SCROLL,
|
2018-02-02 21:52:23 +08:00
|
|
|
CONTROL_EVENT_TYPE_COMMAND,
|
2017-12-14 18:38:44 +08:00
|
|
|
};
|
|
|
|
|
2018-02-02 21:52:23 +08:00
|
|
|
#define CONTROL_EVENT_COMMAND_SCREEN_ON 0
|
|
|
|
|
2017-12-14 18:38:44 +08:00
|
|
|
struct control_event {
|
|
|
|
enum control_event_type type;
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
enum android_keyevent_action action;
|
|
|
|
enum android_keycode keycode;
|
|
|
|
enum android_metastate metastate;
|
|
|
|
} keycode_event;
|
|
|
|
struct {
|
|
|
|
char text[TEXT_MAX_LENGTH + 1]; // nul-terminated string
|
|
|
|
} text_event;
|
|
|
|
struct {
|
|
|
|
enum android_motionevent_action action;
|
|
|
|
enum android_motionevent_buttons buttons;
|
2018-01-29 21:52:22 +08:00
|
|
|
struct position position;
|
2017-12-14 18:38:44 +08:00
|
|
|
} mouse_event;
|
|
|
|
struct {
|
2018-01-29 21:52:22 +08:00
|
|
|
struct position position;
|
2017-12-14 18:38:44 +08:00
|
|
|
Sint32 hscroll;
|
|
|
|
Sint32 vscroll;
|
|
|
|
} scroll_event;
|
2018-02-02 21:52:23 +08:00
|
|
|
struct {
|
|
|
|
int action;
|
|
|
|
} command_event;
|
2017-12-14 18:38:44 +08:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
struct control_event_queue {
|
|
|
|
struct control_event data[CONTROL_EVENT_QUEUE_SIZE];
|
|
|
|
int head;
|
|
|
|
int tail;
|
|
|
|
};
|
|
|
|
|
|
|
|
// buf size must be at least SERIALIZED_EVENT_MAX_SIZE
|
2018-01-19 22:12:22 +08:00
|
|
|
int control_event_serialize(const struct control_event *event, unsigned char *buf);
|
2017-12-14 18:38:44 +08:00
|
|
|
|
|
|
|
SDL_bool control_event_queue_init(struct control_event_queue *queue);
|
|
|
|
void control_event_queue_destroy(struct control_event_queue *queue);
|
|
|
|
|
2018-01-19 22:12:22 +08:00
|
|
|
SDL_bool control_event_queue_is_empty(const struct control_event_queue *queue);
|
|
|
|
SDL_bool control_event_queue_is_full(const struct control_event_queue *queue);
|
2017-12-14 18:38:44 +08:00
|
|
|
|
|
|
|
// event is copied, the queue does not use the event after the function returns
|
2018-01-19 22:12:22 +08:00
|
|
|
SDL_bool control_event_queue_push(struct control_event_queue *queue, const struct control_event *event);
|
2017-12-14 18:38:44 +08:00
|
|
|
SDL_bool control_event_queue_take(struct control_event_queue *queue, struct control_event *event);
|
|
|
|
|
|
|
|
#endif
|