/usr/share/mozart/doc/demo/node35.html is in mozart-doc 1.4.0-8ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Support widgets: Widgets.oz</TITLE><LINK href="ozdoc.css" rel="stylesheet" type="text/css"></HEAD><BODY><TABLE align="center" border="0" cellpadding="6" cellspacing="6" class="nav"><TR bgcolor="#DDDDDD"><TD><A href="node34.html#code.transportation.randomizer"><< Prev</A></TD><TD><A href="transportation.html">- Up -</A></TD></TR></TABLE><DIV class="unnumbered" id="code.transportation.widgets"><H3><A name="code.transportation.widgets">Support widgets: <CODE>Widgets.oz</CODE></A></H3><P class="margin"><A href="Transport/Widgets.oz">Source File</A></P><P> </P><BLOCKQUOTE><PRE><SPAN class="keyword">functor</SPAN> <BR> <BR><SPAN class="keyword">import</SPAN> <BR> Tk<BR> TkTools<BR> <BR> Configure(images: Images<BR> colors: Colors<BR> fonts: Fonts<BR> capacity: Capacity<BR> delta: Delta<BR> delay: DelayMove)<BR> Country(getCoord<BR> width<BR> height<BR> getGraph<BR> getRoute)<BR> <BR><SPAN class="keyword">export</SPAN> <BR> History<BR> EntryChooser<BR> Truck<BR> map: CountryMap<BR> <BR><SPAN class="keyword">define</SPAN> <BR> <BR> <SPAN class="keyword">local</SPAN> <BR> An = <SPAN class="string">'announce: '</SPAN> <BR> Sp = <SPAN class="string">' '</SPAN> <BR> HistoryWidth = 60<BR> HistoryHeight = 8<BR> HistoryFont = <SPAN class="string">'-adobe-helvetica-medium-r-normal-*-*-100*'</SPAN> <BR> HistoryBg = <SPAN class="string">'#fffff0'</SPAN> <BR> <SPAN class="keyword">in</SPAN> <BR> <BR> <SPAN class="keyword">class</SPAN> <SPAN class="type">History</SPAN> <SPAN class="keyword">from</SPAN><SPAN class="type"> Tk.toplevel</SPAN> <BR> <SPAN class="keyword">attr</SPAN> <BR> mapped:<SPAN class="keyword">false</SPAN> <BR> <SPAN class="keyword">feat</SPAN> <BR> text entry var<BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">init</SPAN>(master:M suffix:U)<BR> History<SPAN class="keyword">,</SPAN> tkInit(parent:M<SPAN class="keyword">.</SPAN>toplevel title:<SPAN class="string">'History: '</SPAN><SPAN class="keyword">#</SPAN>U withdraw:<SPAN class="keyword">true</SPAN> <BR> delete: <SPAN class="keyword">self</SPAN> <SPAN class="keyword">#</SPAN> unmap)<BR> F = {New TkTools<SPAN class="keyword">.</SPAN>textframe tkInit(parent:<SPAN class="keyword">self</SPAN> text:<SPAN class="string">'History: '</SPAN><SPAN class="keyword">#</SPAN>U)}<BR> T = {New Tk<SPAN class="keyword">.</SPAN>text tkInit(parent:F<SPAN class="keyword">.</SPAN>inner<BR> width:HistoryWidth height:HistoryHeight<BR> bg:HistoryBg font:HistoryFont<BR> highlightthickness: 0)}<BR> S = {New Tk<SPAN class="keyword">.</SPAN>scrollbar tkInit(parent:F<SPAN class="keyword">.</SPAN>inner)}<BR> V = {New Tk<SPAN class="keyword">.</SPAN>variable tkInit(<SPAN class="keyword">false</SPAN>)}<BR> E = {New Tk<SPAN class="keyword">.</SPAN>menuentry<SPAN class="keyword">.</SPAN>checkbutton<BR> tkInit(parent: M<SPAN class="keyword">.</SPAN>menu<SPAN class="keyword">.</SPAN>windows<SPAN class="keyword">.</SPAN>menu<BR> label: U<BR> variable: V<BR> action: <SPAN class="keyword">self</SPAN> <SPAN class="keyword">#</SPAN> toggle)}<BR> <SPAN class="keyword">in</SPAN> <BR> {T tkBind(event:<SPAN class="string">'<Map>'</SPAN> action: <SPAN class="keyword">self</SPAN> <SPAN class="keyword">#</SPAN> map)}<BR> {T tkBind(event:<SPAN class="string">'<Unmap>'</SPAN> action: <SPAN class="keyword">self</SPAN> <SPAN class="keyword">#</SPAN> unmap)}<BR> {Tk<SPAN class="keyword">.</SPAN>addYScrollbar T S}<BR> {Tk<SPAN class="keyword">.</SPAN>batch [pack(T S side:left fill:y) pack(F)]}<BR> <SPAN class="keyword">self.</SPAN>text = T<BR> <SPAN class="keyword">self.</SPAN>entry = E<BR> <SPAN class="keyword">self.</SPAN>var = V<BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">setMapped</SPAN>(B)<BR> mapped <SPAN class="keyword"><-</SPAN> B<BR> {<SPAN class="keyword">self.</SPAN>var tkSet(B)}<BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">toggle</SPAN> <BR> {Tk<SPAN class="keyword">.</SPAN>send wm(<SPAN class="keyword">if</SPAN> <SPAN class="keyword">@</SPAN>mapped <SPAN class="keyword">then</SPAN> <BR> iconify<BR> <SPAN class="keyword">else</SPAN> <BR> deiconify<BR> <SPAN class="keyword">end</SPAN> <SPAN class="keyword">self</SPAN>)}<BR> History<SPAN class="keyword">,</SPAN> setMapped({Not <SPAN class="keyword">@</SPAN>mapped})<BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">map</SPAN> <BR> <SPAN class="keyword">if</SPAN> {Not <SPAN class="keyword">@</SPAN>mapped} <SPAN class="keyword">then</SPAN> <BR> {Tk<SPAN class="keyword">.</SPAN>send wm(deiconify <SPAN class="keyword">self</SPAN>)}<BR> <SPAN class="keyword">end</SPAN> <BR> History<SPAN class="keyword">,</SPAN> setMapped(<SPAN class="keyword">true</SPAN>)<BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">unmap</SPAN> <BR> <SPAN class="keyword">if</SPAN> <SPAN class="keyword">@</SPAN>mapped <SPAN class="keyword">then</SPAN> <BR> {Tk<SPAN class="keyword">.</SPAN>send wm(iconify <SPAN class="keyword">self</SPAN>)}<BR> <SPAN class="keyword">end</SPAN> <BR> History<SPAN class="keyword">,</SPAN> setMapped(<SPAN class="keyword">false</SPAN>)<BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">print</SPAN>(V)<BR> Text = <SPAN class="keyword">self.</SPAN>text<BR> <SPAN class="keyword">in</SPAN> <BR> {Text tk(insert <SPAN class="string">'end'</SPAN> V<SPAN class="keyword">#</SPAN><SPAN class="string">'\n'</SPAN>)}<BR> {Text tk(yview pickplace:<SPAN class="string">'end'</SPAN>)}<BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">announce</SPAN>(what:W weight:N src:S dst:D reply:R<SPAN class="keyword"><=unit</SPAN> <SPAN class="keyword">...</SPAN>)<BR> History<SPAN class="keyword">,</SPAN>print(An<SPAN class="keyword">#</SPAN>W<SPAN class="keyword">#</SPAN><SPAN class="string">', '</SPAN><SPAN class="keyword">#</SPAN>N<SPAN class="keyword">#</SPAN><SPAN class="string">'\n'</SPAN><SPAN class="keyword">#</SPAN> <BR> Sp<SPAN class="keyword">#</SPAN><SPAN class="string">'from: '</SPAN><SPAN class="keyword">#</SPAN>S<SPAN class="keyword">#</SPAN><SPAN class="string">' to: '</SPAN><SPAN class="keyword">#</SPAN>D<SPAN class="keyword">#</SPAN> <BR> <SPAN class="keyword">case</SPAN> R<BR> <SPAN class="keyword">of</SPAN> grant <SPAN class="keyword">then</SPAN> <SPAN class="string">'\n'</SPAN><SPAN class="keyword">#</SPAN>Sp<SPAN class="keyword">#</SPAN><SPAN class="string">'granted'</SPAN> <BR> <SPAN class="keyword">[]</SPAN> reject <SPAN class="keyword">then</SPAN> <SPAN class="string">'\n'</SPAN><SPAN class="keyword">#</SPAN>Sp<SPAN class="keyword">#</SPAN><SPAN class="string">'rejected'</SPAN> <BR> <SPAN class="keyword">else</SPAN> <SPAN class="string">''</SPAN> <BR> <SPAN class="keyword">end</SPAN>)<BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">tkClose</SPAN> <BR> {<SPAN class="keyword">self.</SPAN>entry tkClose}<BR> Tk<SPAN class="keyword">.</SPAN>toplevel<SPAN class="keyword">,</SPAN> tkClose<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">local</SPAN> <BR> <SPAN class="keyword">proc</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">DefAction</SPAN> _}<BR> <SPAN class="keyword">skip</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> TextHeight = 6<BR> BigTextWidth = 17<BR> <SPAN class="keyword">in</SPAN> <BR> <SPAN class="keyword">class</SPAN> <SPAN class="type">EntryChooser</SPAN> <BR> <SPAN class="keyword">from</SPAN><SPAN class="type"> Tk.frame</SPAN> <BR> <SPAN class="keyword">feat</SPAN> entry button toplevel action<BR> <SPAN class="keyword">attr</SPAN> entries<BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">tkInit</SPAN>(parent:P toplevel:T entries:Es action:A<SPAN class="keyword"><=</SPAN>DefAction)<BR> Tk<SPAN class="keyword">.</SPAN>frame<SPAN class="keyword">,</SPAN> tkInit(parent:P highlightthickness:2)<BR> Entry = {New Tk<SPAN class="keyword">.</SPAN>entry tkInit(parent: <SPAN class="keyword">self</SPAN> <BR> width: BigTextWidth<BR> bg: Colors<SPAN class="keyword">.</SPAN>textBg<BR> font: Fonts<SPAN class="keyword">.</SPAN>text<BR> highlightthickness: 0)}<BR> Button = {New Tk<SPAN class="keyword">.</SPAN>button tkInit(parent: <SPAN class="keyword">self</SPAN> <BR> image: Images<SPAN class="keyword">.</SPAN>down<BR> highlightthickness:0<BR> state: <SPAN class="keyword">if</SPAN> Es<SPAN class="keyword">==</SPAN>nil <SPAN class="keyword">then</SPAN> disabled<BR> <SPAN class="keyword">else</SPAN> normal<BR> <SPAN class="keyword">end</SPAN> <BR> action: <SPAN class="keyword">self</SPAN> <SPAN class="keyword">#</SPAN> OpenChooser)}<BR> <SPAN class="keyword">in</SPAN> <BR> <SPAN class="keyword">self.</SPAN>entry = Entry<BR> <SPAN class="keyword">self.</SPAN>button = Button<BR> <SPAN class="keyword">self.</SPAN>toplevel = T<BR> <SPAN class="keyword">self.</SPAN>action = A<BR> EntryChooser<SPAN class="keyword">,</SPAN>entries(Es)<BR> {Tk<SPAN class="keyword">.</SPAN>send pack(<SPAN class="keyword">self.</SPAN>entry <SPAN class="keyword">self.</SPAN>button side:left fill:y)}<BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">entries</SPAN>(Es)<BR> entries <SPAN class="keyword"><-</SPAN> Es<BR> <SPAN class="keyword">if</SPAN> Es<SPAN class="keyword">\=</SPAN>nil <SPAN class="keyword">then</SPAN> <BR> {<SPAN class="keyword">self.</SPAN>entry tk(delete 0 <SPAN class="string">'end'</SPAN>)}<BR> {<SPAN class="keyword">self.</SPAN>entry tk(insert 0 Es<SPAN class="keyword">.</SPAN>1)}<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">OpenChooser</SPAN> <BR> [X Y H] = {Map [rootx rooty height]<BR> <SPAN class="keyword">fun</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">$</SPAN> WI} {Tk<SPAN class="keyword">.</SPAN>returnInt winfo(WI <SPAN class="keyword">self</SPAN>)} <SPAN class="keyword">end</SPAN>}<BR> T = {New Tk<SPAN class="keyword">.</SPAN>toplevel tkInit(withdraw: <SPAN class="keyword">true</SPAN> <BR> parent: <SPAN class="keyword">self</SPAN> <BR> cursor: top_left_arrow)}<BR> F = {New Tk<SPAN class="keyword">.</SPAN>frame tkInit(parent:T bg:black bd:2)}<BR> L = {New Tk<SPAN class="keyword">.</SPAN>listbox tkInit(parent:F height:TextHeight<BR> width:BigTextWidth<BR> bg:white<BR> exportselection:<SPAN class="keyword">false</SPAN>)}<BR> S = {New Tk<SPAN class="keyword">.</SPAN>scrollbar tkInit(parent:F width:10)}<BR> <SPAN class="keyword">in</SPAN> <BR> {L tk(insert 0 b(<SPAN class="keyword">@</SPAN>entries))}<BR> {Tk<SPAN class="keyword">.</SPAN>addYScrollbar L S}<BR> {<SPAN class="keyword">self.</SPAN>toplevel tkBind(event:<SPAN class="string">'<1>'</SPAN> action:T<SPAN class="keyword">#</SPAN>tkClose)}<BR> {L tkBind(event:<SPAN class="string">'<1>'</SPAN> <BR> action: <SPAN class="keyword">proc</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">$</SPAN>}<BR> A={L tkReturnAtom(get<BR> l(L curselection) $)}<BR> <SPAN class="keyword">in</SPAN> <BR> {<SPAN class="keyword">self.</SPAN>entry tk(delete 0 <SPAN class="string">'end'</SPAN>)}<BR> {<SPAN class="keyword">self.</SPAN>entry tk(insert 0 A)}<BR> {<SPAN class="keyword">self.</SPAN>action A}<BR> {T tkClose}<BR> <SPAN class="keyword">end</SPAN>)}<BR> {L tkBind(event:<SPAN class="string">'<2>'</SPAN> <BR> action: T <SPAN class="keyword">#</SPAN> tkClose)}<BR> {Tk<SPAN class="keyword">.</SPAN>batch [wm(overrideredirect T <SPAN class="keyword">true</SPAN>)<BR> wm(geometry T <SPAN class="string">'+'</SPAN><SPAN class="keyword">#</SPAN>X<SPAN class="keyword">#</SPAN><SPAN class="string">'+'</SPAN><SPAN class="keyword">#</SPAN>Y<SPAN class="keyword">+</SPAN>H)<BR> pack(L S side:left fill:both)<BR> pack(F)<BR> wm(deiconify T)]}<BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">local</SPAN> <BR> LoadLeftX = <SPAN class="keyword">~</SPAN>3<SPAN class="keyword">.</SPAN>0<BR> LoadRightX = <SPAN class="keyword">~</SPAN>24<SPAN class="keyword">.</SPAN>0<BR> LoadY = <SPAN class="keyword">~</SPAN>8<SPAN class="keyword">.</SPAN>0<BR> LoadHeight = 6<SPAN class="keyword">.</SPAN>0<BR> LoadWidth = 27<SPAN class="keyword">.</SPAN>0<BR> <BR> ColMan = {New <SPAN class="keyword">class</SPAN> <SPAN class="type">$</SPAN> <SPAN class="keyword">from</SPAN><SPAN class="type"> BaseObject</SPAN> <BR> <SPAN class="keyword">prop</SPAN> final<BR> <SPAN class="keyword">attr</SPAN> ColS: <SPAN class="keyword">local</SPAN> Cs <SPAN class="keyword">in</SPAN> <BR> Cs={Append Colors<SPAN class="keyword">.</SPAN>truck Cs} Cs<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">get</SPAN>(?Col) ColR <SPAN class="keyword">in</SPAN> Col<SPAN class="keyword">|</SPAN>ColR=(ColS<SPAN class="keyword"><-</SPAN>ColR) <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> noop}<BR> <SPAN class="keyword">in</SPAN> <BR> <SPAN class="keyword">class</SPAN> <SPAN class="type">Truck</SPAN> <BR> <SPAN class="keyword">from</SPAN><SPAN class="type"> Tk.canvasTag</SPAN> <BR> <SPAN class="keyword">prop</SPAN> final<BR> <SPAN class="keyword">feat</SPAN> <BR> parent load fill driver<BR> <SPAN class="keyword">attr</SPAN> <BR> city: <SPAN class="keyword">unit</SPAN> <BR> turn: left<BR> load: 0<BR> x: 0<SPAN class="keyword">.</SPAN>0<BR> y: 0<SPAN class="keyword">.</SPAN>0<BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">init</SPAN>(parent:P city:C driver:D)<BR> X Y<BR> <SPAN class="keyword">in</SPAN> <BR> {Country<SPAN class="keyword">.</SPAN>getCoord C ?X ?Y}<BR> city <SPAN class="keyword"><-</SPAN> C<BR> Truck<SPAN class="keyword">,</SPAN> tkInit(parent:P)<BR> x <SPAN class="keyword"><-</SPAN> {IntToFloat X}<BR> y <SPAN class="keyword"><-</SPAN> {IntToFloat Y}<BR> <SPAN class="keyword">self.</SPAN>parent = P<BR> <SPAN class="keyword">self.</SPAN>load = {New Tk<SPAN class="keyword">.</SPAN>canvasTag tkInit(parent:P)}<BR> <SPAN class="keyword">self.</SPAN>fill = {ColMan get($)}<BR> <SPAN class="keyword">self.</SPAN>driver = D<BR> Truck<SPAN class="keyword">,</SPAN> draw<BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">draw</SPAN> <BR> P = <SPAN class="keyword">self.</SPAN>parent<BR> D = <SPAN class="keyword">@</SPAN>turn<BR> X = <SPAN class="keyword">@</SPAN>x<BR> Y = <SPAN class="keyword">@</SPAN>y<BR> <SPAN class="keyword">in</SPAN> <BR> Truck<SPAN class="keyword">,</SPAN> tk(delete)<BR> <SPAN class="keyword">if</SPAN> Tk<SPAN class="keyword">.</SPAN>isColor <SPAN class="keyword">then</SPAN> <BR> %% <SPAN class="comment">Create the truck's window<BR></SPAN> {P tk(create image X Y <BR> image: Images<SPAN class="keyword">.</SPAN>truck<SPAN class="keyword">.</SPAN>win<SPAN class="keyword">.</SPAN>D<BR> tags: <SPAN class="keyword">self</SPAN>)}<BR> {P tk(create image X Y<BR> image: Images<SPAN class="keyword">.</SPAN>truck<SPAN class="keyword">.</SPAN>fill<SPAN class="keyword">.</SPAN>(<SPAN class="keyword">self.</SPAN>fill)<SPAN class="keyword">.</SPAN>D<BR> tags: <SPAN class="keyword">self</SPAN>)}<BR> <SPAN class="keyword">end</SPAN> <BR> %% <SPAN class="comment">Create the frame for truck (better visibility) <BR></SPAN> {P tk(create image X Y <BR> image: Images<SPAN class="keyword">.</SPAN>truck<SPAN class="keyword">.</SPAN>frame<SPAN class="keyword">.</SPAN>D<BR> tags: <SPAN class="keyword">self</SPAN>)}<BR> {P tk(crea rectangle 0 0 0 0<BR> fill: Colors<SPAN class="keyword">.</SPAN>good<BR> outline: <SPAN class="string">''</SPAN> <BR> tags: q(<SPAN class="keyword">self</SPAN> <SPAN class="keyword">self.</SPAN>load))}<BR> Truck<SPAN class="keyword">,</SPAN> load(<SPAN class="keyword">@</SPAN>load)<BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">load</SPAN>(L)<BR> W = {IntToFloat L} <SPAN class="keyword">/</SPAN> {IntToFloat Capacity} <SPAN class="keyword">*</SPAN> LoadWidth<BR> X0 = <SPAN class="keyword">@</SPAN>x <SPAN class="keyword">+</SPAN> <SPAN class="keyword">case</SPAN> <SPAN class="keyword">@</SPAN>turn<BR> <SPAN class="keyword">of</SPAN> left <SPAN class="keyword">then</SPAN> LoadLeftX<BR> <SPAN class="keyword">[]</SPAN> right <SPAN class="keyword">then</SPAN> LoadRightX <SPAN class="keyword">+</SPAN> LoadWidth <SPAN class="keyword">-</SPAN> W<BR> <SPAN class="keyword">end</SPAN> <BR> X1 = X0 <SPAN class="keyword">+</SPAN> W<BR> Y0 = <SPAN class="keyword">@</SPAN>y <SPAN class="keyword">+</SPAN> LoadY<BR> Y1 = Y0 <SPAN class="keyword">+</SPAN> LoadHeight<BR> <SPAN class="keyword">in</SPAN> <BR> load <SPAN class="keyword"><-</SPAN> L<BR> {<SPAN class="keyword">self.</SPAN>load tk(coords X0 Y0 X1 Y1)}<BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">turn</SPAN>(X0 X1)<BR> NewTurn = <SPAN class="keyword">if</SPAN> X0<SPAN class="keyword"><</SPAN>X1 <SPAN class="keyword">then</SPAN> right <SPAN class="keyword">else</SPAN> left <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">in</SPAN> <BR> <SPAN class="keyword">if</SPAN> <SPAN class="keyword">@</SPAN>turn<SPAN class="keyword">\=</SPAN>NewTurn <SPAN class="keyword">then</SPAN> <BR> turn <SPAN class="keyword"><-</SPAN> NewTurn Truck<SPAN class="keyword">,</SPAN> draw<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">drive</SPAN>(Dst Load NextLoad)<BR> X Y<BR> <SPAN class="keyword">in</SPAN> <BR> {Country<SPAN class="keyword">.</SPAN>getCoord <SPAN class="keyword">@</SPAN>city ?X ?Y}<BR> Truck<SPAN class="keyword">,</SPAN>load(Load)<BR> Truck<SPAN class="keyword">,</SPAN>Route({Country<SPAN class="keyword">.</SPAN>getRoute <SPAN class="keyword">@</SPAN>city Dst}<BR> {IntToFloat X} {IntToFloat Y})<BR> Truck<SPAN class="keyword">,</SPAN>load(NextLoad)<BR> Truck<SPAN class="keyword">,</SPAN>{<SPAN class="keyword">self.</SPAN>driver getMessage($)}<BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">Move</SPAN>(N XS YS)<BR> <SPAN class="keyword">if</SPAN> N<SPAN class="keyword">\=</SPAN>0 <SPAN class="keyword">then</SPAN> <BR> Truck<SPAN class="keyword">,</SPAN>tk(move XS YS)<BR> x <SPAN class="keyword"><-</SPAN> <SPAN class="keyword">@</SPAN>x <SPAN class="keyword">+</SPAN> XS y <SPAN class="keyword"><-</SPAN> <SPAN class="keyword">@</SPAN>y <SPAN class="keyword">+</SPAN> YS<BR> {Delay DelayMove}<BR> Truck<SPAN class="keyword">,</SPAN>Move(N<SPAN class="keyword">-</SPAN>1 XS YS)<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">Route</SPAN>(Rs SrcX SrcY)<BR> %% <SPAN class="comment">Moves the truck according to the route "Rs"<BR></SPAN> Src<SPAN class="keyword">#</SPAN>Dist<SPAN class="keyword">|</SPAN>Rr = Rs<BR> <SPAN class="keyword">in</SPAN> <BR> <SPAN class="keyword">case</SPAN> Rr <SPAN class="keyword">of</SPAN> Dst<SPAN class="keyword">#</SPAN>_<SPAN class="keyword">|</SPAN>_ <SPAN class="keyword">then</SPAN> <BR> Steps = Dist <SPAN class="keyword">div</SPAN> Delta<BR> Ratio = {IntToFloat Steps}<BR> DX DY<BR> {Country<SPAN class="keyword">.</SPAN>getCoord Dst ?DX ?DY}<BR> DstX = {IntToFloat DX}<BR> DstY = {IntToFloat DY}<BR> <SPAN class="keyword">in</SPAN> <BR> %% <SPAN class="comment">Turn the truck<BR></SPAN> Truck<SPAN class="keyword">,</SPAN>turn(SrcX DstX)<BR> Truck<SPAN class="keyword">,</SPAN>Move(Steps (DstX <SPAN class="keyword">-</SPAN> SrcX) <SPAN class="keyword">/</SPAN> Ratio (DstY <SPAN class="keyword">-</SPAN> SrcY) <SPAN class="keyword">/</SPAN> Ratio)<BR> %% <SPAN class="comment">correct<BR></SPAN> Truck<SPAN class="keyword">,</SPAN>tk(move DstX <SPAN class="keyword">-</SPAN> <SPAN class="keyword">@</SPAN>x DstY <SPAN class="keyword">-</SPAN> <SPAN class="keyword">@</SPAN>y)<BR> x <SPAN class="keyword"><-</SPAN> DstX<BR> y <SPAN class="keyword"><-</SPAN> DstY<BR> Truck<SPAN class="keyword">,</SPAN>Route(Rr DstX DstY)<BR> <SPAN class="keyword">[]</SPAN> nil <SPAN class="keyword">then</SPAN> <BR> city <SPAN class="keyword"><-</SPAN> Src<BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">close</SPAN> <BR> Truck<SPAN class="keyword">,</SPAN> tkClose<BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">end</SPAN> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">local</SPAN> <BR> TownSize = 3<BR> TextOffset = 11<BR> <SPAN class="keyword">in</SPAN> <BR> <BR> <SPAN class="keyword">class</SPAN> <SPAN class="type">CountryMap</SPAN> <BR> <SPAN class="keyword">from</SPAN><SPAN class="type"> Tk.canvas</SPAN> <BR> <BR> <SPAN class="keyword">meth</SPAN> <SPAN class="functionname">init</SPAN>(parent:P)<BR> Tk<SPAN class="keyword">.</SPAN>canvas<SPAN class="keyword">,</SPAN>tkInit(parent: P<SPAN class="keyword">.</SPAN>toplevel<BR> relief: sunken<BR> bd: 3<BR> width: Country<SPAN class="keyword">.</SPAN>width<BR> height: Country<SPAN class="keyword">.</SPAN>height<BR> bg: Colors<SPAN class="keyword">.</SPAN>back)<BR> {ForAll {Country<SPAN class="keyword">.</SPAN>getGraph}<BR> <SPAN class="keyword">proc</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">$</SPAN> SPDs}<BR> Src<SPAN class="keyword">#</SPAN>(SrcX<SPAN class="keyword">#</SPAN>SrcY)<SPAN class="keyword">#</SPAN>Dsts = SPDs<BR> Tag = {New Tk<SPAN class="keyword">.</SPAN>canvasTag tkInit(parent:<SPAN class="keyword">self</SPAN>)}<BR> <SPAN class="keyword">in</SPAN> <BR> {Tag tkBind(event:<SPAN class="string">'<1>'</SPAN> action:P <SPAN class="keyword">#</SPAN> putSrc(Src))}<BR> {Tag tkBind(event:<SPAN class="string">'<2>'</SPAN> action:P <SPAN class="keyword">#</SPAN> putDst(Src))}<BR> {ForAll Dsts<BR> <SPAN class="keyword">proc</SPAN><SPAN class="variablename"> </SPAN>{<SPAN class="functionname">$</SPAN> DstX<SPAN class="keyword">#</SPAN>DstY}<BR> {<SPAN class="keyword">self</SPAN> tk(create line SrcX SrcY DstX DstY<BR> fill: Colors<SPAN class="keyword">.</SPAN>street)}<BR> <SPAN class="keyword">end</SPAN>}<BR> {<SPAN class="keyword">self</SPAN> tk(create rectangle<BR> SrcX<SPAN class="keyword">-</SPAN>TownSize SrcY<SPAN class="keyword">-</SPAN>TownSize<BR> SrcX<SPAN class="keyword">+</SPAN>TownSize SrcY<SPAN class="keyword">+</SPAN>TownSize<BR> fill: Colors<SPAN class="keyword">.</SPAN>city<BR> tags: Tag)}<BR> {<SPAN class="keyword">self</SPAN> tk(create text SrcX SrcY<SPAN class="keyword">+</SPAN>TextOffset<BR> text: Src<BR> font: Fonts<SPAN class="keyword">.</SPAN>text<BR> tags: Tag)}<BR> <SPAN class="keyword">end</SPAN>}<BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <SPAN class="keyword">end</SPAN> <BR> <BR> <BR><SPAN class="keyword">end</SPAN> <BR> <BR></PRE></BLOCKQUOTE><P></P></DIV><TABLE align="center" border="0" cellpadding="6" cellspacing="6" class="nav"><TR bgcolor="#DDDDDD"><TD><A href="node34.html#code.transportation.randomizer"><< Prev</A></TD><TD><A href="transportation.html">- Up -</A></TD></TR></TABLE><HR><ADDRESS><SPAN class="version">Version 1.4.0 (20110908185330)</SPAN></ADDRESS></BODY></HTML>
|