Exemplo n.º 1
0
 void IBackgroundDrawable.Draw(AdvancedDrawBatch drawBatch, Rectangle target, Color color)
 {
     for (int idx = 0; idx < _drawables.Count; ++idx)
     {
         _drawables[idx].Draw(drawBatch, target, color);
     }
 }
Exemplo n.º 2
0
        protected override void LoadContent()
        {
            _inited = true;
            if (_mainView == null)
            {
                return;
            }

            _drawBatch = new AdvancedDrawBatch(GraphicsDevice);

            ContentLoading?.Invoke(this);

            IDefinitionClass obj = _mainView.CreateInstance(null, null);

            MainView = (UiContainer)obj;

            MainView.RecalculateAll();

            MainView.RegisterView();
            MainView.ViewAdded();

            ViewLoaded?.Invoke(this);

            MainView.Bounds = new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);
        }
Exemplo n.º 3
0
        public override void Draw(AdvancedDrawBatch drawBatch, DrawButtonInfo info)
        {
            Update(info.EllapsedTime, info.ButtonState);

            ButtonState state = info.ButtonState;

            Color color = ColorFromState * info.Opacity * Opacity;

            NinePatchImage image = _imageReleased;

            switch (state & ButtonState.Mask)
            {
            case ButtonState.Disabled:
                if (_imageDisabled != null)
                {
                    image = _imageDisabled;
                }
                break;

            case ButtonState.Pushed:
                if (_imagePushed != null)
                {
                    image = _imagePushed;
                }
                break;
            }

            float     scale  = _scaleByUnit ? (float)UiUnit.Unit : 1;
            Rectangle target = _margin.ComputeRect(info.Target);

            drawBatch.DrawNinePatchRect(image, target, color, scale * _scale);
        }
Exemplo n.º 4
0
        protected override void LoadContent()
        {
            _drawBatch = new AdvancedDrawBatch(GraphicsDevice);

            if (ContentLoading != null)
            {
                ContentLoading(this);
            }

            IDefinitionClass obj = _mainView.CreateInstance(null, null);

            MainView = (UiContainer)obj;

            MainView.RecalculateAll();

            MainView.RegisterView();
            MainView.ViewAdded();

            if (ViewLoaded != null)
            {
                ViewLoaded(this);
            }

            MainView.Bounds = new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);
        }
Exemplo n.º 5
0
        public override void Draw(AdvancedDrawBatch drawBatch, DrawButtonInfo info)
        {
            Update(info.EllapsedTime, info.ButtonState);

            Rectangle target = _margin.ComputeRect(info.Target);

            drawBatch.DrawRectangle(target, ColorFromState * info.Opacity * Opacity);
        }
Exemplo n.º 6
0
 public void Draw(AdvancedDrawBatch batch, StringBuilder text, Color color)
 {
     for (int idx = 0; idx < text.Length; ++idx)
     {
         int code;
         _chars.TryGetValue(text[idx], out code);
         Draw(batch, code, color);
     }
 }
Exemplo n.º 7
0
        void IBackgroundDrawable.Draw(AdvancedDrawBatch drawBatch, Rectangle target, Color color)
        {
            float scale = _scaleByUnit ? (float)UiUnit.Unit : 1;

            color = GraphicsHelper.MultiplyColors(color, _color.Value);

            target = _margin.ComputeRect(target);
            drawBatch.DrawNinePatchRect(_image, target, color, scale * _scale);
        }
Exemplo n.º 8
0
        public override void Draw(AdvancedDrawBatch drawBatch, DrawButtonInfo info)
        {
            Update(info.EllapsedTime, info.ButtonState);

            Color color = ColorFromState * info.Opacity * Opacity;

            Texture2D image = _image;

            if (image != null)
            {
                float scale = _scale.Value(true);

                if (scale == 0)
                {
                    scale = Math.Min(info.Target.Width / (float)image.Width, info.Target.Height / (float)image.Height);
                    scale = Math.Min(1, scale);
                }

                Rectangle textureSrc = new Rectangle(0, 0, image.Width, image.Height);

                int width  = (int)(scale * image.Width);
                int height = (int)(scale * image.Height);

                Rectangle target = _margin.ComputeRect(info.Target);

                switch (_horizontalAlignment)
                {
                case HorizontalContentAlignment.Center:
                    target.X = target.Center.X - width / 2;
                    break;

                case HorizontalContentAlignment.Right:
                    target.X = target.Right - width;
                    break;
                }

                switch (_verticalAlignment)
                {
                case VerticalContentAlignment.Center:
                    target.Y = target.Center.Y - height / 2;
                    break;

                case VerticalContentAlignment.Bottom:
                    target.Y = target.Bottom - height;
                    break;
                }

                target.Width  = width;
                target.Height = height;

                drawBatch.DrawImage(image, target, textureSrc, color);
            }
        }
