public void LibraryProviderSqlite_NavigationWorking()
        {
            StaticData.Instance = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData"));
            MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4));

            LibraryProviderSQLite testProvider = new LibraryProviderSQLite(null, null, null, "Local Library");

            testProvider.DataReloaded += (sender, e) => { dataReloaded = true; };
            Thread.Sleep(3000);             // wait for the library to finish initializing
            UiThread.InvokePendingActions();
            Assert.IsTrue(testProvider.CollectionCount == 0, "Start with a new database for these tests.");
            Assert.IsTrue(testProvider.ItemCount == 3, "Start with a new database for these tests.");

            // create a collection and make sure it is on disk
            dataReloaded = false;             // it has been loaded for the default set of parts
            string collectionName = "Collection1";

            Assert.IsTrue(!NamedCollectionExists(collectionName));             // assert that the record does not exist in the DB
            Assert.IsTrue(dataReloaded == false);
            testProvider.AddCollectionToLibrary(collectionName);
            Assert.IsTrue(testProvider.CollectionCount == 1);
            Assert.IsTrue(dataReloaded == true);
            Assert.IsTrue(NamedCollectionExists(collectionName));             // assert that the record does exist in the DB

            PrintItemWrapper itemAtRoot = testProvider.GetPrintItemWrapperAsync(0).Result;

            // add an item works correctly
            dataReloaded = false;
            Assert.IsTrue(!NamedItemExists(collectionName));
            Assert.IsTrue(dataReloaded == false);

            testProvider.AddFilesToLibrary(new string[] { meshPathAndFileName });
            Thread.Sleep(3000);             // wait for the add to finish
            UiThread.InvokePendingActions();

            Assert.IsTrue(testProvider.ItemCount == 4);
            Assert.IsTrue(dataReloaded == true);
            string fileNameWithExtension = Path.GetFileNameWithoutExtension(meshPathAndFileName);

            Assert.IsTrue(NamedItemExists(fileNameWithExtension));

            // make sure the provider locater is correct

            // remove item works
            dataReloaded = false;
            Assert.IsTrue(dataReloaded == false);
            testProvider.RemoveItem(0);
            Assert.IsTrue(dataReloaded == true);
            Assert.IsTrue(!NamedItemExists(fileNameWithExtension));

            // remove collection gets rid of it
            dataReloaded = false;
            Assert.IsTrue(dataReloaded == false);
            testProvider.RemoveCollection(0);
            Assert.IsTrue(dataReloaded == true);
            Assert.IsTrue(testProvider.CollectionCount == 0);
            Assert.IsTrue(!NamedCollectionExists(collectionName));             // assert that the record does not exist in the DB

            //MatterControlUtilities.RestoreStaticDataAfterTesting(staticDataState, true);
        }
Example #2
0
        public void ToolTipCloseOnLeave()
        {
            TempData     tempData     = new TempData();
            SystemWindow systemWindow = CreateTwoChildWindow(tempData);

            // move into the first widget
            systemWindow.OnMouseMove(new MouseEventArgs(MouseButtons.None, 0, 11, 11, 0));
            UiThread.InvokePendingActions();

            // sleep long enough to show the tool tip
            Thread.Sleep((int)(systemWindow.ToolTipManager.InitialDelay * 1000 + minMsToBias));
            UiThread.InvokePendingActions();

            // make sure the tool tip came up
            Assert.IsTrue(systemWindow.Children.Count == 3);
            Assert.IsTrue(tempData.showCount == 1);
            Assert.IsTrue(systemWindow.ToolTipManager.CurrentText == toolTip1Text);

            // move off the first widget
            systemWindow.OnMouseMove(new MouseEventArgs(MouseButtons.None, 0, 9, 9, 0));
            Thread.Sleep(minMsTimeToRespond);             // sleep enough for the tool tip to want to respond
            UiThread.InvokePendingActions();

            // make sure the tool tip went away
            Assert.IsTrue(systemWindow.Children.Count == 2);
            Assert.IsTrue(tempData.popCount == 1);
            Assert.IsTrue(systemWindow.ToolTipManager.CurrentText == "");
        }
