mirror of
https://github.com/haven1433/HexManiacAdvance.git
synced 2026-05-23 13:57:01 -05:00
performance improvement: only clip when you absolutely have to
bugfix: typing < or ^ followed by cursor movement should redraw everything
This commit is contained in:
parent
923330d1c7
commit
e9d91a7fbb
|
|
@ -111,16 +111,7 @@ namespace HavenSoft.Gen3Hex.Core.ViewModels {
|
|||
|
||||
private void ClearActiveEditBeforeSelectionChanges(object sender, Point location) {
|
||||
if (location.X >= 0 && location.X < scroll.Width && location.Y >= 0 && location.Y < scroll.Height) {
|
||||
var element = currentView[location.X, location.Y];
|
||||
if (element.Format is UnderEdit underEdit) {
|
||||
if (underEdit.CurrentText.StartsWith(AnchorStart.ToString())) {
|
||||
currentView[location.X, location.Y] = new HexElement(element.Value, underEdit.Edit(" "));
|
||||
if (!TryCompleteEdit(location)) ClearEdits(location);
|
||||
} else {
|
||||
currentView[location.X, location.Y] = new HexElement(element.Value, underEdit.OriginalFormat);
|
||||
NotifyCollectionChanged(ResetArgs);
|
||||
}
|
||||
}
|
||||
ClearEdits(location);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -518,7 +518,7 @@ namespace HavenSoft.Gen3Hex.Tests {
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public void ArrowMovementWhileTypingAnchorInsertsAnchor() {
|
||||
public void ArrowMovementWhileTypingAnchorRevertsChange() {
|
||||
var buffer = Enumerable.Repeat((byte)0xFF, 0x200).ToArray();
|
||||
var model = new PokemonModel(buffer);
|
||||
var viewPort = new ViewPort(new LoadedFile("test.txt", buffer), model) { Width = 0x10, Height = 0x10 };
|
||||
|
|
@ -527,8 +527,7 @@ namespace HavenSoft.Gen3Hex.Tests {
|
|||
|
||||
viewPort.SelectionStart = new Point(1, 1);
|
||||
|
||||
var format = viewPort[0, 0].Format;
|
||||
Assert.IsType<Anchor>(format);
|
||||
Assert.IsType<None>(viewPort[0, 0].Format);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -680,5 +679,21 @@ namespace HavenSoft.Gen3Hex.Tests {
|
|||
|
||||
Assert.Equal(0x100, ((Pointer)viewPort[0, 0].Format).Destination);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void StartingPointerEditAndThenMovingClearsAllEditedCells() {
|
||||
var data = new byte[0x200];
|
||||
var model = new PokemonModel(data);
|
||||
var viewPort = new ViewPort(new LoadedFile("test.txt", data), model) { Width = 0x10, Height = 0x10 };
|
||||
|
||||
viewPort.Edit("<");
|
||||
viewPort.SelectionStart = new Point(2, 2);
|
||||
|
||||
for (int x = 0; x < 0x10; x++) {
|
||||
for (int y = 0; y < 0x10; y++) {
|
||||
Assert.IsNotType<UnderEdit>(viewPort[x, y].Format);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -214,13 +214,12 @@ namespace HavenSoft.Gen3Hex.WPF.Controls {
|
|||
if (ViewPort == null) return;
|
||||
drawingContext.DrawRectangle(Solarized.Theme.Background, null, new Rect(0, 0, ActualWidth, ActualHeight));
|
||||
|
||||
var visitor = new FormatDrawer(drawingContext);
|
||||
var visitor = new FormatDrawer(drawingContext, ViewPort.Width, ViewPort.Height);
|
||||
|
||||
var topLeft = new ScreenPoint(0, 0);
|
||||
var topRight = new ScreenPoint(CellWidth, 0);
|
||||
var bottomLeft = new ScreenPoint(0, CellHeight);
|
||||
var bottomRight = new ScreenPoint(CellWidth, CellHeight);
|
||||
var rectangleGeometry = new RectangleGeometry(new Rect(topLeft, bottomRight));
|
||||
var borderPen = new Pen(Solarized.Brushes.Green, 1);
|
||||
|
||||
// draw matrix
|
||||
|
|
@ -256,10 +255,9 @@ namespace HavenSoft.Gen3Hex.WPF.Controls {
|
|||
visitor.MouseIsOverCurrentFormat = mouseOverPoint.Equals(new ModelPoint(x, y));
|
||||
var element = ViewPort[x, y];
|
||||
drawingContext.PushTransform(new TranslateTransform(x * CellWidth, y * CellHeight));
|
||||
drawingContext.PushClip(rectangleGeometry);
|
||||
visitor.Position = new ModelPoint(x, y);
|
||||
element.Format.Visit(visitor, element.Value);
|
||||
drawingContext.Pop();
|
||||
drawingContext.Pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,11 +14,16 @@ namespace HavenSoft.Gen3Hex.WPF.Implementations {
|
|||
|
||||
private static readonly List<FormattedText> noneVisualCache = new List<FormattedText>();
|
||||
|
||||
private readonly int modelWidth, modelHeight;
|
||||
|
||||
private readonly DrawingContext context;
|
||||
private readonly Geometry rectangleGeometry = new RectangleGeometry(new Rect(new Point(0, 0), new Point(HexContent.CellWidth, HexContent.CellHeight)));
|
||||
|
||||
public bool MouseIsOverCurrentFormat { get; set; }
|
||||
|
||||
public FormatDrawer(DrawingContext drawingContext) => context = drawingContext;
|
||||
public HavenSoft.Gen3Hex.Core.Models.Point Position { get; set; }
|
||||
|
||||
public FormatDrawer(DrawingContext drawingContext, int width, int height) => (context, modelWidth, modelHeight) = (drawingContext, width, height);
|
||||
|
||||
public static void ClearVisualCaches() {
|
||||
noneVisualCache.Clear();
|
||||
|
|
@ -72,7 +77,13 @@ namespace HavenSoft.Gen3Hex.WPF.Implementations {
|
|||
brush,
|
||||
1.0);
|
||||
|
||||
context.DrawText(text, new Point(CellTextOffset.X + xOffset, CellTextOffset.Y));
|
||||
if (dataFormat.Position < Position.X || Position.X - dataFormat.Position > modelWidth - 4) {
|
||||
context.PushClip(rectangleGeometry);
|
||||
context.DrawText(text, new Point(CellTextOffset.X + xOffset, CellTextOffset.Y));
|
||||
context.Pop();
|
||||
} else if (dataFormat.Position == 2) {
|
||||
context.DrawText(text, new Point(CellTextOffset.X + xOffset, CellTextOffset.Y));
|
||||
}
|
||||
}
|
||||
|
||||
private static readonly Geometry Triangle = Geometry.Parse("M0,5 L3,0 6,5");
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user