Exemple #1
0
        public MainForm()
        {
            // The InitializeComponent() call is required for Windows Forms designer support.
            InitializeComponent();

            Log = x => Console.WriteLine(x);

            //register a url and receive a unique websocketport for it
            var url  = WebServer.AddURL("poshdemo");
            var port = WebServer.URLPort[url];

            //create a wampserver/websocket on the given port
            FPoshServer                   = new PoshServer(port);
            FPoshServer.OnDump           += PoshGraphDump;
            FPoshServer.OnSessionCreated += PoshSessionCreated;
            FPoshServer.OnSessionClosed  += PoshSessionClosed;

            //setup keyboard handlers
//			FWAMPServer.OnKeyDown += KeyDownHandler;
//			FWAMPServer.OnKeyUp += KeyUpHandler;
//			FWAMPServer.OnKeyPress += KeyPressHandler;

            //create an svg document
            ViewRoot = new SvgDocument();

            //hand the svg document a custom idmanager that talks to the WampServer
            var manager = new SvgIdManager(ViewRoot, FPoshServer.SvgEventCaller, FPoshServer.RemoteContext);

            ViewRoot.OverwriteIdManager(manager);

            //fill the svg document
            SetupInitialView();

            //open the canvas: the window showing the view is a webbrowser navigating to the given url on localhost
            webBrowser1.Navigate("about:blank");
            webBrowser1.Navigate(new Uri("http://localhost:4444/" + url));

            //dispose web- and wampserver
            this.Disposed += (s, e) =>
            {
                WebServer.Stop();
                FPoshServer.Dispose();
            };
        }
        public TimelineView(TLDocument tl, ICommandHistory history, Timer timer)
        {
            History = history;
            History.CommandInserted += History_Changed;
            History.Undone          += History_Changed;
            History.Redone          += History_Changed;

            Document = tl;
            Timer    = timer;

            //replace id manager before any svg element was added
            var caller  = Document.Mapper.Map <ISvgEventCaller>();
            var manager = new SvgIdManager(SvgRoot, caller, Document.Mapper.Map <RemoteContext>());

            SvgRoot.ID = "svg";
            SvgRoot.OverwriteIdManager(manager);

            Background.Width   = new SvgUnit(SvgUnitType.Percentage, 100);
            Background.Height  = 500;
            Background.ID      = Document.GetID() + "_Background";
            Background.Opacity = 0;

            Background.MouseDown += Default_MouseDown;
            Background.MouseMove += Default_MouseMove;
            Background.MouseUp   += Default_MouseUp;

            Selection.ID = "Selection";
            Selection.CustomAttributes["pointer-events"] = "none";
            Selection.CustomAttributes["class"]          = "selection";

            Ruler = new RulerView(Document.Ruler, this);

            MouseTimeLine.ID     = "MouseTime";
            MouseTimeLine.StartX = 0;
            MouseTimeLine.StartY = 0;
            MouseTimeLine.EndX   = 0;

            TimeBar.ID         = "Timebar";
            TimeBar.Y          = -Ruler.Height;
            TimeBar.X          = -1;
            TimeBar.Width      = 2;
            TimeBar.MouseDown += Default_MouseDown;
            TimeBar.MouseMove += Default_MouseMove;
            TimeBar.MouseUp   += Default_MouseUp;

            MainMenu    = new SvgMenuWidget(120);
            MainMenu.ID = "MainMenu";

            var addValueTrack = new SvgButtonWidget(0, 20, "Add Value Track");

            addValueTrack.ValueChanged += AddValueTrack;

            var addStringTrack = new SvgButtonWidget(0, 20, "Add String Track");

            addStringTrack.ValueChanged += AddStringTrack;

            MainMenu.AddItem(addValueTrack, 0);
            MainMenu.AddItem(addStringTrack, 1);

            FRulerGroup.ID = "Ruler";
            FRulerGroup.CustomAttributes["class"] = "fixed";
            FRulerGroup.Transforms = new SvgTransformCollection();
            FRulerGroup.Transforms.Add(new SvgTranslate(0, 0));

            FTrackGroup.ID            = "Tracks";
            FTrackGroup.Transforms    = new SvgTransformCollection();
            FOverlaysGroup.ID         = "Overlays";
            FOverlaysGroup.Transforms = new SvgTransformCollection();

            //initialize svg tree
            BuildSVGRoot();

            Syncer = Tracks.SyncWith(Document.Tracks,
                                     tm =>
            {
                TrackView tv;
                if (tm is TLValueTrack)
                {
                    tv = new ValueTrackView(tm as TLValueTrack, this, Ruler);
                }
                else if (tm is TLStringTrack)
                {
                    tv = new StringTrackView(tm as TLStringTrack, this, Ruler);
                }
                else
                {
                    tv = new AudioTrackView(tm as TLAudioTrack, this, Ruler);
                }

                if (ActiveTrack == null)
                {
                    ActiveTrack = tv;
                }
                tv.AddToSceneGraphAt(FTrackGroup);

                //update Order on all tracks below the one added
                var order = tv.Model.Order.Value;
                foreach (var track in Tracks.Where(x => x.Model.Order.Value >= order))
                {
                    track.Model.Order.Value += 1;
                }

                return(tv);
            },
                                     tv =>
            {
                var order = tv.Model.Order.Value;
                tv.Dispose();

                //update Order on all tracks below the one removed
                foreach (var track in Tracks.Where(x => x.Model.Order.Value > order))
                {
                    track.Model.Order.Value -= 1;
                }
            });
        }