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

[WIP] Polyline drawing #15

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
24 changes: 17 additions & 7 deletions src/DrawTogether.UI/Client/Pages/Paint.razor
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
<Circle radius="@CursorSize" cursorId="user" cX="@cX" cY="@cY" fillColor="@Color" borderColor="@Color" />
@foreach (var c in ClientStrokes)
{
<Circle radius="@c.cursorSize" cX="@c.cX" cY="@c.cY" fillColor="@c.color" borderColor="@c.color" />
<polyline points="@string.Join(' ', c.points.Select(x => $"{x.X}, {x.Y}"))"
stroke="@(c.color)" stroke-width="@(c.cursorSize)"/>
//<Circle radius="@c.cursorSize" cX="@c.cX" cY="@c.cY" fillColor="@c.color" borderColor="@c.color" />
}
</svg>
</section>
Expand Down Expand Up @@ -66,9 +68,15 @@
await base.OnInitializedAsync();
}

private void OnNext(IList<StrokeData> obj)
private void OnNext(IList<Point> obj)
{
_hubConnection.SendAsync("AddStrokes", SessionId, obj.ToArray());
var strokeData = new StrokeData()
{
color = Color,
cursorSize = CursorSize,
points = obj.ToArray(),
};
_hubConnection.SendAsync("AddStrokes", SessionId, new[]{ strokeData });
}

private void DrawStrokes(StrokeData[] strokes)
Expand All @@ -85,7 +93,7 @@
private string mousePointerMessage = "foo";
private string blazorHubDebugMessage = "bar";
private string Color = "black";
private Subject<StrokeData> _strokeSubject = new Subject<StrokeData>();
private Subject<Point> _strokeSubject = new Subject<Point>();
private IDisposable OutboundStrokes { get; set; }
private int CursorSize = 8;

Expand All @@ -94,11 +102,13 @@
//mousePointerMessage = $"Mouse coordinates: {e.ScreenX}:{e.ScreenY}";
cX = e.OffsetX;
cY = e.OffsetY;
mousePointerMessage = $"Moving circle to {cX},{cY} [button pressed? {e.Buttons}]";
//mousePointerMessage = $"Moving circle to {cX},{cY} [button pressed? {e.Buttons}]";
if (e.Buttons == 1)
{
var newStroke = new StrokeData() {cursorSize = CursorSize, cX = e.OffsetX, cY = e.OffsetY, color = Color};
_strokeSubject.OnNext(newStroke);
var x = e.OffsetX;
var y = e.OffsetY;
mousePointerMessage = $"Writing point {x},{y} [button pressed? {e.Buttons}]";
_strokeSubject.OnNext(new Point(){ X = x, Y = y });
}
}

Expand Down
9 changes: 7 additions & 2 deletions src/DrawTogether.UI/Shared/StrokeData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ namespace DrawTogether.UI.Shared
public struct StrokeData
{
public int cursorSize { get; set; }
public double cX { get; set; }
public double cY { get; set; }
public Point[] points { get; set; }
public string color { get; set; }
}

public struct Point
{
public double X { get; set; }
public double Y { get; set; }
}
}