Changed: movable tiles

This commit is contained in:
Ray 2020-04-12 01:12:21 +01:00
parent c9edc93e40
commit 7fd6c06c78
7 changed files with 164 additions and 53 deletions

26
MainForm.Designer.cs generated
View File

@ -37,6 +37,8 @@
this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel();
this.button3 = new System.Windows.Forms.Button();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
this.contextMenuStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.SuspendLayout();
@ -55,6 +57,8 @@
//
this.titlePanel1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.titlePanel1.BackColor = System.Drawing.Color.Black;
this.titlePanel1.LabelVisible = true;
this.titlePanel1.Location = new System.Drawing.Point(0, 0);
this.titlePanel1.MainMenu = this.contextMenuStrip1;
this.titlePanel1.MinimumSize = new System.Drawing.Size(40, 40);
@ -66,14 +70,16 @@
// contextMenuStrip1
//
this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripMenuItem1,
this.toolStripSeparator1,
this.exitToolStripMenuItem});
this.contextMenuStrip1.Name = "contextMenuStrip1";
this.contextMenuStrip1.Size = new System.Drawing.Size(94, 26);
this.contextMenuStrip1.Size = new System.Drawing.Size(181, 76);
//
// exitToolStripMenuItem
//
this.exitToolStripMenuItem.Name = "exitToolStripMenuItem";
this.exitToolStripMenuItem.Size = new System.Drawing.Size(93, 22);
this.exitToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.exitToolStripMenuItem.Text = "E&xit";
this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click);
//
@ -92,7 +98,7 @@
this.flowLayoutPanel1.FlowDirection = System.Windows.Forms.FlowDirection.TopDown;
this.flowLayoutPanel1.Location = new System.Drawing.Point(12, 59);
this.flowLayoutPanel1.Name = "flowLayoutPanel1";
this.flowLayoutPanel1.Size = new System.Drawing.Size(672, 369);
this.flowLayoutPanel1.Size = new System.Drawing.Size(600, 369);
this.flowLayoutPanel1.TabIndex = 27;
//
// button3
@ -114,6 +120,18 @@
this.pictureBox1.TabIndex = 29;
this.pictureBox1.TabStop = false;
//
// toolStripMenuItem1
//
this.toolStripMenuItem1.Name = "toolStripMenuItem1";
this.toolStripMenuItem1.Size = new System.Drawing.Size(180, 22);
this.toolStripMenuItem1.Text = "Always On &Top";
this.toolStripMenuItem1.Click += new System.EventHandler(this.toolStripMenuItem1_Click);
//
// toolStripSeparator1
//
this.toolStripSeparator1.Name = "toolStripSeparator1";
this.toolStripSeparator1.Size = new System.Drawing.Size(177, 6);
//
// MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -145,6 +163,8 @@
private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem1;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
}
}

View File

@ -19,6 +19,8 @@ namespace AppLauncher
{
public partial class MainForm : AForm
{
protected int collapsedWidth = 40;
protected int expandedWidth = 800;
public MainForm() : base()
{
@ -29,15 +31,14 @@ namespace AppLauncher
private async void button1_Click(object sender, EventArgs e)
{
if (this.Width > 40)
{
await collapseWindow(40, 6);
}
else
{
await expandWindow(800, 8);
}
//if (this.Width > collapsedWidth)
//{
// await collapseWindow(collapsedWidth, 6);
//}
//else
//{
// await expandWindow(expandedWidth, 8);
//}
}
private void button2_Click(object sender, EventArgs e)
@ -98,7 +99,25 @@ namespace AppLauncher
}
protected async Task collapseWindow(int width, int increment = 8)
public async Task ToggleSize()
{
if (this.Width > collapsedWidth)
{
flowLayoutPanel1.Visible = false;
titlePanel1.LabelVisible = false;
await collapseWindow(collapsedWidth, 6);
}
else
{
await expandWindow(expandedWidth, 8);
flowLayoutPanel1.Visible = true;
titlePanel1.LabelVisible = true;
}
}
protected async Task collapseWindow(int width, int increment = 6)
{
await Task.Run(() =>
{
@ -130,13 +149,13 @@ namespace AppLauncher
{
this.Invoke(new MethodInvoker(() => {
this.Width += increment;
this.Invalidate();
//this.Invalidate();
}));
}
else
{
this.Width += increment;
this.Invalidate();
//this.Invalidate();
}
Application.DoEvents();
@ -144,6 +163,13 @@ namespace AppLauncher
});
}
private void toolStripMenuItem1_Click(object sender, EventArgs e)
{
this.TopMost = !this.TopMost;
toolStripMenuItem1.Checked = this.TopMost;
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
@ -178,5 +204,6 @@ namespace AppLauncher
loadSession(Application.StartupPath.TrimEnd('\\') + "\\test1.jsonfig");
}
}
}

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);
}

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;
}

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);
}
}

