This repository has been archived on 2024-08-06. You can view files and clone it, but cannot push or open issues or pull requests.
linear-app-launcher/Windows/Forms/TilePanelContainer.cs
2020-04-05 01:32:49 +01:00

73 lines
1.8 KiB
C#

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