added practicum files, updated gitignore
[fp1415.git] / files / practicum / FrequentielijstGUI.icl
1 implementation module FrequentielijstGUI
2
3 import StdEnv, StdIO
4
5 toonFrequentielijst :: [(a,Int)] *World -> *World | toString a
6 toonFrequentielijst freqs world
7 = startIO SDI Void initGUI [ProcessClose closeProcess] world
8 where
9 nrFreqs = length freqs
10 domain = map fst freqs
11 range = map snd freqs
12 (r_min,r_max) = (minList range, maxList range)
13 r_range = if (r_min <> r_max) (toReal (r_max - r_min + 1)) 1.0
14
15 initGUI = snd o (openWindow Void wdef)
16
17 wdef = Window "Frequentielijst" NilLS
18 [ WindowClose (noLS closeProcess)
19 , WindowLook False look
20 ]
21 look _ {newFrame} picture
22 # (fm,picture) = getPenFontMetrics picture
23 # picture = unfill newFrame picture
24 # picture = setPenColour Red picture
25 # picture = drawAt {x=hMargin,y=h-vMargin} {zero & vx=w} picture
26 # picture = drawAt {x=hMargin,y=h-vMargin} {zero & vy=0-h} picture
27 # picture = setPenColour Black picture
28 # picture = seq [bar (fontLineHeight fm,fm.fDescent) af i \\ af <- freqs & i <- [0..]] picture
29 = picture
30 where
31 frameSize = rectangleSize newFrame
32 (w,h) = (frameSize.w,frameSize.h)
33 wbar = (w-hMargin) / nrFreqs
34 height f = toInt (toReal (h-vMargin) * toReal (f-r_min+1) / r_range)
35
36 bar (fh,fd) (a,f) i picture
37 # picture = fill { corner1={x=hMargin+ i *wbar+1,y=h-vMargin}
38 , corner2={x=hMargin+(i+1)*wbar-1,y=h-vMargin-height f}
39 } picture
40 # (aw,picture) = getPenFontStringWidth (toString a) picture
41 # (fw,picture) = getPenFontStringWidth (toString f) picture
42 # picture = undrawAt {x=hMargin + i*wbar + (wbar-aw)/2, y=h-vMargin-fd} (toString a) picture
43 # picture = undrawAt {x=hMargin + i*wbar + (wbar-fw)/2, y=h-vMargin-height f+fh} (toString f) picture
44 = picture
45
46 hMargin = 10
47 vMargin = 10
48
49 toonFrequentielijst2 :: [(a,Int)] *World -> *World | toString a
50 toonFrequentielijst2 freqs world
51 = startIO SDI Void initGUI [ProcessClose closeProcess] world
52 where
53 nrFreqs = length freqs
54 domain = map fst freqs
55 range = map snd freqs
56 (r_min,r_max) = (minList range, maxList range)
57 r_range = if (r_min <> r_max) (toReal (r_max - r_min + 1)) 1.0
58
59 initGUI = snd o (openWindow Void wdef)
60
61 wdef = Window "Frequentielijst" NilLS
62 [ WindowClose (noLS closeProcess)
63 , WindowLook False look
64 , WindowVScroll (stdScrollFunction Vertical 50)
65 , WindowViewDomain {zero & corner2={x=2^16,y=nrFreqs*20}}
66 ]
67 look _ {newFrame} picture
68 # (fm,picture) = getPenFontMetrics picture
69 # picture = unfill newFrame picture
70 # picture = setPenColour Red picture
71 # picture = drawAt {x=hMargin,y=vMargin} {zero & vx=w} picture
72 # picture = drawAt {x=hMargin,y=vMargin} {zero & vy=nrFreqs*fontLineHeight fm} picture
73 # picture = setPenColour Black picture
74 # picture = seq [bar (fontLineHeight fm,fm.fDescent) af i \\ af <- freqs & i <- [0..]] picture
75 = picture
76 where
77 frameSize = rectangleSize newFrame
78 (w,h) = (frameSize.w,frameSize.h)
79 wbar = (w-hMargin) / nrFreqs
80 height f = toInt (toReal (w-vMargin) * toReal (f-r_min+1) / r_range)
81
82 bar (fh,fd) (a,f) i picture
83 # picture = fill { corner1={y=vMargin+ i *fh,x=hMargin+1}
84 , corner2={y=vMargin+(i+1)*fh,x=hMargin+height f}
85 } picture
86 # (fw,picture) = getPenFontStringWidth (toString f) picture
87 # picture = undrawAt {y=vMargin+(i+1)*fh-fd,x=hMargin + 2} (toString a) picture
88 # picture = undrawAt {y=vMargin+(i+1)*fh-fd,x=hMargin + height f - fw} (toString f) picture
89 = picture