protected void DoViewChangeTasks(bool updateScrollBars = true) { updatingControls = true; try { if (view != null) { lblZoom.Text = ((int)(view.Zoom * 100.0)).ToString() + "%"; if (updateScrollBars) { double xOff = 0; // (view.WorldSpaceBounds.X * view.Zoom); double yOff = 0; //(view.WorldSpaceBounds.Y * view.Zoom); int newVScroll = -(int)(view.TransformY - xOff); int newHScroll = -(int)(view.TransformX - yOff); //these 2 lines are to enable a infinite scolling, which may be bad. adjustRangeToSuite(scrlVert, newVScroll); adjustRangeToSuite(scrlHoriz, newHScroll); scrlVert.Value = newVScroll; scrlHoriz.Value = newHScroll; } if (view is IEditableView2D) { IEditableView2D ev = view as IEditableView2D; //resend the mouse pos. //The mouse did not move on the screen, but the view window is different MouseEventArgs arg = new MouseEventArgs(System.Windows.Forms.MouseButtons.None, 0, ((Control)picMain).PointToClient(Cursor.Position).X, ((Control)picMain).PointToClient(Cursor.Position).Y, 0); ev.DoMouseMove_ScreenSpace(this, arg); } if (onViewChange != null) { onViewChange(view); } } } catch (Exception ex) { WDAppLog.logException(ErrorLevel.SmallError, ex); } updatingControls = false; }
private void picMain_Paint(object sender, PaintEventArgs e) { if (view != null) { try { GDIPlusRenderer r = new GDIPlusRenderer(e.Graphics); r.Clear(this.BackColor); view.Render(r); if (view is IEditableView2D) { IEditableView2D ev = view as IEditableView2D; ev.RenderGizmoLayer(r); } r.Close(); } catch (Exception ex) { e.Graphics.DrawString(ex.GetADecentExplination(), this.Font, Brushes.Red, 20, 20); e.Graphics.DrawString(ex.StackTrace.ToString().Wrap(40), this.Font, Brushes.Red, 20, 50); WDAppLog.logException(ErrorLevel.Error, ex); } } }
public void RenderGizmoLayer(IRenderer r, IView2D view, DistanceGridRenderLayer layers) { double XGapScreenSpace; double YGapScreenSpace; getScreenSpaceGridGap(view, XGapWorldSpace, YGapWorldSpace, out XGapScreenSpace, out YGapScreenSpace); //Determine worldspace location of the screen Rectangle2D viewRec = view.ScreenSpaceBounds; List <Point2D> viewArea = new List <Point2D>() { viewRec.TopLeft, viewRec.TopRight, viewRec.LowerLeft, viewRec.LowerRight }; viewArea = view.ScreenToWorldTransformMatrix.Transform(viewArea); //Iteration bounds int xStart = (int)(Math.Floor(viewArea[0].X / XGapWorldSpace)); int yStart = (int)(Math.Floor(viewArea[0].Y / YGapWorldSpace)); int xEnd = (int)(Math.Ceiling(viewArea[3].X / XGapWorldSpace)); int yEnd = (int)(Math.Ceiling(viewArea[3].Y / YGapWorldSpace)); int xSteps = xEnd - xStart; int ySteps = yEnd - yStart; //Setup avis of screen in world space Point2D xAxis = (viewArea[1] - viewArea[0]); Point2D yAxis = (viewArea[2] - viewArea[0]); Point2D xAxisDir = xAxis.UnitVector(); Point2D yAxisDir = yAxis.UnitVector(); Point2D GridOrigin = (xStart * xAxis) + (yStart * yAxis); //draw the grid Point2D a; Point2D b; int NumberOfGridLinesThreshold = (int)(Math.Min(viewRec.Width, viewRec.Height) / 2); bool gridRenderIsSensible = ((xSteps <= NumberOfGridLinesThreshold) && (ySteps <= NumberOfGridLinesThreshold)); //lines if (ShowGridLines && ((layers & DistanceGridRenderLayer.Grid) != 0)) { if (gridRenderIsSensible) { for (int y = yStart; y < yEnd; y++) { getScreenPosForGridLineY(view, YGapWorldSpace, viewArea, ref xAxis, ref yAxisDir, y, out a, out b); r.DrawLine(gridColor, 1, a, b); } for (int x = xStart; x < xEnd; x++) { getScreenPosForGridLineX(view, XGapWorldSpace, viewArea, ref yAxis, ref xAxisDir, x, out a, out b); r.DrawLine(gridColor, 1, a, b); } } } //rulers if ((layers & DistanceGridRenderLayer.Ruler) != 0) { Rectangle ssb = view.ScreenSpaceBounds; int gutterSizeTop = 20; int gutterSizeLeft = 40; //------------ LEFT GUTTER r.FillRectangle(Color.White, ssb.Left, ssb.Top + gutterSizeTop, gutterSizeLeft, ssb.Height - gutterSizeTop); r.DrawRectangle(Color.Black, 1, ssb.Left, ssb.Top + gutterSizeTop, gutterSizeLeft, ssb.Height - gutterSizeTop); //int pixelsSinceLastStringThreshold = 10; //int pixelPosOfLastString = 0; //int labelMod = (int)(Math.Max(YGapScreenSpace, 1)) / 5; //labelMod = Math.Max(labelMod, 1); int labelMod = 1; int textDistanceInPixels = 15; while ((YGapScreenSpace * labelMod) < MaxSeenLabelSize.Height) //12 { //labelMod *= 10; labelMod *= UnitMode.UsesFractions ? 2 : 10; } for (int y = yStart; y < yEnd; y++) { getScreenPosForGridLineY(view, YGapWorldSpace, viewArea, ref xAxis, ref yAxisDir, y, out a, out b); double distMesure = (y * YGapWorldSpace) / YWorldSpaceResolution.DotsPerMetre; if ((y % labelMod) == 0) { r.DrawLine(Color.Black, 1, (int)gutterSizeLeft - 15, (int)a.Y, (int)gutterSizeLeft, (int)a.Y); if (a.Y > (gutterSizeTop + 5)) { bool isMinor; Point2D TextOffset; string rulertext = getRulerText(r, distMesure, out isMinor, out TextOffset, true); r.DrawString(isMinor ? fmtMinor : fmtMajor, rulertext, (a + TextOffset).AsPoint()); } } else { r.DrawLine(Color.Black, 1, (int)gutterSizeLeft - 5, (int)a.Y, (int)gutterSizeLeft, (int)a.Y); } } //------------ TOP GUTTER //fmt.printVertical = true; labelMod = 1; textDistanceInPixels = UnitMode.UsesFractions ? 120 : 60; while ((XGapScreenSpace * labelMod) < MaxSeenLabelSize.Width) //30 { //labelMod *= (UnitMode.LastUnitModulus <= 1) ? 10 : UnitMode.LastUnitModulus; labelMod *= UnitMode.UsesFractions ? 2 : 10; } r.FillRectangle(Color.White, ssb.Left, ssb.Top, ssb.Width, gutterSizeTop); r.DrawRectangle(Color.Black, 1, ssb.Left, ssb.Top, ssb.Width, gutterSizeTop); for (int x = xStart; x < xEnd; x++) { getScreenPosForGridLineX(view, XGapWorldSpace, viewArea, ref yAxis, ref xAxisDir, x, out a, out b); double distMesure = (x * XGapWorldSpace) / XWorldSpaceResolution.DotsPerMetre; if ((x % labelMod) == 0) //labelMod = 5 { r.DrawLine(Color.Black, 1, (int)a.X, (int)gutterSizeTop - 10, (int)a.X, (int)gutterSizeTop); //if (gridRenderIsSensible) { /* * string rulertext = UnitMode.GetDistanceString(Distance.FromMetres(distMesure), "?"); * bool isMinor = rulertext.StartsWith("?"); * rulertext = rulertext.TrimStart("?".ToCharArray()); * * //Point2D TextOffset = new Point2D(-12, 2); * Point2D TextOffset = new Point2D(-(r.MeasureString(rulertext, fmt.font).Width / 2), 2); * * r.DrawString(isMinor ? fmtMinor : fmt, rulertext, (a + TextOffset).AsPoint());*/ bool isMinor; Point2D TextOffset; string rulertext = getRulerText(r, distMesure, out isMinor, out TextOffset, false); r.DrawString(isMinor ? fmtMinor : fmtMajor, rulertext, (a + TextOffset).AsPoint()); } } else { r.DrawLine(Color.Black, 1, (int)a.X, (int)gutterSizeTop - 3, (int)a.X, (int)gutterSizeTop); } } //draw mouse location marker IEditableView2D ev = view as IEditableView2D; if (ev != null) { Point2D pos = view.WorldToScreenTransformMatrix.Transform(ev.MousePosInWorldSpace); //top r.DrawLine(Color.Red, 1, (int)pos.X, (int)gutterSizeTop - 15, (int)pos.X, (int)gutterSizeTop); //left if (pos.Y > gutterSizeTop) { r.DrawLine(Color.Red, 1, (int)gutterSizeLeft - 10, (int)pos.Y, (int)gutterSizeLeft, (int)pos.Y); } } } }