committed by
GitHub
6 changed files with 1299 additions and 675 deletions
@ -0,0 +1,150 @@ |
|||||
|
using Avalonia.Media; |
||||
|
using Avalonia.Utilities; |
||||
|
using FlatColor = Avalonia.Controls.FlatColorPalette.FlatColor; |
||||
|
|
||||
|
namespace Avalonia.Controls |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Implements half of the <see cref="FlatColorPalette"/> for improved usability.
|
||||
|
/// </summary>
|
||||
|
/// <inheritdoc cref="FlatColorPalette"/>
|
||||
|
public class FlatHalfColorPalette : IColorPalette |
||||
|
{ |
||||
|
protected static Color[,]? _colorChart = null; |
||||
|
protected static object _colorChartMutex = new object(); |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Initializes all color chart colors.
|
||||
|
/// </summary>
|
||||
|
protected void InitColorChart() |
||||
|
{ |
||||
|
lock (_colorChartMutex) |
||||
|
{ |
||||
|
if (_colorChart != null) |
||||
|
{ |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
_colorChart = new Color[,] |
||||
|
{ |
||||
|
// Pomegranate
|
||||
|
{ |
||||
|
Color.FromUInt32((uint)FlatColor.Pomegranate1), |
||||
|
Color.FromUInt32((uint)FlatColor.Pomegranate3), |
||||
|
Color.FromUInt32((uint)FlatColor.Pomegranate5), |
||||
|
Color.FromUInt32((uint)FlatColor.Pomegranate7), |
||||
|
Color.FromUInt32((uint)FlatColor.Pomegranate9), |
||||
|
}, |
||||
|
|
||||
|
// Amethyst
|
||||
|
{ |
||||
|
Color.FromUInt32((uint)FlatColor.Amethyst1), |
||||
|
Color.FromUInt32((uint)FlatColor.Amethyst3), |
||||
|
Color.FromUInt32((uint)FlatColor.Amethyst5), |
||||
|
Color.FromUInt32((uint)FlatColor.Amethyst7), |
||||
|
Color.FromUInt32((uint)FlatColor.Amethyst9), |
||||
|
}, |
||||
|
|
||||
|
// Belize Hole
|
||||
|
{ |
||||
|
Color.FromUInt32((uint)FlatColor.BelizeHole1), |
||||
|
Color.FromUInt32((uint)FlatColor.BelizeHole3), |
||||
|
Color.FromUInt32((uint)FlatColor.BelizeHole5), |
||||
|
Color.FromUInt32((uint)FlatColor.BelizeHole7), |
||||
|
Color.FromUInt32((uint)FlatColor.BelizeHole9), |
||||
|
}, |
||||
|
|
||||
|
// Turquoise
|
||||
|
{ |
||||
|
Color.FromUInt32((uint)FlatColor.Turquoise1), |
||||
|
Color.FromUInt32((uint)FlatColor.Turquoise3), |
||||
|
Color.FromUInt32((uint)FlatColor.Turquoise5), |
||||
|
Color.FromUInt32((uint)FlatColor.Turquoise7), |
||||
|
Color.FromUInt32((uint)FlatColor.Turquoise9), |
||||
|
}, |
||||
|
|
||||
|
// Nephritis
|
||||
|
{ |
||||
|
Color.FromUInt32((uint)FlatColor.Nephritis1), |
||||
|
Color.FromUInt32((uint)FlatColor.Nephritis3), |
||||
|
Color.FromUInt32((uint)FlatColor.Nephritis5), |
||||
|
Color.FromUInt32((uint)FlatColor.Nephritis7), |
||||
|
Color.FromUInt32((uint)FlatColor.Nephritis9), |
||||
|
}, |
||||
|
|
||||
|
// Sunflower
|
||||
|
{ |
||||
|
Color.FromUInt32((uint)FlatColor.Sunflower1), |
||||
|
Color.FromUInt32((uint)FlatColor.Sunflower3), |
||||
|
Color.FromUInt32((uint)FlatColor.Sunflower5), |
||||
|
Color.FromUInt32((uint)FlatColor.Sunflower7), |
||||
|
Color.FromUInt32((uint)FlatColor.Sunflower9), |
||||
|
}, |
||||
|
|
||||
|
// Carrot
|
||||
|
{ |
||||
|
Color.FromUInt32((uint)FlatColor.Carrot1), |
||||
|
Color.FromUInt32((uint)FlatColor.Carrot3), |
||||
|
Color.FromUInt32((uint)FlatColor.Carrot5), |
||||
|
Color.FromUInt32((uint)FlatColor.Carrot7), |
||||
|
Color.FromUInt32((uint)FlatColor.Carrot9), |
||||
|
}, |
||||
|
|
||||
|
// Clouds
|
||||
|
{ |
||||
|
Color.FromUInt32((uint)FlatColor.Clouds1), |
||||
|
Color.FromUInt32((uint)FlatColor.Clouds3), |
||||
|
Color.FromUInt32((uint)FlatColor.Clouds5), |
||||
|
Color.FromUInt32((uint)FlatColor.Clouds7), |
||||
|
Color.FromUInt32((uint)FlatColor.Clouds9), |
||||
|
}, |
||||
|
|
||||
|
// Concrete
|
||||
|
{ |
||||
|
Color.FromUInt32((uint)FlatColor.Concrete1), |
||||
|
Color.FromUInt32((uint)FlatColor.Concrete3), |
||||
|
Color.FromUInt32((uint)FlatColor.Concrete5), |
||||
|
Color.FromUInt32((uint)FlatColor.Concrete7), |
||||
|
Color.FromUInt32((uint)FlatColor.Concrete9), |
||||
|
}, |
||||
|
|
||||
|
// Wet Asphalt
|
||||
|
{ |
||||
|
Color.FromUInt32((uint)FlatColor.WetAsphalt1), |
||||
|
Color.FromUInt32((uint)FlatColor.WetAsphalt3), |
||||
|
Color.FromUInt32((uint)FlatColor.WetAsphalt5), |
||||
|
Color.FromUInt32((uint)FlatColor.WetAsphalt7), |
||||
|
Color.FromUInt32((uint)FlatColor.WetAsphalt9), |
||||
|
}, |
||||
|
}; |
||||
|
} |
||||
|
|
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
public int ColorCount |
||||
|
{ |
||||
|
get => 10; |
||||
|
} |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
public int ShadeCount |
||||
|
{ |
||||
|
get => 5; |
||||
|
} |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
public Color GetColor(int colorIndex, int shadeIndex) |
||||
|
{ |
||||
|
if (_colorChart == null) |
||||
|
{ |
||||
|
InitColorChart(); |
||||
|
} |
||||
|
|
||||
|
return _colorChart![ |
||||
|
MathUtilities.Clamp(colorIndex, 0, ColorCount - 1), |
||||
|
MathUtilities.Clamp(shadeIndex, 0, ShadeCount - 1)]; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,150 @@ |
|||||
|
using Avalonia.Media; |
||||
|
using Avalonia.Utilities; |
||||
|
using MaterialColor = Avalonia.Controls.MaterialColorPalette.MaterialColor; |
||||
|
|
||||
|
namespace Avalonia.Controls |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Implements half of the <see cref="MaterialColorPalette"/> for improved usability.
|
||||
|
/// </summary>
|
||||
|
/// <inheritdoc cref="MaterialColorPalette"/>
|
||||
|
public class MaterialHalfColorPalette : IColorPalette |
||||
|
{ |
||||
|
protected static Color[,]? _colorChart = null; |
||||
|
protected static object _colorChartMutex = new object(); |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Initializes all color chart colors.
|
||||
|
/// </summary>
|
||||
|
protected void InitColorChart() |
||||
|
{ |
||||
|
lock (_colorChartMutex) |
||||
|
{ |
||||
|
if (_colorChart != null) |
||||
|
{ |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
_colorChart = new Color[,] |
||||
|
{ |
||||
|
// Red
|
||||
|
{ |
||||
|
Color.FromUInt32((uint)MaterialColor.Red50), |
||||
|
Color.FromUInt32((uint)MaterialColor.Red200), |
||||
|
Color.FromUInt32((uint)MaterialColor.Red400), |
||||
|
Color.FromUInt32((uint)MaterialColor.Red600), |
||||
|
Color.FromUInt32((uint)MaterialColor.Red800), |
||||
|
}, |
||||
|
|
||||
|
// Purple
|
||||
|
{ |
||||
|
Color.FromUInt32((uint)MaterialColor.Purple50), |
||||
|
Color.FromUInt32((uint)MaterialColor.Purple200), |
||||
|
Color.FromUInt32((uint)MaterialColor.Purple400), |
||||
|
Color.FromUInt32((uint)MaterialColor.Purple600), |
||||
|
Color.FromUInt32((uint)MaterialColor.Purple800), |
||||
|
}, |
||||
|
|
||||
|
// Indigo
|
||||
|
{ |
||||
|
Color.FromUInt32((uint)MaterialColor.Indigo50), |
||||
|
Color.FromUInt32((uint)MaterialColor.Indigo200), |
||||
|
Color.FromUInt32((uint)MaterialColor.Indigo400), |
||||
|
Color.FromUInt32((uint)MaterialColor.Indigo600), |
||||
|
Color.FromUInt32((uint)MaterialColor.Indigo800), |
||||
|
}, |
||||
|
|
||||
|
// Light Blue
|
||||
|
{ |
||||
|
Color.FromUInt32((uint)MaterialColor.LightBlue50), |
||||
|
Color.FromUInt32((uint)MaterialColor.LightBlue200), |
||||
|
Color.FromUInt32((uint)MaterialColor.LightBlue400), |
||||
|
Color.FromUInt32((uint)MaterialColor.LightBlue600), |
||||
|
Color.FromUInt32((uint)MaterialColor.LightBlue800), |
||||
|
}, |
||||
|
|
||||
|
// Teal
|
||||
|
{ |
||||
|
Color.FromUInt32((uint)MaterialColor.Teal50), |
||||
|
Color.FromUInt32((uint)MaterialColor.Teal200), |
||||
|
Color.FromUInt32((uint)MaterialColor.Teal400), |
||||
|
Color.FromUInt32((uint)MaterialColor.Teal600), |
||||
|
Color.FromUInt32((uint)MaterialColor.Teal800), |
||||
|
}, |
||||
|
|
||||
|
// Light Green
|
||||
|
{ |
||||
|
Color.FromUInt32((uint)MaterialColor.LightGreen50), |
||||
|
Color.FromUInt32((uint)MaterialColor.LightGreen200), |
||||
|
Color.FromUInt32((uint)MaterialColor.LightGreen400), |
||||
|
Color.FromUInt32((uint)MaterialColor.LightGreen600), |
||||
|
Color.FromUInt32((uint)MaterialColor.LightGreen800), |
||||
|
}, |
||||
|
|
||||
|
// Yellow
|
||||
|
{ |
||||
|
Color.FromUInt32((uint)MaterialColor.Yellow50), |
||||
|
Color.FromUInt32((uint)MaterialColor.Yellow200), |
||||
|
Color.FromUInt32((uint)MaterialColor.Yellow400), |
||||
|
Color.FromUInt32((uint)MaterialColor.Yellow600), |
||||
|
Color.FromUInt32((uint)MaterialColor.Yellow800), |
||||
|
}, |
||||
|
|
||||
|
// Orange
|
||||
|
{ |
||||
|
Color.FromUInt32((uint)MaterialColor.Orange50), |
||||
|
Color.FromUInt32((uint)MaterialColor.Orange200), |
||||
|
Color.FromUInt32((uint)MaterialColor.Orange400), |
||||
|
Color.FromUInt32((uint)MaterialColor.Orange600), |
||||
|
Color.FromUInt32((uint)MaterialColor.Orange800), |
||||
|
}, |
||||
|
|
||||
|
// Brown
|
||||
|
{ |
||||
|
Color.FromUInt32((uint)MaterialColor.Brown50), |
||||
|
Color.FromUInt32((uint)MaterialColor.Brown200), |
||||
|
Color.FromUInt32((uint)MaterialColor.Brown400), |
||||
|
Color.FromUInt32((uint)MaterialColor.Brown600), |
||||
|
Color.FromUInt32((uint)MaterialColor.Brown800), |
||||
|
}, |
||||
|
|
||||
|
// Blue Gray
|
||||
|
{ |
||||
|
Color.FromUInt32((uint)MaterialColor.BlueGray50), |
||||
|
Color.FromUInt32((uint)MaterialColor.BlueGray200), |
||||
|
Color.FromUInt32((uint)MaterialColor.BlueGray400), |
||||
|
Color.FromUInt32((uint)MaterialColor.BlueGray600), |
||||
|
Color.FromUInt32((uint)MaterialColor.BlueGray800), |
||||
|
}, |
||||
|
}; |
||||
|
} |
||||
|
|
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
public int ColorCount |
||||
|
{ |
||||
|
get => 10; |
||||
|
} |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
public int ShadeCount |
||||
|
{ |
||||
|
get => 5; |
||||
|
} |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
public Color GetColor(int colorIndex, int shadeIndex) |
||||
|
{ |
||||
|
if (_colorChart == null) |
||||
|
{ |
||||
|
InitColorChart(); |
||||
|
} |
||||
|
|
||||
|
return _colorChart![ |
||||
|
MathUtilities.Clamp(colorIndex, 0, ColorCount - 1), |
||||
|
MathUtilities.Clamp(shadeIndex, 0, ShadeCount - 1)]; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue