servicepoint/crates/servicepoint_binding_cs/ServicePoint/Command.cs

130 lines
3.3 KiB
C#
Raw Normal View History

2024-05-13 00:17:40 +02:00
using System.Diagnostics.CodeAnalysis;
using ServicePoint.BindGen;
2024-05-13 00:17:40 +02:00
namespace ServicePoint;
2024-05-13 00:17:40 +02:00
2024-10-16 21:59:35 +02:00
public sealed class Command : SpNativeInstance<SPCommand>
2024-05-13 00:17:40 +02:00
{
public static bool TryFromPacket(Packet packet, [MaybeNullWhen(false)] out Command command)
2024-05-13 00:17:40 +02:00
{
unsafe
{
2024-10-16 21:59:35 +02:00
var result = CommandNative.sp_command_try_from_packet(packet.Into());
if (result == null)
{
command = null;
return false;
}
command = new Command(result);
return true;
2024-05-13 00:17:40 +02:00
}
}
public Command Clone()
2024-05-13 00:17:40 +02:00
{
unsafe
{
2024-10-16 21:59:35 +02:00
return new Command(CommandNative.sp_command_clone(Instance));
2024-05-13 00:17:40 +02:00
}
}
public static Command Clear()
{
unsafe
{
2024-10-16 21:59:35 +02:00
return new Command(CommandNative.sp_command_clear());
2024-05-13 00:17:40 +02:00
}
}
public static Command HardReset()
{
unsafe
{
2024-10-16 21:59:35 +02:00
return new Command(CommandNative.sp_command_hard_reset());
2024-05-13 00:17:40 +02:00
}
}
public static Command FadeOut()
{
unsafe
{
2024-10-16 21:59:35 +02:00
return new Command(CommandNative.sp_command_fade_out());
2024-05-13 00:17:40 +02:00
}
}
public static Command Brightness(byte brightness)
{
unsafe
{
2024-10-16 21:59:35 +02:00
return new Command(CommandNative.sp_command_brightness(brightness));
2024-05-13 00:17:40 +02:00
}
}
2024-10-16 20:56:55 +02:00
public static Command CharBrightness(ushort x, ushort y, BrightnessGrid grid)
2024-05-13 00:17:40 +02:00
{
unsafe
{
2024-10-16 21:59:35 +02:00
return new Command(CommandNative.sp_command_char_brightness(x, y, grid.Into()));
2024-05-13 00:17:40 +02:00
}
}
2024-10-16 20:56:55 +02:00
public static Command BitmapLinear(ushort offset, BitVec bitVec, CompressionCode compressionCode)
2024-05-13 00:17:40 +02:00
{
unsafe
{
return new Command(
2024-10-16 21:59:35 +02:00
CommandNative.sp_command_bitmap_linear(offset, bitVec.Into(), compressionCode));
2024-05-13 00:17:40 +02:00
}
}
2024-10-16 20:56:55 +02:00
public static Command BitmapLinearAnd(ushort offset, BitVec bitVec, CompressionCode compressionCode)
2024-05-13 00:17:40 +02:00
{
unsafe
{
return new Command(
2024-10-16 21:59:35 +02:00
CommandNative.sp_command_bitmap_linear_and(offset, bitVec.Into(), compressionCode));
2024-05-13 00:17:40 +02:00
}
}
2024-10-16 20:56:55 +02:00
public static Command BitmapLinearOr(ushort offset, BitVec bitVec, CompressionCode compressionCode)
2024-05-13 00:17:40 +02:00
{
unsafe
{
return new Command(
2024-10-16 21:59:35 +02:00
CommandNative.sp_command_bitmap_linear_or(offset, bitVec.Into(), compressionCode));
2024-05-13 00:17:40 +02:00
}
}
2024-10-16 20:56:55 +02:00
public static Command BitmapLinearXor(ushort offset, BitVec bitVec, CompressionCode compressionCode)
2024-05-13 00:17:40 +02:00
{
unsafe
{
return new Command(
2024-10-16 21:59:35 +02:00
CommandNative.sp_command_bitmap_linear_xor(offset, bitVec.Into(), compressionCode));
2024-05-13 00:17:40 +02:00
}
}
2024-10-16 20:56:55 +02:00
public static Command BitmapLinearWin(ushort x, ushort y, Bitmap bitmap, CompressionCode compression)
2024-05-13 00:17:40 +02:00
{
unsafe
{
2024-10-16 21:59:35 +02:00
return new Command(CommandNative.sp_command_bitmap_linear_win(x, y, bitmap.Into(), compression));
2024-05-13 00:17:40 +02:00
}
}
2024-10-16 20:56:55 +02:00
public static Command Cp437Data(ushort x, ushort y, Cp437Grid byteGrid)
2024-05-13 00:17:40 +02:00
{
unsafe
{
2024-10-16 21:59:35 +02:00
return new Command(CommandNative.sp_command_cp437_data(x, y, byteGrid.Into()));
2024-05-13 00:17:40 +02:00
}
}
2024-10-16 21:59:35 +02:00
private unsafe Command(SPCommand* instance) : base(instance)
2024-05-13 00:17:40 +02:00
{
}
2024-10-16 21:59:35 +02:00
private protected override unsafe void Free() => CommandNative.sp_command_free(Instance);
2024-05-13 00:17:40 +02:00
}