Archived
WIP: tile container animation
This commit is contained in:
1 parent
caec9c7317
commit
2c116af5aa
13 files changed
+758
-122
No files matched your search
+21
@@ -28,8 +28,12 @@
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.components = new System.ComponentModel.Container();
|
||||
this.label1 = new AppLauncher.Windows.Forms.TileGroupLabel();
|
||||
this.panel1 = new AppLauncher.Windows.Forms.TileLayoutPanel();
|
||||
this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
|
||||
this.addToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.contextMenuStrip1.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// label1
|
||||
@@ -57,6 +61,20 @@
|
||||
this.panel1.Size = new System.Drawing.Size(223, 127);
|
||||
this.panel1.TabIndex = 27;
|
||||
//
|
||||
// contextMenuStrip1
|
||||
//
|
||||
this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.addToolStripMenuItem});
|
||||
this.contextMenuStrip1.Name = "contextMenuStrip1";
|
||||
this.contextMenuStrip1.Size = new System.Drawing.Size(181, 48);
|
||||
//
|
||||
// addToolStripMenuItem
|
||||
//
|
||||
this.addToolStripMenuItem.Name = "addToolStripMenuItem";
|
||||
this.addToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
this.addToolStripMenuItem.Text = "&Add";
|
||||
this.addToolStripMenuItem.Click += new System.EventHandler(this.addToolStripMenuItem_Click);
|
||||
//
|
||||
// TileContainer
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
@@ -66,6 +84,7 @@
|
||||
this.Controls.Add(this.label1);
|
||||
this.Name = "TileContainer";
|
||||
this.Size = new System.Drawing.Size(370, 150);
|
||||
this.contextMenuStrip1.ResumeLayout(false);
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
@@ -74,5 +93,7 @@
|
||||
|
||||
private TileGroupLabel label1;
|
||||
private TileLayoutPanel panel1;
|
||||
private System.Windows.Forms.ContextMenuStrip contextMenuStrip1;
|
||||
private System.Windows.Forms.ToolStripMenuItem addToolStripMenuItem;
|
||||
}
|
||||
}
|
||||
@@ -17,11 +17,15 @@ namespace AppLauncher.Windows.Forms
|
||||
protected int collapseIncrement = 6;
|
||||
protected int expandIncrement = 8;
|
||||
protected TileGroupModel groupInfo = null;
|
||||
protected bool isAnimating = false;
|
||||
|
||||
public TileContainer(TileGroupModel model) : base()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
this.ContextMenuStrip = contextMenuStrip1;
|
||||
//this.BackColor = Color.MistyRose;
|
||||
|
||||
label1.TileGroupPanel = this;
|
||||
|
||||
groupInfo = model;
|
||||
@@ -29,40 +33,36 @@ namespace AppLauncher.Windows.Forms
|
||||
label1.TitleText = groupInfo.Title;
|
||||
panel1.SetGridSize(groupInfo.GridSize.Width, groupInfo.GridSize.Height);
|
||||
label1.Checked = groupInfo.IsExpanded;
|
||||
|
||||
//label1.Width = panel1.Width;
|
||||
//label1.PanelHeight = panel1.Height;
|
||||
|
||||
//this.Margin = new Padding(0);
|
||||
//this.Size = new Size(panel1.Width, (label1.Height + panel1.Height));
|
||||
//this.MaximumSize = this.Size;
|
||||
//this.MinimumSize = this.Size;
|
||||
|
||||
//this.BackColor = Color.MistyRose;
|
||||
|
||||
panel1.LoadTiles(model.Items);
|
||||
}
|
||||
|
||||
protected override void OnLoad(EventArgs e)
|
||||
protected override async void OnLoad(EventArgs e)
|
||||
{
|
||||
base.OnLoad(e);
|
||||
|
||||
label1.Width = panel1.Width;
|
||||
|
||||
this.Margin = new Padding(0);
|
||||
this.MaximumSize = new Size(panel1.Width, (label1.Height + panel1.ExpandedHeight));
|
||||
this.Margin = new Padding(0, 0, 0, 0);
|
||||
this.Padding = new Padding(0, 0, 0, 20);
|
||||
this.MaximumSize = new Size(panel1.Width, expandedHeight);
|
||||
this.MinimumSize = new Size(panel1.Width, label1.Height);
|
||||
this.Size = this.MaximumSize;
|
||||
}
|
||||
|
||||
protected int collapseHeight => label1.Height + panel1.CollapseHeight;
|
||||
|
||||
protected int expandedHeight => label1.Height + panel1.ExpandedHeight;
|
||||
protected int expandedHeight => label1.Height + panel1.ExpandedHeight + this.Padding.Top + this.Padding.Bottom;
|
||||
|
||||
public bool IsAnimating => isAnimating;
|
||||
|
||||
public async Task Collapse()
|
||||
{
|
||||
await Task.Run(() =>
|
||||
{
|
||||
if (isAnimating) return;
|
||||
|
||||
isAnimating = true;
|
||||
|
||||
while (this.Height > collapseHeight)
|
||||
{
|
||||
if (this.InvokeRequired)
|
||||
@@ -78,6 +78,8 @@ namespace AppLauncher.Windows.Forms
|
||||
|
||||
Thread.Sleep(10);
|
||||
}
|
||||
|
||||
isAnimating = false;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -85,6 +87,10 @@ namespace AppLauncher.Windows.Forms
|
||||
{
|
||||
await Task.Run(() =>
|
||||
{
|
||||
if (isAnimating) return;
|
||||
|
||||
isAnimating = true;
|
||||
|
||||
if (this.InvokeRequired)
|
||||
{
|
||||
this.Invoke(new MethodInvoker(() => {
|
||||
@@ -95,6 +101,8 @@ namespace AppLauncher.Windows.Forms
|
||||
{
|
||||
this.Height = collapseHeight;
|
||||
}
|
||||
|
||||
isAnimating = false;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -102,6 +110,10 @@ namespace AppLauncher.Windows.Forms
|
||||
{
|
||||
await Task.Run(() =>
|
||||
{
|
||||
if (isAnimating) return;
|
||||
|
||||
isAnimating = true;
|
||||
|
||||
while (this.Height < expandedHeight)
|
||||
{
|
||||
if (this.InvokeRequired)
|
||||
@@ -119,8 +131,40 @@ namespace AppLauncher.Windows.Forms
|
||||
|
||||
Thread.Sleep(10);
|
||||
}
|
||||
|
||||
isAnimating = false;
|
||||
});
|
||||
}
|
||||
|
||||
public async Task InvalidateContainer(bool animate = true)
|
||||
{
|
||||
if (this.IsAnimating)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (label1.Checked)
|
||||
{
|
||||
await this.Expand();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (animate)
|
||||
{
|
||||
await this.Collapse();
|
||||
}
|
||||
else
|
||||
{
|
||||
await this.CollapseNow();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
AddTileForm addForm = new AddTileForm(panel1);
|
||||
addForm.ShowDialog();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -117,4 +117,7 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="contextMenuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
</root>
|
||||
@@ -1,20 +1,15 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Threading.Tasks;
|
||||
using System.ComponentModel;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace AppLauncher.Windows.Forms
|
||||
{
|
||||
public partial class TileGroupLabel : AUserControl
|
||||
{
|
||||
protected bool isChecked = false;
|
||||
protected bool isChecked = true;
|
||||
|
||||
public TileGroupLabel() : base()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
this.Checked = false;
|
||||
|
||||
}
|
||||
|
||||
[Category("Appearance"), Browsable(true)]
|
||||
@@ -29,20 +24,18 @@ namespace AppLauncher.Windows.Forms
|
||||
isChecked = value;
|
||||
|
||||
pictureBox1.BackgroundImage = (value) ? Properties.Resources.toggle_right_ea_16 : Properties.Resources.toggle_left_ea_16;
|
||||
|
||||
if (this.TileGroupPanel != null)
|
||||
{
|
||||
this.TileGroupPanel.InvalidateContainer();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public TileContainer TileGroupPanel { get; set; } = null;
|
||||
|
||||
protected async override void OnLoad(EventArgs e)
|
||||
{
|
||||
base.OnLoad(e);
|
||||
|
||||
await invalidateToggle(false);
|
||||
}
|
||||
|
||||
protected async void panel_MouseClick(object sender, MouseEventArgs e)
|
||||
protected void panel_MouseClick(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (e.Button != MouseButtons.Left)
|
||||
{
|
||||
@@ -50,32 +43,6 @@ namespace AppLauncher.Windows.Forms
|
||||
}
|
||||
|
||||
this.Checked = !this.Checked;
|
||||
|
||||
await invalidateToggle();
|
||||
}
|
||||
|
||||
protected async Task invalidateToggle(bool animate = true)
|
||||
{
|
||||
if (this.TileGroupPanel == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.Checked)
|
||||
{
|
||||
await this.TileGroupPanel.Expand();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (animate)
|
||||
{
|
||||
await this.TileGroupPanel.Collapse();
|
||||
}
|
||||
else
|
||||
{
|
||||
await this.TileGroupPanel.CollapseNow();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -56,6 +56,11 @@ namespace AppLauncher.Windows.Forms
|
||||
|
||||
public int ExpandedHeight => expandedHeight;
|
||||
|
||||
public void AddTile(TileModel tile)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
this.Controls.Clear();
|
||||
@@ -87,13 +92,6 @@ namespace AppLauncher.Windows.Forms
|
||||
return new Point((x * this.TileSize), (y * this.TileSize));
|
||||
}
|
||||
|
||||
public void SetGridSize(int width, int height)
|
||||
{
|
||||
expandedHeight = (this.TileSize * height);
|
||||
|
||||
this.Size = new Size((this.TileSize * width), expandedHeight);
|
||||
}
|
||||
|
||||
public void LoadTiles(List<TileModel> tiles)
|
||||
{
|
||||
if (tiles == null)
|
||||
@@ -109,7 +107,7 @@ namespace AppLauncher.Windows.Forms
|
||||
foreach (TileModel item in tiles)
|
||||
{
|
||||
// resolve final grid position
|
||||
Point? confirmedPosition = resolvePosition(item.Position);
|
||||
Point? confirmedPosition = resolveCoord(item.Position);
|
||||
if (confirmedPosition == null)
|
||||
{
|
||||
continue;
|
||||
@@ -119,7 +117,7 @@ namespace AppLauncher.Windows.Forms
|
||||
// place control
|
||||
TilePanel panel = new TilePanel();
|
||||
panel.LoadInfo(item);
|
||||
panel.Location = convertPositionToLocation(confirmedPosition.Value);
|
||||
panel.Location = convertCoordToLocation(confirmedPosition.Value);
|
||||
|
||||
items.Add(new Item()
|
||||
{
|
||||
@@ -139,7 +137,7 @@ namespace AppLauncher.Windows.Forms
|
||||
return;
|
||||
}
|
||||
|
||||
Point newPosition = convertLocationToPosition(posX, posY);
|
||||
Point newPosition = convertLocationToCoord(posX, posY);
|
||||
if (!isTileInBounds(newPosition))
|
||||
{
|
||||
return;
|
||||
@@ -151,22 +149,40 @@ namespace AppLauncher.Windows.Forms
|
||||
if (swapItem != null)
|
||||
{
|
||||
swapItem.Coord = item.Coord;
|
||||
swapItem.Tile.Location = convertPositionToLocation(item.Coord);
|
||||
swapItem.Tile.Location = convertCoordToLocation(item.Coord);
|
||||
}
|
||||
|
||||
item.Coord = newPosition;
|
||||
panel.Location = convertPositionToLocation(newPosition);
|
||||
panel.Location = convertCoordToLocation(newPosition);
|
||||
}
|
||||
else
|
||||
{
|
||||
item.Coord = newPosition;
|
||||
panel.Location = convertPositionToLocation(newPosition);
|
||||
panel.Location = convertCoordToLocation(newPosition);
|
||||
}
|
||||
}
|
||||
|
||||
protected Point convertPositionToLocation(Point position) => new Point((position.X * this.TileSize), (position.Y * this.TileSize));
|
||||
public void Remove(TilePanel panel)
|
||||
{
|
||||
Item m = items.Where(x => x.Tile.Equals(panel)).FirstOrDefault();
|
||||
if (m != null)
|
||||
{
|
||||
items.Remove(m);
|
||||
}
|
||||
|
||||
protected Point convertLocationToPosition(int posX, int posY)
|
||||
this.Controls.Remove(panel);
|
||||
}
|
||||
|
||||
public void SetGridSize(int width, int height)
|
||||
{
|
||||
expandedHeight = (this.TileSize * height);
|
||||
|
||||
this.Size = new Size((this.TileSize * width), expandedHeight);
|
||||
}
|
||||
|
||||
protected Point convertCoordToLocation(Point position) => new Point((position.X * this.TileSize), (position.Y * this.TileSize));
|
||||
|
||||
protected Point convertLocationToCoord(int posX, int posY)
|
||||
{
|
||||
int x = (int)Math.Round(decimal.Divide(posX, this.TileSize));
|
||||
int y = (int)Math.Round(decimal.Divide(posY, this.TileSize));
|
||||
@@ -177,47 +193,47 @@ namespace AppLauncher.Windows.Forms
|
||||
return new Point(x, y);
|
||||
}
|
||||
|
||||
protected Point? resolvePosition(Point position)
|
||||
protected Point? resolveCoord(Point coord)
|
||||
{
|
||||
if (!isTileInBounds(position))
|
||||
if (!isTileInBounds(coord))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!hasTile(position))
|
||||
if (!hasTile(coord))
|
||||
{
|
||||
return position;
|
||||
return coord;
|
||||
}
|
||||
|
||||
return resolveNextPosition(position);
|
||||
return resolveNextCoord(coord);
|
||||
}
|
||||
|
||||
protected Point? resolveNextPosition(Point position)
|
||||
protected Point? resolveNextCoord(Point coord)
|
||||
{
|
||||
Point gridSize = this.GridSize;
|
||||
Point newPosition = position;
|
||||
Point newCoord = coord;
|
||||
|
||||
while (true)
|
||||
{
|
||||
newPosition.X++;
|
||||
newCoord.X++;
|
||||
|
||||
if (newPosition.X >= gridSize.X)
|
||||
if (newCoord.X >= gridSize.X)
|
||||
{
|
||||
newPosition.Y++;
|
||||
newPosition.X = 0;
|
||||
newCoord.Y++;
|
||||
newCoord.X = 0;
|
||||
}
|
||||
|
||||
if (!isTileInBounds(newPosition))
|
||||
if (!isTileInBounds(newCoord))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (hasTile(newPosition))
|
||||
if (hasTile(newCoord))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
return newPosition;
|
||||
return newCoord;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace AppLauncher.Windows.Forms
|
||||
protected bool isDragging = false;
|
||||
protected Point startPosition = new Point();
|
||||
|
||||
protected TileModel model = new TileModel();
|
||||
protected TileModel modelInfo = new TileModel();
|
||||
protected EditTileForm editForm = null;
|
||||
|
||||
public TilePanel() : base()
|
||||
@@ -40,7 +40,7 @@ namespace AppLauncher.Windows.Forms
|
||||
public Image Image { get => pictureBox1.BackgroundImage; protected set => pictureBox1.BackgroundImage = value; }
|
||||
|
||||
[Browsable(false)]
|
||||
public TileModel Info => model;
|
||||
public TileModel ModelInfo => modelInfo;
|
||||
|
||||
public TileLayoutPanel PanelContainer
|
||||
{
|
||||
@@ -62,25 +62,25 @@ namespace AppLauncher.Windows.Forms
|
||||
|
||||
public void LoadInfo(TileModel model)
|
||||
{
|
||||
this.model = model;
|
||||
this.modelInfo = 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
|
||||
{
|
||||
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -127,27 +127,27 @@ namespace AppLauncher.Windows.Forms
|
||||
|
||||
private void TilePanel_MouseDoubleClick(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (this.Info == null)
|
||||
if (this.ModelInfo == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(this.Info.ProcessFilename))
|
||||
if (string.IsNullOrWhiteSpace(this.ModelInfo.ProcessFilename))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!File.Exists(this.Info.ProcessFilename))
|
||||
if (!File.Exists(this.ModelInfo.ProcessFilename))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ProcessStartInfo p = new ProcessStartInfo();
|
||||
p.FileName = this.Info.ProcessFilename;
|
||||
p.WindowStyle = this.Info.ProcessWindowStyle;
|
||||
if (!string.IsNullOrWhiteSpace(this.Info.ProcessArgument)) p.Arguments = this.Info.ProcessArgument;
|
||||
if (!string.IsNullOrWhiteSpace(this.Info.ProcessWorkingDirectory)) p.WorkingDirectory = this.Info.ProcessWorkingDirectory;
|
||||
if (this.Info.ProcessAsAdmin) p.Verb = "runas";
|
||||
p.FileName = this.ModelInfo.ProcessFilename;
|
||||
p.WindowStyle = this.ModelInfo.ProcessWindowStyle;
|
||||
if (!string.IsNullOrWhiteSpace(this.ModelInfo.ProcessArgument)) p.Arguments = this.ModelInfo.ProcessArgument;
|
||||
if (!string.IsNullOrWhiteSpace(this.ModelInfo.ProcessWorkingDirectory)) p.WorkingDirectory = this.ModelInfo.ProcessWorkingDirectory;
|
||||
if (this.ModelInfo.ProcessAsAdmin) p.Verb = "runas";
|
||||
|
||||
try
|
||||
{
|
||||
@@ -172,7 +172,12 @@ namespace AppLauncher.Windows.Forms
|
||||
|
||||
private void removeToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (this.PanelContainer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.PanelContainer.Remove(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user