Changed: movable tiles

This commit is contained in:
Ray committed 2020-04-12 01:12:21 +01:00
1 parent c9edc93e40
commit 7fd6c06c78
7 files changed
+164 -53

No files matched your search

+2
View File
@@ -38,6 +38,8 @@ namespace AppLauncher.Windows.Forms
//this.MaximumSize = this.Size;
//this.MinimumSize = this.Size;
//this.BackColor = Color.MistyRose;
panel1.LoadTiles(model.Items);
}
+39 -2
View File
@@ -133,13 +133,50 @@ namespace AppLauncher.Windows.Forms
public void MoveTile(TilePanel panel, int posX, int posY)
{
Item item = items.Where(x => x.Tile.Equals(panel)).FirstOrDefault();
if (item == null)
{
return;
}
Point newPosition = convertLocationToPosition(posX, posY);
if (!isTileInBounds(newPosition))
{
return;
}
if (hasTile(newPosition))
{
Item swapItem = items.Where(x => x.Coord.Equals(newPosition)).FirstOrDefault();
if (swapItem != null)
{
swapItem.Coord = item.Coord;
swapItem.Tile.Location = convertPositionToLocation(item.Coord);
}
item.Coord = newPosition;
panel.Location = convertPositionToLocation(newPosition);
}
else
{
item.Coord = newPosition;
panel.Location = convertPositionToLocation(newPosition);
}
}
protected Point convertPositionToLocation(Point position) => new Point((position.X * this.TileSize), (position.Y * this.TileSize));
protected Point convertLocationToPosition(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);
}
protected Point? resolvePosition(Point position)
{
if (!isTileInBounds(position))
@@ -203,12 +240,12 @@ namespace AppLauncher.Windows.Forms
{
Point gridSize = this.GridSize;
if (position.X > gridSize.X)
if (position.X >= gridSize.X)
{
return false;
}
if (position.Y > gridSize.Y)
if (position.Y >= gridSize.Y)
{
return false;
}
+15 -24
View File
@@ -39,15 +39,6 @@ namespace AppLauncher.Windows.Forms
[Browsable(false)]
public TileModel Info => model;
//[Browsable(false)]
//public string ProcessArgument { get; set; }
//[Browsable(false)]
//public string ProcessWorkingDirectory { get; set; }
//[Browsable(false)]
//public ProcessWindowStyle ProcessWindowStyle { get; set; } = ProcessWindowStyle.Normal;
public TileLayoutPanel PanelContainer
{
get
@@ -71,22 +62,23 @@ namespace AppLauncher.Windows.Forms
this.model = model;
this.Title = model.Title;
this.Image = model.Icon;
//this.Image = model.Icon;
if (this.Image == null)
{
if (File.Exists(model.ProcessFilename))
{
try
{
this.Image = Icon.ExtractAssociatedIcon(model.ProcessFilename)?.ToBitmap();
}
catch
{
//if (this.Image == null)
//{
// if (File.Exists(model.ProcessFilename))
// {
// try
// {
// this.Image = Icon.ExtractAssociatedIcon(model.ProcessFilename)?.ToBitmap();
// }
// catch
// {
// }
// }
//}
}
}
}
}
private void panel_MouseDown(object sender, MouseEventArgs e)
@@ -126,7 +118,6 @@ namespace AppLauncher.Windows.Forms
int x = (this.Location.X + (e.Location.X - startPosition.X));
int y = (this.Location.Y + (e.Location.Y - startPosition.Y));
//this.Location = layoutPanel.GetTilePosition(x, y);
layoutPanel.MoveTile(this, x, y);
}
}