aboutsummaryrefslogtreecommitdiff
path: root/tut6_7_1.icl
blob: c26c24491f3ba91ad5fff90ccc52c12abb2194a5 (plain) (blame)
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
module tut6_7_1

// ********************************************************************************
// Clean tutorial example program.
//
// This program monitors keyboard input that is sent to a Window.
// ********************************************************************************

import StdEnv, StdIO

Start :: *World -> *World
Start world
# (wid, world)      = openId world
# window            = Window "Keyspotting" NilLS [
                        WindowKeyboard (const True) Able (noLS1 (spotting wid)), 
                        WindowId wid, 
                        WindowClose (noLS closeProcess)]
= startIO SDI Void (snd o openWindow Void window) [ProcessClose closeProcess] world
where
    spotting :: Id x (PSt .l) -> PSt .l | toString x
    spotting wid x pst = appPIO (setWindowLook wid True (False, look (toString x))) pst

    look :: String SelectState UpdateState *Picture -> *Picture
    look text _ {newFrame} picture
    # picture           = unfill newFrame picture
    # (width, picture)  = getPenFontStringWidth text picture
    = drawAt {x=(w-width)/2,y=h/2} text picture
    where
        {w,h}           = rectangleSize newFrame