コード例 #1
0
        public override void Draw(GdxSpriteBatch spriteBatch, float parentAlpha)
        {
            Validate();

            spriteBatch.Color = Color.MultiplyAlpha(parentAlpha);

            float x      = X;
            float y      = Y;
            float scaleX = ScaleX;
            float scaleY = ScaleY;

            if (_drawable != null)
            {
                if (_drawable is TextureRegionDrawable)
                {
                    TextureRegion region   = (Drawable as TextureRegionDrawable).Region;
                    float         rotation = Rotation;
                    if (scaleX == 1 && scaleY == 1 && rotation == 0)
                    {
                        spriteBatch.Draw(region, x + ImageX, y + ImageY, ImageWidth, ImageHeight);
                    }
                    else
                    {
                        spriteBatch.Draw(region, x + ImageX, y + ImageY, OriginX - ImageX, OriginY - ImageY, ImageWidth, ImageHeight, scaleX, scaleY, rotation);
                    }
                }
                else
                {
                    _drawable.Draw(spriteBatch, x + ImageX, y + ImageY, ImageWidth * scaleX, ImageHeight * scaleY);
                }
            }
        }
コード例 #2
0
        public override void Draw(GdxSpriteBatch spriteBatch, float parentAlpha)
        {
            Validate();
            DrawBackground(spriteBatch, parentAlpha);

            if (IsTransform)
            {
                ApplyTransform(spriteBatch, ComputeTransform());
                if (_clip)
                {
                    bool draw = Background == null
                        ? ClipBegin(0, 0, Width, Height)
                        : ClipBegin(_layout.PadLeft, _layout.PadBottom, Width - _layout.PadLeft - _layout.PadRight, Height - _layout.PadBottom - _layout.PadTop);

                    if (draw)
                    {
                        DrawChildren(spriteBatch, parentAlpha);
                        ClipEnd();
                    }
                }
                else
                {
                    DrawChildren(spriteBatch, parentAlpha);
                }
                ResetTransform(spriteBatch);
            }
            else
            {
                base.Draw(spriteBatch, parentAlpha);
            }
        }
コード例 #3
0
        public override void Draw(GdxSpriteBatch spriteBatch, float parentAlpha)
        {
            Stage stage = Stage;

            if (KeepWithinStage && Parent == stage.Root)
            {
                float parentWidth  = stage.Width;
                float parentHeight = stage.Height;
                if (X < 0)
                {
                    X = 0;
                }
                if (Right > parentWidth)
                {
                    X = parentWidth - Width;
                }
                if (Y < 0)
                {
                    Y = 0;
                }
                if (Top > parentHeight)
                {
                    Y = parentHeight - Height;
                }
            }

            base.Draw(spriteBatch, parentAlpha);
        }
コード例 #4
0
        public override void Draw(GdxSpriteBatch spriteBatch, float parentAlpha)
        {
            UpdateImage();

            Color?fontColor;

            if (IsDisabled && _style.DisabledFontColor != null)
            {
                fontColor = _style.DisabledFontColor;
            }
            else if (IsPressed && _style.DownFontColor != null)
            {
                fontColor = _style.DownFontColor;
            }
            else if (IsChecked && _style.CheckedFontColor != null)
            {
                fontColor = IsOver ? (_style.CheckedOverFontColor ?? _style.CheckedFontColor) : _style.CheckedFontColor;
            }
            else if (IsOver && _style.OverFontColor != null)
            {
                fontColor = _style.OverFontColor;
            }
            else
            {
                fontColor = _style.FontColor;
            }

            if (fontColor != null)
            {
                _label.Style.FontColor = fontColor;
            }

            base.Draw(spriteBatch, parentAlpha);
        }
コード例 #5
0
        protected override void InitializeCore()
        {
            string fontFile  = "verdana39.fnt";
            string imageFile = "verdana39.png";

            _batch = new GdxSpriteBatch(Context.GraphicsDevice);
            _font  = new BitmapFont(Context.GraphicsDevice, fontFile, imageFile, false);
        }
