Exemplo n.º 1
0
 private void TranslateModeChecked(object sender, EventArgs e)
 {
     if (TranslateModeCheckbox.Checked && _selectedType != SelectionBoxDraggableState.TransformationMode.Resize)
     {
         Oy.Publish("SelectTool:TransformationModeChanged", "Resize");
     }
     else
     {
         SetCheckState();
     }
 }
Exemplo n.º 2
0
        /// <inheritdoc />
        public Task OnStartup()
        {
            Oy.Subscribe <IDocument>("Document:Activated", DocumentActivated);
            Oy.Subscribe <IDocument>("Document:Closed", DocumentClosed);
            Oy.Subscribe <Change>("MapDocument:Changed", DocumentChanged);

            _engine.Value.ViewportCreated   += ViewportCreated;
            _engine.Value.ViewportDestroyed += ViewportDestroyed;

            return(Task.FromResult(0));
        }
Exemplo n.º 3
0
        public async Task Invoke(IContext context, CommandParameters parameters)
        {
            var md = context.Get <MapDocument>("ActiveDocument");

            if (md == null)
            {
                return;
            }

            await Oy.Publish("Context:Add", new ContextInfo("BspEditor:TextureReplace"));
        }
Exemplo n.º 4
0
        protected override async Task Invoke(MapDocument document, CommandParameters parameters)
        {
            if (document.Selection.IsEmpty)
            {
                return;
            }

            var box = document.Selection.GetSelectionBoundingBox();

            await Oy.Publish("MapDocument:Viewport:Focus3D", box);
        }
Exemplo n.º 5
0
 private async Task PostLoad()
 {
     if (_openDocuments != null)
     {
         foreach (var dp in _openDocuments)
         {
             await _documentRegister.Value.OpenDocument(dp.ToPointer(), dp.Loader);
         }
     }
     await Oy.Publish("Shell:InstanceOpened", Environment.GetCommandLineArgs().ToList());
 }
Exemplo n.º 6
0
        public void TestExceptionHandling()
        {
            Exception ex = null;

            Oy.UnhandledException += (s, a) => { ex = a.Exception; };
            Oy.Subscribe("Nothing", () => throw new NotImplementedException());

            Oy.Publish("Nothing").Wait(100);

            Assert.IsType <NotImplementedException>(ex);
        }
Exemplo n.º 7
0
        public void TestEmpty()
        {
            int number = 0;

            Oy.Subscribe("Nothing", () =>
            {
                Interlocked.Add(ref number, 1);
            });
            Oy.Publish("Nothing").Wait(100);
            Assert.Equal(1, number);
        }
Exemplo n.º 8
0
        public void TestStruct()
        {
            int number = 0;

            Oy.Subscribe <decimal>("Test 1", d =>
            {
                Interlocked.Add(ref number, (int)d);
            });
            Oy.Publish("Test 1", 10m).Wait(100);
            Assert.Equal(10, number);
        }
Exemplo n.º 9
0
        protected BaseTool()
        {
            Active        = true;
            Viewport      = null;
            Usage         = ToolUsage.View2D;
            UseValidation = false;
            Children      = new List <BaseTool>();

            Oy.Subscribe <IDocument>("Document:Activated", id => SetDocument(id as MapDocument));
            Oy.Subscribe <IContext>("Context:Changed", c => ContextChanged(c));
        }
Exemplo n.º 10
0
        protected override IEnumerable <Subscription> Subscribe()
        {
            yield return(Oy.Subscribe <RightClickMenuBuilder>("MapViewport:RightClick", b =>
            {
                b.Intercepted = true;
            }));

            yield return(Oy.Subscribe <ClickAction>("BspEditor:TextureTool:SetLeftClickAction", a => _leftClickAction = a));

            yield return(Oy.Subscribe <ClickAction>("BspEditor:TextureTool:SetRightClickAction", a => _rightClickAction = a));
        }
        private async Task OpenMenu(ViewportEvent e)
        {
            var mb = new RightClickMenuBuilder(Viewport, e);
            await Oy.Publish("MapViewport:RightClick", mb);

            if (mb.Intercepted || mb.IsEmpty)
            {
                return;
            }
            mb.Populate(_contextMenu);
            _contextMenu.Show(Viewport.Control, e.X, e.Y);
        }
Exemplo n.º 12
0
        private void GoToSelectedEntity(object sender, EventArgs e)
        {
            var selected = GetSelected();

            if (selected == null)
            {
                return;
            }
            SelectEntity(selected);
            Oy.Publish("MapDocument:Viewport:Focus2D", selected.BoundingBox);
            Oy.Publish("MapDocument:Viewport:Focus3D", selected.BoundingBox);
        }
