Support left/right mouse button

This commit is contained in:
rock88 2020-05-03 20:24:20 +03:00
parent 2270003a43
commit 8e26419f8a
5 changed files with 63 additions and 13 deletions

View file

@ -32,6 +32,7 @@ static int video_decoder_setup(int videoFormat, int width, int height, int redra
static void video_decoder_cleanup() {
ffmpeg_destroy();
frame = NULL;
}
static int video_decoder_submit_decode_unit(PDECODE_UNIT decodeUnit) {

View file

@ -123,10 +123,6 @@ static void update_variables(void) {
}
void retro_run(void) {
// bool updated = false;
// if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &updated) && updated)
// update_variables();
moonlight_libretro_wrapper_init(width, height);
// Handle inputs
@ -159,6 +155,10 @@ void retro_run(void) {
moonlight_libretro_wrapper_handle_mouse_button(0, 0, 0);
}
for (int i = 0; i < RETROK_LAST; i++) {
keyboard_state[i] = input_state_cb(0, RETRO_DEVICE_KEYBOARD, 0, i);
}
// Draw
glBindFramebuffer(RARCH_GL_FRAMEBUFFER, hw_render.get_current_framebuffer());

View file

@ -3,6 +3,7 @@
#include "GameStreamClient.hpp"
#include "gl_render.h"
#include <openssl/ssl.h>
#include "libretro.h"
#include <curl/curl.h>
static bool moonlight_is_initialized = false;
@ -10,6 +11,8 @@ static bool moonlight_is_initialized = false;
static Application* app;
static std::string working_dir;
int16_t keyboard_state[RETROK_LAST];
void moonlight_libretro_wrapper_preinit() {
OpenSSL_add_all_algorithms();
curl_global_init(CURL_GLOBAL_ALL);

View file

@ -3,9 +3,11 @@
#ifdef __cplusplus
#define EXTERN extern "C"
#else
#define EXTERN
#define EXTERN extern
#endif
EXTERN int16_t keyboard_state[];
EXTERN void moonlight_libretro_wrapper_preinit();
EXTERN void moonlight_libretro_wrapper_init(int width, int height);
EXTERN void moonlight_libretro_wrapper_set_working_dir(const char* dir);

View file

@ -5,14 +5,25 @@
#include "video_decoder.h"
#include "audio_decoder.h"
#include "nanovg.h"
#include "moonlight_libretro_wrapper.h"
#include "libretro.h"
#include <algorithm>
static bool pressed = false, sent_l_press = false, sent_r_press = false;
static int current_mouse_x = 0, current_mouse_y = 0;
static int start_mouse_x = 0, start_mouse_y = 0;
using namespace nanogui;
StreamWindow::StreamWindow(Widget *parent, const std::string &address, int app_id): Widget(parent) {
m_address = address;
m_app_id = app_id;
pressed = sent_l_press = sent_r_press = false;
current_mouse_x = parent->width() / 2;
current_mouse_y = parent->height() / 2;
start_mouse_x = start_mouse_y = 0;
LiInitializeStreamConfiguration(&m_config);
int h = 720;
@ -47,7 +58,10 @@ void StreamWindow::setup_stream() {
LiStartConnection(&m_data.serverInfo, &m_config, NULL, &video_decoder_callbacks, &audio_decoder_callbacks, NULL, 0, NULL, 0);
async([this] {
if (m_loader) {
m_loader->dispose();
m_loader = NULL;
}
});
});
@ -63,10 +77,22 @@ void StreamWindow::draw(NVGcontext *ctx) {
}
nvgRestore(ctx);
}
static bool pressed = false;
static int start_mouse_x = 0, start_mouse_y = 0;
// TODO: Get out of here...
if (keyboard_state[RETROK_q]) {
LiStopConnection();
async([this]{
if (m_loader) {
m_loader->dispose();
m_loader = NULL;
}
auto app = static_cast<Application *>(screen());
app->pop_window();
});
}
}
bool StreamWindow::mouse_button_event(const nanogui::Vector2i &p, int button, bool down, int modifiers) {
if (button == 0) {
@ -75,7 +101,22 @@ bool StreamWindow::mouse_button_event(const nanogui::Vector2i &p, int button, bo
start_mouse_y = p.y();
}
pressed = down;
//LiSendMouseButtonEvent(down ? BUTTON_ACTION_PRESS : BUTTON_ACTION_RELEASE, BUTTON_LEFT);
if (pressed && keyboard_state[RETROK_LCTRL]) {
sent_l_press = true;
LiSendMouseButtonEvent(BUTTON_ACTION_PRESS, BUTTON_LEFT);
} else if (sent_l_press) {
sent_l_press = false;
LiSendMouseButtonEvent(BUTTON_ACTION_RELEASE, BUTTON_LEFT);
}
if (pressed && keyboard_state[RETROK_LALT]) {
sent_r_press = true;
LiSendMouseButtonEvent(BUTTON_ACTION_PRESS, BUTTON_RIGHT);
} else if (sent_r_press) {
sent_r_press = false;
LiSendMouseButtonEvent(BUTTON_ACTION_RELEASE, BUTTON_RIGHT);
}
}
return true;
}
@ -83,7 +124,10 @@ bool StreamWindow::mouse_button_event(const nanogui::Vector2i &p, int button, bo
bool StreamWindow::mouse_motion_event(const Vector2i &p, const Vector2i &rel, int button, int modifiers) {
#if defined(__LAKKA_SWITCH__) || defined(__APPLE__)
if (pressed) {
LiSendMouseMoveEvent(p.x() - start_mouse_x, p.y() - start_mouse_y);
current_mouse_x = current_mouse_x + p.x() - start_mouse_x;
current_mouse_y = current_mouse_y + p.y() - start_mouse_y;
LiSendMousePositionEvent(current_mouse_x, current_mouse_y, width(), height());
start_mouse_x = p.x();
start_mouse_y = p.y();