Exemplo n.º 1
0
 public ListStyle(BitmapFont font, Color fontColorSelected, Color fontColorUnselected, ISceneDrawable selection)
 {
     Font = font;
     FontColorSelected   = fontColorSelected;
     FontColorUnselected = fontColorUnselected;
     Selection           = selection;
 }
Exemplo n.º 2
0
        public TiledDrawable GetTiledDrawable(string name)
        {
            TiledDrawable tiled = Optional <TiledDrawable>(name);

            if (tiled != null)
            {
                return(tiled);
            }

            ISceneDrawable drawable = Optional <ISceneDrawable>(name);

            if (drawable != null)
            {
                if (!(drawable is TiledDrawable))
                {
                    throw new Exception("Drawable found but is not a TiledDrawable: " + name + ", " + drawable.GetType());
                }
                return(drawable as TiledDrawable);
            }

            try {
                tiled = new TiledDrawable(GetRegion(name));
                Add <TiledDrawable>(name, tiled);
                return(tiled);
            }
            catch {
                throw new Exception("No TiledDrawable, Drawable, TextureRegion, or Texture registered with name: " + name);
            }
        }
Exemplo n.º 3
0
        private float Layout(List <TreeNode> nodes, float indent, float y)
        {
            float          ySpacing      = YSpacing;
            float          indentSpacing = _indentSpacing;
            ISceneDrawable plus          = _style.Plus;
            ISceneDrawable minus         = _style.Minus;

            foreach (TreeNode node in nodes)
            {
                Actor actor = node.Actor;
                float x     = indent;
                if (node.Icon != null)
                {
                    x += node.Icon.MinWidth;
                }

                y -= node.Height;
                node.Actor.SetPosition(x, y);
                y -= ySpacing;

                if (node.IsExpanded)
                {
                    y = Layout(node.Children, indent + indentSpacing, y);
                }
            }

            return(y);
        }
Exemplo n.º 4
0
 public CheckBoxStyle(ISceneDrawable checkboxOff, ISceneDrawable checkboxOn, BitmapFont font, Color fontColor)
 {
     CheckboxOff = checkboxOff;
     CheckboxOn  = checkboxOn;
     Font        = font;
     FontColor   = fontColor;
 }
Exemplo n.º 5
0
 public SelectBoxStyle(BitmapFont font, Color fontColor, ISceneDrawable background, ScrollPaneStyle scrollStyle, ListStyle listStyle)
 {
     Font        = font;
     FontColor   = fontColor;
     Background  = background;
     ScrollStyle = scrollStyle;
     ListStyle   = listStyle;
 }
Exemplo n.º 6
0
 public ImageButtonStyle(ISceneDrawable up, ISceneDrawable down, ISceneDrawable chkd,
                         ISceneDrawable imageUp, ISceneDrawable imageDown, ISceneDrawable imageChkd)
     : base(up, down, chkd)
 {
     ImageUp      = imageUp;
     ImageDown    = imageDown;
     ImageChecked = imageChkd;
 }
Exemplo n.º 7
0
 public TextFieldStyle(BitmapFont font, Color?fontColor, ISceneDrawable cursor, ISceneDrawable selection, ISceneDrawable background)
 {
     Background = background;
     Cursor     = cursor;
     Font       = font;
     FontColor  = fontColor;
     Selection  = selection;
 }
Exemplo n.º 8
0
 public BaseDrawable(ISceneDrawable drawable)
 {
     LeftWidth    = drawable.LeftWidth;
     RightWidth   = drawable.RightWidth;
     TopHeight    = drawable.TopHeight;
     BottomHeight = drawable.BottomHeight;
     MinWidth     = drawable.MinWidth;
     MinHeight    = drawable.MinHeight;
 }
