forked from HeinrichApfelmus/threepenny-gui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Drawing.hs
42 lines (30 loc) · 1.15 KB
/
Drawing.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import Control.Monad
import Paths
import System.FilePath
import qualified Graphics.UI.Threepenny as UI
import Graphics.UI.Threepenny.Core
{-----------------------------------------------------------------------------
Main
------------------------------------------------------------------------------}
main :: IO ()
main = startGUI defaultConfig { tpPort = 10000 } setup
setup :: Window -> UI ()
setup window = do
return window # set title "Drawing"
canvas <- UI.canvas
# set UI.height 400
# set UI.width 400
# set style [("border", "solid black 1px")]
clear <- UI.button #+ [string "Clear the canvas."]
getBody window #+ [column
[element canvas, string "Click to places images."]
,element clear
]
dir <- liftIO $ getStaticDir
url <- loadFile "image/png" (dir </> "game" </> "wizard-blue" <.> "png")
img <- UI.img # set UI.src url
let positions = [(x,y) | x <- [0,20..300], y <- [0,20..300]] :: [(Int,Int)]
on UI.click canvas $ const $ forM_ positions $
\xy -> UI.drawImage img xy canvas
on UI.click clear $ const $ do
UI.clearCanvas canvas