From 5e348148df61707c88b750590bb84f36d2f9691c Mon Sep 17 00:00:00 2001 From: Vasiliy Horbachenko Date: Sat, 17 Sep 2016 22:44:58 +0300 Subject: [PATCH] ability to use special keys and mouse input simultaneously; special key area used by mouse input if key not set; top-right touch anywhere on menus to go back to stream; remove use_fronttouchscreen option --- .gitignore | 1 + src/config.c | 3 - src/gui/guilib.c | 35 ++++++++++- src/gui/guilib.h | 3 +- src/gui/ui.c | 19 +++++- src/gui/ui_settings.c | 16 +---- src/input/vita.c | 136 ++++++++++++++++++++++-------------------- 7 files changed, 127 insertions(+), 86 deletions(-) diff --git a/.gitignore b/.gitignore index a007feab..2f348080 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ build/* +.DS_Store diff --git a/src/config.c b/src/config.c index 0b52b388..6362efc9 100644 --- a/src/config.c +++ b/src/config.c @@ -248,8 +248,6 @@ bool config_file_parse(char* filename, PCONFIGURATION config) { config->sops = strcmp("true", value) == 0; } else if (strcmp(key, "localaudio") == 0) { config->localaudio = strcmp("true", value) == 0; - } else if (strcmp(key, "fronttouchscreen_buttons") == 0) { - config->fronttouchscreen_buttons = strcmp("true", value) == 0; } else if (strcmp(key, "backtouchscreen_deadzone") == 0) { sscanf(value, "%d,%d,%d,%d", @@ -311,7 +309,6 @@ void config_save(char* filename, PCONFIGURATION config) { if (strcmp(config->app, "Steam") != 0) write_config_string(fd, "app", config->app); - write_config_bool(fd, "fronttouchscreen_buttons", config->fronttouchscreen_buttons); write_config_bool(fd, "disable_powersave", config->disable_powersave); char value[256]; diff --git a/src/gui/guilib.c b/src/gui/guilib.c index bd3231f1..f526edf1 100644 --- a/src/gui/guilib.c +++ b/src/gui/guilib.c @@ -21,6 +21,9 @@ #define BUTTON_DELAY 150 * 1000 +static gui_draw_callback gui_global_draw_callback; +static gui_loop_callback gui_global_loop_callback; + struct menu_geom make_geom_centered(int w, int h) { struct menu_geom geom = {0}; geom.x = WIDTH / 2 - w / 2; @@ -104,6 +107,7 @@ void draw_statusbar(struct menu_geom geom) { battery_color); } +SceTouchData touch_data; SceCtrlData ctrl_new_pad; static SceRtcTick button_current_tick, button_until_tick; @@ -124,6 +128,18 @@ bool is_button_down(short id) { return ctrl_new_pad.buttons & id; } +#define lerp(value, from_max, to_max) ((((value*10) * (to_max*10))/(from_max*10))/10) +bool is_rectangle_touched(int lx, int ly, int rx, int ry) { + for (int i = 0; i < touch_data.reportNum; i++) { + int x = lerp(touch_data.report[i].x, 1919, WIDTH); + int y = lerp(touch_data.report[i].y, 1087, HEIGHT); + if (x < lx || x > rx || y < ly || y > ry) continue; + return true; + } + + return false; +} + void draw_menu(struct menu_entry menu[], int total_elements, struct menu_geom geom, int cursor, int offset) { vita2d_draw_rectangle(geom.x, geom.y, geom.width, geom.height, 0x10ffffff); @@ -265,6 +281,7 @@ void draw_alert(char *message, struct menu_geom geom, char *buttons_captions[], void gui_ctrl_begin() { sceCtrlPeekBufferPositive(0, &ctrl_new_pad, 1); + sceTouchPeek(SCE_TOUCH_PORT_FRONT, &touch_data, 1); } void gui_ctrl_end() { @@ -335,6 +352,11 @@ int display_menu( if (draw_callback && tick_number > 3) { draw_callback(); } + + if (gui_global_draw_callback && tick_number > 3) { + gui_global_draw_callback(); + } + draw_menu(menu, total_elements, geom, cursor, offset); int real_cursor = 0; @@ -356,6 +378,10 @@ int display_menu( exit_code = cb(menu[real_cursor].id, context); } + if (gui_global_loop_callback) { + gui_global_loop_callback(menu[real_cursor].id, context); + } + if (was_button_pressed(SCE_CTRL_CIRCLE)) { if (!back_cb || back_cb(context) == 0) { exit_code = 1; @@ -445,8 +471,15 @@ void flash_message(char *format, ...) { vita2d_swap_buffers(); } -void guilib_init() { +void drw() { + vita2d_draw_rectangle(0, 0, 150, 150, 0xffffffff); +} + +void guilib_init(gui_loop_callback global_loop_cb, gui_draw_callback global_draw_cb) { vita2d_init(); vita2d_set_clear_color(0xff000000); gui_font = vita2d_load_default_pgf(); + + gui_global_draw_callback = global_draw_cb; + gui_global_loop_callback = global_loop_cb; } diff --git a/src/gui/guilib.h b/src/gui/guilib.h index 24be3d48..25a5a054 100644 --- a/src/gui/guilib.h +++ b/src/gui/guilib.h @@ -26,6 +26,7 @@ typedef void (*gui_draw_callback) (void); bool was_button_pressed(short id); bool is_button_down(short id); +bool is_rectangle_touched(int lx, int ly, int rx, int ry); int display_menu( struct menu_entry menu[], @@ -49,4 +50,4 @@ void display_error(char *format, ...); void flash_message(char *format, ...); -void guilib_init(); +void guilib_init(gui_loop_callback global_loop_cb, gui_draw_callback global_draw_cb); diff --git a/src/gui/ui.c b/src/gui/ui.c index 10dbdb0a..d2732147 100644 --- a/src/gui/ui.c +++ b/src/gui/ui.c @@ -7,6 +7,7 @@ #include "ui_connect.h" #include "../config.h" +#include "../connection.h" #include #include @@ -77,8 +78,24 @@ int ui_main_menu() { return display_menu(menu, idx, &geom, &ui_main_menu_loop, &ui_main_menu_back, NULL, NULL); } +int global_loop(int cursor, void *ctx) { + if (is_rectangle_touched(0, 0, 150, 150)) { + if (connection_get_status() == LI_MINIMIZED) { + vitapower_config(config); + vitainput_config(config); + + sceKernelDelayThread(500 * 1000); + connection_resume(); + + while (connection_get_status() == LI_CONNECTED) { + sceKernelDelayThread(500 * 1000); + } + } + } +} + void gui_init() { - guilib_init(); + guilib_init(&global_loop, NULL); } void gui_loop() { diff --git a/src/gui/ui_settings.c b/src/gui/ui_settings.c index 7c1b1ae3..9fd6f805 100644 --- a/src/gui/ui_settings.c +++ b/src/gui/ui_settings.c @@ -338,7 +338,6 @@ enum { SETTINGS_RESOLUTION = 100, SETTINGS_FPS, SETTINGS_BITRATE, - SETTINGS_FRONTTOUCHSCREEN, SETTINGS_DISABLE_POWERSAVE, SETTINGS_ENABLE_MAPPING, SETTINGS_BACK_DEADZONE, @@ -349,10 +348,9 @@ enum { SETTINGS_VIEW_RESOLUTION = 1, SETTINGS_VIEW_FPS, SETTINGS_VIEW_BITRATE, - SETTINGS_VIEW_FRONTTOUCHSCREEN = 5, - SETTINGS_VIEW_DISABLE_POWERSAVE = 7, + SETTINGS_VIEW_DISABLE_POWERSAVE = 5, SETTINGS_VIEW_ENABLE_MAPPING, - SETTINGS_VIEW_BACK_DEADZONE = 11 + SETTINGS_VIEW_BACK_DEADZONE = 9 }; static int move_idx_in_array(char *array[], int count, char *find, int index_dist) { @@ -434,11 +432,6 @@ static int settings_loop(int id, void *context) { } } } break; - case SETTINGS_FRONTTOUCHSCREEN: - if (was_button_pressed(SCE_CTRL_CROSS)) { - did_change = 1; - config.fronttouchscreen_buttons = !config.fronttouchscreen_buttons; - } break; case SETTINGS_DISABLE_POWERSAVE: if (was_button_pressed(SCE_CTRL_CROSS)) { did_change = 1; @@ -477,9 +470,6 @@ static int settings_loop(int id, void *context) { sprintf(current, "%d", config.stream.bitrate); strcpy(menu[SETTINGS_VIEW_BITRATE].subname, current); - sprintf(current, "%s", config.fronttouchscreen_buttons ? "yes" : "no"); - strcpy(menu[SETTINGS_VIEW_FRONTTOUCHSCREEN].subname, current); - sprintf(current, "%s", config.disable_powersave ? "yes" : "no"); strcpy(menu[SETTINGS_VIEW_DISABLE_POWERSAVE].subname, current); @@ -514,8 +504,6 @@ int ui_settings_menu() { // --------- menu[idx++] = (struct menu_entry) { .name = "Input", .disabled = true, .separator = true }; - idx++; menu[SETTINGS_VIEW_FRONTTOUCHSCREEN] = (struct menu_entry) { .name = "Use front touchscreen for buttons", .id = SETTINGS_FRONTTOUCHSCREEN }; - menu[idx++] = (struct menu_entry) { .name = "", .disabled = true, .subname = "Disables mouse input and special keys." }; idx++; menu[SETTINGS_VIEW_DISABLE_POWERSAVE] = (struct menu_entry) { .name = "Disable power save", .id = SETTINGS_DISABLE_POWERSAVE }; idx++; menu[SETTINGS_VIEW_ENABLE_MAPPING] = (struct menu_entry) { .name = "Enable mapping file", .id = SETTINGS_ENABLE_MAPPING }; diff --git a/src/input/vita.c b/src/input/vita.c index e7a4d70d..91c9eecf 100644 --- a/src/input/vita.c +++ b/src/input/vita.c @@ -48,17 +48,17 @@ static struct mapping map = {0}; #define lerp(value, from_max, to_max) ((((value*10) * (to_max*10))/(from_max*10))/10) -static bool check_touch(SceTouchData scr, int lx, int ly, int rx, int ry) { +static int check_touch(SceTouchData scr, int lx, int ly, int rx, int ry) { for (int i = 0; i < scr.reportNum; i++) { int x = lerp(scr.report[i].x, 1919, WIDTH); int y = lerp(scr.report[i].y, 1087, HEIGHT); if (x < lx || x > rx || y < ly || y > ry) continue; - return true; + return i; } - return false; + return -1; } -static bool check_touch_sector(SceTouchData scr, int section) { +int check_touch_sector(SceTouchData scr, int section) { int vertical = (WIDTH - config.back_deadzone.left - config.back_deadzone.right) / 2 + config.back_deadzone.left, horizontal = (HEIGHT - config.back_deadzone.top - config.back_deadzone.bottom) / 2 + config.back_deadzone.top; @@ -176,12 +176,12 @@ static short pad_value(SceCtrlData pad, int sec) { bool check_input(short identifier, SceCtrlData pad, SceTouchData screen, SceTouchData front, SceTouchData back) { if (identifier >= TOUCHSEC_NORTHWEST && identifier < TOUCHSEC_SPECIAL_SW) { - return check_touch_sector(screen, identifier); + return check_touch_sector(screen, identifier) != -1; } else if (identifier >= TOUCHSEC_SPECIAL_SW && identifier <= TOUCHSEC_SPECIAL_NE) { if (config.fronttouchscreen_buttons == true) { return false; } else { - return check_touch_sector(front, identifier); + return check_touch_sector(front, identifier) != -1; } } else { identifier = identifier + 1; @@ -213,7 +213,7 @@ static void special_input(SceTouchData screen, int *btn) { unsigned int type = config_code & INPUT_TYPE_MASK; unsigned int code = config_code & INPUT_VALUE_MASK; - if (check_touch_sector(screen, identifier) && !current_status) { + if (check_touch_sector(screen, identifier) != -1 && !current_status) { switch (type) { case INPUT_TYPE_SPECIAL: if (code == INPUT_SPECIAL_KEY_PAUSE) { @@ -231,7 +231,7 @@ static void special_input(SceTouchData screen, int *btn) { LiSendKeyboardEvent(code, KEY_ACTION_DOWN, 0); break; } - } else if (!check_touch_sector(screen, identifier) && current_status) { + } else if (check_touch_sector(screen, identifier) == -1 && current_status) { special_input_status[idx] = false; switch (type) { @@ -281,72 +281,78 @@ void vitainput_process(void) { sceTouchPeek(SCE_TOUCH_PORT_BACK, &back, 1); sceRtcGetCurrentTick(¤t); - if (config.fronttouchscreen_buttons == false) { - switch (front_state) { - case NO_TOUCH_ACTION: - if (front.reportNum > 0) { - front_state = ON_SCREEN_TOUCH; - finger_count = front.reportNum; - sceRtcTickAddMicroseconds(&until, ¤t, MOUSE_ACTION_DELAY); + input_data input = {0}; + + SceTouchData buttons_screen = config.fronttouchscreen_buttons ? front : back; + special_input(front, &input.button); + + for (int i = TOUCHSEC_SPECIAL_NW, touchIdx = -1; i <= TOUCHSEC_SPECIAL_SE; i++) { + unsigned int config_code = special_input_config_code(i); + if (config_code && (touchIdx = check_touch_sector(front, i)) != -1) { + for (int n = 0, idx = 0; n < front.reportNum; n++) { + if (n != touchIdx) { + front.report[idx++] = front.report[n]; } - break; - case ON_SCREEN_TOUCH: - if (sceRtcCompareTick(¤t, &until) < 0) { - if (front.reportNum < finger_count) { - // TAP - if (mouse_click(front, finger_count, true)) { - front_state = SCREEN_TAP; - sceRtcTickAddMicroseconds(&until, ¤t, MOUSE_ACTION_DELAY); - } else { - front_state = NO_TOUCH_ACTION; - } - } else if (front.reportNum > finger_count) { - // finger count changed - finger_count = front.reportNum; + } + + front.reportNum--; + } + } + + switch (front_state) { + case NO_TOUCH_ACTION: + if (front.reportNum > 0) { + front_state = ON_SCREEN_TOUCH; + finger_count = front.reportNum; + sceRtcTickAddMicroseconds(&until, ¤t, MOUSE_ACTION_DELAY); + } + break; + case ON_SCREEN_TOUCH: + if (sceRtcCompareTick(¤t, &until) < 0) { + if (front.reportNum < finger_count) { + // TAP + if (mouse_click(front, finger_count, true)) { + front_state = SCREEN_TAP; + sceRtcTickAddMicroseconds(&until, ¤t, MOUSE_ACTION_DELAY); + } else { + front_state = NO_TOUCH_ACTION; } - } else { - front_state = SWIPE_START; + } else if (front.reportNum > finger_count) { + // finger count changed + finger_count = front.reportNum; } - break; - case SCREEN_TAP: - if (sceRtcCompareTick(¤t, &until) >= 0) { - mouse_click(front, finger_count, false); + } else { + front_state = SWIPE_START; + } + break; + case SCREEN_TAP: + if (sceRtcCompareTick(¤t, &until) >= 0) { + mouse_click(front, finger_count, false); - front_state = NO_TOUCH_ACTION; + front_state = NO_TOUCH_ACTION; + } + break; + case SWIPE_START: + memcpy(&front_old, &front, sizeof(front_old)); + front_state = ON_SCREEN_SWIPE; + break; + case ON_SCREEN_SWIPE: + if (front.reportNum > 0) { + switch (front.reportNum) { + case 1: + move_mouse(front_old, front); + break; + case 2: + move_wheel(front_old, front); + break; } - break; - case SWIPE_START: memcpy(&front_old, &front, sizeof(front_old)); - front_state = ON_SCREEN_SWIPE; - break; - case ON_SCREEN_SWIPE: - if (front.reportNum > 0) { - switch (front.reportNum) { - case 1: - move_mouse(front_old, front); - break; - case 2: - move_wheel(front_old, front); - break; - } - memcpy(&front_old, &front, sizeof(front_old)); - } else { - front_state = NO_TOUCH_ACTION; - } - break; - } - - for (int i = TOUCHSEC_SPECIAL_NW; i <= TOUCHSEC_SPECIAL_SE; i++) { - if (check_touch_sector(front, i)) { + } else { front_state = NO_TOUCH_ACTION; } - } + break; } - input_data input = {0}; - - SceTouchData buttons_screen = config.fronttouchscreen_buttons ? front : back; - INPUT(map.btn_dpad_up, UP_FLAG); INPUT(map.btn_dpad_up, UP_FLAG); INPUT(map.btn_dpad_left, LEFT_FLAG); @@ -367,8 +373,6 @@ void vitainput_process(void) { INPUT(map.btn_thumbl, LB_FLAG); INPUT(map.btn_thumbr, RB_FLAG); - special_input(front, &input.button); - // TRIGGERS input.left_trigger = CHECK_INPUT(map.btn_tl) ? 0xff : 0; input.right_trigger = CHECK_INPUT(map.btn_tr) ? 0xff : 0;