Ejemplo n.º 1
0
        public virtual void Render(IRenderContext context, ISkinLayout skinLayout, ISkinDelegator skinDelegator, Rectangle layout)
        {
            var layoutWidth  = layout.Width - skinLayout.HorizontalScrollBarHeight;
            var layoutHeight = layout.Height - skinLayout.VerticalScrollBarWidth;

            int childWidth, childHeight;

            if (!(_child is IHasDesiredSize))
            {
                childWidth  = layoutWidth;
                childHeight = layoutHeight;
            }
            else
            {
                var hasDesiredSize = (IHasDesiredSize)_child;
                childWidth  = hasDesiredSize.GetDesiredWidth(skinLayout) ?? layoutWidth;
                childHeight = hasDesiredSize.GetDesiredHeight(skinLayout) ?? layoutHeight;
                if (childWidth < layoutWidth)
                {
                    childWidth = layoutWidth;
                }
                if (childHeight < layoutHeight)
                {
                    childHeight = layoutHeight;
                }
            }

            if (_renderTarget == null || _renderTarget.Width != childWidth ||
                _renderTarget.Height != childHeight)
            {
                _renderTarget?.Dispose();

                _renderTarget = new RenderTarget2D(
                    context.GraphicsDevice,
                    Math.Max(1, childWidth),
                    Math.Max(1, childHeight));
            }

            context.SpriteBatch.End();
            context.PushRenderTarget(_renderTarget);
            context.GraphicsDevice.Clear(Color.Transparent);
            context.SpriteBatch.Begin();

            try
            {
                _child?.Render(
                    context,
                    skinLayout,
                    skinDelegator,
                    new Rectangle(0, 0, childWidth, childHeight));
            }
            finally
            {
                context.SpriteBatch.End();
                context.PopRenderTarget();
                context.SpriteBatch.Begin();
            }

            skinDelegator.Render(context, layout, this);
        }
Ejemplo n.º 2
0
        public override bool HandleEvent(ISkinLayout skinLayout, Rectangle layout, IGameContext context, Event @event)
        {
            foreach (var kv in ChildrenWithLayouts(layout))
            {
                if (kv.Key is Button)
                {
                    if (kv.Key.HandleEvent(skinLayout, kv.Value, context, @event))
                    {
                        return(true);
                    }
                }
            }

            var mouseReleaseEvent = @event as MouseReleaseEvent;

            if (mouseReleaseEvent != null && mouseReleaseEvent.Button == MouseButton.Left)
            {
                if (layout.Contains(mouseReleaseEvent.Position))
                {
                    Click?.Invoke(this, new ProtogameEventArgs(context));
                    return(true);
                }
            }

            return(base.HandleEvent(skinLayout, layout, context, @event));
        }
Ejemplo n.º 3
0
        public bool HandleEvent(ISkinLayout skin, Rectangle layout, IGameContext context, Event @event)
        {
            var mouseEvent = @event as MousePressEvent;

            if (mouseEvent == null)
            {
                return(false);
            }

            if (!layout.Contains(mouseEvent.X, mouseEvent.Y))
            {
                return(false);
            }

            var treeView = Parent as TreeView;

            if (treeView == null)
            {
                return(false);
            }

            treeView.SelectedItem = this;

            return(true);
        }
Ejemplo n.º 4
0
 public override void Update(ISkinLayout skin, Rectangle layout, GameTime gameTime, ref bool stealFocus)
 {
     foreach (var kv in this.GetChildLocations(skin, layout))
     {
         kv.Key.Update(skin, kv.Value, gameTime, ref stealFocus);
     }
 }
Ejemplo n.º 5
0
        public IEnumerable <Rectangle> GetActiveChildrenLayouts(ISkinLayout skin, Rectangle layout)
        {
            yield return(layout);

            if (!Active)
            {
                yield break;
            }

            var childrenLayout = GetMenuListLayout(skin, layout);

            if (childrenLayout == null)
            {
                yield break;
            }

            yield return(childrenLayout.Value);

            foreach (var kv in GetMenuChildren(skin, layout))
            {
                foreach (var childLayout in kv.Key.GetActiveChildrenLayouts(skin, kv.Value))
                {
                    yield return(childLayout);
                }
            }
        }
Ejemplo n.º 6
0
 public CanvasEntity(ISkinLayout skinLayout, ISkinDelegator skinDelegator)
 {
     _skinLayout     = skinLayout;
     _skinDelegator  = skinDelegator;
     CanvasesEnabled = true;
     Windows         = new List <Window>();
 }
Ejemplo n.º 7
0
 public override void Update(ISkinLayout skin, Rectangle layout, GameTime gameTime, ref bool stealFocus)
 {
     foreach (var kv in this.GetChildLocations(skin, layout))
     {
         kv.Key.Update(skin, kv.Value, gameTime, ref stealFocus);
     }
 }
