2

I am working on an android app that is written in Processing 3. It needs to be able to increase a variable when the pinch action "zoom in" is initiated, and decrease when "zoomed out".

Is there a built-in way of doing this in Processing, and if not can someone give me a hint in the right direction to creating my own solution?

Thanks in advance.

Jachdich
  • 782
  • 8
  • 23
  • Take a look at this answer: https://stackoverflow.com/questions/5705923/how-to-detect-the-pinch-zoom-event-with-ongesturelistener-in-android – PedroMazarini May 25 '19 at 18:56
  • @PedroMazarini Thanks but I'm not sure how to implement this in Processing. Could you give me a nudge in the right direction about how to do it? – Jachdich May 25 '19 at 19:39

1 Answers1

2

Take a look at the Ketai Library - KetaiGesture:

Provides gesture recognition services to a processing sketch. To receive gesture events a sketch can define the following methods:

...

onPinch(float x, float y, float r) - x,y of center, r is the distance

Example of code use to change the size of a circle using the Pinch motion:

import ketai.ui.*;
import android.view.MotionEvent;
 
float ellipseWidth = 50;
float ellipseHeight = 50;
KetaiGesture gesture;
 
void setup() {
  size(displayWidth, displayHeight);
  gesture = new KetaiGesture(this);
}
 
void draw() {
  orientation(PORTRAIT);
  background(0);
  fill(0);
  stroke(255);
  ellipse(width/2, height/2, ellipseWidth, ellipseHeight);
}
 
void onPinch (float x, float y, float d) {
  ellipseWidth += d;
  ellipseHeight += d;
}

public boolean surfaceTouchEvent(MotionEvent event) {
  //Call this to keep mouseX and mouseY updated
  super.surfaceTouchEvent(event);
 
  //Forward the event to the class for processing
  return gesture.surfaceTouchEvent(event);
}

Hope this helps!

enter image description here

Community
  • 1
  • 1
vs97
  • 5,765
  • 3
  • 28
  • 41
  • Thanks for answering such a relatively old question! Unfortunately I'm on holiday for a bit and can't test it however I will try to remember when I get back. – Jachdich Jun 23 '19 at 07:30
  • @Jachdich no problem, let us know how you get on and whether it works for you! – vs97 Jun 26 '19 at 17:27
  • @Jachdich has this answer at all resolved your problem? – vs97 Jul 09 '19 at 09:56
  • sorry, I'm still away. As I'm on mobile data, I can't download the huge android SDK to try it out. Unfortunately it may be another 3/4 weeks before I can access my desktop (with Android SDK). – Jachdich Jul 09 '19 at 10:00