/// <summary>
        /// Renders a given layer on a surface and caches it.
        /// </summary>
        /// <param name="setting">Display setting</param>
        /// <param name="layer">Which layer is it we're rendering</param>
        /// <param name="layerStyleDef">Style definition</param>
        /// <param name="layerStyle">Style to render</param>
        /// <param name="segments">Which segments to render</param>
        /// <param name="skewAngle">How much to skew</param>
        public void RasterizeLayer(DisplaySetting setting, RasterizeLayer layer, RasterizeLayerStyleDefinition layerStyleDef, RasterizeLayerStyle layerStyle, IEnumerable <int> segments, float skewAngle)
        {
            var source = _svgs[setting.SegmentType][setting.StyleDefinition.SegmentWeight];

            //Logger.Info("Rasterizing {0} segments of layer {1} on display {2} segment size = {3}x{4}", setting.SegmentType, layer, setting.Display, setting.Dim.SvgWidth, setting.Dim.SvgHeight);
            using (var paint = new SKPaint()) {
                ApplyFilters(paint, layerStyleDef, layerStyle);
                foreach (var i in segments)
                {
                    var initialKey = new RasterCacheKey(InitialCache, layer, setting.SegmentType, setting.StyleDefinition.SegmentWeight, i);
                    var cacheKey   = new RasterCacheKey(setting.Display, layer, setting.SegmentType, setting.StyleDefinition.SegmentWeight, i);
                    if (!_rasterCache.ContainsKey(initialKey))
                    {
                        _rasterCache[initialKey] = RasterizeSegment(source[i].Picture, setting.Dim, skewAngle, paint);
                    }
                    else
                    {
                        if (_rasterCache.ContainsKey(cacheKey))
                        {
                            _rasterCache[cacheKey]?.Dispose();
                        }
                        _rasterCache[cacheKey] = RasterizeSegment(source[i].Picture, setting.Dim, skewAngle, paint);
                    }
                }
            }
        }
Example #2
0
        private static void DrawFullSegment(DisplaySetting ds, SKCanvas canvas, SKPoint position)
        {
            var segment = Res.GetRasterized(ds.Display, RasterizeLayer.Background, ds.SegmentType, ds.StyleDefinition.SegmentWeight, AlphaNumericResources.FullSegment);

            if (segment != null)
            {
                canvas.DrawSurface(segment, position);
            }
        }
        public AlphanumericControl()
        {
            DataContext = this;
            InitializeComponent();
            DisplaySetting = new DisplaySetting();

            SizeChanged += SizeChanged_Event;
            CompositionTarget.Rendering += (o, e) => DrawImage(_writeableBitmap);
        }
Example #4
0
        public static void DrawSegments(DisplaySetting displaySetting, SKCanvas canvas, Action <int, SKCanvas, SKPoint> draw)
        {
            float posX = displaySetting.Dim.OuterPadding;
            float posY = displaySetting.Dim.OuterPadding;

            for (var j = 0; j < displaySetting.NumLines; j++)
            {
                for (var i = 0; i < displaySetting.NumChars; i++)
                {
                    draw(i + displaySetting.NumChars * j, canvas, new SKPoint(posX - displaySetting.Dim.SegmentPadding, posY - displaySetting.Dim.SegmentPadding));
                    posX += displaySetting.Dim.SvgWidth;
                }
                posX  = displaySetting.Dim.OuterPadding;
                posY += displaySetting.Dim.SvgHeight + displaySetting.Dim.LinePadding;
            }
        }