Example #3
0
        public void ToolTipInitialOpenTests()
        {
            TempData tempData = new TempData();
            // test simple open then wait for pop
            SystemWindow systemWindow = CreateTwoChildWindow(tempData);

            // move into the first widget
            systemWindow.OnMouseMove(new MouseEventArgs(MouseButtons.None, 0, 11, 11, 0));
            UiThread.InvokePendingActions();

            // show that initialy we don't have a tooltip
            Assert.IsTrue(systemWindow.Children.Count == 2);

            // sleep 1/2 long enough to show the tool tip
            Thread.Sleep((int)(systemWindow.ToolTipManager.InitialDelay / 2 * 1000 + minMsToBias));
            UiThread.InvokePendingActions();

            // make sure it is still not up
            Assert.IsTrue(systemWindow.Children.Count == 2);
            Assert.IsTrue(tempData.showCount == 0);
            Assert.IsTrue(systemWindow.ToolTipManager.CurrentText == "");

            // sleep 1/2 long enough to show the tool tip
            Thread.Sleep((int)(systemWindow.ToolTipManager.InitialDelay / 2 * 1000 + minMsToBias));
            UiThread.InvokePendingActions();

            // make sure the tool tip came up
            Assert.IsTrue(systemWindow.Children.Count == 3);
            Assert.IsTrue(tempData.showCount == 1);
            Assert.IsTrue(systemWindow.ToolTipManager.CurrentText == toolTip1Text);

            // wait 1/2 long enough for the tool tip to go away
            Thread.Sleep((int)(systemWindow.ToolTipManager.AutoPopDelay * 1000 / 2 + minMsToBias));
            UiThread.InvokePendingActions();

            // make sure the tool did not go away
            Assert.IsTrue(systemWindow.Children.Count == 3);
            Assert.IsTrue(tempData.popCount == 0);
            Assert.IsTrue(systemWindow.ToolTipManager.CurrentText == toolTip1Text);

            // wait 1/2 long enough for the tool tip to go away
            Thread.Sleep((int)(systemWindow.ToolTipManager.AutoPopDelay * 1000 / 2 + minMsToBias));
            UiThread.InvokePendingActions();

            // make sure the tool tip went away
            Assert.IsTrue(systemWindow.Children.Count == 2);
            Assert.IsTrue(tempData.popCount == 1);
            Assert.IsTrue(systemWindow.ToolTipManager.CurrentText == "");
        }
Example #4
0
        private static SystemWindow CreateTwoChildWindow(TempData tempData)
        {
            SystemWindow systemWindow = new SystemWindow(200, 200);
            GuiWidget    toolTip1     = new GuiWidget()
            {
                LocalBounds = new RectangleDouble(10, 10, 20, 20),
                ToolTipText = toolTip1Text,
            };
            GuiWidget toolTip2 = new GuiWidget()
            {
                LocalBounds = new RectangleDouble(30, 30, 40, 40),
                ToolTipText = toolTip2Text,
            };

            systemWindow.ToolTipManager.ToolTipShown += (sender, stringEvent) =>
            {
                tempData.showCount++;
                tempData.lastShownText = stringEvent.Data;
            };

            systemWindow.ToolTipManager.ToolTipPop += (sender, e) =>
            {
                tempData.popCount++;
            };

            systemWindow.AddChild(toolTip1);
            systemWindow.AddChild(toolTip2);

            Assert.IsTrue(systemWindow.Children.Count == 2);

            // make sure we start out with only the widgets (no tool tip)
            systemWindow.OnMouseMove(new MouseEventArgs(MouseButtons.None, 0, 0, 0, 0));
            UiThread.InvokePendingActions();
            Assert.IsTrue(systemWindow.Children.Count == 2);

            tempData.lastShownText = "";
            tempData.showCount     = 0;
            tempData.popCount      = 0;

            return(systemWindow);
        }
Example #5
0
        public void MoveFastFromToolTipToToolTip()
        {
            TempData     tempData     = new TempData();
            SystemWindow systemWindow = CreateTwoChildWindow(tempData);

            // move into the first widget
            systemWindow.OnMouseMove(new MouseEventArgs(MouseButtons.None, 0, 11, 11, 0));
            UiThread.InvokePendingActions();

            // sleep long enough to show the tool tip
            Thread.Sleep((int)(systemWindow.ToolTipManager.InitialDelay * 1000 + minMsToBias));
            UiThread.InvokePendingActions();

            // make sure the tool tip came up
            Assert.IsTrue(systemWindow.Children.Count == 3);
            Assert.IsTrue(tempData.showCount == 1);
            Assert.IsTrue(systemWindow.ToolTipManager.CurrentText == toolTip1Text);

            // wait 1/2 long enough for the tool tip to go away
            Thread.Sleep((int)(systemWindow.ToolTipManager.AutoPopDelay * 1000 / 2 + minMsToBias));
            UiThread.InvokePendingActions();

            // move onto the other widget
            systemWindow.OnMouseMove(new MouseEventArgs(MouseButtons.None, 0, 31, 31, 0));
            Thread.Sleep(minMsTimeToRespond);             // sleep enough for the tool tip to want to respond
            UiThread.InvokePendingActions();

            // make sure the first tool tip went away
            Assert.IsTrue(systemWindow.Children.Count == 2);
            Assert.IsTrue(tempData.popCount == 1);
            Assert.IsTrue(systemWindow.ToolTipManager.CurrentText == "");

            // wait long enough for the second tool tip to come up
            Thread.Sleep((int)(systemWindow.ToolTipManager.ReshowDelay * 1000 + minMsToBias));
            UiThread.InvokePendingActions();

            // make sure the tool tip 2 came up
            Assert.IsTrue(systemWindow.Children.Count == 3);
            Assert.IsTrue(tempData.showCount == 2);
            Assert.IsTrue(systemWindow.ToolTipManager.CurrentText == toolTip2Text);
        }
