Ejemplo n.º 1
0
        protected override Gui.Mesh Redraw()
        {
            var meshes   = new List <Gui.Mesh>();
            var interior = Rect;

            if (DrawFrame)
            {
                meshes.Add(Gui.Mesh.Quad()
                           .Scale(Rect.Width, Rect.Height)
                           .Translate(Rect.X, Rect.Y)
                           .Colorize(MouseIsOver
                        ? new Vector4(1, 0.5f, 0.5f, 1)
                        : (Hilite ? new Vector4(1, 0, 0, 1) : BackgroundColor))
                           .Texture(Root.GetTileSheet(Background.Sheet).TileMatrix(Background.Tile)));
                interior = Rect.Interior(4, 4, 4, 4);
            }

            if (Icon != null)
            {
                var iconSheet = Root.GetTileSheet(Icon.Sheet);

                if (interior.Width > iconSheet.TileWidth)
                {
                    meshes.Add(Gui.Mesh.Quad()
                               .Scale(iconSheet.TileWidth, iconSheet.TileHeight)
                               .Texture(iconSheet.TileMatrix(Icon.Tile))
                               .Translate(Rect.X + (Rect.Width / 2) - (iconSheet.TileWidth / 2),
                                          Rect.Y + (Rect.Height / 2) - (iconSheet.TileHeight / 2))
                               .Colorize(Enabled ? Tint : new Vector4(0.15f * Tint.X, 0.15f * Tint.Y, 0.15f * Tint.Z, 1 * Tint.W)));
                }
                else
                {
                    meshes.Add(Gui.Mesh.Quad()
                               .Scale(interior.Width, interior.Height)
                               .Texture(iconSheet.TileMatrix(Icon.Tile))
                               .Translate(interior.X, interior.Y)
                               .Colorize(Enabled ? Tint : new Vector4(0.15f * Tint.X, 0.15f * Tint.Y, 0.15f * Tint.Z, 1 * Tint.W)));
                }
            }

            if (!string.IsNullOrEmpty(Text))
            {
                if (Enabled && ChangeTextColorOnEnable)
                {
                    TextColor = EnabledTextColor;
                }
                else if (!Enabled && ChangeTextColorOnEnable)
                {
                    TextColor = DisabledTextColor;
                }
                base.GetTextMesh(meshes);
            }

            if (DrawIndicator && IndicatorValue != 0)
            {
                var indicatorTile = Root.GetTileSheet("indicator-circle");
                meshes.Add(Gui.Mesh.Quad()
                           .Scale(16, 16)
                           .Texture(indicatorTile.TileMatrix(0))
                           .Translate(Rect.Right - 16,
                                      Rect.Bottom - 16).Colorize(Color.OrangeRed.ToVector4()));
                var numberSize = new Rectangle();
                var font       = Root.GetTileSheet("font8");
                var stringMesh = Gui.Mesh.CreateStringMesh(
                    IndicatorValue.ToString(),
                    font,
                    new Vector2(1, 1),
                    out numberSize)
                                 .Colorize(new Vector4(1, 1, 1, 1));
                meshes.Add(stringMesh.
                           Translate(Rect.Right - 8 - (numberSize.Width / 2),
                                     Rect.Bottom - 8 - (numberSize.Height / 2)));
            }

            if (DrawHotkey)
            {
                var  font       = Root.GetTileSheet("font8");
                var  numberSize = new Rectangle();
                char hotkey     = '?';
                InputManager.TryConvertKeyboardInput(HotkeyValue, false, out hotkey);
                var stringMesh = Gui.Mesh.CreateStringMesh(
                    hotkey.ToString(),
                    font,
                    new Vector2(1, 1),
                    out numberSize)
                                 .Colorize(new Vector4(1, 1, 1, 0.4f));
                meshes.Add(stringMesh.
                           Translate(Rect.Left + 8 - (numberSize.Width / 2),
                                     Rect.Top + 8 - (numberSize.Height / 2)));
            }

            return(Gui.Mesh.Merge(meshes.ToArray()));
        }
Ejemplo n.º 2
0
        private void DrawValueIndicator(SKCanvas canvas, int width, int height)
        {
            if (IndicatorValue < Minimum || IndicatorValue > Maximum)
            {
                return;
            }

            float indicatorPosition = (height - guageWidth * 2) * (1f - (IndicatorValue - Minimum) / (Maximum - Minimum)) + guageWidth;
            float verticalMargin    = guageWidth / 2 + regularStrokeWidth / 2;

            //Draw Indicator Line
            var start = new SKPoint(IndicatorDirection == "Right" ? guageWidth + 10 : width - guageWidth - 10, indicatorPosition);
            var end   = new SKPoint(IndicatorDirection == "Right" ? guageWidth + 40 : width - guageWidth - 40, indicatorPosition);

            canvas.DrawLine(start, end, indicatorStrokePaint);

            //Draw Value Label
            using (var textPaint = new SKPaint())
            {
                textPaint.TextSize    = (Device.RuntimePlatform == Device.Android) ? 36 : 20;
                textPaint.IsAntialias = true;
                textPaint.Color       = strokeColor;
                textPaint.IsStroke    = false;

                var indicatorText = IndicatorValue.ToString("0.0") + (!String.IsNullOrEmpty(IndicatorValueUnit) ? " " + IndicatorValueUnit : "");

                if (IndicatorDirection == "Right")
                {
                    canvas.DrawText(indicatorText, guageWidth + 40 + 10, indicatorPosition + 14, textPaint);
                }
                else
                {
                    float textWidth = textPaint.MeasureText(indicatorText);

                    canvas.DrawText(indicatorText, width - guageWidth - 40 - 10 - textWidth, indicatorPosition + 14, textPaint);
                }
            }

            //Fill the guage
            using (SKPath containerPath = new SKPath())
            {
                switch (IndicatorDirection)
                {
                case "Right":
                    containerPath.MoveTo(regularStrokeWidth / 2, indicatorPosition);
                    containerPath.LineTo(guageWidth + regularStrokeWidth / 2, indicatorPosition);
                    containerPath.LineTo(guageWidth + regularStrokeWidth / 2, height - verticalMargin);
                    containerPath.ArcTo(guageWidth / 2, guageWidth / 2, 0, SKPathArcSize.Large, SKPathDirection.Clockwise, regularStrokeWidth / 2, height - verticalMargin);
                    containerPath.Close();
                    break;

                case "Left":
                    containerPath.MoveTo(width - guageWidth - regularStrokeWidth / 2, indicatorPosition);
                    containerPath.LineTo(width - regularStrokeWidth / 2, indicatorPosition);
                    containerPath.LineTo(width - regularStrokeWidth / 2, height - verticalMargin);
                    containerPath.ArcTo(guageWidth / 2, guageWidth / 2, 0, SKPathArcSize.Large, SKPathDirection.Clockwise, width - guageWidth - regularStrokeWidth / 2, height - verticalMargin);
                    containerPath.Close();
                    break;
                }

                canvas.DrawPath(containerPath, fillPaint);
            }
        }