using Gtk; using System; public class Interpolation:TerrPlugin{ mutable host:TerrHost; public Host:TerrHost { set { host=value; } } mutable nr:int; //settings mutable sFactor=0.5; mutable sIter=2; mutable sMethod=0; //-------------------------------------------------------------------------------------------------------------- public Register(n:int):void{ nr=n; def mItem=MenuItem("interpolation"); host.MFilter.Append(mItem); mItem.Activated+=EventHandler(optionsWin); } //-------------------------------------------------------------------------------------------------------------- public Run():void{ host.Start(nr); def progStep=100/(sIter*100):>double; def map=host.HMap; def sizeX=map.SizeX; def sizeY=map.SizeY; def linear(x:int,y:int){ def hor=map[x-1,y]*(1-sFactor)+map[x+1,y]*sFactor; def ver=map[x,y-1]*(1-sFactor)+map[x,y+1]*sFactor; def nwse=map[x-1,y-1]*(1-sFactor)+map[x+1,y+1]*sFactor; def nesw=map[x+1,y-1]*(1-sFactor)+map[x-1,y+1]*sFactor; (hor+ver+nwse+nesw)/4.0; } when (sMethod==1){ def ft=sFactor*Math.PI; def f=(1-Math.Cos(ft))*0.5; sFactor=f; } def cosine(x:int,y:int) { linear(x,y); } repeat(sIter){ for (mutable x=0; x map[x,y]=linear(x,y); | 1 => map[x,y]=cosine(x,y); | _ => Console.WriteLine("hmm, a weird error seems to have occurred..."); } host.ProgBar.FractionAddResp(progStep); } host.Update(); } //-------------------------------------------------------------------------------------------------------------- private optionsWin(_o:object,_e:EventArgs):void{ def win=Window("interpolation"); win.BorderWidth=5; def tips=Tooltips(); def whole=VBox(false,10); win.Add(whole); def sett=VBox(false,10); whole.PackStart(sett); def methods=array["linear","cosine"]; def methodHBox=HBox(false,10); sett.PackStart(methodHBox); def methodLab=Label("method:"); methodHBox.PackStart(methodLab); def methodBox=ComboBox.NewText(); methodHBox.PackStart(methodBox); foreach (i in methods) methodBox.AppendText(i); methodBox.Active=sMethod; methodBox.Changed+=fun(_) { sMethod=methodBox.Active; } def factorHBox=HBox(false,10); sett.PackStart(factorHBox); def factorLab=Label("factor:"); factorHBox.PackStart(factorLab); def factorSpin=SpinButton(0.0,1.0,0.01); factorHBox.PackStart(factorSpin); tips.SetTip(factorSpin,"the change factor",""); factorSpin.Value=sFactor; factorSpin.ValueChanged+=fun(_) { sFactor=factorSpin.ValueAsInt; } def iterHBox=HBox(false,10); sett.PackStart(iterHBox); def iterLab=Label("iterations:"); iterHBox.PackStart(iterLab); def iterSpin=SpinButton(0.0,500.0,1.0); iterHBox.PackStart(iterSpin); tips.SetTip(iterSpin,"nr of iterations",""); iterSpin.Value=sIter; iterSpin.ValueChanged+=fun(_) { sIter=iterSpin.ValueAsInt; } def buttBox=HBox(false,10); whole.PackStart(buttBox); def aboutButt=Button("about"); buttBox.PackStart(aboutButt); aboutButt.Clicked+=EventHandler(aboutButtHandler); def cancelButt=Button("cancel"); buttBox.PackStart(cancelButt); cancelButt.Clicked+=fun(_) { win.Destroy(); } def okButt=Button("ok"); buttBox.PackStart(okButt); okButt.Clicked+=fun(_) { Run(); win.Destroy(); } win.ShowAll(); } //-------------------------------------------------------------------------------------------------------------- private aboutButtHandler(_o:object,_e:EventArgs):void{ def dial=MessageDialog(null,DialogFlags.Modal,MessageType.Info,ButtonsType.Ok,"interpolation plugin 0.2:0.3 by caminoix, 03.09.2006\n\nfor more information on the algorithm please see\nhttp://terraineer.sourceforge.net/plugins/interpolation.php"); _=dial.Run(); dial.Destroy(); } }