Exemplo n.º 9
0
        public override void Draw(AdvancedDrawBatch batch, Point startPosition, Vector2 position, float scale)
        {
            int size     = UnitToPixels(scale);
            int unitSize = UnitToPixels(1);

            Rectangle target = new Rectangle(0, 0, size, size);

            position = position.TrimToIntValues() * size;

            SamplerState oldSamplerState = batch.SamplerState;

            batch.SamplerState = SamplerState.PointClamp;

            TiledLayer layer = Document.Current.SelectedLayer.Layer as TiledLayer;

            if (layer != null)
            {
                int maxX = _tiles.GetLength(0);
                int maxY = _tiles.GetLength(1);

                int targetX = (int)(position.X / size);
                int targetY = (int)(position.Y / size);

                maxX = Math.Min(layer.Width - targetX, maxX);
                maxY = Math.Min(layer.Height - targetY, maxY);

                position.X -= startPosition.X;
                position.Y -= startPosition.Y;

                for (int idxX = 0; idxX < maxX; ++idxX)
                {
                    target.X = (int)(idxX * size + position.X);

                    for (int idxY = 0; idxY < maxY; ++idxY)
                    {
                        target.Y = (int)(idxY * size + position.Y);

                        ushort tile = _tiles[idxX, idxY];

                        Point src = new Point(tile & 0xff, (tile >> 8) & 0xff);

                        Rectangle source = new Rectangle(src.X * unitSize, src.Y * unitSize, unitSize - 1, unitSize - 1);

                        batch.DrawImage(_tileset, target, source, Color.White * 0.5f);
                    }
                }
            }

            batch.SamplerState = oldSamplerState;
        }
Exemplo n.º 10
0
        public override void Draw(AdvancedDrawBatch drawBatch, DrawButtonInfo info)
        {
            Update(info.EllapsedTime, info.ButtonState);

            SharedString str = _text != null ? _text : info.Text;

            float         scale = _font.Scale;
            UniversalFont font  = _font.Font;

            Color color = ColorFromState * info.Opacity * Opacity;

            Rectangle target = _margin.ComputeRect(info.Target);

            drawBatch.DrawText(font, str, target, _textAlign, color, _font.Spacing, (float)_lineHeight / 100.0f, scale, _textRotation);
        }
Exemplo n.º 11
0
        public override void Draw(AdvancedDrawBatch drawBatch, Rectangle target, float opacity)
        {
            if (_lastWidth != target.Width)
            {
                _leftMargin  = _left.Compute(target.Width);
                _rightMargin = _right.Compute(target.Width);

                _lastWidth = target.Width;
            }

            target.X     += _leftMargin;
            target.Width -= _leftMargin + _rightMargin;

            drawBatch.DrawRectangle(target, _color.Value * opacity);
        }
Exemplo n.º 12
0
        public override void Draw(AdvancedDrawBatch batch, Point startPosition, Vector2 position, float scale)
        {
            int size     = UnitToPixels(scale);
            int unitSize = UnitToPixels(1);

            Rectangle target = new Rectangle(0, 0, size, size);

            position = position.TrimToIntValues() * size;

            position.X -= startPosition.X;
            position.Y -= startPosition.Y;

            target.X = (int)(position.X);
            target.Y = (int)(position.Y);

            batch.DrawRectangle(target, _backgroundColor * 0.5f);
        }
