Skip to content

Commit

Permalink
Merge branch 'master' into fix-win32-right-modifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
MarchingCube authored Dec 4, 2019
2 parents cede1eb + 800a5f8 commit 25aade0
Show file tree
Hide file tree
Showing 21 changed files with 351 additions and 218 deletions.
14 changes: 12 additions & 2 deletions native/Avalonia.Native/inc/avalonia-native.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,17 @@ enum AvnRawMouseEventType
RightButtonUp,
MiddleButtonDown,
MiddleButtonUp,
XButton1Down,
XButton1Up,
XButton2Down,
XButton2Up,
Move,
Wheel,
NonClientLeftButtonDown
NonClientLeftButtonDown,
TouchBegin,
TouchUpdate,
TouchEnd,
TouchCancel
};

enum AvnRawKeyEventType
Expand All @@ -112,7 +120,9 @@ enum AvnInputModifiers
Windows = 8,
LeftMouseButton = 16,
RightMouseButton = 32,
MiddleMouseButton = 64
MiddleMouseButton = 64,
XButton1MouseButton = 128,
XButton2MouseButton = 256
};

enum AvnWindowState
Expand Down
41 changes: 36 additions & 5 deletions native/Avalonia.Native/src/OSX/window.mm
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ @implementation AvnView
AvnFramebuffer _swRenderedFrameBuffer;
bool _queuedDisplayFromThread;
NSTrackingArea* _area;
bool _isLeftPressed, _isMiddlePressed, _isRightPressed, _isMouseOver;
bool _isLeftPressed, _isMiddlePressed, _isRightPressed, _isXButton1Pressed, _isXButton2Pressed, _isMouseOver;
NSEvent* _lastMouseDownEvent;
bool _lastKeyHandled;
}
Expand Down Expand Up @@ -942,9 +942,23 @@ - (void)mouseDown:(NSEvent *)event

- (void)otherMouseDown:(NSEvent *)event
{
_isMiddlePressed = true;
_lastMouseDownEvent = event;
[self mouseEvent:event withType:MiddleButtonDown];

switch(event.buttonNumber)
{
case 3:
_isMiddlePressed = true;
[self mouseEvent:event withType:MiddleButtonDown];
break;
case 4:
_isXButton1Pressed = true;
[self mouseEvent:event withType:XButton1Down];
break;
case 5:
_isXButton2Pressed = true;
[self mouseEvent:event withType:XButton2Down];
break;
}
}

- (void)rightMouseDown:(NSEvent *)event
Expand All @@ -962,8 +976,21 @@ - (void)mouseUp:(NSEvent *)event

- (void)otherMouseUp:(NSEvent *)event
{
_isMiddlePressed = false;
[self mouseEvent:event withType:MiddleButtonUp];
switch(event.buttonNumber)
{
case 3:
_isMiddlePressed = false;
[self mouseEvent:event withType:MiddleButtonUp];
break;
case 4:
_isXButton1Pressed = false;
[self mouseEvent:event withType:XButton1Up];
break;
case 5:
_isXButton2Pressed = false;
[self mouseEvent:event withType:XButton2Up];
break;
}
}

- (void)rightMouseUp:(NSEvent *)event
Expand Down Expand Up @@ -1062,6 +1089,10 @@ - (AvnInputModifiers)getModifiers:(NSEventModifierFlags)mod
rv |= MiddleMouseButton;
if (_isRightPressed)
rv |= RightMouseButton;
if (_isXButton1Pressed)
rv |= XButton1MouseButton;
if (_isXButton2Pressed)
rv |= XButton2MouseButton;

