mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Brushed up brushes
This commit is contained in:
parent
f797bc470a
commit
a9194e6906
@ -16,7 +16,7 @@ namespace Artemis.Profiles.Lua.Brushes
|
||||
public LuaLinearGradientBrush(Script script, LinearGradientBrush linearGradientBrush)
|
||||
{
|
||||
_script = script;
|
||||
Brush = linearGradientBrush;
|
||||
LinearGradientBrush = linearGradientBrush;
|
||||
}
|
||||
|
||||
public LuaLinearGradientBrush(Script script, Table gradientColors,
|
||||
@ -30,13 +30,14 @@ namespace Artemis.Profiles.Lua.Brushes
|
||||
/// The underlying brush
|
||||
/// </summary>
|
||||
[MoonSharpVisible(false)]
|
||||
public new LinearGradientBrush Brush
|
||||
public LinearGradientBrush LinearGradientBrush
|
||||
{
|
||||
get { return _brush; }
|
||||
set
|
||||
{
|
||||
_brush = value;
|
||||
_brush.Freeze();
|
||||
Brush = _brush;
|
||||
}
|
||||
}
|
||||
|
||||
@ -45,12 +46,12 @@ namespace Artemis.Profiles.Lua.Brushes
|
||||
/// </summary>
|
||||
public Table Colors
|
||||
{
|
||||
get { return CreateGradientTable(_script, Brush.GradientStops); }
|
||||
get { return CreateGradientTable(_script, LinearGradientBrush.GradientStops); }
|
||||
set
|
||||
{
|
||||
var updatedBrush = Brush.CloneCurrentValue();
|
||||
var updatedBrush = LinearGradientBrush.CloneCurrentValue();
|
||||
updatedBrush.GradientStops = CreateGradientCollection(value);
|
||||
Brush = updatedBrush;
|
||||
LinearGradientBrush = updatedBrush;
|
||||
}
|
||||
}
|
||||
|
||||
@ -65,7 +66,7 @@ namespace Artemis.Profiles.Lua.Brushes
|
||||
private void SetupBrush(Table gradientColors, double startX, double startY, double endX, double endY)
|
||||
{
|
||||
var collection = CreateGradientCollection(gradientColors);
|
||||
Brush = new LinearGradientBrush(collection, new Point(startX, startY), new Point(endX, endY));
|
||||
LinearGradientBrush = new LinearGradientBrush(collection, new Point(startX, startY), new Point(endX, endY));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -14,7 +14,7 @@ namespace Artemis.Profiles.Lua.Brushes
|
||||
public LuaRadialGradientBrush(Script script, RadialGradientBrush radialGradientBrush)
|
||||
{
|
||||
_script = script;
|
||||
Brush = radialGradientBrush;
|
||||
RadialGradientBrush = radialGradientBrush;
|
||||
}
|
||||
|
||||
public LuaRadialGradientBrush(Script script, Table gradientColors,
|
||||
@ -28,13 +28,14 @@ namespace Artemis.Profiles.Lua.Brushes
|
||||
/// The underlying brush
|
||||
/// </summary>
|
||||
[MoonSharpVisible(false)]
|
||||
public new RadialGradientBrush Brush
|
||||
public RadialGradientBrush RadialGradientBrush
|
||||
{
|
||||
get { return _brush; }
|
||||
set
|
||||
{
|
||||
_brush = value;
|
||||
_brush.Freeze();
|
||||
Brush = _brush;
|
||||
}
|
||||
}
|
||||
|
||||
@ -43,12 +44,12 @@ namespace Artemis.Profiles.Lua.Brushes
|
||||
/// </summary>
|
||||
public Table Colors
|
||||
{
|
||||
get { return LuaLinearGradientBrush.CreateGradientTable(_script, Brush.GradientStops); }
|
||||
get { return LuaLinearGradientBrush.CreateGradientTable(_script, RadialGradientBrush.GradientStops); }
|
||||
set
|
||||
{
|
||||
var updatedBrush = Brush.CloneCurrentValue();
|
||||
var updatedBrush = RadialGradientBrush.CloneCurrentValue();
|
||||
updatedBrush.GradientStops = LuaLinearGradientBrush.CreateGradientCollection(value);
|
||||
Brush = updatedBrush;
|
||||
RadialGradientBrush = updatedBrush;
|
||||
}
|
||||
}
|
||||
|
||||
@ -63,7 +64,7 @@ namespace Artemis.Profiles.Lua.Brushes
|
||||
private void SetupBrush(Table gradientColors, double centerX, double centerY, double originX, double originY)
|
||||
{
|
||||
var collection = LuaLinearGradientBrush.CreateGradientCollection(gradientColors);
|
||||
Brush = new RadialGradientBrush(collection)
|
||||
RadialGradientBrush = new RadialGradientBrush(collection)
|
||||
{
|
||||
Center = new Point(centerX, centerY),
|
||||
GradientOrigin = new Point(originX, originY)
|
||||
|
||||
@ -12,25 +12,26 @@ namespace Artemis.Profiles.Lua.Brushes
|
||||
|
||||
public LuaSolidColorBrush(SolidColorBrush solidColorBrush)
|
||||
{
|
||||
Brush = solidColorBrush;
|
||||
SolidColorBrush = solidColorBrush;
|
||||
}
|
||||
|
||||
public LuaSolidColorBrush(string hexCode)
|
||||
{
|
||||
Brush = new SolidColorBrush(new Color().FromHex(hexCode));
|
||||
SolidColorBrush = new SolidColorBrush(new Color().FromHex(hexCode));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The underlying brush
|
||||
/// </summary>
|
||||
[MoonSharpVisible(false)]
|
||||
public new SolidColorBrush Brush
|
||||
public SolidColorBrush SolidColorBrush
|
||||
{
|
||||
get { return _brush; }
|
||||
set
|
||||
{
|
||||
_brush = value;
|
||||
_brush.Freeze();
|
||||
Brush = _brush;
|
||||
}
|
||||
}
|
||||
|
||||
@ -39,8 +40,8 @@ namespace Artemis.Profiles.Lua.Brushes
|
||||
/// </summary>
|
||||
public string Color
|
||||
{
|
||||
get { return Brush.Color.ToHex(); }
|
||||
set { Brush = new SolidColorBrush(new Color().FromHex(value)); }
|
||||
get { return SolidColorBrush.Color.ToHex(); }
|
||||
set { SolidColorBrush = new SolidColorBrush(new Color().FromHex(value)); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -13,22 +13,22 @@ namespace Artemis.Profiles.Lua
|
||||
_script = script;
|
||||
}
|
||||
|
||||
// TODO: Check default values
|
||||
public LuaRadialGradientBrush GetSolidColorBrush(Table gradientColors,
|
||||
double centerX = 0.5, double centerY = 0.5, double originX = 0.5, double originY = 0.5)
|
||||
public LuaSolidColorBrush GetSolidColorBrush(string hexCode)
|
||||
{
|
||||
return new LuaRadialGradientBrush(_script, gradientColors, centerX, centerY, originX, originY);
|
||||
return new LuaSolidColorBrush(hexCode);
|
||||
}
|
||||
|
||||
|
||||
public LuaLinearGradientBrush GetLinearGradientBrush(Table gradientColors,
|
||||
double startX = 0.5, double startY = 0.0, double endX = 0.5, double endY = 1.0)
|
||||
{
|
||||
return new LuaLinearGradientBrush(_script, gradientColors, startX, startY, endX, endY);
|
||||
}
|
||||
|
||||
public LuaSolidColorBrush GetRadialGradientBrush(string hexCode)
|
||||
// TODO: Check default values
|
||||
public LuaRadialGradientBrush GetRadialGradientBrush(Table gradientColors,
|
||||
double centerX = 0.5, double centerY = 0.5, double originX = 0.5, double originY = 0.5)
|
||||
{
|
||||
return new LuaSolidColorBrush(hexCode);
|
||||
return new LuaRadialGradientBrush(_script, gradientColors, centerX, centerY, originX, originY);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,9 +1,9 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using Artemis.Profiles.Lua.Brushes;
|
||||
using MoonSharp.Interpreter;
|
||||
using Pen = System.Windows.Media.Pen;
|
||||
|
||||
namespace Artemis.Profiles.Lua
|
||||
{
|
||||
@ -17,10 +17,32 @@ namespace Artemis.Profiles.Lua
|
||||
_ctx = ctx;
|
||||
}
|
||||
|
||||
public void DrawCircle(LuaBrush luaBrush, double x, double y, double height, double width)
|
||||
public void DrawEllipse(LuaBrush luaBrush, double x, double y, double height, double width)
|
||||
{
|
||||
var center = new Point(x + width/2, y + height/2);
|
||||
_ctx.DrawEllipse(luaBrush.Brush, new Pen(), center, width, height);
|
||||
}
|
||||
|
||||
public void DrawLine(LuaBrush luaBrush, double startX, double startY, double endX, double endY,
|
||||
double thickness)
|
||||
{
|
||||
_ctx.DrawLine(new Pen(luaBrush.Brush, thickness), new Point(startX, startY), new Point(endX, endY));
|
||||
}
|
||||
|
||||
public void DrawRectangle(LuaBrush luaBrush, double x, double y, double height, double width)
|
||||
{
|
||||
_ctx.DrawRectangle(luaBrush.Brush, new Pen(), new Rect(x, y, width, height));
|
||||
}
|
||||
|
||||
public void DrawText(string text, string fontName, int fontSize, LuaBrush luaBrush, double x, double y)
|
||||
{
|
||||
var font = Fonts.SystemTypefaces.FirstOrDefault(f => f.FontFamily.ToString() == fontName);
|
||||
if (font == null)
|
||||
throw new ScriptRuntimeException($"Font '{fontName}' not found");
|
||||
|
||||
var formatted = new FormattedText(text, CultureInfo.InvariantCulture, FlowDirection.LeftToRight, font,
|
||||
fontSize, luaBrush.Brush);
|
||||
_ctx.DrawText(formatted, new Point(x, y));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -15,14 +15,30 @@ namespace Artemis.Profiles.Lua
|
||||
|
||||
internal void InvokeProfileUpdate(ProfileModel profileModel, IDataModel dataModel, bool preview)
|
||||
{
|
||||
OnLuaProfileUpdating(new LuaProfileWrapper(profileModel),
|
||||
try
|
||||
{
|
||||
OnLuaProfileUpdating(new LuaProfileWrapper(profileModel),
|
||||
new LuaProfileUpdatingEventArgs(dataModel, preview));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal void InvokeProfileDraw(ProfileModel profileModel, IDataModel dataModel, bool preview, DrawingContext c)
|
||||
{
|
||||
OnLuaProfileDrawing(new LuaProfileWrapper(profileModel),
|
||||
try
|
||||
{
|
||||
OnLuaProfileDrawing(new LuaProfileWrapper(profileModel),
|
||||
new LuaProfileDrawingEventArgs(dataModel, preview, new LuaDrawWrapper(c)));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user