Ejemplo n.º 1
0
        private void MapEventHappened(object sender, MapEventArgs e)
        {
            switch (e.EventType)
            {
            case MapEventType.MapViewChanged:
            {
                CentrXY         = e.CentrXY;
                CentrOffset     = e.CentrOffset;
                ActiveOffset    = e.ActiveOffset;
                PanelMap_offset = e.PanelMap_offset;
                MapPanel_offset = e.MapPanel_offset;
                MapRect1        = e.MapRect1;
                MapRect2        = e.MapRect2;
                DrawPanel.Refresh();
                break;
            }

            case MapEventType.ToggleBetweenCurrentEntireMapView:
            {
                DrawPanel.Refresh();
                break;
            }

            default: break;
            }
        }
Ejemplo n.º 2
0
        private void DrawPanel_MouseClick(object sender, MouseEventArgs e)
        {
            var figure = new FigureClass
            {
                x           = e.X,
                y           = e.Y,
                borderColor = _borderColor,
                fillColor   = _fillColor,
                size        = _size
            };

            switch (_figure)
            {
            case Figure.Circle:
                _circleCoords.Add(figure);
                break;

            case Figure.Square:
                _squaresCoords.Add(figure);
                break;

            case Figure.Triangle:
                _triangesCoords.Add(figure);
                break;

            default:
                break;
            }

            DrawPanel.Update();
            DrawPanel.Refresh();
        }
Ejemplo n.º 3
0
        private void DrawPanel_Click(object sender, EventArgs e)
        {
            saved = false;
            int x = GetCursorX();
            int y = GetCursorY();

            if (tsbPicker.Checked)
            {
                tsbColorPicker.Color = pixels[x, y];
                tsbPicker.Checked    = false;
                tsbDraw.Checked      = true;
            }
            else if (tsbFill.Checked || tsbTexturize.Checked)
            {
                BackupForUndo();
                if (tsbFill.Checked)
                {
                    Fill(x, y);
                }
                else if (tsbTexturize.Checked)
                {
                    Texturize(x, y);
                }
                DrawPanel.Refresh();
            }
        }
Ejemplo n.º 4
0
 private void DrawPanel_MouseWheel(object sender, MouseEventArgs e)
 {
     if ((Keyboard.GetKeyStates(Key.LeftCtrl) & KeyStates.Down) > 0)
     {
         ((HandledMouseEventArgs)e).Handled = true;
         if (e.Delta > 0)
         {
             scale *= 1.3;
         }
         else
         {
             scale /= 1.3;
         }
         if (scale < 1)
         {
             scale = 1;
         }
         if (scale > 30)
         {
             scale = 30;
         }
         AdjustDrawPanel();
         DrawPanel.Refresh();
     }
 }
Ejemplo n.º 5
0
        private void Calculate_Click(object sender, EventArgs e)
        {
            if (PointsN < 3)
            {
                MessageBox.Show("Введено слишком мало точек! Минимум 3 точки.");
                return;
            }
            string[] a = new String[PointsN];
            int      i = 0;

            foreach (object x in VertexesBox.Items)
            {
                a[i++] = (String)x;
            }
            double         Square = 0;
            List <MyPoint> pts    = new List <MyPoint>();

            if (Find3DPolygon.CalculatePolySq(a, ref Square, ref pts))
            {
                OutputBox.Text = "Итак, программа получила, что:\nПлощадь = " + Square + "\nМногоугольник сосотоит из " + pts.Count + " точек.";
                LastPolyPts    = pts;
                PolyCreated    = true;
                DrawPanel.Refresh();
                DrawPolyPoints(LastPolyPts);
            }
            else
            {
                MessageBox.Show("Ошибка: не удалось вычислить площадь при заданных вершинах!");
            }
        }
Ejemplo n.º 6
0
 private void DrawPanel_MouseUp(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Middle)
     {
         midDown = false;
     }
     else if (e.Button == MouseButtons.Right)
     {
         rightDown = false;
         if (mouseDown.X < mouseUp.X) //保证该box Xmin,Xmax不弄反。
         {
             box.Xmin = mouseDown.X;
             box.Xmax = mouseUp.X;
         }
         else
         {
             box.Xmin = mouseUp.X;
             box.Xmax = mouseDown.X;
         }
         if (mouseDown.Y < mouseUp.Y)
         {
             box.Ymin = mouseDown.Y;
             box.Ymax = mouseUp.Y;
         }
         else
         {
             box.Ymin = mouseUp.Y;
             box.Ymax = mouseDown.Y;
         }
     }
     DrawPanel.Cursor = Cursors.Cross;
     leftDown         = false;
     DrawPanel.Refresh();
 }