Example #6
0
        /// <summary>
        /// Creates or connects a PlatformWindow to the given SystemWindow
        /// </summary>
        public void ShowSystemWindow(SystemWindow systemWindow)
        {
            if (_graphicsDevice == null)
            {
                WindowCreateInfo windowCI = new WindowCreateInfo()
                {
                    X            = 100,
                    Y            = 100,
                    WindowWidth  = 960,
                    WindowHeight = 540,
                    WindowTitle  = "Veldrid Tutorial",
                };

                Sdl2Window window = VeldridStartup.CreateWindow(ref windowCI);

                veldridPlatformWindow = new VeldridSystemWindow(this);

                systemWindow.PlatformWindow = veldridPlatformWindow;

                _graphicsDevice = VeldridStartup.CreateGraphicsDevice(window, GraphicsBackend.OpenGL);

                window.KeyDown += (KeyEvent keyEvent) =>
                {
                    systemWindow.OnKeyDown(
                        new KeyEventArgs((Keys)keyEvent.Key));
                };

                window.KeyUp += (KeyEvent keyEvent) =>
                {
                    systemWindow.OnKeyUp(
                        new KeyEventArgs((Keys)keyEvent.Key));
                };

                // setup our veldrid gl immediate mode emulator
                var veldridGl = new VeldridGL();
                MatterHackers.RenderOpenGl.OpenGl.GL.Instance = veldridGl;
                veldridGl.CreateResources(_graphicsDevice);

                ShaderData.Instance.CreateResources(_graphicsDevice);

                long runNextMs = 0;

                VectorMath.Vector2 lastPosition = VectorMath.Vector2.Zero;
                while (window.Exists)
                {
                    InputSnapshot inputSnapshot = window.PumpEvents();

                    var position = new VectorMath.Vector2(inputSnapshot.MousePosition.X, window.Height - inputSnapshot.MousePosition.Y);

                    if (lastPosition != position)
                    {
                        systemWindow.OnMouseMove(new MouseEventArgs(MouseButtons.None, 0, position.X, position.Y, 0));
                    }

                    if (inputSnapshot.WheelDelta != 0)
                    {
                        systemWindow.OnMouseWheel(new MouseEventArgs(MouseButtons.None, 0, position.X, position.Y, (int)inputSnapshot.WheelDelta * 120));
                    }

                    if (runNextMs <= UiThread.CurrentTimerMs)
                    {
                        UiThread.InvokePendingActions();

                        runNextMs = UiThread.CurrentTimerMs + 10;
                    }

                    foreach (var mouseEvent in inputSnapshot.MouseEvents)
                    {
                        MouseButtons buttons = MapMouseButtons(mouseEvent.MouseButton);
                        if (inputSnapshot.IsMouseDown(mouseEvent.MouseButton))
                        {
                            systemWindow.OnMouseDown(new MouseEventArgs(buttons, 1, position.X, position.Y, 0));
                        }
                        else
                        {
                            systemWindow.OnMouseUp(new MouseEventArgs(buttons, 0, position.X, position.Y, 0));
                        }
                    }

                    systemWindow.Width  = veldridPlatformWindow.Width = window.Width;
                    systemWindow.Height = veldridPlatformWindow.Height = window.Height;

                    var graphics2D = veldridPlatformWindow.NewGraphics2D();

                    // We must call on draw background as this is effectively our child and that is the way it is done in GuiWidget.
                    // Parents call child OnDrawBackground before they call OnDraw
                    systemWindow.OnDrawBackground(graphics2D);
                    systemWindow.OnDraw(graphics2D);

                    _graphicsDevice.SwapBuffers();



                    // Copy to screen/backbuffer

                    //window.PumpEvents();
                }

                // MyOpenGLView.RootGLView.ShowSystemWindow(systemWindow);
                veldridGl.DisposeResources();
                ShaderData.Instance.DisposeResources();
            }

            MouseButtons MapMouseButtons(MouseButton mouseButton)
            {
                switch (mouseButton)
                {
                case MouseButton.Left:
                    return(MouseButtons.Left);

                case MouseButton.Middle:
                    break;

                case MouseButton.Right:
                    break;

                case MouseButton.Button1:
                    break;

                case MouseButton.Button2:
                    break;

                case MouseButton.Button3:
                    break;

                case MouseButton.Button4:
                    break;

                case MouseButton.Button5:
                    break;

                case MouseButton.Button6:
                    break;

                case MouseButton.Button7:
                    break;

                case MouseButton.Button8:
                    break;

                case MouseButton.Button9:
                    break;

                case MouseButton.LastButton:
                    break;
                }

                return(MouseButtons.None);
            }
        }
