// checking the boundary of zoom rectangle - if it is two small then, it will be not visible private void CheckZoomRectangleBoundary() { // computing the screen coordinates ScreenPlaneCoordinatesTransfornation tempTransformation = new ScreenPlaneCoordinatesTransfornation(FractalImage.Width, FractalImage.Height, myFractalObserverConfiguration.CurrentRectangle); Point aStartPoint = tempTransformation.GetScreenCoordinates(myFractalObserverConfiguration.ZoomRectangle.MinX, myFractalObserverConfiguration.ZoomRectangle.MinY); Point aEndPoint = tempTransformation.GetScreenCoordinates(myFractalObserverConfiguration.ZoomRectangle.MaxX, myFractalObserverConfiguration.ZoomRectangle.MaxY); // not allowing to draw the zooming rectangle if it is outside of scope(outside of current rectangle), or if it is too small. if (myFractalObserverConfiguration.ZoomRectangle.MinX < myFractalObserverConfiguration.CurrentRectangle.MinX) { myShowZoomRectangleAndAllowModification = false; } else if (myFractalObserverConfiguration.ZoomRectangle.MinY < myFractalObserverConfiguration.CurrentRectangle.MinY) { myShowZoomRectangleAndAllowModification = false; } else if (myFractalObserverConfiguration.ZoomRectangle.MaxX > myFractalObserverConfiguration.CurrentRectangle.MaxX) { myShowZoomRectangleAndAllowModification = false; } else if (Math.Abs(aStartPoint.X - aEndPoint.X) < myLowerSizeLimitForZoomRectangle) { myShowZoomRectangleAndAllowModification = false; } else if (Math.Abs(aStartPoint.Y - aEndPoint.Y) < myLowerSizeLimitForZoomRectangle) { myShowZoomRectangleAndAllowModification = false; } else { myShowZoomRectangleAndAllowModification = true; } }
private void FractalImage_MouseMove(object sender, MouseEventArgs e) { ScreenPlaneCoordinatesTransfornation tempTransformation = new ScreenPlaneCoordinatesTransfornation(FractalImage.Width, FractalImage.Height, myFractalObserverConfiguration.CurrentRectangle); Point aCurrentMouseLocation = e.Location; if (showZoomRectangleToolStripMenuItem.Checked == true && myShowZoomRectangleAndAllowModification) { // Getting the screen coordinates of zoom rectangle Point aStartPoint = tempTransformation.GetScreenCoordinates(myFractalObserverConfiguration.ZoomRectangle.StartX, myFractalObserverConfiguration.ZoomRectangle.StartY); Point aEndPoint = tempTransformation.GetScreenCoordinates(myFractalObserverConfiguration.ZoomRectangle.EndX, myFractalObserverConfiguration.ZoomRectangle.EndY); bool aModifyRectangle = false; // finding out if the current mouse pointer position is near or in the zoom rectangle, if yes - then change the mouse pointer shape if (!myMouseIsDown) { if (Math.Abs(aCurrentMouseLocation.X - aStartPoint.X) < myLimitForZoomRectangleChange && aCurrentMouseLocation.Y > Math.Min(aStartPoint.Y, aEndPoint.Y) && aCurrentMouseLocation.Y < Math.Max(aStartPoint.Y, aEndPoint.Y)) { myCurrentZoomRectangleOperation = ZoomingRectangleOperations.LeftSizing; this.Cursor = Cursors.SizeWE; } else if (Math.Abs(aCurrentMouseLocation.X - aEndPoint.X) < myLimitForZoomRectangleChange && aCurrentMouseLocation.Y > Math.Min(aStartPoint.Y, aEndPoint.Y) && aCurrentMouseLocation.Y < Math.Max(aStartPoint.Y, aEndPoint.Y)) { myCurrentZoomRectangleOperation = ZoomingRectangleOperations.RightSizing; this.Cursor = Cursors.SizeWE; } else if (Math.Abs(aCurrentMouseLocation.Y - aStartPoint.Y) < myLimitForZoomRectangleChange && aCurrentMouseLocation.X > Math.Min(aStartPoint.X, aEndPoint.X) && aCurrentMouseLocation.X < Math.Max(aStartPoint.X, aEndPoint.X)) { myCurrentZoomRectangleOperation = ZoomingRectangleOperations.UpSizing; this.Cursor = Cursors.SizeNS; } else if (Math.Abs(aCurrentMouseLocation.Y - aEndPoint.Y) < myLimitForZoomRectangleChange && aCurrentMouseLocation.X > Math.Min(aStartPoint.X, aEndPoint.X) && aCurrentMouseLocation.X < Math.Max(aStartPoint.X, aEndPoint.X)) { myCurrentZoomRectangleOperation = ZoomingRectangleOperations.DownSizing; this.Cursor = Cursors.SizeNS; } else if (aCurrentMouseLocation.X > Math.Min(aStartPoint.X, aEndPoint.X) && aCurrentMouseLocation.X < Math.Max(aStartPoint.X, aEndPoint.X) && aCurrentMouseLocation.Y > Math.Min(aStartPoint.Y, aEndPoint.Y) && aCurrentMouseLocation.Y < Math.Max(aStartPoint.Y, aEndPoint.Y)) { myCurrentZoomRectangleOperation = ZoomingRectangleOperations.Panning; this.Cursor = Cursors.Hand; } else { myCurrentZoomRectangleOperation = ZoomingRectangleOperations.None; this.Cursor = Cursors.Default; } } // if mouse button is pressed and the mouse pointer is on the right area then zooming rectangle will be modified if (myMouseIsDown) { PointInPlane tempNewPoint = tempTransformation.GetPlaneCoordinates(aCurrentMouseLocation.X, aCurrentMouseLocation.Y); // corrections of new zooming rectangle, it cannot be set outside the current view area if (tempNewPoint.x <= myFractalObserverConfiguration.CurrentRectangle.MinX) { tempNewPoint.x = myFractalObserverConfiguration.CurrentRectangle.MinX; } if (tempNewPoint.y <= myFractalObserverConfiguration.CurrentRectangle.MinY) { tempNewPoint.y = myFractalObserverConfiguration.CurrentRectangle.MinY; } if (tempNewPoint.x >= myFractalObserverConfiguration.CurrentRectangle.MaxX) { tempNewPoint.x = myFractalObserverConfiguration.CurrentRectangle.MaxX; } if (tempNewPoint.y >= myFractalObserverConfiguration.CurrentRectangle.MaxY) { tempNewPoint.y = myFractalObserverConfiguration.CurrentRectangle.MaxY; } if (myCurrentZoomRectangleOperation == ZoomingRectangleOperations.LeftSizing) { // correction of zoom rectangle - it cannot be too small, then it is not allowed to further reduce its size if (Math.Abs(aEndPoint.X - aCurrentMouseLocation.X) < myLowerSizeLimitForZoomRectangle) { int aSign = Math.Sign(aEndPoint.X - aStartPoint.X); tempNewPoint.x = tempTransformation.GetPlaneCoordinates(aEndPoint.X - aSign * myLowerSizeLimitForZoomRectangle, aCurrentMouseLocation.Y).x; } myFractalObserverConfiguration.ZoomRectangle.StartX = tempNewPoint.x; aModifyRectangle = true; } else if (myCurrentZoomRectangleOperation == ZoomingRectangleOperations.RightSizing) { // correction of zoom rectangle - it cannot be too small, then it is not allowed to further reduce its size if (Math.Abs(aStartPoint.X - aCurrentMouseLocation.X) < myLowerSizeLimitForZoomRectangle) { int aSign = Math.Sign(aEndPoint.X - aStartPoint.X); tempNewPoint.x = tempTransformation.GetPlaneCoordinates(aStartPoint.X + aSign * myLowerSizeLimitForZoomRectangle, aCurrentMouseLocation.Y).x; } myFractalObserverConfiguration.ZoomRectangle.EndX = tempNewPoint.x; aModifyRectangle = true; } else if (myCurrentZoomRectangleOperation == ZoomingRectangleOperations.UpSizing) { // correction of zoom rectangle - it cannot be too small, then it is not allowed to further reduce its size if (Math.Abs(aEndPoint.Y - aCurrentMouseLocation.Y) < myLowerSizeLimitForZoomRectangle) { int aSign = Math.Sign(aEndPoint.Y - aStartPoint.Y); tempNewPoint.y = tempTransformation.GetPlaneCoordinates(aCurrentMouseLocation.X, aEndPoint.Y - aSign * myLowerSizeLimitForZoomRectangle).y; } myFractalObserverConfiguration.ZoomRectangle.StartY = tempNewPoint.y; aModifyRectangle = true; } else if (myCurrentZoomRectangleOperation == ZoomingRectangleOperations.DownSizing) { // correction of zoom rectangle - it cannot be too small, then it is not allowed to further reduce its size if (Math.Abs(aStartPoint.Y - aCurrentMouseLocation.Y) < myLowerSizeLimitForZoomRectangle) { int aSign = Math.Sign(aEndPoint.Y - aStartPoint.Y); tempNewPoint.y = tempTransformation.GetPlaneCoordinates(aCurrentMouseLocation.X, aStartPoint.Y - aSign * myLowerSizeLimitForZoomRectangle).y; } myFractalObserverConfiguration.ZoomRectangle.EndY = tempNewPoint.y; aModifyRectangle = true; } else if (myCurrentZoomRectangleOperation == ZoomingRectangleOperations.Panning) { // computing the new zooming rectangle coordinates if panning occured if (!myIsPanNow) { myStartingDifferenceForPan = tempNewPoint - myFractalObserverConfiguration.ZoomRectangle.StartPoint; myIsPanNow = true; } if (myIsPanNow) // if zoom rectangle is currenty in panning operation - then the following code is ran { double aRectangleWidth = myFractalObserverConfiguration.ZoomRectangle.Width; double aRectangleHeight = myFractalObserverConfiguration.ZoomRectangle.Height; myFractalObserverConfiguration.ZoomRectangle.StartX = tempNewPoint.x - myStartingDifferenceForPan.x; myFractalObserverConfiguration.ZoomRectangle.StartY = tempNewPoint.y - myStartingDifferenceForPan.y; myFractalObserverConfiguration.ZoomRectangle.EndX = myFractalObserverConfiguration.ZoomRectangle.StartX + aRectangleWidth; myFractalObserverConfiguration.ZoomRectangle.EndY = myFractalObserverConfiguration.ZoomRectangle.StartY + aRectangleHeight; // during panning the zoom rectangle cannot be moved outside of current view, the checks for this are following if (myFractalObserverConfiguration.ZoomRectangle.MinX < myFractalObserverConfiguration.CurrentRectangle.MinX) { myFractalObserverConfiguration.ZoomRectangle.MinX = myFractalObserverConfiguration.CurrentRectangle.MinX; myFractalObserverConfiguration.ZoomRectangle.MaxX = myFractalObserverConfiguration.ZoomRectangle.MinX + aRectangleWidth; } if (myFractalObserverConfiguration.ZoomRectangle.MaxX > myFractalObserverConfiguration.CurrentRectangle.MaxX) { myFractalObserverConfiguration.ZoomRectangle.MaxX = myFractalObserverConfiguration.CurrentRectangle.MaxX; myFractalObserverConfiguration.ZoomRectangle.MinX = myFractalObserverConfiguration.ZoomRectangle.MaxX - aRectangleWidth; } if (myFractalObserverConfiguration.ZoomRectangle.MinY < myFractalObserverConfiguration.CurrentRectangle.MinY) { myFractalObserverConfiguration.ZoomRectangle.MinY = myFractalObserverConfiguration.CurrentRectangle.MinY; myFractalObserverConfiguration.ZoomRectangle.MaxY = myFractalObserverConfiguration.ZoomRectangle.MinY + aRectangleHeight; } if (myFractalObserverConfiguration.ZoomRectangle.MaxY > myFractalObserverConfiguration.CurrentRectangle.MaxY) { myFractalObserverConfiguration.ZoomRectangle.MaxY = myFractalObserverConfiguration.CurrentRectangle.MaxY; myFractalObserverConfiguration.ZoomRectangle.MinY = myFractalObserverConfiguration.ZoomRectangle.MaxY - aRectangleHeight; } } aModifyRectangle = true; } // if zooming rectangle was modified and mouse button is pressed then modify the zoom rectangle if (aModifyRectangle) { // invalidation of screen (onpaint will be called on this area, and new zooming rectangle will be drawn) FractalImage.Invalidate(); FractalImage.Update(); } } } else { myCurrentZoomRectangleOperation = ZoomingRectangleOperations.None; this.Cursor = Cursors.Default; } // showing of current mouse position in plane coordinates in status bar PointInPlane tempMousePositionInPlane = tempTransformation.GetPlaneCoordinates(aCurrentMouseLocation.X, aCurrentMouseLocation.Y); tsStatusLabelMousePosition.Text = "Current Mouse Position : X = " + Convert.ToString(tempMousePositionInPlane.x, CultureInfo.CurrentCulture) + " Y= " + Convert.ToString(tempMousePositionInPlane.y, CultureInfo.CurrentCulture); }
private void FractalImage_Paint(object sender, PaintEventArgs e) { Graphics aGraphics = e.Graphics; // here are drawn fractals which contain vector data if (myComputedFractalValues != null) { if (myComputedFractalValues.IsVectorData() == true) { using (Brush aBrush = new SolidBrush(Color.FromArgb(myFractalObserverConfiguration.BackgroundColor.alpha, myFractalObserverConfiguration.BackgroundColor.red, myFractalObserverConfiguration.BackgroundColor.green, myFractalObserverConfiguration.BackgroundColor.blue))) { aGraphics.FillRectangle(aBrush, e.ClipRectangle); } } foreach (ComputedFractalValue aCFValue in myComputedFractalValues.GetComputedFractalValues()) { ScreenPlaneCoordinatesTransfornation tempSPCT = new ScreenPlaneCoordinatesTransfornation(FractalImage.Width, FractalImage.Height, myFractalObserverConfiguration.CurrentRectangle); List <Point> tempListOfScreenPoints = new List <Point>(); foreach (PointInPlane tempPointInPlane in aCFValue.GetComputedPlanePoints()) { // here for each fractal computed object are computed screen coordinates and next is check if the values are inside of screen Point tempPoint = tempSPCT.GetScreenCoordinates(tempPointInPlane.x, tempPointInPlane.y); if (tempPoint.X < 0) { tempPoint.X = 0; } else if (tempPoint.X > FractalImage.Width) { tempPoint.X = FractalImage.Width; } if (tempPoint.Y < 0) { tempPoint.Y = 0; } else if (tempPoint.Y > FractalImage.Height) { tempPoint.Y = FractalImage.Height; } tempListOfScreenPoints.Add(tempPoint); } if (tempListOfScreenPoints.Count > 0) { //drawing of fractal - for each computed object there is draw of object on screen switch (aCFValue.TypeOfShape) { case TypesOfShape.Lines: if (myComputedFractalValues.ShallFillInterior == false) { using (Pen aPen = new Pen(Color.FromArgb(aCFValue.ColorValue.alpha, aCFValue.ColorValue.red, aCFValue.ColorValue.green, aCFValue.ColorValue.blue), 1)) { aGraphics.DrawLines(aPen, tempListOfScreenPoints.ToArray()); } } else if (myComputedFractalValues.ShallFillInterior == true) { using (Brush aBrush = new SolidBrush(Color.FromArgb(aCFValue.ColorValue.alpha, aCFValue.ColorValue.red, aCFValue.ColorValue.green, aCFValue.ColorValue.blue))) { aGraphics.FillClosedCurve(aBrush, tempListOfScreenPoints.ToArray()); } } break; case TypesOfShape.Rectangle: using (Brush aBrush = new SolidBrush(Color.FromArgb(aCFValue.ColorValue.alpha, aCFValue.ColorValue.red, aCFValue.ColorValue.green, aCFValue.ColorValue.blue))) { aGraphics.FillPolygon(aBrush, tempListOfScreenPoints.ToArray()); } break; } } } } // drawing of overlay graphics - if grid should be shown, then it is drawn here if (showGridToolStripMenuItem.Checked == true) { Color aGridColor = Color.FromArgb(myFractalObserverConfiguration.GridColor.alpha, myFractalObserverConfiguration.GridColor.red, myFractalObserverConfiguration.GridColor.green, myFractalObserverConfiguration.GridColor.blue); using (Pen aPen = new Pen(aGridColor, 1)) { ScreenPlaneCoordinatesTransfornation tempTransformation = new ScreenPlaneCoordinatesTransfornation(FractalImage.Width, FractalImage.Height, myFractalObserverConfiguration.CurrentRectangle); IGeometryInPlane aGridInPlane = new GridInPlane(myFractalObserverConfiguration.CurrentRectangle, myFractalObserverConfiguration.HorizontalSpacing, myFractalObserverConfiguration.VerticalSpacing); foreach (LineInPlane tempLineInPlane in aGridInPlane.ReturnListOfInPlaneLines()) { Point aStartPoint = tempTransformation.GetScreenCoordinates(tempLineInPlane.begin.x, tempLineInPlane.begin.y); Point aEndPoint = tempTransformation.GetScreenCoordinates(tempLineInPlane.end.x, tempLineInPlane.end.y); aGraphics.DrawLine(aPen, aStartPoint, aEndPoint); } } } // drawing of overlay graphics - if zooming rectangle should be shown, then it is drawn here if (showZoomRectangleToolStripMenuItem.Checked == true && myShowZoomRectangleAndAllowModification) { Color aZoomInRectangleColor = Color.FromArgb(myFractalObserverConfiguration.ZoomRectangleColor.alpha, myFractalObserverConfiguration.ZoomRectangleColor.red, myFractalObserverConfiguration.ZoomRectangleColor.green, myFractalObserverConfiguration.ZoomRectangleColor.blue); using (Pen aPen = new Pen(aZoomInRectangleColor, 2)) { // computing the screen coordinates ScreenPlaneCoordinatesTransfornation tempTransformation = new ScreenPlaneCoordinatesTransfornation(FractalImage.Width, FractalImage.Height, myFractalObserverConfiguration.CurrentRectangle); Point aStartPoint = tempTransformation.GetScreenCoordinates(myFractalObserverConfiguration.ZoomRectangle.MinX, myFractalObserverConfiguration.ZoomRectangle.MinY); Point aEndPoint = tempTransformation.GetScreenCoordinates(myFractalObserverConfiguration.ZoomRectangle.MaxX, myFractalObserverConfiguration.ZoomRectangle.MaxY); Rectangle aRect = new Rectangle(aStartPoint.X, aStartPoint.Y, Math.Abs(aEndPoint.X - aStartPoint.X), Math.Abs(aEndPoint.Y - aStartPoint.Y)); aGraphics.DrawRectangle(aPen, aRect); } } }