Exemplo n.º 13
0
        protected override void Draw(ref UiViewDrawParameters parameters)
        {
            float zoom     = (float)_zoom.Value / 100f;
            int   unitSize = Tools.Tool.UnitToPixels(zoom);

            int startX = CurrentPosition.X / unitSize;
            int startY = CurrentPosition.Y / unitSize;

            Rectangle bounds = ScreenBounds;

            startX = startX * unitSize - CurrentPosition.X + bounds.X;
            startY = startY * unitSize - CurrentPosition.Y + bounds.Y + 1;

            int size = (int)Math.Ceiling(UiUnit.Unit * 3);

            int right  = bounds.Right + size;
            int bottom = bounds.Bottom + size;

            AdvancedDrawBatch batch = parameters.DrawBatch;

            batch.PushClip(bounds);

            Color color = Color.White * 0.25f;

            for (int x = startX; x < right; x += unitSize)
            {
                for (int y = startY; y < bottom; y += unitSize)
                {
                    batch.DrawLine(new Point(x - size, y), new Point(x + size - 1, y), color);
                    batch.DrawLine(new Point(x, y - size), new Point(x, y + size - 1), color);
                }
            }

            DrawCurrentLayer(ref parameters);

            if (MousePosition.HasValue)
            {
                Point pos = CurrentPosition;
                pos.X -= bounds.X;
                pos.Y -= bounds.Y;

                Tools.Tool.Current.Draw(parameters.DrawBatch, pos, MousePosition.Value, zoom);
            }

            batch.PopClip();
        }
Exemplo n.º 14
0
        public override void Draw(AdvancedDrawBatch drawBatch, DrawButtonInfo info)
        {
            Update(info.EllapsedTime, info.ButtonState);

            float  opacity;
            Matrix transform;

            _transitionPushed.Get(_reverse ? 1 - PushedState : PushedState, info.Target, info.Target, out transform, out opacity);

            drawBatch.PushTransform(transform);
            info.Opacity *= opacity;

            for (int idx = 0; idx < _drawables.Count; ++idx)
            {
                _drawables[idx].Draw(drawBatch, info);
            }

            drawBatch.PopTransform();
        }
Exemplo n.º 15
0
 public abstract void Draw(AdvancedDrawBatch drawBatch, T context);
Exemplo n.º 16
0
        public void Draw(AdvancedDrawBatch batch)
        {
            if (!Enabled)
            {
                return;
            }

            Color normalColor     = Color.LightBlue;
            Color errorColor      = Color.Red;
            Color backgroundColor = Color.Black;

            int offset = Math.Max(1, _height / 10);

            _display.Reset(new Point(offset, offset));

            if (_right > 0)
            {
                Matrix matrix;

                matrix = Matrix.CreateRotationZ(MathHelper.PiOver2) * Matrix.CreateTranslation(new Vector3(_right, 0, 0));
                batch.PushTransform(matrix);
            }

            batch.BeginPrimitive(PrimitiveType.TriangleList, null);
            batch.PushVertex(new Vector2(0, 0), backgroundColor);
            batch.PushVertex(new Vector2(0, _height), backgroundColor);
            batch.PushVertex(new Vector2(6000, 0), backgroundColor);

            batch.PushVertex(new Vector2(0, _height), backgroundColor);
            batch.PushVertex(new Vector2(6000, 0), backgroundColor);
            batch.PushVertex(new Vector2(6000, _height), backgroundColor);

            int   lastMaxFrameFill = (int)(100 * _maxFrame / (_targetFrameTime)) - 100;
            Color color;

            lastMaxFrameFill = Math.Min(99, lastMaxFrameFill);

            _stringBuilder.Clear();
            _stringBuilder.AppendFormat("{0,-2} ", (int)_minFps);
            color = (_maxFrame > _minFrameTime) ? errorColor : normalColor;
            _display.Draw(batch, _stringBuilder, color);

            _stringBuilder.Clear();
            _stringBuilder.AppendFormat("{0,-2} ", (int)_fps);
            color = _fps < (1 / _minFrameTime) ? errorColor : normalColor;
            _display.Draw(batch, _stringBuilder, color);

            _stringBuilder.Clear();
            _stringBuilder.AppendFormat("{0,-2} ", Math.Max(0, lastMaxFrameFill));
            color = (_maxFrame > _minFrameTime) ? errorColor : normalColor;
            _display.Draw(batch, _stringBuilder, color);

            for (int idx = 0; idx < _counters.Count; ++idx)
            {
                var counter = _counters[idx];

                float frameTime         = counter.Value;
                int   lastUpdatePercent = float.IsNaN(frameTime) ? -1 : (int)(100 * frameTime / (_targetFrameTime));
                lastUpdatePercent = Math.Min(99, lastUpdatePercent);

                _stringBuilder.Clear();

                if (lastUpdatePercent < 0)
                {
                    _stringBuilder.AppendFormat("{1}{0,-2} ", "-", (char)(idx + 'A'));
                }
                else
                {
                    _stringBuilder.AppendFormat("{1}{0,-2} ", lastUpdatePercent, (char)(idx + 'A'));
                }

                color = (lastUpdatePercent > counter.MaxFill) ? errorColor : normalColor;
                _display.Draw(batch, _stringBuilder, color);
            }

            if (_right > 0)
            {
                batch.PopTransform();
            }
        }
