public void CheckNodeAdded() { Debug.WriteLine("Entering check."); if (this.QueryNodeGroup != null) { // check each node and add if not there. foreach (Node ndCurr in this.QueryNodeGroup.GetNodeList()) { Debug.WriteLine("checking the node (" + ndCurr.GetSparqlID() + ")"); if (!this.renderNodes.ContainsKey(ndCurr)) { // not found, add it. Debug.WriteLine("--- added new node to canvas ---"); CanvasNode cn = new CanvasNode(ndCurr, this); this.renderNodes[ndCurr] = cn; cn.SetX(this.GetRandomXPositionForNewElement()); cn.SetY(this.GetRandomYPositionForNewElement()); // add to the canvas. this.myRenderTarget.Children.Add(cn.Box); } } this.RenderCanvas(); } }
private (Line line, Polygon tip) CreateLine(CanvasNode toNode, CanvasNode fromNode) { var head = toNode.GetInPort(fromNode); var tail = fromNode.GetOutPort(toNode); var line = new Line { StartPoint = tail, EndPoint = head, Stroke = Brushes.Black }; //make arrows less retarded var unitVector = (tail.X - head.X, tail.Y - head.Y); var unitVectorMagnitude = Math.Floor(Math.Sqrt(Math.Pow(unitVector.Item1, 2) + Math.Pow(unitVector.Item2, 2))); unitVector = ((int)Math.Floor(unitVector.Item1 / unitVectorMagnitude) * 5, (int)Math.Floor(unitVector.Item2 / unitVectorMagnitude) * 5); var middlePoint = (head.X + unitVector.Item1, head.Y + unitVector.Item2); var leftPoint = new Point(middlePoint.Item1 + unitVector.Item2, middlePoint.Item2 - unitVector.Item1); var rightPoint = new Point(middlePoint.Item1 - unitVector.Item2, middlePoint.Item2 + unitVector.Item1); var tip = new Polygon { Points = new List <Point> { line.EndPoint, leftPoint, rightPoint }, Fill = Brushes.Black }; return(line, tip); }
private void AddArrowsAsNeeded() { foreach (Node nd in this.renderNodes.Keys) { CanvasNode startNode = this.renderNodes[nd]; foreach (NodeItem ni in nd.GetNodeItemList()) { if (!ni.GetConnected()) { continue; } // else do something. List <Node> nodeList = ni.GetNodeList(); foreach (Node nde in nodeList) { CanvasNode cnConnection = this.renderNodes[nde]; // create the line Line connectionLine = new Line { StrokeThickness = 4, Stroke = new SolidColorBrush(Windows.UI.Colors.DarkGray), X1 = startNode.GetX() + startNode.Box.Width / 2, Y1 = startNode.GetY() + startNode.Box.Height / 2, X2 = cnConnection.GetX() + cnConnection.Box.Width / 2, Y2 = cnConnection.GetY() + cnConnection.Box.Height / 2, }; connectionLine.SetValue(Canvas.ZIndexProperty, 1); this.myRenderTarget.Children.Add(connectionLine); // add the line label this.AddLineLabel(connectionLine, this.myRenderTarget, ni.GetValueType()); } } } }
public NodeGroupCanvas(NodeGroup qng, Canvas renderTargetCanvas) { this.QueryNodeGroup = qng; this.myRenderTarget = renderTargetCanvas; this.random = new Random(); // set up the initial canvas list. this.renderNodes = new Dictionary <Node, CanvasNode>(); if (this.QueryNodeGroup != null) { foreach (Node nd in this.QueryNodeGroup.GetNodeList()) { CanvasNode cn = new CanvasNode(nd, this); this.renderNodes[nd] = cn; cn.SetX(this.GetRandomXPositionForNewElement()); cn.SetY(this.GetRandomYPositionForNewElement()); this.myRenderTarget.Children.Add(cn.Box); } this.RenderCanvas(); } }
private SceneContainer CreateGui() { var vsTex = AssetStorage.Get <string>("texture.vert"); var psTex = AssetStorage.Get <string>("texture.frag"); var btnFuseeLogo = new GUIButton { Name = "Canvas_Button" }; btnFuseeLogo.OnMouseEnter += BtnLogoEnter; btnFuseeLogo.OnMouseExit += BtnLogoExit; btnFuseeLogo.OnMouseDown += BtnLogoDown; var guiFuseeLogo = new Texture(AssetStorage.Get <ImageData>("FuseeText.png")); var fuseeLogo = new TextureNode( "fuseeLogo", vsTex, psTex, //Set the diffuse texture you want to use. guiFuseeLogo, //Define anchor points. They are given in percent, seen from the lower left corner, respectively to the width/height of the parent. //In this setup the element will stretch horizontally but stay the same vertically if the parent element is scaled. UIElementPosition.GetAnchors(AnchorPos.TopTopLeft), //Define Offset and therefor the size of the element. UIElementPosition.CalcOffsets(AnchorPos.TopTopLeft, new float2(0, _initCanvasHeight - 0.5f), _initCanvasHeight, _initCanvasWidth, new float2(1.75f, 0.5f)) ); fuseeLogo.AddComponent(btnFuseeLogo); // Initialize the information text line. var textToDisplay = "FUSEE 3D Scene"; if (_scene.Header.CreatedBy != null || _scene.Header.CreationDate != null) { textToDisplay += " created"; if (_scene.Header.CreatedBy != null) { textToDisplay += " by " + _scene.Header.CreatedBy; } if (_scene.Header.CreationDate != null) { textToDisplay += " on " + _scene.Header.CreationDate; } } var fontLato = AssetStorage.Get <Font>("Lato-Black.ttf"); var guiLatoBlack = new FontMap(fontLato, 24); var text = new TextNode( textToDisplay, "SceneDescriptionText", vsTex, psTex, UIElementPosition.GetAnchors(AnchorPos.StretchHorizontal), UIElementPosition.CalcOffsets(AnchorPos.StretchHorizontal, new float2(_initCanvasWidth / 2 - 4, 0), _initCanvasHeight, _initCanvasWidth, new float2(8, 1)), guiLatoBlack, ColorUint.Tofloat4(ColorUint.Greenery), HorizontalTextAlignment.Center, VerticalTextAlignment.Center); var canvas = new CanvasNode( "Canvas", _canvasRenderMode, new MinMaxRect { Min = new float2(-_canvasWidth / 2, -_canvasHeight / 2f), Max = new float2(_canvasWidth / 2, _canvasHeight / 2f) }); canvas.Children.Add(fuseeLogo); canvas.Children.Add(text); return(new SceneContainer { Children = new List <SceneNode> { //Add canvas. canvas } }); }
void drawPaths(CanvasNode node) { for (int i = 0; i < node.Neighbours.Count; i++) { Line line = new Line(); line.StrokeThickness = 4; line.Stroke = System.Windows.Media.Brushes.Black; line.X1 = node.X + 32; line.X2 = node.Neighbours[i].X + 32; line.Y1 = node.Y + 32; line.Y2 = node.Neighbours[i].Y + 32; line.StrokeDashArray = new DoubleCollection(); line.StrokeDashArray.Add(2); line.StrokeDashArray.Add(2); MapCanvas.Children.Add(line); double low = 0, high = 1, mid; double d = Math.Sqrt((line.X1 - line.X2) * (line.X1 - line.X2) + (line.Y1 - line.Y2) * (line.Y1 - line.Y2)); double normx1 = line.X1 - Math.Min(line.X1, line.X2); double normx2 = line.X2 - Math.Min(line.X1, line.X2); double normy1 = line.Y1 - Math.Min(line.Y1, line.Y2); double normy2 = line.Y2 - Math.Min(line.Y1, line.Y2); while (Math.Abs(low - high) > 0.000001) { mid = (low + high) / 2.0; if (d * mid < MapViewModel.NodeSpace / 2.0) { low = mid; } else if (d * mid > MapViewModel.NodeSpace / 2.0) { high = mid; } else { low = high = mid; } } if (normx1 < normx2) { line.X2 -= normx2 * low; } else { line.X2 += normx1 * low; } if (normx1 < normx2) { line.X1 += normx2 * low; } else { line.X1 -= normx1 * low; } if (normy1 < normy2) { line.Y1 += normy2 * low; } else { line.Y2 -= normy1 * low; } if (normy1 < normy2) { line.Y2 -= normy2 * low; } else { line.Y2 += normy1 * low; } } }
private SceneContainer CreateGui() { var vsTex = AssetStorage.Get <string>("texture.vert"); var psTex = AssetStorage.Get <string>("texture.frag"); var canvasWidth = Width / 100f; var canvasHeight = Height / 100f; var btnFuseeLogo = new GUIButton { Name = "Canvas_Button" }; btnFuseeLogo.OnMouseEnter += BtnLogoEnter; btnFuseeLogo.OnMouseExit += BtnLogoExit; btnFuseeLogo.OnMouseDown += BtnLogoDown; var guiFuseeLogo = new Texture(AssetStorage.Get <ImageData>("FuseeText.png")); var fuseeLogo = new TextureNode( "fuseeLogo", vsTex, psTex, //Set the albedo texture you want to use. guiFuseeLogo, //Define anchor points. They are given in percent, seen from the lower left corner, respectively to the width/height of the parent. //In this setup the element will stretch horizontally but stay the same vertically if the parent element is scaled. UIElementPosition.GetAnchors(AnchorPos.TopTopLeft), //Define Offset and therefor the size of the element. UIElementPosition.CalcOffsets(AnchorPos.TopTopLeft, new float2(0, canvasHeight - 0.5f), canvasHeight, canvasWidth, new float2(1.75f, 0.5f)) ); fuseeLogo.AddComponent(btnFuseeLogo); var fontLato = AssetStorage.Get <Font>("Lato-Black.ttf"); var guiLatoBlack = new FontMap(fontLato, 24); var text = new TextNode( "FUSEE Simple Example", "ButtonText", vsTex, psTex, UIElementPosition.GetAnchors(AnchorPos.StretchHorizontal), UIElementPosition.CalcOffsets(AnchorPos.StretchHorizontal, new float2(canvasWidth / 2 - 4, 0), canvasHeight, canvasWidth, new float2(8, 1)), guiLatoBlack, ColorUint.Tofloat4(ColorUint.Greenery), HorizontalTextAlignment.Center, VerticalTextAlignment.Center); var canvas = new CanvasNode( "Canvas", _canvasRenderMode, new MinMaxRect { Min = new float2(-canvasWidth / 2, -canvasHeight / 2f), Max = new float2(canvasWidth / 2, canvasHeight / 2f) }) { Children = new ChildList() { //Simple Texture Node, contains the fusee logo. fuseeLogo, text } }; return(new SceneContainer { Children = new List <SceneNode> { //Add canvas. canvas } }); }
//Build a scene graph consisting out of a canvas and other UI elements. private SceneContainer CreateNineSliceScene() { var vsTex = AssetStorage.Get <string>("texture.vert"); var psTex = AssetStorage.Get <string>("texture.frag"); var vsNineSlice = AssetStorage.Get <string>("nineSlice.vert"); var psNineSlice = AssetStorage.Get <string>("nineSliceTile.frag"); var canvasScaleFactor = _initWindowWidth / _canvasWidth; float borderScaleFactor = 1; if (_canvasRenderMode == CanvasRenderMode.Screen) { borderScaleFactor = canvasScaleFactor; } var fps = new TextNode( "FPS: 0.00", "FPSText", vsTex, psTex, UIElementPosition.GetAnchors(AnchorPos.DownDownRight), new MinMaxRect { Min = new float2(-2, 0), Max = new float2(0, 1) }, _fontMap, ColorUint.Tofloat4(ColorUint.White), HorizontalTextAlignment.Center, VerticalTextAlignment.Center ); _fpsText = fps.GetComponentsInChildren <GUIText>().FirstOrDefault(); var text = new TextNode( "The five\n" + "boxing wizards\n" + "jump\n" + "quickly.", "ButtonText", vsTex, psTex, UIElementPosition.GetAnchors(AnchorPos.StretchAll), new MinMaxRect { Min = new float2(1f, 0.5f), Max = new float2(-1f, -0.5f) }, _fontMap, ColorUint.Tofloat4(ColorUint.Greenery), HorizontalTextAlignment.Center, VerticalTextAlignment.Center); var catTextureNode = new TextureNode( "Cat", AssetStorage.Get <string>("nineSlice.vert"), AssetStorage.Get <string>("nineSliceTile.frag"), //Set the albedo texture you want to use. new Texture(AssetStorage.Get <ImageData>("Kitti.jpg")), //Define anchor points. They are given in percent, seen from the lower left corner, respectively to the width/height of the parent. //In this setup the element will stretch horizontally but stay the same vertically if the parent element is scaled. UIElementPosition.GetAnchors(AnchorPos.StretchHorizontal),//Anchor is in the lower left corner of the parent. Anchor is in the lower right corner of the parent. //Define Offset and therefor the size of the element. //Min: distance to this elements Min anchor. //Max: distance to this elements Max anchor. UIElementPosition.CalcOffsets(AnchorPos.StretchHorizontal, new float2(_initCanvasWidth / 2 - 2.5f, 0), _initCanvasHeight, _initCanvasWidth, new float2(5, 4)), //Choose in how many tiles you want to split the inner part of the texture. Use float2.one if you want it stretched. new float2(5, 5), //Tell how many percent of the texture, seen from the edges, belongs to the border. Order: left, right, top, bottom. new float4(0.11f, 0.11f, 0.06f, 0.17f), 4, 4, 4, 4, borderScaleFactor ) { Children = new ChildList() { text } }; catTextureNode.Components.Add(_btnCat); var bltTextureNode = new TextureNode( "Blt", vsTex, psTex, //Set the albedo texture you want to use. _bltDestinationTex, //_fontMap.Image, //Define anchor points. They are given in percent, seen from the lower left corner, respectively to the width/height of the parent. //In this setup the element will stretch horizontally but stay the same vertically if the parent element is scaled. UIElementPosition.GetAnchors(AnchorPos.DownDownLeft),//Anchor is in the lower left corner of the parent. Anchor is in the lower right corner of the parent. //Define Offset and therefor the size of the element. //Min: distance to this elements Min anchor. //Max: distance to this elements Max anchor. UIElementPosition.CalcOffsets(AnchorPos.DownDownLeft, new float2(0, 0), _initCanvasHeight, _initCanvasWidth, new float2(4, 4))); var quagganTextureNode1 = new TextureNode( "Quaggan1", vsNineSlice, psNineSlice, new Texture(AssetStorage.Get <ImageData>("testTex.jpg")), //In this setup the element will stay in the upper left corner of the parent and will not be stretched at all. UIElementPosition.GetAnchors(AnchorPos.TopTopLeft), //Anchor is in the lower right corner.Anchor is in the lower left corner. UIElementPosition.CalcOffsets(AnchorPos.TopTopLeft, new float2(2.5f, 0), 3, 6, new float2(1, 1)), new float2(1, 1), new float4(0.1f, 0.1f, 0.1f, 0.09f), 1, 1, 1, 1, borderScaleFactor ); var nineSliceTextureNode = new TextureNode( "testImage", vsNineSlice, psNineSlice, new Texture(AssetStorage.Get <ImageData>("9SliceSprites-4.png")), //In this setup the element will stay in the upper right corner of the parent and will not be stretched at all. UIElementPosition.GetAnchors(AnchorPos.TopTopRight),//Anchor is in the upper right corner.//Anchor is in the upper right corner. UIElementPosition.CalcOffsets(AnchorPos.TopTopRight, new float2(_initCanvasWidth - 6, _initCanvasHeight - 3), _initCanvasHeight, _initCanvasWidth, new float2(6, 3)), new float2(2, 3), new float4(0.1f, 0.1f, 0.1f, 0.1f), 2.5f, 2.5f, 2.5f, 2.5f, borderScaleFactor ) { Children = new ChildList() { quagganTextureNode1, text } }; var quagganTextureNode = new TextureNode( "Quaggan", vsNineSlice, psNineSlice, new Texture(AssetStorage.Get <ImageData>("testTex.jpg")), //In this setup the element will stay in the upper left corner of the parent and will not be stretched at all. UIElementPosition.GetAnchors(AnchorPos.TopTopLeft), //Anchor is in the lower right corner.Anchor is in the lower left corner. UIElementPosition.CalcOffsets(AnchorPos.TopTopLeft, new float2(0, _initCanvasHeight - 1), _initCanvasHeight, _initCanvasWidth, new float2(6, 1)), new float2(5, 1), new float4(0.1f, 0.1f, 0.1f, 0.09f), 1, 1, 1, 1, borderScaleFactor ); var quagganTextureNode2 = new TextureNode( "Quaggan", vsNineSlice, psNineSlice, new Texture(AssetStorage.Get <ImageData>("testTex.jpg")), //In this setup the element will stay in the upper left corner of the parent and will not be stretched at all. UIElementPosition.GetAnchors(AnchorPos.TopTopLeft), //Anchor is in the lower right corner.Anchor is in the lower left corner. UIElementPosition.CalcOffsets(AnchorPos.TopTopLeft, new float2(0, _initCanvasHeight - 3), _initCanvasHeight, _initCanvasWidth, new float2(6, 1)), new float2(5, 1), new float4(0.1f, 0.1f, 0.1f, 0.09f), 1, 1, 1, 1, borderScaleFactor ); var quagganTextureNode3 = new TextureNode( "Quaggan", vsNineSlice, psNineSlice, new Texture(AssetStorage.Get <ImageData>("testTex.jpg")), //In this setup the element will stay in the upper left corner of the parent and will not be stretched at all. UIElementPosition.GetAnchors(AnchorPos.StretchVertical), //Anchor is in the lower right corner. Anchor is in the lower left corner. UIElementPosition.CalcOffsets(AnchorPos.StretchVertical, new float2(0, _initCanvasHeight - 5), _initCanvasHeight, _initCanvasWidth, new float2(6, 1)), new float2(5, 1), new float4(0.1f, 0.1f, 0.1f, 0.09f), 1, 1, 1, 1, borderScaleFactor ); var canvas = new CanvasNode( "Canvas", _canvasRenderMode, new MinMaxRect { Min = new float2(-_canvasWidth / 2, -_canvasHeight / 2f), Max = new float2(_canvasWidth / 2, _canvasHeight / 2f) }) { Children = new ChildList() { //Simple Texture Node, contains a Blt"ed" texture. bltTextureNode, //Add nine sliced textures to canvas catTextureNode, quagganTextureNode, nineSliceTextureNode, quagganTextureNode2, quagganTextureNode3, fps } }; var canvasMat = ShaderCodeBuilder.MakeShaderEffect(new float4(1, 0, 0, 1)); canvas.AddComponent(canvasMat); canvas.AddComponent(new Plane()); canvas.AddComponent(_btnCanvas); return(new SceneContainer { Children = new List <SceneNode> { //Add canvas. new SceneNode() { Components = new List <SceneComponent>() { new Transform() { Translation = new float3(0, 0, 0) } }, Children = new ChildList() { canvas } }, } }); }
private SceneContainer CreateGui() { float canvasScaleFactor = _initWidth / _canvasWidth; float borderScaleFactor = 1; if (_canvasRenderMode == CanvasRenderMode.Screen) { borderScaleFactor = canvasScaleFactor; } GUIButton btnFuseeLogo = new GUIButton { Name = "Canvas_Button" }; btnFuseeLogo.OnMouseEnter += BtnLogoEnter; btnFuseeLogo.OnMouseExit += BtnLogoExit; btnFuseeLogo.OnMouseDown += BtnLogoDown; Texture guiFuseeLogo = new Texture(AssetStorage.Get <ImageData>("FuseeText.png")); TextureNode fuseeLogo = new TextureNode( "fuseeLogo", UIHelper.VsTex, UIHelper.PsTex, guiFuseeLogo, UIElementPosition.GetAnchors(AnchorPos.TopTopLeft), UIElementPosition.CalcOffsets(AnchorPos.TopTopLeft, new float2(0, _canvasHeight - 0.5f), _canvasHeight, _canvasWidth, new float2(1.75f, 0.5f)), float2.One); fuseeLogo.AddComponent(btnFuseeLogo); SceneNode markModelContainer = new SceneNode { Name = "MarkModelContainer", }; CanvasNode canvas = new CanvasNode( "Canvas", _canvasRenderMode, new MinMaxRect { Min = new float2(-_canvasWidth / 2f, -_canvasHeight / 2f), Max = new float2(_canvasWidth / 2f, _canvasHeight / 2f) } ) { Children = new ChildList() { fuseeLogo, markModelContainer } }; for (int i = 0; i < _uiInput.Count; i++) { var item = _uiInput[i]; if (item.AnnotationKind != UIHelper.AnnotationKind.Confirmed) { UIHelper.CreateAndAddCircleAnnotationAndLine(markModelContainer, item.AnnotationKind, item.Size, _uiInput[i].AnnotationCanvasPos, borderScaleFactor, "#" + i + " " + item.SegmentationClass + ", " + item.Probability.ToString(CultureInfo.GetCultureInfo("en-gb"))); } else { UIHelper.CreateAndAddCircleAnnotationAndLine(markModelContainer, item.AnnotationKind, item.Size, _uiInput[i].AnnotationCanvasPos, borderScaleFactor, "#" + i + " " + item.SegmentationClass); } } return(new SceneContainer { Children = new List <SceneNode> { //Add canvas. canvas } }); }