Skip to content

Commit

Permalink
Merge pull request #46 from MarvinKlein1508/fix-background-color
Browse files Browse the repository at this point in the history
Fix background color
  • Loading branch information
MarvinKlein1508 committed Jul 23, 2024
2 parents 871f3a1 + c927fe5 commit 34ea882
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 7 deletions.
3 changes: 3 additions & 0 deletions BlazorSRRDemo/BlazorSRRDemo/Components/Pages/BGColor.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@page "/BGColorDemo"

<BackgroundColorDemo @rendermode="InteractiveServer" />
3 changes: 3 additions & 0 deletions BlazorServerDemo/Pages/BGColor.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@page "/BGColorDemo"

<BackgroundColorDemo />
3 changes: 3 additions & 0 deletions BlazorWebAssemblyDemo/Pages/BGColor.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@page "/BGColorDemo"

<BackgroundColorDemo />
6 changes: 6 additions & 0 deletions Demos.Core/NavMenu.razor
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@
</NavLink>
</div>

<div class="nav-item px-3">
<NavLink class="nav-link" href="BGColorDemo" Match="NavLinkMatch.All">
<span class="oi oi-home" aria-hidden="true"></span> BG Color
</NavLink>
</div>

<div class="nav-item px-3">
<NavLink class="nav-link" href="BGImageDemo" Match="NavLinkMatch.All">
<span class="oi oi-home" aria-hidden="true"></span> BG Image
Expand Down
52 changes: 52 additions & 0 deletions Demos.Core/SignaturePadDemos/BackgroundColorDemo.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
@inject NavigationManager navigationManager
@inject SignatureInMemoryService memoryService

<h3>BackgroundColorDemo</h3>

<SignaturePad @bind-Value="Input.Signature" Options="_options" style="width: 100%;" />


@if (Input.Signature.Any())
{
<h2>Signature</h2>
<img src="@Input.SignatureAsBase64" />
<button type="button" class="btn btn-primary" @onclick="SaveSignature">Save signature</button>
<button type="button" class="btn btn-primary" @onclick="OpenSignature">Open signature</button>
}

@if (memoryService.Signature.Any())
{
<button type="button" class="btn btn-primary ms-1" @onclick="ReadSignature">Read signature</button>
}



@code {
public MyInput Input { get; set; } = new();

private SignaturePadOptions _options = new SignaturePadOptions
{
LineCap = LineCap.Round,
LineJoin = LineJoin.Round,
LineWidth = 10,
BackgroundColor = "red",
StrokeStyle = System.Drawing.Color.White
};


private void SaveSignature()
{
memoryService.Signature = Input.Signature;
}

private void OpenSignature()
{
navigationManager.NavigateTo(Input.SignatureAsBase64);
}

private void ReadSignature()
{
Input.Signature = memoryService.Signature;
StateHasChanged();
}
}
2 changes: 1 addition & 1 deletion SignaturePad/SignaturePad.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<Version>8.1.4</Version>
<Version>8.1.5</Version>
<Description>A simple to use blazor component to draw a signature.</Description>
<Copyright>2023</Copyright>
<RepositoryUrl>https://github.com/MarvinKlein1508/SignaturePad</RepositoryUrl>
Expand Down
2 changes: 1 addition & 1 deletion SignaturePad/SignaturePad.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ protected async override Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
_jsModule = await jsRuntime.InvokeAsync<IJSObjectReference>("import", "./_content/Blazor.SignaturePad/sigpad.interop.js?ver=8.1.4");
_jsModule = await jsRuntime.InvokeAsync<IJSObjectReference>("import", "./_content/Blazor.SignaturePad/sigpad.interop.js?ver=8.1.5");
await Setup();
await Update();
await UpdateImage();
Expand Down
2 changes: 1 addition & 1 deletion SignaturePad/wwwroot/sigpad.interop.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Sigpad from "./sigpad.min.js?ver=8.1.4"
import Sigpad from "./sigpad.min.js?ver=8.1.5"
var dotNetHelper;

export function setup(id, reference, options, image) {
Expand Down
13 changes: 9 additions & 4 deletions SignaturePad/wwwroot/sigpad.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ export default class Sigpad {

this._element.width = this._element.clientWidth;
this._element.height = this._element.clientHeight;

this.render(true);
}

destroy() {
Expand Down Expand Up @@ -143,10 +145,7 @@ export default class Sigpad {
}

setImage(image) {
if (this._config.backgroundColor != null && this._config.backgroundColor != "") {
ctx.fillStyle = this._config.backgroundColor;
ctx.fillRect(0, 0, this._element.width, this._element.height);
}


if (this._config.backgroundImage != null && this._config.backgroundImage != "") {
this.setBackgroundImage(this._config.backgroundImage);
Expand Down Expand Up @@ -285,6 +284,12 @@ export default class Sigpad {

ctx.clearRect(0, 0, this._element.width, this._element.height);

if (this._config.backgroundColor != null && this._config.backgroundColor != "") {
ctx.fillStyle = this._config.backgroundColor;
ctx.fillRect(0, 0, this._element.width, this._element.height);
}


if (this._bgImg != undefined && this._bgImg.complete) {
ctx.drawImage(this._bgImg, 0, 0,
this._bgImg.width * window.devicePixelRatio,
Expand Down

0 comments on commit 34ea882

Please sign in to comment.