Exemplo n.º 17
0
        void Draw(AdvancedDrawBatch batch, int code, Color color)
        {
            Color c = Color.Black;

            batch.BeginPrimitive(Microsoft.Xna.Framework.Graphics.PrimitiveType.TriangleList, null);

            Color offColor = color * 0.15f;

            // a
            c = (code & 0x01) != 0 ? color : offColor;

            PushVertex(batch, 2, 2, ref c);
            PushVertex(batch, 3, 1, ref c);
            PushVertex(batch, 3, 3, ref c);

            PushVertex(batch, 8, 2, ref c);
            PushVertex(batch, 7, 1, ref c);
            PushVertex(batch, 7, 3, ref c);

            PushVertex(batch, 3, 1, ref c);
            PushVertex(batch, 3, 3, ref c);
            PushVertex(batch, 7, 1, ref c);

            PushVertex(batch, 3, 3, ref c);
            PushVertex(batch, 7, 1, ref c);
            PushVertex(batch, 7, 3, ref c);

            // b
            c = (code & 0x02) != 0 ? color : offColor;

            PushVertex(batch, 8, 2, ref c);
            PushVertex(batch, 9, 3, ref c);
            PushVertex(batch, 7, 3, ref c);

            PushVertex(batch, 8, 8, ref c);
            PushVertex(batch, 9, 7, ref c);
            PushVertex(batch, 7, 7, ref c);

            PushVertex(batch, 7, 3, ref c);
            PushVertex(batch, 9, 3, ref c);
            PushVertex(batch, 7, 7, ref c);

            PushVertex(batch, 9, 3, ref c);
            PushVertex(batch, 7, 7, ref c);
            PushVertex(batch, 9, 7, ref c);

            // c
            c = (code & 0x04) != 0 ? color : offColor;

            PushVertex(batch, 8, 8, ref c);
            PushVertex(batch, 9, 9, ref c);
            PushVertex(batch, 7, 9, ref c);

            PushVertex(batch, 8, 14, ref c);
            PushVertex(batch, 9, 13, ref c);
            PushVertex(batch, 7, 13, ref c);

            PushVertex(batch, 7, 9, ref c);
            PushVertex(batch, 9, 9, ref c);
            PushVertex(batch, 7, 13, ref c);

            PushVertex(batch, 9, 9, ref c);
            PushVertex(batch, 7, 13, ref c);
            PushVertex(batch, 9, 13, ref c);

            // d
            c = (code & 0x08) != 0 ? color : offColor;

            PushVertex(batch, 2, 14, ref c);
            PushVertex(batch, 3, 13, ref c);
            PushVertex(batch, 3, 15, ref c);

            PushVertex(batch, 8, 14, ref c);
            PushVertex(batch, 7, 13, ref c);
            PushVertex(batch, 7, 15, ref c);

            PushVertex(batch, 3, 13, ref c);
            PushVertex(batch, 3, 15, ref c);
            PushVertex(batch, 7, 13, ref c);

            PushVertex(batch, 3, 15, ref c);
            PushVertex(batch, 7, 13, ref c);
            PushVertex(batch, 7, 15, ref c);

            // e
            c = (code & 0x10) != 0 ? color : offColor;

            PushVertex(batch, 2, 8, ref c);
            PushVertex(batch, 3, 9, ref c);
            PushVertex(batch, 1, 9, ref c);

            PushVertex(batch, 2, 14, ref c);
            PushVertex(batch, 3, 13, ref c);
            PushVertex(batch, 1, 13, ref c);

            PushVertex(batch, 1, 9, ref c);
            PushVertex(batch, 3, 9, ref c);
            PushVertex(batch, 1, 13, ref c);

            PushVertex(batch, 3, 9, ref c);
            PushVertex(batch, 1, 13, ref c);
            PushVertex(batch, 3, 13, ref c);

            // f
            c = (code & 0x20) != 0 ? color : offColor;

            PushVertex(batch, 2, 2, ref c);
            PushVertex(batch, 3, 3, ref c);
            PushVertex(batch, 1, 3, ref c);

            PushVertex(batch, 2, 8, ref c);
            PushVertex(batch, 3, 7, ref c);
            PushVertex(batch, 1, 7, ref c);

            PushVertex(batch, 1, 3, ref c);
            PushVertex(batch, 3, 3, ref c);
            PushVertex(batch, 1, 7, ref c);

            PushVertex(batch, 3, 3, ref c);
            PushVertex(batch, 1, 7, ref c);
            PushVertex(batch, 3, 7, ref c);

            // g
            c = (code & 0x40) != 0 ? color : offColor;

            PushVertex(batch, 2, 8, ref c);
            PushVertex(batch, 3, 7, ref c);
            PushVertex(batch, 3, 9, ref c);

            PushVertex(batch, 8, 8, ref c);
            PushVertex(batch, 7, 7, ref c);
            PushVertex(batch, 7, 9, ref c);

            PushVertex(batch, 3, 7, ref c);
            PushVertex(batch, 3, 9, ref c);
            PushVertex(batch, 7, 7, ref c);

            PushVertex(batch, 3, 9, ref c);
            PushVertex(batch, 7, 7, ref c);
            PushVertex(batch, 7, 9, ref c);

            _position.X += _size;
        }
