0

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?

pkuszewski
  • 262
  • 1
  • 12
  • Have you seen the example at http://www.haskell.org/haskellwiki/WxHaskell/Quick_start ? The part in section 3 shows how to use the on paint event to do drawing. – InFreefall Jun 07 '14 at 20:27

1 Answers1

0


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

Schoon
  • 394
  • 1
  • 9
  • That is exactly what I used, but I think that my approach was wrong from the begining. This was my first Haskell project and I still had OOP in mind instead of pure functional programming. Later I started over and got much better results. Thank you for your answer! – pkuszewski Oct 10 '14 at 11:08