1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

LUA changes, added font for DrawText

This commit is contained in:
SpoinkyNL 2016-11-03 23:27:40 +01:00
parent 3a01536d85
commit 39f7d180d8
16 changed files with 103 additions and 23 deletions

View File

@ -682,6 +682,7 @@
<Compile Include="Properties\AssemblyInfo.cs"> <Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Resource Include="Resources\Kottke Silkscreen License.txt" />
<None Include="Resources\lua-placeholder.lua" /> <None Include="Resources\lua-placeholder.lua" />
<None Include="NLog.xsd"> <None Include="NLog.xsd">
<SubType>Designer</SubType> <SubType>Designer</SubType>
@ -708,6 +709,7 @@
<SubType>Designer</SubType> <SubType>Designer</SubType>
</None> </None>
<AppDesigner Include="Properties\" /> <AppDesigner Include="Properties\" />
<Resource Include="Resources\slkscr.ttf" />
<Resource Include="Resources\bow.png" /> <Resource Include="Resources\bow.png" />
<Content Include="lib\CUE.NET.dll" /> <Content Include="lib\CUE.NET.dll" />
<Content Include="lib\Ets2SdkClient.dll" /> <Content Include="lib\Ets2SdkClient.dll" />

View File

@ -8,6 +8,6 @@ namespace Artemis.Profiles.Lua.Brushes
public abstract class LuaBrush public abstract class LuaBrush
{ {
[MoonSharpVisible(false)] [MoonSharpVisible(false)]
public Brush Brush { get; set; } public virtual Brush Brush { get; set; }
} }
} }

View File

@ -1,7 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Windows.Media;
using Artemis.Utilities; using Artemis.Utilities;
using CUE.NET.Helper;
using MoonSharp.Interpreter; using MoonSharp.Interpreter;
namespace Artemis.Profiles.Lua.Brushes namespace Artemis.Profiles.Lua.Brushes

View File

@ -12,9 +12,9 @@ namespace Artemis.Profiles.Lua.Brushes
{ {
private LinearGradientBrush _brush; private LinearGradientBrush _brush;
public LuaLinearGradientBrush(LinearGradientBrush linearGradientBrush) public LuaLinearGradientBrush(LinearGradientBrush brush)
{ {
LinearGradientBrush = linearGradientBrush; LinearGradientBrush = brush;
} }
public LuaLinearGradientBrush(Dictionary<LuaColor, double> gradientColors, double startX, double startY, public LuaLinearGradientBrush(Dictionary<LuaColor, double> gradientColors, double startX, double startY,
@ -38,6 +38,12 @@ namespace Artemis.Profiles.Lua.Brushes
} }
} }
public override Brush Brush
{
get { return LinearGradientBrush; }
set { LinearGradientBrush = (LinearGradientBrush) value; }
}
/// <summary> /// <summary>
/// Gets or sets the Brush's GradientStops using a LUA table /// Gets or sets the Brush's GradientStops using a LUA table
/// </summary> /// </summary>

View File

@ -12,9 +12,9 @@ namespace Artemis.Profiles.Lua.Brushes
{ {
private RadialGradientBrush _brush; private RadialGradientBrush _brush;
public LuaRadialGradientBrush(RadialGradientBrush radialGradientBrush) public LuaRadialGradientBrush(RadialGradientBrush brush)
{ {
RadialGradientBrush = radialGradientBrush; RadialGradientBrush = brush;
} }
public LuaRadialGradientBrush(Dictionary<LuaColor, double> gradientColors, double centerX, public LuaRadialGradientBrush(Dictionary<LuaColor, double> gradientColors, double centerX,
@ -38,6 +38,12 @@ namespace Artemis.Profiles.Lua.Brushes
} }
} }
public override Brush Brush
{
get { return RadialGradientBrush; }
set { RadialGradientBrush = (RadialGradientBrush) value; }
}
/// <summary> /// <summary>
/// Gets or sets the Brush's GradientStops using a LUA table /// Gets or sets the Brush's GradientStops using a LUA table
/// </summary> /// </summary>

View File