Exemplo n.º 18
0
 void PushVertex(AdvancedDrawBatch batch, int x, int y, ref Color c)
 {
     batch.PushVertex(new Vector2(x * _thick, y * _thick) + _position, c);
 }
Exemplo n.º 19
0
        public override void Draw(AdvancedDrawBatch drawBatch, DrawButtonInfo info)
        {
            Update(info.EllapsedTime, info.ButtonState);

            if (info.Icon == null)
            {
                return;
            }

            float scale = (float)UiUnit.Unit * _scale;

            float scaleX = scale;
            float scaleY = scale;

            Rectangle target = info.Target;
            Texture2D image  = info.Icon;

            Rectangle bounds = _margin.ComputeRect(target);

            switch (_stretch)
            {
            case Stretch.Uniform:
                scaleX = scaleY = Math.Min((float)target.Width / (float)image.Width, (float)target.Height / (float)image.Height);
                break;

            case Stretch.UniformToFill:
                scaleX = scaleY = Math.Max((float)target.Width / (float)image.Width, (float)target.Height / (float)image.Height);
                break;

            case Stretch.Fill:
                scaleX = (float)target.Width / (float)image.Width;
                scaleY = (float)target.Height / (float)image.Height;
                break;
            }

            Color color = ColorFromState * info.Opacity * Opacity;

            Rectangle source = new Rectangle(0, 0, info.Icon.Width, info.Icon.Height);
            Vector2   size   = new Vector2(source.Width * scaleX, source.Height * scaleY);

            target.Width  = (int)size.X;
            target.Height = (int)size.Y;

            switch (_horzAlign)
            {
            case HorizontalContentAlignment.Center:
            case HorizontalContentAlignment.Auto:
                target.X = bounds.Center.X - target.Width / 2;
                break;

            case HorizontalContentAlignment.Left:
                target.X = bounds.X;
                break;

            case HorizontalContentAlignment.Right:
                target.X = bounds.Right - target.Width;
                break;
            }

            switch (_vertAlign)
            {
            case VerticalContentAlignment.Center:
            case VerticalContentAlignment.Auto:
                target.Y = bounds.Center.Y - target.Height / 2;
                break;

            case VerticalContentAlignment.Top:
                target.Y = bounds.Y;
                break;

            case VerticalContentAlignment.Bottom:
                target.Y = bounds.Bottom - target.Height;
                break;
            }



            drawBatch.DrawImage(info.Icon, target, source, color);
        }
