Example #1
0
    public MainForm(GraphicsBackend backend, string exeDir, string shaderSubdir)
    {
        InitializeComponent();

        Shown += (sender, e) => FormReady = true;

        GraphicsDeviceOptions options = new(
            false,
            Veldrid.PixelFormat.R32_Float,
            false,
            ResourceBindingModel.Improved);

        Surface = new VeldridSurface(backend, options);
        Surface.VeldridInitialized += (sender, e) => VeldridReady = true;

        Content = Surface;

        ovpSettings = new OVPSettings();
        ovpSettings.drawFilled(true);
        ovpSettings.drawDrawn(true);
        ovpSettings.drawPoints(true);

        addPolys();

        Driver = new VeldridDriver(ref ovpSettings, ref Surface)
        {
            Surface             = Surface,
            ExecutableDirectory = exeDir,
            ShaderSubdirectory  = shaderSubdir
        };

        // TODO: Make this binding actually work both ways.
        CmdAnimate.Bind <bool>("Checked", Driver, "Animate");
        CmdClockwise.Bind <bool>("Checked", Driver, "Clockwise");
    }
Example #2
0
    private void createVPContextMenu()
    {
        // Single viewport now mandates regeneration of the context menu each time, to allow for entry screening.
        vp_menu = new ContextMenu();

        int itemIndex = 0;

        vp_menu.Items.Add(new ButtonMenuItem {
            Text = "Reset"
        });
        vp_menu.Items[itemIndex].Click += delegate
        {
            Driver.reset();
            updateViewport();
        };
        itemIndex++;

        ButtonMenuItem VPMenuDisplayOptionsMenu = vp_menu.Items.GetSubmenu("Display Options");

        itemIndex++;
        int displayOptionsSubItemIndex = 0;

        VPMenuDisplayOptionsMenu.Items.Add(new ButtonMenuItem {
            Text = "Toggle AA"
        });
        VPMenuDisplayOptionsMenu.Items[displayOptionsSubItemIndex].Click += delegate
        {
            ovpSettings.aA(!ovpSettings.aA());
            updateViewport();
        };
        displayOptionsSubItemIndex++;
        VPMenuDisplayOptionsMenu.Items.Add(new ButtonMenuItem {
            Text = "Toggle Fill"
        });
        VPMenuDisplayOptionsMenu.Items[displayOptionsSubItemIndex].Click += delegate
        {
            ovpSettings.drawFilled(!ovpSettings.drawFilled());
            updateViewport();
        };
        displayOptionsSubItemIndex++;
        VPMenuDisplayOptionsMenu.Items.Add(new ButtonMenuItem {
            Text = "Toggle Points"
        });
        VPMenuDisplayOptionsMenu.Items[displayOptionsSubItemIndex].Click += delegate
        {
            ovpSettings.drawPoints(!ovpSettings.drawPoints());
            updateViewport();
        };
        displayOptionsSubItemIndex++;

        {
            if (Driver.ovpSettings.isLocked())
            {
                vp_menu.Items.Add(new ButtonMenuItem {
                    Text = "Thaw"
                });
            }
            else
            {
                vp_menu.Items.Add(new ButtonMenuItem {
                    Text = "Freeze"
                });
            }
            vp_menu.Items[itemIndex].Click += delegate
            {
                Driver.freeze_thaw();
                updateViewport();
            };
            itemIndex++;
            vp_menu.Items.AddSeparator();
            itemIndex++;
            vp_menu.Items.Add(new ButtonMenuItem {
                Text = "Save bookmark"
            });
            vp_menu.Items[itemIndex].Click += delegate
            {
                Driver.saveLocation();
            };
            itemIndex++;
            vp_menu.Items.Add(new ButtonMenuItem {
                Text = "Load bookmark"
            });
            vp_menu.Items[itemIndex].Click += delegate
            {
                Driver.loadLocation();
            };
            vp_menu.Items[itemIndex].Enabled = Driver.savedLocation_valid switch
            {
                false => false,
                _ => vp_menu.Items[itemIndex].Enabled
            };
            itemIndex++;
        }
        vp_menu.Items.AddSeparator();
        itemIndex++;
        vp_menu.Items.Add(new ButtonMenuItem {
            Text = "Zoom Extents"
        });
        vp_menu.Items[itemIndex].Click += delegate
        {
            Driver.zoomExtents(0);
        };
        itemIndex++;
        vp_menu.Items.AddSeparator();
        itemIndex++;
        vp_menu.Items.Add(new ButtonMenuItem {
            Text = "Zoom In"
        });
        vp_menu.Items[itemIndex].Click += delegate
        {
            Driver.zoomIn(-1);
            updateViewport();
        };
        itemIndex++;

        ButtonMenuItem VPMenuZoomInMenu = vp_menu.Items.GetSubmenu("Fast Zoom In");

        itemIndex++;
        int zoomInSubItemIndex = 0;

        VPMenuZoomInMenu.Items.Add(new ButtonMenuItem {
            Text = "Zoom In (x5)"
        });
        VPMenuZoomInMenu.Items[zoomInSubItemIndex].Click += delegate
        {
            Driver.zoomIn(-50);
            updateViewport();
        };
        zoomInSubItemIndex++;
        VPMenuZoomInMenu.Items.Add(new ButtonMenuItem {
            Text = "Zoom In (x10)"
        });
        VPMenuZoomInMenu.Items[zoomInSubItemIndex].Click += delegate
        {
            Driver.zoomIn(-100);
            updateViewport();
        };
        zoomInSubItemIndex++;
        VPMenuZoomInMenu.Items.Add(new ButtonMenuItem {
            Text = "Zoom In (x50)"
        });
        VPMenuZoomInMenu.Items[zoomInSubItemIndex].Click += delegate
        {
            Driver.zoomIn(-500);
            updateViewport();
        };
        zoomInSubItemIndex++;
        VPMenuZoomInMenu.Items.Add(new ButtonMenuItem {
            Text = "Zoom In (x100)"
        });
        VPMenuZoomInMenu.Items[zoomInSubItemIndex].Click += delegate
        {
            Driver.zoomIn(-1000);
            updateViewport();
        };
        zoomInSubItemIndex++;

        vp_menu.Items.AddSeparator();
        itemIndex++;

        vp_menu.Items.Add(new ButtonMenuItem {
            Text = "Zoom Out"
        });
        vp_menu.Items[itemIndex].Click += delegate
        {
            Driver.zoomOut(-1);
            updateViewport();
        };
        itemIndex++;

        ButtonMenuItem VPMenuZoomOutMenu = vp_menu.Items.GetSubmenu("Fast Zoom Out");

        itemIndex++;
        int zoomOutSubItemIndex = 0;

        VPMenuZoomOutMenu.Items.Add(new ButtonMenuItem {
            Text = "Zoom Out (x5)"
        });
        VPMenuZoomOutMenu.Items[zoomOutSubItemIndex].Click += delegate
        {
            Driver.zoomOut(-50);
            updateViewport();
        };
        zoomOutSubItemIndex++;
        VPMenuZoomOutMenu.Items.Add(new ButtonMenuItem {
            Text = "Zoom Out (x10)"
        });
        VPMenuZoomOutMenu.Items[zoomOutSubItemIndex].Click += delegate
        {
            Driver.zoomOut(-100);
            updateViewport();
        };
        zoomOutSubItemIndex++;
        VPMenuZoomOutMenu.Items.Add(new ButtonMenuItem {
            Text = "Zoom Out (x50)"
        });
        VPMenuZoomOutMenu.Items[zoomOutSubItemIndex].Click += delegate
        {
            Driver.zoomOut(-500);
            updateViewport();
        };
        zoomOutSubItemIndex++;
        VPMenuZoomOutMenu.Items.Add(new ButtonMenuItem {
            Text = "Zoom Out (x100)"
        });
        VPMenuZoomOutMenu.Items[zoomOutSubItemIndex].Click += delegate
        {
            Driver.zoomOut(-1000);
            updateViewport();
        };
        zoomOutSubItemIndex++;

        Driver.setContextMenu(ref vp_menu);
    }