Exemplo n.º 1
0
        private void addImageButton_Click(object sender, EventArgs e)
        {
            OpenFileDialog open = new OpenFileDialog();

            open.Filter = "Image Files(*.png; *.jpg; *.jpeg; *.gif; *.bmp)|*.png; *.jpg; *.jpeg; *.gif; *.bmp";
            if (open.ShowDialog() == DialogResult.OK)
            {
                ShapeToDraw = new ImageShape();
                CurrentViewPort.AddShape(new ImageShape(open.FileName, new RectangleShape(new RectangleF(0, 0, Image.FromFile(open.FileName).Width / 2, Image.FromFile(open.FileName).Height / 2))));
            }

            //layoutButtons.Add(new Button());
            //foreach (var item in layoutButtons)
            //{
            //    item.BackgroundImage = Image.FromFile(open.FileName);
            //    item.FlatStyle = FlatStyle.Flat;
            //    item.BackColor = Color.FromArgb(0, Color.White);
            //    item.BackgroundImageLayout = ImageLayout.Zoom;
            //    item.TextAlign = ContentAlignment.MiddleLeft;
            //    item.Text = "layout" + layoutButtons.Count.ToString();
            //    item.ForeColor = Color.White;
            //    item.Size = new Size(layoutPanel.Width, 65);
            //    layoutPanel.Controls.Add(item);
            //}
            CurrentViewPort.Refresh();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Прихващане на отпускането на бутона на мишката.
        /// Излизаме от режим "влачене".
        /// </summary>
        void ViewPortMouseUp(object sender, MouseEventArgs e)
        {
            dialogProcessor.IsDragging = false;
            if (dialogProcessor.IsDrawingNewShape)
            {
                // Specify a rectangle as the basis for creating a shape with zoom scale of viewPort
                RectangleShape rect = new RectangleShape(new RectangleF(new PointF(Math.Min(_p.X, e.Location.X) / zoom, Math.Min(_p.Y, e.Location.Y) / zoom),
                                                                        new SizeF(Math.Abs(_p.X - e.Location.X) / zoom, Math.Abs(_p.Y - e.Location.Y) / zoom)));

                rect.BorderWidth  = penWidth;
                rect.Transparency = (int)transparencyPicker.Value;
                rect.Rotation     = (float)rotationPicker.Value;

                if (ShapeToDraw is RectangleShape)
                {
                    CurrentViewPort.AddShape(rect);
                }
                else if (ShapeToDraw is EllipseShape)
                {
                    CurrentViewPort.AddShape(new EllipseShape(rect));
                }
                else if (ShapeToDraw is HeartShape)
                {
                    CurrentViewPort.AddShape(new HeartShape(rect));
                }
                else if (ShapeToDraw is StarShape)
                {
                    CurrentViewPort.AddShape(new StarShape(rect));
                }
                else if (ShapeToDraw is LineShape)
                {
                    CurrentViewPort.AddShape(new LineShape(new PointF(_p.X / zoom, _p.Y / zoom), new PointF(_p2.X / zoom, _p2.Y / zoom), penWidth, rect.Transparency));
                }
                dialogProcessor.IsDrawingNewShape = false;
                CurrentViewPort.Refresh();
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Прихващане на координатите при натискането на бутон на мишката и проверка (в обратен ред) дали не е
        /// щракнато върху елемент. Ако е така то той се отбелязва като селектиран и започва процес на "влачене".
        /// Промяна на статуса и инвалидиране на контрола, в който визуализираме.
        /// Реализацията се диалогът с потребителя, при който се избира "най-горния" елемент от екрана.
        /// </summary>
        void ViewPortMouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (pickUpSpeedButton.Checked)
            {
                dialogProcessor.Selection = dialogProcessor.ContainsPoint(e.Location, CurrentViewPort);
                if (dialogProcessor.Selection != null)
                {
                    //move picked shape to top of list
                    CurrentViewPort.ShapeList.Remove(dialogProcessor.Selection);
                    CurrentViewPort.AddShape(dialogProcessor.Selection);

                    //  Add and remove in multiple selection using Ctrl
                    if (ModifierKeys.HasFlag(Keys.Control))
                    {
                        if (!dialogProcessor.Selections.Contains(dialogProcessor.Selection))
                        {
                            dialogProcessor.Selections.Add(dialogProcessor.Selection);
                            dialogProcessor.Selections[dialogProcessor.Selections.Count - 1].IsSelected = true;
                        }
                        else
                        {
                            CurrentViewPort.ShapeList.Find(s => s.Equals(dialogProcessor.Selection)).IsSelected = false;
                            dialogProcessor.Selections.Remove(dialogProcessor.Selection);
                        }
                    }
                    else
                    {
                        // When pressed without the shapes - remove all selections
                        for (int i = 0; i < dialogProcessor.Selections.Count - 1; i++)
                        {
                            dialogProcessor.Selections[i].IsSelected = false;
                            dialogProcessor.Selections.Remove(dialogProcessor.Selections[i]);
                        }
                    }
                    dialogProcessor.IsDragging   = true;
                    dialogProcessor.LastLocation = e.Location;

                    // Output info
                    statusBar.Items[0].Text = "Последно действие: Селекция на примитив";
                    infoLabel.Text          = "Fill " + dialogProcessor.Selection.FillColor.ToString()
                                              + " Border " + dialogProcessor.Selection.BorderColor.ToString()
                                              + "\n width: " + dialogProcessor.Selection.Width + "px;" + " height: " + dialogProcessor.Selection.Height + "px;"
                                              + "\n border: " + dialogProcessor.Selection.BorderWidth.ToString() + "px;"
                                              + " transparency: " + dialogProcessor.Selection.Transparency + "\n"
                                              + " location: " + dialogProcessor.Selection.Location.ToString() + "\n"
                                              + " shape: " + dialogProcessor.Selection.GetType().Name;
                }
                CurrentViewPort.Refresh();
            }
            if (pickUpButton.Checked)
            {
                dialogProcessor.IsDrawingNewShape = true;
                _p = e.Location;
            }
            if (eraseButton.Checked)
            {
                dialogProcessor.Selection = dialogProcessor.ContainsPoint(e.Location, CurrentViewPort);
                if (dialogProcessor.Selection != null)
                {
                    statusBar.Items[0].Text = "Last action: Erase primitive";
                    CurrentViewPort.ShapeList.Remove(dialogProcessor.Selection);
                    CurrentViewPort.Refresh();
                }
            }
        }