121 lines
3.3 KiB
C#
121 lines
3.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace AppLauncher.Windows.Forms
|
|
{
|
|
public class TilePanelContainer : AUserControl
|
|
{
|
|
protected readonly int tileSize = 70;
|
|
protected readonly int margin = 3;
|
|
|
|
public TilePanelContainer() : base()
|
|
{
|
|
|
|
}
|
|
|
|
protected override void OnLoad(EventArgs e)
|
|
{
|
|
base.OnLoad(e);
|
|
|
|
OnResize(e);
|
|
}
|
|
|
|
public Point GridSize
|
|
{
|
|
get
|
|
{
|
|
int w = (int)Math.Floor(decimal.Divide(this.Width, this.TileSize));
|
|
int h = (int)Math.Floor(decimal.Divide(this.Height, this.TileSize));
|
|
|
|
return new Point(w, h);
|
|
}
|
|
}
|
|
|
|
public int TileSize => (tileSize + margin);
|
|
|
|
|
|
public async Task Collapse(int height, int increment = 6)
|
|
{
|
|
await Task.Run(() =>
|
|
{
|
|
while (this.Height > height)
|
|
{
|
|
if (this.InvokeRequired)
|
|
{
|
|
this.Invoke(new MethodInvoker(() => {
|
|
this.Height -= increment;
|
|
}));
|
|
}
|
|
else
|
|
{
|
|
this.Height -= increment;
|
|
}
|
|
|
|
Thread.Sleep(10);
|
|
}
|
|
});
|
|
}
|
|
|
|
public async Task Expand(int height, int increment = 8)
|
|
{
|
|
await Task.Run(() =>
|
|
{
|
|
while (this.Height < height)
|
|
{
|
|
if (this.InvokeRequired)
|
|
{
|
|
this.Invoke(new MethodInvoker(() => {
|
|
this.Height += increment;
|
|
this.Invalidate();
|
|
}));
|
|
}
|
|
else
|
|
{
|
|
this.Height += increment;
|
|
this.Invalidate();
|
|
}
|
|
|
|
Thread.Sleep(10);
|
|
}
|
|
});
|
|
}
|
|
|
|
public Point GetTileCoord(Point location) => this.GetTileCoord(location.X, location.Y);
|
|
|
|
public Point GetTileCoord(int posX, int posY)
|
|
{
|
|
int x = (int)Math.Round(decimal.Divide(posX, this.TileSize));
|
|
int y = (int)Math.Round(decimal.Divide(posY, this.TileSize));
|
|
|
|
if (x < 0) x = 0;
|
|
if (y < 0) y = 0;
|
|
|
|
return new Point(x, y);
|
|
}
|
|
|
|
public Point GetTilePosition(Point location) => this.GetTilePosition(location.X, location.Y);
|
|
|
|
public Point GetTilePosition(int posX, int posY)
|
|
{
|
|
int x = (int)Math.Round(decimal.Divide(posX, this.TileSize));
|
|
int y = (int)Math.Round(decimal.Divide(posY, this.TileSize));
|
|
|
|
if (x < 0) x = 0;
|
|
if (y < 0) y = 0;
|
|
|
|
return new Point((x * this.TileSize), (y * this.TileSize));
|
|
}
|
|
|
|
public void SetGridSize(int width, int height)
|
|
{
|
|
this.Size = new Size((this.TileSize * width), (this.TileSize * height));
|
|
}
|
|
}
|
|
} |