Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Mouse Touch event cross compatibility — Gideros Forum

Mouse Touch event cross compatibility

ar2rsawseenar2rsawseen Maintainer
edited August 2012 in General questions
Hello,
does any one know a better solution of Mouse/Touch event cross compatibility.

Basically what I want to do is to make Mouse events behave as single touch event. So I can test my app both on Desktop (with mouse) and on Device (with multi touch support).

For now all I do is adding something similar to every event handler:
if e.x and e.y then
    e.touch = {}
    e.touch.id = 1
    e.touch.x = e.x
    e.touch.y = e.y
end
And I can use same event handlers for both functions and test on both platforms. But I need to modify every event handler with this code and need to add same handlers for both events. Which is bad, because on device both methods are called and of course it is a lot of work to do, especially when you have many different elements.

So maybe anyone knows a better way?

Or maybe event cross compatibility someday would be supported by Gideros? :)

Likes: thomas2k6, krisakti, MichaelStrauss

Dislikes: shu

+1 -1 (+3 / -1 )Share on Facebook

Comments

  • atilimatilim Maintainer
    Accepted Answer
    Hi,

    One possibility can be redefining EventDispather:addEventListener on Windows and Mac OS. I just get your approach and move it one step forward:
    local os = application:getDeviceInfo()
     
    if os == "Windows" or os == "Mac OS" then
    	EventDispatcher.__addEventListener = EventDispatcher.addEventListener
     
    	local function wrapper(t, e)
    		e.touch = {}
    		e.touch.id = 1
    		e.touch.x = e.x
    		e.touch.y = e.y
     
    		if t.data then
    			t.listener(t.data, e)
    		else
    			t.listener(e)
    		end
    	end
     
    	function EventDispatcher:addEventListener(type, listener, data)
    		if type == Event.TOUCHES_BEGIN then
    			self:__addEventListener(Event.MOUSE_DOWN, wrapper, {listener = listener, data = data})
    		elseif type == Event.TOUCHES_MOVE then
    			self:__addEventListener(Event.MOUSE_MOVE, wrapper, {listener = listener, data = data})
    		elseif type == Event.TOUCHES_END then
    			self:__addEventListener(Event.MOUSE_UP, wrapper, {listener = listener, data = data})
    		else
    			self:__addEventListener(type, listener, data)
    		end
    	end
    end
     
     
    local function onTouchesBegin(e)
    	print("begin", e.touch.id, e.touch.x, e.touch.y)
    end
     
    local function onTouchesMove(e)
    	print("move", e.touch.id, e.touch.x, e.touch.y)
    end
     
    local function onTouchesEnd(e)
    	print("end", e.touch.id, e.touch.x, e.touch.y)
    end
     
    stage:addEventListener(Event.TOUCHES_BEGIN, onTouchesBegin)
    stage:addEventListener(Event.TOUCHES_MOVE, onTouchesMove)
    stage:addEventListener(Event.TOUCHES_END, onTouchesEnd)
  • atilimatilim Maintainer

    Or maybe event cross compatibility someday would be supported by Gideros? :)
    Yes this issue is always on my mind :)

    +1 -1 (+2 / -0 )Share on Facebook
  • alexzhengalexzheng Guru
    edited August 2012
    Is this means we will get this feature in next release?

    And we do not need to add mouse events any more?
  • Hi @atilim,

    Yes this issue is always on my mind
    Can we get an update on this topic?
    twitter@TheWindApps Artful applications : The Wind Forest. #art #japan #apps
Sign In or Register to comment.