Exemplo n.º 9
0
        public void SetItems(object[] objects)
        {
            if (objects == null)
            {
                throw new ArgumentNullException("objects");
            }

            _items = objects;
            if (!(objects is string[]))
            {
                string[] strings = new string[objects.Length];
                for (int i = 0, n = objects.Length; i < n; i++)
                {
                    strings[i] = objects[i].ToString();
                }
                _itemsText = strings;
            }
            else
            {
                _itemsText = objects as string[];
            }

            _selectionIndex = 0;

            ISceneDrawable bg   = _style.Background;
            BitmapFont     font = _style.Font;

            _prefHeight = Math.Max(bg.TopHeight + bg.BottomHeight + font.CapHeight - font.Descent * 2, bg.MinHeight);

            float maxItemWIdth = 0;

            for (int i = 0; i < _items.Length; i++)
            {
                maxItemWIdth = Math.Max(font.GetBounds(_itemsText[i]).Width, maxItemWIdth);
            }

            _prefWidth = bg.LeftWidth + bg.RightWidth + maxItemWIdth;

            ListStyle       listStyle   = _style.ListStyle;
            ScrollPaneStyle scrollStyle = _style.ScrollStyle;

            _prefWidth = Math.Max(_prefWidth, maxItemWIdth + scrollStyle.Background.LeftWidth + scrollStyle.Background.RightWidth
                                  + listStyle.Selection.LeftWidth + listStyle.Selection.RightWidth
                                  + Math.Max(_style.ScrollStyle.VScroll != null ? _style.ScrollStyle.VScroll.MinWidth : 0,
                                             _style.ScrollStyle.VScrollKnob != null ? _style.ScrollStyle.VScrollKnob.MinWidth : 0));

            if (_items.Length > 0)
            {
                // TODO: Event for change of items

                //ChangeEvent changeEvent = Pools<ChangeEvent>.Obtain();
                //Fire(changeEvent);
                //Pools<ChangeEvent>.Release(changeEvent);
            }

            InvalidateHierarchy();
        }
Exemplo n.º 10
0
        public Image(ISceneDrawable drawable, Scaling scaling, Alignment align)
        {
            Drawable = drawable;
            Scaling  = scaling;
            Align    = align;

            Width  = PrefWidth;
            Height = PrefHeight;
        }
Exemplo n.º 11
0
        public Image(ISceneDrawable drawable, Scaling scaling, Alignment align)
        {
            Drawable = drawable;
            Scaling = scaling;
            Align = align;

            Width = PrefWidth;
            Height = PrefHeight;
        }
Exemplo n.º 12
0
 public BaseDrawable(ISceneDrawable drawable)
 {
     LeftWidth = drawable.LeftWidth;
     RightWidth = drawable.RightWidth;
     TopHeight = drawable.TopHeight;
     BottomHeight = drawable.BottomHeight;
     MinWidth = drawable.MinWidth;
     MinHeight = drawable.MinHeight;
 }
Exemplo n.º 13
0
 public ScrollPaneStyle(ISceneDrawable background, ISceneDrawable hScroll, ISceneDrawable hScrollKnob,
                        ISceneDrawable vScoll, ISceneDrawable vScrollKnob)
 {
     Background  = background;
     HScroll     = hScroll;
     HScrollKnob = hScrollKnob;
     VScroll     = vScoll;
     VScrollKnob = vScrollKnob;
 }
Exemplo n.º 14
0
        public override void Draw(GdxSpriteBatch spriteBatch, float parentAlpha)
        {
            Validate();

            ISceneDrawable background = null;
            float          offsetX    = 0;
            float          offsetY    = 0;

            if (IsPressed && !IsDisabled)
            {
                background = _style.Down ?? _style.Up;
                offsetX    = _style.PressedOffsetX;
                offsetY    = _style.PressedOffsetY;
            }
            else
            {
                if (IsDisabled && _style.Disabled != null)
                {
                    background = _style.Disabled;
                }
                else if (IsChecked && _style.Checked != null)
                {
                    background = IsOver ? (_style.CheckedOver ?? _style.Checked) : _style.Checked;
                }
                else if (IsOver && _style.Over != null)
                {
                    background = _style.Over;
                }
                else
                {
                    background = _style.Up;
                }

                offsetX = _style.UnpressedOffsetX;
                offsetY = _style.UnpressedOffsetY;
            }

            if (background != null)
            {
                spriteBatch.Color = Color.MultiplyAlpha(parentAlpha);
                background.Draw(spriteBatch, X, Y, Width, Height);
            }

            foreach (var child in Children)
            {
                child.Translate(offsetX, offsetY);
            }

            base.Draw(spriteBatch, parentAlpha);

            foreach (var child in Children)
            {
                child.Translate(-offsetX, -offsetY);
            }
        }
