public virtual double PrepareForDrawing(ILayoutParameters parameters)
        {
            cursorInRow       = null;
            defaultForeground = parameters.DefaultForeground;
            selectionColor    = parameters.SelectionColor;
            textLayout        = TextLayoutCache.GetValue(parameters);
            lineSize          = LineSizeCache.GetValue(parameters);
            charWidth         = CharSizeCache.GetValue(parameters).Width;

            if (lineSize.Width == 0)
            {
                return(0);
            }

            // Math.Max used to prevent division by zero errors on windows narrower than one character
            MaximalColumn = Math.Max(((int)(lineSize.Width / charWidth)) - 1, 0);

            var charsOnLine = MaximalColumn + 1;
            var lengthInTextElementsAtLeastOne = lengthInTextElements == 0 ? 1 : lengthInTextElements; // because even empty line has height of one line

            lineCount = Math.Max(minimalSublineCount, DivisionWithCeiling(lengthInTextElementsAtLeastOne, charsOnLine));
            return(lineSize.Height * lineCount);
        }
Ejemplo n.º 2
0
        public static void LoadTheme()
        {
            IResourceDictionary resDict = Application.Current.Resources;
            object?outVar;

            IsDarkMode = false;
            if (resDict.TryGetResource("IsDarkMode", out outVar))
            {
                if (outVar is bool b)
                {
                    IsDarkMode = b;
                }
            }
            if (resDict.TryGetResource("SystemControlForegroundBaseHighBrush", out outVar))
            {
                ForegroundBrush = (IBrush)outVar !;
            }
            if (resDict.TryGetResource("SystemControlBackgroundAltHighBrush", out outVar))
            {
                BackgroundBrush = (IBrush)outVar !;
            }
            if (resDict.TryGetResource("AccentBrush1", out outVar))
            {
                AccentBrush1         = (IBrush)outVar !;
                AccentPen1           = new Pen(AccentBrush1);
                AccentPen1Thickness2 = new Pen(AccentBrush1, 2);
                AccentPen1Thickness3 = new Pen(AccentBrush1, 3);
            }
            if (resDict.TryGetResource("AccentBrush1Semi", out outVar))
            {
                AccentBrush1Semi = (IBrush)outVar !;
            }
            if (resDict.TryGetResource("AccentBrush2", out outVar))
            {
                AccentBrush2         = (IBrush)outVar !;
                AccentPen2           = new Pen(AccentBrush2, 1);
                AccentPen2Thickness2 = new Pen(AccentBrush2, 2);
                AccentPen2Thickness3 = new Pen(AccentBrush2, 3);
            }
            if (resDict.TryGetResource("AccentBrush2Semi", out outVar))
            {
                AccentBrush2Semi = (IBrush)outVar !;
            }
            if (resDict.TryGetResource("AccentBrush3", out outVar))
            {
                AccentBrush3    = (IBrush)outVar !;
                AccentPen3      = new Pen(AccentBrush3, 1);
                AccentPen3Thick = new Pen(AccentBrush3, 3);
            }
            if (resDict.TryGetResource("AccentBrush3Semi", out outVar))
            {
                AccentBrush3Semi = (IBrush)outVar !;
            }
            if (resDict.TryGetResource("TickLineBrushLow", out outVar))
            {
                TickLineBrushLow = (IBrush)outVar !;
            }
            if (resDict.TryGetResource("BarNumberBrush", out outVar))
            {
                BarNumberBrush = (IBrush)outVar !;
                BarNumberPen   = new Pen(BarNumberBrush, 1);
            }
            if (resDict.TryGetResource("WhiteKeyBrush", out outVar))
            {
                WhiteKeyBrush = (IBrush)outVar !;
            }
            if (resDict.TryGetResource("WhiteKeyNameBrush", out outVar))
            {
                WhiteKeyNameBrush = (IBrush)outVar !;
            }
            if (resDict.TryGetResource("CenterKeyBrush", out outVar))
            {
                CenterKeyBrush = (IBrush)outVar !;
            }
            if (resDict.TryGetResource("CenterKeyNameBrush", out outVar))
            {
                CenterKeyNameBrush = (IBrush)outVar !;
            }
            if (resDict.TryGetResource("BlackKeyBrush", out outVar))
            {
                BlackKeyBrush = (IBrush)outVar !;
            }
            if (resDict.TryGetResource("BlackKeyNameBrush", out outVar))
            {
                BlackKeyNameBrush = (IBrush)outVar !;
            }
            if (!IsDarkMode)
            {
                ExpBrush           = WhiteKeyBrush;
                ExpNameBrush       = WhiteKeyNameBrush;
                ExpActiveBrush     = BlackKeyBrush;
                ExpActiveNameBrush = BlackKeyNameBrush;
                ExpShadowBrush     = CenterKeyBrush;
                ExpShadowNameBrush = CenterKeyNameBrush;
            }
            else
            {
                ExpBrush           = BlackKeyBrush;
                ExpNameBrush       = BlackKeyNameBrush;
                ExpActiveBrush     = WhiteKeyBrush;
                ExpActiveNameBrush = WhiteKeyNameBrush;
                ExpShadowBrush     = CenterKeyBrush;
                ExpShadowNameBrush = CenterKeyNameBrush;
            }
            TextLayoutCache.Clear();
            MessageBus.Current.SendMessage(new ThemeChangedEvent());
        }
Ejemplo n.º 3
0
 public TextLayoutCache(TextLayoutCache layout) : this()
 {
     Previus = layout;
 }