Ejemplo n.º 1
0
		Rect GetCaretRect(HexViewLine line, bool drawOverwriteMode, HexColumnType column, HexCell cell, int cellPosition) {
			if (cell == null)
				return new Rect();

			int linePosition = cell.CellSpan.Start + Math.Max(0, Math.Min(cell.CellSpan.Length - 1, cellPosition));
			if (hexCaret.CurrentPosition.ActiveColumn != column) {
				var r = ToRect(line.GetNormalizedTextBounds(cell.CellSpan));
				return new Rect(r.X, r.Bottom - INACTIVE_CARET_HEIGHT, r.Width, INACTIVE_CARET_HEIGHT);
			}
			else if (drawOverwriteMode) {
				var textBounds = line.GetExtendedCharacterBounds(linePosition);
				var left = textBounds.Left;
				var top = line.TextTop;
				var width = textBounds.Width;
				var height = line.TextHeight;
				return new Rect(left, top, width, height);
			}
			else {
				double left;
				if (linePosition != 0 && linePosition <= line.BufferLine.Text.Length)
					left = line.GetExtendedCharacterBounds(linePosition - 1).Trailing;
				else
					left = line.GetExtendedCharacterBounds(linePosition).Leading;
				var top = line.TextTop;
				var width = SystemParameters.CaretWidth;
				var height = line.TextHeight;
				return new Rect(left, top, width, height);
			}
		}
		IList<VSTF.TextBounds> GetTextBounds(HexViewLine line) {
			if (lineSpan.IsTextSpan) {
				if (lineSpan.TextSpan.Value.Length == 0) {
					if (line.BufferSpan.Contains(lineSpan.BufferSpan)) {
						var bounds = line.GetCharacterBounds(lineSpan.TextSpan.Value.Start);
						// It's just a point, so use zero width
						bounds = new VSTF.TextBounds(bounds.Leading, bounds.Top, 0, bounds.Height, bounds.TextTop, bounds.TextHeight);
						return new VSTF.TextBounds[] { bounds };
					}
					return Array.Empty<VSTF.TextBounds>();
				}
				else
					return line.GetNormalizedTextBounds(lineSpan);
			}
			else {
				var fullSpan = lineSpan.BufferSpan;
				if (fullSpan.Length == 0) {
					if (line.BufferSpan.Contains(fullSpan))
						return line.GetNormalizedTextBounds(fullSpan, lineSpan.SelectionFlags.Value);
					return Array.Empty<VSTF.TextBounds>();
				}
				else
					return line.GetNormalizedTextBounds(lineSpan);
			}
		}
Ejemplo n.º 3
0
		IEnumerable<KeyValuePair<HexColumnType, Rect>> GetRectanglePositions(HexViewLine line) {
			var column = wpfHexView.Caret.Position.Position.ActiveColumn;
			if (!line.BufferLine.IsColumnPresent(column))
				yield break;
			var span = line.BufferLine.GetSpan(column, onlyVisibleCells: false);
			var rect = GetBounds(line.GetNormalizedTextBounds(span));
			if (rect == null || rect.Value.Width <= 0)
				yield break;
			yield return new KeyValuePair<HexColumnType, Rect>(column, new Rect(rect.Value.X, wpfHexView.ViewportTop, rect.Value.Width, wpfHexView.ViewportHeight));
		}
Ejemplo n.º 4
0
		bool Intersects(HexBufferSpan fullSpan, HexViewLine line, Rect rect) {
			var span = fullSpan.Intersection(line.BufferSpan);
			if (span == null || span.Value.Length == 0)
				return false;
			var allBounds = line.GetNormalizedTextBounds(span.Value, HexSpanSelectionFlags.Selection);
			if (allBounds.Count == 0)
				return false;
			double left = double.MaxValue, right = double.MinValue, top = double.MaxValue, bottom = double.MinValue;
			foreach (var bounds in allBounds) {
				left = Math.Min(left, bounds.Left);
				right = Math.Max(right, bounds.Right);
				top = Math.Min(top, bounds.TextTop);
				bottom = Math.Max(bottom, bounds.TextBottom);
			}
			left -= wpfHexView.ViewportLeft;
			top -= wpfHexView.ViewportTop;
			right -= wpfHexView.ViewportLeft;
			bottom -= wpfHexView.ViewportTop;
			bool b = left <= right && top <= bottom;
			Debug.Assert(b);
			if (!b)
				return false;
			var r = new Rect(left, top, right - left, bottom - top);
			return r.IntersectsWith(rect);
		}