Ejemplo n.º 8
0
        public virtual void Update(ISkinLayout skin, Rectangle layout, GameTime gameTime, ref bool stealFocus)
        {
            var mouse       = Mouse.GetState();
            var leftPressed = mouse.LeftChanged(this) == ButtonState.Pressed;

            if (layout.Contains(mouse.X, mouse.Y))
            {
                Hovered        = true;
                HoverCountdown = 5;
                if (leftPressed)
                {
                    Click?.Invoke(this, new EventArgs());

                    Active = true;
                }
            }

            var deactivate = true;

            foreach (var activeLayout in GetActiveChildrenLayouts(skin, layout))
            {
                if (activeLayout.Contains(mouse.X, mouse.Y))
                {
                    deactivate = false;
                    break;
                }
            }

            Hovered = !deactivate;
            if (leftPressed)
            {
                Active = !deactivate;
            }

            if (HoverCountdown == 0)
            {
                Hovered = false;
            }

            if (!(Parent is MainMenu))
            {
                Active = Hovered;
            }

            if (Active)
            {
                foreach (var kv in GetMenuChildren(skin, layout))
                {
                    kv.Key.Update(skin, kv.Value, gameTime, ref stealFocus);
                }

                this.Focus();
            }

            // If the menu item is active, we steal focus from any further updating by our parent.
            if (Active)
            {
                stealFocus = true;
            }
        }
Ejemplo n.º 9
0
        public bool HandleEvent(ISkinLayout skin, Rectangle layout, IGameContext context, Event @event)
        {
            var mousePressEvent = @event as MousePressEvent;
            if (mousePressEvent != null)
            {
                if (!layout.Contains(mousePressEvent.MouseState.X, mousePressEvent.MouseState.Y))
                {
                    return false;
                }

                State = LinkState.Clicked;

                Click?.Invoke(this, new EventArgs());

                return true;
            }

            var mouseReleaseEvent = @event as MouseReleaseEvent;
            if (mouseReleaseEvent != null)
            {
                if (!layout.Contains(mouseReleaseEvent.MouseState.X, mouseReleaseEvent.MouseState.Y))
                {
                    return false;
                }

                State = LinkState.None;
            }

            return false;
        }
Ejemplo n.º 10
0
        public ProtogameEditorWorld(
            INode worldNode,
            IHierarchy hierarchy,
            ISkinLayout skinLayout,
            ISkinDelegator skinDelegator,
            IAssetManager assetManager,
            IMainMenuController mainMenuController,
            IEditorWindowFactory editorWindowFactory,
            IProjectManager projectManager,
            ILoadedGame loadedGame,
            IRecentProjects recentProjects,
            IThumbnailSampler thumbnailSampler,
            IExtensionManager extensionManager)
        {
            _skinLayout          = skinLayout;
            _skinDelegator       = skinDelegator;
            _assetManager        = assetManager;
            _mainMenuController  = mainMenuController;
            _editorWindowFactory = editorWindowFactory;
            _projectManager      = projectManager;
            _loadedGame          = loadedGame;
            _recentProjects      = recentProjects;
            _thumbnailSampler    = thumbnailSampler;
            _extensionManager    = extensionManager;

            SetupCanvas();

            var entity = new CanvasEntity(_skinLayout, _skinDelegator);

            entity.Canvas = _canvas;
            hierarchy.AddChildNode(worldNode, hierarchy.CreateNodeForObject(entity));
        }
Ejemplo n.º 11
0
        public bool HandleEvent(ISkinLayout skin, Rectangle layout, IGameContext context, Event @event)
        {
            var mousePressEvent = @event as MousePressEvent;

            if (mousePressEvent != null)
            {
                if (!layout.Contains(mousePressEvent.X, mousePressEvent.Y))
                {
                    return(false);
                }

                State = LinkState.Clicked;

                Click?.Invoke(this, new EventArgs());

                return(true);
            }

            var mouseReleaseEvent = @event as MouseReleaseEvent;

            if (mouseReleaseEvent != null)
            {
                if (!layout.Contains(mouseReleaseEvent.X, mouseReleaseEvent.Y))
                {
                    return(false);
                }

                State = LinkState.None;
            }

            return(false);
        }
Ejemplo n.º 12
0
        public IEnumerable <KeyValuePair <MenuItem, Rectangle> > GetMenuChildren(ISkinLayout skin, Rectangle layout)
        {
            var childLayout = GetMenuListLayout(skin, layout);

            if (childLayout == null)
            {
                yield break;
            }

            var accumulated = 0;

            foreach (var child in Items)
            {
                yield return
                    (new KeyValuePair <MenuItem, Rectangle>(
                         child,
                         new Rectangle(
                             childLayout.Value.X,
                             childLayout.Value.Y + accumulated,
                             childLayout.Value.Width,
                             skin.MenuItemHeight)));

                accumulated += skin.MenuItemHeight;
            }
        }
