Blame mono/Assistance/InputModifierAssistants.cs

1d3aae
using System;
1d3aae
using System.Diagnostics;
1d3aae
using System.Collections.Generic;
1d3aae
1d3aae
namespace Assistance {
ed66f8
	public class InputModifierAssistants: InputManager.Modifier {
1d3aae
		public readonly Workarea workarea;
0f2bf8
		public readonly List<guideline> shownGuidelines = new List<guideline>();</guideline></guideline>
0f2bf8
				
ed66f8
		public InputModifierAssistants(Workarea workarea)
ed66f8
			{ this.workarea = workarea; }
1d3aae
		
ed66f8
		public class Modifier: Track.Modifier {
1d3aae
			public Modifier(Track.Handler handler):
1d3aae
				base(handler) { }
1d3aae
			
1d3aae
			public InputManager.KeyPoint.Holder holder = null;
1d3aae
			public List<guideline> guidelines = new List<guideline>();</guideline></guideline>
1d3aae
			
702257
			public override Track.Point calcPoint(double originalIndex) {
702257
				Track.Point p = base.calcPoint(originalIndex);
1d3aae
				return guidelines.Count > 0 ? guidelines[0].transformPoint(p) : p;
1d3aae
			}
1d3aae
		}
1d3aae
589f9a
		public override void modify(Track track, InputManager.KeyPoint keyPoint, List<track> outTracks) {
1d3aae
			Track subTrack;
1d3aae
			Modifier modifier;
1d3aae
			
1d3aae
			if (track.handler == null) {
72d2fd
				if (track.isEmpty)
1d3aae
					return;
1d3aae
ed66f8
				track.handler = new Track.Handler(this, track);
ed66f8
				modifier = new Modifier(track.handler);
72d2fd
				workarea.getGuidelines(modifier.guidelines, track.getFirst().position);
1d3aae
				
1d3aae
				subTrack = new Track(modifier);
1d3aae
				track.handler.tracks.Add(subTrack);
1d3aae
				
1d3aae
				if (modifier.guidelines.Count > 1) {
1d3aae
					modifier.holder = keyPoint.hold();
1d3aae
					outTracks.Add(subTrack);
1d3aae
					return;
1d3aae
				}
1d3aae
			}
1d3aae
			
1d3aae
			subTrack = track.handler.tracks[0];
1d3aae
			modifier = (Modifier)subTrack.modifier;
1d3aae
			outTracks.Add(subTrack);
1d3aae
			
72d2fd
			if (!track.wasChanged)
1d3aae
				return;
1d3aae
			
1d3aae
			// remove points
72d2fd
			int start = track.count - track.pointsAdded;
1d3aae
			if (start < 0) start = 0;
72d2fd
			subTrack.truncate(start);
1d3aae
			
72d2fd
			bool trackIsLong = !track.isEmpty && (track.getLast().length >= Guideline.maxLenght || track.isFinished());
1d3aae
			if (!trackIsLong && modifier.holder != null && !modifier.holder.isHolded && modifier.holder.available)
1d3aae
				modifier.holder.reuse();
1d3aae
			
1d3aae
			// select guideline
1d3aae
			if (modifier.holder != null && modifier.holder.isHolded) {
1d3aae
				Guideline guideline = Guideline.findBest(modifier.guidelines, track);
0f2bf8
				if (guideline != null && guideline != modifier.guidelines[0]) {
1d3aae
					modifier.guidelines[ modifier.guidelines.IndexOf(guideline) ] = modifier.guidelines[0];
1d3aae
					modifier.guidelines[0] = guideline;
1d3aae
					start = 0;
72d2fd
					subTrack.truncate(0);
1d3aae
				}
1d3aae
				if (trackIsLong)
1d3aae
					modifier.holder.release();
1d3aae
			}
1d3aae
			
1d3aae
			// add points
72d2fd
			for(int i = start; i < track.count; ++i) {
72d2fd
				double di = (double)i;
72d2fd
				Track.Point p = modifier.calcPoint(di);
72d2fd
				subTrack.add(p);
72d2fd
			}
0f2bf8
			
72d2fd
			track.resetCounters();
1d3aae
		}
0f2bf8
0f2bf8
		public override void drawHover(Cairo.Context context, Point hover) {
0f2bf8
			workarea.getGuidelines(shownGuidelines, hover);
0f2bf8
			foreach(Guideline guideline in shownGuidelines)
0f2bf8
				guideline.draw(context);
0f2bf8
			shownGuidelines.Clear();
0f2bf8
		}
0f2bf8
				
0f2bf8
		public override void drawTrack(Cairo.Context context, Track track) {
b9e5e0
			if (track.handler == null) return;
b9e5e0
			Track subTrack = track.handler.tracks[0];
72d2fd
			if (!subTrack.isEmpty)
702257
				drawHover(context, subTrack.getLast().position);
b9e5e0
		}
1d3aae
	}
1d3aae
}
1d3aae