mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Working on render logic
This commit is contained in:
parent
7cd8bc246c
commit
49e6dbf09b
@ -14,16 +14,24 @@ namespace Artemis.Core.RGB.NET
|
|||||||
|
|
||||||
public GraphicsDecorator(ListLedGroup ledGroup)
|
public GraphicsDecorator(ListLedGroup ledGroup)
|
||||||
{
|
{
|
||||||
var width = ledGroup.GetLeds().Max(l => l.AbsoluteLedRectangle.X + l.AbsoluteLedRectangle.Width);
|
var leds = ledGroup.GetLeds().ToList();
|
||||||
var height = ledGroup.GetLeds().Max(l => l.AbsoluteLedRectangle.Y + l.AbsoluteLedRectangle.Height);
|
if (!leds.Any())
|
||||||
|
{
|
||||||
|
_bitmap = null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var width = leds.Max(l => l.AbsoluteLedRectangle.X + l.AbsoluteLedRectangle.Width);
|
||||||
|
var height = leds.Max(l => l.AbsoluteLedRectangle.Y + l.AbsoluteLedRectangle.Height);
|
||||||
|
|
||||||
_bitmap = new DirectBitmap((int) width, (int) height);
|
_bitmap = new DirectBitmap((int) width, (int) height);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Color ManipulateColor(Rectangle rectangle, BrushRenderTarget renderTarget, Color color)
|
public Color ManipulateColor(Rectangle rectangle, BrushRenderTarget renderTarget, Color color)
|
||||||
{
|
{
|
||||||
var point = renderTarget.Point;
|
var point = renderTarget.Led.AbsoluteLedRectangle.Center;
|
||||||
if (_bitmap.Width - 1 >= point.X && _bitmap.Height - 1 >= point.Y)
|
if (_bitmap != null && _bitmap.Width - 1 >= point.X && _bitmap.Height - 1 >= point.Y)
|
||||||
{
|
{
|
||||||
var pixel = _bitmap.GetPixel((int) point.X, (int) point.Y);
|
var pixel = _bitmap.GetPixel((int) point.X, (int) point.Y);
|
||||||
return new Color(pixel.A, pixel.R, pixel.G, pixel.B);
|
return new Color(pixel.A, pixel.R, pixel.G, pixel.B);
|
||||||
@ -34,7 +42,7 @@ namespace Artemis.Core.RGB.NET
|
|||||||
|
|
||||||
public Graphics GetGraphics()
|
public Graphics GetGraphics()
|
||||||
{
|
{
|
||||||
return Graphics.FromImage(_bitmap.Bitmap);
|
return _bitmap == null ? null : Graphics.FromImage(_bitmap.Bitmap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -64,12 +64,17 @@ namespace Artemis.Core.Services
|
|||||||
foreach (var module in modules)
|
foreach (var module in modules)
|
||||||
module.Update(args.DeltaTime);
|
module.Update(args.DeltaTime);
|
||||||
|
|
||||||
|
// If there is no graphics decorator, skip the frame
|
||||||
if (_rgbService.GraphicsDecorator == null)
|
if (_rgbService.GraphicsDecorator == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Render all active modules
|
// Render all active modules
|
||||||
using (var g = _rgbService.GraphicsDecorator.GetGraphics())
|
using (var g = _rgbService.GraphicsDecorator.GetGraphics())
|
||||||
{
|
{
|
||||||
|
// If there are no graphics, skip the frame
|
||||||
|
if (g == null)
|
||||||
|
return;
|
||||||
|
|
||||||
g.Clear(Color.Black);
|
g.Clear(Color.Black);
|
||||||
foreach (var module in modules)
|
foreach (var module in modules)
|
||||||
module.Render(args.DeltaTime, _rgbService.Surface, g);
|
module.Render(args.DeltaTime, _rgbService.Surface, g);
|
||||||
|
|||||||
@ -25,5 +25,7 @@ namespace Artemis.Core.Services.Interfaces
|
|||||||
/// Occurs when a single device has reloaded
|
/// Occurs when a single device has reloaded
|
||||||
/// </summary>
|
/// </summary>
|
||||||
event EventHandler<DeviceEventArgs> DeviceReloaded;
|
event EventHandler<DeviceEventArgs> DeviceReloaded;
|
||||||
|
|
||||||
|
void UpdateGraphicsDecorator();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -19,6 +19,7 @@ namespace Artemis.Core.Services
|
|||||||
private readonly List<IRGBDevice> _loadedDevices;
|
private readonly List<IRGBDevice> _loadedDevices;
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly TimerUpdateTrigger _updateTrigger;
|
private readonly TimerUpdateTrigger _updateTrigger;
|
||||||
|
private ListLedGroup _background;
|
||||||
|
|
||||||
internal RgbService(ILogger logger)
|
internal RgbService(ILogger logger)
|
||||||
{
|
{
|
||||||
@ -74,11 +75,6 @@ namespace Artemis.Core.Services
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply the application wide brush and decorator
|
|
||||||
var background = new ListLedGroup(Surface.Leds) {Brush = new SolidColorBrush(new Color(255, 255, 255, 255))};
|
|
||||||
GraphicsDecorator = new GraphicsDecorator(background);
|
|
||||||
background.Brush.AddDecorator(GraphicsDecorator);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
@ -99,6 +95,23 @@ namespace Artemis.Core.Services
|
|||||||
public event EventHandler<DeviceEventArgs> DeviceLoaded;
|
public event EventHandler<DeviceEventArgs> DeviceLoaded;
|
||||||
public event EventHandler<DeviceEventArgs> DeviceReloaded;
|
public event EventHandler<DeviceEventArgs> DeviceReloaded;
|
||||||
|
|
||||||
|
public void UpdateGraphicsDecorator()
|
||||||
|
{
|
||||||
|
// Clean up the old background if present
|
||||||
|
if (_background != null)
|
||||||
|
{
|
||||||
|
_background.RemoveAllDecorators();
|
||||||
|
_background.Detach();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply the application wide brush and decorator
|
||||||
|
_background = new ListLedGroup(Surface.Leds) {Brush = new SolidColorBrush(new Color(255, 255, 255, 255))};
|
||||||
|
GraphicsDecorator = new GraphicsDecorator(_background);
|
||||||
|
_background.Brush.RemoveAllDecorators();
|
||||||
|
|
||||||
|
_background.Brush.AddDecorator(GraphicsDecorator);
|
||||||
|
}
|
||||||
|
|
||||||
private void OnDeviceLoaded(DeviceEventArgs e)
|
private void OnDeviceLoaded(DeviceEventArgs e)
|
||||||
{
|
{
|
||||||
DeviceLoaded?.Invoke(this, e);
|
DeviceLoaded?.Invoke(this, e);
|
||||||
|
|||||||
@ -58,7 +58,7 @@ namespace Artemis.Core.Services.Storage
|
|||||||
deviceConfiguration.ApplyToDevice();
|
deviceConfiguration.ApplyToDevice();
|
||||||
}
|
}
|
||||||
// Update the RGB service's graphics decorator to work with the new surface configuration
|
// Update the RGB service's graphics decorator to work with the new surface configuration
|
||||||
_rgbService.GraphicsDecorator.UpdateBitmap();
|
_rgbService.UpdateGraphicsDecorator();
|
||||||
|
|
||||||
OnActiveSurfaceConfigurationChanged(new SurfaceConfigurationEventArgs(_activeSurfaceConfiguration));
|
OnActiveSurfaceConfigurationChanged(new SurfaceConfigurationEventArgs(_activeSurfaceConfiguration));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -63,8 +63,8 @@ namespace Artemis.UI.ViewModels.Controls.SurfaceEditor
|
|||||||
{
|
{
|
||||||
var roundedX = Math.Round((mousePosition.X + _dragOffsetX) / 10, 0, MidpointRounding.AwayFromZero) * 10;
|
var roundedX = Math.Round((mousePosition.X + _dragOffsetX) / 10, 0, MidpointRounding.AwayFromZero) * 10;
|
||||||
var roundedY = Math.Round((mousePosition.Y + _dragOffsetY) / 10, 0, MidpointRounding.AwayFromZero) * 10;
|
var roundedY = Math.Round((mousePosition.Y + _dragOffsetY) / 10, 0, MidpointRounding.AwayFromZero) * 10;
|
||||||
X = roundedX;
|
X = Math.Max(0, roundedX);
|
||||||
Y = roundedY;
|
Y = Math.Max(0, roundedY);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReSharper disable once UnusedMember.Global - Called from view
|
// ReSharper disable once UnusedMember.Global - Called from view
|
||||||
|
|||||||
@ -42,8 +42,8 @@ namespace Artemis.UI.ViewModels
|
|||||||
Zoom = Math.Max(0.1, Math.Min(4, Zoom));
|
Zoom = Math.Max(0.1, Math.Min(4, Zoom));
|
||||||
|
|
||||||
// Update the PanX/Y to enable zooming relative to cursor
|
// Update the PanX/Y to enable zooming relative to cursor
|
||||||
PanX = absoluteX - relative.X * Zoom;
|
PanX = Math.Min(0, absoluteX - relative.X * Zoom);
|
||||||
PanY = absoluteY - relative.Y * Zoom;
|
PanY = Math.Min(0, absoluteY - relative.Y * Zoom);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ProcessMouseMove(object sender, MouseEventArgs e)
|
public void ProcessMouseMove(object sender, MouseEventArgs e)
|
||||||
@ -60,8 +60,9 @@ namespace Artemis.UI.ViewModels
|
|||||||
|
|
||||||
var position = e.GetPosition((IInputElement) sender);
|
var position = e.GetPosition((IInputElement) sender);
|
||||||
var delta = _lastPanPosition - position;
|
var delta = _lastPanPosition - position;
|
||||||
PanX -= delta.Value.X;
|
|
||||||
PanY -= delta.Value.Y;
|
PanX = Math.Min(0, PanX - delta.Value.X);
|
||||||
|
PanY = Math.Min(0, PanY - delta.Value.Y);
|
||||||
|
|
||||||
_lastPanPosition = position;
|
_lastPanPosition = position;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -105,6 +105,8 @@ namespace Artemis.UI.ViewModels.Screens
|
|||||||
Devices.Add(viewModel);
|
Devices.Add(viewModel);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
_surfaceService.ActiveSurfaceConfiguration = SelectedSurfaceConfiguration;
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Overrides of Screen
|
#region Overrides of Screen
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user