Forum Archive

Getting at ObjC touch instance from Scene?

trey

I have a Scene-based program where I’d like to distinguish between finger and Pencil touch events.

An example from omz showed how to do this in a ui.View; in the touch_* methods, use ObjCInstance on the touch argument:

    def touch_moved(self, touch):
        ui_touch = ObjCInstance(touch)

then, I have verified, you can check the value of ui_touch.type() to determine if the touch is from a finger (0) or a Pencil (2).

Unfortunately, I found out if you attempt to do the same in a Scene, the touch argument to the methods is not compatible with ObjCInstance. You get:

ctypes.ArgumentError: argument 1: <class 'TypeError'>: wrong type

so, I’m wondering how I can get at a Touch object I can use the ObjC bridge with via a Scene?

mikael

@trey, one idea would be to place a transparent view on top (as a subview of scene.view) to handle the touches.

Then you would need to check if the touch is near the top-right corner to simulate clicking on the ”x” with superview.close(). And remember to flip the y coordinate before passing the coordinate and touch type to your scene code. And maybe go via screen coordinates if you do a lot of zooming and panning in your scene.