@ -9,11 +9,16 @@ namespace Artemis.Profiles.Lua.Brushes
{ {
private SolidColorBrush _brush; private SolidColorBrush _brush;
public LuaSolidColorBrush(SolidColorBrush brush)
{
SolidColorBrush = brush;
}
public LuaSolidColorBrush(LuaColor luaColor) public LuaSolidColorBrush(LuaColor luaColor)
{ {
SolidColorBrush = new SolidColorBrush(luaColor.Color); SolidColorBrush = new SolidColorBrush(luaColor.Color);
} }
/// <summary> /// <summary>
/// The underlying brush /// The underlying brush
/// </summary> /// </summary>
@ -29,6 +34,12 @@ namespace Artemis.Profiles.Lua.Brushes
} }
} }
public override Brush Brush
{
get { return SolidColorBrush; }
set { SolidColorBrush = (SolidColorBrush)value; }
}
public LuaColor Color public LuaColor Color
{ {
get { return new LuaColor(SolidColorBrush.Color); } get { return new LuaColor(SolidColorBrush.Color); }

View File

@ -11,7 +11,7 @@ namespace Artemis.Profiles.Lua.Events
public class LuaEventsWrapper public class LuaEventsWrapper
{ {
private readonly Logger _logger = LogManager.GetCurrentClassLogger(); private readonly Logger _logger = LogManager.GetCurrentClassLogger();
private readonly string _invokeLock = string.Empty; public readonly string InvokeLock = string.Empty;
public event EventHandler<LuaProfileUpdatingEventArgs> ProfileUpdating; public event EventHandler<LuaProfileUpdatingEventArgs> ProfileUpdating;
public event EventHandler<LuaProfileDrawingEventArgs> ProfileDrawing; public event EventHandler<LuaProfileDrawingEventArgs> ProfileDrawing;
public event EventHandler<LuaKeyPressEventArgs> KeyboardKeyPressed; public event EventHandler<LuaKeyPressEventArgs> KeyboardKeyPressed;
@ -57,7 +57,7 @@ namespace Artemis.Profiles.Lua.Events
private void LuaInvoke(ProfileModel profileModel, Action action) private void LuaInvoke(ProfileModel profileModel, Action action)
{ {
lock (_invokeLock) lock (InvokeLock)
{ {
try try
{ {

View File

@ -1,4 +1,6 @@
using System.Globalization; using System;
using System.Drawing.Text;
using System.Globalization;
using System.Linq; using System.Linq;
using System.Windows; using System.Windows;
using System.Windows.Media; using System.Windows.Media;
@ -11,10 +13,12 @@ namespace Artemis.Profiles.Lua
public class LuaDrawWrapper public class LuaDrawWrapper
{ {
private readonly DrawingContext _ctx; private readonly DrawingContext _ctx;
private FontFamily _font;
public LuaDrawWrapper(DrawingContext ctx) public LuaDrawWrapper(DrawingContext ctx)
{ {
_ctx = ctx; _ctx = ctx;
_font = new FontFamily(new Uri("pack://application:,,,/"), "./resources/#Silkscreen");
} }
public void DrawEllipse(LuaBrush luaBrush, double x, double y, double height, double width) public void DrawEllipse(LuaBrush luaBrush, double x, double y, double height, double width)
@ -50,17 +54,16 @@ namespace Artemis.Profiles.Lua
_ctx.DrawRectangle(luaBrush.Brush, new Pen(), new Rect(x, y, width, height)); _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) public void DrawText(LuaBrush luaBrush, double x, double y, string text, int fontSize)
{ {
x *= 4; x *= 4;
y *= 4; y *= 4;
fontSize *= 4;
var font = Fonts.SystemTypefaces.FirstOrDefault(f => f.FontFamily.ToString() == fontName); var typeFace = new Typeface(_font, new FontStyle(), new FontWeight(), new FontStretch());
if (font == null) var formatted = new FormattedText(text, CultureInfo.InvariantCulture, FlowDirection.LeftToRight, typeFace,
throw new ScriptRuntimeException($"Font '{fontName}' not found");
var formatted = new FormattedText(text, CultureInfo.InvariantCulture, FlowDirection.LeftToRight, font,
fontSize, luaBrush.Brush); fontSize, luaBrush.Brush);
_ctx.DrawText(formatted, new Point(x, y)); _ctx.DrawText(formatted, new Point(x, y));
} }
} }

View File

@ -38,9 +38,9 @@ namespace Artemis.Profiles.Lua
keyMatch.Value.X, keyMatch.Value.Y); keyMatch.Value.X, keyMatch.Value.Y);
} }
public void SendKeys(string keys) public void PressKeys(string keys)
{ {
System.Windows.Forms.SendKeys.SendWait(keys); SendKeys.SendWait(keys);
} }
} }
} }

View File

@ -1,6 +1,8 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Windows.Media;
using Artemis.Profiles.Layers.Models; using Artemis.Profiles.Layers.Models;
using Artemis.Profiles.Lua.Brushes;
using MoonSharp.Interpreter; using MoonSharp.Interpreter;
namespace Artemis.Profiles.Lua namespace Artemis.Profiles.Lua
@ -107,6 +109,23 @@ namespace Artemis.Profiles.Lua
set { _layerModel.Properties.AnimationProgress = value; } set { _layerModel.Properties.AnimationProgress = value; }
} }
public string BrushType => _layerModel.Properties.Brush?.GetType().Name;
public LuaBrush Brush
{
get
{
if (_layerModel.Properties.Brush is SolidColorBrush)
return new LuaSolidColorBrush((SolidColorBrush) _layerModel.Properties.Brush);
if (_layerModel.Properties.Brush is LinearGradientBrush)
return new LuaLinearGradientBrush((LinearGradientBrush) _layerModel.Properties.Brush);
if (_layerModel.Properties.Brush is RadialGradientBrush)
return new LuaRadialGradientBrush((RadialGradientBrush) _layerModel.Properties.Brush);
return null;
}
set { _layerModel.Properties.Brush = value.Brush; }
}
#endregion #endregion
} }
} }