Exemplo n.º 15
0
        private void Draw(GdxSpriteBatch spriteBatch, List <TreeNode> nodes, float indent)
        {
            ISceneDrawable plus  = _style.Plus;
            ISceneDrawable minus = _style.Minus;
            float          x     = X;
            float          y     = Y;

            foreach (TreeNode node in nodes)
            {
                Actor actor = node.Actor;
                float iconY = 0;

                bool selected = _selectedNodes.Contains(node);
                if (selected && _style.Selection != null)
                {
                    _style.Selection.Draw(spriteBatch, x, y + actor.Y - YSpacing / 2, Width, node.Height + YSpacing);
                }
                else if (node == OverNode && _style.Over != null)
                {
                    _style.Over.Draw(spriteBatch, x, y + actor.Y - YSpacing / 2, Width, node.Height + YSpacing);
                }

                if (node.Icon != null)
                {
                    ISceneDrawable icon = node.Icon;
                    iconY             = actor.Y + (float)Math.Round((node.Height - icon.MinHeight) / 2);
                    spriteBatch.Color = actor.Color;
                    icon.Draw(spriteBatch, x + node.Actor.X - IconSpacing - icon.MinWidth, y + iconY, icon.MinWidth, icon.MinHeight);
                    spriteBatch.Color = Microsoft.Xna.Framework.Color.White;
                }

                if (node.Children.Count == 0)
                {
                    continue;
                }

                ISceneDrawable expandIcon = node.IsExpanded ? minus : plus;
                if (selected)
                {
                    expandIcon = node.IsExpanded ? _style.MinusSelection ?? minus : _style.PlusSelection ?? plus;
                }

                iconY = actor.Y + (float)Math.Round((node.Height - expandIcon.MinHeight) / 2);
                expandIcon.Draw(spriteBatch, x + indent - IconSpacing, y + iconY, expandIcon.MinWidth, expandIcon.MinHeight);

                if (node.IsExpanded)
                {
                    Draw(spriteBatch, node.Children, indent + _indentSpacing);
                }
            }
        }
Exemplo n.º 16
0
        private void CalculateHorizBoundsAndPositions()
        {
            ISceneDrawable handle = _style.Handle;
            float          height = Height;

            float availWidth     = Width - handle.MinWidth;
            float leftAreaWidth  = (int)(availWidth * _splitAmount);
            float rightAreaWidth = availWidth - leftAreaWidth;
            float handleWidth    = handle.MinWidth;

            _firstWidgetBounds  = new RectangleF(0, 0, leftAreaWidth, height);
            _secondWidgetBounds = new RectangleF(leftAreaWidth + handleWidth, 0, rightAreaWidth, height);
            _handleBounds       = new RectangleF(leftAreaWidth, 0, handleWidth, height);
        }
Exemplo n.º 17
0
        private void CalculateVertBoundsAndPositions()
        {
            ISceneDrawable handle = _style.Handle;
            float          width  = Width;
            float          height = Height;

            float availHeight      = height - handle.MinHeight;
            float topAreaHeight    = (int)(availHeight * _splitAmount);
            float bottomAreaHeight = availHeight - topAreaHeight;
            float handleHeight     = handle.MinHeight;

            _firstWidgetBounds  = new RectangleF(0, height - topAreaHeight, width, topAreaHeight);
            _secondWidgetBounds = new RectangleF(0, 0, width, bottomAreaHeight);
            _handleBounds       = new RectangleF(0, bottomAreaHeight, width, handleHeight);
        }
Exemplo n.º 18
0
        public ISceneDrawable NewDrawable(ISceneDrawable drawable, Xna.Color tint)
        {
            if (drawable is TextureRegionDrawable)
            {
                TextureRegion region = (drawable as TextureRegionDrawable).Region;
                Sprite        sprite;
                if (region is TextureAtlas.AtlasRegion)
                {
                    sprite = new TextureAtlas.AtlasSprite(region as TextureAtlas.AtlasRegion);
                }
                else
                {
                    sprite = new Sprite(region);
                }

                sprite.Color = tint;
                return(new SpriteDrawable(sprite));
            }

            if (drawable is NinePatchDrawable)
            {
                NinePatchDrawable patchDrawable = new NinePatchDrawable(drawable as NinePatchDrawable);
                patchDrawable.Patch = new NinePatch(patchDrawable.Patch, tint);
                return(patchDrawable);
            }

            if (drawable is SpriteDrawable)
            {
                SpriteDrawable spriteDrawable = new SpriteDrawable(drawable as SpriteDrawable);
                Sprite         sprite         = spriteDrawable.Sprite;

                if (sprite is TextureAtlas.AtlasSprite)
                {
                    sprite = new TextureAtlas.AtlasSprite(sprite as TextureAtlas.AtlasSprite);
                }
                else
                {
                    sprite = new Sprite(sprite);
                }

                sprite.Color          = tint;
                spriteDrawable.Sprite = sprite;
                return(spriteDrawable);
            }

            throw new Exception("Unable to copy, unknown drawbale type: " + drawable.GetType());
        }