Exemplo n.º 13
0
        /// <inheritdoc />
        public Task OnStartup()
        {
            Oy.Subscribe <IDocument>("Document:Activated", DocumentActivated);
            Oy.Subscribe <IDocument>("Document:Closed", DocumentClosed);

            foreach (var or in _overlayRenderables.Union(_documentOverlayRenderables))
            {
                _engine.Value.Add(or);
            }

            return(Task.FromResult(0));
        }
Exemplo n.º 14
0
        private void BoxStateChanged(object sender, EventArgs e)
        {
            var box = State.Action == BoxAction.Idle || State.Start == null || State.End == null ? Box.Empty : new Box(State.Start, State.End);

            var label = "";

            if (box != null && !box.IsEmpty())
            {
                label = box.Width.ToString("0") + " x " + box.Length.ToString("0") + " x " + box.Height.ToString("0");
            }
            Oy.Publish("MapDocument:ToolStatus:UpdateText", label);
        }
Exemplo n.º 15
0
        public async Task OnStartup()
        {
            // Register the exported dialogs
            foreach (var export in _dialogs)
            {
                Log.Debug(nameof(DialogRegister), "Loaded: " + export.Value.GetType().FullName);
                _components.Add(export.Value);
            }

            // Subscribe to context changes
            Oy.Subscribe <IContext>("Context:Changed", ContextChanged);
        }
Exemplo n.º 16
0
        public VertexErrorsSidebarPanel(
            [ImportMany] IEnumerable <Lazy <IVertexErrorCheck> > errorChecks,
            [Import] Lazy <ITranslationStringProvider> translator
            )
        {
            _errorChecks = errorChecks;
            _translator  = translator;

            InitializeComponent();

            Oy.Subscribe <VertexSelection>("VertexTool:Updated", t => UpdateErrorList(t));
        }
Exemplo n.º 17
0
 private void Subscribe()
 {
     if (_subscriptions != null)
     {
         return;
     }
     _subscriptions = new List <Subscription>
     {
         Oy.Subscribe <MapDocument>("Document:Activated", DocumentActivated),
         Oy.Subscribe <MapDocument>("MapDocument:SelectionChanged", SelectionChanged)
     };
 }
Exemplo n.º 18
0
            public async Task Invoke(IContext context)
            {
                if (!File.Exists(_file.Location))
                {
                    return;
                }

                await Oy.Publish("Command:Run", new CommandMessage("Internal:OpenDocument", new
                {
                    Path = _file.Location
                }));
            }
Exemplo n.º 19
0
        public Task OnInitialise()
        {
            foreach (var si in _statusItems.OrderBy(x => OrderHintAttribute.GetOrderHint(x.Value.GetType())))
            {
                Add(si.Value);
            }

            // Subscribe to context changes
            Oy.Subscribe <IContext>("Context:Changed", ContextChanged);

            return(Task.FromResult(0));
        }
Exemplo n.º 20
0
        private void SetRightClickAction(object sender, ToolStripItemClickedEventArgs e)
        {
            if (!(e.ClickedItem.Tag is ClickAction))
            {
                return;
            }

            var action = (ClickAction)e.ClickedItem.Tag;

            RightClickActionButton.Text = $@"{RightClick}: {e.ClickedItem.Text}";
            Oy.Publish("BspEditor:TextureTool:SetRightClickAction", action);
        }
Exemplo n.º 21
0
        protected override IEnumerable <Subscription> Subscribe()
        {
            yield return(Oy.Subscribe <VertexTool>("Tool:Activated", t => CycleShowPoints()));

            yield return(Oy.Subscribe <string>("VertexPointTool:SetVisiblePoints", v => SetVisiblePoints(v)));

            yield return(Oy.Subscribe <object>("VertexPointTool:Split", _ => Split()));

            yield return(Oy.Subscribe <object>("VertexPointTool:Merge", _ => Merge()));

            yield return(Oy.Subscribe <object>("VertexTool:DeselectAll", _ => DeselectAll()));
        }
Exemplo n.º 22
0
        static void Main(string[] args)
        {
            Oy.Subscribe <Something>("Message", async(x, t) => Console.WriteLine(x.Number + " - " + x.Message));

            for (var i = 5; i >= 0; i--)
            {
                Oy.Publish("Message", new Something {
                    Number = i, Message = "Message #" + i
                });
                Oy.Publish("Message", "Nonsense");
            }
            System.Threading.Thread.Sleep(2000);
        }
Exemplo n.º 23
0
        public VertexSidebarPanel()
        {
            InitializeComponent();

            Oy.Subscribe <VertexTool>("Tool:Activated", t =>
            {
                SetSelectedTool(t.CurrentSubTool?.GetType());
            });
            Oy.Subscribe <Type>("VertexTool:SubToolChanged", t =>
            {
                SetSelectedTool(t);
            });
        }