Ejemplo n.º 7
0
        private void DrawPanel_MouseMove(object sender, MouseEventArgs e)
        {
            PointF[] mousePo = { new PointF(e.X, e.Y) };
            if (mat != null)
            {
                mat.TransformPoints(mousePo);
            }
            mouseUp   = mousePo[0];
            lblX.Text = "X:" + String.Format("{0:F}", mousePo[0].X);
            lblY.Text = "Y:" + String.Format("{0:F}", mousePo[0].Y);

            if (e.Button == MouseButtons.Middle)
            {
                float dx = mouseUp.X - mouseDown.X;
                float dy = mouseUp.Y - mouseDown.Y;
                mouseUp   = mousePo[0];
                box.Xmin -= dx;
                box.Xmax -= dx;
                box.Ymin -= dy;
                box.Ymax -= dy;
            }
            else if (e.Button == MouseButtons.Right)
            {
                mouseUp = mousePo[0];
            }
            DrawPanel.Refresh();
        }
Ejemplo n.º 8
0
        private void ClearBtn_Click(object sender, EventArgs e)
        {
            _circleCoords.Clear();
            _squaresCoords.Clear();
            _triangesCoords.Clear();

            DrawPanel.Update();
            DrawPanel.Refresh();
        }
Ejemplo n.º 9
0
 private void tsbRedo_Click(object sender, EventArgs e)
 {
     Color[,] last = RedoBuffer[RedoBuffer.Count - 1];
     UndoBuffer.Add(pixels);
     tsbUndo.Enabled = true;
     pixels          = last;
     RedoBuffer.Remove(last);
     DrawPanel.Refresh();
     if (RedoBuffer.Count <= 0)
     {
         tsbRedo.Enabled = false;
     }
 }
 // Switch between statistics (shows active units) & casualties (shows dead units)
 private void CasualtiesButton_Click(object sender, EventArgs e)
 {
     if (_showStatistics)
     {
         _showStatistics        = false;
         _casualtiesButton.Text = "Statistics";
     }
     else
     {
         _showStatistics        = true;
         _casualtiesButton.Text = "Casualties";
     }
     DrawPanel.Refresh();
 }
Ejemplo n.º 11
0
        private void DrawPanel_MouseDown(object sender, MouseEventArgs e)
        {
            PointF[] mousePo = { new PointF(e.X, e.Y) };
            mat.TransformPoints(mousePo);
            mouseDown = mousePo[0];

            if (e.Button == MouseButtons.Middle)     //中间平移,右键开窗
            {
                DrawPanel.Cursor = Cursors.NoMove2D; //设置光标样式
                midDown          = true;
                ////将窗体内容写入bitscreen
                //bitScreen = new Bitmap(DrawPanel.Width, DrawPanel.Height);
                //Graphics g = Graphics.FromImage(bitScreen);
                //g.CompositingQuality = CompositingQuality.HighQuality;
                //DrawPanel.DrawToBitmap(bitScreen, DrawPanel.ClientRectangle);

                ////创建窗体*3的大小的bitmap
                //if (bitPanel != null) bitPanel.Dispose();
                //bitPanel = new Bitmap(3 * DrawPanel.Width, 3 * DrawPanel.Height);
                //g = Graphics.FromImage(bitPanel);
                //g.CompositingQuality = CompositingQuality.HighQuality;
                //g.Clear(Color.AliceBlue);//清空其内容,作为背景
                //g.DrawImage(bitScreen, DrawPanel.Width, DrawPanel.Height);
            }
            else if (e.Button == MouseButtons.Right)
            {
                DrawPanel.Cursor = Cursors.Cross;//设置成交叉
                rightDown        = true;
            }
            else if (e.Button == MouseButtons.Left)
            {
                leftDown = true;
                if (leftCount == 0)
                {
                    //获取第一个点的用户坐标
                    p1         = mousePo[0];
                    leftCount += 1;
                }
                else if (leftCount == 1)
                {
                    //获取第二个点的用户坐标
                    p2        = mousePo[0];
                    leftCount = 0;
                }
                DrawPanel.Refresh();
            }
        }
