ハニカム パターンを描画し、マウス移動で各セル (行、列) を認識する必要があります。
これが私がグラフを生成する方法です。
protected override void GenerateGridBitmap()
{
if (_circleGrid != null)
{
_circleGrid.Dispose();
_circleGrid = null;
}
Bitmap _texture = new Bitmap(circleSize, circleSize);
using (Graphics g = Graphics.FromImage(_texture))
{
g.SmoothingMode = SmoothingMode.HighQuality;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
Rectangle r = new Rectangle(0, 0, circleSize, circleSize);
g.DrawEllipse(Pens.Black, r);
}
Bitmap rowBlock = new Bitmap(CanvasSize.Width - (circleSize/ 2), circleSize);
using (Brush b = new TextureBrush(_texture))
{
using (Graphics g = Graphics.FromImage(rowBlock))
{
g.CompositingQuality = CompositingQuality.HighQuality;
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.SmoothingMode = SmoothingMode.HighQuality;
g.FillRectangle(b, new Rectangle(new Point(0, 0), rowBlock.Size));
}
}
//rowBlock.Save("rowblock.bmp");
_circleGrid = new Bitmap(CanvasSize.Width, CanvasSize.Height);
using (Graphics g = Graphics.FromImage(_circleGrid))
{
g.CompositingQuality = CompositingQuality.HighQuality;
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.SmoothingMode = SmoothingMode.HighQuality;
int x, y;
for (int i = 0; i < rows; i++)
{
x = 0;
if (i % 2 != 0)
x = (circleSize/ 2);
y = (i * circleSize);
if (i != 0)
{
y -= (VERTICAL_PIXEL_OFFSET * i);
}
g.DrawImage(rowBlock, x, y);
//g.DrawImage(DrawCodedCrystal(i,rowBlock), x, y);
Console.WriteLine(i);
}
}
_circleGrid.Save("grid.bmp");
Console.WriteLine(_circleGrid.Size);
_texture.Dispose();
_texture = null;
rowBlock.Dispose();
rowBlock = null;
}
これは、グラフの座標を取得するために行っていることです。しかし問題は、列を完全に取得できることです。しかし、行については、計算に小さな違いがあると思います。たとえば。99 行では、(1/4) 円は {row 98} と表示され、残りの円は {row 99} と表示されます。行数が増えると偏差が大きくなります。
protected override CanvasCell GetCanvasCellAt(int x, int y)
{
Rectangle rect = GetImageViewPort();
Point pt = new Point(x, y);
CanvasCell c = new CanvasCell() { Row = -1, Column = -1 };
if (rect.Contains(pt))
{
double zoomedCircleSize = CircleSize * ZoomFactor;
Point p = pt;// PointToClient(new Point(x, y));
p.X -= (int)(rect.X + (AutoScrollPosition.X) );
p.Y -= (int)(rect.Y + (AutoScrollPosition.Y));
int row = (int)((p.Y) / (zoomedCircleSize));
//row = (int)((p.Y + (row * ZoomFactor)) / zoomedCircleSize);
int col;
if (row % 2 != 0)
{
if (p.X >= 0 && p.X < (zoomedCircleSize / 2))
{
col = -1;
}
else
col = (int)((p.X - (zoomedCircleSize / 2)) / zoomedCircleSize);
}
else
{
if (p.X > (zoomedCircleSize * cols))
{
col = -1;
}
else
{
col = (int)((p.X) / zoomedCircleSize);
}
}
//if (!GetRectangle(row, col).ContainsWithInBoundingCircle(p))
//{
// c.Column = -1;
// c.Row = -1;
//}
//else
{
c.Column = col;
c.Row = row;
}
}
//
return c;
}
私の問題を明確に説明できたことを願っています。
編集: VERTICAL_PIXEL_OFFSET は 1 で、円のサイズは 16 です