
With the mouseFunc callback, it is very easy to recognize if the user has clicked in a point that belongs to a square:
mouse :: MouseAction mouse (WindowPosition x y) _ = -- check if (x,y) is inside the square
I'm trying to do the same using module UserInput.hs (you can find it in the "Misc" directory), but I'm not succeeding. The problem is that, when you use UserInput, you need to bind an input event to an action, such as:
bindKey (KeyMouse LeftButton) Press (Just quitProgram)
I changed the definition of the KeyMouse construct to
KeyMouse MouseButton Windowposition
rather than only
KeyMouse MouseButton
but this still doesn't solve my problem. Does anyone have an idea? The only think I can do by now is to bind ALL the points of the square to the desired action, but this is surely not the best solution... Thanks a lot, -- Andre

Andre W B Furtado wrote:
With the mouseFunc callback, it is very easy to recognize if the user has clicked in a point that belongs to a square: [...] I'm trying to do the same using module UserInput.hs. [...]
First of all, I've never imagined that anybody would actually have a deeper look at examples/misc... :-) My suggestion is to extend the type of the callback action, i.e. change type KeyBinder = Key -> KeyEvent -> Maybe (IO ()) -> IO () to type KeyBinder = Key -> KeyEvent -> Maybe (WindowPosition -> IO ()) -> IO () and adapt UserInput.initUserInput in the obvious way. Does this help? Cheers, S.

Andre W B Furtado wrote:
With the mouseFunc callback, it is very easy to recognize if the user has clicked in a point that belongs to a square: [...] I'm trying to do the same using module UserInput.hs. [...]
Sven Panne wrote:
First of all, I've never imagined that anybody would actually have a deeper look at examples/misc... :-)
Actually, I think module UserInput is the best solution for FunGEn to deal with input events...
My suggestion is to [...] Does this help?
I used a similar though: I modified the Key data. Now the KeyMouse is: KeyMouse MouseButton MouseRegion Where MouseRegion is: data MouseRegion = Point Int Int | RectangleArea (Int,Int) (Int,Int) Orientation | CircleArea (Int,Int) Float Orientation | PolygonArea [(Int,Int)] Orientation | Anywhere and data Orientation = Inside | Outside Now it is possible to check if the used has clicked inside/outside a pre-defined region, such as a circle, a rectangle or other convex polygon. If no specific region is desired, "Anywhere" can be used. Finally, it is also possible to check if the point clicked is an exact point in the screen (using "Point x y"). I'm sending this UserInput upgrade attached. Perhaps Sven would like to add it to the next release of HOpenGL? :) Cheers, -- Andre
participants (2)
-
Andre W B Furtado
-
Sven Panne