Exemplo n.º 19
0
        public ISceneDrawable NewDrawable(ISceneDrawable drawable)
        {
            if (drawable is TextureRegionDrawable)
            {
                return(new TextureRegionDrawable(drawable as TextureRegionDrawable));
            }
            if (drawable is NinePatchDrawable)
            {
                return(new NinePatchDrawable(drawable as NinePatchDrawable));
            }
            if (drawable is SpriteDrawable)
            {
                return(new SpriteDrawable(drawable as SpriteDrawable));
            }

            throw new Exception("Unable to copy, unknown drawable type: " + drawable.GetType());
        }
Exemplo n.º 20
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ActorView"/> class.
        /// </summary>
        /// <param name="actor">The actor.</param>
        public ActorView(Actor actor)
        {
            _actor = actor;

            if (Actor.DrawableAsset != null)
            {
                sceneDrawable = Actor.DrawableAsset.CreateView();

                Actor.DrawableAsset.DrawableAssetChanged += new EventHandler(DrawableAsset_DrawableAssetChanged);
            }

            Actor.AppearanceChanged    += new EventHandler(Actor_AppearanceChanged);
            Actor.DrawableAssetChanged += new ValueChangedHandler <DrawableAsset>(Actor_DrawableAssetChanged);

            Actor.Children.ListChanged += new ObservableList <Actor> .ListChangedEventHandler(Children_ListChanged);

            UpdateAppearance();
        }
Exemplo n.º 21
0
        public void SetItems(object[] objects)
        {
            if (objects == null)
            {
                throw new ArgumentNullException("objects");
            }

            _items = objects;
            if (!(objects is string[]))
            {
                string[] strings = new string[objects.Length];
                for (int i = 0, n = objects.Length; i < n; i++)
                {
                    strings[i] = objects[i].ToString();
                }
                _itemsText = strings;
            }
            else
            {
                _itemsText = objects as string[];
            }

            _selectedIndex = 0;

            BitmapFont     font             = _style.Font;
            ISceneDrawable selectedDrawable = _style.Selection;

            _itemHeight  = font.CapHeight - font.Descent * 2;
            _itemHeight += selectedDrawable.TopHeight + selectedDrawable.BottomHeight;
            _textOffsetX = selectedDrawable.LeftWidth;
            _textOffsetY = selectedDrawable.TopHeight - font.Descent;

            _prefWidth = 0;
            for (int i = 0; i < _items.Length; i++)
            {
                TextBounds bounds = font.GetBounds(_itemsText[i]);
                _prefWidth = Math.Max(bounds.Width, _prefWidth);
            }
            _prefWidth += selectedDrawable.LeftWidth + selectedDrawable.RightWidth;
            _prefHeight = _items.Length * _itemHeight;

            InvalidateHierarchy();
        }
Exemplo n.º 22
0
        public override void Draw(GdxSpriteBatch spriteBatch, float parentAlpha)
        {
            Stage stage = Stage;

            Validate();

            ISceneDrawable handle = _style.Handle;

            ApplyTransform(spriteBatch, ComputeTransform());
            Matrix transform = spriteBatch.TransformMatrix;

            if (_firstWidget != null)
            {
                _firstScissors = ScissorStack.CalculateScissors(stage.Camera, spriteBatch.TransformMatrix, (Rectangle)_firstWidgetBounds);
                if (stage.ScissorStack.PushScissors(_firstScissors))
                {
                    if (_firstWidget.IsVisible)
                    {
                        _firstWidget.Draw(spriteBatch, parentAlpha * Color.A / 255f);
                    }
                    spriteBatch.Flush();
                    stage.ScissorStack.PopScissors();
                }
            }

            if (_secondWidget != null)
            {
                _secondScissors = ScissorStack.CalculateScissors(stage.Camera, spriteBatch.TransformMatrix, (Rectangle)_secondWidgetBounds);
                if (stage.ScissorStack.PushScissors(_secondScissors))
                {
                    if (_secondWidget.IsVisible)
                    {
                        _secondWidget.Draw(spriteBatch, parentAlpha * Color.A / 255f);
                    }
                    spriteBatch.Flush();
                    stage.ScissorStack.PopScissors();
                }
            }

            spriteBatch.Color = Color;
            handle.Draw(spriteBatch, _handleBounds.X, _handleBounds.Y, _handleBounds.Width, _handleBounds.Height);
            ResetTransform(spriteBatch);
        }
