implemented use of rectangle renderer.
This commit is contained in:
parent
07e172d913
commit
b3685cd80c
@ -1,5 +1,7 @@
|
|||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using RecrownedAthenaeum.Camera;
|
||||||
|
using RecrownedAthenaeum.Render;
|
||||||
using RecrownedAthenaeum.UI.Modular;
|
using RecrownedAthenaeum.UI.Modular;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -11,8 +13,7 @@ namespace RecrownedAthenaeum.Audio.Visualizer
|
|||||||
{
|
{
|
||||||
internal class HorizontalVisualizer : UIModule, IDisposable
|
internal class HorizontalVisualizer : UIModule, IDisposable
|
||||||
{
|
{
|
||||||
GraphicsDevice graphicsDevice;
|
private RectangleRenderer renderer;
|
||||||
Texture2D barTexture;
|
|
||||||
private const int BAR_COUNT = 70;
|
private const int BAR_COUNT = 70;
|
||||||
private const int SMOOTH_RANGE = 3;
|
private const int SMOOTH_RANGE = 3;
|
||||||
private readonly int binsPerBar;
|
private readonly int binsPerBar;
|
||||||
@ -21,18 +22,17 @@ namespace RecrownedAthenaeum.Audio.Visualizer
|
|||||||
private TransparentSampleProvider tsp;
|
private TransparentSampleProvider tsp;
|
||||||
private int[] barValue;
|
private int[] barValue;
|
||||||
|
|
||||||
internal HorizontalVisualizer(TransparentSampleProvider transparentSampleProvider, GraphicsDevice graphicsDevice)
|
internal HorizontalVisualizer(TransparentSampleProvider transparentSampleProvider, GraphicsDevice graphicsDevice, Camera2D camera2D)
|
||||||
{
|
{
|
||||||
this.graphicsDevice = graphicsDevice;
|
|
||||||
tsp = transparentSampleProvider;
|
tsp = transparentSampleProvider;
|
||||||
bar.Width = (int)(graphicsDevice.Viewport.Width / 70f);
|
bar.Width = (int)(graphicsDevice.Viewport.Width / 70f);
|
||||||
spaceBetweenBars = (int)(0.25f * bar.Width);
|
spaceBetweenBars = (int)(0.25f * bar.Width);
|
||||||
bar.Width -= spaceBetweenBars;
|
bar.Width -= spaceBetweenBars;
|
||||||
|
|
||||||
barTexture = new Texture2D(graphicsDevice, 1, 1);
|
|
||||||
barTexture.SetData(new[] { Color.White });
|
|
||||||
binsPerBar = tsp.GetCurrentSpectrum().Length / BAR_COUNT;
|
binsPerBar = tsp.GetCurrentSpectrum().Length / BAR_COUNT;
|
||||||
barValue = new int[BAR_COUNT];
|
barValue = new int[BAR_COUNT];
|
||||||
|
|
||||||
|
renderer = new RectangleRenderer(graphicsDevice, camera2D);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Update(GameTime gameTime)
|
public override void Update(GameTime gameTime)
|
||||||
@ -49,11 +49,12 @@ namespace RecrownedAthenaeum.Audio.Visualizer
|
|||||||
bar.X = (i * (bar.Width + spaceBetweenBars)) + bounds.X;
|
bar.X = (i * (bar.Width + spaceBetweenBars)) + bounds.X;
|
||||||
bar.Y = bounds.Y;
|
bar.Y = bounds.Y;
|
||||||
|
|
||||||
|
renderer.Begin(true);
|
||||||
bar.Height = barValue[i];
|
bar.Height = barValue[i];
|
||||||
batch.Draw(barTexture, bar, color);
|
renderer.DrawRectangle(bar.X, bar.Y, bar.Width, bar.Height, color);
|
||||||
|
|
||||||
bar.Height = -barValue[BAR_COUNT - i - 1];
|
bar.Height = -barValue[BAR_COUNT - i - 1];
|
||||||
batch.Draw(barTexture, bar, color);
|
renderer.DrawRectangle(bar.X, bar.Y, bar.Width, bar.Height, color);
|
||||||
}
|
}
|
||||||
base.Draw(batch);
|
base.Draw(batch);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user