mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
More core rendering
This commit is contained in:
parent
9a2ea0c2b3
commit
31e9eb511b
@ -1,10 +1,14 @@
|
|||||||
using System;
|
using System;
|
||||||
using Artemis.Core.Plugins.Interfaces;
|
using Artemis.Core.Plugins.Interfaces;
|
||||||
|
using Artemis.Core.ProfileElements;
|
||||||
|
using RGB.NET.Core;
|
||||||
|
|
||||||
namespace Artemis.Core.Plugins.Abstract
|
namespace Artemis.Core.Plugins.Abstract
|
||||||
{
|
{
|
||||||
public abstract class ProfileModule : IModule
|
public abstract class ProfileModule : IModule
|
||||||
{
|
{
|
||||||
|
public Profile ActiveProfile { get; private set; }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public abstract Type ViewModelType { get; }
|
public abstract Type ViewModelType { get; }
|
||||||
|
|
||||||
@ -17,16 +21,38 @@ namespace Artemis.Core.Plugins.Abstract
|
|||||||
// Load and activate the last active profile
|
// Load and activate the last active profile
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
public void ChangeActiveProfile(Profile profile)
|
||||||
public virtual void Update(double deltaTime)
|
|
||||||
{
|
{
|
||||||
// Update the profile
|
lock (this)
|
||||||
|
{
|
||||||
|
if (profile == null)
|
||||||
|
throw new ArgumentNullException(nameof(profile));
|
||||||
|
|
||||||
|
ActiveProfile?.Deactivate();
|
||||||
|
|
||||||
|
ActiveProfile = profile;
|
||||||
|
ActiveProfile.Activate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public virtual void Render(double deltaTime)
|
public virtual void Update(double deltaTime)
|
||||||
|
{
|
||||||
|
lock (this)
|
||||||
|
{
|
||||||
|
// Update the profile
|
||||||
|
ActiveProfile?.Update(deltaTime);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public virtual void Render(double deltaTime, RGBSurface surface)
|
||||||
|
{
|
||||||
|
lock (this)
|
||||||
{
|
{
|
||||||
// Render the profile
|
// Render the profile
|
||||||
|
ActiveProfile?.Render(deltaTime, surface);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@ -18,8 +18,6 @@ namespace Artemis.Core.Plugins.Interfaces
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Renders the layer type
|
/// Renders the layer type
|
||||||
/// </summary>
|
/// </summary>
|
||||||
void Render(Layer device, IRGBDevice rgbDevice);
|
void Render(Layer device, RGBSurface surface);
|
||||||
|
|
||||||
ILayerType ApplyToLayer(Layer layer);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using RGB.NET.Core;
|
||||||
|
|
||||||
namespace Artemis.Core.Plugins.Interfaces
|
namespace Artemis.Core.Plugins.Interfaces
|
||||||
{
|
{
|
||||||
@ -29,6 +30,7 @@ namespace Artemis.Core.Plugins.Interfaces
|
|||||||
/// Called each frame when the module must render
|
/// Called each frame when the module must render
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="deltaTime">Time since the last render</param>
|
/// <param name="deltaTime">Time since the last render</param>
|
||||||
void Render(double deltaTime);
|
/// <param name="surface">The RGB Surface to render to</param>
|
||||||
|
void Render(double deltaTime, RGBSurface surface);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -123,5 +123,10 @@ namespace Artemis.Core.Plugins.Models
|
|||||||
vm.PluginInfo = this;
|
vm.PluginInfo = this;
|
||||||
return vm;
|
return vm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return $"{nameof(Guid)}: {Guid}, {nameof(Name)}: {Name}, {nameof(Version)}: {Version}";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -8,32 +8,34 @@ namespace Artemis.Core.ProfileElements
|
|||||||
{
|
{
|
||||||
public class Folder : IProfileElement
|
public class Folder : IProfileElement
|
||||||
{
|
{
|
||||||
public Folder()
|
public Folder(Profile profile)
|
||||||
{
|
{
|
||||||
|
Profile = profile;
|
||||||
Children = new List<IProfileElement>();
|
Children = new List<IProfileElement>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Profile Profile { get; }
|
||||||
public List<IProfileElement> Children { get; set; }
|
public List<IProfileElement> Children { get; set; }
|
||||||
public int Order { get; set; }
|
public int Order { get; set; }
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
public void Update()
|
public void Update(double deltaTime)
|
||||||
{
|
{
|
||||||
// Folders don't update but their children do
|
// Folders don't update but their children do
|
||||||
foreach (var profileElement in Children)
|
foreach (var profileElement in Children)
|
||||||
profileElement.Update();
|
profileElement.Update(deltaTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Render(IRGBDevice rgbDevice)
|
public void Render(double deltaTime, RGBSurface surface)
|
||||||
{
|
{
|
||||||
// Folders don't render but their children do
|
// Folders don't render but their children do
|
||||||
foreach (var profileElement in Children)
|
foreach (var profileElement in Children)
|
||||||
profileElement.Render(rgbDevice);
|
profileElement.Render(deltaTime, surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Folder FromFolderEntity(FolderEntity folderEntity, IPluginService pluginService)
|
public static Folder FromFolderEntity(Profile profile, FolderEntity folderEntity, IPluginService pluginService)
|
||||||
{
|
{
|
||||||
var folder = new Folder
|
var folder = new Folder(profile)
|
||||||
{
|
{
|
||||||
Name = folderEntity.Name,
|
Name = folderEntity.Name,
|
||||||
Order = folderEntity.Order
|
Order = folderEntity.Order
|
||||||
@ -41,12 +43,17 @@ namespace Artemis.Core.ProfileElements
|
|||||||
|
|
||||||
// Load child folders
|
// Load child folders
|
||||||
foreach (var childFolder in folderEntity.Folders)
|
foreach (var childFolder in folderEntity.Folders)
|
||||||
folder.Children.Add(FromFolderEntity(childFolder, pluginService));
|
folder.Children.Add(FromFolderEntity(profile, childFolder, pluginService));
|
||||||
// Load child layers
|
// Load child layers
|
||||||
foreach (var childLayer in folderEntity.Layers)
|
foreach (var childLayer in folderEntity.Layers)
|
||||||
folder.Children.Add(Layer.FromLayerEntity(childLayer, pluginService));
|
folder.Children.Add(Layer.FromLayerEntity(profile, childLayer, pluginService));
|
||||||
|
|
||||||
return folder;
|
return folder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return $"{nameof(Profile)}: {Profile}, {nameof(Order)}: {Order}, {nameof(Name)}: {Name}";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -23,11 +23,12 @@ namespace Artemis.Core.ProfileElements.Interfaces
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Updates the element
|
/// Updates the element
|
||||||
/// </summary>
|
/// </summary>
|
||||||
void Update();
|
/// <param name="deltaTime"></param>
|
||||||
|
void Update(double deltaTime);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Renders the element
|
/// Renders the element
|
||||||
/// </summary>
|
/// </summary>
|
||||||
void Render(IRGBDevice rgbDevice);
|
void Render(double deltaTime, RGBSurface surface);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -10,18 +10,19 @@ namespace Artemis.Core.ProfileElements
|
|||||||
{
|
{
|
||||||
public class Layer : IProfileElement
|
public class Layer : IProfileElement
|
||||||
{
|
{
|
||||||
public Layer()
|
public Layer(Profile profile)
|
||||||
{
|
{
|
||||||
|
Profile = profile;
|
||||||
Children = new List<IProfileElement>();
|
Children = new List<IProfileElement>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Profile Profile { get; }
|
||||||
public ILayerType LayerType { get; private set; }
|
public ILayerType LayerType { get; private set; }
|
||||||
|
|
||||||
public List<IProfileElement> Children { get; set; }
|
public List<IProfileElement> Children { get; set; }
|
||||||
public int Order { get; set; }
|
public int Order { get; set; }
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
public void Update()
|
public void Update(double deltaTime)
|
||||||
{
|
{
|
||||||
if (LayerType == null)
|
if (LayerType == null)
|
||||||
return;
|
return;
|
||||||
@ -32,20 +33,20 @@ namespace Artemis.Core.ProfileElements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Render(IRGBDevice rgbDevice)
|
public void Render(double deltaTime, RGBSurface surface)
|
||||||
{
|
{
|
||||||
if (LayerType == null)
|
if (LayerType == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
lock (LayerType)
|
lock (LayerType)
|
||||||
{
|
{
|
||||||
LayerType.Render(this, rgbDevice);
|
LayerType.Render(this, surface);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Layer FromLayerEntity(LayerEntity layerEntity, IPluginService pluginService)
|
public static Layer FromLayerEntity(Profile profile, LayerEntity layerEntity, IPluginService pluginService)
|
||||||
{
|
{
|
||||||
var layer = new Layer
|
var layer = new Layer(profile)
|
||||||
{
|
{
|
||||||
Name = layerEntity.Name,
|
Name = layerEntity.Name,
|
||||||
Order = layerEntity.Order,
|
Order = layerEntity.Order,
|
||||||
@ -58,14 +59,17 @@ namespace Artemis.Core.ProfileElements
|
|||||||
public void UpdateLayerType(ILayerType layerType)
|
public void UpdateLayerType(ILayerType layerType)
|
||||||
{
|
{
|
||||||
if (LayerType != null)
|
if (LayerType != null)
|
||||||
{
|
|
||||||
lock (LayerType)
|
lock (LayerType)
|
||||||
{
|
{
|
||||||
LayerType.Dispose();
|
LayerType.Dispose();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
LayerType = layerType;
|
LayerType = layerType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return $"{nameof(Profile)}: {Profile}, {nameof(Order)}: {Order}, {nameof(Name)}: {Name}";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,4 +1,6 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Artemis.Core.Exceptions;
|
||||||
using Artemis.Core.Plugins.Models;
|
using Artemis.Core.Plugins.Models;
|
||||||
using Artemis.Core.ProfileElements.Interfaces;
|
using Artemis.Core.ProfileElements.Interfaces;
|
||||||
using Artemis.Core.Services.Interfaces;
|
using Artemis.Core.Services.Interfaces;
|
||||||
@ -14,31 +16,97 @@ namespace Artemis.Core.ProfileElements
|
|||||||
PluginInfo = pluginInfo;
|
PluginInfo = pluginInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PluginInfo PluginInfo { get; }
|
||||||
|
public bool IsActivated { get; private set; }
|
||||||
public int Order { get; set; }
|
public int Order { get; set; }
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public PluginInfo PluginInfo { get; }
|
|
||||||
public List<IProfileElement> Children { get; set; }
|
public List<IProfileElement> Children { get; set; }
|
||||||
|
|
||||||
public void Update()
|
public void Update(double deltaTime)
|
||||||
{
|
{
|
||||||
|
lock (this)
|
||||||
|
{
|
||||||
|
if (!IsActivated)
|
||||||
|
throw new ArtemisCoreException($"Cannot update inactive profile: {this}");
|
||||||
|
|
||||||
foreach (var profileElement in Children)
|
foreach (var profileElement in Children)
|
||||||
profileElement.Update();
|
profileElement.Update(deltaTime);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Render(IRGBDevice rgbDevice)
|
public void Render(double deltaTime, RGBSurface surface)
|
||||||
{
|
{
|
||||||
|
lock (this)
|
||||||
|
{
|
||||||
|
if (!IsActivated)
|
||||||
|
throw new ArtemisCoreException($"Cannot render inactive profile: {this}");
|
||||||
|
|
||||||
foreach (var profileElement in Children)
|
foreach (var profileElement in Children)
|
||||||
profileElement.Render(rgbDevice);
|
profileElement.Render(deltaTime, surface);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Profile FromProfileEntity(PluginInfo pluginInfo, ProfileEntity profileEntity, IPluginService pluginService)
|
public static Profile FromProfileEntity(PluginInfo pluginInfo, ProfileEntity profileEntity, IPluginService pluginService)
|
||||||
{
|
{
|
||||||
var profile = new Profile(pluginInfo) {Name = profileEntity.Name};
|
var profile = new Profile(pluginInfo) {Name = profileEntity.Name};
|
||||||
|
lock (profile)
|
||||||
|
{
|
||||||
// Populate the profile starting at the root, the rest is populated recursively
|
// Populate the profile starting at the root, the rest is populated recursively
|
||||||
profile.Children.Add(Folder.FromFolderEntity(profileEntity.RootFolder, pluginService));
|
profile.Children.Add(Folder.FromFolderEntity(profile, profileEntity.RootFolder, pluginService));
|
||||||
|
|
||||||
return profile;
|
return profile;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Activate()
|
||||||
|
{
|
||||||
|
lock (this)
|
||||||
|
{
|
||||||
|
if (IsActivated) return;
|
||||||
|
|
||||||
|
OnActivated();
|
||||||
|
IsActivated = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Deactivate()
|
||||||
|
{
|
||||||
|
lock (this)
|
||||||
|
{
|
||||||
|
if (!IsActivated) return;
|
||||||
|
|
||||||
|
IsActivated = false;
|
||||||
|
OnDeactivated();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return $"{nameof(Order)}: {Order}, {nameof(Name)}: {Name}, {nameof(PluginInfo)}: {PluginInfo}";
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Events
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Occurs when the profile is being activated.
|
||||||
|
/// </summary>
|
||||||
|
public event EventHandler Activated;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Occurs when the profile is being deactivated.
|
||||||
|
/// </summary>
|
||||||
|
public event EventHandler Deactivated;
|
||||||
|
|
||||||
|
private void OnActivated()
|
||||||
|
{
|
||||||
|
Activated?.Invoke(this, EventArgs.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnDeactivated()
|
||||||
|
{
|
||||||
|
Deactivated?.Invoke(this, EventArgs.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -51,7 +51,7 @@ namespace Artemis.Core.Services
|
|||||||
module.Update(args.DeltaTime);
|
module.Update(args.DeltaTime);
|
||||||
// Render all active modules
|
// Render all active modules
|
||||||
foreach (var module in _pluginService.Plugins.OfType<IModule>())
|
foreach (var module in _pluginService.Plugins.OfType<IModule>())
|
||||||
module.Render(args.DeltaTime);
|
module.Render(args.DeltaTime, _rgbService.Surface);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user