Example #1
0
        public void Desktop_InputIsSentToActiveWorkspaceOnly()
        {
            Desktop desktop = new Desktop(CommonMocks.FontProvider().Object, CommonMocks.StyleConfigurator().Object);

            (var w1, var e1) = CommonMocks.Widget("w1", elementCanHaveFocus: true);
            (var w2, var e2) = CommonMocks.Widget("w2", elementCanHaveFocus: true);

            var workspace1 = new Workspace("a", w1.Object);
            var workspace2 = new Workspace("b", w2.Object);

            desktop.PushWorkspace(workspace2);
            desktop.PushWorkspace(workspace1);

            desktop.ClearAnimations();
            int goodCalls = 0;
            int badCalls  = 0;

            e1.Setup(x => x.OnUserInterfaceAction(It.IsAny <UserInterfaceActionEventArgs>()))
            .Callback <UserInterfaceActionEventArgs>(e => ++ goodCalls);

            e2.Setup(x => x.OnUserInterfaceAction(It.IsAny <UserInterfaceActionEventArgs>()))
            .Callback <UserInterfaceActionEventArgs>(e => ++ badCalls);

            desktop.OnUserInterfaceAction(new UserInterfaceActionEventArgs().Reset(UserInterfaceAction.Down));

            goodCalls.Should().Be(1);
            badCalls.Should().Be(0);
        }
Example #2
0
        public void Desktop_MultipleWorkspaces()
        {
            Desktop desktop = new Desktop(CommonMocks.FontProvider().Object, CommonMocks.StyleConfigurator().Object);

            bool exited = false;

            desktop.Empty += () => exited = true;

            (var window1, var element1) = CommonMocks.Widget("window");
            (var window2, var element2) = CommonMocks.Widget("window");

            var workspace1 = CreateWorkspace("default", window1.Object);
            var workspace2 = CreateWorkspace("other", window2.Object);

            desktop.PushWorkspace(workspace1);
            desktop.PushWorkspace(workspace2);

            desktop.ActiveWorkspace.Should().BeSameAs(workspace2);
            desktop.WaitForAnimations();
            desktop.ActiveWorkspace.Should().BeSameAs(workspace2);

            desktop.PopWorkspace();

            desktop.ActiveWorkspace.Should().BeSameAs(workspace2, "Active workspace should still be the old one, until the transition out animation is complete.");
            desktop.WaitForAnimations();
            desktop.ActiveWorkspace.Should().BeSameAs(workspace1, "Transition out animation is complete, so the active workspace should be the one underneath.");

            desktop.PopWorkspace();
            desktop.WaitForAnimations();

            exited.Should().BeTrue();
        }
Example #3
0
        public UIContext()
        {
            renderContext = CommonMocks.RenderContext().Object;

            scene = new UserInterfaceSceneDriver(
                renderContext,
                CommonMocks.StyleConfigurator().Object,
                CommonMocks.FontProvider().Object);
        }
Example #4
0
        public FixedSizeTests()
        {
            var themes = new ThemeCollection();

            themes["default"] = new Theme();

            styleConfigurator = new ThemeStyler(themes);

            contentLayoutEngine = new ContentLayoutEngineLogger(
                new ContentLayoutEngine(
                    CommonMocks.FontProvider().Object));
        }
Example #5
0
        public void Desktop_WidgetGetsInstructions()
        {
            var renderContext = new FakeRenderContext();

            Desktop desktop = new Desktop(CommonMocks.FontProvider().Object, CommonMocks.StyleConfigurator().Object);

            (var widget, var element) = CommonMocks.Widget("happy");

            Workspace workspace = new Workspace("default", widget.Object);

            desktop.PushWorkspace(workspace);

            desktop.Update(renderContext);

            element.Object.Display.System.Instructions.Should().BeSameAs(desktop.Instructions);
        }
Example #6
0
        public void ApplyDefaultTheme()
        {
            var             fontProvider = CommonMocks.FontProvider("default");
            ThemeCollection themes       = new ThemeCollection
            {
                ["default"] = Theme.CreateDefaultTheme(),
                ["xyz"]     = CreateTestTheme(),
            };

            ThemeStyler styler = new ThemeStyler(fontProvider.Object, themes);

            var widget = CommonMocks.Widget("widget");

            styler.ApplyStyle(widget.Object, "xyz");

            widget.Object.Display.Style.Padding.Left.Should().Be(14);
            widget.Object.Display.Font.Color.Should().Be(Color.Yellow);
        }
        public void ApplyDefaultTheme()
        {
            var             fontProvider = CommonMocks.FontProvider("default");
            ThemeCollection themes       = new ThemeCollection
            {
                ["default"] = Theme.CreateDefaultTheme(),
                ["xyz"]     = CreateTestTheme(),
            };

            ThemeStyler styler = new ThemeStyler(themes);

            (var widget, var element) = CommonMocks.Widget("widget");

            element.Object.Display.ParentFont = fontProvider.Object.Default;

            styler.Apply(element.Object, "xyz");

            element.Object.Style.Update();
            element.Object.Display.Style.Padding.Left.Should().Be(14);
            element.Object.Style.Font.Color.Should().Be(Color.Yellow);
        }
Example #8
0
        public TestUIDriver(IRenderable app,
                            IStyleConfigurator styleConfigurator     = null,
                            IFontProvider fontProvider               = null,
                            IContentLayoutEngine contentLayoutEngine = null)
        {
            var renderContext = CommonMocks.RenderContext(contentLayoutEngine).Object;

            uiDriver = new UserInterfaceSceneDriver(
                renderContext,
                styleConfigurator ?? new ThemeStyler(new ThemeCollection {
                ["default"] = Theme.CreateDefaultTheme()
            }),
                fontProvider ?? CommonMocks.FontProvider().Object);

            defaultWorkspace = new Workspace("default", app);

            input = new ManualInputState();

            uiDriver.Desktop.PushWorkspace(defaultWorkspace);

            DoLayout();
        }
        public void LayoutText()
        {
            var text = @"Enemies with shields can block your attacks.
Try crouching with {Color Yellow}Down{Color White} and slashing with {Color Yellow}Sword{Color White} to beat enemies with shields.
Be careful! Some enemies may anticipate this!";

            var fontProvider = CommonMocks.FontProvider("temp");

            ContentLayoutEngine layoutEngine = new ContentLayoutEngine(fontProvider.Object);

            var result = (ContentLayout)layoutEngine.LayoutContent(text, 200);

            result.Draw(Vector2.Zero);

            var items = result.Items.Cast <ContentText>().ToList();

            ValidateItem(items, 0, new Vector2(0, 0), "Enemies with shields can block your");
            ValidateItem(items, 1, new Vector2(0, 10), "attacks.");
            ValidateItem(items, 2, new Vector2(0, 20), "Try crouching with ");
            ValidateItem(items, 3, new Vector2(95, 20), "Down");
            ValidateItem(items, 4, new Vector2(115, 20), " and slashing");
        }
Example #10
0
 public FakeRenderContext()
 {
     Fonts = CommonMocks.FontProvider().Object;
 }