private void picRubberBandLayer_MouseDown(object sender, MouseEventArgs e) { if (g_blFileIsOpened || g_blFileIsNewed) { if (m_blAdjusting == true) { m_intAjustingState=0; m_ptStart = new Point(e.X,e.Y); switch (m_abAdjustingBox.GetCurrentHandle(m_ptStart)) //Get Current Handle,and react when mousemove { case 0: SetSelectionRect(); m_intAjustingState = 1; //translate break; case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: m_intAjustingState = 2; //scale break; case 9: m_intAjustingState = 4; //move center break; case 10: case 11: case 12: case 13: m_intAjustingState = 3; //Rotation break; } switch ((int)m_abAdjustingBox.curHandle) //Get Current Handle,and react when mousemove { case -1: break; case 0: break; case 1: this.Cursor = Cursors.SizeNWSE; break; case 2: this.Cursor = Cursors.SizeWE; break; case 3: this.Cursor = Cursors.SizeNESW; break; case 4: this.Cursor = Cursors.SizeNS; break; case 5: this.Cursor = Cursors.SizeNWSE; break; case 6: this.Cursor = Cursors.SizeWE; break; case 7: this.Cursor = Cursors.SizeNESW; break; case 8: this.Cursor = Cursors.SizeNS; break; case 9: this.Cursor = Cursors.SizeAll; break; case 10: case 11: case 12: case 13: this.Cursor = new Cursor(GetType(), "Cursors.RotateToolCursor.cur"); break; } } else { switch (ToolBoxForm.g_tmUsingToolMode) { case ToolBoxForm.ToolMode.Move: m_ptStart = new Point(e.X, e.Y); //Record the current position when you click down m_blOperating = true; break; case ToolBoxForm.ToolMode.Line: m_lnNewLine.SetLine(e.Location, e.Location); m_lnNewLine.SetPen(ColorBoxForm.g_clrSelectedColor1, //Set up the rubber band PenStyle ToolBoxForm.g_ftLineWidth); m_blOperating = true; //On Operatin so enable the MouseMove break; case ToolBoxForm.ToolMode.Curve: if (m_cvNewCurve.m_blCurveIsWaiting == false) //There hasn't been a curve yet { m_ptStart = new Point(e.X, e.Y); //Save the start position m_cvNewCurve.SetPen(ColorBoxForm.g_clrSelectedColor1, //Set up the rubber band PenStyle ToolBoxForm.g_ftLineWidth); m_blOperating = true; } else //One curve has been newed { m_intCurveNodeIndex = m_cvNewCurve.GetCurrentNode(e.Location); if (m_intCurveNodeIndex == -1) //Not selecting a Node.Start a new curve { g_lstShapeList[g_lstShapeList.Count - 1].m_blShapeIsFormed = true; //Finish the old one before start a new curve m_cvNewCurve = new Curve(); m_ptStart = new Point(e.X, e.Y); m_cvNewCurve.SetPen(ColorBoxForm.g_clrSelectedColor1, ToolBoxForm.g_ftLineWidth); m_blOperating = true; } else //Into Adjusting State { m_cvNewCurve.m_blCurveAdjusting = true; } } break; case ToolBoxForm.ToolMode.Rectangle: m_ptStart = new Point(e.X, e.Y); m_blOperating = true; break; case ToolBoxForm.ToolMode.Text: m_ptStart = new Point(e.X, e.Y); if (m_blItatic == true) m_fsFontStyle = m_fsFontStyle | FontStyle.Italic; //Itatic else m_fsFontStyle = m_fsFontStyle & (~FontStyle.Italic); if (m_blBold == true) m_fsFontStyle = m_fsFontStyle | FontStyle.Bold; //Bold else m_fsFontStyle = m_fsFontStyle & (~FontStyle.Bold); if (m_blUnderline == true) m_fsFontStyle = m_fsFontStyle | FontStyle.Underline; else m_fsFontStyle = m_fsFontStyle & (~FontStyle.Underline); //Underline m_strStringYouInsert = frmToolBox.richTextBox1.Text; m_sfFontStringFormat = new StringFormat(); m_sfFontStringFormat.Alignment = StringAlignment.Center; m_sfFontStringFormat.FormatFlags = StringFormatFlags.LineLimit; m_sfFontStringFormat.Trimming = StringTrimming.EllipsisWord; m_blOperating = true; break; case ToolBoxForm.ToolMode.Ellipse: m_ptStart = new Point(e.X, e.Y); m_blOperating = true; break; case ToolBoxForm.ToolMode.RoundedRectangle: m_ptStart = new Point(e.X, e.Y); m_blOperating = true; break; case ToolBoxForm.ToolMode.ColorPicker: Bitmap pick = new Bitmap(1, 1); Graphics tempGraphics = Graphics.FromImage(pick); 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 frmColorBox.PickColor(pick.GetPixel(0, 0)); //Pick up the color in colobox break; case ToolBoxForm.ToolMode.Pencil: m_penPencil = new Pen(ColorBoxForm.g_clrSelectedColor1, 1); //Create the pencil when mouse down m_ptStart.X = e.X; m_ptStart.Y = e.Y; m_blOperating = true; break; case ToolBoxForm.ToolMode.Eraser: this.Cursor = new Cursor(GetType(), "Cursors.EraserToolCursorMouseDown.cur"); m_brsEraserBrush = new SolidBrush(Color.White); m_blOperating = true; break; case ToolBoxForm.ToolMode.Brush: switch (ToolBoxForm.g_intBrushStyle) //Initialize the brush according to the selection { case 1: m_brsSolidBrush = new SolidBrush(ColorBoxForm.g_clrSelectedColor1); break; case 2: m_brsHatchBrush = new HatchBrush(HatchStyle.DiagonalCross, ColorBoxForm.g_clrSelectedColor1 , Color.Transparent); break; case 3: Rectangle rect1 = new Rectangle(20, 80, 250, 100); m_brsLinearBrush = new LinearGradientBrush(rect1, ColorBoxForm.g_clrSelectedColor1, Color.White, LinearGradientMode.BackwardDiagonal); break; } m_blOperating = true; break; case ToolBoxForm.ToolMode.FillBorder: if (g_rtFillRectangle.Contains(e.Location)) { Graphics g = Graphics.FromImage(g_bmBackground); SolidBrush brush = new SolidBrush(ColorBoxForm.g_clrSelectedColor2); g.FillRectangle(brush, g_rtFillRectangle); this.pnlBackground.Invalidate(); } g_blFileHasBeenEdited = true; break; case ToolBoxForm.ToolMode.PaintBucket: try { foreach (Rect s in g_lstSelectedShapeList) { if (s.m_rtRect.Contains(e.Location)) { s.SetFillColor(ColorBoxForm.g_clrSelectedColor2); } } } catch { //do nothing } this.pnlBackground.Invalidate(); break; } } } }
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 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); } }