Exemplo n.º 23
0
        /// <summary>
        /// Handles the <see cref="Actors.Actor.DrawableAssetChanged"/> event of the <see cref="Actor"/>.
        /// Updates the scene drawable element for the <see cref="ActorView"/> and collision shapes which are shown at the scene.
        /// </summary>
        private void Actor_DrawableAssetChanged(object sender, ValueChangedEventArgs <DrawableAsset> e)
        {
            if (e.OldValue != null)
            {
                e.OldValue.DrawableAssetChanged -= new EventHandler(DrawableAsset_DrawableAssetChanged);
            }

            if (Actor.DrawableAsset != null)
            {
                sceneDrawable = Actor.DrawableAsset.CreateView();

                Actor.DrawableAsset.DrawableAssetChanged += new EventHandler(DrawableAsset_DrawableAssetChanged);
            }
            else
            {
                sceneDrawable = null;
            }

            UpdateShapes();
        }
Exemplo n.º 24
0
        public void SetBackground(ISceneDrawable background)
        {
            if (Background == background)
            {
                return;
            }

            Background = background;
            if (background == null)
            {
                Pad(null);
            }
            else
            {
                PadBottom = background.BottomHeight;
                PadTop    = background.TopHeight;
                PadLeft   = background.LeftWidth;
                PadRight  = background.RightWidth;
                Invalidate();
            }
        }
Exemplo n.º 25
0
        protected override void OnTouchDrag(TouchEventArgs e)
        {
            base.OnTouchDrag(e);

            if (e.Pointer != _draggingPointer)
            {
                return;
            }

            Vector2 position = e.GetPosition(this);

            ISceneDrawable handle = _style.Handle;

            if (!IsVertical)
            {
                float delta      = position.X - _lastPoint.X;
                float availWidth = Width - handle.MinWidth;
                float dragX      = _handlePosition.X + delta;
                _handlePosition.X = dragX;

                dragX        = MathHelper.Clamp(dragX, 0, availWidth);
                _splitAmount = dragX / availWidth;
                _splitAmount = MathHelper.Clamp(_splitAmount, _minAmount, _maxAmount);
                _lastPoint   = position;
            }
            else
            {
                float delta       = position.Y - _lastPoint.Y;
                float availHeight = Height - handle.MinHeight;
                float dragY       = _handlePosition.Y + delta;
                _handlePosition.Y = dragY;

                dragY        = MathHelper.Clamp(dragY, 0, availHeight);
                _splitAmount = 1 - (dragY / availHeight);
                _splitAmount = MathHelper.Clamp(_splitAmount, _minAmount, _maxAmount);
                _lastPoint   = position;
            }

            Invalidate();
        }
Exemplo n.º 26
0
        public override void Draw(GdxSpriteBatch spriteBatch, float parentAlpha)
        {
            BitmapFont     font                = _style.Font;
            ISceneDrawable selectedDrawable    = _style.Selection;
            Color          fontColorSelected   = _style.FontColorSelected;
            Color          fontColorUnselected = _style.FontColorUnselected;

            spriteBatch.Color = Color.MultiplyAlpha(parentAlpha);

            float x = X;
            float y = Y;

            font.Color = fontColorUnselected.MultiplyAlpha(parentAlpha);
            float itemY = Height;

            for (int i = 0; i < _items.Length; i++)
            {
                if (_cullingArea.IsEmpty || (itemY - _itemHeight <= _cullingArea.Y + _cullingArea.Height && itemY >= _cullingArea.Y))
                {
                    if (_selectedIndex == i)
                    {
                        selectedDrawable.Draw(spriteBatch, x, y + itemY - _itemHeight, Width, ItemHeight);
                        font.Color = fontColorSelected.MultiplyAlpha(parentAlpha);
                    }
                    font.Draw(spriteBatch, _itemsText[i], x + _textOffsetX, y + itemY - _textOffsetY);

                    if (_selectedIndex == i)
                    {
                        font.Color = fontColorUnselected.MultiplyAlpha(parentAlpha);
                    }
                }
                else if (itemY < _cullingArea.Y)
                {
                    break;
                }

                itemY -= ItemHeight;
            }
        }