return (AvnInputModifiers)rv;
}
Expand Down
20 changes: 7 additions & 13 deletions src/Avalonia.Controls/Utils/BorderRenderHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,23 +90,17 @@ public void Render(DrawingContext context, Size size, Thickness borders, CornerR
{
var borderThickness = borders.Top;
var top = borderThickness * 0.5;
var cornerRadius = (float)Math.Max(0, radii.TopLeft - borderThickness - top);

if (background != null)
{
var topLeft = new Point(borders.Left, borders.Top);
var bottomRight = new Point(size.Width - borders.Right, size.Height - borders.Bottom);
var innerRect = new Rect(topLeft, bottomRight);
context.FillRectangle(background, innerRect, cornerRadius);
}
IPen pen = null;

if (borderBrush != null && borderThickness > 0)
if (borderThickness > 0)
{
var topLeft = new Point(top, top);
var bottomRight = new Point(size.Width - top, size.Height - top);
var outerRect = new Rect(topLeft, bottomRight);
context.DrawRectangle(new Pen(borderBrush, borderThickness), outerRect, (float)radii.TopLeft);
pen = new Pen(borderBrush, borderThickness);
}

var rect = new Rect(top, top, size.Width - borderThickness, size.Height - borderThickness);

context.DrawRectangle(background, pen, rect, radii.TopLeft, radii.TopLeft);
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/Avalonia.Input/IKeyboardDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public enum RawInputModifiers
LeftMouseButton = 16,
RightMouseButton = 32,
MiddleMouseButton = 64,
XButton1MouseButton = 128,
XButton2MouseButton = 256,
KeyboardMask = Alt | Control | Shift | Meta
}

Expand Down
16 changes: 16 additions & 0 deletions src/Avalonia.Input/MouseDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ int ButtonCount(PointerPointProperties props)
rv++;
if (props.IsRightButtonPressed)
rv++;
if (props.IsXButton1Pressed)
rv++;
if (props.IsXButton2Pressed)
rv++;
return rv;
}

Expand All @@ -142,6 +146,8 @@ private void ProcessRawEvent(RawPointerEventArgs e)
case RawPointerEventType.LeftButtonDown:
case RawPointerEventType.RightButtonDown:
case RawPointerEventType.MiddleButtonDown:
case RawPointerEventType.XButton1Down:
case RawPointerEventType.XButton2Down:
if (ButtonCount(props) > 1)
e.Handled = MouseMove(mouse, e.Timestamp, e.Root, e.Position, props, keyModifiers);
else
Expand All @@ -151,6 +157,8 @@ private void ProcessRawEvent(RawPointerEventArgs e)
case RawPointerEventType.LeftButtonUp:
case RawPointerEventType.RightButtonUp:
case RawPointerEventType.MiddleButtonUp:
case RawPointerEventType.XButton1Up:
case RawPointerEventType.XButton2Up:
if (ButtonCount(props) != 0)
e.Handled = MouseMove(mouse, e.Timestamp, e.Root, e.Position, props, keyModifiers);
else
Expand Down Expand Up @@ -186,12 +194,20 @@ PointerPointProperties CreateProperties(RawPointerEventArgs args)
kind = PointerUpdateKind.MiddleButtonPressed;
if (args.Type == RawPointerEventType.RightButtonDown)
kind = PointerUpdateKind.RightButtonPressed;
if (args.Type == RawPointerEventType.XButton1Down)
kind = PointerUpdateKind.XButton1Pressed;
if (args.Type == RawPointerEventType.XButton2Down)
kind = PointerUpdateKind.XButton2Pressed;
if (args.Type == RawPointerEventType.LeftButtonUp)
kind = PointerUpdateKind.LeftButtonReleased;
if (args.Type == RawPointerEventType.MiddleButtonUp)
kind = PointerUpdateKind.MiddleButtonReleased;
if (args.Type == RawPointerEventType.RightButtonUp)
kind = PointerUpdateKind.RightButtonReleased;
if (args.Type == RawPointerEventType.XButton1Up)
kind = PointerUpdateKind.XButton1Released;
if (args.Type == RawPointerEventType.XButton2Up)
kind = PointerUpdateKind.XButton2Released;

return new PointerPointProperties(args.InputModifiers, kind);
}
Expand Down
22 changes: 20 additions & 2 deletions src/Avalonia.Input/PointerPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,24 @@ public sealed class PointerPointProperties
public bool IsLeftButtonPressed { get; }
public bool IsMiddleButtonPressed { get; }
public bool IsRightButtonPressed { get; }
public bool IsXButton1Pressed { get; }
public bool IsXButton2Pressed { get; }

public PointerUpdateKind PointerUpdateKind { get; }

