Skip to content

Commit 34ea882

Browse files
Merge pull request #46 from MarvinKlein1508/fix-background-color
Fix background color
2 parents 871f3a1 + c927fe5 commit 34ea882

File tree

9 files changed

+79
-7
lines changed

9 files changed

+79
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@page "/BGColorDemo"
2+
3+
<BackgroundColorDemo @rendermode="InteractiveServer" />

BlazorServerDemo/Pages/BGColor.razor

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@page "/BGColorDemo"
2+
3+
<BackgroundColorDemo />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@page "/BGColorDemo"
2+
3+
<BackgroundColorDemo />

Demos.Core/NavMenu.razor

+6
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@
3535
</NavLink>
3636
</div>
3737

38+
<div class="nav-item px-3">
39+
<NavLink class="nav-link" href="BGColorDemo" Match="NavLinkMatch.All">
40+
<span class="oi oi-home" aria-hidden="true"></span> BG Color
41+
</NavLink>
42+
</div>
43+
3844
<div class="nav-item px-3">
3945
<NavLink class="nav-link" href="BGImageDemo" Match="NavLinkMatch.All">
4046
<span class="oi oi-home" aria-hidden="true"></span> BG Image
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
@inject NavigationManager navigationManager
2+
@inject SignatureInMemoryService memoryService
3+
4+
<h3>BackgroundColorDemo</h3>
5+
6+
<SignaturePad @bind-Value="Input.Signature" Options="_options" style="width: 100%;" />
7+
8+
9+
@if (Input.Signature.Any())
10+
{
11+
<h2>Signature</h2>
12+
<img src="@Input.SignatureAsBase64" />
13+
<button type="button" class="btn btn-primary" @onclick="SaveSignature">Save signature</button>
14+
<button type="button" class="btn btn-primary" @onclick="OpenSignature">Open signature</button>
15+
}
16+
17+
@if (memoryService.Signature.Any())
18+
{
19+
<button type="button" class="btn btn-primary ms-1" @onclick="ReadSignature">Read signature</button>
20+
}
21+
22+
23+
24+
@code {
25+
public MyInput Input { get; set; } = new();
26+
27+
private SignaturePadOptions _options = new SignaturePadOptions
28+
{
29+
LineCap = LineCap.Round,
30+
LineJoin = LineJoin.Round,
31+
LineWidth = 10,
32+
BackgroundColor = "red",
33+
StrokeStyle = System.Drawing.Color.White
34+
};
35+
36+
37+
private void SaveSignature()
38+
{
39+
memoryService.Signature = Input.Signature;
40+
}
41+
42+
private void OpenSignature()
43+
{
44+
navigationManager.NavigateTo(Input.SignatureAsBase64);
45+
}
46+
47+
private void ReadSignature()
48+
{
49+
Input.Signature = memoryService.Signature;
50+
StateHasChanged();
51+
}
52+
}

SignaturePad/SignaturePad.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<TargetFramework>net8.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
<ImplicitUsings>enable</ImplicitUsings>
7-
<Version>8.1.4</Version>
7+
<Version>8.1.5</Version>
88
<Description>A simple to use blazor component to draw a signature.</Description>
99
<Copyright>2023</Copyright>
1010
<RepositoryUrl>https://github.com/MarvinKlein1508/SignaturePad</RepositoryUrl>

SignaturePad/SignaturePad.razor.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ protected async override Task OnAfterRenderAsync(bool firstRender)
7575
{
7676
if (firstRender)
7777
{
78-
_jsModule = await jsRuntime.InvokeAsync<IJSObjectReference>("import", "./_content/Blazor.SignaturePad/sigpad.interop.js?ver=8.1.4");
78+
_jsModule = await jsRuntime.InvokeAsync<IJSObjectReference>("import", "./_content/Blazor.SignaturePad/sigpad.interop.js?ver=8.1.5");
7979
await Setup();
8080
await Update();
8181
await UpdateImage();

SignaturePad/wwwroot/sigpad.interop.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Sigpad from "./sigpad.min.js?ver=8.1.4"
1+
import Sigpad from "./sigpad.min.js?ver=8.1.5"
22
var dotNetHelper;
33

44
export function setup(id, reference, options, image) {

SignaturePad/wwwroot/sigpad.min.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ export default class Sigpad {
8484

8585
this._element.width = this._element.clientWidth;
8686
this._element.height = this._element.clientHeight;
87+
88+
this.render(true);
8789
}
8890

8991
destroy() {
@@ -143,10 +145,7 @@ export default class Sigpad {
143145
}
144146

145147
setImage(image) {
146-
if (this._config.backgroundColor != null && this._config.backgroundColor != "") {
147-
ctx.fillStyle = this._config.backgroundColor;
148-
ctx.fillRect(0, 0, this._element.width, this._element.height);
149-
}
148+
150149

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

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

287+
if (this._config.backgroundColor != null && this._config.backgroundColor != "") {
288+
ctx.fillStyle = this._config.backgroundColor;
289+
ctx.fillRect(0, 0, this._element.width, this._element.height);
290+
}
291+
292+
288293
if (this._bgImg != undefined && this._bgImg.complete) {
289294
ctx.drawImage(this._bgImg, 0, 0,
290295
this._bgImg.width * window.devicePixelRatio,

0 commit comments

Comments
 (0)