1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
#include <android/native_window_jni.h>
#include "common/logging/log.h"
#include "input_common/drivers/touch_screen.h"
#include "input_common/drivers/virtual_gamepad.h"
#include "input_common/main.h"
#include "jni/emu_window/emu_window.h"
void EmuWindow_Android::OnSurfaceChanged(ANativeWindow* surface) {
render_window = surface;
}
bool EmuWindow_Android::OnTouchEvent(float x, float y, bool pressed) {
if (pressed) {
input_subsystem->GetTouchScreen()->TouchPressed(NormalizeX(x), NormalizeY(y), 0);
return true;
}
input_subsystem->GetTouchScreen()->ReleaseAllTouch();
return true;
}
void EmuWindow_Android::OnTouchMoved(float x, float y) {
input_subsystem->GetTouchScreen()->TouchMoved(NormalizeX(x), NormalizeY(y), 0);
}
void EmuWindow_Android::OnGamepadEvent(int button_id, bool pressed) {
input_subsystem->GetVirtualGamepad()->SetButtonState(0, button_id, pressed);
}
void EmuWindow_Android::OnGamepadMoveEvent(float x, float y) {
input_subsystem->GetVirtualGamepad()->SetStickPosition(
0, InputCommon::VirtualGamepad::VirtualStick::Left, x, y);
}
EmuWindow_Android::EmuWindow_Android(InputCommon::InputSubsystem* input_subsystem_,
ANativeWindow* surface_)
: input_subsystem{input_subsystem_} {
LOG_INFO(Frontend, "initializing");
if (!surface_) {
LOG_CRITICAL(Frontend, "surface is nullptr");
return;
}
window_width = ANativeWindow_getWidth(surface_);
window_height = ANativeWindow_getHeight(surface_);
// Ensures that we emulate with the correct aspect ratio.
UpdateCurrentFramebufferLayout(window_width, window_height);
host_window = surface_;
window_info.type = Core::Frontend::WindowSystemType::Android;
window_info.render_surface = reinterpret_cast<void*>(host_window);
input_subsystem->Initialize();
}
EmuWindow_Android::~EmuWindow_Android() {
input_subsystem->Shutdown();
}
|