(+) change mode e <-> b

This commit is contained in:
Francesco 2022-07-31 15:48:17 +02:00
parent dc8763a67c
commit 17e5d43a36
1 changed files with 14 additions and 8 deletions

View File

@ -1,22 +1,28 @@
module Canvas where module Canvas where
import Graphics.Gloss.Data.Picture ( Picture, pictures ) import Graphics.Gloss.Data.Picture ( Picture (Text), pictures )
import Graphics.Gloss.Interface.IO.Interact ( Event ) import Graphics.Gloss.Interface.IO.Interact ( Event (EventKey), KeyState (Down), Key (Char) )
newtype Canvas = Canvas { data Canvas = Canvas {
items :: [Picture] items :: [Picture],
mode :: Mode
} }
data Mode = Brush | Eraser deriving (Eq, Show)
initial :: Canvas initial :: Canvas
initial = Canvas { initial = Canvas {
items = [] items = []
, mode = Brush
} }
render :: Canvas -> Picture render :: Canvas -> Picture
render canvas = pictures ( items canvas ) render canvas = pictures ( Text ( show (mode canvas)) : items canvas )
handle :: Event -> Canvas -> Canvas handle :: Event -> Canvas -> Canvas
handle _ _ = initial handle (EventKey (Char 'b') Down _ _ ) canv = canv { mode = Brush }
handle (EventKey (Char 'e') Down _ _ ) canv = canv { mode = Eraser }
handle _ canv = canv
update :: Float -> Canvas -> Canvas update :: Float -> Canvas -> Canvas
update _ _ = initial update _ canv = canv