More core rendering

This commit is contained in:
SpoinkyNL committed 2018-04-07 14:24:49 +02:00
1 parent c22a78cd30
commit 36d1a88c4e
9 files changed
+155 -44

No files matched your search

+17 -10
View File
@@ -8,45 +8,52 @@ namespace Artemis.Core.ProfileElements
{
public class Folder : IProfileElement
{
public Folder()
public Folder(Profile profile)
{
Profile = profile;
Children = new List<IProfileElement>();
}
public Profile Profile { get; }
public List<IProfileElement> Children { get; set; }
public int Order { get; set; }
public string Name { get; set; }
public void Update()
public void Update(double deltaTime)
{
// Folders don't update but their children do
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
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,
Order = folderEntity.Order
};
// Load child folders
foreach (var childFolder in folderEntity.Folders)
folder.Children.Add(FromFolderEntity(childFolder, pluginService));
folder.Children.Add(FromFolderEntity(profile, childFolder, pluginService));
// Load child layers
foreach (var childLayer in folderEntity.Layers)
folder.Children.Add(Layer.FromLayerEntity(childLayer, pluginService));
folder.Children.Add(Layer.FromLayerEntity(profile, childLayer, pluginService));
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>
/// Updates the element
/// </summary>
void Update();
/// <param name="deltaTime"></param>
void Update(double deltaTime);
/// <summary>
/// Renders the element
/// </summary>
void Render(IRGBDevice rgbDevice);
void Render(double deltaTime, RGBSurface surface);
}
}
+14 -10
View File
@@ -10,18 +10,19 @@ namespace Artemis.Core.ProfileElements
{
public class Layer : IProfileElement
{
public Layer()
public Layer(Profile profile)
{
Profile = profile;
Children = new List<IProfileElement>();
}
public Profile Profile { get; }
public ILayerType LayerType { get; private set; }
public List<IProfileElement> Children { get; set; }
public int Order { get; set; }
public string Name { get; set; }
public void Update()
public void Update(double deltaTime)
{
if (LayerType == null)
return;
@@ -32,40 +33,43 @@ namespace Artemis.Core.ProfileElements
}
}
public void Render(IRGBDevice rgbDevice)
public void Render(double deltaTime, RGBSurface surface)
{
if (LayerType == null)
return;
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,
Order = layerEntity.Order,
LayerType = pluginService.GetLayerTypeByGuid(Guid.Parse(layerEntity.Guid))
};
return layer;
}
public void UpdateLayerType(ILayerType layerType)
{
if (LayerType != null)
{
lock (LayerType)
{
LayerType.Dispose();
}
}
LayerType = layerType;
}
public override string ToString()
{
return $"{nameof(Profile)}: {Profile}, {nameof(Order)}: {Order}, {nameof(Name)}: {Name}";
}
}
}
+80 -12
View File
@@ -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.ProfileElements.Interfaces;
using Artemis.Core.Services.Interfaces;
@@ -14,31 +16,97 @@ namespace Artemis.Core.ProfileElements
PluginInfo = pluginInfo;
}
public PluginInfo PluginInfo { get; }
public bool IsActivated { get; private set; }
public int Order { get; set; }
public string Name { get; set; }
public PluginInfo PluginInfo { get; }
public List<IProfileElement> Children { get; set; }
public void Update()
public void Update(double deltaTime)
{
foreach (var profileElement in Children)
profileElement.Update();
lock (this)
{
if (!IsActivated)
throw new ArtemisCoreException($"Cannot update inactive profile: {this}");
foreach (var profileElement in Children)
profileElement.Update(deltaTime);
}
}
public void Render(IRGBDevice rgbDevice)
public void Render(double deltaTime, RGBSurface surface)
{
foreach (var profileElement in Children)
profileElement.Render(rgbDevice);
lock (this)
{
if (!IsActivated)
throw new ArtemisCoreException($"Cannot render inactive profile: {this}");
foreach (var profileElement in Children)
profileElement.Render(deltaTime, surface);
}
}
public static Profile FromProfileEntity(PluginInfo pluginInfo, ProfileEntity profileEntity, IPluginService pluginService)
{
var profile = new Profile(pluginInfo) {Name = profileEntity.Name};
lock (profile)
{
// Populate the profile starting at the root, the rest is populated recursively
profile.Children.Add(Folder.FromFolderEntity(profile, profileEntity.RootFolder, pluginService));
// Populate the profile starting at the root, the rest is populated recursively
profile.Children.Add(Folder.FromFolderEntity(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
}
}