Skip to content

Commit

Permalink
Merge pull request #12382 from hrydgard/touch-test-screen
Browse files Browse the repository at this point in the history
Touchscreen: Apply weihouya's fix, add a touchscreen test screen.
  • Loading branch information
unknownbrackets authored Oct 3, 2019
2 parents 6a16764 + 0b9353b commit 5a4a968
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 3 deletions.
85 changes: 85 additions & 0 deletions UI/ControlMappingScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
30 changes: 28 additions & 2 deletions UI/ControlMappingScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,32 @@ class AnalogTestScreen : public UIDialogScreenWithBackground {
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);
};
1 change: 1 addition & 0 deletions UI/DevScreens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion UI/GameSettingsScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions UI/GameSettingsScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ class DeveloperToolsScreen : public UIDialogScreenWithBackground {
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;
Expand Down
1 change: 1 addition & 0 deletions android/src/org/ppsspp/ppsspp/NativeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,7 @@ public void surfaceCreated(SurfaceHolder holder) {
}

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.
Expand Down

0 comments on commit 5a4a968

Please sign in to comment.