View File

@ -51,7 +51,10 @@ namespace Artemis.Profiles.Lua
try try
{ {
LuaScript.DoString(ProfileModel.LuaScript); lock (LuaEventsWrapper.InvokeLock)
{
LuaScript.DoString(ProfileModel.LuaScript);
}
} }
catch (InternalErrorException e) catch (InternalErrorException e)
{ {

View File

@ -1,4 +1,5 @@
using System.Reflection; using System.Runtime.CompilerServices;
using System.Reflection;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Windows; using System.Windows;
@ -53,4 +54,7 @@ using System.Windows;
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.4.0.0")] [assembly: AssemblyVersion("1.4.0.0")]
[assembly: AssemblyFileVersion("1.4.0.0")] [assembly: AssemblyFileVersion("1.4.0.0")]
[assembly: InternalsVisibleTo("Artemis.Tests")]
[assembly: InternalsVisibleTo("Artemis.Explorables")]

View File

@ -0,0 +1,25 @@
Thank you for downloading Silkscreen, a type family for your Web graphics
by Jason Kottke (jason@kottke.org).
To install the Silkscreen type family, unzip this file and drag the files
into the Fonts folder in the Control Panel.
If you encounter any problems in using this font, please email me and I'll
see if I can try and fix it. Please note that I can't help you with any
installation issues. Please consult your system's help files for assistance.
This font is free for personal and corporate use and may be redistributed in
this unmodified form on your Web site. I would ask that you not modify and
then redistribute this font...although you may modify it for your own
personal use. If you really like this font and use it often, feel free to
mail me (e- or snail mail) some small token of your appreciation. A URL
of your work using Silkscreen would be appreciated as well.
All future bug fixes, updates, and additions to the Silkscreen type family
will be available on my Web site at the following URL:
http://www.kottke.org/plus/type/silkscreen/index.html
Again, thanks for downloading Silkscreen. Enjoy!
-jason

Binary file not shown.

View File

@ -12,6 +12,7 @@ using Artemis.Modules.Effects.ProfilePreview;
using Artemis.Profiles; using Artemis.Profiles;
using Artemis.Profiles.Layers.Models; using Artemis.Profiles.Layers.Models;
using Artemis.Profiles.Layers.Types.Folder; using Artemis.Profiles.Layers.Types.Folder;
using Artemis.Profiles.Lua;
using Artemis.Properties; using Artemis.Properties;
using Artemis.Utilities; using Artemis.Utilities;
using Caliburn.Micro; using Caliburn.Micro;
@ -114,6 +115,8 @@ namespace Artemis.ViewModels.Profiles
new Point(layerRect.BottomRight.X - 0.7, layerRect.BottomRight.Y - 0.7)); new Point(layerRect.BottomRight.X - 0.7, layerRect.BottomRight.Y - 0.7));
} }
LuaWrapper.LuaEventsWrapper?.InvokeProfileDraw(SelectedProfile, new ProfilePreviewDataModel(), true, drawingContext);
// Remove the clip // Remove the clip
drawingContext.Pop(); drawingContext.Pop();
} }

View File

@ -18,7 +18,7 @@
</Label> </Label>
<TextBlock Grid.Row="1" VerticalAlignment="Center" Margin="0,8" TextWrapping="Wrap" <TextBlock Grid.Row="1" VerticalAlignment="Center" Margin="0,8" TextWrapping="Wrap"
HorizontalAlignment="Left" MaxWidth="520" TextAlignment="Justify"> HorizontalAlignment="Left" MaxWidth="520" TextAlignment="Justify" FontFamily="Te">
Hello, <LineBreak /><LineBreak /> Hello, <LineBreak /><LineBreak />
Thanks a bunch for downloading this application. You're going to enjoy this! :)<LineBreak /> Thanks a bunch for downloading this application. You're going to enjoy this! :)<LineBreak />
<LineBreak /> <LineBreak />