diff --git a/.editorconfig b/.editorconfig index 3ad2ee46d..576839082 100644 --- a/.editorconfig +++ b/.editorconfig @@ -17,3 +17,6 @@ csharp_preserve_single_line_blocks = true dotnet_style_require_accessibility_modifiers = never csharp_style_var_when_type_is_apparent = true csharp_prefer_braces = false +csharp_space_before_open_square_brackets = true +csharp_space_between_method_call_name_and_opening_parenthesis = true +csharp_space_between_method_declaration_name_and_open_parenthesis = true \ No newline at end of file diff --git a/Terminal.Gui/Core.cs b/Terminal.Gui/Core.cs index e2cb24d79..4a54dfd69 100644 --- a/Terminal.Gui/Core.cs +++ b/Terminal.Gui/Core.cs @@ -1585,9 +1585,9 @@ namespace Terminal.Gui { // a pending mouse event activated. if (true) return false; - + if ((mouseEvent.Flags == MouseFlags.Button1Pressed|| mouseEvent.Flags == MouseFlags.Button4Pressed)){ - + if (dragPosition.HasValue) { var dx = mouseEvent.X - dragPosition.Value.X; var dy = mouseEvent.Y - dragPosition.Value.Y; @@ -1741,7 +1741,7 @@ namespace Terminal.Gui { /// public static void Init () => Init (() => Toplevel.Create ()); - static bool _initialized = false; + internal static bool _initialized = false; /// /// Initializes the Application @@ -1749,7 +1749,6 @@ namespace Terminal.Gui { static void Init (Func topLevelFactory) { if (_initialized) return; - _initialized = true; var p = Environment.OSVersion.Platform; Mono.Terminal.IMainLoopDriver mainLoopDriver; @@ -1770,6 +1769,7 @@ namespace Terminal.Gui { SynchronizationContext.SetSynchronizationContext (new MainLoopSyncContext (MainLoop)); Top = topLevelFactory (); Current = Top; + _initialized = true; } /// diff --git a/Terminal.Gui/Drivers/ConsoleDriver.cs b/Terminal.Gui/Drivers/ConsoleDriver.cs index 7ab4139f5..684245cc6 100644 --- a/Terminal.Gui/Drivers/ConsoleDriver.cs +++ b/Terminal.Gui/Drivers/ConsoleDriver.cs @@ -6,6 +6,7 @@ // using System; using System.Collections.Generic; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using Mono.Terminal; using NStack; @@ -93,14 +94,27 @@ namespace Terminal.Gui { /// public struct Attribute { internal int value; + internal Color foreground; + internal Color background; /// /// Initializes a new instance of the struct. /// /// Value. - public Attribute (int value) + /// Foreground + /// Background + public Attribute (int value, Color foreground = new Color(), Color background = new Color()) { this.value = value; + this.foreground = foreground; + this.background = background; + } + + public Attribute (Color foreground = new Color (), Color background = new Color ()) + { + this.value = value = ((int)foreground | (int)background << 4); + this.foreground = foreground; + this.background = background; } /// @@ -137,50 +151,168 @@ namespace Terminal.Gui { /// views contained inside. /// public class ColorScheme { + private Attribute _normal; + private Attribute _focus; + private Attribute _hotNormal; + private Attribute _hotFocus; + /// /// The default color for text, when the view is not focused. /// - public Attribute Normal; + public Attribute Normal { get { return _normal; } set { _normal = SetAttribute (value); } } + /// /// The color for text when the view has the focus. /// - public Attribute Focus; + public Attribute Focus { get { return _focus; } set { _focus = SetAttribute (value); } } /// /// The color for the hotkey when a view is not focused /// - public Attribute HotNormal; + public Attribute HotNormal { get { return _hotNormal; } set { _hotNormal = SetAttribute (value); } } /// /// The color for the hotkey when the view is focused. /// - public Attribute HotFocus; + public Attribute HotFocus { get { return _hotFocus; } set { _hotFocus = SetAttribute (value); } } + + public string Caller = ""; + + private bool preparingScheme = false; + + private Attribute SetAttribute (Attribute attribute, [CallerMemberName]string callerMemberName = null) + { + if (!Application._initialized && !preparingScheme) + return attribute; + + if (preparingScheme) + return attribute; + + preparingScheme = true; + switch (Caller) { + case "Base": + switch (callerMemberName) { + case "Normal": + HotNormal = Application.Driver.MakeAttribute (HotNormal.foreground, attribute.background); + break; + case "Focus": + HotFocus = Application.Driver.MakeAttribute (HotFocus.foreground, attribute.background); + break; + case "HotNormal": + HotFocus = Application.Driver.MakeAttribute (attribute.foreground, HotFocus.background); + Normal = Application.Driver.MakeAttribute (Normal.foreground, attribute.background); + break; + case "HotFocus": + HotNormal = Application.Driver.MakeAttribute (attribute.foreground, HotNormal.background); + if (Focus.foreground != attribute.background) + Focus = Application.Driver.MakeAttribute (Focus.foreground, attribute.background); + break; + } + break; + + case "Menu": + switch (callerMemberName) { + case "Normal": + if (Focus.background != attribute.background) + Focus = Application.Driver.MakeAttribute (attribute.foreground, Focus.background); + HotNormal = Application.Driver.MakeAttribute (HotNormal.foreground, attribute.background); + break; + case "Focus": + Normal = Application.Driver.MakeAttribute (attribute.foreground, Normal.background); + HotFocus = Application.Driver.MakeAttribute (HotFocus.foreground, attribute.background); + break; + case "HotNormal": + if (Focus.background != attribute.background) + HotFocus = Application.Driver.MakeAttribute (attribute.foreground, HotFocus.background); + Normal = Application.Driver.MakeAttribute (Normal.foreground, attribute.background); + break; + case "HotFocus": + HotNormal = Application.Driver.MakeAttribute (attribute.foreground, HotNormal.background); + if (Focus.foreground != attribute.background) + Focus = Application.Driver.MakeAttribute (Focus.foreground, attribute.background); + break; + } + break; + + case "Dialog": + switch (callerMemberName) { + case "Normal": + if (Focus.background != attribute.background) + Focus = Application.Driver.MakeAttribute (attribute.foreground, Focus.background); + HotNormal = Application.Driver.MakeAttribute (HotNormal.foreground, attribute.background); + break; + case "Focus": + Normal = Application.Driver.MakeAttribute (attribute.foreground, Normal.background); + HotFocus = Application.Driver.MakeAttribute (HotFocus.foreground, attribute.background); + break; + case "HotNormal": + if (Focus.background != attribute.background) + HotFocus = Application.Driver.MakeAttribute (attribute.foreground, HotFocus.background); + if (Normal.foreground != attribute.background) + Normal = Application.Driver.MakeAttribute (Normal.foreground, attribute.background); + break; + case "HotFocus": + HotNormal = Application.Driver.MakeAttribute (attribute.foreground, HotNormal.background); + if (Focus.foreground != attribute.background) + Focus = Application.Driver.MakeAttribute (Focus.foreground, attribute.background); + break; + } + break; + + case "Error": + switch (callerMemberName) { + case "Normal": + HotNormal = Application.Driver.MakeAttribute (HotNormal.foreground, attribute.background); + HotFocus = Application.Driver.MakeAttribute (HotFocus.foreground, attribute.background); + break; + case "HotNormal": + case "HotFocus": + HotFocus = Application.Driver.MakeAttribute (attribute.foreground, attribute.background); + Normal = Application.Driver.MakeAttribute (Normal.foreground, attribute.background); + break; + } + break; + + } + preparingScheme = false; + return attribute; + } } /// /// The default ColorSchemes for the application. /// public static class Colors { + private static ColorScheme _base; + private static ColorScheme _dialog; + private static ColorScheme _menu; + private static ColorScheme _error; + /// /// The base color scheme, for the default toplevel views. /// - public static ColorScheme Base; - + public static ColorScheme Base { get { return _base; } set { _base = SetColorScheme (value); } } + /// /// The dialog color scheme, for standard popup dialog boxes /// - public static ColorScheme Dialog; + public static ColorScheme Dialog { get { return _dialog; } set { _dialog = SetColorScheme (value); } } /// /// The menu bar color /// - public static ColorScheme Menu; + public static ColorScheme Menu { get { return _menu; } set { _menu = SetColorScheme (value); } } /// /// The color scheme for showing errors. /// - public static ColorScheme Error; + public static ColorScheme Error { get { return _error; } set { _error = SetColorScheme (value); } } + private static ColorScheme SetColorScheme (ColorScheme colorScheme, [CallerMemberName]string callerMemberName = null) + { + colorScheme.Caller = callerMemberName; + return colorScheme; + } } /// @@ -388,7 +520,7 @@ namespace Terminal.Gui { for (int l = 0; l < padding; l++) for (b = 0; b < width; b++) AddRune (' '); - } + } } diff --git a/Terminal.Gui/Drivers/WindowsDriver.cs b/Terminal.Gui/Drivers/WindowsDriver.cs index 0074181c7..31652f2ec 100644 --- a/Terminal.Gui/Drivers/WindowsDriver.cs +++ b/Terminal.Gui/Drivers/WindowsDriver.cs @@ -763,10 +763,10 @@ namespace Terminal.Gui { Colors.Base.HotNormal = MakeColor (ConsoleColor.Yellow, ConsoleColor.Blue); Colors.Base.HotFocus = MakeColor (ConsoleColor.Yellow, ConsoleColor.Cyan); - Colors.Menu.HotFocus = MakeColor (ConsoleColor.Yellow, ConsoleColor.Black); + Colors.Menu.Normal = MakeColor (ConsoleColor.White, ConsoleColor.Cyan); Colors.Menu.Focus = MakeColor (ConsoleColor.White, ConsoleColor.Black); Colors.Menu.HotNormal = MakeColor (ConsoleColor.Yellow, ConsoleColor.Cyan); - Colors.Menu.Normal = MakeColor (ConsoleColor.White, ConsoleColor.Cyan); + Colors.Menu.HotFocus = MakeColor (ConsoleColor.Yellow, ConsoleColor.Black); Colors.Dialog.Normal = MakeColor (ConsoleColor.Black, ConsoleColor.Gray); Colors.Dialog.Focus = MakeColor (ConsoleColor.Black, ConsoleColor.Cyan); @@ -847,7 +847,9 @@ namespace Terminal.Gui { { // Encode the colors into the int value. return new Attribute () { - value = ((int)f | (int)b << 4) + value = ((int)f | (int)b << 4), + foreground = (Color)f, + background = (Color)b }; } @@ -881,7 +883,7 @@ namespace Terminal.Gui { { if (damageRegion.Left == -1) return; - + var bufferCoords = new WindowsConsole.Coord (){ X = (short)Clip.Width, Y = (short)Clip.Height @@ -945,5 +947,4 @@ namespace Terminal.Gui { } - }