Exemplo n.º 27
0
        bool CalculatePositionAndValue(float x, float y)
        {
            ISceneDrawable knob = (IsDisabled && _style.DisabledKnob != null) ? _style.DisabledKnob : _style.Knob;
            ISceneDrawable bg   = (IsDisabled && _style.DisabledBackground != null) ? _style.DisabledBackground : _style.Background;

            float value;
            float oldPosition = _sliderPos;

            if (_vertical)
            {
                float height     = Height - bg.TopHeight - bg.BottomHeight;
                float knobHeight = (knob == null) ? 0 : knob.MinHeight;
                _sliderPos = y - bg.BottomHeight - knobHeight * .5f;
                value      = _min + (_max - _min) * (_sliderPos / (height - knobHeight));
                _sliderPos = Math.Max(0, _sliderPos);
                _sliderPos = Math.Min(height - knobHeight, _sliderPos);
            }
            else
            {
                float width     = Width - bg.LeftWidth - bg.RightWidth;
                float knobWidth = (knob == null) ? 0 : knob.MinWidth;
                _sliderPos = x - bg.LeftWidth - knobWidth * .5f;
                value      = _min + (_max - _min) * (_sliderPos / (width - knobWidth));
                _sliderPos = Math.Max(0, _sliderPos);
                _sliderPos = Math.Min(width - knobWidth, _sliderPos);
            }

            float oldValue = value;
            bool  valueSet = SetValue(value);

            if (value == oldValue)
            {
                _sliderPos = oldPosition;
            }

            return(valueSet);
        }
Exemplo n.º 28
0
            public void Show(Stage stage)
            {
                stage.AddActor(this);

                Vector2 stageCoords = _selectBox.LocalToStageCoordinates(Vector2.Zero);

                _screenCoords = stageCoords;

                _list.SetItems(_selectBox.Items);
                _list.SelectedIndex = _selectBox.SelectionIndex;

                // Show the list above or below the select box, limited to a number of items and the available height in the stage.
                float itemHeight = _list.ItemHeight;
                float height     = itemHeight * (_selectBox.MaxListCount <= 0 ? _selectBox.Items.Length
                    : Math.Min(_selectBox.MaxListCount, _selectBox.Items.Length));
                ISceneDrawable background = Style.Background;

                if (background != null)
                {
                    height += background.TopHeight + background.BottomHeight;
                }

                float heightBelow = stageCoords.Y;
                float heightAbove = stage.Camera.ViewportHeight - stageCoords.Y - _selectBox.Height;

                bool below = true;

                if (height > heightBelow)
                {
                    if (heightAbove > heightBelow)
                    {
                        below  = false;
                        height = Math.Min(height, heightAbove);
                    }
                    else
                    {
                        height = heightBelow;
                    }
                }

                if (below)
                {
                    Y = stageCoords.Y - height;
                }
                else
                {
                    Y = stageCoords.Y + _selectBox.Height;
                }

                X      = stageCoords.X + _selectBox.Style.ListLeftOffset;
                Width  = _selectBox.Width + _selectBox.Style.ListLeftOffset + _selectBox.Style.ListRightOffset;
                Height = height;

                ScrollToCenter(0, _list.Height - _selectBox.SelectionIndex * itemHeight - itemHeight / 2, 0, 0);
                UpdateVisualScroll();

                ClearActions();
                Color = new Color(Color.R, Color.G, Color.B, 0);
                AddAction(ActionRepo.FadeIn(.3f, Interpolation.Fade));

                stage.SetScrollFocus(this);
            }
Exemplo n.º 29
0
        public void SetBackground(ISceneDrawable background)
        {
            if (Background == background)
                return;

            Background = background;
            if (background == null)
                Pad(null);
            else {
                PadBottom = background.BottomHeight;
                PadTop = background.TopHeight;
                PadLeft = background.LeftWidth;
                PadRight = background.RightWidth;
                Invalidate();
            }
        }
Exemplo n.º 30
0
 public ImageButtonStyle(ISceneDrawable up, ISceneDrawable down, ISceneDrawable chkd, 
     ISceneDrawable imageUp, ISceneDrawable imageDown, ISceneDrawable imageChkd)
     : base(up, down, chkd)
 {
     ImageUp = imageUp;
     ImageDown = imageDown;
     ImageChecked = imageChkd;
 }
