-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCTContainer.t
160 lines (136 loc) · 5.32 KB
/
CTContainer.t
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
module CTContainer where
import CocoaDef
--------------------------------------------------------------------------------------------------
------ ** CONTAINER ** ----------------------------------------------------------
mkCocoaContainer :: World -> Class Container
mkCocoaContainer w = class
myComponents := []
color := {r=255, g=255, b=255}
alpha := 1.0
appRef := Nothing
state := Inactive
BaseComponent {getAllChildren=dummy, setPosition = setPositionImpl, setSize = setSizeImpl,..} =
new basicComponent False Nothing "Container"
setPosition p = request
if isActive state then
Active ref = state
containerSetPosition ref p
setPositionImpl p
setSize s = request
if isActive state then
Active ref = state
containerSetSize ref s
setSizeImpl s
getAllChildren = request
cs <- forall c <- myComponents do
list <- c.getAllChildren
result list ++ [c] -- order is important here for reactions to mouse events
result concat cs
setBackgroundColor c = setBackgroundColorWithAlpha c 1.0
setBackgroundColorWithAlpha c a = request
if isActive state then
Active ref = state
containerSetBackgroundColor ref c a
color := c
alpha := a
getBackgroundColor = request
result color
addComponent c = request
myComponents := c : myComponents
c.setParent this
if isActive state then
Active ref = state
s <- c.initComp (fromJust appRef)
if isActive s then
Active c_ref = s
containerAddComponent ref c_ref
removeComponent c = request
myComponents := [x | x <- myComponents, not (x == c)]
if isActive state then
Active ref = state
cmpState <- c.getState
if isActive cmpState then
Active cmpRef = cmpState
containerRemoveComponent ref cmpRef
c.destroyComp
removeAllComponents = request
removeAllComponentsImpl
removeAllComponentsImpl = do
if isActive state then
Active ref = state
forall c <- myComponents do
s <- c.getState
if isActive s then
Active c_ref = s
containerRemoveComponent ref c_ref
c.destroyComp
myComponents := []
getComponents = request
result myComponents
destroyComp = request
if (isActive state) then
removeAllComponentsImpl
Active ref = state
destroyContainer ref
state := destroyState state
initComp app = request
if isInactive state then
appRef := Just app
ref <- initContainer w
state := Active ref
containerSetSize ref (<-getSize)
containerSetBackgroundColor ref color alpha
containerSetPosition ref (<-getPosition)
forall c <- myComponents do
s <- c.initComp app
if isActive s then
Active c_ref = s
containerAddComponent ref c_ref
result state
getState = request
result state
this = Container {id = self,..}
result this
basicHasResponders :: Class DefaultEventResponder
basicHasResponders = class
responders := []
addResponder a = request
responders := responders ++ [a]
setResponders aa = request
responders := aa
getResponders = request
result responders
-- return true (block cocoa) if any of the installed responders say so
returnVal := NotConsumed
respondToInputEvent inputEvent modifiers = request
returnVal := NotConsumed
forall h <- responders do
if returnVal == NotConsumed then
returnVal := <- h.respondToInputEvent inputEvent modifiers
result returnVal
result DefaultEventResponder {..}
basicComponent :: Bool -> (Maybe Component) -> String -> Class BaseComponent
basicComponent f p n = class
DefaultEventResponder {..} = new basicHasResponders
(getName,setName) = new wrapper n
(getParent,setParentImpl) = new wrapper p
setParent p = request setParentImpl (Just p)
(getIsFocusable,setIsFocusable) = new wrapper f
(getPosition,setPosition) = new wrapper ({x=0, y=0})
(getSize,setSize) = new wrapper ({width=100, height=100})
getAllChildren = request result []
result BaseComponent {..}
private
wrapper :: a -> Class (Request a, a -> Request ())
wrapper s = class
a := s
set b = request a := b
get = request result a
result (get,set)
extern initContainer :: World -> Request CocoaRef
extern destroyContainer :: CocoaRef -> Request ()
extern containerSetBackgroundColor :: CocoaRef -> Color -> Float -> Request ()
extern containerSetSize :: CocoaRef -> Size -> Request ()
extern containerSetPosition :: CocoaRef -> Position -> Request ()
extern containerAddComponent :: CocoaRef -> CocoaRef -> Request ()
extern containerRemoveComponent :: CocoaRef -> CocoaRef -> Request ()