Ejemplo n.º 12
0
 private void DrawPanel_MouseMove(object sender, MouseEventArgs e)
 {
     if (mouseDown)
     {
         saved = false;
         int x = GetCursorX();
         int y = GetCursorY();
         if (tsbDraw.Checked)
         {
             pixels[x, y] = tsbColorPicker.Color;
         }
         else if (tsbClear.Checked)
         {
             pixels[x, y] = Color.Transparent;
         }
         else if (tsbRectangle.Checked)
         {
             for (int i = 0; i < width; i++)
             {
                 for (int j = 0; j < height; j++)
                 {
                     pixels[i, j] = UndoBuffer[UndoBuffer.Count - 1][i, j];
                 }
             }
             int sx = Math.Min(startPoint.X, x);
             int fx = Math.Max(startPoint.X, x);
             int sy = Math.Min(startPoint.Y, y);
             int fy = Math.Max(startPoint.Y, y);
             for (int i = sx; i <= fx; i++)
             {
                 for (int j = sy; j <= fy; j++)
                 {
                     pixels[i, j] = tsbColorPicker.Color;
                 }
             }
         }
         DrawPanel.Refresh();
     }
 }
Ejemplo n.º 13
0
        private void DrawPanel_MouseWheel(object sender, MouseEventArgs e)
        {
            float scale;

            if (e.Delta > 0)//向上滚动滑轮
            {
                scale = 1.2f;
            }
            else//向下滚动滑轮
            {
                scale = 0.8f;
            }
            PointF[] mousePo = { new PointF(e.X, e.Y) };
            mat.TransformPoints(mousePo);
            PointF mouse = mousePo[0];

            box.Xmin = ZoomChange(scale, mouse.X, box.Xmin);
            box.Ymin = ZoomChange(scale, mouse.Y, box.Ymin);
            box.Xmax = ZoomChange(scale, mouse.X, box.Xmax);
            box.Ymax = ZoomChange(scale, mouse.Y, box.Ymax);
            DrawPanel.Refresh();
        }
