1
0
mirror of synced 2024-11-12 02:00:50 +01:00

Some more layout editor improvements

Textures in the list keep aspect ratio now.
Fix creating new user data. and remove any if empty.
This commit is contained in:
KillzXGaming 2020-02-16 11:18:18 -05:00
parent 1a548f9f80
commit 07b0259805
10 changed files with 61 additions and 3 deletions

View File

@ -514,7 +514,8 @@ namespace LayoutBXLYT.Cafe
WriteSection(writer, pane.Signature, pane, () => pane.Write(writer, header));
sectionCount++;
if (pane is IUserDataContainer && ((IUserDataContainer)pane).UserData != null)
if (pane is IUserDataContainer && ((IUserDataContainer)pane).UserData != null &&
((IUserDataContainer)pane).UserData.Entries.Count > 0)
{
var userData = ((IUserDataContainer)pane).UserData;
WriteSection(writer, "usd1", userData, () => userData.Write(writer, this));

View File

@ -114,6 +114,7 @@ namespace LayoutBXLYT.Cafe
originY = (OriginY)(mainorigin / 4);
ParentOriginX = (OriginX)(parentorigin % 4);
ParentOriginY = (OriginY)(parentorigin / 4);
UserData = new USD1();
}
public override void Write(FileWriter writer, LayoutHeader header)

View File

@ -14,6 +14,10 @@ namespace LayoutBXLYT.Cafe
Entries = new List<UserDataEntry>();
}
public override UserDataEntry CreateUserData() {
return new USD1Entry();
}
public USD1(FileReader reader, Header header) : base()
{
long startPos = reader.Position - 8;
@ -68,6 +72,8 @@ namespace LayoutBXLYT.Cafe
public class USD1Entry : UserDataEntry
{
public USD1Entry() { }
public USD1Entry(FileReader reader, long startPos, Header header)
{
long pos = reader.Position;

View File

@ -541,7 +541,8 @@ namespace LayoutBXLYT
WriteSection(writer, pane.Signature, pane, () => pane.Write(writer, header));
sectionCount++;
if (pane is IUserDataContainer && ((IUserDataContainer)pane).UserData != null)
if (pane is IUserDataContainer && ((IUserDataContainer)pane).UserData != null &&
((IUserDataContainer)pane).UserData.Entries.Count > 0)
{
var userData = ((IUserDataContainer)pane).UserData;
WriteSection(writer, "usd1", userData, () => userData.Write(writer, this));

View File

@ -93,6 +93,7 @@ namespace LayoutBXLYT.CTR
originX = OriginXMap[(OriginXRev)(origin % 3)];
originY = OriginYMap[(OriginYRev)(origin / 3)];
UserData = new USD1();
}
public override void Write(FileWriter writer, LayoutHeader header)

View File

@ -14,6 +14,10 @@ namespace LayoutBXLYT.CTR
Entries = new List<UserDataEntry>();
}
public override UserDataEntry CreateUserData() {
return new USD1Entry();
}
public USD1(FileReader reader, BxlytHeader header) : base()
{
long startPos = reader.Position - 8;
@ -64,6 +68,8 @@ namespace LayoutBXLYT.CTR
public class USD1Entry : UserDataEntry
{
public USD1Entry() { }
public USD1Entry(FileReader reader, long startPos, BxlytHeader header)
{
long pos = reader.Position;

View File

@ -873,6 +873,10 @@ namespace LayoutBXLYT
Entries = new List<UserDataEntry>();
}
public virtual UserDataEntry CreateUserData() {
return new UserDataEntry();
}
public override void Write(FileWriter writer, LayoutHeader header)
{
}

View File

@ -140,6 +140,7 @@ namespace LayoutBXLYT
return;
temp = texture.GetComponentBitmap(temp, true);
temp = BitmapExtension.CreateImageThumbnail(temp, 80, 80);
if (listViewCustom1.InvokeRequired)
{

View File

@ -110,7 +110,7 @@ namespace LayoutBXLYT
{
if (activePane == null) return;
UserDataEntry userDataNew = new UserDataEntry();
UserDataEntry userDataNew = ActiveUserData.CreateUserData();
userDataNew.SetValue(new int[0]);
SelectedEntry = userDataNew;
bool IsEdited = EditData();

View File

@ -730,6 +730,43 @@ namespace Toolbox.Library
}
}
public static Bitmap CreateImageThumbnail(Bitmap image, int width, int height)
{
int tw, th, tx, ty;
int w = image.Width;
int h = image.Height;
double whRatio = (double)w / h;
if (image.Width >= image.Height)
{
tw = width;
th = (int)(tw / whRatio);
}
else
{
th = height;
tw = (int)(th * whRatio);
}
tx = (width - tw) / 2;
ty = (height - th) / 2;
Bitmap thumb = new Bitmap(width, height, image.PixelFormat);
Graphics g = Graphics.FromImage(thumb);
// g.Clear(Color.White);
g.InterpolationMode = InterpolationMode.NearestNeighbor;
g.DrawImage(image, new Rectangle(tx, ty, tw, th),
new Rectangle(0, 0, w, h),
GraphicsUnit.Pixel);
return thumb;
}
public static Bitmap AdjustBrightness(Image image, float level)
{
ImageAttributes attributes = new ImageAttributes();