Browse files

added mouse events to buttons

  • Loading branch information...
1 parent 1b38b1c commit e67eb0768085662d3fef71c89ca259036a6a89d9 Nik Nyby committed Apr 26, 2010
Showing with 32 additions and 3 deletions.
  1. +31 −2 Bindings.hs
  2. +1 −1 makefile
View
33 Bindings.hs
@@ -6,6 +6,7 @@ import Data.IORef
import Data.List ((\\))
import Graphics.UI.GLUT
+import Menu
import Rectangle
import State
import Sprite
@@ -49,11 +50,33 @@ animatorAction e (MouseButton RightButton) Down =
e { sprites = (makeSprite (mousePos $ vars $ e)) : sprites e }
animatorAction e (MouseButton LeftButton) Down =
- e { sprites = (updateSelected . updateDragged) (sprites e) }
+ e { sprites = (updateSelected . updateDragged) (sprites e),
+
-- TODO: map over MmaMenu?
- --vars { menu
+ vars = (vars e) { menu = MmaMenu {
+ playButton = updateButton $ (playButton$menu$vars$e),
+
+ sprtWindow = updateWindow $ (sprtWindow$menu$vars$e),
+ nextSprtButton = updateButton $ (nextSprtButton$menu$vars$e),
+ prevSprtButton = updateButton $ (prevSprtButton$menu$vars$e),
+
+ bgWindow = updateWindow $ (bgWindow$menu$vars$e),
+ nextBgButton = updateButton $ (nextBgButton$menu$vars$e),
+ prevBgButton = updateButton $ (prevBgButton$menu$vars$e),
+
+ frameWindow = updateWindow $ (frameWindow$menu$vars$e),
+ prevFrameButton = updateButton $ (prevFrameButton$menu$vars$e),
+ nextFrameButton = updateButton $ (nextFrameButton$menu$vars$e),
+
+ saveButton = updateButton $ (saveButton$menu$vars$e)
+ }
+ }
+ }
+
where
+ --
-- TODO: just look at this mess!
+ --
updateSelected :: [Sprite] -> [Sprite]
updateSelected ss = map (\s -> s {selected=True}) (spriteUnder ss) ++
map (\s -> s {selected=False}) (ss \\ (spriteUnder ss))
@@ -69,6 +92,12 @@ animatorAction e (MouseButton LeftButton) Down =
oneOrNone :: [a] -> [a]
oneOrNone x = if length x >= 1 then [head x] else []
+ updateButton :: MmaButton -> MmaButton
+ updateButton b = b { buttonState = within mp (buttonRect b) }
+
+ updateWindow :: MmaWindow -> MmaWindow
+ updateWindow w = w
+
mp :: Position
mp = mousePos $ vars $ e
View
2 makefile
@@ -3,4 +3,4 @@ build:
ghc --make -package GLUT -Wall -O2 Main.hs -o mma
clean:
- rm *.hi *.o mma
+ rm *.hi *.o mma \#*\#

0 comments on commit e67eb07

Please sign in to comment.