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);
}
}
+4 -2
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);
+42 -10
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();
}
}
}