Merge branch 'colors-features' into all-pull-request-at-once

This commit is contained in:
BDisp
2020-03-10 13:45:51 +00:00
4 changed files with 156 additions and 20 deletions

View File

@@ -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

View File

@@ -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 {
/// </summary>
public static void Init () => Init (() => Toplevel.Create ());
static bool _initialized = false;
internal static bool _initialized = false;
/// <summary>
/// Initializes the Application
@@ -1749,7 +1749,6 @@ namespace Terminal.Gui {
static void Init (Func<Toplevel> 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;
}
/// <summary>

View File

@@ -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 {
/// </remarks>
public struct Attribute {
internal int value;
internal Color foreground;
internal Color background;
/// <summary>
/// Initializes a new instance of the <see cref="T:Terminal.Gui.Attribute"/> struct.
/// </summary>
/// <param name="value">Value.</param>
public Attribute (int value)
/// <param name="foreground">Foreground</param>
/// <param name="background">Background</param>
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;
}
/// <summary>
@@ -137,50 +151,168 @@ namespace Terminal.Gui {
/// views contained inside.
/// </summary>
public class ColorScheme {
private Attribute _normal;
private Attribute _focus;
private Attribute _hotNormal;
private Attribute _hotFocus;
/// <summary>
/// The default color for text, when the view is not focused.
/// </summary>
public Attribute Normal;
public Attribute Normal { get { return _normal; } set { _normal = SetAttribute (value); } }
/// <summary>
/// The color for text when the view has the focus.
/// </summary>
public Attribute Focus;
public Attribute Focus { get { return _focus; } set { _focus = SetAttribute (value); } }
/// <summary>
/// The color for the hotkey when a view is not focused
/// </summary>
public Attribute HotNormal;
public Attribute HotNormal { get { return _hotNormal; } set { _hotNormal = SetAttribute (value); } }
/// <summary>
/// The color for the hotkey when the view is focused.
/// </summary>
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;
}
}
/// <summary>
/// The default ColorSchemes for the application.
/// </summary>
public static class Colors {
private static ColorScheme _base;
private static ColorScheme _dialog;
private static ColorScheme _menu;
private static ColorScheme _error;
/// <summary>
/// The base color scheme, for the default toplevel views.
/// </summary>
public static ColorScheme Base;
public static ColorScheme Base { get { return _base; } set { _base = SetColorScheme (value); } }
/// <summary>
/// The dialog color scheme, for standard popup dialog boxes
/// </summary>
public static ColorScheme Dialog;
public static ColorScheme Dialog { get { return _dialog; } set { _dialog = SetColorScheme (value); } }
/// <summary>
/// The menu bar color
/// </summary>
public static ColorScheme Menu;
public static ColorScheme Menu { get { return _menu; } set { _menu = SetColorScheme (value); } }
/// <summary>
/// The color scheme for showing errors.
/// </summary>
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;
}
}
/// <summary>
@@ -388,7 +520,7 @@ namespace Terminal.Gui {
for (int l = 0; l < padding; l++)
for (b = 0; b < width; b++)
AddRune (' ');
}
}
}

View File

@@ -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 {
}
}