Exemplo n.º 20
0
        public override void Draw(AdvancedDrawBatch drawBatch, DrawButtonInfo info)
        {
            int  carretPosition = info.Additional != null ? (int)info.Additional : -1;
            bool focused        = false;

            Update(info.EllapsedTime, info.ButtonState);

            if (info.ButtonState.HasFlag(ButtonState.Checked) && carretPosition >= 0)
            {
                _flash += info.EllapsedTime * 2;
                _flash %= 2;
                focused = true;
            }
            else
            {
                _flash = 0;
            }

            SharedString str = info.Text;

            float         scale = _font.Scale;
            UniversalFont font  = _font.Font;
            Color         color = ColorFromState * info.Opacity * Opacity;

            Rectangle target  = _margin.ComputeRect(info.Target);
            float     spacing = _font.Spacing;

            lock (str)
            {
                StringBuilder builder = str.StringBuilder;

                if (_flash > 1)
                {
                    _string.Clear();
                    carretPosition = Math.Min(builder.Length, carretPosition);
                    for (int idx = 0; idx < carretPosition; ++idx)
                    {
                        _string.Append(builder[idx]);
                    }

                    carretPosition = (int)(font.MeasureString(_string, spacing, 0) * scale).X;
                }

                _string.Clear();
                _string.Append(builder);
            }

            Vector2 size = font.MeasureString(_string, spacing, 0) * scale;

            if (focused)
            {
                size.X += font.MeasureString("|", spacing).X *scale;
            }

            int positionX = target.X;

            if (size.X >= target.Width)
            {
                positionX = target.Right - (int)size.X;
            }
            else
            {
                switch (_textAlign & TextAlign.Horz)
                {
                case TextAlign.Right:
                    positionX = target.Right - (int)size.X;
                    break;

                case TextAlign.Center:
                    positionX = target.Center.X - (int)size.X / 2;
                    break;
                }
            }

            drawBatch.PushClip(target);

            target.X = positionX;

            drawBatch.DrawText(font, _string, target, _textAlign & TextAlign.Vert, color, spacing, 0, scale, TextRotation.None);

            if (_flash > 1)
            {
                target.X += carretPosition;

                drawBatch.DrawText(font, "|", target, _textAlign & TextAlign.Vert, color, spacing, 0, scale);
            }

            drawBatch.PopClip();
        }
Exemplo n.º 21
0
 public abstract void Draw(AdvancedDrawBatch drawBatch, Rectangle target, float opacity);
Exemplo n.º 22
0
        protected override void Draw(ref UiViewDrawParameters parameters)
        {
            base.Draw(ref parameters);

            AdvancedDrawBatch batch  = parameters.DrawBatch;
            Rectangle         bounds = ScreenBounds;

            _selectedPosition = bounds.Center.Y + _selectedPositionOffset.Compute(bounds.Height);

            int size = _elementHeight.Compute(bounds.Height) + _spacing.Compute();

            int start  = 0;
            int center = _selectedPosition + (int)(_scroll * size);

            Rectangle rect = bounds;

            rect.Height = _elementHeight.Compute(bounds.Height);

            while (center > bounds.Top - size / 2)
            {
                center -= size;
                start--;
            }

            rect.Y = center - _elementHeight.Compute(bounds.Height) / 2;

            DrawButtonInfo drawInfo = new DrawButtonInfo();

            drawInfo.Icon         = null;
            drawInfo.Opacity      = parameters.Opacity;
            drawInfo.EllapsedTime = parameters.EllapsedTime;
            drawInfo.Text         = _captionText;

            while (rect.Bottom <= bounds.Bottom + size)
            {
                ButtonState state = _touchId != 0 ? ButtonState.Pushed : ButtonState.None;

                if (center == _selectedPosition && !_isScrolling && float.IsNaN(_scrollTo))
                {
                    state |= ButtonState.Checked;
                }

                if (start == (int)((_scroll > 0 ? -0.5 : 0.5) - _scroll))
                {
                    state |= ButtonState.Checked;
                }

                bool enabled = false;
                _context.GetData(start, _captionText.StringBuilder, out enabled);

                if (!enabled)
                {
                    state |= ButtonState.Disabled;
                    state &= ~ButtonState.Pushed;
                }

                drawInfo.Target      = rect;
                drawInfo.ButtonState = state;

                for (int idx = 0; idx < _drawables.Count; ++idx)
                {
                    var drawable = _drawables[idx];
                    drawable.Draw(batch, drawInfo);
                }

                start++;
                center += size;
                rect.Y += size;
            }
        }