private PointerPointProperties()
{

{
}

public PointerPointProperties(RawInputModifiers modifiers, PointerUpdateKind kind)
{
PointerUpdateKind = kind;

IsLeftButtonPressed = modifiers.HasFlagCustom(RawInputModifiers.LeftMouseButton);
IsMiddleButtonPressed = modifiers.HasFlagCustom(RawInputModifiers.MiddleMouseButton);
IsRightButtonPressed = modifiers.HasFlagCustom(RawInputModifiers.RightMouseButton);
IsXButton1Pressed = modifiers.HasFlagCustom(RawInputModifiers.XButton1MouseButton);
IsXButton2Pressed = modifiers.HasFlagCustom(RawInputModifiers.XButton2MouseButton);

// The underlying input source might be reporting the previous state,
// so make sure that we reflect the current state
Expand All @@ -49,6 +55,14 @@ public PointerPointProperties(RawInputModifiers modifiers, PointerUpdateKind kin
IsRightButtonPressed = true;
if (kind == PointerUpdateKind.RightButtonReleased)
IsRightButtonPressed = false;
if (kind == PointerUpdateKind.XButton1Pressed)
IsXButton1Pressed = true;
if (kind == PointerUpdateKind.XButton1Released)
IsXButton1Pressed = false;
if (kind == PointerUpdateKind.XButton2Pressed)
IsXButton2Pressed = true;
if (kind == PointerUpdateKind.XButton2Released)
IsXButton2Pressed = false;
}

public static PointerPointProperties None { get; } = new PointerPointProperties();
Expand All @@ -59,9 +73,13 @@ public enum PointerUpdateKind
LeftButtonPressed,
MiddleButtonPressed,
RightButtonPressed,
XButton1Pressed,
XButton2Pressed,
LeftButtonReleased,
MiddleButtonReleased,
RightButtonReleased,
XButton1Released,
XButton2Released,
Other
}

Expand Down
4 changes: 4 additions & 0 deletions src/Avalonia.Input/Raw/RawPointerEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ public enum RawPointerEventType
RightButtonUp,
MiddleButtonDown,
MiddleButtonUp,
XButton1Down,
XButton1Up,
XButton2Down,
XButton2Up,
Move,
Wheel,
NonClientLeftButtonDown,
Expand Down
46 changes: 38 additions & 8 deletions src/Avalonia.Visuals/Media/DrawingContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,42 @@ public void DrawGeometry(IBrush brush, IPen pen, Geometry geometry)
}
}

/// <summary>
/// Draws a rectangle with the specified Brush and Pen.
/// </summary>
/// <param name="brush">The brush used to fill the rectangle, or <c>null</c> for no fill.</param>
/// <param name="pen">The pen used to stroke the rectangle, or <c>null</c> for no stroke.</param>
/// <param name="rect">The rectangle bounds.</param>
/// <param name="radiusX">The radius in the X dimension of the rounded corners.
/// This value will be clamped to the range of 0 to Width/2
/// </param>
/// <param name="radiusY">The radius in the Y dimension of the rounded corners.
/// This value will be clamped to the range of 0 to Height/2
/// </param>
/// <remarks>
/// The brush and the pen can both be null. If the brush is null, then no fill is performed.
/// If the pen is null, then no stoke is performed. If both the pen and the brush are null, then the drawing is not visible.
/// </remarks>
public void DrawRectangle(IBrush brush, IPen pen, Rect rect, double radiusX = 0, double radiusY = 0)
{
if (brush == null && !PenIsVisible(pen))
{
return;
}

if (Math.Abs(radiusX) > double.Epsilon)
{
radiusX = Math.Min(radiusX, rect.Width / 2);
}

if (Math.Abs(radiusY) > double.Epsilon)
{
radiusY = Math.Min(radiusY, rect.Height / 2);
}

PlatformImpl.DrawRectangle(brush, pen, rect, radiusX, radiusY);
}

