private void TranslateModeChecked(object sender, EventArgs e) { if (TranslateModeCheckbox.Checked && _selectedType != SelectionBoxDraggableState.TransformationMode.Resize) { Oy.Publish("SelectTool:TransformationModeChanged", "Resize"); } else { SetCheckState(); } }
/// <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)); }
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")); }
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); }
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()); }
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); }
public void TestEmpty() { int number = 0; Oy.Subscribe("Nothing", () => { Interlocked.Add(ref number, 1); }); Oy.Publish("Nothing").Wait(100); Assert.Equal(1, number); }
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); }
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)); }
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); }
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); }
/// <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)); }
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); }
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); }
public VertexErrorsSidebarPanel( [ImportMany] IEnumerable <Lazy <IVertexErrorCheck> > errorChecks, [Import] Lazy <ITranslationStringProvider> translator ) { _errorChecks = errorChecks; _translator = translator; InitializeComponent(); Oy.Subscribe <VertexSelection>("VertexTool:Updated", t => UpdateErrorList(t)); }
private void Subscribe() { if (_subscriptions != null) { return; } _subscriptions = new List <Subscription> { Oy.Subscribe <MapDocument>("Document:Activated", DocumentActivated), Oy.Subscribe <MapDocument>("MapDocument:SelectionChanged", SelectionChanged) }; }
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 })); }
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)); }
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); }
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())); }
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); }
public VertexSidebarPanel() { InitializeComponent(); Oy.Subscribe <VertexTool>("Tool:Activated", t => { SetSelectedTool(t.CurrentSubTool?.GetType()); }); Oy.Subscribe <Type>("VertexTool:SubToolChanged", t => { SetSelectedTool(t); }); }
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); }
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); }
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); }
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); } }
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); }
/// <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); }
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); }