WIP: tiles and tiles container

This commit is contained in:
Ray committed 2020-04-05 01:32:49 +01:00
1 parent c426c207e9
commit 0f916de22c
7 files changed
+288 -100

No files matched your search

+123
View File
@@ -7,14 +7,44 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
namespace AppLauncher.Windows.Forms
{
public partial class TilePanel : AUserControl
{
protected bool isDragging = false;
protected Point startPosition = new Point();
public TilePanel() : base()
{
InitializeComponent();
this.MouseDown += panel_MouseDown;
this.MouseUp += panel_MouseUp;
this.MouseMove += panel_MouseMove;
pictureBox1.MouseDown += panel_MouseDown;
pictureBox1.MouseUp += panel_MouseUp;
pictureBox1.MouseMove += panel_MouseMove;
label1.MouseDown += panel_MouseDown;
label1.MouseUp += panel_MouseUp;
label1.MouseMove += panel_MouseMove;
}
protected override void OnLocationChanged(EventArgs e)
{
base.OnLocationChanged(e);
if (this.Parent != null)
{
if (this.Parent.GetType() == typeof(TilePanelContainer))
{
TilePanelContainer container = (TilePanelContainer)this.Parent;
Point p = container.GetTilePosition(this.Location);
//label1.Text = p.X.ToString() + ", " + p.Y.ToString();
}
}
}
[Category("Appearance"), Browsable(true)]
@@ -23,5 +53,98 @@ namespace AppLauncher.Windows.Forms
[Category("Appearance"), Browsable(true)]
public Image IconImage { get => pictureBox1.BackgroundImage; set => pictureBox1.BackgroundImage = value; }
[Browsable(false)]
public string ProcessFilename { get; set; }
[Browsable(false)]
public string ProcessArgument { get; set; }
[Browsable(false)]
public string ProcessWorkingDirectory { get; set; }
[Browsable(false)]
public ProcessWindowStyle ProcessWindowStyle { get; set; } = ProcessWindowStyle.Normal;
public TilePanelContainer PanelContainer
{
get
{
if (this.Parent == null)
{
return null;
}
if (this.Parent.GetType() != typeof(TilePanelContainer))
{
return null;
}
return (TilePanelContainer)this.Parent;
}
}
private void panel_MouseDown(object sender, MouseEventArgs e)
{
TilePanelContainer container = this.PanelContainer;
if (container == null)
{
return;
}
if (e.Button != MouseButtons.Left)
{
return;
}
isDragging = true;
startPosition = e.Location;
}
private void panel_MouseUp(object sender, MouseEventArgs e)
{
isDragging = false;
}
private void panel_MouseMove(object sender, MouseEventArgs e)
{
if (isDragging)
{
TilePanelContainer container = this.PanelContainer;
if (container == null)
{
return;
}
//label1.Text = e.Location.ToString();
//this.Location = new Point(e.Location.X - windowOffset.X, e.Location.Y - windowOffset.Y);
//int x = parentPosition.X + (e.Location.X - positionOffset.X);
//int y = parentPosition.Y + (e.Location.Y - positionOffset.Y);
//this.Location = new Point(x, y);
//int x = (tilePosition.X + e.Location.X);
//int y = (tilePosition.Y + e.Location.Y);
int x = (this.Location.X + (e.Location.X - startPosition.X));
int y = (this.Location.Y + (e.Location.Y - startPosition.Y));
this.Location = container.GetTilePosition(x, y);
//label1.Text = x.ToString() + ", " + y.ToString();
//label1.Text = e.X.ToString() + ", " + e.Y.ToString();
//Point pos = this.PointToScreen(e.Location);
//int y = Math.Max((pos.Y - windowOffset.Y), Screen.PrimaryScreen.WorkingArea.Y);
//y = Math.Min(y, (Screen.PrimaryScreen.WorkingArea.Y + Screen.PrimaryScreen.WorkingArea.Height) - this.Height);
//this.Parent.Location = new Point(Screen.PrimaryScreen.WorkingArea.X, y);
}
}
}
}
+72
View File
@@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
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);
}
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
int tileWidth = (tileSize + margin);
int w = (int)Math.Floor(decimal.Divide(this.Width, tileWidth));
int h = (int)Math.Floor(decimal.Divide(this.Height, tileWidth));
this.GridSize = new Point(w, h);
}
public Point GridSize { get; protected set; }
public Point GetTileCoord(Point location) => this.GetTileCoord(location.X, location.Y);
public Point GetTileCoord(int posX, int posY)
{
int w = (tileSize + margin);
int x = (int)Math.Round(decimal.Divide(posX, w));
int y = (int)Math.Round(decimal.Divide(posY, w));
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 w = (tileSize + margin);
int x = (int)Math.Round(decimal.Divide(posX, w));
int y = (int)Math.Round(decimal.Divide(posY, w));
if (x < 0) x = 0;
if (y < 0) y = 0;
return new Point((x * w), (y * w));
}
}
}
+1 -1
View File
@@ -71,7 +71,7 @@
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.label1);
this.Controls.Add(this.pictureBox1);
this.MinimumSize = new System.Drawing.Size(40, 40);
this.MinimumSize = new System.Drawing.Size(100, 40);
this.Name = "TitlePanel";
this.Size = new System.Drawing.Size(697, 40);
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
+4 -4
View File
@@ -12,7 +12,7 @@ namespace AppLauncher.Windows.Forms
{
public partial class TitlePanel : UserControl
{
private bool windowDragging = false;
private bool isDragging = false;
private Point windowOffset = new Point();
public TitlePanel()
@@ -49,18 +49,18 @@ namespace AppLauncher.Windows.Forms
return;
}
windowDragging = true;
isDragging = true;
windowOffset = e.Location;
}
protected void parentForm_MouseUp(object sender, MouseEventArgs e)
{
windowDragging = false;
isDragging = false;
}
protected void parentForm_MouseMove(object sender, MouseEventArgs e)
{
if (windowDragging)
if (isDragging)
{
Point pos = this.PointToScreen(e.Location);