Ejemplo n.º 1
0
        private void MouseClickOnMap(Object s, GLMouseEventArgs e)
        {
            int distmovedsq = gl3dcontroller.MouseMovedSq(e);

            if (distmovedsq >= 4)
            {
                System.Diagnostics.Debug.WriteLine($"Moved mouse {distmovedsq}, reject click");
                return;
            }
            //  System.Diagnostics.Debug.WriteLine("map click");
            Object item = FindObjectOnMap(e.ViewportLocation);

            if (item != null)
            {
                if (e.Button == GLMouseEventArgs.MouseButtons.Left)
                {
                    if (item is HistoryEntry)
                    {
                        travelpath.SetSystem(item as HistoryEntry);
                    }
                    var nl = NameLocationDescription(item);
                    System.Diagnostics.Debug.WriteLine("Click on and slew to " + nl.Item1);
                    SetEntryText(nl.Item1);
                    gl3dcontroller.SlewToPosition(nl.Item2, -1);
                }
                else if (e.Button == GLMouseEventArgs.MouseButtons.Right)
                {
                    rightclickmenu.Tag = item;
                    rightclickmenu.Show(displaycontrol, e.Location);
                }
            }
        }
Ejemplo n.º 2
0
        private void MouseClickOnMap(Object s, GLMouseEventArgs e)
        {
            int distmovedsq = gl3dcontroller.MouseMovedSq(e);        //3dcontroller is monitoring mouse movements

            if (distmovedsq < 4)
            {
                var geo = findshader.GetShader <GLPLGeoShaderFindTriangles>(OpenTK.Graphics.OpenGL4.ShaderType.GeometryShader);
                geo.SetScreenCoords(e.ViewportLocation, matrixcalc.ViewPort.Size);

                rifind.Execute(findshader, glwfc.RenderState);

                var res = geo.GetResult();
                if (res != null)
                {
                    for (int i = 0; i < res.Length; i++)
                    {
                        System.Diagnostics.Debug.WriteLine(i + " = " + res[i]);
                    }

                    if (e.Button == GLMouseEventArgs.MouseButtons.Left)
                    {
                        track = (int)res[0].Y;
                    }
                    else if (e.Button == GLMouseEventArgs.MouseButtons.Right)
                    {
                        rightclickmenubody.Tag = (int)res[0].Y;
                        rightclickmenubody.Show(displaycontrol, e.Location);
                    }
                }
                else
                {
                    if (e.Button == GLMouseEventArgs.MouseButtons.Right)
                    {
                        rightclickmenuscreen.Show(displaycontrol, e.Location);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            Closed += ShaderTest_Closed;

            items.Add(new GLMatrixCalcUniformBlock(), "MCUB");      // create a matrix uniform block

            int front = -20000, back = front + 90000, left = -45000, right = left + 90000, vsize = 2000;

            Vector4[] displaylines = new Vector4[]
            {
                new Vector4(left, -vsize, front, 1), new Vector4(left, +vsize, front, 1),
                new Vector4(left, +vsize, front, 1), new Vector4(right, +vsize, front, 1),
                new Vector4(right, +vsize, front, 1), new Vector4(right, -vsize, front, 1),
                new Vector4(right, -vsize, front, 1), new Vector4(left, -vsize, front, 1),

                new Vector4(left, -vsize, back, 1), new Vector4(left, +vsize, back, 1),
                new Vector4(left, +vsize, back, 1), new Vector4(right, +vsize, back, 1),
                new Vector4(right, +vsize, back, 1), new Vector4(right, -vsize, back, 1),
                new Vector4(right, -vsize, back, 1), new Vector4(left, -vsize, back, 1),

                new Vector4(left, -vsize, front, 1), new Vector4(left, -vsize, back, 1),
                new Vector4(left, +vsize, front, 1), new Vector4(left, +vsize, back, 1),
                new Vector4(right, -vsize, front, 1), new Vector4(right, -vsize, back, 1),
                new Vector4(right, +vsize, front, 1), new Vector4(right, +vsize, back, 1),
            };

            GLRenderState rl       = GLRenderState.Lines(1);

            {
                items.Add(new GLFixedShader(System.Drawing.Color.Yellow), "LINEYELLOW");
                rObjects.Add(items.Shader("LINEYELLOW"), GLRenderableItem.CreateVector4(items, PrimitiveType.Lines, rl, displaylines));
            }

            float h = 0;

            if (h != -1)
            {
                items.Add(new GLColorShaderWorld(), "COS-1L");

                int   dist = 1000;
                Color cr   = Color.FromArgb(100, Color.White);
                rObjects.Add(items.Shader("COS-1L"),    // horizontal
                             GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, rl,
                                                                  GLShapeObjectFactory.CreateLines(new Vector3(left, h, front), new Vector3(left, h, back), new Vector3(dist, 0, 0), (back - front) / dist + 1),
                                                                  new Color4[] { cr })
                             );

                rObjects.Add(items.Shader("COS-1L"),
                             GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, rl,
                                                                  GLShapeObjectFactory.CreateLines(new Vector3(left, h, front), new Vector3(right, h, front), new Vector3(0, 0, dist), (right - left) / dist + 1),
                                                                  new Color4[] { cr })
                             );
            }

            GLMatrixCalc mc = new GLMatrixCalc();

            mc.PerspectiveNearZDistance = 1f;
            mc.PerspectiveFarZDistance  = 500000f;

            if (true)
            {
                bool testform1 = true;

                mc.ResizeViewPort(this, glwfc.Size);                               // must establish size before starting

                displaycontrol           = new GLControlDisplay(items, glwfc, mc); // hook form to the window - its the master, it takes its size fro mc.ScreenCoordMax
                displaycontrol.Focusable = true;                                   // we want to be able to focus and receive key presses.
                displaycontrol.Name      = "displaycontrol";

                if (testform1)
                {
                    GLForm pform = new GLForm("Form1", "GL Menu demonstration", new Rectangle(10, 10, 600, 200));
                    displaycontrol.Add(pform);

                    if (true)
                    {
                        GLMenuStrip menubar = new GLMenuStrip("Menubar", new Rectangle(0, 0, 500, 24));
                        menubar.AutoOpenDelay      = 1000;
                        menubar.Font               = new Font("Euro Caps", 12);
                        menubar.Dock               = DockingType.Top;
                        menubar.SubMenuBorderWidth = 1;

                        GLMenuItem l1 = new GLMenuItem("MI-0A", "MenuA");
                        menubar.Add(l1);

                        GLMenuItem l1a = new GLMenuItem("A-1", "MenuA-1");
                        GLMenuItem l1b = new GLMenuItem("A-2", "MenuA-2");
                        l1b.CheckOnClick = true;
                        l1b.Checked      = true;
                        GLMenuItem l1c = new GLMenuItem("A-3", "MenuA-3")
                        {
                            Image = Properties.Resources.GoToHomeSystem
                        };
                        l1c.CheckOnClick = true;
                        l1.SubMenuItems  = new List <GLBaseControl>()
                        {
                            l1a, l1b, l1c
                        };

                        GLMenuItem l1a1 = new GLMenuItem("A-1-1", "MenuA-1-1");
                        GLMenuItem l1a2 = new GLMenuItem("A-1-2", "MenuA-1-2");

                        GLMenuItem l1a21 = new GLMenuItem("A-1-2-1", "MenuA-1-2-1");
                        GLMenuItem l1a22 = new GLMenuItem("A-1-2-2", "MenuA-1-2-2");
                        l1a2.SubMenuItems = new List <GLBaseControl>()
                        {
                            l1a21, l1a22
                        };

                        GLCheckBox l1a3 = new GLCheckBox("A-1-3", new Rectangle(0, 0, 0, 0), "CheckBox A-1-3");
                        l1a3.CheckOnClick  = true;
                        l1a3.CheckChanged += (bc) => { menubar.CloseMenus(); };     // need to associate check changed with closing menus - optional

                        GLComboBox l1a4 = new GLComboBox("A-1-4", new Rectangle(0, 0, 0, 0), new List <string>()
                        {
                            "one", "two", "three"
                        });
                        l1a4.SelectedIndexChanged += (c) => { menubar.CloseMenus(); };
                        l1a4.DisableChangeKeys     = true;
                        l1a.SubMenuItems           = new List <GLBaseControl>()
                        {
                            l1a1, l1a2, l1a3, l1a4
                        };

                        GLMenuItem l2 = new GLMenuItem("MI-0B", "MenuB");
                        menubar.Add(l2);

                        GLMenuItem l2a = new GLMenuItem("B-1", "MenuB-1");
                        l2a.Click += (s) => { System.Diagnostics.Debug.WriteLine("Clicked Menu " + s.Name); };
                        GLMenuItem l2b = new GLMenuItem("B-2", "MenuB-2");
                        l2.SubMenuItems = new List <GLBaseControl>()
                        {
                            l2a, l2b
                        };

                        GLMenuItem l3 = new GLMenuItem("MI-0C", "MenuC");
                        menubar.Add(l3);

                        pform.Add(menubar);
                    }
                }

                if (true)
                {
                    GLContextMenu ctx1, ctx2;

                    ctx1 = new GLContextMenu("CM1");
                    GLMenuItem cm1 = new GLMenuItem("CM1A", "Menu-1");
                    cm1.CheckOnClick = true;

                    GLMenuItem cm2 = new GLMenuItem("CM1B", "Menu-2");
                    cm2.CheckOnClick = true;
                    GLMenuItem cm3 = new GLMenuItem("CM1C", "Menu-3");

                    GLMenuItem l1a1 = new GLMenuItem("CM1C-1", "Menu-1-1");
                    l1a1.CheckOnClick = true;
                    GLMenuItem l1a2 = new GLMenuItem("CM1C-2", "MenuA-1-2");
                    GLCheckBox l1a3 = new GLCheckBox("CM1C-3", new Rectangle(0, 0, 0, 0), "CheckBox A-1-3");
                    l1a3.CheckOnClick = true;
                    cm3.SubMenuItems  = new List <GLBaseControl>()
                    {
                        l1a1, l1a2, l1a3
                    };

                    int count = 0;
                    ctx1.Opening += (c1, c2) =>
                    {
                        bool on = count++ % 2 == 0;
                        System.Diagnostics.Debug.WriteLine($"Set cm2 state {on}");
                        cm2.Visible = on;
                    };

                    ctx1.Add(cm1);
                    ctx1.Add(cm2);
                    ctx1.Add(cm3);

                    Color tc = Color.Orange;
                    ctx2 = new GLContextMenu("CM1", new GLMenuItem[] {
                        new GLMenuItem("CM1A", "MenuR1")
                        {
                            CheckOnClick = true, ForeColor = tc
                        },
                        new GLMenuItem("CM1B", "MenuR2")
                        {
                            CheckOnClick = true, Enabled = false, ForeColor = tc
                        },
                        new GLMenuItem("CM1C", "MenuR3")
                        {
                            CheckOnClick = true
                        },
                        new GLMenuItem("CM1C", "MenuR4")
                        {
                            CheckOnClick = true
                        },
                        new GLMenuItem("CM1C", "MenuR5")
                        {
                        },
                    });

                    ctx2.Font = new Font("Euro caps", 18f);

                    displaycontrol.MouseClick += (s, ev) =>
                    {
                        if (ev.Button == GLMouseEventArgs.MouseButtons.Left)
                        {
                            System.Diagnostics.Debug.WriteLine($"*********************** OPEN");
                            ctx1.Show(displaycontrol, ev.ScreenCoord);
                        }
                        else if (ev.Button == GLMouseEventArgs.MouseButtons.Right)
                        {
                            ctx2.Show(displaycontrol, ev.ScreenCoord);
                        }
                    };
                }
            }

            gl3dcontroller = new Controller3D();
            gl3dcontroller.ZoomDistance  = 5000F;
            gl3dcontroller.YHoldMovement = true;
            gl3dcontroller.PaintObjects  = Controller3dDraw;

            gl3dcontroller.KeyboardTravelSpeed = (ms, eyedist) =>
            {
                return((float)ms * 10.0f);
            };

            gl3dcontroller.MatrixCalc.InPerspectiveMode = true;

            if (displaycontrol != null)
            {
                gl3dcontroller.Start(mc, displaycontrol, new Vector3(0, 0, 10000), new Vector3(140.75f, 0, 0), 0.5F); // HOOK the 3dcontroller to the form so it gets Form events

                displaycontrol.Paint += (o, ts) =>                                                                    // subscribing after start means we paint over the scene, letting transparency work
                {
                    displaycontrol.Render(glwfc.RenderState, ts);                                                     // we use the same matrix calc as done in controller 3d draw
                };
            }
            else
            {
                gl3dcontroller.Start(glwfc, new Vector3(0, 0, 10000), new Vector3(140.75f, 0, 0), 0.5F);     // HOOK the 3dcontroller to the form so it gets Form events
            }
            systemtimer.Interval = 25;
            systemtimer.Tick    += new EventHandler(SystemTick);
            systemtimer.Start();
        }