/// <summary> /// Called by unity during the launch of KSP. It will only be run once. So make sure it doesn't /// crash. /// </summary> private void Start() { Instance = this; _ledControllers.Add(new LogitechLEDController()); LayoutProvider = new WindowsLayoutProvider(); DontDestroyOnLoad(this); }
public bool RegisterProvider(ILayoutProvider provider) { if (!_providers.Contains(provider)) { _providers.Add(provider); return(true); } return(false); }
private static void DrawEdge(XGraphics g, Edge e, PresentationSettings presentationSettings, ILayoutProvider layout) { Vector3 p1 = layout.GetPositionOfNode(e.Source); Vector3 p2 = layout.GetPositionOfNode(e.Target); g.DrawLine(presentationSettings.CustomColors.HasCustomColor(e) ? presentationSettings.CustomColors.GetEdgePen(e) : presentationSettings.DefaultEdgePen, presentationSettings.ScaleX(p1.X), presentationSettings.ScaleY(p1.Y), presentationSettings.ScaleX(p2.X), presentationSettings.ScaleY(p2.Y)); }
public WidgetRenderContext (IContextProvider contextProvider, ILayoutProvider layoutProvider, IThemeProvider themeProvider) { if (contextProvider == null) throw new ArgumentNullException ("contextProvider"); if (layoutProvider == null) throw new ArgumentNullException ("layoutProvider"); if (themeProvider == null) throw new ArgumentNullException ("themeProvider"); this.context_provider = contextProvider; this.layout_provider = layoutProvider; this.theme_provider = themeProvider; }
/// <summary> /// Creates a new instance of a Networkvisualizer which renders the specified network in real-time /// </summary> /// <param name='n'> /// N. /// </param> /// <param name='layout'> /// Layout. /// </param> public static void Start(Network network, ILayoutProvider layout, NetworkColorizer colorizer = null, int width=800, int height=600) { // The actual rendering needs to be done in a separate thread placed in the single thread appartment state _mainThread = new Thread(new ThreadStart(new Action(delegate() { NetworkVisualizer p = new NetworkVisualizer(network, layout, colorizer, width, height); p.Run(80f); }))); _mainThread.SetApartmentState(ApartmentState.STA); _mainThread.Name = "STA Thread for NETGen Visualizer"; // Fire up the thread _mainThread.Start(); }
private static void Draw(XGraphics g, Network n, PresentationSettings presentationSettings, ILayoutProvider layout) { lock (n) { if (g == null) return; g.SmoothingMode = PdfSharp.Drawing.XSmoothingMode.HighQuality; g.Clear(Color.White); foreach (Edge e in n.Edges) DrawEdge(g, e, presentationSettings, layout); foreach (Vertex v in n.Vertices) DrawVertex(g, v, presentationSettings, layout); } }
internal NetworkVisualizer(Network network, ILayoutProvider layout, NetworkColorizer colorizer, int width, int height) : base(width, height, GraphicsMode.Default, "NETGen Display") { Keyboard.KeyDown += new EventHandler<KeyboardKeyEventArgs>(Keyboard_KeyDown); Mouse.ButtonDown += new EventHandler<MouseButtonEventArgs>(Mouse_ButtonDown); Mouse.ButtonUp += new EventHandler<MouseButtonEventArgs>(Mouse_ButtonUp); Mouse.Move += new EventHandler<MouseMoveEventArgs>(Mouse_Move); Mouse.WheelChanged += new EventHandler<MouseWheelEventArgs>(Mouse_WheelChanged); if (colorizer == null) _colorizer = new NetworkColorizer(); else _colorizer = colorizer; _network = network; _layout = layout; }
private void MoveToClipboard(PropertiesNode focusedPropertiesNode, bool delete) { var layoutProvider = (focusedPropertiesNode.ControlWrapper as ILayoutProvider); if (layoutProvider == null || (focusedPropertiesNode.OnCopy != null && !focusedPropertiesNode.OnCopy())) { MessageBox.Show( string.Format("Can't make clipboard operation on element \"{0}\"", focusedPropertiesNode.ControlName), "Can't make operation", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } var focusedPropertiesNodeParent = ((PropertiesNode)ControlsTree.FocusedNode.Tag); if (delete) { DeleteNode(focusedPropertiesNodeParent); } _clipboardNode = layoutProvider; ButtonPaste.Enabled = true; }
public static void CreatePDF(string path, Network n, PresentationSettings presentationSettings, ILayoutProvider layout) { if (presentationSettings ==null) presentationSettings = new Visualization.PresentationSettings(2000d, 1000d, 0d); PdfSharp.Pdf.PdfDocument doc = new PdfDocument(); doc.Info.Title = "Network"; doc.Info.Subject = "Created by NETGen, the cross-platform network simulation framework"; PdfPage page = doc.AddPage(); page.Size = PageSize.A4; page.Orientation = PageOrientation.Landscape; PresentationSettings newSettings = presentationSettings.Clone(); newSettings.WorldWidth = (int) page.Width.Point; newSettings.WorldHeight = (int) page.Height.Point; newSettings.VertexSize *= (int) (newSettings.WorldWidth/presentationSettings.WorldWidth); // Draw the network to the xgraphics object Draw(XGraphics.FromPdfPage(page), n, presentationSettings, layout); // Save the s_document... doc.Save(path); }
public LayoutProvider(ILayoutProvider innerRepository) : base(innerRepository) { inner = innerRepository; }
/// <summary> /// Register a <see cref="ILayoutProvider"/> for <see cref="TComposite"/> /// </summary> /// <typeparam name="TComposite"></typeparam> /// <param name="layoutProvider"></param> public void Register <TComposite>(ILayoutProvider layoutProvider) { _layoutProviders[typeof(TComposite)] = layoutProvider.PerformLayout; }
public bool UnregisterProvider(ILayoutProvider provider) { return(_providers.Remove(provider)); }
void Update() { if(Input.GetKeyDown(KeyCode.N)) { var newItem = GameObject.CreatePrimitive(PrimitiveType.Sphere); newItem.transform.position = UnityEngine.Random.insideUnitSphere * 20; items.Add(newItem.transform); } if(Input.GetKeyDown(KeyCode.Space)) { layoutToggle = !layoutToggle; print("Toggling layout provider: " + layoutToggle); layoutProvider.Dispose(); if(layoutToggle) { layoutProvider = new CircleLayoutProvider() { Items = items }; } else { layoutProvider = new GridLayoutProvider() { Items = items }; } } }
private static void DrawVertex(XGraphics g, Vertex v, PresentationSettings presentationSettings, ILayoutProvider layout) { Vector3 p = layout.GetPositionOfNode(v); if (!double.IsNaN(p.X) && !double.IsNaN(p.Y) && !double.IsNaN(p.Z)) g.DrawEllipse(presentationSettings.CustomColors.HasCustomColor(v) ? presentationSettings.CustomColors.GetVertexBrush(v) : presentationSettings.DefaultVertexBrush, presentationSettings.ScaleX(p.X) - presentationSettings.VertexSize / 2, presentationSettings.ScaleY(p.Y) - presentationSettings.VertexSize / 2, presentationSettings.VertexSize, presentationSettings.VertexSize); }