Blame mono/Assistance/ActivePoint.cs

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 Mode {
ebcc4f
			Common = 0,
ebcc4f
			Active = 1
ebcc4f
		}
ebcc4f
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;
ebcc4f
		public static readonly Pen[] pens = new Pen[] { Pens.Gray, Pens.Blue };
ebcc4f
		public static readonly Brush[] brushes = new Brush[] { Brushes.LightGray, 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
ebcc4f
		private void drawCircle(Graphics g, Mode mode) {
ebcc4f
			g.DrawEllipse(pens[(int)mode], (float)(position.x - radius), (float)(position.y - radius), (float)(2.0*radius), (float)(2.0*radius));
ebcc4f
		}
ebcc4f
ebcc4f
		private void fillCircle(Graphics g, Mode mode) {
ebcc4f
			g.FillEllipse(brushes[(int)mode], (float)(position.x - radius), (float)(position.y - radius), (float)(2.0*radius), (float)(2.0*radius));
ebcc4f
		}
ebcc4f
ebcc4f
		private void drawCross(Graphics g, Mode mode) {
ebcc4f
			g.DrawLine(pens[(int)mode], (float)(position.x - crossSize), (float)position.y, (float)(position.x + crossSize), (float)position.y);
ebcc4f
			g.DrawLine(pens[(int)mode], (float)position.x, (float)(position.y - crossSize), (float)position.x, (float)(position.y + crossSize));
ebcc4f
		}
ebcc4f
ebcc4f
		public void draw(Graphics g, Mode mode) {
ebcc4f
			switch(type) {
ebcc4f
			case Type.Circle:
ebcc4f
				drawCircle(g, mode);
ebcc4f
				break;
ebcc4f
			case Type.CircleFill:
ebcc4f
				fillCircle(g, mode);
ebcc4f
				drawCircle(g, mode);
ebcc4f
				break;
ebcc4f
			case Type.CircleCross:
ebcc4f
				drawCircle(g, mode);
ebcc4f
				drawCross(g, mode);
ebcc4f
				break;
ebcc4f
			}
ebcc4f
		}
ebcc4f
	}
ebcc4f
}
ebcc4f