Ejemplo n.º 13
0
        public bool HandleEvent(ISkinLayout skin, Rectangle layout, IGameContext context, Event @event)
        {
            var mousePressEvent = @event as MousePressEvent;

            if (mousePressEvent != null && mousePressEvent.Button == MouseButton.Left)
            {
                this.Focus();
            }

            foreach (var kv in LabelsWithLayouts(layout))
            {
                if (kv.Key.HandleEvent(skin, kv.Value, context, @event))
                {
                    return(true);
                }
            }

            foreach (var kv in ChildrenWithLayouts(layout))
            {
                if (kv.Key.HandleEvent(skin, kv.Value, context, @event))
                {
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 14
0
        public IEnumerable <ListEntry> GetChildrenWithLayouts(ISkinLayout skinLayout, Rectangle layout)
        {
            var list = _items.Select(x => new ListEntry {
                Item = x
            }).ToList();
            var current = layout.Y;

            foreach (var item in list)
            {
                item.Layout = new Rectangle(
                    layout.X + skinLayout.ListHorizontalPadding,
                    current + skinLayout.ListVerticalPadding,
                    layout.Width - skinLayout.ListHorizontalPadding * 2,
                    skinLayout.HeightForTreeItem);
                yield return(item);

                var desiredSize = item.Item as IHasDesiredSize;
                if (desiredSize?.GetDesiredHeight(skinLayout) != null)
                {
                    var desiredHeight = desiredSize.GetDesiredHeight(skinLayout);
                    if (desiredHeight != null)
                    {
                        current += desiredHeight.Value;
                    }
                }
                else
                {
                    current += skinLayout.HeightForTreeItem;
                }
            }
        }
Ejemplo n.º 15
0
 public CanvasEntity(ISkinLayout skinLayout, ISkinDelegator skinDelegator)
 {
     _skinLayout = skinLayout;
     _skinDelegator = skinDelegator;
     CanvasesEnabled = true;
     Windows = new List<Window>();
 }
        public bool HandleEvent(ISkinLayout skinLayout, Rectangle layout, IGameContext context, Event @event)
        {
            foreach (var tab in TabWithLayouts(layout))
            {
                var mousePressEvent = @event as MousePressEvent;
                if (mousePressEvent != null)
                {
                    if (tab.Layout.Contains(mousePressEvent.MouseState.Position))
                    {
                        ActiveTabIndex = tab.Index;

                        // Also make the tab content the focus.
                        _innerRegions[ActiveTabIndex]?.Focus();
                    }
                }
            }

            foreach (var kv in ChildrenWithLayouts(layout))
            {
                if (kv.Key.HandleEvent(skinLayout, kv.Value, context, @event))
                {
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 17
0
        public virtual void Render(IRenderContext context, ISkinLayout skinLayout, ISkinDelegator skinDelegator, Rectangle layout)
        {
            var layoutWidth = layout.Width - skinLayout.HorizontalScrollBarHeight;
            var layoutHeight = layout.Height - skinLayout.VerticalScrollBarWidth;

            int childWidth, childHeight;
            if (!(_child is IHasDesiredSize))
            {
                childWidth = layoutWidth;
                childHeight = layoutHeight;
            }
            else
            {
                var hasDesiredSize = (IHasDesiredSize) _child;
                childWidth = hasDesiredSize.GetDesiredWidth(skinLayout) ?? layoutWidth;
                childHeight = hasDesiredSize.GetDesiredHeight(skinLayout) ?? layoutHeight;
                if (childWidth < layoutWidth)
                {
                    childWidth = layoutWidth;
                }
                if (childHeight < layoutHeight)
                {
                    childHeight = layoutHeight;
                }
            }

            if (_renderTarget == null || _renderTarget.Width != childWidth ||
                _renderTarget.Height != childHeight)
            {
                _renderTarget?.Dispose();

                _renderTarget = new RenderTarget2D(
                    context.GraphicsDevice,
                    Math.Max(1, childWidth),
                    Math.Max(1, childHeight));
            }
            
            context.SpriteBatch.End();
            context.PushRenderTarget(_renderTarget);
            context.GraphicsDevice.Clear(Color.Transparent);
            context.SpriteBatch.Begin();

            try
            {
                _child?.Render(
                    context,
                    skinLayout,
                    skinDelegator,
                    new Rectangle(0, 0, childWidth, childHeight));
            }
            finally
            {
                context.SpriteBatch.End();
                context.PopRenderTarget();
                context.SpriteBatch.Begin();
            }

            skinDelegator.Render(context, layout, this);
        }
Ejemplo n.º 18
0
 public override void Render(IRenderContext context, ISkinLayout skinLayout, ISkinDelegator skinDelegator, Rectangle layout)
 {
     skinDelegator.Render(context, layout, this);
     foreach (var kv in this.ChildrenWithLayouts(layout).OrderByDescending(x => x.Key.Order))
     {
         kv.Key.Render(context, skinLayout, skinDelegator, kv.Value);
     }
 }
Ejemplo n.º 19
0
 public override void Render(IRenderContext context, ISkinLayout skinLayout, ISkinDelegator skinDelegator, Rectangle layout)
 {
     skinDelegator.Render(context, layout, this);
     foreach (var kv in GetChildLocations(skinLayout, layout))
     {
         kv.Key.Render(context, skinLayout, skinDelegator, kv.Value);
     }
 }
Ejemplo n.º 20
0
 public override void Render(IRenderContext context, ISkinLayout skinLayout, ISkinDelegator skinDelegator, Rectangle layout)
 {
     skinDelegator.Render(context, layout, this);
     foreach (var kv in GetChildLocations(skinLayout, layout))
     {
         kv.Key.Render(context, skinLayout, skinDelegator, kv.Value);
     }
 }
Ejemplo n.º 21
0
 public override void Render(IRenderContext context, ISkinLayout skinLayout, ISkinDelegator skinDelegator, Rectangle layout)
 {
     skinDelegator.Render(context, layout, this);
     foreach (var kv in this.ChildrenWithLayouts(layout).OrderByDescending(x => x.Key.Order))
     {
         kv.Key.Render(context, skinLayout, skinDelegator, kv.Value);
     }
 }
Ejemplo n.º 22
0
        public bool HandleEvent(ISkinLayout skin, Rectangle layout, IGameContext context, Event @event)
        {
            var mousePressEvent = @event as MousePressEvent;
            var touchPressEvent = @event as TouchPressEvent;

            if (mousePressEvent != null && mousePressEvent.Button == MouseButton.Left)
            {
                if (layout.Contains(mousePressEvent.MouseState.X, mousePressEvent.MouseState.Y))
                {
                    this.Focus();

                    return(true);
                }
            }

            if (touchPressEvent != null)
            {
                if (layout.Contains((int)touchPressEvent.X, (int)touchPressEvent.Y))
                {
                    this.Focus();

#if PLATFORM_ANDROID
                    var manager = (InputMethodManager)Game.Activity.GetSystemService(Context.InputMethodService);
                    manager.ShowSoftInput(((Microsoft.Xna.Framework.AndroidGameWindow)context.Game.Window).GameViewAsView, ShowFlags.Forced);
#endif

                    return(true);
                }
                else
                {
#if PLATFORM_ANDROID
                    var manager = (InputMethodManager)Game.Activity.GetSystemService(Context.InputMethodService);
                    manager.HideSoftInputFromWindow(((Microsoft.Xna.Framework.AndroidGameWindow)context.Game.Window).GameViewAsView.WindowToken, HideSoftInputFlags.None);
#endif
                }
            }

            var keyEvent = @event as KeyboardEvent;

            if (keyEvent != null)
            {
                var keyboard = keyEvent.KeyboardState;
                if (Focused)
                {
                    _keyboardReader.Process(keyboard, context.GameTime, _textBuilder);
                    if (_textBuilder.ToString() != _previousValue)
                    {
                        TextChanged?.Invoke(this, new EventArgs());
                    }

                    _previousValue = _textBuilder.ToString();

                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 23
0
        public bool HandleEvent(ISkinLayout skin, Rectangle layout, IGameContext context, Event @event)
        {
            var mousePressEvent = @event as MousePressEvent;
            var touchPressEvent = @event as TouchPressEvent;

            if (mousePressEvent != null && mousePressEvent.Button == MouseButton.Left)
            {
                if (layout.Contains(mousePressEvent.MouseState.X, mousePressEvent.MouseState.Y))
                {
                    this.Focus();

                    return true;
                }
            }

            if (touchPressEvent != null)
            {
                if (layout.Contains((int)touchPressEvent.X, (int)touchPressEvent.Y))
                {
                    this.Focus();

#if PLATFORM_ANDROID
                    var manager = (InputMethodManager)Game.Activity.GetSystemService(Context.InputMethodService);
                    manager.ShowSoftInput(((Microsoft.Xna.Framework.AndroidGameWindow)context.Game.Window).GameViewAsView, ShowFlags.Forced);
#endif

                    return true;
                }
                else
                {
#if PLATFORM_ANDROID
                    var manager = (InputMethodManager)Game.Activity.GetSystemService(Context.InputMethodService);
                    manager.HideSoftInputFromWindow(((Microsoft.Xna.Framework.AndroidGameWindow)context.Game.Window).GameViewAsView.WindowToken, HideSoftInputFlags.None);
#endif
                }
            }

            var keyEvent = @event as KeyboardEvent;

            if (keyEvent != null)
            {
                var keyboard = keyEvent.KeyboardState;
                if (Focused)
                {
                    _keyboardReader.Process(keyboard, context.GameTime, _textBuilder);
                    if (_textBuilder.ToString() != _previousValue)
                    {
                        TextChanged?.Invoke(this, new EventArgs());
                    }

                    _previousValue = _textBuilder.ToString();

                    return true;
                }
            }

            return false;
        }
Ejemplo n.º 24
0
        public bool HandleEvent(ISkinLayout skin, Rectangle layout, IGameContext context, Event @event)
        {
            if (AttachTo != null)
            {
                return(AttachTo.HandleEvent(skin, layout, context, @event));
            }

            return(false);
        }
Ejemplo n.º 25
0
        public int?GetDesiredHeight(ISkinLayout skin)
        {
            if (Console == null)
            {
                return(null);
            }

            return(Console.Entries.Sum(x => (x.Message ?? "").Split(new[] { Environment.NewLine }, StringSplitOptions.None).Length) * 16);
        }
Ejemplo n.º 26
0
        public int?GetDesiredHeight(ISkinLayout skin)
        {
            if (Console == null)
            {
                return(null);
            }

            return((int)Console.EntryCount * 16);
        }
Ejemplo n.º 27
0
        public void Update(ISkinLayout skin, Rectangle layout, GameTime gameTime, ref bool stealFocus)
        {
            _child?.Update(skin, layout, gameTime, ref stealFocus);

            if (Modal)
            {
                stealFocus = true;
            }
        }
Ejemplo n.º 28
0
        public void Update(ISkinLayout skin, Rectangle layout, GameTime gameTime, ref bool stealFocus)
        {
            _child?.Update(skin, layout, gameTime, ref stealFocus);

            if (Modal)
            {
                stealFocus = true;
            }
        }
Ejemplo n.º 29
0
        public override void Update(ISkinLayout skinLayout, Rectangle layout, GameTime gameTime, ref bool stealFocus)
        {
            base.Update(skinLayout, layout, gameTime, ref stealFocus);

            // Because of padding the size should be slightly smaller.
            _loadedGame.SetPositionOffset(new Point(layout.X + 1, layout.Y + 1));
            _loadedGame.SetRenderTargetSize(new Point(layout.Size.X - 2, layout.Size.Y - 2));
            _rawTextureContainer.Texture = _loadedGame.GetCurrentGameRenderTarget();
        }
Ejemplo n.º 30
0
 public void Update(ISkinLayout skinLayout, Rectangle layout, GameTime gameTime, ref bool stealFocus)
 {
     foreach (var kv in GetChildrenWithLayouts(skinLayout, layout))
     {
         if (kv.Layout != null)
         {
             kv.Item.Update(skinLayout, kv.Layout.Value, gameTime, ref stealFocus);
         }
     }
 }
Ejemplo n.º 31
0
        public NuiHorizontalContainerSkinRenderer(
            I2DRenderUtilities renderUtilities,
            IAssetManager assetManager,
            ISkinLayout skinLayout)
        {
            _renderUtilities = renderUtilities;
            _skinLayout      = skinLayout;

            _assetManager = assetManager;
        }
Ejemplo n.º 32
0
 public void Render(IRenderContext context, ISkinLayout skinLayout, ISkinDelegator skinDelegator, Rectangle layout)
 {
     skinDelegator.Render(context, layout, this);
     foreach (var kv in GetChildrenWithLayouts(skinLayout, layout))
     {
         if (kv.Layout != null)
         {
             kv.Item.Render(context, skinLayout, skinDelegator, kv.Layout.Value);
         }
     }
 }
Ejemplo n.º 33
0
 public void Update(ISkinLayout skinLayout, Rectangle layout, GameTime gameTime, ref bool stealFocus)
 {
     foreach (var kv in ChildrenWithLayouts(layout))
     {
         kv.Key.Update(skinLayout, kv.Value, gameTime, ref stealFocus);
         if (stealFocus)
         {
             break;
         }
     }
 }
Ejemplo n.º 34
0
 public void Update(ISkinLayout skinLayout, Rectangle layout, GameTime gameTime, ref bool stealFocus)
 {
     foreach (var kv in ChildrenWithLayouts(layout))
     {
         kv.Key.Update(skinLayout, kv.Value, gameTime, ref stealFocus);
         if (stealFocus)
         {
             break;
         }
     }
 }
Ejemplo n.º 35
0
        public bool HandleEvent(ISkinLayout skinLayout, Rectangle layout, IGameContext context, Event @event)
        {
            var mouseEvent = @event as MouseEvent;
            var mousePressEvent = @event as MousePressEvent;
            var mouseReleaseEvent = @event as MouseReleaseEvent;
            var mouseMoveEvent = @event as MouseMoveEvent;

            if (mouseEvent == null)
            {
                return false;
            }

            if (layout.Contains(mouseEvent.MouseState.X, mouseEvent.MouseState.Y))
            {
                if (mouseMoveEvent != null)
                {
                    State = ButtonUIState.Hover;
                }
                else if (mousePressEvent != null && mousePressEvent.Button == MouseButton.Left)
                {
                    State = ButtonUIState.Clicked;
                    this.Focus();

#if PLATFORM_WINDOWS || PLATFORM_MACOS || PLATFORM_LINUX
                    using (var openFileDialog = new OpenFileDialog())
                    {
                        if (openFileDialog.ShowDialog() == DialogResult.OK)
                        {
                            Path = openFileDialog.FileName;
                            if (Changed != null)
                            {
                                Changed(this, new EventArgs());
                            }
                        }

                        Application.DoEvents();
                    }
#endif

                    return true;
                }
            }
            else
            {
                State = ButtonUIState.None;
            }

            if (mouseReleaseEvent != null && mouseReleaseEvent.Button == MouseButton.Left)
            {
                State = ButtonUIState.None;
            }

            return false;
        }
Ejemplo n.º 36
0
 public void Render(IRenderContext context, ISkinLayout skinLayout, ISkinDelegator skinDelegator, Rectangle layout)
 {
     skinDelegator.Render(context, layout, this);
     foreach (var kv in GetChildrenWithLayouts(skinLayout, layout))
     {
         if (kv.Layout != null)
         {
             kv.Item.Render(context, skinLayout, skinDelegator, kv.Layout.Value);
         }
     }
 }
Ejemplo n.º 37
0
        public bool HandleEvent(ISkinLayout skinLayout, Rectangle layout, IGameContext context, Event @event)
        {
            var mouseEvent        = @event as MouseEvent;
            var mousePressEvent   = @event as MousePressEvent;
            var mouseReleaseEvent = @event as MouseReleaseEvent;
            var mouseMoveEvent    = @event as MouseMoveEvent;

            if (mouseEvent == null)
            {
                return(false);
            }

            if (layout.Contains(mouseEvent.MouseState.X, mouseEvent.MouseState.Y))
            {
                if (mouseMoveEvent != null)
                {
                    State = ButtonUIState.Hover;
                }
                else if (mousePressEvent != null && mousePressEvent.Button == MouseButton.Left)
                {
                    State = ButtonUIState.Clicked;
                    this.Focus();

#if PLATFORM_WINDOWS || PLATFORM_MACOS || PLATFORM_LINUX
                    using (var openFileDialog = new OpenFileDialog())
                    {
                        if (openFileDialog.ShowDialog() == DialogResult.OK)
                        {
                            Path = openFileDialog.FileName;
                            if (Changed != null)
                            {
                                Changed(this, new EventArgs());
                            }
                        }

                        Application.DoEvents();
                    }
#endif

                    return(true);
                }
            }
            else
            {
                State = ButtonUIState.None;
            }

            if (mouseReleaseEvent != null && mouseReleaseEvent.Button == MouseButton.Left)
            {
                State = ButtonUIState.None;
            }

            return(false);
        }
Ejemplo n.º 38
0
        /*public override void OnFocus()
         * {
         *  // Switch focus to the scrollable container.
         *  _verticalContainer.Focus();
         * }*/

        public override void Update(ISkinLayout skinLayout, Rectangle layout, GameTime gameTime, ref bool stealFocus)
        {
            foreach (var ext in _extensionManager.Extensions)
            {
                if (_verticalContainer.Children.Any(x => x.Userdata == ext))
                {
                    continue;
                }

                var label = new Label
                {
                    Text = ext.Name
                };
                var debugButton = new Button
                {
                    Text = "Debug"
                };
                var restartButton = new Button
                {
                    Text = "Restart"
                };

                debugButton.Click += (sender, e) =>
                {
                    _extensionManager.DebugExtension(ext);
                };
                restartButton.Click += (sender, e) =>
                {
                    _extensionManager.RestartExtension(ext);
                };


                var buttonContainer = new VerticalContainer();
                buttonContainer.AddChild(debugButton, "24");
                buttonContainer.AddChild(restartButton, "24");

                var horizontalContainer = new HorizontalContainer();
                horizontalContainer.Userdata = ext;
                horizontalContainer.AddChild(label, "*");
                horizontalContainer.AddChild(buttonContainer, "120");

                _verticalContainer.AddChild(horizontalContainer, "48");
            }

            foreach (var vert in _verticalContainer.Children.ToArray())
            {
                if (!_extensionManager.Extensions.Any(x => x == vert.Userdata))
                {
                    _verticalContainer.RemoveChild(vert);
                }
            }

            base.Update(skinLayout, layout, gameTime, ref stealFocus);
        }
Ejemplo n.º 39
0
        public bool HandleEvent(ISkinLayout skinLayout, Rectangle layout, IGameContext context, Event @event)
        {
            var mousePressEvent = @event as MousePressEvent;

            if (mousePressEvent != null)
            {
                this.Parent.Focus();
                return(true);
            }

            return(false);
        }
Ejemplo n.º 40
0
        public bool HandleEvent(ISkinLayout skinLayout, Rectangle layout, IGameContext context, Event @event)
        {
            foreach (var kv in ChildrenWithLayouts(layout))
            {
                if (kv.Key.HandleEvent(skinLayout, kv.Value, context, @event))
                {
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 41
0
        public override void Update(ISkinLayout skinLayout, Rectangle layout, GameTime gameTime, ref bool stealFocus)
        {
            base.Update(skinLayout, layout, gameTime, ref stealFocus);

            /*var t = _loadedGame.GetStallState();
             * _readStallLabel.Text = "Read Stall: " + (t.Item1 ? "Yes" : "No");
             * _readStallLabel.TextColor = t.Item1 ? Color.Red : Color.Black;
             * _readStallLabel.HorizontalAlignment = HorizontalAlignment.Left;
             * _writeStallLabel.Text = "Write Stall: " + (t.Item2 ? "Yes" : "No");
             * _writeStallLabel.TextColor = t.Item2 ? Color.Red : Color.Black;
             * _writeStallLabel.HorizontalAlignment = HorizontalAlignment.Left;*/
        }
Ejemplo n.º 42
0
        public void Render(IRenderContext context, ISkinLayout skinLayout, ISkinDelegator skinDelegator, Rectangle layout)
        {
            skinDelegator.Render(context, layout, this);
            foreach (var kv in LabelsWithLayouts(layout))
            {
                kv.Key.Render(context, skinLayout, skinDelegator, kv.Value);
            }

            foreach (var kv in ChildrenWithLayouts(layout))
            {
                kv.Key.Render(context, skinLayout, skinDelegator, kv.Value);
            }
        }
Ejemplo n.º 43
0
 public void Update(ISkinLayout skin, Rectangle layout, GameTime gameTime, ref bool stealFocus)
 {
     _toggleButton.Update(
         skin, 
         new Rectangle(layout.X, layout.Y, layout.Width, 24), 
         gameTime, 
         ref stealFocus);
     if (_instance != null && _instance.State == SoundState.Stopped)
     {
         _toggleButton.Text = "Play";
         _instance.Stop();
         _instance = null;
     }
 }
Ejemplo n.º 44
0
 private IEnumerable<KeyValuePair<MenuItem, Rectangle>> GetChildLocations(ISkinLayout skin, Rectangle layout)
 {
     var accumulated = -skin.MainMenuHorizontalPadding;
     foreach (var child in this.Items)
     {
         yield return
             new KeyValuePair<MenuItem, Rectangle>(
                 child, 
                 new Rectangle(
                     layout.X + accumulated + skin.MainMenuHorizontalPadding, 
                     layout.Y, 
                     child.TextWidth + skin.MainMenuHorizontalPadding, 
                     layout.Height));
         accumulated += child.TextWidth + skin.MainMenuHorizontalPadding;
     }
 }
Ejemplo n.º 45
0
        public virtual void Render(IRenderContext context, ISkinLayout skinLayout, ISkinDelegator skinDelegator, Rectangle layout)
        {
            TextWidth = (int)Math.Ceiling(skinDelegator.MeasureText(context, Text, this).X);
            skinDelegator.Render(context, layout, this);

            var childrenLayout = GetMenuListLayout(skinLayout, layout);
            if (Active && childrenLayout != null)
            {
                IsRenderingMenuList = true;
                skinDelegator.Render(context, childrenLayout.Value, this);
                foreach (var kv in GetMenuChildren(skinLayout, layout))
                {
                    kv.Key.Render(context, skinLayout, skinDelegator, kv.Value);
                }
            }
        }
Ejemplo n.º 46
0
 public int? GetDesiredHeight(ISkinLayout skin)
 {
     var current = 0;
     foreach (var item in _items)
     {
         var desiredSize = item as IHasDesiredSize;
         if (desiredSize?.GetDesiredHeight(skin) != null)
         {
             var desiredHeight = desiredSize.GetDesiredHeight(skin);
             if (desiredHeight != null)
             {
                 current += desiredHeight.Value;
             }
         }
         else
         {
             current += skin.HeightForTreeItem;
         }
     }
     return current;
 }
Ejemplo n.º 47
0
        public bool HandleEvent(ISkinLayout skin, Rectangle layout, IGameContext context, Event @event)
        {
            var mouseEvent = @event as MousePressEvent;
            if (mouseEvent == null)
            {
                return false;
            }
            if (!layout.Contains(mouseEvent.MouseState.X, mouseEvent.MouseState.Y))
            {
                return false;
            }
            var listView = Parent as ListView;

            if (listView == null)
            {
                return false;
            }

            listView.SelectedItem = this;

            return true;
        }
Ejemplo n.º 48
0
        public IEnumerable<Rectangle> GetActiveChildrenLayouts(ISkinLayout skin, Rectangle layout)
        {
            yield return layout;
            if (!Active)
            {
                yield break;
            }

            var childrenLayout = GetMenuListLayout(skin, layout);
            if (childrenLayout == null)
            {
                yield break;
            }

            yield return childrenLayout.Value;
            foreach (var kv in GetMenuChildren(skin, layout))
            {
                foreach (var childLayout in kv.Key.GetActiveChildrenLayouts(skin, kv.Value))
                {
                    yield return childLayout;
                }
            }
        }
Ejemplo n.º 49
0
 public void Update(ISkinLayout skin, Rectangle layout, GameTime gameTime, ref bool stealFocus)
 {
 }
Ejemplo n.º 50
0
 public bool HandleEvent(ISkinLayout skin, Rectangle layout, IGameContext context, Event @event)
 {
     return Child != null && Child.HandleEvent(skin, AbsoluteRectangle, context, @event);
 }
Ejemplo n.º 51
0
 public void Update(ISkinLayout skin, Rectangle layout, GameTime gameTime, ref bool stealFocus)
 {
     Child?.Update(skin, AbsoluteRectangle, gameTime, ref stealFocus);
 }
Ejemplo n.º 52
0
 public void Render(IRenderContext context, ISkinLayout skinLayout, ISkinDelegator skinDelegator, Rectangle layout)
 {
     skinDelegator.Render(context, layout, this);
     Child?.Render(context, skinLayout, skinDelegator, AbsoluteRectangle);
 }
Ejemplo n.º 53
0
        public IEnumerable<KeyValuePair<MenuItem, Rectangle>> GetMenuChildren(ISkinLayout skin, Rectangle layout)
        {
            var childLayout = GetMenuListLayout(skin, layout);
            if (childLayout == null)
            {
                yield break;
            }

            var accumulated = 0;
            foreach (var child in Items)
            {
                yield return
                    new KeyValuePair<MenuItem, Rectangle>(
                        child, 
                        new Rectangle(
                            childLayout.Value.X, 
                            childLayout.Value.Y + accumulated, 
                            childLayout.Value.Width, 
                            skin.MenuItemHeight));
                accumulated += skin.MenuItemHeight;
            }
        }
Ejemplo n.º 54
0
        public Rectangle? GetMenuListLayout(ISkinLayout skin, Rectangle layout)
        {
            // The location of the child items depends on whether we're owned
            // by a main menu or not.
            if (Items.Count == 0)
            {
                return null;
            }

            var maxWidth = Items.Max(x => x.TextWidth) + skin.AdditionalMenuItemWidth;
            var maxHeight = Items.Count * skin.MenuItemHeight;
            if (Parent is MainMenu)
            {
                return new Rectangle(layout.X, layout.Y + layout.Height, maxWidth, maxHeight);
            }

            return new Rectangle(layout.X + layout.Width, layout.Y, maxWidth, maxHeight);
        }
Ejemplo n.º 55
0
        public bool HandleEvent(ISkinLayout skin, Rectangle layout, IGameContext context, Event @event)
        {
            var mousePressEvent = @event as MousePressEvent;

            if (mousePressEvent != null && mousePressEvent.Button == MouseButton.Left)
            {
                this.Focus();
            }

            foreach (var kv in LabelsWithLayouts(layout))
            {
                if (kv.Key.HandleEvent(skin, kv.Value, context, @event))
                {
                    return true;
                }
            }

            foreach (var kv in ChildrenWithLayouts(layout))
            {
                if (kv.Key.HandleEvent(skin, kv.Value, context, @event))
                {
                    return true;
                }
            }

            return false;
        }
Ejemplo n.º 56
0
 public void Render(IRenderContext context, ISkinLayout skinLayout, ISkinDelegator skinDelegator, Rectangle layout)
 {
     skinDelegator.Render(context, layout, this);
 }
Ejemplo n.º 57
0
 public bool HandleEvent(ISkinLayout skin, Rectangle layout, IGameContext context, Event @event)
 {
     return Active;
 }
Ejemplo n.º 58
0
        public virtual void Update(ISkinLayout skin, Rectangle layout, GameTime gameTime, ref bool stealFocus)
        {
            var mouse = Mouse.GetState();
            var leftPressed = mouse.LeftChanged(this) == ButtonState.Pressed;

            if (layout.Contains(mouse.X, mouse.Y))
            {
                Hovered = true;
                HoverCountdown = 5;
                if (leftPressed)
                {
                    Click?.Invoke(this, new EventArgs());

                    Active = true;
                }
            }

            var deactivate = true;
            foreach (var activeLayout in GetActiveChildrenLayouts(skin, layout))
            {
                if (activeLayout.Contains(mouse.X, mouse.Y))
                {
                    deactivate = false;
                    break;
                }
            }

            Hovered = !deactivate;
            if (leftPressed)
            {
                Active = !deactivate;
            }

            if (HoverCountdown == 0)
            {
                Hovered = false;
            }

            if (!(Parent is MainMenu))
            {
                Active = Hovered;
            }

            if (Active)
            {
                foreach (var kv in GetMenuChildren(skin, layout))
                {
                    kv.Key.Update(skin, kv.Value, gameTime, ref stealFocus);
                }

                this.Focus();
            }

            // If the menu item is active, we steal focus from any further updating by our parent.
            if (Active)
            {
                stealFocus = true;
            }
        }
Ejemplo n.º 59
0
        public bool HandleEvent(ISkinLayout skinLayout, Rectangle layout, IGameContext context, Event @event)
        {
            foreach (var kv in ChildrenWithLayouts(layout))
            {
                if (kv.Key.HandleEvent(skinLayout, kv.Value, context, @event))
                {
                    return true;
                }
            }

            return false;
        }
Ejemplo n.º 60
0
        public bool HandleEvent(ISkinLayout skin, Rectangle layout, IGameContext context, Event @event)
        {
            foreach (var kv in GetChildrenWithLayouts(skin, layout))
            {
                if (kv.Layout != null && kv.Item.HandleEvent(skin, kv.Layout.Value, context, @event))
                {
                    return true;
                }
            }

            var keyPressEvent = @event as KeyPressEvent;
            if (keyPressEvent != null)
            {
                var upPressed = keyPressEvent.Key == Keys.Up;
                var downPressed = keyPressEvent.Key == Keys.Down;
                if (SelectedItem != null && (upPressed || downPressed))
                {
                    var tree = BuildEntryGraph(layout);
                    var list = NormalizeTree(tree, true);
                    var current = list.IndexOf(list.First(x => SelectedItem == x.Item));
                    if (upPressed)
                    {
                        current -= 1;
                    }
                    else
                    {
                        current += 1;
                    }

                    if (current >= 0 && current < list.Count)
                    {
                        SelectedItem = list[current].Item;

                        return true;
                    }
                }
            }

            return false;
        }