Touchscreen: Apply weihouya's fix, add a touchscreen test screen. See #12381.

This commit is contained in:
Henrik Rydgård 2019-10-02 22:03:02 +02:00
parent 6a1676413e
commit 0b9353b1dc
6 changed files with 123 additions and 3 deletions

View File

@ -570,3 +570,88 @@ void AnalogTestScreen::CreateViews() {
root_->Add(new Button(di->T("Back")))->OnClick.Handle<UIScreen>(this, &UIScreen::OnBack);
}
bool TouchTestScreen::touch(const TouchInput &touch) {
UIDialogScreenWithBackground::touch(touch);
if (touch.flags & TOUCH_DOWN) {
bool found = false;
for (int i = 0; i < MAX_TOUCH_POINTS; i++) {
if (touches_[i].id == touch.id) {
WLOG("Double touch");
touches_[i].x = touch.x;
touches_[i].y = touch.y;
found = true;
}
}
if (!found) {
for (int i = 0; i < MAX_TOUCH_POINTS; i++) {
if (touches_[i].id == -1) {
touches_[i].id = touch.id;
touches_[i].x = touch.x;
touches_[i].y = touch.y;
break;
}
}
}
}
if (touch.flags & TOUCH_MOVE) {
bool found = false;
for (int i = 0; i < MAX_TOUCH_POINTS; i++) {
if (touches_[i].id == touch.id) {
touches_[i].x = touch.x;
touches_[i].y = touch.y;
found = true;
}
}
if (!found) {
WLOG("Move without touch down: %d", touch.id);
}
}
if (touch.flags & TOUCH_UP) {
bool found = false;
for (int i = 0; i < MAX_TOUCH_POINTS; i++) {
if (touches_[i].id == touch.id) {
found = true;
touches_[i].id = -1;
break;
}
}
if (!found) {
WLOG("Touch release without touch down");
}
}
return true;
}
void TouchTestScreen::CreateViews() {
using namespace UI;
I18NCategory *di = GetI18NCategory("Dialog");
I18NCategory *gr = GetI18NCategory("Graphics");
root_ = new LinearLayout(ORIENT_VERTICAL);
LinearLayout *theTwo = new LinearLayout(ORIENT_HORIZONTAL, new LinearLayoutParams(1.0f));
root_->Add(theTwo);
root_->Add(new CheckBox(&g_Config.bImmersiveMode, gr->T("FullScreen", "Full Screen")))->OnClick.Handle(this, &TouchTestScreen::OnImmersiveModeChange);
root_->Add(new Button(di->T("Back")))->OnClick.Handle<UIScreen>(this, &UIScreen::OnBack);
}
void TouchTestScreen::render() {
UIDialogScreenWithBackground::render();
screenManager()->getUIContext()->BeginNoTex();
for (int i = 0; i < MAX_TOUCH_POINTS; i++) {
if (touches_[i].id != -1) {
screenManager()->getUIContext()->Draw()->Circle(touches_[i].x, touches_[i].y, 100.0, 3.0, 80, 0.0f, 0xFFFFFFFF, 1.0);
}
}
screenManager()->getUIContext()->Flush();
}
void RecreateActivity();
UI::EventReturn TouchTestScreen::OnImmersiveModeChange(UI::EventParams &e) {
System_SendMessage("immersive", "");
if (g_Config.iAndroidHwScale != 0) {
RecreateActivity();
}
return UI::EVENT_DONE;
}

View File

@ -105,6 +105,32 @@ public:
protected:
virtual void CreateViews() override;
UI::TextView *lastKeyEvent_;
UI::TextView *lastLastKeyEvent_;
UI::TextView *lastKeyEvent_ = nullptr;
UI::TextView *lastLastKeyEvent_ = nullptr;
};
class TouchTestScreen : public UIDialogScreenWithBackground {
public:
TouchTestScreen() {
for (int i = 0; i < MAX_TOUCH_POINTS; i++) {
touches_[i].id = -1;
}
}
bool touch(const TouchInput &touch) override;
void render() override;
protected:
struct TrackedTouch {
int id;
int x;
int y;
};
enum {
MAX_TOUCH_POINTS = 10,
};
TrackedTouch touches_[MAX_TOUCH_POINTS]{};
virtual void CreateViews() override;
UI::EventReturn OnImmersiveModeChange(UI::EventParams &e);
};

View File

@ -42,6 +42,7 @@
#include "GPU/GPUState.h"
#include "UI/MiscScreens.h"
#include "UI/DevScreens.h"
#include "UI/ControlMappingScreen.h"
#include "UI/GameSettingsScreen.h"
#ifdef _WIN32

View File

@ -839,7 +839,7 @@ UI::EventReturn GameSettingsScreen::OnScreenRotation(UI::EventParams &e) {
return UI::EVENT_DONE;
}
static void RecreateActivity() {
void RecreateActivity() {
const int SYSTEM_JELLYBEAN = 16;
if (System_GetPropertyInt(SYSPROP_SYSTEMVERSION) >= SYSTEM_JELLYBEAN) {
ILOG("Sending recreate");
@ -1342,6 +1342,7 @@ void DeveloperToolsScreen::CreateViews() {
if (g_Config.iGPUBackend == (int)GPUBackend::VULKAN || g_Config.iGPUBackend == (int)GPUBackend::OPENGL) {
list->Add(new Choice(dev->T("GPU Driver Test")))->OnClick.Handle(this, &DeveloperToolsScreen::OnGPUDriverTest);
}
list->Add(new Choice(dev->T("Touchscreen Test")))->OnClick.Handle(this, &DeveloperToolsScreen::OnTouchscreenTest);
allowDebugger_ = !WebServerStopped(WebServerFlags::DEBUGGER);
canAllowDebugger_ = !WebServerStopping(WebServerFlags::DEBUGGER);
@ -1443,6 +1444,11 @@ UI::EventReturn DeveloperToolsScreen::OnGPUDriverTest(UI::EventParams &e) {
return UI::EVENT_DONE;
}
UI::EventReturn DeveloperToolsScreen::OnTouchscreenTest(UI::EventParams &e) {
screenManager()->push(new TouchTestScreen());
return UI::EVENT_DONE;
}
UI::EventReturn DeveloperToolsScreen::OnJitAffectingSetting(UI::EventParams &e) {
NativeMessageReceived("clear jit", "");
return UI::EVENT_DONE;

View File

@ -173,6 +173,7 @@ private:
UI::EventReturn OnJitDebugTools(UI::EventParams &e);
UI::EventReturn OnRemoteDebugger(UI::EventParams &e);
UI::EventReturn OnGPUDriverTest(UI::EventParams &e);
UI::EventReturn OnTouchscreenTest(UI::EventParams &e);
bool allowDebugger_ = false;
bool canAllowDebugger_ = true;

View File

@ -578,6 +578,7 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C
}
Log.d(TAG, "Surface created. pixelWidth=" + pixelWidth + ", pixelHeight=" + pixelHeight + " holder: " + holder.toString() + " or: " + requestedOr);
NativeApp.setDisplayParameters(pixelWidth, pixelHeight, (int) densityDpi, refreshRate);
getDesiredBackbufferSize(desiredSize);
// Note that desiredSize might be 0,0 here - but that's fine when calling setFixedSize! It means auto.