#### ## this is your code ported to a Nasal submodule ## to be saved in $FG_ROOT/Nasal/fgplot2/fgplot2.nas ## # below is a piece of test code. var menubar = {}; var sidebar = {}; var plot = {}; var Button = { B1: 0, new: func { var m = { parents: [Button] }; return m; }, create: func (bar,x,y,w,h) { me.B1 = bar.createChild("path") .moveTo(x, y) .vertTo(y + h) .horizTo(x + w) .vertTo(y) .horizTo(x) .close() .setColor(0,0,0) .setColorFill(0.8,0.8,0.8) .setStrokeLineWidth(1); print("Button created."); return me; }, color: func (cl) { me.B1.setColorFill(cl); print("ButtonColor set"); return me; }, addhandler: func (Ev,Act) { me.B1.addEventListener(Ev, Act ); return me; }, }; var Box = { trp: 0, B1: 0, T1: 0, W: 0, H: 0, new: func { var m = { parents: [Box] }; return m; }, create: func(root,bar,x,y,w,h) { me.H = h; me.W = w; me.B1 = bar.createChild("path") .moveTo(x, y) .vertTo(y + h) .horizTo(x + w) .vertTo(y) .horizTo(x) .close() .setColorFill(0.5,0.5,0.5,1) .setStrokeLineWidth(1); # This is going to be the resizer. # Maby much more code is needed. # Resizing the graph area , but not thicken the menubars. me.B1.addEventListener("drag", func(e) { print("B1 event listener running!"); bar.set("size[0]",me.W+=e.deltaX); # size[] x, y , w , h ? bar.set("size[1]",me.H+=e.deltaX); }); print("Box created."); return me; }, color: func (t) { me.B1.setColorFill(t); print("SetColor done."); return me; }, settitle: func (bar,t) { me.T1 = bar.createChild("text", "box-caption") .setText( t ) .setTranslation(4,24) .setAlignment("left-top") .setFontSize(14) .setFont("LiberationFonts/LiberationSans-Bold.ttf") .setColor(0,1,0); print("Settitle done."); return me; }, settext: func (t) { me.T1.setText(t); print("Settext done."); return me; }, transparency: func () { if(me.trp) { me.B1.setColorFill(0.5,0.5,0.5,1); me.trp = 0; }else{ me.B1.setColorFill(0.5,0.5,0.5,0.5); me.trp = 1; } print("Transparency done."); return me; }, addhandler: func (Ev,Act) { me.B1.addEventListener(Ev, Act ); return me; }, }; var Menubar = { B: 0, T: 0, new: func { var m = { parents: [Menubar] }; return m; }, create: func(root,bar,x,y,w,h) { var rx = 8; var ry = 8; me.B = bar.createChild("path") .moveTo(x + w - rx, y) .arcSmallCWTo(rx, ry, 0, x + w, y + ry) .vertTo(y + h) .horizTo(x) .vertTo(y + ry) .arcSmallCWTo(rx, ry, 0, x + rx, y) .close() .setColorFill(0.8,0.8,0.8) .setStrokeLineWidth(1); me.B.addEventListener("drag", func(e) { root.move(e.deltaX, e.deltaY); }); print("Menubar created."); return me; }, createtitle: func (bar,t) { me.T = bar.createChild("text", "dialog-caption") .setText(t) .setTranslation(4,4) .setAlignment("left-top") .setFontSize(14) .setFont("LiberationFonts/LiberationSans-Bold.ttf") .setColor(0,0,0); print("Createtitle done."); return me; }, settitle: func (t) { me.T.setText(t); print("Settitle done."); return me; }, addbutton: func (bar,graph,x,y,w,h) { var Child = Button.new(); Child.create(bar,graph,x,y,w,h); print("AddButton done."); return Child; }, }; var Xline = { new: func () { var m = { parents: [Xline] }; return m; }, start: func (bar,x,w,h,Th) { bar.createChild("path") .moveTo(0,0) .lineTo(w,0) .setColor(0,0,0) .setTranslation(x,Th-h/2); return me; }, }; var _plot = { lines: 0, running: 0, new: func () { var m = { parents: [_plot] }; return m; }, do_plot: func () { return me; }, add: func () { print("adding property to plot."); return me; }, run: func () { me.do_Plot(); return me; }, start: func () { me.running=1; print("graph running."); return me; }, stop: func () { me.running=0; print("graph paused."); return me; }, }; var _App = { x: 200, y: 200, width:400, height:300, mbwidth:400, mbheight: 20, sbwidth: 20, sbheight:280, pwidth: 380, pheight: 280, bg: '#00000000', hello: func {print("Hello world"); }, info: func { print("x:",me.x, " y:", me.y, " width:", me.width, " height:", me.height); }, create: func { var x = me.x; var y = me.y; var dlg = canvas.Window.new([me.width, me.height+me.mbheight]); var cnv = dlg.createCanvas() .setColorBackground(me.bg); cnv.addEventListener('wheel', func () { dlg.del();} ); var root = cnv.createGroup(); var mbr = root.createChild("group"); # All about menubar var grphB = root.createChild("group"); # The background of All,maby unneeded. var grph = root.createChild("group"); # All about plot plot["canvas"] = Box.new(); plot["canvas"].create(dlg,grphB, me.sbwidth,me.mbheight,me.pwidth,me.pheight); plot["xline"] = Xline.new(); plot["xline"].start(grph,me.sbwidth,me.pwidth,me.pheight,me.height); plot["line"] = _plot.new(); print ( "type plot[0] : "~typeof(plot[0])); sidebar["side"] = Menubar.new(); sidebar["side"].create(dlg,mbr,0,me.mbheight,me.sbwidth,me.sbheight); sidebar["start"] = Button.new(); sidebar["start"].create(mbr,0,20,20,25); sidebar["start"].color("#0000FF"); sidebar["start"].addhandler('click', func plot["line"].start()); sidebar["stop"] = Button.new(); sidebar["stop"].create(mbr,0,45,20,25); sidebar["stop"].color("#00FFFF"); sidebar["stop"].addhandler('click', func plot["line"].stop()); menubar["bar"] = Menubar.new(); menubar["bar"].create(dlg,mbr,0,0,me.mbwidth,me.mbheight); menubar["title"] = menubar["bar"].createtitle(mbr,"Dyn.FgPlot"); menubar["title"].settitle("My.FgPlot"); menubar["chgtxt"] = Button.new(); menubar["chgtxt"].create(mbr,80,0,25,me.mbheight); menubar["chgtxt"].addhandler('click', func menubar["title"].settitle("My.Oh.My")); menubar["chgtxt"].color('#00FF00'); menubar["trnsp"] = Button.new(); menubar["trnsp"].create(mbr,105,0,25,me.mbheight); print("after create : "~typeof(menubar["trnsp"])); menubar["trnsp"].addhandler('click', func plot["canvas"].transparency()); menubar["trnsp"].color('#0000FF'); menubar["addline"] = Button.new(); menubar["addline"].create(mbr,130,0,25,me.mbheight); print("after create : "~typeof(menubar["addline"])); menubar["addline"].addhandler('click', func plot["line"].add()); menubar["addline"].color('#880088'); menubar["quit"] = Button.new(); menubar["quit"].create(mbr,155,0,25,me.mbheight); print("after create : "~typeof(menubar["quit"])); menubar["quit"].addhandler('click', func dlg.del()); menubar["quit"].color('#880000'); print(typeof(menubar["quit"])); }, chgbg: func (e) { me.bg = e ; cnv.setColorBackground(me.bg); }, delete: func () { MyApp.del(); }, }; var initialize = func { var MyApp = { parents:[_App] }; MyApp.hello(); MyApp.info(); MyApp.create(); #var listener_id = _setlistener("/sim/test/start", MyApp.hello(); ); } _setlistener("/nasal/fgplot2/loaded", initialize);