Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Touch control #77

Open
wants to merge 55 commits into
base: main
Choose a base branch
from
Open

Touch control #77

wants to merge 55 commits into from

Conversation

XITRIX
Copy link

@XITRIX XITRIX commented Feb 3, 2021

I've made a basic touch-event system, hope it could be useful.

# Conflicts:
#	library/borealis.mk
#	library/include/borealis/platforms/switch/switch_platform.hpp
# Conflicts:
#	library/include/borealis/core/platform.hpp
#	library/include/borealis/platforms/glfw/glfw_platform.hpp
#	library/include/borealis/platforms/switch/switch_platform.hpp
#	library/include/borealis/views/view.hpp
#	library/lib/platforms/glfw/glfw_platform.cpp
#	library/lib/platforms/switch/switch_platform.cpp
#	library/lib/views/scrolling_frame.cpp
#	library/meson.build
@natinusala
Copy link
Owner

Hey, thanks for the PR! I'm sorry I didn't get to review it the first time, seeing that it's pretty large.

It's going to take me some time to process everything, can you maybe explain quickly how your implementation works / how is its architecture? Thanks!

@natinusala
Copy link
Owner

It does not look like your branch is building for Switch, I see glfw / OpenGL stuff being built 🙁

@XITRIX
Copy link
Author

XITRIX commented Feb 11, 2021

That's strange... Merged yoga branch right now and checked, make clean / make -j works fine.

@natinusala
Copy link
Owner

You added glfw back to the Switch Makefile it seems

@XITRIX
Copy link
Author

XITRIX commented Feb 11, 2021

Oh, I remember, in one of your old commits it was there, and I could not build nro, so I removed it by my self but not commited it, cause I thought you need it for any reason.
Is my last commit building? I checked, where is no glfw in makefile right now.

@natinusala
Copy link
Owner

I was able to try it by removing the glfw line in the Makefile.

It works quite well, good job! Don't forget to add your name to the copyrights if you didn't already 😄

I don't know how far you wanted to go with your code, but there are a few things I noticed:

  • when we use touch, the highlight doesn't disappear, while it does in HOS, it can be fixed by having a "touch" mode that's enabled when we use touch and disabled when we use the controller
  • some gestures are a bit sloppy, especially scrolling, it doesn't accelerate when we flick the finger for instance. I think RetroArch has some pretty good acceleration code that's GPL so we can use it!
  • pressing things only moves the highlight cursor, it doesn't actually "click" the thing. I think it should run the "A" (or "click") action if there's any on the clicked view. If you look on HOS, touching things with the finger actually clicks them.
  • if you try to touch something that's not fully in view (so if it's clipped by scrolling), you won't be able to touch it, whereas in what you did it becomes focused and scrolls to the center. That's tied to the "fancy" scrolling that's not yet implemented in borealis so we can take care of it later I think.
  • there's no audio but that's polishing for later 😛

How do you want to proceed? Do you want me to look at the code and review it before changing anything? Or do you want to tackle some of these issues first?

@natinusala
Copy link
Owner

In qlaunch when you touch on things, you need to touch them once to select them THEN touch them another time to click them. So actually borealis views should have two modes: a "touch to click" one and a "touch to highlight, touch another time to click" mode

@XITRIX
Copy link
Author

XITRIX commented Feb 11, 2021