Ejemplo n.º 14
0
        private void RunButton_Click(object sender, EventArgs e)
        {
            bool czy = int.TryParse(InputBox.Text, out Amount);

            if (czy)
            {
                if (Amount < 1)
                {
                    // Incorrect number!
                    MessageBox.Show("Please input a correct number!", "Incorrect number", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Amount        = 5000;
                    InputBox.Text = "5000";
                }
            }
            else
            {
                MessageBox.Show("Please input a correct number!", "Incorrect number", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Amount        = 5000;
                InputBox.Text = "5000";
            }

            WasClicked = true;
            DrawPanel.Refresh();
        }
Ejemplo n.º 15
0
        private void ButtonValidate_Click(object sender, EventArgs e)
        {
            DrawPanel.Refresh();

            double ValueA = 0;
            double ValueB = 0;
            double ValueC = 0;
            double FirstX;
            double FirstY;

            int   origo_x = DrawPanel.Width / 2;
            int   origo_y = DrawPanel.Height / 2;
            Point origo   = new Point(origo_x, origo_y);

            Bitmap pen = new Bitmap(1, 1);

            pen.SetPixel(0, 0, Color.Blue);
            System.Drawing.Graphics g = DrawPanel.CreateGraphics();

            if (TextBoxValueA.Text == "" || TextBoxValueB.Text == "" || TextBoxValueC.Text == "")
            {
                MessageBox.Show("Veuillez remplir toute les cellules (en cas de valeur nulle entrer la valeur 0 et ne laisser pas la cellule vide)");
            }
            else
            {
                //ValueA = Convert.ToDouble(TextBoxValueA.Text) * (-1);
                //ValueB = Convert.ToDouble(TextBoxValueB.Text) * (-1);
                //ValueC = Convert.ToDouble(TextBoxValueC.Text) * (-1);
                ValueA = Convert.ToDouble(TextBoxValueA.Text);
                ValueB = Convert.ToDouble(TextBoxValueB.Text);
                ValueC = Convert.ToDouble(TextBoxValueC.Text);

                if (ValueA >= -10 && ValueA <= 10)
                {
                    if (ValueB >= -10 && ValueB <= 10)
                    {
                        if (ValueC >= -10 && ValueC <= 10)
                        {
                        }
                        else
                        {
                            MessageBox.Show("Veuiller entrer une valeur comprise entre -10 et 10");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Veuiller entrer une valeur comprise entre -10 et 10");
                    }
                }
                else
                {
                    MessageBox.Show("Veuiller entrer une valeur comprise entre -10 et 10");
                }

                //if ((Math.Pow(ValueB, 2) - (4 * ValueA * ValueC)) / (2 * ValueA) < 0) // Check if the discriminant is positiv
                //{
                //    FirstX = (-ValueB + Math.Sqrt(Math.Pow(ValueB, 2) - (4 * ValueA * ValueC))) / (2 * ValueA);
                //    SecondX = (-ValueB - Math.Sqrt(Math.Pow(ValueB, 2) - (4 * ValueA * ValueC))) / (2 * ValueA);
                //}
                //else if ((Math.Pow(ValueB, 2) - (4 * ValueA * ValueC)) / (2 * ValueA) == 0) // check if the discriminant is neutral
                //{
                //    FirstX = SecondX = -(ValueB / (2 * ValueA));
                //}
                //else
                //{

                //}

                //Début tableau
                Double[,] storePoint = new Double[201, 2];

                double minY = 0;
                double maxY = 0;

                //store
                for (double j = 0, i = -10; i <= 10 && j < 201; i += 0.1, j++)
                {
                    FirstX = i;
                    FirstY = (ValueA * (FirstX * FirstX)) + ((ValueB * FirstX) + ValueC);
                    storePoint[(int)j, 0] = FirstX;
                    storePoint[(int)j, 1] = FirstY;

                    //g.DrawImageUnscaled(pen, origo_x + (int)FirstX, origo_y - (int)FirstY);
                    //g.DrawImageUnscaled(pen, origo_x - (int)FirstX, origo_y - (int)FirstY);

                    if (maxY < storePoint[(int)j, 1] && storePoint[(int)j, 1] > 0)
                    {
                        maxY = storePoint[(int)j, 1];
                    }
                    if (minY > storePoint[(int)j, 1] && storePoint[(int)j, 1] < 0)
                    {
                        minY = storePoint[(int)j, 1];
                    }
                }


                if (Math.Abs(minY) > Math.Abs(maxY))
                {
                    maxY = minY;
                }

                double MaxYValue = maxY;
                MaxYValue = Math.Round(maxY);

                if (MaxYValue < 0)
                {
                    lblmaxY.Text = Convert.ToString(MaxYValue * (-1));
                    lblminY.Text = Convert.ToString(MaxYValue);
                }
                else if (MaxYValue > 0)
                {
                    lblmaxY.Text = Convert.ToString(MaxYValue);
                    lblminY.Text = "- " + Convert.ToString(MaxYValue);
                }
                maxY = Math.Abs(origo_y / maxY);



                //Draw
                for (int i = 0; i <= 200; i++)
                {
                    Point newpoint = new Point((int)((storePoint[i, 0] + 10) * (origo.X / 10)),
                                               (int)(origo_y - (maxY * storePoint[i, 1])));

                    //g.DrawImageUnscaled(pen, origo_x + (int)FirstX, origo_y - (int)FirstY);
                    //g.DrawImageUnscaled(pen, origo_x - (int)FirstX, origo_y - (int)FirstY);
                    //g.DrawImageUnscaled(pen, origo);
                    g.DrawImageUnscaled(pen, newpoint);
                }

                SaveDrawing();
            }
        }
Ejemplo n.º 16
0
 private void btnClear_Click(object sender, EventArgs e)
 {
     DrawPanel.Refresh();
 }
Ejemplo n.º 17
0
 /// <summary>
 /// 将“视口”还原
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnRedraw_Click(object sender, EventArgs e)
 {
     initial = true;
     DrawPanel.Refresh();
     initial = false;
 }