Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix caret cursor #212

Merged
merged 10 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions src/Consolonia.Core/Drawing/DrawingContextImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,16 @@ public void DrawGeometry(IBrush brush, IPen pen, IGeometryImpl geometry)
if (sceneBrushContent != null) sceneBrushContent.Render(this, Matrix.Identity);
return;
}
case MoveConsoleCaretToPositionBrush:
{
Point head = r.TopLeft.Transform(Transform);
CurrentClip.ExecuteWithClipping(head,
() =>
{
_pixelBuffer.Set((PixelBufferCoordinate)head, pixel => pixel.Blend(new Pixel(true)));
});
return;
}
}

FillRectangleWithBrush(brush, pen, r);
Expand Down Expand Up @@ -458,6 +468,14 @@ private void DrawLineInternal(IPen pen, Line line)
return;
}

if (pen.Brush is MoveConsoleCaretToPositionBrush)
{
Point head = line.PStart.Transform(Transform);
CurrentClip.ExecuteWithClipping(head,
() => { _pixelBuffer.Set((PixelBufferCoordinate)head, pixel => pixel.Blend(new Pixel(true))); });
return;
}

DrawBoxLineInternal(pen, line, RectangleLinePosition.Unknown);
}

Expand Down Expand Up @@ -532,13 +550,6 @@ private void DrawBoxLineInternal(IPen pen, Line line, RectangleLinePosition line

Point head = line.PStart;

if (pen.Brush is MoveConsoleCaretToPositionBrush)
{
CurrentClip.ExecuteWithClipping(head,
() => { _pixelBuffer.Set((PixelBufferCoordinate)head, pixel => pixel.Blend(new Pixel(true))); });
return;
}

var extractColorCheckPlatformSupported = ExtractColorOrNullWithPlatformCheck(pen, out var lineStyle);
if (extractColorCheckPlatformSupported == null)
return;
Expand Down
29 changes: 7 additions & 22 deletions src/Consolonia.Themes/Templates/Controls/CaretControl.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,22 @@
<Setter.Value>
<ControlTemplate>
<Grid Background="{TemplateBinding Background}">
<TextBlock Width="1"
<Rectangle Name="PART_CaretLine"
Width="1"
Height="1"
HorizontalAlignment="Left"
VerticalAlignment="Top"
IsHitTestVisible="False"
Background="{DynamicResource ThemeActionBackgroundBrush}"
IsVisible="{TemplateBinding IsCaretShown}"
Margin="{TemplateBinding Padding}"
Tag="This TextBlock is a hack. Otherwise Line below does not get redrawn in CheckBox">
<!--<TextBlock.Background>
<drawing:ConsoleBrush Mode="Transparent"/>
</TextBlock.Background>-->
</TextBlock>
IsVisible="{TemplateBinding IsCaretShown}">
<Rectangle.Fill>
<drawing:MoveConsoleCaretToPositionBrush />
</Rectangle.Fill>
</Rectangle>
<ContentPresenter Name="PART_ContentPresenter"
ContentTemplate="{TemplateBinding ContentTemplate}"
Content="{TemplateBinding Content}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" />
<Line Margin="{TemplateBinding Padding}"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Name="PART_CaretLine"
Width="1"
Height="1"
IsHitTestVisible="False"
IsVisible="{TemplateBinding IsCaretShown}"
StrokeThickness="1">
<Line.Stroke>
<drawing:MoveConsoleCaretToPositionBrush />
</Line.Stroke>
</Line>
</Grid>
</ControlTemplate>
</Setter.Value>
Expand Down
Loading