I think if you'll review it, it will be better cause I'm new in c++ (I'm c#/swift developer).
I tried to implement something similar like iOS handles touches, and I had a problem with idea of how acceleration on scroll should work so I'll try to find how it works in RetroArch.
I know about current problems it have, cause I just used default giveFocus on items without any modifications. If you think it's ok, and you'd like me to continue touch development, I'll be happy to help with it :)

@XITRIX
Copy link
Author

XITRIX commented Feb 11, 2021

Also I have no sounds in borealis at all, do you have any idea of why that could be?

@natinusala
Copy link
Owner

Sound is only implemented on Switch right now, are you trying on Switch? It works for me, does it not work for you?

@XITRIX
Copy link
Author

XITRIX commented Feb 11, 2021

Yes, I'm trying on switch with atmosphere 17.1, hos 11.1

@natinusala
Copy link
Owner

Using touch or controller? Do you see anything relevant in the logs?

@XITRIX
Copy link
Author

XITRIX commented Feb 11, 2021

Controller, I know that I've not implemented sound with touch. That what inside logs, I'm not sure what qlaunch is, may be it's some kind related:
image

@natinusala
Copy link
Owner

Is your hbloader old by any chance?

@XITRIX
Copy link
Author

XITRIX commented Feb 11, 2021

It's v3.4.0

@XITRIX
Copy link
Author

XITRIX commented Feb 11, 2021

oh, it's hbmenu
I'll check right now, but I think it's latest one
upd. no way it's outdated, it was installed with latest atmosphere 18.0 (updated half an hour ago)

@HookedBehemoth
Copy link

This is a filesystem permission issue. The qlaunch romfs is accessible with hbloader since v2.3.3.

Don't use forwarders.

@XITRIX
Copy link
Author

XITRIX commented Feb 12, 2021

I got it, I don't know why, but I cannot run hbmenu by holding R while running any title (albums works fine, but it's an applet), so I created a forwarder for hbmenu. It worked fine when I was on SXOS, but after updating on Atmosphere it stoped working, do you know any reason of why that could happen?

@natinusala
Copy link
Owner

It looks like a botched Atmos install and/or config to me 👀

I'm going to read and review the changes when I can, it's a big PR so it might take me a while to take in lol

@natinusala
Copy link
Owner

Tell me how you would test scrolling without a super long text?

@XITRIX
Copy link
Author

XITRIX commented Mar 23, 2021

+1, I used it to test long scrolling view. True, it's on Russia, but I could replace it with lorem ipsum text. It was the first I found in google with "super long text" request.

Also I've found, that there is the problem with cyrillic character "Ц" in glfw version of font, it shows like " ," without "U".

@EmmmaTech
Copy link
Contributor

It's understandable if the super long text is for the scrolling, but yeah the text should be changed to the lorem ipsum example.

You could also move the current example to another folder for Russian text.

@EmmmaTech
Copy link
Contributor

Tell me how you would test scrolling without a super long text?

Well, I thought an alternative could be a bunch of elements that you scroll down on. For example, a bunch of pictures on the screen, maybe some big buttons that do nothing, rectangles? And yes, I'm aware my example is similar to the first tab in the demo.

@XITRIX
Copy link
Author

XITRIX commented Mar 24, 2021

I've changed sound processing a bit. Now I'm not calling play() inside recognizer's callback anymore, now I'm setting sound to the pointer, provided by recognitionLoop() and play it inside Application. If there are several recognizers with custom sound, only the closest to the firstFesponder will be taken.

@EmmmaTech
Copy link
Contributor

I wanted to try this out, and I like it. It controls pretty smoothly, even on a Mac. Only one suggestion (might be hard to implement), I wish the scrolling on GLFW platforms was easier to do (what I mean is adding support for the scroll-wheel).

@XITRIX
Copy link
Author

XITRIX commented Mar 25, 2021

I thought a lot about scrolling by wheel but I cannot realise how could I do that without any problem for users of Borealis...
The main idea is to allow pan gesture recognizer work with both scenarious, like it works on iOS apps ported on Mac, it's gestures automatically translates to Mac's equivalents.
I think first of all I need to separate mouse from touches and implement separate recognition scenarious for it.

@natinusala
Copy link
Owner

natinusala commented Mar 26, 2021 via email

@XITRIX
Copy link
Author

XITRIX commented Mar 28, 2021

I've added mouse scrolling, tried to use as less code as possible. Review it please.

@natinusala
Copy link
Owner