/// <summary>
/// Draws the outline of a rectangle.
/// </summary>
Expand All @@ -126,10 +162,7 @@ public void DrawGeometry(IBrush brush, IPen pen, Geometry geometry)
/// <param name="cornerRadius">The corner radius.</param>
public void DrawRectangle(IPen pen, Rect rect, float cornerRadius = 0.0f)
{
if (PenIsVisible(pen))
{
PlatformImpl.DrawRectangle(pen, rect, cornerRadius);
}
DrawRectangle(null, pen, rect, cornerRadius, cornerRadius);
}

/// <summary>
Expand Down Expand Up @@ -162,10 +195,7 @@ public void DrawText(IBrush foreground, Point origin, FormattedText text)
/// <param name="cornerRadius">The corner radius.</param>
public void FillRectangle(IBrush brush, Rect rect, float cornerRadius = 0.0f)
{
if (brush != null && rect != Rect.Empty)
{
PlatformImpl.FillRectangle(brush, rect, cornerRadius);
}
DrawRectangle(brush, null, rect, cornerRadius, cornerRadius);
}

public readonly struct PushedState : IDisposable
Expand Down
26 changes: 14 additions & 12 deletions src/Avalonia.Visuals/Platform/IDrawingContextImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,22 @@ public interface IDrawingContextImpl : IDisposable
void DrawGeometry(IBrush brush, IPen pen, IGeometryImpl geometry);

/// <summary>
/// Draws the outline of a rectangle.
/// Draws a rectangle with the specified Brush and Pen.
/// </summary>
/// <param name="pen">The pen.</param>
/// <param name="brush">The brush used to fill the rectangle, or <c>null</c> for no fill.</param>
/// <param name="pen">The pen used to stroke the rectangle, or <c>null</c> for no stroke.</param>
/// <param name="rect">The rectangle bounds.</param>
/// <param name="cornerRadius">The corner radius.</param>
void DrawRectangle(IPen pen, Rect rect, float cornerRadius = 0.0f);
/// <param name="radiusX">The radius in the X dimension of the rounded corners.
/// This value will be clamped to the range of 0 to Width/2
/// </param>
/// <param name="radiusY">The radius in the Y dimension of the rounded corners.
/// This value will be clamped to the range of 0 to Height/2
/// </param>
/// <remarks>
/// The brush and the pen can both be null. If the brush is null, then no fill is performed.
/// If the pen is null, then no stoke is performed. If both the pen and the brush are null, then the drawing is not visible.
/// </remarks>
void DrawRectangle(IBrush brush, IPen pen, Rect rect, double radiusX = 0, double radiusY = 0);

/// <summary>
/// Draws text.
Expand All @@ -76,14 +86,6 @@ public interface IDrawingContextImpl : IDisposable
/// <param name="text">The text.</param>
void DrawText(IBrush foreground, Point origin, IFormattedTextImpl text);

/// <summary>
/// Draws a filled rectangle.
/// </summary>
/// <param name="brush">The brush.</param>
/// <param name="rect">The rectangle bounds.</param>
/// <param name="cornerRadius">The corner radius.</param>
void FillRectangle(IBrush brush, Rect rect, float cornerRadius = 0.0f);

/// <summary>
/// Creates a new <see cref="IRenderTargetBitmapImpl"/> that can be used as a render layer
/// for the current render target.
Expand Down
2 changes: 1 addition & 1 deletion src/Avalonia.Visuals/Rendering/DeferredRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ private void RenderDirtyRects(IDrawingContextImpl context)
foreach (var r in _dirtyRectsDisplay)
{
var brush = new ImmutableSolidColorBrush(Colors.Magenta, r.Opacity);
context.FillRectangle(brush, r.Rect);
context.DrawRectangle(brush,null, r.Rect);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Avalonia.Visuals/Rendering/RendererBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected void RenderFps(IDrawingContextImpl context, Rect clientRect, int? laye
var rect = new Rect(clientRect.Right - size.Width, 0, size.Width, size.Height);

context.Transform = Matrix.Identity;
context.FillRectangle(Brushes.Black, rect);
context.DrawRectangle(Brushes.Black,null, rect);
context.DrawText(Brushes.White, rect.TopLeft, _fpsText.PlatformImpl);
}
}
Expand Down
Loading

0 comments on commit 25aade0

Please sign in to comment.