mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/PCK-Studio.git
synced 2026-06-24 19:35:33 +00:00
Core - Update GraphicsConfig
This commit is contained in:
@@ -32,11 +32,7 @@ namespace PckStudio.Forms.Editor
|
||||
|
||||
private Core.App.SettingsManager _settingsManager;
|
||||
|
||||
private static GraphicsConfig _graphicsConfig = new GraphicsConfig()
|
||||
{
|
||||
InterpolationMode = InterpolationMode.NearestNeighbor,
|
||||
PixelOffsetMode = PixelOffsetMode.HighQuality,
|
||||
};
|
||||
private static GraphicsConfig _graphicsConfig = GraphicsConfig.PixelPerfect();
|
||||
|
||||
private CustomSkinEditor() : this(null, null)
|
||||
{ }
|
||||
|
||||
@@ -81,7 +81,8 @@ namespace PckStudio.Forms.Editor
|
||||
|
||||
private int SelectedIndex
|
||||
{
|
||||
set {
|
||||
set
|
||||
{
|
||||
if (value < 0)
|
||||
{
|
||||
value += _atlas.TileCount;
|
||||
@@ -94,13 +95,9 @@ namespace PckStudio.Forms.Editor
|
||||
}
|
||||
}
|
||||
|
||||
private const ImageLayoutDirection _imageLayout = ImageLayoutDirection.Horizontal;
|
||||
private readonly ImageLayoutDirection _imageLayout = ImageLayoutDirection.Horizontal;
|
||||
|
||||
private readonly GraphicsConfig _graphicsConfig = new GraphicsConfig()
|
||||
{
|
||||
InterpolationMode = InterpolationMode.NearestNeighbor,
|
||||
PixelOffsetMode = PixelOffsetMode.HighQuality
|
||||
};
|
||||
private readonly GraphicsConfig _graphicsConfig = GraphicsConfig.PixelPerfect();
|
||||
|
||||
private void UpdateAtlasDisplay()
|
||||
{
|
||||
|
||||
@@ -3,30 +3,20 @@ using System.Drawing.Drawing2D;
|
||||
|
||||
namespace PckStudio.Core.Extensions
|
||||
{
|
||||
public struct GraphicsConfig
|
||||
public readonly struct GraphicsConfig(InterpolationMode interpolationMode, SmoothingMode smoothingMode, PixelOffsetMode pixelOffsetMode)
|
||||
{
|
||||
public GraphicsConfig()
|
||||
{
|
||||
CompositingQuality = default;
|
||||
InterpolationMode = default;
|
||||
SmoothingMode = default;
|
||||
PixelOffsetMode = default;
|
||||
CompositingMode = default;
|
||||
}
|
||||
public InterpolationMode InterpolationMode { get; } = interpolationMode;
|
||||
public SmoothingMode SmoothingMode { get; } = smoothingMode;
|
||||
public PixelOffsetMode PixelOffsetMode { get; } = pixelOffsetMode;
|
||||
|
||||
public CompositingMode CompositingMode { get; set; }
|
||||
public CompositingQuality CompositingQuality { get; set; }
|
||||
public InterpolationMode InterpolationMode { get; set; }
|
||||
public SmoothingMode SmoothingMode { get; set; }
|
||||
public PixelOffsetMode PixelOffsetMode { get; set; }
|
||||
public static GraphicsConfig PixelPerfect()
|
||||
=> new GraphicsConfig(InterpolationMode.NearestNeighbor, SmoothingMode.None, PixelOffsetMode.HighQuality);
|
||||
}
|
||||
|
||||
public static class GraphicsExtensions
|
||||
{
|
||||
public static void ApplyConfig(this Graphics graphics, GraphicsConfig config)
|
||||
{
|
||||
graphics.CompositingMode = config.CompositingMode;
|
||||
graphics.CompositingQuality = config.CompositingQuality;
|
||||
graphics.InterpolationMode = config.InterpolationMode;
|
||||
graphics.SmoothingMode = config.SmoothingMode;
|
||||
graphics.PixelOffsetMode = config.PixelOffsetMode;
|
||||
|
||||
@@ -40,15 +40,13 @@ namespace PckStudio.Core.Extensions
|
||||
|
||||
public static Image GetArea(this Image source, Rectangle area)
|
||||
{
|
||||
Image tileImage = new Bitmap(area.Width, area.Height);
|
||||
using (Graphics gfx = Graphics.FromImage(tileImage))
|
||||
Image result = new Bitmap(area.Width, area.Height);
|
||||
using (Graphics gfx = Graphics.FromImage(result))
|
||||
{
|
||||
gfx.SmoothingMode = SmoothingMode.None;
|
||||
gfx.InterpolationMode = InterpolationMode.NearestNeighbor;
|
||||
gfx.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
||||
gfx.ApplyConfig(GraphicsConfig.PixelPerfect());
|
||||
gfx.DrawImage(source, new Rectangle(Point.Empty, area.Size), area, GraphicsUnit.Pixel);
|
||||
}
|
||||
return tileImage;
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -518,11 +518,7 @@ namespace PckStudio.ModelSupport
|
||||
areasToFix = areasToFix.Where(rect => rect.Size.Width > 0 && rect.Size.Height > 0);
|
||||
Image result = new Bitmap(texture);
|
||||
using var g = Graphics.FromImage(result);
|
||||
g.ApplyConfig(new GraphicsConfig()
|
||||
{
|
||||
InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor,
|
||||
PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality
|
||||
});
|
||||
g.ApplyConfig(GraphicsConfig.PixelPerfect());
|
||||
foreach (Rectangle area in areasToFix)
|
||||
{
|
||||
Image targetAreaImage = texture.GetArea(area);
|
||||
|
||||
Reference in New Issue
Block a user