|
|
ebcc4f |
using System;
|
|
|
ebcc4f |
using System.Drawing;
|
|
|
ebcc4f |
using System.Drawing.Imaging;
|
|
|
ebcc4f |
using System.Collections.Generic;
|
|
|
ebcc4f |
|
|
|
ebcc4f |
namespace Assistance {
|
|
|
ebcc4f |
public class ActivePoint {
|
|
|
ebcc4f |
public enum Type {
|
|
|
ebcc4f |
Circle,
|
|
|
ebcc4f |
CircleFill,
|
|
|
ebcc4f |
CircleCross,
|
|
|
ebcc4f |
};
|
|
|
ebcc4f |
|
|
|
ebcc4f |
public static readonly double radius = 10.0;
|
|
|
ebcc4f |
public static readonly double crossSize = 1.2*radius;
|
|
|
38ad69 |
public static readonly Pen pen = Pens.Gray;
|
|
|
38ad69 |
public static readonly Brush brush = Brushes.LightGray;
|
|
|
38ad69 |
public static readonly Pen penActive = Pens.Blue;
|
|
|
38ad69 |
public static readonly Brush brushActive = Brushes.LightBlue;
|
|
|
ebcc4f |
|
|
|
b1ff53 |
public readonly Workarea canvas;
|
|
|
ebcc4f |
public readonly Assistant assistant;
|
|
|
ebcc4f |
public readonly Type type;
|
|
|
ebcc4f |
public Point position;
|
|
|
ebcc4f |
|
|
|
ebcc4f |
public ActivePoint(Assistant assistant, Type type, Point position = new Point()) {
|
|
|
ebcc4f |
this.canvas = assistant.canvas;
|
|
|
ebcc4f |
this.assistant = assistant;
|
|
|
ebcc4f |
this.type = type;
|
|
|
ebcc4f |
this.position = position;
|
|
|
ebcc4f |
canvas.points.Add(this);
|
|
|
ebcc4f |
assistant.points.Add(this);
|
|
|
ebcc4f |
}
|
|
|
ebcc4f |
|
|
|
ebcc4f |
public bool isInside(Point p) {
|
|
|
ebcc4f |
return (position - p).lenSqr() <= radius*radius;
|
|
|
ebcc4f |
}
|
|
|
ebcc4f |
|
|
|
ebcc4f |
public void bringToFront() {
|
|
|
ebcc4f |
assistant.bringToFront();
|
|
|
ebcc4f |
assistant.points.Remove(this);
|
|
|
ebcc4f |
assistant.points.Add(this);
|
|
|
ebcc4f |
canvas.points.Remove(this);
|
|
|
ebcc4f |
canvas.points.Add(this);
|
|
|
ebcc4f |
}
|
|
|
ebcc4f |
|
|
|
38ad69 |
private Pen getPen(bool active) {
|
|
|
38ad69 |
return active ? penActive : pen;
|
|
|
38ad69 |
}
|
|
|
38ad69 |
|
|
|
38ad69 |
private Brush getBrush(bool active) {
|
|
|
38ad69 |
return active ? brushActive : brush;
|
|
|
38ad69 |
}
|
|
|
38ad69 |
|
|
|
38ad69 |
private void drawCircle(Graphics g, bool active) {
|
|
|
38ad69 |
g.DrawEllipse(getPen(active), (float)(position.x - radius), (float)(position.y - radius), (float)(2.0*radius), (float)(2.0*radius));
|
|
|
ebcc4f |
}
|
|
|
ebcc4f |
|
|
|
38ad69 |
private void fillCircle(Graphics g, bool active) {
|
|
|
38ad69 |
g.FillEllipse(getBrush(active), (float)(position.x - radius), (float)(position.y - radius), (float)(2.0*radius), (float)(2.0*radius));
|
|
|
ebcc4f |
}
|
|
|
ebcc4f |
|
|
|
38ad69 |
private void drawCross(Graphics g, bool active) {
|
|
|
38ad69 |
g.DrawLine(getPen(active), (float)(position.x - crossSize), (float)position.y, (float)(position.x + crossSize), (float)position.y);
|
|
|
38ad69 |
g.DrawLine(getPen(active), (float)position.x, (float)(position.y - crossSize), (float)position.x, (float)(position.y + crossSize));
|
|
|
ebcc4f |
}
|
|
|
ebcc4f |
|
|
|
38ad69 |
public void draw(Graphics g, bool active = false) {
|
|
|
ebcc4f |
switch(type) {
|
|
|
ebcc4f |
case Type.Circle:
|
|
|
38ad69 |
drawCircle(g, active);
|
|
|
ebcc4f |
break;
|
|
|
ebcc4f |
case Type.CircleFill:
|
|
|
38ad69 |
fillCircle(g, active);
|
|
|
38ad69 |
drawCircle(g, active);
|
|
|
ebcc4f |
break;
|
|
|
ebcc4f |
case Type.CircleCross:
|
|
|
38ad69 |
drawCircle(g, active);
|
|
|
38ad69 |
drawCross(g, active);
|
|
|
ebcc4f |
break;
|
|
|
ebcc4f |
}
|
|
|
ebcc4f |
}
|
|
|
ebcc4f |
}
|
|
|
ebcc4f |
}
|
|
|
ebcc4f |
|