-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ViewBase class to Blazor UI; add code behind to GalaxyMap.razor; …
…delete placeholder Component1.razor. (#325)
- Loading branch information
Showing
10 changed files
with
100 additions
and
192 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Excubo.Blazor.Canvas; | ||
using Microsoft.AspNetCore.Components; | ||
|
||
namespace FrEee.UI.Blazor.Views; | ||
|
||
public partial class GalaxyMap | ||
{ | ||
private Canvas helper_canvas; | ||
private ElementReference normal_canvas; | ||
protected override async Task OnAfterRenderAsync(bool firstRender) | ||
{ | ||
var size = VM.Scale + 1; | ||
var xoffset = VM.Width / 2d; | ||
var yoffset = VM.Height / 2d; | ||
|
||
await using (var ctx = await helper_canvas.GetContext2DAsync()) | ||
{ | ||
await ctx.ClearRectAsync(0, 0, VM.Width, VM.Height); | ||
await ctx.SetTransformAsync(size, 0, 0, size, (xoffset + 0.5) * size, (yoffset + 0.5) * size); | ||
await ctx.RestoreAsync(); | ||
await ctx.SaveAsync(); | ||
await ctx.StrokeStyleAsync("white"); | ||
await ctx.LineWidthAsync(0.1); | ||
foreach (var connections in VM.WarpGraph.Connections) | ||
{ | ||
var src = connections.Key; | ||
foreach (var dest in connections.Value) | ||
{ | ||
// TODO: display one way warps differently (arrows, incomplete lines, gradients?) | ||
await ctx.MoveToAsync(src.Location.X, src.Location.Y); | ||
await ctx.LineToAsync(dest.Location.X, dest.Location.Y); | ||
await ctx.StrokeAsync(); | ||
} | ||
} | ||
} | ||
|
||
await base.OnAfterRenderAsync(firstRender); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,8 @@ | ||
@using System.Drawing | ||
@using System.ComponentModel | ||
@inherits ViewBase<ImageDisplayViewModel> | ||
|
||
@code { | ||
[Parameter] | ||
public ImageDisplayViewModel VM { get; set; } = new(); | ||
|
||
/// <summary> | ||
/// When the view model's properties change, update the UI. | ||
/// </summary> | ||
/// <param name="sender"></param> | ||
/// <param name="e"></param> | ||
private void ViewModelPropertyChanged(object? sender, PropertyChangedEventArgs e) | ||
{ | ||
StateHasChanged(); | ||
} | ||
|
||
protected override void OnInitialized() | ||
{ | ||
VM.PropertyChanged += ViewModelPropertyChanged; | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
VM.PropertyChanged -= ViewModelPropertyChanged; | ||
} | ||
} | ||
|
||
<img src="@VM.ImageSource" @onclick="VM.OnClick" style="overflow: hidden; aspect-ratio: @(VM.AspectRatio); width: 100%; max-width: 100%; max-height: 100%"/> | ||
<img | ||
src="@VM.ImageSource" | ||
@onclick="VM.OnClick" | ||
style="overflow: hidden; aspect-ratio: @(VM.AspectRatio); width: 100%; max-width: 100%; max-height: 100%" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Components; | ||
|
||
namespace FrEee.UI.Blazor.Views; | ||
|
||
/// <summary> | ||
/// Base class for Razor views in FrEee. | ||
/// </summary> | ||
/// <typeparam name="TVM"></typeparam> | ||
public class ViewBase<TVM> | ||
: ComponentBase | ||
where TVM : INotifyPropertyChanged, new() | ||
{ | ||
/// <summary> | ||
/// The view model for this view. | ||
/// </summary> | ||
[Parameter] | ||
public TVM VM { get; set; } = new(); | ||
|
||
/// <summary> | ||
/// When the view model's properties change, update the UI. | ||
/// </summary> | ||
/// <param name="sender"></param> | ||
/// <param name="e"></param> | ||
private void ViewModelPropertyChanged(object? sender, PropertyChangedEventArgs e) | ||
{ | ||
StateHasChanged(); | ||
} | ||
|
||
protected override void OnInitialized() | ||
{ | ||
VM.PropertyChanged += ViewModelPropertyChanged; | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
VM.PropertyChanged -= ViewModelPropertyChanged; | ||
} | ||
} |