private void MainForm_Load(object sender, EventArgs e) { frmToolBox = new ToolBoxForm(); frmInfoBox = new InfoBoxForm(); frmColorBox = new ColorBoxForm(); frmLayerBox = new LayerBoxForm(); frmColorBox.Show(); frmToolBox.Show(); frmInfoBox.Show(); frmLayerBox.Show(); frmLayerBox.frmMainForm = this; g_intPaperWidth = 600; g_intPaperHeight = 500; g_blFileIsNewed = false; g_blFileIsOpened = false; g_blFileHasBeenEdited = false; g_blColorBoxIsShow = true; g_blInfoBoxIsShow = true; g_blToolBoxIsShow = true; g_blLayerBoxIsShow = true; g_lstShapeList = new List<Shape>(); g_lstSelectedShapeList = new List<Shape>(); g_intNumberOfShape = 0; g_bmCache = new Bitmap(1, 1); m_blAdjusting = false; m_blOperating = false; m_lnNewLine = new Line(); m_cvNewCurve = new Curve(); m_elNewElli = new Elli(); m_rtNewRect = new Rect(); m_rrNewRdRect = new RoundedRect(); m_txtNewText = new Text(); m_abAdjustingBox = new AdjustingBox(); m_intAjustingState = 0; m_blShiftKeyDown = false; m_blBold = false; m_blItatic = false; m_blUnderline = false; m_dbScaleMatrix = new double[3, 3]; m_dbRotationMatrix = new double[3, 3]; foreach (FontFamily ff in FontFamily.Families) //Get ready for the list of FontFamily { toolStripFontFamily.Items.Add(ff.Name); } }
private void picRubberBandLayer_MouseMove(object sender, MouseEventArgs e) { //Processing the InfoBox if (g_blFileIsOpened || g_blFileIsNewed) { if (m_blAdjusting == true) { if (m_intAjustingState != 0) { switch (m_intAjustingState) //1.tanslate 2.scale 3.rotate 4.move center { case 1: Size TransSize = new Size(e.X - m_ptStart.X, e.Y - m_ptStart.Y); g_lstSelectedShapeList[g_lstSelectedShapeList.Count - 1].Translate(TransSize); //move the shape m_abAdjustingBox.Translate(TransSize); //move the control box this.picRubberBandLayer.Invalidate(); this.pnlBackground.Invalidate(); m_ptStart = new Point(e.X, e.Y); break; case 2: m_abAdjustingBox.Scale(new Point(e.X,e.Y)); //Scale the adjustingbox this.picRubberBandLayer.Invalidate(); this.pnlBackground.Invalidate(); break; case 3: m_ptEnd = new Point(e.X, e.Y); SetRotation(m_ptStart, m_ptEnd); //Set up the RotationMatrix m_abAdjustingBox.Rotate(m_dbRotationMatrix); this.picRubberBandLayer.Invalidate(); this.pnlBackground.Invalidate(); break; case 4: m_abAdjustingBox.m_ptRotationCenter = new Point(e.X, e.Y); this.pnlBackground.Invalidate(); break; } } } else { if (m_blOperating == false) //get cursor's RGB color when it is not on operating { Graphics tempGraphics = Graphics.FromImage(g_bmCache); Point screen = ((Control)sender).PointToScreen(new Point(e.X, e.Y)); tempGraphics.CopyFromScreen(screen.X, screen.Y, 0, 0, new Size(1, 1)); //copy the (X,Y) in screen point to a 1*1 bitmap cache m_clrPixelColor = g_bmCache.GetPixel(0, 0); //Get the pixel color of cashe frmInfoBox.SetCurrentCursor(e.Location); m_btPixelColorR = m_clrPixelColor.R; m_btPixelColorG = m_clrPixelColor.G; m_btPixelColorB = m_clrPixelColor.B; frmInfoBox.SetColorRGB(m_btPixelColorR, m_btPixelColorG, m_btPixelColorB); } else //Refresh the size of shape when in operating { if (ToolBoxForm.g_tmUsingToolMode == ToolBoxForm.ToolMode.Rectangle || ToolBoxForm.g_tmUsingToolMode == ToolBoxForm.ToolMode.Ellipse) { frmInfoBox.SetSize(m_ptStart, m_ptEnd); } } if (m_blOperating == true) { switch (ToolBoxForm.g_tmUsingToolMode) { case ToolBoxForm.ToolMode.Move: Size translation = new Size(e.X - m_ptStart.X, e.Y - m_ptStart.Y); foreach (Shape G in g_lstSelectedShapeList) //Translate the selected shape { G.Translate(translation); } this.pnlBackground.Invalidate(); //Move the Adjustingbox with the shape m_ptStart = new Point(e.X, e.Y); //Prepare for the next StartPoint break; case ToolBoxForm.ToolMode.Line: m_lnNewLine.SetEnd(e.Location); picRubberBandLayer.Invalidate(); //Refresh the picture box to realize rubber band break; case ToolBoxForm.ToolMode.Curve: m_cvNewCurve = new Curve(m_ptStart, e.Location); picRubberBandLayer.Invalidate(); //Refresh the picture box to realize rubber band break; case ToolBoxForm.ToolMode.Rectangle: m_ptEnd = new Point(e.X, e.Y); m_rtNewRect = new Rect(m_ptStart, m_ptEnd, m_blShiftKeyDown); m_rtNewRect.SetPen(ColorBoxForm.g_clrSelectedColor1, //Set up the pen ToolBoxForm.g_ftLineWidth); picRubberBandLayer.Invalidate(); break; case ToolBoxForm.ToolMode.Text: //The Text Frame m_ptEnd = new Point(e.X, e.Y); m_txtNewText = new Text(m_ptStart, m_ptEnd); m_txtNewText.SetPen(DashStyle.Dot, Color.Black, 1); //Dash Dot Frame picRubberBandLayer.Invalidate(); break; case ToolBoxForm.ToolMode.Ellipse: m_ptEnd = new Point(e.X, e.Y); m_elNewElli = new Elli(m_ptStart, m_ptEnd, m_blShiftKeyDown); m_elNewElli.SetPen(ColorBoxForm.g_clrSelectedColor1, ToolBoxForm.g_ftLineWidth); picRubberBandLayer.Invalidate(); break; case ToolBoxForm.ToolMode.RoundedRectangle: m_ptEnd = new Point(e.X, e.Y); m_rrNewRdRect = new RoundedRect(m_ptStart, m_ptEnd, m_blShiftKeyDown); m_rrNewRdRect.g_blRdRectHasBeenCreated = true; m_rrNewRdRect.SetPen(ColorBoxForm.g_clrSelectedColor1, ToolBoxForm.g_ftLineWidth); picRubberBandLayer.Invalidate(); break; case ToolBoxForm.ToolMode.Pencil: Graphics g = Graphics.FromImage(g_bmBackground); //Drawing line continually to make a free line pencil g.DrawLine(m_penPencil, m_ptStart.X, m_ptStart.Y, e.X, e.Y); g.SmoothingMode = SmoothingMode.HighQuality; g.PixelOffsetMode = PixelOffsetMode.HighSpeed; m_ptStart.X = e.X; m_ptStart.Y = e.Y; this.pnlBackground.Invalidate(); break; case ToolBoxForm.ToolMode.Eraser: Graphics g2 = Graphics.FromImage(g_bmBackground); int r2 = ToolBoxForm.g_intEraserWidth / 2; g2.FillEllipse(m_brsEraserBrush, e.X - r2, e.Y - r2, r2 * 2, r2 * 2); this.pnlBackground.Invalidate(); break; case ToolBoxForm.ToolMode.Brush: Graphics g3 = Graphics.FromImage(g_bmBackground); g3.SmoothingMode = SmoothingMode.HighQuality; g3.PixelOffsetMode = PixelOffsetMode.HighSpeed; int r = ToolBoxForm.g_intBrushWidth / 2; m_ptStart = e.Location; switch (ToolBoxForm.g_intBrushStyle) //Initialize the brush according to the selection { case 1: g3.FillEllipse(m_brsSolidBrush, m_ptStart.X - r, m_ptStart.Y - r, 2 * r, 2 * r); break; case 2: g3.FillEllipse(m_brsHatchBrush, m_ptStart.X - r, m_ptStart.Y - r, 2 * r, 2 * r); break; case 3: g3.FillEllipse(m_brsLinearBrush, m_ptStart.X - r, m_ptStart.Y - r, 2 * r, 2 * r); break; } m_ptStart = e.Location; this.pnlBackground.Invalidate(); break; } } else { switch (ToolBoxForm.g_tmUsingToolMode) { case ToolBoxForm.ToolMode.Curve: if (m_cvNewCurve.m_blCurveIsWaiting == true) { if (g_lstShapeList[g_lstShapeList.Count - 1].GetCurrentNode(e.Location) >= 0) //Change the icon when cursor is on one node { this.Cursor = new Cursor(GetType(), "Cursors.PanToolCursor.cur"); } else { this.Cursor = new Cursor(GetType(), "Cursors.GenericToolCursor.cur"); } } if (m_cvNewCurve.m_blCurveAdjusting == true) { this.Cursor = new Cursor(GetType(), "Cursors.PanToolCursorMouseDown.cur"); g_lstShapeList[g_lstShapeList.Count - 1].SetNode(m_intCurveNodeIndex, e.Location); picRubberBandLayer.Invalidate(); } break; } } } } }
private void picRubberBandLayer_MouseUp(object sender, MouseEventArgs e) { if (g_blFileIsOpened || g_blFileIsNewed) { if (m_blAdjusting == true) { this.Cursor = new Cursor(GetType(), "Cursors.MoveSelectionToolCursor.cur"); //Reset the cursor if (m_intAjustingState != 0) { switch (m_intAjustingState) { case 1: break; case 2: Scale(new Point(e.X, e.Y)); this.pnlBackground.Invalidate(); break; case 3: m_ptEnd = new Point(e.X, e.Y); g_lstSelectedShapeList[g_lstSelectedShapeList.Count-1].Rotate (GetAngle(m_ptStart, m_ptEnd, m_abAdjustingBox.m_ptRotationCenter), m_abAdjustingBox.m_ptRotationCenter); m_abAdjustingBox.SetOldHandles(); this.pnlBackground.Invalidate(); break; case 4: break; } m_intAjustingState = 0; } } else { switch (ToolBoxForm.g_tmUsingToolMode) { case ToolBoxForm.ToolMode.Move: m_blOperating = false; break; case ToolBoxForm.ToolMode.Line: m_lnNewLine.SetEnd(e.Location); //This is the final fixed line m_lnNewLine.SetPen(ColorBoxForm.g_clrSelectedColor1, ToolBoxForm.g_ftLineWidth); g_lstShapeList.Add(m_lnNewLine); //Add the new line in the list g_intNumberOfShape++; frmLayerBox.AddItem(g_intNumberOfShape, 1); g_blFileHasBeenEdited = true; //Now the file has been edited m_lnNewLine = new Line(); //Get the next coming line prepared this.pnlBackground.Invalidate(); m_blOperating = false; break; case ToolBoxForm.ToolMode.Curve: if (m_cvNewCurve.m_blCurveIsWaiting == false) { g_lstShapeList.Add(m_cvNewCurve); g_intNumberOfShape++; frmLayerBox.AddItem(g_intNumberOfShape, 6); g_blFileHasBeenEdited = true; this.pnlBackground.Invalidate(); m_blOperating = false; m_cvNewCurve.m_blCurveIsWaiting = true; } if (m_cvNewCurve.m_blCurveAdjusting == true) { m_cvNewCurve.m_blCurveAdjusting = false; this.Cursor = new Cursor(GetType(), "Cursors.GenericToolCursor.cur"); } break; case ToolBoxForm.ToolMode.Rectangle: g_lstShapeList.Add(m_rtNewRect); g_intNumberOfShape++; frmLayerBox.AddItem(g_intNumberOfShape, 2); g_blFileHasBeenEdited = true; m_rtNewRect = new Rect(); this.pnlBackground.Invalidate(); m_blOperating = false; break; case ToolBoxForm.ToolMode.Text: m_txtNewText = new Text(m_ptStart, m_ptEnd, m_ffFontKind, m_fsFontStyle, m_intFontsize, m_strStringYouInsert, m_sfFontStringFormat); g_lstShapeList.Add(m_txtNewText); g_intNumberOfShape++; frmLayerBox.AddItem(g_intNumberOfShape, 5); g_blFileHasBeenEdited = true; m_txtNewText = new Text(); this.pnlBackground.Invalidate(); m_blOperating = false; break; case ToolBoxForm.ToolMode.Ellipse: g_lstShapeList.Add(m_elNewElli); g_intNumberOfShape++; frmLayerBox.AddItem(g_intNumberOfShape, 3); g_blFileHasBeenEdited = true; m_elNewElli = new Elli(); this.pnlBackground.Invalidate(); m_blOperating = false; break; case ToolBoxForm.ToolMode.RoundedRectangle: g_lstShapeList.Add(m_rrNewRdRect); g_intNumberOfShape++; frmLayerBox.AddItem(g_intNumberOfShape, 4); g_blFileHasBeenEdited = true; m_rrNewRdRect = new RoundedRect(); this.pnlBackground.Invalidate(); m_blOperating = false; break; case ToolBoxForm.ToolMode.Pencil: m_blOperating = false; break; case ToolBoxForm.ToolMode.Eraser: this.Cursor = new Cursor(GetType(), "Cursors.EraserToolCursor.cur"); m_blOperating = false; break; case ToolBoxForm.ToolMode.Brush: m_ptStart = new Point(); m_blOperating = false; break; } } } }