Exemplo n.º 31
0
 public ImageButton(ISceneDrawable imageUp, ISceneDrawable imageDown, ISceneDrawable imageChecked)
     : this(new ImageButtonStyle(null, null, null, imageUp, imageDown, imageChecked))
 {
 }
Exemplo n.º 32
0
 public ImageButton(ISceneDrawable imageUp)
     : this(new ImageButtonStyle(null, null, null, imageUp, null, null))
 {
 }
Exemplo n.º 33
0
        public override void Draw(Graphics.G2D.GdxSpriteBatch spriteBatch, float parentAlpha)
        {
            SliderStyle style    = Style;
            bool        disabled = IsDisabled;

            ISceneDrawable knob       = (disabled && style.DisabledKnob != null) ? style.DisabledKnob : style.Knob;
            ISceneDrawable bg         = (disabled && style.DisabledBackground != null) ? style.DisabledBackground : style.Background;
            ISceneDrawable knobBefore = (disabled && style.DisabledKnobBefore != null) ? style.DisabledKnobBefore : style.KnobBefore;
            ISceneDrawable knobAfter  = (disabled && style.DisabledKnobAfter != null) ? style.DisabledKnobAfter : style.KnobAfter;

            Color color      = Color;
            float x          = X;
            float y          = Y;
            float width      = Width;
            float height     = Height;
            float knobHeight = (knob == null) ? 0 : knob.MinHeight;
            float knobWidth  = (knob == null) ? 0 : knob.MinWidth;
            float value      = VisualValue;

            spriteBatch.Color = color.MultiplyAlpha(parentAlpha);

            if (_vertical)
            {
                bg.Draw(spriteBatch, x + (int)((width - bg.MinWidth) * .5f), y, bg.MinWidth, height);

                float sliderPosHeight = height - (bg.TopHeight + bg.BottomHeight);
                if (_min != _max)
                {
                    _sliderPos = (value - _min) / (_max - _min) * (sliderPosHeight - knobHeight);
                    _sliderPos = Math.Max(0, _sliderPos);
                    _sliderPos = Math.Min(sliderPosHeight - knobHeight, _sliderPos) + bg.BottomHeight;
                }

                float knobHeightHalf = knobHeight * .5f;
                if (knobBefore != null)
                {
                    knobBefore.Draw(spriteBatch, x + (int)((width - knobBefore.MinWidth) * .5f), y,
                                    knobBefore.MinWidth, (int)(_sliderPos + knobHeightHalf));
                }
                if (knobAfter != null)
                {
                    knobAfter.Draw(spriteBatch, x + (int)((width - knobAfter.MinWidth) * .5f), y + (int)(_sliderPos + knobHeightHalf),
                                   knobAfter.MinWidth, height - (int)(_sliderPos + knobHeightHalf));
                }
                if (knob != null)
                {
                    knob.Draw(spriteBatch, x + (int)((width - knobWidth) * .5f), (int)(y + _sliderPos), knobWidth, knobHeight);
                }
            }
            else
            {
                bg.Draw(spriteBatch, x, y + (int)((height - bg.MinHeight) * .5f), width, bg.MinHeight);

                float sliderPosWidth = width - (bg.LeftWidth + bg.RightWidth);
                if (_min != _max)
                {
                    _sliderPos = (value - _min) / (_max - _min) * (sliderPosWidth - knobWidth);
                    _sliderPos = Math.Max(0, _sliderPos);
                    _sliderPos = Math.Min(sliderPosWidth - knobWidth, _sliderPos) + bg.LeftWidth;
                }

                float knobWidthHalf = knobWidth * .5f;
                if (knobBefore != null)
                {
                    knobBefore.Draw(spriteBatch, x, y + (int)((height - knobBefore.MinHeight) * .5f),
                                    (int)(_sliderPos + knobWidthHalf), knobBefore.MinHeight);
                }
                if (knobAfter != null)
                {
                    knobAfter.Draw(spriteBatch, x + (int)(_sliderPos + knobWidthHalf), y + (int)((height - knobAfter.MinWidth) * .5f),
                                   width - (int)(_sliderPos + knobWidthHalf), knobAfter.MinHeight);
                }
                if (knob != null)
                {
                    knob.Draw(spriteBatch, (int)(x + _sliderPos), (int)(y + (height - knobHeight) * .5f), knobWidth, knobHeight);
                }
            }
        }
