Compare commits

...

3 Commits

7 changed files with 111 additions and 12 deletions

@ -0,0 +1,26 @@
using BlurgText;
using Dashboard.CommandMachine;
namespace Dashboard.BlurgText
{
public static class BlurgCommand
{
public static void PutBlurgText(this CommandList list, DashboardBlurg blurg, BlurgResult result, QVec2 origin)
{
for (int i = 0; i < result.Count; i++)
{
BlurgRect rect = result[i];
QRectangle pos = new QRectangle()
{
Min = origin + new QVec2(rect.X, rect.Y),
Size = new QVec2(rect.Width, rect.Height)
};
QRectangle uv = new QRectangle(rect.U1, rect.V1, rect.U0, rect.V0);
list.Image(blurg.Images[(int)rect.UserData], pos, uv);
}
}
}
}

@ -7,6 +7,7 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Dashboard\Dashboard.csproj" />
<PackageReference Include="BlurgText" Version="0.1.0-nightly-4" />
</ItemGroup>

@ -0,0 +1,63 @@
using BlurgText;
using Dashboard.Media;
using Dashboard.Media.Color;
namespace Dashboard.BlurgText
{
public class DashboardBlurg : IDisposable
{
private readonly List<QImageBuffer> images = new List<QImageBuffer>();
public Blurg Blurg { get; }
public IReadOnlyList<QImageBuffer> Images => images.AsReadOnly();
public DashboardBlurg()
{
Blurg = new Blurg(TextureAllocationCallback, TextureUpdateCallback);
}
private nint TextureAllocationCallback(int width, int height)
{
QImageBuffer image = new QImageBuffer(QImageFormat.RgbaU8, width, height);
images.Add(image);
return images.Count - 1;
}
private void TextureUpdateCallback(nint userData, nint buffer, int x, int y, int width, int height)
{
if (width == 0 || height == 0)
return;
QImageLock src = new QImageLock(QImageFormat.RgbaU8, width, height, 1, buffer);
QImageBuffer image = images[(int)userData];
image.LockBits2d(out QImageLock dest, QImageLockOptions.Default);
src.CopyTo(dest, x, y);
image.UnlockBits();
}
private bool _isDisposed = false;
private void Dispose(bool disposing)
{
if (_isDisposed) return;
if (disposing)
{
Blurg.Dispose();
foreach (QImageBuffer image in images)
{
image.Dispose();
}
images.Clear();
}
_isDisposed = true;
}
public void Dispose() => Dispose(true);
}
}

@ -22,7 +22,7 @@ namespace Dashboard.Media.Color
Height = height;
Depth = depth;
buffer = new byte[width * height * depth];
buffer = new byte[(long)width * height * depth * format.BytesPerPixel()];
}
~QImageBuffer()
{

@ -65,8 +65,8 @@ namespace Dashboard.Media
public unsafe void CopyTo(QImageLock destination, int x, int y)
{
if (
Width + x > destination.Width ||
Height + y > destination.Height)
Width + x >= destination.Width ||
Height + y >= destination.Height)
{
throw new Exception("Image falls outside the bounds of the destination.");
}

@ -4,11 +4,12 @@
<ProjectReference Include="..\..\Dashboard\Dashboard.csproj" />
<ProjectReference Include="..\..\Dashboard.Media.Defaults\Dashboard.Media.Defaults.csproj" />
<ProjectReference Include="..\..\Dashboard.OpenTK\Dashboard.OpenTK.csproj" />
<ProjectReference Include="..\..\Dashboard.BlurgText\Dashboard.BlurgText.csproj" />
</ItemGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

@ -5,6 +5,8 @@ using Dashboard.OpenTK;
using Dashboard.Media.Defaults;
using Dashboard.Media;
using Dashboard.PAL;
using Dashboard.BlurgText;
using BlurgText;
namespace Dashboard.Demo
{
@ -21,24 +23,30 @@ namespace Dashboard.Demo
public class EmptyView : View
{
private QFont? font;
private readonly Label Label = new Label() { Text = "Hello world!", Position = new QVec2(300, 300) };
DashboardBlurg dblurg = new DashboardBlurg();
BlurgResult? result;
// private readonly Label Label = new Label() { Text = "Hello world!", Position = new QVec2(300, 300) };
protected override void PaintBegin(CommandList cmd)
{
base.PaintBegin(cmd);
if (font == null)
if (result == null)
{
IFontDataBase db = FontDataBaseProvider.Instance;
font = new QFontFreeType(db.FontFileInfo(db.Sans).OpenRead());
// IFontDataBase db = FontDataBaseProvider.Instance;
// font = new QFontFreeType(db.FontFileInfo(db.Sans).OpenRead());
Label.Font = font;
Label.TextSize = 12;
Label.InvalidateVisual();
// Label.Font = font;
// Label.TextSize = 12;
// Label.InvalidateVisual();
var font = dblurg.Blurg.AddFontFile("/usr/share/fonts/google-noto/NotoSans-Regular.ttf");
result = dblurg.Blurg.BuildString(font!, 12, BlurgColor.White, "Hello World");
}
cmd.PutBlurgText(dblurg, result!, new QVec2(300, 300));
cmd.Rectangle(new QRectangle(16, 16, 0, 0));
Label.Paint(cmd);
// Label.Paint(cmd);
}
}
}