Permalink
Browse files

cleaned up selection

  • Loading branch information...
1 parent e7decd3 commit 854d9d0f281591736156258462be2ca4948c853a Nik Nyby committed Mar 24, 2010
Showing with 25 additions and 14 deletions.
  1. +4 −5 Bindings.hs
  2. +0 −1 Main.hs
  3. +8 −5 Render.hs
  4. +13 −3 Sprite.hs
View
@@ -50,13 +50,12 @@ animatorAction e (MouseButton LeftButton) Down =
where
-- TODO: just look at this mess!
updateSelected :: [Sprite] -> [Sprite]
- --updateSelected ss = map (\s -> s {selected=True}) (spritesUnder ss)
- -- ++ map (\s -> s {selected=False}) (theRest ss)
- updateSelected ss = map (\s -> s {selected=True}) (spriteUnder ss) ++ map (\s -> s {selected=False}) (ss \\ (spriteUnder ss))
+ updateSelected ss = map (\s -> s {selected=True}) (spriteUnder ss) ++
+ map (\s -> s {selected=False}) (ss \\ (spriteUnder ss))
updateDragged :: [Sprite] -> [Sprite]
- --updateDragged ss = map (initDragSprite mp) (spritesUnder ss) ++ (theRest ss)
- updateDragged ss = map (initDragSprite mp) (spriteUnder ss) ++ (ss \\ spriteUnder ss)
+ updateDragged ss = map (initDragSprite mp) (spriteUnder ss) ++
+ (ss \\ spriteUnder ss)
spriteUnder :: [Sprite] -> [Sprite]
spriteUnder ss = oneOrNone $ filter (within mp) ss
View
@@ -36,7 +36,6 @@ main = do
let
moveCursor p = do
(Env v sp) <- readIORef env
- --print p
writeIORef env $ Env v{mousePos = p} sp
trans :: Position -> IO Position
View
@@ -18,7 +18,6 @@ drawWorld e =
drawAnimator :: Env -> MmaTextures -> IO ()
drawAnimator e t = do
- --currentColor $= Color4 0.2 0 0.3 0
mapM_ (drawSprite) $ sprites e
drawMenu (menu $ vars $ e) t
@@ -33,12 +32,16 @@ drawIntro e t = do
drawSprite :: Sprite -> IO ()
drawSprite s = do
- currentColor $= if selected s
- then Color4 1 0.7 0.5 0
- else Color4 0.2 0 0.3 0
-
+ currentColor $= Color4 0.2 0 0.3 0
renderPrimitive Quads $ mapM_ vertex $ spritePoints s
+ -- TODO: why isn't this transparent?
+ if selected s
+ then do
+ currentColor $= Color4 0.85 0 0.4 0.8
+ renderPrimitive Quads $ mapM_ vertex $ selectPoints s
+ else return ()
+
drawMenu :: MmaMenu -> MmaTextures -> IO ()
drawMenu m t = do
drawTexture 0 0 (menuTexture t) 1
View
@@ -3,6 +3,7 @@ module Sprite (
Rectangle(..),
makeSprite,
spritePoints,
+ selectPoints,
initDragSprite,
dragSprite,
within,
@@ -40,7 +41,16 @@ makeSprite (Position x y) =
Sprite (Rectangle (conv x) (conv y) 20 20) [] False False (0,0)
spritePoints :: Sprite -> [Vertex2 GLdouble]
-spritePoints s = vertexRect (rectangle s)
+spritePoints s = vertexRect $ rectangle s
+
+-- calculate a rectangle around the sprite
+selectPoints :: Sprite -> [Vertex2 GLdouble]
+selectPoints s = vertexRect $ r
+ { rectWidth = rectWidth r + 8.0,
+ rectHeight = rectHeight r + 8.0
+ }
+ where
+ r = rectangle s
-- start dragging a sprite
initDragSprite :: Position -> Sprite -> Sprite
@@ -77,5 +87,5 @@ vertexRect (Rectangle x y width height) =
, (Vertex2 (x+w) (y-h))
, (Vertex2 (x+w) (y+h))]
where
- w = width / 2
- h = height / 2
+ w = width / 2
+ h = height / 2

0 comments on commit 854d9d0

Please sign in to comment.