Пример #1
0
        public void RegisterBitmap(CalculatorGateway calculatorGateway)
        {
            HasFlashElement = Text.Any(e => e.Flash);

            if (IsAutoWidth)
            {
                int width = 0;

                foreach (IRichTextElement element in Text)
                {
                    if (element is Run)
                    {
                        Run run = (Run)element;
                        if (run.InnerText != "")
                        {
                            width += calculatorGateway.GetStringWidth(run.InnerText, run.Font.FontIndex);
                        }
                    }
                    else if (element is Image)
                    {
                        Image image = (Image)element;
                        width += image.DrawWidth;
                    }
                }

                Width = width;
            }

            byte[] stableBitmap = new byte[Width * Height * 3];
            calculatorGateway.ClearDots(stableBitmap, Width, Height);

            byte[] flashBitmap = new byte[Width * Height * 3];
            calculatorGateway.ClearDots(flashBitmap, Width, Height);

            List <int> stopPositions = new List <int>();

            if (!(BiggestFont is null))
            {
                int ascent = calculatorGateway.GetStringAscent(BiggestFont.FontIndex);
                int y      = Height - calculatorGateway.GetStringHeight(BiggestFont.FontIndex);

                int x = 0;
                foreach (IRichTextElement element in Text)
                {
                    if (x >= Width)
                    {
                        break;
                    }

                    if (element is Run)
                    {
                        Run run = (Run)element;
                        if (run.InnerText != "")
                        {
                            calculatorGateway.WriteStringToDots(
                                run.Flash ? flashBitmap : stableBitmap,
                                run.InnerText, run.Font.FontIndex, run.FontColor, run.BackgroundColor,
                                x, BiggestFont.FontIndex == run.Font.FontIndex ? y : y + ascent - calculatorGateway.GetStringAscent(run.Font.FontIndex),
                                Width, Height);
                            x += calculatorGateway.GetStringWidth(run.InnerText, run.Font.FontIndex);
                        }
                    }
                    else if (element is Image)
                    {
                        Image image = (Image)element;
                        calculatorGateway.WriteImageToDots(
                            image.Flash ? flashBitmap : stableBitmap, image.Bitmap,
                            x, Height - image.DrawHeight,
                            image.Width, image.Height,
                            image.DrawWidth, image.DrawHeight,
                            Width, Height,
                            image.XIndex, image.YIndex,
                            false);
                        x += image.DrawWidth;
                    }
                    else if (element is Stop)
                    {
                        stopPositions.Add(x);
                    }
                }
            }

            StableBitmap  = stableBitmap;
            FlashBitmap   = flashBitmap;
            StopPositions = stopPositions.AsReadOnly();

            HasBitmapRegistered = true;
        }
