Skip to content

Commit

Permalink
ability to use special keys and mouse input simultaneously; special k…
Browse files Browse the repository at this point in the history
…ey area used by mouse input if key not set; top-right touch anywhere on menus to go back to stream; remove use_fronttouchscreen option
  • Loading branch information
Vasiliy Horbachenko committed Sep 17, 2016
1 parent b39b80e commit 5e34814
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 86 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
build/*
.DS_Store
3 changes: 0 additions & 3 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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];
Expand Down
35 changes: 34 additions & 1 deletion src/gui/guilib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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);

Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
3 changes: 2 additions & 1 deletion src/gui/guilib.h
Original file line number Diff line number Diff line change
Expand Up @@ -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[],
Expand All @@ -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);
19 changes: 18 additions & 1 deletion src/gui/ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "ui_connect.h"

#include "../config.h"
#include "../connection.h"

#include <stdarg.h>
#include <stdio.h>
Expand Down Expand Up @@ -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() {
Expand Down
16 changes: 2 additions & 14 deletions src/gui/ui_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,6 @@ enum {
SETTINGS_RESOLUTION = 100,
SETTINGS_FPS,
SETTINGS_BITRATE,
SETTINGS_FRONTTOUCHSCREEN,
SETTINGS_DISABLE_POWERSAVE,
SETTINGS_ENABLE_MAPPING,
SETTINGS_BACK_DEADZONE,
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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 };

Expand Down
Loading

0 comments on commit 5e34814

Please sign in to comment.