コード例 #6
0
 protected virtual void DrawBackground(GdxSpriteBatch spriteBatch, float parentAlpha)
 {
     if (Background != null)
     {
         Color c = Color;
         spriteBatch.Color = new Color(c.R, c.G, c.B, c.A * parentAlpha);
         Background.Draw(spriteBatch, X, Y, Width, Height);
     }
 }
コード例 #7
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);
            }
        }
コード例 #8
0
        public override void Draw(GdxSpriteBatch spriteBatch, float x, float y, float width, float height)
        {
            Sprite.SetBounds(x, y, width, height);

            Color color = Sprite.Color;

            Sprite.Color = ColorExt.Multiply(color, spriteBatch.Color);

            Sprite.Draw(spriteBatch);
            Sprite.Color = color;
        }
コード例 #9
0
        public override void Draw(GdxSpriteBatch spriteBatch, float parentAlpha)
        {
            Validate();

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

            base.Draw(spriteBatch, parentAlpha);
        }
コード例 #10
0
        public override void Draw(GdxSpriteBatch spriteBatch, float parentAlpha)
        {
            if (_style.Background != null)
            {
                spriteBatch.Color = Color.MultiplyAlpha(parentAlpha);
                _style.Background.Draw(spriteBatch, X, Y, Width, Height);
                spriteBatch.Color = Microsoft.Xna.Framework.Color.White;
            }

            Draw(spriteBatch, _rootNodes, _leftColumnWidth);
            base.Draw(spriteBatch, parentAlpha);
        }
コード例 #11
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);
                }
            }
        }
コード例 #12
0
        public override void Draw(GdxSpriteBatch spriteBatch, float parentAlpha)
        {
            if (IsTransform)
            {
                ApplyTransform(spriteBatch, ComputeTransform());
            }

            DrawChildren(spriteBatch, parentAlpha);

            if (IsTransform)
            {
                ResetTransform(spriteBatch);
            }
        }
コード例 #13
0
        public override void Draw(GdxSpriteBatch spriteBatch, float parentAlpha)
        {
            ISceneDrawable background;

            if (_list != null && _list.Parent != null && _style.BackgroundOpen != null)
            {
                background = _style.BackgroundOpen;
            }
            else if (IsDisabled && _style.BackgroundDisabled != null)
            {
                background = _style.BackgroundDisabled;
            }
            else if (_pointerIsOver && _style.BackgroundOver != null)
            {
                background = _style.BackgroundOver;
            }
            else
            {
                background = _style.Background;
            }

            BitmapFont font      = _style.Font;
            Color      fontColor = _style.FontColor;

            if (IsDisabled && _style.FontColorDisabled != null)
            {
                fontColor = _style.FontColorDisabled.Value;
            }

            float x      = (int)X;
            float y      = (int)Y;
            float width  = Width;
            float height = Height;

            spriteBatch.Color = Color.MultiplyAlpha(parentAlpha);
            background.Draw(spriteBatch, x, y, width, height);

            if (_items.Length > 0)
            {
                float availableWidth = width - background.LeftWidth - background.RightWidth;
                int   numGlyphs      = font.ComputeVisibleGlyphs(_itemsText[SelectionIndex], 0, _itemsText[SelectionIndex].Length, availableWidth);
                _bounds = font.GetBounds(_itemsText[SelectionIndex]);

                height -= background.BottomHeight + background.TopHeight;
                float textY = (int)(height / 2 + background.BottomHeight + _bounds.Height / 2);

                font.Color = fontColor.MultiplyAlpha(parentAlpha);
                font.Draw(spriteBatch, _itemsText[SelectionIndex], x + background.LeftWidth, y + textY, 0, numGlyphs);
            }
        }
コード例 #14
0
        public override void Draw(GdxSpriteBatch spriteBatch, float parentAlpha)
        {
            Validate();

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

            _cache.Color = (_style.FontColor == null) ? Color : Color.Multiply(_style.FontColor.Value);
            _cache.SetPosition(X, Y);
            _cache.Draw(spriteBatch, (Color.A / 255f) * parentAlpha);
        }
