Skip to content

Commit

Permalink
Merge pull request #30 from xyzz/improved-mouse
Browse files Browse the repository at this point in the history
Improved mouse and special keys support
  • Loading branch information
d3m3vilurr authored Sep 18, 2016
2 parents b39b80e + a17d793 commit cbb4873
Show file tree
Hide file tree
Showing 9 changed files with 181 additions and 129 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
1 change: 0 additions & 1 deletion src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ typedef struct _CONFIGURATION {
bool fullscreen;
bool forcehw;
bool unsupported_version;
bool fronttouchscreen_buttons;
struct touchscreen_deadzone back_deadzone;
struct special_keys special_keys;
bool disable_powersave;
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
32 changes: 11 additions & 21 deletions src/gui/ui_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,19 @@
#include <Limelight.h>

static unsigned int settings_special_codes[] = {0, INPUT_SPECIAL_KEY_PAUSE | INPUT_TYPE_SPECIAL,
1024 | INPUT_TYPE_GAMEPAD,
256 | INPUT_TYPE_GAMEPAD,
512 | INPUT_TYPE_GAMEPAD,
64 | INPUT_TYPE_GAMEPAD,
128 | INPUT_TYPE_GAMEPAD,
SPECIAL_FLAG | INPUT_TYPE_GAMEPAD,
LB_FLAG | INPUT_TYPE_GAMEPAD,
RB_FLAG | INPUT_TYPE_GAMEPAD,
LS_CLK_FLAG | INPUT_TYPE_GAMEPAD,
RS_CLK_FLAG | INPUT_TYPE_GAMEPAD,
LEFT_TRIGGER | INPUT_TYPE_AXIS,
RIGHT_TRIGGER | INPUT_TYPE_AXIS,
BUTTON_LEFT | INPUT_TYPE_MOUSE,
BUTTON_RIGHT | INPUT_TYPE_MOUSE,
BUTTON_MIDDLE | INPUT_TYPE_MOUSE,
27, 73, 77, 9, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123 };
static char *settings_special_names[] = {"None", "Pause stream",
"Special (XBox button)", "LB", "RB", "LS", "RS",
"Special (XBox button)", "LB", "RB", "LS", "RS", "LT", "RT",
"LMB", "RMB", "MMB",
"Esc", "I", "M", "Tab", "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12" };
static bool settings_loop_setup = 1;
Expand Down Expand Up @@ -278,7 +280,7 @@ static void special_keys_draw() {
int special_offset = config.special_keys.offset,
special_size = config.special_keys.size;

unsigned int color = 0xffffffff;
unsigned int color = 0xff006000;

for (int i = TOUCHSEC_SPECIAL_NW; i <= TOUCHSEC_SPECIAL_SE; i++) {
switch (i) {
Expand Down Expand Up @@ -338,7 +340,6 @@ enum {
SETTINGS_RESOLUTION = 100,
SETTINGS_FPS,
SETTINGS_BITRATE,
SETTINGS_FRONTTOUCHSCREEN,
SETTINGS_DISABLE_POWERSAVE,
SETTINGS_ENABLE_MAPPING,
SETTINGS_BACK_DEADZONE,
Expand All @@ -349,10 +350,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 +434,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 +472,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 +506,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 cbb4873

Please sign in to comment.