Пример #2
0
        public override async void Loaded()
        {
            File.Delete(tempDllPath);

            long count = 0;
            int  fps   = 0;
            long elapsedMilliseconds = PluginConnector.ElapsedMilliseconds;

            while (true)
            {
                await Task.Delay(1);

                ledControls.ForEach(control =>
                {
                    switch (control.Mode)
                    {
                    case LedDisplayMode.Fps:
                        FpsLedCalculator.WriteToDots(control.DotPixels, control.DotStride, fps);
                        break;

                    case LedDisplayMode.ElapsedMilliseconds:
                        List <LedControl> controls = ledControls.FindAll(c => c.Mode == LedDisplayMode.Normal && c.Parts.Count != 0);
                        MillisecLedCalculator.WriteToDots(control.DotPixels, control.DotStride, (int)(PluginConnector.ElapsedMilliseconds % 100000));
                        break;

                    case LedDisplayMode.Normal:
                        calculatorGateway.ClearDots(control.DotPixels, control.DotWidth, control.DotHeight);

                        if (control.UseFullText)
                        {
                            if (control.FullText.HasBitmapRegistered)
                            {
                                int x = control.ScrollFullText ? control.GetScrollingFullTextX((int)(PluginConnector.ElapsedMilliseconds - control.FunnTextScrollStartedTime)) : 0;

                                calculatorGateway.CopyDots(
                                    control.DotPixels, control.FullText.StableBitmap,
                                    control.FullText.Width, control.DotHeight,
                                    x, 0,
                                    control.DotWidth, control.DotHeight,
                                    0, 0,
                                    control.FullText.Width, control.DotHeight,
                                    false);

                                if (control.FullText.HasFlashElement && PluginConnector.ElapsedMilliseconds % 800 < 600)
                                {
                                    calculatorGateway.CopyDots(
                                        control.DotPixels, control.FullText.FlashBitmap,
                                        control.FullText.Width, control.DotHeight,
                                        x, 0,
                                        control.DotWidth, control.DotHeight,
                                        0, 0,
                                        control.FullText.Width, control.DotHeight,
                                        true);
                                }
                            }
                        }
                        else
                        {
                            control.Parts.ForEach(part =>
                            {
                                LedPartDisplayPhase displaySetting = part.DisplayPhases[part.CurrentDisplayPhase];
                                if ((part.Visibility & displaySetting.VisibilityIndex) == displaySetting.VisibilityIndex)
                                {
                                    part.DisplayingXIndex = displaySetting.FaceIndex;

                                    if (part.UseFreeText)
                                    {
                                        if (part.FreeText.HasBitmapRegistered)
                                        {
                                            calculatorGateway.CopyDots(
                                                control.DotPixels, part.FreeText.StableBitmap,
                                                part.Width, part.Height,
                                                part.X, part.Y,
                                                control.DotWidth, control.DotHeight,
                                                0, 0,
                                                part.Width, part.Height,
                                                false);

                                            if (part.FreeText.HasFlashElement && PluginConnector.ElapsedMilliseconds % 800 < 600)
                                            {
                                                calculatorGateway.CopyDots(
                                                    control.DotPixels, part.FreeText.FlashBitmap,
                                                    part.Width, part.Height,
                                                    part.X, part.Y,
                                                    control.DotWidth, control.DotHeight,
                                                    0, 0,
                                                    part.Width, part.Height,
                                                    true);
                                            }
                                        }
                                    }
                                    else if (part.DisplayingYIndex != -1 && (!part.Bitmaps[part.DisplayingBitmapIndex].Definitions[part.DisplayingYIndex].Flash || PluginConnector.ElapsedMilliseconds % 800 < 600))
                                    {
                                        calculatorGateway.WriteImageToDots(
                                            control.DotPixels, part.Bitmaps[part.DisplayingBitmapIndex].Pixels,
                                            part.X, part.Y,
                                            part.Bitmaps[part.DisplayingBitmapIndex].Width, part.Bitmaps[part.DisplayingBitmapIndex].Height,
                                            part.Width, part.Height,
                                            control.DotWidth, control.DotHeight,
                                            part.DisplayingXIndex, part.DisplayingYIndex,
                                            true);
                                    }
                                }
                                else
                                {
                                    part.DisplayingXIndex = -1;
                                }
                            });
                        }
                        break;
                    }

                    calculatorGateway.Draw(control.Pixels, control.DotPixels, control.DotWidth, control.DotHeight, control.DotXDistance, control.DotYDistance, control.DotRadius, control.Stride, count == 0);
                });

                await dispatcher.BeginInvoke((Action)(() =>
                {
                    foreach (LedControl led in ledControls)
                    {
                        led.Bitmap.WritePixels(new Int32Rect(0, 0, led.Width, led.Height), led.Pixels, led.Stride, 0, 0);
                    }
                }));

                count++;
                if (((count >> 2) & 0b1) == 0b1)
                {
                    fps = (int)(1000L * count / (PluginConnector.ElapsedMilliseconds - elapsedMilliseconds));
                }
            }
        }