Blame mono/Assistance/Workarea.cs

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