-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTutorial4ColorPicker.t
More file actions
42 lines (35 loc) · 1.4 KB
/
Tutorial4ColorPicker.t
File metadata and controls
42 lines (35 loc) · 1.4 KB
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
41
42
module Tutorial4ColorPicker where
import COCOA
mkColorPicker :: World -> (Color -> Action) -> Class CocoaWindow
mkColorPicker w callback = class
CocoaWindow{initWindow=initWindowImpl,..} = new mkCocoaWindow w
initWindow app = request
setSize ({width=215,height=215})
setVisible False
setResizable False
setWindowResponder (new class
onWindowResize _ = request
onWindowCloseRequest = request
result RespondsToWindowEvents{..}) True
initGrid
initWindowImpl app
initGrid = do
tileSize = 12
forall x <- [1..16] do
forall y <- [1..16] do
tile = new mkCocoaContainer w
tile.setSize ({width=tileSize,height=tileSize})
tile.setPosition ({x=tileSize*x,y=tileSize*y})
tileColor = ({r=128,g=16*x,b=16*y})
tile.setBackgroundColor tileColor
tile.addResponder ({respondToInputEvent=invokeCallback tileColor})
addComponent tile
invokeCallback color (MouseEvent (MouseClicked _)) _ = request
send callback color
result Consumed
invokeCallback color (MouseEvent (MouseMoved _)) modifiers = request
if elem Shift modifiers then send callback color
result Consumed
invokeCallback _ _ _ = request
result Consumed
result CocoaWindow{..}