Example #1
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();
        }
Example #2
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();
        }