Exemplo n.º 1
0
        public void InitializeSketching()
        {
            Image         image;
            ToolBarButton tbBtnShape;
            Type          shapeType;
            XmlObjectDesignTimeBehaviorAttribute xmlObjectDesignTimeBehaviorAttribute;

            tbBtnShape             = new ToolBarButton();
            tbBtnShape.ToolTipText = "Arrow";
            tbBtnShape.Tag         = null;
            tbBtnShape.ImageIndex  =
                this.ilMain.Images.Add(Image.FromStream(this.GetType().Assembly.GetManifestResourceStream("TextMetal.Common.WinForms.DesignTime.Shapes.Resources.SketchArrow.bmp")), Color.Magenta);
            tbBtnShape.Pushed = true;

            this.tbarTools.Buttons.Add(tbBtnShape);

            foreach (string shapeKey in SketchFactory.ShapeKeys)
            {
                tbBtnShape = new ToolBarButton();

                shapeType = SketchFactory.GetShapeType(shapeKey);

                if ((object)shapeType == null)
                {
                    throw new InvalidOperationException();
                }

                xmlObjectDesignTimeBehaviorAttribute = ReflectionFascade.Instance.GetOneAttribute <XmlObjectDesignTimeBehaviorAttribute>(shapeType);

                if ((object)xmlObjectDesignTimeBehaviorAttribute == null)
                {
                    continue;
                }

                if (!xmlObjectDesignTimeBehaviorAttribute.ShowInToolbox)
                {
                    continue;
                }

                tbBtnShape.ToolTipText = xmlObjectDesignTimeBehaviorAttribute.Description;
                tbBtnShape.Tag         = shapeKey;

                image = xmlObjectDesignTimeBehaviorAttribute.GetToolboxImage();

                if ((object)image != null)
                {
                    tbBtnShape.ImageIndex = this.ilMain.Images.Add(image, Color.Magenta);
                }
                else
                {
                    tbBtnShape.ImageIndex = 4;
                }

                this.tbarTools.Buttons.Add(tbBtnShape);
            }

            this.SetSketch(null);
        }
Exemplo n.º 2
0
        private void pnlCanvas_MouseDown(object sender, MouseEventArgs e)
        {
            SketchShape shapeUnderCursor;

            if ((object)this.Sketch == null)
            {
                return;
            }

            if (e.Button == MouseButtons.Left)
            {
                if ((object)this.CurrentShapeTypeName == null)
                {
                    // hit test sketch
                    shapeUnderCursor = this.Sketch.GetShapeAtPoint(this.pnlCanvas.PointToClient(new Point(Cursor.Position.X, Cursor.Position.Y)));

                    if ((object)shapeUnderCursor != null)
                    {
                        this.CurrentShape = shapeUnderCursor;
                        this.pnlCanvas.Refresh();
                    }
                    else
                    {
                        this.CurrentShape = null;
                        this.pnlCanvas.Refresh();
                    }
                }
                else
                {
                    this.CurrentShape = null;
                    this.pnlCanvas.Refresh();

                    if ((object)this.CurrentShape != null)
                    {
                        return;
                    }

                    this.CurrentShape = SketchFactory.CreateShape(this.CurrentShapeTypeName);

                    if ((object)this.CurrentShape == null)
                    {
                        Cursor.Current = Cursors.No;
                        return;
                    }

                    this.CurrentShape.BeginSketch(new Point(e.X, e.Y));
                    this.pnlCanvas.Refresh();
                }
            }
            else if (e.Button == MouseButtons.Right)
            {
                if ((object)this.CurrentShapeTypeName == null)
                {
                    // hit test sketch
                    shapeUnderCursor = this.Sketch.GetShapeAtPoint(this.pnlCanvas.PointToClient(new Point(Cursor.Position.X, Cursor.Position.Y)));

                    if ((object)shapeUnderCursor != null)
                    {
                        this.CurrentShape = shapeUnderCursor;
                        this.pnlCanvas.Refresh();

                        this.ctxMnuSpecific.Show(this, new Point(e.X, e.Y));
                    }
                    else
                    {
                        this.CurrentShape = null;
                        this.pnlCanvas.Refresh();

                        this.ctxMnuGeneric.Show(this, new Point(e.X, e.Y));
                    }
                }
                else
                {
                    this.CurrentShape = null;
                    this.pnlCanvas.Refresh();
                }
            }
        }