ivanperez-keera / gloss-gtk

Embed gloss in Gtk+ programs using gtkglext

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Keyboard handling issue

cheater opened this issue · comments

Hi,
I tried doing some basic keyboard handling in gloss-gtk and found that a couple of things needed to be modified for it in order to work. I attach my email to the Gloss mailing list on Google Groups. It describes the (very few) changes needed. My repo is currently too far customized to submit a pull req though.


Hi guys,
I have just tried gloss-gtk and it's pretty cool. I had to fix some things to make it run but they're mostly straightforward for anyone, just use cabal sandbox and cabal unpack so that you can fix up issues in dependencies. One tricky part was getting keyboard input to work. I was using the GTK backend (Hadn't tried the GLUT or GLFW ones). What gloss-gtk does is it takes a gtk window and attaches a canvas to it and puts glut in it. There were a couple of issues. First of all, in Graphics/UI/GLUTGtk.hs I had to change:

_ <- canvas `on` keyPressEvent      $ tryEvent $ handleKey Down
_ <- canvas `on` keyReleaseEvent    $ tryEvent $ handleKey Up

to

_ <- container `on` keyPressEvent      $ tryEvent $ handleKey Down
_ <- container `on` keyReleaseEvent    $ tryEvent $ handleKey Up

because the canvas itself wasn't getting any keyboard input.

Second of all, that disabled tabbing out of the window. So in Graphics/Gloss/Internals/Interface/Backend/GtkGL.hs, in callbackKeyMouse, I had to add this guard:

| key' == Just (SpecialKey KeyTab)
= throw (PatternMatchFail "cannot handle Tab")

and obviously import the right values:

import           Control.Exception (throw, PatternMatchFail(..))

That worked perfectly. Now I can get keyboard input and it works quite well. For example I added an "undo" action to the "draw" example in gloss-gtk. I extracted the examples to a separate cabal package so that I can build them easily.

I am still trying to figure out how to do antialiasing in Gloss. Has anyone got any tips? I would be very grateful. I think the animations could look much cooler with antialiasing.

Thanks!