Search code examples
haskelluser-interfacewxhaskell

How can I obtain device context (DC) in wxHaskell?


I am using wxHaskell to display GUI of simple Haskell game.

I have a problem: I am writing GUI part of the simple game. When game state is updated one of the functions of GUI module is being invoked and new game state parameters are passed. The gui must be updated now. GUI is few rectangles, update of GUI is simply draw some new rectangles over the old ones.

However, to draw the rectangle I need to pass the device context DC as an argument. First painting of the board is done as a result of "on paint" event generated by the panel that contains my rectangles. On Paint handler must have signature:

DC a -> Rect -> IO ()

When the event occurs the dc is passed and board is displayed.

My question: how can I obtain the DC?

Or alternate question: if event handler requires specific signature - how can I pass additional arguments to the handler?


Solution


  • Have a look at the function repaint :: w -> IO (). You pass in the frame/panel you want to get repainted and don´t need the dc. I found the function via the following pdf. Very good wx tutorial. The author is building a simple game as well. Might be helpful. http://web.archive.org/web/20120211184204/http://legacy.cs.uu.nl/daan/download/papers/wxhaskell.pdf