← Back

ofxDualTouch

github.com/PeteHaughie/ofxDualTouch · @PeteHaughie
OF 0.12 macOS GUI

Dual-zone multi-touch trackpad input for openFrameworks on macOS

0 0 Last commit 2mo ago Created 2mo ago

README

ofxDualTouch



Dual-zone multi-touch trackpad input for openFrameworks on macOS.

GLFW/OF do not deliver raw trackpad touch events on macOS, so this addon bridges AppKit's NSTouch API directly into OF. Two optional zones (left/right half of the window) each track the first finger that touches them, with easing back to a centre point and click-to-lock behaviour, plus a turnkey controller that wires it all together.

Requirements



via a stub; isAvailable() reports false.

Quick start (turnkey)



#include "ofxDualTouch.h"

class ofApp : public ofBaseApp {
	ofxDualTouchController dualTouch;
	void setup() override { dualTouch.setup(); }
	void update() override { dualTouch.update(ofGetLastFrameTime()); }
	void mousePressed(int x, int y, int button) override { dualTouch.handleMousePressed(x, y, button); }
};


The controller owns a capture and two ofxDualTouchZones:

Call setup() again in windowResized() — it is idempotent and re-swizzles the touch methods and recomputes zone centres.

Raw capture (events + polling)



ofxDualTouchCapture capture;

capture.setup();                                  // must run after the OF window exists
ofAddListener(capture.touchDown, this, &ofApp::onTouchDown);
// ... capture.touchMoved, capture.touchUp with void onTouch...(ofxDualTouchPoint & p)

for (auto & t : capture.getTouches()) {           // polling works too
	ofDrawCircle(t.pos.x, t.pos.y, 10);
}


ofxDualTouchPoint { int id; glm::vec2 pos; } — pos is in window pixels, y-down (already flipped from AppKit's bottom-left origin).

Zones



ofxDualTouchZone implements first-finger-wins tracking plus return-to-centre:

touch it owns. using the current easing function. stays where you leave it (and locks again anywhere you drag it). isTouching(), isLerping(), getLerpProgress().

Eight easings are provided in ofxDualTouchEasing.h (default EASE_OUT_QUAD), as enum, names, and std::function table.

Examples



built on ofxDualTouchController (split, lock, easings, keys). Build with make Release (or make RunRelease) from addons/ofxDualTouch/example-ofxDualTouchZone. circles, finger count, event logging. a top-level OF example.

How it works



ofxDualTouchCapture::setup() finds the OF window (ofGetCocoaWindow()) and uses class_replaceMethod to substitute the content view's touchesBegan/Moved/Ended/CancelledWithEvent: implementations. Touches are normalized from NSTouch.normalizedPosition to window pixels, the Y axis is flipped, and each NSTouch.identity is mapped to a sequential integer id that is released when the finger lifts.

Note: class_replaceMethod swizzles the view's class directly. If you swizzle
a different GL view class, only the same class is affected.

License



MIT, see license.md.

Get this addon

HTTPS
SSH