Example #5
0
 public static void DrawSegment(DisplaySetting displaySetting, RasterizeLayer layer, ushort seg, SKCanvas canvas, SKPoint canvasPosition, double percentage)
 {
     using (var surfacePaint = new SKPaint()) {
         if (percentage < 1)
         {
             surfacePaint.Color = new SKColor(0, 0, 0, (byte)Math.Round(percentage * 255));
         }
         for (var j = 0; j < Res.SegmentSize[displaySetting.SegmentType]; j++)
         {
             var rasterizedSegment = Res.GetRasterized(displaySetting.Display, layer, displaySetting.SegmentType, displaySetting.StyleDefinition.SegmentWeight, j);
             if (((seg >> j) & 0x1) != 0 && rasterizedSegment != null)
             {
                 canvas.DrawSurface(rasterizedSegment, canvasPosition, surfacePaint);
             }
         }
     }
 }
 public void CreateImage(int width, int height)
 {
     Logger.Debug("Creating image...");
     Res.Loaded[DisplaySetting.SegmentType][DisplaySetting.StyleDefinition.SegmentWeight].Take(1).Subscribe(_ => {
         DisplaySetting.SetDimensions(width, height);
         if (!_aspectRatioSet)
         {
             Host.SetDimensions(DisplaySetting.Dim.CanvasWidth, DisplaySetting.Dim.CanvasHeight);
             _aspectRatioSet = true;
         }
         else
         {
             Res.Rasterize(DisplaySetting);
         }
         SetBitmap(new WriteableBitmap(width, height, Dpi, Dpi, PixelFormats.Bgra32, BitmapPalettes.Halftone256Transparent));
     });
 }
        /// <summary>
        /// Renders each layer on a surface and caches it.
        /// </summary>
        ///
        /// <remarks>
        /// We assume that if there is already a surface with the same dimension,
        /// it's the same and we skip rendering.
        ///
        /// However, during customization, different settings are applied to the
        /// same dimensions, so we there is an additional flag to force
        /// rasterization.
        /// </remarks>
        ///
        /// <param name="setting">Display setting</param>
        /// <param name="force">True to force, otherwise it'll skip if dimension already rasterized</param>
        public void Rasterize(DisplaySetting setting, bool force = false)
        {
            if (!force && _rasterizedDim.ContainsKey(setting.SegmentType) && _rasterizedDim[setting.SegmentType].Equals(setting.Dim))
            {
                Logger.Info("Already rasterized {0}, aborting.", setting.SegmentType);
                return;
            }

            var source   = _svgs[setting.SegmentType][setting.StyleDefinition.SegmentWeight];
            var segments = source.Keys.Where(i => i != FullSegment).ToList();

            RasterizeLayer(setting, AlphaNumeric.RasterizeLayer.OuterGlow, setting.StyleDefinition.OuterGlow, setting.Style.OuterGlow, segments, setting.StyleDefinition.SkewAngle);
            RasterizeLayer(setting, AlphaNumeric.RasterizeLayer.InnerGlow, setting.StyleDefinition.InnerGlow, setting.Style.InnerGlow, segments, setting.StyleDefinition.SkewAngle);
            RasterizeLayer(setting, AlphaNumeric.RasterizeLayer.Foreground, setting.StyleDefinition.Foreground, setting.Style.Foreground, segments, setting.StyleDefinition.SkewAngle);
            RasterizeLayer(setting, AlphaNumeric.RasterizeLayer.Background, setting.StyleDefinition.Background, setting.Style.Background, new [] { FullSegment }, setting.StyleDefinition.SkewAngle);

            _rasterizedDim[setting.SegmentType] = setting.Dim;
            Logger.Info("Rasterization done.");
        }
Example #8
0
        public static void DrawDisplay(SKSurface surface, DisplaySetting ds, ushort[] data, ConcurrentDictionary <int, double> switchPercentage = null)
        {
            var canvas = surface.Canvas;

            canvas.Clear(ds.StyleDefinition.BackgroundColor);
            if (ds.StyleDefinition.Background.IsEnabled)
            {
                DrawSegments(ds, canvas, (i, c, p) => DrawFullSegment(ds, c, p));
            }
            if (ds.StyleDefinition.OuterGlow.IsEnabled)
            {
                DrawSegments(ds, canvas, (i, c, p) => DrawSegment(ds, RasterizeLayer.OuterGlow, data.Length > i ? data[i] : (ushort)0, c, p, GetPercentage(switchPercentage, i)));
            }
            if (ds.StyleDefinition.InnerGlow.IsEnabled)
            {
                DrawSegments(ds, canvas, (i, c, p) => DrawSegment(ds, RasterizeLayer.InnerGlow, data.Length > i ? data[i] : (ushort)0, c, p, GetPercentage(switchPercentage, i)));
            }
            if (ds.StyleDefinition.Foreground.IsEnabled)
            {
                DrawSegments(ds, canvas, (i, c, p) => DrawSegment(ds, RasterizeLayer.Foreground, data.Length > i ? data[i] : (ushort)0, c, p, GetPercentage(switchPercentage, i)));
            }
        }
Example #9
0
        private VirtualAlphaNumericDisplay CreateDisplay(int displayNumber, int numChars, int numLines, SegmentType type)
        {
            var displaySettings = new DisplaySetting {
                Display         = displayNumber,
                NumChars        = numChars,
                NumLines        = numLines,
                SegmentType     = type,
                StyleDefinition = _styleDef
            };
            var display = new VirtualAlphaNumericDisplay(displaySettings, _config, ToggleSettings);

            if (_config != null && _config.HasGameName)
            {
                display.PositionChanged.Throttle(TimeSpan.FromMilliseconds(500)).Subscribe(position => {
                    Logger.Info("Position changed: {0}", position);
                    (_config.VirtualAlphaNumericDisplay as VirtualAlphaNumericDisplayConfig).SetPosition(displayNumber, position);
                });
            }

            _displays[displayNumber] = display;

            return(display);
        }
 public void UpdateStyle(RasterizeStyleDefinition styleDef)
 {
     DisplaySetting.ApplyStyle(styleDef);
     Res.Rasterize(DisplaySetting, true);
 }