Example #7
0
        public void ListMenuTests()
        {
            string menuSelected = "";

            GuiWidget  container = new GuiWidget(400, 400);
            TextWidget menueView = new TextWidget("Edit");
            Menu       listMenu  = new Menu(menueView);

            listMenu.OriginRelativeParent = new Vector2(10, 300);

            MenuItem cutMenuItem = new MenuItem(new TextWidget("Cut"));

            cutMenuItem.Selected += (sender, e) => { menuSelected = "Cut"; };
            listMenu.MenuItems.Add(cutMenuItem);

            MenuItem copyMenuItem = new MenuItem(new TextWidget("Copy"));

            copyMenuItem.Selected += (sender, e) => { menuSelected = "Copy"; };
            listMenu.MenuItems.Add(copyMenuItem);

            MenuItem pastMenuItem = new MenuItem(new TextWidget("Paste"));

            pastMenuItem.Selected += (sender, e) => { menuSelected = "Paste"; };
            listMenu.MenuItems.Add(pastMenuItem);

            container.AddChild(listMenu);

            Assert.IsTrue(!listMenu.IsOpen);

            // open the menu
            container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 11, 300, 0));
            Assert.IsTrue(!listMenu.IsOpen);
            container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 11, 300, 0));
            UiThread.InvokePendingActions();
            Assert.IsTrue(listMenu.IsOpen);

            // all the menu itmes should be added to the open menu
            Assert.IsTrue(cutMenuItem.Parent != null);
            Assert.IsTrue(copyMenuItem.Parent != null);
            Assert.IsTrue(pastMenuItem.Parent != null);

            // click on menu again to close
            container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 11, 300, 0));
            UiThread.InvokePendingActions();
            Assert.IsTrue(!listMenu.IsOpen);
            // all the mune itmes should be removed from the closed menu
            Assert.IsTrue(cutMenuItem.Parent == null);
            Assert.IsTrue(copyMenuItem.Parent == null);
            Assert.IsTrue(pastMenuItem.Parent == null);

            container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 11, 300, 0));
            UiThread.InvokePendingActions();
            Assert.IsTrue(!listMenu.IsOpen);

            // all the menu itmes should be removed from the closed menu
            Assert.IsTrue(cutMenuItem.Parent == null);
            Assert.IsTrue(copyMenuItem.Parent == null);
            Assert.IsTrue(pastMenuItem.Parent == null);

            // open the menu
            container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 11, 300, 0));
            UiThread.InvokePendingActions();
            Assert.IsTrue(!listMenu.IsOpen);
            container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 11, 300, 0));
            UiThread.InvokePendingActions();
            Assert.IsTrue(listMenu.IsOpen);
            // all the menu itmes should be added to the open menu
            Assert.IsTrue(cutMenuItem.Parent != null);
            Assert.IsTrue(copyMenuItem.Parent != null);
            Assert.IsTrue(pastMenuItem.Parent != null);

            // click off menu to close
            container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 5, 299, 0));
            UiThread.InvokePendingActions();
            Assert.IsTrue(!listMenu.IsOpen);
            // all the mune itmes should be removed from the closed menu
            Assert.IsTrue(cutMenuItem.Parent == null);
            Assert.IsTrue(copyMenuItem.Parent == null);
            Assert.IsTrue(pastMenuItem.Parent == null);
            container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 5, 299, 0));
            UiThread.InvokePendingActions();
            Assert.IsTrue(!listMenu.IsOpen);

            // open the menu again
            container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 11, 300, 0));
            UiThread.InvokePendingActions();
            Assert.IsTrue(!listMenu.IsOpen);
            container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 11, 300, 0));
            UiThread.InvokePendingActions();
            Assert.IsTrue(listMenu.IsOpen);

            // select the first item
            container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 11, 290, 0));
            UiThread.InvokePendingActions();
            Assert.IsTrue(listMenu.IsOpen);
            container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 11, 290, 0));
            UiThread.InvokePendingActions();
            Assert.IsTrue(!listMenu.IsOpen);
            Assert.IsTrue(menuSelected == "Cut");

            // open the menu
            container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 11, 300, 0));
            UiThread.InvokePendingActions();
            Assert.IsTrue(!listMenu.IsOpen);
            container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 11, 300, 0));
            UiThread.InvokePendingActions();
            Assert.IsTrue(listMenu.IsOpen);

            // select the second item
            menuSelected = "";
            container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 11, 275, 0));
            UiThread.InvokePendingActions();
            Assert.IsTrue(listMenu.IsOpen);
            container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 11, 275, 0));
            UiThread.InvokePendingActions();
            Assert.IsTrue(!listMenu.IsOpen);
            Assert.IsTrue(menuSelected == "Copy");

            // make sure click down then move off item does not select it.
            menuSelected = "";
            // open the menu
            container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 11, 300, 0));
            UiThread.InvokePendingActions();
            Assert.IsTrue(!listMenu.IsOpen);
            container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 11, 300, 0));
            UiThread.InvokePendingActions();
            Assert.IsTrue(listMenu.IsOpen);

            // click down on the first item
            container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 11, 290, 0));
            UiThread.InvokePendingActions();
            Assert.IsTrue(listMenu.IsOpen);
            // move off of it
            container.OnMouseMove(new MouseEventArgs(MouseButtons.None, 1, 5, 290, 0));
            UiThread.InvokePendingActions();
            container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 5, 290, 0));
            UiThread.InvokePendingActions();
            Assert.IsTrue(!listMenu.IsOpen);
            Assert.IsTrue(menuSelected == "");

            // make sure click down and then move to new items selects the new item.

            // click and draw down to item should work as well
        }
