Blame mono/Assistance/Workarea.cs

Ivan Mahonin cfceb0
using System;
Ivan Mahonin cfceb0
using System.Collections.Generic;
Ivan Mahonin cfceb0
using System.Linq;
Ivan Mahonin cfceb0
Ivan Mahonin cfceb0
namespace Assistance {
Ivan Mahonin cfceb0
	public class Workarea {
Ivan Mahonin 726e8a
		public readonly Document document;
Ivan Mahonin b9e5e0
		public readonly InputManager inputManager;
Ivan Mahonin b9e5e0
		
Ivan Mahonin b9e5e0
		private readonly InputModifierTangents modifierTangents;
Ivan Mahonin ed66f8
		private readonly InputModifierAssistants modifierAssistants;
Ivan Mahonin ed66f8
		private readonly InputModifierSegmentation modifierSegmentation;
Ivan Mahonin cfceb0
		
Ivan Mahonin 726e8a
		public Workarea() {
Ivan Mahonin 726e8a
			document = new Document(this);
Ivan Mahonin b9e5e0
			inputManager = new InputManager(this);
Ivan Mahonin b9e5e0
			
Ivan Mahonin b9e5e0
			modifierTangents = new InputModifierTangents();
Ivan Mahonin ed66f8
			modifierAssistants = new InputModifierAssistants(this);
Ivan Mahonin ed66f8
			modifierSegmentation = new InputModifierSegmentation();
Ivan Mahonin b9e5e0
		}
Ivan Mahonin b9e5e0
		
Ivan Mahonin b9e5e0
		public Tool getTool()
Ivan Mahonin b9e5e0
			{ return inputManager.getTool(); }
Ivan Mahonin b9e5e0
			
Ivan Mahonin b9e5e0
		public void setTool(Tool tool, bool force = false) {
Ivan Mahonin b9e5e0
			if (getTool() != tool || force) {
Ivan Mahonin b9e5e0
				inputManager.deactivate();
Ivan Mahonin b9e5e0
				inputManager.clearModifiers();
Ivan Mahonin b9e5e0
				if (tool != null) {
Ivan Mahonin b9e5e0
					Tool.ModifierTypes types = tool.getAvailableModifierTypes();
Ivan Mahonin ed66f8
					if ((Tool.ModifierTypes.Tangents & types) != 0)
Ivan Mahonin b9e5e0
						inputManager.addModifier(modifierTangents);
Ivan Mahonin ed66f8
					if ((Tool.ModifierTypes.Guideline & types) != 0)
Ivan Mahonin ed66f8
						inputManager.addModifier(modifierAssistants);
Ivan Mahonin b9e5e0
					if ((Tool.ModifierTypes.Multiline & types) != 0)
Ivan Mahonin b9e5e0
						foreach(Modifier modifier in document.modifiers)
Ivan Mahonin b9e5e0
							inputManager.addModifier(modifier);
Ivan Mahonin ed66f8
					if ((Tool.ModifierTypes.Segmentation & types) != 0)
Ivan Mahonin ed66f8
						inputManager.addModifier(modifierSegmentation);
Ivan Mahonin b9e5e0
				}
Ivan Mahonin b9e5e0
				inputManager.setTool(tool);
Ivan Mahonin b9e5e0
				inputManager.activate();
Ivan Mahonin b9e5e0
			}
Ivan Mahonin 726e8a
		}
Ivan Mahonin 0f2bf8
		
Ivan Mahonin 0f2bf8
		public void updateModifiers()
Ivan Mahonin 0f2bf8
			{ setTool(getTool(), true); }
Ivan Mahonin 726e8a
Ivan Mahonin cfceb0
		public ActivePoint findPoint(Point position) {
Ivan Mahonin 726e8a
			foreach(ActivePoint point in document.points.Reverse<ActivePoint>())
Ivan Mahonin cfceb0
				if (point.isInside(position))
Ivan Mahonin cfceb0
					return point;
Ivan Mahonin cfceb0
			return null;
Ivan Mahonin cfceb0
		}
Ivan Mahonin cfceb0
Ivan Mahonin cfceb0
		public void getGuidelines(List<Guideline> outGuidelines, Point target) {
Ivan Mahonin 726e8a
			foreach(Assistant assistant in document.assistants)
Ivan Mahonin cfceb0
				assistant.getGuidelines(outGuidelines, target);
Ivan Mahonin cfceb0
		}
Ivan Mahonin cfceb0
Ivan Mahonin 0f2bf8
		public void draw(Cairo.Context context, List<Point> hovers, ActivePoint activePoint) {
Ivan Mahonin cfceb0
			// canvas
Ivan Mahonin b82ef4
			document.canvas.draw(context);
Ivan Mahonin cfceb0
Ivan Mahonin b9e5e0
			// input manager
Ivan Mahonin 0f2bf8
			inputManager.draw(context, hovers);
Ivan Mahonin cfceb0
			
Ivan Mahonin 72b17c
			// modifiers
Ivan Mahonin 726e8a
			foreach(Modifier modifier in document.modifiers)
Ivan Mahonin b82ef4
				modifier.draw(context);
Ivan Mahonin 72b17c
Ivan Mahonin cfceb0
			// assistants
Ivan Mahonin 726e8a
			foreach(Assistant assistant in document.assistants)
Ivan Mahonin b82ef4
				assistant.draw(context);
Ivan Mahonin cfceb0
Ivan Mahonin 72b17c
			// active points
Ivan Mahonin 726e8a
			foreach(ActivePoint point in document.points)
Ivan Mahonin b82ef4
				point.draw(context, activePoint == point);
Ivan Mahonin cfceb0
		}
Ivan Mahonin cfceb0
	}
Ivan Mahonin cfceb0
}
Ivan Mahonin cfceb0