private void internalTextEditWidget_InsertBarPositionChanged(object sender, EventArgs e) { double fontHeight = Printer.TypeFaceStyle.EmSizeInPixels; Vector2 barPosition = internalTextEditWidget.InsertBarPosition; // move the minimum amount required to keep the bar in view Vector2 currentOffsetInView = barPosition + TopLeftOffset; Vector2 requiredOffet = Vector2.Zero; if (currentOffsetInView.x > Width - 2) { requiredOffet.x = currentOffsetInView.x - Width + 2; } else if (currentOffsetInView.x < 0) { requiredOffet.x = currentOffsetInView.x; } if (currentOffsetInView.y <= -(Height - fontHeight)) { requiredOffet.y = -(currentOffsetInView.y + Height) + fontHeight; } else if (currentOffsetInView.y > 0) { requiredOffet.y = -currentOffsetInView.y; } TopLeftOffset = new VectorMath.Vector2(TopLeftOffset.x - requiredOffet.x, TopLeftOffset.y + requiredOffet.y); }
public override (bool adjustOrigin, bool adjustWidth) GetOriginAndWidthForChild(GuiWidget parent, GuiWidget child, out Vector2 newOriginRelParent, out double newWidth) { bool needToAdjustWidth = false; bool needToAdjustOrigin = false; newOriginRelParent = child.OriginRelativeParent; newWidth = child.Width; if (child.HAnchor.HasFlag(HAnchor.Left)) { needToAdjustOrigin = true; // Hold it to the left newOriginRelParent = new Vector2(parent.LocalBounds.Left + child.DeviceMarginAndBorder.Left + parent.DevicePadding.Left - child.LocalBounds.Left, child.OriginRelativeParent.Y); if ((child.HAnchor & HAnchor.Center) == HAnchor.Center) { // widen the bounds to the center double parentUsableWidth = parent.LocalBounds.Width - (parent.DevicePadding.Left + parent.DevicePadding.Right); newWidth = parentUsableWidth / 2 - (child.DeviceMarginAndBorder.Left + child.DeviceMarginAndBorder.Right); needToAdjustWidth = true; } else if ((child.HAnchor & HAnchor.Right) == HAnchor.Right) { // widen the bounds to the right double parentUsableWidth = parent.LocalBounds.Width - (parent.DevicePadding.Left + parent.DevicePadding.Right); newWidth = parentUsableWidth - (child.DeviceMarginAndBorder.Left + child.DeviceMarginAndBorder.Right); needToAdjustWidth = true; } } else if ((child.HAnchor & HAnchor.Center) == HAnchor.Center) { if ((child.HAnchor & HAnchor.Right) == HAnchor.Right) { // fix the offset newOriginRelParent = new VectorMath.Vector2( parent.DevicePadding.Left + child.DeviceMarginAndBorder.Left + (parent.Width - parent.DevicePadding.Left - parent.DevicePadding.Right) / 2, child.OriginRelativeParent.Y); // widen the bounds to the right double parentUsableWidth = parent.LocalBounds.Width - (parent.DevicePadding.Left + parent.DevicePadding.Right); newWidth = parentUsableWidth / 2 - (child.DeviceMarginAndBorder.Left + child.DeviceMarginAndBorder.Right); needToAdjustWidth = true; } else { // hold it centered double parentCenterX = parent.LocalBounds.Left + parent.DevicePadding.Left + (parent.Width - (parent.DevicePadding.Left + parent.DevicePadding.Right)) / 2; double originX = parentCenterX - child.LocalBounds.Left - (child.Width + child.DeviceMarginAndBorder.Left + child.DeviceMarginAndBorder.Right) / 2 + child.DeviceMarginAndBorder.Left; newOriginRelParent = new Vector2(originX, child.OriginRelativeParent.Y); needToAdjustOrigin = true; } } else if ((child.HAnchor & HAnchor.Right) == HAnchor.Right) { // hold it to the right newOriginRelParent = new Vector2(parent.LocalBounds.Right - child.DeviceMarginAndBorder.Right - parent.DevicePadding.Right - child.LocalBounds.Right, child.OriginRelativeParent.Y); needToAdjustOrigin = true; } return(needToAdjustOrigin, needToAdjustWidth); }
public MeshViewerApplication(string meshFileToLoad = "") : base(800, 600) { BackgroundColor = RGBA_Bytes.White; MinimumSize = new VectorMath.Vector2(200, 200); Title = "MatterHackers MeshViewr"; UseOpenGL = true; FlowLayoutWidget mainContainer = new FlowLayoutWidget(FlowDirection.TopToBottom); mainContainer.AnchorAll(); viewArea = new GuiWidget(); viewArea.AnchorAll(); Vector3 viewerVolume = new Vector3(200, 200, 200); double scale = 1; meshViewerWidget = new MeshViewerWidget(viewerVolume, scale, MeshViewerWidget.BedShape.Rectangular, "No Part Loaded"); meshViewerWidget.AnchorAll(); viewArea.AddChild(meshViewerWidget); mainContainer.AddChild(viewArea); FlowLayoutWidget buttonPanel = new FlowLayoutWidget(FlowDirection.LeftToRight); buttonPanel.HAnchor = HAnchor.ParentLeftRight; buttonPanel.Padding = new BorderDouble(3, 3); buttonPanel.BackgroundColor = RGBA_Bytes.DarkGray; if (meshFileToLoad != "") { meshViewerWidget.LoadMesh(meshFileToLoad); } else { openFileButton = new Button("Open 3D File", 0, 0); openFileButton.Click += new Button.ButtonEventHandler(openFileButton_ButtonClick); buttonPanel.AddChild(openFileButton); } bedCheckBox = new CheckBox("Bed"); bedCheckBox.Checked = true; buttonPanel.AddChild(bedCheckBox); wireframeCheckBox = new CheckBox("Wireframe"); buttonPanel.AddChild(wireframeCheckBox); GuiWidget leftRightSpacer = new GuiWidget(); leftRightSpacer.HAnchor = HAnchor.ParentLeftRight; buttonPanel.AddChild(leftRightSpacer); mainContainer.AddChild(buttonPanel); this.AddChild(mainContainer); this.AnchorAll(); AddHandlers(); }
public override bool GetOriginAndWidthForChild(GuiWidget parent, GuiWidget child, out Vector2 newOriginRelParent, out double newWidth) { bool needToAdjustAnything = false; newOriginRelParent = child.OriginRelativeParent; newWidth = child.Width; if ((child.HAnchor & HAnchor.ParentLeft) == HAnchor.ParentLeft) { // Hold it to the left newOriginRelParent = new Vector2(parent.LocalBounds.Left + child.Margin.Left + parent.Padding.Left - child.LocalBounds.Left, child.OriginRelativeParent.y); if ((child.HAnchor & HAnchor.ParentCenter) == HAnchor.ParentCenter) { // widen the bounds to the center double parentUsableWidth = parent.LocalBounds.Width - (parent.Padding.Left + parent.Padding.Right); newWidth = parentUsableWidth / 2 - (child.Margin.Left + child.Margin.Right); } else if ((child.HAnchor & HAnchor.ParentRight) == HAnchor.ParentRight) { // widen the bounds to the right double parentUsableWidth = parent.LocalBounds.Width - (parent.Padding.Left + parent.Padding.Right); newWidth = parentUsableWidth - (child.Margin.Left + child.Margin.Right); } needToAdjustAnything = true; } else if ((child.HAnchor & HAnchor.ParentCenter) == HAnchor.ParentCenter) { if ((child.HAnchor & HAnchor.ParentRight) == HAnchor.ParentRight) { // fix the offset newOriginRelParent = new VectorMath.Vector2( parent.Padding.Left + child.Margin.Left + (parent.Width - parent.Padding.Left - parent.Padding.Right) / 2, child.OriginRelativeParent.y); // widen the bounds to the right double parentUsableWidth = parent.LocalBounds.Width - (parent.Padding.Left + parent.Padding.Right); newWidth = parentUsableWidth / 2 - (child.Margin.Left + child.Margin.Right); } else { // hold it centered double parentCenterX = parent.LocalBounds.Left + parent.Padding.Left + (parent.Width - (parent.Padding.Left + parent.Padding.Right)) / 2; double originX = parentCenterX - child.LocalBounds.Left - (child.Width + child.Margin.Left + child.Margin.Right) / 2 + child.Margin.Left; newOriginRelParent = new Vector2(originX, child.OriginRelativeParent.y); } needToAdjustAnything = true; } else if ((child.HAnchor & HAnchor.ParentRight) == HAnchor.ParentRight) { // hold it to the right newOriginRelParent = new Vector2(parent.LocalBounds.Right - child.Margin.Right - parent.Padding.Right - child.LocalBounds.Right, child.OriginRelativeParent.y); needToAdjustAnything = true; } return(needToAdjustAnything); }
public UpdateControlView() { textImageButtonFactory.normalFillColor = RGBA_Bytes.Gray; textImageButtonFactory.normalTextColor = ActiveTheme.Instance.PrimaryTextColor; HAnchor = HAnchor.ParentLeftRight; BackgroundColor = ActiveTheme.Instance.TransparentDarkOverlay; Padding = new BorderDouble(6, 5); { updateStatusText = new TextWidget(string.Format(""), textColor: ActiveTheme.Instance.PrimaryTextColor); updateStatusText.AutoExpandBoundsToText = true; updateStatusText.VAnchor = VAnchor.ParentCenter; GuiWidget horizontalSpacer = new GuiWidget(); horizontalSpacer.HAnchor = HAnchor.ParentLeftRight; checkUpdateLink = textImageButtonFactory.Generate("Check for Update".Localize()); checkUpdateLink.VAnchor = VAnchor.ParentCenter; checkUpdateLink.Click += CheckForUpdate; checkUpdateLink.Visible = false; downloadUpdateLink = textImageButtonFactory.Generate("Download Update".Localize()); downloadUpdateLink.VAnchor = VAnchor.ParentCenter; downloadUpdateLink.Click += DownloadUpdate; downloadUpdateLink.Visible = false; installUpdateLink = textImageButtonFactory.Generate("Install Update".Localize()); installUpdateLink.VAnchor = VAnchor.ParentCenter; installUpdateLink.Click += InstallUpdate; installUpdateLink.Visible = false; AddChild(updateStatusText); AddChild(horizontalSpacer); AddChild(checkUpdateLink); AddChild(downloadUpdateLink); AddChild(installUpdateLink); } UpdateControlData.Instance.UpdateStatusChanged.RegisterEvent(UpdateStatusChanged, ref unregisterEvents); MinimumSize = new VectorMath.Vector2(0, 50); UpdateStatusChanged(null, null); }
public GCodeViewerApplication(string gCodeToLoad = "") : base(800, 600) { this.Title = "G Code Visualizer"; MinimumSize = new VectorMath.Vector2(200, 200); Title = "MatterHackers GCodeVisualizer"; gCodeViewWidget = new GCodeViewWidget(new Vector2(), new Vector2(100, 100)); AddChild(gCodeViewWidget); FlowLayoutWidget keepOnTop = new FlowLayoutWidget(); prevLayerButton = new Button("<<", 0, 0); prevLayerButton.Click += prevLayer_ButtonClick; keepOnTop.AddChild(prevLayerButton); currentLayerIndex = new NumberEdit(1, pixelWidth: 40); keepOnTop.AddChild(currentLayerIndex); currentLayerIndex.EditComplete += new EventHandler(layerCountTextWidget_EditComplete); layerCountTextWidget = new TextWidget("/1____", 12); keepOnTop.AddChild(layerCountTextWidget); nextLayerButton = new Button(">>", 0, 0); nextLayerButton.Click += nextLayer_ButtonClick; keepOnTop.AddChild(nextLayerButton); if (gCodeToLoad != "") { gCodeViewWidget.LoadFile(gCodeToLoad); } else { openFileButton = new Button("Open GCode", 0, 0); openFileButton.Click += openFileButton_ButtonClick; keepOnTop.AddChild(openFileButton); } AddChild(keepOnTop); AnchorAll(); UiThread.RunOnIdle(currentLayerIndex.Focus); }
public GCodeViewerApplication(string gCodeToLoad = "") : base(800, 600) { MinimumSize = new VectorMath.Vector2(200, 200); Title = "MatterHackers GCodeVisualizer"; gCodeViewWidget = new GCodeViewWidget(new Vector2(), new Vector2(100, 100)); AddChild(gCodeViewWidget); FlowLayoutWidget keepOnTop = new FlowLayoutWidget(); prevLayerButton = new Button("<<", 0, 0); prevLayerButton.Click += new Button.ButtonEventHandler(prevLayer_ButtonClick); keepOnTop.AddChild(prevLayerButton); currentLayerIndex = new NumberEdit(1, pixelWidth: 40); keepOnTop.AddChild(currentLayerIndex); currentLayerIndex.EditComplete += new EventHandler(layerCountTextWidget_EditComplete); layerCountTextWidget = new TextWidget("/1____", 12); keepOnTop.AddChild(layerCountTextWidget); nextLayerButton = new Button(">>", 0, 0); nextLayerButton.Click += new Button.ButtonEventHandler(nextLayer_ButtonClick); keepOnTop.AddChild(nextLayerButton); if (gCodeToLoad != "") { gCodeViewWidget.Load(gCodeToLoad); } else { openFileButton = new Button("Open GCode", 0, 0); openFileButton.Click += new Button.ButtonEventHandler(openFileButton_ButtonClick); keepOnTop.AddChild(openFileButton); } AddChild(keepOnTop); AnchorAll(); currentLayerIndex.Focus(); }
void ClearCollectedTmpPoints(out double tmp_expectedLen) { //clear all previous collected points int j = _tempPoints.Count; tmp_expectedLen = 0; if (j > 0) { tmp_expectedLen = _expectedSegmentLen; for (int i = 0; i < j;) { //p0-p1 VectorMath.Vector2 p0 = _tempPoints[i]; VectorMath.Vector2 p1 = _tempPoints[i + 1]; //------------------------------- //a series of connected line if (i == 0) { //1st move to _currentMark.InvokeMoveTo(_output, p0.x, p0.y); } _currentMark.InvokeLineTo(_output, p1.x, p1.y); //------------------------------- double len = AggMath.calc_distance(p0.x, p0.y, p1.x, p1.y); tmp_expectedLen -= len; i += 2; _latest_X = p1.x; _latest_Y = p1.y; } _tempPoints.Clear(); } //----------------- }
public VertexStore MakeVxs2(VertexStoreSnap vsnap) { VertexStore vxs = new VertexStore(); m_curve3.Reset(); m_curve4.Reset(); var snapIter = vsnap.GetVertexSnapIter(); CurvePointMode latestCurveMode = CurvePointMode.NotCurve; double x, y; VertexCmd cmd; VectorMath.Vector2 c3p2 = new VectorMath.Vector2(); VectorMath.Vector2 c4p2 = new VectorMath.Vector2(); VectorMath.Vector2 c4p3 = new VectorMath.Vector2(); double lastX = 0; double lasty = 0; double lastMoveX = 0; double lastMoveY = 0; do { //this vertex cmd = snapIter.GetNextVertex(out x, out y); switch (cmd) { //this p2 control case VertexCmd.P2c: { switch (latestCurveMode) { case CurvePointMode.P2: { } break; case CurvePointMode.P3: { } break; case CurvePointMode.NotCurve: { c3p2.x = x; c3p2.y = y; } break; default: { } break; } latestCurveMode = CurvePointMode.P2; } break; case VertexCmd.P3c: { //this is p3c switch (latestCurveMode) { case CurvePointMode.P2: { c4p2.x = c3p2.x; c4p2.y = c3p2.y; c4p3.x = x; c4p3.y = y; c3p2.x = x; } break; case CurvePointMode.P3: { // vxs.AddVertex(x, y, cmd); c4p3.x = x; c4p3.y = y; //m_curve4.MakeLines(vxs, // lastX, lasty, // c3p2.X, c3p2.Y, // c4p2.x, c4p2.y, // x, y); // vxs.AddVertex(x, y, cmd); } break; case CurvePointMode.NotCurve: { c4p2.x = x; c4p2.y = y; } break; } latestCurveMode = CurvePointMode.P3; } break; case VertexCmd.LineTo: { switch (latestCurveMode) { case CurvePointMode.P2: { m_curve3.MakeLines(vxs, lastX, lasty, c3p2.X, c3p2.Y, x, y); } break; case CurvePointMode.P3: { //from curve4 // vxs.AddVertex(x, y, cmd); m_curve4.MakeLines(vxs, lastX, lasty, c4p2.x, c4p2.y, c4p3.x, c4p3.y, x, y); } break; default: { vxs.AddVertex(x, y, cmd); } break; } //----------- latestCurveMode = CurvePointMode.NotCurve; lastX = x; lasty = y; //----------- } break; case VertexCmd.MoveTo: { //move to, and end command vxs.AddVertex(x, y, cmd); //----------- latestCurveMode = CurvePointMode.NotCurve; lastMoveX = lastX = x; lastMoveY = lasty = y; //----------- } break; case VertexCmd.CloseAndEndFigure: { latestCurveMode = CurvePointMode.NotCurve; vxs.AddVertex(x, y, cmd); //move to begin lastX = lastMoveX; lasty = lastMoveY; } break; case VertexCmd.EndFigure: { latestCurveMode = CurvePointMode.NotCurve; vxs.AddVertex(x, y, cmd); } break; default: { //move to, and end command vxs.AddVertex(x, y, cmd); //----------- latestCurveMode = CurvePointMode.NotCurve; lastX = x; lasty = y; //----------- } break; } } while (cmd != VertexCmd.Stop); return(vxs); }
public MeshViewerApplication(string meshFileToLoad = "") : base(800, 600) { BackgroundColor = Color.White; MinimumSize = new VectorMath.Vector2(200, 200); Title = "MatterHackers MeshViewr"; UseOpenGL = true; FlowLayoutWidget mainContainer = new FlowLayoutWidget(FlowDirection.TopToBottom); mainContainer.AnchorAll(); viewArea = new GuiWidget(); viewArea.AnchorAll(); Vector3 viewerVolume = new Vector3(200, 200, 200); meshViewerWidget = new MeshViewerWidget(viewerVolume, new Vector2(100, 100), BedShape.Rectangular, "No Part Loaded"); meshViewerWidget.AnchorAll(); viewArea.AddChild(meshViewerWidget); mainContainer.AddChild(viewArea); FlowLayoutWidget buttonPanel = new FlowLayoutWidget(FlowDirection.LeftToRight); buttonPanel.HAnchor = HAnchor.Stretch; buttonPanel.Padding = new BorderDouble(3, 3); buttonPanel.BackgroundColor = Color.DarkGray; if (meshFileToLoad != "") { meshViewerWidget.LoadItemIntoScene(meshFileToLoad); } else { openFileButton = new Button("Open 3D File", 0, 0); openFileButton.Click += openFileButton_ButtonClick; buttonPanel.AddChild(openFileButton); } bedCheckBox = new CheckBox("Bed"); bedCheckBox.Checked = true; buttonPanel.AddChild(bedCheckBox); wireframeCheckBox = new CheckBox("Wireframe"); buttonPanel.AddChild(wireframeCheckBox); GuiWidget leftRightSpacer = new GuiWidget(); leftRightSpacer.HAnchor = HAnchor.Stretch; buttonPanel.AddChild(leftRightSpacer); mainContainer.AddChild(buttonPanel); this.AddChild(mainContainer); this.AnchorAll(); AddHandlers(); }
public CSGOpenGLApplication(string meshFileToLoad = "") : base(800, 600) { MinimumSize = new VectorMath.Vector2(200, 200); Title = "MatterHackers MeshViewr"; UseOpenGL = true; StencilBufferDepth = 8; BitDepth = ValidDepthVaules.Depth24; FlowLayoutWidget mainContainer = new FlowLayoutWidget(FlowDirection.TopToBottom); mainContainer.AnchorAll(); viewArea = new GuiWidget(); viewArea.AnchorAll(); double bedXSize = 200; double bedYSize = 200; double scale = 1; meshViewerWidget = new MeshViewerWidget(bedXSize, bedYSize, scale); MeshViewWidget.AnchorAll(); viewArea.AddChild(MeshViewWidget); mainContainer.AddChild(viewArea); FlowLayoutWidget buttonPanel = new FlowLayoutWidget(FlowDirection.LeftToRight); buttonPanel.HAnchor = HAnchor.ParentLeftRight; buttonPanel.Padding = new BorderDouble(3, 3); buttonPanel.BackgroundColor = RGBA_Bytes.DarkGray; if (meshFileToLoad != "") { MeshViewWidget.LoadMesh(meshFileToLoad); } else { openFileButton = new Button("Open 3D File", 0, 0); openFileButton.Click += new Button.ButtonEventHandler(openFileButton_ButtonClick); buttonPanel.AddChild(openFileButton); } bedCheckBox = new CheckBox("Bed"); bedCheckBox.Checked = true; buttonPanel.AddChild(bedCheckBox); wireframeCheckBox = new CheckBox("Wireframe"); buttonPanel.AddChild(wireframeCheckBox); GuiWidget leftRightSpacer = new GuiWidget(); leftRightSpacer.HAnchor = HAnchor.ParentLeftRight; buttonPanel.AddChild(leftRightSpacer); mainContainer.AddChild(buttonPanel); this.AddChild(mainContainer); this.AnchorAll(); bedCheckBox.CheckedStateChanged += new CheckBox.CheckedStateChangedEventHandler(bedCheckBox_CheckedStateChanged); wireframeCheckBox.CheckedStateChanged += new CheckBox.CheckedStateChangedEventHandler(wireframeCheckBox_CheckedStateChanged); }
/// <summary> /// Creates or connects a PlatformWindow to the given SystemWindow /// </summary> public void ShowSystemWindow(SystemWindow systemWindow) { if (_graphicsDevice == null) { WindowCreateInfo windowCI = new WindowCreateInfo() { X = 100, Y = 100, WindowWidth = 960, WindowHeight = 540, WindowTitle = "Veldrid Tutorial", }; Sdl2Window window = VeldridStartup.CreateWindow(ref windowCI); veldridPlatformWindow = new VeldridSystemWindow(this); systemWindow.PlatformWindow = veldridPlatformWindow; _graphicsDevice = VeldridStartup.CreateGraphicsDevice(window, GraphicsBackend.OpenGL); window.KeyDown += (KeyEvent keyEvent) => { systemWindow.OnKeyDown( new KeyEventArgs((Keys)keyEvent.Key)); }; window.KeyUp += (KeyEvent keyEvent) => { systemWindow.OnKeyUp( new KeyEventArgs((Keys)keyEvent.Key)); }; // setup our veldrid gl immediate mode emulator var veldridGl = new VeldridGL(); MatterHackers.RenderOpenGl.OpenGl.GL.Instance = veldridGl; veldridGl.CreateResources(_graphicsDevice); ShaderData.Instance.CreateResources(_graphicsDevice); long runNextMs = 0; VectorMath.Vector2 lastPosition = VectorMath.Vector2.Zero; while (window.Exists) { InputSnapshot inputSnapshot = window.PumpEvents(); var position = new VectorMath.Vector2(inputSnapshot.MousePosition.X, window.Height - inputSnapshot.MousePosition.Y); if (lastPosition != position) { systemWindow.OnMouseMove(new MouseEventArgs(MouseButtons.None, 0, position.X, position.Y, 0)); } if (inputSnapshot.WheelDelta != 0) { systemWindow.OnMouseWheel(new MouseEventArgs(MouseButtons.None, 0, position.X, position.Y, (int)inputSnapshot.WheelDelta * 120)); } if (runNextMs <= UiThread.CurrentTimerMs) { UiThread.InvokePendingActions(); runNextMs = UiThread.CurrentTimerMs + 10; } foreach (var mouseEvent in inputSnapshot.MouseEvents) { MouseButtons buttons = MapMouseButtons(mouseEvent.MouseButton); if (inputSnapshot.IsMouseDown(mouseEvent.MouseButton)) { systemWindow.OnMouseDown(new MouseEventArgs(buttons, 1, position.X, position.Y, 0)); } else { systemWindow.OnMouseUp(new MouseEventArgs(buttons, 0, position.X, position.Y, 0)); } } systemWindow.Width = veldridPlatformWindow.Width = window.Width; systemWindow.Height = veldridPlatformWindow.Height = window.Height; var graphics2D = veldridPlatformWindow.NewGraphics2D(); // We must call on draw background as this is effectively our child and that is the way it is done in GuiWidget. // Parents call child OnDrawBackground before they call OnDraw systemWindow.OnDrawBackground(graphics2D); systemWindow.OnDraw(graphics2D); _graphicsDevice.SwapBuffers(); // Copy to screen/backbuffer //window.PumpEvents(); } // MyOpenGLView.RootGLView.ShowSystemWindow(systemWindow); veldridGl.DisposeResources(); ShaderData.Instance.DisposeResources(); } MouseButtons MapMouseButtons(MouseButton mouseButton) { switch (mouseButton) { case MouseButton.Left: return(MouseButtons.Left); case MouseButton.Middle: break; case MouseButton.Right: break; case MouseButton.Button1: break; case MouseButton.Button2: break; case MouseButton.Button3: break; case MouseButton.Button4: break; case MouseButton.Button5: break; case MouseButton.Button6: break; case MouseButton.Button7: break; case MouseButton.Button8: break; case MouseButton.Button9: break; case MouseButton.LastButton: break; } return(MouseButtons.None); } }
public override bool GetOriginAndHeightForChild(GuiWidget parent, GuiWidget child, out Vector2 newOriginRelParent, out double newHeight) { bool needToAdjustAnything = false; newOriginRelParent = child.OriginRelativeParent; newHeight = child.Height; if (!parent.Children.Contains(child)) { throw new Exception("You need to call this on the parent that has this child."); } if ((child.VAnchor & VAnchor.ParentBottom) == VAnchor.ParentBottom) { // hold it to the Bottom newOriginRelParent = new Vector2(child.OriginRelativeParent.x, parent.LocalBounds.Bottom + child.Margin.Bottom + parent.Padding.Bottom - child.LocalBounds.Bottom); if ((child.VAnchor & VAnchor.ParentCenter) == VAnchor.ParentCenter) { // widen the bounds to the center double parentUsableHeight = parent.LocalBounds.Height - (parent.Padding.Top + parent.Padding.Bottom); newHeight = parentUsableHeight / 2 - child.Margin.Height; } else if ((child.VAnchor & VAnchor.ParentTop) == VAnchor.ParentTop) { // bounds need to be stretched double parentUsableHeight = parent.LocalBounds.Height - (parent.Padding.Bottom + parent.Padding.Top); newHeight = parentUsableHeight - (child.Margin.Bottom + child.Margin.Top); } needToAdjustAnything = true; } else if ((child.VAnchor & VAnchor.ParentCenter) == VAnchor.ParentCenter) { if ((child.VAnchor & VAnchor.ParentTop) == VAnchor.ParentTop) { // fix the offset newOriginRelParent = new VectorMath.Vector2(child.OriginRelativeParent.x, parent.Padding.Bottom + child.Margin.Bottom + (parent.Height - parent.Padding.Bottom - parent.Padding.Top) / 2); // bounds need to be stretched double parentUsableHeight = parent.LocalBounds.Height - (parent.Padding.Top + parent.Padding.Bottom); newHeight = parentUsableHeight / 2 - child.Margin.Height; } else { // hold it centered double parentCenterY = parent.LocalBounds.Bottom + parent.Padding.Bottom + (parent.Height - parent.Padding.Bottom - parent.Padding.Top) / 2; double originY = parentCenterY - child.LocalBounds.Bottom - (child.Height + child.Margin.Bottom + child.Margin.Top) / 2 + child.Margin.Bottom; newOriginRelParent = new Vector2(child.OriginRelativeParent.x, originY); } needToAdjustAnything = true; } else if ((child.VAnchor & VAnchor.ParentTop) == VAnchor.ParentTop) { // hold it to the Top newOriginRelParent = new Vector2(child.OriginRelativeParent.x, parent.LocalBounds.Top - child.Margin.Top - parent.Padding.Top - child.LocalBounds.Top); needToAdjustAnything = true; } return needToAdjustAnything; }
public override (bool adjustOrigin, bool adjustHeight) GetOriginAndHeightForChild(GuiWidget parent, GuiWidget child, out Vector2 newOriginRelParent, out double newHeight) { bool needToAdjustHeight = false; bool needToAdjustOrigin = false; newOriginRelParent = child.OriginRelativeParent; newHeight = child.Height; if (!parent.Children.Contains(child)) { throw new Exception("You need to call this on the parent that has this child."); } if ((child.VAnchor & VAnchor.Bottom) == VAnchor.Bottom) { // hold it to the Bottom newOriginRelParent = new Vector2(child.OriginRelativeParent.X, parent.LocalBounds.Bottom + child.DeviceMarginAndBorder.Bottom + parent.DevicePadding.Bottom - child.LocalBounds.Bottom); needToAdjustOrigin = true; if ((child.VAnchor & VAnchor.Center) == VAnchor.Center) { // widen the bounds to the center double parentUsableHeight = parent.LocalBounds.Height - (parent.DevicePadding.Top + parent.DevicePadding.Bottom); newHeight = parentUsableHeight / 2 - child.DeviceMarginAndBorder.Height; needToAdjustHeight = true; } else if ((child.VAnchor & VAnchor.Top) == VAnchor.Top) { // bounds need to be stretched double parentUsableHeight = parent.LocalBounds.Height - (parent.DevicePadding.Bottom + parent.DevicePadding.Top); newHeight = parentUsableHeight - (child.DeviceMarginAndBorder.Bottom + child.DeviceMarginAndBorder.Top); needToAdjustHeight = true; } } else if ((child.VAnchor & VAnchor.Center) == VAnchor.Center) { if ((child.VAnchor & VAnchor.Top) == VAnchor.Top) { // fix the offset newOriginRelParent = new VectorMath.Vector2(child.OriginRelativeParent.X, parent.DevicePadding.Bottom + child.DeviceMarginAndBorder.Bottom + (parent.Height - parent.DevicePadding.Bottom - parent.DevicePadding.Top) / 2); // bounds need to be stretched double parentUsableHeight = parent.LocalBounds.Height - (parent.DevicePadding.Top + parent.DevicePadding.Bottom); newHeight = parentUsableHeight / 2 - child.DeviceMarginAndBorder.Height; needToAdjustHeight = true; } else { // hold it centered double parentCenterY = parent.LocalBounds.Bottom + parent.DevicePadding.Bottom + (parent.Height - parent.DevicePadding.Bottom - parent.DevicePadding.Top) / 2; double originY = parentCenterY - child.LocalBounds.Bottom - (child.Height + child.DeviceMarginAndBorder.Bottom + child.DeviceMarginAndBorder.Top) / 2 + child.DeviceMarginAndBorder.Bottom; newOriginRelParent = new Vector2(child.OriginRelativeParent.X, originY); needToAdjustOrigin = true; } } else if ((child.VAnchor & VAnchor.Top) == VAnchor.Top) { // hold it to the Top newOriginRelParent = new Vector2(child.OriginRelativeParent.X, parent.LocalBounds.Top - child.DeviceMarginAndBorder.Top - parent.DevicePadding.Top - child.LocalBounds.Top); needToAdjustOrigin = true; } return(needToAdjustOrigin, needToAdjustHeight); }
public void MakeVxs(VertexStoreSnap vsnap, VertexStore vxs) { m_curve3.Reset(); m_curve4.Reset(); var snapIter = vsnap.GetVertexSnapIter(); CurvePointMode latestCurveMode = CurvePointMode.NotCurve; double x, y; VertexCmd cmd; VectorMath.Vector2 c3p2 = new VectorMath.Vector2(); VectorMath.Vector2 c4p2 = new VectorMath.Vector2(); VectorMath.Vector2 c4p3 = new VectorMath.Vector2(); double lastX = 0; double lasty = 0; double lastMoveX = 0; double lastMoveY = 0; do { //this vertex cmd = snapIter.GetNextVertex(out x, out y); #if DEBUG if (VertexStore.dbugCheckNANs(x, y)) { int dbugIter = snapIter.dbugIterIndex; } //if (VertexStore.dbugCheckIfNAN(x, y)) //{ // //} #endif switch (cmd) { case VertexCmd.P2c: { switch (latestCurveMode) { case CurvePointMode.P2: { } break; case CurvePointMode.P3: { } break; case CurvePointMode.NotCurve: { c3p2.x = x; c3p2.y = y; } break; default: { } break; } latestCurveMode = CurvePointMode.P2; } break; case VertexCmd.P3c: { //this is p3c switch (latestCurveMode) { case CurvePointMode.P2: { c3p2.x = x; c3p2.y = y; } break; case CurvePointMode.P3: { c4p3.x = x; c4p3.y = y; } break; case CurvePointMode.NotCurve: { c4p2.x = x; c4p2.y = y; } break; } latestCurveMode = CurvePointMode.P3; } break; case VertexCmd.LineTo: { switch (latestCurveMode) { case CurvePointMode.P2: { m_curve3.MakeLines(vxs, lastX, lasty, c3p2.X, c3p2.Y, x, y); } break; case CurvePointMode.P3: { m_curve4.MakeLines(vxs, lastX, lasty, c4p2.x, c4p2.y, c4p3.x, c4p3.y, x, y); } break; default: { vxs.AddVertex(x, y, cmd); } break; } //----------- latestCurveMode = CurvePointMode.NotCurve; lastX = x; lasty = y; //----------- } break; case VertexCmd.MoveTo: { //move to, and end command vxs.AddVertex(x, y, cmd); //----------- latestCurveMode = CurvePointMode.NotCurve; lastMoveX = lastX = x; lastMoveY = lasty = y; //----------- } break; case VertexCmd.Close: case VertexCmd.CloseAndEndFigure: { latestCurveMode = CurvePointMode.NotCurve; vxs.AddVertex(x, y, cmd); //move to begin lastX = lastMoveX; lasty = lastMoveY; } break; default: { //move to, and end command vxs.AddVertex(x, y, cmd); //----------- latestCurveMode = CurvePointMode.NotCurve; lastX = x; lasty = y; //----------- } break; } } while (cmd != VertexCmd.NoMore); }
public VertexStore MakeVxs(VertexStore vxs, ICoordTransformer tx, VertexStore output) { _curve3.Reset(); _curve4.Reset(); CurvePointMode latestCurveMode = CurvePointMode.NotCurve; double x, y; VertexCmd cmd; VectorMath.Vector2 c3p2 = new VectorMath.Vector2(); VectorMath.Vector2 c4p2 = new VectorMath.Vector2(); VectorMath.Vector2 c4p3 = new VectorMath.Vector2(); double lastX = 0; double lasty = 0; double lastMoveX = 0; double lastMoveY = 0; int index = 0; bool hasTx = tx != null; while ((cmd = vxs.GetVertex(index++, out x, out y)) != VertexCmd.NoMore) { #if DEBUG if (VertexStore.dbugCheckNANs(x, y)) { } #endif //----------------- if (hasTx) { tx.Transform(ref x, ref y); } //----------------- switch (cmd) { case VertexCmd.C3: { switch (latestCurveMode) { case CurvePointMode.P2: { } break; case CurvePointMode.P3: { } break; case CurvePointMode.NotCurve: { c3p2.x = x; c3p2.y = y; } break; default: { } break; } latestCurveMode = CurvePointMode.P2; } break; case VertexCmd.C4: { //this is p3c switch (latestCurveMode) { case CurvePointMode.P2: { c3p2.x = x; c3p2.y = y; } break; case CurvePointMode.P3: { c4p3.x = x; c4p3.y = y; } break; case CurvePointMode.NotCurve: { c4p2.x = x; c4p2.y = y; } break; } latestCurveMode = CurvePointMode.P3; } break; case VertexCmd.LineTo: { switch (latestCurveMode) { case CurvePointMode.P2: { _curve3.MakeLines(output, lastX, lasty, c3p2.X, c3p2.Y, x, y); } break; case CurvePointMode.P3: { _curve4.MakeLines(output, lastX, lasty, c4p2.x, c4p2.y, c4p3.x, c4p3.y, x, y); } break; default: { output.AddVertex(x, y, cmd); } break; } //----------- latestCurveMode = CurvePointMode.NotCurve; lastX = x; lasty = y; //----------- } break; case VertexCmd.MoveTo: { //move to, and end command output.AddVertex(x, y, cmd); //----------- latestCurveMode = CurvePointMode.NotCurve; lastMoveX = lastX = x; lastMoveY = lasty = y; //----------- } break; case VertexCmd.Close: case VertexCmd.CloseAndEndFigure: { latestCurveMode = CurvePointMode.NotCurve; output.AddVertex(lastMoveX, lastMoveY, cmd); //move to begin lastX = lastMoveX; lasty = lastMoveY; } break; default: { //move to, and end command output.AddVertex(x, y, cmd); //----------- latestCurveMode = CurvePointMode.NotCurve; lastX = x; lasty = y; //----------- } break; } } return(output); }
public override bool GetOriginAndWidthForChild(GuiWidget parent, GuiWidget child, out Vector2 newOriginRelParent, out double newWidth) { bool needToAdjustAnything = false; newOriginRelParent = child.OriginRelativeParent; newWidth = child.Width; if ((child.HAnchor & HAnchor.ParentLeft) == HAnchor.ParentLeft) { // Hold it to the left newOriginRelParent = new Vector2(parent.LocalBounds.Left + child.Margin.Left + parent.Padding.Left - child.LocalBounds.Left, child.OriginRelativeParent.y); if ((child.HAnchor & HAnchor.ParentCenter) == HAnchor.ParentCenter) { // widen the bounds to the center double parentUsableWidth = parent.LocalBounds.Width - (parent.Padding.Left + parent.Padding.Right); newWidth = parentUsableWidth / 2 - (child.Margin.Left + child.Margin.Right); } else if ((child.HAnchor & HAnchor.ParentRight) == HAnchor.ParentRight) { // widen the bounds to the right double parentUsableWidth = parent.LocalBounds.Width - (parent.Padding.Left + parent.Padding.Right); newWidth = parentUsableWidth - (child.Margin.Left + child.Margin.Right); } needToAdjustAnything = true; } else if ((child.HAnchor & HAnchor.ParentCenter) == HAnchor.ParentCenter) { if ((child.HAnchor & HAnchor.ParentRight) == HAnchor.ParentRight) { // fix the offset newOriginRelParent = new VectorMath.Vector2( parent.Padding.Left + child.Margin.Left + (parent.Width - parent.Padding.Left - parent.Padding.Right) / 2, child.OriginRelativeParent.y); // widen the bounds to the right double parentUsableWidth = parent.LocalBounds.Width - (parent.Padding.Left + parent.Padding.Right); newWidth = parentUsableWidth / 2 - (child.Margin.Left + child.Margin.Right); } else { // hold it centered double parentCenterX = parent.LocalBounds.Left + parent.Padding.Left + (parent.Width - (parent.Padding.Left + parent.Padding.Right)) / 2; double originX = parentCenterX - child.LocalBounds.Left - (child.Width + child.Margin.Left + child.Margin.Right) / 2 + child.Margin.Left; newOriginRelParent = new Vector2(originX, child.OriginRelativeParent.y); } needToAdjustAnything = true; } else if ((child.HAnchor & HAnchor.ParentRight) == HAnchor.ParentRight) { // hold it to the right newOriginRelParent = new Vector2(parent.LocalBounds.Right - child.Margin.Right - parent.Padding.Right - child.LocalBounds.Right, child.OriginRelativeParent.y); needToAdjustAnything = true; } return needToAdjustAnything; }
public void MakeVxs(VertexStoreSnap vsnap, VertexStore vxs) { m_curve3.Reset(); m_curve4.Reset(); var snapIter = vsnap.GetVertexSnapIter(); CurvePointMode latestCurveMode = CurvePointMode.NotCurve; double x, y; VertexCmd cmd; VectorMath.Vector2 c3p2 = new VectorMath.Vector2(); VectorMath.Vector2 c4p2 = new VectorMath.Vector2(); VectorMath.Vector2 c4p3 = new VectorMath.Vector2(); double lastX = 0; double lasty = 0; double lastMoveX = 0; double lastMoveY = 0; do { //this vertex cmd = snapIter.GetNextVertex(out x, out y); switch (cmd) { case VertexCmd.P2c: { switch (latestCurveMode) { case CurvePointMode.P2: { } break; case CurvePointMode.P3: { } break; case CurvePointMode.NotCurve: { c3p2.x = x; c3p2.y = y; } break; default: { } break; } latestCurveMode = CurvePointMode.P2; } break; case VertexCmd.P3c: { //this is p3c switch (latestCurveMode) { case CurvePointMode.P2: { c3p2.x = x; c3p2.y = y; } break; case CurvePointMode.P3: { // vxs.AddVertex(x, y, cmd); c4p3.x = x; c4p3.y = y; //m_curve4.MakeLines(vxs, // lastX, lasty, // c3p2.X, c3p2.Y, // c4p2.x, c4p2.y, // x, y); // vxs.AddVertex(x, y, cmd); } break; case CurvePointMode.NotCurve: { c4p2.x = x; c4p2.y = y; } break; } latestCurveMode = CurvePointMode.P3; } break; case VertexCmd.LineTo: { switch (latestCurveMode) { case CurvePointMode.P2: { m_curve3.MakeLines(vxs, lastX, lasty, c3p2.X, c3p2.Y, x, y); } break; case CurvePointMode.P3: { //from curve4 // vxs.AddVertex(x, y, cmd); m_curve4.MakeLines(vxs, lastX, lasty, c4p2.x, c4p2.y, c4p3.x, c4p3.y, x, y); } break; default: { vxs.AddVertex(x, y, cmd); } break; } //----------- latestCurveMode = CurvePointMode.NotCurve; lastX = x; lasty = y; //----------- } break; case VertexCmd.MoveTo: { //move to, and end command vxs.AddVertex(x, y, cmd); //----------- latestCurveMode = CurvePointMode.NotCurve; lastMoveX = lastX = x; lastMoveY = lasty = y; //----------- } break; case VertexCmd.CloseAndEndFigure: { latestCurveMode = CurvePointMode.NotCurve; vxs.AddVertex(x, y, cmd); //move to begin lastX = lastMoveX; lasty = lastMoveY; } break; case VertexCmd.EndFigure: { latestCurveMode = CurvePointMode.NotCurve; vxs.AddVertex(x, y, cmd); } break; default: { //move to, and end command vxs.AddVertex(x, y, cmd); //----------- latestCurveMode = CurvePointMode.NotCurve; lastX = x; lasty = y; //----------- } break; } } while (cmd != VertexCmd.Stop); }