Is it implemented as part of touch or separately? Because scrolling using the wheel doesn't make sense in a touch context, since... touch screens don't have a mouse wheel. If it works it's fine but it's weird to have a hybrid touch emulation / scroll wheel on a computer.

I would rather implememt mouse as mouse with its own defined behavior and stuff

@XITRIX
Copy link
Author

XITRIX commented Mar 28, 2021

As you could guess, I'm using ios and macos as reference. Apple's UIKit has auto adaptation of its gesture recognizers for touch and mouse, so I can use the same recognizer on both platforms. I wanted to implement something like that, but right now I've implemented only scrolling wheel as separate part for mouse. May be I should fully separate their inputs and combine them in single struct i.e. "ScreenInput" and toss it through recognizers, but that will double the code of recognizers, cause then we'll need to handle both touch and mouse. I'm still not sure what will be the best solution, so decided to write something what will not have too many lines of code and will be easy to replace later.

@EmmmaTech
Copy link
Contributor

Wow, it works really fluently! It feels like i'm using a web browser, which is good.

@natinusala
Copy link
Owner

@XITRIX And what purpose does it serve at the moment? Does mouse still act as a touch pointer on PC? Isn't it weird to have a half touch half mouse thing?

@XITRIX
Copy link
Author

XITRIX commented Mar 30, 2021

You could test it, it works perfectly fine now, like it should work on PC.
Tap works the same on touch and mouse click, Pan also works the same like drag and drop event, and I've made another recognizer - Scroll one, which with touch works the same way as pan, but on PC also handles scrolling wheel. Also I've added NO_TOUCH_SCROLLING define for platforms without touch input, so mouse will not be able to scroll by dragging that window.

Copy link
Owner

@natinusala natinusala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are some more tiny comments, I think I'm starting to get through the review!

Once I go through the whole code I'll try it once again on PC and on Switch to see how it looks and feels, and see if there are little things that need to be tweaked here and there.

library/include/borealis/core/audio.hpp Outdated Show resolved Hide resolved
library/include/borealis/core/input.hpp Outdated Show resolved Hide resolved
*
* Child of Pan recognizer.
* The only difference is that Scroll recognizer will translate scrolling wheel to pan gestures.
* If NO_TOUCH_SCROLLING=true defined, will ignore scrolling by touch.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the "should touch scroll" boolean be defined in the platform instead of as a define?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think while it's temporary solution there is no reason to create separate variable for that.
When mouse will be separated from touch, scroll will not trigger by mouse dragging the view.

library/include/borealis/core/touch/tap_gesture.hpp Outdated Show resolved Hide resolved
library/include/borealis/platforms/switch/switch_input.hpp Outdated Show resolved Hide resolved
@@ -149,6 +150,7 @@ void Application::createWindow(std::string windowTitle)
bool Application::mainLoop()
{
static ControllerState oldControllerState = {};
static View* firstResponder;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

touchFirstResponder ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it will be used also for mouse , so may be leave it as is?

switch (touchState.phase)
{
case TouchPhase::START:
Logger::debug("Touched at X: " + std::to_string(touchState.position.x) + ", Y: " + std::to_string(touchState.position.y));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to remember to remove all debug prints once we're done

{
Sound sound = firstResponder->gestureRecognizerRequest(touchState, firstResponder);
float pitch = 1;
if (sound == SOUND_TOUCH)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC in HOS there are more sounds that have their pitch randomized, did you poke around to see for yourself?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you hint me what else sounds have randomized pitch? It was the only sound I heard randomized.

library/lib/core/touch/pan_gesture.cpp Show resolved Hide resolved
@natinusala
Copy link
Owner

TODO for me after I'm done reviewing the code:

  • Remember to remove all logs
  • See if everything behaves likes HOS
  • See if sounds behave like HOS
  • Think of how to easily integrate the "tap" gesture to the "click" action we already have, so that it just works (tm)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api design enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants