示例#1
0
        protected override void LoadExample()
        {
            // init form fields
            batchLayout = new NBatchLayout(document);
            grid        = view.Grid;

            view.BeginInit();

            view.Grid.Visible = true;

            // init document
            document.BeginInit();
            InitDocument();
            document.EndInit();

            // init form controls
            InitFormControls();

            // end view init
            view.EndInit();
        }
        void InitToolbar()
        {
            if (nDrawingViewToolbar.RequiresInitialization)
            {
                ActiveCommand = toolbarButtons[0].CommandName;

                // begin view init
                nDrawingViewToolbar.ViewLayout      = CanvasLayout.Normal;
                nDrawingViewToolbar.DocumentPadding = new Nevron.Diagram.NMargins(0);

                // init document
                nDrawingViewToolbar.Document.BeginInit();

                nDrawingViewToolbar.Document.AutoBoundsPadding = new Nevron.Diagram.NMargins(4);

                nDrawingViewToolbar.Document.GraphicsSettings.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
                nDrawingViewToolbar.Document.GraphicsSettings.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                nDrawingViewToolbar.Document.GraphicsSettings.PixelOffsetMode   = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;

                // set up visual formatting
                nDrawingViewToolbar.Document.Style.FillStyle = new NColorFillStyle(Color.White);
                nDrawingViewToolbar.Document.Style.TextStyle.FontStyle.InitFromFont(new Font("Arial Narrow", 8));

                nDrawingViewToolbar.Document.BackgroundStyle.FrameStyle.Visible = false;

                //	set up the shape factories
                NBasicShapesFactory buttonFactory = new NBasicShapesFactory(nDrawingViewToolbar.Document);
                buttonFactory.DefaultSize = new NSizeF(24, 24);

                NBrainstormingShapesFactory iconFactory = new NBrainstormingShapesFactory(nDrawingViewToolbar.Document);
                iconFactory.DefaultSize = new NSizeF(16, 16);

                //	create a batch layout, which will align shapes
                NBatchLayout batchLayout = new NBatchLayout(nDrawingViewToolbar.Document);

                //	create buttons
                int count = toolbarButtons.Length;
                for (int i = 0; i < count; i++)
                {
                    ToolbarButton btn         = toolbarButtons[i];
                    bool          isActive    = (this.ActiveCommand == btn.CommandName);
                    NShape        buttonShape = buttonFactory.CreateShape(BasicShapes.RoundedRectangle);

                    //	create the button shape group
                    NGroup      g      = new NGroup();
                    NBatchGroup bgroup = new NBatchGroup(nDrawingViewToolbar.Document);
                    NNodeList   shapes = new NNodeList();
                    if (btn.IsSeparator)
                    {
                        buttonShape.Width            /= 2;
                        buttonShape.Style.StrokeStyle = new NStrokeStyle(Color.White);
                        shapes.Add(buttonShape);
                    }
                    else if (!btn.IsColorSelector)
                    {
                        shapes.Add(buttonShape);
                    }
                    else
                    {
                        buttonShape.Style.FillStyle = new NColorFillStyle(btn.Color);
                        shapes.Add(buttonShape);
                    }

                    NRectanglePath  imagePath = new NRectanglePath(0f, 0f, btn.IconSize.Width, btn.IconSize.Height);
                    NImageFillStyle fs1       = new NImageFillStyle(this.MapPathSecure(@"..\..\..\Images\FlowChartBuilder\" + btn.IconFile));
                    NStyle.SetFillStyle(imagePath, fs1);
                    NStyle.SetStrokeStyle(imagePath, new NStrokeStyle(0, Color.White));
                    NCompositeShape imageShape = new NCompositeShape();
                    imageShape.Primitives.AddChild(imagePath);
                    imageShape.UpdateModelBounds();
                    shapes.Add(imageShape);

                    NShape coverShape = buttonFactory.CreateShape(BasicShapes.RoundedRectangle);
                    coverShape.Width = buttonShape.Width;
                    coverShape.Name  = "coverShape";
                    shapes.Add(coverShape);

                    if (!isActive && !btn.IsClientSide && !btn.IsSeparator)
                    {
                        if (btn.IsColorSelector)
                        {
                            coverShape.Style.FillStyle = new NColorFillStyle(Color.FromArgb(180, Color.White));
                        }
                        else
                        {
                            coverShape.Style.FillStyle = new NColorFillStyle(Color.FromArgb(160, Color.White));
                        }
                        coverShape.Style.StrokeStyle = new NStrokeStyle(Color.FromArgb(160, Color.White));
                    }
                    else
                    {
                        coverShape.Style.FillStyle   = new NColorFillStyle(Color.FromArgb(0, Color.White));
                        coverShape.Style.StrokeStyle = new NStrokeStyle(Color.FromArgb(0, Color.White));
                        if (!btn.IsSeparator)
                        {
                            coverShape.Style.ShadowStyle = new NShadowStyle(ShadowType.GaussianBlur, Color.FromArgb(70, Color.Black), new NPointL(1, 0));
                        }
                    }

                    // perform layout
                    batchLayout.Build(shapes);
                    batchLayout.AlignVertically(buttonShape, VertAlign.Center, false);
                    batchLayout.AlignHorizontally(buttonShape, HorzAlign.Center, false);

                    // group shapes
                    bgroup.Build(shapes);
                    bgroup.Group(null, false, out g);

                    // enable interactivity
                    if (!btn.IsSeparator)
                    {
                        g.Style.InteractivityStyle = new NInteractivityStyle(true, btn.CommandName, btn.Title, CursorType.Hand);
                    }

                    // set the command of the button
                    g.Tag = btn.CommandName;

                    nDrawingViewToolbar.Document.ActiveLayer.AddChild(g);
                }

                // layout the shapes in the active layer using a table layout
                NTableLayout layout = new NTableLayout();

                // setup the table layout
                layout.Direction         = LayoutDirection.LeftToRight;
                layout.ConstrainMode     = CellConstrainMode.Ordinal;
                layout.MaxOrdinal        = toolbarButtons.Length;
                layout.HorizontalSpacing = 7;

                // create a layout context
                NLayoutContext layoutContext = new NLayoutContext();
                layoutContext.GraphAdapter         = new NShapeGraphAdapter();
                layoutContext.BodyAdapter          = new NShapeBodyAdapter(nDrawingViewToolbar.Document);
                layoutContext.BodyContainerAdapter = new NDrawingBodyContainerAdapter(nDrawingViewToolbar.Document);

                // layout the shapes
                layout.Layout(nDrawingViewToolbar.Document.ActiveLayer.Children(null), layoutContext);

                nDrawingViewToolbar.Document.EndInit();
            }
        }