View File

@ -37,7 +37,7 @@
//
this.pictureBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)));
this.pictureBox1.BackColor = System.Drawing.Color.Transparent;
this.pictureBox1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(76)))), ((int)(((byte)(83)))), ((int)(((byte)(93)))));
this.pictureBox1.BackgroundImage = global::AppLauncher.Properties.Resources.grid_ea_24;
this.pictureBox1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center;
this.pictureBox1.ErrorImage = null;
@ -48,6 +48,7 @@
this.pictureBox1.Size = new System.Drawing.Size(40, 40);
this.pictureBox1.TabIndex = 5;
this.pictureBox1.TabStop = false;
this.pictureBox1.DoubleClick += new System.EventHandler(this.pictureBox1_DoubleClick);
this.pictureBox1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseUp);
//
// label1
@ -55,7 +56,7 @@
this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.label1.BackColor = System.Drawing.Color.Black;
this.label1.BackColor = System.Drawing.Color.Transparent;
this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label1.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(234)))), ((int)(((byte)(234)))), ((int)(((byte)(234)))));
this.label1.Location = new System.Drawing.Point(40, 0);
@ -70,6 +71,7 @@
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.Black;
this.Controls.Add(this.label1);
this.Controls.Add(this.pictureBox1);
this.MinimumSize = new System.Drawing.Size(100, 40);

View File

@ -1,11 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AppLauncher.Windows.Forms
@ -20,6 +15,13 @@ namespace AppLauncher.Windows.Forms
InitializeComponent();
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
this.BackColor = Color.Black;
}
protected override void OnParentBindingContextChanged(EventArgs e)
{
base.OnParentBindingContextChanged(e);
@ -31,19 +33,39 @@ namespace AppLauncher.Windows.Forms
pictureBox1.MouseDown += parentForm_MouseDown;
pictureBox1.MouseUp += parentForm_MouseUp;
pictureBox1.MouseMove += parentForm_MouseMove;
label1.MouseDown += parentForm_MouseDown;
label1.MouseUp += parentForm_MouseUp;
label1.MouseMove += parentForm_MouseMove;
}
}
}
[Category("Appearance"), Browsable(true)]
public string TitleText
{
get => label1.Text;
set => label1.Text = value;
}
public string TitleText { get => label1.Text; set => label1.Text = value; }
[Category("Appearance"), Browsable(true)]
public bool LabelVisible { get => label1.Visible; set => label1.Visible = value; }
public ContextMenuStrip MainMenu { get; set; } = null;
public MainForm MainForm
{
get
{
if (this.Parent == null)
{
return null;
}
if (this.Parent.GetType() != typeof(MainForm))
{
return null;
}
return (MainForm)this.Parent;
}
}
protected void parentForm_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Left)
@ -84,5 +106,15 @@ namespace AppLauncher.Windows.Forms
}
}
private async void pictureBox1_DoubleClick(object sender, EventArgs e)
{
if (this.MainForm == null)
{
return;
}
await this.MainForm.ToggleSize();
}
}
}