Example #8
0
        public void DropDownListTests()
        {
            string menuSelected = "";

            GuiWidget    container = new GuiWidget(400, 400);
            DropDownList listMenu  = new DropDownList("- Select Something -", RGBA_Bytes.Black, RGBA_Bytes.Gray);

            listMenu.OriginRelativeParent = new Vector2(10, 300);

            MenuItem cutMenuItem = new MenuItem(new TextWidget("Cut"));

            cutMenuItem.Selected += (sender, e) => { menuSelected = "Cut"; };
            listMenu.MenuItems.Add(cutMenuItem);

            MenuItem copyMenuItem = new MenuItem(new TextWidget("Copy"));

            copyMenuItem.Selected += (sender, e) => { menuSelected = "Copy"; };
            listMenu.MenuItems.Add(copyMenuItem);

            MenuItem pastMenuItem = new MenuItem(new TextWidget("Paste"));

            pastMenuItem.Selected += (sender, e) => { menuSelected = "Paste"; };
            listMenu.MenuItems.Add(pastMenuItem);

            container.AddChild(listMenu);

            Assert.IsTrue(!listMenu.IsOpen);

            // open the menu
            container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 11, 300, 0));
            UiThread.InvokePendingActions();
            Assert.IsTrue(!listMenu.IsOpen);
            container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 11, 300, 0));
            UiThread.InvokePendingActions();
            Assert.IsTrue(listMenu.IsOpen);

            // click on menu again to close
            container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 11, 300, 0));
            container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 11, 300, 0));
            UiThread.InvokePendingActions();
            Assert.IsTrue(!listMenu.IsOpen);

            // open the menu
            container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 11, 300, 0));
            UiThread.InvokePendingActions();
            Assert.IsTrue(!listMenu.IsOpen);
            container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 11, 300, 0));
            UiThread.InvokePendingActions();
            Assert.IsTrue(listMenu.IsOpen);

            // click off menu to close
            container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 5, 299, 0));
            container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 5, 299, 0));
            UiThread.InvokePendingActions();
            Assert.IsTrue(!listMenu.IsOpen);

            // open the menu
            container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 11, 300, 0));
            UiThread.InvokePendingActions();
            Assert.IsTrue(!listMenu.IsOpen);
            container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 11, 300, 0));
            UiThread.InvokePendingActions();
            Assert.IsTrue(listMenu.IsOpen);

            // select the first item
            container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 11, 290, 0));
            UiThread.InvokePendingActions();
            Assert.IsTrue(listMenu.IsOpen);
            container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 11, 290, 0));
            UiThread.InvokePendingActions();
            Assert.IsTrue(!listMenu.IsOpen);
            Assert.IsTrue(menuSelected == "Cut");

            // open the menu
            container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 11, 300, 0));
            UiThread.InvokePendingActions();
            Assert.IsTrue(!listMenu.IsOpen);
            container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 11, 300, 0));
            UiThread.InvokePendingActions();
            Assert.IsTrue(listMenu.IsOpen);

            // select the second item
            menuSelected = "";
            container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 11, 275, 0));
            UiThread.InvokePendingActions();
            Assert.IsTrue(listMenu.IsOpen);
            container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 11, 275, 0));
            UiThread.InvokePendingActions();
            Assert.IsTrue(!listMenu.IsOpen);
            Assert.IsTrue(menuSelected == "Copy");

            // make sure click down then move off item does not select it.
            menuSelected = "";
            // open the menu
            container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 11, 300, 0));
            UiThread.InvokePendingActions();
            Assert.IsTrue(!listMenu.IsOpen);
            container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 11, 300, 0));
            UiThread.InvokePendingActions();
            Assert.IsTrue(listMenu.IsOpen);

            // click down on the first item
            container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 11, 290, 0));
            UiThread.InvokePendingActions();
            Assert.IsTrue(listMenu.IsOpen);
            // move off of it
            container.OnMouseMove(new MouseEventArgs(MouseButtons.None, 1, 5, 290, 0));
            container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 5, 290, 0));
            UiThread.InvokePendingActions();
            Assert.IsTrue(!listMenu.IsOpen);
            Assert.IsTrue(menuSelected == "");

            // make sure click down and then move to new items selects the new item.

            // click and draw down to item should work as well
        }
