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;
cfceb0
		
726e8a
		public Workarea() {
726e8a
			document = new Document(this);
726e8a
		}
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
b82ef4
		public void draw(Cairo.Context context, ActivePoint activePoint, Point target, Track track) {
cfceb0
			// canvas
b82ef4
			document.canvas.draw(context);
cfceb0
cfceb0
			// guidelines and track
cfceb0
			List<guideline> guidelines = new List<guideline>();</guideline></guideline>
cfceb0
			if (track != null && track.points.Count > 0) {
72b17c
				Guideline guideline;
72b17c
				Track modifiedTrack = modifyTrackByAssistant(track, out guideline);
72b17c
				
b82ef4
				getGuidelines(guidelines, modifiedTrack.transform(track.points.Last()).point);
b82ef4
				foreach(Guideline gl in guidelines)
b82ef4
					gl.draw(context);
e6a405
b82ef4
				track.draw(context, true);
b82ef4
				if (guideline != null) guideline.draw(context, true);
72b17c
				
72b17c
				List<track> modifiedTracks = modifyTrackByModifiers(modifiedTrack);
72b17c
				rebuildTracks(modifiedTracks);
72b17c
				foreach(Track t in modifiedTracks)
b82ef4
					t.draw(context);
cfceb0
			} else {
cfceb0
				getGuidelines(guidelines, target);
cfceb0
				foreach(Guideline guideline in guidelines)
b82ef4
					guideline.draw(context);
cfceb0
			}
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
	
72b17c
		public Track modifyTrackByAssistant(Track track, out Guideline guideline) {
72b17c
			guideline = null;
cfceb0
			if (track.points.Count < 1)
72b17c
				return track.createChild(Geometry.noTransform);
72b17c
cfceb0
			List<guideline> guidelines = new List<guideline>();</guideline></guideline>
b82ef4
			getGuidelines(guidelines, track.points[0].point);
72b17c
			guideline = Guideline.findBest(guidelines, track);
cfceb0
			if (guideline == null)
72b17c
				return track.createChild(Geometry.noTransform);
72b17c
			return track.createChild(guideline.transformPoint);
cfceb0
		}
cfceb0
		
72b17c
		public List<track> modifyTrackByModifiers(Track track) {
72b17c
			List<track> tracks = new List<track>() { track };
726e8a
			foreach(Modifier modifier in document.modifiers)
72b17c
				tracks = modifier.modify(tracks);
72b17c
			return tracks;
72b17c
		}
72b17c
72b17c
		public void rebuildTracks(List<track> tracks) {
72b17c
			foreach(Track track in tracks)
72b17c
				track.rebuild();
72b17c
		}
72b17c
72b17c
		public List<track> modifyTrack(Track track) {
72b17c
			Guideline guideline;
72b17c
			List<track> tracks = modifyTrackByModifiers(
72b17c
				modifyTrackByAssistant(track, out guideline) );
72b17c
			rebuildTracks(tracks);
72b17c
			return tracks;
72b17c
		}
72b17c
				
cfceb0
		public void paintTrack(Track track) {
72b17c
			List<track> tracks = modifyTrack(track);
72b17c
			foreach(Track t in tracks)
726e8a
				document.canvas.paintTrack(t);
cfceb0
		}
cfceb0
	}
cfceb0
}
cfceb0