Exemplo n.º 23
0
        void DrawTiles(ref UiViewDrawParameters parameters, TiledLayer layer)
        {
            Rectangle bounds = ScreenBounds;

            AdvancedDrawBatch batch = parameters.DrawBatch;

            SamplerState oldSamplerState = batch.SamplerState;

            batch.SamplerState = SamplerState.PointClamp;

            int width  = layer.Width;
            int height = layer.Height;

            float zoom     = (float)_zoom.Value / 100f;
            int   unitSize = Tools.Tool.UnitToPixels(zoom);

            int tileSize = Tools.Tool.UnitToPixels(1);

            Rectangle target = new Rectangle(bounds.X - CurrentPosition.X, bounds.Y - CurrentPosition.Y, unitSize, unitSize);
            Rectangle source = new Rectangle(0, 0, tileSize - 1, tileSize - 1);

            Texture2D tileset = CurrentTemplate.Instance.Tileset(layer.Tileset).Item2;

            int startY = target.Y;

            int maxY = 0;

            ushort[,] tiles = layer.Content;

            for (int idxX = 0; idxX < width; ++idxX)
            {
                target.Y = startY;

                if (target.Right >= bounds.X && target.X <= bounds.Right)
                {
                    for (int idxY = 0; idxY < height; ++idxY)
                    {
                        if (target.Bottom >= bounds.Y && target.Y <= bounds.Bottom)
                        {
                            ushort tile = tiles[idxX, idxY];

                            if (tile != 0xffff)
                            {
                                source.X = (tile & 0xff) * tileSize;
                                source.Y = ((tile >> 8) & 0xff) * tileSize;

                                batch.DrawImage(tileset, target, source, Color.White * 0.5f);
                            }
                        }

                        target.Y += unitSize;
                        maxY      = Math.Max(target.Y, maxY);
                    }
                }

                target.X += unitSize;
            }

            Color color = Color.White * 0.25f;

            batch.DrawLine(new Point(target.X, bounds.Top), new Point(target.X, maxY), color);
            batch.DrawLine(new Point(bounds.Left, maxY), new Point(target.X, maxY), color);

            batch.SamplerState = oldSamplerState;
        }
Exemplo n.º 24
0
        public override void Draw(AdvancedDrawBatch drawBatch, DrawButtonInfo info)
        {
            Update(info.EllapsedTime, info.ButtonState);

            SharedString str = _text != null ? _text : info.Text;

            float         scale = _font.Scale;
            UniversalFont font  = _font.Font;

            Color     color  = ColorFromState * info.Opacity * Opacity;
            Rectangle target = _margin.ComputeRect(info.Target);

            bool drawWithEllipsis = false;
            int  ellipsisSize     = _textRotation == TextRotation.Rotate90 || _textRotation == TextRotation.Rotate270 ? target.Height : target.Width;

            if (_pathEllipsis)
            {
                int length = (int)_font.MeasureString(str).X;

                if (length >= ellipsisSize)
                {
                    drawWithEllipsis = true;
                }
            }

            if (drawWithEllipsis)
            {
                int cut = 3;
                while (drawWithEllipsis)
                {
                    lock (str)
                    {
                        ComputeEllipsis(_stringBuilder, str.StringBuilder, cut);
                    }

                    int length = (int)_font.MeasureString(_stringBuilder).X;

                    if (length < ellipsisSize)
                    {
                        break;
                    }

                    cut += 2;
                }

                drawBatch.DrawText(font, _stringBuilder, target, _textAlign, color, _font.Spacing, (float)_lineHeight / 100.0f, scale, _textRotation);
            }
            else if (_line >= 0)
            {
                _stringBuilder.Clear();

                lock (str)
                {
                    StringBuilder textStringBuilder = str.StringBuilder;

                    int line = 0;

                    for (int idx = 0; idx < textStringBuilder.Length; ++idx)
                    {
                        char character = textStringBuilder[idx];

                        if (character == '\n')
                        {
                            line++;

                            if (line > _line)
                            {
                                break;
                            }
                        }

                        if (character == '\r')
                        {
                            continue;
                        }

                        if (line == _line)
                        {
                            _stringBuilder.Append(textStringBuilder[idx]);
                        }
                    }
                }

                drawBatch.DrawText(font, _stringBuilder, target, _textAlign, color, _font.Spacing, (float)_lineHeight / 100.0f, scale, _textRotation);
            }
            else
            {
                drawBatch.DrawText(font, str, target, _textAlign, color, _font.Spacing, (float)_lineHeight / 100.0f, scale, _textRotation);
            }
        }
Exemplo n.º 25
0
 public virtual void Draw(AdvancedDrawBatch batch, Point startPosition, Vector2 position, float scale)
 {
 }