Exemplo n.º 34
0
 public ImageButton(ISceneDrawable imageUp, ISceneDrawable imageDown, ISceneDrawable imageChecked)
     : this(new ImageButtonStyle(null, null, null, imageUp, imageDown, imageChecked))
 {
 }
Exemplo n.º 35
0
 public SliderStyle(ISceneDrawable background, ISceneDrawable knob)
 {
     Background = background;
     Knob = knob;
 }
Exemplo n.º 36
0
 public ImageTextButtonStyle(ISceneDrawable up, ISceneDrawable down, ISceneDrawable chkd,
     BitmapFont font)
     : base(up, down, chkd, font)
 {
 }
Exemplo n.º 37
0
 public Image(ISceneDrawable drawable)
     : this(drawable, Scaling.Stretch, Alignment.Center)
 {
 }
Exemplo n.º 38
0
 public Image(ISceneDrawable drawable, Scaling scaling)
     : this(drawable, scaling, Alignment.Center)
 {
 }
Exemplo n.º 39
0
 public ListStyle(BitmapFont font, Color fontColorSelected, Color fontColorUnselected, ISceneDrawable selection)
 {
     Font = font;
     FontColorSelected = fontColorSelected;
     FontColorUnselected = fontColorUnselected;
     Selection = selection;
 }
Exemplo n.º 40
0
 public SplitPaneStyle(ISceneDrawable handle)
 {
     Handle = handle;
 }
Exemplo n.º 41
0
 public SliderStyle(ISceneDrawable background, ISceneDrawable knob)
 {
     Background = background;
     Knob       = knob;
 }
Exemplo n.º 42
0
 public SelectBoxStyle(BitmapFont font, Color fontColor, ISceneDrawable background, ScrollPaneStyle scrollStyle, ListStyle listStyle)
 {
     Font = font;
     FontColor = fontColor;
     Background = background;
     ScrollStyle = scrollStyle;
     ListStyle = listStyle;
 }
Exemplo n.º 43
0
 public TextButtonStyle(ISceneDrawable up, ISceneDrawable down, ISceneDrawable chkd, BitmapFont font)
     : base(up, down, chkd)
 {
     Font = font;
 }
Exemplo n.º 44
0
 public HorizontalGroupStyle(ISceneDrawable background)
 {
     Background = background;
 }
Exemplo n.º 45
0
 public TreeStyle(ISceneDrawable plus, ISceneDrawable minus, ISceneDrawable selection)
 {
     Plus = plus;
     Minus = minus;
     Selection = selection;
 }
Exemplo n.º 46
0
 public Button(ISceneDrawable up, ISceneDrawable down)
     : this(new ButtonStyle(up, down, null))
 {
 }
Exemplo n.º 47
0
 public CheckBoxStyle(ISceneDrawable checkboxOff, ISceneDrawable checkboxOn, BitmapFont font, Color fontColor)
 {
     CheckboxOff = checkboxOff;
     CheckboxOn = checkboxOn;
     Font = font;
     FontColor = fontColor;
 }
Exemplo n.º 48
0
 public ScrollPaneStyle(ISceneDrawable background, ISceneDrawable hScroll, ISceneDrawable hScrollKnob, 
     ISceneDrawable vScoll, ISceneDrawable vScrollKnob)
 {
     Background = background;
     HScroll = hScroll;
     HScrollKnob = hScrollKnob;
     VScroll = vScoll;
     VScrollKnob = vScrollKnob;
 }
Exemplo n.º 49
0
 public Button(ISceneDrawable up, ISceneDrawable down, ISceneDrawable chkd)
     : this(new ButtonStyle(up, down, chkd))
 {
 }
Exemplo n.º 50
0
 public ImageButton(ISceneDrawable imageUp)
     : this(new ImageButtonStyle(null, null, null, imageUp, null, null))
 {
 }
Exemplo n.º 51
0
 public ButtonStyle(ISceneDrawable up, ISceneDrawable down, ISceneDrawable chkd)
 {
     Up = up;
     Down = down;
     Checked = chkd;
 }
Exemplo n.º 52
0
 public WindowStyle(BitmapFont titleFont, Color titleFontColor, ISceneDrawable background)
 {
     Background = background;
     TitleFont = titleFont;
     TitleFontColor = titleFontColor;
 }
Exemplo n.º 53
0
 public Button(ISceneDrawable up)
     : this(new ButtonStyle(up, null, null))
 {
 }