Example #9
0
        private void Show()
        {
            // Glfw.WindowHint(Hint.Decorated, false);
            var config = AggContext.Config.GraphicsMode;

            Glfw.WindowHint(Hint.Samples, config.FSAASamples);
            Glfw.WindowHint(Hint.Visible, false);             // this line causing crash on windows tablet
            Glfw.WindowHint(Hint.CocoaRetinaFrameBuffer, true);

            var screenSize = Glfw.PrimaryMonitor.WorkArea;

            // Create window
            if (aggSystemWindow.Maximized)
            {
                aggSystemWindow.Width  = screenSize.Width;
                aggSystemWindow.Height = screenSize.Height - screenSize.Y;
            }

            glfwWindow = Glfw.CreateWindow((int)aggSystemWindow.Width, (int)aggSystemWindow.Height, aggSystemWindow.Title, GLFW.Monitor.None, Window.None);

            Glfw.MakeContextCurrent(glfwWindow);

            // Effectively enables VSYNC by setting to 1.
            Glfw.SwapInterval(1);

            aggSystemWindow.PlatformWindow = this;

            Glfw.SetWindowSizeLimits(glfwWindow,
                                     (int)aggSystemWindow.MinimumSize.X,
                                     (int)aggSystemWindow.MinimumSize.Y,
                                     -1,
                                     -1);

            if (aggSystemWindow.Maximized)
            {
                // TODO: make this right
                Glfw.SetWindowPosition(glfwWindow, 0, 0);
                Glfw.MaximizeWindow(glfwWindow);
            }
            else if (aggSystemWindow.InitialDesktopPosition == new Point2D(-1, -1))
            {
                // Find center position based on window and monitor sizes
                var x = (screenSize.Width - (int)aggSystemWindow.Width) / 2;
                var y = (screenSize.Height - (int)aggSystemWindow.Height) / 2;
                Glfw.SetWindowPosition(glfwWindow, x, y);
            }
            else
            {
                Glfw.SetWindowPosition(glfwWindow,
                                       (int)aggSystemWindow.InitialDesktopPosition.x,
                                       (int)aggSystemWindow.InitialDesktopPosition.y);
            }

            staticThis = this;
            Glfw.SetWindowSizeCallback(glfwWindow, (a, b, c) => staticThis.SizeCallback(a, b, c));
            Glfw.SetWindowMaximizeCallback(glfwWindow, (a, b) => staticThis.MaximizeCallback(a, b));
            Glfw.SetWindowIconifyCallback(glfwWindow, (a, b) => staticThis.IconifyCallback(a, b));

            // Set a key callback
            Glfw.SetKeyCallback(glfwWindow, (a, b, c, d, e) => staticThis.KeyCallback(a, b, c, d, e));
            Glfw.SetCharCallback(glfwWindow, (a, b) => staticThis.CharCallback(a, b));
            Glfw.SetCursorPositionCallback(glfwWindow, (a, b, c) => staticThis.CursorPositionCallback(a, b, c));
            Glfw.SetMouseButtonCallback(glfwWindow, (a, b, c, d) => staticThis.MouseButtonCallback(a, b, c, d));
            Glfw.SetScrollCallback(glfwWindow, (a, b, c) => staticThis.ScrollCallback(a, b, c));
            Glfw.SetCloseCallback(glfwWindow, (a) => staticThis.CloseCallback(a));
            Glfw.SetDropCallback(glfwWindow, (a, b, c) => staticThis.DropCallback(a, b, c));

            var applicationIcon = StaticData.Instance.LoadIcon("application.png");

            if (applicationIcon != null)
            {
                Glfw.SetWindowIcon(glfwWindow,
                                   2,
                                   new Image[]
                {
                    ConvertImageBufferToImage(applicationIcon),
                    ConvertImageBufferToImage(applicationIcon.CreateScaledImage(16, 16))
                });
            }

            // set the gl renderer to the GLFW specific one rather than the OpenTk one
            var glfwGl = new GlfwGL();

            GL.Instance = glfwGl;

            Glfw.ShowWindow(glfwWindow);

            while (!Glfw.WindowShouldClose(glfwWindow))
            {
                // Poll for OS events and swap front/back buffers
                Glfw.PollEvents();
                ConditionalDrawAndRefresh(aggSystemWindow);

                // keep the event thread running
                UiThread.InvokePendingActions();

                // the mac does not report maximize changes correctly
                var maximized = Glfw.GetWindowAttribute(glfwWindow, WindowAttribute.Maximized);
                if (maximized != aggSystemWindow.Maximized)
                {
                    aggSystemWindow.Maximized = maximized;
                }

                Thread.Sleep(1);
            }
        }