コード例 #15
0
        protected override void DrawBackground(GdxSpriteBatch spriteBatch, float parentAlpha)
        {
            if (_style.StageBackground != null)
            {
                spriteBatch.Color = Color.MultiplyAlpha(parentAlpha);

                Stage   stage     = Stage;
                Vector2 localPos  = StageToLocalCoordinates(Vector2.Zero);
                Vector2 localSize = StageToLocalCoordinates(new Vector2(stage.Width, stage.Height));

                _style.StageBackground.Draw(spriteBatch, X + localPos.X, Y + localPos.Y, X + localSize.X, Y + localSize.Y);
            }

            base.DrawBackground(spriteBatch, parentAlpha);

            float      x      = X;
            float      y      = Y + Height;
            TextBounds bounds = _titleCache.Bounds;

            if ((_titleAlignment & Alignment.Left) != 0)
            {
                x += PadLeft;
            }
            else if ((_titleAlignment & Alignment.Right) != 0)
            {
                x += Width - bounds.Width - PadRight;
            }
            else
            {
                x += (Width - bounds.Width) / 2;
            }

            if ((_titleAlignment & Alignment.Top) == 0)
            {
                if ((_titleAlignment & Alignment.Bottom) != 0)
                {
                    y -= PadTop - bounds.Height;
                }
                else
                {
                    y -= (PadTop - bounds.Height) / 2;
                }
            }

            _titleCache.Color = Color.Multiply(_style.TitleFontColor);
            _titleCache.SetPosition((int)x, (int)y);
            _titleCache.Draw(spriteBatch, parentAlpha);
        }
コード例 #16
0
ファイル: Stage.cs プロジェクト: SkyVault/desire_and_doom
        public Stage(float width, float height, bool keepAspectRatio, GdxSpriteBatch spriteBatch)
        {
            Width       = width;
            Height      = height;
            SpriteBatch = spriteBatch;

            Root = new Group()
            {
                Stage = this,
            };

            Camera = new OrthographicCamera(spriteBatch.GraphicsDevice);
            SetViewport(width, height, keepAspectRatio);

            ScissorStack = new ScissorStack(spriteBatch.GraphicsDevice);
        }
コード例 #17
0
        public override void Draw(GdxSpriteBatch spriteBatch, float parentAlpha)
        {
            if (IsDisabled)
            {
                _image.Drawable = (IsChecked) ? _style.CheckboxOnDisabled ?? _style.CheckboxOn : _style.CheckboxOffDisabled ?? _style.CheckboxOff;
            }
            else if (IsOver)
            {
                _image.Drawable = (IsChecked) ? _style.CheckboxOnOver ?? _style.CheckboxOn : _style.CheckboxOffOver ?? _style.CheckboxOff;
            }
            else
            {
                _image.Drawable = (IsChecked) ? _style.CheckboxOn : _style.CheckboxOff;
            }

            base.Draw(spriteBatch, parentAlpha);
        }
コード例 #18
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);
        }
コード例 #19
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;
            }
        }
コード例 #20
0
 protected void ResetTransform(GdxSpriteBatch spriteBatch)
 {
     spriteBatch.TransformMatrix = _oldBatchTransform;
 }
コード例 #21
0
 protected void ApplyTransform(GdxSpriteBatch spriteBatch, Matrix transform)
 {
     _oldBatchTransform          = spriteBatch.TransformMatrix;
     spriteBatch.TransformMatrix = transform;
 }
