Skip to content

Commit

Permalink
Code style
Browse files Browse the repository at this point in the history
  • Loading branch information
Webreaper committed Jan 1, 2024
1 parent c626802 commit 50153c3
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 58 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@ dotnet_style_qualification_for_method = false:suggestion
dotnet_style_qualification_for_property = false:suggestion
dotnet_style_require_accessibility_modifiers = for_non_interface_members:suggestion

# Start of NO underscore prefix on private fields
# Define the 'private_fields' symbol group:
dotnet_naming_symbols.private_fields.applicable_kinds = field
dotnet_naming_symbols.private_fields.applicable_accessibilities = private

# Define the 'notunderscored' naming style
dotnet_naming_style.notunderscored.capitalization = camel_case
dotnet_naming_style.notunderscored.required_prefix =

# Define the 'private_fields_notunderscored' naming rule
dotnet_naming_rule.private_fields_notunderscored.symbols = private_fields
dotnet_naming_rule.private_fields_notunderscored.style = notunderscored
dotnet_naming_rule.private_fields_notunderscored.severity = error
# End of No underscore prefix on private fields

# ReSharper properties
resharper_autodetect_indent_settings = true
resharper_csharp_extra_spaces = leave_all
Expand Down
4 changes: 2 additions & 2 deletions Damselfly.Web.Client/Components/General/Bricks.razor.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
display: flex;
align-items: center;
margin: 2px;
padding: 2px 1px 1px 0px;
padding: 2px 1px 1px;
flex-wrap: nowrap;
font-size: 9pt;
cursor: default;
Expand All @@ -32,7 +32,7 @@
}

.bricktext-label {
margin: 0 2px 0 2px;
margin: 5px 2px 0 2px;
text-wrap: none;
flex: 0 1 auto;
}
Expand Down
119 changes: 63 additions & 56 deletions Damselfly.Web.Client/Shared/ImageCanvas.razor
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