Exemplo n.º 24
0
        public void TestThatItWorks()
        {
            var tcs = new TaskCompletionSource <string>();

            Oy.Subscribe <string>("Test it works", x => {
                tcs.SetResult(x);
            });

            Oy.Publish("Test it works", "Value");

            tcs.Task.Wait(100);
            Assert.Equal("Value", tcs.Task.Result);
        }
Exemplo n.º 25
0
        public void TestDownCasting()
        {
            int hitCount = 0;
            var tcs      = new TaskCompletionSource <object>();

            Oy.Subscribe <object>("Test Downcasting", x => { Interlocked.Add(ref hitCount, 1); tcs.SetResult(x); });

            Oy.Publish <string>("Test Downcasting", "Value 1");

            tcs.Task.Wait(100);
            Assert.Equal("Value 1", tcs.Task.Result);
            Assert.Equal(1, hitCount);
        }
Exemplo n.º 26
0
        private async Task Performed(MapDocumentOperation operation)
        {
            if (operation.Operation.Trivial)
            {
                return;
            }

            var stack = operation.Document.Map.Data.GetOne <HistoryStack>();

            stack?.Add(operation.Operation);

            Oy.Publish("MapDocument:HistoryChanged", operation.Document);
        }
Exemplo n.º 27
0
        private async Task Handle <T>(string description, T hook, Func <T, Task> function)
        {
            try
            {
#if DEBUG
                Log.Debug("Bootstrapper", description + ": " + hook.GetType().FullName);
#endif
                await function(hook);
            }
            catch (Exception e)
            {
                Oy.Publish("Shell:UnhandledException", e);
            }
        }
Exemplo n.º 28
0
 public LogComponent()
 {
     _logs    = new List <LogMessage>();
     _control = new TextBox
     {
         Dock       = DockStyle.Fill,
         Multiline  = true,
         Font       = new Font(FontFamily.GenericMonospace, 10),
         ScrollBars = ScrollBars.Both,
         WordWrap   = false,
         ReadOnly   = true
     };
     Oy.Subscribe <LogMessage>("Log", AppendLog);
 }
Exemplo n.º 29
0
            /// <summary>
            /// Add a section to the tree. This will create a top-level menu as well as a toolbar.
            /// </summary>
            private void AddSection(MenuSection ds)
            {
                // Create the root
                var rtn = new MenuTreeRoot(_context, ds.Description, ds);

                // When the menu is closed, push an empty string to the status bar
                rtn.MenuMenuItem.DropDownClosed += (s, a) => { Oy.Publish("Status:Information", ""); };

                // When the menu is opened, update the state of all the menu items in this section
                rtn.MenuMenuItem.DropDownOpening += (s, a) => { rtn.Update(); };

                // Add the node, menu, and toolbar
                RootNodes.Add(ds.Name, rtn);
            }
Exemplo n.º 30
0
        public void Build(RenderContext context, IEnumerable <IOverlayRenderable> builders)
        {
            Resize(context);

            var min = Vector3.Zero;
            var max = Vector3.Zero;

            var oc = _viewport.Camera as OrthographicCamera;
            var pc = _viewport.Camera as PerspectiveCamera;

            if (oc != null)
            {
                var up = (Vector3.One - oc.Expand(new Vector3(1, 1, 0))) * 1000;
                var tl = oc.ScreenToWorld(Vector3.Zero) + up;
                var br = oc.ScreenToWorld(new Vector3(_width, _height, 0)) - up;
                min = Vector3.Min(tl, br);
                max = Vector3.Max(tl, br);
            }

            using (var g = Graphics.FromImage(_bitmap))
            {
                g.CompositingMode = CompositingMode.SourceCopy;
                g.FillRectangle(Brushes.Transparent, 0, 0, _width, _height);
                g.CompositingMode = CompositingMode.SourceOver;

                foreach (var b in builders)
                {
                    try
                    {
                        if (pc != null)
                        {
                            b.Render(_viewport, pc, g);
                        }
                        if (oc != null)
                        {
                            b.Render(_viewport, oc, min, max, g);
                        }
                    }
                    catch (Exception ex)
                    {
                        Oy.Publish("Shell:UnhandledExceptionOnce", ex);
                    }
                }
            }

            var lb = _bitmap.LockBits(new Rectangle(0, 0, _width, _height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);

            context.Device.UpdateTexture(_texture, lb.Scan0, (uint)(lb.Stride * lb.Height), 0, 0, 0, _texture.Width, _texture.Height, _texture.Depth, 0, 0);
            _bitmap.UnlockBits(lb);
        }