コード例 #22
0
        public override void Draw(GdxSpriteBatch spriteBatch, float x, float y, float width, float height)
        {
            TextureRegion region = Region;

            float regionWidth  = region.RegionWidth;
            float regionHeight = region.RegionHeight;
            float remainingX   = width % regionWidth;
            float remainingY   = height % regionHeight;

            float startX = x;
            float startY = y;
            float endX   = x + width - remainingX;
            float endY   = y + height - remainingY;

            while (x < endX)
            {
                y = startY;
                while (y < endY)
                {
                    spriteBatch.Draw(region, x, y, regionWidth, regionHeight);
                    y += regionHeight;
                }
                x += regionWidth;
            }

            TextureContext texture = region.Texture;
            float          u       = region.U;
            float          v2      = region.V2;

            if (remainingX > 0)
            {
                float u2 = u + remainingX / texture.Width;
                float v  = region.V;

                y = startY;
                while (y < endY)
                {
                    spriteBatch.Draw(texture, x, y, remainingX, regionHeight, u, v2, u2, v);
                    y += regionHeight;
                }

                if (remainingY > 0)
                {
                    v = v2 - remainingY / texture.Height;
                    spriteBatch.Draw(texture, x, y, remainingX, remainingY, u, v2, u2, v);
                }
            }

            if (remainingY > 0)
            {
                float u2 = region.U2;
                float v  = v2 - remainingY / texture.Height;

                x = startX;
                while (x < endX)
                {
                    spriteBatch.Draw(texture, x, y, regionWidth, remainingY, u, v2, u2, v);
                    x += regionWidth;
                }
            }
        }
コード例 #23
0
 public override void Draw(GdxSpriteBatch spriteBatch, float x, float y, float width, float height)
 {
     spriteBatch.Draw(Region, x, y, width, height);
 }
コード例 #24
0
 public override void Draw(GdxSpriteBatch spriteBatch, float parentAlpha)
 {
     UpdateImage();
     base.Draw(spriteBatch, parentAlpha);
 }
コード例 #25
0
 public virtual void Draw(GdxSpriteBatch spriteBatch, float parentAlpha)
 {
 }
コード例 #26
0
 protected override void DrawBackground(GdxSpriteBatch spriteBatch, float parentAlpha)
 {
 }
コード例 #27
0
        protected override void InitializeCore()
        {
            ShowDebug = true;

            //Debugger.Launch();

            _spriteBatch = new GdxSpriteBatch(Context.GraphicsDevice);
            _skin        = new Skin(Context.GraphicsDevice, "Data/uiskin.json");
            _texture1    = new TextureContext(Context.GraphicsDevice, "Data/badlogicsmall.jpg", true);
            _texture2    = new TextureContext(Context.GraphicsDevice, "Data/badlogic.jpg", true);

            TextureRegion image        = new TextureRegion(_texture1);
            TextureRegion imageFlipped = new TextureRegion(image);

            imageFlipped.Flip(true, true);
            TextureRegion image2 = new TextureRegion(_texture2);

            _stage = new Stage(Context.GraphicsDevice.Viewport.Width, Context.GraphicsDevice.Viewport.Height, true, Context.GraphicsDevice);

            Context.Input.Processor = _stage;

            ImageButtonStyle style = new ImageButtonStyle(_skin.Get <ButtonStyle>())
            {
                ImageUp   = new TextureRegionDrawable(image),
                ImageDown = new TextureRegionDrawable(imageFlipped),
            };
            ImageButton iconButton = new ImageButton(style);

            Button buttonMulti = new TextButton("Multi\nLine\nToggle", _skin, "toggle")
            {
                IsToggle = true,
            };
            Button imgButton       = new Button(new Image(image), _skin);
            Button imgToggleButton = new Button(new Image(image), _skin, "toggle")
            {
                IsToggle = true,
            };

            Label myLabel = new Label("This is some text.", _skin);

            myLabel.TextWrapping = true;

            Table t = new Table();

            t.Row();
            t.Add(myLabel);

            t.Layout();

            CheckBox  checkbox  = new CheckBox("Check me", _skin);
            Slider    slider    = new Slider(0, 10, 1, false, _skin);
            TextField textField = new TextField("", _skin)
            {
                MessageText = "Click here!",
            };
            SelectBox  dropdown   = new SelectBox(selectEntries, _skin);
            Image      imageActor = new Image(image2);
            ScrollPane scrollPane = new ScrollPane(imageActor);

            MonoGdx.Scene2D.UI.List list = new MonoGdx.Scene2D.UI.List(listEntries, _skin);
            ScrollPane scrollPane2       = new ScrollPane(list, _skin);
            //scrollPane2.FlickScroll = false;
            SplitPane splitPane = new SplitPane(scrollPane, scrollPane2, false, _skin, "default-horizontal");

            _fpsLabel = new Label("fps:", _skin);

            Label     passwordLabel = new Label("Textfield in password mode: ", _skin);
            TextField passwordField = new TextField("", _skin)
            {
                MessageText       = "password",
                PasswordCharacter = '*',
                IsPasswordMode    = true,
            };

            Window window = new Window("Dialog", _skin);

            window.SetPosition(0, 0);
            window.Defaults().SpaceBottom = 10;
            window.Row().Configure.Fill().ExpandX();
            window.Add(iconButton);
            window.Add(buttonMulti);
            window.Add(imgButton);
            window.Add(imgToggleButton);
            window.Row();
            window.Add(checkbox);
            window.Add(slider).Configure.MinWidth(100).FillX().Colspan(3);
            window.Row();
            window.Add(dropdown).Configure.MinWidth(100).FillX();
            window.Add(textField).Configure.MinWidth(100).ExpandX().FillX().Colspan(3);
            window.Row();
            window.Add(splitPane).Configure.Fill().Expand().Colspan(4).MaxHeight(200);
            window.Row();
            window.Add(passwordLabel).Configure.Colspan(2);
            window.Add(passwordField).Configure.MinWidth(100).ExpandX().FillX().Colspan(2);

            window.Pack();

            /*textField.KeyUp += (field, c) => {
             *  if (c == '\n')
             *      field.OnscreenKeyboard.Show(false);
             * };*/

            _stage.AddActor(window);

            MonoGdx.Scene2D.UI.List list2 = new MonoGdx.Scene2D.UI.List(listEntries, _skin);
            ScrollPane scrollPane22       = new ScrollPane(list2, _skin);
            Window     window2            = new Window("ScrollPane", _skin);

            window2.SetPosition(300, 300);
            window2.Defaults().SpaceBottom = 10;
            window2.Row().Configure.Fill().ExpandX();
            window2.Add(scrollPane22).Configure.MaxHeight(250).MaxWidth(150);
            window2.Pack();

            _stage.AddActor(window2);
        }