@code {
[Parameter]
public Image Image { get; set; }
public Image? Image { get; set; }

[Parameter]
public string Class { get; set; }
Expand All @@ -57,7 +57,7 @@
private string CropTooltip => isCropping ? "Click to apply crop" : "Click to start crop mode";

private SKBlendMode mode = SKBlendMode.Color;
private SKGLView glViewRef;
private SKGLView? glViewRef;
private SKBitmap? sourceBitmap;
private int currentImageId = 0;
private CancellationTokenSource loadCancellationSource = new();
Expand All @@ -76,7 +76,7 @@

private SKRect paintArea = new SKRect(0, 0, 0, 0);
private float paintScale = 0f;
private float lastDPI = 1.0f;
private float lastDpi = 1.0f;
private float zoomAmount = 0.0f;
private SKPoint zoomOffset = new SKPoint();

Expand All @@ -97,30 +97,33 @@
/// <param name="degrees"></param>
private void DoRotate(int degrees)
{
var oldBitmap = sourceBitmap;
if( Image != null )
{
var oldBitmap = sourceBitmap;

rotation += degrees;
if (rotation >= 360)
rotation = 0;
if (rotation < 0)
rotation = 270;
rotation += degrees;
if ( rotation >= 360 )
rotation = 0;
if ( rotation < 0 )
rotation = 270;

tagService.SetExifFieldAsync(new[] { Image.ImageId }, ExifOperation.ExifType.Rotate, rotation.ToString() );
tagService.SetExifFieldAsync(new[] { Image.ImageId }, ExifOperation.ExifType.Rotate, rotation.ToString() );

sourceBitmap = Rotate(oldBitmap, degrees);
oldBitmap.Dispose();
ClearCrop();
Repaint();
sourceBitmap = Rotate(oldBitmap, degrees);
oldBitmap.Dispose();
ClearCrop();
Repaint();
}
}

private SKRect? GetDragRect()
{
if (dragStart.HasValue && dragEnd.HasValue)
{
SKRect rect = new SKRect(dragStart.Value.X * lastDPI,
dragStart.Value.Y * lastDPI,
dragEnd.Value.X * lastDPI,
dragEnd.Value.Y * lastDPI);
SKRect rect = new SKRect(dragStart.Value.X * lastDpi,
dragStart.Value.Y * lastDpi,
dragEnd.Value.X * lastDpi,
dragEnd.Value.Y * lastDpi);

if (rect.Left > rect.Right)
{
Expand Down Expand Up @@ -196,7 +199,7 @@
if (obj != null)
dpi = (double)obj.GetValue(glViewRef)!;

lastDPI = (float)dpi;
lastDpi = (float)dpi;
}

private SKPoint GetCoords(MouseEventArgs e)
Expand Down Expand Up @@ -272,57 +275,61 @@

private async Task LoadImage(CancellationToken token)
{
var url = Image.ThumbUrl(ThumbSize.Medium);

SKBitmap? bmp = null;
try
if( Image != null )
{
using var imageStream = await restClient.GetStreamAsync(url, token);
var url = Image.ThumbUrl(ThumbSize.Medium);

bmp = LoadOriented(imageStream);
try
{
using var imageStream = await restClient.GetStreamAsync(url, token);

if (bmp != null && !token.IsCancellationRequested)
var bmp = LoadOriented(imageStream);

if ( !token.IsCancellationRequested )
{
logger.LogInformation($"Loaded image {url} successfully");
SetBitmap(bmp);
}
else
logger.LogError($"Failed to decode {url} - bitmap was null");
}
catch ( OperationCanceledException )
{
logger.LogInformation($"Loaded image {url} successfully");
SetBitmap(bmp);
logger.LogWarning($"Cancelling low-res load as hi-res image is already loaded {url}");
}
catch ( Exception ex )
{
logger.LogError($"Unable to load image {url}: {ex}");
}
else
logger.LogError($"Failed to decode {url} - bitmap was null");
}
catch (OperationCanceledException)
{
logger.LogWarning($"Cancelling low-res load as hi-res image is already loaded {url}");
}
catch (Exception ex)
{
logger.LogError($"Unable to load image {url}: {ex}");
}
}

private async Task LoadHiResImage()
{
var url = Image.ThumbUrl(ThumbSize.ExtraLarge);

SKBitmap? bmp = null;
try
if( Image != null )
{
using var imageStream = await restClient.GetStreamAsync(url);
var url = Image.ThumbUrl(ThumbSize.ExtraLarge);

try
{
using var imageStream = await restClient.GetStreamAsync(url);

bmp = SKBitmap.Decode(imageStream);
var bmp = SKBitmap.Decode(imageStream);

if (bmp != null)
if ( bmp != null )
{
logger.LogInformation($"Loaded hi-res image {url} successfully");
// Cancel the low-res load.
loadCancellationSource.Cancel();
SetBitmap(bmp);
}
else
logger.LogError($"Failed to decode hi-res {url} - bitmap was null");
}
catch ( Exception ex )
{
logger.LogInformation($"Loaded hi-res image {url} successfully");
// Cancel the low-res load.
loadCancellationSource.Cancel();
SetBitmap(bmp);
logger.LogError($"Unable to load hi-res image {url}: {ex}");
}
else
logger.LogError($"Failed to decode hi-res {url} - bitmap was null");
}
catch (Exception ex)
{
logger.LogError($"Unable to load hi-res image {url}: {ex}");
}
}

Expand Down Expand Up @@ -508,7 +515,7 @@
StrokeCap = SKStrokeCap.Round,
StrokeWidth = 2f,
Color = SKColor.Parse("#ffffff"),
PathEffect = SKPathEffect.CreateDash(new[] { 5 * lastDPI, 2 * lastDPI }, 20)
PathEffect = SKPathEffect.CreateDash(new[] { 5 * lastDpi, 2 * lastDpi }, 20)
};

canvas.DrawRect(dragRect.Value, dragBorder);
Expand Down

0 comments on commit 50153c3

Please sign in to comment.