Example #10
0
        public void MenuDisabledItemsWorkCorrectly()
        {
            int       item1ClickCount  = 0;
            int       item2ClickCount  = 0;
            int       item3ClickCount  = 0;
            GuiWidget fakeSystemWindow = new GuiWidget(300, 200)
            {
                Name = "SystemWindowBase",
            };

            GuiWidget menuTestContainer = new GuiWidget(300, 200)
            {
                BackgroundColor = RGBA_Bytes.White,
                Name            = "SystemWindow",
            };

            fakeSystemWindow.AddChild(menuTestContainer);

            DropDownList testList = new DropDownList("no selection", RGBA_Bytes.Blue, RGBA_Bytes.Green)
            {
                MenuItemsBackgroundColor      = RGBA_Bytes.White,
                MenuItemsBackgroundHoverColor = RGBA_Bytes.LightGray,
                Name = "menu1",
            };

            var menuItem1 = testList.AddItem("item1");

            menuItem1.Name      = "item1";
            menuItem1.Selected += (s, e) => item1ClickCount++;

            var menuItem2 = testList.AddItem("item2");

            menuItem2.Name      = "item2";
            menuItem2.Selected += (s, e) => item2ClickCount++;

            var menuItem3 = testList.AddItem("item3");

            menuItem3.Name      = "item3";
            menuItem3.Enabled   = false;
            menuItem3.Selected += (s, e) => item3ClickCount++;
            menuTestContainer.AddChild(testList);

            menuTestContainer.AddChild(new GuiWidget(20, 20)
            {
                OriginRelativeParent = new Vector2(160, 150),
                BackgroundColor      = RGBA_Bytes.Cyan,
                Name = "OffMenu",
            });

            int itemHeight = 14;
            // Now do the actions specific to this test. (replace this for new tests)
            {
                Assert.IsTrue(item1ClickCount == 0);
                Assert.IsTrue(item2ClickCount == 0);
                Assert.IsTrue(item3ClickCount == 0);

                // "menu1"
                fakeSystemWindow.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 10, itemHeight / 2 + itemHeight * 0, 0));
                fakeSystemWindow.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 10, itemHeight / 2 + itemHeight * 0, 0));
                UiThread.InvokePendingActions();
                Assert.IsTrue(testList.IsOpen);
                // "item1"
                fakeSystemWindow.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 10, itemHeight / 2 + itemHeight * 3, 0));
                fakeSystemWindow.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 10, itemHeight / 2 + itemHeight * 3, 0));
                UiThread.InvokePendingActions();
                Assert.IsTrue(!testList.IsOpen);
                Assert.IsTrue(item1ClickCount == 1);
                Assert.IsTrue(item2ClickCount == 0);
                Assert.IsTrue(item3ClickCount == 0);

                //testRunner.ClickByName("menu1", 5);
                fakeSystemWindow.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 10, itemHeight / 2 + itemHeight * 0, 0));
                fakeSystemWindow.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 10, itemHeight / 2 + itemHeight * 0, 0));
                UiThread.InvokePendingActions();
                Assert.IsTrue(testList.IsOpen);
                //testRunner.ClickByName("item2", 5);
                fakeSystemWindow.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 10, itemHeight / 2 + itemHeight * 2, 0));
                fakeSystemWindow.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 10, itemHeight / 2 + itemHeight * 2, 0));
                UiThread.InvokePendingActions();
                //testRunner.Wait(.1);
                Assert.IsTrue(!testList.IsOpen);
                Assert.IsTrue(item1ClickCount == 1);
                Assert.IsTrue(item2ClickCount == 1);
                Assert.IsTrue(item3ClickCount == 0);

                //testRunner.ClickByName("menu1", 5);
                fakeSystemWindow.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 10, itemHeight / 2 + itemHeight * 0, 0));
                fakeSystemWindow.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 10, itemHeight / 2 + itemHeight * 0, 0));
                UiThread.InvokePendingActions();
                Assert.IsTrue(testList.IsOpen);
                //testRunner.ClickByName("item3", 5);
                fakeSystemWindow.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 10, itemHeight / 2 + itemHeight * 1, 0));
                fakeSystemWindow.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 10, itemHeight / 2 + itemHeight * 1, 0));
                UiThread.InvokePendingActions();
                //testRunner.Wait(.1);
                Assert.IsTrue(testList.IsOpen, "It should remain open when clicking on a disabled item.");
                Assert.IsTrue(item1ClickCount == 1);
                Assert.IsTrue(item2ClickCount == 1);
                Assert.IsTrue(item3ClickCount == 0);
                //testRunner.ClickByName("item2", 5);
                fakeSystemWindow.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 10, itemHeight / 2 + itemHeight * 2, 0));
                fakeSystemWindow.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 10, itemHeight / 2 + itemHeight * 2, 0));
                UiThread.InvokePendingActions();
                //testRunner.Wait(.1);
                Assert.IsTrue(!testList.IsOpen);
                Assert.IsTrue(item1ClickCount == 1);
                Assert.IsTrue(item2ClickCount == 2);
                Assert.IsTrue(item3ClickCount == 0);

                //testRunner.ClickByName("menu1", 5);
                fakeSystemWindow.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 10, itemHeight / 2 + itemHeight * 0, 0));
                fakeSystemWindow.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 10, itemHeight / 2 + itemHeight * 0, 0));
                UiThread.InvokePendingActions();
                Assert.IsTrue(testList.IsOpen);
                //testRunner.ClickByName("OffMenu", 5);
                fakeSystemWindow.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 200, itemHeight / 2 + itemHeight * 3, 0));
                fakeSystemWindow.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 200, itemHeight / 2 + itemHeight * 3, 0));
                UiThread.InvokePendingActions();
                //testRunner.Wait(.1);
                Assert.IsTrue(!testList.IsOpen);
                Assert.IsTrue(item1ClickCount == 1);
                Assert.IsTrue(item2ClickCount == 2);
                Assert.IsTrue(item3ClickCount == 0);

                //testRunner.ClickByName("menu1", 5);
                fakeSystemWindow.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 10, itemHeight / 2 + itemHeight * 0, 0));
                fakeSystemWindow.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 10, itemHeight / 2 + itemHeight * 0, 0));
                UiThread.InvokePendingActions();
                Assert.IsTrue(testList.IsOpen);
                Assert.IsTrue(item1ClickCount == 1);
                Assert.IsTrue(item2ClickCount == 2);
                Assert.IsTrue(item3ClickCount == 0);
                //testRunner.ClickByName("item3", 5);
                fakeSystemWindow.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 10, itemHeight / 2 + itemHeight * 1, 0));
                fakeSystemWindow.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 10, itemHeight / 2 + itemHeight * 1, 0));
                UiThread.InvokePendingActions();
                Assert.IsTrue(testList.IsOpen);
                Assert.IsTrue(item1ClickCount == 1);
                Assert.IsTrue(item2ClickCount == 2);
                Assert.IsTrue(item3ClickCount == 0);
                //testRunner.ClickByName("OffMenu", 5);
                fakeSystemWindow.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 200, itemHeight / 2 + itemHeight * 3, 0));
                fakeSystemWindow.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 200, itemHeight / 2 + itemHeight * 3, 0));
                UiThread.InvokePendingActions();
                Assert.IsTrue(item1ClickCount == 1);
                Assert.IsTrue(item2ClickCount == 2);
                Assert.IsTrue(item3ClickCount == 0);
                Assert.IsTrue(!testList.IsOpen, "had a bug where after clicking a disabled item would not close clicking outside");
            }

            //testRunner.Wait(1);
        }
        public async Task NoContentChangedOnLoad()
        {
            AggContext.StaticData = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData"));
            MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4));

            bool onIdlePumpActive = true;

            var uiPump = Task.Run(() =>
            {
                while (onIdlePumpActive)
                {
                    UiThread.InvokePendingActions();
                    Thread.Sleep(10);
                }
                ;

                Console.Write("Exiting");
            });

            // Find and validate all ILibraryContainer types, skipping abstract classes
            foreach (var containerType in PluginFinder.FindTypes <ILibraryContainer>().Where(fieldType => !fieldType.IsAbstract))
            {
                var args = new List <object>();

                if (containerType == typeof(FileSystemContainer))
                {
                    args.Add(TestContext.CurrentContext.ResolveProjectPath(4));
                }
                else if (containerType == typeof(RootLibraryContainer))
                {
                    // TODO: Not sure how to test RootLibrary given content loads after MatterControl init is finished, skipping for now
                    continue;
                }

                if (Activator.CreateInstance(containerType, args.ToArray()) is ILibraryContainer libraryContainer)
                {
                    if (libraryContainer is ZipMemoryContainer zipContainer)
                    {
                        zipContainer.Path = TestContext.CurrentContext.ResolveProjectPath(4, "Tests", "TestData", "TestParts", "Batman.zip");
                        zipContainer.RelativeDirectory = Path.GetDirectoryName(zipContainer.Path);
                    }

                    int changedCount = 0;
                    libraryContainer.ContentChanged += (s, e) =>
                    {
                        changedCount++;
                    };

                    await Task.Run(() =>
                    {
                        libraryContainer.Load();
                    });

                    // Allow time for invalid additional reloads
                    await Task.Delay(300);

                    // Verify Reload is called;
                    Assert.AreEqual(0, changedCount, "Expected reload count not hit - container should fire reload event after acquiring content");
                }
            }

            onIdlePumpActive = false;
        }
        public async Task AddFiresContentChangedEvent()
        {
            AggContext.StaticData = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData"));
            MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4));

            string filePath = TestContext.CurrentContext.ResolveProjectPath(4, "Tests", "TestData", "TestParts", "Batman.stl");

            bool onIdlePumpActive = true;

            var uiPump = Task.Run(() =>
            {
                while (onIdlePumpActive)
                {
                    UiThread.InvokePendingActions();
                    Thread.Sleep(10);
                }
                ;

                Console.Write("Exiting");
            });

            Type writable = typeof(ILibraryWritableContainer);

            // Find and validate all ILibraryContainer types, skipping abstract classes
            foreach (var containerType in PluginFinder.FindTypes <ILibraryContainer>().Where(fieldType => !fieldType.IsAbstract))
            {
                var args = new List <object>();

                if (containerType == typeof(FileSystemContainer))
                {
                    Directory.CreateDirectory(ApplicationDataStorage.Instance.ApplicationTempDataPath);
                    args.Add(ApplicationDataStorage.Instance.ApplicationTempDataPath);
                }
                else if (containerType == typeof(RootLibraryContainer) ||
                         !writable.IsAssignableFrom(containerType))
                {
                    // TODO: Not sure how to test RootLibrary given content loads after MatterControl init is finished, skipping for now
                    continue;
                }

                if (Activator.CreateInstance(containerType, args.ToArray()) is ILibraryWritableContainer libraryContainer)
                {
                    if (!libraryContainer.AllowAction(ContainerActions.AddItems))
                    {
                        continue;
                    }

                    if (libraryContainer is ZipMemoryContainer zipContainer)
                    {
                        zipContainer.Path = TestContext.CurrentContext.ResolveProjectPath(4, "Tests", "TestData", "TestParts", "Batman.zip");
                        zipContainer.RelativeDirectory = Path.GetDirectoryName(zipContainer.Path);
                    }

                    int changedCount = 0;
                    libraryContainer.ContentChanged += (s, e) =>
                    {
                        changedCount++;
                    };

                    var waitUntil = DateTime.Now.AddSeconds(15);

                    var result = Task.Run(() =>
                    {
                        libraryContainer.Load();
                        libraryContainer.Add(new[] { new FileSystemFileItem(filePath) });
                    });

                    // Wait for reload
                    while (DateTime.Now <= waitUntil)
                    {
                        if (changedCount > 0)
                        {
                            break;
                        }

                        await Task.Delay(200);
                    }

                    // Allow time for invalid additional reloads
                    await Task.Delay(300);

                    Console.WriteLine($"ContentChanged for {containerType.Name}");

                    // Verify Reload is called;
                    Assert.AreEqual(1, changedCount, $"Expected reload count for {containerType.Name} not hit - container should fire reload event after acquiring content");
                }
            }

            onIdlePumpActive = false;
        }