コード例 #28
0
 public virtual void Draw(GdxSpriteBatch spriteBatch, float x, float y, float width, float height)
 {
 }
コード例 #29
0
        protected void DrawChildren(GdxSpriteBatch spriteBatch, float parentAlpha)
        {
            parentAlpha *= Color.A / 255f;

            IList <Actor> actors = Children.Begin();

            if (_cullingArea != null)
            {
                RectangleF cull       = _cullingArea.Value;
                float      cullLeft   = cull.X;
                float      cullRight  = cullLeft + cull.Width;
                float      cullBottom = cull.Y;
                float      cullTop    = cullBottom + cull.Height;

                // Draw children only if inside the culling area.
                if (IsTransform)
                {
                    foreach (Actor child in actors)
                    {
                        if (!child.IsVisible)
                        {
                            continue;
                        }

                        float cx = child.X;
                        float cy = child.Y;
                        if (cx <= cullRight && cy <= cullTop && cx + child.Width >= cullLeft && cy + child.Height >= cullBottom)
                        {
                            child.Draw(spriteBatch, parentAlpha);
                        }
                    }
                    spriteBatch.Flush();
                }
                else
                {
                    // No transform for this group, offset each child.
                    float offsetX = X;
                    float offsetY = Y;
                    X = 0;
                    Y = 0;

                    foreach (Actor child in actors)
                    {
                        if (!child.IsVisible)
                        {
                            continue;
                        }

                        float cx = child.X;
                        float cy = child.Y;
                        if (cx <= cullRight && cy <= cullTop && cx + child.Width >= cullLeft && cy + child.Height >= cullBottom)
                        {
                            child.X = cx + offsetX;
                            child.Y = cy + offsetY;
                            child.Draw(spriteBatch, parentAlpha);
                            child.X = cx;
                            child.Y = cy;
                        }
                    }

                    X = offsetX;
                    Y = offsetY;
                }
            }
            else
            {
                // No culling, draw all children
                if (IsTransform)
                {
                    foreach (Actor child in actors)
                    {
                        if (!child.IsVisible)
                        {
                            continue;
                        }
                        child.Draw(spriteBatch, parentAlpha);
                    }
                    spriteBatch.Flush();
                }
                else
                {
                    // No transform for this group, offset each child.
                    float offsetX = X;
                    float offsetY = Y;
                    X = 0;
                    Y = 0;

                    foreach (Actor child in actors)
                    {
                        if (!child.IsVisible)
                        {
                            continue;
                        }

                        float cx = child.X;
                        float cy = child.Y;

                        child.X = cx + offsetX;
                        child.Y = cy + offsetY;
                        child.Draw(spriteBatch, parentAlpha);
                        child.X = cx;
                        child.Y = cy;
                    }

                    X = offsetX;
                    Y = offsetY;
                }
            }
            Children.End();
        }
コード例 #30
0
        public override void Draw(GdxSpriteBatch spriteBatch, float parentAlpha)
        {
            bool focused = IsKeyboardFocused;

            BitmapFont font      = _style.Font;
            Color?     fontColor = (IsDisabled)
                ? _style.DisabledFontColor ?? _style.FontColor
                : (focused) ? _style.FocusedFontColor ?? _style.FontColor : _style.FontColor;
            ISceneDrawable selection   = _style.Selection;
            ISceneDrawable cursorPatch = _style.Cursor;
            ISceneDrawable background  = (IsDisabled)
                ? _style.DisabledBackground ?? _style.Background
                : (focused) ? _style.FocusedBackground ?? _style.Background : _style.Background;

            float x      = (int)X;
            float y      = (int)Y;
            float width  = Width;
            float height = Height;
            float textY  = _textBounds.Height / 2 + font.Descent;

            spriteBatch.Color = Color.MultiplyAlpha(parentAlpha);
            float bgLeftWidth = 0;

            if (background != null)
            {
                background.Draw(spriteBatch, x, y, width, height);
                bgLeftWidth = background.LeftWidth;
                float bottom = background.BottomHeight;
                textY = (int)(textY + (height - background.TopHeight - bottom) / 2 + bottom);
            }
            else
            {
                textY = (int)(textY + height / 2);
            }

            CalculateOffsets();

            if (focused && _hasSelection && selection != null)
            {
                selection.Draw(spriteBatch, x + _selectionX + bgLeftWidth + _renderOffset, y + textY - _textBounds.Height - font.Descent,
                               _selectionWidth, _textBounds.Height + font.Descent / 2);
            }

            float yOffset = font.IsFlipped ? -_textBounds.Height : 0;

            if (_displayText.Length == 0)
            {
                if (!focused && MessageText != null)
                {
                    if (_style.MessageFontColor != null)
                    {
                        font.Color = _style.MessageFontColor.Value.MultiplyAlpha(parentAlpha);
                    }
                    else
                    {
                        font.Color = new Color(.7f, .7f, .7f, parentAlpha);
                    }

                    BitmapFont messageFont = _style.MessageFont ?? font;
                    messageFont.Draw(spriteBatch, MessageText, x + bgLeftWidth, y + textY + yOffset);
                }
            }
            else
            {
                font.Color = fontColor.Value.MultiplyAlpha(parentAlpha);
                font.Draw(spriteBatch, _displayText, x + bgLeftWidth + _textOffset, y + textY + yOffset, _visibleTextStart, _visibleTextEnd);
            }

            if (focused && !IsDisabled)
            {
                Blink();
                if (_cursorOn && cursorPatch != null)
                {
                    cursorPatch.Draw(spriteBatch, x + bgLeftWidth + _textOffset + _glyphPositions[_cursor] - _glyphPositions[_visibleTextStart] - 1,
                                     y + textY - _textBounds.Height - font.Descent,
                                     cursorPatch.MinWidth, _textBounds.Height + font.Descent / 2);
                }
            }
        }